/[PAMELA software]/PamelaLevel2/src/PamLevel2.cpp
ViewVC logotype

Diff of /PamelaLevel2/src/PamLevel2.cpp

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

revision 1.82 by mocchiut, Thu Jun 4 15:10:47 2009 UTC revision 1.112 by pam-fi, Mon Nov 2 09:59:54 2015 UTC
# Line 30  void GPamela::Clear() { Line 30  void GPamela::Clear() {
30  void GPamela::Delete() {  void GPamela::Delete() {
31    
32    Clear();    Clear();
33      /* EM all these are in the stack not in the heap, so no need to delete by hand...
34    delete[] Ipltof;    delete[] Ipltof;
35    delete[] Ipaddle;    delete[] Ipaddle;
36    delete[] Ipartof;    delete[] Ipartof;
# Line 131  void GPamela::Delete() { Line 131  void GPamela::Delete() {
131    delete[] Timecard;    delete[] Timecard;
132    delete[] Pathcard;    delete[] Pathcard;
133    delete[] P0card;    delete[] P0card;
134      */
135  }  }
136  ;  
137    
138  void GPamela::SetBranchAddress(TChain* fhBookTree) {  void GPamela::SetBranchAddress(TChain* fhBookTree) {
139    
# Line 278  ClassImp( GPamela); Line 278  ClassImp( GPamela);
278   */   */
279  PamTrack::PamTrack() {  PamTrack::PamTrack() {
280    trk_track = 0;    trk_track = 0;
281      trk_ext_track = 0;
282    calo_track = 0;    calo_track = 0;
283    tof_track = 0;    tof_track = 0;
284    orb_track = 0;    orb_track = 0;
# Line 295  PamTrack::PamTrack() { Line 296  PamTrack::PamTrack() {
296   */   */
297  PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o, OrbitalInfoTrkVar *r) {  PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o, OrbitalInfoTrkVar *r) {
298    
299      trk_ext_track = 0;
300    trk_track = 0;    trk_track = 0;
301    calo_track = 0;    calo_track = 0;
302    tof_track = 0;    tof_track = 0;
# Line 302  PamTrack::PamTrack(TrkTrack* t, CaloTrkV Line 304  PamTrack::PamTrack(TrkTrack* t, CaloTrkV
304    //     if(t)trk_track  = new TrkTrack(*t);    //     if(t)trk_track  = new TrkTrack(*t);
305    //     if(c)calo_track = new CaloTrkVar(*c);    //     if(c)calo_track = new CaloTrkVar(*c);
306    //     if(o)tof_track  = new ToFTrkVar(*o);    //     if(o)tof_track  = new ToFTrkVar(*o);
307    if (t)  //   if (t)
308      trk_track = t;  //     trk_track = t;
309    //   if (c)
310    //     calo_track = c;
311    //   if (o)
312    //     tof_track = o;
313    //   if (r)
314    //     orb_track = r;
315    
316    //   candeleteobj = 0;
317    
318    //  cout << t<<"--"<<c<<"--"<<o<<"--"<<r<<"--"<< endl;
319    
320      if (t){
321          trk_track = new TrkTrack(*t);
322          trk_ext_track = new ExtTrack(*t);//NB!! ha dimensione 6 invece che 8
323      }else{
324          trk_track = new TrkTrack();
325          trk_ext_track = new ExtTrack();
326          
327      }
328    
329    if (c)    if (c)
330      calo_track = c;      calo_track = new CaloTrkVar(*c);
331      else
332        calo_track = new CaloTrkVar();
333      
334    if (o)    if (o)
335      tof_track = o;      tof_track = new ToFTrkVar(*o);
336      else
337        tof_track = new ToFTrkVar();
338    
339    if (r)    if (r)
340      orb_track = r;      orb_track = new OrbitalInfoTrkVar(*r);
341      else
342        orb_track = new OrbitalInfoTrkVar();
343    
344    candeleteobj = 0;  //  cout << trk_track<<"--"<< calo_track <<"--"<<tof_track<<"--"<<orb_track<<"--"<< endl;
345    
346      candeleteobj = 1;
347    
348    }
349    ;
350    /**
351     * Constructor
352     */
353    PamTrack::PamTrack(ExtTrack* t, CaloTrkVar* c, ToFTrkVar* o, OrbitalInfoTrkVar *r) {
354    
355        
356    
357      trk_ext_track = 0;
358      trk_track = 0;
359      calo_track = 0;
360      tof_track = 0;
361      orb_track = 0;
362      //     if(t)trk_track  = new TrkTrack(*t);
363      //     if(c)calo_track = new CaloTrkVar(*c);
364      //     if(o)tof_track  = new ToFTrkVar(*o);
365    //   if (t)
366    //     trk_track = t;
367    //   if (c)
368    //     calo_track = c;
369    //   if (o)
370    //     tof_track = o;
371    //   if (r)
372    //     orb_track = r;
373    
374    //   candeleteobj = 0;
375    
376    //  cout << t<<"--"<<c<<"--"<<o<<"--"<<r<<"--"<< endl;
377    
378    
379      if (t){
380    ////      trk_track = new TrkTrack(*t);//in this case TrkTrack object remains null
381          trk_ext_track = new ExtTrack(*t);
382      }else{
383          trk_ext_track = new ExtTrack();
384      }
385      if (c)
386        calo_track = new CaloTrkVar(*c);
387      else
388          calo_track = new CaloTrkVar();
389    
390      if (o)
391        tof_track = new ToFTrkVar(*o);
392      else
393        tof_track = new ToFTrkVar();
394    
395      if (r)
396        orb_track = new OrbitalInfoTrkVar(*r);
397      else
398        orb_track = new OrbitalInfoTrkVar();
399    
400    //  cout << trk_track<<"--"<< calo_track <<"--"<<tof_track<<"--"<<orb_track<<"--"<< endl;
401    
402      candeleteobj = 1;
403      pscore = 0;
404      iscore = 0;
405    
406  }  }
407  ;  ;
408    
409  PamTrack::PamTrack(const PamTrack& track) {  PamTrack::PamTrack(const PamTrack& track) {
410    
411    TrkTrack *t = track.trk_track;    TrkTrack *t = track.trk_track;
412      ExtTrack *e = track.trk_ext_track;
413    CaloTrkVar *c = track.calo_track;    CaloTrkVar *c = track.calo_track;
414    ToFTrkVar *o = track.tof_track;    ToFTrkVar *o = track.tof_track;
415    OrbitalInfoTrkVar *r = track.orb_track;    OrbitalInfoTrkVar *r = track.orb_track;
416    
417    trk_track = 0;    trk_ext_track = 0;
418    calo_track = 0;    trk_track     = 0;
419    tof_track = 0;    calo_track    = 0;
420    orb_track = 0;    tof_track     = 0;
421      orb_track     = 0;
422      if(e)
423          trk_ext_track = new ExtTrack(*e);
424    if (t)    if (t)
425      trk_track = new TrkTrack(*t);      trk_track = new TrkTrack(*t);
426    if (c)    if (c)
# Line 334  PamTrack::PamTrack(const PamTrack& track Line 429  PamTrack::PamTrack(const PamTrack& track
429      tof_track = new ToFTrkVar(*o);      tof_track = new ToFTrkVar(*o);
430    if (r)    if (r)
431      orb_track = new OrbitalInfoTrkVar(*r);      orb_track = new OrbitalInfoTrkVar(*r);
432    
433    candeleteobj = 1;    candeleteobj = 1;
434      pscore = 0;
435      iscore = 0;
436    
437    }
438    
439    void PamTrack::Copy( PamTrack& track) const {
440    
441        track.trk_track = trk_track;
442        track.trk_ext_track = trk_ext_track;
443        track.calo_track = calo_track;
444        track.tof_track = tof_track;
445        track.orb_track = orb_track;
446        
447        track.candeleteobj = candeleteobj;
448        track.pscore = pscore;
449        track.iscore = iscore;
450        
451  }  }
 void PamTrack::Clear() {  
452    
453    //    cout << "PamTrack::Clear() "<<candeleteobj<<endl;  
454    
455    void PamTrack::Clear(Option_t *option) {
456    
457    //    cout << "PamTrack::Clear( "<<option<<" ) "<<candeleteobj<<endl;
458    if (candeleteobj) {    if (candeleteobj) {
459          
460        if (trk_ext_track)
461          trk_ext_track->ExtTrack::Clear(option);
462      if (trk_track)      if (trk_track)
463        trk_track->TrkTrack::Clear();        trk_track->TrkTrack::Clear();
464      if (calo_track)      if (calo_track)
# Line 351  void PamTrack::Clear() { Line 469  void PamTrack::Clear() {
469        orb_track->OrbitalInfoTrkVar::Clear();//???        orb_track->OrbitalInfoTrkVar::Clear();//???
470    }    }
471    else {    else {
472        trk_ext_track = 0;
473      trk_track = 0;      trk_track = 0;
474      calo_track = 0;      calo_track = 0;
475      tof_track = 0;      tof_track = 0;
# Line 363  void PamTrack::Clear() { Line 482  void PamTrack::Clear() {
482  void PamTrack::Delete() {  void PamTrack::Delete() {
483    //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;    //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;
484    if (candeleteobj) {    if (candeleteobj) {
485        if (trk_ext_track) {
486    //      trk_ext_track->ExtTrack::Clear("C");//Clear is called for all the array elements
487            trk_ext_track->ExtTrack::Clear("C+C");//Clear is called for all the array elements passing option 'C'
488          delete trk_ext_track;
489        }
490      if (trk_track) {      if (trk_track) {
491        trk_track->TrkTrack::Clear();        trk_track->TrkTrack::Clear();
492        delete trk_track;        delete trk_track;
# Line 384  void PamTrack::Delete() { Line 508  void PamTrack::Delete() {
508      Clear();      Clear();
509    }    }
510  }  }
511    
512    
513    
514    
515  //--------------------------------------  //--------------------------------------
516  //  //
517  //  //
# Line 394  void PamTrack::Delete() { Line 522  void PamTrack::Delete() {
522  PamLevel2::PamLevel2() {  PamLevel2::PamLevel2() {
523    Initialize();    Initialize();
524  }  }
525  ;  
526    
527  /**  /**
528   * Constructor   * Constructor
# Line 417  PamLevel2::PamLevel2(TString ddir, TStri Line 545  PamLevel2::PamLevel2(TString ddir, TStri
545      GetPamTree(listf, detlist);      GetPamTree(listf, detlist);
546    if (listf)    if (listf)
547      GetRunTree(listf);      GetRunTree(listf);
548      SetMaxShift(-1);
549  }  }
550  ;  
551    
552  PamLevel2::PamLevel2(TString ddir, TList *llist, TString detlist) {  PamLevel2::PamLevel2(TString ddir, TList *llist, TString detlist) {
553    Initialize();    Initialize();
554    GetPamTree(llist, detlist);    GetPamTree(llist, detlist);
555    GetRunTree(llist);    GetRunTree(llist);
556      SetMaxShift(-1);
557  }  }
558  ;  
559  /**  /**
560   * Constructor   * Constructor
561   * @param ddir Name of directory where level2 files are stored.   * @param ddir Name of directory where level2 files are stored.
# Line 435  PamLevel2::PamLevel2(TString ddir, TList Line 565  PamLevel2::PamLevel2(TString ddir, TList
565   */   */
566  PamLevel2::PamLevel2(TString ddir, TString llist) {  PamLevel2::PamLevel2(TString ddir, TString llist) {
567    Initialize();    Initialize();
568    TList* listf = GetListOfLevel2Files(ddir, llist);    TList* listf = GetListOfLevel2Files(ddir, llist);
569      cout << "GetPamTree: "<<endl;
570    GetPamTree(listf, "");    GetPamTree(listf, "");
571      cout << "GetRunTree: "<<endl;
572    GetRunTree(listf);    GetRunTree(listf);
573      SetMaxShift(-1);
574  }  }
575  ;  
576    
577  void PamLevel2::Initialize() {  void PamLevel2::Initialize() {
578    
# Line 452  void PamLevel2::Initialize() { Line 585  void PamLevel2::Initialize() {
585    trkh_obj = 0;    trkh_obj = 0;
586    calo1_obj = 0;    calo1_obj = 0;
587    calo2_obj = 0;    calo2_obj = 0;
588    tof_obj = 0;    tof2_obj = 0;
589    trig_obj = 0;    trig_obj = 0;
590    s4_obj = 0;    s4_obj = 0;
591    nd_obj = 0;    nd_obj = 0;
592    ac_obj = 0;    ac_obj = 0;
593    orb_obj = 0;    orb2_obj = 0;
594    gp_obj = 0;    gp_obj = 0;
595    
596      extAlgFlag=0;
597    
598      trk_ext_obj     = 0;
599      trk_ext_nuc_obj = 0;
600      trk_nuc_obj     = 0;
601      
602      calo_ext_obj     = 0;
603      calo_ext_nuc_obj = 0;
604      calo_nuc_obj     = 0;
605      
606      tof_ext_obj     = 0;
607      tof_ext_nuc_obj = 0;
608      tof_nuc_obj     = 0;
609      
610      orb_ext_obj     = 0;
611      orb_ext_nuc_obj = 0;
612      orb_nuc_obj     = 0;
613    
614      trk2_nuc_obj  = 0;
615      calo2_nuc_obj = 0;
616      tof2_nuc_obj  = 0;
617      orb2_nuc_obj  = 0;
618    
619    
620    run_obj = 0;//new GL_RUN();    run_obj = 0;//new GL_RUN();
621    soft_obj = 0;// Emiliano    soft_obj = 0;// Emiliano
622      proc_obj = 0;// Emiliano
623    irun = -1LL;    irun = -1LL;
624    irunt = -1LL;    irunt = -1LL;
625      totrunentry = 0LL;
626      totrunentrymax = 0LL;
627      totrunentrymin = 0LL;
628    runfirstentry = 0LL;    runfirstentry = 0LL;
629    runlastentry = 0LL;    runlastentry = 0LL;
630    gltsync = 0; // Emiliano    gltsync = 0; // Emiliano
631      fUpdateRunInfo = true; // Emiliano
632      fUseDBinRunInfo = true; // Emiliano
633      fDiscarded = false; //EM
634      isSync = false; // by default assume that the level2 file(s) is(are) not sinchronized between L0/DB and L2, that is we miss some packets in L2 due to nested/DV-skipped events
635      il0entry = 0LL;
636      //  hasL0EE = true;
637    
638    l0_file = NULL;    l0_file = NULL;
639    l0_tree = NULL;    l0_tree = NULL;
# Line 474  void PamLevel2::Initialize() { Line 641  void PamLevel2::Initialize() {
641    dbc = 0;    dbc = 0;
642    
643    prevshift = 0;    prevshift = 0;
644    maxshift = 10; //EMILIANO    yprevshift = 0;
645      maxshift = 10; //EMILIANO now overridden by SetMaxShift(-1) called by constructors
646    
647    run_tree = NULL;    run_tree = NULL;
648    run_tree_clone = NULL;    run_tree_clone = NULL;
649    
650      proc_tree = NULL;
651      proc_tree_clone = NULL;
652    
653    sel_tree = NULL;    sel_tree = NULL;
654    sel_tree_clone = NULL;    sel_tree_clone = NULL;
655    
# Line 509  void PamLevel2::Initialize() { Line 681  void PamLevel2::Initialize() {
681    if (strcmp(pamdbpsw, ""))    if (strcmp(pamdbpsw, ""))
682      psw = pamdbpsw;      psw = pamdbpsw;
683    
684      customString = "";
685    
686    //    sorted_tracks = 0;//new TRefArray();    //    sorted_tracks = 0;//new TRefArray();
687    
688    CAL0 = false;    CAL0 = false;
# Line 525  void PamLevel2::Initialize() { Line 699  void PamLevel2::Initialize() {
699    ND = true;    ND = true;
700    AC = true;    AC = true;
701    ORB = true;    ORB = true;
702      PROC = true;
703    GP = false;    GP = false;
704    
705      EXT = false;
706      NUC = false;
707      trkAlg = "STD";//default tracking algorythm
708    
709    RUN = true;    RUN = true;
710    
711    SELLI = -1;    SELLI = -1;
# Line 537  void PamLevel2::Initialize() { Line 716  void PamLevel2::Initialize() {
716    
717    tsorted = 0;    tsorted = 0;
718    timage = 0;    timage = 0;
719      text = 0 ;
720    
721      tsorted_nuc = 0;
722      timage_nuc = 0;
723      text_nuc = 0 ;
724    
725    howtosort = "+CAL+TOF";    howtosort = "+CAL+TOF";
726    //howtosort = "+TOF";    //howtosort = "+TOF";
# Line 544  void PamLevel2::Initialize() { Line 728  void PamLevel2::Initialize() {
728    
729    issorted = false;    issorted = false;
730    lastsorted = -1;    lastsorted = -1;
731      issorted_new = false;
732      lastsorted_new = -1;
733    
734  }  }
735  ;  ;
# Line 556  void PamLevel2::Delete() { Line 742  void PamLevel2::Delete() {
742      delete run_obj;      delete run_obj;
743    if (soft_obj)    if (soft_obj)
744      delete soft_obj; //Emiliano      delete soft_obj; //Emiliano
745      if (proc_obj)
746        delete proc_obj; //Emiliano
747    
748    //    cout << "void PamLevel2::Clear()"<<endl;    //    cout << "void PamLevel2::Clear()"<<endl;
749    if (h0_obj)    if (h0_obj)
# Line 574  void PamLevel2::Delete() { Line 762  void PamLevel2::Delete() {
762      delete calo1_obj;      delete calo1_obj;
763    if (calo2_obj)    if (calo2_obj)
764      delete calo2_obj;      delete calo2_obj;
765    if (tof_obj)    if (tof2_obj)
766      delete tof_obj;      delete tof2_obj;
767    if (trig_obj)    if (trig_obj)
768      delete trig_obj;      delete trig_obj;
769    if (s4_obj)    if (s4_obj)
# Line 584  void PamLevel2::Delete() { Line 772  void PamLevel2::Delete() {
772      delete nd_obj;      delete nd_obj;
773    if (ac_obj)    if (ac_obj)
774      delete ac_obj;      delete ac_obj;
775    if (orb_obj)    if (orb2_obj)
776      delete orb_obj;      delete orb2_obj;
777    if (gp_obj)    if (gp_obj)
778      delete gp_obj;      delete gp_obj;
779    
780      if(trk_nuc_obj)trk_nuc_obj->Delete();
781      if(trk_ext_obj)trk_ext_obj->Delete();
782      if(trk_ext_nuc_obj)trk_ext_nuc_obj->Delete();
783    
784      if(calo_nuc_obj)calo_nuc_obj->Delete();
785      if(calo_ext_obj)calo_ext_obj->Delete();
786      if(calo_ext_nuc_obj)calo_ext_nuc_obj->Delete();
787    
788      if(tof_nuc_obj)tof_nuc_obj->Delete();
789      if(tof_ext_obj)tof_ext_obj->Delete();
790      if(tof_ext_nuc_obj)tof_ext_nuc_obj->Delete();
791    
792      if(orb_nuc_obj)orb_nuc_obj->Delete();
793      if(orb_ext_obj)orb_ext_obj->Delete();
794      if(orb_ext_nuc_obj)orb_ext_nuc_obj->Delete();
795    
796    
797      if(trk2_nuc_obj)trk2_nuc_obj->Delete();;
798      if( calo2_nuc_obj)calo2_nuc_obj->Delete();;
799      if(tof2_nuc_obj)tof2_nuc_obj->Delete();;
800      if(orb2_nuc_obj)orb2_nuc_obj->Delete();;
801      
802    
803    
804    if (tsorted) {    if (tsorted) {
805      tsorted->Delete();      tsorted->Delete();
806      delete tsorted;      delete tsorted;
# Line 597  void PamLevel2::Delete() { Line 809  void PamLevel2::Delete() {
809      timage->Delete();      timage->Delete();
810      delete timage;      delete timage;
811    }    }
812      if (text) {
813        text->Delete();
814        delete text;
815      }
816      if (tsorted_nuc) {
817        tsorted_nuc->Delete();
818        delete tsorted_nuc;
819      }
820      if (timage_nuc) {
821        timage_nuc->Delete();
822        delete timage_nuc;
823      }
824      if (text_nuc) {
825        text_nuc->Delete();
826        delete text_nuc;
827      }
828    
829    
830    
831    if (dbc) {    if (dbc) {
832      dbc->Close();      dbc->Close();
# Line 633  void PamLevel2::Delete() { Line 863  void PamLevel2::Delete() {
863      //      //
864      TIter next2(contents);      TIter next2(contents);
865      TChain *questa = 0;      TChain *questa = 0;
866      while (questa = (TChain*) next2()) {      while ( (questa = (TChain*)next2()) ) {
867        TString name = questa->GetName();        TString name = questa->GetName();
868        questa->Delete();        questa->Delete();
869        questa = NULL;        questa = NULL;
# Line 646  void PamLevel2::Delete() { Line 876  void PamLevel2::Delete() {
876      run_tree->Delete();;      run_tree->Delete();;
877    if (sel_tree)    if (sel_tree)
878      sel_tree->Delete();;      sel_tree->Delete();;
879    for (Int_t i = 0; i < NCLONES; i++)  
880      // The following lines are commented out since they may generate a double delete error
881      // if the file containing the clone trees is closed. This is because the file owns the
882      // clone trees which are written into it, so it will delete them when it is closed; if
883      // also PamLevel2 will try to delete these trees, a double delete error will be generated
884      // when exiting from analysis program. (Nicola 28/11/2011)
885    
886      /*for (Int_t i = 0; i < NCLONES; i++)
887      if (pam_tree_clone[i])      if (pam_tree_clone[i])
888        pam_tree_clone[i]->Delete();;        pam_tree_clone[i]->Delete();;
889    if (run_tree_clone)    if (run_tree_clone)
890      run_tree_clone->Delete();;      run_tree_clone->Delete();;
891    if (sel_tree_clone)    if (sel_tree_clone)
892      sel_tree_clone->Delete();;      sel_tree_clone->Delete();;*/
893    
894    if (irunoffset)    if (irunoffset)
895      delete[] irunoffset;      delete[] irunoffset;
896    
897    
898      Initialize();
899    
900  }  }
901  ;  ;
902    
# Line 690  void PamLevel2::Clear() { Line 930  void PamLevel2::Clear() {
930      calo1_obj->Clear();      calo1_obj->Clear();
931    if (calo2_obj)    if (calo2_obj)
932      calo2_obj->Clear();      calo2_obj->Clear();
933    if (tof_obj)    if (tof2_obj)
934      tof_obj->Clear();      tof2_obj->Clear();
935    if (trig_obj)    if (trig_obj)
936      trig_obj->Clear();      trig_obj->Clear();
937    if (s4_obj)    if (s4_obj)
# Line 700  void PamLevel2::Clear() { Line 940  void PamLevel2::Clear() {
940      nd_obj->Clear();      nd_obj->Clear();
941    if (ac_obj)    if (ac_obj)
942      ac_obj->Clear();      ac_obj->Clear();
943    if (orb_obj)    if (orb2_obj)
944      orb_obj->Clear();      orb2_obj->Clear();
945    if (gp_obj)    if (gp_obj)
946      gp_obj->Clear();      gp_obj->Clear();
947      if (proc_obj)
948        proc_obj->Clear();
949    
950    //    if(sorted_tracks)sorted_tracks->Clear();    //    if(sorted_tracks)sorted_tracks->Clear();
951    //    sorted_tracks.Clear();    //    sorted_tracks.Clear();
952    
953    if (tsorted) {    if(trk_nuc_obj)trk_nuc_obj->Clear();
954      tsorted->Delete();    if(trk_ext_obj)trk_ext_obj->Clear();
955    }    if(trk_ext_nuc_obj)trk_ext_nuc_obj->Clear();
956    if (timage) {  
957      timage->Delete();    if(calo_nuc_obj)calo_nuc_obj->Clear();
958    }    if(calo_ext_obj)calo_ext_obj->Clear();
959      if(calo_ext_nuc_obj)calo_ext_nuc_obj->Clear();
960    
961      if(tof_nuc_obj)tof_nuc_obj->Clear();
962      if(tof_ext_obj)tof_ext_obj->Clear();
963      if(tof_ext_nuc_obj)tof_ext_nuc_obj->Clear();
964    
965      if(orb_nuc_obj)orb_nuc_obj->Clear();
966      if(orb_ext_obj)orb_ext_obj->Clear();
967      if(orb_ext_nuc_obj)orb_ext_nuc_obj->Clear();
968    
969      if(trk2_nuc_obj)trk2_nuc_obj->Clear();;
970      if( calo2_nuc_obj)calo2_nuc_obj->Clear();;
971      if(tof2_nuc_obj)tof2_nuc_obj->Clear();;
972      if(orb2_nuc_obj)orb2_nuc_obj->Clear();;
973    
974      if (tsorted)tsorted->Delete();
975      if (timage)timage->Delete();
976      if (text) text->Delete();
977    
978      if (tsorted_nuc)tsorted_nuc->Delete();
979      if (timage_nuc)timage_nuc->Delete();
980      if (text_nuc) text_nuc->Delete();
981  }  }
982  ;  ;
983    
# Line 747  void PamLevel2::Reset() { Line 1011  void PamLevel2::Reset() {
1011      //      //
1012      TIter next2(contents);      TIter next2(contents);
1013      TChain *questa = 0;      TChain *questa = 0;
1014      while (questa = (TChain*) next2()) {      while ( (questa = (TChain*) next2()) ) {
1015        TString name = questa->GetName();        TString name = questa->GetName();
1016        questa->Delete();        questa->Delete();
1017        questa = NULL;        questa = NULL;
# Line 762  void PamLevel2::Reset() { Line 1026  void PamLevel2::Reset() {
1026    if (sel_tree)    if (sel_tree)
1027      sel_tree->Delete();;      sel_tree->Delete();;
1028    sel_tree = NULL;    sel_tree = NULL;
1029    
1030      if (proc_tree)
1031        proc_tree->Delete();
1032      proc_tree = NULL;
1033    //    //
1034    // Close file    // Close file
1035    //    //
# Line 778  void PamLevel2::Reset() { Line 1046  void PamLevel2::Reset() {
1046    trkh_obj = 0;    trkh_obj = 0;
1047    calo1_obj = 0;    calo1_obj = 0;
1048    calo2_obj = 0;    calo2_obj = 0;
1049    tof_obj = 0;    tof2_obj = 0;
1050    trig_obj = 0;    trig_obj = 0;
1051    s4_obj = 0;    s4_obj = 0;
1052    nd_obj = 0;    nd_obj = 0;
1053    ac_obj = 0;    ac_obj = 0;
1054    orb_obj = 0;    orb2_obj = 0;
1055    gp_obj = 0;    gp_obj = 0;
1056      proc_obj = 0;
1057    
1058      trk_ext_obj     = 0;
1059      trk_ext_nuc_obj = 0;
1060      trk_nuc_obj     = 0;
1061      
1062      calo_ext_obj     = 0;
1063      calo_ext_nuc_obj = 0;
1064      calo_nuc_obj     = 0;
1065      
1066      tof_ext_obj     = 0;
1067      tof_ext_nuc_obj = 0;
1068      tof_nuc_obj     = 0;
1069      
1070      orb_ext_obj     = 0;
1071      orb_ext_nuc_obj = 0;
1072      orb_nuc_obj     = 0;
1073    
1074      trk2_nuc_obj  = 0;
1075      calo2_nuc_obj = 0;
1076      tof2_nuc_obj  = 0;
1077      orb2_nuc_obj  = 0;
1078    
1079      trk2_nuc_obj  = 0;
1080      calo2_nuc_obj = 0;
1081      tof2_nuc_obj  = 0;
1082      orb2_nuc_obj  = 0;
1083    //    //
1084    // Reset run pointers    // Reset run pointers
1085    //    //
1086    run_obj = 0;//new GL_RUN();    run_obj = 0;//new GL_RUN();
1087    soft_obj = 0;// Emiliano    soft_obj = 0;// Emiliano
1088      proc_obj = 0;// Emiliano
1089    irun = -1;    irun = -1;
1090    irunt = -1;    irunt = -1;
1091      totrunentry = 0LL;
1092      totrunentrymax = 0LL;
1093      totrunentrymin = 0LL;
1094    runfirstentry = 0ULL;    runfirstentry = 0ULL;
1095    runlastentry = 0ULL;    runlastentry = 0ULL;
1096      prevabstime = 0ULL;
1097      prevpktnum = 0;
1098      abstime = 0ULL;
1099      pktnum = 0;
1100      isFragment = false;
1101    //    //
1102    totdltime[0] = 0LL;    totdltime[0] = 0LL;
1103    totdltime[1] = 0LL;    totdltime[1] = 0LL;
# Line 811  Bool_t PamLevel2::IsGood(Bool_t strict) Line 1115  Bool_t PamLevel2::IsGood(Bool_t strict)
1115    if (strict) {    if (strict) {
1116      if (trk2_obj && trk2_obj->UnpackError() != 0)      if (trk2_obj && trk2_obj->UnpackError() != 0)
1117        goodev = false;        goodev = false;
1118      if (tof_obj && tof_obj->unpackError != 0)      if (tof2_obj && tof2_obj->unpackError != 0)
1119        goodev = false;        goodev = false;
1120      if (trig_obj && trig_obj->unpackError != 0)      if (trig_obj && trig_obj->unpackError != 0)
1121        goodev = false;        goodev = false;
# Line 821  Bool_t PamLevel2::IsGood(Bool_t strict) Line 1125  Bool_t PamLevel2::IsGood(Bool_t strict)
1125        goodev = false;        goodev = false;
1126      if (ac_obj && (ac_obj->unpackError != 0 || ((ac_obj->status[0] >> 2) & 1) || ((ac_obj->status[1] >> 2) & 1)))      if (ac_obj && (ac_obj->unpackError != 0 || ((ac_obj->status[0] >> 2) & 1) || ((ac_obj->status[1] >> 2) & 1)))
1127        goodev = false;        goodev = false;
1128      //  if(orb_obj)      //  if(orb2_obj)
1129    }    }
1130    else {    else {
1131      if (nd_obj && nd_obj->unpackError != 0)      if (nd_obj && nd_obj->unpackError != 0)
# Line 833  Bool_t PamLevel2::IsGood(Bool_t strict) Line 1137  Bool_t PamLevel2::IsGood(Bool_t strict)
1137  }  }
1138  ;  ;
1139    
1140    void PamLevel2::SkipRunInfoUpdate(){
1141      printf("\n\n ******** WARNING ******** \n Skip DB connections, DO NOT USE PamLevel2::GetRunInfo() method! \n\n");
1142      fUpdateRunInfo = false;
1143      this->SetSELLI(2);
1144      printf(" ===============> W A R N I N G <================ \n");
1145      printf(" in case PamLevel2::CreateCloneTrees() will be called \n");
1146      printf(" it will be reverted to PadmeAmidala level2 structure , i.e. NO SELECTIONLIST WILL BE CREATED IN THE NEW LEVEL2 FILE! \n\n");
1147      if ( run_tree_clone ){
1148        printf(" ===============> W A R N I N G <================ \n");
1149        printf(" PamLevel2::SkipRunIndoUpdate or PamLevel2::NoDBconnections() has been called together with PamLevel2::CreateCloneTrees() \n");
1150        printf(" TO AVOID CRASHES call PamLevel2::CreateCloneTrees() after PamLevel2::SkipRunIndoUpdate or PamLevel2::NoDBconnections() \n");    
1151      };
1152    }
1153    
1154    void PamLevel2::SetMaxShift(Int_t sh){
1155      if ( sh >=  0 ){
1156        printf("PamLevel2::SetMaxShift(Int_t) --WARNING-- the default is optimized by checking the level2 file\n it is strongly suggested to let PamLevel2 choose the max shift!\n");
1157        maxshift = sh;
1158      } else {
1159        ULong64_t nev = GetEntries();
1160        ULong64_t runnev = 0ULL;
1161        for (Int_t r=0; r< run_tree->GetEntries();r++){
1162          run_tree->GetEntry(r);//update runinfo
1163          runnev += GetRunInfo()->NEVENTS;
1164        }
1165        maxshift = (Int_t)(runnev-nev) + 10; // +10 just to be conservative
1166        if ( (runnev-nev) == 0 ) isSync = true;
1167        if (DBG) printf("PamLevel2::SetMaxShift(Int_t_) - sh negative %i - nev is %lld runnnev is %lld so maxshift set to %i \n",sh,nev,runnev,maxshift);
1168        //    printf("PamLevel2::SetMaxShift(Int_t_) - sh negative %i - nev is %lld runnnev is %lld so maxshift set to %i \n",sh,nev,runnev,maxshift); // TOGLITOGLI
1169      }
1170    }
1171    
1172  //--------------------------------------  //--------------------------------------
1173  //  //
1174  //  //
# Line 875  void *PamLevel2::GetPointerTo(const char Line 1211  void *PamLevel2::GetPointerTo(const char
1211      return &calo2_obj;      return &calo2_obj;
1212    };    };
1213    if (!objname.CompareTo("ToFLevel2")) {    if (!objname.CompareTo("ToFLevel2")) {
1214      if (!tof_obj) {      if (!tof2_obj) {
1215        tof_obj = new ToFLevel2();        tof2_obj = new ToFLevel2();
1216        tof_obj->Set();        tof2_obj->Set();
1217      }      }
1218      return &tof_obj;      return &tof2_obj;
1219    };    };
1220    if (!objname.CompareTo("TrigLevel2")) {    if (!objname.CompareTo("TrigLevel2")) {
1221      if (!trig_obj)      if (!trig_obj)
# Line 902  void *PamLevel2::GetPointerTo(const char Line 1238  void *PamLevel2::GetPointerTo(const char
1238      return &ac_obj;      return &ac_obj;
1239    };    };
1240    if (!objname.CompareTo("OrbitalInfo")) {    if (!objname.CompareTo("OrbitalInfo")) {
1241      if (!orb_obj) {      if (!orb2_obj) {
1242        orb_obj = new OrbitalInfo();        orb2_obj = new OrbitalInfo();
1243        orb_obj->Set();        orb2_obj->Set();
1244      }      }
1245      return &orb_obj;      return &orb2_obj;
1246    };    };
1247    //     if(!objname.CompareTo("OrbitalInfo")){    //     if(!objname.CompareTo("OrbitalInfo")){
1248    //    if(!orb_obj)   orb_obj   = new OrbitalInfo();    //    if(!orb2_obj)   orb2_obj   = new OrbitalInfo();
1249    //    return &orb_obj;    //    return &orb2_obj;
1250    //     };    //     };
1251    if (!objname.CompareTo("GPamela")) {    if (!objname.CompareTo("GPamela")) {
1252      if (!gp_obj)      if (!gp_obj)
# Line 924  void *PamLevel2::GetPointerTo(const char Line 1260  void *PamLevel2::GetPointerTo(const char
1260    if (!objname.CompareTo("SoftInfo"))    if (!objname.CompareTo("SoftInfo"))
1261      return &soft_obj; // Emiliano      return &soft_obj; // Emiliano
1262    
1263      if (!objname.CompareTo("ProcInfo")){
1264        if (!proc_obj)
1265          proc_obj = new ProcInfo();    
1266        return &proc_obj; // Emiliano
1267      }
1268    
1269    return NULL;    return NULL;
1270  }  }
1271  ;  ;
# Line 941  CaloTrkVar *PamLevel2::GetCaloStoredTrac Line 1283  CaloTrkVar *PamLevel2::GetCaloStoredTrac
1283      return 0;      return 0;
1284    
1285    if (calo2_obj->CaloLevel2::ntrk() == 0) {    if (calo2_obj->CaloLevel2::ntrk() == 0) {
1286      cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo " << seqno        if( seqno >=0 ){
1287          << " but no Calorimeter tracks are stored" << endl;            cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo " << seqno;
1288      return NULL;            cout << " but no Calorimeter tracks are stored" << endl;
1289          }
1290          return NULL;
1291    };    };
1292    
1293    CaloTrkVar *c = 0;    CaloTrkVar *c = 0;
# Line 956  CaloTrkVar *PamLevel2::GetCaloStoredTrac Line 1300  CaloTrkVar *PamLevel2::GetCaloStoredTrac
1300    
1301    if (!c || seqno != c->trkseqno) {    if (!c || seqno != c->trkseqno) {
1302      c = 0;      c = 0;
1303      if (seqno != -1)      if (seqno != -1 && seqno>=0)
1304        cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo " << seqno        cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo " << seqno
1305            << " does not match Calorimeter stored tracks" << endl;            << " does not match Calorimeter stored tracks" << endl;
1306    };    };
# Line 974  CaloTrkVar *PamLevel2::GetCaloStoredTrac Line 1318  CaloTrkVar *PamLevel2::GetCaloStoredTrac
1318   */   */
1319  ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno) {  ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno) {
1320    
1321    if (!tof_obj)    if (!tof2_obj)
1322      return 0;      return 0;
1323    
1324    if (tof_obj->ToFLevel2::ntrk() == 0) {    if (tof2_obj->ToFLevel2::ntrk() == 0) {
1325      cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo " << seqno << " but no ToF tracks are stored"      cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo " << seqno << " but no ToF tracks are stored"
1326          << endl;          << endl;
1327      return NULL;      return NULL;
# Line 987  ToFTrkVar *PamLevel2::GetToFStoredTrack( Line 1331  ToFTrkVar *PamLevel2::GetToFStoredTrack(
1331    Int_t it_tof = 0;    Int_t it_tof = 0;
1332    
1333    do {    do {
1334      c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);      c = tof2_obj->ToFLevel2::GetToFTrkVar(it_tof);
1335      it_tof++;      it_tof++;
1336    } while (c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());    } while (c && seqno != c->trkseqno && it_tof < tof2_obj->ToFLevel2::ntrk());
1337    
1338    if (!c || seqno != c->trkseqno) {    if (!c || seqno != c->trkseqno) {
1339      c = 0;      c = 0;
# Line 1012  ToFTrkVar *PamLevel2::GetToFStoredTrack( Line 1356  ToFTrkVar *PamLevel2::GetToFStoredTrack(
1356   */   */
1357  OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno) {  OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno) {
1358    
1359    if (!orb_obj)    if (!orb2_obj)
1360      return 0;      return 0;
1361    
1362    if (orb_obj->OrbitalInfo::ntrk() == 0) {    if (orb2_obj->OrbitalInfo::ntrk() == 0) {
1363      //       // TRICK BEGIN      //       // TRICK BEGIN
1364      //       OrbitalInfoTrkVar  *r = new OrbitalInfoTrkVar(); // TEMPORARY TRICK      //       OrbitalInfoTrkVar  *r = new OrbitalInfoTrkVar(); // TEMPORARY TRICK
1365      //       Int_t nn = 0;      //       Int_t nn = 0;
1366      //       TClonesArray &tor = *orb_obj->OrbitalInfoTrk;      //       TClonesArray &tor = *orb2_obj->OrbitalInfoTrk;
1367      //       for(Int_t nt=0; nt < tof_obj->ToFLevel2::ntrk(); nt++){      //       for(Int_t nt=0; nt < tof2_obj->ToFLevel2::ntrk(); nt++){
1368      //  //      //  //
1369      //  ToFTrkVar *ptt = tof_obj->ToFLevel2::GetToFTrkVar(nt);      //  ToFTrkVar *ptt = tof2_obj->ToFLevel2::GetToFTrkVar(nt);
1370      //  if ( ptt->trkseqno != -1  ){      //  if ( ptt->trkseqno != -1  ){
1371      //    //      //    //
1372      //    r->trkseqno = ptt->trkseqno;      //    r->trkseqno = ptt->trkseqno;
# Line 1044  OrbitalInfoTrkVar *PamLevel2::GetOrbital Line 1388  OrbitalInfoTrkVar *PamLevel2::GetOrbital
1388      //       };      //       };
1389      //       delete r;      //       delete r;
1390      //       OrbitalInfoTrkVar *c = 0;      //       OrbitalInfoTrkVar *c = 0;
1391      //       c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(0);      //       c = orb2_obj->OrbitalInfo::GetOrbitalInfoTrkVar(0);
1392      //       return c;      //       return c;
1393      //       //TRICK END      //       //TRICK END
1394      cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo " << seqno      cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo " << seqno
# Line 1056  OrbitalInfoTrkVar *PamLevel2::GetOrbital Line 1400  OrbitalInfoTrkVar *PamLevel2::GetOrbital
1400    Int_t it_tof = 0;    Int_t it_tof = 0;
1401    
1402    do {    do {
1403      c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);      c = orb2_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);
1404      it_tof++;      it_tof++;
1405    } while (c && seqno != c->trkseqno && it_tof < orb_obj->OrbitalInfo::ntrk());    } while (c && seqno != c->trkseqno && it_tof < orb2_obj->OrbitalInfo::ntrk());
1406    
1407    if (!c || seqno != c->trkseqno) {    if (!c || seqno != c->trkseqno) {
1408      c = 0;      c = 0;
# Line 1075  OrbitalInfoTrkVar *PamLevel2::GetOrbital Line 1419  OrbitalInfoTrkVar *PamLevel2::GetOrbital
1419  //  //
1420  //  //
1421  //--------------------------------------  //--------------------------------------
1422  /**  // /**
1423   * Give the pamela track associated to a tracker track, retrieving related calorimeter, orbitalinfo and tof track information.  //  * Give the pamela track associated to a tracker track, retrieving related calorimeter, orbitalinfo and tof track information.
1424   */  //  */
1425  PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t) {  // PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t) {
1426    
1427    cout << "PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** " << endl;  //   cout << "PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** " << endl;
1428    cout << "(if you use it, remember to delete the PamTrack object)" << endl;  //   cout << "(if you use it, remember to delete the PamTrack object)" << endl;
1429    
1430    CaloTrkVar *c = 0;  //   CaloTrkVar *c = 0;
1431    ToFTrkVar *o = 0;  //   ToFTrkVar *o = 0;
1432    OrbitalInfoTrkVar *r = 0;  //   OrbitalInfoTrkVar *r = 0;
1433    
1434    if (CAL2)  //   if (CAL2)
1435      c = GetCaloStoredTrack(t->GetSeqNo());  //     c = GetCaloStoredTrack(t->GetSeqNo());
1436    if (TOF)  //   if (TOF)
1437      o = GetToFStoredTrack(t->GetSeqNo());  //     o = GetToFStoredTrack(t->GetSeqNo());
1438    if (ORB)  //   if (ORB)
1439      r = GetOrbitalInfoStoredTrack(t->GetSeqNo());  //     r = GetOrbitalInfoStoredTrack(t->GetSeqNo());
1440    
1441    //    if(t && c && o)track = new PamTrack(t,c,o);  //   //    if(t && c && o)track = new PamTrack(t,c,o);
1442    PamTrack *track = new PamTrack(t, c, o, r);  //   PamTrack *track = new PamTrack(t, c, o, r);
1443    
1444    return track;  //   return track;
1445    
1446  }  // }
1447  ;  // ;
1448  //--------------------------------------  //--------------------------------------
1449  //  //
1450  //  //
1451  //--------------------------------------  //--------------------------------------
1452  /**  // /**
1453   * Retrieves the it-th stored track.  //  * Retrieves the it-th stored track.
1454   * It override TrkLevel2::GetTrack(int it).  //  * It override TrkLevel2::GetTrack(int it).
1455   * @param itrk Track number, ranging from 0 to GetNTracks().  //  * @param itrk Track number, ranging from 0 to GetNTracks().
1456   */  //  */
1457    
1458  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk) {  // PamTrack* PamLevel2::GetStoredTrack(Int_t itrk) {
1459    
1460    cout << "PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** " << endl;  //   cout << "PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** " << endl;
1461    cout  //   cout
1462        << "for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack) OrbitalInfo::GetOrbitalInfoTrkVar(Int_t notrack)"  //       << "for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack) OrbitalInfo::GetOrbitalInfoTrkVar(Int_t notrack)"
1463        << endl;  //       << endl;
1464    cout << "(if you use it, remember to delete the PamTrack object)" << endl;  //   cout << "(if you use it, remember to delete the PamTrack object)" << endl;
1465    PamTrack *track = 0;  //   PamTrack *track = 0;
1466    
1467    if (itrk >= 0 && itrk < trk2_obj->TrkLevel2::ntrk()) {  //   if (itrk >= 0 && itrk < trk2_obj->TrkLevel2::ntrk()) {
1468    
1469      TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk);  //     TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk);
1470      track = GetPamTrackAlong(t);  //     track = GetPamTrackAlong(t);
1471    
1472    }  //   }
1473    else {  //   else {
1474      cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo " << itrk << " does not exist (GetNTracks() = "  //     cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo " << itrk << " does not exist (GetNTracks() = "
1475          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;  //         << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
1476    };  //   };
1477    
1478    return track;  //   return track;
1479    
1480  }  // }
1481  //--------------------------------------  //--------------------------------------
1482  //  //
1483    
# Line 1187  void PamLevel2::SortTracks() { Line 1531  void PamLevel2::SortTracks() {
1531    Int_t ObjectNumber = TProcessID::GetObjectCount();    Int_t ObjectNumber = TProcessID::GetObjectCount();
1532    
1533    // create TCloneArrays to store tracks and its images    // create TCloneArrays to store tracks and its images
1534    if (!tsorted)  //   if (!tsorted)
1535      tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());  //     tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1536    tsorted->Delete();  //   tsorted->Clear("C+C");//Delete();
1537    TClonesArray &ttsorted = *tsorted;  //   if (!timage)
1538    //     timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1539    //   timage->Clear("C+C");//Delete();
1540    
1541      if(tsorted)delete tsorted;
1542      if(timage) delete timage;
1543      tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1544      timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1545    
1546    if (!timage)  
1547      timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());    TClonesArray &ttsorted = *tsorted;
   timage->Delete();  
1548    TClonesArray &ttimage = *timage;    TClonesArray &ttimage = *timage;
1549    
1550    
1551    
1552    //--------------------------------------------------    //--------------------------------------------------
1553    // retrieve sorting method    // retrieve sorting method
1554    //--------------------------------------------------    //--------------------------------------------------
# Line 1312  void PamLevel2::SortTracks() { Line 1664  void PamLevel2::SortTracks() {
1664        // -----------------------------------------------------------------------------------------        // -----------------------------------------------------------------------------------------
1665        // check the number of hit pmts along the track        // check the number of hit pmts along the track
1666        // on S12 S21 and S32, where paddles are parallel to Y axis        // on S12 S21 and S32, where paddles are parallel to Y axis
1667        if ((use_TOF || use_S1 || use_S2 || use_S3) && !tof_obj) {        if ((use_TOF || use_S1 || use_S2 || use_S3) && !tof2_obj) {
1668          cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but ToFLevel2 not loaded !!!";          cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but ToFLevel2 not loaded !!!";
1669          return;          return;
1670        };        };
# Line 1329  void PamLevel2::SortTracks() { Line 1681  void PamLevel2::SortTracks() {
1681          //          //
1682          Float_t sen = 0.;          Float_t sen = 0.;
1683          for (Int_t ih = 0; ih < op->npmtadc; ih++) {          for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1684            Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));            Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1685            if (pl == 2 || pl == 3 || pl == 4 || pl == 5)            if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
1686              sen += (op->dedx).At(ih);              sen += (op->dedx).At(ih);
1687          };          };
1688          for (Int_t ih = 0; ih < oi->npmtadc; ih++) {          for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1689            Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));            Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1690            if (pl == 2 || pl == 3 || pl == 4 || pl == 5)            if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
1691              sen += (oi->dedx).At(ih);              sen += (oi->dedx).At(ih);
1692          };          };
# Line 1347  void PamLevel2::SortTracks() { Line 1699  void PamLevel2::SortTracks() {
1699            Int_t nz = 6;            Int_t nz = 6;
1700            Float_t zin[6]; // << define TOF z-coordinates            Float_t zin[6]; // << define TOF z-coordinates
1701            for (Int_t ip = 0; ip < nz; ip++)            for (Int_t ip = 0; ip < nz; ip++)
1702              zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip)); // << read ToF plane z-coordinates              zin[ip] = tof2_obj->ToFLevel2::GetZTOF(tof2_obj->ToFLevel2::GetToFPlaneID(ip)); // << read ToF plane z-coordinates
1703            Trajectory *tr = new Trajectory(nz, zin);            Trajectory *tr = new Trajectory(nz, zin);
1704            //            //
1705            Int_t nphit_p = 0;            Int_t nphit_p = 0;
# Line 1356  void PamLevel2::SortTracks() { Line 1708  void PamLevel2::SortTracks() {
1708            Float_t enhit_i = 0.;            Float_t enhit_i = 0.;
1709            //            //
1710            for (Int_t ih = 0; ih < op->npmtadc; ih++) {            for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1711              Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));              Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1712              if (pl == 1 || pl == 2 || pl == 5) {              if (pl == 1 || pl == 2 || pl == 5) {
1713                nphit_p++;                nphit_p++;
1714                enhit_p += (op->dedx).At(ih);                enhit_p += (op->dedx).At(ih);
# Line 1367  void PamLevel2::SortTracks() { Line 1719  void PamLevel2::SortTracks() {
1719            //            //
1720            if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {            if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
1721              for (Int_t ih = 0; ih < op->npmtadc; ih++) {              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1722                Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1723                if (pl == 0) {                if (pl == 0) {
1724                  nphit_p++;                  nphit_p++;
1725                  enhit_p += (op->dedx).At(ih);                  enhit_p += (op->dedx).At(ih);
# Line 1376  void PamLevel2::SortTracks() { Line 1728  void PamLevel2::SortTracks() {
1728            };            };
1729            if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {            if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
1730              for (Int_t ih = 0; ih < op->npmtadc; ih++) {              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1731                Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1732                if (pl == 3) {                if (pl == 3) {
1733                  nphit_p++;                  nphit_p++;
1734                  enhit_p += (op->dedx).At(ih);                  enhit_p += (op->dedx).At(ih);
# Line 1385  void PamLevel2::SortTracks() { Line 1737  void PamLevel2::SortTracks() {
1737            };            };
1738            if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {            if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
1739              for (Int_t ih = 0; ih < op->npmtadc; ih++) {              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1740                Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1741                if (pl == 4) {                if (pl == 4) {
1742                  nphit_p++;                  nphit_p++;
1743                  enhit_p += (op->dedx).At(ih);                  enhit_p += (op->dedx).At(ih);
# Line 1394  void PamLevel2::SortTracks() { Line 1746  void PamLevel2::SortTracks() {
1746            };            };
1747    
1748            for (Int_t ih = 0; ih < oi->npmtadc; ih++) {            for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1749              Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));              Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1750              if (pl == 1 || pl == 2 || pl == 5) {              if (pl == 1 || pl == 2 || pl == 5) {
1751                nphit_i++;                nphit_i++;
1752                enhit_i += (op->dedx).At(ih);                enhit_i += (op->dedx).At(ih);
# Line 1405  void PamLevel2::SortTracks() { Line 1757  void PamLevel2::SortTracks() {
1757            //            //
1758            if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {            if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
1759              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1760                Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1761                if (pl == 0) {                if (pl == 0) {
1762                  nphit_i++;                  nphit_i++;
1763                  enhit_i += (op->dedx).At(ih);                  enhit_i += (op->dedx).At(ih);
# Line 1414  void PamLevel2::SortTracks() { Line 1766  void PamLevel2::SortTracks() {
1766            };            };
1767            if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {            if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
1768              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1769                Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1770                if (pl == 3) {                if (pl == 3) {
1771                  nphit_i++;                  nphit_i++;
1772                  enhit_i += (op->dedx).At(ih);                  enhit_i += (op->dedx).At(ih);
# Line 1423  void PamLevel2::SortTracks() { Line 1775  void PamLevel2::SortTracks() {
1775            };            };
1776            if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {            if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
1777              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1778                Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1779                if (pl == 4) {                if (pl == 4) {
1780                  nphit_i++;                  nphit_i++;
1781                  enhit_i += (op->dedx).At(ih);                  enhit_i += (op->dedx).At(ih);
# Line 1467  void PamLevel2::SortTracks() { Line 1819  void PamLevel2::SortTracks() {
1819             cout << "image: npmttdc "<< oi->npmttdc << endl;*/             cout << "image: npmttdc "<< oi->npmttdc << endl;*/
1820    
1821            //      for (Int_t ih=0; ih < op->npmtadc; ih++){            //      for (Int_t ih=0; ih < op->npmtadc; ih++){
1822            //        Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );            //        Int_t pl = tof2_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1823            //        if(pl == 1 || pl == 2 || pl == 5)nphit_p++;            //        if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
1824            //      };            //      };
1825    
1826            //      for (Int_t ih=0; ih < oi->npmtadc; ih++){            //      for (Int_t ih=0; ih < oi->npmtadc; ih++){
1827            //        Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );            //        Int_t pl = tof2_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1828            //        if(pl == 1 || pl == 2 || pl == 5)nphit_i++;            //        if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
1829            //      };            //      };
1830            // --- modified to count tdc signals (more efficient?)            // --- modified to count tdc signals (more efficient?)
1831            // --- and to implement check on tdcflag            // --- and to implement check on tdcflag
1832            for (Int_t ih = 0; ih < op->npmttdc; ih++) {            for (Int_t ih = 0; ih < op->npmttdc; ih++) {
1833              Int_t pl = tof_obj->GetPlaneIndex((op->pmttdc).At(ih));              Int_t pl = tof2_obj->GetPlaneIndex((op->pmttdc).At(ih));
1834              //      if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;              //      if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
1835              if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))              if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
1836                  || (use_S3 && (pl == 4 || pl == 5))) {                  || (use_S3 && (pl == 4 || pl == 5))) {
# Line 1488  void PamLevel2::SortTracks() { Line 1840  void PamLevel2::SortTracks() {
1840            };            };
1841    
1842            for (Int_t ih = 0; ih < oi->npmttdc; ih++) {            for (Int_t ih = 0; ih < oi->npmttdc; ih++) {
1843              Int_t pl = tof_obj->GetPlaneIndex((oi->pmttdc).At(ih));              Int_t pl = tof2_obj->GetPlaneIndex((oi->pmttdc).At(ih));
1844              //      if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;              //      if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;
1845              if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))              if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
1846                  || (use_S3 && (pl == 4 || pl == 5))) {                  || (use_S3 && (pl == 4 || pl == 5))) {
# Line 1634  void PamLevel2::SortTracks() { Line 1986  void PamLevel2::SortTracks() {
1986      //  cout<<"o "<<cp<<endl;      //  cout<<"o "<<cp<<endl;
1987      //  cout<<"o "<<op<<endl;      //  cout<<"o "<<op<<endl;
1988    
1989    //     cout <<"old p:"<< tp<<"--"<<cp<<"--"<<op<<"--"<<rp<<"--"<< endl;
1990    //     cout <<"old i:"<< ti<<"--"<<ci<<"--"<<oi<<"--"<<ri<<"--"<< endl;
1991    
1992      new (ttsorted[i]) PamTrack(tp, cp, op, rp);      new (ttsorted[i]) PamTrack(tp, cp, op, rp);
1993      new (ttimage[i]) PamTrack(ti, ci, oi, ri);      new (ttimage[i]) PamTrack(ti, ci, oi, ri);
1994    
# Line 1661  void PamLevel2::SortTracks() { Line 2016  void PamLevel2::SortTracks() {
2016    issorted = true;    issorted = true;
2017    lastsorted = GetReadEntry();    lastsorted = GetReadEntry();
2018    
2019    //  cout <<" SortTracks() -- end"<<endl;
2020    
2021  }  }
2022  ;  ;
2023    //
2024    //--------------------------------------
2025    /**
2026     * Sort physical (tracker) tracks.
2027     * @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...).
2028     * Sorting cryteria:
2029     * TRK: lower chi**2
2030     * CAL: lower Y spatial residual on the first calorimeter plane
2031     * TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis).
2032     * S1: (ask Emiliano)
2033     * S2: (ask Emiliano)
2034     * S3: (ask Emiliano)
2035     * GP: more GP hits
2036     * The default sorting cryterium is "TOF+CAL".
2037     *
2038     * The total number of physical tracks is always given by GetNTracks() and the it-th physical track can be retrieved by means of the methods GetTrack(int it) and GetTrack(int it, TString how).
2039     *
2040     * New version, with handling of extended tracks and nuclei tracks.
2041     */
2042    void PamLevel2::SortTracksNew() {
2043    
2044      //--------------------------------------------------
2045      //Check if the current event has already been sorted
2046      //--------------------------------------------------
2047      if (issorted_new && lastsorted_new == GetReadEntry()) {
2048          return; //already done for this event
2049      }
2050    
2051    
2052    //  cout << "SORT" << endl;
2053    
2054      //Reset the sort flags, just in case something will go wrong...
2055      issorted_new = false;
2056      lastsorted_new = -1;
2057    
2058      //--------------------------------------------------
2059      // set input variables
2060      //--------------------------------------------------
2061    
2062      TString how = howtosort;
2063      //Save current Object count
2064      Int_t ObjectNumber = TProcessID::GetObjectCount();
2065    
2066    
2067    
2068    
2069      TrkLevel2  * trk2 ;
2070      CaloLevel2 * calo2;
2071      ToFLevel2  * tof2  ;
2072      OrbitalInfo  * orb2 ;
2073      
2074      TClonesArray * trkext ;
2075      TClonesArray * caloext;
2076      TClonesArray * tofext ;
2077      TClonesArray * orbext ;
2078    
2079    
2080    //   cout << "trk2_obj" << trk2_obj<< endl;
2081    //   cout << "trk2_nuc_obj" << trk2_nuc_obj<< endl;
2082    //   cout << " trk_ext_obj "<<trk_ext_obj<< endl;
2083    //   cout << " trk_ext_nuc_obj "<<trk_ext_nuc_obj<< endl;
2084    
2085      //-----------------------------------------------------------
2086      // create/reset TCloneArrays to store tracks and their images
2087      //-----------------------------------------------------------
2088    
2089    //  cout << " PamLevel2::SortTracksNew() --- Clear TClonesArray objects"<<endl;
2090      
2091      // main tracks from standard alg
2092    //   if (!tsorted)
2093    //       tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2094    //   tsorted->Clear("C+C");//Delete();
2095    //   // track images from standard alg
2096    //   if (!timage)
2097    //       timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2098    //   timage->Clear("C+C");//Delete();
2099    //   // tracks from extended algorythm
2100    //   if(EXT && !text)
2101    //       text = new TClonesArray("PamTrack",trk_ext_obj->GetEntries());
2102    //   if(text)text->Clear("C+C");//Delete();
2103    
2104      if(tsorted)delete tsorted;
2105      if(timage) delete timage;
2106      if(text)   delete text;
2107      tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2108      timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2109      text = new TClonesArray("PamTrack",trk_ext_obj->GetEntries());
2110    
2111      //-----------------------------------------------------------
2112      // create/reset TCloneArrays to store tracks and their images
2113      //-----------------------------------------------------------
2114      if(NUC){
2115    
2116          
2117          if(tsorted_nuc)delete tsorted_nuc;
2118          if(timage_nuc) delete timage_nuc;
2119          if(text_nuc)   delete text_nuc;
2120          tsorted_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2121          timage_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2122          text_nuc = new TClonesArray("PamTrack",trk_ext_nuc_obj->GetEntries());
2123    
2124      // main tracks from standard alg
2125    //       if (!tsorted_nuc)
2126    //        tsorted_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2127    //       tsorted_nuc->Clear("C+C");//Delete();
2128    //       // track images from standard alg
2129    //       if (!timage_nuc)
2130    //        timage_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2131    //       timage_nuc->Clear("C+C");//Delete();
2132    //       // tracks from extended algorythm
2133    //       if(EXT && !text_nuc)
2134    //        text_nuc = new TClonesArray("PamTrack",trk_ext_nuc_obj->GetEntries());
2135    //       if(text_nuc)text_nuc->Clear("C+C");//Delete();
2136    
2137      }
2138      //--------------------------------------------------
2139      // retrieve sorting method
2140      //--------------------------------------------------
2141      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
2142      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
2143      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
2144      Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
2145      Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
2146      Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
2147      Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
2148    
2149      if (use_TOF) {
2150        use_S1 = true;
2151        use_S2 = true;
2152        use_S3 = true;
2153      };
2154      if (!CAL2 && use_CAL)
2155        use_CAL = false;
2156      if (!TOF) {
2157        use_TOF = false;
2158        use_S1 = false;
2159        use_S2 = false;
2160        use_S3 = false;
2161      }
2162      if (!GP) {
2163        use_GP = false;
2164      }
2165    
2166      if (!TRK2) {
2167        cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
2168        return;
2169      };
2170    
2171    
2172      ///////////////////////////////////////////////////////////////////////////////////
2173      //
2174      //   sort tracks and fill PamTrack arrays
2175      //
2176      ///////////////////////////////////////////////////////////////////////////////////
2177      for(int doit=0; doit<2; doit++){
2178    
2179    //       cout << "doit "<<doit<<endl;
2180    
2181    
2182          if(doit == 0){
2183    
2184              trk2  = (TRK2 ? trk2_obj: NULL);;
2185              calo2 = (CAL2 ? calo2_obj: NULL);;
2186              tof2  = (TOF  ?tof2_obj: NULL);;
2187              orb2  = (ORB ? orb2_obj: NULL);;
2188          
2189              trkext = (TRK2 ? trk_ext_obj: NULL);;
2190              caloext = (CAL2 ? calo_ext_obj: NULL);;
2191              tofext = (TOF  ?tof_ext_obj: NULL);;
2192              orbext = (ORB ? orb_ext_obj: NULL);;
2193    
2194          }else if (doit == 1){
2195    
2196              if(!NUC)break;
2197    
2198          
2199              trk2  = (TRK2 ?trk2_nuc_obj: NULL);;
2200              calo2 = (CAL2 ? calo2_nuc_obj: NULL);;
2201              tof2  = (TOF  ?tof2_nuc_obj: NULL);;
2202              orb2  = (ORB ? orb2_nuc_obj: NULL);;
2203          
2204              trkext = (TRK2 ?trk_ext_nuc_obj: NULL);;
2205              caloext = (CAL2 ? calo_ext_nuc_obj: NULL);;
2206              tofext = (TOF  ?tof_ext_nuc_obj: NULL);;
2207              orbext = (ORB ? orb_ext_nuc_obj: NULL);;
2208          
2209          
2210          
2211    
2212          }
2213    
2214    //       cout << "trk2" << trk2<<endl;
2215    //       cout << "calo2" << calo2<<endl;
2216    //       cout << "tof2" << tof2<<endl;
2217    //       cout << "orb2" << orb2<<endl;
2218    //       cout << "trkext" <<trkext <<endl;
2219    //       cout << "tofext" << tofext<<endl;
2220    //       cout << "caloext" << caloext<<endl;
2221    //       cout << "orbext" << orbext<<endl;
2222    
2223          TClonesArray &ttext    = (doit==0 ? *text : *text_nuc);
2224          TClonesArray &ttimage  = (doit==0 ? *timage : *timage_nuc);
2225          TClonesArray &ttsorted = (doit==0 ? *tsorted : *tsorted_nuc);
2226      
2227    //       cout << "tsorted + timage "<<doit<<endl;
2228    
2229          //--------------------------------------------------
2230          // loop over "physical" tracks sorted by the tracker
2231          //--------------------------------------------------
2232          for (Int_t i = 0; i < trk2->TrkLevel2::GetNTracks(); i++) {
2233    
2234              TrkTrack *ts = 0;
2235              CaloTrkVar *cs = 0;
2236              ToFTrkVar *os = 0;
2237              OrbitalInfoTrkVar *rs = 0;
2238    
2239              // get tracker tracks
2240              TrkTrack *tp          = (TRK2 ? trk2->GetTrack(i): NULL); //tracker
2241              CaloTrkVar *cp        = (CAL2 ? calo2->GetCaloStoredTrack(tp->GetSeqNo()) : NULL);
2242              ToFTrkVar *op         = (TOF  ? tof2->GetToFStoredTrack(tp->GetSeqNo())   : NULL);
2243              OrbitalInfoTrkVar *rp = (ORB ? orb2->GetOrbitalInfoStoredTrack(tp->GetSeqNo()) : NULL);
2244    
2245    //        cout << "ORB="<<ORB<<" rp="<<rp<<endl;
2246    
2247              TrkTrack *ti = 0; //tracker (image)
2248              CaloTrkVar *ci = 0;
2249              ToFTrkVar *oi = 0;
2250              OrbitalInfoTrkVar *ri = 0;
2251              //    cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
2252              // if track has an image, check image selection
2253    
2254              Int_t tp_score = 0; //main track sorted by the tracker
2255              Int_t ti_score = 0; //image track
2256              Int_t totp_score = 0; //main track sorted by the tracker
2257              Int_t toti_score = 0; //image track
2258    
2259              if (tp->HasImage()) {
2260    
2261                  ti = (TRK2 ? trk2->GetTrackImage(i) : NULL); //tracker (image)
2262                  ci = (CAL2 ? calo2->GetCaloStoredTrack(ti->GetSeqNo()): NULL);
2263                  oi = (TOF  ? tof2->GetToFStoredTrack(ti->GetSeqNo()): NULL);
2264                  ri = (ORB ? orb2->GetOrbitalInfoStoredTrack(ti->GetSeqNo()): NULL);
2265    
2266                  //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
2267    
2268                  //assign starting scores
2269                  tp_score = 0; //main track sorted by the tracker
2270                  ti_score = 0; //image track
2271    
2272                  // -----------------------------------------------------------------------------------------
2273                  // *****************************************************************************************
2274                  // -----------------------------------------------------------------------------------------
2275                  // calorimeter check
2276                  // -----------------------------------------------------------------------------------------
2277                  if (use_CAL && !calo2) {
2278                      cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but CaloLevel2 not loaded !!!";
2279                      return;
2280                  };
2281                  if (use_CAL && !cp && ci) {
2282                      ti_score++;
2283                      toti_score++;
2284                  };
2285                  if (use_CAL && cp && !ci) {
2286                      tp_score++;
2287                      totp_score++;
2288                  };
2289                  if (use_CAL && cp && ci && true) {
2290    
2291                      if (cp->npresh > ci->npresh && true) {
2292                          tp_score++;
2293                          totp_score++;
2294                      };
2295                      if (cp->npresh < ci->npresh && true) {
2296                          ti_score++;
2297                          toti_score++;
2298                      };
2299    
2300                      //    cout << "CALO "<<tp_score<<ti_score<<endl;
2301    
2302                  };
2303                  // -----------------------------------------------------------------------------------------
2304                  // *****************************************************************************************
2305                  // -----------------------------------------------------------------------------------------
2306                  // TOF check
2307                  // -----------------------------------------------------------------------------------------
2308                  // check the number of hit pmts along the track
2309                  // on S12 S21 and S32, where paddles are parallel to Y axis
2310                  if ((use_TOF || use_S1 || use_S2 || use_S3) && !tof2) {
2311                      cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but ToFLevel2 not loaded !!!";
2312                      return;
2313                  };
2314                  //
2315                  if ((use_TOF || use_S1 || use_S2 || use_S3) && !op && oi) {
2316                      ti_score++;
2317                      toti_score++;
2318                  };
2319                  if ((use_TOF || use_S1 || use_S2 || use_S3) && op && !oi) {
2320                      tp_score++;
2321                      totp_score++;
2322                  };
2323                  if ((use_TOF || use_S1 || use_S2 || use_S3) && op && oi) {
2324                      //
2325                      Float_t sen = 0.;
2326                      for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2327                          Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2328                          if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
2329                              sen += (op->dedx).At(ih);
2330                      };
2331                      for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2332                          Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2333                          if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
2334                              sen += (oi->dedx).At(ih);
2335                      };
2336                      //
2337                      if (sen >= sortthr && false) { // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
2338                          //printf(" IS A NUCLEUS! en = %f \n",sen);
2339                          //
2340                          // is a nucleus use a different algorithm
2341                          //
2342                          Int_t nz = 6;
2343                          Float_t zin[6]; // << define TOF z-coordinates
2344                          for (Int_t ip = 0; ip < nz; ip++)
2345                              zin[ip] = tof2->GetZTOF(tof2->GetToFPlaneID(ip)); // << read ToF plane z-coordinates
2346                          Trajectory *tr = new Trajectory(nz, zin);
2347                          //
2348                          Int_t nphit_p = 0;
2349                          Int_t nphit_i = 0;
2350                          Float_t enhit_p = 0.;
2351                          Float_t enhit_i = 0.;
2352                          //
2353                          for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2354                              Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2355                              if (pl == 1 || pl == 2 || pl == 5) {
2356                                  nphit_p++;
2357                                  enhit_p += (op->dedx).At(ih);
2358                              };
2359                          };
2360                          //
2361                          tp->DoTrack2(tr);
2362                          //
2363                          if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
2364                              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2365                                  Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2366                                  if (pl == 0) {
2367                                      nphit_p++;
2368                                      enhit_p += (op->dedx).At(ih);
2369                                  };
2370                              };
2371                          };
2372                          if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
2373                              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2374                                  Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2375                                  if (pl == 3) {
2376                                      nphit_p++;
2377                                      enhit_p += (op->dedx).At(ih);
2378                                  };
2379                              };
2380                          };
2381                          if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
2382                              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2383                                  Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2384                                  if (pl == 4) {
2385                                      nphit_p++;
2386                                      enhit_p += (op->dedx).At(ih);
2387                                  };
2388                              };
2389                          };
2390    
2391                          for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2392                              Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2393                              if (pl == 1 || pl == 2 || pl == 5) {
2394                                  nphit_i++;
2395                                  enhit_i += (op->dedx).At(ih);
2396                              };
2397                          };
2398                          //
2399                          ti->DoTrack2(tr);
2400                          //
2401                          if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
2402                              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2403                                  Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2404                                  if (pl == 0) {
2405                                      nphit_i++;
2406                                      enhit_i += (op->dedx).At(ih);
2407                                  };
2408                              };
2409                          };
2410                          if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
2411                              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2412                                  Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2413                                  if (pl == 3) {
2414                                      nphit_i++;
2415                                      enhit_i += (op->dedx).At(ih);
2416                                  };
2417                              };
2418                          };
2419                          if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
2420                              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2421                                  Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2422                                  if (pl == 4) {
2423                                      nphit_i++;
2424                                      enhit_i += (op->dedx).At(ih);
2425                                  };
2426                              };
2427                          };
2428    
2429                          if ((use_TOF || use_S1 || use_S2 || use_S3) && (nphit_p + nphit_i) != 0 && true) {
2430    
2431                              //        printf(" seqno %i nphit_p %i nphit_i %i enhit_p %f enhit_i %f \n",trk2_obj->TrkLevel2::GetSeqNo(i),nphit_p,nphit_i,enhit_p,enhit_i);
2432                              //        printf(" score p %i score i %i \n",tp_score,ti_score);
2433                              //              if( enhit_p > enhit_i ) tp_score++;
2434                              //              if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
2435                              if (nphit_p > nphit_i)
2436                                  tp_score++;
2437                              if (nphit_p < nphit_i)
2438                                  ti_score++;
2439                              if (nphit_p == nphit_i) {
2440                                  if (enhit_p > enhit_i)
2441                                      tp_score++;
2442                                  else
2443                                      ti_score++;
2444                              };
2445                              //        printf(" dopo score p %i score i %i \n",tp_score,ti_score);
2446                          };
2447                          delete tr;
2448                          //
2449                      }
2450                      else {
2451                          // -------------
2452                          // NOT a NUCLEUS
2453                          // -------------
2454                          //printf(" NOT a NUCLEUS! en = %f \n",sen);
2455    
2456                          Int_t nphit_p = 0;
2457                          Int_t nphit_i = 0;
2458    
2459                          /*                                cout << "track: npmtadc "<< op->npmtadc << endl;
2460                            cout << "track: npmttdc "<< op->npmttdc << endl;
2461                            cout << "image: npmtadc "<< oi->npmtadc << endl;
2462                            cout << "image: npmttdc "<< oi->npmttdc << endl;*/
2463    
2464                          //          for (Int_t ih=0; ih < op->npmtadc; ih++){
2465                          //            Int_t pl = tof2_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
2466                          //            if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
2467                          //          };
2468    
2469                          //          for (Int_t ih=0; ih < oi->npmtadc; ih++){
2470                          //            Int_t pl = tof2_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
2471                          //            if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
2472                          //          };
2473                          // --- modified to count tdc signals (more efficient?)
2474                          // --- and to implement check on tdcflag
2475                          for (Int_t ih = 0; ih < op->npmttdc; ih++) {
2476                              Int_t pl = tof2->GetPlaneIndex((op->pmttdc).At(ih));
2477                              //        if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
2478                              if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
2479                                  || (use_S3 && (pl == 4 || pl == 5))) {
2480                                  if ((op->tdcflag).At(ih) == 0)
2481                                      nphit_p++;
2482                              };
2483                          };
2484    
2485                          for (Int_t ih = 0; ih < oi->npmttdc; ih++) {
2486                              Int_t pl = tof2->GetPlaneIndex((oi->pmttdc).At(ih));
2487                              //        if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;
2488                              if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
2489                                  || (use_S3 && (pl == 4 || pl == 5))) {
2490                                  if ((oi->tdcflag).At(ih) == 0)
2491                                      nphit_i++;
2492                              };
2493                          };
2494    
2495                          if ((nphit_p + nphit_i) != 0 && true) {
2496    
2497                              if (nphit_p != nphit_i) {
2498                                  totp_score += nphit_p;
2499                                  toti_score += nphit_i;
2500                                  tp_score += nphit_p;
2501                                  ti_score += nphit_i;
2502                              };
2503                              //        if     ( nphit_p > nphit_i) tp_score+=nphit_p;
2504                              //        else if( nphit_p < nphit_i) ti_score+=nphit_i;
2505                              //        else ;//niente
2506                          };
2507                      };
2508                      //    cout << "TOF "<<tp_score<<ti_score<<endl;
2509                  };
2510    
2511                  //      if(tp_score == ti_score) use_TRK = true;
2512    
2513    
2514                  // -----------------------------------------------------------------------------------------
2515                  // *****************************************************************************************
2516                  // -----------------------------------------------------------------------------------------
2517                  // tracker check
2518                  // -----------------------------------------------------------------------------------------
2519                  // chi**2 difference is not always large enough to distinguish among
2520                  // the real track and its image.
2521                  // Tracker check will be applied always when calorimeter and tof information is ambiguous.
2522                  // *** MODIFIED ON AUGUST 2007 ***
2523                  if (use_TRK) {
2524                      //    if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
2525                      //    else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
2526    
2527                      // CHECK 1 : number of points along X
2528                      if (tp->GetNX() >= ti->GetNX()) {
2529                          tp_score++;
2530                          totp_score++;
2531                      };
2532                      if (tp->GetNX() <= ti->GetNX()) {
2533                          ti_score++;
2534                          toti_score++;
2535                      };
2536                      // CHECK 2 : number of points along Y
2537                      if (tp->GetNY() >= ti->GetNY()) {
2538                          tp_score++;
2539                          totp_score++;
2540                      };
2541                      if (tp->GetNY() <= ti->GetNY()) {
2542                          ti_score++;
2543                          toti_score++;
2544                      };
2545    
2546                      //    cout << "TRK "<<tp_score<<ti_score<<endl;
2547                  };
2548    
2549                  // -----------------------------------------------------------------------------------------
2550                  // *****************************************************************************************
2551                  // -----------------------------------------------------------------------------------------
2552                  // GPamela check
2553                  // -----------------------------------------------------------------------------------------
2554    
2555                  //---------------------------------------------------
2556                  // count the number of GP hits
2557                  //---------------------------------------------------
2558                  if (use_GP) {
2559                      int ngphits_p = 0;
2560                      int ngphits_i = 0;
2561                      float toll = 0.02; //200 micron
2562                      for (int ih = 0; ih < GetGPamela()->Nthspe; ih++) {
2563                          int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
2564                          if (tp && tp->YGood(ip) && fabs(tp->ym[ip] - GetGPamela()->Yavspe[ih]) < toll && true)
2565                              ngphits_p++;
2566                          if (ti && ti->YGood(ip) && fabs(ti->ym[ip] - GetGPamela()->Yavspe[ih]) < toll && true)
2567                              ngphits_i++;
2568                      }
2569                      if (ngphits_p > ngphits_i && true) {
2570                          tp_score++;
2571                          totp_score++;
2572                      }
2573                      if (ngphits_p < ngphits_i && true) {
2574                          ti_score++;
2575                          toti_score++;
2576                      }
2577                  }
2578    
2579                  // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2580                  // the winner is....
2581                  // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2582                  if (tp_score > ti_score) {
2583    
2584                  }
2585                  else if (tp_score < ti_score) {
2586    
2587                      ts = ti;//its image!!
2588                      cs = ci;
2589                      os = oi;
2590                      rs = ri;
2591                      Int_t totis = toti_score;
2592    
2593                      ti = tp;//its image!!
2594                      ci = cp;
2595                      oi = op;
2596                      ri = rp;
2597    
2598                      tp = ts;//its image!!
2599                      cp = cs;
2600                      op = os;
2601                      rp = rs;
2602    
2603                      toti_score = totp_score;
2604                      totp_score = totis;
2605    
2606                  }
2607                  else {
2608    
2609                      //    cout << "Warning - track image ambiguity not solved" << endl;
2610    
2611                  };
2612    
2613              }
2614              else {
2615                  totp_score = 1;
2616                  toti_score = 0;
2617    
2618                  //            ts = tp;
2619                  //            cs = cp;
2620                  //            os = op;
2621              };
2622    
2623              //    cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
2624              //    sorted_tracks->Add(ts);//save the track in the sorted array
2625              //    sorted_tracks.Add(ts);//save the track in the sorted array
2626              //    sorted_tracks.Add(tp);//save the track in the sorted array
2627              //    cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
2628              //    cout<<"o "<<tp<<endl;
2629              //    cout<<"o "<<cp<<endl;
2630              //    cout<<"o "<<op<<endl;
2631    
2632    //        cout <<"p:"<< tp<<"--"<<cp<<"--"<<op<<"--"<<rp<<"--"<< endl;
2633    //        cout <<"i:"<< ti<<"--"<<ci<<"--"<<oi<<"--"<<ri<<"--"<< endl;
2634    
2635    
2636    
2637              new (ttsorted[i]) PamTrack(tp, cp, op, rp);
2638              new (ttimage[i]) PamTrack(ti, ci, oi, ri);
2639    
2640              ((PamTrack*) (ttsorted[i]))->SetPScore(totp_score);
2641              ((PamTrack*) (ttsorted[i]))->SetIScore(toti_score);
2642              ((PamTrack*) (ttimage[i]))->SetPScore(totp_score);
2643              ((PamTrack*) (ttimage[i]))->SetIScore(toti_score);
2644          };
2645    
2646    
2647    
2648    
2649    
2650    //   if (tsorted->GetEntries() != trk2->GetNTracks()) {
2651    //     cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() " << tsorted->GetEntries()
2652    //         << " != trk2->GetNTracks() = " << trk2->GetNTracks() << endl;
2653    //     tsorted->Delete();
2654    //     tsorted = 0;
2655    //     timage->Delete();
2656    //     timage = 0;
2657    //   }
2658    
2659    
2660          //      cout << "text "<<orbext<<endl;
2661    
2662    
2663          //--------------------------------------------------
2664          // fill array with extended tracks (this is easy...)
2665          //--------------------------------------------------
2666          if(EXT){
2667              for(int it=0; it<trkext->GetEntries(); it++){
2668                  
2669    //            if(
2670    //                it < caloext->GetEntries() &&
2671    //                it < tofext->GetEntries() &&
2672    //                it < orbext->GetEntries() &&
2673    //                true){
2674                  
2675                  ExtTrack *t = (trkext ?(ExtTrack*)(*trkext)[it]:NULL );
2676                  CaloTrkVar *c =(caloext ?(CaloTrkVar*)(*caloext)[it]:NULL );
2677                  ToFTrkVar *o = (tofext ?(ToFTrkVar*)(*tofext)[it]:NULL );
2678                  OrbitalInfoTrkVar *r =(orbext ?(OrbitalInfoTrkVar*)(*orbext)[it]:NULL );
2679    //            cout <<"ext:"<< t<<"--"<<c<<"--"<<o<<"--"<<r<<"--"<< endl;
2680                  
2681                  new (ttext[it]) PamTrack(t, c, o, r);
2682    //            }else{
2683    //                cout << " PamLevel2::SortTracksNew() --> ORRORE E RACCAPRICCIO!!!"<<endl;
2684    //                cout << " trk  ext-tracks = "<<trkext->GetEntries()<<endl;
2685    //                cout << " calo ext-tracks = "<<caloext->GetEntries()<<endl;
2686    //                cout << " tof  ext-tracks = "<<tofext->GetEntries()<<endl;
2687    //                cout << " orb  ext-tracks = "<<orbext->GetEntries()<<endl;
2688    //            }
2689              }
2690          }
2691          
2692    //  cout <<" SortTracksNew() -- end"<<endl;
2693    
2694    
2695      };
2696    
2697    
2698      //Restore Object count
2699      //To save space in the table keeping track of all referenced objects
2700      //We reset the object count to what it was at the beginning of the event.
2701      TProcessID::SetObjectCount(ObjectNumber);
2702    
2703      //Everything went fine so the current event can be tagged as sorted
2704      issorted_new = true;
2705      lastsorted_new = GetReadEntry();
2706    
2707    //   cout << " tsorted "<< tsorted << " "<<(tsorted ? tsorted->GetEntries() : 0)<<endl;
2708    //   cout << " timage  "<< timage  << " "<<(timage  ? timage->GetEntries() : 0)<<endl;
2709    //   cout << " text    "<< text    << " "<<(text    ? text->GetEntries() : 0)<<endl;
2710    
2711    
2712    };
2713  //--------------------------------------  //--------------------------------------
2714  //  //
2715  //  //
# Line 1671  void PamLevel2::SortTracks() { Line 2718  void PamLevel2::SortTracks() {
2718   * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2.   * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2.
2719   * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information.   * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information.
2720   */   */
2721    
2722  // TRefArray *PamLevel2::GetTracks(){  // TRefArray *PamLevel2::GetTracks(){
2723    
2724  // //  *-*-*-*-*-*-*-*-*-*-*-*-*  // //  *-*-*-*-*-*-*-*-*-*-*-*-*
# Line 1681  void PamLevel2::SortTracks() { Line 2729  void PamLevel2::SortTracks() {
2729  //     return &sorted_tracks;  //     return &sorted_tracks;
2730    
2731  //  };  //  };
 TClonesArray *PamLevel2::GetTracks() {  
   
   //  *-*-*-*-*-*-*-*-*-*-*-*-*  
   SortTracks();  
   //  *-*-*-*-*-*-*-*-*-*-*-*-*  
2732    
   return tsorted;  
2733    
 }  
 ;  
