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