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