1 |
// |
2 |
//- Emiliano Mocchiutti |
3 |
// |
4 |
// FCaloADC2MIP.c version 1.02 (2006-03-31) |
5 |
// |
6 |
// The only input needed is |
7 |
// |
8 |
// Changelog: |
9 |
// |
10 |
// 1.01 - 1.02 (2006-03-31): Added FCaloALIG2DAT and FCaloREADALIG to create and read the calorimeter alignment data file. |
11 |
// |
12 |
// 1.00 - 1.01 (2006-03-20): First flight version, read single yoda file. |
13 |
// |
14 |
// 0.00 - 1.00 (2006-03-20): Clone of CaloADC2MIP v4r01. |
15 |
// |
16 |
// |
17 |
#include <fstream> |
18 |
#include <sstream> |
19 |
#include <string> |
20 |
#include <iostream> |
21 |
#include <TTree.h> |
22 |
#include <TClassEdit.h> |
23 |
#include <TObject.h> |
24 |
#include <TList.h> |
25 |
#include <TSystem.h> |
26 |
#include <TSystemDirectory.h> |
27 |
#include <TString.h> |
28 |
#include <TFile.h> |
29 |
#include <TClass.h> |
30 |
#include <TCanvas.h> |
31 |
#include <TH1.h> |
32 |
#include <TH1F.h> |
33 |
#include <TH2D.h> |
34 |
#include <TLatex.h> |
35 |
#include <TPad.h> |
36 |
#include <TPaveLabel.h> |
37 |
#include <TChain.h> |
38 |
#include <TGraph.h> |
39 |
#include <TMultiGraph.h> |
40 |
#include <TLine.h> |
41 |
#include <TStyle.h> |
42 |
#include <TF1.h> |
43 |
// |
44 |
#include <fcalostructs.h> |
45 |
// |
46 |
extern const char *pathtocalibration(); |
47 |
extern TString getFilename(const TString); |
48 |
extern TString whatnamewith(TString, Int_t); |
49 |
extern void stringcopy(TString&, const TString&, Int_t, Int_t); |
50 |
extern int CaloPede(TString, Int_t, Int_t, Calib &); |
51 |
extern void CaloFindBaseRaw(Calib &, Evento &, Int_t, Int_t, Int_t); |
52 |
extern void CaloFindBaseRawNC(Calib &, Evento &, Int_t, Int_t, Int_t); |
53 |
extern void CaloCompressData(Calib &, Evento &, Int_t, Int_t, Int_t); |
54 |
extern int CaloFindCalibs(TString &, TString &, Int_t &, Calib &); |
55 |
extern bool existfile(TString); |
56 |
TF1 *langaufit(TH1F *, Double_t *, Double_t *, Double_t *, Double_t *, Double_t *, Double_t *, Double_t *, Int_t *, TString); |
57 |
Double_t langaupro(Double_t *); |
58 |
// |
59 |
// |
60 |
#include <PamelaRun.h> |
61 |
#include <physics/calorimeter/CalorimeterEvent.h> |
62 |
#include <physics/trigger/TriggerEvent.h> |
63 |
#include <CalibCalPedEvent.h> |
64 |
// |
65 |
#include <caloclassesfun.h> |
66 |
#include <FCaloADC2MIPfun.h> |
67 |
using namespace std; |
68 |
|
69 |
void FCaloADC2MIP(TString Filename, TString calcalibfile = "", TString OutDir="", TString flist="", Int_t fit=1){ |
70 |
const char *pam_calib = pathtocalibration(); |
71 |
if ( !strcmp(OutDir.Data(),"") ){ |
72 |
OutDir = pam_calib; |
73 |
}; |
74 |
// |
75 |
TString calcalib; |
76 |
struct Evento evento; |
77 |
struct Calib calib; |
78 |
Int_t debug = 0; |
79 |
Int_t b[4]; |
80 |
Int_t etime,evno; |
81 |
Float_t sdexy[2][22][96],sdexyc[2][22][96]; |
82 |
Float_t edelta[2][22][96]; |
83 |
Float_t estrip[2][22][96]; |
84 |
Float_t estripnull[2][22][96]; |
85 |
Float_t delta; |
86 |
delta = 1.; |
87 |
evento.emin = 0.7; |
88 |
Int_t UPYES = 0; |
89 |
Int_t se =5; |
90 |
Int_t pre; |
91 |
Int_t rdone=0; |
92 |
Int_t done; |
93 |
bool isCOMP = 0; |
94 |
bool isFULL = 0; |
95 |
bool isRAW = 0; |
96 |
TH1F *pfmip[2][22][96]; |
97 |
TF1 *pfitsnr[2][22][96]; |
98 |
stringstream Fmip; |
99 |
for (Int_t i=0; i<2;i++){ |
100 |
for (Int_t j=0; j<22;j++){ |
101 |
for (Int_t m=0; m<96;m++){ |
102 |
Fmip.str(""); |
103 |
Fmip << "Fmip " << i; |
104 |
Fmip << " " << j; |
105 |
Fmip << " " << m; |
106 |
pfmip[i][j][m] = new TH1F(Fmip.str().c_str(),"",56,0.,55.); |
107 |
pfitsnr[i][j][m] = new TF1; |
108 |
}; |
109 |
}; |
110 |
}; |
111 |
// |
112 |
// the file which contains the calorimeter ADC to MIP conversion values is file2 = path to the script dir / CaloADC2MIP.root |
113 |
// |
114 |
stringstream file2; |
115 |
file2.str(""); |
116 |
file2 << OutDir.Data() << "/CaloADC2MIP.root"; |
117 |
// |
118 |
// this the figures and fit (4224 x 2 objects!) |
119 |
// |
120 |
stringstream file3; |
121 |
file3.str(""); |
122 |
file3 << OutDir.Data() << "/CaloADC2MIPf.root"; |
123 |
// |
124 |
stringstream file4; |
125 |
file4.str(""); |
126 |
file4 << OutDir.Data() << "/CaloADC2MIPf"; |
127 |
// |
128 |
stringstream file5; |
129 |
file5.str(""); |
130 |
file5 << OutDir.Data() << "/CaloADC2MIPdata.root"; |
131 |
// |
132 |
Int_t nfile = 0; |
133 |
Int_t fileup = 0; |
134 |
if ( flist != "" ){ |
135 |
printf("\n You have given an input file list \n\n Files: \n"); |
136 |
ifstream in; |
137 |
in.open(flist, ios::in); |
138 |
char ctime[20]; |
139 |
while (1) { |
140 |
in >> ctime; |
141 |
if (!in.good()) break; |
142 |
printf(" File number %i = %s \n",nfile+1,ctime); |
143 |
nfile++; |
144 |
}; |
145 |
in.close(); |
146 |
if ( !nfile ) { |
147 |
printf("\n\n The list is empty, exiting... \n\n"); |
148 |
return; |
149 |
}; |
150 |
} else { |
151 |
nfile = 1; |
152 |
}; |
153 |
printf("\n"); |
154 |
// |
155 |
// First check if the calibration file exists: |
156 |
// |
157 |
Int_t EFILE = 0; |
158 |
printf(" Check the existence of CaloADC2MIP.root file: \n\n"); |
159 |
if ( !existfile(file2.str().c_str()) ){ |
160 |
printf(" %s :no such file or directory \n",file2.str().c_str()); |
161 |
printf("\n OK, I will create it!\n\n"); |
162 |
EFILE = 0; |
163 |
} else { |
164 |
printf(" The file already exists! Check if an update is needed \n\n"); |
165 |
EFILE = 1; |
166 |
}; |
167 |
// |
168 |
// the check for an update is done once even if we have a list. |
169 |
// |
170 |
TTree *tree; |
171 |
CalorimeterCalibration *calo = new CalorimeterCalibration(); |
172 |
if ( EFILE == 1) { |
173 |
// |
174 |
// The file exists, open it (READ ONLY) and check if any update is needed: |
175 |
// |
176 |
TFile *hfile = 0; |
177 |
hfile = new TFile(file2.str().c_str(),"READ","Calorimeter CALIBRATION data"); |
178 |
tree = (TTree*)hfile->Get("CaloADC"); |
179 |
calo = new CalorimeterCalibration(); |
180 |
tree->SetBranchAddress("Event", &calo); |
181 |
// |
182 |
Long64_t nevents = tree->GetEntries(); |
183 |
printf("\n Number of updates: %i\n",(int)nevents); |
184 |
tree->GetEntry(nevents-1); |
185 |
// |
186 |
// Read the status variable of the last event: if it is 0 then we need an update, if it is one print out informations and exit |
187 |
// |
188 |
if ( calo->status == 0 ) { |
189 |
printf("\n An update is needed: \n"); |
190 |
Int_t upstrip = 0; |
191 |
for (Int_t i = 0; i<2; i++){ |
192 |
for (Int_t j = 0; j<22; j++){ |
193 |
for (Int_t l = 0; l<96; l++){ |
194 |
if ( calo->mask[i][j][l] == 0. ) upstrip++; |
195 |
}; |
196 |
}; |
197 |
}; |
198 |
printf(" %i strip out of 4224 have no statistic enough.\n\n",upstrip); |
199 |
} else { |
200 |
printf(" No update is needed! \n The data files used to obtain the ADC to MIP conversion are: \n"); |
201 |
for (Int_t i = 0; i<nevents; i++){ |
202 |
tree->GetEntry(i); |
203 |
const char *fout = calo->fname; |
204 |
printf(" - %s \n",fout); |
205 |
}; |
206 |
printf("\n\n"); |
207 |
return; |
208 |
}; |
209 |
hfile->Close(); |
210 |
}; |
211 |
// |
212 |
const char *filename2 = Filename; |
213 |
// |
214 |
TString lfile; |
215 |
TString sfile; |
216 |
// |
217 |
Int_t e = 0; |
218 |
ifstream in; |
219 |
in.open(flist, ios::in); |
220 |
char ctime[20]; |
221 |
TString file2f; |
222 |
TString pfile; |
223 |
const char *cali; |
224 |
const char *ffile; |
225 |
Int_t calibex = 0; |
226 |
// |
227 |
TString filename; |
228 |
const char *nome; |
229 |
TFile *hfile = 0; |
230 |
calo = new CalorimeterCalibration(); |
231 |
Long64_t nevents; |
232 |
Int_t used = 0; |
233 |
const char *compare; |
234 |
Int_t hf3 = 0; |
235 |
Int_t ufile = 0; |
236 |
TFile *headerFile = 0; |
237 |
file2f = ""; |
238 |
pfile = ""; |
239 |
stringstream fmippa; |
240 |
const char *porca; |
241 |
Int_t S4; |
242 |
Int_t upnn; |
243 |
Int_t notgood = 0; |
244 |
Int_t notgood1 = 0; |
245 |
stringstream files; |
246 |
TFile *hfileb = 0; |
247 |
// |
248 |
Int_t pl1, pl2, strmin, strmax; |
249 |
Int_t spre=0; |
250 |
Int_t surstrip = 0; |
251 |
Float_t estrippa = 0.; |
252 |
Int_t surmam = 0; |
253 |
Int_t surman = 0; |
254 |
Int_t surmatrix[3][3]; |
255 |
// |
256 |
TString fififile; |
257 |
const char *file; |
258 |
// |
259 |
stringstream nofi; |
260 |
nofi.str(""); |
261 |
TFile *hfile3 = 0; |
262 |
// |
263 |
while ( e < nfile ){ |
264 |
if ( flist != "" ){ |
265 |
in >> ctime; |
266 |
nofi.str(""); |
267 |
nofi << filename2 << "/"; |
268 |
nofi << ctime; |
269 |
lfile = TString(nofi.str().c_str()); |
270 |
fififile = getFilename(lfile); |
271 |
file = fififile; |
272 |
nofi.str(""); |
273 |
nofi << file; |
274 |
sfile = TString(nofi.str().c_str()); |
275 |
} else { |
276 |
nofi.str(""); |
277 |
nofi << filename2; |
278 |
lfile = TString(nofi.str().c_str()); |
279 |
fififile = getFilename(lfile); |
280 |
file = fififile; |
281 |
nofi.str(""); |
282 |
nofi << file; |
283 |
sfile = TString(nofi.str().c_str()); |
284 |
}; |
285 |
// |
286 |
filename = lfile; |
287 |
nome = filename; |
288 |
printf("\n Processing file number %i: %s \n\n",e,nome); |
289 |
nome = sfile; |
290 |
// |
291 |
// this must be done for each file. |
292 |
// |
293 |
const char *calname; |
294 |
calname = ""; |
295 |
Int_t wused = 0; |
296 |
TTree *otr; |
297 |
pamela::calorimeter::CalorimeterEvent *de = 0; |
298 |
pamela::trigger::TriggerEvent *trigger = 0; |
299 |
pamela::PscuHeader *ph = 0; |
300 |
pamela::EventHeader *eh = 0; |
301 |
// |
302 |
if ( EFILE == 1 ){ |
303 |
hfile = new TFile(file2.str().c_str(),"UPDATE","Calorimeter CALIBRATION data"); |
304 |
tree = (TTree*)hfile->Get("CaloADC"); |
305 |
calo = new CalorimeterCalibration(); |
306 |
tree->SetBranchAddress("Event", &calo); |
307 |
// |
308 |
// Check if the input file has already been used |
309 |
// |
310 |
printf(" Check if file %s has already been used... \n",nome); |
311 |
nevents = tree->GetEntries(); |
312 |
used = 0; |
313 |
for (Int_t i = 0; i<nevents; i++){ |
314 |
tree->GetEntry(i); |
315 |
compare= calo->fname; |
316 |
if ( !strcmp(compare,nome) ) { |
317 |
used = 1; |
318 |
break; |
319 |
}; |
320 |
}; |
321 |
if ( used ) { |
322 |
printf(" The file %s has already been used!\n You cannot run twice this program with that file!\n\n",nome); |
323 |
hfile->Close(); |
324 |
goto jumpfile; |
325 |
} else { |
326 |
printf(" Good, the file has not been used yet. \n\n"); |
327 |
nevents = tree->GetEntries() -1; |
328 |
tree->GetEntry(nevents); |
329 |
}; |
330 |
} else { |
331 |
// |
332 |
// If the file doesn't exist create it |
333 |
// |
334 |
calo = new CalorimeterCalibration(); |
335 |
hfile = new TFile(file2.str().c_str(),"NEW","Calorimeter CALIBRATION data"); |
336 |
if ( !existfile(file2.str().c_str()) ){ |
337 |
printf(" %s :no such file or directory \n",filename.Data()); |
338 |
printf(" ERROR: Cannot create file \n"); |
339 |
return; |
340 |
}; |
341 |
// if ( hfile->IsZombie() ){ |
342 |
// printf(" ERROR: Cannot create file \n"); |
343 |
// return; |
344 |
//}; |
345 |
tree = new TTree("CaloADC","Calorimeter calibration data"); |
346 |
tree->Branch("Event","CalorimeterCalibration",&calo); |
347 |
}; |
348 |
// |
349 |
// |
350 |
// |
351 |
hf3 = 0; |
352 |
if ( e == 0 ){ |
353 |
if ( !existfile(file3.str().c_str()) ){ |
354 |
ufile = 0; |
355 |
} else { |
356 |
printf(" Update figures file! \n\n"); |
357 |
ufile = 1; |
358 |
}; |
359 |
}; |
360 |
if ( (EFILE == 1 || ufile == 1) && e == 0 ){ |
361 |
printf(" Reading the old MIP figures to be updated...\n "); |
362 |
hfile3 = new TFile(file3.str().c_str()); |
363 |
hf3 = 1; |
364 |
// |
365 |
stringstream fmino; |
366 |
fmino.str(""); |
367 |
for (Int_t l = 0; l < 2; l++){ |
368 |
for (Int_t m = 0; m < 22; m++){ |
369 |
for (Int_t n =0 ; n < 96; n++){ |
370 |
fmino.str(""); |
371 |
fmino << "fmip " << l; |
372 |
fmino << " " << m; |
373 |
fmino << " " << n; |
374 |
gDirectory->Delete(fmino.str().c_str()); |
375 |
TH1F *temp = (TH1F*)hfile3->Get(fmino.str().c_str()); |
376 |
pfmip[l][m][n] = (TH1F*)temp->Clone(); |
377 |
}; |
378 |
}; |
379 |
}; |
380 |
printf(" ...done!\n"); |
381 |
}; |
382 |
EFILE = 1; |
383 |
// |
384 |
// Check if the input calibration file contains any calibration data |
385 |
// |
386 |
done = 0; |
387 |
printf(" Check for calorimeter calibration: \n"); |
388 |
calcalib = filename; |
389 |
findcalibs: printf(" Calibration file: %s \n",calname); |
390 |
calname = calcalib; |
391 |
for (Int_t s=0; s<4;s++){ |
392 |
for (Int_t d = 0; d<50; d++){ |
393 |
calib.ttime[s][d] = 0 ; |
394 |
if ( d < 49 ) calib.time[s][d] = 0 ; |
395 |
}; |
396 |
}; |
397 |
for (Int_t m = 0; m < 2 ; m++ ){ |
398 |
for (Int_t k = 0; k < 22; k++ ){ |
399 |
for (Int_t l = 0; l < 96; l++ ){ |
400 |
calib.calped[m][k][l] = 0. ; |
401 |
evento.dexy[m][k][l] = 0. ; |
402 |
evento.dexyc[m][k][l] = 0. ; |
403 |
edelta[m][k][l] = 0.; |
404 |
estrip[m][k][l] = 0.; |
405 |
estripnull[m][k][l] = 0.; |
406 |
}; |
407 |
}; |
408 |
} |
409 |
wused = 0; |
410 |
CaloFindCalibs(calcalib, calcalib, wused, calib); |
411 |
// |
412 |
// print on the screen the results: |
413 |
// |
414 |
ffile = filename; |
415 |
printf(" ------ %s ------- \n \n",ffile); |
416 |
calibex = 0; |
417 |
for (Int_t s=0; s<4;s++){ |
418 |
printf(" ** SECTION %i **\n",s); |
419 |
for (Int_t d = 0; d<51; d++){ |
420 |
if ( calib.ttime[s][d] != 0 ) { |
421 |
calibex++; |
422 |
if ( calib.fcode[s][d] != 10 ){ |
423 |
file2f = ""; |
424 |
stringcopy(file2f,calcalib,0,0); |
425 |
pfile = (TString)whatnamewith(file2f,calib.fcode[s][d]); |
426 |
} else { |
427 |
pfile = (TString)calcalib; |
428 |
}; |
429 |
ffile = pfile; |
430 |
printf(" - from time %i to time %i use calibration at\n time %i, file: %s \n",calib.time[s][d],calib.time[s][d+1],calib.ttime[s][d],ffile); |
431 |
}; |
432 |
}; |
433 |
printf("\n"); |
434 |
}; |
435 |
printf(" ----------------------------------------------------------------------- \n \n"); |
436 |
// |
437 |
if ( calibex < 1 ) { |
438 |
printf("No calibration data in this file!\n"); |
439 |
calcalib = calcalibfile; |
440 |
if ( !done && calcalibfile != "" ) { |
441 |
cali = calcalibfile; |
442 |
printf(" Search in the calibration file %s \n",cali); |
443 |
done = 1; |
444 |
goto findcalibs; |
445 |
} else { |
446 |
printf(" Cannot find any calibration for this file! \n"); |
447 |
goto jumpfile; |
448 |
}; |
449 |
}; |
450 |
if ( calibex < 4 ) { |
451 |
printf(" WARNING! No full calibration data in this file! \n\n"); |
452 |
}; |
453 |
// |
454 |
// upgrade data... |
455 |
// |
456 |
if ( !existfile(filename) ){ |
457 |
printf(" %s :no such file or directory \n",filename.Data()); |
458 |
goto jumpfile; |
459 |
}; |
460 |
headerFile = new TFile(filename.Data()); |
461 |
otr = (TTree*)headerFile->Get("Physics"); |
462 |
otr->SetBranchAddress("Header", &eh); |
463 |
otr->SetBranchAddress("Calorimeter", &de); |
464 |
otr->SetBranchAddress("Trigger", &trigger); |
465 |
// |
466 |
nevents = otr->GetEntries(); |
467 |
// |
468 |
// calibrate before starting |
469 |
// |
470 |
for (Int_t s = 0; s < 4; s++){ |
471 |
b[s]=0; |
472 |
if ( calib.fcode[s][b[s]] != 10 ){ |
473 |
stringcopy(file2f,calcalib,0,0); |
474 |
pfile = (TString)whatnamewith(file2f,calib.fcode[s][b[s]]); |
475 |
} else { |
476 |
pfile = (TString)calcalib; |
477 |
}; |
478 |
porca = pfile; |
479 |
if ( debug ) printf(" porca miseria %s \n",porca); |
480 |
CaloPede(pfile,s,calib.ttime[s][b[s]],calib); |
481 |
}; |
482 |
// |
483 |
// run over all the events |
484 |
// |
485 |
printf("\n Processed events: \n\n"); |
486 |
// |
487 |
for (Int_t i = 0; i < nevents; i++){ |
488 |
evno = i; |
489 |
if ( i%100000 == 0 && i > 0 ) printf(" %i00K \n",i/100000); |
490 |
// printf(" %i \n",i); |
491 |
// |
492 |
// read from the header of the event the absolute time at which it was recorded |
493 |
// |
494 |
otr->GetEntry(i); |
495 |
// |
496 |
S4 = trigger->patterntrig[1] & (1<<0); |
497 |
// |
498 |
if ( !S4 || i == 0 ) { |
499 |
ph = eh->GetPscuHeader(); |
500 |
etime = ph->GetOrbitalTime(); |
501 |
// |
502 |
// for each event check that the calibration we are using are still within calibration limits, if not call the next calibration |
503 |
// |
504 |
if ( !calib.obtjump ) { |
505 |
for (Int_t s = 0; s < 4; s++){ |
506 |
if ( calib.ttime[s][b[s]] ){ |
507 |
while ( etime > calib.time[s][b[s]+1] ){ |
508 |
printf(" CALORIMETER: \n" ); |
509 |
printf(" - Section %i, event at time %i while old calibration time limit at %i. Use new calibration at time %i -\n",s,etime,calib.time[s][b[s]+1],calib.ttime[s][b[s]+1]); |
510 |
printf(" END CALORIMETER. \n\n" ); |
511 |
b[s]++; |
512 |
if ( calib.fcode[s][b[s]] != 10 ){ |
513 |
stringcopy(file2f,calcalib,0,0); |
514 |
pfile = (TString)whatnamewith(file2f,calib.fcode[s][b[s]]); |
515 |
} else { |
516 |
pfile = (TString)calcalib; |
517 |
}; |
518 |
porca = pfile; |
519 |
if ( debug ) printf(" porca miseria %s \n",porca); |
520 |
CaloPede(pfile,s,calib.ttime[s][b[s]],calib); |
521 |
}; |
522 |
}; |
523 |
}; |
524 |
}; |
525 |
// |
526 |
// do whatever you want with data |
527 |
// |
528 |
evento.iev = de->iev; |
529 |
// |
530 |
// run over views and planes |
531 |
// |
532 |
for (Int_t l = 0; l < 2; l++){ |
533 |
for (Int_t m = 0; m < 22; m++){ |
534 |
// |
535 |
// determine the section number |
536 |
// |
537 |
if (l == 0 && m%2 == 0) se = 3; |
538 |
if (l == 0 && m%2 != 0) se = 2; |
539 |
if (l == 1 && m%2 == 0) se = 0; |
540 |
if (l == 1 && m%2 != 0) se = 1; |
541 |
// |
542 |
// determine what kind of event we are going to analyze |
543 |
// |
544 |
isCOMP = 0; |
545 |
isFULL = 0; |
546 |
isRAW = 0; |
547 |
if ( de->stwerr[se] & (1 << 16) ) isCOMP = 1; |
548 |
if ( de->stwerr[se] & (1 << 17) ) isFULL = 1; |
549 |
if ( de->stwerr[se] & (1 << 3) ) isRAW = 1; |
550 |
// |
551 |
// save the prevoius energy deposit and calibration in sbase, sdexy, sdexyc |
552 |
// |
553 |
pre = -1; |
554 |
if ( isRAW ){ |
555 |
for (Int_t nn = 0; nn < 96; nn++){ |
556 |
if ( nn%16 == 0 ) pre++; |
557 |
evento.base[l][m][pre] = calib.calbase[l][m][pre]; |
558 |
sdexy[l][m][nn] = evento.dexy[l][m][nn]; |
559 |
evento.dexy[l][m][nn] = de->dexy[l][m][nn] ; |
560 |
sdexyc[l][m][nn] = evento.dexyc[l][m][nn]; |
561 |
evento.dexyc[l][m][nn] = de->dexyc[l][m][nn] ; |
562 |
}; |
563 |
}; |
564 |
// |
565 |
// run over strips |
566 |
// |
567 |
pre = -1; |
568 |
for (Int_t n =0 ; n < 96; n++){ |
569 |
if ( n%16 == 0 ) { |
570 |
pre++; |
571 |
rdone = 0; |
572 |
done = 0; |
573 |
}; |
574 |
if ( calo->mask[l][m][n] == 0. && ( isRAW || ( de->dexyc[l][m][n] > 0. && de->dexyc[l][m][n] < 32000.)) ){ |
575 |
// |
576 |
// baseline check and calculation |
577 |
// |
578 |
if ( isRAW ) { |
579 |
if ( !rdone ){ |
580 |
CaloFindBaseRaw(calib,evento,l,m,pre); |
581 |
rdone = 1; |
582 |
}; |
583 |
} else { |
584 |
if ( !done ){ |
585 |
evento.base[l][m][pre] = de->base[l][m][pre] ; |
586 |
evento.dexyc[l][m][n] = de->dexyc[l][m][n] ; |
587 |
}; |
588 |
}; |
589 |
// |
590 |
// no suitable new baseline, use old ones and compress data! |
591 |
// |
592 |
if ( !done && (evento.base[l][m][pre] > 30000. || evento.base[l][m][pre] == 0.) ){ |
593 |
evento.base[l][m][pre] = calib.sbase[l][m][pre]; |
594 |
upnn = n+16; |
595 |
if ( upnn > 96 ) upnn = 96; |
596 |
for ( Int_t nn = n; nn<upnn; nn++ ){ |
597 |
evento.dexyc[l][m][nn] = de->dexyc[l][m][nn] ; |
598 |
}; |
599 |
CaloCompressData(calib,evento,l,m,pre); |
600 |
done = 1; |
601 |
}; |
602 |
// |
603 |
// CALIBRATION ALGORITHM |
604 |
// |
605 |
pl1 = -1; |
606 |
pl2 = -1; |
607 |
pl1 = m - 1; |
608 |
pl2 = m + 1; |
609 |
if ( pl1 < 0 ) { |
610 |
pl1 = pl2; |
611 |
pl2 = m + 2; |
612 |
}; |
613 |
if ( pl2 > 21 ) { |
614 |
pl2 = pl1; |
615 |
pl1 = m - 2; |
616 |
}; |
617 |
strmin = n - 1; |
618 |
if ( strmin < 0 ) strmin = 0; |
619 |
strmax = n + 1; |
620 |
if ( strmax > 95 ) strmax = 95; |
621 |
surstrip = 0; |
622 |
surmam = 0; |
623 |
surman = 0; |
624 |
for (Int_t im = 0; im<3 ;im++){ |
625 |
for (Int_t jm = 0; jm<3 ;jm++){ |
626 |
surmatrix[im][jm] = 0; |
627 |
}; |
628 |
}; |
629 |
for (Int_t spl = pl1; spl<pl2+1; spl++){ |
630 |
if ( spl != m ){ |
631 |
surmam = spl - pl1; |
632 |
for (Int_t sst = strmin; sst <= strmax ; sst++){ |
633 |
surman = sst - strmin; |
634 |
if ( sst < 16 ) spre = 0; |
635 |
if ( 15 < sst && sst < 32 ) spre = 1; |
636 |
if ( 31 < sst && sst < 48 ) spre = 2; |
637 |
if ( 47 < sst && sst < 64 ) spre = 3; |
638 |
if ( 63 < sst && sst < 80 ) spre = 4; |
639 |
if ( 79 < sst ) spre = 5; |
640 |
if ( isRAW ){ |
641 |
estrippa = ( evento.dexy[l][spl][sst] - calib.calped[l][spl][sst] - calib.sbase[l][spl][spre])/26. ; |
642 |
} else { |
643 |
estrippa = ( evento.dexyc[l][spl][sst] - calib.calped[l][spl][sst] - calib.sbase[l][spl][spre])/26. ; |
644 |
}; |
645 |
if ( estrippa > 0.7 && estrippa < 10. && calib.calgood[l][spl][sst] == 0 ){ |
646 |
surstrip++; |
647 |
surmatrix[surmam][surman]++; |
648 |
//printf("surstrip = %i estrip = %f \n",surstrip,estrip); |
649 |
}; |
650 |
}; |
651 |
}; |
652 |
}; |
653 |
if ( (surmatrix[0][0] && surmatrix[2][0]) ) surstrip = 0; |
654 |
if ( (surmatrix[0][2] && surmatrix[2][2]) ) surstrip = 0; |
655 |
// |
656 |
// |
657 |
estrip[l][m][n] = ( evento.dexyc[l][m][n] - calib.calped[l][m][n] - evento.base[l][m][pre]) ; |
658 |
if ( estrip[l][m][n] >= 0. && estrip[l][m][n] <= 56. && surstrip >=2 ){ |
659 |
pfmip[l][m][n]->Fill(estrip[l][m][n]); |
660 |
UPYES = 1; |
661 |
}; |
662 |
calib.sbase[l][m][pre] = evento.base[l][m][pre]; |
663 |
}; |
664 |
}; |
665 |
}; |
666 |
}; |
667 |
}; |
668 |
}; |
669 |
// |
670 |
// save filename |
671 |
// |
672 |
calo->fname = sfile; |
673 |
tree->Fill(); |
674 |
hfile->Write(); |
675 |
fileup++; |
676 |
hfile->Close(); |
677 |
// |
678 |
// create a backup copy! |
679 |
// |
680 |
|
681 |
if ( nfile > 1 && ( e%10 == 0 || e == nfile-1 ) && e > 0 ){ |
682 |
files.str(""); |
683 |
files << file4.str().c_str() << (e+1); |
684 |
files << ".bak"; |
685 |
printf(" Save the backup file with figures:\n %s \n ",files.str().c_str()); |
686 |
hfileb = new TFile(files.str().c_str(),"RECREATE","Calorimeter CALIBRATION figures"); |
687 |
if ( !existfile(files.str().c_str()) ){ |
688 |
printf(" ERROR: Cannot create file!!! \n"); |
689 |
goto oltre; |
690 |
}; |
691 |
TH1F *bfmip[2][22][96]; |
692 |
stringstream bmippa; |
693 |
bmippa.str(""); |
694 |
for (Int_t l = 0; l < 2; l++){ |
695 |
for (Int_t m = 0; m < 22; m++){ |
696 |
for (Int_t n =0 ; n < 96; n++){ |
697 |
bmippa.str(""); |
698 |
bmippa << "bmip " << l; |
699 |
bmippa << " " << m; |
700 |
bmippa << " " << n; |
701 |
bfmip[l][m][n] = new TH1F(bmippa.str().c_str(),"",56,0.,55.); |
702 |
bfmip[l][m][n] = (TH1F*)pfmip[l][m][n]->Clone(bmippa.str().c_str()); |
703 |
bfmip[l][m][n]->Write(); |
704 |
}; |
705 |
}; |
706 |
}; |
707 |
hfileb->Close(); |
708 |
}; |
709 |
// |
710 |
// |
711 |
// |
712 |
headerFile->Close(); |
713 |
// caloFile->Close(); |
714 |
//triggerFile->Close(); |
715 |
goto oltre; |
716 |
jumpfile: printf(" File not processed! \n "); |
717 |
hfile->Close(); |
718 |
oltre: |
719 |
// gObjectTable->Print(); |
720 |
e++; |
721 |
}; |
722 |
// |
723 |
if ( !fit ) UPYES=0; |
724 |
// |
725 |
if ( !UPYES ) goto end; |
726 |
printf("\n OK, now I will fit the MIP distribution for each strip \n\n"); |
727 |
// |
728 |
hfile = new TFile(file2.str().c_str(),"UPDATE","Calorimeter CALIBRATION data"); |
729 |
calo = new CalorimeterCalibration(); |
730 |
tree = (TTree*)hfile->Get("CaloADC"); |
731 |
tree->SetBranchAddress("Event", &calo); |
732 |
nevents = tree->GetEntries(); |
733 |
if ( (nevents-1-fileup) > 0 ){ |
734 |
tree->GetEntry(nevents-1-fileup); |
735 |
}; |
736 |
// |
737 |
// Fit all 4224 distributions and save parameters, fit, figures (all basically). |
738 |
// |
739 |
notgood = 0; |
740 |
notgood1 = 0; |
741 |
// |
742 |
// |
743 |
for (Int_t l = 0; l < 2; l++){ |
744 |
for (Int_t m = 0; m < 22; m++){ |
745 |
for (Int_t n =0 ; n < 96; n++){ |
746 |
Double_t SNRPeak = 0.; |
747 |
if ( calo->mask[l][m][n] == 0. ){ |
748 |
// |
749 |
// Setting fit range and start values |
750 |
// |
751 |
Double_t fr[2]; |
752 |
Double_t sv[4], pllo[4], plhi[4], fp[4], fpe[4]; |
753 |
// if ( SNRPeak > 16. && SNRPeak < 35. ){ |
754 |
if ( SNRPeak > 16. && SNRPeak < 35. && fp[3] < 8.){ |
755 |
fr[0] = (Float_t)SNRPeak - 7.; |
756 |
sv[0]= fp[0]; |
757 |
sv[1]= fp[1]; |
758 |
sv[2]= fp[2]; |
759 |
sv[3]= fp[3]; |
760 |
} else { |
761 |
// fr[0] = 19.; |
762 |
fr[0] = 17.5; |
763 |
sv[0] = 2.8; |
764 |
// sv[1] = 21.0; |
765 |
sv[1] = 23.0; |
766 |
sv[2] = 1000.0; |
767 |
sv[3] = 0.1; |
768 |
}; |
769 |
Int_t doitagain = 0; |
770 |
fitting: printf("Fitting strip %i %i %i \n",l,m,n); |
771 |
// fr[1] = 60.; |
772 |
fr[1] = 50.; |
773 |
pllo[0]=0.5; pllo[1]=5.0; pllo[2]=1.0; pllo[3]=0.2; |
774 |
// plhi[0]=8.0; plhi[1]=50.0; plhi[2]=1000000.0; plhi[3]=8.0; |
775 |
plhi[0]=15.0; plhi[1]=50.0; plhi[2]=1000000.0; plhi[3]=8.0; |
776 |
Double_t chisqr; |
777 |
Int_t ndf; |
778 |
// |
779 |
// fit the figure pfmip and put fit results in pfitsnr |
780 |
// |
781 |
pfitsnr[l][m][n] = langaufit(pfmip[l][m][n],fr,sv,pllo,plhi,fp,fpe,&chisqr,&ndf,"QR0"); |
782 |
// |
783 |
// search for the maximum of the distribution, it will be the conversion factor between ADC channels and the MIP |
784 |
// |
785 |
Double_t SNRPeak = langaupro(fp); |
786 |
printf("\n Conversion factor: %f \n\n",SNRPeak); |
787 |
// |
788 |
// |
789 |
// |
790 |
// if ( ( SNRPeak < 0. || (SNRPeak < 16. || SNRPeak > 35.) || chisqr > 100.) && doitagain < 3 ){ |
791 |
if ( ( SNRPeak < 0. || (SNRPeak < 16. || SNRPeak > 35.) || chisqr > 100.) && doitagain < 4 ){ |
792 |
printf("\n The fit is not good, I will try again, step %i \n\n",doitagain); |
793 |
doitagain++; |
794 |
if ( chisqr > 100. ) { |
795 |
// fr[0] = fr[0] + 5.; |
796 |
fr[0] = fr[0] + 2.; |
797 |
sv[0] = fp[0]; |
798 |
sv[1] = fp[1]; |
799 |
sv[2] = fp[2]; |
800 |
sv[3] = fp[3]; |
801 |
goto fitting; |
802 |
}; |
803 |
if ( doitagain == 2 ) { |
804 |
fr[0] = 19.; |
805 |
sv[0] = 2.8; |
806 |
sv[1] = 21.0; |
807 |
sv[2] = 1000.0; |
808 |
sv[3] = 0.1; |
809 |
goto fitting; |
810 |
}; |
811 |
if ( doitagain == 1 ) { |
812 |
fr[0] = 22.; |
813 |
sv[0] = 2.8; |
814 |
sv[1] = 25.0; |
815 |
sv[2] = 1000.0; |
816 |
sv[3] = 0.1; |
817 |
goto fitting; |
818 |
}; |
819 |
if ( doitagain == 3 ) { |
820 |
fr[0] = 12.; |
821 |
sv[0] = 2.8; |
822 |
sv[1] = 15.0; |
823 |
sv[2] = 1000.0; |
824 |
sv[3] = 0.1; |
825 |
goto fitting; |
826 |
}; |
827 |
}; |
828 |
|
829 |
// |
830 |
// save data |
831 |
// |
832 |
calo->mip[l][m][n] = (float)SNRPeak; |
833 |
calo->ermip[l][m][n] = (float)fpe[1]; |
834 |
for (Int_t a = 0; a < 4 ; a++){ |
835 |
calo->fp[a][l][m][n] = (float)fp[a]; |
836 |
calo->fpe[a][l][m][n] = (float)fpe[a]; |
837 |
}; |
838 |
calo->ndf[l][m][n] = (float)ndf; |
839 |
calo->chi2[l][m][n] = (float)chisqr; |
840 |
if ( calo->fp[1][l][m][n] > 16. && calo->fp[1][l][m][n] < 35. ) notgood1++; |
841 |
// |
842 |
if ( ndf!=0 && chisqr/ndf < 2. && fpe[1] < 0.15 && fp[1] > 15. && fp[1] < 40. && SNRPeak > 0. ) { |
843 |
printf(" THIS IS A GOOD FIT, SAVED! \n\n"); |
844 |
calo->mask[l][m][n] = 1.; |
845 |
} else { |
846 |
notgood++; |
847 |
calo->mask[l][m][n] = 0.; |
848 |
}; |
849 |
printf("Fitting done, strip %i %i %i \n\n\n",l,m,n); |
850 |
// |
851 |
// draw the figure and fit on the screen |
852 |
// |
853 |
//c1->Clear(); |
854 |
//c1->cd(); |
855 |
//pfmip[l][m][n]->DrawCopy(); |
856 |
//pfitsnr[l][m][n]->DrawCopy("lsame"); |
857 |
//c1->Modified(); |
858 |
//c1->Update(); |
859 |
}; |
860 |
}; |
861 |
}; |
862 |
}; |
863 |
// |
864 |
calo->status = 0; |
865 |
if ( !notgood ) calo->status = 1; |
866 |
// |
867 |
// save fit data |
868 |
// |
869 |
tree->Fill(); |
870 |
hfile->Write(); |
871 |
hfile->Close(); |
872 |
// |
873 |
// Save histograms and fit figures |
874 |
// |
875 |
TFile *hfile2; |
876 |
hfile2 = new TFile(file3.str().c_str(),"RECREATE","Calorimeter CALIBRATION figures"); |
877 |
if ( !existfile(file3.str().c_str()) ){ |
878 |
printf(" ERROR: Cannot create file \n"); |
879 |
return; |
880 |
}; |
881 |
TH1F *sfmip[2][22][96]; |
882 |
TF1 *sfitsnr[2][22][96]; |
883 |
fmippa.str(""); |
884 |
for (Int_t l = 0; l < 2; l++){ |
885 |
for (Int_t m = 0; m < 22; m++){ |
886 |
for (Int_t n =0 ; n < 96; n++){ |
887 |
fmippa.str(""); |
888 |
fmippa << "fmip " << l; |
889 |
fmippa << " " << m; |
890 |
fmippa << " " << n; |
891 |
sfmip[l][m][n] = new TH1F(fmippa.str().c_str(),"",56,0.,55.); |
892 |
sfmip[l][m][n] = (TH1F*)pfmip[l][m][n]->Clone(fmippa.str().c_str()); |
893 |
fmippa.str(""); |
894 |
fmippa << "fit " << l; |
895 |
fmippa << " " << m; |
896 |
fmippa << " " << n; |
897 |
sfitsnr[l][m][n] = (TF1*)pfitsnr[l][m][n]->Clone(fmippa.str().c_str()); |
898 |
sfmip[l][m][n]->Write(); |
899 |
sfitsnr[l][m][n]->Write(); |
900 |
}; |
901 |
}; |
902 |
}; |
903 |
hfile2->Close(); |
904 |
if ( hf3 ) hfile3->Close(); |
905 |
// |
906 |
if ( notgood ) { |
907 |
printf("\n An update will be necessary:\n %i strip with too low statistic (%i of them gave a result anyway)\n\n",notgood,notgood1); |
908 |
}; |
909 |
// |
910 |
end: printf("\n"); |
911 |
// |
912 |
} |
913 |
|
914 |
void FCaloRAWADC2MIPPLOT(TString Filename, TString calcalibfile = "", TString OutDir="", TString flist=""){ |
915 |
const char *pam_calib = pathtocalibration(); |
916 |
if ( !strcmp(OutDir.Data(),"") ){ |
917 |
OutDir = pam_calib; |
918 |
}; |
919 |
// |
920 |
TString calcalib; |
921 |
struct Evento evento; |
922 |
struct Calib calib; |
923 |
Int_t debug = 0; |
924 |
Int_t b[4]; |
925 |
Int_t etime,evno; |
926 |
Float_t sdexy[2][22][96],sdexyc[2][22][96]; |
927 |
Float_t edelta[2][22][96]; |
928 |
Float_t estrip[2][22][96]; |
929 |
Float_t estripnull[2][22][96]; |
930 |
Float_t delta; |
931 |
CalorimeterCalibration *calo = new CalorimeterCalibration(); |
932 |
delta = 1.; |
933 |
evento.emin = 0.7; |
934 |
Int_t se =5; |
935 |
Int_t pre; |
936 |
Int_t rdone = 0; |
937 |
Int_t done; |
938 |
bool isCOMP = 0; |
939 |
bool isFULL = 0; |
940 |
bool isRAW = 0; |
941 |
TH1F *pfmip[2][22][96]; |
942 |
TF1 *pfitsnr[2][22][96]; |
943 |
stringstream Fmip; |
944 |
Fmip.str(""); |
945 |
for (Int_t i=0; i<2;i++){ |
946 |
for (Int_t j=0; j<22;j++){ |
947 |
for (Int_t m=0; m<96;m++){ |
948 |
Fmip.str(""); |
949 |
Fmip << "Fmip " << i; |
950 |
Fmip << " " << j; |
951 |
Fmip << " " << m; |
952 |
pfmip[i][j][m] = new TH1F(Fmip.str().c_str(),"",70,-15.,55.); |
953 |
pfitsnr[i][j][m] = new TF1; |
954 |
}; |
955 |
}; |
956 |
}; |
957 |
// |
958 |
// the file which contains the calorimeter ADC to MIP conversion values is file2 = path to the script dir / CaloADC2MIP.root |
959 |
// |
960 |
stringstream file2; |
961 |
file2.str(""); |
962 |
file2 << OutDir.Data() << "/CaloADC2MIP.raw"; |
963 |
// |
964 |
// this the figures and fit (4224 x 2 objects!) |
965 |
// |
966 |
stringstream file3; |
967 |
file3 << OutDir.Data() << "/CaloADC2MIPfr.raw"; |
968 |
// |
969 |
stringstream file4; |
970 |
file4.str(""); |
971 |
file4 << OutDir.Data() << "/CaloADC2MIPfr"; |
972 |
// |
973 |
stringstream file5; |
974 |
file5.str(""); |
975 |
file5 << OutDir.Data() << "/CaloADC2MIPdata.raw"; |
976 |
// |
977 |
Int_t nfile = 0; |
978 |
Int_t fileup = 0; |
979 |
if ( flist != "" ){ |
980 |
printf("\n You have given an input file list \n\n Files: \n"); |
981 |
ifstream in; |
982 |
in.open(flist, ios::in); |
983 |
char ctime[20]; |
984 |
while (1) { |
985 |
in >> ctime; |
986 |
if (!in.good()) break; |
987 |
printf(" File number %i = %s \n",nfile+1,ctime); |
988 |
nfile++; |
989 |
}; |
990 |
in.close(); |
991 |
if ( !nfile ) { |
992 |
printf("\n\n The list is empty, exiting... \n\n"); |
993 |
return; |
994 |
}; |
995 |
} else { |
996 |
nfile = 1; |
997 |
}; |
998 |
printf("\n"); |
999 |
// |
1000 |
// First check if the calibration file exists: |
1001 |
// |
1002 |
Int_t EFILE = 0; |
1003 |
printf(" Check the existence of CaloADC2MIP.raw file: \n\n"); |
1004 |
|
1005 |
if ( !existfile(file2.str().c_str()) ){ |
1006 |
printf(" %s :no such file or directory \n",file2.str().c_str()); |
1007 |
printf("\n OK, I will create it!\n\n"); |
1008 |
EFILE = 0; |
1009 |
} else { |
1010 |
printf(" The file already exists! Check if an update is needed \n\n"); |
1011 |
EFILE = 1; |
1012 |
}; |
1013 |
// |
1014 |
// the check for an update is done once even if we have a list. |
1015 |
// |
1016 |
TTree *tree = 0; |
1017 |
if ( EFILE == 1) { |
1018 |
// |
1019 |
// The file exists, open it (READ ONLY) and check if any update is needed: |
1020 |
// |
1021 |
TFile *hfile = 0; |
1022 |
hfile = new TFile(file2.str().c_str(),"READ","Calorimeter CALIBRATION data"); |
1023 |
calo = new CalorimeterCalibration(); |
1024 |
tree = (TTree*)hfile->Get("CaloADC"); |
1025 |
tree->SetBranchAddress("Event", &calo); |
1026 |
// |
1027 |
Long64_t nevents = tree->GetEntries(); |
1028 |
printf("\n Number of updates: %i\n",(int)nevents); |
1029 |
tree->GetEntry(nevents-1); |
1030 |
// |
1031 |
// Read the status variable of the last event: if it is 0 then we need an update, if it is one print out informations and exit |
1032 |
// |
1033 |
if ( calo->status == 0 ) { |
1034 |
printf("\n An update is needed: \n"); |
1035 |
Int_t upstrip = 0; |
1036 |
for (Int_t i = 0; i<2; i++){ |
1037 |
for (Int_t j = 0; j<22; j++){ |
1038 |
for (Int_t l = 0; l<96; l++){ |
1039 |
if ( calo->mask[i][j][l] == 0. ) upstrip++; |
1040 |
}; |
1041 |
}; |
1042 |
}; |
1043 |
printf(" %i strip out of 4224 have no statistic enough.\n\n",upstrip); |
1044 |
} else { |
1045 |
printf(" No update is needed! \n The data files used to obtain the ADC to MIP conversion are: \n"); |
1046 |
for (Int_t i = 0; i<nevents; i++){ |
1047 |
tree->GetEntry(i); |
1048 |
const char *fnout = calo->fname; |
1049 |
printf(" - %s \n",fnout); |
1050 |
}; |
1051 |
printf("\n\n"); |
1052 |
return; |
1053 |
}; |
1054 |
hfile->Close(); |
1055 |
}; |
1056 |
// |
1057 |
const char *filename2 = Filename; |
1058 |
// |
1059 |
TString lfile; |
1060 |
TString sfile; |
1061 |
// |
1062 |
Int_t e = 0; |
1063 |
ifstream in; |
1064 |
in.open(flist, ios::in); |
1065 |
char ctime[20]; |
1066 |
TString pfile; |
1067 |
const char *cali; |
1068 |
const char *ffile; |
1069 |
Int_t calibex = 0; |
1070 |
// |
1071 |
TString filename; |
1072 |
const char *nome = 0; |
1073 |
TFile *hfile = 0; |
1074 |
// CalorimeterCalibration *calo = 0; |
1075 |
Long64_t nevents; |
1076 |
Int_t used = 0; |
1077 |
const char *compare = 0; |
1078 |
Int_t hf3 = 0; |
1079 |
TFile *headerFile = 0; |
1080 |
TString file2f = ""; |
1081 |
pfile = ""; |
1082 |
const char *porca = 0; |
1083 |
Int_t S4; |
1084 |
Int_t upnn; |
1085 |
stringstream files; |
1086 |
TFile *hfileb = 0; |
1087 |
// |
1088 |
Int_t pl1, pl2, strmin, strmax; |
1089 |
Int_t spre=0; |
1090 |
Int_t surstrip = 0; |
1091 |
Float_t estrippa = 0.; |
1092 |
// |
1093 |
TFile *hfile3 = 0; |
1094 |
TString fififile; |
1095 |
const char *file; |
1096 |
// |
1097 |
calo = new CalorimeterCalibration(); |
1098 |
stringstream finome; |
1099 |
finome.str(""); |
1100 |
while ( e < nfile ){ |
1101 |
if ( flist != "" ){ |
1102 |
in >> ctime; |
1103 |
finome.str(""); |
1104 |
finome << filename2 << "/"; |
1105 |
finome << ctime; |
1106 |
lfile = TString(finome.str().c_str()); |
1107 |
fififile = getFilename(lfile); |
1108 |
file = fififile; |
1109 |
finome.str(""); |
1110 |
finome << file; |
1111 |
sfile = TString(finome.str().c_str()); |
1112 |
} else { |
1113 |
finome.str(""); |
1114 |
finome << filename2; |
1115 |
lfile = TString(finome.str().c_str()); |
1116 |
fififile = getFilename(lfile); |
1117 |
file = fififile; |
1118 |
finome.str(""); |
1119 |
finome << file; |
1120 |
sfile = TString(finome.str().c_str()); |
1121 |
}; |
1122 |
// |
1123 |
filename = lfile; |
1124 |
nome = filename; |
1125 |
printf("\n Processing file number %i: %s \n\n",e,nome); |
1126 |
nome = sfile; |
1127 |
// |
1128 |
// this must be done for each file. |
1129 |
// |
1130 |
TTree *otr; |
1131 |
pamela::calorimeter::CalorimeterEvent *de = 0; |
1132 |
pamela::trigger::TriggerEvent *trigger = 0; |
1133 |
pamela::PscuHeader *ph = 0; |
1134 |
pamela::EventHeader *eh = 0; |
1135 |
const char *calname; |
1136 |
Int_t wused = 0; |
1137 |
// |
1138 |
// TTree *tree; |
1139 |
if ( EFILE == 1 ){ |
1140 |
hfile = new TFile(file2.str().c_str(),"UPDATE","Calorimeter CALIBRATION data"); |
1141 |
tree = (TTree*)hfile->Get("CaloADC"); |
1142 |
tree->SetBranchAddress("Event", &calo); |
1143 |
// |
1144 |
// Check if the input file has already been used |
1145 |
// |
1146 |
printf(" Check if file %s has already been used... \n",nome); |
1147 |
nevents = tree->GetEntries(); |
1148 |
used = 0; |
1149 |
for (Int_t i = 0; i<nevents; i++){ |
1150 |
tree->GetEntry(i); |
1151 |
compare= calo->fname; |
1152 |
if ( !strcmp(compare,nome) ) { |
1153 |
used = 1; |
1154 |
break; |
1155 |
}; |
1156 |
}; |
1157 |
if ( used ) { |
1158 |
printf(" The file %s has already been used!\n You cannot run twice this program with that file!\n\n",nome); |
1159 |
hfile->Close(); |
1160 |
goto jumpfile; |
1161 |
} else { |
1162 |
printf(" Good, the file has not been used yet. \n\n"); |
1163 |
nevents = tree->GetEntries() -1; |
1164 |
tree->GetEntry(nevents); |
1165 |
}; |
1166 |
} else { |
1167 |
// |
1168 |
// If the file doesn't exist create it |
1169 |
// |
1170 |
calo = new CalorimeterCalibration(); |
1171 |
hfile = new TFile(file2.str().c_str(),"NEW","Calorimeter CALIBRATION data"); |
1172 |
if ( !existfile(file2.str().c_str()) ){ |
1173 |
printf(" %s :no such file or directory \n",filename.Data()); |
1174 |
printf(" ERROR: Cannot create file \n"); |
1175 |
return; |
1176 |
}; |
1177 |
tree = new TTree("CaloADC","Calorimeter calibration data"); |
1178 |
tree->Branch("Event","CalorimeterCalibration",&calo); |
1179 |
}; |
1180 |
// |
1181 |
// |
1182 |
// |
1183 |
hf3 = 0; |
1184 |
if ( EFILE == 1 && e == 0 ){ |
1185 |
printf(" Reading the old MIP figures to be updated...\n "); |
1186 |
hfile3 = new TFile(file3.str().c_str()); |
1187 |
hf3 = 1; |
1188 |
// |
1189 |
stringstream fmippa; |
1190 |
fmippa.str(""); |
1191 |
for (Int_t l = 0; l < 2; l++){ |
1192 |
for (Int_t m = 0; m < 22; m++){ |
1193 |
for (Int_t n =0 ; n < 96; n++){ |
1194 |
fmippa.str(""); |
1195 |
fmippa << "fmip " << l; |
1196 |
fmippa << " " << m; |
1197 |
fmippa << " " << n; |
1198 |
TH1F *temp = (TH1F*)hfile3->Get(fmippa.str().c_str()); |
1199 |
pfmip[l][m][n] = (TH1F*)temp->Clone(); |
1200 |
}; |
1201 |
}; |
1202 |
}; |
1203 |
printf(" ...done!\n"); |
1204 |
}; |
1205 |
EFILE = 1; |
1206 |
// |
1207 |
// Check if the input calibration file contains any calibration data |
1208 |
// |
1209 |
done = 0; |
1210 |
printf(" Check for calorimeter calibration: \n"); |
1211 |
calcalib = filename; |
1212 |
findcalibs: calname = calcalib; |
1213 |
printf(" Calibration file: %s \n",calname); |
1214 |
for (Int_t s=0; s<4;s++){ |
1215 |
for (Int_t d = 0; d<50; d++){ |
1216 |
calib.ttime[s][d] = 0 ; |
1217 |
if ( d < 49 ) calib.time[s][d] = 0 ; |
1218 |
}; |
1219 |
}; |
1220 |
for (Int_t m = 0; m < 2 ; m++ ){ |
1221 |
for (Int_t k = 0; k < 22; k++ ){ |
1222 |
for (Int_t l = 0; l < 96; l++ ){ |
1223 |
calib.calped[m][k][l] = 0. ; |
1224 |
evento.dexy[m][k][l] = 0. ; |
1225 |
evento.dexyc[m][k][l] = 0. ; |
1226 |
edelta[m][k][l] = 0.; |
1227 |
estrip[m][k][l] = 0.; |
1228 |
estripnull[m][k][l] = 0.; |
1229 |
}; |
1230 |
}; |
1231 |
} |
1232 |
wused = 0; |
1233 |
CaloFindCalibs(calcalib, calcalib, wused, calib); |
1234 |
// |
1235 |
// print on the screen the results: |
1236 |
// |
1237 |
ffile = filename; |
1238 |
printf(" ------ %s ------- \n \n",ffile); |
1239 |
calibex = 0; |
1240 |
for (Int_t s=0; s<4;s++){ |
1241 |
printf(" ** SECTION %i **\n",s); |
1242 |
for (Int_t d = 0; d<51; d++){ |
1243 |
if ( calib.ttime[s][d] != 0 ) { |
1244 |
calibex++; |
1245 |
if ( calib.fcode[s][d] != 10 ){ |
1246 |
file2f = ""; |
1247 |
stringcopy(file2f,calcalib,0,0); |
1248 |
pfile = (TString)whatnamewith(file2f,calib.fcode[s][d]); |
1249 |
} else { |
1250 |
pfile = (TString)calcalib; |
1251 |
}; |
1252 |
ffile = pfile; |
1253 |
printf(" - from time %i to time %i use calibration at\n time %i, file: %s \n",calib.time[s][d],calib.time[s][d+1],calib.ttime[s][d],ffile); |
1254 |
}; |
1255 |
}; |
1256 |
printf("\n"); |
1257 |
}; |
1258 |
printf(" ----------------------------------------------------------------------- \n \n"); |
1259 |
// |
1260 |
if ( calibex < 1 ) { |
1261 |
printf("No calibration data in this file!\n"); |
1262 |
calcalib = calcalibfile; |
1263 |
if ( !done && calcalibfile != "" ) { |
1264 |
cali = calcalibfile; |
1265 |
printf(" Search in the calibration file %s \n",cali); |
1266 |
done = 1; |
1267 |
goto findcalibs; |
1268 |
} else { |
1269 |
printf(" Cannot find any calibration for this file! \n"); |
1270 |
goto jumpfile; |
1271 |
}; |
1272 |
}; |
1273 |
if ( calibex < 4 ) { |
1274 |
printf(" WARNING! No full calibration data in this file! \n\n"); |
1275 |
}; |
1276 |
// |
1277 |
// upgrade data... |
1278 |
// |
1279 |
if ( !existfile(filename) ){ |
1280 |
printf(" %s :no such file or directory \n",filename.Data()); |
1281 |
goto jumpfile; |
1282 |
}; |
1283 |
headerFile = new TFile(filename.Data()); |
1284 |
otr = (TTree*)headerFile->Get("Physics"); |
1285 |
otr->SetBranchAddress("Header", &eh); |
1286 |
otr->SetBranchAddress("Calorimeter", &de); |
1287 |
otr->SetBranchAddress("Trigger", &trigger); |
1288 |
// |
1289 |
// |
1290 |
nevents = otr->GetEntries(); |
1291 |
// |
1292 |
// calibrate before starting |
1293 |
// |
1294 |
for (Int_t s = 0; s < 4; s++){ |
1295 |
b[s]=0; |
1296 |
if ( calib.fcode[s][b[s]] != 10 ){ |
1297 |
stringcopy(file2f,calcalib,0,0); |
1298 |
pfile = (TString)whatnamewith(file2f,calib.fcode[s][b[s]]); |
1299 |
} else { |
1300 |
pfile = (TString)calcalib; |
1301 |
}; |
1302 |
porca = pfile; |
1303 |
if ( debug ) printf(" porca miseria %s \n",porca); |
1304 |
CaloPede(pfile,s,calib.ttime[s][b[s]],calib); |
1305 |
}; |
1306 |
// |
1307 |
// run over all the events |
1308 |
// |
1309 |
printf("\n Processed events: \n\n"); |
1310 |
// |
1311 |
for (Int_t i = 0; i < nevents; i++){ |
1312 |
evno = i; |
1313 |
if ( i%1000 == 0 && i > 0 ) printf(" %iK \n",i/1000); |
1314 |
// |
1315 |
// read from the header of the event the absolute time at which it was recorded |
1316 |
// |
1317 |
otr->GetEntry(i); |
1318 |
// |
1319 |
S4 = trigger->patterntrig[1] & (1<<0); |
1320 |
// |
1321 |
if ( !S4 || i == 0 ) { |
1322 |
ph = eh->GetPscuHeader(); |
1323 |
etime = ph->GetOrbitalTime(); |
1324 |
// |
1325 |
// for each event check that the calibration we are using are still within calibration limits, if not call the next calibration |
1326 |
// |
1327 |
if ( !calib.obtjump ) { |
1328 |
for (Int_t s = 0; s < 4; s++){ |
1329 |
if ( calib.ttime[s][b[s]] ){ |
1330 |
while ( etime > calib.time[s][b[s]+1] ){ |
1331 |
printf(" CALORIMETER: \n" ); |
1332 |
printf(" - Section %i, event at time %i while old calibration time limit at %i. Use new calibration at time %i -\n",s,etime,calib.time[s][b[s]+1],calib.ttime[s][b[s]+1]); |
1333 |
printf(" END CALORIMETER. \n\n" ); |
1334 |
b[s]++; |
1335 |
if ( calib.fcode[s][b[s]] != 10 ){ |
1336 |
stringcopy(file2f,calcalib,0,0); |
1337 |
pfile = (TString)whatnamewith(file2f,calib.fcode[s][b[s]]); |
1338 |
} else { |
1339 |
pfile = (TString)calcalib; |
1340 |
}; |
1341 |
porca = pfile; |
1342 |
if ( debug ) printf(" porca miseria %s \n",porca); |
1343 |
CaloPede(pfile,s,calib.ttime[s][b[s]],calib); |
1344 |
}; |
1345 |
}; |
1346 |
}; |
1347 |
}; |
1348 |
// |
1349 |
// do whatever you want with data |
1350 |
// |
1351 |
evento.iev = de->iev; |
1352 |
// |
1353 |
// run over views and planes |
1354 |
// |
1355 |
for (Int_t l = 0; l < 2; l++){ |
1356 |
for (Int_t m = 0; m < 22; m++){ |
1357 |
// |
1358 |
// determine the section number |
1359 |
// |
1360 |
if (l == 0 && m%2 == 0) se = 3; |
1361 |
if (l == 0 && m%2 != 0) se = 2; |
1362 |
if (l == 1 && m%2 == 0) se = 0; |
1363 |
if (l == 1 && m%2 != 0) se = 1; |
1364 |
// |
1365 |
// determine what kind of event we are going to analyze |
1366 |
// |
1367 |
isCOMP = 0; |
1368 |
isFULL = 0; |
1369 |
isRAW = 0; |
1370 |
if ( de->stwerr[se] & (1 << 16) ) isCOMP = 1; |
1371 |
if ( de->stwerr[se] & (1 << 17) ) isFULL = 1; |
1372 |
if ( de->stwerr[se] & (1 << 3) ) isRAW = 1; |
1373 |
// |
1374 |
// save the prevoius energy deposit and calibration in sbase, sdexy, sdexyc |
1375 |
// |
1376 |
pre = -1; |
1377 |
if ( isRAW ){ |
1378 |
for (Int_t nn = 0; nn < 96; nn++){ |
1379 |
if ( nn%16 == 0 ) pre++; |
1380 |
evento.base[l][m][pre] = calib.calbase[l][m][pre]; |
1381 |
sdexy[l][m][nn] = evento.dexy[l][m][nn]; |
1382 |
evento.dexy[l][m][nn] = de->dexy[l][m][nn] ; |
1383 |
sdexyc[l][m][nn] = evento.dexyc[l][m][nn]; |
1384 |
evento.dexyc[l][m][nn] = de->dexyc[l][m][nn] ; |
1385 |
}; |
1386 |
// |
1387 |
// run over strips |
1388 |
// |
1389 |
pre = -1; |
1390 |
for (Int_t n =0 ; n < 96; n++){ |
1391 |
if ( n%16 == 0 ) { |
1392 |
pre++; |
1393 |
rdone = 0; |
1394 |
done = 0; |
1395 |
}; |
1396 |
if ( calo->mask[l][m][n] == 0. && ( isRAW || ( de->dexyc[l][m][n] > 0. && de->dexyc[l][m][n] < 32000.)) ){ |
1397 |
// |
1398 |
// baseline check and calculation |
1399 |
// |
1400 |
if ( !rdone ){ |
1401 |
CaloFindBaseRawNC(calib,evento,l,m,pre); |
1402 |
rdone = 1; |
1403 |
}; |
1404 |
// |
1405 |
// no suitable new baseline, use old ones and compress data! |
1406 |
// |
1407 |
if ( !done && (evento.base[l][m][pre] > 30000. || evento.base[l][m][pre] == 0.) ){ |
1408 |
evento.base[l][m][pre] = calib.sbase[l][m][pre]; |
1409 |
upnn = n+16; |
1410 |
if ( upnn > 96 ) upnn = 96; |
1411 |
for ( Int_t nn = n; nn<upnn; nn++ ){ |
1412 |
evento.dexyc[l][m][nn] = de->dexyc[l][m][nn] ; |
1413 |
}; |
1414 |
done = 1; |
1415 |
}; |
1416 |
// |
1417 |
// CALIBRATION ALGORITHM |
1418 |
// |
1419 |
pl1 = -1; |
1420 |
pl2 = -1; |
1421 |
pl1 = m - 1; |
1422 |
pl2 = m + 1; |
1423 |
if ( pl1 < 0 ) { |
1424 |
pl1 = pl2; |
1425 |
pl2 = m + 2; |
1426 |
}; |
1427 |
if ( pl2 > 21 ) { |
1428 |
pl2 = pl1; |
1429 |
pl1 = m - 2; |
1430 |
}; |
1431 |
strmin = n - 2; |
1432 |
if ( strmin < 0 ) strmin = 0; |
1433 |
strmax = n + 2; |
1434 |
if ( strmax > 95 ) strmax = 95; |
1435 |
surstrip = 0; |
1436 |
for (Int_t spl = pl1; spl<pl2+1; spl++){ |
1437 |
if ( spl != m ){ |
1438 |
for (Int_t sst = strmin; sst<strmax+1; sst++){ |
1439 |
if ( sst < 16 ) spre = 0; |
1440 |
if ( 15 < sst && sst < 32 ) spre = 2; |
1441 |
if ( 31 < sst && sst < 48 ) spre = 3; |
1442 |
if ( 47 < sst && sst < 64 ) spre = 4; |
1443 |
if ( 63 < sst && sst < 80 ) spre = 5; |
1444 |
if ( 79 < sst ) spre = 6; |
1445 |
if ( isRAW ){ |
1446 |
estrippa = ( evento.dexy[l][spl][sst] - calib.calped[l][spl][sst] - calib.sbase[l][spl][spre])/26. ; |
1447 |
} else { |
1448 |
estrippa = ( evento.dexyc[l][spl][sst] - calib.calped[l][spl][sst] - calib.sbase[l][spl][spre])/26. ; |
1449 |
}; |
1450 |
if ( estrippa > 0.7 && estrippa < 10. && calib.calgood[l][spl][sst] == 0 ){ |
1451 |
surstrip++; |
1452 |
//printf("surstrip = %i estrip = %f \n",surstrip,estrip); |
1453 |
}; |
1454 |
}; |
1455 |
}; |
1456 |
}; |
1457 |
// |
1458 |
// |
1459 |
estrip[l][m][n] = ( evento.dexyc[l][m][n] - calib.calped[l][m][n] - evento.base[l][m][pre]) ; |
1460 |
pfmip[l][m][n]->Fill(estrip[l][m][n]); |
1461 |
calib.sbase[l][m][pre] = evento.base[l][m][pre]; |
1462 |
}; |
1463 |
}; |
1464 |
}; |
1465 |
}; |
1466 |
}; |
1467 |
}; |
1468 |
}; |
1469 |
// |
1470 |
// save filename |
1471 |
// |
1472 |
calo->fname = sfile; |
1473 |
tree->Fill(); |
1474 |
hfile->Write(); |
1475 |
fileup++; |
1476 |
hfile->Close(); |
1477 |
// |
1478 |
// create a backup copy! |
1479 |
// |
1480 |
if ( nfile > 1 && ( e%10 == 0 || e == nfile-1 ) && e > 0 ){ |
1481 |
files.str(""); |
1482 |
files << file4.str().c_str() << (e+1); |
1483 |
files << ".bak"; |
1484 |
printf(" Save the backup file with figures:\n %s \n ",files.str().c_str()); |
1485 |
hfileb = new TFile(files.str().c_str(),"RECREATE","Calorimeter CALIBRATION figures"); |
1486 |
if ( !existfile(files.str().c_str()) ){ |
1487 |
printf(" ERROR: Cannot create file!!! \n"); |
1488 |
goto oltre; |
1489 |
}; |
1490 |
TH1F *bfmip[2][22][96]; |
1491 |
stringstream bmippa; |
1492 |
for (Int_t l = 0; l < 2; l++){ |
1493 |
for (Int_t m = 0; m < 22; m++){ |
1494 |
for (Int_t n =0 ; n < 96; n++){ |
1495 |
bmippa.str(""); |
1496 |
bmippa << "bmip " << l; |
1497 |
bmippa << " " << m; |
1498 |
bmippa << " " << n; |
1499 |
bfmip[l][m][n] = new TH1F(bmippa.str().c_str(),"",70,-15.,55.); |
1500 |
bfmip[l][m][n] = (TH1F*)pfmip[l][m][n]->Clone(bmippa.str().c_str()); |
1501 |
bfmip[l][m][n]->Write(); |
1502 |
}; |
1503 |
}; |
1504 |
}; |
1505 |
hfileb->Close(); |
1506 |
}; |
1507 |
// |
1508 |
// |
1509 |
// |
1510 |
headerFile->Close(); |
1511 |
goto oltre; |
1512 |
jumpfile: printf(" File not processed! \n "); |
1513 |
hfile->Close(); |
1514 |
oltre: |
1515 |
// gObjectTable->Print(); |
1516 |
e++; |
1517 |
}; |
1518 |
// |
1519 |
// Save histograms and fit figures |
1520 |
// |
1521 |
TFile *hfile2; |
1522 |
hfile2 = new TFile(file3.str().c_str(),"RECREATE","Calorimeter CALIBRATION figures"); |
1523 |
if ( !existfile(file3.str().c_str()) ){ |
1524 |
printf(" ERROR: Cannot create file!!! \n"); |
1525 |
return; |
1526 |
}; |
1527 |
TH1F *sfmip[2][22][96]; |
1528 |
stringstream fmippa; |
1529 |
for (Int_t l = 0; l < 2; l++){ |
1530 |
for (Int_t m = 0; m < 22; m++){ |
1531 |
for (Int_t n =0 ; n < 96; n++){ |
1532 |
fmippa.str(""); |
1533 |
fmippa << "fmip " << l; |
1534 |
fmippa << " " << m; |
1535 |
fmippa << " " << n; |
1536 |
sfmip[l][m][n] = new TH1F(fmippa.str().c_str(),"",72,-15.,55.); |
1537 |
sfmip[l][m][n] = (TH1F*)pfmip[l][m][n]->Clone(fmippa.str().c_str()); |
1538 |
sfmip[l][m][n]->Write(); |
1539 |
}; |
1540 |
}; |
1541 |
}; |
1542 |
hfile2->Close(); |
1543 |
if ( hf3 ) hfile3->Close(); |
1544 |
} |
1545 |
|
1546 |
void FCaloRAWADC2MIPDATA(TString Filename, TString calcalibfile = "", TString OutDir="", TString flist=""){ |
1547 |
const char *pam_calib = pathtocalibration(); |
1548 |
if ( !strcmp(OutDir.Data(),"") ){ |
1549 |
OutDir = pam_calib; |
1550 |
}; |
1551 |
TString calcalib; |
1552 |
struct Evento evento; |
1553 |
struct Calib calib; |
1554 |
Int_t debug = 0; |
1555 |
Int_t b[4]; |
1556 |
Int_t etime,evno; |
1557 |
Float_t sdexy[2][22][96],sdexyc[2][22][96]; |
1558 |
Float_t edelta[2][22][96]; |
1559 |
Float_t estrip[2][22][96]; |
1560 |
Float_t estripnull[2][22][96]; |
1561 |
Float_t delta; |
1562 |
delta = 1.; |
1563 |
evento.emin = 0.7; |
1564 |
Int_t se =5; |
1565 |
Int_t pre; |
1566 |
Int_t rdone = 0; |
1567 |
Int_t done; |
1568 |
bool isCOMP = 0; |
1569 |
bool isFULL = 0; |
1570 |
bool isRAW = 0; |
1571 |
// |
1572 |
// the file which contains the calorimeter ADC to MIP conversion values is file2 = path to the script dir / CaloADC2MIP.root |
1573 |
// |
1574 |
stringstream file5; |
1575 |
file5.str(""); |
1576 |
file5 << OutDir.Data() << "/CaloADC2MIPdata.raw"; |
1577 |
// |
1578 |
Int_t nfile = 0; |
1579 |
Int_t fileup = 0; |
1580 |
if ( flist != "" ){ |
1581 |
printf("\n You have given an input file list \n\n Files: \n"); |
1582 |
ifstream in; |
1583 |
in.open(flist, ios::in); |
1584 |
char ctime[20]; |
1585 |
while (1) { |
1586 |
in >> ctime; |
1587 |
if (!in.good()) break; |
1588 |
printf(" File number %i = %s \n",nfile+1,ctime); |
1589 |
nfile++; |
1590 |
}; |
1591 |
in.close(); |
1592 |
if ( !nfile ) { |
1593 |
printf("\n\n The list is empty, exiting... \n\n"); |
1594 |
return; |
1595 |
}; |
1596 |
} else { |
1597 |
nfile = 1; |
1598 |
}; |
1599 |
printf("\n"); |
1600 |
// |
1601 |
// First check if the calibration file exists: |
1602 |
// |
1603 |
// |
1604 |
const char *filename2 = Filename; |
1605 |
// |
1606 |
TString lfile; |
1607 |
TString sfile; |
1608 |
// |
1609 |
Int_t e = 0; |
1610 |
ifstream in; |
1611 |
in.open(flist, ios::in); |
1612 |
char ctime[20]; |
1613 |
TString file2f; |
1614 |
TString pfile; |
1615 |
const char *cali; |
1616 |
const char *ffile; |
1617 |
Int_t calibex = 0; |
1618 |
// |
1619 |
TString filename; |
1620 |
const char *nome = 0; |
1621 |
Long64_t nevents; |
1622 |
TFile *headerFile = 0; |
1623 |
file2f = ""; |
1624 |
pfile = ""; |
1625 |
const char *porca = 0; |
1626 |
Int_t upnn; |
1627 |
// |
1628 |
// |
1629 |
TFile *hfl1 = 0; |
1630 |
hfl1 = new TFile(file5.str().c_str(),"RECREATE","Calorimeter LEVEL1 data"); |
1631 |
// |
1632 |
// class CalorimeterLevel1 |
1633 |
// |
1634 |
CalorimeterADCRAW *clev1 = new CalorimeterADCRAW(); |
1635 |
TTree *trl1 = 0; |
1636 |
trl1 = new TTree("CaloADCRAW","PAMELA Level1 calorimeter data"); |
1637 |
trl1->Branch("Rawdata","CalorimeterADCRAW",&clev1); |
1638 |
// |
1639 |
Int_t glbc = 0; |
1640 |
// |
1641 |
TString fififile; |
1642 |
const char *file; |
1643 |
// |
1644 |
stringstream lfillo; |
1645 |
while ( e < nfile ){ |
1646 |
if ( flist != "" ){ |
1647 |
in >> ctime; |
1648 |
lfillo.str(""); |
1649 |
lfillo << filename2 << "/"; |
1650 |
lfillo << ctime; |
1651 |
lfile = TString(lfillo.str().c_str()); |
1652 |
fififile = getFilename(lfile); |
1653 |
file = fififile; |
1654 |
lfillo.str(""); |
1655 |
lfillo << file; |
1656 |
sfile = TString(lfillo.str().c_str()); |
1657 |
} else { |
1658 |
lfillo.str(""); |
1659 |
lfillo << filename2; |
1660 |
lfile = TString(lfillo.str().c_str()); |
1661 |
fififile = getFilename(lfile); |
1662 |
file = fififile; |
1663 |
lfillo.str(""); |
1664 |
lfillo << file; |
1665 |
sfile = TString(lfillo.str().c_str()); |
1666 |
}; |
1667 |
// |
1668 |
filename = lfile; |
1669 |
nome = filename; |
1670 |
printf("\n Processing file number %i: %s \n\n",e,nome); |
1671 |
nome = sfile; |
1672 |
// |
1673 |
// Check if the input calibration file contains any calibration data |
1674 |
// |
1675 |
TTree *otr; |
1676 |
pamela::calorimeter::CalorimeterEvent *de = 0; |
1677 |
pamela::PscuHeader *ph = 0; |
1678 |
pamela::EventHeader *eh = 0; |
1679 |
// |
1680 |
done = 0; |
1681 |
printf(" Check for calorimeter calibration: \n"); |
1682 |
calcalib = filename; |
1683 |
findcalibs: const char *calname = calcalib; |
1684 |
printf(" Calibration file: %s \n",calname); |
1685 |
for (Int_t s=0; s<4;s++){ |
1686 |
for (Int_t d = 0; d<50; d++){ |
1687 |
calib.ttime[s][d] = 0 ; |
1688 |
if ( d < 49 ) calib.time[s][d] = 0 ; |
1689 |
}; |
1690 |
}; |
1691 |
for (Int_t m = 0; m < 2 ; m++ ){ |
1692 |
for (Int_t k = 0; k < 22; k++ ){ |
1693 |
for (Int_t l = 0; l < 96; l++ ){ |
1694 |
calib.calped[m][k][l] = 0. ; |
1695 |
evento.dexy[m][k][l] = 0. ; |
1696 |
evento.dexyc[m][k][l] = 0. ; |
1697 |
edelta[m][k][l] = 0.; |
1698 |
estrip[m][k][l] = 0.; |
1699 |
estripnull[m][k][l] = 0.; |
1700 |
}; |
1701 |
}; |
1702 |
} |
1703 |
Int_t wused = 0; |
1704 |
CaloFindCalibs(filename, calcalibfile, wused, calib); |
1705 |
if ( wused == 1 ) calcalibfile = filename; |
1706 |
// |
1707 |
// print on the screen the results: |
1708 |
// |
1709 |
ffile = filename; |
1710 |
printf(" ------ %s ------- \n \n",ffile); |
1711 |
calibex = 0; |
1712 |
for (Int_t s=0; s<4;s++){ |
1713 |
printf(" ** SECTION %i **\n",s); |
1714 |
for (Int_t d = 0; d<51; d++){ |
1715 |
if ( calib.ttime[s][d] != 0 ) { |
1716 |
calibex++; |
1717 |
if ( calib.fcode[s][d] != 10 ){ |
1718 |
file2f = ""; |
1719 |
stringcopy(file2f,calcalib,0,0); |
1720 |
pfile = (TString)whatnamewith(file2f,calib.fcode[s][d]); |
1721 |
} else { |
1722 |
pfile = (TString)calcalib; |
1723 |
}; |
1724 |
ffile = pfile; |
1725 |
printf(" - from time %i to time %i use calibration at\n time %i, file: %s \n",calib.time[s][d],calib.time[s][d+1],calib.ttime[s][d],ffile); |
1726 |
}; |
1727 |
}; |
1728 |
printf("\n"); |
1729 |
}; |
1730 |
printf(" ----------------------------------------------------------------------- \n \n"); |
1731 |
// |
1732 |
if ( calibex < 1 ) { |
1733 |
printf("No calibration data in this file!\n"); |
1734 |
calcalib = calcalibfile; |
1735 |
if ( !done && calcalibfile != "" ) { |
1736 |
cali = calcalibfile; |
1737 |
printf(" Search in the calibration file %s \n",cali); |
1738 |
done = 1; |
1739 |
goto findcalibs; |
1740 |
} else { |
1741 |
printf(" Cannot find any calibration for this file! \n"); |
1742 |
goto jumpfile; |
1743 |
}; |
1744 |
}; |
1745 |
if ( calibex < 4 ) { |
1746 |
printf(" WARNING! No full calibration data in this file! \n\n"); |
1747 |
}; |
1748 |
// |
1749 |
// upgrade data... |
1750 |
// |
1751 |
if ( !existfile(filename) ){ |
1752 |
printf(" %s :no such file or directory \n",filename.Data()); |
1753 |
goto jumpfile; |
1754 |
}; |
1755 |
headerFile = new TFile(filename.Data()); |
1756 |
otr = (TTree*)headerFile->Get("Physics"); |
1757 |
otr->SetBranchAddress("Header", &eh); |
1758 |
otr->SetBranchAddress("Calorimeter", &de); |
1759 |
// |
1760 |
nevents = otr->GetEntries(); |
1761 |
// |
1762 |
// calibrate before starting |
1763 |
// |
1764 |
for (Int_t s = 0; s < 4; s++){ |
1765 |
b[s]=0; |
1766 |
if ( calib.fcode[s][b[s]] != 10 ){ |
1767 |
stringcopy(file2f,calcalib,0,0); |
1768 |
pfile = (TString)whatnamewith(file2f,calib.fcode[s][b[s]]); |
1769 |
} else { |
1770 |
pfile = (TString)calcalib; |
1771 |
}; |
1772 |
porca = pfile; |
1773 |
if ( debug ) printf(" porca miseria %s \n",porca); |
1774 |
CaloPede(pfile,s,calib.ttime[s][b[s]],calib); |
1775 |
}; |
1776 |
// |
1777 |
// run over all the events |
1778 |
// |
1779 |
printf("\n Processed events: \n\n"); |
1780 |
// |
1781 |
Int_t updata; |
1782 |
for (Int_t i = 0; i < nevents; i++){ |
1783 |
evno = i; |
1784 |
if ( i%1000 == 0 && i > 0 ) printf(" %iK \n",i/1000); |
1785 |
// |
1786 |
// read from the header of the event the absolute time at which it was recorded |
1787 |
// |
1788 |
otr->GetEntry(i); |
1789 |
// |
1790 |
// |
1791 |
ph = eh->GetPscuHeader(); |
1792 |
etime = ph->GetOrbitalTime(); |
1793 |
// |
1794 |
// for each event check that the calibration we are using are still within calibration limits, if not call the next calibration |
1795 |
// |
1796 |
if ( !calib.obtjump ) { |
1797 |
for (Int_t s = 0; s < 4; s++){ |
1798 |
if ( calib.ttime[s][b[s]] ){ |
1799 |
while ( etime > calib.time[s][b[s]+1] ){ |
1800 |
printf(" CALORIMETER: \n" ); |
1801 |
printf(" - Section %i, event at time %i while old calibration time limit at %i. Use new calibration at time %i -\n",s,etime,calib.time[s][b[s]+1],calib.ttime[s][b[s]+1]); |
1802 |
printf(" END CALORIMETER. \n\n" ); |
1803 |
b[s]++; |
1804 |
if ( calib.fcode[s][b[s]] != 10 ){ |
1805 |
stringcopy(file2f,calcalib,0,0); |
1806 |
pfile = (TString)whatnamewith(file2f,calib.fcode[s][b[s]]); |
1807 |
} else { |
1808 |
pfile = (TString)calcalib; |
1809 |
}; |
1810 |
porca = pfile; |
1811 |
if ( debug ) printf(" porca miseria %s \n",porca); |
1812 |
CaloPede(pfile,s,calib.ttime[s][b[s]],calib); |
1813 |
}; |
1814 |
}; |
1815 |
}; |
1816 |
}; |
1817 |
// |
1818 |
// do whatever you want with data |
1819 |
// |
1820 |
evento.iev = de->iev; |
1821 |
// |
1822 |
// run over views and planes |
1823 |
// |
1824 |
updata = 0; |
1825 |
glbc++; |
1826 |
for (Int_t l = 0; l < 2; l++){ |
1827 |
for (Int_t m = 0; m < 22; m++){ |
1828 |
// |
1829 |
// determine the section number |
1830 |
// |
1831 |
if (l == 0 && m%2 == 0) se = 3; |
1832 |
if (l == 0 && m%2 != 0) se = 2; |
1833 |
if (l == 1 && m%2 == 0) se = 0; |
1834 |
if (l == 1 && m%2 != 0) se = 1; |
1835 |
// |
1836 |
// determine what kind of event we are going to analyze |
1837 |
// |
1838 |
isCOMP = 0; |
1839 |
isFULL = 0; |
1840 |
isRAW = 0; |
1841 |
if ( de->stwerr[se] & (1 << 16) ) isCOMP = 1; |
1842 |
if ( de->stwerr[se] & (1 << 17) ) isFULL = 1; |
1843 |
if ( de->stwerr[se] & (1 << 3) ) isRAW = 1; |
1844 |
// |
1845 |
// save the prevoius energy deposit and calibration in sbase, sdexy, sdexyc |
1846 |
// |
1847 |
pre = -1; |
1848 |
if ( isRAW || isFULL ){ |
1849 |
updata = 1; |
1850 |
for (Int_t nn = 0; nn < 96; nn++){ |
1851 |
if ( nn%16 == 0 ) pre++; |
1852 |
evento.base[l][m][pre] = calib.calbase[l][m][pre]; |
1853 |
sdexy[l][m][nn] = evento.dexy[l][m][nn]; |
1854 |
evento.dexy[l][m][nn] = de->dexy[l][m][nn] ; |
1855 |
sdexyc[l][m][nn] = evento.dexyc[l][m][nn]; |
1856 |
// !!! |
1857 |
evento.dexyc[l][m][nn] = de->dexy[l][m][nn] ; |
1858 |
// !!! |
1859 |
}; |
1860 |
// |
1861 |
// run over strips |
1862 |
// |
1863 |
pre = -1; |
1864 |
for (Int_t n =0 ; n < 96; n++){ |
1865 |
if ( n%16 == 0 ) { |
1866 |
pre++; |
1867 |
rdone = 0; |
1868 |
done = 0; |
1869 |
}; |
1870 |
if ( isRAW || ( de->dexyc[l][m][n] > 0. && de->dexyc[l][m][n] < 32000.) || isFULL ){ |
1871 |
if ( isFULL && !rdone ) rdone = 1; |
1872 |
// |
1873 |
// baseline check and calculation |
1874 |
// |
1875 |
if ( !rdone ){ |
1876 |
CaloFindBaseRawNC(calib,evento,l,m,pre); |
1877 |
rdone = 1; |
1878 |
}; |
1879 |
// |
1880 |
// no suitable new baseline, use old ones and compress data! |
1881 |
// |
1882 |
if ( !done && (evento.base[l][m][pre] > 30000. || evento.base[l][m][pre] == 0.) ){ |
1883 |
evento.base[l][m][pre] = calib.sbase[l][m][pre]; |
1884 |
upnn = n+16; |
1885 |
if ( upnn > 96 ) upnn = 96; |
1886 |
for ( Int_t nn = n; nn<upnn; nn++ ){ |
1887 |
evento.dexyc[l][m][nn] = de->dexy[l][m][nn] ; |
1888 |
}; |
1889 |
done = 1; |
1890 |
}; |
1891 |
// |
1892 |
// CALIBRATION ALGORITHM |
1893 |
// |
1894 |
estrip[l][m][n] = ( evento.dexyc[l][m][n] - calib.calped[l][m][n] - evento.base[l][m][pre]) ; |
1895 |
calib.sbase[l][m][pre] = evento.base[l][m][pre]; |
1896 |
clev1->diffbas[l][m][pre] = evento.base[l][m][pre]; |
1897 |
clev1->estrip[l][m][n] = estrip[l][m][n]; |
1898 |
}; |
1899 |
}; |
1900 |
}; |
1901 |
}; |
1902 |
}; |
1903 |
// if ( updata ){ |
1904 |
clev1->evno = glbc; |
1905 |
clev1->etime = etime; |
1906 |
trl1->Fill(); |
1907 |
for (Int_t l =0 ; l < 2; l++){ |
1908 |
for (Int_t m =0 ; m < 22; m++){ |
1909 |
pre = -1; |
1910 |
for (Int_t n =0 ; n < 96; n++){ |
1911 |
// memcpy(estrip, estripnull, sizeof(estrip)); |
1912 |
if ( n%16 == 0 ) pre++; |
1913 |
estrip[l][m][n] = 0.; |
1914 |
evento.base[l][m][pre] = 0.; |
1915 |
clev1->diffbas[l][m][pre] = evento.base[l][m][pre]; |
1916 |
clev1->estrip[l][m][n] = estrip[l][m][n]; |
1917 |
}; |
1918 |
}; |
1919 |
}; |
1920 |
//gObjectTable->Print(); |
1921 |
//}; |
1922 |
}; |
1923 |
// |
1924 |
// save filename |
1925 |
// |
1926 |
fileup++; |
1927 |
// |
1928 |
headerFile->Close(); |
1929 |
goto oltre; |
1930 |
jumpfile: printf(" File not processed! \n "); |
1931 |
oltre: |
1932 |
e++; |
1933 |
}; |
1934 |
hfl1->Write(); |
1935 |
hfl1->Close(); |
1936 |
} |
1937 |
|
1938 |
void FCalo4224STATUS(TString filename = "", TString style = ""){ |
1939 |
const char *pam_calib = pathtocalibration(); |
1940 |
// |
1941 |
// this routine shows the calorimeter calibration status with a figure. You can choose style between "error" (or "") to show the error on the |
1942 |
// peak maximum determined and "status" to show which strips have converged to a certain value. |
1943 |
// |
1944 |
if ( filename == "" ){ |
1945 |
stringstream filenome; |
1946 |
filenome.str(""); |
1947 |
filenome << pam_calib << "/CaloADC2MIP.root"; |
1948 |
filename = (TString)filenome.str().c_str(); |
1949 |
}; |
1950 |
if ( style == "" ) style = "error"; |
1951 |
const char *file2 = filename; |
1952 |
TFile *hfile; |
1953 |
hfile = new TFile(file2,"READ","Calorimeter CALIBRATION data"); |
1954 |
CalorimeterCalibration *calo = 0; |
1955 |
TTree *tree; |
1956 |
tree = (TTree*)hfile->Get("CaloADC"); |
1957 |
tree->SetBranchAddress("Event", &calo); |
1958 |
// |
1959 |
Long64_t nevents = tree->GetEntries(); |
1960 |
tree->GetEntry(nevents-1); |
1961 |
// |
1962 |
// Book the histograms: |
1963 |
// |
1964 |
// |
1965 |
TH2F *Xview = new TH2F("x-view event ","",96,-0.5,95.5,22,-0.5,21.5); |
1966 |
TH2F *Yview = new TH2F("y-view event ","",96,-0.5,95.5,22,-0.5,21.5); |
1967 |
// |
1968 |
// figures: |
1969 |
// |
1970 |
TCanvas *figura2 = new TCanvas("Calorimeter:_strip_RMS", "Calorimeter:_strip_RMS", 750, 650); |
1971 |
figura2->SetFillColor(10); |
1972 |
figura2->Range(0,0,100,100); |
1973 |
Int_t bgcolor = 10; |
1974 |
TPad *pd1 = new TPad("pd1","This is pad1",0.02,0.05,0.88,0.49,bgcolor); |
1975 |
TPad *pd2 = new TPad("pd2","This is pad2",0.02,0.51,0.88,0.95,bgcolor); |
1976 |
TPad *palette = new TPad("palette","This is palette",0.90,0.05,0.98,0.90,bgcolor); |
1977 |
figura2->cd(); |
1978 |
TLatex *t=new TLatex(); |
1979 |
t->SetTextFont(32); |
1980 |
t->SetTextColor(1); |
1981 |
t->SetTextSize(0.03); |
1982 |
t->SetTextAlign(12); |
1983 |
t->DrawLatex(90.,92.5,"error"); |
1984 |
pd1->Range(0,0,100,100); |
1985 |
pd2->Range(0,0,100,100); |
1986 |
palette->Range(0,0,101,100); |
1987 |
pd1->SetTicks(); |
1988 |
pd2->SetTicks(); |
1989 |
pd1->Draw(); |
1990 |
pd2->Draw(); |
1991 |
palette->Draw(); |
1992 |
palette->cd(); |
1993 |
const char *style2 = style; |
1994 |
if ( !strcmp(style2,"error") ){ |
1995 |
// palette |
1996 |
TPaveLabel *box1 = new TPaveLabel(1,2,99,14,"no fit",""); |
1997 |
box1->SetTextFont(32); |
1998 |
box1->SetTextColor(1); |
1999 |
box1->SetTextSize(0.25); |
2000 |
box1->SetFillColor(10); |
2001 |
box1->Draw(); |
2002 |
TPaveLabel *box2 = new TPaveLabel(1,16,99,28,"< 0.15",""); |
2003 |
box2->SetTextFont(32); |
2004 |
box2->SetTextColor(1); |
2005 |
box2->SetTextSize(0.25); |
2006 |
box2->SetFillColor(38); |
2007 |
box2->Draw(); |
2008 |
TPaveLabel *box3 = new TPaveLabel(1,30,99,42,"0.15 - 0.25",""); |
2009 |
box3->SetTextFont(32); |
2010 |
box3->SetTextColor(1); |
2011 |
box3->SetTextSize(0.2); |
2012 |
box3->SetFillColor(4); |
2013 |
box3->Draw(); |
2014 |
TPaveLabel *box4 = new TPaveLabel(1,44,99,56,"0.25 - 0.55",""); |
2015 |
box4->SetTextFont(32); |
2016 |
box4->SetTextColor(1); |
2017 |
box4->SetTextSize(0.2); |
2018 |
box4->SetFillColor(3); |
2019 |
box4->Draw(); |
2020 |
TPaveLabel *box5 = new TPaveLabel(1,58,99,70,"0.55 - 1",""); |
2021 |
box5->SetTextFont(32); |
2022 |
box5->SetTextColor(1); |
2023 |
box5->SetTextSize(0.25); |
2024 |
box5->SetFillColor(2); |
2025 |
box5->Draw(); |
2026 |
TPaveLabel *box6 = new TPaveLabel(1,72,99,84,"1 - 5",""); |
2027 |
box6->SetTextFont(32); |
2028 |
box6->SetTextColor(1); |
2029 |
box6->SetTextSize(0.25); |
2030 |
box6->SetFillColor(6); |
2031 |
box6->Draw(); |
2032 |
TPaveLabel *box7 = new TPaveLabel(1,86,99,98,"> 5",""); |
2033 |
box7->SetTextFont(32); |
2034 |
box7->SetTextColor(10); |
2035 |
box7->SetTextSize(0.25); |
2036 |
box7->SetFillColor(1); |
2037 |
box7->Draw(); |
2038 |
} else { |
2039 |
TPaveLabel *box1 = new TPaveLabel(1,2,99,14,"not done",""); |
2040 |
box1->SetTextFont(32); |
2041 |
box1->SetTextColor(1); |
2042 |
box1->SetTextSize(0.25); |
2043 |
box1->SetFillColor(10); |
2044 |
box1->Draw(); |
2045 |
TPaveLabel *box2 = new TPaveLabel(1,16,99,28,"done",""); |
2046 |
box2->SetTextFont(32); |
2047 |
box2->SetTextColor(1); |
2048 |
box2->SetTextSize(0.25); |
2049 |
box2->SetFillColor(38); |
2050 |
box2->Draw(); |
2051 |
}; |
2052 |
// |
2053 |
pd1->cd(); |
2054 |
gStyle->SetOptStat(0); |
2055 |
Xview->SetXTitle("strip"); |
2056 |
Xview->SetYTitle("X - plane"); |
2057 |
Xview->GetYaxis()->SetTitleOffset(0.5); |
2058 |
Xview->SetFillColor(bgcolor); |
2059 |
Xview->Fill(1.,1.,1.); |
2060 |
Xview->Draw("box"); |
2061 |
pd1->Update(); |
2062 |
pd2->cd(); |
2063 |
gStyle->SetOptStat(0); |
2064 |
Yview->SetXTitle("strip"); |
2065 |
Yview->SetYTitle("Y - plane"); |
2066 |
Yview->GetYaxis()->SetTitleOffset(0.5); |
2067 |
Yview->SetFillColor(bgcolor); |
2068 |
Yview->Fill(1.,1.,1.); |
2069 |
Yview->Draw("box"); |
2070 |
pd2->Update(); |
2071 |
// |
2072 |
// run over views and planes |
2073 |
// |
2074 |
stringstream xview; |
2075 |
stringstream yview; |
2076 |
for (Int_t m = 0; m < 22; m++){ |
2077 |
for (Int_t l = 0; l < 2; l++){ |
2078 |
for (Int_t n = 0; n < 96; n++){ |
2079 |
xview.str(""); |
2080 |
xview << "x-view event " << n; |
2081 |
xview << " " << m; |
2082 |
xview << " " << l; |
2083 |
yview.str(""); |
2084 |
yview << "y-view event " << n; |
2085 |
yview << " " << m; |
2086 |
yview << " " << l; |
2087 |
gDirectory->Delete(xview.str().c_str()); |
2088 |
gDirectory->Delete(yview.str().c_str()); |
2089 |
TH2F *Xview = new TH2F(xview.str().c_str(),"",96,-0.5,95.5,22,-0.5,21.5); |
2090 |
TH2F *Yview = new TH2F(yview.str().c_str(),"",96,-0.5,95.5,22,-0.5,21.5); |
2091 |
if ( !strcmp(style2,"error") ){ |
2092 |
if ( calo->fpe[1][l][m][n] < 0.15 ){ |
2093 |
Xview->SetFillColor(38); |
2094 |
Yview->SetFillColor(38); |
2095 |
}; |
2096 |
if ( calo->fpe[1][l][m][n] >= 0.15 ){ |
2097 |
Xview->SetFillColor(4); |
2098 |
Yview->SetFillColor(4); |
2099 |
}; |
2100 |
if ( calo->fpe[1][l][m][n] >= 0.25){ |
2101 |
Xview->SetFillColor(3); |
2102 |
Yview->SetFillColor(3); |
2103 |
}; |
2104 |
if ( calo->fpe[1][l][m][n] >= 0.55 ){ |
2105 |
Xview->SetFillColor(2); |
2106 |
Yview->SetFillColor(2); |
2107 |
}; |
2108 |
if ( calo->fpe[1][l][m][n] >= 1. ){ |
2109 |
Xview->SetFillColor(6); |
2110 |
Yview->SetFillColor(6); |
2111 |
}; |
2112 |
if ( calo->fpe[1][l][m][n] >= 5. ){ |
2113 |
Xview->SetFillColor(1); |
2114 |
Yview->SetFillColor(1); |
2115 |
}; |
2116 |
if ( calo->mip[l][m][n] < 15. || calo->mip[l][m][n] > 40. ){ |
2117 |
Xview->SetFillColor(10); |
2118 |
Yview->SetFillColor(10); |
2119 |
}; |
2120 |
} else { |
2121 |
if ( calo->mask[l][m][n] == 1 ){ |
2122 |
Xview->SetFillColor(38); |
2123 |
Yview->SetFillColor(38); |
2124 |
} else { |
2125 |
Xview->SetFillColor(10); |
2126 |
Yview->SetFillColor(10); |
2127 |
}; |
2128 |
}; |
2129 |
if ( l == 0 ) { |
2130 |
Xview->Fill(n,m,1.); |
2131 |
pd1->cd(); |
2132 |
Xview->Draw("box same"); |
2133 |
}; |
2134 |
if ( l == 1 ) { |
2135 |
Yview->Fill(n,m,1.); |
2136 |
pd2->cd(); |
2137 |
Yview->Draw("box same"); |
2138 |
}; |
2139 |
}; |
2140 |
}; |
2141 |
}; |
2142 |
figura2->cd(); |
2143 |
gStyle->SetOptDate(1); |
2144 |
// |
2145 |
t=new TLatex(); |
2146 |
t->SetTextFont(32); |
2147 |
t->SetTextColor(8); |
2148 |
t->SetTextAlign(12); |
2149 |
t->SetTextSize(0.02); |
2150 |
figura2->Update(); |
2151 |
pd1->Update(); |
2152 |
pd2->Update(); |
2153 |
// |
2154 |
} |
2155 |
|
2156 |
void FCalo4224FIT(TString filename = "", TString OutDir="", TString filevalue = "", TString type=""){ |
2157 |
const char *pam_calib = pathtocalibration(); |
2158 |
if ( !strcmp(OutDir.Data(),"") ){ |
2159 |
OutDir=pam_calib; |
2160 |
}; |
2161 |
// |
2162 |
// this routine shows the 4224 figures with fit from the main program |
2163 |
// |
2164 |
const char* startingdir = gSystem->WorkingDirectory(); |
2165 |
stringstream filenome; |
2166 |
filenome.str(""); |
2167 |
if ( filename == "" ){ |
2168 |
filenome << OutDir.Data() << "/CaloADC2MIPf.root"; |
2169 |
filename = (TString)filenome.str().c_str(); |
2170 |
filenome.str(""); |
2171 |
}; |
2172 |
if ( filevalue == "" ){ |
2173 |
filenome.str(""); |
2174 |
filenome << OutDir.Data() << "/CaloADC2MIP.root"; |
2175 |
} else { |
2176 |
filenome << filevalue.Data(); |
2177 |
}; |
2178 |
// EM |
2179 |
const char *file2; |
2180 |
file2 = filenome.str().c_str(); |
2181 |
TFile *hfile = 0; |
2182 |
hfile = new TFile(filevalue.Data(),"UPDATE","Calorimeter CALIBRATION data"); |
2183 |
CalorimeterCalibration *calo = 0; |
2184 |
TTree *tree; |
2185 |
tree = (TTree*)hfile->Get("CaloADC"); |
2186 |
tree->SetBranchAddress("Event", &calo); |
2187 |
Long64_t nevents = tree->GetEntries(); |
2188 |
tree->GetEntry(nevents-1); |
2189 |
// EM end |
2190 |
// |
2191 |
const char *file = filename; |
2192 |
stringstream file3; |
2193 |
file3.str(""); |
2194 |
// file3 << OutDir.Data() << "/"; |
2195 |
file3 << file; |
2196 |
TFile hfile3(filename.Data()); |
2197 |
Int_t l = 0; |
2198 |
TCanvas *c1; |
2199 |
Int_t ty = 1; |
2200 |
if ( type != "" ) ty = 0; |
2201 |
c1 = new TCanvas("canvas","canvas",800,800); |
2202 |
c1->Draw(); |
2203 |
gStyle->SetOptFit(111); |
2204 |
gPad->SetLogy(); |
2205 |
gPad->SetTickx(); |
2206 |
gPad->SetTicky(); |
2207 |
gPad->SetGrid(); |
2208 |
Int_t j = -1; |
2209 |
Int_t k = -1; |
2210 |
Int_t h = -1;; |
2211 |
Int_t changed = 0; |
2212 |
beginning: |
2213 |
if ( j >= 0 ) l = j; |
2214 |
stringstream fmippa; |
2215 |
TF1 *tempf = 0; |
2216 |
TH1F *temp; |
2217 |
while ( l < 2){ |
2218 |
Int_t m = 0; |
2219 |
if ( k >= 0 ) m = k; |
2220 |
while ( m < 22 ){ |
2221 |
Int_t n =0 ; |
2222 |
if ( h >= 0 ) n = h; |
2223 |
while ( n < 96 ){ |
2224 |
c1->Clear(); |
2225 |
c1->cd(); |
2226 |
fmippa.str(""); |
2227 |
fmippa << "fmip " << l; |
2228 |
fmippa << " " << m; |
2229 |
fmippa << " " << n; |
2230 |
temp = (TH1F*)hfile3.Get(fmippa.str().c_str()); |
2231 |
if ( ty ) { |
2232 |
fmippa.str(""); |
2233 |
fmippa << "fit " << l; |
2234 |
fmippa << " " << m; |
2235 |
fmippa << " " << n; |
2236 |
tempf = (TF1*)hfile3.Get(fmippa.str().c_str()); |
2237 |
}; |
2238 |
j = -1; |
2239 |
k = -1; |
2240 |
h = -1; |
2241 |
temp->DrawCopy(); |
2242 |
if ( ty ) tempf->DrawCopy("lsame"); |
2243 |
c1->Update(); |
2244 |
// |
2245 |
// |
2246 |
// |
2247 |
printf(" **** STRIP: %i %i %i **** \n",l,m,n); |
2248 |
printf(" MIP: %f \n",calo->mip[l][m][n]); |
2249 |
printf(" ERMIP: %f \n",calo->ermip[l][m][n]); |
2250 |
printf(" FP[0-3]: %f / %f / %f / %f \n",calo->fp[0][l][m][n],calo->fp[1][l][m][n],calo->fp[2][l][m][n],calo->fp[3][l][m][n]); |
2251 |
printf(" FPE[0-3]: %f / %f / %f / %f \n",calo->fpe[0][l][m][n],calo->fpe[1][l][m][n],calo->fpe[2][l][m][n],calo->fpe[3][l][m][n]); |
2252 |
printf(" CHI2: %f \n",calo->chi2[l][m][n]); |
2253 |
printf(" NDF: %f \n",calo->ndf[l][m][n]); |
2254 |
printf(" MASK: %f \n",calo->mask[l][m][n]); |
2255 |
// |
2256 |
// what to do? |
2257 |
// |
2258 |
char tellme[256]; |
2259 |
char tellme2[256]; |
2260 |
stringstream input; |
2261 |
stringstream input2; |
2262 |
stringstream out; |
2263 |
stringstream stc; |
2264 |
input.str("a"); |
2265 |
out.str("a"); |
2266 |
while ( !strcmp(input.str().c_str(),out.str().c_str()) ) { |
2267 |
printf("\nPress <enter> to continue, b<enter> to go backward, j<enter> to jump to a\nfigure, p<enter> to save the figure, f<enter> to do the fit, q<enter> to quit: \n"); |
2268 |
cin.getline(tellme,256); |
2269 |
input.str(""); |
2270 |
input << tellme; |
2271 |
out.str("1"); |
2272 |
// |
2273 |
stc.str("f"); |
2274 |
if ( !strcmp(input.str().c_str(),stc.str().c_str()) ) { |
2275 |
printf("\n Do you want to give a number by hand, h<enter>, or do you want to try a better fit, f<enter>?"); |
2276 |
cin.getline(tellme,256); |
2277 |
input.str(""); |
2278 |
input << tellme; |
2279 |
out.str("f"); |
2280 |
if ( !strcmp(input.str().c_str(),stc.str().c_str()) ) { |
2281 |
Double_t fr[2],vtemp; |
2282 |
Double_t sv[4], pllo[4], plhi[4], ffp[4], ffpe[4]; |
2283 |
for ( Int_t fk = 0; fk < 4; fk++){ |
2284 |
sv[fk] = (int)calo->fp[fk][l][m][n]; |
2285 |
printf(" Give input parameter [fp[%i]=%f] \n",fk,sv[fk]); |
2286 |
cin.getline(tellme2,256); |
2287 |
input2.str(""); |
2288 |
input2 << tellme2; |
2289 |
vtemp = (Double_t)atoi(input2.str().c_str()); |
2290 |
if ( vtemp != 0. ) sv[fk] = vtemp; |
2291 |
printf(" -> fp[%i] = %f \n\n",fk,sv[fk]); |
2292 |
}; |
2293 |
printf(" Give lower limit of fitting range fr[0] \n"); |
2294 |
cin.getline(tellme2,256); |
2295 |
input2.str(""); |
2296 |
input2 << tellme2; |
2297 |
fr[0] = (Double_t)atoi(input2.str().c_str()); |
2298 |
printf(" -> fr[0] = %f \n\n",fr[0]); |
2299 |
printf(" Give upper limit of fitting range fr[1] \n"); |
2300 |
cin.getline(tellme2,256); |
2301 |
input2.str(""); |
2302 |
input2 << tellme2; |
2303 |
fr[1] = (Double_t)atoi(input2.str().c_str()); |
2304 |
printf(" -> fr[1] = %f \n",fr[1]); |
2305 |
pllo[0]=0.5; pllo[1]=5.0; pllo[2]=1.0; pllo[3]=0.2; |
2306 |
plhi[0]=8.0; plhi[1]=50.0; plhi[2]=1000000.0; plhi[3]=8.0; |
2307 |
Double_t chisqr; |
2308 |
Int_t fndf; |
2309 |
// |
2310 |
// fit the figure pfmip and put fit results in pfitsnr |
2311 |
// |
2312 |
tempf = langaufit(temp,fr,sv,pllo,plhi,ffp,ffpe,&chisqr,&fndf,"R0"); |
2313 |
Double_t SNRPeak = langaupro(ffp); |
2314 |
printf("\n Conversion factor: %f \n",SNRPeak); |
2315 |
tempf->DrawCopy("lsame"); |
2316 |
c1->Update(); |
2317 |
c1->Modified(); |
2318 |
c1->Update(); |
2319 |
printf(" Do you want to save this result y/n<enter> ?\n"); |
2320 |
cin.getline(tellme,256); |
2321 |
input.str(""); |
2322 |
input << tellme; |
2323 |
out.str("y"); |
2324 |
if ( !strcmp(input.str().c_str(),out.str().c_str()) ) { |
2325 |
calo->mip[l][m][n] = (float)SNRPeak; |
2326 |
calo->ermip[l][m][n] = (float)ffpe[1]; |
2327 |
for (Int_t a = 0; a < 4 ; a++){ |
2328 |
calo->fp[a][l][m][n] = (float)ffp[a]; |
2329 |
calo->fpe[a][l][m][n] = (float)ffpe[a]; |
2330 |
}; |
2331 |
calo->ndf[l][m][n] = (float)fndf; |
2332 |
calo->chi2[l][m][n] = (float)chisqr; |
2333 |
// |
2334 |
if ( fndf!=0 && (float)chisqr/(float)fndf < 2. && ffpe[1] < 0.15 && ffp[1] > 15. && ffp[1] < 40. ) { |
2335 |
calo->mask[l][m][n] = 1.; |
2336 |
} else { |
2337 |
calo->mask[l][m][n] = 0.; |
2338 |
}; |
2339 |
printf(" Saved! \n"); |
2340 |
changed = 1; |
2341 |
}; |
2342 |
} else { |
2343 |
printf(" Give the MIP conversion value \n"); |
2344 |
cin.getline(tellme2,256); |
2345 |
input2.str(""); |
2346 |
input2 << tellme2; |
2347 |
calo->mip[l][m][n] = (Float_t)atoi(input2.str().c_str()); |
2348 |
printf(" -> mip = %f \n",calo->mip[l][m][n]); |
2349 |
printf(" Give the mask value \n"); |
2350 |
cin.getline(tellme2,256); |
2351 |
input2.str(""); |
2352 |
input2 << tellme2; |
2353 |
calo->mask[l][m][n] = (Float_t)atoi(input2.str().c_str()); |
2354 |
printf(" -> mask = %f \n",calo->mask[l][m][n]); |
2355 |
changed = 1; |
2356 |
}; |
2357 |
out.str(""); |
2358 |
out << input.str().c_str(); |
2359 |
}; |
2360 |
stc.str("b"); |
2361 |
if ( !strcmp(input.str().c_str(),stc.str().c_str()) ) { |
2362 |
if ( n > 0 ) { |
2363 |
printf("WARNING: going one figure backward!\n\n"); |
2364 |
n -= 2; |
2365 |
} else { |
2366 |
printf("This is the first strip of plane, you can't go backward! \n"); |
2367 |
out.str(""); |
2368 |
out << input.str().c_str(); |
2369 |
}; |
2370 |
}; |
2371 |
stc.str("j"); |
2372 |
if ( !strcmp(input.str().c_str(),stc.str().c_str()) ) { |
2373 |
printf("\n Enter the view number you want to jump to (0 = x, 1 = y): "); |
2374 |
cin.getline(tellme2,256); |
2375 |
input2.str(""); |
2376 |
input2 << tellme2; |
2377 |
j = atoi(input2.str().c_str()); |
2378 |
if ( j < 0 || j > 1 ) { |
2379 |
printf("\n You can choose between 0 and 1 \n"); |
2380 |
out.str(""); |
2381 |
out << input.str().c_str(); |
2382 |
} else { |
2383 |
printf("\n Enter the plane number you want to jump to (0 to 21): "); |
2384 |
cin.getline(tellme2,256); |
2385 |
input2.str(""); |
2386 |
input2 << tellme2; |
2387 |
k = atoi(input2.str().c_str()); |
2388 |
if ( k < 0 || k > 21 ) { |
2389 |
printf("\n You can choose between 0 and 21 \n"); |
2390 |
out.str(""); |
2391 |
out << input.str().c_str(); |
2392 |
} else { |
2393 |
printf("\n Enter the strip number you want to jump to (0 to 95): "); |
2394 |
cin.getline(tellme2,256); |
2395 |
input2.str(""); |
2396 |
input2 << tellme2; |
2397 |
h = atoi(input2.str().c_str()); |
2398 |
if ( h < 0 || h > 95 ) { |
2399 |
printf("\n You can choose between 0 and 95 \n"); |
2400 |
out.str(""); |
2401 |
out << input.str().c_str(); |
2402 |
} else { |
2403 |
printf("\n Jumping to strip %i %i %i \n\n",j,k,h); |
2404 |
goto beginning; |
2405 |
}; |
2406 |
}; |
2407 |
}; |
2408 |
}; |
2409 |
// |
2410 |
stc.str("q"); |
2411 |
if ( !strcmp(input.str().c_str(),stc.str().c_str()) ) { |
2412 |
printf("Exiting...\n"); |
2413 |
goto end; |
2414 |
}; |
2415 |
// |
2416 |
stc.str("p"); |
2417 |
if ( !strcmp(input.str().c_str(),stc.str().c_str()) ) { |
2418 |
printf("Enter a file extension recognized by ROOT (ps, eps, gif,...):\n"); |
2419 |
cin.getline(tellme2,256); |
2420 |
input2.str(""); |
2421 |
input2 << tellme2; |
2422 |
out.str(""); |
2423 |
out << input.str().c_str(); |
2424 |
stringstream figsave; |
2425 |
figsave.str(""); |
2426 |
figsave << startingdir << "/mip2adc_"; |
2427 |
figsave << l << "_"; |
2428 |
figsave << m << "_"; |
2429 |
figsave << n << "."; |
2430 |
figsave << input2.str().c_str(); |
2431 |
c1->SaveAs(figsave.str().c_str()); |
2432 |
printf("\n"); |
2433 |
}; |
2434 |
}; |
2435 |
n++; |
2436 |
}; |
2437 |
m++; |
2438 |
}; |
2439 |
l++; |
2440 |
}; |
2441 |
end: printf("\n"); |
2442 |
if ( changed ){ |
2443 |
tree->Fill(); |
2444 |
hfile->Write(); |
2445 |
}; |
2446 |
hfile->Close(); |
2447 |
} |
2448 |
|
2449 |
void FCalo4224MIPVALUES(TString filevalue = "", TString type=""){ |
2450 |
const char* startingdir = gSystem->WorkingDirectory(); |
2451 |
const char *pam_calib = pathtocalibration(); |
2452 |
// |
2453 |
// this routine shows the 4224 figures with fit from the main program |
2454 |
// |
2455 |
stringstream filenome; |
2456 |
filenome.str(""); |
2457 |
if ( filevalue == "" ){ |
2458 |
filenome << pam_calib << "/CaloADC2MIP.root"; |
2459 |
} else { |
2460 |
filenome << filevalue.Data(); |
2461 |
}; |
2462 |
// EM |
2463 |
const char *file2; |
2464 |
file2 = filenome.str().c_str(); |
2465 |
TFile *hfile = 0; |
2466 |
hfile = new TFile(filevalue.Data(),"READ","Calorimeter CALIBRATION data"); |
2467 |
CalorimeterCalibration *calo = 0; |
2468 |
TTree *tree; |
2469 |
tree = (TTree*)hfile->Get("CaloADC"); |
2470 |
tree->SetBranchAddress("Event", &calo); |
2471 |
Long64_t nevents = tree->GetEntries(); |
2472 |
tree->GetEntry(nevents-1); |
2473 |
// EM end |
2474 |
// |
2475 |
TCanvas *c1; |
2476 |
Int_t ty = 1; |
2477 |
if ( type != "" ) ty = 0; |
2478 |
c1 = new TCanvas("canvas","canvas",1200,800); |
2479 |
c1->Draw(); |
2480 |
gStyle->SetOptFit(111); |
2481 |
gPad->SetTickx(); |
2482 |
gPad->SetTicky(); |
2483 |
Int_t k = -1; |
2484 |
Int_t changed = 0; |
2485 |
Float_t mipf[1]={0}; |
2486 |
Float_t val[1]={0}; |
2487 |
TLatex *text=new TLatex(); |
2488 |
TLine *linea; |
2489 |
stringstream testo; |
2490 |
beginning: |
2491 |
Int_t m = 0; |
2492 |
if ( k >= 0 ) m = k; |
2493 |
while ( m < 22 ){ |
2494 |
Int_t l = 0; |
2495 |
c1->Clear(); |
2496 |
c1->cd(); |
2497 |
TMultiGraph *mg = new TMultiGraph(); |
2498 |
while ( l < 2){ |
2499 |
Int_t n = 0; |
2500 |
while ( n < 96 ){ |
2501 |
val[0] = (float)n + 100.*(float)l ; |
2502 |
mipf[0] = (float)calo->mip[l][m][n]; |
2503 |
TGraph *graph = new TGraph(1, val, mipf); |
2504 |
graph->SetMarkerColor(2); |
2505 |
graph->SetMarkerStyle(22+l); |
2506 |
graph->SetMarkerSize(0.7); |
2507 |
mg->Add(graph); |
2508 |
printf(" **** STRIP: %i %i %i **** \n",l,m,n); |
2509 |
printf(" MIP: %f \n",calo->mip[l][m][n]); |
2510 |
printf(" ERMIP: %f \n",calo->ermip[l][m][n]); |
2511 |
printf(" FP[0-3]: %f / %f / %f / %f \n",calo->fp[0][l][m][n],calo->fp[1][l][m][n],calo->fp[2][l][m][n],calo->fp[3][l][m][n]); |
2512 |
printf(" FPE[0-3]: %f / %f / %f / %f \n",calo->fpe[0][l][m][n],calo->fpe[1][l][m][n],calo->fpe[2][l][m][n],calo->fpe[3][l][m][n]); |
2513 |
printf(" CHI2: %f \n",calo->chi2[l][m][n]); |
2514 |
printf(" NDF: %f \n",calo->ndf[l][m][n]); |
2515 |
printf(" MASK: %f \n",calo->mask[l][m][n]); |
2516 |
n++; |
2517 |
}; |
2518 |
l++; |
2519 |
}; |
2520 |
mg->SetMaximum(50.); |
2521 |
mg->SetMinimum(0.); |
2522 |
mg->Draw("AP"); |
2523 |
for (Int_t e = 0; e<2 ; e++){ |
2524 |
for (Int_t ep = 0; ep<96 ; ep++){ |
2525 |
if ( ep%16 == 0 ) { |
2526 |
linea = new TLine((float)ep+100.*(float)e,0.,(float)ep+100.*(float)e,50.); |
2527 |
linea->SetLineColor(15); |
2528 |
linea->SetLineStyle(2); |
2529 |
linea->SetLineWidth(1); |
2530 |
linea->Draw("lsame"); |
2531 |
if ( ep > 0 ){ |
2532 |
linea = new TLine((float)ep-1.+100.*(float)e,0.,(float)ep-1.+100.*(float)e,50.); |
2533 |
linea->SetLineColor(15); |
2534 |
linea->SetLineStyle(2); |
2535 |
linea->SetLineWidth(1); |
2536 |
linea->Draw("lsame"); |
2537 |
}; |
2538 |
}; |
2539 |
if ( ep == 95 ){ |
2540 |
linea = new TLine(95.+100.*(float)e,0.,95.+100.*(float)e,50.); |
2541 |
linea->SetLineColor(15); |
2542 |
linea->SetLineStyle(2); |
2543 |
linea->SetLineWidth(1); |
2544 |
linea->Draw("lsame"); |
2545 |
}; |
2546 |
}; |
2547 |
}; |
2548 |
text->SetTextAngle(0); |
2549 |
text->SetTextFont(32); |
2550 |
text->SetTextColor(1); |
2551 |
text->SetTextSize(0.050); |
2552 |
text->SetTextAlign(12); |
2553 |
testo.str(""); |
2554 |
testo << "Plane " << m; |
2555 |
text->DrawLatex(85.,52.,testo.str().c_str()); |
2556 |
c1->Update(); |
2557 |
// |
2558 |
// what to do? |
2559 |
// |
2560 |
|
2561 |
char tellme[256]; |
2562 |
char tellme2[256]; |
2563 |
stringstream input; |
2564 |
stringstream input2; |
2565 |
stringstream out; |
2566 |
stringstream stc; |
2567 |
input.str("a"); |
2568 |
out.str("a"); |
2569 |
while ( !strcmp(input.str().c_str(),out.str().c_str()) ) { |
2570 |
printf("\nPress <enter> to continue, b<enter> to go backward, j<enter> to jump to a\nfigure, p<enter> to save the figure, q<enter> to quit: \n"); |
2571 |
cin.getline(tellme,256); |
2572 |
input.str(""); |
2573 |
input << tellme; |
2574 |
out.str("1"); |
2575 |
// |
2576 |
stc.str("b"); |
2577 |
if ( !strcmp(input.str().c_str(),stc.str().c_str()) ) { |
2578 |
if ( m > 0 ) { |
2579 |
printf("WARNING: going one figure backward!\n\n"); |
2580 |
m -= 2; |
2581 |
} else { |
2582 |
printf("This is the first plane, you can't go backward! \n"); |
2583 |
out.str(""); |
2584 |
out << input.str().c_str(); |
2585 |
}; |
2586 |
}; |
2587 |
stc.str("j"); |
2588 |
if ( !strcmp(input.str().c_str(),stc.str().c_str()) ) { |
2589 |
printf("\n Enter the plane number you want to jump to (0 to 21): "); |
2590 |
cin.getline(tellme2,256); |
2591 |
input2.str(""); |
2592 |
input2 << tellme2; |
2593 |
k = atoi(input2.str().c_str()); |
2594 |
if ( k < 0 || k > 21 ) { |
2595 |
printf("\n You can choose between 0 and 21 \n"); |
2596 |
out.str(""); |
2597 |
out << input.str().c_str(); |
2598 |
} else { |
2599 |
printf("\n Jumping to plane %i \n\n",k); |
2600 |
m = k; |
2601 |
goto beginning; |
2602 |
}; |
2603 |
}; |
2604 |
// |
2605 |
stc.str("q"); |
2606 |
if ( !strcmp(input.str().c_str(),stc.str().c_str()) ) { |
2607 |
printf("Exiting...\n"); |
2608 |
goto end; |
2609 |
}; |
2610 |
// |
2611 |
stc.str("p"); |
2612 |
if ( !strcmp(input.str().c_str(),stc.str().c_str()) ) { |
2613 |
printf("Enter a file extension recognized by ROOT (ps, eps, gif,...):\n"); |
2614 |
cin.getline(tellme2,256); |
2615 |
input2.str(""); |
2616 |
input2 << tellme2; |
2617 |
out.str(""); |
2618 |
out << input.str().c_str(); |
2619 |
stringstream figsave; |
2620 |
figsave.str(""); |
2621 |
figsave << startingdir << "/mip2adc_plane_"; |
2622 |
figsave << m << "."; |
2623 |
figsave << input2.str().c_str(); |
2624 |
c1->SaveAs(figsave.str().c_str()); |
2625 |
printf("\n"); |
2626 |
}; |
2627 |
}; |
2628 |
m++; |
2629 |
}; |
2630 |
end: printf("\n"); |
2631 |
if ( changed ){ |
2632 |
tree->Fill(); |
2633 |
hfile->Write(); |
2634 |
}; |
2635 |
hfile->Close(); |
2636 |
} |
2637 |
|
2638 |
void FCalo4224BAK(TString filename){ |
2639 |
// |
2640 |
// this shows the 4224 figure from a backup file |
2641 |
// |
2642 |
const char* startingdir = gSystem->WorkingDirectory(); |
2643 |
const char *file3 = filename; |
2644 |
TFile hfile3(file3); |
2645 |
Int_t l = 0; |
2646 |
TCanvas *c1; |
2647 |
c1 = new TCanvas("canvas","canvas",800,800); |
2648 |
c1->Draw(); |
2649 |
gStyle->SetOptFit(111); |
2650 |
gPad->SetLogy(); |
2651 |
Int_t j = 0; |
2652 |
Int_t k = 0; |
2653 |
Int_t h = 0; |
2654 |
beginning: |
2655 |
if ( j ) l = j; |
2656 |
stringstream bmippa; |
2657 |
while ( l < 2){ |
2658 |
Int_t m = 0; |
2659 |
if ( k ) m = k; |
2660 |
while ( m < 22 ){ |
2661 |
Int_t n =0 ; |
2662 |
if ( h ) n = h; |
2663 |
while ( n < 96 ){ |
2664 |
c1->Clear(); |
2665 |
c1->cd(); |
2666 |
bmippa.str(""); |
2667 |
bmippa << "bmip " << l; |
2668 |
bmippa << " " << m; |
2669 |
bmippa << " " << n; |
2670 |
TH1F *temp = (TH1F*)hfile3.Get(bmippa.str().c_str()); |
2671 |
j = 0; |
2672 |
k = 0; |
2673 |
h = 0; |
2674 |
temp->DrawCopy(); |
2675 |
c1->Update(); |
2676 |
// |
2677 |
// what to do? |
2678 |
// |
2679 |
char tellme[256]; |
2680 |
char tellme2[256]; |
2681 |
stringstream input; |
2682 |
stringstream input2; |
2683 |
stringstream out; |
2684 |
stringstream stc; |
2685 |
input.str("a"); |
2686 |
out.str("a"); |
2687 |
while ( !strcmp(input.str().c_str(),out.str().c_str()) ) { |
2688 |
printf("\nPress <enter> to continue, b<enter> to go backward, j<enter> to jump to a\nfigure, p<enter> to save the figure, q<enter> to quit: \n"); |
2689 |
cin.getline(tellme,256); |
2690 |
input.str(""); |
2691 |
input << tellme; |
2692 |
out.str("1"); |
2693 |
// |
2694 |
stc.str("b"); |
2695 |
if ( !strcmp(input.str().c_str(),stc.str().c_str()) ) { |
2696 |
if ( n > 0 ) { |
2697 |
printf("WARNING: going one figure backward!\n\n"); |
2698 |
n -= 2; |
2699 |
} else { |
2700 |
printf("This is the first strip of plane, you can't go backward! \n"); |
2701 |
out.str(""); |
2702 |
out << input.str().c_str(); |
2703 |
}; |
2704 |
}; |
2705 |
stc.str("j"); |
2706 |
if ( !strcmp(input.str().c_str(),stc.str().c_str()) ) { |
2707 |
printf("\n Enter the view number you want to jump to (0 = x, 1 = y): "); |
2708 |
cin.getline(tellme2,256); |
2709 |
input2.str(""); |
2710 |
input2 << tellme2; |
2711 |
j = atoi(input2.str().c_str()); |
2712 |
if ( j < 0 || j > 1 ) { |
2713 |
printf("\n You can choose between 0 and 1 \n"); |
2714 |
out.str(""); |
2715 |
out << input.str().c_str(); |
2716 |
} else { |
2717 |
printf("\n Enter the plane number you want to jump to (0 to 21): "); |
2718 |
cin.getline(tellme2,256); |
2719 |
input2.str(""); |
2720 |
input2 << tellme2; |
2721 |
k = atoi(input2.str().c_str()); |
2722 |
if ( k < 0 || k > 21 ) { |
2723 |
printf("\n You can choose between 0 and 21 \n"); |
2724 |
out.str(""); |
2725 |
out << input.str().c_str(); |
2726 |
} else { |
2727 |
printf("\n Enter the strip number you want to jump to (0 to 95): "); |
2728 |
cin.getline(tellme2,256); |
2729 |
input2.str(""); |
2730 |
input2 << tellme2; |
2731 |
h = atoi(input2.str().c_str()); |
2732 |
if ( h < 0 || h > 95 ) { |
2733 |
printf("\n You can choose between 0 and 95 \n"); |
2734 |
out.str(""); |
2735 |
out << input.str().c_str(); |
2736 |
} else { |
2737 |
printf("\n Jumping to strip %i %i %i \n\n",j,k,h); |
2738 |
goto beginning; |
2739 |
}; |
2740 |
}; |
2741 |
}; |
2742 |
}; |
2743 |
// |
2744 |
stc.str("q"); |
2745 |
if ( !strcmp(input.str().c_str(),stc.str().c_str()) ) { |
2746 |
printf("Exiting...\n"); |
2747 |
goto end; |
2748 |
}; |
2749 |
// |
2750 |
stc.str("p"); |
2751 |
if ( !strcmp(input.str().c_str(),stc.str().c_str()) ) { |
2752 |
printf("Enter a file extension recognized by ROOT (ps, eps, gif,...):\n"); |
2753 |
cin.getline(tellme2,256); |
2754 |
input2.str(""); |
2755 |
input2 << tellme2; |
2756 |
out.str(""); |
2757 |
out << input.str().c_str(); |
2758 |
stringstream figsave; |
2759 |
figsave.str(""); |
2760 |
figsave << startingdir << "/mip2adcbak_"; |
2761 |
figsave << l << "_"; |
2762 |
figsave << m << "_"; |
2763 |
figsave << n << "."; |
2764 |
figsave << input2.str().c_str(); |
2765 |
c1->SaveAs(figsave.str().c_str()); |
2766 |
printf("\n"); |
2767 |
}; |
2768 |
}; |
2769 |
n++; |
2770 |
}; |
2771 |
m++; |
2772 |
}; |
2773 |
l++; |
2774 |
}; |
2775 |
end: printf("\n"); |
2776 |
} |
2777 |
|
2778 |
void FCaloBAKFIT(TString filename, TString OutDir=""){ |
2779 |
const char *pam_calib = pathtocalibration(); |
2780 |
if ( !strcmp(OutDir.Data(),"") ){ |
2781 |
OutDir = pam_calib; |
2782 |
}; |
2783 |
// |
2784 |
// this routine perform the 4224 fit on a backup figure file and save - with extension .bak - the two output file |
2785 |
// in the correct format, ready to be updated etc. etc. |
2786 |
// NB: you will LOSE information about used files |
2787 |
// |
2788 |
stringstream file2; |
2789 |
file2.str(""); |
2790 |
file2 << OutDir.Data() << "/CaloADC2MIP.bak"; |
2791 |
stringstream file4; |
2792 |
file4.str(""); |
2793 |
file4 << OutDir.Data() << "/CaloADC2MIPf.bak"; |
2794 |
// |
2795 |
Int_t notgood = 0; |
2796 |
// |
2797 |
TFile *hfile = 0; |
2798 |
CalorimeterCalibration *calo = new CalorimeterCalibration(); |
2799 |
hfile = new TFile(file2.str().c_str(),"RECREATE","Calorimeter CALIBRATION data"); |
2800 |
if ( !existfile(file2.str().c_str()) ){ |
2801 |
printf(" ERROR: Cannot create file!!! \n"); |
2802 |
return; |
2803 |
}; |
2804 |
TTree *tree = 0; |
2805 |
tree = new TTree("CaloADC","Calorimeter calibration data"); |
2806 |
tree->Branch("Event","CalorimeterCalibration",&calo); |
2807 |
// |
2808 |
const char *file3 = filename; |
2809 |
TFile hfile3(file3); |
2810 |
TCanvas *c1; |
2811 |
c1 = new TCanvas("canvas","canvas",800,800); |
2812 |
c1->Draw(); |
2813 |
gStyle->SetOptFit(111); |
2814 |
TH1F *pfmip[2][22][96]; |
2815 |
TF1 *pfitsnr[2][22][96]; |
2816 |
stringstream Fmip; |
2817 |
for (Int_t i=0; i<2;i++){ |
2818 |
for (Int_t j=0; j<22;j++){ |
2819 |
for (Int_t m=0; m<96;m++){ |
2820 |
Fmip.str(""); |
2821 |
Fmip << "Fmip " << i; |
2822 |
Fmip << " " << j; |
2823 |
Fmip << " " << m; |
2824 |
pfmip[i][j][m] = new TH1F(Fmip.str().c_str(),"",56,0.,55.); |
2825 |
pfitsnr[i][j][m] = new TF1; |
2826 |
}; |
2827 |
}; |
2828 |
}; |
2829 |
gStyle->SetOptFit(111); |
2830 |
gPad->SetLogy(); |
2831 |
// |
2832 |
Int_t l = 0; |
2833 |
stringstream bmippa; |
2834 |
while ( l < 2){ |
2835 |
Int_t m = 0; |
2836 |
while ( m < 22 ){ |
2837 |
Int_t n =0 ; |
2838 |
Double_t SNRPeak = 0.; |
2839 |
while ( n < 96 ){ |
2840 |
c1->Clear(); |
2841 |
c1->cd(); |
2842 |
bmippa.str(""); |
2843 |
bmippa << "bmip " << l; |
2844 |
bmippa << " " << m; |
2845 |
bmippa << " " << n; |
2846 |
TH1F *temp = (TH1F*)hfile3.Get(bmippa.str().c_str()); |
2847 |
bmippa.str(""); |
2848 |
bmippa << "fmip " << l; |
2849 |
bmippa << " " << m; |
2850 |
bmippa << " " << n; |
2851 |
pfmip[l][m][n] = (TH1F*)temp->Clone(bmippa.str().c_str()); |
2852 |
Int_t doitagain = 0; |
2853 |
Int_t ndoitagain = 0; |
2854 |
Double_t fr[2]; |
2855 |
Double_t sv[4], pllo[4], plhi[4], fp[4], fpe[4]; |
2856 |
// if ( SNRPeak > 16. && SNRPeak < 35. ){ |
2857 |
if ( SNRPeak > 16. && SNRPeak < 35. && fp[3] < 8. ){ |
2858 |
fr[0] = (Float_t)SNRPeak - 7.; |
2859 |
sv[0]= fp[0]; |
2860 |
sv[1]= fp[1]; |
2861 |
sv[2]= fp[2]; |
2862 |
sv[3]= fp[3]; |
2863 |
} else { |
2864 |
fr[0] = 12.5; |
2865 |
sv[0] = 2.8; |
2866 |
sv[1] = 23.0; |
2867 |
sv[2] = 1000.0; |
2868 |
sv[3] = 0.1; |
2869 |
}; |
2870 |
fr[1] = 50.; |
2871 |
// fr[1] = 60.; |
2872 |
fitting: printf("Fitting strip %i %i %i \n",l,m,n); |
2873 |
pllo[0]=0.5; pllo[1]=5.0; pllo[2]=1.0; pllo[3]=0.2; |
2874 |
plhi[0]=15.0; plhi[1]=50.0; plhi[2]=1000000.0; plhi[3]=8.0; |
2875 |
Double_t chisqr; |
2876 |
Int_t ndf; |
2877 |
pfitsnr[l][m][n] = langaufit(pfmip[l][m][n],fr,sv,pllo,plhi,fp,fpe,&chisqr,&ndf,"QR0"); |
2878 |
// |
2879 |
Double_t SNRPeak = langaupro(fp); |
2880 |
printf("\n Conversion factor: %f \n\n",SNRPeak); |
2881 |
// |
2882 |
c1->cd(); |
2883 |
pfmip[l][m][n]->DrawCopy(); |
2884 |
pfitsnr[l][m][n]->DrawCopy("lsame"); |
2885 |
c1->Modified(); |
2886 |
c1->Update(); |
2887 |
// |
2888 |
// |
2889 |
if ( (SNRPeak<0. || (SNRPeak < 16. || SNRPeak > 35.) || chisqr > 100.) && doitagain < 11 ){ |
2890 |
printf("\n The fit is not good, I will try again, step %i \n\n",doitagain); |
2891 |
doitagain++; |
2892 |
if ( chisqr > 100. ) { |
2893 |
if ( fr[0] < 20. && !(doitagain%2) ) fr[0] += 1.; |
2894 |
if ( fr[1] > 35. && doitagain%2 ) fr[1] -= 3.; |
2895 |
// if ( doitagain > 1 ) fr[1] = 35.; |
2896 |
sv[0] = fp[0]; |
2897 |
sv[1] = fp[1]; |
2898 |
sv[2] = fp[2]; |
2899 |
sv[3] = fp[3]; |
2900 |
printf(" chi \n"); |
2901 |
goto fitting; |
2902 |
}; |
2903 |
ndoitagain++; |
2904 |
if ( ndoitagain == 1 ) { |
2905 |
fr[0] = 19.; |
2906 |
sv[0] = 2.8; |
2907 |
sv[1] = 21.0; |
2908 |
sv[2] = 1000.0; |
2909 |
sv[3] = 0.1; |
2910 |
printf(" uno \n"); |
2911 |
goto fitting; |
2912 |
}; |
2913 |
if ( ndoitagain == 2 ) { |
2914 |
fr[0] = 22.; |
2915 |
sv[0] = 2.8; |
2916 |
sv[1] = 25.0; |
2917 |
sv[2] = 1000.0; |
2918 |
sv[3] = 0.1; |
2919 |
printf(" due \n"); |
2920 |
goto fitting; |
2921 |
}; |
2922 |
if ( ndoitagain == 3 ) { |
2923 |
fr[0] = 12.; |
2924 |
sv[0] = 2.8; |
2925 |
sv[1] = 15.0; |
2926 |
sv[2] = 1000.0; |
2927 |
sv[3] = 0.1; |
2928 |
printf(" tre \n"); |
2929 |
goto fitting; |
2930 |
}; |
2931 |
}; |
2932 |
// |
2933 |
calo->mip[l][m][n] = (float)SNRPeak; |
2934 |
calo->ermip[l][m][n] = (float)fpe[1]; |
2935 |
for (Int_t a = 0; a < 4 ; a++){ |
2936 |
calo->fp[a][l][m][n] = (float)fp[a]; |
2937 |
calo->fpe[a][l][m][n] = (float)fpe[a]; |
2938 |
}; |
2939 |
calo->ndf[l][m][n] = (float)ndf; |
2940 |
calo->chi2[l][m][n] = (float)chisqr; |
2941 |
// |
2942 |
if ( ndf!=0 && chisqr/ndf < 2. && fpe[1] < 0.15 && fp[1] > 15. && fp[1] < 40. && SNRPeak > 0. ) { |
2943 |
printf("\n THIS IS A GOOD FIT, SAVED! \n\n"); |
2944 |
calo->mask[l][m][n] = 1.; |
2945 |
} else { |
2946 |
notgood++; |
2947 |
calo->mask[l][m][n] = 0.; |
2948 |
}; |
2949 |
printf("Fitting done, strip %i %i %i \n\n\n",l,m,n); |
2950 |
c1->cd(); |
2951 |
pfmip[l][m][n]->DrawCopy(); |
2952 |
pfitsnr[l][m][n]->DrawCopy("lsame"); |
2953 |
c1->Modified(); |
2954 |
c1->Update(); |
2955 |
n++; |
2956 |
}; |
2957 |
m++; |
2958 |
}; |
2959 |
l++; |
2960 |
}; |
2961 |
// |
2962 |
calo->status = 0; |
2963 |
if ( !notgood ) calo->status = 1; |
2964 |
// |
2965 |
tree->Fill(); |
2966 |
hfile->Write(); |
2967 |
hfile->Close(); |
2968 |
// |
2969 |
// Save histograms |
2970 |
// |
2971 |
TFile *hfile2; |
2972 |
hfile2 = new TFile(file4.str().c_str(),"RECREATE","Calorimeter CALIBRATION figures"); |
2973 |
if ( !existfile(file4.str().c_str()) ){ |
2974 |
printf(" ERROR: Cannot create file!!! \n"); |
2975 |
return; |
2976 |
}; |
2977 |
TH1F *sfmip[2][22][96]; |
2978 |
TF1 *sfitsnr[2][22][96]; |
2979 |
stringstream fmipfi; |
2980 |
for (Int_t l = 0; l < 2; l++){ |
2981 |
for (Int_t m = 0; m < 22; m++){ |
2982 |
for (Int_t n =0 ; n < 96; n++){ |
2983 |
fmipfi.str(""); |
2984 |
fmipfi << "fmip " << l; |
2985 |
fmipfi << " " << m; |
2986 |
fmipfi << " " << n; |
2987 |
sfmip[l][m][n] = new TH1F(fmipfi.str().c_str(),"",56,0.,55.); |
2988 |
sfmip[l][m][n] = (TH1F*)pfmip[l][m][n]->Clone(fmipfi.str().c_str()); |
2989 |
fmipfi.str(""); |
2990 |
fmipfi << "fit " << l; |
2991 |
fmipfi << " " << m; |
2992 |
fmipfi << " " << n; |
2993 |
sfitsnr[l][m][n] = (TF1*)pfitsnr[l][m][n]->Clone(fmipfi.str().c_str()); |
2994 |
sfmip[l][m][n]->Write(); |
2995 |
sfitsnr[l][m][n]->Write(); |
2996 |
}; |
2997 |
}; |
2998 |
}; |
2999 |
hfile2->Close(); |
3000 |
printf("\n"); |
3001 |
hfile3.Close(); |
3002 |
FCalo4224STATUS("CaloADC2MIP.bak",""); |
3003 |
} |
3004 |
|
3005 |
void FCaloROOT2TXT(TString rootple, TString txtple){ |
3006 |
FILE *f; |
3007 |
f = fopen(txtple.Data(),"wb"); |
3008 |
TTree *ctree = 0; |
3009 |
TFile *chfile; |
3010 |
CalorimeterCalibration *ccalo = new CalorimeterCalibration(); |
3011 |
chfile = new TFile(rootple.Data(),"READ","Calorimeter CALIBRATION data"); |
3012 |
if ( chfile->IsZombie() ){ |
3013 |
printf(" ERROR: no calorimeter calibration file! \n"); |
3014 |
} else { |
3015 |
ctree = (TTree*)chfile->Get("CaloADC"); |
3016 |
ctree->SetBranchAddress("Event", &ccalo); |
3017 |
// |
3018 |
Long64_t cnevents = ctree->GetEntries(); |
3019 |
ctree->GetEntry(cnevents-1); |
3020 |
}; |
3021 |
// |
3022 |
Float_t mip = 0.; |
3023 |
for (Int_t m = 0; m < 2 ; m++ ){ |
3024 |
for (Int_t k = 0; k < 22; k++ ){ |
3025 |
for (Int_t l = 0; l < 96; l++ ){ |
3026 |
mip = 0.; |
3027 |
// if ( (ccalo->fp[1][m][k][l] > 20. && ccalo->fp[1][m][k][l] < 32.) || ccalo->mask[m][k][l] == 1. ) { |
3028 |
// if ( (ccalo->fp[1][m][k][l] > 15. && ccalo->fp[1][m][k][l] < 45.) || ccalo->mask[m][k][l] == 1. ) { |
3029 |
mip = ccalo->mip[m][k][l]; |
3030 |
// } else { |
3031 |
// mip = 26. ; |
3032 |
// mip = 28. ; |
3033 |
// }; |
3034 |
// if ( mip == 0 ) mip = 26. ; |
3035 |
// if ( mip == 0 ) mip = 28. ; |
3036 |
// if ( m == 1 && k == 17 ) printf(" %i mip = %f \n",l,mip); |
3037 |
fwrite(&mip,sizeof(mip),1,f); |
3038 |
}; |
3039 |
}; |
3040 |
}; |
3041 |
fclose(f); |
3042 |
} |
3043 |
|
3044 |
void FCaloREADTXT(TString txtple){ |
3045 |
FILE *f; |
3046 |
f = fopen(txtple.Data(),"rb"); |
3047 |
Float_t mip = 0.; |
3048 |
Float_t tmip = 0.; |
3049 |
for (Int_t m = 0; m < 2 ; m++ ){ |
3050 |
for (Int_t k = 0; k < 22; k++ ){ |
3051 |
for (Int_t l = 0; l < 96; l++ ){ |
3052 |
mip = 0.; |
3053 |
fread(&mip,sizeof(mip),1,f); |
3054 |
tmip += mip; |
3055 |
printf(" m %i k %i l %i mip %f \n",m,k,l,mip); |
3056 |
// if ( m == 1 && k == 17 ) printf(" %i mip = %f \n",l,mip); |
3057 |
}; |
3058 |
}; |
3059 |
}; |
3060 |
fclose(f); |
3061 |
// |
3062 |
printf(" Average mip is %f \n",tmip/4224.); |
3063 |
// |
3064 |
} |
3065 |
|
3066 |
void FCaloALIG2DAT(TString txtple){ |
3067 |
// clevel1_.xalig = 121.1; |
3068 |
// clevel1_.yalig = 119.8; |
3069 |
// clevel1_.zalig = -263.1; |
3070 |
char value[256]; |
3071 |
Int_t ixalig; |
3072 |
Int_t iyalig; |
3073 |
Int_t izalig; |
3074 |
Int_t iemip; |
3075 |
Float_t xalig; |
3076 |
Float_t yalig; |
3077 |
Float_t zalig; |
3078 |
Float_t emip; |
3079 |
// |
3080 |
FILE *f; |
3081 |
f = fopen(txtple.Data(),"wb"); |
3082 |
// |
3083 |
printf("\n Insert parameters in microns \n"); |
3084 |
printf("\n Insert the x alignment parameter: \n"); |
3085 |
cin.getline(value,256); |
3086 |
ixalig = atoi(value); |
3087 |
xalig = (Float_t)ixalig/1000.; |
3088 |
fwrite(&xalig,sizeof(xalig),1,f); |
3089 |
printf(" xalig = %f mm\n",xalig); |
3090 |
// |
3091 |
printf("\n Insert the y alignment parameter: \n"); |
3092 |
cin.getline(value,256); |
3093 |
iyalig = atoi(value); |
3094 |
yalig = (Float_t)iyalig/1000.; |
3095 |
fwrite(&yalig,sizeof(yalig),1,f); |
3096 |
printf(" yalig = %f mm\n",yalig); |
3097 |
// |
3098 |
printf("\n Insert the z alignment parameter: \n"); |
3099 |
cin.getline(value,256); |
3100 |
izalig = atoi(value); |
3101 |
zalig = (Float_t)izalig/1000.; |
3102 |
fwrite(&zalig,sizeof(zalig),1,f); |
3103 |
printf(" zalig = %f mm\n",zalig); |
3104 |
// |
3105 |
printf("\n Insert the signal/noise threshold (times 1000): \n"); |
3106 |
cin.getline(value,256); |
3107 |
iemip = atoi(value); |
3108 |
emip = (Float_t)iemip/1000.; |
3109 |
fwrite(&emip,sizeof(emip),1,f); |
3110 |
printf(" emip = %f mip \n",emip); |
3111 |
// |
3112 |
fclose(f); |
3113 |
} |
3114 |
|
3115 |
void FCaloREADALIG(TString txtple){ |
3116 |
FILE *f; |
3117 |
f = fopen(txtple.Data(),"rb"); |
3118 |
Float_t mip = 0.; |
3119 |
fread(&mip,sizeof(mip),1,f); |
3120 |
printf(" xalig = %f \n",mip); |
3121 |
mip = 0.; |
3122 |
fread(&mip,sizeof(mip),1,f); |
3123 |
printf(" yalig = %f \n",mip); |
3124 |
mip = 0.; |
3125 |
fread(&mip,sizeof(mip),1,f); |
3126 |
printf(" zalig = %f \n",mip); |
3127 |
mip = 0.; |
3128 |
fread(&mip,sizeof(mip),1,f); |
3129 |
printf(" signal threshold = %f \n",mip); |
3130 |
fclose(f); |
3131 |
} |