1 |
mocchiut |
1.1 |
// |
2 |
|
|
// Given a calibration and a data file this program create an ntuple with LEVEL2 calorimeter variables - Emiliano Mocchiutti |
3 |
|
|
// |
4 |
mocchiut |
1.3 |
// CaloCore.cxx version 3.05 (2006-05-30) |
5 |
mocchiut |
1.1 |
// |
6 |
|
|
// The only input needed is the path to the directory created by YODA for the data file you want to analyze. |
7 |
|
|
// |
8 |
|
|
// Changelog: |
9 |
mocchiut |
1.3 |
// |
10 |
mocchiut |
1.11 |
// 3.08 (2006-11-13): Added high energy nuclei capability and "process all events" capability. |
11 |
|
|
// |
12 |
mocchiut |
1.4 |
// 3.04 - 3.05 (2006-05-30): Qlast and nlast are now calculated using 4 (not 8) strips aournd the shower axis. Small bug fixed. |
13 |
mocchiut |
1.2 |
// |
14 |
|
|
// 3.03 - 3.04 (2006-05-23): Forgot to put impx and impy in the PAMELA reference system, fixed. |
15 |
mocchiut |
1.1 |
// |
16 |
|
|
// 3.02 - 3.03 (2006-05-18): updated to be called in DarthVader. Output dimension are now in cm and in the PAMELA reference system. |
17 |
|
|
// |
18 |
|
|
// 3.01 - 3.02 (2006-04-21): when copying entries get size of caclone and not of ca... (shouldn't matter). Fixed increasing file dimension bug when reprocessing. |
19 |
|
|
// Added variable planemax[2], plane of maximum energy release (x and y) in final output. Use ItoRunInfo instead of RunInfo. |
20 |
|
|
// |
21 |
|
|
// 3.00 - 3.01 (2006-04-14): fixed small bug in tagging the track used to determine track-related variables, put in caloprocessing the opening of parameters files, fixed |
22 |
|
|
// small bug in fortran routines |
23 |
|
|
// |
24 |
|
|
// 2.01 - 3.00 (2006-04-14): almost everything has changed. Now it can process one, all or some runs, introduced the final CaloLevel2 class+methods and the |
25 |
|
|
// working class "CaloProcessing", linked to the preliminary tracker flight software v0r00, reads YODA unique output files, |
26 |
|
|
// reduced the number of installed libraries, F77 programs splitted depending on the function contained, introduced the readout and |
27 |
|
|
// processing of self-trigger events, if the tracker provides more than one track all calorimeter track-related variables are saved |
28 |
|
|
// as many times as the number of tracks (via the TClonesArray object in the level2 rootple) and many other small changes. |
29 |
|
|
// |
30 |
|
|
// 2.00 - 2.01 (2006-01-26): bug: wrong calculation of baselines in some cases, fixed. |
31 |
|
|
// |
32 |
|
|
// 1.00 - 2.00 (2006-01-11): use TSQL ROOT classes instead of directly calling MySQL. |
33 |
|
|
// |
34 |
|
|
// 0.00 - 1.00 (2005-09-14): seems working. |
35 |
|
|
// |
36 |
|
|
// 0.00 (2005-09-09): clone of CaloLEVEL2.c . |
37 |
|
|
// |
38 |
|
|
// C/C++ headers |
39 |
|
|
// |
40 |
|
|
#include <fstream> |
41 |
|
|
#include <string.h> |
42 |
|
|
// |
43 |
|
|
// ROOT headers |
44 |
|
|
// |
45 |
|
|
#include <TTree.h> |
46 |
|
|
#include <TClassEdit.h> |
47 |
|
|
#include <TObject.h> |
48 |
|
|
#include <TList.h> |
49 |
mocchiut |
1.8 |
#include <TArrayI.h> |
50 |
mocchiut |
1.1 |
#include <TSystem.h> |
51 |
|
|
#include <TSystemDirectory.h> |
52 |
|
|
#include <TString.h> |
53 |
|
|
#include <TFile.h> |
54 |
|
|
#include <TClass.h> |
55 |
|
|
#include <TCanvas.h> |
56 |
|
|
#include <TH1.h> |
57 |
|
|
#include <TH1F.h> |
58 |
|
|
#include <TH2D.h> |
59 |
|
|
#include <TLatex.h> |
60 |
|
|
#include <TPad.h> |
61 |
|
|
#include <TSQLServer.h> |
62 |
|
|
#include <TSQLRow.h> |
63 |
|
|
#include <TSQLResult.h> |
64 |
|
|
#include <TClonesArray.h> |
65 |
|
|
#include <TStreamerInfo.h> |
66 |
|
|
// |
67 |
mocchiut |
1.20 |
// This program headers |
68 |
|
|
// |
69 |
|
|
#include <RunInfo.h> |
70 |
|
|
// |
71 |
mocchiut |
1.1 |
// YODA headers |
72 |
|
|
// |
73 |
|
|
#include <PamelaRun.h> |
74 |
|
|
#include <physics/trigger/TriggerEvent.h> |
75 |
|
|
// |
76 |
|
|
// This program headers |
77 |
|
|
// |
78 |
|
|
#include <CaloCore.h> |
79 |
mocchiut |
1.13 |
#include <CaloLevel1.h> |
80 |
mocchiut |
1.1 |
#include <CaloLevel2.h> |
81 |
mocchiut |
1.22 |
#include <CaloLevel0.h> |
82 |
mocchiut |
1.1 |
#include <CaloVerl2.h> |
83 |
|
|
// |
84 |
|
|
// Tracker classes headers and definitions |
85 |
|
|
// |
86 |
|
|
#include <TrkLevel2.h> |
87 |
|
|
// |
88 |
|
|
using namespace std; |
89 |
|
|
// |
90 |
|
|
// CORE ROUTINE |
91 |
|
|
// |
92 |
mocchiut |
1.32 |
int CaloCore(UInt_t run, TFile *file, GL_TABLES *glt, Int_t calargc, char *calargv[]){ |
93 |
mocchiut |
1.1 |
// |
94 |
|
|
// Set these to true to have a very verbose output. |
95 |
|
|
// |
96 |
|
|
Bool_t verbose = false; |
97 |
|
|
Bool_t debug = false; |
98 |
|
|
// |
99 |
mocchiut |
1.21 |
Bool_t crosst = true; |
100 |
mocchiut |
1.36 |
Bool_t ctground = false; |
101 |
|
|
// Bool_t ctground = true; |
102 |
mocchiut |
1.21 |
// |
103 |
mocchiut |
1.11 |
Bool_t trackanyway = true; |
104 |
|
|
// |
105 |
|
|
Float_t rigdefault = 50.; |
106 |
mocchiut |
1.35 |
// |
107 |
mocchiut |
1.11 |
Bool_t hZn = true; |
108 |
|
|
// |
109 |
|
|
Bool_t withtrk = true; |
110 |
|
|
// |
111 |
|
|
Bool_t st = true; |
112 |
|
|
// |
113 |
mocchiut |
1.13 |
Bool_t getl1 = true; |
114 |
|
|
// |
115 |
mocchiut |
1.23 |
Bool_t mechal = false; |
116 |
|
|
// |
117 |
mocchiut |
1.30 |
Bool_t checksimu = true; |
118 |
|
|
// |
119 |
mocchiut |
1.1 |
// Output directory is the working directoy. |
120 |
|
|
// |
121 |
|
|
const char* outdir = gSystem->DirName(gSystem->DirName(file->GetPath())); |
122 |
|
|
// |
123 |
|
|
Int_t ri = 0; |
124 |
mocchiut |
1.26 |
TString processFolder = Form("calorimeterFolder_%u",run); |
125 |
mocchiut |
1.1 |
if ( calargc > 0 ){ |
126 |
|
|
ri = 0; |
127 |
|
|
while ( ri < calargc ){ |
128 |
|
|
if ( !strcmp(calargv[ri],"-processFolder") ) { |
129 |
|
|
if ( calargc < ri+1 ){ |
130 |
|
|
throw -3; |
131 |
|
|
}; |
132 |
|
|
processFolder = (TString)calargv[ri+1]; |
133 |
|
|
ri++; |
134 |
|
|
}; |
135 |
|
|
if ( !strcmp(calargv[ri],"-v") || !strcmp(calargv[ri],"--verbose") ) { |
136 |
|
|
verbose = true; |
137 |
|
|
}; |
138 |
|
|
if ( !strcmp(calargv[ri],"-g") || !strcmp(calargv[ri],"--debug") ) { |
139 |
mocchiut |
1.13 |
verbose = true; |
140 |
mocchiut |
1.1 |
debug = true; |
141 |
|
|
}; |
142 |
mocchiut |
1.11 |
if ( !strcmp(calargv[ri],"--alltracks") ) { |
143 |
|
|
trackanyway = true; |
144 |
|
|
}; |
145 |
mocchiut |
1.23 |
if ( !strcmp(calargv[ri],"--use-default-alig") ) { |
146 |
|
|
mechal = true; |
147 |
|
|
}; |
148 |
mocchiut |
1.21 |
if ( !strcmp(calargv[ri],"--no-crosstalk") ) { |
149 |
|
|
crosst = false; |
150 |
|
|
}; |
151 |
mocchiut |
1.34 |
if ( !strcmp(calargv[ri],"--flight-crosstalk") ) { |
152 |
|
|
ctground = false; |
153 |
|
|
}; |
154 |
|
|
if ( !strcmp(calargv[ri],"--ground-crosstalk") ) { |
155 |
|
|
ctground = true; |
156 |
|
|
}; |
157 |
mocchiut |
1.11 |
if ( !strcmp(calargv[ri],"--no-tracker") ) { |
158 |
|
|
withtrk = false; |
159 |
|
|
}; |
160 |
|
|
if ( !strcmp(calargv[ri],"--with-tracker") ) { |
161 |
|
|
withtrk = true; |
162 |
|
|
}; |
163 |
|
|
if ( !strcmp(calargv[ri],"--defrig") ) { |
164 |
|
|
if ( calargc < ri+1 ){ |
165 |
|
|
throw -3; |
166 |
|
|
}; |
167 |
|
|
rigdefault = atof(calargv[ri+1]); |
168 |
|
|
ri++; |
169 |
|
|
}; |
170 |
|
|
if ( !strcmp(calargv[ri],"--no-alltracks") ) { |
171 |
|
|
trackanyway = false; |
172 |
|
|
}; |
173 |
|
|
if ( !strcmp(calargv[ri],"--highZnuclei") ) { |
174 |
|
|
hZn = true; |
175 |
|
|
}; |
176 |
|
|
if ( !strcmp(calargv[ri],"--no-highZnuclei") ) { |
177 |
|
|
hZn = false; |
178 |
|
|
}; |
179 |
|
|
if ( !strcmp(calargv[ri],"--selftrigger") ) { |
180 |
|
|
st = true; |
181 |
|
|
}; |
182 |
|
|
if ( !strcmp(calargv[ri],"--no-selftrigger") ) { |
183 |
|
|
st = false; |
184 |
|
|
}; |
185 |
mocchiut |
1.13 |
if ( !strcmp(calargv[ri],"--no-level1") ) { |
186 |
|
|
getl1 = false; |
187 |
|
|
}; |
188 |
mocchiut |
1.30 |
if ( !strcmp(calargv[ri],"--ignore-h20") ) { |
189 |
|
|
checksimu = false; |
190 |
|
|
}; |
191 |
mocchiut |
1.11 |
if ( !strcmp(calargv[ri],"--help") ) { |
192 |
|
|
printf("\n\n CALORIMETER HELP CALLED\n\n"); |
193 |
|
|
printf(" CaloCore options: \n"); |
194 |
|
|
printf(" -v | --verbose be verbose\n"); |
195 |
|
|
printf(" -g | --debug be really verbose\n"); |
196 |
|
|
printf(" --defrig rig rig is the default rigidity in GV to be used to\n"); |
197 |
|
|
printf(" obtain calorimeter variables in the routines\n"); |
198 |
|
|
printf(" \"alltracks\" and \"higZnuclei\" [default = 50]\n"); |
199 |
|
|
printf(" --alltracks fill the track related variables even in the case\n"); |
200 |
|
|
printf(" of no tracks from tracker and no selftrigger event\n"); |
201 |
mocchiut |
1.14 |
printf(" when we have a calorimeter fit for both views [default]\n"); |
202 |
|
|
printf(" --no-alltracks fill the track related variables only in the case\n"); |
203 |
|
|
printf(" of a good track from tracker or selftrigger\n"); |
204 |
mocchiut |
1.11 |
printf(" --highZnuclei call the routine to analyze high Z nuclei\n"); |
205 |
|
|
printf(" selftrigger events [default]\n"); |
206 |
|
|
printf(" --no-highZnuclei do not call the routine to analyze high Z nuclei\n"); |
207 |
|
|
printf(" selftrigger events\n"); |
208 |
|
|
printf(" --no-tracker do not use tracker level2\n"); |
209 |
|
|
printf(" --with-tracker use tracker level2 [default]\n"); |
210 |
mocchiut |
1.21 |
printf(" --no-crosstalk do not apply crosstalk corrections\n"); |
211 |
mocchiut |
1.37 |
printf(" --ground-crosstalk apply ground crosstalk corrections\n"); |
212 |
|
|
printf(" --flight-crosstalk apply flight crosstalk corrections [default]\n"); |
213 |
mocchiut |
1.11 |
printf(" --selftrigger process selftrigger events [default]\n"); |
214 |
|
|
printf(" --no-selftrigger skip selftrigger events\n"); |
215 |
mocchiut |
1.13 |
printf(" --no-level1 do not save Level1 TBranch\n"); |
216 |
mocchiut |
1.30 |
printf(" --ignore-h20 do not check if it is a file from simulations\n"); |
217 |
mocchiut |
1.27 |
printf(" --use-default-alig use default mechanical alignement (defined in CaloLevel1.h)\n"); |
218 |
mocchiut |
1.11 |
throw -114; |
219 |
|
|
}; |
220 |
mocchiut |
1.1 |
ri++; |
221 |
|
|
}; |
222 |
|
|
}; |
223 |
|
|
// |
224 |
mocchiut |
1.13 |
if ( verbose ){ |
225 |
|
|
printf("\n"); |
226 |
|
|
if ( getl1 ) printf(" Saving calorimeter level1 data \n"); |
227 |
|
|
if ( st ) printf(" Calling selftrigger subroutine \n"); |
228 |
|
|
if ( hZn ) printf(" Calling high energy nuclei subroutine \n"); |
229 |
|
|
if ( trackanyway ) printf(" Filling track related variables for all the possible tracks \n"); |
230 |
|
|
if ( hZn || trackanyway ) printf(" => default assumed rigidity %f \n",rigdefault); |
231 |
|
|
if ( withtrk ) printf(" Using tracker level2 data \n"); |
232 |
mocchiut |
1.27 |
if ( mechal ) printf(" Using default mechanical alignement (defined in CaloLevel1.h)\n"); |
233 |
mocchiut |
1.34 |
if ( crosst ){ |
234 |
|
|
printf(" Applying cross-talk corrections \n"); |
235 |
|
|
if ( ctground ){ |
236 |
|
|
printf(" => Using ground cross-talk coefficients \n"); |
237 |
|
|
} else { |
238 |
|
|
printf(" => Using flight cross-talk coefficients \n"); |
239 |
|
|
}; |
240 |
|
|
} else { |
241 |
|
|
printf(" Do not applying cross-talk corrections \n"); |
242 |
|
|
}; |
243 |
|
|
if ( !checksimu ) printf(" Check on h20 TTree in level2 file skipped \n"); |
244 |
mocchiut |
1.13 |
printf("\n"); |
245 |
|
|
}; |
246 |
mocchiut |
1.11 |
// |
247 |
mocchiut |
1.1 |
// Working filename |
248 |
|
|
// |
249 |
|
|
TString outputfile; |
250 |
|
|
stringstream name; |
251 |
|
|
name.str(""); |
252 |
|
|
name << outdir << "/"; |
253 |
|
|
// |
254 |
|
|
// Variables. |
255 |
|
|
// |
256 |
|
|
TTree *tracker = 0; |
257 |
|
|
TTree *calo = 0; |
258 |
|
|
TTree *caloclone = 0; |
259 |
|
|
Bool_t reproc = false; |
260 |
|
|
Bool_t reprocall = false; |
261 |
mocchiut |
1.8 |
UInt_t nevents = 0; |
262 |
mocchiut |
1.1 |
UInt_t nobefrun = 0; |
263 |
|
|
UInt_t noaftrun = 0; |
264 |
|
|
UInt_t numbofrun = 0; |
265 |
mocchiut |
1.8 |
UInt_t totnorun = 0; |
266 |
mocchiut |
1.1 |
// |
267 |
|
|
Int_t code = 0; |
268 |
|
|
Int_t sgnl; |
269 |
|
|
// |
270 |
|
|
// calorimeter level2 classes |
271 |
|
|
// |
272 |
mocchiut |
1.13 |
CaloLevel1 *c1 = 0; |
273 |
|
|
CaloLevel1 *c1clone = 0; |
274 |
|
|
if ( getl1 ){ |
275 |
|
|
c1 = new CaloLevel1(); |
276 |
|
|
c1clone = new CaloLevel1(); |
277 |
|
|
}; |
278 |
|
|
// |
279 |
|
|
// calorimeter level2 classes |
280 |
|
|
// |
281 |
mocchiut |
1.1 |
CaloLevel2 *ca = new CaloLevel2(); |
282 |
|
|
CaloLevel2 *caclone = new CaloLevel2(); |
283 |
|
|
// |
284 |
|
|
TrkLevel2 *trk = new TrkLevel2(); |
285 |
mocchiut |
1.8 |
Int_t nevtrkl2 = 0; |
286 |
mocchiut |
1.1 |
// |
287 |
|
|
UInt_t procev = 0; |
288 |
|
|
// |
289 |
mocchiut |
1.8 |
// define variables where to store the absolute run header and run trailer times (unsigned long long integers, when set to a number use to store the correct number). |
290 |
mocchiut |
1.1 |
// |
291 |
mocchiut |
1.8 |
UInt_t runheadtime = 0; |
292 |
|
|
UInt_t runtrailtime = 0; |
293 |
mocchiut |
1.1 |
UInt_t evfrom = 0; |
294 |
|
|
UInt_t evto = 0; |
295 |
mocchiut |
1.8 |
UInt_t totfileentries = 0; |
296 |
|
|
UInt_t idRun = 0; |
297 |
mocchiut |
1.1 |
Int_t id_reg_run=-1; |
298 |
|
|
stringstream ftmpname; |
299 |
|
|
TString fname; |
300 |
|
|
// |
301 |
|
|
// define variables for opening and reading level0 file |
302 |
|
|
// |
303 |
|
|
TFile *l0File = 0; |
304 |
|
|
TTree *l0tr = 0; |
305 |
mocchiut |
1.24 |
TTree *softinfo = 0; |
306 |
mocchiut |
1.1 |
TBranch *l0head = 0; |
307 |
|
|
TBranch *l0calo = 0; |
308 |
|
|
TBranch *l0trig = 0; |
309 |
mocchiut |
1.8 |
pamela::EventHeader *eh = 0; |
310 |
|
|
pamela::PscuHeader *ph = 0; |
311 |
mocchiut |
1.1 |
pamela::trigger::TriggerEvent *trig = 0; |
312 |
mocchiut |
1.24 |
Int_t yodaver = 0; |
313 |
mocchiut |
1.1 |
// |
314 |
|
|
// Define some basic variables |
315 |
|
|
// |
316 |
mocchiut |
1.22 |
CaloLevel0 *event = new CaloLevel0(); // NOTICE: very important to call here the constructor! |
317 |
mocchiut |
1.21 |
event->SetCrossTalk(crosst); |
318 |
mocchiut |
1.34 |
event->SetCrossTalkType(ctground); |
319 |
mocchiut |
1.1 |
stringstream file2; |
320 |
|
|
stringstream file3; |
321 |
|
|
stringstream qy; |
322 |
|
|
// Bool_t imtrack = false; |
323 |
|
|
Bool_t filled = false; |
324 |
|
|
// |
325 |
mocchiut |
1.8 |
UInt_t caloevents = 0; |
326 |
mocchiut |
1.1 |
stringstream calfile; |
327 |
|
|
stringstream aligfile; |
328 |
|
|
// |
329 |
|
|
Int_t i = -1; |
330 |
|
|
Int_t itr = -1; |
331 |
|
|
Int_t badevent = 0; |
332 |
|
|
Int_t totevent = 0; |
333 |
|
|
// |
334 |
mocchiut |
1.8 |
UInt_t atime = 0; |
335 |
mocchiut |
1.1 |
// |
336 |
|
|
Int_t S3 = 0; |
337 |
|
|
Int_t S2 = 0; |
338 |
|
|
Int_t S12 = 0; |
339 |
|
|
Int_t S11 = 0; |
340 |
|
|
UInt_t re = 0; |
341 |
mocchiut |
1.9 |
UInt_t jumped = 0; |
342 |
mocchiut |
1.1 |
// |
343 |
|
|
TString caloversion; |
344 |
|
|
ItoRunInfo *runinfo = 0; |
345 |
mocchiut |
1.8 |
TArrayI *runlist = 0; |
346 |
mocchiut |
1.1 |
// |
347 |
|
|
Float_t tmptrigty = -1.; |
348 |
|
|
Int_t ntrkentry = 0; |
349 |
|
|
GL_PARAM *q4 = new GL_PARAM(); |
350 |
mocchiut |
1.8 |
UInt_t tttrkpar1 = 0; |
351 |
mocchiut |
1.1 |
Bool_t trkpar1 = true; |
352 |
|
|
GL_ROOT *glroot = new GL_ROOT(); |
353 |
mocchiut |
1.8 |
GL_TIMESYNC *dbtime = 0; |
354 |
mocchiut |
1.1 |
// |
355 |
mocchiut |
1.15 |
Long64_t maxsize = 10000000000LL; |
356 |
|
|
TTree::SetMaxTreeSize(maxsize); |
357 |
mocchiut |
1.1 |
// |
358 |
|
|
// |
359 |
|
|
TFile *tempfile = 0; |
360 |
|
|
TTree *tempcalo = 0; |
361 |
mocchiut |
1.30 |
Bool_t myfold = false; |
362 |
mocchiut |
1.1 |
stringstream tempname; |
363 |
|
|
stringstream calofolder; |
364 |
|
|
tempname.str(""); |
365 |
|
|
tempname << outdir; |
366 |
|
|
tempname << "/" << processFolder.Data(); |
367 |
|
|
calofolder.str(""); |
368 |
|
|
calofolder << tempname.str().c_str(); |
369 |
|
|
tempname << "/calotree_run"; |
370 |
|
|
tempname << run << ".root"; |
371 |
|
|
// |
372 |
|
|
// As a first thing we must check what we have to do: if run = -1 we must process all events in the file has been passed |
373 |
|
|
// if run != -1 we must process only that run but first we have to check if the branch calorimeter already exist in the file |
374 |
|
|
// if it exists we are reprocessing data and we must delete that entries, if not we must create it. |
375 |
|
|
// |
376 |
mocchiut |
1.8 |
if ( run == 0 ) reproc = true; |
377 |
mocchiut |
1.1 |
// |
378 |
|
|
// |
379 |
|
|
// |
380 |
|
|
if ( !file->IsOpen() ){ |
381 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: cannot open file for writing\n"); |
382 |
|
|
throw -101; |
383 |
|
|
}; |
384 |
|
|
// |
385 |
mocchiut |
1.11 |
if ( withtrk ){ |
386 |
|
|
// |
387 |
|
|
// Does it contain the Tracker tree? |
388 |
|
|
// |
389 |
|
|
tracker = (TTree*)file->Get("Tracker"); |
390 |
|
|
if ( !tracker ) { |
391 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: no tracker tree\n"); |
392 |
|
|
code = -102; |
393 |
|
|
goto closeandexit; |
394 |
|
|
}; |
395 |
|
|
tracker->SetBranchAddress("TrkLevel2",&trk); |
396 |
|
|
nevtrkl2 = tracker->GetEntries(); |
397 |
mocchiut |
1.1 |
}; |
398 |
|
|
// |
399 |
mocchiut |
1.30 |
// Is it a file from simulations? |
400 |
|
|
// |
401 |
|
|
if ( checksimu ){ |
402 |
|
|
TTree *h20 = (TTree*)file->Get("h20"); |
403 |
|
|
if ( h20 ){ |
404 |
|
|
// |
405 |
|
|
// yes! |
406 |
|
|
// |
407 |
|
|
crosst = false; |
408 |
mocchiut |
1.34 |
ctground = true; |
409 |
mocchiut |
1.30 |
mechal = true; |
410 |
|
|
if ( verbose ) printf("\n\n SIMULATION!!! Setting --use-default-alig and --no-crosstalk flags!\n\n"); |
411 |
|
|
h20->Delete(); |
412 |
|
|
}; |
413 |
|
|
}; |
414 |
|
|
// |
415 |
mocchiut |
1.1 |
// Call runinfo |
416 |
|
|
// |
417 |
|
|
sgnl = 0; |
418 |
|
|
runinfo = new ItoRunInfo(file); |
419 |
|
|
// |
420 |
|
|
// update versioning information and retrieve informations about the run to be processed |
421 |
|
|
// |
422 |
|
|
caloversion = CaloInfo(false); |
423 |
|
|
sgnl = runinfo->Update(run,"CALO",caloversion); |
424 |
|
|
// |
425 |
|
|
if ( sgnl ){ |
426 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: RunInfo exited with non-zero status\n"); |
427 |
|
|
code = sgnl; |
428 |
|
|
goto closeandexit; |
429 |
|
|
} else { |
430 |
|
|
sgnl = 0; |
431 |
|
|
}; |
432 |
|
|
// |
433 |
|
|
// number of events in the file BEFORE the first event of our run |
434 |
|
|
// |
435 |
|
|
nobefrun = runinfo->GetFirstEntry(); |
436 |
|
|
// |
437 |
|
|
// total number of events in the file |
438 |
|
|
// |
439 |
|
|
totfileentries = runinfo->GetFileEntries(); |
440 |
|
|
// |
441 |
|
|
// first file entry AFTER the last event of our run |
442 |
|
|
// |
443 |
|
|
noaftrun = runinfo->GetLastEntry() + 1; |
444 |
|
|
// |
445 |
|
|
// number of run to be processed |
446 |
|
|
// |
447 |
|
|
numbofrun = runinfo->GetNoRun(); |
448 |
|
|
// |
449 |
|
|
// number of runs in the file |
450 |
|
|
// |
451 |
|
|
totnorun = runinfo->GetRunEntries(); |
452 |
|
|
// |
453 |
|
|
// Does it contain already a Calorimeter branch? if so we are reprocessing data, if not we must create it. |
454 |
|
|
// |
455 |
|
|
caloclone = (TTree*)file->Get("Calorimeter"); |
456 |
|
|
// |
457 |
|
|
if ( !caloclone ){ |
458 |
|
|
reproc = false; |
459 |
mocchiut |
1.8 |
if ( run == 0 && verbose ) printf(" CALORIMETER - WARNING: you are reprocessing data but calorimeter tree does not exist!\n"); |
460 |
|
|
if ( runinfo->IsReprocessing() && run != 0 && verbose ) printf(" CALORIMETER - WARNING: it seems you are not reprocessing data but calorimeter\n versioning information already exists in RunInfo.\n"); |
461 |
mocchiut |
1.1 |
// |
462 |
|
|
} else { |
463 |
|
|
// |
464 |
mocchiut |
1.15 |
caloclone->SetAutoSave(900000000000000LL); |
465 |
mocchiut |
1.1 |
reproc = true; |
466 |
|
|
// |
467 |
|
|
if ( verbose ) printf("\n Preparing the pre-processing...\n"); |
468 |
|
|
// |
469 |
mocchiut |
1.28 |
if ( run == 0 || totnorun == 1 ){ |
470 |
mocchiut |
1.1 |
// |
471 |
|
|
// if we are reprocessing everything we don't need to copy any old event and we can just create a new branch in the clone tree and jump steps 4/5/7. |
472 |
|
|
// |
473 |
|
|
if ( verbose ) printf("\n CALORIMETER - WARNING: Reprocessing all runs in the file\n"); |
474 |
|
|
reprocall = true; |
475 |
|
|
// |
476 |
|
|
} else { |
477 |
|
|
// |
478 |
|
|
// we are reprocessing a single run |
479 |
|
|
// |
480 |
mocchiut |
1.8 |
if ( verbose ) printf("\n CALORIMETER - WARNING: Reprocessing run number %u \n",run); |
481 |
mocchiut |
1.1 |
reprocall = false; |
482 |
|
|
// |
483 |
|
|
// |
484 |
|
|
// |
485 |
mocchiut |
1.30 |
gSystem->MakeDirectory(calofolder.str().c_str()); |
486 |
|
|
myfold = true; |
487 |
mocchiut |
1.1 |
tempfile = new TFile(tempname.str().c_str(),"RECREATE"); |
488 |
|
|
tempcalo = caloclone->CloneTree(-1,"fast"); |
489 |
|
|
tempcalo->SetName("Calorimeter-old"); |
490 |
|
|
tempfile->Write(); |
491 |
|
|
tempfile->Close(); |
492 |
|
|
}; |
493 |
|
|
// |
494 |
|
|
// delete old tree |
495 |
|
|
// |
496 |
|
|
caloclone->Delete("all"); |
497 |
|
|
// |
498 |
|
|
if ( verbose ) printf("\n ...done!\n"); |
499 |
|
|
// |
500 |
|
|
}; |
501 |
|
|
// |
502 |
|
|
// create calorimeter tree calo |
503 |
|
|
// |
504 |
|
|
file->cd(); |
505 |
|
|
calo = new TTree("Calorimeter-new","PAMELA Level2 calorimeter data"); |
506 |
mocchiut |
1.15 |
calo->SetAutoSave(900000000000000LL); |
507 |
pam-fi |
1.16 |
ca->Set(); |
508 |
mocchiut |
1.1 |
calo->Branch("CaloLevel2","CaloLevel2",&ca); |
509 |
mocchiut |
1.13 |
if ( getl1 ) calo->Branch("CaloLevel1","CaloLevel1",&c1); |
510 |
mocchiut |
1.1 |
// |
511 |
|
|
if ( reproc && !reprocall ){ |
512 |
|
|
// |
513 |
|
|
// |
514 |
|
|
// |
515 |
|
|
tempfile = new TFile(tempname.str().c_str(),"READ"); |
516 |
|
|
caloclone = (TTree*)tempfile->Get("Calorimeter-old"); |
517 |
mocchiut |
1.15 |
caloclone->SetAutoSave(900000000000000LL); |
518 |
mocchiut |
1.1 |
caloclone->SetBranchAddress("CaloLevel2",&caclone); |
519 |
mocchiut |
1.13 |
TBranch *havel1 = caloclone->GetBranch("CaloLevel1"); |
520 |
|
|
if ( !havel1 && getl1 ) throw -117; |
521 |
|
|
if ( havel1 && !getl1 ) throw -118; |
522 |
|
|
if ( getl1 ) caloclone->SetBranchAddress("CaloLevel1",&c1clone); |
523 |
mocchiut |
1.1 |
// |
524 |
|
|
if ( nobefrun > 0 ){ |
525 |
|
|
if ( verbose ) printf("\n Pre-processing: copying events from the old tree before the processed run\n"); |
526 |
mocchiut |
1.8 |
if ( verbose ) printf(" Copying %u events in the file which are before the beginning of the run %u \n",nobefrun,run); |
527 |
mocchiut |
1.1 |
if ( verbose ) printf(" Start copying at event number 0, end copying at event number %u \n",nobefrun); |
528 |
|
|
for (UInt_t j = 0; j < nobefrun; j++){ |
529 |
|
|
// |
530 |
|
|
caloclone->GetEntry(j); |
531 |
|
|
// |
532 |
|
|
// copy caclone to ca |
533 |
|
|
// |
534 |
mocchiut |
1.13 |
if ( getl1 ) memcpy(&c1,&c1clone,sizeof(c1clone)); |
535 |
mocchiut |
1.1 |
memcpy(&ca,&caclone,sizeof(caclone)); |
536 |
|
|
// |
537 |
|
|
// Fill entry in the new tree |
538 |
|
|
// |
539 |
|
|
calo->Fill(); |
540 |
|
|
// |
541 |
mocchiut |
1.13 |
if ( getl1 ) c1->Clear(); |
542 |
mocchiut |
1.6 |
ca->Clear(); |
543 |
|
|
// |
544 |
mocchiut |
1.1 |
}; |
545 |
|
|
if ( verbose ) printf(" Finished successful copying!\n"); |
546 |
|
|
}; |
547 |
|
|
}; |
548 |
|
|
// |
549 |
|
|
// Get the list of run to be processed |
550 |
|
|
// |
551 |
|
|
runlist = runinfo->GetRunList(); |
552 |
|
|
// |
553 |
|
|
// Loop over the run to be processed |
554 |
|
|
// |
555 |
|
|
for (UInt_t irun=0; irun < numbofrun; irun++){ |
556 |
|
|
// |
557 |
|
|
badevent = 0; |
558 |
|
|
// |
559 |
|
|
idRun = runlist->At(irun); |
560 |
|
|
if ( verbose ) printf("\n\n\n ####################################################################### \n"); |
561 |
mocchiut |
1.8 |
if ( verbose ) printf(" PROCESSING RUN NUMBER %u \n",idRun); |
562 |
mocchiut |
1.1 |
if ( verbose ) printf(" ####################################################################### \n\n\n"); |
563 |
|
|
// |
564 |
|
|
sgnl = runinfo->GetRunInfo(idRun); |
565 |
|
|
if ( sgnl ){ |
566 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: RunInfo exited with non-zero status\n"); |
567 |
|
|
code = sgnl; |
568 |
|
|
goto closeandexit; |
569 |
|
|
} else { |
570 |
|
|
sgnl = 0; |
571 |
|
|
}; |
572 |
mocchiut |
1.8 |
id_reg_run = runinfo->ID_ROOT_L0; |
573 |
mocchiut |
1.1 |
runheadtime = runinfo->RUNHEADER_TIME; |
574 |
|
|
runtrailtime = runinfo->RUNTRAILER_TIME; |
575 |
mocchiut |
1.8 |
evfrom = runinfo->EV_FROM; |
576 |
|
|
evto = runinfo->EV_TO; |
577 |
mocchiut |
1.1 |
// |
578 |
|
|
if ( id_reg_run == -1 ){ |
579 |
mocchiut |
1.8 |
if ( verbose ) printf("\n CALORIMETER - ERROR: no run with ID_RUN = %u \n\n Exiting... \n\n",idRun); |
580 |
mocchiut |
1.1 |
code = -5; |
581 |
|
|
goto closeandexit; |
582 |
|
|
}; |
583 |
|
|
// |
584 |
mocchiut |
1.8 |
// prepare the timesync for the db |
585 |
|
|
// |
586 |
mocchiut |
1.32 |
TString host = glt->CGetHost(); |
587 |
|
|
TString user = glt->CGetUser(); |
588 |
|
|
TString psw = glt->CGetPsw(); |
589 |
|
|
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
590 |
|
|
if ( !dbc->IsConnected() ) throw -116; |
591 |
mocchiut |
1.33 |
stringstream myquery; |
592 |
|
|
myquery.str(""); |
593 |
|
|
myquery << "SET time_zone='+0:00'"; |
594 |
|
|
dbc->Query(myquery.str().c_str()); |
595 |
mocchiut |
1.32 |
// |
596 |
mocchiut |
1.31 |
// if ( !dbc->IsConnected() ) throw -116; |
597 |
mocchiut |
1.8 |
dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc); |
598 |
|
|
// |
599 |
mocchiut |
1.1 |
// Search in the DB the path and name of the LEVEL0 file to be processed. |
600 |
|
|
// |
601 |
mocchiut |
1.31 |
// if ( !dbc->IsConnected() ) throw -116; |
602 |
mocchiut |
1.8 |
glroot->Query_GL_ROOT(runinfo->ID_ROOT_L0,dbc); |
603 |
mocchiut |
1.1 |
// |
604 |
|
|
ftmpname.str(""); |
605 |
|
|
ftmpname << glroot->PATH.Data() << "/"; |
606 |
|
|
ftmpname << glroot->NAME.Data(); |
607 |
|
|
fname = ftmpname.str().c_str(); |
608 |
|
|
// |
609 |
|
|
// print out informations |
610 |
|
|
// |
611 |
mocchiut |
1.8 |
totevent = runinfo->NEVENTS; |
612 |
mocchiut |
1.1 |
if ( verbose ) printf("\n LEVEL0 data file: %s \n",fname.Data()); |
613 |
mocchiut |
1.8 |
if ( verbose ) printf(" RUN HEADER absolute time is: %u \n",runheadtime); |
614 |
|
|
if ( verbose ) printf(" RUN TRAILER absolute time is: %u \n",runtrailtime); |
615 |
|
|
if ( verbose ) printf(" %i events to be processed for run %u: from %i to %i (reg entries)\n\n",totevent,idRun,evfrom,evfrom+totevent); |
616 |
mocchiut |
1.1 |
// |
617 |
|
|
// Open Level0 file |
618 |
|
|
// |
619 |
|
|
l0File = new TFile(fname.Data()); |
620 |
|
|
if ( !l0File ) { |
621 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: problems opening Level0 file\n"); |
622 |
|
|
code = -6; |
623 |
|
|
goto closeandexit; |
624 |
|
|
}; |
625 |
|
|
l0tr = (TTree*)l0File->Get("Physics"); |
626 |
|
|
if ( !l0tr ) { |
627 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: no Physics tree in Level0 file\n"); |
628 |
|
|
l0File->Close(); |
629 |
|
|
code = -7; |
630 |
|
|
goto closeandexit; |
631 |
|
|
}; |
632 |
|
|
l0head = l0tr->GetBranch("Header"); |
633 |
|
|
if ( !l0head ) { |
634 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: no Header branch in Level0 tree\n"); |
635 |
|
|
l0File->Close(); |
636 |
|
|
code = -8; |
637 |
|
|
goto closeandexit; |
638 |
|
|
}; |
639 |
|
|
l0calo = l0tr->GetBranch("Calorimeter"); |
640 |
|
|
if ( !l0calo ) { |
641 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: no Calorimeter branch in Level0 tree\n"); |
642 |
|
|
l0File->Close(); |
643 |
|
|
code = -103; |
644 |
|
|
goto closeandexit; |
645 |
|
|
}; |
646 |
|
|
l0trig = l0tr->GetBranch("Trigger"); |
647 |
|
|
if ( !l0trig ) { |
648 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: no Trigger branch in Level0 tree\n"); |
649 |
|
|
l0File->Close(); |
650 |
|
|
code = -104; |
651 |
|
|
goto closeandexit; |
652 |
|
|
}; |
653 |
|
|
// |
654 |
|
|
l0tr->SetBranchAddress("Trigger", &trig); |
655 |
mocchiut |
1.8 |
l0tr->SetBranchAddress("Header", &eh); |
656 |
mocchiut |
1.1 |
// |
657 |
mocchiut |
1.24 |
softinfo = (TTree*)l0File->Get("SoftInfo"); |
658 |
|
|
if ( softinfo ){ |
659 |
|
|
softinfo->SetBranchAddress("SoftInfo",&yodaver); |
660 |
|
|
softinfo->GetEntry(0); |
661 |
|
|
}; |
662 |
|
|
if ( debug ) printf(" LEVEL0 FILE GENERATED WITH YODA VERSION %i \n",yodaver); |
663 |
|
|
// |
664 |
mocchiut |
1.38 |
if ( withtrk ){ |
665 |
|
|
if ( trkpar1 || ( tttrkpar1 != 0 && tttrkpar1 < runheadtime ) ){ |
666 |
|
|
trkpar1 = false; |
667 |
|
|
Int_t glpar = q4->Query_GL_PARAM(runinfo->RUNHEADER_TIME,1,dbc); |
668 |
|
|
if ( glpar < 0 ){ |
669 |
|
|
code = glpar; |
670 |
|
|
goto closeandexit; |
671 |
|
|
}; |
672 |
|
|
tttrkpar1 = q4->TO_TIME; |
673 |
|
|
// ---------------------------- |
674 |
|
|
// Read the magnetic field |
675 |
|
|
// ---------------------------- |
676 |
|
|
if ( verbose ) printf(" Reading magnetic field maps at %s\n",(q4->PATH+q4->NAME).Data()); |
677 |
|
|
trk->LoadField(q4->PATH+q4->NAME); |
678 |
|
|
if ( verbose ) printf("\n"); |
679 |
|
|
}; |
680 |
|
|
}; |
681 |
|
|
// |
682 |
|
|
// Close DB connection |
683 |
|
|
// |
684 |
|
|
if ( dbc ){ |
685 |
|
|
dbc->Close(); |
686 |
|
|
delete dbc; |
687 |
|
|
}; |
688 |
|
|
// |
689 |
|
|
// |
690 |
mocchiut |
1.1 |
// Construct the event object, look for the calibration which include the first header |
691 |
|
|
// |
692 |
|
|
sgnl = 0; |
693 |
|
|
if ( verbose ) printf(" Check for calorimeter calibrations and initialize event object \n"); |
694 |
mocchiut |
1.31 |
// if ( !dbc->IsConnected() ) throw -116; |
695 |
mocchiut |
1.32 |
event->ProcessingInit(glt,runheadtime,sgnl,l0tr,debug,verbose); |
696 |
mocchiut |
1.1 |
if ( verbose ) printf("\n"); |
697 |
|
|
if ( sgnl == 100 ) { |
698 |
|
|
code = sgnl; |
699 |
|
|
if ( verbose ) printf(" CALORIMETER - WARNING: run header not included in any calibration interval\n"); |
700 |
|
|
sgnl = 0; |
701 |
|
|
}; |
702 |
|
|
if ( sgnl ){ |
703 |
|
|
l0File->Close(); |
704 |
|
|
code = sgnl; |
705 |
|
|
goto closeandexit; |
706 |
|
|
}; |
707 |
|
|
// |
708 |
|
|
qy.str(""); |
709 |
|
|
// |
710 |
mocchiut |
1.8 |
nevents = l0head->GetEntries(); |
711 |
mocchiut |
1.1 |
caloevents = l0calo->GetEntries(); |
712 |
|
|
// |
713 |
|
|
if ( nevents < 1 ) { |
714 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: Level0 file is empty\n\n"); |
715 |
|
|
l0File->Close(); |
716 |
|
|
code = -11; |
717 |
|
|
goto closeandexit; |
718 |
|
|
}; |
719 |
|
|
// |
720 |
|
|
if ( evto > nevents-1 ) { |
721 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: too few entries in the registry tree\n"); |
722 |
|
|
l0File->Close(); |
723 |
|
|
code = -12; |
724 |
|
|
goto closeandexit; |
725 |
|
|
}; |
726 |
|
|
// |
727 |
|
|
// Check if we have to load parameter files |
728 |
|
|
// |
729 |
|
|
sgnl = 0; |
730 |
mocchiut |
1.32 |
sgnl = event->ChkParam(glt,runheadtime,mechal); // calorimeter parameter files |
731 |
mocchiut |
1.1 |
if ( sgnl < 0 ){ |
732 |
|
|
code = sgnl; |
733 |
|
|
l0File->Close(); |
734 |
|
|
goto closeandexit; |
735 |
|
|
}; |
736 |
|
|
// |
737 |
mocchiut |
1.34 |
// Calculate the cross talk corrections needed for this run using calibration informations |
738 |
|
|
// |
739 |
|
|
if ( crosst && !ctground ){ |
740 |
|
|
sgnl = 0; |
741 |
|
|
sgnl = event->CalcCrossTalkCorr(glt,runheadtime); |
742 |
|
|
if ( sgnl < 0 ){ |
743 |
|
|
code = sgnl; |
744 |
|
|
l0File->Close(); |
745 |
|
|
goto closeandexit; |
746 |
|
|
}; |
747 |
|
|
}; |
748 |
|
|
// |
749 |
mocchiut |
1.1 |
// run over all the events of the run |
750 |
|
|
// |
751 |
|
|
if ( verbose ) printf("\n Ready to start! \n\n Processed events: \n\n"); |
752 |
|
|
// |
753 |
mocchiut |
1.19 |
for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){ |
754 |
mocchiut |
1.40 |
//for ( re = 92012+3400; re < 92012+3700; re++){ |
755 |
mocchiut |
1.18 |
// printf(" i = %i \n",re-200241); |
756 |
mocchiut |
1.1 |
// |
757 |
|
|
if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000); |
758 |
|
|
// |
759 |
mocchiut |
1.39 |
if ( debug ) printf("\n\n\n EVENT NUMBER %i \n",procev); |
760 |
|
|
// |
761 |
mocchiut |
1.8 |
l0head->GetEntry(re); |
762 |
mocchiut |
1.1 |
// |
763 |
|
|
// absolute time of this event |
764 |
|
|
// |
765 |
mocchiut |
1.8 |
ph = eh->GetPscuHeader(); |
766 |
|
|
atime = dbtime->DBabsTime(ph->GetOrbitalTime()); |
767 |
mocchiut |
1.1 |
// |
768 |
|
|
// |
769 |
|
|
// |
770 |
mocchiut |
1.8 |
if ( re > caloevents-1 ){ |
771 |
mocchiut |
1.1 |
if ( verbose ) printf(" CALORIMETER - ERROR: no physics events with entry = %i in Level0 file\n",i); |
772 |
|
|
l0File->Close(); |
773 |
|
|
code = -112; |
774 |
|
|
goto closeandexit; |
775 |
|
|
}; |
776 |
|
|
// |
777 |
|
|
if ( atime > runtrailtime || atime < runheadtime ) { |
778 |
|
|
if ( verbose ) printf(" CALORIMETER - WARNING: event at time outside the run time window, skipping it\n"); |
779 |
mocchiut |
1.9 |
jumped++; |
780 |
mocchiut |
1.1 |
goto jumpev; |
781 |
|
|
}; |
782 |
|
|
// |
783 |
|
|
// retrieve tracker informations |
784 |
|
|
// |
785 |
|
|
if ( !reprocall ){ |
786 |
mocchiut |
1.19 |
itr = nobefrun + (re - evfrom - jumped); |
787 |
|
|
//itr = re-(46438+200241); |
788 |
mocchiut |
1.1 |
} else { |
789 |
mocchiut |
1.9 |
itr = runinfo->GetFirstEntry() + (re - evfrom - jumped); |
790 |
mocchiut |
1.1 |
}; |
791 |
mocchiut |
1.11 |
// |
792 |
|
|
if ( withtrk ){ |
793 |
|
|
if ( itr > nevtrkl2 ){ |
794 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: no tracker events with entry = %i in Level2 file\n",itr); |
795 |
|
|
l0File->Close(); |
796 |
|
|
code = -113; |
797 |
|
|
goto closeandexit; |
798 |
|
|
}; |
799 |
|
|
// |
800 |
|
|
trk->Clear(); |
801 |
|
|
// |
802 |
|
|
tracker->GetEntry(itr); |
803 |
|
|
// |
804 |
mocchiut |
1.1 |
}; |
805 |
mocchiut |
1.10 |
// |
806 |
mocchiut |
1.1 |
procev++; |
807 |
|
|
// |
808 |
|
|
// start processing |
809 |
|
|
// |
810 |
mocchiut |
1.13 |
if ( getl1 ) c1->Clear(); |
811 |
mocchiut |
1.6 |
ca->Clear(); |
812 |
mocchiut |
1.1 |
// |
813 |
|
|
// determine who generate the trigger for this event (TOF, S4/PULSER, CALO) |
814 |
|
|
// |
815 |
mocchiut |
1.8 |
l0trig->GetEntry(re); |
816 |
mocchiut |
1.1 |
S3 = 0; |
817 |
|
|
S2 = 0; |
818 |
|
|
S12 = 0; |
819 |
|
|
S11 = 0; |
820 |
|
|
S3 = trig->patterntrig[2]; |
821 |
|
|
S2 = trig->patterntrig[3]; |
822 |
|
|
S12 = trig->patterntrig[4]; |
823 |
|
|
S11 = trig->patterntrig[5]; |
824 |
mocchiut |
1.17 |
if ( trig->patterntrig[1] & (1<<0) ) tmptrigty = 1.; |
825 |
mocchiut |
1.1 |
if ( trig->patterntrig[0] ) tmptrigty = 2.; |
826 |
|
|
if ( S3 || S2 || S12 || S11 ) tmptrigty = 0.; |
827 |
mocchiut |
1.17 |
if ( !(trig->patterntrig[1] & (1<<0)) && !trig->patterntrig[0] && !S3 && !S2 && !S12 && !S11 ) tmptrigty = 1.; |
828 |
mocchiut |
1.1 |
event->clevel2->trigty = tmptrigty; |
829 |
|
|
// |
830 |
|
|
// check if the calibration we are using is still good, if not load another calibration |
831 |
|
|
// |
832 |
|
|
sgnl = 0; |
833 |
mocchiut |
1.32 |
sgnl = event->ChkCalib(glt,atime); |
834 |
mocchiut |
1.1 |
if ( sgnl < 0 ){ |
835 |
|
|
code = sgnl; |
836 |
|
|
goto closeandexit; |
837 |
|
|
}; |
838 |
|
|
if ( sgnl == 100 ){ |
839 |
|
|
code = sgnl; |
840 |
|
|
if ( verbose ) printf(" CALORIMETER - WARNING: data not associated to any calibration interval\n"); |
841 |
|
|
badevent++; |
842 |
|
|
sgnl = 0; |
843 |
|
|
}; |
844 |
|
|
// |
845 |
mocchiut |
1.11 |
// do we have at least one track from the tracker? this check has been disabled |
846 |
mocchiut |
1.1 |
// |
847 |
|
|
event->clevel1->good2 = 1; |
848 |
mocchiut |
1.8 |
// |
849 |
mocchiut |
1.29 |
// use the whole calorimeter, 22 W planes |
850 |
|
|
// |
851 |
|
|
event->clevel1->npla = 22; |
852 |
|
|
// |
853 |
|
|
// Use the standard silicon planes shifting |
854 |
|
|
// |
855 |
|
|
event->clevel1->reverse = 0; |
856 |
|
|
// |
857 |
mocchiut |
1.1 |
// |
858 |
mocchiut |
1.8 |
// Calibrate calorimeter event "re" and store output in the two structures that will be passed to fortran routine |
859 |
mocchiut |
1.1 |
// |
860 |
mocchiut |
1.11 |
event->Calibrate(re); |
861 |
mocchiut |
1.1 |
// |
862 |
|
|
// Here we have calibrated data, ready to be passed to the FORTRAN routine which will extract topological variables. |
863 |
|
|
// |
864 |
|
|
// |
865 |
|
|
// Calculate variables common to all tracks (qtot, nstrip, etc.) |
866 |
|
|
// |
867 |
|
|
event->GetCommonVar(); |
868 |
|
|
// |
869 |
|
|
// Fill common variables |
870 |
|
|
// |
871 |
mocchiut |
1.13 |
event->FillCommonVar(c1,ca); |
872 |
mocchiut |
1.1 |
// |
873 |
|
|
// Calculate variables related to tracks only if we have at least one track (from selftrigger and/or tracker) |
874 |
|
|
// |
875 |
|
|
ntrkentry = 0; |
876 |
|
|
// |
877 |
|
|
filled = false; |
878 |
|
|
// |
879 |
mocchiut |
1.11 |
// Run over tracks (tracker or calorimeter ) |
880 |
|
|
// |
881 |
|
|
if ( withtrk ){ |
882 |
|
|
for(Int_t nt=0; nt < trk->ntrk(); nt++){ |
883 |
|
|
// |
884 |
|
|
event->clevel1->good2 = 1; |
885 |
|
|
// |
886 |
|
|
TrkTrack *ptt = trk->GetStoredTrack(nt); |
887 |
|
|
// |
888 |
|
|
event->clevel1->trkchi2 = 0; |
889 |
|
|
// |
890 |
|
|
// Copy the alpha vector in the input structure |
891 |
|
|
// |
892 |
|
|
for (Int_t e = 0; e < 5 ; e++){ |
893 |
|
|
event->clevel1->al_p[e][0] = ptt->al[e]; |
894 |
|
|
}; |
895 |
|
|
// |
896 |
|
|
// Get tracker related variables for this track |
897 |
|
|
// |
898 |
|
|
event->GetTrkVar(); |
899 |
|
|
// |
900 |
|
|
// Save tracker track sequence number |
901 |
|
|
// |
902 |
|
|
event->trkseqno = nt; |
903 |
|
|
// |
904 |
|
|
// Copy values in the class ca from the structure clevel2 |
905 |
|
|
// |
906 |
|
|
event->FillTrkVar(ca,ntrkentry); |
907 |
|
|
ntrkentry++; |
908 |
|
|
filled = true; |
909 |
|
|
// |
910 |
|
|
}; // loop on all the tracks |
911 |
|
|
}; |
912 |
|
|
// |
913 |
|
|
// if no tracks found but there is the possibility to have a good track we should try to calculate anyway the track related variables using the calorimeter |
914 |
|
|
// fit of the track (to be used for example when TRK is off due to any reason like IPM3/5 off). |
915 |
|
|
// here we make an event selection so it must be done very carefully... |
916 |
|
|
// |
917 |
|
|
// conditions are: 0) no track from the tracker 1) we have a track fit both in x and y 2) no problems with calo for this event 3) no selftrigger event |
918 |
|
|
// |
919 |
|
|
if ( trackanyway && !filled && event->clevel2->npcfit[0] >= 2 && event->clevel2->npcfit[1] >= 2 && event->clevel2->good != 0 && event->clevel2->trigty < 2. ){ |
920 |
|
|
if ( debug ) printf(" Event with a track not fitted by the tracker at entry %i \n",itr); |
921 |
|
|
// |
922 |
|
|
// Disable "track mode" in the fortran routine |
923 |
|
|
// |
924 |
|
|
event->clevel1->good2 = 0; |
925 |
|
|
event->clevel1->riginput = rigdefault; |
926 |
|
|
if ( debug ) printf(" Using as default rigidity: %f \n",event->clevel1->riginput); |
927 |
|
|
// |
928 |
|
|
// We have a selftrigger event to analyze. |
929 |
|
|
// |
930 |
|
|
for (Int_t e = 0; e < 5 ; e++){ |
931 |
|
|
event->clevel1->al_p[e][0] = 0.; |
932 |
|
|
event->clevel1->al_p[e][1] = 0.; |
933 |
|
|
}; |
934 |
|
|
event->clevel1->trkchi2 = 0; |
935 |
|
|
// |
936 |
|
|
event->GetTrkVar(); |
937 |
|
|
// |
938 |
|
|
// if we had no problem (clevel1->good2 = 0, NOTICE zero, not one in this mode!), fill and go on |
939 |
mocchiut |
1.1 |
// |
940 |
mocchiut |
1.11 |
if ( event->clevel1->good2 == 0 ) { |
941 |
mocchiut |
1.1 |
// |
942 |
mocchiut |
1.11 |
// In selftrigger mode the trkentry variable is set to -1 |
943 |
mocchiut |
1.1 |
// |
944 |
mocchiut |
1.11 |
event->trkseqno = -3; |
945 |
mocchiut |
1.1 |
// |
946 |
mocchiut |
1.11 |
// Copy values in the class ca from the structure clevel2 |
947 |
mocchiut |
1.1 |
// |
948 |
mocchiut |
1.11 |
event->FillTrkVar(ca,ntrkentry); |
949 |
|
|
ntrkentry++; |
950 |
|
|
filled = true; |
951 |
|
|
// |
952 |
|
|
} else { |
953 |
|
|
if ( verbose ) printf(" Selftrigger: problems with event at entry %i \n",itr); |
954 |
|
|
}; |
955 |
|
|
// |
956 |
|
|
}; |
957 |
|
|
// |
958 |
|
|
// Call high energy nuclei routine |
959 |
|
|
// |
960 |
|
|
if ( hZn && event->clevel2->trigty >= 2. ){ |
961 |
|
|
if ( debug ) printf(" Calling selftrigger high energy nuclei routine for entry %i \n",itr); |
962 |
|
|
// |
963 |
|
|
// Disable "track mode" in the fortran routine |
964 |
|
|
// |
965 |
|
|
event->clevel1->good2 = 0; |
966 |
|
|
// |
967 |
|
|
// Set high energy nuclei flag to one |
968 |
|
|
// |
969 |
|
|
event->clevel1->hzn = 1; |
970 |
|
|
event->clevel1->riginput = rigdefault; |
971 |
|
|
// |
972 |
|
|
// We have a selftrigger event to analyze. |
973 |
|
|
// |
974 |
|
|
for (Int_t e = 0; e < 5 ; e++){ |
975 |
|
|
event->clevel1->al_p[e][0] = 0.; |
976 |
|
|
event->clevel1->al_p[e][1] = 0.; |
977 |
mocchiut |
1.1 |
}; |
978 |
mocchiut |
1.11 |
event->clevel1->trkchi2 = 0; |
979 |
|
|
// |
980 |
|
|
event->GetTrkVar(); |
981 |
|
|
// |
982 |
|
|
// if we had no problem (clevel1->good2 = 0, NOTICE zero, not one in this mode!), fill and go on |
983 |
|
|
// |
984 |
|
|
if ( event->clevel1->good2 == 0 ) { |
985 |
|
|
// |
986 |
|
|
// In selftrigger mode the trkentry variable is set to -1 |
987 |
|
|
// |
988 |
|
|
event->trkseqno = -2; |
989 |
|
|
// |
990 |
|
|
// Copy values in the class ca from the structure clevel2 |
991 |
mocchiut |
1.1 |
// |
992 |
mocchiut |
1.11 |
event->FillTrkVar(ca,ntrkentry); |
993 |
|
|
ntrkentry++; |
994 |
|
|
filled = true; |
995 |
mocchiut |
1.1 |
// |
996 |
mocchiut |
1.11 |
} else { |
997 |
|
|
if ( verbose ) printf(" Selftrigger: problems with event at entry %i \n",itr); |
998 |
|
|
}; |
999 |
|
|
// |
1000 |
|
|
}; |
1001 |
|
|
// |
1002 |
|
|
// self trigger event |
1003 |
|
|
// |
1004 |
|
|
if ( st && event->clevel2->trigty >= 2. ){ |
1005 |
|
|
if ( verbose ) printf(" Selftrigger event at entry %i \n",itr); |
1006 |
|
|
// |
1007 |
|
|
// Disable "track mode" in the fortran routine |
1008 |
|
|
// |
1009 |
|
|
event->clevel1->good2 = 0; |
1010 |
|
|
// |
1011 |
|
|
// disable high enery nuclei flag; |
1012 |
|
|
// |
1013 |
|
|
event->clevel1->hzn = 0; |
1014 |
|
|
// |
1015 |
|
|
// We have a selftrigger event to analyze. |
1016 |
|
|
// |
1017 |
|
|
for (Int_t e = 0; e < 5 ; e++){ |
1018 |
|
|
event->clevel1->al_p[e][0] = 0.; |
1019 |
|
|
event->clevel1->al_p[e][1] = 0.; |
1020 |
|
|
}; |
1021 |
|
|
event->clevel1->trkchi2 = 0; |
1022 |
|
|
// |
1023 |
|
|
event->GetTrkVar(); |
1024 |
|
|
// |
1025 |
|
|
// if we had no problem (clevel2->good = 0, NOTICE zero, not one in selftrigger mode!), fill and go on |
1026 |
|
|
// |
1027 |
|
|
if ( event->clevel1->good2 == 0 ) { |
1028 |
mocchiut |
1.1 |
// |
1029 |
mocchiut |
1.11 |
// In selftrigger mode the trkentry variable is set to -1 |
1030 |
mocchiut |
1.1 |
// |
1031 |
mocchiut |
1.11 |
event->trkseqno = -1; |
1032 |
mocchiut |
1.1 |
// |
1033 |
mocchiut |
1.11 |
// Copy values in the class ca from the structure clevel2 |
1034 |
mocchiut |
1.1 |
// |
1035 |
mocchiut |
1.11 |
event->FillTrkVar(ca,ntrkentry); |
1036 |
|
|
ntrkentry++; |
1037 |
|
|
filled = true; |
1038 |
mocchiut |
1.1 |
// |
1039 |
mocchiut |
1.11 |
} else { |
1040 |
|
|
if ( verbose ) printf(" Selftrigger: problems with event at entry %i \n",itr); |
1041 |
mocchiut |
1.1 |
}; |
1042 |
|
|
}; |
1043 |
|
|
// |
1044 |
|
|
if ( !filled ) badevent++; |
1045 |
|
|
// |
1046 |
|
|
// Clear structures used to communicate with fortran |
1047 |
|
|
// |
1048 |
|
|
event->ClearStructs(); |
1049 |
|
|
// |
1050 |
|
|
// Fill the rootple |
1051 |
|
|
// |
1052 |
|
|
calo->Fill(); |
1053 |
|
|
// |
1054 |
mocchiut |
1.6 |
// delete ca; |
1055 |
mocchiut |
1.1 |
// |
1056 |
|
|
jumpev: |
1057 |
mocchiut |
1.23 |
if ( !debug ) debug = false; |
1058 |
mocchiut |
1.1 |
// |
1059 |
|
|
}; |
1060 |
|
|
// |
1061 |
|
|
if ( verbose ) printf("\n SUMMARY:\n"); |
1062 |
|
|
if ( verbose ) printf(" Total number of events: %i \n",totevent); |
1063 |
|
|
if ( verbose ) printf(" Events with at least one track: %i \n",totevent-badevent); |
1064 |
|
|
if ( verbose ) printf(" Events without tracks: %i \n",badevent); |
1065 |
|
|
// |
1066 |
|
|
if ( badevent == totevent ){ |
1067 |
mocchiut |
1.8 |
if ( verbose ) printf("\n CALORIMETER - WARNING no tracks or good events in run %u \n",idRun); |
1068 |
mocchiut |
1.1 |
code = 101; |
1069 |
|
|
}; |
1070 |
|
|
// |
1071 |
mocchiut |
1.8 |
delete dbtime; |
1072 |
mocchiut |
1.1 |
// |
1073 |
|
|
// Clear variables before processing another run (needed to have always the same result when reprocessing data with the same software). |
1074 |
|
|
// |
1075 |
|
|
event->RunClose(); |
1076 |
|
|
if ( l0File ) l0File->Close(); |
1077 |
|
|
// |
1078 |
|
|
}; // process all the runs |
1079 |
|
|
// |
1080 |
|
|
if ( verbose ) printf("\n Finished processing data \n"); |
1081 |
|
|
// |
1082 |
|
|
closeandexit: |
1083 |
|
|
// |
1084 |
|
|
if ( !reprocall && reproc && code >= 0 ){ |
1085 |
|
|
if ( totfileentries > noaftrun ){ |
1086 |
|
|
if ( verbose ) printf("\n Post-processing: copying events from the old tree after the processed run\n"); |
1087 |
mocchiut |
1.8 |
if ( verbose ) printf(" Copying %u events in the file which are after the end of the run %u \n",(totfileentries-noaftrun),run); |
1088 |
|
|
if ( verbose ) printf(" Start copying at event number %u end copying at event number %u \n",noaftrun,totfileentries); |
1089 |
mocchiut |
1.1 |
for (UInt_t j = noaftrun; j < totfileentries; j++ ){ |
1090 |
|
|
// |
1091 |
|
|
// Get entry from old tree |
1092 |
|
|
// |
1093 |
|
|
caloclone->GetEntry(j); |
1094 |
|
|
// |
1095 |
|
|
// copy caclone to ca |
1096 |
|
|
// |
1097 |
mocchiut |
1.13 |
if ( getl1 ) c1->Clear(); |
1098 |
mocchiut |
1.6 |
ca->Clear(); |
1099 |
mocchiut |
1.8 |
// |
1100 |
mocchiut |
1.13 |
if ( getl1 ) memcpy(&c1,&c1clone,sizeof(c1clone)); |
1101 |
mocchiut |
1.1 |
memcpy(&ca,&caclone,sizeof(caclone)); |
1102 |
|
|
// |
1103 |
|
|
// Fill entry in the new tree |
1104 |
|
|
// |
1105 |
|
|
calo->Fill(); |
1106 |
|
|
// |
1107 |
|
|
}; |
1108 |
|
|
if ( verbose ) printf(" Finished successful copying!\n"); |
1109 |
|
|
}; |
1110 |
|
|
}; |
1111 |
|
|
// |
1112 |
|
|
// Case of no errors: close files, delete old tree(s), write and close level2 file |
1113 |
|
|
// |
1114 |
|
|
if ( l0File ) l0File->Close(); |
1115 |
|
|
if ( tempfile ) tempfile->Close(); |
1116 |
mocchiut |
1.30 |
if ( myfold ) gSystem->Unlink(tempname.str().c_str()); |
1117 |
mocchiut |
1.1 |
if ( tracker ) tracker->Delete(); |
1118 |
|
|
// |
1119 |
|
|
if ( code < 0 ) printf("\n CALORIMETER - ERROR: an error occurred, try to save anyway...\n"); |
1120 |
|
|
if ( verbose ) printf("\n Writing and closing rootple\n"); |
1121 |
|
|
if ( runinfo ) runinfo->Close(); |
1122 |
|
|
if ( calo ) calo->SetName("Calorimeter"); |
1123 |
|
|
if ( file ){ |
1124 |
|
|
file->cd(); |
1125 |
|
|
file->Write(); |
1126 |
|
|
}; |
1127 |
|
|
if ( calo ) calo->Delete(); |
1128 |
|
|
// |
1129 |
mocchiut |
1.30 |
if ( myfold ) gSystem->Unlink(calofolder.str().c_str()); |
1130 |
mocchiut |
1.1 |
// |
1131 |
mocchiut |
1.7 |
if ( ca ) delete ca; |
1132 |
|
|
if ( caclone ) delete caclone; |
1133 |
mocchiut |
1.13 |
if ( c1 ) delete c1; |
1134 |
|
|
if ( c1clone ) delete c1clone; |
1135 |
mocchiut |
1.7 |
if ( trk ) delete trk; |
1136 |
|
|
if ( q4 ) delete q4; |
1137 |
|
|
if ( glroot ) delete glroot; |
1138 |
|
|
if ( runinfo ) delete runinfo; |
1139 |
|
|
// |
1140 |
mocchiut |
1.1 |
// the end |
1141 |
|
|
// |
1142 |
|
|
if ( verbose ) printf("\n Exiting...\n"); |
1143 |
|
|
if ( code < 0 ) throw code; |
1144 |
|
|
return(code); |
1145 |
|
|
} |
1146 |
|
|
|
1147 |
|
|
|
1148 |
|
|
|