2734  //--------------------------------------  //--------------------------------------
2735  //  //
2736  //  //
2737  //--------------------------------------  //--------------------------------------
2738    
2739  /**  /**
2740   * Retrieves the it-th Pamela "physical" track.   * Retrieves the it-th Pamela "physical" track.
2741   * It override TrkLevel2::GetTrack(int it).   * It override TrkLevel2::GetTrack(int it).
2742   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
2743   */   */
2744  PamTrack *PamLevel2::GetTrack(int it) {  PamTrack *PamLevel2::GetTrackOld(int it) {
   
   //    if(!trk2_obj) return 0;  
   
   // //  *-*-*-*+-*-*-*-*-*-*-*-*-*  
   //     SortTracks("+CAL+TOF");  
   // //  *-*-*-*-*-*-*-*-*-*-*-*-*  
   // //    if(!sorted_tracks)return 0;  
   //     if(sorted_tracks.IsEmpty())return 0;  
   
   //     PamTrack *track = 0;  
   
   //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() && it<sorted_tracks.GetEntriesFast() ){  
   //    TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);  
   //    track = GetPamTrackAlong(t);  
   //     }else{  
   //    cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;  
   //     };  
2745    
2746    //     return track;    PamTrack *track = NULL;
2747    
   //    cout << "PamLevel2::GetTrack(int it) "<<endl;  
2748    //  *-*-*-*-*-*-*-*-*-*-*-*-*    //  *-*-*-*-*-*-*-*-*-*-*-*-*
2749    SortTracks();    SortTracks();
2750    //  *-*-*-*-*-*-*-*-*-*-*-*-*    //  *-*-*-*-*-*-*-*-*-*-*-*-*
2751    if (!tsorted)    if (!tsorted)
2752      return 0;      return track;
2753    if (!tsorted->GetEntries())  //   if (!tsorted->GetEntries())
2754      return 0;  //     return track;
2755      if (tsorted->GetEntries()==0)
2756        return track;
2757    
   PamTrack *track = 0;  
2758    
2759    if (it >= 0 && it < trk2_obj->TrkLevel2::GetNTracks()) {    if (
2760      //  TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);        tsorted &&
2761      //  track = GetPamTrackAlong(t);        it >= 0 &&
2762      //TClonesArray &t = *(tsorted);        it < trk2_obj->TrkLevel2::GetNTracks() &&
2763      //track = (PamTrack*)t[it];        it < tsorted->GetEntries() &&
2764      track = (PamTrack*)((*tsorted)[it]);        true) {
2765          track = (PamTrack*)((*tsorted)[it]);
2766    }    }
2767    else {    else {
2768      cout << "PamLevel2::GetTrack(int) : tracker track SeqNo " << it << " does not exist (GetNTracks() = "      cout << "PamLevel2::GetTrackOld(int) : tracker track SeqNo " << it << " does not exist (GetNTracks() = "
2769          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
2770    };    };
2771    
2772    return track;    return track;
2773    
2774    };
2775    
2776    //PamTrack *PamLevel2::GetTrack(int it) { return GetTrack(it,trkAlg); };
2777    
2778    /**
2779     * Retrieves the it-th Pamela "physical" track.
2780     * It override TrkLevel2::GetTrack(int it).
2781     * @param it Track number, ranging from 0 to GetNTracks().
2782     * @param alg Algorythm, see SetTrakingAlgorythm(char *alg) for explanation.
2783     */
2784    PamTrack *PamLevel2::GetTrack(int it, const char* alg) {
2785    
2786        TString s(alg);
2787        if(!s.CompareTo("") ||!s.CompareTo("STD") )return GetTrackOld(it); //old algorythm
2788    
2789    
2790        SortTracksNew();
2791        // >> fill tsorted, timage and text
2792    
2793        if ( ( !s.Contains("EXTF", TString::kIgnoreCase) || !EXT )){ //not forced exteded-alg requested (or exteded-data missing)
2794    
2795            if( s.Contains("NUC")){
2796                if(
2797                    tsorted_nuc &&
2798                    it < tsorted_nuc->GetEntries() &&                             //enough tracks found
2799                    it >= 0 &&                                                //valid index
2800                    true) return (PamTrack*)((*tsorted_nuc)[it]);                 //ok return the track
2801            }else{
2802                if(
2803                    tsorted &&
2804                    it < tsorted->GetEntries() &&                             //enough tracks found
2805                    it >= 0 &&                                                //valid index
2806                    true )return (PamTrack*)((*tsorted)[it]);                 //ok return the track
2807            }
2808    
2809        }
2810        
2811    
2812        /////////////////////////////////////////////////////////////////////////
2813        /// if requested get track from extended algorythm output
2814        /////////////////////////////////////////////////////////////////////////
2815        
2816        if(s.Contains("EXT", TString::kIgnoreCase) && EXT){//if exteded-alg requested
2817            
2818            if(s.Contains("NUC")){
2819                if(
2820                    text_nuc &&
2821                    it < text_nuc->GetEntries() &&                             //enough tracks found
2822                    it >= 0 &&                                                //valid index
2823                    true) return (PamTrack*)((*text_nuc)[it]);
2824            }else{
2825                if(
2826                    text &&
2827                    it < text->GetEntries() &&                             //enough tracks found
2828                    it >= 0 &&                                                //valid index
2829                    true) return (PamTrack*)((*text)[it]);
2830            }
2831    
2832        };
2833        
2834        
2835        cout << "PamTrack *PamLevel2::GetTrack("<<it<<","<<alg<<") -- wrong track number or unrecognised algorithm"<<endl;
2836        
2837        return NULL;
2838    
2839  }  }
2840  ;  ;
2841    TClonesArray *PamLevel2::GetTracks() {
2842    
2843      //  *-*-*-*-*-*-*-*-*-*-*-*-*
2844      SortTracks();
2845      //  *-*-*-*-*-*-*-*-*-*-*-*-*
2846    
2847      return tsorted;
2848    
2849    }
2850    ;
2851    Int_t  PamLevel2::GetNTracks(const char* alg) {
2852    
2853    
2854    //    cout << " trk_nuc_obj->GetEntries() "<<trk_nuc_obj->GetEntries()<<" trk2_nuc_obj->GetNTracks() "<<trk2_nuc_obj->GetNTracks()<<endl;
2855    
2856        TString s(alg);
2857    
2858        if(!s.CompareTo("") || !s.CompareTo("STD"))return trk2_obj->TrkLevel2::GetNTracks(); //standard algorythm
2859            
2860        if(s.Contains("EXTF", TString::kIgnoreCase) && EXT){
2861            if(s.Contains("NUC", TString::kIgnoreCase) && NUC)return trk_ext_nuc_obj->GetEntries();//ok
2862            return trk_ext_obj->GetEntries();//ok
2863        }
2864        if( s.Contains("EXT", TString::kIgnoreCase) && EXT) {
2865            if(s.Contains("NUC", TString::kIgnoreCase) && NUC)
2866                return (trk2_nuc_obj->TrkLevel2::GetNTracks() ?  trk2_nuc_obj->TrkLevel2::GetNTracks() :  trk_ext_nuc_obj->GetEntries() );  
2867            return (trk2_obj->TrkLevel2::GetNTracks() ?  trk2_obj->TrkLevel2::GetNTracks() :  trk_ext_obj->GetEntries() );
2868        }
2869        if(s.Contains("NUC", TString::kIgnoreCase) && NUC )
2870            return trk2_nuc_obj->TrkLevel2::GetNTracks();
2871        
2872        cout << "Int_t  PamLevel2::GetNTracks("<<alg<<") -- unrecognised algorithm"<<endl;
2873    
2874        return 0;
2875    
2876    }
2877    
2878    
2879  //--------------------------------------  //--------------------------------------
2880  //  //
# Line 1757  PamTrack *PamLevel2::GetTrack(int it) { Line 2884  PamTrack *PamLevel2::GetTrack(int it) {
2884   * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().   * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().
2885   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
2886   */   */
2887  PamTrack *PamLevel2::GetTrackImage(int it) {  PamTrack *PamLevel2::GetTrackImageOld(int it) {
2888    
2889    //  *-*-*-*-*-*-*-*-*-*-*-*-*    //  *-*-*-*-*-*-*-*-*-*-*-*-*
2890    SortTracks();    SortTracks();
# Line 1781  PamTrack *PamLevel2::GetTrackImage(int i Line 2908  PamTrack *PamLevel2::GetTrackImage(int i
2908      };      };
2909    }    }
2910    else {    else {
2911      cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo " << it << " does not exist (GetNTracks() = "      cout << "PamLevel2::GetTrackImageOld(int) : Tracker track SeqNo " << it << " does not exist (GetNTracks() = "
2912          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
2913    };    };
2914    
2915    return image;    return image;
2916  }  }
2917    /**
2918     * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().
2919     * @param it Track number, ranging from 0 to GetNTracks().
2920     * @param alg Algorythm, see SetTrakingAlgorythm(char *alg) for explanation.
2921     */
2922    PamTrack *PamLevel2::GetTrackImage(int it, const char* alg) {
2923    
2924        TString s(alg);
2925        if(!s.CompareTo("") || !s.CompareTo("STD"))return GetTrackImageOld(it); //old algorythm
2926    
2927    
2928        SortTracksNew();
2929        // >> fill tsorted, timage and text
2930    
2931        if ( ( !s.Contains("EXTF", TString::kIgnoreCase) || !EXT )){ //not forced exteded-alg requested (or exteded-data missing)
2932    
2933            if( s.Contains("NUC")){
2934                if(
2935                    tsorted_nuc &&
2936                    it < tsorted_nuc->GetEntries() &&                             //enough tracks found
2937                    it >= 0 &&                                                //valid index
2938                    true){
2939                    TClonesArray &t = *(tsorted_nuc);
2940                    PamTrack *temp = (PamTrack*) t[it];
2941                    if (temp->GetTrkTrack()->HasImage()) {
2942                        return (PamTrack*)((*timage_nuc)[it]);                 //ok return the track
2943                    }else{
2944                        return NULL;
2945                    }
2946                    
2947                }
2948            }else{
2949                if(
2950                    tsorted &&
2951                    it < tsorted->GetEntries() &&                             //enough tracks found
2952                    it >= 0 &&                                                //valid index
2953                    true ){
2954                    TClonesArray &t = *(tsorted);
2955                    PamTrack *temp = (PamTrack*) t[it];
2956                    if (temp->GetTrkTrack()->HasImage()) {              
2957                        return (PamTrack*)((*timage)[it]);                 //ok return the track
2958                    }else{
2959                        return NULL;
2960                    }
2961                }
2962            }
2963    
2964        }
2965    
2966    //    cout << "PamTrack *PamLevel2::GetTrackImage("<<it<<","<<alg<<") -- wrong track number or unrecognised algorithm"<<endl;
2967          
2968        return NULL;
2969    
2970    }
2971    ;
2972    
2973  //--------------------------------------  //--------------------------------------
2974  //  //
# Line 1876  TTree *PamLevel2::GetPamTree(TFile *f, T Line 3058  TTree *PamLevel2::GetPamTree(TFile *f, T
3058      if (!Trout)      if (!Trout)
3059        Trout = T;        Trout = T;
3060      else      else
3061        Trout->AddFriend(T);          Trout->AddFriend(T);
3062    }    }
3063    else {    else {
3064      cout << "Tracker      : missing tree" << endl;      cout << "Tracker      : missing tree" << endl;
# Line 2113  TList* PamLevel2::GetListOfLevel2Files(T Line 3295  TList* PamLevel2::GetListOfLevel2Files(T
3295          if (file.EndsWith(".root")) {          if (file.EndsWith(".root")) {
3296            TString filedir;            TString filedir;
3297            cout << ddir << endl;            cout << ddir << endl;
3298            if (ddir != "") {            if ( ddir != "" ) {
3299              filedir = ddir; // take the input dir              filedir = ddir; // take the input dir
3300            }            }
3301            else {            else {
# Line 2121  TList* PamLevel2::GetListOfLevel2Files(T Line 3303  TList* PamLevel2::GetListOfLevel2Files(T
3303              filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir              filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir
3304            };            };
3305            filedir.Append("/");            filedir.Append("/");
3306            char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir), gSystem->BaseName(file));            //          char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir), gSystem->BaseName(file));
3307              char *fullpath = gSystem->ConcatFileName(filedir.Data(), gSystem->BaseName(file));
3308            contents->Add(new TSystemFile(fullpath, gSystem->DirName(fullpath)));// add file to the list            contents->Add(new TSystemFile(fullpath, gSystem->DirName(fullpath)));// add file to the list
3309            cout << fullpath << endl;            cout << fullpath << endl;
3310            delete fullpath;            delete fullpath;
# Line 2240  TChain *PamLevel2::GetPamTree(TList *fl, Line 3423  TChain *PamLevel2::GetPamTree(TList *fl,
3423    TChain *G = 0;    TChain *G = 0;
3424    
3425    TChain *L = 0;    TChain *L = 0;
3426      TChain *P = 0;
3427    
3428    if (TRK2 || TRK1 || TRKh)    if (TRK2 || TRK1 || TRKh)
3429      T = new TChain("Tracker");      T = new TChain("Tracker");
# Line 2259  TChain *PamLevel2::GetPamTree(TList *fl, Line 3443  TChain *PamLevel2::GetPamTree(TList *fl,
3443      B = new TChain("OrbitalInfo");      B = new TChain("OrbitalInfo");
3444    if (GP)    if (GP)
3445      G = new TChain("h20");      G = new TChain("h20");
3446      if (PROC)
3447        P = new TChain("ProcessingInfo");
3448    L = new TChain("SelectionList");    L = new TChain("SelectionList");
3449    
3450    // loop over files and create chains    // loop over files and create chains
# Line 2286  TChain *PamLevel2::GetPamTree(TList *fl, Line 3472  TChain *PamLevel2::GetPamTree(TList *fl,
3472          B->Add(name);          B->Add(name);
3473        if (GP)        if (GP)
3474          G->Add(name);          G->Add(name);
3475          if (P)
3476            P->Add(name);
3477        if (SELLI == 1)        if (SELLI == 1)
3478          L->Add(name);          L->Add(name);
3479      };       };
3480    };    };
3481    
3482    cout << "done chains\n";    cout << "done data-tree chains  "<<  T->GetNtrees() <<" \n";
3483    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;    cout << "----------------------------------------------------" << endl;
3484    
3485    // -------------------------------------------    // -------------------------------------------
3486    // make friends    // make friends
# Line 2375  TChain *PamLevel2::GetPamTree(TList *fl, Line 3563  TChain *PamLevel2::GetPamTree(TList *fl,
3563    //  =====================================    //  =====================================
3564    //  SET BRANCH-ADDRESS AFTER CHAIN+FRIEND    //  SET BRANCH-ADDRESS AFTER CHAIN+FRIEND
3565    //  =====================================    //  =====================================
3566    SetBranchAddress(Trout);    if( Trout->GetNtrees() )SetBranchAddress(Trout);
3567    
3568    //  ------------------------------------    //  ------------------------------------
3569    //  finally handle selection trees...    //  finally handle selection trees...
3570    //  (it is not friend of pamela tree)    //  (it is not friend of pamela tree)
3571    //  ------------------------------------    //  ------------------------------------
3572    
3573    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;    cout << "----------------------------------------------------" << endl;
3574    
3575    // Selection List    // Selection List
3576    if (L && SELLI == 1) {    if (L && SELLI == 1) {
# Line 2392  TChain *PamLevel2::GetPamTree(TList *fl, Line 3580  TChain *PamLevel2::GetPamTree(TList *fl,
3580      cout << "SelectionList: set branch address RunEntry" << endl;      cout << "SelectionList: set branch address RunEntry" << endl;
3581      L->SetBranchAddress("EventEntry", &irunentry);      L->SetBranchAddress("EventEntry", &irunentry);
3582      cout << "SelectionList: set branch address EventEntry" << endl;      cout << "SelectionList: set branch address EventEntry" << endl;
3583        /*    if ( L->GetBranch("L0EventEntry") ){
3584          hasL0EE = true;
3585          L->SetBranchAddress("L0EventEntry", &il0entry);
3586          cout << "SelectionList: set branch address L0EventEntry" << endl;
3587        } else {
3588          hasL0EE = false; // backward compatibility with old preselected files...
3589          }*/
3590      sel_tree = L;      sel_tree = L;
3591      //          if(!Trout)Trout=O;      //          if(!Trout)Trout=O;
3592      //          else Trout->AddFriend("SelectionList");      //          else Trout->AddFriend("SelectionList");
3593      cout << "+SelectionList" << endl;      cout << "+SelectionList" << endl;
3594      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;      cout << "----------------------------------------------------" << endl;
3595    }    }
3596    else {    else {
3597      //  cout << "SelectionList  : missing tree"<<endl;      //  cout << "SelectionList  : missing tree"<<endl;
# Line 2404  TChain *PamLevel2::GetPamTree(TList *fl, Line 3599  TChain *PamLevel2::GetPamTree(TList *fl,
3599        L->Delete();        L->Delete();
3600    };    };
3601    
3602      //ProcessingInfo EM
3603      if ( P && P->GetEntries() ){
3604        cout << "----------------------------------------------------" << endl;
3605        cout << ">>> Found ProcessingInfo <<<" << endl;
3606        //  L->SetBranchAddress("RunEntry",&irun);
3607        P->SetBranchAddress("ProcInfo", &proc_obj);//NEWNEW
3608        proc_tree = P;
3609      } else {
3610        //    proc_tree = new TChain("ProcessingInfo","Log of data processing");
3611        //    proc_tree->Branch("ProcInfo", "ProcInfo", &proc_obj);
3612        cout << "----------------------------------------------------" << endl;
3613        cout << ">>> ProcessingInfo not found, PROC set to false and continue (not 10RED files?)<<<" << endl;
3614        PROC = false;
3615      }
3616    //  --------------------------------------------    //  --------------------------------------------
3617    //  return the pamela chain with all the friends    //  return the pamela chain with all the friends
3618    //  --------------------------------------------    //  --------------------------------------------
3619    
3620    pam_tree = Trout;    pam_tree = Trout;
   
