1 |
mocchiut |
1.1 |
// |
2 |
|
|
//- Emiliano Mocchiutti |
3 |
|
|
// |
4 |
|
|
// FCaloCALIBSCAN.cxx version 1.01 (2006-03-08) |
5 |
|
|
// |
6 |
|
|
// The only input needed is |
7 |
|
|
// |
8 |
|
|
// Changelog: |
9 |
|
|
// |
10 |
|
|
// 1.00 - 1.01 (2006-03-08): Flight version, read unique YODA file. |
11 |
|
|
// |
12 |
|
|
// 0.00 - 1.00 (2006-03-08): Clone of CaloCALIBSCAN. |
13 |
|
|
// |
14 |
|
|
#include <fstream> |
15 |
|
|
#include <sstream> |
16 |
|
|
#include <string> |
17 |
mocchiut |
1.3 |
#include <stdlib.h> |
18 |
mocchiut |
1.1 |
#include <TTree.h> |
19 |
|
|
#include <TClassEdit.h> |
20 |
|
|
#include <TObject.h> |
21 |
|
|
#include <TList.h> |
22 |
|
|
#include <TSystem.h> |
23 |
|
|
#include <TSystemDirectory.h> |
24 |
|
|
#include <TString.h> |
25 |
|
|
#include <TFile.h> |
26 |
|
|
#include <TClass.h> |
27 |
|
|
#include <TCanvas.h> |
28 |
|
|
#include <TH1.h> |
29 |
|
|
#include <TH1F.h> |
30 |
|
|
#include <TH2D.h> |
31 |
|
|
#include <TLatex.h> |
32 |
|
|
#include <TPad.h> |
33 |
|
|
#include <TPaveLabel.h> |
34 |
|
|
#include <TChain.h> |
35 |
|
|
#include <TStyle.h> |
36 |
|
|
// |
37 |
|
|
#include <PamelaRun.h> |
38 |
|
|
#include <physics/calorimeter/CalorimeterEvent.h> |
39 |
|
|
#include <physics/trigger/TriggerEvent.h> |
40 |
|
|
#include <CalibCalPedEvent.h> |
41 |
|
|
#include <fcalostructs.h> |
42 |
|
|
// |
43 |
|
|
extern bool existfile(TString); |
44 |
|
|
extern void stringcopy(TString&, const TString&, Int_t, Int_t); |
45 |
|
|
extern TString getFilename(const TString); |
46 |
|
|
// |
47 |
|
|
#include <caloclassesfun.h> |
48 |
|
|
// |
49 |
|
|
using namespace std; |
50 |
|
|
// |
51 |
|
|
|
52 |
|
|
short int FCaloCALIBSCAN(TString Filename, TString flist=""){ |
53 |
|
|
const char* startingdir = gSystem->WorkingDirectory(); |
54 |
|
|
TString calcalib; |
55 |
|
|
struct Calib calib; |
56 |
|
|
// |
57 |
|
|
stringstream file5; |
58 |
|
|
file5.str(""); |
59 |
|
|
file5 << startingdir << "/CaloCALIBdata.root"; |
60 |
|
|
// |
61 |
|
|
Int_t nfile = 0; |
62 |
|
|
Int_t calibex = 0; |
63 |
|
|
Int_t fileup = 0; |
64 |
|
|
if ( flist != "" ){ |
65 |
|
|
printf("\n You have given an input file list \n\n Files: \n"); |
66 |
|
|
ifstream in; |
67 |
|
|
in.open(flist, ios::in); |
68 |
|
|
char ctime[20]; |
69 |
|
|
while (1) { |
70 |
|
|
in >> ctime; |
71 |
|
|
if (!in.good()) break; |
72 |
|
|
printf(" File number %i = %s \n",nfile+1,ctime); |
73 |
|
|
nfile++; |
74 |
|
|
}; |
75 |
|
|
in.close(); |
76 |
|
|
if ( !nfile ) { |
77 |
|
|
printf("\n\n The list is empty, exiting... \n\n"); |
78 |
|
|
return(0); |
79 |
|
|
}; |
80 |
|
|
} else { |
81 |
|
|
nfile = 1; |
82 |
|
|
}; |
83 |
|
|
printf("\n"); |
84 |
|
|
// |
85 |
|
|
// First check if the calibration file exists: |
86 |
|
|
// |
87 |
|
|
Int_t EFILE = 0; |
88 |
|
|
printf(" Check the existence of CaloCALIBdata.root file: \n\n"); |
89 |
|
|
// |
90 |
|
|
if ( !existfile((TString)file5.str().c_str()) ){ |
91 |
|
|
printf(" %s :no such file or directory \n",file5.str().c_str()); |
92 |
|
|
printf("\n OK, I will create it!\n\n"); |
93 |
|
|
EFILE = 0; |
94 |
|
|
} else { |
95 |
|
|
printf(" The file already exists! It will be updated \n\n"); |
96 |
|
|
EFILE = 1; |
97 |
|
|
} |
98 |
|
|
// |
99 |
|
|
// this must be done for each file. |
100 |
|
|
// |
101 |
|
|
Long64_t neven = 0; |
102 |
|
|
TTree *trl1 = 0; |
103 |
|
|
TFile *hfl1 = 0; |
104 |
|
|
CalorimeterCalibScan *calo = new CalorimeterCalibScan(); |
105 |
|
|
if ( EFILE == 1 ){ |
106 |
|
|
// |
107 |
|
|
// If the file doesn't exist create it |
108 |
|
|
// |
109 |
|
|
hfl1 = new TFile(file5.str().c_str(),"UPDATE","Calorimeter calib data"); |
110 |
mocchiut |
1.2 |
// calo = new CalorimeterCalibScan(); |
111 |
mocchiut |
1.1 |
// |
112 |
|
|
trl1 = (TTree*)hfl1->Get("CaloCALIBdata"); |
113 |
|
|
trl1->SetBranchAddress("Event", &calo); |
114 |
|
|
neven = trl1->GetEntries()-1; |
115 |
|
|
trl1->GetEntry(neven); |
116 |
|
|
calibex = calo->evno; |
117 |
|
|
} else { |
118 |
|
|
// |
119 |
|
|
// If the file doesn't exist create it |
120 |
|
|
// |
121 |
|
|
hfl1 = new TFile(file5.str().c_str(),"RECREATE","Calorimeter calib data"); |
122 |
|
|
// |
123 |
mocchiut |
1.2 |
// calo = new CalorimeterCalibScan(); |
124 |
mocchiut |
1.1 |
// |
125 |
|
|
trl1 = new TTree("CaloCALIBdata","PAMELA calorimeter calibration data"); |
126 |
|
|
trl1->Branch("Event","CalorimeterCalibScan",&calo); |
127 |
|
|
}; |
128 |
|
|
// |
129 |
|
|
const char *filename2 = Filename; |
130 |
|
|
// |
131 |
|
|
TString lfile; |
132 |
|
|
TString sfile; |
133 |
|
|
// |
134 |
|
|
Int_t e = 0; |
135 |
|
|
ifstream in; |
136 |
|
|
in.open(flist, ios::in); |
137 |
|
|
char ctime[20]; |
138 |
|
|
const char *nome; |
139 |
|
|
// |
140 |
|
|
TString fififile; |
141 |
|
|
const char *file; |
142 |
|
|
TString filename; |
143 |
|
|
// |
144 |
|
|
stringstream lfillo; |
145 |
|
|
// |
146 |
|
|
pamela::CalibCalPedEvent *ce = 0; |
147 |
|
|
pamela::PscuHeader *cph = 0; |
148 |
|
|
pamela::EventHeader *ceh = 0; |
149 |
|
|
Long64_t ncalibs = 0; |
150 |
|
|
Int_t s = -1; |
151 |
|
|
Int_t l = 0; |
152 |
|
|
Int_t m = 0; |
153 |
|
|
Int_t ss = 0; |
154 |
mocchiut |
1.2 |
TTree *tr = 0; |
155 |
|
|
TFile *File = 0; |
156 |
mocchiut |
1.1 |
// |
157 |
|
|
while ( e < nfile ){ |
158 |
|
|
if ( flist != "" ){ |
159 |
|
|
in >> ctime; |
160 |
|
|
lfillo.str(""); |
161 |
|
|
lfillo << filename2 << "/"; |
162 |
|
|
lfillo << ctime; |
163 |
|
|
lfile = (TString)lfillo.str().c_str(); |
164 |
|
|
fififile = getFilename(lfile); |
165 |
|
|
file = fififile; |
166 |
|
|
lfillo.str(""); |
167 |
|
|
lfillo << file; |
168 |
|
|
sfile = (TString)lfillo.str().c_str(); |
169 |
|
|
} else { |
170 |
|
|
lfillo.str(""); |
171 |
|
|
lfillo << filename2; |
172 |
|
|
lfile = (TString)lfillo.str().c_str(); |
173 |
|
|
fififile = getFilename(lfile); |
174 |
|
|
file = fififile; |
175 |
|
|
lfillo.str(""); |
176 |
|
|
lfillo << file; |
177 |
|
|
sfile = (TString)lfillo.str().c_str(); |
178 |
|
|
}; |
179 |
|
|
// |
180 |
|
|
filename = lfile; |
181 |
|
|
nome = filename; |
182 |
|
|
printf("\n Processing file number %i: %s \n\n",e+1,nome); |
183 |
|
|
// |
184 |
mocchiut |
1.2 |
const string fil = (const char *)(gSystem->BaseName(filename)); |
185 |
|
|
Int_t posiz = 0; |
186 |
|
|
// Int_t posiz = fil.find("dw_"); |
187 |
|
|
// if ( posiz == -1 ) posiz = fil.find("DW_"); |
188 |
|
|
// if ( posiz == -1 ) return(-1); |
189 |
|
|
TString filenam2=(TString)(gSystem->BaseName(filename)); |
190 |
|
|
TString year; |
191 |
|
|
stringcopy(year,filenam2,posiz,posiz+5); |
192 |
|
|
const char *ye = year; |
193 |
|
|
TString month; |
194 |
|
|
stringcopy(month,filenam2,posiz+7,posiz+9); |
195 |
|
|
const char *mo = month; |
196 |
|
|
TString day; |
197 |
|
|
stringcopy(day,filenam2,posiz+11,posiz+13); |
198 |
|
|
const char *da = day; |
199 |
|
|
// TString fno; |
200 |
|
|
// stringcopy(fno,filename,posiz+10,posiz+13); |
201 |
|
|
// const char *fn = fno; |
202 |
|
|
stringstream unino; |
203 |
|
|
unino.str(""); |
204 |
|
|
unino << ye << mo; |
205 |
|
|
unino << da; |
206 |
|
|
// unino << da << fn; |
207 |
|
|
// |
208 |
|
|
// stringstream unino; |
209 |
|
|
// unino.str(""); |
210 |
|
|
// unino << (e+1); |
211 |
|
|
// unino << ye; |
212 |
|
|
// |
213 |
|
|
// printf("unino is %s \n",unino.str().c_str()); |
214 |
mocchiut |
1.1 |
// |
215 |
|
|
// upgrade data... |
216 |
|
|
// |
217 |
|
|
if ( !existfile(filename) ){ |
218 |
|
|
printf(" %s :no such file or directory \n",filename.Data()); |
219 |
|
|
goto jumpfile; |
220 |
|
|
}; |
221 |
|
|
File = new TFile(filename.Data()); |
222 |
mocchiut |
1.2 |
// tr = new TTree; |
223 |
mocchiut |
1.1 |
tr = (TTree*)File->Get("CalibCalPed"); |
224 |
|
|
tr->SetBranchAddress("Header", &ceh); |
225 |
|
|
tr->SetBranchAddress("CalibCalPed", &ce); |
226 |
|
|
ncalibs = tr->GetEntries(); |
227 |
|
|
if ( ncalibs == 0 ) goto oltre; |
228 |
mocchiut |
1.2 |
//calo = new CalorimeterCalibScan(); |
229 |
mocchiut |
1.1 |
s = -1; |
230 |
|
|
l = 0; |
231 |
|
|
m = 0; |
232 |
mocchiut |
1.2 |
calo->Clear(); |
233 |
mocchiut |
1.1 |
for (Int_t ci = 0; ci < ncalibs ; ci++){ |
234 |
mocchiut |
1.2 |
// calo = new CalorimeterCalibScan(); |
235 |
mocchiut |
1.1 |
tr->GetEntry(ci); |
236 |
|
|
// |
237 |
|
|
s++; |
238 |
|
|
if ( s == 4 ) s = 0; |
239 |
|
|
if ( s == 0 ) ss = 0; |
240 |
|
|
if ( s == 1 ) ss = 2; |
241 |
|
|
if ( s == 2 ) ss = 3; |
242 |
|
|
if ( s == 3 ) ss = 1; |
243 |
|
|
// |
244 |
|
|
if ( s == 0 ){ |
245 |
|
|
Double_t noca = (double)ci/100.; |
246 |
|
|
Double_t calno = atof(unino.str().c_str())+noca; |
247 |
|
|
calo->calno = calno; |
248 |
|
|
calibex++; |
249 |
|
|
calo->evno = calibex; |
250 |
|
|
}; |
251 |
|
|
// |
252 |
|
|
// |
253 |
|
|
if (ce->cstwerr[s] != 0 && ce->cperror[s] == 0 ) { |
254 |
|
|
cph = ceh->GetPscuHeader(); |
255 |
|
|
calo->etime[ss] = cph->GetOrbitalTime(); |
256 |
|
|
for ( Int_t d=0 ; d<11 ;d++ ){ |
257 |
|
|
Int_t pre = -1; |
258 |
|
|
if ( s == 2 ) m = 2*d+1; |
259 |
|
|
if ( s == 3 ) m = 2*d; |
260 |
|
|
if ( s == 0 ) m = 2*d; |
261 |
|
|
if ( s == 1 ) m = 2*d+1; |
262 |
|
|
if ( s == 3 ) l = 0; |
263 |
|
|
if ( s == 2 ) l = 0; |
264 |
|
|
if ( s == 1 ) l = 1; |
265 |
|
|
if ( s == 0 ) l = 1; |
266 |
|
|
for ( Int_t j=0; j<96 ;j++){ |
267 |
|
|
if ( j%16 == 0 ) pre++; |
268 |
|
|
calo->calped[l][m][j] = ce->calped[ss][d][j]; |
269 |
|
|
calo->cstwerr[ss] = ce->cstwerr[s]; |
270 |
|
|
calo->cperror[ss] = ce->cperror[s]; |
271 |
|
|
calo->calgood[l][m][j] = ce->calgood[ss][d][j]; |
272 |
|
|
calo->calthr[l][m][pre] = ce->calthr[ss][d][pre]; |
273 |
|
|
calo->calrms[l][m][j] = ce->calrms[ss][d][j]/4.; |
274 |
|
|
calo->calbase[l][m][pre] = ce->calbase[ss][d][pre]; |
275 |
|
|
calo->calvar[l][m][pre] = ce->calvar[ss][d][pre]; |
276 |
|
|
}; |
277 |
|
|
}; |
278 |
|
|
}; |
279 |
|
|
// |
280 |
|
|
if ( s == 3 ){ |
281 |
|
|
trl1->Fill(); |
282 |
mocchiut |
1.2 |
calo->Clear(); |
283 |
|
|
// calo = new CalorimeterCalibScan(); |
284 |
mocchiut |
1.1 |
}; |
285 |
|
|
}; |
286 |
mocchiut |
1.2 |
// |
287 |
|
|
//if ( calo ) delete calo; |
288 |
|
|
// |
289 |
mocchiut |
1.1 |
fileup++; |
290 |
|
|
// |
291 |
|
|
goto oltre; |
292 |
|
|
jumpfile: printf(" File not processed! \n "); |
293 |
|
|
oltre: |
294 |
mocchiut |
1.2 |
if ( File ) File->Close(); |
295 |
|
|
// if ( tr ) delete tr; |
296 |
mocchiut |
1.1 |
e++; |
297 |
|
|
}; |
298 |
|
|
hfl1->Write(); |
299 |
|
|
hfl1->Close(); |
300 |
|
|
return(0); |
301 |
|
|
} |