1 |
// |
// |
2 |
|
// Given a calibration and a data file this program create an ntuple with LEVEL2 S4 variables |
3 |
|
// |
4 |
|
// |
5 |
// C/C++ headers |
// C/C++ headers |
6 |
// |
// |
7 |
#include <fstream> |
#include <fstream> |
12 |
// |
// |
13 |
// ROOT headers |
// ROOT headers |
14 |
// |
// |
15 |
|
#include <TGraph.h> |
16 |
|
#include <TF1.h> |
17 |
#include <TTree.h> |
#include <TTree.h> |
18 |
#include <TClassEdit.h> |
#include <TClassEdit.h> |
19 |
#include <TObject.h> |
#include <TObject.h> |
20 |
#include <TList.h> |
#include <TList.h> |
21 |
#include <TArrayL.h> |
#include <TArrayI.h> |
22 |
|
#include <TArrayD.h> |
23 |
#include <TSystem.h> |
#include <TSystem.h> |
24 |
#include <TSystemDirectory.h> |
#include <TSystemDirectory.h> |
25 |
#include <TString.h> |
#include <TString.h> |
32 |
#include <stdlib.h> |
#include <stdlib.h> |
33 |
#include <math.h> |
#include <math.h> |
34 |
// |
// |
35 |
|
// RunInfo header |
36 |
|
// |
37 |
|
#include <RunInfo.h> |
38 |
|
#include <GLTables.h> |
39 |
|
// |
40 |
// YODA headers |
// YODA headers |
41 |
// |
// |
42 |
#include <PamelaRun.h> |
#include <PamelaRun.h> |
|
#include <RegistryEvent.h> |
|
43 |
#include <PscuHeader.h> |
#include <PscuHeader.h> |
44 |
#include <PscuEvent.h> |
#include <PscuEvent.h> |
45 |
#include <EventHeader.h> |
#include <EventHeader.h> |
|
#include <RegistryEvent.h> |
|
46 |
#include <CalibS4Event.h> |
#include <CalibS4Event.h> |
47 |
#include <physics/S4/S4Event.h> |
#include <physics/S4/S4Event.h> |
|
//#include <yodaUtility.h> |
|
|
// |
|
|
// RunInfo header |
|
|
// |
|
|
#include <RunInfo.h> |
|
|
#include <GLTables.h> |
|
48 |
// |
// |
49 |
// This program headers |
// This program headers |
50 |
// |
// |
51 |
#include <S4Level2.h> |
#include <S4Level2.h> |
52 |
#include <S4Core.h> |
#include <S4Core.h> |
53 |
#include <S4Verl2.h> |
#include <S4Verl2.h> |
54 |
|
// |
55 |
using namespace std; |
using namespace std; |
56 |
|
// |
57 |
|
/* |
58 |
|
* Fit function Received from Valeria Malvezzi 06/02/2006 |
59 |
|
*/ |
60 |
|
Double_t fitf(Double_t *x, Double_t *par){ |
61 |
|
Double_t fitval =(par[0]*x[0])+par[1]; |
62 |
|
return fitval; |
63 |
|
} |
64 |
|
|
65 |
|
/* |
66 |
|
* Fit the S4 calibration with a straight line - Received from Valeria Malvezzi 06/02/2006 |
67 |
|
*/ |
68 |
|
TArrayD *S4_paramfit(UInt_t atime, TSQLServer *dbc){ |
69 |
|
// |
70 |
|
TArrayD *parametri = new TArrayD(2); |
71 |
|
// |
72 |
|
GL_S4_CALIB *glS4calib = new GL_S4_CALIB(); |
73 |
|
// |
74 |
|
if ( !dbc->IsConnected() ) throw -504; |
75 |
|
glS4calib->Query_GL_S4_CALIB(atime, dbc); |
76 |
|
// |
77 |
|
GL_ROOT *glroot = new GL_ROOT(); |
78 |
|
if ( !dbc->IsConnected() ) throw -504; |
79 |
|
glroot->Query_GL_ROOT(glS4calib->ID_ROOT_L0,dbc); |
80 |
|
// |
81 |
|
stringstream ftmpname; |
82 |
|
ftmpname.str(""); |
83 |
|
ftmpname << glroot->PATH.Data() << "/"; |
84 |
|
ftmpname << glroot->NAME.Data(); |
85 |
|
// |
86 |
|
TFile *file = 0; |
87 |
|
file = new TFile(ftmpname.str().c_str()); |
88 |
|
// |
89 |
|
if ( !file ) return(NULL); |
90 |
|
// |
91 |
|
TTree *tr = 0; |
92 |
|
tr = (TTree*)file->Get("CalibS4"); |
93 |
|
if ( !tr ){ |
94 |
|
file->Close(); |
95 |
|
return(NULL); |
96 |
|
}; |
97 |
|
// |
98 |
|
pamela::CalibS4Event *S4CalibEvent = 0; |
99 |
|
tr->SetBranchAddress("CalibS4", &S4CalibEvent); |
100 |
|
if ( tr->GetEntries() < glS4calib->EV_ROOT ) return(NULL); |
101 |
|
// |
102 |
|
tr->GetEntry(glS4calib->EV_ROOT); |
103 |
|
// |
104 |
|
// Variables initialization |
105 |
|
// |
106 |
|
Double_t mip[3]={1, 30, 300}; |
107 |
|
Double_t adc[3] = {0.,0.,0.}; |
108 |
|
// |
109 |
|
// Fit calibrations and find parameters to calibrate data |
110 |
|
// |
111 |
|
pamela::S4::S4Event *s4Record = 0; |
112 |
|
// |
113 |
|
for (Int_t j = 0; j < 4; j++){ |
114 |
|
for (Int_t i = 0; i < 128; i++){ |
115 |
|
s4Record = (pamela::S4::S4Event*)S4CalibEvent->Records->At((j*128 + i)); |
116 |
|
switch (j) { |
117 |
|
case 0 :{ |
118 |
|
adc[0]=adc[0]+((s4Record->S4_DATA)-32); |
119 |
|
break; |
120 |
|
}; |
121 |
|
case 1 :{ |
122 |
|
adc[1]=adc[1]+((s4Record->S4_DATA)-32); |
123 |
|
break; |
124 |
|
}; |
125 |
|
case 3 :{ |
126 |
|
adc[2]=adc[2]+((s4Record->S4_DATA)-32); |
127 |
|
break; |
128 |
|
}; |
129 |
|
}; |
130 |
|
}; |
131 |
|
}; |
132 |
|
// |
133 |
|
adc[0]=adc[0]/128; |
134 |
|
adc[1]=adc[1]/128; |
135 |
|
adc[2]=adc[2]/128; |
136 |
|
// if ( IsDebug() ) printf(" adc1 = %g adc2 = %g adc3 = %g\n",adc[0],adc[1],adc[2]); |
137 |
|
TGraph *fitpar = new TGraph (3, adc, mip); |
138 |
|
TF1 *func = new TF1("fitf", fitf, -1., 400., 2); // function definition with 2 parameters |
139 |
|
// |
140 |
|
func->SetParameters(0.3,1.); // parameters initialization to 1 |
141 |
|
func->SetParNames("m","q"); //parameter's name |
142 |
|
fitpar->Fit(func,"qr"); //function fit |
143 |
|
parametri->AddAt(func->GetParameter(0),0); |
144 |
|
parametri->AddAt(func->GetParameter(1),1); |
145 |
|
// if ( parametri[0] < 0. || parametri[0] > 0.5 || parametri[1] < 0.7 || parametri[1] > 1.1 ) valid = 0; |
146 |
|
// |
147 |
|
delete glroot; |
148 |
|
delete glS4calib; |
149 |
|
delete fitpar; |
150 |
|
delete func; |
151 |
|
file->Close(); |
152 |
|
// |
153 |
|
return parametri; |
154 |
|
}; |
155 |
|
|
156 |
// |
// |
157 |
// CORE ROUTINE |
// CORE ROUTINE |
158 |
// |
// |
159 |
// |
// |
160 |
|
int S4Core(UInt_t run, TFile *file, TSQLServer *dbc, Int_t S4argc, char *S4argv[]){ |
|
int S4Core(ULong64_t run, TFile *file, TSQLServer *dbc, Int_t S4argc, char *S4argv[]){ |
|
|
Int_t i = 0; |
|
161 |
// |
// |
162 |
TString processFolder = "S4Folder"; |
// Set these to true to have a verbose output. |
163 |
// |
// |
164 |
// Set these to true to have a very verbose output. |
Bool_t debug = false; |
165 |
Bool_t debug = false; |
Bool_t verbose = false; |
|
// |
|
|
Bool_t verbose = false; |
|
166 |
// |
// |
167 |
|
// |
168 |
|
// Output directory is the working directoy. |
169 |
|
// |
170 |
|
const char* outDir = gSystem->DirName(gSystem->DirName(file->GetPath())); |
171 |
|
// |
172 |
|
Int_t i = 0; |
173 |
|
TString processFolder = Form("S4Folder_%u",run); |
174 |
if ( S4argc > 0 ){ |
if ( S4argc > 0 ){ |
175 |
i = 0; |
i = 0; |
176 |
while ( i < S4argc ){ |
while ( i < S4argc ){ |
183 |
}; |
}; |
184 |
if ( (!strcmp(S4argv[i],"--debug")) || (!strcmp(S4argv[i],"-g"))) { |
if ( (!strcmp(S4argv[i],"--debug")) || (!strcmp(S4argv[i],"-g"))) { |
185 |
verbose = true; |
verbose = true; |
186 |
|
debug = true; |
187 |
}; |
}; |
188 |
if ( (!strcmp(S4argv[i],"--verbose")) || (!strcmp(S4argv[i],"-v"))) { |
if ( (!strcmp(S4argv[i],"--verbose")) || (!strcmp(S4argv[i],"-v"))) { |
189 |
verbose = true; |
verbose = true; |
191 |
i++; |
i++; |
192 |
}; |
}; |
193 |
}; |
}; |
|
|
|
|
const char* outDir = gSystem->DirName(gSystem->DirName(file->GetPath())); |
|
194 |
// Variables for level2 |
// Variables for level2 |
195 |
// |
// |
196 |
TTree *S4tr = 0; |
TTree *S4tr = 0; |
197 |
Long64_t nevents = 0LL; |
UInt_t nevents = 0; |
198 |
|
// |
199 |
|
// Variables needed to reprocess data |
200 |
// |
// |
201 |
// variables needed to reprocess data |
Long64_t maxsize = 10000000000LL; |
202 |
|
TTree::SetMaxTreeSize(maxsize); |
203 |
// |
// |
204 |
TString S4version; |
TString S4version; |
205 |
ItoRunInfo *runinfo = 0; |
ItoRunInfo *runinfo = 0; |
206 |
TArrayL *runlist = 0; |
TArrayI *runlist = 0; |
207 |
TTree *S4trclone = 0; |
TTree *S4trclone = 0; |
208 |
Bool_t reproc = false; |
Bool_t reproc = false; |
209 |
Bool_t reprocall = false; |
Bool_t reprocall = false; |
212 |
UInt_t numbofrun = 0; |
UInt_t numbofrun = 0; |
213 |
stringstream ftmpname; |
stringstream ftmpname; |
214 |
TString fname; |
TString fname; |
215 |
Long64_t totfileentries = 0ULL; |
UInt_t totfileentries = 0; |
216 |
Long64_t idRun = 0LL; |
UInt_t idRun = 0; |
217 |
Double_t ParamFit0 = 0ULL; |
Double_t ParamFit0 = 0.; |
218 |
Double_t ParamFit1 = 0ULL; |
Double_t ParamFit1 = 0.; |
219 |
// |
// |
220 |
// variables needed to handle error signals |
// variables needed to handle error signals |
221 |
// |
// |
232 |
TFile *l0File = 0; |
TFile *l0File = 0; |
233 |
TTree *l0tr = 0; |
TTree *l0tr = 0; |
234 |
TBranch *l0head = 0; |
TBranch *l0head = 0; |
|
TBranch *l0registry = 0; |
|
235 |
TBranch *l0S4 =0; |
TBranch *l0S4 =0; |
|
pamela::RegistryEvent *l0reg=0; |
|
236 |
pamela::S4::S4Event *l0s4e = 0; |
pamela::S4::S4Event *l0s4e = 0; |
237 |
pamela::EventHeader *eh = 0; |
pamela::EventHeader *eh = 0; |
238 |
|
pamela::PscuHeader *ph = 0; |
239 |
// |
// |
240 |
// Define other basic variables |
// Define other basic variables |
241 |
// |
// |
244 |
stringstream file3; |
stringstream file3; |
245 |
stringstream qy; |
stringstream qy; |
246 |
Int_t totevent = 0; |
Int_t totevent = 0; |
247 |
ULong64_t atime = 0ULL; |
UInt_t atime = 0; |
248 |
Int_t ei = 0; |
// Int_t ei = 0; |
249 |
Int_t re = 0; |
UInt_t re = 0; |
250 |
// |
// |
251 |
// Working filename |
// Working filename |
252 |
// |
// |
273 |
// DB classes |
// DB classes |
274 |
// |
// |
275 |
GL_ROOT *glroot = new GL_ROOT(); |
GL_ROOT *glroot = new GL_ROOT(); |
276 |
GL_S4_CALIB *glS4calib = new GL_S4_CALIB(); |
GL_TIMESYNC *dbtime = 0; |
277 |
// |
// |
278 |
// Let's start! |
// Let's start! |
279 |
// |
// |
281 |
// if run != 0 we must process only that run but first we have to check if the tree MyDetector2 already exist in the file |
// if run != 0 we must process only that run but first we have to check if the tree MyDetector2 already exist in the file |
282 |
// if it exists we are reprocessing data and we must delete that entries, if not we must create it. |
// if it exists we are reprocessing data and we must delete that entries, if not we must create it. |
283 |
// |
// |
284 |
if ( run == 0ULL ) reproc = true; |
if ( run == 0 ) reproc = true; |
285 |
// |
// |
286 |
// |
// |
287 |
// Output file is "outputfile" |
// Output file is "outputfile" |
336 |
// tree does not exist, we are not reprocessing |
// tree does not exist, we are not reprocessing |
337 |
// |
// |
338 |
reproc = false; |
reproc = false; |
339 |
if ( run == 0ULL ){ |
if ( run == 0 ){ |
340 |
if (verbose) printf(" S4 - WARNING: you are reprocessing data but S4 tree does not exist!\n"); |
if (verbose) printf(" S4 - WARNING: you are reprocessing data but S4 tree does not exist!\n"); |
341 |
} |
} |
342 |
if ( runinfo->IsReprocessing() && run != 0ULL ) { |
if ( runinfo->IsReprocessing() && run != 0 ) { |
343 |
if (verbose) printf(" S4 - WARNING: it seems you are not reprocessing data but S4\n versioning information already exists in RunInfo.\n"); |
if (verbose) printf(" S4 - WARNING: it seems you are not reprocessing data but S4\n versioning information already exists in RunInfo.\n"); |
344 |
} |
} |
345 |
} else { |
} else { |
346 |
// |
// |
347 |
// tree exists, we are reprocessing data. Are we reprocessing a single run or all the file? |
// tree exists, we are reprocessing data. Are we reprocessing a single run or all the file? |
348 |
// |
// |
349 |
|
S4trclone->SetAutoSave(900000000000000LL); |
350 |
reproc = true; |
reproc = true; |
351 |
// |
// |
352 |
// update versioning information |
// update versioning information |
353 |
// |
// |
|
//sgnl = runinfo->Update(run, "S4",S4version); |
|
354 |
if (verbose) printf("\n Preparing the pre-processing...\n"); |
if (verbose) printf("\n Preparing the pre-processing...\n"); |
355 |
// |
// |
356 |
if ( run == 0ULL ){ |
if ( run == 0 ){ |
357 |
// |
// |
358 |
// we are reprocessing all the file |
// we are reprocessing all the file |
359 |
// 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 |
// 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 |
368 |
// |
// |
369 |
reprocall = false; |
reprocall = false; |
370 |
// |
// |
371 |
if (verbose) printf("\n S4 - WARNING: Reprocessing run number %llu \n",run); |
if (verbose) printf("\n S4 - WARNING: Reprocessing run number %u \n",run); |
372 |
// |
// |
373 |
// copying old tree to a new file |
// copying old tree to a new file |
374 |
// |
// |
391 |
// |
// |
392 |
file->cd(); |
file->cd(); |
393 |
S4tr = new TTree("S4-new","PAMELA Level2 S4 data"); |
S4tr = new TTree("S4-new","PAMELA Level2 S4 data"); |
394 |
|
S4tr->SetAutoSave(900000000000000LL); |
395 |
S4tr->Branch("S4Level2","S4Level2",&s4); |
S4tr->Branch("S4Level2","S4Level2",&s4); |
396 |
// |
// |
397 |
if ( reproc && !reprocall ){ |
if ( reproc && !reprocall ){ |
400 |
// |
// |
401 |
tempfile = new TFile(tempname.str().c_str(),"READ"); |
tempfile = new TFile(tempname.str().c_str(),"READ"); |
402 |
S4trclone = (TTree*)tempfile->Get("S4-old"); |
S4trclone = (TTree*)tempfile->Get("S4-old"); |
403 |
|
S4trclone->SetAutoSave(900000000000000LL); |
404 |
S4trclone->SetBranchAddress("S4Level2",&s4clone); |
S4trclone->SetBranchAddress("S4Level2",&s4clone); |
405 |
// |
// |
406 |
if ( nobefrun > 0 ){ |
if ( nobefrun > 0 ){ |
407 |
if (verbose){ |
if (verbose){ |
408 |
printf("\n Pre-processing: copying events from the old tree before the processed run\n"); |
printf("\n Pre-processing: copying events from the old tree before the processed run\n"); |
409 |
printf(" Copying %u events in the file which are before the beginning of the run %llu \n",nobefrun,run); |
printf(" Copying %u events in the file which are before the beginning of the run %u \n",nobefrun,run); |
410 |
printf(" Start copying at event number 0, end copying at event number %u \n",nobefrun); |
printf(" Start copying at event number 0, end copying at event number %u \n",nobefrun); |
411 |
} |
} |
412 |
for (UInt_t j = 0; j < nobefrun; j++){ |
for (UInt_t j = 0; j < nobefrun; j++){ |
415 |
// |
// |
416 |
// copy s4clone to mydec |
// copy s4clone to mydec |
417 |
// |
// |
|
// s4 = new S4Level2(); |
|
418 |
s4->Clear(); |
s4->Clear(); |
419 |
|
// |
420 |
memcpy(&s4,&s4clone,sizeof(s4clone)); |
memcpy(&s4,&s4clone,sizeof(s4clone)); |
421 |
// |
// |
422 |
// Fill entry in the new tree |
// Fill entry in the new tree |
441 |
idRun = runlist->At(irun); |
idRun = runlist->At(irun); |
442 |
if (verbose){ |
if (verbose){ |
443 |
printf("\n\n\n ####################################################################### \n"); |
printf("\n\n\n ####################################################################### \n"); |
444 |
printf(" PROCESSING RUN NUMBER %i \n",(int)idRun); |
printf(" PROCESSING RUN NUMBER %u \n",idRun); |
445 |
printf(" ####################################################################### \n\n\n"); |
printf(" ####################################################################### \n\n\n"); |
446 |
} |
} |
447 |
// |
// |
448 |
runinfo->ID_REG_RUN = 0ULL; |
runinfo->ID_ROOT_L0 = 0; |
449 |
// |
// |
450 |
// store in the runinfo class the GL_RUN variables for our run |
// store in the runinfo class the GL_RUN variables for our run |
451 |
// |
// |
452 |
sgnl = 0; |
sgnl = 0; |
453 |
sgnl = runinfo->GetRunInfo(idRun); |
sgnl = runinfo->GetRunInfo(idRun); |
454 |
if ( sgnl ){ |
if ( sgnl ){ |
455 |
//printf(" S4 - ERROR: RunInfo exited with non-zero status\n"); |
if ( debug ) printf(" S4 - ERROR: RunInfo exited with non-zero status\n"); |
456 |
code = sgnl; |
code = sgnl; |
457 |
goto closeandexit; |
goto closeandexit; |
458 |
} else { |
} else { |
459 |
sgnl = 0; |
sgnl = 0; |
460 |
}; |
}; |
461 |
// |
// |
462 |
// now you can access that variables using the RunInfo class this way runinfo->ID_REG_RUN |
// now you can access that variables using the RunInfo class this way runinfo->ID_ROOT_L0 |
463 |
// |
// |
464 |
if ( runinfo->ID_REG_RUN == 0 ){ |
if ( runinfo->ID_ROOT_L0 == 0 ){ |
465 |
//printf("\n S4 - ERROR: no run with ID_RUN = %i \n\n Exiting... \n\n",(int)idRun); |
if ( debug ) printf("\n S4 - ERROR: no run with ID_RUN = %u \n\n Exiting... \n\n",idRun); |
466 |
code = -5; |
code = -5; |
467 |
goto closeandexit; |
goto closeandexit; |
468 |
}; |
}; |
469 |
// |
// |
470 |
|
// prepare the timesync for the db |
471 |
|
// |
472 |
|
if ( !dbc->IsConnected() ) throw -504; |
473 |
|
dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc); |
474 |
|
// |
475 |
// Search in the DB the path and name of the LEVEL0 file to be processed. |
// Search in the DB the path and name of the LEVEL0 file to be processed. |
476 |
// |
// |
477 |
glroot->Query_GL_ROOT(runinfo->ID_REG_RUN,dbc); |
if ( !dbc->IsConnected() ) throw -504; |
478 |
|
glroot->Query_GL_ROOT(runinfo->ID_ROOT_L0,dbc); |
479 |
// |
// |
480 |
ftmpname.str(""); |
ftmpname.str(""); |
481 |
ftmpname << glroot->PATH.Data() << "/"; |
ftmpname << glroot->PATH.Data() << "/"; |
484 |
// |
// |
485 |
// print out informations |
// print out informations |
486 |
// |
// |
487 |
totevent = runinfo->EV_REG_PHYS_TO - runinfo->EV_REG_PHYS_FROM + 1; |
totevent = runinfo->NEVENTS; |
488 |
if (verbose){ |
if (verbose){ |
489 |
printf("\n LEVEL0 data file: %s \n",fname.Data()); |
printf("\n LEVEL0 data file: %s \n",fname.Data()); |
490 |
printf(" RUN HEADER absolute time is: %llu \n",runinfo->RUNHEADER_TIME); |
printf(" RUN HEADER absolute time is: %u \n",runinfo->RUNHEADER_TIME); |
491 |
printf(" RUN TRAILER absolute time is: %llu \n",runinfo->RUNTRAILER_TIME); |
printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME); |
492 |
printf(" %i events to be processed for run %llu: from %i to %i (reg entries)\n\n",totevent,idRun,runinfo->EV_REG_PHYS_FROM,runinfo->EV_REG_PHYS_TO); |
printf(" %i events to be processed for run %u: from %u to %u \n\n",totevent,idRun,runinfo->EV_FROM,(runinfo->EV_FROM+totevent)); |
493 |
} |
} |
494 |
// |
// |
495 |
// Open Level0 file |
// Open Level0 file |
496 |
// |
// |
497 |
l0File = new TFile(fname.Data()); |
l0File = new TFile(fname.Data()); |
498 |
if ( !l0File ) { |
if ( !l0File ) { |
499 |
//printf(" S4 - ERROR: problems opening Level0 file\n"); |
if ( debug ) printf(" S4 - ERROR: problems opening Level0 file\n"); |
500 |
code = -6; |
code = -6; |
501 |
goto closeandexit; |
goto closeandexit; |
502 |
}; |
}; |
503 |
|
// |
504 |
l0tr = (TTree*)l0File->Get("Physics"); |
l0tr = (TTree*)l0File->Get("Physics"); |
505 |
if ( !l0tr ) { |
if ( !l0tr ) { |
506 |
//printf(" S4 - ERROR: no Physics tree in Level0 file\n"); |
if ( debug ) printf(" S4 - ERROR: no Physics tree in Level0 file\n"); |
507 |
l0File->Close(); |
l0File->Close(); |
508 |
code = -7; |
code = -7; |
509 |
goto closeandexit; |
goto closeandexit; |
510 |
}; |
}; |
511 |
l0head = l0tr->GetBranch("Header"); |
l0head = l0tr->GetBranch("Header"); |
512 |
if ( !l0head ) { |
if ( !l0head ) { |
513 |
//printf(" S4 - ERROR: no Header branch in Level0 tree\n"); |
if ( debug ) printf(" S4 - ERROR: no Header branch in Level0 tree\n"); |
514 |
l0File->Close(); |
l0File->Close(); |
515 |
code = -8; |
code = -8; |
516 |
goto closeandexit; |
goto closeandexit; |
517 |
}; |
}; |
|
l0registry = l0tr->GetBranch("Registry"); |
|
|
if ( !l0registry ) { |
|
|
//printf(" S4 - ERROR: no Registry branch in Level0 tree\n"); |
|
|
l0File->Close(); |
|
|
code = -9; |
|
|
goto closeandexit; |
|
|
}; |
|
518 |
l0S4 = l0tr->GetBranch("S4"); |
l0S4 = l0tr->GetBranch("S4"); |
519 |
if ( !l0S4 ) { |
if ( !l0S4 ) { |
520 |
//printf(" S4 - ERROR: no S4 branch in Level0 tree\n"); |
if ( debug ) printf(" S4 - ERROR: no S4 branch in Level0 tree\n"); |
521 |
l0File->Close(); |
l0File->Close(); |
522 |
code = -503; |
code = -503; |
523 |
goto closeandexit; |
goto closeandexit; |
524 |
}; |
}; |
|
|
|
525 |
// |
// |
|
l0tr->SetBranchAddress("Registry", &l0reg); |
|
526 |
l0tr->SetBranchAddress("S4", &l0s4e); |
l0tr->SetBranchAddress("S4", &l0s4e); |
527 |
l0tr->SetBranchAddress("Header", &eh); |
l0tr->SetBranchAddress("Header", &eh); |
528 |
// |
// |
529 |
nevents = l0registry->GetEntries(); |
nevents = l0S4->GetEntries(); |
530 |
// |
// |
531 |
if ( nevents < 1 ) { |
if ( nevents < 1 ) { |
532 |
//printf(" S4 - ERROR: Level0 file is empty\n\n"); |
if ( debug ) printf(" S4 - ERROR: Level0 file is empty\n\n"); |
533 |
l0File->Close(); |
l0File->Close(); |
534 |
code = -11; |
code = -11; |
535 |
goto closeandexit; |
goto closeandexit; |
536 |
}; |
}; |
537 |
// |
// |
538 |
if ( runinfo->EV_REG_PHYS_TO > nevents-1 ) { |
if ( runinfo->EV_TO > nevents-1 ) { |
539 |
//printf(" S4 - ERROR: too few entries in the registry tree\n"); |
if ( debug ) printf(" S4 - ERROR: too few entries in the S4 tree\n"); |
540 |
l0File->Close(); |
l0File->Close(); |
541 |
code = -12; |
code = -12; |
542 |
goto closeandexit; |
goto closeandexit; |
545 |
// Check if we have to load parameter files (or calibration associated to runs and not to events) |
// Check if we have to load parameter files (or calibration associated to runs and not to events) |
546 |
// second query: which is the value of paramfit relative to the calibration? |
// second query: which is the value of paramfit relative to the calibration? |
547 |
// |
// |
548 |
glS4calib->Query_GL_S4_CALIB(runinfo->RUNHEADER_TIME, dbc); |
TArrayD *params = 0; |
549 |
ParamFit0 = glS4calib->PARAM_FIT0; |
params = S4_paramfit(runinfo->RUNHEADER_TIME, dbc); |
550 |
ParamFit1 = glS4calib->PARAM_FIT1; |
if ( !params ){ |
551 |
|
code = -13; |
552 |
|
goto closeandexit; |
553 |
|
}; |
554 |
|
// |
555 |
|
ParamFit0 = params->At(0); |
556 |
|
ParamFit1 = params->At(1); |
557 |
// |
// |
558 |
// run over all the events of the run |
// run over all the events of the run |
559 |
// |
// |
560 |
if (verbose) printf("\n Ready to start! \n\n Processed events: \n\n"); |
if (verbose) printf("\n Ready to start! \n\n Processed events: \n\n"); |
561 |
// |
// |
562 |
for ( re = runinfo->EV_REG_PHYS_FROM; re <= runinfo->EV_REG_PHYS_TO; re++){ |
for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){ |
563 |
// |
// |
564 |
if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000); |
if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000); |
565 |
// |
// |
566 |
l0registry->GetEntry(re); |
l0head->GetEntry(re); |
567 |
// |
// |
568 |
// absolute time of this event |
// absolute time of this event |
569 |
// |
// |
570 |
atime = l0reg->absTime; |
ph = eh->GetPscuHeader(); |
571 |
// |
atime = dbtime->DBabsTime(ph->GetOrbitalTime()); |
|
// physics events is at entry number ei where |
|
|
// |
|
|
ei = l0reg->event; |
|
572 |
// |
// |
573 |
// paranoid check |
// paranoid check |
574 |
// |
// |
581 |
// |
// |
582 |
// start processing |
// start processing |
583 |
// |
// |
|
// s4 = new S4Level2(); |
|
584 |
s4->Clear(); |
s4->Clear(); |
585 |
l0S4->GetEntry(ei); |
l0S4->GetEntry(re); |
586 |
if (l0s4e->unpackError == 1) continue; |
if (l0s4e->unpackError == 0){ |
587 |
s4->S4adc = l0s4e->S4_DATA; |
s4->S4adc = l0s4e->S4_DATA; |
588 |
if ((l0s4e->S4_DATA) > 31 ){ |
// |
589 |
s4->S4calibrated = ParamFit0*((l0s4e->S4_DATA)-32)+ParamFit1; |
if ((l0s4e->S4_DATA) > 31 ){ |
590 |
}else{ |
s4->S4calibrated = ParamFit0*((l0s4e->S4_DATA)-32)+ParamFit1; |
591 |
s4->S4calibrated = 0; |
}else{ |
592 |
} |
s4->S4calibrated = 0; |
593 |
|
} |
594 |
|
}; |
595 |
|
// |
596 |
|
s4->unpackError = l0s4e->unpackError; |
597 |
|
// |
598 |
S4tr->Fill(); |
S4tr->Fill(); |
599 |
// |
// |
600 |
// |
// |
605 |
// |
// |
606 |
// Here you may want to clear some variables before processing another run |
// Here you may want to clear some variables before processing another run |
607 |
// |
// |
608 |
ei = 0; |
delete dbtime; |
609 |
|
if ( params ) delete params; |
610 |
|
// |
611 |
}; // process all the runs |
}; // process all the runs |
612 |
// |
// |
613 |
if (verbose) printf("\n Finished processing data \n"); |
if (verbose) printf("\n Finished processing data \n"); |
648 |
if ( l0File ) l0File->Close(); |
if ( l0File ) l0File->Close(); |
649 |
if ( tempfile ) tempfile->Close(); |
if ( tempfile ) tempfile->Close(); |
650 |
gSystem->Unlink(tempname.str().c_str()); |
gSystem->Unlink(tempname.str().c_str()); |
651 |
|
// |
|
//if ( code < 0 ) printf("\n S4 - ERROR: an error occurred, try to save anyway...\n"); |
|
|
//printf("\n Writing and closing rootple\n"); |
|
652 |
if ( runinfo ) runinfo->Close(); |
if ( runinfo ) runinfo->Close(); |
653 |
if ( S4tr ) S4tr->SetName("S4"); |
if ( S4tr ) S4tr->SetName("S4"); |
654 |
if ( file ){ |
if ( file ){ |
661 |
// the end |
// the end |
662 |
// |
// |
663 |
if (verbose) printf("\n Exiting...\n"); |
if (verbose) printf("\n Exiting...\n"); |
664 |
if(S4tr)S4tr->Delete(); |
if ( S4tr ) S4tr->Delete(); |
665 |
|
// |
666 |
|
if ( s4 ) delete s4; |
667 |
|
if ( s4clone ) delete s4clone; |
668 |
|
if ( glroot ) delete glroot; |
669 |
|
if ( runinfo ) delete runinfo; |
670 |
|
// |
671 |
if(code < 0) throw code; |
if(code < 0) throw code; |
672 |
return(code); |
return(code); |
673 |
} |
} |
674 |
|
|
675 |
|
|
|
|
|