3621    return Trout;    return Trout;
3622  }  }
3623    
# Line 2422  TChain *PamLevel2::GetPamTree(TList *fl, Line 3630  TChain *PamLevel2::GetPamTree(TList *fl,
3630   */   */
3631  void PamLevel2::SetBranchAddress(TTree *t) {  void PamLevel2::SetBranchAddress(TTree *t) {
3632    
3633    TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");  //   TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
3634    TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");  //   TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
3635    TRKh = TRKh & t->GetBranchStatus("TrkHough");  //   TRKh = TRKh & t->GetBranchStatus("TrkHough");
3636    CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");  //   CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
3637    CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");  //   CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
3638    TOF = TOF & t->GetBranchStatus("ToFLevel2");  //   TOF = TOF & t->GetBranchStatus("ToFLevel2");
3639    TRG = TRG & t->GetBranchStatus("TrigLevel2");  //   TRG = TRG & t->GetBranchStatus("TrigLevel2");
3640    S4 = S4 & t->GetBranchStatus("S4Level2");  //   S4 = S4 & t->GetBranchStatus("S4Level2");
3641    ND = ND & t->GetBranchStatus("NDLevel2");  //   ND = ND & t->GetBranchStatus("NDLevel2");
3642    AC = AC & t->GetBranchStatus("AcLevel2");  //   AC = AC & t->GetBranchStatus("AcLevel2");
3643    ORB = ORB & t->GetBranchStatus("OrbitalInfo");  //   ORB = ORB & t->GetBranchStatus("OrbitalInfo");
3644    GP = GP & t->GetBranchStatus("h20");  //   GP = GP & t->GetBranchStatus("h20");
3645    
3646    
3647    // Tracker    // Tracker
3648    if (TRK1) {    if (TRK1) {
# Line 2443  void PamLevel2::SetBranchAddress(TTree * Line 3652  void PamLevel2::SetBranchAddress(TTree *
3652    if (TRK2) {    if (TRK2) {
3653      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));
3654      cout << "Tracker      : set branch address TrkLevel2" << endl;      cout << "Tracker      : set branch address TrkLevel2" << endl;
3655        NUC = t->GetBranchStatus("TrackNuclei");
3656        EXT = t->GetBranchStatus("RecoveredTrack") && (NUC ? t->GetBranchStatus("RecoveredTrackNuclei"): true );    
3657    };    };
3658    if (TRKh) {    if (TRKh) {
3659      t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));      t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
# Line 2503  void PamLevel2::SetBranchAddress(TTree * Line 3714  void PamLevel2::SetBranchAddress(TTree *
3714    
3715      cout << "h20          : set branch address GPamela " << endl;      cout << "h20          : set branch address GPamela " << endl;
3716    };    };
3717      if(NUC){
3718          
3719          cout << "Found nuclei-track branches" << endl;
3720    
3721          if( !trk_nuc_obj )trk_nuc_obj = new TClonesArray("TrkTrack");
3722          if( !calo_nuc_obj)calo_nuc_obj= new TClonesArray("CaloTrkVar");
3723          if( !tof_nuc_obj)tof_nuc_obj= new TClonesArray("ToFTrkVar");
3724          if( !orb_nuc_obj)orb_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3725          if (TRK2)t->                          SetBranchAddress("TrackNuclei",&trk_nuc_obj);
3726          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("TrackNuclei",&calo_nuc_obj);
3727          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("TrackNuclei",&tof_nuc_obj);
3728          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("TrackNuclei",&orb_nuc_obj);
3729    
3730          ///copy the vector content inside a "fake" object (all aother info are missing)    
3731    
3732          if( !trk2_nuc_obj )trk2_nuc_obj =  new TrkLevel2();
3733          if( !calo2_nuc_obj )calo2_nuc_obj =  new CaloLevel2();
3734          if( !tof2_nuc_obj )tof2_nuc_obj =  new ToFLevel2();
3735          if( !orb2_nuc_obj )orb2_nuc_obj =  new OrbitalInfo();
3736    //       *(trk2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*trk_nuc_obj);
3737    //       *(calo2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*calo_nuc_obj);
3738    //       *(tof2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*tof_nuc_obj);
3739    //       *(orb2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*orb_nuc_obj);
3740    
3741          trk2_nuc_obj->SetTrackArray(  trk_nuc_obj  );
3742          calo2_nuc_obj->SetTrackArray( calo_nuc_obj );
3743          tof2_nuc_obj->SetTrackArray(  tof_nuc_obj  );
3744          orb2_nuc_obj->SetTrackArray(  orb_nuc_obj  );
3745    
3746          
3747      }    
3748    
3749      if(EXT){
3750          
3751          cout << "Found extended tracking algorythm branches" << endl;
3752    
3753          if( !trk_ext_obj )trk_ext_obj = new TClonesArray("ExtTrack");
3754          if( !calo_ext_obj)calo_ext_obj= new TClonesArray("CaloTrkVar");
3755          if( !tof_ext_obj)tof_ext_obj= new TClonesArray("ToFTrkVar");
3756          if( !orb_ext_obj)orb_ext_obj= new TClonesArray("OrbitalInfoTrkVar");
3757          
3758          if (TRK2)t->                          SetBranchAddress("RecoveredTrack",&trk_ext_obj);
3759          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrack",&calo_ext_obj);
3760          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrack",&tof_ext_obj);
3761          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrack",&orb_ext_obj);
3762    
3763        
3764          if(NUC){
3765              if( !trk_ext_nuc_obj )trk_ext_nuc_obj = new TClonesArray("ExtTrack");
3766              if( !calo_ext_nuc_obj)calo_ext_nuc_obj= new TClonesArray("CaloTrkVar");
3767              if( !tof_ext_nuc_obj)tof_ext_nuc_obj= new TClonesArray("ToFTrkVar");
3768              if( !orb_ext_nuc_obj)orb_ext_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3769              if (TRK2)t->                          SetBranchAddress("RecoveredTrackNuclei",&trk_ext_nuc_obj);
3770              if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrackNuclei",&calo_ext_nuc_obj);
3771              if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrackNuclei",&tof_ext_nuc_obj);
3772              if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrackNuclei",&orb_ext_nuc_obj);
3773          }
3774      }    
3775  }  }
3776  /**  /**
3777   * Set branch addresses for Pamela friend trees   * Set branch addresses for Pamela friend trees
# Line 2527  void PamLevel2::SetBranchAddress(TChain Line 3795  void PamLevel2::SetBranchAddress(TChain
3795    if (TRK2) {    if (TRK2) {
3796      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
3797      cout << "Tracker      : set branch address TrkLevel2" << endl;      cout << "Tracker      : set branch address TrkLevel2" << endl;
3798        NUC = t->GetBranchStatus("TrackNuclei");
3799        EXT = t->GetBranchStatus("RecoveredTrack") && (NUC ? t->GetBranchStatus("RecoveredTrackNuclei"): true );
3800    };    };
3801    if (TRK1) {    if (TRK1) {
3802      t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));      t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
# Line 2540  void PamLevel2::SetBranchAddress(TChain Line 3810  void PamLevel2::SetBranchAddress(TChain
3810    // Calorimeter    // Calorimeter
3811    if (CAL2) {    if (CAL2) {
3812      t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));      t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
3813      cout << "Calorimeter  : set branch address CaloLevel2" << endl;      cout << "Calorimeter  : set branch address CaloLevel2" << endl;    
3814    };    };
3815    if (CAL1) {    if (CAL1) {
3816      t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));      t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
# Line 2598  void PamLevel2::SetBranchAddress(TChain Line 3868  void PamLevel2::SetBranchAddress(TChain
3868    //    cout << "SelectionList: set branch address EventEntry"<<endl;    //    cout << "SelectionList: set branch address EventEntry"<<endl;
3869    
3870    //     }    //     }
3871      if(NUC){
3872          
3873          cout << "Found nuclei-track branches" << endl;
3874    
3875          if( !trk_nuc_obj )trk_nuc_obj = new TClonesArray("TrkTrack");
3876          if( !calo_nuc_obj)calo_nuc_obj= new TClonesArray("CaloTrkVar");
3877          if( !tof_nuc_obj)tof_nuc_obj= new TClonesArray("ToFTrkVar");
3878          if( !orb_nuc_obj)orb_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3879          if (TRK2)t->                          SetBranchAddress("TrackNuclei",&trk_nuc_obj);
3880          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("TrackNuclei",&calo_nuc_obj);
3881          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("TrackNuclei",&tof_nuc_obj);
3882          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("TrackNuclei",&orb_nuc_obj);
3883          
3884          ///copy the vector content inside a "fake" object (all aother info are missing)    
3885    
3886          if( !trk2_nuc_obj )trk2_nuc_obj =  new TrkLevel2();
3887          if( !calo2_nuc_obj )calo2_nuc_obj =  new CaloLevel2();
3888          if( !tof2_nuc_obj )tof2_nuc_obj =  new ToFLevel2();
3889          if( !orb2_nuc_obj )orb2_nuc_obj =  new OrbitalInfo();
3890    
3891    //       *(trk2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*trk_nuc_obj);
3892    //       *(calo2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*calo_nuc_obj);
3893    //       *(tof2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*tof_nuc_obj);
3894    //       *(orb2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*orb_nuc_obj);
3895          trk2_nuc_obj->SetTrackArray(  trk_nuc_obj  );
3896          calo2_nuc_obj->SetTrackArray( calo_nuc_obj );
3897          tof2_nuc_obj->SetTrackArray(  tof_nuc_obj  );
3898          orb2_nuc_obj->SetTrackArray(  orb_nuc_obj  );
3899    
3900      }    
3901      if(EXT){
3902          
3903          cout << "Found extended tracking algorythm branches" << endl;
3904    
3905          t->SetBranchAddress("extAlgFlag",&extAlgFlag);
3906    
3907          if( !trk_ext_obj )trk_ext_obj = new TClonesArray("ExtTrack");
3908          if( !calo_ext_obj)calo_ext_obj= new TClonesArray("CaloTrkVar");
3909          if( !tof_ext_obj)tof_ext_obj= new TClonesArray("ToFTrkVar");
3910          if( !orb_ext_obj)orb_ext_obj= new TClonesArray("OrbitalInfoTrkVar");
3911          
3912          if (TRK2)t->                          SetBranchAddress("RecoveredTrack",&trk_ext_obj);
3913          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrack",&calo_ext_obj);
3914          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrack",&tof_ext_obj);
3915          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrack",&orb_ext_obj);
3916          
3917          if(NUC){
3918              if( !trk_ext_nuc_obj )trk_ext_nuc_obj = new TClonesArray("ExtTrack");
3919              if( !calo_ext_nuc_obj)calo_ext_nuc_obj= new TClonesArray("CaloTrkVar");
3920              if( !tof_ext_nuc_obj)tof_ext_nuc_obj= new TClonesArray("ToFTrkVar");
3921              if( !orb_ext_nuc_obj)orb_ext_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3922              if (TRK2)t->                          SetBranchAddress("RecoveredTrackNuclei",&trk_ext_nuc_obj);
3923              if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrackNuclei",&calo_ext_nuc_obj);
3924              if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrackNuclei",&tof_ext_nuc_obj);
3925              if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrackNuclei",&orb_ext_nuc_obj);
3926          }
3927      }    
3928      
3929  }  }
3930    
3931    /**
3932     * Set the tracking algorythm
3933     * @param alg String to choose the track.
3934     * "" --> take the output of the standard tracking algorythm
3935     * "STD" --> take the output of the standard tracking algorythm
3936     * "NUC" --> take the output of the standard tracking algorythm for nuclei cluster selection
3937     * "EXT" --> in case the standard tracking algorythm has not found any track, take the output of the extended one
3938     * "EXTF" --> force the extended tracking algorythm
3939     * "NUCEXT" --> as "EXT", but for nuclei
3940     * "NUCEXTF" --> as "EXTF", but for nuclei
3941     */
3942    // void PamLevel2::SetTrackingAlgorythm(const char *alg){
3943    
3944    
3945    //     TString s(alg);
3946    //     if(s.Contains("NUC", TString::kIgnoreCase) && !NUC)
3947    //      cout << "Warning! NUC algorythm requested, but branches are missing"<<endl;
3948    //     if(s.Contains("EXT", TString::kIgnoreCase) && !EXT)
3949    //      cout << "Warning! EXT algorythm requested, but branches are missing"<<endl;;
3950                
3951    //     trkAlg = alg;
3952    
3953    // };
3954    // const char* PamLevel2::GetTrackingAlgorythm(){
3955    
3956    
3957    //     cout<<endl<<" Implemented tracking algorythm: ";
3958    //     cout<<endl<<"  \"\" or \"STD\"  --> take the output of the standard tracking algorythm";
3959    //     cout<<endl<<"  \"NUC\"      --> take the output of the standard tracking algorythm for nuclei cluster selection";
3960    //     cout<<endl<<"  \"EXT\"      --> in case the standard tracking algorythm has not found any track,";
3961    //     cout<<endl<<"                 take the output of the extended one";
3962    //     cout<<endl<<"  \"EXTF\"     --> force the extended tracking algorythm";
3963    //     cout<<endl<<"  \"NUCEXT\"   --> as \"EXT\", but for nuclei ";
3964    //     cout<<endl<<"  \"NUCEXTF\"  --> as \"EXTF\", but for nuclei";
3965    
3966    //     cout<<endl;
3967    //     cout<<" <<Currently set algorythm>> "<<trkAlg<<endl;
3968    //     cout<<endl;
3969    
3970    //     return trkAlg;
3971    // };
3972    
3973    
3974    
3975  //--------------------------------------  //--------------------------------------
3976  //  //
3977  //  //
# Line 2634  TChain *PamLevel2::GetRunTree(TList *fl) Line 4005  TChain *PamLevel2::GetRunTree(TList *fl)
4005      };      };
4006    }    }
4007    
4008      cout << "done run chain  "<<  R->GetNtrees() <<" \n";
4009    
4010    
4011    if (RUN && R->GetNtrees()) {    if (RUN && R->GetNtrees()) {
4012    
4013      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
# Line 2673  TChain *PamLevel2::GetRunTree(TList *fl) Line 4047  TChain *PamLevel2::GetRunTree(TList *fl)
4047      cout << "----------------------------------------------------" << endl;      cout << "----------------------------------------------------" << endl;
4048    
4049    }    }
4050    else {  //   else {
4051      delete R;  //     delete R;
4052      R = 0;  //     R = 0;
4053    }  //   }
4054    
4055    run_tree = R;    run_tree = R;
4056    
# Line 2715  TTree *PamLevel2::GetRunTree(TFile *f) { Line 4089  TTree *PamLevel2::GetRunTree(TFile *f) {
4089    return T;    return T;
4090    
4091  }  }
 /**  
  * Update the runinfo informations (to be used to have Run infos event by event basis)  
  * @param run Pointer to the chain/tree which contains run infos  
  * @return true if a new run has been read, false if it is still the same run  
  */  
 Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) {  
   //  
   // check if we have already called once GetEntry, if not call it  
   //  
   cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) --- ATTENZIONE --- NON E` MANTENUTA!!!!!!!.... "  
       << endl;  
   if (!run) {  
     cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree " << endl;  
     return (false);  
   }  
   if (run->GetEntries() <= 0)  
     return (false);  
   //  
   
   //  Int_t oldrun = irun;  
   Long64_t oldrun = irun;  
   
   // --------------------------------------  
   // if it is a full file (not preselected)  
   // --------------------------------------  
   if (SELLI == 0) {  
   
     //  
     // the absolute time is necessary to relate the event with the run  
     //  
     if (!GetOrbitalInfo() && !ISGP) {  
       cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo " << endl;  
       return (false);  
     }  
   
     ULong64_t abstime = 0;  
     if (GetOrbitalInfo())  
       abstime = GetOrbitalInfo()->absTime;  
   
     //  
     // the first time the routine is called, set run search from the beginning  
     //  
     if (irun < 0LL) {  
       irun = 0LL;  
       run->GetEntry(irun);  
       runfirstentry = 0LL;  
       runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);  
       if ((Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL)  
         runlastentry -= 1LL;  
   
       if (ISGP && run->GetEntries() != 1) {  
         cout << "** WARNING ** simulated files are assumed to have 1 single run, not " << run->GetEntries() << endl;  
         cout << "** WARNING ** run will not be updated" << endl;  
       }  
   
     };  
     //  
     if (ISGP)  
       abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO  
     //  
     if (irun == run->GetEntries() - 1LL && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime  
         <= GetRunInfo()->RUNTRAILER_TIME)) {  
       irun = -1LL;  
       irunt = -1LL;  
       runfirstentry = 0LL;  
       runlastentry = -1LL;  
     };  
     // modificato il controllo sull'aggiornamento del run, per evitare problemi  
     // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)  
     //  
     bool fromfirst = true;  
     //  
     while (!(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun  
         < run->GetEntries() - 1LL) {  
       //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){  
       irun++;  
       run->GetEntry(irun);  
       runfirstentry = runlastentry;  
       if ((Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL)  
         runfirstentry += 1LL;  
       runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);  
       //          cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;  
       //          cout << "runfirstentry "<<runfirstentry<<endl;  
       //          printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));  
       //          printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);  
       //          printf(" IDRUN %u \n",GetRunInfo()->ID);  
       //  
       //          prevshift = 0;  
       //  
       if (irun == (Long64_t)(run->GetEntries() - 1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME  
           && abstime <= GetRunInfo()->RUNTRAILER_TIME)) {  
         printf(" resetting irun  (it should NOT happen!!!)\n");  
         fromfirst = false;  
         irun = 0;  
         run->GetEntry(irun);  
         runfirstentry = 0ULL;  
         runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);  
         if ((Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL)  
           runlastentry -= 1LL;  
       };  
       //  
     };  
     //  
     if (!(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)) {  
       printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n", abstime);  
       return false;  
     }  
     //  
     if (irun == oldrun || irun >= run->GetEntries())  
       return (false);  
     //  
     //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);  
     //  
     prevshift = 0;  
     cout << " ))))) UPDATE RUN INFO (((((  @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun << endl;  
     //      cout << "runfirstentry "<<runfirstentry<<endl;  
     return (true);  
   };  
   // ----------------------------------------------------  
   // if it is a preselected file (there is SelectionList)  
   // NBNB - the event tree MUST be read first  
   // ----------------------------------------------------  
   if (SELLI == 1) {  
     sel_tree->GetEntry(iev);  
     //      cout << irun << " "<< irunentry << endl;  
     if (irun != oldrun) {  
       run->GetEntry(irun);  
       cout << " ))))) UPDATE RUN INFO (((((  @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun << endl;  
       prevshift = 0;  
       return true;  
     }  
     return false;  
   }  
   
   return false;  
   //  
 }  
 ;  
4092    
4093  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) {  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) {
4094    
4095      if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - inside\n");
4096    
4097    if (!run_tree) {    if (!run_tree) {
4098      cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded" << endl;      cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded" << endl;
4099      return false;      return false;
# Line 2865  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4103  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4103      return (false);      return (false);
4104    }    }
4105    
4106    
4107    Int_t oldrun = irun; // store current run index    Int_t oldrun = irun; // store current run index
4108    
4109    // -----------------------------------------------------------------------    // -----------------------------------------------------------------------
# Line 2874  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4113  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4113    if (irun < 0) {    if (irun < 0) {
4114      irun = 0LL;      irun = 0LL;
4115      irunt = 0LL;      irunt = 0LL;
4116      irunentry = 0;      totrunentry = 0LL;
4117        totrunentrymin = 0LL;
4118        totrunentrymax = 0LL;
4119        irunentry = 0LL;
4120        il0entry = 0LL;
4121      prevshift = 0;      prevshift = 0;
4122        yprevshift = 0;
4123        prevabstime = 0;
4124        prevpktnum = 0;
4125        abstime = 0ULL;
4126        pktnum = 0;
4127        isFragment = false;
4128      run_tree->GetEntry(irun);      run_tree->GetEntry(irun);
4129      if (!GetOrbitalInfo())      if (!GetOrbitalInfo())
4130        cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated " << endl;          cout << "PamLevel2::UpdateRunInfo(Long64_t "<<iev<<") ** WARNING ** missing OrbitalInfo    ORB="<<ORB << endl;
4131      if (gltsync)      if ( fUseDBinRunInfo ){
4132        delete gltsync; //Emiliano        if (gltsync)
4133      if (!dbc || (dbc && !dbc->IsConnected()))          delete gltsync; //Emiliano
4134        SetDBConnection(); //Emiliano        if (!dbc || (dbc && !dbc->IsConnected()))
4135      gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); //Emiliano // the "false" means not to use level0 file (not necessary here)          SetDBConnection(); //Emiliano
4136      if (dbc){        gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); //Emiliano // the "false" means not to use level0 file (not necessary here)
4137        dbc->Close();// Emiliano        if (dbc){
4138        dbc=0;          dbc->Close();// Emiliano
4139      };          delete dbc;
4140    };          dbc=0;
4141          }
4142        }
4143      }
4144    // ---------------------------------------------------------------    // ---------------------------------------------------------------
4145    // retrieve OBT and absolute time of the event    // retrieve OBT and absolute time of the event
4146    // ---------------------------------------------------------------    // ---------------------------------------------------------------
   ULong64_t abstime = 0LL;  
   //    ULong64_t obt     = 0LL; // Emiliano  
4147    Long64_t obt = 0LL; // Emiliano, Long64_t GL_TIMESYNC::DBobt(UInt_t obt) since depending on the situation OBT is lowered or boosted    Long64_t obt = 0LL; // Emiliano, Long64_t GL_TIMESYNC::DBobt(UInt_t obt) since depending on the situation OBT is lowered or boosted
4148      prevabstime = abstime;
4149      prevpktnum = pktnum;
4150    if (GetOrbitalInfo()) {    if (GetOrbitalInfo()) {
4151      abstime = GetOrbitalInfo()->absTime;      abstime = GetOrbitalInfo()->absTime;
4152      obt = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano      if ( fUseDBinRunInfo ) obt = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano
4153        pktnum = GetOrbitalInfo()->pkt_num; // Emiliano
4154    }    }
4155    else {    else {
4156      abstime = GetRunInfo()->RUNHEADER_TIME;      abstime = GetRunInfo()->RUNHEADER_TIME;
4157      obt = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano      if ( fUseDBinRunInfo ) obt = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano
4158        pktnum = GetRunInfo()->RUNHEADER_PKT; // Emiliano
4159      }
4160    
4161      if (DBG){
4162        printf("0abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4163        printf("0        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4164        printf("0        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4165        if ( fUseDBinRunInfo ) printf("0        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4166        printf("0        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4167        printf("0        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);
4168    }    }
4169    
4170    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# Line 2922  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4185  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4185      }      }
4186    
4187      //      //
4188      bool fromfirst = true; // first loop over runs      bool a = true;
4189        bool b = true;
4190        if ( fUseDBinRunInfo ){
4191          a = false;    
4192          b = false;
4193          if ( obt < gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) ) a = true;
4194          if ( obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ) b = true;
4195        }
4196        if ( iev < totrunentrymin || iev > totrunentrymax // entry is outside run limits
4197             || iev == 0 // or it is the first entry
4198             || (!isSync && (
4199                             (abstime <= GetRunInfo()->RUNHEADER_TIME && a ) // or it is outside obt limits (and abstime limits for security reasons)
4200                             || (abstime >= GetRunInfo()->RUNTRAILER_TIME && b ) ))// or it is outside obt limits (and abstime limits for security reasons)
4201             ){ // check on abstime and obt needed to handle nested+DV_skipped packets
4202          
4203          // check for a new run (ma prima il primo!)
4204          if (DBG){
4205            printf("1abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4206            printf("1        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4207            printf("1        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4208            if ( fUseDBinRunInfo ) printf("1        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4209            printf("1        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4210            printf("1        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);
4211          }
4212          //        printf("1abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4213          //        printf("1        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4214          //        printf("1        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4215          //        printf("1        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4216          //        printf("1        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4217          //        printf("1        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);//TOGLITOGLI
4218    
4219      // ------------------------------------------------------        totrunentry = 0LL;
4220      // loop over runs to find the one that contains the event        runfirstentry = 0LL;
4221      // ------------------------------------------------------        for (Int_t r=0; r< run_tree->GetEntries();r++){
4222      while ((          // -------------------------------------------------------------------
4223      //          (          // save the index of the first entry of the run, relative to pam_tree,
4224      //              !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)          // and read a new run
4225      //                abstime <= GetRunInfo()->RUNTRAILER_TIME) &&          // -------------------------------------------------------------------
4226      //              !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)          run_tree->GetEntry(r);//update runinfo
4227      //                obt <= GetRunInfo()->RUNTRAILER_OBT)          if ( r > 0 ){
4228      //              )            totrunentrymin = totrunentrymax+1;
4229            } else {
4230      !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s)            totrunentrymin = 0LL;
4231          abstime <= GetRunInfo()->RUNTRAILER_TIME) || !(obt >= gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) && // additional check on OBT (ms) // Emiliano          }
4232          obt <= gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) // Emiliano          totrunentry += GetRunInfo()->NEVENTS;
4233          || GetRunInfo()->NEVENTS == 0          totrunentrymax = totrunentry - 1 - prevshift; // prevshift is needed to handle nested+DV_skipped packets
4234      //          || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento          irun = r;        
4235          || !(irunentry <= GetRunInfo()->NEVENTS - 1 - prevshift)) && irun < run_tree->GetEntries()) {          if ( fUseDBinRunInfo ){
4236              a = false;    
4237        //            if( !(abstime >= GetRunInfo()->RUNHEADER_TIME &&abstime <= GetRunInfo()->RUNTRAILER_TIME)  )cout << "ABS TIME "<<abstime << " " <<GetRunInfo()->RUNTRAILER_TIME <<endl;            b = false;
4238        //            if( !(obt >= GetRunInfo()->RUNHEADER_OBT && obt <= GetRunInfo()->RUNTRAILER_OBT) )cout << "OBT TIME "<< obt <<" "<< GetRunInfo()->RUNTRAILER_OBT << endl;            if ( obt < gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) ) a = true;
4239        //            if( GetRunInfo()->NEVENTS==0  )cout <<"GetRunInfo()->NEVENTS==0 "<<endl;            if ( obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ) b = true;
4240        //            if( !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift) ) cout << "irunentry > "<<GetRunInfo()->NEVENTS-1-prevshift << endl;          }
4241        // - - - - - - - - - - - - -          if ( (iev >= totrunentrymin && iev <= totrunentrymax) || // entry is inside run limits
4242        // irunentry = position of current entry, relative to the run               ( !isSync &&
4243        // prevshift = shift needed to synchronize l0 and l2 data (nested events)                 ( abstime >= GetRunInfo()->RUNHEADER_TIME  && a // or it is inside obt limits (and abstime limits for security reasons)
4244        // - - - - - - - - - - - - -                   && abstime <= GetRunInfo()->RUNTRAILER_TIME && b))  // or it is inside obt limits (and abstime limits for security reasons)
4245                 ){ // check on abstime and obt needed to handle nested+DV_skipped packets
4246        // -----------------------------------------            if ( totrunentrymin > iev ){ // there is a shift (nested+DV_skipped packets)
4247        // store dead and live-time of previous run              if ( !isSync ){
4248        // -----------------------------------------                if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - unconsistent iev - nevents, probable DBL0-L2 async\n");
4249        //            if(SELLI==0){                if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);
4250        if (SELLI != 2) {                //              printf("PamLevel2::UpdateRunInfo(Long64_t) - unconsistent iev - nevents, probable DBL0-L2 async\n");
4251          if (fromfirst) {                //              printf("PamLevel2::UpdateRunInfo(Long64_t) - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI
4252            if (oldrun == irun) {                prevshift += (totrunentrymin-iev); // add the new shift to total shift
4253              /// decrement counters                totrunentrymin -= (totrunentrymin-iev); // shift run position min
4254              if (GetTrigLevel2()) {                totrunentrymax -= (totrunentrymin-iev); // shift run position max
4255                totdltime[0] -= GetTrigLevel2()->dltime[0];//live-time                if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);
4256                totdltime[1] -= GetTrigLevel2()->dltime[1];//dead-time                //              printf("PamLevel2::UpdateRunInfo(Long64_t) - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI
4257              }              } else {
4258              totdltime[2]--; //event counter                printf(" PamLevel2::UpdateRunInfo(Long64_t) ERROR! sync file but unconsistent totrunetrymin %lld and iev %lld!!! \n",totrunentrymin,iev);
4259              if (DBG) {                cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
4260                cout << endl;                cout << "\nFor bug reporting instructions, please see for example:\n";
4261                cout << "n.events     : " << totdltime[2] << endl;                cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
4262                cout << "RUN LIVE-TIME: " << totdltime[0] * 0.16 << " ms" << endl;                cout << "  " << endl;
               cout << "RUN DEAD-TIME: " << totdltime[1] * 0.01 << " ms" << endl;  
4263              }              }
4264            }            }
4265            else {            runfirstentry = totrunentrymin; // first entry of the run in the level2
4266              totdltime[0] = 0;//live-time            
4267              totdltime[1] = 0;//dead-time  
4268              totdltime[2] = 0; //event counter            //
4269              if (DBG)            if ( fUseDBinRunInfo ){
4270                cout << " *** JUMP RUN *** irun " << irun << endl;              if (gltsync)
4271                  delete gltsync; // Emiliano
4272                if (!dbc || (dbc && !dbc->IsConnected()))
4273                  SetDBConnection(); //Emiliano
4274                gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano
4275                TrkParams::Set(GetRunInfo(), dbc);
4276                if (dbc){
4277                  dbc->Close(); // Emiliano
4278                  delete dbc;
4279                  dbc=0;
4280                }          
4281                if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano
4282                  cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun
4283                       << "  has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl;
4284                  cout
4285                    << "                                                            (NB!! in this case some events could be assigned to a wrong run)"
4286                    << endl;
4287                }
4288            }            }
4289            /// add an entry            //
4290            if (run_tree_clone)            if (DBG) printf(" found \n");
4291              if (run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())            //          printf(" found \n");//TOGLITOGLI
4292                run_tree_clone->GetBranch("DeadLiveTime")->Fill();            //
4293            /// reset counters            break;
4294            }
4295          } // loop over run
4296          
4297          // --------------------------------------
4298          // if there was no need to update the run
4299          // ---> exit with FALSE
4300          // --------------------------------------
4301          if (irun == oldrun){
4302            if (DBG) printf(" no new run \n");
4303            //        printf(" no new run \n");//TOGLITOGLI
4304            return (false);
4305          }      
4306          // --------------------------------------
4307          // ... otherwise
4308          // ---> exit with TRUE
4309          // --------------------------------------
4310    
4311          if (SELLI != 2) {
4312            /// decrement counters since this event belongs to a new run
4313            if (GetTrigLevel2()) {
4314              totdltime[0] -= GetTrigLevel2()->dltime[0];//live-time
4315              totdltime[1] -= GetTrigLevel2()->dltime[1];//dead-time
4316            }
4317            totdltime[2]--; //event counter
4318            if (DBG) {
4319              cout << endl;
4320              cout << "n.events     : " << totdltime[2] << endl;
4321              cout << "RUN LIVE-TIME: " << totdltime[0] * 0.16 << " ms" << endl;
4322              cout << "RUN DEAD-TIME: " << totdltime[1] * 0.01 << " ms" << endl;
4323            }
4324            // add an entry
4325            if (run_tree_clone && totdltime[2] > 0)
4326              if (run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
4327                run_tree_clone->GetBranch("DeadLiveTime")->Fill();
4328            // reset counters
4329            if ( totdltime[2] > 0 ){
4330            if (GetTrigLevel2()) {            if (GetTrigLevel2()) {
4331              totdltime[0] = GetTrigLevel2()->dltime[0];//live-time              totdltime[0] = GetTrigLevel2()->dltime[0];//live-time
4332              totdltime[1] = 0; //dead-time              totdltime[1] = 0; //dead-time
# Line 2991  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4334  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4334            totdltime[2] = 1; //event counter            totdltime[2] = 1; //event counter
4335          }          }
4336        }        }
       //            }  
4337    
4338        irun++;        if (DBG){
4339        // ------------------------------------          cout << endl << " ))))) UPDATE RUN INFO (((((  @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun
4340        // if the end of run tree is reached...               << endl;        
4341        // ------------------------------------          printf("2abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4342        if (irun == run_tree->GetEntries()) {          printf("2        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4343          if (!fromfirst) {          printf("2        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4344            // -----------------------------------------------------          if ( fUseDBinRunInfo ) printf("2        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4345            // if it happened already once and the run was not found          printf("2        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4346            // ---> exit with error          printf("2        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);
           // -----------------------------------------------------  
           cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- event entry #" << iev  
               << " does not belong to any run (should not happen)" << endl;  
           return false;  
         }  
         // -----------------------------------------  
         // ...otherwise repeat search from beginning  
         // -----------------------------------------  
         cout  
             << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- reached end of run tree. searchin again from beginning "  
             << endl;  
         fromfirst = false;  
         irun = 0LL;  
         runfirstentry = 0LL;  
4347        }        }
4348        // -------------------------------------------------------------------        //        printf("2abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4349        // save the index of the first entry of the run, relative to pam_tree,        //        printf("2        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4350        // and read a new run        //        printf("2        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4351        // -------------------------------------------------------------------        //        printf("2        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4352        if (irun > 0)        //        printf("2        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4353          runfirstentry += (GetRunInfo()->NEVENTS) - prevshift;        //        printf("2        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);//TOGLITOGLI
4354        irunentry = 0;  
4355        prevshift = 0;        return (true);
4356        run_tree->GetEntry(irun);//update runinfo      } // need for run upgrade
4357        irunt = irun - irunoffset[run_tree->GetTreeNumber()];      if (DBG) printf("return false\n");
4358        if (gltsync)      return (false);
4359          delete gltsync; // Emiliano    }// SELLI = 0 SELLI = 2
4360        if (!dbc || (dbc && !dbc->IsConnected()))    
         SetDBConnection(); //Emiliano  
       gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano  
       if (dbc){  
         dbc->Close(); // Emiliano  
         dbc=0;  
       };  
       if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano  
         cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun  
             << "  has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl;  
         cout  
             << "                                                            (NB!! in this case some events are assigned to a wrong run)"  
             << endl;  
       }  
       //            if(hasfrag &&  fragid != GetRunInfo()->ID){  
       //                cout << "... where is the next fragment ??"<<endl;  
       //            }  
     };  
   
     // --------------------------------------  
     // if there was no need to update the run  
     // ---> exit with FALSE  
     // --------------------------------------  
     if (irun == oldrun)  
       return (false);  
   
     // --------------------------------------  
     // ... otherwise  
     // --------------------------------------  
   
   
     // --------------------------------------  
     // ---> exit with TRUE  
     // --------------------------------------  
     if (DBG)  
       cout << endl << " ))))) UPDATE RUN INFO (((((  @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun  
           << endl;  
     // ----------------------------------------------------  
     // update the tracker parameters  
     // (non ho trovato nessun altro modo sicuro di farlo...)  
     // ----------------------------------------------------  
     if (!dbc || (dbc && !dbc->IsConnected()))  
       SetDBConnection();  
     TrkParams::Set(GetRunInfo(), dbc);  
     if (dbc){  
       dbc->Close();  
       dbc=0;  
     };  
   
     // ----------------------------------------------------  
     // then check if the run has a fragment  
     // in this case we have to switch to the next fragment  
     // when the end of the first fragment is reached  
     // ----------------------------------------------------  
     if (GetRunInfo()->ID_RUN_FRAG != 0 &&  
     //      GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&  
         DBG && true) {  
       cout << "* fragment *" << endl;  
     }  
   
     return (true);  
   };  
4361    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
4362    // if it is a preselected file (there is SelectionList)    // if it is a preselected file (there is SelectionList)
4363    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# Line 3165  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4432  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4432        // update the tracker parameters        // update the tracker parameters
4433        // (non ho trovato nessun altro modo sicuro di farlo...)        // (non ho trovato nessun altro modo sicuro di farlo...)
4434        // ----------------------------------------------------        // ----------------------------------------------------
4435        if (!dbc || (dbc && !dbc->IsConnected()))        if ( fUseDBinRunInfo ){
4436          SetDBConnection();          if (!dbc || (dbc && !dbc->IsConnected()))
4437        TrkParams::Set(GetRunInfo(), dbc);            SetDBConnection();
4438        if (dbc){          TrkParams::Set(GetRunInfo(), dbc);
4439          dbc->Close();          if (dbc){
4440          dbc=0;            dbc->Close();
4441        };            delete dbc;
4442              dbc=0;
4443            }
4444          }
4445        //            cout << endl;        //            cout << endl;
4446        prevshift = 0;        prevshift = 0;
4447          yprevshift = 0;
4448        return true;        return true;
4449      }      }
4450      return false;      return false;
# Line 3182  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4453  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4453    return false;    return false;
4454    //    //
4455  }  }
4456  ;  
4457    /**
4458     * Update the runinfo informations (to be used to have Run infos event by event basis)
4459     * @param run Pointer to the chain/tree which contains run infos
4460     * @return true if a new run has been read, false if it is still the same run
4461     */
4462    Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) {
4463      return (UpdateRunInfo(iev));
4464    }
4465    
4466  /**  /**
4467   * Update the runinfo informations (to be used to have Run infos event by event basis)   * Update the runinfo informations (to be used to have Run infos event by event basis)
4468   * @param run Pointer to the chain/tree which contains run infos   * @param run Pointer to the chain/tree which contains run infos
# Line 3191  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4471  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4471  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev) {  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev) {
4472    return (UpdateRunInfo((TChain*) run, iev));    return (UpdateRunInfo((TChain*) run, iev));
4473  }  }
4474  ;  
4475    
4476  //--------------------------------------  //--------------------------------------
4477  //  //
# Line 3429  void PamLevel2::GetWhichTrees(TFile* f) Line 4709  void PamLevel2::GetWhichTrees(TFile* f)
4709    //    cout << "Checking file: "<<f->GetName()<<endl;    //    cout << "Checking file: "<<f->GetName()<<endl;
4710    if (!f || f->IsZombie()) {    if (!f || f->IsZombie()) {
4711      cout << "File: " << f->GetName() << " Non valid root file" << endl;      cout << "File: " << f->GetName() << " Non valid root file" << endl;
4712        fDiscarded = true;
4713      return;      return;
4714    }    }
4715    
# Line 3635  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4916  Bool_t PamLevel2::CheckLevel2File(TStrin
4916    TFile *f = new TFile(name.Data());    TFile *f = new TFile(name.Data());
4917    if (!f || f->IsZombie()) {    if (!f || f->IsZombie()) {
4918      cout << "File: " << f->GetName() << " discarded ---- Non valid root file" << endl;      cout << "File: " << f->GetName() << " discarded ---- Non valid root file" << endl;
4919        fDiscarded = true;
4920      return false;      return false;
4921    }    }
4922    //    cout << "Get list of keys: "<<f<<endl;    //    cout << "Get list of keys: "<<f<<endl;
# Line 3673  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4955  Bool_t PamLevel2::CheckLevel2File(TStrin
4955          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4956            cout << "File: " << f->GetName() << " discarded ---- SelectionList tree has " << nevt            cout << "File: " << f->GetName() << " discarded ---- SelectionList tree has " << nevt
4957                << " events instead of " << nev << endl;                << " events instead of " << nev << endl;
4958              fDiscarded = true;
4959            return false;            return false;
4960          }          }
4961          nev = nevt;          nev = nevt;
# Line 3687  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4970  Bool_t PamLevel2::CheckLevel2File(TStrin
4970          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4971            cout << "File: " << f->GetName() << " discarded ---- Trigger tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- Trigger tree has " << nevt << " events instead of "
4972                << nev << endl;                << nev << endl;
4973              fDiscarded = true;
4974            return false;            return false;
4975          }          }
4976          nev = nevt;          nev = nevt;
# Line 3700  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4984  Bool_t PamLevel2::CheckLevel2File(TStrin
4984          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4985            cout << "File: " << f->GetName() << " discarded ---- ToF tree has " << nevt << " events instead of " << nev            cout << "File: " << f->GetName() << " discarded ---- ToF tree has " << nevt << " events instead of " << nev
4986                << endl;                << endl;
4987              fDiscarded = true;
4988            return false;            return false;
4989          }          }
4990          nev = nevt;          nev = nevt;
# Line 3713  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4998  Bool_t PamLevel2::CheckLevel2File(TStrin
4998          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4999            cout << "File: " << f->GetName() << " discarded ---- S4 tree has " << nevt << " events instead of " << nev            cout << "File: " << f->GetName() << " discarded ---- S4 tree has " << nevt << " events instead of " << nev
5000                << endl;                << endl;
5001              fDiscarded = true;
5002            return false;            return false;
5003          }          }
5004          nev = nevt;          nev = nevt;
# Line 3727  Bool_t PamLevel2::CheckLevel2File(TStrin Line 5013  Bool_t PamLevel2::CheckLevel2File(TStrin
5013          if (nev && nevt != nev) {          if (nev && nevt != nev) {
5014            cout << "File: " << f->GetName() << " discarded ---- NeutronD tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- NeutronD tree has " << nevt << " events instead of "
5015                << nev << endl;                << nev << endl;
5016              fDiscarded = true;
5017            return false;            return false;
5018          }          }
5019          nev = nevt;          nev = nevt;
# Line 3740  Bool_t PamLevel2::CheckLevel2File(TStrin Line 5027  Bool_t PamLevel2::CheckLevel2File(TStrin
5027          if (nev && nevt != nev) {          if (nev && nevt != nev) {
5028            cout << "File: " << f->GetName() << " discarded ---- Anticounter tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- Anticounter tree has " << nevt << " events instead of "
5029                << nev << endl;                << nev << endl;
5030              fDiscarded = true;
5031            return false;            return false;
5032          }          }
5033          nev = nevt;          nev = nevt;
# Line 3753  Bool_t PamLevel2::CheckLevel2File(TStrin Line 5041  Bool_t PamLevel2::CheckLevel2File(TStrin
5041          if (nev && nevt != nev) {          if (nev && nevt != nev) {
5042            cout << "File: " << f->GetName() << " discarded ---- OrbitalInfo tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- OrbitalInfo tree has " << nevt << " events instead of "
5043                << nev << endl;                << nev << endl;
5044              fDiscarded = true;
5045            return false;            return false;
5046          }          }
5047          nev = nevt;          nev = nevt;
# Line 3766  Bool_t PamLevel2::CheckLevel2File(TStrin Line 5055  Bool_t PamLevel2::CheckLevel2File(TStrin
5055          if (nev && nevt != nev) {          if (nev && nevt != nev) {
5056            cout << "File: " << f->GetName() << " discarded ---- Tracker tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- Tracker tree has " << nevt << " events instead of "
5057                << nev << endl;                << nev << endl;
5058              fDiscarded = true;
5059            return false;            return false;
5060          }          }
5061          nev = nevt;          nev = nevt;
# Line 3789  Bool_t PamLevel2::CheckLevel2File(TStrin Line 5079  Bool_t PamLevel2::CheckLevel2File(TStrin
5079          if (nev && nevt != nev) {          if (nev && nevt != nev) {
5080            cout << "File: " << f->GetName() << " discarded ---- Calorimeter tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- Calorimeter tree has " << nevt << " events instead of "
5081                << nev << endl;                << nev << endl;
5082              fDiscarded = true;
5083            return false;            return false;
5084          }          }
5085          nev = nevt;          nev = nevt;
# Line 3811  Bool_t PamLevel2::CheckLevel2File(TStrin Line 5102  Bool_t PamLevel2::CheckLevel2File(TStrin
5102          if (nev && nevt != nev) {          if (nev && nevt != nev) {
5103            cout << "File: " << f->GetName() << " discarded ---- h20 tree has " << nevt << " events instead of " << nev            cout << "File: " << f->GetName() << " discarded ---- h20 tree has " << nevt << " events instead of " << nev
5104                << endl;                << endl;
5105              fDiscarded = true;
5106            return false;            return false;
5107          }          }
5108          nev = nevt;          nev = nevt;
# Line 3823  Bool_t PamLevel2::CheckLevel2File(TStrin Line 5115  Bool_t PamLevel2::CheckLevel2File(TStrin
5115      SELLI = (Int_t) SELLI__ok;      SELLI = (Int_t) SELLI__ok;
5116    if (SELLI == 0 && SELLI__ok) {    if (SELLI == 0 && SELLI__ok) {
5117      cout << "File: " << f->GetName() << " discarded ---- found SelectionList (it is not a full-event file)" << endl;      cout << "File: " << f->GetName() << " discarded ---- found SelectionList (it is not a full-event file)" << endl;
5118        fDiscarded = true;
5119      return false;      return false;
5120    }    }
5121    if (SELLI == 1 && !SELLI__ok) {    if (SELLI == 1 && !SELLI__ok) {
5122      cout << "File: " << f->GetName() << " discarded ---- SelectionList missing" << endl;      cout << "File: " << f->GetName() << " discarded ---- SelectionList missing" << endl;
5123        fDiscarded = true;
5124      return false;      return false;
5125    }    }
5126    
# Line 3865  Bool_t PamLevel2::CheckLevel2File(TStrin Line 5159  Bool_t PamLevel2::CheckLevel2File(TStrin
5159    
5160    if (CAL1 && !CAL1__ok) {    if (CAL1 && !CAL1__ok) {
5161      cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel1 branch" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel1 branch" << endl;
5162        fDiscarded = true;
5163      return false;      return false;
5164    };    };
5165    if (CAL2 && !CAL2__ok) {    if (CAL2 && !CAL2__ok) {
5166      cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel2 branch" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel2 branch" << endl;
5167        fDiscarded = true;
5168      return false;      return false;
5169    };    };
5170    if (TRK2 && !TRK2__ok) {    if (TRK2 && !TRK2__ok) {
5171      cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel2 branch" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel2 branch" << endl;
5172        fDiscarded = true;
5173      return false;      return false;
5174    };    };
5175    if (TRK1 && !TRK1__ok) {    if (TRK1 && !TRK1__ok) {
5176      cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel1 branch" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel1 branch" << endl;
5177        fDiscarded = true;
5178      return false;      return false;
5179    };    };
5180    if (TRKh && !TRKh__ok) {    if (TRKh && !TRKh__ok) {
5181      cout << "File: " << f->GetName() << " discarded ---- Missing TrkHough branch" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing TrkHough branch" << endl;
5182        fDiscarded = true;
5183      return false;      return false;
5184    };    };
5185    if (ORB && !ORB__ok) {    if (ORB && !ORB__ok) {
5186      cout << "File: " << f->GetName() << " discarded ---- Missing ORB tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing ORB tree" << endl;
5187        fDiscarded = true;
5188      return false;      return false;
5189    };    };
5190    if (AC && !AC__ok) {    if (AC && !AC__ok) {
5191      cout << "File: " << f->GetName() << " discarded ---- Missing AC tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing AC tree" << endl;
5192        fDiscarded = true;
5193      return false;      return false;
5194    };    };
5195    if (S4 && !S4__ok) {    if (S4 && !S4__ok) {
5196      cout << "File: " << f->GetName() << " discarded ---- Missing S4 tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing S4 tree" << endl;
5197        fDiscarded = true;
5198      return false;      return false;
5199    };    };
5200    if (TOF && !TOF__ok) {    if (TOF && !TOF__ok) {
5201      cout << "File: " << f->GetName() << " discarded ---- Missing ToF tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing ToF tree" << endl;
5202        fDiscarded = true;
5203      return false;      return false;
5204    };    };
5205    
5206    if (ND && !ND__ok) {    if (ND && !ND__ok) {
5207      cout << "File: " << f->GetName() << " discarded ---- Missing ND tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing ND tree" << endl;
5208        fDiscarded = true;
5209      return false;      return false;
5210    };    };
5211    if (TRG && !TRG__ok) {    if (TRG && !TRG__ok) {
5212      cout << "File: " << f->GetName() << " discarded ---- Missing Trigger tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing Trigger tree" << endl;
5213        fDiscarded = true;
5214      return false;      return false;
5215    };    };
5216    if (GP && !GP__ok) {    if (GP && !GP__ok) {
5217      cout << "File: " << f->GetName() << " discarded ---- Missing h20 tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing h20 tree" << endl;
5218        fDiscarded = true;
5219      return false;      return false;
5220    };    };
5221    
# Line 4009  void PamLevel2::CreateCloneTrees(TFile * Line 5315  void PamLevel2::CreateCloneTrees(TFile *
5315      //  cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;      //  cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;
5316      run_tree_clone->Fill();      run_tree_clone->Fill();
5317    }    }
5318    cout << "----------------------------------------------------" << endl;    //
5319      // replicate processinginfo tree
5320      //
5321      if ( PROC ){ // EMEMEM
5322        proc_tree_clone = new TTree("ProcessingInfo","Log of data processing");
5323        proc_tree_clone->Branch("ProcInfo", "ProcInfo", GetPointerTo("ProcInfo"));
5324        cout << "ProcessingInfo: branch ProcessingInfo" << endl;  
5325        // ------------------
5326        // replicate processinginfo tree
5327        // ------------------
5328        //    cout << "----------------------------------------------------"<<endl;
5329        //    cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
5330        for (Int_t i = 0; i < proc_tree->GetEntries(); i++) {
5331          proc_tree->GetEntry(i);
5332          //      cout << i<< "\t | "<<endl;
5333          proc_tree_clone->Fill();
5334        }
5335        if ( SELLI != 2 ){      
5336          proc_obj->runID = 0;
5337          TTimeStamp *dt = new TTimeStamp();
5338          proc_obj->date = dt->AsString();
5339          delete dt;
5340          proc_obj->commandLine = Form("PamelaLevel2 was called: CAL2 %i CAL1 %i CAL0 %i TRK2 %i TRK1 %i TRKh %i TRK0 %i TOF %i TOF0 %i TRG %i \n                                            S4 %i ND %i AC %i ORB %i GP %i EXT %i NUC %i RUN %i ISGP %i SELLI %i \n Custom string   = %s",CAL2,CAL1,CAL0,TRK2,TRK1,TRKh,TRK0,TOF,TOF0,TRG,S4,ND,AC,ORB,GP,EXT,NUC,RUN,ISGP,SELLI,customString.Data());
5341          proc_obj->outputFilename = ofile->GetName();
5342          proc_obj->localDir = gSystem->WorkingDirectory();
5343          proc_obj->uname = gSystem->GetFromPipe("uname -a");
5344          if (!dbc || (dbc && !dbc->IsConnected())) SetDBConnection();
5345          proc_obj->DB = Form("mysql://%s/%s",dbc->GetHost(),dbc->GetDB());
5346          dbc->Close();
5347          proc_tree_clone->Fill();
5348        }
5349        cout << "----------------------------------------------------" << endl;
5350      }
5351    // ------------------------------------    // ------------------------------------
5352    // add branch with dead and live times    // add branch with dead and live times
5353    // ------------------------------------    // ------------------------------------
# Line 4022  void PamLevel2::CreateCloneTrees(TFile * Line 5359  void PamLevel2::CreateCloneTrees(TFile *
5359      //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");      //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
5360      sel_tree_clone->Branch("RunEntry", &irunt, "runentry/L");//NEWNEW      sel_tree_clone->Branch("RunEntry", &irunt, "runentry/L");//NEWNEW
5361      sel_tree_clone->Branch("EventEntry", &irunentry, "eventry/L");      sel_tree_clone->Branch("EventEntry", &irunentry, "eventry/L");
5362        //    if ( hasL0EE ) sel_tree_clone->Branch("L0EventEntry", &il0entry, "l0eventry/L");
5363    };    };
5364    
5365    Int_t i = 0;    Int_t i = 0;
# Line 4041  void PamLevel2::CreateCloneTrees(TFile * Line 5379  void PamLevel2::CreateCloneTrees(TFile *
5379        pam_tree_clone[i]->Branch("TrkHough", "TrkHough", GetPointerTo("TrkHough"));        pam_tree_clone[i]->Branch("TrkHough", "TrkHough", GetPointerTo("TrkHough"));
5380        cout << "Tracker      : branch TrkHough" << endl;        cout << "Tracker      : branch TrkHough" << endl;
5381      };      };
5382        if(NUC){
5383            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&trk_nuc_obj);
5384            cout << "Tracker      : branch TrackNuclei" << endl;    
5385        }
5386        if(EXT){
5387            pam_tree_clone[i]->Branch("extAlgFlag",&extAlgFlag,"extAlgFlag/I");
5388            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&trk_ext_obj);
5389            cout << "Tracker      : branch RecoveredTrack" << endl;
5390            if(NUC){
5391                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&trk_ext_nuc_obj);
5392                cout << "Tracker      : branch RecoveredTrackNuclei" << endl;                  
5393            }
5394        }
5395    
5396      i++;      i++;
5397    }    }
5398    
# Line 4055  void PamLevel2::CreateCloneTrees(TFile * Line 5407  void PamLevel2::CreateCloneTrees(TFile *
5407        pam_tree_clone[i]->Branch("CaloLevel2", "CaloLevel2", GetPointerTo("CaloLevel2"));        pam_tree_clone[i]->Branch("CaloLevel2", "CaloLevel2", GetPointerTo("CaloLevel2"));
5408        cout << "Calorimeter  : branch CaloLevel2" << endl;        cout << "Calorimeter  : branch CaloLevel2" << endl;
5409      };      };
5410        if(NUC){
5411            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&calo_nuc_obj);
5412            cout << "Calorimeter  : branch TrackNuclei" << endl;    
5413        }
5414        if(EXT){
5415            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&calo_ext_obj);
5416            cout << "Calorimeter  : branch RecoveredTrack" << endl;
5417            if(NUC){
5418                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&calo_ext_nuc_obj);
5419                cout << "Calorimeter  : branch RecoveredTrackNuclei" << endl;                  
5420            }
5421        }
5422      i++;      i++;
5423    }    }
5424    
# Line 4063  void PamLevel2::CreateCloneTrees(TFile * Line 5427  void PamLevel2::CreateCloneTrees(TFile *
5427      pam_tree_clone[i] = new TTree("ToF", "PAMELA ToF level2 data ");      pam_tree_clone[i] = new TTree("ToF", "PAMELA ToF level2 data ");
5428      pam_tree_clone[i]->Branch("ToFLevel2", "ToFLevel2", GetPointerTo("ToFLevel2"));      pam_tree_clone[i]->Branch("ToFLevel2", "ToFLevel2", GetPointerTo("ToFLevel2"));
5429      cout << "ToF          : branch ToFLevel2" << endl;      cout << "ToF          : branch ToFLevel2" << endl;
5430        if(NUC){
5431            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&tof_nuc_obj);
5432            cout << "ToF          : branch TrackNuclei" << endl;    
5433        }
5434        if(EXT){
5435            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&tof_ext_obj);
5436            cout << "ToF          : branch RecoveredTrack" << endl;
5437            if(NUC){
5438                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&tof_ext_nuc_obj);
5439                cout << "ToF          : branch RecoveredTrackNuclei" << endl;                  
5440            }
5441        }
5442      i++;      i++;
5443    };    };
5444    // Trigger    // Trigger
# Line 4098  void PamLevel2::CreateCloneTrees(TFile * Line 5474  void PamLevel2::CreateCloneTrees(TFile *
5474      pam_tree_clone[i] = new TTree("OrbitalInfo", "PAMELA orbital info  ");      pam_tree_clone[i] = new TTree("OrbitalInfo", "PAMELA orbital info  ");
5475      pam_tree_clone[i]->Branch("OrbitalInfo", "OrbitalInfo", GetPointerTo("OrbitalInfo"));      pam_tree_clone[i]->Branch("OrbitalInfo", "OrbitalInfo", GetPointerTo("OrbitalInfo"));
5476      cout << "OrbitalInfo  : branch OrbitalInfo" << endl;      cout << "OrbitalInfo  : branch OrbitalInfo" << endl;
5477        if(NUC){
5478            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&orb_nuc_obj);
5479            cout << "OrbitalInfo  : branch TrackNuclei" << endl;    
5480        }
5481        if(EXT){
5482            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&orb_ext_obj);
5483            cout << "OrbitalInfo  : branch RecoveredTrack" << endl;
5484            if(NUC){
5485                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&orb_ext_nuc_obj);
5486                cout << "OrbitalInfo  : branch RecoveredTrackNuclei" << endl;                  
5487            }
5488        }
5489      i++;      i++;
5490    };    };
5491    // GPamela    // GPamela
5492    if (GP) {    if (GP) {
5493      pam_tree_clone[i] = new TTree("h20", "GPAMELA info ");      pam_tree_clone[i] = new TTree("h20", "GPAMELA info ");
5494      pam_tree_clone[i]->Branch("GPamela", "GPamela", GetPointerTo("GPamela"), 32000, 1);//split      pam_tree_clone[i]->Branch("GPamela", "GPamela", GetPointerTo("GPamela"), 32000, 1);//split
5495      cout << "OrbitalInfo  : branch OrbitalInfo" << endl;      cout << "GPamela  : branch GPamela" << endl;
5496      i++;      i++;
5497    };    };
5498    
5499    
5500    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
5501    
5502  }  }
# Line 4148  TTree* PamLevel2::GetCloneTree(TString n Line 5538  TTree* PamLevel2::GetCloneTree(TString n
5538      if (!name.CompareTo(na))      if (!name.CompareTo(na))
5539        return sel_tree_clone;        return sel_tree_clone;
5540    }    }
5541      if (proc_tree_clone && PROC) {
5542        TString na = proc_tree_clone->GetName();
5543        if (!name.CompareTo(na))
5544          return proc_tree_clone;
5545      }
5546    return NULL;    return NULL;
5547    
5548  }  }
# Line 4167  void PamLevel2::WriteCloneTrees() { Line 5562  void PamLevel2::WriteCloneTrees() {
5562    for (Int_t i = 0; i < NCLONES; i++) {    for (Int_t i = 0; i < NCLONES; i++) {
5563      if (pam_tree_clone[i]) {      if (pam_tree_clone[i]) {
5564        cout << pam_tree_clone[i]->GetName() << endl;        cout << pam_tree_clone[i]->GetName() << endl;
5565        pam_tree_clone[i]->Write();        pam_tree_clone[i]->Write(pam_tree_clone[i]->GetName(),TObject::kOverwrite);
5566      };      };
5567    }    }
5568      
5569      if ( PROC ){//EMEMEMEM
5570        proc_tree_clone->Write("ProcessingInfo",TObject::kOverwrite);
5571      }
5572    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
5573    
5574  }  }
# Line 4177  void PamLevel2::WriteCloneTrees() { Line 5576  void PamLevel2::WriteCloneTrees() {
5576  /**  /**
5577   * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry.   * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry.
5578   */   */
 //Int_t PamLevel2::GetEntry(Int_t iee){  
5579  Int_t PamLevel2::GetEntry(Long64_t iee) {  Int_t PamLevel2::GetEntry(Long64_t iee) {
5580    
   //     cout << "-------------------------------------"<<endl;  
   //     cout << "Int_t PamLevel2::GetEntry("<<iee<<")"<<endl;  
   
5581    if (!pam_tree) {    if (!pam_tree) {
5582      cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded" << endl;      cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded" << endl;
5583      return 0;      return 0;
# Line 4196  Int_t PamLevel2::GetEntry(Long64_t iee) Line 5591  Int_t PamLevel2::GetEntry(Long64_t iee)
5591    //    return 0;    //    return 0;
5592    //    }    //    }
5593    
   Long64_t ii = 0;  
5594    //-------------------------------    //-------------------------------
5595    ii = iee;    if (!pam_tree->GetEntry(iee)) {
   if (!pam_tree->GetEntry(ii)) {  
5596      cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree" << endl;      cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree" << endl;
5597      return 0;      return 0;
5598    }    }
# Line 4219  Int_t PamLevel2::GetEntry(Long64_t iee) Line 5612  Int_t PamLevel2::GetEntry(Long64_t iee)
5612    }    }
5613    
5614    //-------------------------------    //-------------------------------
5615    ii = iee;    //
5616    //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii);    if ( fUpdateRunInfo ) UpdateRunInfo(iee); // Emiliano
5617    //    Bool_t UPDATED = UpdateRunInfo(ii);    if (SELLI == 0 || SELLI == 2) irunentry = iee - runfirstentry;
   UpdateRunInfo(ii);  
   if (SELLI == 0 || SELLI == 2)  
     irunentry = iee - runfirstentry;  
   //    if(UPDATED && run_tree_clone)run_tree_clone->Fill();  
   
   //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;  
   
   //     cout << "irunentry     "<<irunentry << endl;  
   //     cout << "runfirstentry "<<runfirstentry << endl;  
   //     cout << "nevents       "<<GetRunInfo()->NEVENTS<< endl;  
   
   //     if( TRK0 || CAL0 || TOF0 ){  
   //    if( !GetYodaEntry( ) ){  
   //        cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<<endl;  
   //        return 0;  
   //    }  
   //     }  
   
5618    
5619    return 1;    return 1;
5620    
# Line 4280  TTree* PamLevel2::GetYodaTree() { Line 5655  TTree* PamLevel2::GetYodaTree() {
5655    //===================================    //===================================
5656    if (irun < 0) {    if (irun < 0) {
5657      cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = " << irun << endl;      cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = " << irun << endl;
5658      //  cout << "In order to use this method you have to first load the RunInfo tree "<<endl;      if (DBG) cout << "In order to use this method you have to first load the RunInfo tree "<<endl;
5659      return NULL;      return NULL;
5660    }    }
5661    Int_t irootnew = run_obj->ID_ROOT_L0;    Int_t irootnew = GetRunInfo()->ID_ROOT_L0;
5662    //      cout << "iroot    "<<iroot<<endl;    if (DBG){
5663    //      cout << "irootnew "<<irootnew<<endl;      cout << "iroot    "<<iroot<<endl;
5664        cout << "irootnew "<<irootnew<<endl;
5665      }
5666    
5667    //===================================    //===================================
5668    // load the level0 file    // load the level0 file
# Line 4323  TTree* PamLevel2::GetYodaTree() { Line 5700  TTree* PamLevel2::GetYodaTree() {
5700      if (!h0_obj)      if (!h0_obj)
5701        h0_obj = new EventHeader();        h0_obj = new EventHeader();
5702      l0_tree->SetBranchAddress("Header", &h0_obj);      l0_tree->SetBranchAddress("Header", &h0_obj);
5703      prevshift = 0;      yprevshift = 0; // yes, yprevshift is the shift in the level0, prevshift is the shift in the level2
5704      //---------------------------------------------------      //---------------------------------------------------
5705      // TRACKER:      // TRACKER:
5706      if (TRK0) {      if (TRK0) {
# Line 4341  TTree* PamLevel2::GetYodaTree() { Line 5718  TTree* PamLevel2::GetYodaTree() {
5718          calo0_obj->Set();          calo0_obj->Set();
5719        };        };
5720        l0_tree->SetBranchAddress("Calorimeter", calo0_obj->GetPointerToCalorimeterEvent());        l0_tree->SetBranchAddress("Calorimeter", calo0_obj->GetPointerToCalorimeterEvent());
       //            cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;  
5721      }      }
5722      //---------------------------------------------------      //---------------------------------------------------
5723      // TOF:      // TOF:
# Line 4350  TTree* PamLevel2::GetYodaTree() { Line 5726  TTree* PamLevel2::GetYodaTree() {
5726      }      }
5727    
5728      dbc->Close(); // EMILIANO, do not leave open connections, open only when needed      dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
5729        delete dbc;
5730      dbc=0;      dbc=0;
5731    
5732    };    };
5733    
   //     if(!dbc || (dbc && !dbc->IsConnected())){  
   //    cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;  
   //     }  
   
5734    if (TRK0) {    if (TRK0) {
5735      //  TrkParams::Load(6);      if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
     //  if( !TrkParams::IsLoaded(6) ){  
     //      cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;  
     //  };  
     if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection(); // PERCHE` ERA COMMENTATA QUESTA RIGA?  
