/[PAMELA software]/DarthVader/S4Level2/src/S4Core.cpp
ViewVC logotype

Diff of /DarthVader/S4Level2/src/S4Core.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.10

  ViewVC Help
Powered by ViewVC 1.1.23