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