| 9 |
// |
// |
| 10 |
// ROOT headers |
// ROOT headers |
| 11 |
// |
// |
| 12 |
|
#include <TGraph.h> |
| 13 |
|
#include <TF1.h> |
| 14 |
#include <TTree.h> |
#include <TTree.h> |
| 15 |
#include <TClassEdit.h> |
#include <TClassEdit.h> |
| 16 |
#include <TObject.h> |
#include <TObject.h> |
| 17 |
#include <TList.h> |
#include <TList.h> |
| 18 |
#include <TArrayL.h> |
#include <TArrayI.h> |
| 19 |
|
#include <TArrayD.h> |
| 20 |
#include <TSystem.h> |
#include <TSystem.h> |
| 21 |
#include <TSystemDirectory.h> |
#include <TSystemDirectory.h> |
| 22 |
#include <TString.h> |
#include <TString.h> |
| 32 |
// YODA headers |
// YODA headers |
| 33 |
// |
// |
| 34 |
#include <PamelaRun.h> |
#include <PamelaRun.h> |
|
#include <RegistryEvent.h> |
|
| 35 |
#include <PscuHeader.h> |
#include <PscuHeader.h> |
| 36 |
#include <PscuEvent.h> |
#include <PscuEvent.h> |
| 37 |
#include <EventHeader.h> |
#include <EventHeader.h> |
|
#include <RegistryEvent.h> |
|
| 38 |
#include <CalibS4Event.h> |
#include <CalibS4Event.h> |
| 39 |
#include <physics/S4/S4Event.h> |
#include <physics/S4/S4Event.h> |
| 40 |
//#include <yodaUtility.h> |
//#include <yodaUtility.h> |
| 53 |
using namespace std; |
using namespace std; |
| 54 |
|
|
| 55 |
// |
// |
|
// CORE ROUTINE |
|
| 56 |
// |
// |
| 57 |
// |
// |
| 58 |
|
/* |
| 59 |
|
* Fit function Received from Valeria Malvezzi 06/02/2006 |
| 60 |
|
*/ |
| 61 |
|
Double_t fitf(Double_t *x, Double_t *par){ |
| 62 |
|
Double_t fitval =(par[0]*x[0])+par[1]; |
| 63 |
|
return fitval; |
| 64 |
|
} |
| 65 |
|
|
| 66 |
int S4Core(ULong64_t run, TFile *file, TSQLServer *dbc, Int_t S4argc, char *S4argv[]){ |
/* |
| 67 |
|
* Fit the S4 calibration with a straight line - Received from Valeria Malvezzi 06/02/2006 |
| 68 |
|
*/ |
| 69 |
|
TArrayD *S4_paramfit(UInt_t atime, TSQLServer *dbc){ |
| 70 |
|
// |
| 71 |
|
TArrayD *parametri = new TArrayD(2); |
| 72 |
|
// |
| 73 |
|
GL_S4_CALIB *glS4calib = new GL_S4_CALIB(); |
| 74 |
|
// |
| 75 |
|
glS4calib->Query_GL_S4_CALIB(atime, dbc); |
| 76 |
|
// |
| 77 |
|
GL_ROOT *glroot = new GL_ROOT(); |
| 78 |
|
glroot->Query_GL_ROOT(glS4calib->ID_ROOT_L0,dbc); |
| 79 |
|
// |
| 80 |
|
stringstream ftmpname; |
| 81 |
|
ftmpname.str(""); |
| 82 |
|
ftmpname << glroot->PATH.Data() << "/"; |
| 83 |
|
ftmpname << glroot->NAME.Data(); |
| 84 |
|
// |
| 85 |
|
TFile *file = 0; |
| 86 |
|
file = new TFile(ftmpname.str().c_str()); |
| 87 |
|
// |
| 88 |
|
if ( !file ) return(NULL); |
| 89 |
|
// |
| 90 |
|
TTree *tr = 0; |
| 91 |
|
tr = (TTree*)file->Get("CalibS4"); |
| 92 |
|
if ( !tr ){ |
| 93 |
|
file->Close(); |
| 94 |
|
return(NULL); |
| 95 |
|
}; |
| 96 |
|
// |
| 97 |
|
pamela::CalibS4Event *S4CalibEvent = 0; |
| 98 |
|
tr->SetBranchAddress("CalibS4", &S4CalibEvent); |
| 99 |
|
if ( tr->GetEntries() < glS4calib->EV_ROOT ) return(NULL); |
| 100 |
|
// |
| 101 |
|
tr->GetEntry(glS4calib->EV_ROOT); |
| 102 |
|
// |
| 103 |
|
//----------- variable initialization ------------------------------------------------- |
| 104 |
|
// |
| 105 |
|
Double_t mip[3]={1, 30, 300}; |
| 106 |
|
Double_t adc[3] = {0.,0.,0.}; |
| 107 |
|
// |
| 108 |
|
//------------ Fit calibrations and find parameters to calibrate data ------------------ |
| 109 |
|
// |
| 110 |
|
pamela::S4::S4Event *s4Record = 0; |
| 111 |
|
// |
| 112 |
|
for (Int_t j = 0; j < 4; j++){ |
| 113 |
|
for (Int_t i = 0; i < 128; i++){ |
| 114 |
|
s4Record = (pamela::S4::S4Event*)S4CalibEvent->Records->At((j*128 + i)); |
| 115 |
|
switch (j) { |
| 116 |
|
case 0 :{ |
| 117 |
|
adc[0]=adc[0]+((s4Record->S4_DATA)-32); |
| 118 |
|
break; |
| 119 |
|
}; |
| 120 |
|
case 1 :{ |
| 121 |
|
adc[1]=adc[1]+((s4Record->S4_DATA)-32); |
| 122 |
|
break; |
| 123 |
|
}; |
| 124 |
|
case 3 :{ |
| 125 |
|
adc[2]=adc[2]+((s4Record->S4_DATA)-32); |
| 126 |
|
break; |
| 127 |
|
}; |
| 128 |
|
}; |
| 129 |
|
}; |
| 130 |
|
}; |
| 131 |
|
// |
| 132 |
|
adc[0]=adc[0]/128; |
| 133 |
|
adc[1]=adc[1]/128; |
| 134 |
|
adc[2]=adc[2]/128; |
| 135 |
|
// if ( IsDebug() ) printf(" adc1 = %g adc2 = %g adc3 = %g\n",adc[0],adc[1],adc[2]); |
| 136 |
|
TGraph *fitpar = new TGraph (3, adc, mip); |
| 137 |
|
TF1 *func = new TF1("fitf", fitf, -1., 400., 2); // definizione della funzione, 2 = num. parametri |
| 138 |
|
// TF1 *func = new TF1("fitf", fitf, -0., 1000., 2); // definizione della funzione, 2 = num. parametri |
| 139 |
|
// |
| 140 |
|
func->SetParameters(0.3,1.); //inizializzazione dei parametri a 1 |
| 141 |
|
func->SetParNames("m","q"); //definisce il nome dei parametri |
| 142 |
|
fitpar->Fit(func,"qr"); //fitta fitpar con la funzione func nel range definito nella funzione |
| 143 |
|
//fitpar->Fit(func,"r"); //fitta fitpar con la funzione func nel range definito nella funzione |
| 144 |
|
parametri->AddAt(func->GetParameter(0),0); |
| 145 |
|
parametri->AddAt(func->GetParameter(1),1); |
| 146 |
|
// if ( parametri[0] < 0. || parametri[0] > 0.5 || parametri[1] < 0.7 || parametri[1] > 1.1 ) valid = 0; |
| 147 |
|
// |
| 148 |
|
delete glroot; |
| 149 |
|
delete glS4calib; |
| 150 |
|
delete fitpar; |
| 151 |
|
delete func; |
| 152 |
|
file->Close(); |
| 153 |
|
// |
| 154 |
|
return parametri; |
| 155 |
|
}; |
| 156 |
|
|
| 157 |
|
// |
| 158 |
|
// CORE ROUTINE |
| 159 |
|
// |
| 160 |
|
// |
| 161 |
|
int S4Core(UInt_t run, TFile *file, TSQLServer *dbc, Int_t S4argc, char *S4argv[]){ |
| 162 |
Int_t i = 0; |
Int_t i = 0; |
| 163 |
// |
// |
| 164 |
TString processFolder = "S4Folder"; |
TString processFolder = "S4Folder"; |
| 165 |
// |
// |
| 166 |
// Set these to true to have a very verbose output. |
Bool_t debug = false; |
|
Bool_t debug = false; |
|
| 167 |
// |
// |
| 168 |
Bool_t verbose = false; |
Bool_t verbose = false; |
| 169 |
// |
// |
| 170 |
if ( S4argc > 0 ){ |
if ( S4argc > 0 ){ |
| 171 |
i = 0; |
i = 0; |
| 186 |
i++; |
i++; |
| 187 |
}; |
}; |
| 188 |
}; |
}; |
| 189 |
|
// |
| 190 |
const char* outDir = gSystem->DirName(gSystem->DirName(file->GetPath())); |
const char* outDir = gSystem->DirName(gSystem->DirName(file->GetPath())); |
| 191 |
|
// |
| 192 |
// Variables for level2 |
// Variables for level2 |
| 193 |
// |
// |
| 194 |
TTree *S4tr = 0; |
TTree *S4tr = 0; |
| 195 |
Long64_t nevents = 0LL; |
UInt_t nevents = 0; |
| 196 |
// |
// |
| 197 |
// variables needed to reprocess data |
// variables needed to reprocess data |
| 198 |
// |
// |
| 199 |
TString S4version; |
TString S4version; |
| 200 |
ItoRunInfo *runinfo = 0; |
ItoRunInfo *runinfo = 0; |
| 201 |
TArrayL *runlist = 0; |
TArrayI *runlist = 0; |
| 202 |
TTree *S4trclone = 0; |
TTree *S4trclone = 0; |
| 203 |
Bool_t reproc = false; |
Bool_t reproc = false; |
| 204 |
Bool_t reprocall = false; |
Bool_t reprocall = false; |
| 207 |
UInt_t numbofrun = 0; |
UInt_t numbofrun = 0; |
| 208 |
stringstream ftmpname; |
stringstream ftmpname; |
| 209 |
TString fname; |
TString fname; |
| 210 |
Long64_t totfileentries = 0ULL; |
UInt_t totfileentries = 0; |
| 211 |
Long64_t idRun = 0LL; |
UInt_t idRun = 0; |
| 212 |
Double_t ParamFit0 = 0ULL; |
Double_t ParamFit0 = 0.; |
| 213 |
Double_t ParamFit1 = 0ULL; |
Double_t ParamFit1 = 0.; |
| 214 |
// |
// |
| 215 |
// variables needed to handle error signals |
// variables needed to handle error signals |
| 216 |
// |
// |
| 227 |
TFile *l0File = 0; |
TFile *l0File = 0; |
| 228 |
TTree *l0tr = 0; |
TTree *l0tr = 0; |
| 229 |
TBranch *l0head = 0; |
TBranch *l0head = 0; |
|
TBranch *l0registry = 0; |
|
| 230 |
TBranch *l0S4 =0; |
TBranch *l0S4 =0; |
|
pamela::RegistryEvent *l0reg=0; |
|
| 231 |
pamela::S4::S4Event *l0s4e = 0; |
pamela::S4::S4Event *l0s4e = 0; |
| 232 |
pamela::EventHeader *eh = 0; |
pamela::EventHeader *eh = 0; |
| 233 |
|
pamela::PscuHeader *ph = 0; |
| 234 |
// |
// |
| 235 |
// Define other basic variables |
// Define other basic variables |
| 236 |
// |
// |
| 239 |
stringstream file3; |
stringstream file3; |
| 240 |
stringstream qy; |
stringstream qy; |
| 241 |
Int_t totevent = 0; |
Int_t totevent = 0; |
| 242 |
ULong64_t atime = 0ULL; |
UInt_t atime = 0; |
| 243 |
Int_t ei = 0; |
// Int_t ei = 0; |
| 244 |
Int_t re = 0; |
UInt_t re = 0; |
| 245 |
// |
// |
| 246 |
// Working filename |
// Working filename |
| 247 |
// |
// |
| 268 |
// DB classes |
// DB classes |
| 269 |
// |
// |
| 270 |
GL_ROOT *glroot = new GL_ROOT(); |
GL_ROOT *glroot = new GL_ROOT(); |
| 271 |
GL_S4_CALIB *glS4calib = new GL_S4_CALIB(); |
GL_TIMESYNC *dbtime = 0; |
| 272 |
// |
// |
| 273 |
// Let's start! |
// Let's start! |
| 274 |
// |
// |
| 276 |
// 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 |
| 277 |
// 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. |
| 278 |
// |
// |
| 279 |
if ( run == 0ULL ) reproc = true; |
if ( run == 0 ) reproc = true; |
| 280 |
// |
// |
| 281 |
// |
// |
| 282 |
// Output file is "outputfile" |
// Output file is "outputfile" |
| 331 |
// tree does not exist, we are not reprocessing |
// tree does not exist, we are not reprocessing |
| 332 |
// |
// |
| 333 |
reproc = false; |
reproc = false; |
| 334 |
if ( run == 0ULL ){ |
if ( run == 0 ){ |
| 335 |
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"); |
| 336 |
} |
} |
| 337 |
if ( runinfo->IsReprocessing() && run != 0ULL ) { |
if ( runinfo->IsReprocessing() && run != 0 ) { |
| 338 |
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"); |
| 339 |
} |
} |
| 340 |
} else { |
} else { |
| 345 |
// |
// |
| 346 |
// update versioning information |
// update versioning information |
| 347 |
// |
// |
|
//sgnl = runinfo->Update(run, "S4",S4version); |
|
| 348 |
if (verbose) printf("\n Preparing the pre-processing...\n"); |
if (verbose) printf("\n Preparing the pre-processing...\n"); |
| 349 |
// |
// |
| 350 |
if ( run == 0ULL ){ |
if ( run == 0 ){ |
| 351 |
// |
// |
| 352 |
// we are reprocessing all the file |
// we are reprocessing all the file |
| 353 |
// 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 |
| 362 |
// |
// |
| 363 |
reprocall = false; |
reprocall = false; |
| 364 |
// |
// |
| 365 |
if (verbose) printf("\n S4 - WARNING: Reprocessing run number %llu \n",run); |
if (verbose) printf("\n S4 - WARNING: Reprocessing run number %u \n",run); |
| 366 |
// |
// |
| 367 |
// copying old tree to a new file |
// copying old tree to a new file |
| 368 |
// |
// |
| 398 |
if ( nobefrun > 0 ){ |
if ( nobefrun > 0 ){ |
| 399 |
if (verbose){ |
if (verbose){ |
| 400 |
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"); |
| 401 |
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); |
| 402 |
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); |
| 403 |
} |
} |
| 404 |
for (UInt_t j = 0; j < nobefrun; j++){ |
for (UInt_t j = 0; j < nobefrun; j++){ |
| 407 |
// |
// |
| 408 |
// copy s4clone to mydec |
// copy s4clone to mydec |
| 409 |
// |
// |
| 410 |
s4 = new S4Level2(); |
s4->Clear(); |
| 411 |
|
// |
| 412 |
memcpy(&s4,&s4clone,sizeof(s4clone)); |
memcpy(&s4,&s4clone,sizeof(s4clone)); |
| 413 |
// |
// |
| 414 |
// Fill entry in the new tree |
// Fill entry in the new tree |
| 433 |
idRun = runlist->At(irun); |
idRun = runlist->At(irun); |
| 434 |
if (verbose){ |
if (verbose){ |
| 435 |
printf("\n\n\n ####################################################################### \n"); |
printf("\n\n\n ####################################################################### \n"); |
| 436 |
printf(" PROCESSING RUN NUMBER %i \n",(int)idRun); |
printf(" PROCESSING RUN NUMBER %u \n",idRun); |
| 437 |
printf(" ####################################################################### \n\n\n"); |
printf(" ####################################################################### \n\n\n"); |
| 438 |
} |
} |
| 439 |
// |
// |
| 440 |
runinfo->ID_REG_RUN = 0ULL; |
runinfo->ID_ROOT_L0 = 0; |
| 441 |
// |
// |
| 442 |
// store in the runinfo class the GL_RUN variables for our run |
// store in the runinfo class the GL_RUN variables for our run |
| 443 |
// |
// |
| 444 |
sgnl = 0; |
sgnl = 0; |
| 445 |
sgnl = runinfo->GetRunInfo(idRun); |
sgnl = runinfo->GetRunInfo(idRun); |
| 446 |
if ( sgnl ){ |
if ( sgnl ){ |
| 447 |
//printf(" S4 - ERROR: RunInfo exited with non-zero status\n"); |
if ( debug ) printf(" S4 - ERROR: RunInfo exited with non-zero status\n"); |
| 448 |
code = sgnl; |
code = sgnl; |
| 449 |
goto closeandexit; |
goto closeandexit; |
| 450 |
} else { |
} else { |
| 451 |
sgnl = 0; |
sgnl = 0; |
| 452 |
}; |
}; |
| 453 |
// |
// |
| 454 |
// 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 |
| 455 |
// |
// |
| 456 |
if ( runinfo->ID_REG_RUN == 0 ){ |
if ( runinfo->ID_ROOT_L0 == 0 ){ |
| 457 |
//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); |
| 458 |
code = -5; |
code = -5; |
| 459 |
goto closeandexit; |
goto closeandexit; |
| 460 |
}; |
}; |
| 461 |
// |
// |
| 462 |
|
// prepare the timesync for the db |
| 463 |
|
// |
| 464 |
|
dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc); |
| 465 |
|
// |
| 466 |
// 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. |
| 467 |
// |
// |
| 468 |
glroot->Query_GL_ROOT(runinfo->ID_REG_RUN,dbc); |
glroot->Query_GL_ROOT(runinfo->ID_ROOT_L0,dbc); |
| 469 |
// |
// |
| 470 |
ftmpname.str(""); |
ftmpname.str(""); |
| 471 |
ftmpname << glroot->PATH.Data() << "/"; |
ftmpname << glroot->PATH.Data() << "/"; |
| 474 |
// |
// |
| 475 |
// print out informations |
// print out informations |
| 476 |
// |
// |
| 477 |
totevent = runinfo->EV_REG_PHYS_TO - runinfo->EV_REG_PHYS_FROM + 1; |
totevent = runinfo->NEVENTS; |
| 478 |
if (verbose){ |
if (verbose){ |
| 479 |
printf("\n LEVEL0 data file: %s \n",fname.Data()); |
printf("\n LEVEL0 data file: %s \n",fname.Data()); |
| 480 |
printf(" RUN HEADER absolute time is: %llu \n",runinfo->RUNHEADER_TIME); |
printf(" RUN HEADER absolute time is: %u \n",runinfo->RUNHEADER_TIME); |
| 481 |
printf(" RUN TRAILER absolute time is: %llu \n",runinfo->RUNTRAILER_TIME); |
printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME); |
| 482 |
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)); |
| 483 |
} |
} |
| 484 |
// |
// |
| 485 |
// Open Level0 file |
// Open Level0 file |
| 486 |
// |
// |
| 487 |
l0File = new TFile(fname.Data()); |
l0File = new TFile(fname.Data()); |
| 488 |
if ( !l0File ) { |
if ( !l0File ) { |
| 489 |
//printf(" S4 - ERROR: problems opening Level0 file\n"); |
if ( debug ) printf(" S4 - ERROR: problems opening Level0 file\n"); |
| 490 |
code = -6; |
code = -6; |
| 491 |
goto closeandexit; |
goto closeandexit; |
| 492 |
}; |
}; |
| 493 |
|
// |
| 494 |
l0tr = (TTree*)l0File->Get("Physics"); |
l0tr = (TTree*)l0File->Get("Physics"); |
| 495 |
if ( !l0tr ) { |
if ( !l0tr ) { |
| 496 |
//printf(" S4 - ERROR: no Physics tree in Level0 file\n"); |
if ( debug ) printf(" S4 - ERROR: no Physics tree in Level0 file\n"); |
| 497 |
l0File->Close(); |
l0File->Close(); |
| 498 |
code = -7; |
code = -7; |
| 499 |
goto closeandexit; |
goto closeandexit; |
| 500 |
}; |
}; |
| 501 |
l0head = l0tr->GetBranch("Header"); |
l0head = l0tr->GetBranch("Header"); |
| 502 |
if ( !l0head ) { |
if ( !l0head ) { |
| 503 |
//printf(" S4 - ERROR: no Header branch in Level0 tree\n"); |
if ( debug ) printf(" S4 - ERROR: no Header branch in Level0 tree\n"); |
| 504 |
l0File->Close(); |
l0File->Close(); |
| 505 |
code = -8; |
code = -8; |
| 506 |
goto closeandexit; |
goto closeandexit; |
| 507 |
}; |
}; |
|
l0registry = l0tr->GetBranch("Registry"); |
|
|
if ( !l0registry ) { |
|
|
//printf(" S4 - ERROR: no Registry branch in Level0 tree\n"); |
|
|
l0File->Close(); |
|
|
code = -9; |
|
|
goto closeandexit; |
|
|
}; |
|
| 508 |
l0S4 = l0tr->GetBranch("S4"); |
l0S4 = l0tr->GetBranch("S4"); |
| 509 |
if ( !l0S4 ) { |
if ( !l0S4 ) { |
| 510 |
//printf(" S4 - ERROR: no S4 branch in Level0 tree\n"); |
if ( debug ) printf(" S4 - ERROR: no S4 branch in Level0 tree\n"); |
| 511 |
l0File->Close(); |
l0File->Close(); |
| 512 |
code = -503; |
code = -503; |
| 513 |
goto closeandexit; |
goto closeandexit; |
| 514 |
}; |
}; |
|
|
|
| 515 |
// |
// |
|
l0tr->SetBranchAddress("Registry", &l0reg); |
|
| 516 |
l0tr->SetBranchAddress("S4", &l0s4e); |
l0tr->SetBranchAddress("S4", &l0s4e); |
| 517 |
l0tr->SetBranchAddress("Header", &eh); |
l0tr->SetBranchAddress("Header", &eh); |
| 518 |
// |
// |
| 519 |
nevents = l0registry->GetEntries(); |
nevents = l0S4->GetEntries(); |
| 520 |
// |
// |
| 521 |
if ( nevents < 1 ) { |
if ( nevents < 1 ) { |
| 522 |
//printf(" S4 - ERROR: Level0 file is empty\n\n"); |
if ( debug ) printf(" S4 - ERROR: Level0 file is empty\n\n"); |
| 523 |
l0File->Close(); |
l0File->Close(); |
| 524 |
code = -11; |
code = -11; |
| 525 |
goto closeandexit; |
goto closeandexit; |
| 526 |
}; |
}; |
| 527 |
// |
// |
| 528 |
if ( runinfo->EV_REG_PHYS_TO > nevents-1 ) { |
if ( runinfo->EV_TO > nevents-1 ) { |
| 529 |
//printf(" S4 - ERROR: too few entries in the registry tree\n"); |
if ( debug ) printf(" S4 - ERROR: too few entries in the S4 tree\n"); |
| 530 |
l0File->Close(); |
l0File->Close(); |
| 531 |
code = -12; |
code = -12; |
| 532 |
goto closeandexit; |
goto closeandexit; |
| 535 |
// 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) |
| 536 |
// second query: which is the value of paramfit relative to the calibration? |
// second query: which is the value of paramfit relative to the calibration? |
| 537 |
// |
// |
| 538 |
glS4calib->Query_GL_S4_CALIB(runinfo->RUNHEADER_TIME, dbc); |
TArrayD *params = 0; |
| 539 |
ParamFit0 = glS4calib->PARAM_FIT0; |
params = S4_paramfit(runinfo->RUNHEADER_TIME, dbc); |
| 540 |
ParamFit1 = glS4calib->PARAM_FIT1; |
if ( !params ){ |
| 541 |
|
code = -13; |
| 542 |
|
goto closeandexit; |
| 543 |
|
}; |
| 544 |
|
// |
| 545 |
|
ParamFit0 = params->At(0); |
| 546 |
|
ParamFit1 = params->At(1); |
| 547 |
// |
// |
| 548 |
// run over all the events of the run |
// run over all the events of the run |
| 549 |
// |
// |
| 550 |
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"); |
| 551 |
// |
// |
| 552 |
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++){ |
| 553 |
// |
// |
| 554 |
if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000); |
if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000); |
| 555 |
// |
// |
| 556 |
l0registry->GetEntry(re); |
l0head->GetEntry(re); |
| 557 |
// |
// |
| 558 |
// absolute time of this event |
// absolute time of this event |
| 559 |
// |
// |
| 560 |
atime = l0reg->absTime; |
ph = eh->GetPscuHeader(); |
| 561 |
// |
atime = dbtime->DBabsTime(ph->GetOrbitalTime()); |
|
// physics events is at entry number ei where |
|
|
// |
|
|
ei = l0reg->event; |
|
| 562 |
// |
// |
| 563 |
// paranoid check |
// paranoid check |
| 564 |
// |
// |
| 571 |
// |
// |
| 572 |
// start processing |
// start processing |
| 573 |
// |
// |
| 574 |
s4 = new S4Level2(); |
s4->Clear(); |
| 575 |
l0S4->GetEntry(ei); |
l0S4->GetEntry(re); |
| 576 |
if (l0s4e->unpackError == 1) continue; |
if (l0s4e->unpackError == 0){ |
| 577 |
s4->S4adc = l0s4e->S4_DATA; |
s4->S4adc = l0s4e->S4_DATA; |
| 578 |
if ((l0s4e->S4_DATA) > 31 ){ |
// |
| 579 |
s4->S4calibrated = ParamFit0*((l0s4e->S4_DATA)-32)+ParamFit1; |
if ((l0s4e->S4_DATA) > 31 ){ |
| 580 |
}else{ |
s4->S4calibrated = ParamFit0*((l0s4e->S4_DATA)-32)+ParamFit1; |
| 581 |
s4->S4calibrated = 0; |
}else{ |
| 582 |
} |
s4->S4calibrated = 0; |
| 583 |
|
} |
| 584 |
|
}; |
| 585 |
|
// |
| 586 |
S4tr->Fill(); |
S4tr->Fill(); |
| 587 |
// |
// |
| 588 |
// |
// |
| 593 |
// |
// |
| 594 |
// Here you may want to clear some variables before processing another run |
// Here you may want to clear some variables before processing another run |
| 595 |
// |
// |
| 596 |
ei = 0; |
delete dbtime; |
| 597 |
|
if ( params ) delete params; |
| 598 |
|
// |
| 599 |
}; // process all the runs |
}; // process all the runs |
| 600 |
// |
// |
| 601 |
if (verbose) printf("\n Finished processing data \n"); |
if (verbose) printf("\n Finished processing data \n"); |
| 619 |
// |
// |
| 620 |
// copy s4clone to s4 |
// copy s4clone to s4 |
| 621 |
// |
// |
| 622 |
s4 = new S4Level2(); |
// s4 = new S4Level2(); |
| 623 |
|
s4->Clear(); |
| 624 |
memcpy(&s4,&s4clone,sizeof(s4clone)); |
memcpy(&s4,&s4clone,sizeof(s4clone)); |
| 625 |
// |
// |
| 626 |
// Fill entry in the new tree |
// Fill entry in the new tree |
| 636 |
if ( l0File ) l0File->Close(); |
if ( l0File ) l0File->Close(); |
| 637 |
if ( tempfile ) tempfile->Close(); |
if ( tempfile ) tempfile->Close(); |
| 638 |
gSystem->Unlink(tempname.str().c_str()); |
gSystem->Unlink(tempname.str().c_str()); |
| 639 |
|
// |
|
//if ( code < 0 ) printf("\n S4 - ERROR: an error occurred, try to save anyway...\n"); |
|
|
//printf("\n Writing and closing rootple\n"); |
|
| 640 |
if ( runinfo ) runinfo->Close(); |
if ( runinfo ) runinfo->Close(); |
| 641 |
if ( S4tr ) S4tr->SetName("S4"); |
if ( S4tr ) S4tr->SetName("S4"); |
| 642 |
if ( file ){ |
if ( file ){ |
| 649 |
// the end |
// the end |
| 650 |
// |
// |
| 651 |
if (verbose) printf("\n Exiting...\n"); |
if (verbose) printf("\n Exiting...\n"); |
| 652 |
if(S4tr)S4tr->Delete(); |
if ( S4tr ) S4tr->Delete(); |
| 653 |
|
// |
| 654 |
|
if ( s4 ) delete s4; |
| 655 |
|
if ( s4clone ) delete s4clone; |
| 656 |
|
if ( glroot ) delete glroot; |
| 657 |
|
if ( runinfo ) delete runinfo; |
| 658 |
|
// |
| 659 |
if(code < 0) throw code; |
if(code < 0) throw code; |
| 660 |
return(code); |
return(code); |
| 661 |
} |
} |
| 662 |
|
|
| 663 |
|
|
|
|
|