1 |
mocchiut |
1.1 |
// |
2 |
|
|
//- Emiliano Mocchiutti |
3 |
|
|
// |
4 |
|
|
// CaloCALIBSCAN.c version 1.05 (2005-11-17) |
5 |
|
|
// |
6 |
|
|
// The only input needed is |
7 |
|
|
// |
8 |
|
|
// Changelog: |
9 |
|
|
// |
10 |
|
|
// 1.04 - 1.05 (2005-11-17): compiled! |
11 |
|
|
// |
12 |
|
|
// 1.03 - 1.04 (2005-08-15): 64 bit arch bugs fixed. |
13 |
|
|
// |
14 |
|
|
// 1.02 - 1.03 (2005-08-04): small bugs fixed. |
15 |
|
|
// |
16 |
|
|
// 1.01 - 1.02 (2005-07-21): don't load anymore yodaUtility.c, use instead clone routines. |
17 |
|
|
// |
18 |
|
|
// 1.00 - 1.01 (2005-07-12): small changes for compilation. |
19 |
|
|
// |
20 |
|
|
// 0.90 - 1.00 (2005-06-28): Working. Many changes. |
21 |
|
|
// |
22 |
|
|
// 0.90 (2005-04-14): Created and partially working. |
23 |
|
|
// |
24 |
|
|
#include <fstream> |
25 |
|
|
#include <sstream> |
26 |
|
|
#include <string> |
27 |
|
|
#include <TTree.h> |
28 |
|
|
#include <TClassEdit.h> |
29 |
|
|
#include <TObject.h> |
30 |
|
|
#include <TList.h> |
31 |
|
|
#include <TSystem.h> |
32 |
|
|
#include <TSystemDirectory.h> |
33 |
|
|
#include <TString.h> |
34 |
|
|
#include <TFile.h> |
35 |
|
|
#include <TClass.h> |
36 |
|
|
#include <TCanvas.h> |
37 |
|
|
#include <TH1.h> |
38 |
|
|
#include <TH1F.h> |
39 |
|
|
#include <TH2D.h> |
40 |
|
|
#include <TLatex.h> |
41 |
|
|
#include <TPad.h> |
42 |
|
|
#include <TPaveLabel.h> |
43 |
|
|
#include <TChain.h> |
44 |
|
|
#if !defined (__CINT__) |
45 |
|
|
#include <event/PamelaRun.h> |
46 |
|
|
#include <event/physics/calorimeter/CalorimeterEvent.h> |
47 |
|
|
#include <event/physics/trigger/TriggerEvent.h> |
48 |
|
|
#include <event/CalibCalPedEvent.h> |
49 |
|
|
#include <caloclasses.h> |
50 |
|
|
#endif |
51 |
|
|
#include <CaloFunctions.h> |
52 |
|
|
|
53 |
|
|
short int CaloCALIBSCAN(TString Filename, TString flist=""){ |
54 |
|
|
gROOT->GetListOfCanvases()->Delete("a"); |
55 |
|
|
gDirectory->GetList()->Delete(); |
56 |
|
|
#if defined (__CINT__) |
57 |
|
|
emicheckLib(); |
58 |
|
|
stringstream llib; |
59 |
|
|
const char *pamlib = gSystem->ExpandPathName("$PAM_LIB"); |
60 |
|
|
llib << pamlib << "/caloclasses_h.so"; |
61 |
|
|
gSystem->Load(llib.str().c_str()); |
62 |
|
|
#endif |
63 |
|
|
TString calcalib; |
64 |
|
|
struct Calib calib; |
65 |
|
|
// |
66 |
|
|
stringstream file5; |
67 |
|
|
const char *pam_calib=gSystem->Getenv("PAM_CALIB"); |
68 |
|
|
file5.str(""); |
69 |
|
|
file5 << pam_calib << "/CaloCALIBdata.root"; |
70 |
|
|
// sprintf(file5,"%s/CaloCALIBdata.root",pam_calib); |
71 |
|
|
//file5 = Form("%s/CaloCALIBdata.root",pam_calib); |
72 |
|
|
// |
73 |
|
|
Int_t nfile = 0; |
74 |
|
|
Int_t calibex = 0; |
75 |
|
|
Int_t fileup = 0; |
76 |
|
|
if ( flist != "" ){ |
77 |
|
|
printf("\n You have given an input file list \n\n Files: \n"); |
78 |
|
|
ifstream in; |
79 |
|
|
in.open(flist, ios::in); |
80 |
|
|
char ctime[20]; |
81 |
|
|
while (1) { |
82 |
|
|
in >> ctime; |
83 |
|
|
if (!in.good()) break; |
84 |
|
|
printf(" File number %i = %s \n",nfile+1,ctime); |
85 |
|
|
nfile++; |
86 |
|
|
// if ( nfile > 499 ) { |
87 |
|
|
// printf(" No more than 500 files please! \n "); |
88 |
|
|
// return; |
89 |
|
|
//}; |
90 |
|
|
}; |
91 |
|
|
in.close(); |
92 |
|
|
if ( !nfile ) { |
93 |
|
|
printf("\n\n The list is empty, exiting... \n\n"); |
94 |
|
|
return(0); |
95 |
|
|
}; |
96 |
|
|
} else { |
97 |
|
|
nfile = 1; |
98 |
|
|
}; |
99 |
|
|
printf("\n"); |
100 |
|
|
// |
101 |
|
|
// First check if the calibration file exists: |
102 |
|
|
// |
103 |
|
|
Int_t EFILE = 0; |
104 |
|
|
printf(" Check the existence of CaloCALIBdata.root file: \n\n"); |
105 |
|
|
TFile tfile(file5.str().c_str()); |
106 |
|
|
if ( !tfile.IsZombie() ) { |
107 |
|
|
printf(" The file already exists! It will be updated \n\n"); |
108 |
|
|
EFILE = 1; |
109 |
|
|
tfile.Close(); |
110 |
|
|
} else { |
111 |
|
|
printf("\n OK, I will create it!\n\n"); |
112 |
|
|
EFILE = 0; |
113 |
|
|
}; |
114 |
|
|
// EFILE = 0; |
115 |
|
|
// |
116 |
|
|
// this must be done for each file. |
117 |
|
|
// |
118 |
|
|
Long64_t neven = 0; |
119 |
|
|
TTree *trl1 = 0; |
120 |
|
|
TFile *hfl1 = 0; |
121 |
|
|
CalorimeterCalibScan *calo = new CalorimeterCalibScan(); |
122 |
|
|
if ( EFILE == 1 ){ |
123 |
|
|
// |
124 |
|
|
// If the file doesn't exist create it |
125 |
|
|
// |
126 |
|
|
hfl1 = new TFile(file5.str().c_str(),"UPDATE","Calorimeter calib data"); |
127 |
|
|
calo = new CalorimeterCalibScan(); |
128 |
|
|
// |
129 |
|
|
trl1 = (TTree*)hfl1->Get("CaloCALIBdata"); |
130 |
|
|
trl1->SetBranchAddress("Event", &calo); |
131 |
|
|
neven = trl1->GetEntries()-1; |
132 |
|
|
trl1->GetEntry(neven); |
133 |
|
|
calibex = calo->evno; |
134 |
|
|
printf("neven %i calibex = %i calo->evno %i calo->rms %f \n",(int)neven,calibex,calo->evno,calo->calrms[0][0][0]); |
135 |
|
|
} else { |
136 |
|
|
// |
137 |
|
|
// If the file doesn't exist create it |
138 |
|
|
// |
139 |
|
|
hfl1 = new TFile(file5.str().c_str(),"RECREATE","Calorimeter calib data"); |
140 |
|
|
// |
141 |
|
|
calo = new CalorimeterCalibScan(); |
142 |
|
|
// |
143 |
|
|
trl1 = new TTree("CaloCALIBdata","PAMELA calorimeter calibration data"); |
144 |
|
|
trl1->Branch("Event","CalorimeterCalibScan",&calo); |
145 |
|
|
}; |
146 |
|
|
// |
147 |
|
|
const char *filename2 = Filename; |
148 |
|
|
// |
149 |
|
|
TString lfile; |
150 |
|
|
TString sfile; |
151 |
|
|
// |
152 |
|
|
Int_t e = 0; |
153 |
|
|
ifstream in; |
154 |
|
|
in.open(flist, ios::in); |
155 |
|
|
char ctime[20]; |
156 |
|
|
const char *nome; |
157 |
|
|
// |
158 |
|
|
// TString *file[17]; |
159 |
|
|
TString fififile; |
160 |
|
|
const char *file; |
161 |
|
|
TString filename; |
162 |
|
|
// |
163 |
|
|
stringstream lfillo; |
164 |
|
|
// |
165 |
|
|
// |
166 |
|
|
// |
167 |
|
|
TTree *tr; |
168 |
|
|
pamela::CalibCalPedEvent *ce = 0; |
169 |
|
|
pamela::PscuHeader *cph = 0; |
170 |
|
|
pamela::EventHeader *ceh = 0; |
171 |
|
|
Long64_t ncalibs = 0; |
172 |
|
|
Int_t s = -1; |
173 |
|
|
Int_t l = 0; |
174 |
|
|
Int_t m = 0; |
175 |
|
|
Int_t ss = 0; |
176 |
|
|
// |
177 |
|
|
while ( e < nfile ){ |
178 |
|
|
if ( flist != "" ){ |
179 |
|
|
in >> ctime; |
180 |
|
|
lfillo.str(""); |
181 |
|
|
lfillo << filename2 << "/"; |
182 |
|
|
lfillo << ctime; |
183 |
|
|
lfile = (TString)lfillo.str().c_str(); |
184 |
|
|
//file = "dw_000000_000.dat"; |
185 |
|
|
// file = emigetFilename(lfile); |
186 |
|
|
fififile = getFilename(lfile); |
187 |
|
|
file = fififile; |
188 |
|
|
lfillo.str(""); |
189 |
|
|
lfillo << file; |
190 |
|
|
sfile = (TString)lfillo.str().c_str(); |
191 |
|
|
} else { |
192 |
|
|
lfillo.str(""); |
193 |
|
|
lfillo << filename2; |
194 |
|
|
lfile = (TString)lfillo.str().c_str(); |
195 |
|
|
// file = "dw_000000_000.dat"; |
196 |
|
|
// file = emigetFilename(lfile); |
197 |
|
|
fififile = getFilename(lfile); |
198 |
|
|
file = fififile; |
199 |
|
|
lfillo.str(""); |
200 |
|
|
lfillo << file; |
201 |
|
|
sfile = (TString)lfillo.str().c_str(); |
202 |
|
|
}; |
203 |
|
|
// |
204 |
|
|
filename = lfile; |
205 |
|
|
nome = filename; |
206 |
|
|
printf("\n Processing file number %i: %s \n\n",e+1,nome); |
207 |
|
|
// |
208 |
|
|
const string fil = (const char *)filename; |
209 |
|
|
Int_t posiz = fil.find("dw_"); |
210 |
|
|
if ( posiz == -1 ) posiz = fil.find("DW_"); |
211 |
|
|
if ( posiz == -1 ) return(-1); |
212 |
|
|
TString year; |
213 |
|
|
stringcopy(year,filename,posiz+3,posiz+5); |
214 |
|
|
const char *ye = year; |
215 |
|
|
TString month; |
216 |
|
|
stringcopy(month,filename,posiz+5,posiz+7); |
217 |
|
|
const char *mo = month; |
218 |
|
|
TString day; |
219 |
|
|
stringcopy(day,filename,posiz+7,posiz+9); |
220 |
|
|
const char *da = day; |
221 |
|
|
TString fno; |
222 |
|
|
stringcopy(fno,filename,posiz+10,posiz+13); |
223 |
|
|
const char *fn = fno; |
224 |
|
|
stringstream unino; |
225 |
|
|
// char *unino = 0; |
226 |
|
|
// unino = Form("%s%s%s%s",ye,mo,da,fn); |
227 |
|
|
unino.str(""); |
228 |
|
|
unino << ye << mo; |
229 |
|
|
unino << da << fn; |
230 |
|
|
// |
231 |
|
|
// upgrade data... |
232 |
|
|
// |
233 |
|
|
TFile *calheadFile = 0; |
234 |
|
|
calheadFile = getEmiFile(filename, "CalibCalPed", "Header"); |
235 |
|
|
TFile *calcalibFile = 0; |
236 |
|
|
calcalibFile = getEmiFile(filename, "CalibCalPed","Event"); |
237 |
|
|
// |
238 |
|
|
const char *filen = filename; |
239 |
|
|
if ( !calheadFile || !calcalibFile ) { |
240 |
|
|
if ( calheadFile ) calheadFile->Close(); |
241 |
|
|
if ( calcalibFile ) calcalibFile->Close(); |
242 |
|
|
printf("\n\nERROR: not able to open file: %s \n",filen); |
243 |
|
|
goto jumpfile; |
244 |
|
|
}; |
245 |
|
|
tr = (TTree*)calheadFile->Get("Pscu"); |
246 |
|
|
tr->AddFriend("CalibCalPed", calcalibFile); |
247 |
|
|
tr->SetBranchAddress("Header", &ceh); |
248 |
|
|
tr->SetBranchAddress("Event", &ce); |
249 |
|
|
ncalibs = tr->GetEntries(); |
250 |
|
|
if ( ncalibs == 0 ) goto oltre; |
251 |
|
|
calo = new CalorimeterCalibScan(); |
252 |
|
|
s = -1; |
253 |
|
|
l = 0; |
254 |
|
|
m = 0; |
255 |
|
|
for (Int_t ci = 0; ci < ncalibs ; ci++){ |
256 |
|
|
tr->GetEntry(ci); |
257 |
|
|
// |
258 |
|
|
// qui si deve definire "s" |
259 |
|
|
// |
260 |
|
|
s++; |
261 |
|
|
if ( s == 4 ) s = 0; |
262 |
|
|
if ( s == 0 ) ss = 0; |
263 |
|
|
if ( s == 1 ) ss = 2; |
264 |
|
|
if ( s == 2 ) ss = 3; |
265 |
|
|
if ( s == 3 ) ss = 1; |
266 |
|
|
// |
267 |
|
|
if ( s == 0 ){ |
268 |
|
|
Double_t noca = (double)ci/100.; |
269 |
|
|
Double_t calno = atof(unino.str().c_str())+noca; |
270 |
|
|
calo->calno = calno; |
271 |
|
|
calibex++; |
272 |
|
|
calo->evno = calibex; |
273 |
|
|
// printf("unino %s atof %f calno = %f calocalno %f \n",unino,atof(unino)+noca,calno,calo->calno); |
274 |
|
|
}; |
275 |
|
|
// |
276 |
|
|
// |
277 |
|
|
// |
278 |
|
|
if (ce->cstwerr[s] != 0 && ce->cperror[s] == 0 ) { |
279 |
|
|
// printf("ci %i , s %i \n",ci,s); |
280 |
|
|
cph = ceh->GetPscuHeader(); |
281 |
|
|
calo->etime[ss] = cph->GetOrbitalTime(); |
282 |
|
|
for ( Int_t d=0 ; d<11 ;d++ ){ |
283 |
|
|
Int_t pre = -1; |
284 |
|
|
if ( s == 2 ) m = 2*d+1; |
285 |
|
|
if ( s == 3 ) m = 2*d; |
286 |
|
|
if ( s == 0 ) m = 2*d; |
287 |
|
|
if ( s == 1 ) m = 2*d+1; |
288 |
|
|
if ( s == 3 ) l = 0; |
289 |
|
|
if ( s == 2 ) l = 0; |
290 |
|
|
if ( s == 1 ) l = 1; |
291 |
|
|
if ( s == 0 ) l = 1; |
292 |
|
|
for ( Int_t j=0; j<96 ;j++){ |
293 |
|
|
if ( j%16 == 0 ) pre++; |
294 |
|
|
calo->calped[l][m][j] = ce->calped[ss][d][j]; |
295 |
|
|
calo->cstwerr[ss] = ce->cstwerr[s]; |
296 |
|
|
calo->cperror[ss] = ce->cperror[s]; |
297 |
|
|
calo->calgood[l][m][j] = ce->calgood[ss][d][j]; |
298 |
|
|
calo->calthr[l][m][pre] = ce->calthr[ss][d][pre]; |
299 |
|
|
calo->calrms[l][m][j] = ce->calrms[ss][d][j]/4.; |
300 |
|
|
calo->calbase[l][m][pre] = ce->calbase[ss][d][pre]; |
301 |
|
|
calo->calvar[l][m][pre] = ce->calvar[ss][d][pre]; |
302 |
|
|
}; |
303 |
|
|
}; |
304 |
|
|
}; |
305 |
|
|
// |
306 |
|
|
if ( s == 3 ){ |
307 |
|
|
trl1->Fill(); |
308 |
|
|
calo = new CalorimeterCalibScan(); |
309 |
|
|
}; |
310 |
|
|
// |
311 |
|
|
}; |
312 |
|
|
fileup++; |
313 |
|
|
// |
314 |
|
|
goto oltre; |
315 |
|
|
jumpfile: printf(" File not processed! \n "); |
316 |
|
|
oltre: |
317 |
|
|
e++; |
318 |
|
|
}; |
319 |
|
|
hfl1->Write(); |
320 |
|
|
hfl1->Close(); |
321 |
|
|
return(0); |
322 |
|
|
} |