5736      TrkParams::SetCalib(run_obj, dbc);      TrkParams::SetCalib(run_obj, dbc);
5737      TrkParams::LoadCalib();      TrkParams::LoadCalib();
5738      if (!TrkParams::CalibIsLoaded()) {      if (!TrkParams::CalibIsLoaded()) {
# Line 4371  TTree* PamLevel2::GetYodaTree() { Line 5740  TTree* PamLevel2::GetYodaTree() {
5740      };      };
5741      if(dbc){      if(dbc){
5742        dbc->Close(); // EMILIANO, do not leave open connections, open only when needed        dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
5743          delete dbc;
5744        dbc=0;        dbc=0;
5745      };      };
5746    }    }
   
   //    cout << l0_tree << endl;  
5747    return l0_tree;    return l0_tree;
   
5748  }  }
5749    
5750  /**  /**
# Line 4385  TTree* PamLevel2::GetYodaTree() { Line 5752  TTree* PamLevel2::GetYodaTree() {
5752   */   */
5753  Int_t PamLevel2::GetYodaEntry() {  Int_t PamLevel2::GetYodaEntry() {
5754    
5755    //    cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;    Long64_t iev = this->GetReadEntry();
   if (!GetYodaTree())  
     return 0;  
5756    
5757    // patch    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
5758    if (irunentry < 0) {    // if it is a full file (not preselected)
5759      //  cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
5760      irunentry = 0LL;    //  if (SELLI == 0 || SELLI == 2 || !hasL0EE) {
   }  
   //  ---------------------------------  
   //  if file is NOT a preselected file  
   //  ---------------------------------  
   Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM);  
   //     cout << " irunentry "<<irunentry<<endl;  
   //     cout << " EV_FROM "<<run_obj->EV_FROM<<endl;  
   //     cout << " quellagiusta = irunentry + EV_FROM "<< quellagiusta << endl;  
   
   //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;  
   //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;  
   //     cout << " time "<< abstime << endl;  
   //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;  
5761    
5762    ULong64_t obt = 0;      if (!GetYodaTree()){
5763    ULong64_t pktn = 0;        printf(" PamLevel2::GetYodaEntry() : ERROR no level0 file loaded!\n");
5764    if (GetOrbitalInfo()) {        return 0;
5765      obt = GetOrbitalInfo()->OBT;      }
     pktn = GetOrbitalInfo()->pkt_num;  
   }  
5766    
5767    if (!GetOrbitalInfo() && !ISGP) {      if (irunentry < 0) {
5768      cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo " << endl;        if (DBG) cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
5769      return 0;        //      cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl; // TOGLITOGLI
5770    }        irunentry = 0LL;
5771    if (obt == 0 && pktn == 0 && !ISGP) {      }
5772      cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? " << endl;      //  ---------------------------------
5773      return 0;      //  if file is NOT a preselected file
5774    }      //  ---------------------------------
5775        Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM); // prevshift already included in irunentry
5776    
5777        if (DBG){
5778          cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
5779          cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
5780          cout << " time "<< abstime << endl;
5781        }
5782    
5783        ULong64_t obt = 0;
5784        ULong64_t pktn = 0;
5785        if (GetOrbitalInfo()) {
5786          obt = GetOrbitalInfo()->OBT;
5787          pktn = GetOrbitalInfo()->pkt_num;
5788        }
5789    
5790    // ---------------------------------------------------------------------      if (!GetOrbitalInfo() && !ISGP) {
5791    // ATTENTION!!!        cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo " << endl;
5792    // If data are not pre-processed with cleaner, the level0 tree may contain        return 0;
   // spurious nested physics packets.  
   // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries  
   // while level2 tree DOES NOT!!  
   // This means that "quellagiusta" in these cases is not correct.  
   // In order to retrieve the correct level0 event, I implemented a check  
   // of the OBT and pkt-number. In case of mismatch, the level0 entry number  
   // is shift forward until when the packets match.  
   // ---------------------------------------------------------------------  
   Int_t answer = 0;  
   Int_t shift = 0;  
   //    printf(" siamo qui %i %i \n",shift,prevshift);  
   //    Int_t maxshift = 50; // EMILIANO  
   do {  
     if (shift > 0) {  
       cout << " PKTNUM  L2 --- " << pktn << " --- L0 --- " << GetEventHeader()->GetPscuHeader()->GetCounter() << endl;  
       if (DBG)  
         cout << "         RUN: ID " << GetRunInfo()->ID << " ID_ROOT_L0 " << run_obj->ID_ROOT_L0 << " ID_RUN_FRAG "  
             << GetRunInfo()->ID_RUN_FRAG << " EV_FROM " << GetRunInfo()->EV_FROM << endl;  
       if (DBG)  
         cout << "         L2 <--> L0 mismatch ( irun " << irun << " irunentry " << irunentry << " shift " << shift  
             << " prevshift " << prevshift << " )" << endl;  
5793      }      }
5794      answer = l0_tree->GetEntry(quellagiusta + (Long64_t) shift + (Long64_t) prevshift);      if (obt == 0 && pktn == 0 && !ISGP) {
5795      shift++;        cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? " << endl;
     if (!GetEventHeader()) {  
       cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader " << endl;  
5796        return 0;        return 0;
5797      }      }
5798    
5799        // ---------------------------------------------------------------------
5800        // ATTENTION!!!
5801        // If data are not pre-processed with cleaner, the level0 tree may contain
5802        // spurious nested physics packets.
5803        // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries
5804        // while level2 tree DOES NOT!!
5805        // This means that "quellagiusta" in these cases is not correct.
5806        // In order to retrieve the correct level0 event, I implemented a check
5807        // of the OBT and pkt-number. In case of mismatch, the level0 entry number
5808        // is shift forward until when the packets match.
5809        // ---------------------------------------------------------------------
5810        Long64_t shift = 0LL;
5811        Long64_t answer = quellagiusta + shift + yprevshift;
5812        Int_t readl0 = 0;
5813        readl0 = l0_tree->GetEntry(answer); // prevshift already included in irunentry
5814    
5815        if (DBG){
5816          printf(" siamo qui shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);
5817        }
5818    
5819    
5820      if (ISGP) {      if (ISGP) {
5821        obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO        obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO
5822        pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO        pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO
5823      }      }
5824    
5825      //  cout << "PKTNUM "<<shift<<" ==  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;      while ( (obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta + (Long64_t) shift) < GetYodaTree()->GetEntries() && shift < maxshift ){
5826      //  cout << " L2 --- "<< obt << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;        if ( isSync && shift == 0LL ){
5827      //  if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;          printf(" PamLevel2::GetYodaEntry() ERROR! sync file but the level0 entry not found in place!!! \n");
5828      //  cout << " obt "<< obt << endl;          cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5829      //  cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;          cout << "\nFor bug reporting instructions, please see for example:\n";
5830      //  cout << " pktn "<< pktn << endl;          cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5831      //  cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;          cout << "  " << endl;
5832      //  printf(" IDRUN %u \n",GetRunInfo()->ID);        }
5833      //        if (shift > 0) {
5834      if (prevshift != 0 && (quellagiusta + (Long64_t) shift) == GetYodaTree()->GetEntries()) {          if (DBG) cout << " PKTNUM  L2 --- " << pktn << " --- L0 --- " << GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
5835        prevshift = 0;          if (DBG)
5836        shift = -1;            cout << "         RUN: ID " << GetRunInfo()->ID << " ID_ROOT_L0 " << run_obj->ID_ROOT_L0 << " ID_RUN_FRAG "
5837      };                 << GetRunInfo()->ID_RUN_FRAG << " EV_FROM " << GetRunInfo()->EV_FROM << endl;
5838            if (DBG)
5839              cout << "         L2 <--> L0 mismatch ( irun " << irun << " irunentry " << irunentry << " shift " << shift
5840                   << " prevshift " << prevshift << " )" << endl;
5841          }
5842          answer = quellagiusta +  shift+ yprevshift;
5843          readl0 = l0_tree->GetEntry(answer);
5844          //      printf(" inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5845    
5846    } while ((obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(        if (!GetEventHeader()) {
5847        GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta + (Long64_t) shift)          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader " << endl;
5848        < GetYodaTree()->GetEntries() && shift < maxshift);          return 0;
5849          }
5850    
5851    if ((quellagiusta + (Long64_t) shift + (Long64_t) prevshift) > GetYodaTree()->GetEntries() || shift == maxshift) {        //
5852      cout << " Big trouble here, no such event in Level0 data! (NB maxshift set to " << maxshift << " )" << endl;        if (yprevshift != 0 && (quellagiusta + (Long64_t) shift) == GetYodaTree()->GetEntries()) {
5853      return 0;          if (DBG) printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);
5854    }          //        printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5855    //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;          yprevshift = 0LL;
5856    //    return GetYodaTree()->GetEntry(quellagiusta);          shift = -1LL;
5857    if (shift > 1)        };
5858      prevshift += (shift - 1);      
5859          shift++;
5860        }
5861                                      
5862    
5863        if ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()) ){
5864          if ( isSync ){
5865            printf(" PamLevel2::GetYodaEntry() ERROR! sync file but the level0 entry not found AT ALL!!! \n");
5866            cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5867            cout << "\nFor bug reporting instructions, please see for example:\n";
5868            cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5869            cout << "  " << endl;
5870          }
5871          cout << "Int_t PamLevel2::GetYodaEntry() -- WARNING -- " << endl;
5872          cout << " Big trouble here, no such event in Level0 data! (NB maxshift set to " << maxshift << " )" << endl;    
5873          cout << " Nested and/or DarthVader skipped packets in fragmented run? checking and trying to fix " <<endl;
5874          // query the DB for runs containing the event, loop over LEVEL0 files which could contain the level0 event and try to find it
5875          // ma nel mezzo del cammin per ogni run che pesco devo vedere la posizione relativa di iev rispetto al runheader nel livello2 per andare a cercare nel posto giusto
5876          // connect to db
5877          if (!dbc || (dbc && !dbc->IsConnected())) SetDBConnection(); //Emiliano
5878          //
5879          if (GetOrbitalInfo()){
5880            abstime = GetOrbitalInfo()->absTime;
5881          } else {
5882            printf(" PamLevel2::GetYodaEntry() ERROR! no OrbitalInfo, cannot get the absolute time for event \n");
5883            return 0;
5884          }
5885          // query DB looking for runs containing the processed event
5886          TSQLResult *pResult;
5887          TSQLRow *Row = NULL;
5888          TString myquery = Form("select ID,NEVENTS from GL_RUN where RUNHEADER_TIME<=%lld and RUNTRAILER_TIME>=%lld;",abstime,abstime);
5889          if ( DBG ) printf(" query is %s \n",myquery.Data());
5890          //      printf(" query is %s \n",myquery.Data());// TOGLITOGLI
5891          pResult = dbc->Query(myquery.Data());    
5892          if (!pResult->GetRowCount()){
5893            printf(" PamLevel2::GetYodaEntry() ERROR! event is not included in any run!!! \n");
5894            cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5895            cout << "\nFor bug reporting instructions, please see for example:\n";
5896            cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5897            cout << "  " << endl;
5898            return 0;
5899          }
5900          if ( pResult->GetRowCount() == 1 ){
5901            if (DBG) printf(" PamLevel2::GetYodaEntry() - WARNING - YodaEntry not found but only one run containing the event, it should not happen \n");
5902            //        printf(" PamLevel2::GetYodaEntry() - WARNING - YodaEntry not found but only one run containing the event, it should not happen \n");//TOGLITOGLI
5903          }
5904          for( Int_t ru=0; ru < pResult->GetRowCount(); ru++){ // loop over runs containing the event
5905            if (Row) delete Row;
5906            Row = pResult->Next();  
5907            if( Row == NULL ) break;
5908            UInt_t idrun = (UInt_t)atoll(Row->GetField(0));
5909            UInt_t nev = (UInt_t)atoll(Row->GetField(1));
5910            if (DBG) printf(" inside loop over runs: ru %i idrun %i nev %i \n",ru,idrun,nev);
5911            //        printf(" inside loop over runs: ru %i idrun %i nev %i \n",ru,idrun,nev);//TOGLITOGLI
5912    
5913            // now look for this run in the level2 file, it must be present! code is taken from updateruninfo of course
5914            Bool_t rfound = false;
5915            totrunentry = 0LL;
5916            runfirstentry = 0LL;
5917            for (Int_t r=0; r< run_tree->GetEntries();r++){
5918              run_tree->GetEntry(r);//update runinfo
5919              if ( r > 0 ){
5920                totrunentrymin = totrunentrymax+1;
5921              } else {
5922                totrunentrymin = 0LL;
5923              }
5924              totrunentry += GetRunInfo()->NEVENTS;
5925              totrunentrymax = totrunentry - 1 - prevshift; // prevshift is needed to handle nested+DV_skipped packets
5926              irun = r;        
5927    
5928              if (idrun == GetRunInfo()->ID){
5929                if ( totrunentrymin > iev ){ // there is a shift (nested+DV_skipped packets)
5930                  if (DBG) printf("PamLevel2::GetYodaEntry - unconsistent iev - nevents, probable DBL0-L2 async\n");
5931                  if (DBG) printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);
5932                  //              printf("PamLevel2::GetYodaEntry - unconsistent iev - nevents, probable DBL0-L2 async\n");
5933                  //              printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI
5934                  prevshift += (totrunentrymin-iev); // add the new shift to total shift
5935                  totrunentrymin -= (totrunentrymin-iev); // shift run position min
5936                  totrunentrymax -= (totrunentrymin-iev); // shift run position max
5937                  if (DBG) printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);
5938                  //              printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI
5939                }
5940                runfirstentry = totrunentrymin; // first entry of the run in the level2
5941              
5942    
5943                //
5944                if (gltsync)
5945                  delete gltsync; // Emiliano
5946                if (!dbc || (dbc && !dbc->IsConnected()))
5947                  SetDBConnection(); //Emiliano
5948                gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano
5949                if (dbc){
5950                  dbc->Close(); // Emiliano
5951                  delete dbc;
5952                  dbc=0;
5953                }          
5954                if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano
5955                  cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun
5956                       << "  has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl;
5957                  cout
5958                    << "                                                            (NB!! in this case some events could be assigned to a wrong run)"
5959                    << endl;
5960                }
5961                //
5962                if (DBG) printf(" found \n");
5963                //            printf(" found \n");//TOGLITOGLI
5964                rfound = true;
5965                //
5966                break;
5967              }
5968            } // loop over run
5969            if ( !rfound ){
5970              printf(" PamLevel2::GetYodaEntry() ERROR! run is not present in the level2 file!!! \n");
5971              cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5972              cout << "\nFor bug reporting instructions, please see for example:\n";
5973              cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5974              cout << "  " << endl;        
5975              return 0;
5976            }
5977    
5978    return answer;          // here we got the first run and we can check if it contains the level0 event
5979            if (!GetYodaTree()){
5980              printf(" PamLevel2::GetYodaEntry() : ERROR no level0 file loaded!\n");
5981              return 0;
5982            }      
5983    
5984            // get the current run entry
5985            irunentry = iev - runfirstentry;
5986            if (irunentry < 0) {
5987              if (DBG) cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
5988              //          cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl; // TOGLITOGLI
5989              irunentry = 0LL;
5990            }
5991            //  ---------------------------------
5992            //  if file is NOT a preselected file
5993            //  ---------------------------------
5994            quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM); // prevshift already included in irunentry
5995          
5996            if (DBG){
5997              cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
5998              cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
5999              cout << " time "<< abstime << endl;
6000            }
6001            //        cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
6002            //        cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
6003            //        cout << " time "<< abstime << endl; // TOGLITOGLI
6004          
6005            shift = 0;
6006            answer = quellagiusta + shift + yprevshift; // prevshift already included in irunentry
6007            readl0 = l0_tree->GetEntry(answer); // prevshift already included in irunentry
6008    
6009            if (DBG){
6010              printf(" siamo qua shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);
6011            }
6012            //        printf(" siamo qua shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
6013          
6014            while ( (obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta + (Long64_t) shift) < GetYodaTree()->GetEntries() && shift < maxshift ){
6015              if (shift > 0) {
6016                if (DBG) cout << " PKTNUM  L2 --- " << pktn << " --- L0 --- " << GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
6017                if (DBG)
6018                  cout << "         RUN: ID " << GetRunInfo()->ID << " ID_ROOT_L0 " << run_obj->ID_ROOT_L0 << " ID_RUN_FRAG "
6019                       << GetRunInfo()->ID_RUN_FRAG << " EV_FROM " << GetRunInfo()->EV_FROM << endl;
6020                if (DBG)
6021                  cout << "         L2 <--> L0 mismatch ( irun " << irun << " irunentry " << irunentry << " shift " << shift
6022                       << " prevshift " << prevshift << " )" << endl;
6023              }
6024              answer = quellagiusta +  shift+ yprevshift;
6025              readl0 = l0_tree->GetEntry(answer);
6026              //          printf(" inside inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
6027            
6028              if (!GetEventHeader()) {
6029                cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader " << endl;
6030                return 0;
6031              }
6032              //
6033              if (yprevshift != 0 && (quellagiusta + (Long64_t) shift) == GetYodaTree()->GetEntries()) {
6034                if (DBG) printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);
6035                //            printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
6036                yprevshift = 0;
6037                shift = -1;
6038              };
6039            
6040              shift++;
6041            }
6042          
6043            if ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()) ){
6044              //still not the good run... continue with the nex one!
6045              printf("still not the good run... continue with the nex one!\n");
6046            } else {
6047              if (DBG) cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
6048              //          cout << "LA ENTRY GIUSTA E`: "<<answer<<" (spero...)"<<endl;//TOGLITOGLI
6049              if (shift > 1) yprevshift = (shift - 1);
6050              if (Row) delete Row;
6051              delete pResult;  
6052              if (dbc){
6053                dbc->Close(); // Emiliano
6054                delete dbc;
6055                dbc=0;
6056              }    
6057              il0entry = answer;
6058              return readl0;
6059            }
6060            // perhaps it is all
6061          }// loop over runs containing the event
6062          if (Row) delete Row;
6063          delete pResult;  
6064          if (dbc){
6065            dbc->Close(); // Emiliano
6066            delete dbc;
6067            dbc=0;
6068          }          
6069          // arriving here it means no run found, cannot be! error!
6070          printf(" PamLevel2::GetYodaEntry() ERROR! run is not present in the level0 files!!! \n");
6071          cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
6072          cout << "\nFor bug reporting instructions, please see for example:\n";
6073          cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
6074          cout << "  " << endl;        
6075          return 0;
6076        } else {
6077          if (DBG) cout << "=> LA ENTRY GIUSTA E`: "<<answer<<" (spero...)"<<endl;
6078          //    cout << "=> LA ENTRY GIUSTA E`: "<<answer<<" (spero...)"<<endl;
6079          //    printf("obt %lld (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) %i  pktn %lld (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter() %i \n",obt,(UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()), pktn, (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()) );
6080          if (shift > 1) yprevshift = (shift - 1);
6081          il0entry = answer;
6082          return readl0;
6083        }
6084    
6085        /*  } // if selli 0 || 2
6086      if ( SELLI == 1 && hasL0EE ){
6087        sel_tree->GetEntry(iev);  
6088        Long64_t answer = il0entry;
6089        Int_t readl0 = 0;
6090        readl0 = l0_tree->GetEntry(answer);
6091        return readl0;
6092        }*/
6093      printf(" PamLevel2::GetYodaEntry() ERROR! \n");
6094      cout << " Entry not found! OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
6095      cout << "\nFor bug reporting instructions, please see for example:\n";
6096      cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
6097      cout << "  " << endl;
6098      return 0;
6099  }  }
6100    
6101  /**  /**
6102   * \Brief Set DB connection   * \Brief Set DB connection
6103   */   */
# Line 4582  Long64_t PamLevel2::GetReadEntry() { Line 6190  Long64_t PamLevel2::GetReadEntry() {
6190  void PamLevel2::SetSortingMethod(TString how) {  void PamLevel2::SetSortingMethod(TString how) {
6191    if (howtosort != how) {    if (howtosort != how) {
6192      issorted = false;      issorted = false;
6193        issorted_new = false;
6194    }    }
6195    howtosort = how;    howtosort = how;
6196  }  }

Legend:
Removed from v.1.82  
changed lines
  Added in v.1.112

  ViewVC Help
Powered by ViewVC 1.1.23