1 |
mocchiut |
1.49 |
// // C/C++ headers // |
2 |
mocchiut |
1.1 |
#include <fstream> |
3 |
|
|
#include <string.h> |
4 |
mocchiut |
1.32 |
#include <iomanip> |
5 |
mocchiut |
1.1 |
// |
6 |
|
|
// ROOT headers |
7 |
|
|
// |
8 |
|
|
#include <TTree.h> |
9 |
|
|
#include <TClassEdit.h> |
10 |
|
|
#include <TObject.h> |
11 |
|
|
#include <TList.h> |
12 |
mocchiut |
1.6 |
#include <TArrayI.h> |
13 |
mocchiut |
1.1 |
#include <TSystem.h> |
14 |
|
|
#include <TSystemDirectory.h> |
15 |
|
|
#include <TString.h> |
16 |
|
|
#include <TFile.h> |
17 |
|
|
#include <TClass.h> |
18 |
|
|
#include <TCanvas.h> |
19 |
|
|
#include <TH1.h> |
20 |
|
|
#include <TH1F.h> |
21 |
|
|
#include <TH2D.h> |
22 |
|
|
#include <TLatex.h> |
23 |
|
|
#include <TPad.h> |
24 |
|
|
#include <TSQLServer.h> |
25 |
|
|
#include <TSQLRow.h> |
26 |
|
|
#include <TSQLResult.h> |
27 |
|
|
#include <TClonesArray.h> |
28 |
|
|
// |
29 |
mocchiut |
1.16 |
// RunInfo header |
30 |
|
|
// |
31 |
|
|
#include <RunInfo.h> |
32 |
|
|
// |
33 |
mocchiut |
1.1 |
// YODA headers |
34 |
|
|
// |
35 |
|
|
#include <PamelaRun.h> |
36 |
mocchiut |
1.48 |
//#include <physics/trigger/TriggerEvent.h> |
37 |
mocchiut |
1.1 |
#include <physics/tof/TofEvent.h> |
38 |
|
|
// |
39 |
|
|
// This program headers |
40 |
|
|
// |
41 |
|
|
#include <ToFCore.h> |
42 |
|
|
#include <ToFLevel2.h> |
43 |
|
|
#include <ToFVerl2.h> |
44 |
|
|
// |
45 |
|
|
// |
46 |
|
|
// Declaration of the core fortran routines |
47 |
|
|
// |
48 |
|
|
#define tofl2com tofl2com_ |
49 |
|
|
extern "C" int tofl2com(); |
50 |
|
|
#define toftrk toftrk_ |
51 |
|
|
extern "C" int toftrk(); |
52 |
|
|
#define rdtofcal rdtofcal_ |
53 |
mocchiut |
1.46 |
//extern "C" int rdtofcal(char [], int *); |
54 |
|
|
extern "C" int rdtofcal(const char *, int *); |
55 |
mocchiut |
1.1 |
|
56 |
|
|
// |
57 |
|
|
// Tracker classes headers and definitions |
58 |
|
|
// |
59 |
|
|
#include <TrkLevel2.h> |
60 |
|
|
// |
61 |
|
|
using namespace std; |
62 |
|
|
// |
63 |
|
|
// |
64 |
|
|
// CORE ROUTINE |
65 |
|
|
// |
66 |
|
|
// |
67 |
mocchiut |
1.27 |
int ToFCore(UInt_t run, TFile *file, GL_TABLES *glt, Int_t ToFargc, char *ToFargv[]){ |
68 |
mocchiut |
1.1 |
// |
69 |
|
|
// |
70 |
|
|
// Set these to true to have a very verbose output. |
71 |
|
|
// |
72 |
|
|
Bool_t verbose = false; |
73 |
|
|
Bool_t debug = false; |
74 |
|
|
// |
75 |
mocchiut |
1.19 |
TString processFolder = Form("ToFFolder_%u",run); |
76 |
mocchiut |
1.1 |
if ( ToFargc > 0 ){ |
77 |
|
|
Int_t i = 0; |
78 |
|
|
while ( i < ToFargc ){ |
79 |
|
|
if ( !strcmp(ToFargv[i],"-processFolder") ) { |
80 |
|
|
if ( ToFargc < i+1 ){ |
81 |
|
|
throw -3; |
82 |
|
|
}; |
83 |
|
|
processFolder = (TString)ToFargv[i+1]; |
84 |
|
|
i++; |
85 |
|
|
}; |
86 |
mocchiut |
1.20 |
if ( !strcmp(ToFargv[i],"-v") || !strcmp(ToFargv[i],"--verbose") ) { |
87 |
mocchiut |
1.1 |
verbose = true; |
88 |
mocchiut |
1.20 |
}; |
89 |
mocchiut |
1.1 |
if ( !strcmp(ToFargv[i],"-g") || !strcmp(ToFargv[i],"--debug") ) { |
90 |
mocchiut |
1.18 |
verbose = true; |
91 |
mocchiut |
1.1 |
debug = true; |
92 |
|
|
}; |
93 |
|
|
i++; |
94 |
|
|
}; |
95 |
|
|
}; |
96 |
|
|
// |
97 |
|
|
// |
98 |
|
|
// Output directory is the working directoy. |
99 |
|
|
// |
100 |
|
|
const char* outdir = gSystem->DirName(gSystem->DirName(file->GetPath())); |
101 |
|
|
// |
102 |
|
|
// Variables for level2 |
103 |
|
|
// |
104 |
|
|
TTree *tracker = 0; |
105 |
mocchiut |
1.48 |
TTree *trigger = 0; |
106 |
mocchiut |
1.1 |
TTree *toft = 0; |
107 |
mocchiut |
1.6 |
UInt_t nevents = 0; |
108 |
mocchiut |
1.15 |
Long64_t maxsize = 10000000000LL; |
109 |
|
|
TTree::SetMaxTreeSize(maxsize); |
110 |
mocchiut |
1.1 |
// |
111 |
|
|
// variables needed to reprocess data |
112 |
|
|
// |
113 |
|
|
TString tofversion; |
114 |
|
|
ItoRunInfo *runinfo = 0; |
115 |
mocchiut |
1.6 |
TArrayI *runlist = 0; |
116 |
mocchiut |
1.1 |
TTree *toftclone = 0; |
117 |
|
|
Bool_t reproc = false; |
118 |
|
|
Bool_t reprocall = false; |
119 |
|
|
UInt_t nobefrun = 0; |
120 |
|
|
UInt_t noaftrun = 0; |
121 |
|
|
UInt_t numbofrun = 0; |
122 |
|
|
stringstream ftmpname; |
123 |
|
|
TString fname; |
124 |
mocchiut |
1.6 |
UInt_t totfileentries = 0; |
125 |
|
|
UInt_t idRun = 0; |
126 |
mocchiut |
1.1 |
// |
127 |
|
|
// variables needed to handle error signals |
128 |
|
|
// |
129 |
|
|
Int_t code = 0; |
130 |
|
|
Int_t sgnl; |
131 |
|
|
// |
132 |
|
|
// tof level2 classes |
133 |
|
|
// |
134 |
|
|
ToFLevel2 *tof = new ToFLevel2(); |
135 |
|
|
ToFLevel2 *tofclone = new ToFLevel2(); |
136 |
carbone |
1.37 |
ToFdEdx *tofdedx = new ToFdEdx(); |
137 |
mocchiut |
1.1 |
// |
138 |
|
|
// tracker level2 variables |
139 |
|
|
// |
140 |
|
|
TrkLevel2 *trk = new TrkLevel2(); |
141 |
mocchiut |
1.6 |
Int_t nevtrkl2 = 0; |
142 |
mocchiut |
1.1 |
// |
143 |
mocchiut |
1.48 |
// trigger level2 variables |
144 |
|
|
// |
145 |
|
|
TrigLevel2 *trg = new TrigLevel2(); |
146 |
|
|
Int_t nevtrgl2 = 0; |
147 |
|
|
// |
148 |
mocchiut |
1.1 |
// define variables for opening and reading level0 file |
149 |
|
|
// |
150 |
|
|
TFile *l0File = 0; |
151 |
|
|
TTree *l0tr = 0; |
152 |
|
|
TBranch *l0head = 0; |
153 |
mocchiut |
1.48 |
// TBranch *l0trig = 0; |
154 |
mocchiut |
1.1 |
TBranch *l0tof = 0; |
155 |
mocchiut |
1.6 |
pamela::EventHeader *eh = 0; |
156 |
|
|
pamela::PscuHeader *ph = 0; |
157 |
mocchiut |
1.48 |
// pamela::trigger::TriggerEvent *trig = 0; |
158 |
mocchiut |
1.1 |
pamela::tof::TofEvent *tofEvent = 0; |
159 |
|
|
// |
160 |
|
|
// Define other basic variables |
161 |
|
|
// |
162 |
|
|
UInt_t procev = 0; |
163 |
|
|
stringstream file2; |
164 |
|
|
stringstream file3; |
165 |
|
|
stringstream qy; |
166 |
|
|
Int_t itr = -1; |
167 |
|
|
Int_t totevent = 0; |
168 |
mocchiut |
1.6 |
UInt_t atime = 0; |
169 |
|
|
UInt_t re = 0; |
170 |
mocchiut |
1.7 |
UInt_t jumped = 0; |
171 |
mocchiut |
1.1 |
// |
172 |
|
|
// Working filename |
173 |
|
|
// |
174 |
|
|
TString outputfile; |
175 |
|
|
stringstream name; |
176 |
|
|
name.str(""); |
177 |
|
|
name << outdir << "/"; |
178 |
|
|
// |
179 |
|
|
// temporary file and folder |
180 |
|
|
// |
181 |
|
|
TFile *tempfile = 0; |
182 |
|
|
TTree *temptof = 0; |
183 |
|
|
stringstream tempname; |
184 |
|
|
stringstream toffolder; |
185 |
mocchiut |
1.25 |
Bool_t myfold = false; |
186 |
mocchiut |
1.1 |
tempname.str(""); |
187 |
|
|
tempname << outdir; |
188 |
|
|
tempname << "/" << processFolder.Data(); |
189 |
|
|
toffolder.str(""); |
190 |
|
|
toffolder << tempname.str().c_str(); |
191 |
|
|
tempname << "/toftree_run"; |
192 |
|
|
tempname << run << ".root"; |
193 |
mocchiut |
1.36 |
UInt_t totnorun = 0; |
194 |
mocchiut |
1.1 |
// |
195 |
|
|
// variables needed to load magnetic field maps |
196 |
|
|
// |
197 |
|
|
Int_t ntrkentry = 0; |
198 |
mocchiut |
1.4 |
Int_t npmtentry = 0; |
199 |
mocchiut |
1.6 |
UInt_t tttrkpar1 = 0; |
200 |
mocchiut |
1.1 |
Bool_t trkpar1 = true; |
201 |
mocchiut |
1.6 |
UInt_t tttofpar1 = 0; |
202 |
mocchiut |
1.1 |
Bool_t tofpar1 = true; |
203 |
|
|
// |
204 |
|
|
// DB classes |
205 |
|
|
// |
206 |
|
|
GL_ROOT *glroot = new GL_ROOT(); |
207 |
|
|
GL_PARAM *glparam = new GL_PARAM(); |
208 |
mocchiut |
1.6 |
GL_TIMESYNC *dbtime = 0; |
209 |
mocchiut |
1.1 |
// |
210 |
|
|
// declaring external output and input structures |
211 |
|
|
// |
212 |
|
|
extern struct ToFInput tofinput_; |
213 |
|
|
extern struct ToFOutput tofoutput_; |
214 |
|
|
// |
215 |
mocchiut |
1.32 |
// WM variables perform dE/dx II order corrections |
216 |
|
|
// |
217 |
mocchiut |
1.48 |
//Float_t dedx_corr_m[100][48],dedx_corr[48]; |
218 |
mocchiut |
1.32 |
Double_t mtime[100],t1,t2,tm; |
219 |
mocchiut |
1.48 |
//Float_t yhelp1,yhelp2,slope,inter,thelp1,thelp2; |
220 |
|
|
|
221 |
|
|
//RC variables for new dEdx II order correction (10th reduction) |
222 |
|
|
Float_t Heyhelp1,Heyhelp2,Heslope,Heinter,thelp1,thelp2; |
223 |
|
|
Float_t pyhelp1,pyhelp2,pslope,pinter; |
224 |
|
|
Float_t dedx_Hepeak[48],dedx_ppeak[48]; |
225 |
|
|
Float_t dedx_Hepeak_m[100][48],dedx_ppeak_m[100][48]; |
226 |
|
|
Float_t inter_dedx[48],slope_dedx[48]; |
227 |
|
|
|
228 |
mocchiut |
1.32 |
Float_t xmean1,xwidth1; |
229 |
|
|
Int_t ical,ii,wj,jj; |
230 |
mocchiut |
1.40 |
Float_t xleft=0; |
231 |
|
|
Float_t xright=0; |
232 |
|
|
Float_t yleft=0; |
233 |
|
|
Float_t yright=0; |
234 |
mocchiut |
1.48 |
|
235 |
|
|
Int_t warning = 0; |
236 |
|
|
int a=0, b=0; |
237 |
|
|
|
238 |
mocchiut |
1.32 |
// |
239 |
mocchiut |
1.1 |
// Let's start! |
240 |
|
|
// |
241 |
|
|
// |
242 |
|
|
// As a first thing we must check what we have to do: if run = 0 we must process all events in the file has been passed |
243 |
|
|
// if run != 0 we must process only that run but first we have to check if the tree ToF already exist in the file |
244 |
|
|
// if it exists we are reprocessing data and we must delete that entries, if not we must create it. |
245 |
|
|
// |
246 |
mocchiut |
1.6 |
if ( run == 0 ) reproc = true; |
247 |
mocchiut |
1.1 |
// |
248 |
|
|
// |
249 |
|
|
// Output file is "outputfile" |
250 |
|
|
// |
251 |
|
|
if ( !file->IsOpen() ){ |
252 |
|
|
if ( verbose ) printf(" ToF - ERROR: cannot open file for writing\n"); |
253 |
|
|
throw -301; |
254 |
|
|
}; |
255 |
|
|
// |
256 |
|
|
// Does it contain the Tracker tree? |
257 |
|
|
// |
258 |
|
|
tracker = (TTree*)file->Get("Tracker"); |
259 |
|
|
if ( !tracker ) { |
260 |
|
|
if ( verbose ) printf(" TOF - ERROR: no tracker tree\n"); |
261 |
|
|
code = -302; |
262 |
|
|
goto closeandexit; |
263 |
|
|
}; |
264 |
|
|
// |
265 |
|
|
// get tracker level2 data pointer |
266 |
|
|
// |
267 |
|
|
tracker->SetBranchAddress("TrkLevel2",&trk); |
268 |
|
|
nevtrkl2 = tracker->GetEntries(); |
269 |
mocchiut |
1.48 |
|
270 |
|
|
// |
271 |
|
|
// Does it contain the Trigger tree? |
272 |
|
|
// |
273 |
|
|
trigger = (TTree*)file->Get("Trigger"); |
274 |
|
|
if ( !trigger ) { |
275 |
|
|
if ( verbose ) printf(" TOF - ERROR: no trigger tree\n"); |
276 |
|
|
code = -302; |
277 |
|
|
goto closeandexit; |
278 |
|
|
}; |
279 |
|
|
// |
280 |
|
|
// get trigger level2 data pointer |
281 |
|
|
// |
282 |
|
|
trigger->SetBranchAddress("TrigLevel2",&trg); |
283 |
|
|
nevtrgl2 = trigger->GetEntries(); |
284 |
|
|
|
285 |
mocchiut |
1.1 |
// |
286 |
|
|
// Retrieve GL_RUN variables from the level2 file |
287 |
|
|
// |
288 |
|
|
tofversion = ToFInfo(false); // we should decide how to handle versioning system |
289 |
|
|
// |
290 |
|
|
// create an interface to RunInfo called "runinfo" |
291 |
|
|
// |
292 |
|
|
// ItoRunInfo= interface with RunInfo and GL_RUN |
293 |
|
|
runinfo = new ItoRunInfo(file); |
294 |
|
|
// |
295 |
|
|
// open "Run" tree in level2 file, if not existing return an error (sngl != 0) |
296 |
|
|
// |
297 |
|
|
sgnl = 0; |
298 |
|
|
sgnl = runinfo->Update(run, "TOF",tofversion); |
299 |
|
|
if ( sgnl ){ |
300 |
|
|
if ( verbose ) printf(" TOF - ERROR: RunInfo exited with non-zero status\n"); |
301 |
|
|
code = sgnl; |
302 |
|
|
goto closeandexit; |
303 |
|
|
} else { |
304 |
|
|
sgnl = 0; |
305 |
|
|
}; |
306 |
|
|
// |
307 |
|
|
// number of events in the file BEFORE the first event of our run |
308 |
|
|
// |
309 |
|
|
nobefrun = runinfo->GetFirstEntry(); |
310 |
|
|
// |
311 |
|
|
// total number of events in the file |
312 |
|
|
// |
313 |
|
|
totfileentries = runinfo->GetFileEntries(); |
314 |
|
|
// |
315 |
|
|
// first file entry AFTER the last event of our run |
316 |
|
|
// |
317 |
|
|
noaftrun = runinfo->GetLastEntry() + 1; |
318 |
|
|
// |
319 |
|
|
// number of run to be processed |
320 |
|
|
// |
321 |
|
|
numbofrun = runinfo->GetNoRun(); |
322 |
mocchiut |
1.36 |
totnorun = runinfo->GetRunEntries(); |
323 |
mocchiut |
1.1 |
// |
324 |
|
|
// Try to access the ToF tree in the file, if it exists we are reprocessing data if not we are processing a new run |
325 |
|
|
// |
326 |
|
|
toftclone = (TTree*)file->Get("ToF"); |
327 |
|
|
// |
328 |
|
|
if ( !toftclone ){ |
329 |
|
|
// |
330 |
|
|
// tree does not exist, we are not reprocessing |
331 |
|
|
// |
332 |
|
|
reproc = false; |
333 |
mocchiut |
1.6 |
if ( run == 0 && verbose ) printf(" ToF - WARNING: you are reprocessing data but ToF tree does not exist!\n"); |
334 |
|
|
if ( runinfo->IsReprocessing() && run != 0 && verbose ) printf(" ToF - WARNING: it seems you are not reprocessing data but ToF\n versioning information already exists in RunInfo.\n"); |
335 |
mocchiut |
1.1 |
|
336 |
|
|
} else { |
337 |
|
|
// |
338 |
|
|
// tree exists, we are reprocessing data. Are we reprocessing a single run or all the file? |
339 |
|
|
// |
340 |
mocchiut |
1.15 |
toftclone->SetAutoSave(900000000000000LL); |
341 |
mocchiut |
1.1 |
reproc = true; |
342 |
|
|
// |
343 |
|
|
// update versioning information |
344 |
|
|
// |
345 |
|
|
if ( verbose ) printf("\n Preparing the pre-processing...\n"); |
346 |
|
|
// |
347 |
mocchiut |
1.21 |
if ( run == 0 || totnorun == 1 ){ |
348 |
mocchiut |
1.1 |
// |
349 |
|
|
// we are reprocessing all the file |
350 |
|
|
// if we are reprocessing everything we don't need to copy any old event and we can just work with the new tree and delete the old one immediately |
351 |
|
|
// |
352 |
|
|
reprocall = true; |
353 |
|
|
// |
354 |
|
|
if ( verbose ) printf("\n ToF - WARNING: Reprocessing all runs\n"); |
355 |
|
|
// |
356 |
|
|
} else { |
357 |
|
|
// |
358 |
|
|
// we are reprocessing a single run, we must copy to the new tree the events in the file which preceed the first event of the run |
359 |
|
|
// |
360 |
|
|
reprocall = false; |
361 |
|
|
// |
362 |
mocchiut |
1.6 |
if ( verbose ) printf("\n ToF - WARNING: Reprocessing run number %u \n",run); |
363 |
mocchiut |
1.1 |
// |
364 |
|
|
// copying old tree to a new file |
365 |
|
|
// |
366 |
mocchiut |
1.25 |
gSystem->MakeDirectory(toffolder.str().c_str()); |
367 |
|
|
myfold = true; |
368 |
mocchiut |
1.1 |
tempfile = new TFile(tempname.str().c_str(),"RECREATE"); |
369 |
|
|
temptof = toftclone->CloneTree(-1,"fast"); |
370 |
|
|
temptof->SetName("ToF-old"); |
371 |
|
|
tempfile->Write(); |
372 |
|
|
tempfile->Close(); |
373 |
|
|
} |
374 |
|
|
// |
375 |
|
|
// Delete the old tree from old file and memory |
376 |
|
|
// |
377 |
|
|
toftclone->Delete("all"); |
378 |
|
|
// |
379 |
|
|
if ( verbose ) printf(" ...done!\n"); |
380 |
|
|
// |
381 |
|
|
}; |
382 |
|
|
// |
383 |
|
|
// create ToF detector tree toft |
384 |
|
|
// |
385 |
|
|
file->cd(); |
386 |
|
|
toft = new TTree("ToF-new","PAMELA Level2 ToF data"); |
387 |
mocchiut |
1.15 |
toft->SetAutoSave(900000000000000LL); |
388 |
|
|
tof->Set();//ELENA **TEMPORANEO?** |
389 |
mocchiut |
1.1 |
toft->Branch("ToFLevel2","ToFLevel2",&tof); |
390 |
|
|
// |
391 |
|
|
if ( reproc && !reprocall ){ |
392 |
|
|
// |
393 |
|
|
// open new file and retrieve all tree informations |
394 |
|
|
// |
395 |
|
|
tempfile = new TFile(tempname.str().c_str(),"READ"); |
396 |
|
|
toftclone = (TTree*)tempfile->Get("ToF-old"); |
397 |
mocchiut |
1.15 |
toftclone->SetAutoSave(900000000000000LL); |
398 |
mocchiut |
1.1 |
toftclone->SetBranchAddress("ToFLevel2",&tofclone); |
399 |
|
|
// |
400 |
|
|
if ( nobefrun > 0 ){ |
401 |
|
|
if ( verbose ) printf("\n Pre-processing: copying events from the old tree before the processed run\n"); |
402 |
mocchiut |
1.6 |
if ( verbose ) printf(" Copying %u events in the file which are before the beginning of the run %u \n",nobefrun,run); |
403 |
mocchiut |
1.1 |
if ( verbose ) printf(" Start copying at event number 0, end copying at event number %u \n",nobefrun); |
404 |
|
|
for (UInt_t j = 0; j < nobefrun; j++){ |
405 |
|
|
// |
406 |
mocchiut |
1.42 |
if ( toftclone->GetEntry(j) <= 0 ) throw -36; |
407 |
mocchiut |
1.1 |
// |
408 |
|
|
// copy tofclone to tof |
409 |
|
|
// |
410 |
mocchiut |
1.3 |
tof->Clear(); |
411 |
mocchiut |
1.1 |
memcpy(&tof,&tofclone,sizeof(tofclone)); |
412 |
|
|
// |
413 |
|
|
// Fill entry in the new tree |
414 |
|
|
// |
415 |
|
|
toft->Fill(); |
416 |
|
|
// |
417 |
|
|
}; |
418 |
|
|
if ( verbose ) printf(" Finished successful copying!\n"); |
419 |
|
|
}; |
420 |
|
|
}; |
421 |
|
|
// |
422 |
|
|
// Get the list of run to be processed, if only one run has to be processed the list will contain one entry only. |
423 |
|
|
// |
424 |
|
|
runlist = runinfo->GetRunList(); |
425 |
|
|
// |
426 |
|
|
// Loop over the run to be processed |
427 |
|
|
// |
428 |
|
|
for (UInt_t irun=0; irun < numbofrun; irun++){ |
429 |
|
|
// |
430 |
|
|
// retrieve the first run ID to be processed using the RunInfo list |
431 |
|
|
// |
432 |
|
|
idRun = runlist->At(irun); |
433 |
|
|
if ( verbose ) printf("\n\n\n ####################################################################### \n"); |
434 |
mocchiut |
1.6 |
if ( verbose ) printf(" PROCESSING RUN NUMBER %u \n",idRun); |
435 |
mocchiut |
1.1 |
if ( verbose ) printf(" ####################################################################### \n\n\n"); |
436 |
|
|
// |
437 |
mocchiut |
1.6 |
runinfo->ID_ROOT_L0 = 0; |
438 |
mocchiut |
1.1 |
// |
439 |
|
|
// store in the runinfo class the GL_RUN variables for our run |
440 |
|
|
// |
441 |
|
|
sgnl = 0; |
442 |
|
|
sgnl = runinfo->GetRunInfo(idRun); |
443 |
|
|
if ( sgnl ){ |
444 |
|
|
if ( verbose ) printf(" TOF - ERROR: RunInfo exited with non-zero status\n"); |
445 |
|
|
code = sgnl; |
446 |
|
|
goto closeandexit; |
447 |
|
|
} else { |
448 |
|
|
sgnl = 0; |
449 |
|
|
}; |
450 |
|
|
// |
451 |
mocchiut |
1.6 |
// now you can access that variables using the RunInfo class this way runinfo->ID_ROOT_L0 |
452 |
mocchiut |
1.1 |
// |
453 |
mocchiut |
1.6 |
if ( runinfo->ID_ROOT_L0 == 0 ){ |
454 |
|
|
if ( verbose ) printf("\n TOF - ERROR: no run with ID_RUN = %u \n\n Exiting... \n\n",idRun); |
455 |
mocchiut |
1.1 |
code = -5; |
456 |
|
|
goto closeandexit; |
457 |
|
|
}; |
458 |
|
|
// |
459 |
mocchiut |
1.6 |
// prepare the timesync for the db |
460 |
|
|
// |
461 |
mocchiut |
1.27 |
TString host = glt->CGetHost(); |
462 |
|
|
TString user = glt->CGetUser(); |
463 |
|
|
TString psw = glt->CGetPsw(); |
464 |
|
|
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
465 |
|
|
if ( !dbc->IsConnected() ) throw -314; |
466 |
mocchiut |
1.28 |
stringstream myquery; |
467 |
|
|
myquery.str(""); |
468 |
|
|
myquery << "SET time_zone='+0:00'"; |
469 |
|
|
dbc->Query(myquery.str().c_str()); |
470 |
mocchiut |
1.6 |
dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc); |
471 |
|
|
// |
472 |
mocchiut |
1.1 |
// Search in the DB the path and name of the LEVEL0 file to be processed. |
473 |
|
|
// |
474 |
mocchiut |
1.26 |
// if ( !dbc->IsConnected() ) throw -314; |
475 |
mocchiut |
1.6 |
glroot->Query_GL_ROOT(runinfo->ID_ROOT_L0,dbc); |
476 |
mocchiut |
1.1 |
// |
477 |
|
|
ftmpname.str(""); |
478 |
|
|
ftmpname << glroot->PATH.Data() << "/"; |
479 |
|
|
ftmpname << glroot->NAME.Data(); |
480 |
|
|
fname = ftmpname.str().c_str(); |
481 |
|
|
// |
482 |
|
|
// print out informations |
483 |
|
|
// |
484 |
mocchiut |
1.6 |
totevent = runinfo->NEVENTS; |
485 |
mocchiut |
1.1 |
if ( verbose ) printf("\n LEVEL0 data file: %s \n",fname.Data()); |
486 |
mocchiut |
1.6 |
if ( verbose ) printf(" RUN HEADER absolute time is: %u \n",runinfo->RUNHEADER_TIME); |
487 |
|
|
if ( verbose ) printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME); |
488 |
|
|
if ( verbose ) printf(" %i events to be processed for run %u: from %i to %i \n\n",totevent,idRun,runinfo->EV_FROM,runinfo->EV_FROM+totevent); |
489 |
mocchiut |
1.1 |
// |
490 |
mocchiut |
1.31 |
// if ( !totevent ) goto closeandexit; |
491 |
mocchiut |
1.30 |
// |
492 |
mocchiut |
1.1 |
// Open Level0 file |
493 |
|
|
// |
494 |
|
|
l0File = new TFile(fname.Data()); |
495 |
|
|
if ( !l0File ) { |
496 |
|
|
if ( verbose ) printf(" TOF - ERROR: problems opening Level0 file\n"); |
497 |
|
|
code = -6; |
498 |
|
|
goto closeandexit; |
499 |
|
|
}; |
500 |
|
|
l0tr = (TTree*)l0File->Get("Physics"); |
501 |
|
|
if ( !l0tr ) { |
502 |
|
|
if ( verbose ) printf(" TOF - ERROR: no Physics tree in Level0 file\n"); |
503 |
|
|
l0File->Close(); |
504 |
|
|
code = -7; |
505 |
|
|
goto closeandexit; |
506 |
|
|
}; |
507 |
|
|
l0head = l0tr->GetBranch("Header"); |
508 |
|
|
if ( !l0head ) { |
509 |
|
|
if ( verbose ) printf(" TOF - ERROR: no Header branch in Level0 tree\n"); |
510 |
|
|
l0File->Close(); |
511 |
|
|
code = -8; |
512 |
|
|
goto closeandexit; |
513 |
|
|
}; |
514 |
mocchiut |
1.48 |
// l0trig = l0tr->GetBranch("Trigger"); |
515 |
|
|
// if ( !l0trig ) { |
516 |
|
|
// if ( verbose ) printf(" TOF - ERROR: no Trigger branch in Level0 tree\n"); |
517 |
|
|
// l0File->Close(); |
518 |
|
|
// code = -300; |
519 |
|
|
// goto closeandexit; |
520 |
|
|
// }; |
521 |
mocchiut |
1.1 |
l0tof = l0tr->GetBranch("Tof"); |
522 |
|
|
if ( !l0tof ) { |
523 |
|
|
if ( verbose ) printf(" TOF - ERROR: no ToF branch in Level0 tree\n"); |
524 |
|
|
l0File->Close(); |
525 |
|
|
code = -303; |
526 |
|
|
goto closeandexit; |
527 |
|
|
}; |
528 |
|
|
// |
529 |
mocchiut |
1.48 |
// l0tr->SetBranchAddress("Trigger", &trig); |
530 |
mocchiut |
1.1 |
l0tr->SetBranchAddress("Tof", &tofEvent); |
531 |
mocchiut |
1.6 |
l0tr->SetBranchAddress("Header", &eh); |
532 |
mocchiut |
1.1 |
// |
533 |
mocchiut |
1.6 |
nevents = l0tof->GetEntries(); |
534 |
mocchiut |
1.1 |
// |
535 |
mocchiut |
1.31 |
if ( nevents < 1 && totevent ) { |
536 |
mocchiut |
1.1 |
if ( verbose ) printf(" TOF - ERROR: Level0 file is empty\n\n"); |
537 |
|
|
l0File->Close(); |
538 |
|
|
code = -11; |
539 |
|
|
goto closeandexit; |
540 |
|
|
}; |
541 |
|
|
// |
542 |
mocchiut |
1.31 |
if ( runinfo->EV_TO > nevents-1 && totevent ) { |
543 |
mocchiut |
1.1 |
if ( verbose ) printf(" TOF - ERROR: too few entries in the registry tree\n"); |
544 |
|
|
l0File->Close(); |
545 |
|
|
code = -12; |
546 |
|
|
goto closeandexit; |
547 |
|
|
}; |
548 |
|
|
// |
549 |
|
|
// Check if we have to load parameter files (or calibration associated to runs and not to events) |
550 |
|
|
// |
551 |
|
|
// for example let's assume that we could have different magnetic field maps for different runs: |
552 |
|
|
// |
553 |
|
|
if ( trkpar1 || ( tttrkpar1 != 0 && tttrkpar1 < runinfo->RUNHEADER_TIME ) ){ |
554 |
|
|
trkpar1 = false; |
555 |
|
|
// read from DB infos about Magnetic filed maps |
556 |
mocchiut |
1.26 |
// if ( !dbc->IsConnected() ) throw -314; |
557 |
mocchiut |
1.6 |
glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,1,dbc); // parameters stored in DB in GL_PRAM table |
558 |
mocchiut |
1.1 |
tttrkpar1 = glparam->TO_TIME; |
559 |
|
|
// ---------------------------- |
560 |
|
|
// Read the magnetic field |
561 |
|
|
// ---------------------------- |
562 |
|
|
if ( verbose ) printf(" Reading magnetic field maps: \n"); |
563 |
|
|
trk->LoadField(glparam->PATH+glparam->NAME); |
564 |
|
|
if ( verbose ) printf("\n"); |
565 |
|
|
}; |
566 |
mocchiut |
1.6 |
// |
567 |
mocchiut |
1.22 |
// variable to save information about the tof calibration used |
568 |
|
|
// |
569 |
|
|
Bool_t defcal = true; |
570 |
|
|
// |
571 |
mocchiut |
1.1 |
if ( tofpar1 || ( tttofpar1 != 0 && tttofpar1 < runinfo->RUNHEADER_TIME ) ){ |
572 |
|
|
tofpar1 = false; |
573 |
|
|
// |
574 |
mocchiut |
1.26 |
// if ( !dbc->IsConnected() ) throw -314; |
575 |
mocchiut |
1.6 |
Int_t error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,201,dbc); // parameters stored in DB in GL_PRAM table |
576 |
mocchiut |
1.1 |
if ( error<0 ) { |
577 |
|
|
code = error; |
578 |
|
|
goto closeandexit; |
579 |
|
|
}; |
580 |
|
|
// |
581 |
mocchiut |
1.9 |
if ( verbose ) printf(" Reading ToF parameter file: %s \n",(glparam->PATH+glparam->NAME).Data()); |
582 |
|
|
// |
583 |
mocchiut |
1.24 |
if ( (UInt_t)glparam->TO_TIME != (UInt_t)4294967295UL ) defcal = false; |
584 |
mocchiut |
1.22 |
// |
585 |
mocchiut |
1.1 |
tttofpar1 = glparam->TO_TIME; |
586 |
mocchiut |
1.9 |
Int_t nlen = (Int_t)(glparam->PATH+glparam->NAME).Length(); |
587 |
mocchiut |
1.46 |
// rdtofcal((char *)(glparam->PATH+glparam->NAME).Data(),&nlen); |
588 |
|
|
rdtofcal((const char *)(glparam->PATH+glparam->NAME).Data(),&nlen); |
589 |
mocchiut |
1.20 |
// |
590 |
mocchiut |
1.1 |
}; |
591 |
|
|
// |
592 |
carbone |
1.37 |
Int_t error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,204,dbc); // parameters stored in DB in GL_PRAM table |
593 |
|
|
if ( error<0 ) { |
594 |
|
|
code = error; |
595 |
|
|
goto closeandexit; |
596 |
|
|
}; |
597 |
|
|
// |
598 |
|
|
if ( verbose ) printf(" Reading ToF attenuation parameter file: %s \n",(glparam->PATH+glparam->NAME).Data()); |
599 |
|
|
tofdedx->ReadParAtt((glparam->PATH+glparam->NAME).Data()); |
600 |
|
|
|
601 |
|
|
// |
602 |
|
|
error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,205,dbc); // parameters stored in DB in GL_PRAM table |
603 |
|
|
if ( error<0 ) { |
604 |
|
|
code = error; |
605 |
|
|
goto closeandexit; |
606 |
|
|
}; |
607 |
|
|
// |
608 |
|
|
if ( verbose ) printf(" Reading ToF desaturation on position parameter file: %s \n",(glparam->PATH+glparam->NAME).Data()); |
609 |
|
|
tofdedx->ReadParPos((glparam->PATH+glparam->NAME).Data()); |
610 |
|
|
|
611 |
|
|
// |
612 |
|
|
error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,206,dbc); // parameters stored in DB in GL_PRAM table |
613 |
|
|
if ( error<0 ) { |
614 |
|
|
code = error; |
615 |
|
|
goto closeandexit; |
616 |
|
|
}; |
617 |
|
|
// |
618 |
|
|
if ( verbose ) printf(" Reading ToF BetheBloch parameter file: %s \n",(glparam->PATH+glparam->NAME).Data()); |
619 |
|
|
tofdedx->ReadParBBneg((glparam->PATH+glparam->NAME).Data()); |
620 |
|
|
|
621 |
|
|
// |
622 |
|
|
error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,207,dbc); // parameters stored in DB in GL_PRAM table |
623 |
|
|
if ( error<0 ) { |
624 |
|
|
code = error; |
625 |
|
|
goto closeandexit; |
626 |
|
|
}; |
627 |
|
|
// |
628 |
|
|
if ( verbose ) printf(" Reading ToF Bethe-Bloch parameter file for beta gt1: %s \n",(glparam->PATH+glparam->NAME).Data()); |
629 |
|
|
tofdedx->ReadParBBpos((glparam->PATH+glparam->NAME).Data()); |
630 |
|
|
|
631 |
|
|
// |
632 |
|
|
error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,208,dbc); // parameters stored in DB in GL_PRAM table |
633 |
|
|
if ( error<0 ) { |
634 |
|
|
code = error; |
635 |
|
|
goto closeandexit; |
636 |
|
|
}; |
637 |
|
|
// |
638 |
|
|
if ( verbose ) printf(" Reading ToF desaturation on beta parameter file: %s \n",(glparam->PATH+glparam->NAME).Data()); |
639 |
|
|
tofdedx->ReadParDesatBB((glparam->PATH+glparam->NAME).Data()); |
640 |
|
|
|
641 |
|
|
|
642 |
|
|
tofdedx->CheckConnectors(runinfo->RUNHEADER_TIME,glparam,dbc); |
643 |
|
|
|
644 |
|
|
// |
645 |
mocchiut |
1.32 |
// WM reading parameter file for dE/dx II order corrections |
646 |
|
|
// |
647 |
mocchiut |
1.48 |
//memset(dedx_corr_m,0,100*48*sizeof(Float_t)); |
648 |
|
|
//memset(dedx_corr,0,48*sizeof(Float_t)); |
649 |
|
|
//memset(mtime,0,100*sizeof(Double_t)); |
650 |
|
|
|
651 |
|
|
// |
652 |
|
|
// RC reading parameter file for new dE/dx II order correction (10th red) |
653 |
|
|
// |
654 |
|
|
memset(dedx_Hepeak_m,0,100*48*sizeof(Float_t)); |
655 |
|
|
memset(dedx_ppeak_m,0,100*48*sizeof(Float_t)); |
656 |
|
|
memset(dedx_Hepeak,0,48*sizeof(Float_t)); |
657 |
|
|
memset(dedx_ppeak,0,48*sizeof(Float_t)); |
658 |
mocchiut |
1.32 |
memset(mtime,0,100*sizeof(Double_t)); |
659 |
mocchiut |
1.48 |
|
660 |
mocchiut |
1.32 |
// |
661 |
|
|
// Query the DB to get the file |
662 |
|
|
// |
663 |
carbone |
1.37 |
error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,203,dbc); // parameters stored in DB in GL_PRAM table |
664 |
mocchiut |
1.32 |
if ( error<0 ) { |
665 |
|
|
code = error; |
666 |
|
|
goto closeandexit; |
667 |
|
|
}; |
668 |
|
|
// |
669 |
|
|
if ( verbose ) printf(" Reading ToF dE/dx II order correction parameter file: %s \n",(glparam->PATH+glparam->NAME).Data()); |
670 |
|
|
// |
671 |
|
|
ical=0; // counter set to zero if first-time reading |
672 |
|
|
//----------------------------------------------------------- |
673 |
|
|
// Here I read the dEdx_korr parameters |
674 |
|
|
//----------------------------------------------------------- |
675 |
|
|
jj=0; |
676 |
|
|
ifstream fin((glparam->PATH+glparam->NAME).Data()); |
677 |
mocchiut |
1.33 |
UInt_t window = 200000; |
678 |
|
|
Bool_t first = true; |
679 |
|
|
Bool_t last = true; |
680 |
mocchiut |
1.48 |
//Float_t sdedx_corr_m[48]; |
681 |
|
|
//memset(sdedx_corr_m,0,48*sizeof(Float_t)); |
682 |
|
|
|
683 |
|
|
Float_t sdedx_Hepeak_m[48]; |
684 |
|
|
memset(sdedx_Hepeak_m,0,48*sizeof(Float_t)); |
685 |
|
|
Float_t sdedx_ppeak_m[48]; |
686 |
|
|
memset(sdedx_ppeak_m,0,48*sizeof(Float_t)); |
687 |
|
|
|
688 |
mocchiut |
1.33 |
Double_t stm = 0; |
689 |
mocchiut |
1.32 |
while ( !fin.eof() ){ |
690 |
mocchiut |
1.33 |
stm = tm; |
691 |
mocchiut |
1.35 |
// if ( jj > 0 ) memcpy(sdedx_corr_m,dedx_corr_m[jj-1],48*sizeof(Float_t)); // BUG sdedx should be the previous in time not the previous saved [absurd dE/dx for 8th reduction March and > March 2008 data - fixed on 2009/02/04 |
692 |
mocchiut |
1.32 |
fin>>t1>>tm>>t2; |
693 |
|
|
if ( verbose ) cout << setiosflags(ios::fixed) << setw(10) << setprecision(3) << tm << endl; |
694 |
mocchiut |
1.33 |
if ( (tm >= (runinfo->RUNHEADER_TIME-window) && tm <= (runinfo->RUNTRAILER_TIME+window)) || (tm > (runinfo->RUNTRAILER_TIME+window) && last) ){ |
695 |
|
|
if ( first ){ |
696 |
|
|
mtime[jj]=stm; |
697 |
|
|
jj++; |
698 |
|
|
if ( jj >= 100 ){ |
699 |
|
|
code = -318; |
700 |
|
|
goto closeandexit; |
701 |
|
|
}; |
702 |
|
|
}; |
703 |
mocchiut |
1.32 |
mtime[jj]=tm; |
704 |
|
|
}; |
705 |
|
|
for (ii=0; ii<48;ii++){ |
706 |
|
|
fin>>wj>>xmean1>>xwidth1; |
707 |
mocchiut |
1.33 |
if ( (tm >= (runinfo->RUNHEADER_TIME-window) && tm <= (runinfo->RUNTRAILER_TIME+window)) || (tm > (runinfo->RUNTRAILER_TIME+window) && last) ){ |
708 |
mocchiut |
1.35 |
if ( first ){ |
709 |
mocchiut |
1.48 |
//dedx_corr_m[jj-1][ii]=sdedx_corr_m[ii]; |
710 |
|
|
|
711 |
|
|
dedx_Hepeak_m[jj-1][ii]=sdedx_Hepeak_m[ii]; |
712 |
|
|
dedx_ppeak_m[jj-1][ii]=sdedx_ppeak_m[ii]; |
713 |
mocchiut |
1.33 |
}; |
714 |
mocchiut |
1.48 |
//dedx_corr_m[jj][ii]=xmean1; |
715 |
|
|
|
716 |
|
|
dedx_Hepeak_m[jj][ii]=xmean1; |
717 |
|
|
dedx_ppeak_m[jj][ii]=xwidth1; |
718 |
mocchiut |
1.32 |
}; |
719 |
mocchiut |
1.48 |
//sdedx_corr_m[ii]=xmean1; // BUG sdedx should be the previous in time not the previous saved [absurd dE/dx for 8th reduction March and > March 2008 data - fixed on 2009/02/04 |
720 |
|
|
sdedx_Hepeak_m[ii]=xmean1; |
721 |
|
|
sdedx_ppeak_m[ii]=xwidth1; |
722 |
|
|
|
723 |
mocchiut |
1.32 |
}; |
724 |
mocchiut |
1.33 |
if ( (tm >= (runinfo->RUNHEADER_TIME-window) && tm <= (runinfo->RUNTRAILER_TIME+window)) || (tm > (runinfo->RUNTRAILER_TIME+window) && last)){ |
725 |
|
|
if ( first ) first = false; |
726 |
|
|
if ( tm > (runinfo->RUNTRAILER_TIME+window) ) last = false; |
727 |
mocchiut |
1.32 |
jj++; |
728 |
|
|
}; |
729 |
|
|
if ( jj >= 100 ){ |
730 |
|
|
code = -318; |
731 |
|
|
goto closeandexit; |
732 |
|
|
}; |
733 |
|
|
}; |
734 |
|
|
// |
735 |
mocchiut |
1.35 |
fin.close(); |
736 |
|
|
// this is a possible bug... |
737 |
|
|
// Bool_t ff = false; |
738 |
|
|
// while ( runinfo->RUNHEADER_TIME > mtime[ical] && ical < 100 ) { |
739 |
|
|
// ical = ical+1; |
740 |
|
|
// ff = true; |
741 |
|
|
// }; |
742 |
|
|
while ( (mtime[ical] > runinfo->RUNHEADER_TIME || runinfo->RUNHEADER_TIME > mtime[ical+1] ) && ical < 99 ) { |
743 |
mocchiut |
1.32 |
ical = ical+1; |
744 |
mocchiut |
1.35 |
// ff = true; |
745 |
mocchiut |
1.32 |
}; |
746 |
mocchiut |
1.35 |
// if ( ff ) ical = ical-1; |
747 |
mocchiut |
1.32 |
if ( verbose ) cout<<"rh time "<<runinfo->RUNHEADER_TIME<<" rt time "<<runinfo->RUNTRAILER_TIME<<" limit low "<<mtime[ical]<<" limit up "<<mtime[ical+1]<<" ical "<<ical<< " jj " << jj<< endl; |
748 |
|
|
if ( ical < 0 || ical >= 98 ){ |
749 |
|
|
code = -315; |
750 |
|
|
goto closeandexit; |
751 |
|
|
}; |
752 |
|
|
// |
753 |
mocchiut |
1.1 |
// run over all the events of the run |
754 |
|
|
// |
755 |
|
|
if ( verbose ) printf("\n Ready to start! \n\n Processed events: \n\n"); |
756 |
|
|
// |
757 |
mocchiut |
1.26 |
if ( dbc ){ |
758 |
|
|
dbc->Close(); |
759 |
mocchiut |
1.27 |
delete dbc; |
760 |
pam-fi |
1.47 |
dbc = 0; |
761 |
mocchiut |
1.26 |
}; |
762 |
|
|
// |
763 |
mocchiut |
1.7 |
jumped = 0; |
764 |
mocchiut |
1.6 |
// |
765 |
|
|
for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){ |
766 |
mocchiut |
1.49 |
// for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+100); re++){ // QUIIIIIII |
767 |
mocchiut |
1.1 |
// |
768 |
|
|
if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000); |
769 |
|
|
// |
770 |
mocchiut |
1.42 |
if ( l0head->GetEntry(re) <= 0 ) throw -36; |
771 |
mocchiut |
1.1 |
// |
772 |
|
|
// absolute time of this event |
773 |
|
|
// |
774 |
mocchiut |
1.6 |
ph = eh->GetPscuHeader(); |
775 |
|
|
atime = dbtime->DBabsTime(ph->GetOrbitalTime()); |
776 |
mocchiut |
1.4 |
// |
777 |
|
|
tof->Clear(); |
778 |
|
|
Int_t pmt_id = 0; |
779 |
|
|
ToFPMT *t_pmt = new ToFPMT(); |
780 |
mocchiut |
1.15 |
if(!(tof->PMT))tof->PMT = new TClonesArray("ToFPMT",12); //ELENA |
781 |
mocchiut |
1.4 |
TClonesArray &tpmt = *tof->PMT; |
782 |
|
|
ToFTrkVar *t_tof = new ToFTrkVar(); |
783 |
mocchiut |
1.15 |
if(!(tof->ToFTrk))tof->ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA |
784 |
mocchiut |
1.4 |
TClonesArray &t = *tof->ToFTrk; |
785 |
|
|
// |
786 |
mocchiut |
1.1 |
// paranoid check |
787 |
|
|
// |
788 |
mocchiut |
1.32 |
if ( atime > (runinfo->RUNTRAILER_TIME+1) || atime < (runinfo->RUNHEADER_TIME-1) ) { |
789 |
mocchiut |
1.1 |
if ( verbose ) printf(" TOF - WARNING: event at time outside the run time window, skipping it\n"); |
790 |
mocchiut |
1.7 |
jumped++; |
791 |
mocchiut |
1.1 |
goto jumpev; |
792 |
|
|
}; |
793 |
|
|
// |
794 |
|
|
// retrieve tracker informations, the LEVEL2 entry which correspond to our event will be "itr" |
795 |
|
|
// |
796 |
|
|
if ( !reprocall ){ |
797 |
mocchiut |
1.7 |
itr = nobefrun + (re - runinfo->EV_FROM -jumped); |
798 |
mocchiut |
1.1 |
} else { |
799 |
mocchiut |
1.7 |
itr = runinfo->GetFirstEntry() + (re - runinfo->EV_FROM -jumped); |
800 |
mocchiut |
1.1 |
}; |
801 |
|
|
if ( itr > nevtrkl2 ){ // nevtrkl2 tracker entry number |
802 |
|
|
if ( verbose ) printf(" TOF - ERROR: no tracker events with entry = %i in Level2 file\n",itr); |
803 |
|
|
l0File->Close(); |
804 |
|
|
code = -313; |
805 |
|
|
goto closeandexit; |
806 |
|
|
}; |
807 |
mocchiut |
1.48 |
if ( itr > nevtrgl2 ){ // nevtrgl2 trigger entry number |
808 |
|
|
if ( verbose ) printf(" TOF - ERROR: no trigger events with entry = %i in Level2 file\n",itr); |
809 |
|
|
l0File->Close(); |
810 |
|
|
code = -319; |
811 |
|
|
goto closeandexit; |
812 |
|
|
}; |
813 |
mocchiut |
1.8 |
// |
814 |
|
|
trk->Clear(); |
815 |
mocchiut |
1.48 |
trg->Clear(); |
816 |
mocchiut |
1.8 |
// |
817 |
mocchiut |
1.42 |
if ( tracker->GetEntry(itr) <= 0 ) throw -36; |
818 |
mocchiut |
1.48 |
if ( trigger->GetEntry(itr) <= 0 ) throw -36; |
819 |
mocchiut |
1.1 |
/// |
820 |
mocchiut |
1.2 |
// |
821 |
mocchiut |
1.42 |
if ( l0tof->GetEntry(re) <= 0 ) throw -36; |
822 |
mocchiut |
1.48 |
// if ( l0trig->GetEntry(re) <= 0 ) throw -36; |
823 |
mocchiut |
1.1 |
/// |
824 |
|
|
// |
825 |
|
|
procev++; |
826 |
|
|
// |
827 |
|
|
// start processing |
828 |
|
|
// |
829 |
mocchiut |
1.32 |
// dE/dx II order correction: check time limits and interpolate time correction |
830 |
|
|
//================================================================== |
831 |
|
|
//== if time is outside time limits: |
832 |
|
|
//================================================================== |
833 |
|
|
if ( atime<mtime[ical] || atime>mtime[ical+1] ){ |
834 |
|
|
if ( verbose ) cout<<"Checking Time Limits!"<<endl; |
835 |
|
|
ical=0; |
836 |
mocchiut |
1.35 |
//Bool_t fg = false; |
837 |
|
|
while ( ( mtime[ical] > atime || atime > mtime[ical+1]) && ical < 99 ){ |
838 |
mocchiut |
1.32 |
ical = ical+1; |
839 |
mocchiut |
1.35 |
//fg = true; |
840 |
mocchiut |
1.32 |
} |
841 |
mocchiut |
1.35 |
// if ( fg ) ical = ical-1; |
842 |
mocchiut |
1.32 |
if ( ical < 0 || ical >= 98 ){ |
843 |
|
|
code = -317; |
844 |
|
|
goto closeandexit; |
845 |
|
|
}; |
846 |
|
|
if ( verbose ) cout<<"abs time "<<atime<<" limit low "<<mtime[ical]<<" limit up "<<mtime[ical+1]<<" ical "<<ical<<endl; |
847 |
|
|
}; |
848 |
|
|
//================================================================== |
849 |
|
|
//== interpolate betwen time limits |
850 |
|
|
//================================================================== |
851 |
|
|
thelp1 = mtime[ical]; |
852 |
|
|
thelp2 = mtime[ical+1]; |
853 |
|
|
for (ii=0; ii<48;ii++) { |
854 |
mocchiut |
1.48 |
//yhelp1 = fabs(dedx_corr_m[ical][ii]); |
855 |
|
|
//if ( yhelp1 < 0.1 ) yhelp1 = 4.; |
856 |
|
|
//yhelp2 = fabs(dedx_corr_m[ical+1][ii]); |
857 |
|
|
//if ( yhelp2 < 0.1 ) yhelp2 = 4.; |
858 |
|
|
//slope = (yhelp2-yhelp1)/(thelp2-thelp1); |
859 |
|
|
//inter = yhelp1 - slope*thelp1; |
860 |
|
|
//dedx_corr[ii] = slope*atime + inter; |
861 |
|
|
|
862 |
|
|
Heyhelp1 = fabs(dedx_Hepeak_m[ical][ii]); |
863 |
|
|
if ( Heyhelp1 < 0.1 ) Heyhelp1 = 4.; |
864 |
|
|
Heyhelp2 = fabs(dedx_Hepeak_m[ical+1][ii]); |
865 |
|
|
if ( Heyhelp2 < 0.1 ) Heyhelp2 = 4.; |
866 |
|
|
Heslope = (Heyhelp2-Heyhelp1)/(thelp2-thelp1); |
867 |
|
|
Heinter = Heyhelp1 - Heslope*thelp1; |
868 |
|
|
dedx_Hepeak[ii] = Heslope*atime + Heinter; |
869 |
|
|
|
870 |
|
|
pyhelp1 = fabs(dedx_ppeak_m[ical][ii]); |
871 |
|
|
if ( pyhelp1 < 0.1 ) pyhelp1 = 1.; |
872 |
|
|
pyhelp2 = fabs(dedx_ppeak_m[ical+1][ii]); |
873 |
|
|
if ( pyhelp2 < 0.1 ) pyhelp2 = 1.; |
874 |
|
|
pslope = (pyhelp2-pyhelp1)/(thelp2-thelp1); |
875 |
|
|
pinter = pyhelp1 - pslope*thelp1; |
876 |
|
|
dedx_ppeak[ii] = pslope*atime + pinter; |
877 |
|
|
|
878 |
|
|
if(dedx_Hepeak[ii]>dedx_ppeak[ii])slope_dedx[ii]=3./(dedx_Hepeak[ii]-dedx_ppeak[ii]); |
879 |
|
|
else slope_dedx[ii]=4.; |
880 |
|
|
if(dedx_Hepeak[ii]>dedx_ppeak[ii])inter_dedx[ii]=1.-(slope_dedx[ii]*dedx_ppeak[ii]); |
881 |
|
|
else inter_dedx[ii]=0.; |
882 |
|
|
|
883 |
|
|
|
884 |
|
|
//if ( fabs(dedx_corr[ii]) <= 1e-15 ){ |
885 |
|
|
if ( fabs(dedx_ppeak[ii]) <= 1e-15 ){ |
886 |
|
|
//if ( verbose ) printf("ii %i slope %f atime %u inter %f dedx_corr %f \n",ii,slope,atime,inter,dedx_corr[ii]); |
887 |
|
|
if ( verbose ) printf("ii %i pslope %f atime %u pinter %f dedx_ppeak %f \n",ii,pslope,atime,pinter,dedx_ppeak[ii]); |
888 |
|
|
//if ( verbose ) printf("ical %i yhelp2 %f yhelp1 %f thelp2 %f thelp1 %f \n",ical,yhelp2,yhelp1,thelp2,thelp1); |
889 |
|
|
if ( verbose ) printf("ical %i pyhelp2 %f pyhelp1 %f thelp2 %f thelp1 %f \n",ical,pyhelp2,pyhelp1,thelp2,thelp1); |
890 |
mocchiut |
1.32 |
code = -316; |
891 |
|
|
goto closeandexit; |
892 |
|
|
}; |
893 |
|
|
}; |
894 |
|
|
//================================================================ |
895 |
|
|
//================================================================ |
896 |
mocchiut |
1.1 |
// |
897 |
|
|
// Here we will use some procedure to calibrate our data and put some kind of informations in the cinput structure |
898 |
mocchiut |
1.32 |
// |
899 |
mocchiut |
1.1 |
for (Int_t gg=0; gg<4;gg++){ |
900 |
|
|
for (Int_t hh=0; hh<12;hh++){ |
901 |
mocchiut |
1.48 |
tofinput_.tdc[hh][gg] = (0xFFF & tofEvent->tdc[gg][hh]); // exclude warning bits |
902 |
|
|
tofinput_.adc[hh][gg] = (0xFFF & tofEvent->adc[gg][hh]); // exclude warning bits |
903 |
mocchiut |
1.49 |
/* if (tofEvent->tdc[gg][hh] < 4095 || tofEvent->adc[gg][hh] < 4095 || tofinput_.tdc[hh][gg] < 4095 || tofinput_.adc[hh][gg] < 4095 ) { |
904 |
|
|
printf(" g %i h %i TDC event %i masked %i \n",gg,hh,tofEvent->tdc[gg][hh],tofinput_.tdc[hh][gg]); |
905 |
|
|
printf(" g %i h %i ADC event %i masked %i \n",gg,hh,tofEvent->adc[gg][hh],tofinput_.adc[hh][gg]); |
906 |
|
|
}*/ |
907 |
mocchiut |
1.1 |
}; |
908 |
|
|
}; |
909 |
mocchiut |
1.32 |
// |
910 |
mocchiut |
1.38 |
tofdedx->Init(tofEvent); |
911 |
mocchiut |
1.49 |
/* for (Int_t gg=0; gg<4;gg++){ |
912 |
|
|
for (Int_t hh=0; hh<12;hh++){ |
913 |
|
|
if (tofEvent->tdc[gg][hh] < 4095 || tofEvent->adc[gg][hh] < 4095 || tofinput_.tdc[hh][gg] < 4095 || tofinput_.adc[hh][gg] < 4095 ) { |
914 |
|
|
printf("A g %i h %i TDC event %i masked %i \n",gg,hh,tofEvent->tdc[gg][hh],tofinput_.tdc[hh][gg]); |
915 |
|
|
printf("A g %i h %i ADC event %i masked %i \n",gg,hh,tofEvent->adc[gg][hh],tofinput_.adc[hh][gg]); |
916 |
|
|
} |
917 |
|
|
}; |
918 |
|
|
};*/ |
919 |
|
|
|
920 |
mocchiut |
1.48 |
warning = 0; |
921 |
mocchiut |
1.38 |
// |
922 |
mocchiut |
1.1 |
for (Int_t hh=0; hh<5;hh++){ |
923 |
mocchiut |
1.48 |
tofinput_.patterntrig[hh]=trg->patterntrig[hh]; |
924 |
mocchiut |
1.1 |
}; |
925 |
|
|
// |
926 |
|
|
// Here we have calibrated data, ready to be passed to the FORTRAN routine which will extract common and track-related variables. |
927 |
|
|
// |
928 |
mocchiut |
1.4 |
npmtentry = 0; |
929 |
|
|
// |
930 |
|
|
ntrkentry = 0; |
931 |
mocchiut |
1.1 |
// |
932 |
|
|
// Calculate tracks informations from ToF alone |
933 |
|
|
// |
934 |
|
|
tofl2com(); |
935 |
mocchiut |
1.49 |
/* for (Int_t gg=0; gg<4;gg++){ |
936 |
|
|
for (Int_t hh=0; hh<12;hh++){ |
937 |
|
|
if (tofEvent->tdc[gg][hh] < 4095 || tofEvent->adc[gg][hh] < 4095 || tofinput_.tdc[hh][gg] < 4095 || tofinput_.adc[hh][gg] < 4095 ) { |
938 |
|
|
printf("B g %i h %i TDC event %i masked %i \n",gg,hh,tofEvent->tdc[gg][hh],tofinput_.tdc[hh][gg]); |
939 |
|
|
printf("B g %i h %i ADC event %i masked %i \n",gg,hh,tofEvent->adc[gg][hh],tofinput_.adc[hh][gg]); |
940 |
|
|
} |
941 |
|
|
}; |
942 |
|
|
};*/ |
943 |
mocchiut |
1.1 |
// |
944 |
mocchiut |
1.4 |
memcpy(tof->tof_j_flag,tofoutput_.tof_j_flag,6*sizeof(Int_t)); |
945 |
|
|
// |
946 |
|
|
t_tof->trkseqno = -1; |
947 |
|
|
// |
948 |
mocchiut |
1.1 |
// and now we must copy from the output structure to the level2 class: |
949 |
|
|
// |
950 |
mocchiut |
1.4 |
t_tof->npmttdc = 0; |
951 |
|
|
// |
952 |
mocchiut |
1.1 |
for (Int_t hh=0; hh<12;hh++){ |
953 |
|
|
for (Int_t kk=0; kk<4;kk++){ |
954 |
mocchiut |
1.4 |
if ( tofoutput_.tofmask[hh][kk] != 0 ){ |
955 |
|
|
pmt_id = tof->GetPMTid(kk,hh); |
956 |
|
|
t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc); |
957 |
mocchiut |
1.14 |
t_tof->tdcflag.AddAt(tofoutput_.tdcflagtof[hh][kk],t_tof->npmttdc); // gf: Jan 09/07 |
958 |
mocchiut |
1.4 |
t_tof->npmttdc++; |
959 |
|
|
}; |
960 |
|
|
}; |
961 |
|
|
}; |
962 |
|
|
for (Int_t kk=0; kk<13;kk++){ |
963 |
|
|
t_tof->beta[kk] = tofoutput_.betatof_a[kk]; |
964 |
mocchiut |
1.1 |
} |
965 |
mocchiut |
1.4 |
// |
966 |
carbone |
1.37 |
|
967 |
|
|
// |
968 |
|
|
memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos)); |
969 |
|
|
memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos)); |
970 |
|
|
memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof)); |
971 |
|
|
memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof)); |
972 |
|
|
// |
973 |
|
|
{ |
974 |
|
|
|
975 |
mocchiut |
1.40 |
Float_t xtof_temp[6]={100.,100.,100.,100.,100.,100.}; |
976 |
|
|
Float_t ytof_temp[6]={100.,100.,100.,100.,100.,100.}; |
977 |
|
|
|
978 |
|
|
if(t_tof->xtofpos[0]<100. && t_tof->ytofpos[0]<100.){ |
979 |
|
|
xtof_temp[1]=t_tof->xtofpos[0]; |
980 |
|
|
ytof_temp[0]=t_tof->ytofpos[0]; |
981 |
|
|
}else if(t_tof->xtofpos[0]>=100. && t_tof->ytofpos[0]<100.){ |
982 |
|
|
ytof_temp[0]=t_tof->ytofpos[0]; |
983 |
|
|
tof->GetPaddleGeometry(0,(Int_t)log2(tof->tof_j_flag[0]),xleft, xright, yleft, yright); |
984 |
mocchiut |
1.41 |
xtof_temp[1]=xleft+2.55; |
985 |
mocchiut |
1.40 |
}else if(t_tof->ytofpos[0]>=100. && t_tof->xtofpos[0]<100.){ |
986 |
|
|
xtof_temp[1]=t_tof->xtofpos[0]; |
987 |
|
|
tof->GetPaddleGeometry(1,(Int_t)log2(tof->tof_j_flag[1]),xleft, xright, yleft, yright); |
988 |
mocchiut |
1.41 |
ytof_temp[0]=yleft+2.75; |
989 |
mocchiut |
1.40 |
} |
990 |
|
|
|
991 |
|
|
if(t_tof->xtofpos[1]<100. && t_tof->ytofpos[1]<100.){ |
992 |
|
|
xtof_temp[2]=t_tof->xtofpos[1]; |
993 |
|
|
ytof_temp[3]=t_tof->ytofpos[1]; |
994 |
|
|
}else if(t_tof->xtofpos[1]>=100. && t_tof->ytofpos[1]<100.){ |
995 |
|
|
ytof_temp[3]=t_tof->ytofpos[1]; |
996 |
|
|
tof->GetPaddleGeometry(3,(Int_t)log2(tof->tof_j_flag[3]),xleft, xright, yleft, yright); |
997 |
mocchiut |
1.41 |
xtof_temp[2]=xleft+4.5; |
998 |
mocchiut |
1.40 |
}else if(t_tof->ytofpos[1]>=100. && t_tof->xtofpos[1]<100.){ |
999 |
|
|
xtof_temp[2]=t_tof->xtofpos[1]; |
1000 |
|
|
tof->GetPaddleGeometry(2,(Int_t)log2(tof->tof_j_flag[2]),xleft, xright, yleft, yright); |
1001 |
mocchiut |
1.41 |
ytof_temp[3]=yleft+3.75; |
1002 |
mocchiut |
1.40 |
} |
1003 |
|
|
|
1004 |
|
|
if(t_tof->xtofpos[2]<100. && t_tof->ytofpos[2]<100.){ |
1005 |
|
|
xtof_temp[5]=t_tof->xtofpos[2]; |
1006 |
|
|
ytof_temp[4]=t_tof->ytofpos[2]; |
1007 |
|
|
}else if(t_tof->xtofpos[2]>=100. && t_tof->ytofpos[2]<100.){ |
1008 |
|
|
ytof_temp[4]=t_tof->ytofpos[2]; |
1009 |
|
|
tof->GetPaddleGeometry(4,(Int_t)log2(tof->tof_j_flag[4]),xleft, xright, yleft, yright); |
1010 |
mocchiut |
1.41 |
xtof_temp[5]=xleft+3; |
1011 |
mocchiut |
1.40 |
}else if(t_tof->ytofpos[2]>=100. && t_tof->xtofpos[2]<100.){ |
1012 |
|
|
xtof_temp[5]=t_tof->xtofpos[2]; |
1013 |
|
|
tof->GetPaddleGeometry(5,(Int_t)log2(tof->tof_j_flag[5]),xleft, xright, yleft, yright); |
1014 |
mocchiut |
1.41 |
ytof_temp[4]=yleft+2.5; |
1015 |
mocchiut |
1.40 |
} |
1016 |
|
|
// Float_t xtof_temp[6]={0.,t_tof->xtofpos[0],t_tof->xtofpos[1],0.,0.,t_tof->xtofpos[2]}; |
1017 |
|
|
// Float_t ytof_temp[6]={t_tof->ytofpos[0],0.,0.,t_tof->ytofpos[1],t_tof->ytofpos[2],0.}; |
1018 |
mocchiut |
1.49 |
/* for (Int_t gg=0; gg<4;gg++){ |
1019 |
|
|
for (Int_t hh=0; hh<12;hh++){ |
1020 |
|
|
if (tofEvent->tdc[gg][hh] < 4095 || tofEvent->adc[gg][hh] < 4095 || tofinput_.tdc[hh][gg] < 4095 || tofinput_.adc[hh][gg] < 4095 ) { |
1021 |
|
|
printf("B0 g %i h %i TDC event %i masked %i \n",gg,hh,tofEvent->tdc[gg][hh],tofinput_.tdc[hh][gg]); |
1022 |
|
|
printf("B0 g %i h %i ADC event %i masked %i \n",gg,hh,tofEvent->adc[gg][hh],tofinput_.adc[hh][gg]); |
1023 |
|
|
} |
1024 |
|
|
}; |
1025 |
|
|
};*/ |
1026 |
mocchiut |
1.40 |
tofdedx->Process(atime,t_tof->beta[12], (Float_t *)xtof_temp,(Float_t *)ytof_temp); |
1027 |
mocchiut |
1.49 |
/* for (Int_t gg=0; gg<4;gg++){ |
1028 |
|
|
for (Int_t hh=0; hh<12;hh++){ |
1029 |
|
|
if (tofEvent->tdc[gg][hh] < 4095 || tofEvent->adc[gg][hh] < 4095 || tofinput_.tdc[hh][gg] < 4095 || tofinput_.adc[hh][gg] < 4095 ) { |
1030 |
|
|
printf("B1 g %i h %i TDC event %i masked %i \n",gg,hh,tofEvent->tdc[gg][hh],tofinput_.tdc[hh][gg]); |
1031 |
|
|
printf("B1 g %i h %i ADC event %i masked %i \n",gg,hh,tofEvent->adc[gg][hh],tofinput_.adc[hh][gg]); |
1032 |
|
|
} |
1033 |
|
|
}; |
1034 |
|
|
};*/ |
1035 |
mocchiut |
1.40 |
t_tof->npmtadc = 0; |
1036 |
|
|
for (Int_t hh=0; hh<12;hh++){ |
1037 |
|
|
for (Int_t kk=0; kk<4;kk++){ |
1038 |
mocchiut |
1.4 |
pmt_id = tof->GetPMTid(kk,hh); |
1039 |
mocchiut |
1.40 |
Int_t Iplane=-1; |
1040 |
|
|
Int_t Ipaddle=-1; |
1041 |
|
|
// Int_t IpaddleT=-1; |
1042 |
|
|
tof->GetPMTPaddle(pmt_id, Iplane, Ipaddle); |
1043 |
|
|
tof->GetPaddleGeometry(Iplane,Ipaddle,xleft,xright,yleft,yright); |
1044 |
mocchiut |
1.49 |
if (tofEvent->tdc[kk][hh] < 4095 || tofEvent->adc[kk][hh] < 4095 || tofinput_.tdc[hh][kk] < 4095 || tofinput_.adc[hh][kk] < 4095 ) { |
1045 |
mocchiut |
1.48 |
if ( tofdedx->GetdEdx_pmt(pmt_id)>-1. && (inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)) > 0. &&((xtof_temp[Iplane]>=xleft&&xtof_temp[Iplane]<=xright) || (ytof_temp[Iplane]>=yleft&&ytof_temp[Iplane]<=yright)) ){ |
1046 |
|
|
//t_tof->dedx.AddAt((tofdedx->GetdEdx_pmt(pmt_id)*4./dedx_corr[pmt_id]),t_tof->npmtadc); |
1047 |
|
|
|
1048 |
|
|
t_tof->dedx.AddAt((inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)),t_tof->npmtadc);// RC new dE/dx II order correction |
1049 |
|
|
|
1050 |
mocchiut |
1.40 |
t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc); |
1051 |
|
|
t_tof->adcflag.AddAt(0,t_tof->npmtadc); // gf: Jan 09/07 |
1052 |
|
|
t_tof->npmtadc++; |
1053 |
mocchiut |
1.49 |
}; |
1054 |
mocchiut |
1.40 |
}; |
1055 |
mocchiut |
1.4 |
}; |
1056 |
|
|
}; |
1057 |
|
|
}; |
1058 |
mocchiut |
1.40 |
|
1059 |
mocchiut |
1.20 |
/* |
1060 |
|
|
cout<<"ToFCore tofl2com"<<endl; |
1061 |
|
|
cout<<tofoutput_.xtofpos[0]<<" "<<tofoutput_.xtofpos[1]<<" "<<tofoutput_.xtofpos[2]<<endl; |
1062 |
|
|
cout<<tofoutput_.ytofpos[0]<<" "<<tofoutput_.ytofpos[1]<<" "<<tofoutput_.ytofpos[2]<<endl; |
1063 |
|
|
cout<<tofoutput_.xtr_tof[0]<<" "<<tofoutput_.xtr_tof[1]<<" "<<tofoutput_.xtr_tof[2]<<" "<<tofoutput_.xtr_tof[3]<<" "<<tofoutput_.xtr_tof[4]<<" "<<tofoutput_.xtr_tof[5]<<endl; |
1064 |
|
|
cout<<tofoutput_.ytr_tof[0]<<" "<<tofoutput_.ytr_tof[1]<<" "<<tofoutput_.ytr_tof[2]<<" "<<tofoutput_.ytr_tof[3]<<" "<<tofoutput_.ytr_tof[4]<<" "<<tofoutput_.ytr_tof[5]<<endl; |
1065 |
|
|
*/ |
1066 |
|
|
|
1067 |
|
|
|
1068 |
mocchiut |
1.4 |
new(t[ntrkentry]) ToFTrkVar(*t_tof); |
1069 |
|
|
ntrkentry++; |
1070 |
|
|
t_tof->Clear(); |
1071 |
|
|
// |
1072 |
mocchiut |
1.1 |
// |
1073 |
|
|
// |
1074 |
mocchiut |
1.4 |
t_pmt->Clear(); |
1075 |
mocchiut |
1.1 |
// |
1076 |
mocchiut |
1.49 |
/* for (Int_t gg=0; gg<4;gg++){ |
1077 |
|
|
for (Int_t hh=0; hh<12;hh++){ |
1078 |
|
|
if (tofEvent->tdc[gg][hh] < 4095 || tofEvent->adc[gg][hh] < 4095 || tofinput_.tdc[hh][gg] < 4095 || tofinput_.adc[hh][gg] < 4095 ) { |
1079 |
|
|
printf("B2 g %i h %i TDC event %i masked %i \n",gg,hh,tofEvent->tdc[gg][hh],tofinput_.tdc[hh][gg]); |
1080 |
|
|
printf("B2 g %i h %i ADC event %i masked %i \n",gg,hh,tofEvent->adc[gg][hh],tofinput_.adc[hh][gg]); |
1081 |
|
|
} |
1082 |
|
|
}; |
1083 |
|
|
};*/ |
1084 |
|
|
for (Int_t gg=0; gg<4;gg++){ |
1085 |
|
|
for (Int_t hh=0; hh<12;hh++){ |
1086 |
mocchiut |
1.29 |
// new WM |
1087 |
mocchiut |
1.49 |
if ( tofoutput_.tdc_c[hh][gg] < 4095 || (0xFFF & tofEvent->adc[gg][hh]) < 4095 || (0xFFF & tofEvent->tdc[gg][hh]) < 4095 ){ |
1088 |
mocchiut |
1.4 |
// |
1089 |
mocchiut |
1.49 |
/* printf(" FILL h %i k %i TDC event %i masked %i \n",hh,gg,tofEvent->tdc[gg][hh],tofinput_.tdc[hh][gg]); |
1090 |
|
|
printf(" FILL h %i k %i ADC event %i masked %i \n",hh,gg,tofEvent->adc[gg][hh],tofinput_.adc[hh][gg]); |
1091 |
|
|
printf(" FILL h %i k %i TDC_C event %f \n",hh,gg,tofoutput_.tdc_c[hh][gg]);*/ |
1092 |
|
|
|
1093 |
|
|
t_pmt->pmt_id = tof->GetPMTid(gg,hh); |
1094 |
|
|
t_pmt->tdc_tw = tofoutput_.tdc_c[hh][gg]; |
1095 |
|
|
t_pmt->adc = (Float_t)(0xFFF & tofEvent->adc[gg][hh]); |
1096 |
|
|
t_pmt->tdc = (Float_t)(0xFFF & tofEvent->tdc[gg][hh]); |
1097 |
|
|
t_pmt->l0flag_adc = (Float_t)(tofEvent->adc[gg][hh]>>12); |
1098 |
|
|
t_pmt->l0flag_tdc = (Float_t)(tofEvent->tdc[gg][hh]>>12); |
1099 |
mocchiut |
1.48 |
if ( t_pmt->l0flag_adc || t_pmt->l0flag_tdc ) warning |= 1 << 0; |
1100 |
mocchiut |
1.29 |
// |
1101 |
mocchiut |
1.4 |
new(tpmt[npmtentry]) ToFPMT(*t_pmt); |
1102 |
|
|
npmtentry++; |
1103 |
|
|
t_pmt->Clear(); |
1104 |
|
|
}; |
1105 |
|
|
}; |
1106 |
|
|
}; |
1107 |
mocchiut |
1.49 |
/* for (Int_t gg=0; gg<4;gg++){ |
1108 |
|
|
for (Int_t hh=0; hh<12;hh++){ |
1109 |
|
|
if (tofEvent->tdc[gg][hh] < 4095 || tofEvent->adc[gg][hh] < 4095 || tofinput_.tdc[hh][gg] < 4095 || tofinput_.adc[hh][gg] < 4095 ) { |
1110 |
|
|
printf("B3 g %i h %i TDC event %i masked %i \n",gg,hh,tofEvent->tdc[gg][hh],tofinput_.tdc[hh][gg]); |
1111 |
|
|
printf("B3 g %i h %i ADC event %i masked %i \n",gg,hh,tofEvent->adc[gg][hh],tofinput_.adc[hh][gg]); |
1112 |
|
|
} |
1113 |
|
|
}; |
1114 |
|
|
};*/ |
1115 |
mocchiut |
1.1 |
// |
1116 |
mocchiut |
1.38 |
if ( debug ) printf(" ATIME %u re %u \n",atime,(UInt_t)re); |
1117 |
mocchiut |
1.4 |
// Calculate track-related variables |
1118 |
mocchiut |
1.1 |
// |
1119 |
mocchiut |
1.2 |
if ( trk->ntrk() > 0 ){ |
1120 |
mocchiut |
1.1 |
// |
1121 |
|
|
// We have at least one track |
1122 |
|
|
// |
1123 |
|
|
// |
1124 |
|
|
// Run over tracks |
1125 |
|
|
// |
1126 |
|
|
for(Int_t nt=0; nt < trk->ntrk(); nt++){ |
1127 |
|
|
// |
1128 |
|
|
TrkTrack *ptt = trk->GetStoredTrack(nt); |
1129 |
|
|
// |
1130 |
|
|
// Copy the alpha vector in the input structure |
1131 |
|
|
// |
1132 |
|
|
for (Int_t e = 0; e < 5 ; e++){ |
1133 |
|
|
tofinput_.al_pp[e] = ptt->al[e]; |
1134 |
|
|
}; |
1135 |
mocchiut |
1.45 |
|
1136 |
|
|
// new input for 9th reduction: tracker dEdx |
1137 |
|
|
tofinput_.trkmip = ptt->GetDEDX(); |
1138 |
|
|
|
1139 |
mocchiut |
1.1 |
// |
1140 |
|
|
// Get tracker related variables for this track |
1141 |
|
|
// |
1142 |
|
|
toftrk(); |
1143 |
mocchiut |
1.49 |
/* for (Int_t gg=0; gg<4;gg++){ |
1144 |
|
|
for (Int_t hh=0; hh<12;hh++){ |
1145 |
|
|
if (tofEvent->tdc[gg][hh] < 4095 || tofEvent->adc[gg][hh] < 4095 || tofinput_.tdc[hh][gg] < 4095 || tofinput_.adc[hh][gg] < 4095 ) { |
1146 |
|
|
printf("C%i g %i h %i TDC event %i masked %i \n",nt,gg,hh,tofEvent->tdc[gg][hh],tofinput_.tdc[hh][gg]); |
1147 |
|
|
printf("C%i g %i h %i ADC event %i masked %i \n",nt,gg,hh,tofEvent->adc[gg][hh],tofinput_.adc[hh][gg]); |
1148 |
|
|
} |
1149 |
|
|
}; |
1150 |
|
|
};*/ |
1151 |
mocchiut |
1.1 |
// |
1152 |
|
|
// Copy values in the class from the structure (we need to use a temporary class to store variables). |
1153 |
|
|
// |
1154 |
mocchiut |
1.4 |
t_tof->npmttdc = 0; |
1155 |
|
|
for (Int_t hh=0; hh<12;hh++){ |
1156 |
|
|
for (Int_t kk=0; kk<4;kk++){ |
1157 |
|
|
if ( tofoutput_.tofmask[hh][kk] != 0 ){ |
1158 |
|
|
pmt_id = tof->GetPMTid(kk,hh); |
1159 |
|
|
t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc); |
1160 |
mocchiut |
1.14 |
t_tof->tdcflag.AddAt(tofoutput_.tdcflag[hh][kk],t_tof->npmttdc); // gf: Jan 09/07 |
1161 |
mocchiut |
1.4 |
t_tof->npmttdc++; |
1162 |
|
|
}; |
1163 |
|
|
}; |
1164 |
|
|
}; |
1165 |
mocchiut |
1.1 |
for (Int_t kk=0; kk<13;kk++){ |
1166 |
mocchiut |
1.4 |
t_tof->beta[kk] = tofoutput_.beta_a[kk]; |
1167 |
|
|
}; |
1168 |
carbone |
1.37 |
memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos)); |
1169 |
|
|
memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos)); |
1170 |
|
|
memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof)); |
1171 |
|
|
memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof)); |
1172 |
mocchiut |
1.4 |
// |
1173 |
mocchiut |
1.38 |
tofdedx->Process(atime,t_tof->beta[12], (Float_t *)t_tof->xtr_tof,(Float_t *)t_tof->ytr_tof); |
1174 |
mocchiut |
1.4 |
t_tof->npmtadc = 0; |
1175 |
mocchiut |
1.44 |
// for (Int_t rrtt = 0; rrtt<48; rrtt++){ |
1176 |
|
|
// printf(" ===>>> %i ===> %f \n",rrtt,tofdedx->GetdEdx_pmt(rrtt)); |
1177 |
|
|
// }; |
1178 |
mocchiut |
1.1 |
for (Int_t hh=0; hh<12;hh++){ |
1179 |
|
|
for (Int_t kk=0; kk<4;kk++){ |
1180 |
carbone |
1.37 |
pmt_id = tof->GetPMTid(kk,hh); |
1181 |
mocchiut |
1.40 |
Int_t Iplane=-1; |
1182 |
|
|
Int_t Ipaddle=-1; |
1183 |
|
|
Int_t IpaddleT=-1; |
1184 |
|
|
tof->GetPMTPaddle(pmt_id, Iplane, Ipaddle); |
1185 |
mocchiut |
1.44 |
IpaddleT=tof->GetPaddleIdOfTrack(t_tof->xtr_tof[Iplane],t_tof->ytr_tof[Iplane], Iplane,0.0); |
1186 |
mocchiut |
1.48 |
//if ( debug ) printf(" 1nt %i pmt_id %i npmtadc %i dedx %f dedx corr %f\n",nt,pmt_id,t_tof->npmtadc,(tofdedx->GetdEdx_pmt(pmt_id)*4./dedx_corr[pmt_id]),dedx_corr[pmt_id]); |
1187 |
|
|
if ( debug ) printf(" 1nt %i pmt_id %i npmtadc %i dedx %f dedx slope %f dedx inter %f\n",nt,pmt_id,t_tof->npmtadc,(inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)),inter_dedx[pmt_id],slope_dedx[pmt_id]); |
1188 |
mocchiut |
1.49 |
|
1189 |
|
|
if (tofEvent->tdc[kk][hh] < 4095 || tofEvent->adc[kk][hh] < 4095 || tofinput_.tdc[hh][kk] < 4095 || tofinput_.adc[hh][kk] < 4095 ) { |
1190 |
|
|
|
1191 |
mocchiut |
1.48 |
if ( tofdedx->GetdEdx_pmt(pmt_id) > -1. && (inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)) > 0. && Ipaddle==IpaddleT ){ |
1192 |
|
|
//t_tof->dedx.AddAt((tofdedx->GetdEdx_pmt(pmt_id)*4./dedx_corr[pmt_id]),t_tof->npmtadc); |
1193 |
|
|
|
1194 |
|
|
t_tof->dedx.AddAt((inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)),t_tof->npmtadc);// RC new dE/dx II order correction |
1195 |
|
|
|
1196 |
|
|
//if ( debug ) printf(" 2nt %i npmtadc %i dedx %f dedx corr %f\n",nt,t_tof->npmtadc,(tofdedx->GetdEdx_pmt(pmt_id)*4./dedx_corr[pmt_id]),dedx_corr[pmt_id]); |
1197 |
|
|
if ( debug ) printf(" 2nt %i npmtadc %i dedx %f dedx slope %f dedx inter %f\n",nt,t_tof->npmtadc,(inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)),inter_dedx[pmt_id],slope_dedx[pmt_id]); |
1198 |
mocchiut |
1.4 |
t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc); |
1199 |
carbone |
1.37 |
t_tof->adcflag.AddAt(0,t_tof->npmtadc); // gf: Jan 09/07 |
1200 |
mocchiut |
1.4 |
t_tof->npmtadc++; |
1201 |
|
|
}; |
1202 |
mocchiut |
1.49 |
|
1203 |
|
|
}; |
1204 |
mocchiut |
1.4 |
}; |
1205 |
|
|
}; |
1206 |
|
|
// |
1207 |
mocchiut |
1.20 |
|
1208 |
|
|
/* |
1209 |
|
|
cout<<"ToFCore toftrk"<<endl; |
1210 |
|
|
cout<<tofoutput_.xtofpos[0]<<" "<<tofoutput_.xtofpos[1]<<" "<<tofoutput_.xtofpos[2]<<endl; |
1211 |
|
|
cout<<tofoutput_.ytofpos[0]<<" "<<tofoutput_.ytofpos[1]<<" "<<tofoutput_.ytofpos[2]<<endl; |
1212 |
|
|
cout<<tofoutput_.xtr_tof[0]<<" "<<tofoutput_.xtr_tof[1]<<" "<<tofoutput_.xtr_tof[2]<<" "<<tofoutput_.xtr_tof[3]<<" "<<tofoutput_.xtr_tof[4]<<" "<<tofoutput_.xtr_tof[5]<<endl; |
1213 |
|
|
cout<<tofoutput_.ytr_tof[0]<<" "<<tofoutput_.ytr_tof[1]<<" "<<tofoutput_.ytr_tof[2]<<" "<<tofoutput_.ytr_tof[3]<<" "<<tofoutput_.ytr_tof[4]<<" "<<tofoutput_.ytr_tof[5]<<endl; |
1214 |
|
|
*/ |
1215 |
|
|
|
1216 |
mocchiut |
1.1 |
// |
1217 |
|
|
// Store the tracker track number in order to be sure to have shyncronized data during analysis |
1218 |
|
|
// |
1219 |
|
|
t_tof->trkseqno = nt; |
1220 |
|
|
// |
1221 |
|
|
// create a new object for this event with track-related variables |
1222 |
|
|
// |
1223 |
|
|
new(t[ntrkentry]) ToFTrkVar(*t_tof); |
1224 |
|
|
ntrkentry++; |
1225 |
mocchiut |
1.4 |
t_tof->Clear(); |
1226 |
mocchiut |
1.1 |
// |
1227 |
|
|
}; // loop on all the tracks |
1228 |
|
|
}; |
1229 |
|
|
// |
1230 |
mocchiut |
1.9 |
tof->unpackError = tofEvent->unpackError; |
1231 |
mocchiut |
1.48 |
|
1232 |
|
|
a = 0; |
1233 |
|
|
b = 0; |
1234 |
|
|
if ( !tof->checkPMTpatternPMThit(trg, a, b) ) warning |= 1 << 1; |
1235 |
|
|
if ( !tof->checkPMTpmttrig(trg) ) warning |= 1 << 2; |
1236 |
|
|
if ( !trg->checkPMTpatterntrig() ) warning |= 1 << 3; |
1237 |
|
|
tof->unpackWarning = warning; |
1238 |
|
|
|
1239 |
mocchiut |
1.22 |
if ( defcal ){ |
1240 |
|
|
tof->default_calib = 1; |
1241 |
|
|
} else { |
1242 |
|
|
tof->default_calib = 0; |
1243 |
|
|
}; |
1244 |
mocchiut |
1.9 |
// |
1245 |
mocchiut |
1.1 |
// Fill the rootple |
1246 |
|
|
// |
1247 |
|
|
toft->Fill(); |
1248 |
|
|
// |
1249 |
|
|
// |
1250 |
mocchiut |
1.4 |
// |
1251 |
|
|
delete t_tof; |
1252 |
|
|
// |
1253 |
|
|
// |
1254 |
|
|
// |
1255 |
mocchiut |
1.1 |
jumpev: |
1256 |
mocchiut |
1.38 |
if ( !debug ) debug = false; |
1257 |
mocchiut |
1.1 |
// |
1258 |
|
|
}; |
1259 |
mocchiut |
1.6 |
// |
1260 |
|
|
// Here you may want to clear some variables before processing another run |
1261 |
|
|
// |
1262 |
|
|
delete dbtime; |
1263 |
mocchiut |
1.1 |
}; // process all the runs |
1264 |
|
|
// |
1265 |
|
|
if ( verbose ) printf("\n Finished processing data \n"); |
1266 |
|
|
// |
1267 |
|
|
closeandexit: |
1268 |
|
|
// |
1269 |
|
|
// we have finished processing the run(s). If we processed a single run now we must copy all the events after our run from the old tree to the new one and delete the old tree. |
1270 |
|
|
// |
1271 |
|
|
if ( !reprocall && reproc && code >= 0 ){ |
1272 |
|
|
if ( totfileentries > noaftrun ){ |
1273 |
|
|
if ( verbose ) printf("\n Post-processing: copying events from the old tree after the processed run\n"); |
1274 |
|
|
if ( verbose ) printf(" Copying %i events in the file which are after the end of the run %i \n",(int)(totfileentries-noaftrun),(int)run); |
1275 |
|
|
if ( verbose ) printf(" Start copying at event number %i end copying at event number %i \n",(int)noaftrun,(int)totfileentries); |
1276 |
|
|
for (UInt_t j = noaftrun; j < totfileentries; j++ ){ |
1277 |
|
|
// |
1278 |
|
|
// Get entry from old tree |
1279 |
|
|
// |
1280 |
mocchiut |
1.42 |
if ( toftclone->GetEntry(j) <= 0 ) throw -36; |
1281 |
mocchiut |
1.1 |
// |
1282 |
|
|
// copy tofclone to tof |
1283 |
|
|
// |
1284 |
mocchiut |
1.3 |
tof->Clear(); |
1285 |
mocchiut |
1.1 |
memcpy(&tof,&tofclone,sizeof(tofclone)); |
1286 |
|
|
// |
1287 |
|
|
// Fill entry in the new tree |
1288 |
|
|
// |
1289 |
|
|
toft->Fill(); |
1290 |
|
|
}; |
1291 |
|
|
if ( verbose ) printf(" Finished successful copying!\n"); |
1292 |
|
|
}; |
1293 |
|
|
}; |
1294 |
|
|
// |
1295 |
|
|
// Close files, delete old tree(s), write and close level2 file |
1296 |
|
|
// |
1297 |
|
|
if ( l0File ) l0File->Close(); |
1298 |
|
|
if ( tempfile ) tempfile->Close(); |
1299 |
mocchiut |
1.25 |
if ( myfold ) gSystem->Unlink(tempname.str().c_str()); |
1300 |
mocchiut |
1.1 |
// |
1301 |
|
|
if ( code < 0 && verbose ) printf("\n TOF - ERROR: an error occurred, try to save anyway...\n"); |
1302 |
|
|
if ( verbose ) printf("\n Writing and closing rootple\n"); |
1303 |
|
|
if ( toft ) toft->SetName("ToF"); |
1304 |
|
|
if ( file ){ |
1305 |
|
|
file->cd(); |
1306 |
mocchiut |
1.49 |
toft->Write(0, TObject::kOverwrite); |
1307 |
mocchiut |
1.1 |
}; |
1308 |
|
|
// |
1309 |
mocchiut |
1.25 |
if ( myfold ) gSystem->Unlink(toffolder.str().c_str()); |
1310 |
mocchiut |
1.1 |
// |
1311 |
|
|
// the end |
1312 |
|
|
// |
1313 |
|
|
if ( verbose ) printf("\n Exiting...\n"); |
1314 |
mocchiut |
1.5 |
// |
1315 |
carbone |
1.37 |
if ( tofdedx ) delete tofdedx; |
1316 |
mocchiut |
1.5 |
if ( glroot ) delete glroot; |
1317 |
mocchiut |
1.49 |
if ( glparam ) delete glparam; |
1318 |
|
|
if ( runinfo ) runinfo->Close(); |
1319 |
mocchiut |
1.5 |
if ( runinfo ) delete runinfo; |
1320 |
|
|
// |
1321 |
mocchiut |
1.1 |
if ( code < 0 ) throw code; |
1322 |
|
|
return(code); |
1323 |
|
|
} |