/[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.88 by pam-fi, Tue Nov 29 15:34:12 2011 UTC revision 1.110 by pam-fi, Tue Mar 24 09:15:01 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    
319      if (t){
320          trk_track = new TrkTrack(*t);
321          trk_ext_track = new ExtTrack(*t);//NB!! ha dimensione 6 invece che 8
322      }
323    if (c)    if (c)
324      calo_track = c;      calo_track = new CaloTrkVar(*c);
325    if (o)    if (o)
326      tof_track = o;      tof_track = new ToFTrkVar(*o);
327    if (r)    if (r)
328      orb_track = r;      orb_track = new OrbitalInfoTrkVar(*r);
329      candeleteobj = 1;
330    
331    candeleteobj = 0;  }
332    ;
333    /**
334     * Constructor
335     */
336    PamTrack::PamTrack(ExtTrack* t, CaloTrkVar* c, ToFTrkVar* o, OrbitalInfoTrkVar *r) {
337    
338      trk_ext_track = 0;
339      trk_track = 0;
340      calo_track = 0;
341      tof_track = 0;
342      orb_track = 0;
343      //     if(t)trk_track  = new TrkTrack(*t);
344      //     if(c)calo_track = new CaloTrkVar(*c);
345      //     if(o)tof_track  = new ToFTrkVar(*o);
346    //   if (t)
347    //     trk_track = t;
348    //   if (c)
349    //     calo_track = c;
350    //   if (o)
351    //     tof_track = o;
352    //   if (r)
353    //     orb_track = r;
354    
355    //   candeleteobj = 0;
356    
357    
358      if (t){
359    ////      trk_track = new TrkTrack(*t);//in this case TrkTrack object remains null
360          trk_ext_track = new ExtTrack(*t);
361      }
362      if (c)
363        calo_track = new CaloTrkVar(*c);
364      if (o)
365        tof_track = new ToFTrkVar(*o);
366      if (r)
367        orb_track = new OrbitalInfoTrkVar(*r);
368      candeleteobj = 1;
369      pscore = 0;
370      iscore = 0;
371    
372  }  }
373  ;  ;
374    
375  PamTrack::PamTrack(const PamTrack& track) {  PamTrack::PamTrack(const PamTrack& track) {
376    
377    TrkTrack *t = track.trk_track;    TrkTrack *t = track.trk_track;
378      ExtTrack *e = track.trk_ext_track;
379    CaloTrkVar *c = track.calo_track;    CaloTrkVar *c = track.calo_track;
380    ToFTrkVar *o = track.tof_track;    ToFTrkVar *o = track.tof_track;
381    OrbitalInfoTrkVar *r = track.orb_track;    OrbitalInfoTrkVar *r = track.orb_track;
382    
383    trk_track = 0;    trk_ext_track = 0;
384    calo_track = 0;    trk_track     = 0;
385    tof_track = 0;    calo_track    = 0;
386    orb_track = 0;    tof_track     = 0;
387      orb_track     = 0;
388      if(e)
389          trk_ext_track = new ExtTrack(*e);
390    if (t)    if (t)
391      trk_track = new TrkTrack(*t);      trk_track = new TrkTrack(*t);
392    if (c)    if (c)
# Line 334  PamTrack::PamTrack(const PamTrack& track Line 395  PamTrack::PamTrack(const PamTrack& track
395      tof_track = new ToFTrkVar(*o);      tof_track = new ToFTrkVar(*o);
396    if (r)    if (r)
397      orb_track = new OrbitalInfoTrkVar(*r);      orb_track = new OrbitalInfoTrkVar(*r);
398    
399    candeleteobj = 1;    candeleteobj = 1;
400      pscore = 0;
401      iscore = 0;
402    
403    }
404    
405    void PamTrack::Copy( PamTrack& track) const {
406    
407        track.trk_track = trk_track;
408        track.trk_ext_track = trk_ext_track;
409        track.calo_track = calo_track;
410        track.tof_track = tof_track;
411        track.orb_track = orb_track;
412        
413        track.candeleteobj = candeleteobj;
414        track.pscore = pscore;
415        track.iscore = iscore;
416        
417  }  }
 void PamTrack::Clear() {  
418    
419    //    cout << "PamTrack::Clear() "<<candeleteobj<<endl;  
420    
421    void PamTrack::Clear(Option_t *option) {
422    
423    //    cout << "PamTrack::Clear( "<<option<<" ) "<<candeleteobj<<endl;
424    if (candeleteobj) {    if (candeleteobj) {
425          
426        if (trk_ext_track)
427          trk_ext_track->ExtTrack::Clear(option);
428      if (trk_track)      if (trk_track)
429        trk_track->TrkTrack::Clear();        trk_track->TrkTrack::Clear();
430      if (calo_track)      if (calo_track)
# Line 351  void PamTrack::Clear() { Line 435  void PamTrack::Clear() {
435        orb_track->OrbitalInfoTrkVar::Clear();//???        orb_track->OrbitalInfoTrkVar::Clear();//???
436    }    }
437    else {    else {
438        trk_ext_track = 0;
439      trk_track = 0;      trk_track = 0;
440      calo_track = 0;      calo_track = 0;
441      tof_track = 0;      tof_track = 0;
# Line 363  void PamTrack::Clear() { Line 448  void PamTrack::Clear() {
448  void PamTrack::Delete() {  void PamTrack::Delete() {
449    //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;    //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;
450    if (candeleteobj) {    if (candeleteobj) {
451        if (trk_ext_track) {
452    //      trk_ext_track->ExtTrack::Clear("C");//Clear is called for all the array elements
453            trk_ext_track->ExtTrack::Clear("C+C");//Clear is called for all the array elements passing option 'C'
454          delete trk_ext_track;
455        }
456      if (trk_track) {      if (trk_track) {
457        trk_track->TrkTrack::Clear();        trk_track->TrkTrack::Clear();
458        delete trk_track;        delete trk_track;
# Line 384  void PamTrack::Delete() { Line 474  void PamTrack::Delete() {
474      Clear();      Clear();
475    }    }
476  }  }
477    
478    
479    
480    
481  //--------------------------------------  //--------------------------------------
482  //  //
483  //  //
# Line 394  void PamTrack::Delete() { Line 488  void PamTrack::Delete() {
488  PamLevel2::PamLevel2() {  PamLevel2::PamLevel2() {
489    Initialize();    Initialize();
490  }  }
491  ;  
492    
493  /**  /**
494   * Constructor   * Constructor
# Line 417  PamLevel2::PamLevel2(TString ddir, TStri Line 511  PamLevel2::PamLevel2(TString ddir, TStri
511      GetPamTree(listf, detlist);      GetPamTree(listf, detlist);
512    if (listf)    if (listf)
513      GetRunTree(listf);      GetRunTree(listf);
514      SetMaxShift(-1);
515  }  }
516  ;  
517    
518  PamLevel2::PamLevel2(TString ddir, TList *llist, TString detlist) {  PamLevel2::PamLevel2(TString ddir, TList *llist, TString detlist) {
519    Initialize();    Initialize();
520    GetPamTree(llist, detlist);    GetPamTree(llist, detlist);
521    GetRunTree(llist);    GetRunTree(llist);
522      SetMaxShift(-1);
523  }  }
524  ;  
525  /**  /**
526   * Constructor   * Constructor
527   * @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 531  PamLevel2::PamLevel2(TString ddir, TList
531   */   */
532  PamLevel2::PamLevel2(TString ddir, TString llist) {  PamLevel2::PamLevel2(TString ddir, TString llist) {
533    Initialize();    Initialize();
534    TList* listf = GetListOfLevel2Files(ddir, llist);    TList* listf = GetListOfLevel2Files(ddir, llist);
535      cout << "GetPamTree: "<<endl;
536    GetPamTree(listf, "");    GetPamTree(listf, "");
537      cout << "GetRunTree: "<<endl;
538    GetRunTree(listf);    GetRunTree(listf);
539      SetMaxShift(-1);
540  }  }
541  ;  
542    
543  void PamLevel2::Initialize() {  void PamLevel2::Initialize() {
544    
# Line 452  void PamLevel2::Initialize() { Line 551  void PamLevel2::Initialize() {
551    trkh_obj = 0;    trkh_obj = 0;
552    calo1_obj = 0;    calo1_obj = 0;
553    calo2_obj = 0;    calo2_obj = 0;
554    tof_obj = 0;    tof2_obj = 0;
555    trig_obj = 0;    trig_obj = 0;
556    s4_obj = 0;    s4_obj = 0;
557    nd_obj = 0;    nd_obj = 0;
558    ac_obj = 0;    ac_obj = 0;
559    orb_obj = 0;    orb2_obj = 0;
560    gp_obj = 0;    gp_obj = 0;
561    
562      extAlgFlag=0;
563    
564      trk_ext_obj     = 0;
565      trk_ext_nuc_obj = 0;
566      trk_nuc_obj     = 0;
567      
568      calo_ext_obj     = 0;
569      calo_ext_nuc_obj = 0;
570      calo_nuc_obj     = 0;
571      
572      tof_ext_obj     = 0;
573      tof_ext_nuc_obj = 0;
574      tof_nuc_obj     = 0;
575      
576      orb_ext_obj     = 0;
577      orb_ext_nuc_obj = 0;
578      orb_nuc_obj     = 0;
579    
580      trk2_nuc_obj  = 0;
581      calo2_nuc_obj = 0;
582      tof2_nuc_obj  = 0;
583      orb2_nuc_obj  = 0;
584    
585    
586    run_obj = 0;//new GL_RUN();    run_obj = 0;//new GL_RUN();
587    soft_obj = 0;// Emiliano    soft_obj = 0;// Emiliano
588      proc_obj = 0;// Emiliano
589    irun = -1LL;    irun = -1LL;
590    irunt = -1LL;    irunt = -1LL;
591      totrunentry = 0LL;
592      totrunentrymax = 0LL;
593      totrunentrymin = 0LL;
594    runfirstentry = 0LL;    runfirstentry = 0LL;
595    runlastentry = 0LL;    runlastentry = 0LL;
596    gltsync = 0; // Emiliano    gltsync = 0; // Emiliano
597    fUpdateRunInfo = true; // Emiliano    fUpdateRunInfo = true; // Emiliano
598      fUseDBinRunInfo = true; // Emiliano
599      fDiscarded = false; //EM
600      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
601      il0entry = 0LL;
602      //  hasL0EE = true;
603    
604    l0_file = NULL;    l0_file = NULL;
605    l0_tree = NULL;    l0_tree = NULL;
# Line 475  void PamLevel2::Initialize() { Line 607  void PamLevel2::Initialize() {
607    dbc = 0;    dbc = 0;
608    
609    prevshift = 0;    prevshift = 0;
610    maxshift = 10; //EMILIANO    yprevshift = 0;
611      maxshift = 10; //EMILIANO now overridden by SetMaxShift(-1) called by constructors
612    
613    run_tree = NULL;    run_tree = NULL;
614    run_tree_clone = NULL;    run_tree_clone = NULL;
615    
616      proc_tree = NULL;
617      proc_tree_clone = NULL;
618    
619    sel_tree = NULL;    sel_tree = NULL;
620    sel_tree_clone = NULL;    sel_tree_clone = NULL;
621    
# Line 510  void PamLevel2::Initialize() { Line 647  void PamLevel2::Initialize() {
647    if (strcmp(pamdbpsw, ""))    if (strcmp(pamdbpsw, ""))
648      psw = pamdbpsw;      psw = pamdbpsw;
649    
650      customString = "";
651    
652    //    sorted_tracks = 0;//new TRefArray();    //    sorted_tracks = 0;//new TRefArray();
653    
654    CAL0 = false;    CAL0 = false;
# Line 526  void PamLevel2::Initialize() { Line 665  void PamLevel2::Initialize() {
665    ND = true;    ND = true;
666    AC = true;    AC = true;
667    ORB = true;    ORB = true;
668      PROC = true;
669    GP = false;    GP = false;
670    
671      EXT = false;
672      NUC = false;
673      trkAlg = "STD";//default tracking algorythm
674    
675    RUN = true;    RUN = true;
676    
677    SELLI = -1;    SELLI = -1;
# Line 538  void PamLevel2::Initialize() { Line 682  void PamLevel2::Initialize() {
682    
683    tsorted = 0;    tsorted = 0;
684    timage = 0;    timage = 0;
685      text = 0 ;
686    
687      tsorted_nuc = 0;
688      timage_nuc = 0;
689      text_nuc = 0 ;
690    
691    howtosort = "+CAL+TOF";    howtosort = "+CAL+TOF";
692    //howtosort = "+TOF";    //howtosort = "+TOF";
# Line 545  void PamLevel2::Initialize() { Line 694  void PamLevel2::Initialize() {
694    
695    issorted = false;    issorted = false;
696    lastsorted = -1;    lastsorted = -1;
697      issorted_new = false;
698      lastsorted_new = -1;
699    
700  }  }
701  ;  ;
# Line 557  void PamLevel2::Delete() { Line 708  void PamLevel2::Delete() {
708      delete run_obj;      delete run_obj;
709    if (soft_obj)    if (soft_obj)
710      delete soft_obj; //Emiliano      delete soft_obj; //Emiliano
711      if (proc_obj)
712        delete proc_obj; //Emiliano
713    
714    //    cout << "void PamLevel2::Clear()"<<endl;    //    cout << "void PamLevel2::Clear()"<<endl;
715    if (h0_obj)    if (h0_obj)
# Line 575  void PamLevel2::Delete() { Line 728  void PamLevel2::Delete() {
728      delete calo1_obj;      delete calo1_obj;
729    if (calo2_obj)    if (calo2_obj)
730      delete calo2_obj;      delete calo2_obj;
731    if (tof_obj)    if (tof2_obj)
732      delete tof_obj;      delete tof2_obj;
733    if (trig_obj)    if (trig_obj)
734      delete trig_obj;      delete trig_obj;
735    if (s4_obj)    if (s4_obj)
# Line 585  void PamLevel2::Delete() { Line 738  void PamLevel2::Delete() {
738      delete nd_obj;      delete nd_obj;
739    if (ac_obj)    if (ac_obj)
740      delete ac_obj;      delete ac_obj;
741    if (orb_obj)    if (orb2_obj)
742      delete orb_obj;      delete orb2_obj;
743    if (gp_obj)    if (gp_obj)
744      delete gp_obj;      delete gp_obj;
745    
746      if(trk_nuc_obj)trk_nuc_obj->Delete();
747      if(trk_ext_obj)trk_ext_obj->Delete();
748      if(trk_ext_nuc_obj)trk_ext_nuc_obj->Delete();
749    
750      if(calo_nuc_obj)calo_nuc_obj->Delete();
751      if(calo_ext_obj)calo_ext_obj->Delete();
752      if(calo_ext_nuc_obj)calo_ext_nuc_obj->Delete();
753    
754      if(tof_nuc_obj)tof_nuc_obj->Delete();
755      if(tof_ext_obj)tof_ext_obj->Delete();
756      if(tof_ext_nuc_obj)tof_ext_nuc_obj->Delete();
757    
758      if(orb_nuc_obj)orb_nuc_obj->Delete();
759      if(orb_ext_obj)orb_ext_obj->Delete();
760      if(orb_ext_nuc_obj)orb_ext_nuc_obj->Delete();
761    
762    
763      if(trk2_nuc_obj)trk2_nuc_obj->Delete();;
764      if( calo2_nuc_obj)calo2_nuc_obj->Delete();;
765      if(tof2_nuc_obj)tof2_nuc_obj->Delete();;
766      if(orb2_nuc_obj)orb2_nuc_obj->Delete();;
767      
768    
769    
770    if (tsorted) {    if (tsorted) {
771      tsorted->Delete();      tsorted->Delete();
772      delete tsorted;      delete tsorted;
# Line 598  void PamLevel2::Delete() { Line 775  void PamLevel2::Delete() {
775      timage->Delete();      timage->Delete();
776      delete timage;      delete timage;
777    }    }
778      if (text) {
779        text->Delete();
780        delete text;
781      }
782      if (tsorted_nuc) {
783        tsorted_nuc->Delete();
784        delete tsorted_nuc;
785      }
786      if (timage_nuc) {
787        timage_nuc->Delete();
788        delete timage_nuc;
789      }
790      if (text_nuc) {
791        text_nuc->Delete();
792        delete text_nuc;
793      }
794    
795    
796    
797    if (dbc) {    if (dbc) {
798      dbc->Close();      dbc->Close();
# Line 665  void PamLevel2::Delete() { Line 860  void PamLevel2::Delete() {
860    if (irunoffset)    if (irunoffset)
861      delete[] irunoffset;      delete[] irunoffset;
862    
863    
864      Initialize();
865    
866  }  }
867  ;  ;
868    
# Line 698  void PamLevel2::Clear() { Line 896  void PamLevel2::Clear() {
896      calo1_obj->Clear();      calo1_obj->Clear();
897    if (calo2_obj)    if (calo2_obj)
898      calo2_obj->Clear();      calo2_obj->Clear();
899    if (tof_obj)    if (tof2_obj)
900      tof_obj->Clear();      tof2_obj->Clear();
901    if (trig_obj)    if (trig_obj)
902      trig_obj->Clear();      trig_obj->Clear();
903    if (s4_obj)    if (s4_obj)
# Line 708  void PamLevel2::Clear() { Line 906  void PamLevel2::Clear() {
906      nd_obj->Clear();      nd_obj->Clear();
907    if (ac_obj)    if (ac_obj)
908      ac_obj->Clear();      ac_obj->Clear();
909    if (orb_obj)    if (orb2_obj)
910      orb_obj->Clear();      orb2_obj->Clear();
911    if (gp_obj)    if (gp_obj)
912      gp_obj->Clear();      gp_obj->Clear();
913      if (proc_obj)
914        proc_obj->Clear();
915    
916    //    if(sorted_tracks)sorted_tracks->Clear();    //    if(sorted_tracks)sorted_tracks->Clear();
917    //    sorted_tracks.Clear();    //    sorted_tracks.Clear();
918    
919    if (tsorted) {    if(trk_nuc_obj)trk_nuc_obj->Clear();
920      tsorted->Delete();    if(trk_ext_obj)trk_ext_obj->Clear();
921    }    if(trk_ext_nuc_obj)trk_ext_nuc_obj->Clear();
922    if (timage) {  
923      timage->Delete();    if(calo_nuc_obj)calo_nuc_obj->Clear();
924    }    if(calo_ext_obj)calo_ext_obj->Clear();
925      if(calo_ext_nuc_obj)calo_ext_nuc_obj->Clear();
926    
927      if(tof_nuc_obj)tof_nuc_obj->Clear();
928      if(tof_ext_obj)tof_ext_obj->Clear();
929      if(tof_ext_nuc_obj)tof_ext_nuc_obj->Clear();
930    
931      if(orb_nuc_obj)orb_nuc_obj->Clear();
932      if(orb_ext_obj)orb_ext_obj->Clear();
933      if(orb_ext_nuc_obj)orb_ext_nuc_obj->Clear();
934    
935      if(trk2_nuc_obj)trk2_nuc_obj->Clear();;
936      if( calo2_nuc_obj)calo2_nuc_obj->Clear();;
937      if(tof2_nuc_obj)tof2_nuc_obj->Clear();;
938      if(orb2_nuc_obj)orb2_nuc_obj->Clear();;
939    
940      if (tsorted)tsorted->Delete();
941      if (timage)timage->Delete();
942      if (text) text->Delete();
943    
944      if (tsorted_nuc)tsorted_nuc->Delete();
945      if (timage_nuc)timage_nuc->Delete();
946      if (text_nuc) text_nuc->Delete();
947  }  }
948  ;  ;
949    
# Line 770  void PamLevel2::Reset() { Line 992  void PamLevel2::Reset() {
992    if (sel_tree)    if (sel_tree)
993      sel_tree->Delete();;      sel_tree->Delete();;
994    sel_tree = NULL;    sel_tree = NULL;
995    
996      if (proc_tree)
997        proc_tree->Delete();
998      proc_tree = NULL;
999    //    //
1000    // Close file    // Close file
1001    //    //
# Line 786  void PamLevel2::Reset() { Line 1012  void PamLevel2::Reset() {
1012    trkh_obj = 0;    trkh_obj = 0;
1013    calo1_obj = 0;    calo1_obj = 0;
1014    calo2_obj = 0;    calo2_obj = 0;
1015    tof_obj = 0;    tof2_obj = 0;
1016    trig_obj = 0;    trig_obj = 0;
1017    s4_obj = 0;    s4_obj = 0;
1018    nd_obj = 0;    nd_obj = 0;
1019    ac_obj = 0;    ac_obj = 0;
1020    orb_obj = 0;    orb2_obj = 0;
1021    gp_obj = 0;    gp_obj = 0;
1022      proc_obj = 0;
1023    
1024      trk_ext_obj     = 0;
1025      trk_ext_nuc_obj = 0;
1026      trk_nuc_obj     = 0;
1027      
1028      calo_ext_obj     = 0;
1029      calo_ext_nuc_obj = 0;
1030      calo_nuc_obj     = 0;
1031      
1032      tof_ext_obj     = 0;
1033      tof_ext_nuc_obj = 0;
1034      tof_nuc_obj     = 0;
1035      
1036      orb_ext_obj     = 0;
1037      orb_ext_nuc_obj = 0;
1038      orb_nuc_obj     = 0;
1039    
1040      trk2_nuc_obj  = 0;
1041      calo2_nuc_obj = 0;
1042      tof2_nuc_obj  = 0;
1043      orb2_nuc_obj  = 0;
1044    
1045      trk2_nuc_obj  = 0;
1046      calo2_nuc_obj = 0;
1047      tof2_nuc_obj  = 0;
1048      orb2_nuc_obj  = 0;
1049    //    //
1050    // Reset run pointers    // Reset run pointers
1051    //    //
1052    run_obj = 0;//new GL_RUN();    run_obj = 0;//new GL_RUN();
1053    soft_obj = 0;// Emiliano    soft_obj = 0;// Emiliano
1054      proc_obj = 0;// Emiliano
1055    irun = -1;    irun = -1;
1056    irunt = -1;    irunt = -1;
1057      totrunentry = 0LL;
1058      totrunentrymax = 0LL;
1059      totrunentrymin = 0LL;
1060    runfirstentry = 0ULL;    runfirstentry = 0ULL;
1061    runlastentry = 0ULL;    runlastentry = 0ULL;
1062      prevabstime = 0ULL;
1063      prevpktnum = 0;
1064      abstime = 0ULL;
1065      pktnum = 0;
1066      isFragment = false;
1067    //    //
1068    totdltime[0] = 0LL;    totdltime[0] = 0LL;
1069    totdltime[1] = 0LL;    totdltime[1] = 0LL;
# Line 819  Bool_t PamLevel2::IsGood(Bool_t strict) Line 1081  Bool_t PamLevel2::IsGood(Bool_t strict)
1081    if (strict) {    if (strict) {
1082      if (trk2_obj && trk2_obj->UnpackError() != 0)      if (trk2_obj && trk2_obj->UnpackError() != 0)
1083        goodev = false;        goodev = false;
1084      if (tof_obj && tof_obj->unpackError != 0)      if (tof2_obj && tof2_obj->unpackError != 0)
1085        goodev = false;        goodev = false;
1086      if (trig_obj && trig_obj->unpackError != 0)      if (trig_obj && trig_obj->unpackError != 0)
1087        goodev = false;        goodev = false;
# Line 829  Bool_t PamLevel2::IsGood(Bool_t strict) Line 1091  Bool_t PamLevel2::IsGood(Bool_t strict)
1091        goodev = false;        goodev = false;
1092      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)))
1093        goodev = false;        goodev = false;
1094      //  if(orb_obj)      //  if(orb2_obj)
1095    }    }
1096    else {    else {
1097      if (nd_obj && nd_obj->unpackError != 0)      if (nd_obj && nd_obj->unpackError != 0)
# Line 855  void PamLevel2::SkipRunInfoUpdate(){ Line 1117  void PamLevel2::SkipRunInfoUpdate(){
1117    };    };
1118  }  }
1119    
1120    void PamLevel2::SetMaxShift(Int_t sh){
1121      if ( sh >=  0 ){
1122        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");
1123        maxshift = sh;
1124      } else {
1125        ULong64_t nev = GetEntries();
1126        ULong64_t runnev = 0ULL;
1127        for (Int_t r=0; r< run_tree->GetEntries();r++){
1128          run_tree->GetEntry(r);//update runinfo
1129          runnev += GetRunInfo()->NEVENTS;
1130        }
1131        maxshift = (Int_t)(runnev-nev) + 10; // +10 just to be conservative
1132        if ( (runnev-nev) == 0 ) isSync = true;
1133        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);
1134        //    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
1135      }
1136    }
1137    
1138  //--------------------------------------  //--------------------------------------
1139  //  //
1140  //  //
# Line 897  void *PamLevel2::GetPointerTo(const char Line 1177  void *PamLevel2::GetPointerTo(const char
1177      return &calo2_obj;      return &calo2_obj;
1178    };    };
1179    if (!objname.CompareTo("ToFLevel2")) {    if (!objname.CompareTo("ToFLevel2")) {
1180      if (!tof_obj) {      if (!tof2_obj) {
1181        tof_obj = new ToFLevel2();        tof2_obj = new ToFLevel2();
1182        tof_obj->Set();        tof2_obj->Set();
1183      }      }
1184      return &tof_obj;      return &tof2_obj;
1185    };    };
1186    if (!objname.CompareTo("TrigLevel2")) {    if (!objname.CompareTo("TrigLevel2")) {
1187      if (!trig_obj)      if (!trig_obj)
# Line 924  void *PamLevel2::GetPointerTo(const char Line 1204  void *PamLevel2::GetPointerTo(const char
1204      return &ac_obj;      return &ac_obj;
1205    };    };
1206    if (!objname.CompareTo("OrbitalInfo")) {    if (!objname.CompareTo("OrbitalInfo")) {
1207      if (!orb_obj) {      if (!orb2_obj) {
1208        orb_obj = new OrbitalInfo();        orb2_obj = new OrbitalInfo();
1209        orb_obj->Set();        orb2_obj->Set();
1210      }      }
1211      return &orb_obj;      return &orb2_obj;
1212    };    };
1213    //     if(!objname.CompareTo("OrbitalInfo")){    //     if(!objname.CompareTo("OrbitalInfo")){
1214    //    if(!orb_obj)   orb_obj   = new OrbitalInfo();    //    if(!orb2_obj)   orb2_obj   = new OrbitalInfo();
1215    //    return &orb_obj;    //    return &orb2_obj;
1216    //     };    //     };
1217    if (!objname.CompareTo("GPamela")) {    if (!objname.CompareTo("GPamela")) {
1218      if (!gp_obj)      if (!gp_obj)
# Line 946  void *PamLevel2::GetPointerTo(const char Line 1226  void *PamLevel2::GetPointerTo(const char
1226    if (!objname.CompareTo("SoftInfo"))    if (!objname.CompareTo("SoftInfo"))
1227      return &soft_obj; // Emiliano      return &soft_obj; // Emiliano
1228    
1229      if (!objname.CompareTo("ProcInfo")){
1230        if (!proc_obj)
1231          proc_obj = new ProcInfo();    
1232        return &proc_obj; // Emiliano
1233      }
1234    
1235    return NULL;    return NULL;
1236  }  }
1237  ;  ;
# Line 963  CaloTrkVar *PamLevel2::GetCaloStoredTrac Line 1249  CaloTrkVar *PamLevel2::GetCaloStoredTrac
1249      return 0;      return 0;
1250    
1251    if (calo2_obj->CaloLevel2::ntrk() == 0) {    if (calo2_obj->CaloLevel2::ntrk() == 0) {
1252      cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo " << seqno        if( seqno >=0 ){
1253          << " but no Calorimeter tracks are stored" << endl;            cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo " << seqno;
1254      return NULL;            cout << " but no Calorimeter tracks are stored" << endl;
1255          }
1256          return NULL;
1257    };    };
1258    
1259    CaloTrkVar *c = 0;    CaloTrkVar *c = 0;
# Line 978  CaloTrkVar *PamLevel2::GetCaloStoredTrac Line 1266  CaloTrkVar *PamLevel2::GetCaloStoredTrac
1266    
1267    if (!c || seqno != c->trkseqno) {    if (!c || seqno != c->trkseqno) {
1268      c = 0;      c = 0;
1269      if (seqno != -1)      if (seqno != -1 && seqno>=0)
1270        cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo " << seqno        cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo " << seqno
1271            << " does not match Calorimeter stored tracks" << endl;            << " does not match Calorimeter stored tracks" << endl;
1272    };    };
# Line 996  CaloTrkVar *PamLevel2::GetCaloStoredTrac Line 1284  CaloTrkVar *PamLevel2::GetCaloStoredTrac
1284   */   */
1285  ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno) {  ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno) {
1286    
1287    if (!tof_obj)    if (!tof2_obj)
1288      return 0;      return 0;
1289    
1290    if (tof_obj->ToFLevel2::ntrk() == 0) {    if (tof2_obj->ToFLevel2::ntrk() == 0) {
1291      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"
1292          << endl;          << endl;
1293      return NULL;      return NULL;
# Line 1009  ToFTrkVar *PamLevel2::GetToFStoredTrack( Line 1297  ToFTrkVar *PamLevel2::GetToFStoredTrack(
1297    Int_t it_tof = 0;    Int_t it_tof = 0;
1298    
1299    do {    do {
1300      c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);      c = tof2_obj->ToFLevel2::GetToFTrkVar(it_tof);
1301      it_tof++;      it_tof++;
1302    } while (c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());    } while (c && seqno != c->trkseqno && it_tof < tof2_obj->ToFLevel2::ntrk());
1303    
1304    if (!c || seqno != c->trkseqno) {    if (!c || seqno != c->trkseqno) {
1305      c = 0;      c = 0;
# Line 1034  ToFTrkVar *PamLevel2::GetToFStoredTrack( Line 1322  ToFTrkVar *PamLevel2::GetToFStoredTrack(
1322   */   */
1323  OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno) {  OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno) {
1324    
1325    if (!orb_obj)    if (!orb2_obj)
1326      return 0;      return 0;
1327    
1328    if (orb_obj->OrbitalInfo::ntrk() == 0) {    if (orb2_obj->OrbitalInfo::ntrk() == 0) {
1329      //       // TRICK BEGIN      //       // TRICK BEGIN
1330      //       OrbitalInfoTrkVar  *r = new OrbitalInfoTrkVar(); // TEMPORARY TRICK      //       OrbitalInfoTrkVar  *r = new OrbitalInfoTrkVar(); // TEMPORARY TRICK
1331      //       Int_t nn = 0;      //       Int_t nn = 0;
1332      //       TClonesArray &tor = *orb_obj->OrbitalInfoTrk;      //       TClonesArray &tor = *orb2_obj->OrbitalInfoTrk;
1333      //       for(Int_t nt=0; nt < tof_obj->ToFLevel2::ntrk(); nt++){      //       for(Int_t nt=0; nt < tof2_obj->ToFLevel2::ntrk(); nt++){
1334      //  //      //  //
1335      //  ToFTrkVar *ptt = tof_obj->ToFLevel2::GetToFTrkVar(nt);      //  ToFTrkVar *ptt = tof2_obj->ToFLevel2::GetToFTrkVar(nt);
1336      //  if ( ptt->trkseqno != -1  ){      //  if ( ptt->trkseqno != -1  ){
1337      //    //      //    //
1338      //    r->trkseqno = ptt->trkseqno;      //    r->trkseqno = ptt->trkseqno;
# Line 1066  OrbitalInfoTrkVar *PamLevel2::GetOrbital Line 1354  OrbitalInfoTrkVar *PamLevel2::GetOrbital
1354      //       };      //       };
1355      //       delete r;      //       delete r;
1356      //       OrbitalInfoTrkVar *c = 0;      //       OrbitalInfoTrkVar *c = 0;
1357      //       c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(0);      //       c = orb2_obj->OrbitalInfo::GetOrbitalInfoTrkVar(0);
1358      //       return c;      //       return c;
1359      //       //TRICK END      //       //TRICK END
1360      cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo " << seqno      cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo " << seqno
# Line 1078  OrbitalInfoTrkVar *PamLevel2::GetOrbital Line 1366  OrbitalInfoTrkVar *PamLevel2::GetOrbital
1366    Int_t it_tof = 0;    Int_t it_tof = 0;
1367    
1368    do {    do {
1369      c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);      c = orb2_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);
1370      it_tof++;      it_tof++;
1371    } while (c && seqno != c->trkseqno && it_tof < orb_obj->OrbitalInfo::ntrk());    } while (c && seqno != c->trkseqno && it_tof < orb2_obj->OrbitalInfo::ntrk());
1372    
1373    if (!c || seqno != c->trkseqno) {    if (!c || seqno != c->trkseqno) {
1374      c = 0;      c = 0;
# Line 1097  OrbitalInfoTrkVar *PamLevel2::GetOrbital Line 1385  OrbitalInfoTrkVar *PamLevel2::GetOrbital
1385  //  //
1386  //  //
1387  //--------------------------------------  //--------------------------------------
1388  /**  // /**
1389   * 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.
1390   */  //  */
1391  PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t) {  // PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t) {
1392    
1393    cout << "PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** " << endl;  //   cout << "PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** " << endl;
1394    cout << "(if you use it, remember to delete the PamTrack object)" << endl;  //   cout << "(if you use it, remember to delete the PamTrack object)" << endl;
1395    
1396    CaloTrkVar *c = 0;  //   CaloTrkVar *c = 0;
1397    ToFTrkVar *o = 0;  //   ToFTrkVar *o = 0;
1398    OrbitalInfoTrkVar *r = 0;  //   OrbitalInfoTrkVar *r = 0;
1399    
1400    if (CAL2)  //   if (CAL2)
1401      c = GetCaloStoredTrack(t->GetSeqNo());  //     c = GetCaloStoredTrack(t->GetSeqNo());
1402    if (TOF)  //   if (TOF)
1403      o = GetToFStoredTrack(t->GetSeqNo());  //     o = GetToFStoredTrack(t->GetSeqNo());
1404    if (ORB)  //   if (ORB)
1405      r = GetOrbitalInfoStoredTrack(t->GetSeqNo());  //     r = GetOrbitalInfoStoredTrack(t->GetSeqNo());
1406    
1407    //    if(t && c && o)track = new PamTrack(t,c,o);  //   //    if(t && c && o)track = new PamTrack(t,c,o);
1408    PamTrack *track = new PamTrack(t, c, o, r);  //   PamTrack *track = new PamTrack(t, c, o, r);
1409    
1410    return track;  //   return track;
1411    
1412  }  // }
1413  ;  // ;
1414  //--------------------------------------  //--------------------------------------
1415  //  //
1416  //  //
1417  //--------------------------------------  //--------------------------------------
1418  /**  // /**
1419   * Retrieves the it-th stored track.  //  * Retrieves the it-th stored track.
1420   * It override TrkLevel2::GetTrack(int it).  //  * It override TrkLevel2::GetTrack(int it).
1421   * @param itrk Track number, ranging from 0 to GetNTracks().  //  * @param itrk Track number, ranging from 0 to GetNTracks().
1422   */  //  */
1423    
1424  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk) {  // PamTrack* PamLevel2::GetStoredTrack(Int_t itrk) {
1425    
1426    cout << "PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** " << endl;  //   cout << "PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** " << endl;
1427    cout  //   cout
1428        << "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)"
1429        << endl;  //       << endl;
1430    cout << "(if you use it, remember to delete the PamTrack object)" << endl;  //   cout << "(if you use it, remember to delete the PamTrack object)" << endl;
1431    PamTrack *track = 0;  //   PamTrack *track = 0;
1432    
1433    if (itrk >= 0 && itrk < trk2_obj->TrkLevel2::ntrk()) {  //   if (itrk >= 0 && itrk < trk2_obj->TrkLevel2::ntrk()) {
1434    
1435      TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk);  //     TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk);
1436      track = GetPamTrackAlong(t);  //     track = GetPamTrackAlong(t);
1437    
1438    }  //   }
1439    else {  //   else {
1440      cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo " << itrk << " does not exist (GetNTracks() = "  //     cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo " << itrk << " does not exist (GetNTracks() = "
1441          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;  //         << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
1442    };  //   };
1443    
1444    return track;  //   return track;
1445    
1446  }  // }
1447  //--------------------------------------  //--------------------------------------
1448  //  //
1449    
# Line 1209  void PamLevel2::SortTracks() { Line 1497  void PamLevel2::SortTracks() {
1497    Int_t ObjectNumber = TProcessID::GetObjectCount();    Int_t ObjectNumber = TProcessID::GetObjectCount();
1498    
1499    // create TCloneArrays to store tracks and its images    // create TCloneArrays to store tracks and its images
1500    if (!tsorted)  //   if (!tsorted)
1501      tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());  //     tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1502    tsorted->Delete();  //   tsorted->Clear("C+C");//Delete();
1503    TClonesArray &ttsorted = *tsorted;  //   if (!timage)
1504    //     timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1505    //   timage->Clear("C+C");//Delete();
1506    
1507      if(tsorted)delete tsorted;
1508      if(timage) delete timage;
1509      tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1510      timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1511    
1512    if (!timage)  
1513      timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());    TClonesArray &ttsorted = *tsorted;
   timage->Delete();  
1514    TClonesArray &ttimage = *timage;    TClonesArray &ttimage = *timage;
1515    
1516    
1517    
1518    //--------------------------------------------------    //--------------------------------------------------
1519    // retrieve sorting method    // retrieve sorting method
1520    //--------------------------------------------------    //--------------------------------------------------
# Line 1334  void PamLevel2::SortTracks() { Line 1630  void PamLevel2::SortTracks() {
1630        // -----------------------------------------------------------------------------------------        // -----------------------------------------------------------------------------------------
1631        // check the number of hit pmts along the track        // check the number of hit pmts along the track
1632        // on S12 S21 and S32, where paddles are parallel to Y axis        // on S12 S21 and S32, where paddles are parallel to Y axis
1633        if ((use_TOF || use_S1 || use_S2 || use_S3) && !tof_obj) {        if ((use_TOF || use_S1 || use_S2 || use_S3) && !tof2_obj) {
1634          cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but ToFLevel2 not loaded !!!";          cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but ToFLevel2 not loaded !!!";
1635          return;          return;
1636        };        };
# Line 1351  void PamLevel2::SortTracks() { Line 1647  void PamLevel2::SortTracks() {
1647          //          //
1648          Float_t sen = 0.;          Float_t sen = 0.;
1649          for (Int_t ih = 0; ih < op->npmtadc; ih++) {          for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1650            Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));            Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1651            if (pl == 2 || pl == 3 || pl == 4 || pl == 5)            if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
1652              sen += (op->dedx).At(ih);              sen += (op->dedx).At(ih);
1653          };          };
1654          for (Int_t ih = 0; ih < oi->npmtadc; ih++) {          for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1655            Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));            Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1656            if (pl == 2 || pl == 3 || pl == 4 || pl == 5)            if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
1657              sen += (oi->dedx).At(ih);              sen += (oi->dedx).At(ih);
1658          };          };
# Line 1369  void PamLevel2::SortTracks() { Line 1665  void PamLevel2::SortTracks() {
1665            Int_t nz = 6;            Int_t nz = 6;
1666            Float_t zin[6]; // << define TOF z-coordinates            Float_t zin[6]; // << define TOF z-coordinates
1667            for (Int_t ip = 0; ip < nz; ip++)            for (Int_t ip = 0; ip < nz; ip++)
1668              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
1669            Trajectory *tr = new Trajectory(nz, zin);            Trajectory *tr = new Trajectory(nz, zin);
1670            //            //
1671            Int_t nphit_p = 0;            Int_t nphit_p = 0;
# Line 1378  void PamLevel2::SortTracks() { Line 1674  void PamLevel2::SortTracks() {
1674            Float_t enhit_i = 0.;            Float_t enhit_i = 0.;
1675            //            //
1676            for (Int_t ih = 0; ih < op->npmtadc; ih++) {            for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1677              Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));              Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1678              if (pl == 1 || pl == 2 || pl == 5) {              if (pl == 1 || pl == 2 || pl == 5) {
1679                nphit_p++;                nphit_p++;
1680                enhit_p += (op->dedx).At(ih);                enhit_p += (op->dedx).At(ih);
# Line 1389  void PamLevel2::SortTracks() { Line 1685  void PamLevel2::SortTracks() {
1685            //            //
1686            if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {            if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
1687              for (Int_t ih = 0; ih < op->npmtadc; ih++) {              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1688                Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1689                if (pl == 0) {                if (pl == 0) {
1690                  nphit_p++;                  nphit_p++;
1691                  enhit_p += (op->dedx).At(ih);                  enhit_p += (op->dedx).At(ih);
# Line 1398  void PamLevel2::SortTracks() { Line 1694  void PamLevel2::SortTracks() {
1694            };            };
1695            if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {            if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
1696              for (Int_t ih = 0; ih < op->npmtadc; ih++) {              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1697                Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1698                if (pl == 3) {                if (pl == 3) {
1699                  nphit_p++;                  nphit_p++;
1700                  enhit_p += (op->dedx).At(ih);                  enhit_p += (op->dedx).At(ih);
# Line 1407  void PamLevel2::SortTracks() { Line 1703  void PamLevel2::SortTracks() {
1703            };            };
1704            if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {            if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
1705              for (Int_t ih = 0; ih < op->npmtadc; ih++) {              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1706                Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1707                if (pl == 4) {                if (pl == 4) {
1708                  nphit_p++;                  nphit_p++;
1709                  enhit_p += (op->dedx).At(ih);                  enhit_p += (op->dedx).At(ih);
# Line 1416  void PamLevel2::SortTracks() { Line 1712  void PamLevel2::SortTracks() {
1712            };            };
1713    
1714            for (Int_t ih = 0; ih < oi->npmtadc; ih++) {            for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1715              Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));              Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1716              if (pl == 1 || pl == 2 || pl == 5) {              if (pl == 1 || pl == 2 || pl == 5) {
1717                nphit_i++;                nphit_i++;
1718                enhit_i += (op->dedx).At(ih);                enhit_i += (op->dedx).At(ih);
# Line 1427  void PamLevel2::SortTracks() { Line 1723  void PamLevel2::SortTracks() {
1723            //            //
1724            if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {            if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
1725              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1726                Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1727                if (pl == 0) {                if (pl == 0) {
1728                  nphit_i++;                  nphit_i++;
1729                  enhit_i += (op->dedx).At(ih);                  enhit_i += (op->dedx).At(ih);
# Line 1436  void PamLevel2::SortTracks() { Line 1732  void PamLevel2::SortTracks() {
1732            };            };
1733            if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {            if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
1734              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1735                Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1736                if (pl == 3) {                if (pl == 3) {
1737                  nphit_i++;                  nphit_i++;
1738                  enhit_i += (op->dedx).At(ih);                  enhit_i += (op->dedx).At(ih);
# Line 1445  void PamLevel2::SortTracks() { Line 1741  void PamLevel2::SortTracks() {
1741            };            };
1742            if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {            if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
1743              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1744                Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1745                if (pl == 4) {                if (pl == 4) {
1746                  nphit_i++;                  nphit_i++;
1747                  enhit_i += (op->dedx).At(ih);                  enhit_i += (op->dedx).At(ih);
# Line 1489  void PamLevel2::SortTracks() { Line 1785  void PamLevel2::SortTracks() {
1785             cout << "image: npmttdc "<< oi->npmttdc << endl;*/             cout << "image: npmttdc "<< oi->npmttdc << endl;*/
1786    
1787            //      for (Int_t ih=0; ih < op->npmtadc; ih++){            //      for (Int_t ih=0; ih < op->npmtadc; ih++){
1788            //        Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );            //        Int_t pl = tof2_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1789            //        if(pl == 1 || pl == 2 || pl == 5)nphit_p++;            //        if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
1790            //      };            //      };
1791    
1792            //      for (Int_t ih=0; ih < oi->npmtadc; ih++){            //      for (Int_t ih=0; ih < oi->npmtadc; ih++){
1793            //        Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );            //        Int_t pl = tof2_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1794            //        if(pl == 1 || pl == 2 || pl == 5)nphit_i++;            //        if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
1795            //      };            //      };
1796            // --- modified to count tdc signals (more efficient?)            // --- modified to count tdc signals (more efficient?)
1797            // --- and to implement check on tdcflag            // --- and to implement check on tdcflag
1798            for (Int_t ih = 0; ih < op->npmttdc; ih++) {            for (Int_t ih = 0; ih < op->npmttdc; ih++) {
1799              Int_t pl = tof_obj->GetPlaneIndex((op->pmttdc).At(ih));              Int_t pl = tof2_obj->GetPlaneIndex((op->pmttdc).At(ih));
1800              //      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++;
1801              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))
1802                  || (use_S3 && (pl == 4 || pl == 5))) {                  || (use_S3 && (pl == 4 || pl == 5))) {
# Line 1510  void PamLevel2::SortTracks() { Line 1806  void PamLevel2::SortTracks() {
1806            };            };
1807    
1808            for (Int_t ih = 0; ih < oi->npmttdc; ih++) {            for (Int_t ih = 0; ih < oi->npmttdc; ih++) {
1809              Int_t pl = tof_obj->GetPlaneIndex((oi->pmttdc).At(ih));              Int_t pl = tof2_obj->GetPlaneIndex((oi->pmttdc).At(ih));
1810              //      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++;
1811              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))
1812                  || (use_S3 && (pl == 4 || pl == 5))) {                  || (use_S3 && (pl == 4 || pl == 5))) {
# Line 1685  void PamLevel2::SortTracks() { Line 1981  void PamLevel2::SortTracks() {
1981    
1982  }  }
1983  ;  ;
1984    //
1985    //--------------------------------------
1986    /**
1987     * Sort physical (tracker) tracks.
1988     * @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...).
1989     * Sorting cryteria:
1990     * TRK: lower chi**2
1991     * CAL: lower Y spatial residual on the first calorimeter plane
1992     * TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis).
1993     * S1: (ask Emiliano)
1994     * S2: (ask Emiliano)
1995     * S3: (ask Emiliano)
1996     * GP: more GP hits
1997     * The default sorting cryterium is "TOF+CAL".
1998     *
1999     * 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).
2000     *
2001     * New version, with handling of extended tracks and nuclei tracks.
2002     */
2003    void PamLevel2::SortTracksNew() {
2004    
2005      //--------------------------------------------------
2006      //Check if the current event has already been sorted
2007      //--------------------------------------------------
2008      if (issorted_new && lastsorted_new == GetReadEntry()) {
2009          return; //already done for this event
2010      }
2011    
2012    
2013    //  cout << "SORT" << endl;
2014    
2015      //Reset the sort flags, just in case something will go wrong...
2016      issorted_new = false;
2017      lastsorted_new = -1;
2018    
2019      //--------------------------------------------------
2020      // set input variables
2021      //--------------------------------------------------
2022    
2023      TString how = howtosort;
2024      //Save current Object count
2025      Int_t ObjectNumber = TProcessID::GetObjectCount();
2026    
2027    
2028    
2029    
2030      TrkLevel2  * trk2 ;
2031      CaloLevel2 * calo2;
2032      ToFLevel2  * tof2  ;
2033      OrbitalInfo  * orb2 ;
2034      
2035      TClonesArray * trkext ;
2036      TClonesArray * caloext;
2037      TClonesArray * tofext ;
2038      TClonesArray * orbext ;
2039    
2040    
2041    //   cout << "trk2_obj" << trk2_obj<< endl;
2042    //   cout << "trk2_nuc_obj" << trk2_nuc_obj<< endl;
2043    //   cout << " trk_ext_obj "<<trk_ext_obj<< endl;
2044    //   cout << " trk_ext_nuc_obj "<<trk_ext_nuc_obj<< endl;
2045    
2046      //-----------------------------------------------------------
2047      // create/reset TCloneArrays to store tracks and their images
2048      //-----------------------------------------------------------
2049    
2050    //  cout << " PamLevel2::SortTracksNew() --- Clear TClonesArray objects"<<endl;
2051      
2052      // main tracks from standard alg
2053    //   if (!tsorted)
2054    //       tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2055    //   tsorted->Clear("C+C");//Delete();
2056    //   // track images from standard alg
2057    //   if (!timage)
2058    //       timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2059    //   timage->Clear("C+C");//Delete();
2060    //   // tracks from extended algorythm
2061    //   if(EXT && !text)
2062    //       text = new TClonesArray("PamTrack",trk_ext_obj->GetEntries());
2063    //   if(text)text->Clear("C+C");//Delete();
2064    
2065      if(tsorted)delete tsorted;
2066      if(timage) delete timage;
2067      if(text)   delete text;
2068      tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2069      timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2070      text = new TClonesArray("PamTrack",trk_ext_obj->GetEntries());
2071    
2072      //-----------------------------------------------------------
2073      // create/reset TCloneArrays to store tracks and their images
2074      //-----------------------------------------------------------
2075      if(NUC){
2076    
2077          
2078          if(tsorted_nuc)delete tsorted_nuc;
2079          if(timage_nuc) delete timage_nuc;
2080          if(text_nuc)   delete text_nuc;
2081          tsorted_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2082          timage_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2083          text_nuc = new TClonesArray("PamTrack",trk_ext_nuc_obj->GetEntries());
2084    
2085      // main tracks from standard alg
2086    //       if (!tsorted_nuc)
2087    //        tsorted_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2088    //       tsorted_nuc->Clear("C+C");//Delete();
2089    //       // track images from standard alg
2090    //       if (!timage_nuc)
2091    //        timage_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2092    //       timage_nuc->Clear("C+C");//Delete();
2093    //       // tracks from extended algorythm
2094    //       if(EXT && !text_nuc)
2095    //        text_nuc = new TClonesArray("PamTrack",trk_ext_nuc_obj->GetEntries());
2096    //       if(text_nuc)text_nuc->Clear("C+C");//Delete();
2097    
2098      }
2099      //--------------------------------------------------
2100      // retrieve sorting method
2101      //--------------------------------------------------
2102      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
2103      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
2104      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
2105      Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
2106      Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
2107      Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
2108      Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
2109    
2110      if (use_TOF) {
2111        use_S1 = true;
2112        use_S2 = true;
2113        use_S3 = true;
2114      };
2115      if (!CAL2 && use_CAL)
2116        use_CAL = false;
2117      if (!TOF) {
2118        use_TOF = false;
2119        use_S1 = false;
2120        use_S2 = false;
2121        use_S3 = false;
2122      }
2123      if (!GP) {
2124        use_GP = false;
2125      }
2126    
2127      if (!TRK2) {
2128        cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
2129        return;
2130      };
2131    
2132    
2133      ///////////////////////////////////////////////////////////////////////////////////
2134      //
2135      //   sort tracks and fill PamTrack arrays
2136      //
2137      ///////////////////////////////////////////////////////////////////////////////////
2138      for(int doit=0; doit<2; doit++){
2139    
2140    //       cout << "doit "<<doit<<endl;
2141    
2142    
2143          if(doit == 0){
2144    
2145              trk2  = trk2_obj;
2146              calo2 = calo2_obj;
2147              tof2  = tof2_obj;
2148              orb2  = orb2_obj;
2149          
2150              trkext = trk_ext_obj;
2151              caloext = calo_ext_obj;
2152              tofext = tof_ext_obj;
2153              orbext = orb_ext_obj;
2154        
2155          
2156          
2157          
2158    
2159          }else if (doit == 1){
2160    
2161              if(!NUC)break;
2162    
2163          
2164              trk2  = trk2_nuc_obj;
2165              calo2 = calo2_nuc_obj;
2166              tof2  = tof2_nuc_obj;
2167              orb2  = orb2_nuc_obj;
2168          
2169              trkext = trk_ext_nuc_obj;
2170              caloext = calo_ext_nuc_obj;
2171              tofext = tof_ext_nuc_obj;
2172              orbext = orb_ext_nuc_obj;
2173          
2174          
2175          
2176    
2177          }
2178    
2179    //       cout << "trk2" << trk2<<endl;
2180    //       cout << "calo2" << calo2<<endl;
2181    //       cout << "tof2" << tof2<<endl;
2182    //       cout << "orb2" << orb2<<endl;
2183    //       cout << "trkext" <<trkext <<endl;
2184    //       cout << "tofext" << tofext<<endl;
2185    //       cout << "caloext" << caloext<<endl;
2186    //       cout << "orbext" << orbext<<endl;
2187    
2188          TClonesArray &ttext    = (doit==0 ? *text : *text_nuc);
2189          TClonesArray &ttimage  = (doit==0 ? *timage : *timage_nuc);
2190          TClonesArray &ttsorted = (doit==0 ? *tsorted : *tsorted_nuc);
2191      
2192    //       cout << "tsorted + timage "<<doit<<endl;
2193    
2194          //--------------------------------------------------
2195          // loop over "physical" tracks sorted by the tracker
2196          //--------------------------------------------------
2197          for (Int_t i = 0; i < trk2->TrkLevel2::GetNTracks(); i++) {
2198    
2199              TrkTrack *ts = 0;
2200              CaloTrkVar *cs = 0;
2201              ToFTrkVar *os = 0;
2202              OrbitalInfoTrkVar *rs = 0;
2203    
2204              // get tracker tracks
2205              TrkTrack *tp = trk2->GetTrack(i); //tracker
2206              CaloTrkVar *cp = calo2->GetCaloStoredTrack(tp->GetSeqNo());
2207              ToFTrkVar *op = tof2->GetToFStoredTrack(tp->GetSeqNo());
2208              OrbitalInfoTrkVar *rp = orb2->GetOrbitalInfoStoredTrack(tp->GetSeqNo());
2209    
2210              TrkTrack *ti = 0; //tracker (image)
2211              CaloTrkVar *ci = 0;
2212              ToFTrkVar *oi = 0;
2213              OrbitalInfoTrkVar *ri = 0;
2214              //    cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
2215              // if track has an image, check image selection
2216    
2217              Int_t tp_score = 0; //main track sorted by the tracker
2218              Int_t ti_score = 0; //image track
2219              Int_t totp_score = 0; //main track sorted by the tracker
2220              Int_t toti_score = 0; //image track
2221    
2222              if (tp->HasImage()) {
2223    
2224                  ti = trk2->GetTrackImage(i); //tracker (image)
2225                  ci = calo2->GetCaloStoredTrack(ti->GetSeqNo());
2226                  oi = tof2->GetToFStoredTrack(ti->GetSeqNo());
2227                  ri = orb2->GetOrbitalInfoStoredTrack(ti->GetSeqNo());
2228    
2229                  //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
2230    
2231                  //assign starting scores
2232                  tp_score = 0; //main track sorted by the tracker
2233                  ti_score = 0; //image track
2234    
2235                  // -----------------------------------------------------------------------------------------
2236                  // *****************************************************************************************
2237                  // -----------------------------------------------------------------------------------------
2238                  // calorimeter check
2239                  // -----------------------------------------------------------------------------------------
2240                  if (use_CAL && !calo2) {
2241                      cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but CaloLevel2 not loaded !!!";
2242                      return;
2243                  };
2244                  if (use_CAL && !cp && ci) {
2245                      ti_score++;
2246                      toti_score++;
2247                  };
2248                  if (use_CAL && cp && !ci) {
2249                      tp_score++;
2250                      totp_score++;
2251                  };
2252                  if (use_CAL && cp && ci && true) {
2253    
2254                      if (cp->npresh > ci->npresh && true) {
2255                          tp_score++;
2256                          totp_score++;
2257                      };
2258                      if (cp->npresh < ci->npresh && true) {
2259                          ti_score++;
2260                          toti_score++;
2261                      };
2262    
2263                      //    cout << "CALO "<<tp_score<<ti_score<<endl;
2264    
2265                  };
2266                  // -----------------------------------------------------------------------------------------
2267                  // *****************************************************************************************
2268                  // -----------------------------------------------------------------------------------------
2269                  // TOF check
2270                  // -----------------------------------------------------------------------------------------
2271                  // check the number of hit pmts along the track
2272                  // on S12 S21 and S32, where paddles are parallel to Y axis
2273                  if ((use_TOF || use_S1 || use_S2 || use_S3) && !tof2) {
2274                      cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but ToFLevel2 not loaded !!!";
2275                      return;
2276                  };
2277                  //
2278                  if ((use_TOF || use_S1 || use_S2 || use_S3) && !op && oi) {
2279                      ti_score++;
2280                      toti_score++;
2281                  };
2282                  if ((use_TOF || use_S1 || use_S2 || use_S3) && op && !oi) {
2283                      tp_score++;
2284                      totp_score++;
2285                  };
2286                  if ((use_TOF || use_S1 || use_S2 || use_S3) && op && oi) {
2287                      //
2288                      Float_t sen = 0.;
2289                      for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2290                          Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2291                          if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
2292                              sen += (op->dedx).At(ih);
2293                      };
2294                      for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2295                          Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2296                          if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
2297                              sen += (oi->dedx).At(ih);
2298                      };
2299                      //
2300                      if (sen >= sortthr && false) { // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
2301                          //printf(" IS A NUCLEUS! en = %f \n",sen);
2302                          //
2303                          // is a nucleus use a different algorithm
2304                          //
2305                          Int_t nz = 6;
2306                          Float_t zin[6]; // << define TOF z-coordinates
2307                          for (Int_t ip = 0; ip < nz; ip++)
2308                              zin[ip] = tof2->GetZTOF(tof2->GetToFPlaneID(ip)); // << read ToF plane z-coordinates
2309                          Trajectory *tr = new Trajectory(nz, zin);
2310                          //
2311                          Int_t nphit_p = 0;
2312                          Int_t nphit_i = 0;
2313                          Float_t enhit_p = 0.;
2314                          Float_t enhit_i = 0.;
2315                          //
2316                          for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2317                              Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2318                              if (pl == 1 || pl == 2 || pl == 5) {
2319                                  nphit_p++;
2320                                  enhit_p += (op->dedx).At(ih);
2321                              };
2322                          };
2323                          //
2324                          tp->DoTrack2(tr);
2325                          //
2326                          if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
2327                              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2328                                  Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2329                                  if (pl == 0) {
2330                                      nphit_p++;
2331                                      enhit_p += (op->dedx).At(ih);
2332                                  };
2333                              };
2334                          };
2335                          if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
2336                              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2337                                  Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2338                                  if (pl == 3) {
2339                                      nphit_p++;
2340                                      enhit_p += (op->dedx).At(ih);
2341                                  };
2342                              };
2343                          };
2344                          if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
2345                              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2346                                  Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2347                                  if (pl == 4) {
2348                                      nphit_p++;
2349                                      enhit_p += (op->dedx).At(ih);
2350                                  };
2351                              };
2352                          };
2353    
2354                          for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2355                              Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2356                              if (pl == 1 || pl == 2 || pl == 5) {
2357                                  nphit_i++;
2358                                  enhit_i += (op->dedx).At(ih);
2359                              };
2360                          };
2361                          //
2362                          ti->DoTrack2(tr);
2363                          //
2364                          if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
2365                              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2366                                  Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2367                                  if (pl == 0) {
2368                                      nphit_i++;
2369                                      enhit_i += (op->dedx).At(ih);
2370                                  };
2371                              };
2372                          };
2373                          if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
2374                              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2375                                  Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2376                                  if (pl == 3) {
2377                                      nphit_i++;
2378                                      enhit_i += (op->dedx).At(ih);
2379                                  };
2380                              };
2381                          };
2382                          if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
2383                              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2384                                  Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2385                                  if (pl == 4) {
2386                                      nphit_i++;
2387                                      enhit_i += (op->dedx).At(ih);
2388                                  };
2389                              };
2390                          };
2391    
2392                          if ((use_TOF || use_S1 || use_S2 || use_S3) && (nphit_p + nphit_i) != 0 && true) {
2393    
2394                              //        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);
2395                              //        printf(" score p %i score i %i \n",tp_score,ti_score);
2396                              //              if( enhit_p > enhit_i ) tp_score++;
2397                              //              if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
2398                              if (nphit_p > nphit_i)
2399                                  tp_score++;
2400                              if (nphit_p < nphit_i)
2401                                  ti_score++;
2402                              if (nphit_p == nphit_i) {
2403                                  if (enhit_p > enhit_i)
2404                                      tp_score++;
2405                                  else
2406                                      ti_score++;
2407                              };
2408                              //        printf(" dopo score p %i score i %i \n",tp_score,ti_score);
2409                          };
2410                          delete tr;
2411                          //
2412                      }
2413                      else {
2414                          // -------------
2415                          // NOT a NUCLEUS
2416                          // -------------
2417                          //printf(" NOT a NUCLEUS! en = %f \n",sen);
2418    
2419                          Int_t nphit_p = 0;
2420                          Int_t nphit_i = 0;
2421    
2422                          /*                                cout << "track: npmtadc "<< op->npmtadc << endl;
2423                            cout << "track: npmttdc "<< op->npmttdc << endl;
2424                            cout << "image: npmtadc "<< oi->npmtadc << endl;
2425                            cout << "image: npmttdc "<< oi->npmttdc << endl;*/
2426    
2427                          //          for (Int_t ih=0; ih < op->npmtadc; ih++){
2428                          //            Int_t pl = tof2_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
2429                          //            if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
2430                          //          };
2431    
2432                          //          for (Int_t ih=0; ih < oi->npmtadc; ih++){
2433                          //            Int_t pl = tof2_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
2434                          //            if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
2435                          //          };
2436                          // --- modified to count tdc signals (more efficient?)
2437                          // --- and to implement check on tdcflag
2438                          for (Int_t ih = 0; ih < op->npmttdc; ih++) {
2439                              Int_t pl = tof2->GetPlaneIndex((op->pmttdc).At(ih));
2440                              //        if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
2441                              if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
2442                                  || (use_S3 && (pl == 4 || pl == 5))) {
2443                                  if ((op->tdcflag).At(ih) == 0)
2444                                      nphit_p++;
2445                              };
2446                          };
2447    
2448                          for (Int_t ih = 0; ih < oi->npmttdc; ih++) {
2449                              Int_t pl = tof2->GetPlaneIndex((oi->pmttdc).At(ih));
2450                              //        if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;
2451                              if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
2452                                  || (use_S3 && (pl == 4 || pl == 5))) {
2453                                  if ((oi->tdcflag).At(ih) == 0)
2454                                      nphit_i++;
2455                              };
2456                          };
2457    
2458                          if ((nphit_p + nphit_i) != 0 && true) {
2459    
2460                              if (nphit_p != nphit_i) {
2461                                  totp_score += nphit_p;
2462                                  toti_score += nphit_i;
2463                                  tp_score += nphit_p;
2464                                  ti_score += nphit_i;
2465                              };
2466                              //        if     ( nphit_p > nphit_i) tp_score+=nphit_p;
2467                              //        else if( nphit_p < nphit_i) ti_score+=nphit_i;
2468                              //        else ;//niente
2469                          };
2470                      };
2471                      //    cout << "TOF "<<tp_score<<ti_score<<endl;
2472                  };
2473    
2474                  //      if(tp_score == ti_score) use_TRK = true;
2475    
2476    
2477                  // -----------------------------------------------------------------------------------------
2478                  // *****************************************************************************************
2479                  // -----------------------------------------------------------------------------------------
2480                  // tracker check
2481                  // -----------------------------------------------------------------------------------------
2482                  // chi**2 difference is not always large enough to distinguish among
2483                  // the real track and its image.
2484                  // Tracker check will be applied always when calorimeter and tof information is ambiguous.
2485                  // *** MODIFIED ON AUGUST 2007 ***
2486                  if (use_TRK) {
2487                      //    if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
2488                      //    else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
2489    
2490                      // CHECK 1 : number of points along X
2491                      if (tp->GetNX() >= ti->GetNX()) {
2492                          tp_score++;
2493                          totp_score++;
2494                      };
2495                      if (tp->GetNX() <= ti->GetNX()) {
2496                          ti_score++;
2497                          toti_score++;
2498                      };
2499                      // CHECK 2 : number of points along Y
2500                      if (tp->GetNY() >= ti->GetNY()) {
2501                          tp_score++;
2502                          totp_score++;
2503                      };
2504                      if (tp->GetNY() <= ti->GetNY()) {
2505                          ti_score++;
2506                          toti_score++;
2507                      };
2508    
2509                      //    cout << "TRK "<<tp_score<<ti_score<<endl;
2510                  };
2511    
2512                  // -----------------------------------------------------------------------------------------
2513                  // *****************************************************************************************
2514                  // -----------------------------------------------------------------------------------------
2515                  // GPamela check
2516                  // -----------------------------------------------------------------------------------------
2517    
2518                  //---------------------------------------------------
2519                  // count the number of GP hits
2520                  //---------------------------------------------------
2521                  if (use_GP) {
2522                      int ngphits_p = 0;
2523                      int ngphits_i = 0;
2524                      float toll = 0.02; //200 micron
2525                      for (int ih = 0; ih < GetGPamela()->Nthspe; ih++) {
2526                          int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
2527                          if (tp && tp->YGood(ip) && fabs(tp->ym[ip] - GetGPamela()->Yavspe[ih]) < toll && true)
2528                              ngphits_p++;
2529                          if (ti && ti->YGood(ip) && fabs(ti->ym[ip] - GetGPamela()->Yavspe[ih]) < toll && true)
2530                              ngphits_i++;
2531                      }
2532                      if (ngphits_p > ngphits_i && true) {
2533                          tp_score++;
2534                          totp_score++;
2535                      }
2536                      if (ngphits_p < ngphits_i && true) {
2537                          ti_score++;
2538                          toti_score++;
2539                      }
2540                  }
2541    
2542                  // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2543                  // the winner is....
2544                  // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2545                  if (tp_score > ti_score) {
2546    
2547                  }
2548                  else if (tp_score < ti_score) {
2549    
2550                      ts = ti;//its image!!
2551                      cs = ci;
2552                      os = oi;
2553                      rs = ri;
2554                      Int_t totis = toti_score;
2555    
2556                      ti = tp;//its image!!
2557                      ci = cp;
2558                      oi = op;
2559                      ri = rp;
2560    
2561                      tp = ts;//its image!!
2562                      cp = cs;
2563                      op = os;
2564                      rp = rs;
2565    
2566                      toti_score = totp_score;
2567                      totp_score = totis;
2568    
2569                  }
2570                  else {
2571    
2572                      //    cout << "Warning - track image ambiguity not solved" << endl;
2573    
2574                  };
2575    
2576              }
2577              else {
2578                  totp_score = 1;
2579                  toti_score = 0;
2580    
2581                  //            ts = tp;
2582                  //            cs = cp;
2583                  //            os = op;
2584              };
2585    
2586              //    cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
2587              //    sorted_tracks->Add(ts);//save the track in the sorted array
2588              //    sorted_tracks.Add(ts);//save the track in the sorted array
2589              //    sorted_tracks.Add(tp);//save the track in the sorted array
2590              //    cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
2591              //    cout<<"o "<<tp<<endl;
2592              //    cout<<"o "<<cp<<endl;
2593              //    cout<<"o "<<op<<endl;
2594    
2595              new (ttsorted[i]) PamTrack(tp, cp, op, rp);
2596              new (ttimage[i]) PamTrack(ti, ci, oi, ri);
2597    
2598              ((PamTrack*) (ttsorted[i]))->SetPScore(totp_score);
2599              ((PamTrack*) (ttsorted[i]))->SetIScore(toti_score);
2600              ((PamTrack*) (ttimage[i]))->SetPScore(totp_score);
2601              ((PamTrack*) (ttimage[i]))->SetIScore(toti_score);
2602          };
2603    
2604    
2605    
2606    
2607    
2608    //   if (tsorted->GetEntries() != trk2->GetNTracks()) {
2609    //     cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() " << tsorted->GetEntries()
2610    //         << " != trk2->GetNTracks() = " << trk2->GetNTracks() << endl;
2611    //     tsorted->Delete();
2612    //     tsorted = 0;
2613    //     timage->Delete();
2614    //     timage = 0;
2615    //   }
2616    
2617    
2618    //       cout << "text "<<doit<<endl;
2619    
2620    
2621          //--------------------------------------------------
2622          // fill array with extended tracks (this is easy...)
2623          //--------------------------------------------------
2624          if(EXT){
2625              for(int it=0; it<trkext->GetEntries(); it++){
2626                  
2627                  new (ttext[it]) PamTrack((ExtTrack*)(*trkext)[it], (CaloTrkVar*)(*caloext)[it], (ToFTrkVar*)(*tofext)[it], (OrbitalInfoTrkVar*)(*orbext)[it]);
2628                  
2629              }
2630          }
2631          
2632    
2633    
2634      };
2635    
2636    
2637      //Restore Object count
2638      //To save space in the table keeping track of all referenced objects
2639      //We reset the object count to what it was at the beginning of the event.
2640      TProcessID::SetObjectCount(ObjectNumber);
2641    
2642      //Everything went fine so the current event can be tagged as sorted
2643      issorted_new = true;
2644      lastsorted_new = GetReadEntry();
2645    
2646    //   cout << " tsorted "<< tsorted << " "<<(tsorted ? tsorted->GetEntries() : 0)<<endl;
2647    //   cout << " timage  "<< timage  << " "<<(timage  ? timage->GetEntries() : 0)<<endl;
2648    //   cout << " text    "<< text    << " "<<(text    ? text->GetEntries() : 0)<<endl;
2649    
2650    
2651    };
2652  //--------------------------------------  //--------------------------------------
2653  //  //
2654  //  //
# Line 1693  void PamLevel2::SortTracks() { Line 2657  void PamLevel2::SortTracks() {
2657   * 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.
2658   * 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.
2659   */   */
2660    
2661  // TRefArray *PamLevel2::GetTracks(){  // TRefArray *PamLevel2::GetTracks(){
2662    
2663  // //  *-*-*-*-*-*-*-*-*-*-*-*-*  // //  *-*-*-*-*-*-*-*-*-*-*-*-*
# Line 1703  void PamLevel2::SortTracks() { Line 2668  void PamLevel2::SortTracks() {
2668  //     return &sorted_tracks;  //     return &sorted_tracks;
2669    
2670  //  };  //  };
 TClonesArray *PamLevel2::GetTracks() {  
   
   //  *-*-*-*-*-*-*-*-*-*-*-*-*  
   SortTracks();  
   //  *-*-*-*-*-*-*-*-*-*-*-*-*  
2671    
   return tsorted;  
2672    
 }  
 ;  
2673  //--------------------------------------  //--------------------------------------
2674  //  //
2675  //  //
2676  //--------------------------------------  //--------------------------------------
2677    
2678  /**  /**
2679   * Retrieves the it-th Pamela "physical" track.   * Retrieves the it-th Pamela "physical" track.
2680   * It override TrkLevel2::GetTrack(int it).   * It override TrkLevel2::GetTrack(int it).
2681   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
2682   */   */
2683  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;  
   //     };  
2684    
2685    //     return track;    PamTrack *track = NULL;
2686    
   //    cout << "PamLevel2::GetTrack(int it) "<<endl;  
2687    //  *-*-*-*-*-*-*-*-*-*-*-*-*    //  *-*-*-*-*-*-*-*-*-*-*-*-*
2688    SortTracks();    SortTracks();
2689    //  *-*-*-*-*-*-*-*-*-*-*-*-*    //  *-*-*-*-*-*-*-*-*-*-*-*-*
2690    if (!tsorted)    if (!tsorted)
2691      return 0;      return track;
2692    if (!tsorted->GetEntries())  //   if (!tsorted->GetEntries())
2693      return 0;  //     return track;
2694      if (tsorted->GetEntries()==0)
2695        return track;
2696    
   PamTrack *track = 0;  
2697    
2698    if (it >= 0 && it < trk2_obj->TrkLevel2::GetNTracks()) {    if (
2699      //  TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);        tsorted &&
2700      //  track = GetPamTrackAlong(t);        it >= 0 &&
2701      //TClonesArray &t = *(tsorted);        it < trk2_obj->TrkLevel2::GetNTracks() &&
2702      //track = (PamTrack*)t[it];        it < tsorted->GetEntries() &&
2703      track = (PamTrack*)((*tsorted)[it]);        true) {
2704          track = (PamTrack*)((*tsorted)[it]);
2705    }    }
2706    else {    else {
2707      cout << "PamLevel2::GetTrack(int) : tracker track SeqNo " << it << " does not exist (GetNTracks() = "      cout << "PamLevel2::GetTrackOld(int) : tracker track SeqNo " << it << " does not exist (GetNTracks() = "
2708          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
2709    };    };
2710    
2711    return track;    return track;
2712    
2713  }  };
2714  ;  
2715    //PamTrack *PamLevel2::GetTrack(int it) { return GetTrack(it,trkAlg); };
2716    
 //--------------------------------------  
 //  
 //  
 //--------------------------------------  
2717  /**  /**
2718   * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().   * Retrieves the it-th Pamela "physical" track.
2719     * It override TrkLevel2::GetTrack(int it).
2720   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
2721     * @param alg Algorythm, see SetTrakingAlgorythm(char *alg) for explanation.
2722   */   */
2723  PamTrack *PamLevel2::GetTrackImage(int it) {  PamTrack *PamLevel2::GetTrack(int it, const char* alg) {
2724    
2725    //  *-*-*-*-*-*-*-*-*-*-*-*-*      TString s(alg);
2726    SortTracks();      if(!s.CompareTo("") ||!s.CompareTo("STD") )return GetTrackOld(it); //old algorythm
2727    //  *-*-*-*-*-*-*-*-*-*-*-*-*  
2728    
2729        SortTracksNew();
2730        // >> fill tsorted, timage and text
2731    
2732        if ( ( !s.Contains("EXTF", TString::kIgnoreCase) || !EXT )){ //not forced exteded-alg requested (or exteded-data missing)
2733    
2734            if( s.Contains("NUC")){
2735                if(
2736                    tsorted_nuc &&
2737                    it < tsorted_nuc->GetEntries() &&                             //enough tracks found
2738                    it >= 0 &&                                                //valid index
2739                    true) return (PamTrack*)((*tsorted_nuc)[it]);                 //ok return the track
2740            }else{
2741                if(
2742                    tsorted &&
2743                    it < tsorted->GetEntries() &&                             //enough tracks found
2744                    it >= 0 &&                                                //valid index
2745                    true )return (PamTrack*)((*tsorted)[it]);                 //ok return the track
2746            }
2747    
2748        }
2749        
2750    
2751        /////////////////////////////////////////////////////////////////////////
2752        /// if requested get track from extended algorythm output
2753        /////////////////////////////////////////////////////////////////////////
2754        
2755        if(s.Contains("EXT", TString::kIgnoreCase) && EXT){//if exteded-alg requested
2756            
2757            if(s.Contains("NUC")){
2758                if(
2759                    text_nuc &&
2760                    it < text_nuc->GetEntries() &&                             //enough tracks found
2761                    it >= 0 &&                                                //valid index
2762                    true) return (PamTrack*)((*text_nuc)[it]);
2763            }else{
2764                if(
2765                    text &&
2766                    it < text->GetEntries() &&                             //enough tracks found
2767                    it >= 0 &&                                                //valid index
2768                    true) return (PamTrack*)((*text)[it]);
2769            }
2770    
2771        };
2772        
2773        
2774        cout << "PamTrack *PamLevel2::GetTrack("<<it<<","<<alg<<") -- wrong track number or unrecognised algorithm"<<endl;
2775        
2776        return NULL;
2777    
2778    }
2779    ;
2780    TClonesArray *PamLevel2::GetTracks() {
2781    
2782      //  *-*-*-*-*-*-*-*-*-*-*-*-*
2783      SortTracks();
2784      //  *-*-*-*-*-*-*-*-*-*-*-*-*
2785    
2786      return tsorted;
2787    
2788    }
2789    ;
2790    Int_t  PamLevel2::GetNTracks(const char* alg) {
2791    
2792    
2793    //    cout << " trk_nuc_obj->GetEntries() "<<trk_nuc_obj->GetEntries()<<" trk2_nuc_obj->GetNTracks() "<<trk2_nuc_obj->GetNTracks()<<endl;
2794    
2795        TString s(alg);
2796    
2797        if(!s.CompareTo("") || !s.CompareTo("STD"))return trk2_obj->TrkLevel2::GetNTracks(); //standard algorythm
2798            
2799        if(s.Contains("EXTF", TString::kIgnoreCase) && EXT){
2800            if(s.Contains("NUC", TString::kIgnoreCase) && NUC)return trk_ext_nuc_obj->GetEntries();//ok
2801            return trk_ext_obj->GetEntries();//ok
2802        }
2803        if( s.Contains("EXT", TString::kIgnoreCase) && EXT) {
2804            if(s.Contains("NUC", TString::kIgnoreCase) && NUC)
2805                return (trk2_nuc_obj->TrkLevel2::GetNTracks() ?  trk2_nuc_obj->TrkLevel2::GetNTracks() :  trk_ext_nuc_obj->GetEntries() );  
2806            return (trk2_obj->TrkLevel2::GetNTracks() ?  trk2_obj->TrkLevel2::GetNTracks() :  trk_ext_obj->GetEntries() );
2807        }
2808        if(s.Contains("NUC", TString::kIgnoreCase) && NUC )
2809            return trk2_nuc_obj->TrkLevel2::GetNTracks();
2810        
2811        cout << "Int_t  PamLevel2::GetNTracks("<<alg<<") -- unrecognised algorithm"<<endl;
2812    
2813        return 0;
2814    
2815    }
2816    
2817    
2818    //--------------------------------------
2819    //
2820    //
2821    //--------------------------------------
2822    /**
2823     * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().
2824     * @param it Track number, ranging from 0 to GetNTracks().
2825     */
2826    PamTrack *PamLevel2::GetTrackImageOld(int it) {
2827    
2828      //  *-*-*-*-*-*-*-*-*-*-*-*-*
2829      SortTracks();
2830      //  *-*-*-*-*-*-*-*-*-*-*-*-*
2831    if (!timage)    if (!timage)
2832      return 0;      return 0;
2833    if (!timage->GetEntries())    if (!timage->GetEntries())
# Line 1803  PamTrack *PamLevel2::GetTrackImage(int i Line 2847  PamTrack *PamLevel2::GetTrackImage(int i
2847      };      };
2848    }    }
2849    else {    else {
2850      cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo " << it << " does not exist (GetNTracks() = "      cout << "PamLevel2::GetTrackImageOld(int) : Tracker track SeqNo " << it << " does not exist (GetNTracks() = "
2851          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
2852    };    };
2853    
2854    return image;    return image;
2855  }  }
2856    /**
2857     * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().
2858     * @param it Track number, ranging from 0 to GetNTracks().
2859     * @param alg Algorythm, see SetTrakingAlgorythm(char *alg) for explanation.
2860     */
2861    PamTrack *PamLevel2::GetTrackImage(int it, const char* alg) {
2862    
2863        TString s(alg);
2864        if(!s.CompareTo("") || !s.CompareTo("STD"))return GetTrackImageOld(it); //old algorythm
2865    
2866    
2867        SortTracksNew();
2868        // >> fill tsorted, timage and text
2869    
2870        if ( ( !s.Contains("EXTF", TString::kIgnoreCase) || !EXT )){ //not forced exteded-alg requested (or exteded-data missing)
2871    
2872            if( s.Contains("NUC")){
2873                if(
2874                    tsorted_nuc &&
2875                    it < tsorted_nuc->GetEntries() &&                             //enough tracks found
2876                    it >= 0 &&                                                //valid index
2877                    true){
2878                    TClonesArray &t = *(tsorted_nuc);
2879                    PamTrack *temp = (PamTrack*) t[it];
2880                    if (temp->GetTrkTrack()->HasImage()) {
2881                        return (PamTrack*)((*timage_nuc)[it]);                 //ok return the track
2882                    }else{
2883                        return NULL;
2884                    }
2885                    
2886                }
2887            }else{
2888                if(
2889                    tsorted &&
2890                    it < tsorted->GetEntries() &&                             //enough tracks found
2891                    it >= 0 &&                                                //valid index
2892                    true ){
2893                    TClonesArray &t = *(tsorted);
2894                    PamTrack *temp = (PamTrack*) t[it];
2895                    if (temp->GetTrkTrack()->HasImage()) {              
2896                        return (PamTrack*)((*timage)[it]);                 //ok return the track
2897                    }else{
2898                        return NULL;
2899                    }
2900                }
2901            }
2902    
2903        }
2904    
2905    //    cout << "PamTrack *PamLevel2::GetTrackImage("<<it<<","<<alg<<") -- wrong track number or unrecognised algorithm"<<endl;
2906          
2907        return NULL;
2908    
2909    }
2910    ;
2911    
2912  //--------------------------------------  //--------------------------------------
2913  //  //
# Line 1898  TTree *PamLevel2::GetPamTree(TFile *f, T Line 2997  TTree *PamLevel2::GetPamTree(TFile *f, T
2997      if (!Trout)      if (!Trout)
2998        Trout = T;        Trout = T;
2999      else      else
3000        Trout->AddFriend(T);          Trout->AddFriend(T);
3001    }    }
3002    else {    else {
3003      cout << "Tracker      : missing tree" << endl;      cout << "Tracker      : missing tree" << endl;
# Line 2263  TChain *PamLevel2::GetPamTree(TList *fl, Line 3362  TChain *PamLevel2::GetPamTree(TList *fl,
3362    TChain *G = 0;    TChain *G = 0;
3363    
3364    TChain *L = 0;    TChain *L = 0;
3365      TChain *P = 0;
3366    
3367    if (TRK2 || TRK1 || TRKh)    if (TRK2 || TRK1 || TRKh)
3368      T = new TChain("Tracker");      T = new TChain("Tracker");
# Line 2282  TChain *PamLevel2::GetPamTree(TList *fl, Line 3382  TChain *PamLevel2::GetPamTree(TList *fl,
3382      B = new TChain("OrbitalInfo");      B = new TChain("OrbitalInfo");
3383    if (GP)    if (GP)
3384      G = new TChain("h20");      G = new TChain("h20");
3385      if (PROC)
3386        P = new TChain("ProcessingInfo");
3387    L = new TChain("SelectionList");    L = new TChain("SelectionList");
3388    
3389    // loop over files and create chains    // loop over files and create chains
# Line 2309  TChain *PamLevel2::GetPamTree(TList *fl, Line 3411  TChain *PamLevel2::GetPamTree(TList *fl,
3411          B->Add(name);          B->Add(name);
3412        if (GP)        if (GP)
3413          G->Add(name);          G->Add(name);
3414          if (P)
3415            P->Add(name);
3416        if (SELLI == 1)        if (SELLI == 1)
3417          L->Add(name);          L->Add(name);
3418      };       };
3419    };    };
3420    
3421    cout << "done chains\n";    cout << "done data-tree chains  "<<  T->GetNtrees() <<" \n";
3422    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;    cout << "----------------------------------------------------" << endl;
3423    
3424    // -------------------------------------------    // -------------------------------------------
3425    // make friends    // make friends
# Line 2398  TChain *PamLevel2::GetPamTree(TList *fl, Line 3502  TChain *PamLevel2::GetPamTree(TList *fl,
3502    //  =====================================    //  =====================================
3503    //  SET BRANCH-ADDRESS AFTER CHAIN+FRIEND    //  SET BRANCH-ADDRESS AFTER CHAIN+FRIEND
3504    //  =====================================    //  =====================================
3505    SetBranchAddress(Trout);    if( Trout->GetNtrees() )SetBranchAddress(Trout);
3506    
3507    //  ------------------------------------    //  ------------------------------------
3508    //  finally handle selection trees...    //  finally handle selection trees...
3509    //  (it is not friend of pamela tree)    //  (it is not friend of pamela tree)
3510    //  ------------------------------------    //  ------------------------------------
3511    
3512    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;    cout << "----------------------------------------------------" << endl;
3513    
3514    // Selection List    // Selection List
3515    if (L && SELLI == 1) {    if (L && SELLI == 1) {
# Line 2415  TChain *PamLevel2::GetPamTree(TList *fl, Line 3519  TChain *PamLevel2::GetPamTree(TList *fl,
3519      cout << "SelectionList: set branch address RunEntry" << endl;      cout << "SelectionList: set branch address RunEntry" << endl;
3520      L->SetBranchAddress("EventEntry", &irunentry);      L->SetBranchAddress("EventEntry", &irunentry);
3521      cout << "SelectionList: set branch address EventEntry" << endl;      cout << "SelectionList: set branch address EventEntry" << endl;
3522        /*    if ( L->GetBranch("L0EventEntry") ){
3523          hasL0EE = true;
3524          L->SetBranchAddress("L0EventEntry", &il0entry);
3525          cout << "SelectionList: set branch address L0EventEntry" << endl;
3526        } else {
3527          hasL0EE = false; // backward compatibility with old preselected files...
3528          }*/
3529      sel_tree = L;      sel_tree = L;
3530      //          if(!Trout)Trout=O;      //          if(!Trout)Trout=O;
3531      //          else Trout->AddFriend("SelectionList");      //          else Trout->AddFriend("SelectionList");
3532      cout << "+SelectionList" << endl;      cout << "+SelectionList" << endl;
3533      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;      cout << "----------------------------------------------------" << endl;
3534    }    }
3535    else {    else {
3536      //  cout << "SelectionList  : missing tree"<<endl;      //  cout << "SelectionList  : missing tree"<<endl;
# Line 2427  TChain *PamLevel2::GetPamTree(TList *fl, Line 3538  TChain *PamLevel2::GetPamTree(TList *fl,
3538        L->Delete();        L->Delete();
3539    };    };
3540    
3541      //ProcessingInfo EM
3542      if ( P && P->GetEntries() ){
3543        cout << "----------------------------------------------------" << endl;
3544        cout << ">>> Found ProcessingInfo <<<" << endl;
3545        //  L->SetBranchAddress("RunEntry",&irun);
3546        P->SetBranchAddress("ProcInfo", &proc_obj);//NEWNEW
3547        proc_tree = P;
3548      } else {
3549        //    proc_tree = new TChain("ProcessingInfo","Log of data processing");
3550        //    proc_tree->Branch("ProcInfo", "ProcInfo", &proc_obj);
3551        cout << "----------------------------------------------------" << endl;
3552        cout << ">>> ProcessingInfo not found, PROC set to false and continue (not 10RED files?)<<<" << endl;
3553        PROC = false;
3554      }
3555    //  --------------------------------------------    //  --------------------------------------------
3556    //  return the pamela chain with all the friends    //  return the pamela chain with all the friends
3557    //  --------------------------------------------    //  --------------------------------------------
3558    
3559    pam_tree = Trout;    pam_tree = Trout;
   
3560    return Trout;    return Trout;
3561  }  }
3562    
# Line 2445  TChain *PamLevel2::GetPamTree(TList *fl, Line 3569  TChain *PamLevel2::GetPamTree(TList *fl,
3569   */   */
3570  void PamLevel2::SetBranchAddress(TTree *t) {  void PamLevel2::SetBranchAddress(TTree *t) {
3571    
3572    TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");  //   TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
3573    TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");  //   TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
3574    TRKh = TRKh & t->GetBranchStatus("TrkHough");  //   TRKh = TRKh & t->GetBranchStatus("TrkHough");
3575    CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");  //   CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
3576    CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");  //   CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
3577    TOF = TOF & t->GetBranchStatus("ToFLevel2");  //   TOF = TOF & t->GetBranchStatus("ToFLevel2");
3578    TRG = TRG & t->GetBranchStatus("TrigLevel2");  //   TRG = TRG & t->GetBranchStatus("TrigLevel2");
3579    S4 = S4 & t->GetBranchStatus("S4Level2");  //   S4 = S4 & t->GetBranchStatus("S4Level2");
3580    ND = ND & t->GetBranchStatus("NDLevel2");  //   ND = ND & t->GetBranchStatus("NDLevel2");
3581    AC = AC & t->GetBranchStatus("AcLevel2");  //   AC = AC & t->GetBranchStatus("AcLevel2");
3582    ORB = ORB & t->GetBranchStatus("OrbitalInfo");  //   ORB = ORB & t->GetBranchStatus("OrbitalInfo");
3583    GP = GP & t->GetBranchStatus("h20");  //   GP = GP & t->GetBranchStatus("h20");
3584    
3585    
3586    // Tracker    // Tracker
3587    if (TRK1) {    if (TRK1) {
# Line 2466  void PamLevel2::SetBranchAddress(TTree * Line 3591  void PamLevel2::SetBranchAddress(TTree *
3591    if (TRK2) {    if (TRK2) {
3592      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));
3593      cout << "Tracker      : set branch address TrkLevel2" << endl;      cout << "Tracker      : set branch address TrkLevel2" << endl;
3594        NUC = t->GetBranchStatus("TrackNuclei");
3595        EXT = t->GetBranchStatus("RecoveredTrack") && (NUC ? t->GetBranchStatus("RecoveredTrackNuclei"): true );    
3596    };    };
3597    if (TRKh) {    if (TRKh) {
3598      t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));      t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
# Line 2526  void PamLevel2::SetBranchAddress(TTree * Line 3653  void PamLevel2::SetBranchAddress(TTree *
3653    
3654      cout << "h20          : set branch address GPamela " << endl;      cout << "h20          : set branch address GPamela " << endl;
3655    };    };
3656      if(NUC){
3657          
3658          cout << "Found nuclei-track branches" << endl;
3659    
3660          if( !trk_nuc_obj )trk_nuc_obj = new TClonesArray("TrkTrack");
3661          if( !calo_nuc_obj)calo_nuc_obj= new TClonesArray("CaloTrkVar");
3662          if( !tof_nuc_obj)tof_nuc_obj= new TClonesArray("ToFTrkVar");
3663          if( !orb_nuc_obj)orb_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3664          if (TRK2)t->                          SetBranchAddress("TrackNuclei",&trk_nuc_obj);
3665          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("TrackNuclei",&calo_nuc_obj);
3666          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("TrackNuclei",&tof_nuc_obj);
3667          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("TrackNuclei",&orb_nuc_obj);
3668    
3669          ///copy the vector content inside a "fake" object (all aother info are missing)    
3670    
3671          if( !trk2_nuc_obj )trk2_nuc_obj =  new TrkLevel2();
3672          if( !calo2_nuc_obj )calo2_nuc_obj =  new CaloLevel2();
3673          if( !tof2_nuc_obj )tof2_nuc_obj =  new ToFLevel2();
3674          if( !orb2_nuc_obj )orb2_nuc_obj =  new OrbitalInfo();
3675    //       *(trk2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*trk_nuc_obj);
3676    //       *(calo2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*calo_nuc_obj);
3677    //       *(tof2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*tof_nuc_obj);
3678    //       *(orb2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*orb_nuc_obj);
3679    
3680          trk2_nuc_obj->SetTrackArray(  trk_nuc_obj  );
3681          calo2_nuc_obj->SetTrackArray( calo_nuc_obj );
3682          tof2_nuc_obj->SetTrackArray(  tof_nuc_obj  );
3683          orb2_nuc_obj->SetTrackArray(  orb_nuc_obj  );
3684    
3685          
3686      }    
3687    
3688      if(EXT){
3689          
3690          cout << "Found extended tracking algorythm branches" << endl;
3691    
3692          if( !trk_ext_obj )trk_ext_obj = new TClonesArray("ExtTrack");
3693          if( !calo_ext_obj)calo_ext_obj= new TClonesArray("CaloTrkVar");
3694          if( !tof_ext_obj)tof_ext_obj= new TClonesArray("ToFTrkVar");
3695          if( !orb_ext_obj)orb_ext_obj= new TClonesArray("OrbitalInfoTrkVar");
3696          
3697          if (TRK2)t->                          SetBranchAddress("RecoveredTrack",&trk_ext_obj);
3698          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrack",&calo_ext_obj);
3699          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrack",&tof_ext_obj);
3700          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrack",&orb_ext_obj);
3701    
3702        
3703          if(NUC){
3704              if( !trk_ext_nuc_obj )trk_ext_nuc_obj = new TClonesArray("ExtTrack");
3705              if( !calo_ext_nuc_obj)calo_ext_nuc_obj= new TClonesArray("CaloTrkVar");
3706              if( !tof_ext_nuc_obj)tof_ext_nuc_obj= new TClonesArray("ToFTrkVar");
3707              if( !orb_ext_nuc_obj)orb_ext_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3708              if (TRK2)t->                          SetBranchAddress("RecoveredTrackNuclei",&trk_ext_nuc_obj);
3709              if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrackNuclei",&calo_ext_nuc_obj);
3710              if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrackNuclei",&tof_ext_nuc_obj);
3711              if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrackNuclei",&orb_ext_nuc_obj);
3712          }
3713      }    
3714  }  }
3715  /**  /**
3716   * Set branch addresses for Pamela friend trees   * Set branch addresses for Pamela friend trees
# Line 2550  void PamLevel2::SetBranchAddress(TChain Line 3734  void PamLevel2::SetBranchAddress(TChain
3734    if (TRK2) {    if (TRK2) {
3735      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
3736      cout << "Tracker      : set branch address TrkLevel2" << endl;      cout << "Tracker      : set branch address TrkLevel2" << endl;
3737        NUC = t->GetBranchStatus("TrackNuclei");
3738        EXT = t->GetBranchStatus("RecoveredTrack") && (NUC ? t->GetBranchStatus("RecoveredTrackNuclei"): true );
3739    };    };
3740    if (TRK1) {    if (TRK1) {
3741      t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));      t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
# Line 2563  void PamLevel2::SetBranchAddress(TChain Line 3749  void PamLevel2::SetBranchAddress(TChain
3749    // Calorimeter    // Calorimeter
3750    if (CAL2) {    if (CAL2) {
3751      t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));      t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
3752      cout << "Calorimeter  : set branch address CaloLevel2" << endl;      cout << "Calorimeter  : set branch address CaloLevel2" << endl;    
3753    };    };
3754    if (CAL1) {    if (CAL1) {
3755      t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));      t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
# Line 2621  void PamLevel2::SetBranchAddress(TChain Line 3807  void PamLevel2::SetBranchAddress(TChain
3807    //    cout << "SelectionList: set branch address EventEntry"<<endl;    //    cout << "SelectionList: set branch address EventEntry"<<endl;
3808    
3809    //     }    //     }
3810      if(NUC){
3811          
3812          cout << "Found nuclei-track branches" << endl;
3813    
3814          if( !trk_nuc_obj )trk_nuc_obj = new TClonesArray("TrkTrack");
3815          if( !calo_nuc_obj)calo_nuc_obj= new TClonesArray("CaloTrkVar");
3816          if( !tof_nuc_obj)tof_nuc_obj= new TClonesArray("ToFTrkVar");
3817          if( !orb_nuc_obj)orb_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3818          if (TRK2)t->                          SetBranchAddress("TrackNuclei",&trk_nuc_obj);
3819          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("TrackNuclei",&calo_nuc_obj);
3820          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("TrackNuclei",&tof_nuc_obj);
3821          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("TrackNuclei",&orb_nuc_obj);
3822          
3823          ///copy the vector content inside a "fake" object (all aother info are missing)    
3824    
3825          if( !trk2_nuc_obj )trk2_nuc_obj =  new TrkLevel2();
3826          if( !calo2_nuc_obj )calo2_nuc_obj =  new CaloLevel2();
3827          if( !tof2_nuc_obj )tof2_nuc_obj =  new ToFLevel2();
3828          if( !orb2_nuc_obj )orb2_nuc_obj =  new OrbitalInfo();
3829    
3830    //       *(trk2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*trk_nuc_obj);
3831    //       *(calo2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*calo_nuc_obj);
3832    //       *(tof2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*tof_nuc_obj);
3833    //       *(orb2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*orb_nuc_obj);
3834          trk2_nuc_obj->SetTrackArray(  trk_nuc_obj  );
3835          calo2_nuc_obj->SetTrackArray( calo_nuc_obj );
3836          tof2_nuc_obj->SetTrackArray(  tof_nuc_obj  );
3837          orb2_nuc_obj->SetTrackArray(  orb_nuc_obj  );
3838    
3839      }    
3840      if(EXT){
3841          
3842          cout << "Found extended tracking algorythm branches" << endl;
3843    
3844          t->SetBranchAddress("extAlgFlag",&extAlgFlag);
3845    
3846          if( !trk_ext_obj )trk_ext_obj = new TClonesArray("ExtTrack");
3847          if( !calo_ext_obj)calo_ext_obj= new TClonesArray("CaloTrkVar");
3848          if( !tof_ext_obj)tof_ext_obj= new TClonesArray("ToFTrkVar");
3849          if( !orb_ext_obj)orb_ext_obj= new TClonesArray("OrbitalInfoTrkVar");
3850          
3851          if (TRK2)t->                          SetBranchAddress("RecoveredTrack",&trk_ext_obj);
3852          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrack",&calo_ext_obj);
3853          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrack",&tof_ext_obj);
3854          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrack",&orb_ext_obj);
3855          
3856          if(NUC){
3857              if( !trk_ext_nuc_obj )trk_ext_nuc_obj = new TClonesArray("ExtTrack");
3858              if( !calo_ext_nuc_obj)calo_ext_nuc_obj= new TClonesArray("CaloTrkVar");
3859              if( !tof_ext_nuc_obj)tof_ext_nuc_obj= new TClonesArray("ToFTrkVar");
3860              if( !orb_ext_nuc_obj)orb_ext_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3861              if (TRK2)t->                          SetBranchAddress("RecoveredTrackNuclei",&trk_ext_nuc_obj);
3862              if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrackNuclei",&calo_ext_nuc_obj);
3863              if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrackNuclei",&tof_ext_nuc_obj);
3864              if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrackNuclei",&orb_ext_nuc_obj);
3865          }
3866      }    
3867      
3868  }  }
3869    
3870    /**
3871     * Set the tracking algorythm
3872     * @param alg String to choose the track.
3873     * "" --> take the output of the standard tracking algorythm
3874     * "STD" --> take the output of the standard tracking algorythm
3875     * "NUC" --> take the output of the standard tracking algorythm for nuclei cluster selection
3876     * "EXT" --> in case the standard tracking algorythm has not found any track, take the output of the extended one
3877     * "EXTF" --> force the extended tracking algorythm
3878     * "NUCEXT" --> as "EXT", but for nuclei
3879     * "NUCEXTF" --> as "EXTF", but for nuclei
3880     */
3881    // void PamLevel2::SetTrackingAlgorythm(const char *alg){
3882    
3883    
3884    //     TString s(alg);
3885    //     if(s.Contains("NUC", TString::kIgnoreCase) && !NUC)
3886    //      cout << "Warning! NUC algorythm requested, but branches are missing"<<endl;
3887    //     if(s.Contains("EXT", TString::kIgnoreCase) && !EXT)
3888    //      cout << "Warning! EXT algorythm requested, but branches are missing"<<endl;;
3889                
3890    //     trkAlg = alg;
3891    
3892    // };
3893    // const char* PamLevel2::GetTrackingAlgorythm(){
3894    
3895    
3896    //     cout<<endl<<" Implemented tracking algorythm: ";
3897    //     cout<<endl<<"  \"\" or \"STD\"  --> take the output of the standard tracking algorythm";
3898    //     cout<<endl<<"  \"NUC\"      --> take the output of the standard tracking algorythm for nuclei cluster selection";
3899    //     cout<<endl<<"  \"EXT\"      --> in case the standard tracking algorythm has not found any track,";
3900    //     cout<<endl<<"                 take the output of the extended one";
3901    //     cout<<endl<<"  \"EXTF\"     --> force the extended tracking algorythm";
3902    //     cout<<endl<<"  \"NUCEXT\"   --> as \"EXT\", but for nuclei ";
3903    //     cout<<endl<<"  \"NUCEXTF\"  --> as \"EXTF\", but for nuclei";
3904    
3905    //     cout<<endl;
3906    //     cout<<" <<Currently set algorythm>> "<<trkAlg<<endl;
3907    //     cout<<endl;
3908    
3909    //     return trkAlg;
3910    // };
3911    
3912    
3913    
3914  //--------------------------------------  //--------------------------------------
3915  //  //
3916  //  //
# Line 2657  TChain *PamLevel2::GetRunTree(TList *fl) Line 3944  TChain *PamLevel2::GetRunTree(TList *fl)
3944      };      };
3945    }    }
3946    
3947      cout << "done run chain  "<<  R->GetNtrees() <<" \n";
3948    
3949    
3950    if (RUN && R->GetNtrees()) {    if (RUN && R->GetNtrees()) {
3951    
3952      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
# Line 2696  TChain *PamLevel2::GetRunTree(TList *fl) Line 3986  TChain *PamLevel2::GetRunTree(TList *fl)
3986      cout << "----------------------------------------------------" << endl;      cout << "----------------------------------------------------" << endl;
3987    
3988    }    }
3989    else {  //   else {
3990      delete R;  //     delete R;
3991      R = 0;  //     R = 0;
3992    }  //   }
3993    
3994    run_tree = R;    run_tree = R;
3995    
# Line 2738  TTree *PamLevel2::GetRunTree(TFile *f) { Line 4028  TTree *PamLevel2::GetRunTree(TFile *f) {
4028    return T;    return T;
4029    
4030  }  }
 /**  
  * 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;  
   //  
 }  
 ;  
4031    
4032  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) {  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) {
4033    
4034      if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - inside\n");
4035    
4036    if (!run_tree) {    if (!run_tree) {
4037      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;
4038      return false;      return false;
# Line 2888  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4042  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4042      return (false);      return (false);
4043    }    }
4044    
4045    
4046    Int_t oldrun = irun; // store current run index    Int_t oldrun = irun; // store current run index
4047    
4048    // -----------------------------------------------------------------------    // -----------------------------------------------------------------------
# Line 2897  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4052  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4052    if (irun < 0) {    if (irun < 0) {
4053      irun = 0LL;      irun = 0LL;
4054      irunt = 0LL;      irunt = 0LL;
4055      irunentry = 0;      totrunentry = 0LL;
4056        totrunentrymin = 0LL;
4057        totrunentrymax = 0LL;
4058        irunentry = 0LL;
4059        il0entry = 0LL;
4060      prevshift = 0;      prevshift = 0;
4061        yprevshift = 0;
4062        prevabstime = 0;
4063        prevpktnum = 0;
4064        abstime = 0ULL;
4065        pktnum = 0;
4066        isFragment = false;
4067      run_tree->GetEntry(irun);      run_tree->GetEntry(irun);
4068      if (!GetOrbitalInfo())      if (!GetOrbitalInfo())
4069        cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated " << endl;        cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated " << endl;
4070      if (gltsync)      if ( fUseDBinRunInfo ){
4071        delete gltsync; //Emiliano        if (gltsync)
4072      if (!dbc || (dbc && !dbc->IsConnected()))          delete gltsync; //Emiliano
4073        SetDBConnection(); //Emiliano        if (!dbc || (dbc && !dbc->IsConnected()))
4074      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
4075      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)
4076        dbc->Close();// Emiliano        if (dbc){
4077        delete dbc;          dbc->Close();// Emiliano
4078        dbc=0;          delete dbc;
4079      };          dbc=0;
4080    };        }
4081        }
4082      }
4083    // ---------------------------------------------------------------    // ---------------------------------------------------------------
4084    // retrieve OBT and absolute time of the event    // retrieve OBT and absolute time of the event
4085    // ---------------------------------------------------------------    // ---------------------------------------------------------------
   ULong64_t abstime = 0LL;  
   //    ULong64_t obt     = 0LL; // Emiliano  
4086    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
4087      prevabstime = abstime;
4088      prevpktnum = pktnum;
4089    if (GetOrbitalInfo()) {    if (GetOrbitalInfo()) {
4090      abstime = GetOrbitalInfo()->absTime;      abstime = GetOrbitalInfo()->absTime;
4091      obt = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano      if ( fUseDBinRunInfo ) obt = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano
4092        pktnum = GetOrbitalInfo()->pkt_num; // Emiliano
4093    }    }
4094    else {    else {
4095      abstime = GetRunInfo()->RUNHEADER_TIME;      abstime = GetRunInfo()->RUNHEADER_TIME;
4096      obt = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano      if ( fUseDBinRunInfo ) obt = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano
4097        pktnum = GetRunInfo()->RUNHEADER_PKT; // Emiliano
4098      }
4099    
4100      if (DBG){
4101        printf("0abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4102        printf("0        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4103        printf("0        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4104        if ( fUseDBinRunInfo ) printf("0        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4105        printf("0        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4106        printf("0        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);
4107    }    }
4108    
4109    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# Line 2946  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4124  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4124      }      }
4125    
4126      //      //
4127      bool fromfirst = true; // first loop over runs      bool a = true;
4128        bool b = true;
4129        if ( fUseDBinRunInfo ){
4130          a = false;    
4131          b = false;
4132          if ( obt < gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) ) a = true;
4133          if ( obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ) b = true;
4134        }
4135        if ( iev < totrunentrymin || iev > totrunentrymax // entry is outside run limits
4136             || iev == 0 // or it is the first entry
4137             || (!isSync && (
4138                             (abstime <= GetRunInfo()->RUNHEADER_TIME && a ) // or it is outside obt limits (and abstime limits for security reasons)
4139                             || (abstime >= GetRunInfo()->RUNTRAILER_TIME && b ) ))// or it is outside obt limits (and abstime limits for security reasons)
4140             ){ // check on abstime and obt needed to handle nested+DV_skipped packets
4141          
4142          // check for a new run (ma prima il primo!)
4143          if (DBG){
4144            printf("1abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4145            printf("1        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4146            printf("1        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4147            if ( fUseDBinRunInfo ) printf("1        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4148            printf("1        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4149            printf("1        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);
4150          }
4151          //        printf("1abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4152          //        printf("1        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4153          //        printf("1        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4154          //        printf("1        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4155          //        printf("1        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4156          //        printf("1        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);//TOGLITOGLI
4157    
4158      // ------------------------------------------------------        totrunentry = 0LL;
4159      // loop over runs to find the one that contains the event        runfirstentry = 0LL;
4160      // ------------------------------------------------------        for (Int_t r=0; r< run_tree->GetEntries();r++){
4161      while ((          // -------------------------------------------------------------------
4162      //          (          // save the index of the first entry of the run, relative to pam_tree,
4163      //              !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)          // and read a new run
4164      //                abstime <= GetRunInfo()->RUNTRAILER_TIME) &&          // -------------------------------------------------------------------
4165      //              !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)          run_tree->GetEntry(r);//update runinfo
4166      //                obt <= GetRunInfo()->RUNTRAILER_OBT)          if ( r > 0 ){
4167      //              )            totrunentrymin = totrunentrymax+1;
4168            } else {
4169      !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s)            totrunentrymin = 0LL;
4170          abstime <= GetRunInfo()->RUNTRAILER_TIME) || !(obt >= gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) && // additional check on OBT (ms) // Emiliano          }
4171          obt <= gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) // Emiliano          totrunentry += GetRunInfo()->NEVENTS;
4172          || GetRunInfo()->NEVENTS == 0          totrunentrymax = totrunentry - 1 - prevshift; // prevshift is needed to handle nested+DV_skipped packets
4173      //          || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento          irun = r;        
4174          || !(irunentry <= GetRunInfo()->NEVENTS - 1 - prevshift)) && irun < run_tree->GetEntries()) {          if ( fUseDBinRunInfo ){
4175              a = false;    
4176        //            if( !(abstime >= GetRunInfo()->RUNHEADER_TIME &&abstime <= GetRunInfo()->RUNTRAILER_TIME)  )cout << "ABS TIME "<<abstime << " " <<GetRunInfo()->RUNTRAILER_TIME <<endl;            b = false;
4177        //            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;
4178        //            if( GetRunInfo()->NEVENTS==0  )cout <<"GetRunInfo()->NEVENTS==0 "<<endl;            if ( obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ) b = true;
4179        //            if( !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift) ) cout << "irunentry > "<<GetRunInfo()->NEVENTS-1-prevshift << endl;          }
4180        // - - - - - - - - - - - - -          if ( (iev >= totrunentrymin && iev <= totrunentrymax) || // entry is inside run limits
4181        // irunentry = position of current entry, relative to the run               ( !isSync &&
4182        // 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)
4183        // - - - - - - - - - - - - -                   && abstime <= GetRunInfo()->RUNTRAILER_TIME && b))  // or it is inside obt limits (and abstime limits for security reasons)
4184                 ){ // check on abstime and obt needed to handle nested+DV_skipped packets
4185        // -----------------------------------------            if ( totrunentrymin > iev ){ // there is a shift (nested+DV_skipped packets)
4186        // store dead and live-time of previous run              if ( !isSync ){
4187        // -----------------------------------------                if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - unconsistent iev - nevents, probable DBL0-L2 async\n");
4188        //            if(SELLI==0){                if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);
4189        if (SELLI != 2) {                //              printf("PamLevel2::UpdateRunInfo(Long64_t) - unconsistent iev - nevents, probable DBL0-L2 async\n");
4190          if (fromfirst) {                //              printf("PamLevel2::UpdateRunInfo(Long64_t) - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI
4191            if (oldrun == irun) {                prevshift += (totrunentrymin-iev); // add the new shift to total shift
4192              /// decrement counters                totrunentrymin -= (totrunentrymin-iev); // shift run position min
4193              if (GetTrigLevel2()) {                totrunentrymax -= (totrunentrymin-iev); // shift run position max
4194                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);
4195                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
4196              }              } else {
4197              totdltime[2]--; //event counter                printf(" PamLevel2::UpdateRunInfo(Long64_t) ERROR! sync file but unconsistent totrunetrymin %lld and iev %lld!!! \n",totrunentrymin,iev);
4198              if (DBG) {                cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
4199                cout << endl;                cout << "\nFor bug reporting instructions, please see for example:\n";
4200                cout << "n.events     : " << totdltime[2] << endl;                cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
4201                cout << "RUN LIVE-TIME: " << totdltime[0] * 0.16 << " ms" << endl;                cout << "  " << endl;
               cout << "RUN DEAD-TIME: " << totdltime[1] * 0.01 << " ms" << endl;  
4202              }              }
4203            }            }
4204            else {            runfirstentry = totrunentrymin; // first entry of the run in the level2
4205              totdltime[0] = 0;//live-time            
4206              totdltime[1] = 0;//dead-time  
4207              totdltime[2] = 0; //event counter            //
4208              if (DBG)            if ( fUseDBinRunInfo ){
4209                cout << " *** JUMP RUN *** irun " << irun << endl;              if (gltsync)
4210                  delete gltsync; // Emiliano
4211                if (!dbc || (dbc && !dbc->IsConnected()))
4212                  SetDBConnection(); //Emiliano
4213                gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano
4214                TrkParams::Set(GetRunInfo(), dbc);
4215                if (dbc){
4216                  dbc->Close(); // Emiliano
4217                  delete dbc;
4218                  dbc=0;
4219                }          
4220                if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano
4221                  cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun
4222                       << "  has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl;
4223                  cout
4224                    << "                                                            (NB!! in this case some events could be assigned to a wrong run)"
4225                    << endl;
4226                }
4227            }            }
4228            /// add an entry            //
4229            if (run_tree_clone)            if (DBG) printf(" found \n");
4230              if (run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())            //          printf(" found \n");//TOGLITOGLI
4231                run_tree_clone->GetBranch("DeadLiveTime")->Fill();            //
4232            /// reset counters            break;
4233            }
4234          } // loop over run
4235          
4236          // --------------------------------------
4237          // if there was no need to update the run
4238          // ---> exit with FALSE
4239          // --------------------------------------
4240          if (irun == oldrun){
4241            if (DBG) printf(" no new run \n");
4242            //        printf(" no new run \n");//TOGLITOGLI
4243            return (false);
4244          }      
4245          // --------------------------------------
4246          // ... otherwise
4247          // ---> exit with TRUE
4248          // --------------------------------------
4249    
4250          if (SELLI != 2) {
4251            /// decrement counters since this event belongs to a new run
4252            if (GetTrigLevel2()) {
4253              totdltime[0] -= GetTrigLevel2()->dltime[0];//live-time
4254              totdltime[1] -= GetTrigLevel2()->dltime[1];//dead-time
4255            }
4256            totdltime[2]--; //event counter
4257            if (DBG) {
4258              cout << endl;
4259              cout << "n.events     : " << totdltime[2] << endl;
4260              cout << "RUN LIVE-TIME: " << totdltime[0] * 0.16 << " ms" << endl;
4261              cout << "RUN DEAD-TIME: " << totdltime[1] * 0.01 << " ms" << endl;
4262            }
4263            // add an entry
4264            if (run_tree_clone && totdltime[2] > 0)
4265              if (run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
4266                run_tree_clone->GetBranch("DeadLiveTime")->Fill();
4267            // reset counters
4268            if ( totdltime[2] > 0 ){
4269            if (GetTrigLevel2()) {            if (GetTrigLevel2()) {
4270              totdltime[0] = GetTrigLevel2()->dltime[0];//live-time              totdltime[0] = GetTrigLevel2()->dltime[0];//live-time
4271              totdltime[1] = 0; //dead-time              totdltime[1] = 0; //dead-time
# Line 3015  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4273  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4273            totdltime[2] = 1; //event counter            totdltime[2] = 1; //event counter
4274          }          }
4275        }        }
       //            }  
4276    
4277        irun++;        if (DBG){
4278        // ------------------------------------          cout << endl << " ))))) UPDATE RUN INFO (((((  @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun
4279        // if the end of run tree is reached...               << endl;        
4280        // ------------------------------------          printf("2abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4281        if (irun == run_tree->GetEntries()) {          printf("2        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4282          if (!fromfirst) {          printf("2        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4283            // -----------------------------------------------------          if ( fUseDBinRunInfo ) printf("2        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4284            // if it happened already once and the run was not found          printf("2        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4285            // ---> 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;  
4286        }        }
4287        // -------------------------------------------------------------------        //        printf("2abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4288        // 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);
4289        // and read a new run        //        printf("2        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4290        // -------------------------------------------------------------------        //        printf("2        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4291        if (irun > 0)        //        printf("2        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4292          runfirstentry += (GetRunInfo()->NEVENTS) - prevshift;        //        printf("2        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);//TOGLITOGLI
4293        irunentry = 0;  
4294        prevshift = 0;        return (true);
4295        run_tree->GetEntry(irun);//update runinfo      } // need for run upgrade
4296        irunt = irun - irunoffset[run_tree->GetTreeNumber()];      if (DBG) printf("return false\n");
4297        if (gltsync)      return (false);
4298          delete gltsync; // Emiliano    }// SELLI = 0 SELLI = 2
4299        if (!dbc || (dbc && !dbc->IsConnected()))    
         SetDBConnection(); //Emiliano  
       gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano  
       if (dbc){  
         dbc->Close(); // Emiliano  
         delete dbc;  
         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();  
       delete dbc;  
       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);  
   };  
4300    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
4301    // if it is a preselected file (there is SelectionList)    // if it is a preselected file (there is SelectionList)
4302    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# Line 3191  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4371  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4371        // update the tracker parameters        // update the tracker parameters
4372        // (non ho trovato nessun altro modo sicuro di farlo...)        // (non ho trovato nessun altro modo sicuro di farlo...)
4373        // ----------------------------------------------------        // ----------------------------------------------------
4374        if (!dbc || (dbc && !dbc->IsConnected()))        if ( fUseDBinRunInfo ){
4375          SetDBConnection();          if (!dbc || (dbc && !dbc->IsConnected()))
4376        TrkParams::Set(GetRunInfo(), dbc);            SetDBConnection();
4377        if (dbc){          TrkParams::Set(GetRunInfo(), dbc);
4378          dbc->Close();          if (dbc){
4379          delete dbc;            dbc->Close();
4380          dbc=0;            delete dbc;
4381        };            dbc=0;
4382            }
4383          }
4384        //            cout << endl;        //            cout << endl;
4385        prevshift = 0;        prevshift = 0;
4386          yprevshift = 0;
4387        return true;        return true;
4388      }      }
4389      return false;      return false;
# Line 3209  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4392  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4392    return false;    return false;
4393    //    //
4394  }  }
4395  ;  
4396    /**
4397     * Update the runinfo informations (to be used to have Run infos event by event basis)
4398     * @param run Pointer to the chain/tree which contains run infos
4399     * @return true if a new run has been read, false if it is still the same run
4400     */
4401    Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) {
4402      return (UpdateRunInfo(iev));
4403    }
4404    
4405  /**  /**
4406   * 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)
4407   * @param run Pointer to the chain/tree which contains run infos   * @param run Pointer to the chain/tree which contains run infos
# Line 3218  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4410  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4410  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev) {  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev) {
4411    return (UpdateRunInfo((TChain*) run, iev));    return (UpdateRunInfo((TChain*) run, iev));
4412  }  }
4413  ;  
4414    
4415  //--------------------------------------  //--------------------------------------
4416  //  //
# Line 3456  void PamLevel2::GetWhichTrees(TFile* f) Line 4648  void PamLevel2::GetWhichTrees(TFile* f)
4648    //    cout << "Checking file: "<<f->GetName()<<endl;    //    cout << "Checking file: "<<f->GetName()<<endl;
4649    if (!f || f->IsZombie()) {    if (!f || f->IsZombie()) {
4650      cout << "File: " << f->GetName() << " Non valid root file" << endl;      cout << "File: " << f->GetName() << " Non valid root file" << endl;
4651        fDiscarded = true;
4652      return;      return;
4653    }    }
4654    
# Line 3662  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4855  Bool_t PamLevel2::CheckLevel2File(TStrin
4855    TFile *f = new TFile(name.Data());    TFile *f = new TFile(name.Data());
4856    if (!f || f->IsZombie()) {    if (!f || f->IsZombie()) {
4857      cout << "File: " << f->GetName() << " discarded ---- Non valid root file" << endl;      cout << "File: " << f->GetName() << " discarded ---- Non valid root file" << endl;
4858        fDiscarded = true;
4859      return false;      return false;
4860    }    }
4861    //    cout << "Get list of keys: "<<f<<endl;    //    cout << "Get list of keys: "<<f<<endl;
# Line 3700  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4894  Bool_t PamLevel2::CheckLevel2File(TStrin
4894          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4895            cout << "File: " << f->GetName() << " discarded ---- SelectionList tree has " << nevt            cout << "File: " << f->GetName() << " discarded ---- SelectionList tree has " << nevt
4896                << " events instead of " << nev << endl;                << " events instead of " << nev << endl;
4897              fDiscarded = true;
4898            return false;            return false;
4899          }          }
4900          nev = nevt;          nev = nevt;
# Line 3714  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4909  Bool_t PamLevel2::CheckLevel2File(TStrin
4909          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4910            cout << "File: " << f->GetName() << " discarded ---- Trigger tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- Trigger tree has " << nevt << " events instead of "
4911                << nev << endl;                << nev << endl;
4912              fDiscarded = true;
4913            return false;            return false;
4914          }          }
4915          nev = nevt;          nev = nevt;
# Line 3727  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4923  Bool_t PamLevel2::CheckLevel2File(TStrin
4923          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4924            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
4925                << endl;                << endl;
4926              fDiscarded = true;
4927            return false;            return false;
4928          }          }
4929          nev = nevt;          nev = nevt;
# Line 3740  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4937  Bool_t PamLevel2::CheckLevel2File(TStrin
4937          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4938            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
4939                << endl;                << endl;
4940              fDiscarded = true;
4941            return false;            return false;
4942          }          }
4943          nev = nevt;          nev = nevt;
# Line 3754  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4952  Bool_t PamLevel2::CheckLevel2File(TStrin
4952          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4953            cout << "File: " << f->GetName() << " discarded ---- NeutronD tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- NeutronD tree has " << nevt << " events instead of "
4954                << nev << endl;                << nev << endl;
4955              fDiscarded = true;
4956            return false;            return false;
4957          }          }
4958          nev = nevt;          nev = nevt;
# Line 3767  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4966  Bool_t PamLevel2::CheckLevel2File(TStrin
4966          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4967            cout << "File: " << f->GetName() << " discarded ---- Anticounter tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- Anticounter tree has " << nevt << " events instead of "
4968                << nev << endl;                << nev << endl;
4969              fDiscarded = true;
4970            return false;            return false;
4971          }          }
4972          nev = nevt;          nev = nevt;
# Line 3780  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4980  Bool_t PamLevel2::CheckLevel2File(TStrin
4980          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4981            cout << "File: " << f->GetName() << " discarded ---- OrbitalInfo tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- OrbitalInfo tree has " << nevt << " events instead of "
4982                << nev << endl;                << nev << endl;
4983              fDiscarded = true;
4984            return false;            return false;
4985          }          }
4986          nev = nevt;          nev = nevt;
# Line 3793  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4994  Bool_t PamLevel2::CheckLevel2File(TStrin
4994          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4995            cout << "File: " << f->GetName() << " discarded ---- Tracker tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- Tracker tree has " << nevt << " events instead of "
4996                << nev << endl;                << nev << endl;
4997              fDiscarded = true;
4998            return false;            return false;
4999          }          }
5000          nev = nevt;          nev = nevt;
# Line 3816  Bool_t PamLevel2::CheckLevel2File(TStrin Line 5018  Bool_t PamLevel2::CheckLevel2File(TStrin
5018          if (nev && nevt != nev) {          if (nev && nevt != nev) {
5019            cout << "File: " << f->GetName() << " discarded ---- Calorimeter tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- Calorimeter tree has " << nevt << " events instead of "
5020                << nev << endl;                << nev << endl;
5021              fDiscarded = true;
5022            return false;            return false;
5023          }          }
5024          nev = nevt;          nev = nevt;
# Line 3838  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 ---- h20 tree has " << nevt << " events instead of " << nev            cout << "File: " << f->GetName() << " discarded ---- h20 tree has " << nevt << " events instead of " << nev
5043                << endl;                << endl;
5044              fDiscarded = true;
5045            return false;            return false;
5046          }          }
5047          nev = nevt;          nev = nevt;
# Line 3850  Bool_t PamLevel2::CheckLevel2File(TStrin Line 5054  Bool_t PamLevel2::CheckLevel2File(TStrin
5054      SELLI = (Int_t) SELLI__ok;      SELLI = (Int_t) SELLI__ok;
5055    if (SELLI == 0 && SELLI__ok) {    if (SELLI == 0 && SELLI__ok) {
5056      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;
5057        fDiscarded = true;
5058      return false;      return false;
5059    }    }
5060    if (SELLI == 1 && !SELLI__ok) {    if (SELLI == 1 && !SELLI__ok) {
5061      cout << "File: " << f->GetName() << " discarded ---- SelectionList missing" << endl;      cout << "File: " << f->GetName() << " discarded ---- SelectionList missing" << endl;
5062        fDiscarded = true;
5063      return false;      return false;
5064    }    }
5065    
# Line 3892  Bool_t PamLevel2::CheckLevel2File(TStrin Line 5098  Bool_t PamLevel2::CheckLevel2File(TStrin
5098    
5099    if (CAL1 && !CAL1__ok) {    if (CAL1 && !CAL1__ok) {
5100      cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel1 branch" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel1 branch" << endl;
5101        fDiscarded = true;
5102      return false;      return false;
5103    };    };
5104    if (CAL2 && !CAL2__ok) {    if (CAL2 && !CAL2__ok) {
5105      cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel2 branch" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel2 branch" << endl;
5106        fDiscarded = true;
5107      return false;      return false;
5108    };    };
5109    if (TRK2 && !TRK2__ok) {    if (TRK2 && !TRK2__ok) {
5110      cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel2 branch" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel2 branch" << endl;
5111        fDiscarded = true;
5112      return false;      return false;
5113    };    };
5114    if (TRK1 && !TRK1__ok) {    if (TRK1 && !TRK1__ok) {
5115      cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel1 branch" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel1 branch" << endl;
5116        fDiscarded = true;
5117      return false;      return false;
5118    };    };
5119    if (TRKh && !TRKh__ok) {    if (TRKh && !TRKh__ok) {
5120      cout << "File: " << f->GetName() << " discarded ---- Missing TrkHough branch" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing TrkHough branch" << endl;
5121        fDiscarded = true;
5122      return false;      return false;
5123    };    };
5124    if (ORB && !ORB__ok) {    if (ORB && !ORB__ok) {
5125      cout << "File: " << f->GetName() << " discarded ---- Missing ORB tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing ORB tree" << endl;
5126        fDiscarded = true;
5127      return false;      return false;
5128    };    };
5129    if (AC && !AC__ok) {    if (AC && !AC__ok) {
5130      cout << "File: " << f->GetName() << " discarded ---- Missing AC tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing AC tree" << endl;
5131        fDiscarded = true;
5132      return false;      return false;
5133    };    };
5134    if (S4 && !S4__ok) {    if (S4 && !S4__ok) {
5135      cout << "File: " << f->GetName() << " discarded ---- Missing S4 tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing S4 tree" << endl;
5136        fDiscarded = true;
5137      return false;      return false;
5138    };    };
5139    if (TOF && !TOF__ok) {    if (TOF && !TOF__ok) {
5140      cout << "File: " << f->GetName() << " discarded ---- Missing ToF tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing ToF tree" << endl;
5141        fDiscarded = true;
5142      return false;      return false;
5143    };    };
5144    
5145    if (ND && !ND__ok) {    if (ND && !ND__ok) {
5146      cout << "File: " << f->GetName() << " discarded ---- Missing ND tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing ND tree" << endl;
5147        fDiscarded = true;
5148      return false;      return false;
5149    };    };
5150    if (TRG && !TRG__ok) {    if (TRG && !TRG__ok) {
5151      cout << "File: " << f->GetName() << " discarded ---- Missing Trigger tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing Trigger tree" << endl;
5152        fDiscarded = true;
5153      return false;      return false;
5154    };    };
5155    if (GP && !GP__ok) {    if (GP && !GP__ok) {
5156      cout << "File: " << f->GetName() << " discarded ---- Missing h20 tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing h20 tree" << endl;
5157        fDiscarded = true;
5158      return false;      return false;
5159    };    };
5160    
# Line 4036  void PamLevel2::CreateCloneTrees(TFile * Line 5254  void PamLevel2::CreateCloneTrees(TFile *
5254      //  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;
5255      run_tree_clone->Fill();      run_tree_clone->Fill();
5256    }    }
5257    cout << "----------------------------------------------------" << endl;    //
5258      // replicate processinginfo tree
5259      //
5260      if ( PROC ){ // EMEMEM
5261        proc_tree_clone = new TTree("ProcessingInfo","Log of data processing");
5262        proc_tree_clone->Branch("ProcInfo", "ProcInfo", GetPointerTo("ProcInfo"));
5263        cout << "ProcessingInfo: branch ProcessingInfo" << endl;  
5264        // ------------------
5265        // replicate processinginfo tree
5266        // ------------------
5267        //    cout << "----------------------------------------------------"<<endl;
5268        //    cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
5269        for (Int_t i = 0; i < proc_tree->GetEntries(); i++) {
5270          proc_tree->GetEntry(i);
5271          //      cout << i<< "\t | "<<endl;
5272          proc_tree_clone->Fill();
5273        }
5274        if ( SELLI != 2 ){      
5275          proc_obj->runID = 0;
5276          TTimeStamp *dt = new TTimeStamp();
5277          proc_obj->date = dt->AsString();
5278          delete dt;
5279          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());
5280          proc_obj->outputFilename = ofile->GetName();
5281          proc_obj->localDir = gSystem->WorkingDirectory();
5282          proc_obj->uname = gSystem->GetFromPipe("uname -a");
5283          if (!dbc || (dbc && !dbc->IsConnected())) SetDBConnection();
5284          proc_obj->DB = Form("mysql://%s/%s",dbc->GetHost(),dbc->GetDB());
5285          dbc->Close();
5286          proc_tree_clone->Fill();
5287        }
5288        cout << "----------------------------------------------------" << endl;
5289      }
5290    // ------------------------------------    // ------------------------------------
5291    // add branch with dead and live times    // add branch with dead and live times
5292    // ------------------------------------    // ------------------------------------
# Line 4049  void PamLevel2::CreateCloneTrees(TFile * Line 5298  void PamLevel2::CreateCloneTrees(TFile *
5298      //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");      //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
5299      sel_tree_clone->Branch("RunEntry", &irunt, "runentry/L");//NEWNEW      sel_tree_clone->Branch("RunEntry", &irunt, "runentry/L");//NEWNEW
5300      sel_tree_clone->Branch("EventEntry", &irunentry, "eventry/L");      sel_tree_clone->Branch("EventEntry", &irunentry, "eventry/L");
5301        //    if ( hasL0EE ) sel_tree_clone->Branch("L0EventEntry", &il0entry, "l0eventry/L");
5302    };    };
5303    
5304    Int_t i = 0;    Int_t i = 0;
# Line 4068  void PamLevel2::CreateCloneTrees(TFile * Line 5318  void PamLevel2::CreateCloneTrees(TFile *
5318        pam_tree_clone[i]->Branch("TrkHough", "TrkHough", GetPointerTo("TrkHough"));        pam_tree_clone[i]->Branch("TrkHough", "TrkHough", GetPointerTo("TrkHough"));
5319        cout << "Tracker      : branch TrkHough" << endl;        cout << "Tracker      : branch TrkHough" << endl;
5320      };      };
5321        if(NUC){
5322            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&trk_nuc_obj);
5323            cout << "Tracker      : branch TrackNuclei" << endl;    
5324        }
5325        if(EXT){
5326            pam_tree_clone[i]->Branch("extAlgFlag",&extAlgFlag,"extAlgFlag/I");
5327            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&trk_ext_obj);
5328            cout << "Tracker      : branch RecoveredTrack" << endl;
5329            if(NUC){
5330                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&trk_ext_nuc_obj);
5331                cout << "Tracker      : branch RecoveredTrackNuclei" << endl;                  
5332            }
5333        }
5334    
5335      i++;      i++;
5336    }    }
5337    
# Line 4082  void PamLevel2::CreateCloneTrees(TFile * Line 5346  void PamLevel2::CreateCloneTrees(TFile *
5346        pam_tree_clone[i]->Branch("CaloLevel2", "CaloLevel2", GetPointerTo("CaloLevel2"));        pam_tree_clone[i]->Branch("CaloLevel2", "CaloLevel2", GetPointerTo("CaloLevel2"));
5347        cout << "Calorimeter  : branch CaloLevel2" << endl;        cout << "Calorimeter  : branch CaloLevel2" << endl;
5348      };      };
5349        if(NUC){
5350            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&calo_nuc_obj);
5351            cout << "Calorimeter  : branch TrackNuclei" << endl;    
5352        }
5353        if(EXT){
5354            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&calo_ext_obj);
5355            cout << "Calorimeter  : branch RecoveredTrack" << endl;
5356            if(NUC){
5357                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&calo_ext_nuc_obj);
5358                cout << "Calorimeter  : branch RecoveredTrackNuclei" << endl;                  
5359            }
5360        }
5361      i++;      i++;
5362    }    }
5363    
# Line 4090  void PamLevel2::CreateCloneTrees(TFile * Line 5366  void PamLevel2::CreateCloneTrees(TFile *
5366      pam_tree_clone[i] = new TTree("ToF", "PAMELA ToF level2 data ");      pam_tree_clone[i] = new TTree("ToF", "PAMELA ToF level2 data ");
5367      pam_tree_clone[i]->Branch("ToFLevel2", "ToFLevel2", GetPointerTo("ToFLevel2"));      pam_tree_clone[i]->Branch("ToFLevel2", "ToFLevel2", GetPointerTo("ToFLevel2"));
5368      cout << "ToF          : branch ToFLevel2" << endl;      cout << "ToF          : branch ToFLevel2" << endl;
5369        if(NUC){
5370            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&tof_nuc_obj);
5371            cout << "ToF          : branch TrackNuclei" << endl;    
5372        }
5373        if(EXT){
5374            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&tof_ext_obj);
5375            cout << "ToF          : branch RecoveredTrack" << endl;
5376            if(NUC){
5377                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&tof_ext_nuc_obj);
5378                cout << "ToF          : branch RecoveredTrackNuclei" << endl;                  
5379            }
5380        }
5381      i++;      i++;
5382    };    };
5383    // Trigger    // Trigger
# Line 4125  void PamLevel2::CreateCloneTrees(TFile * Line 5413  void PamLevel2::CreateCloneTrees(TFile *
5413      pam_tree_clone[i] = new TTree("OrbitalInfo", "PAMELA orbital info  ");      pam_tree_clone[i] = new TTree("OrbitalInfo", "PAMELA orbital info  ");
5414      pam_tree_clone[i]->Branch("OrbitalInfo", "OrbitalInfo", GetPointerTo("OrbitalInfo"));      pam_tree_clone[i]->Branch("OrbitalInfo", "OrbitalInfo", GetPointerTo("OrbitalInfo"));
5415      cout << "OrbitalInfo  : branch OrbitalInfo" << endl;      cout << "OrbitalInfo  : branch OrbitalInfo" << endl;
5416        if(NUC){
5417            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&orb_nuc_obj);
5418            cout << "OrbitalInfo  : branch TrackNuclei" << endl;    
5419        }
5420        if(EXT){
5421            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&orb_ext_obj);
5422            cout << "OrbitalInfo  : branch RecoveredTrack" << endl;
5423            if(NUC){
5424                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&orb_ext_nuc_obj);
5425                cout << "OrbitalInfo  : branch RecoveredTrackNuclei" << endl;                  
5426            }
5427        }
5428      i++;      i++;
5429    };    };
5430    // GPamela    // GPamela
# Line 4134  void PamLevel2::CreateCloneTrees(TFile * Line 5434  void PamLevel2::CreateCloneTrees(TFile *
5434      cout << "GPamela  : branch GPamela" << endl;      cout << "GPamela  : branch GPamela" << endl;
5435      i++;      i++;
5436    };    };
5437    
5438    
5439    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
5440    
5441  }  }
# Line 4175  TTree* PamLevel2::GetCloneTree(TString n Line 5477  TTree* PamLevel2::GetCloneTree(TString n
5477      if (!name.CompareTo(na))      if (!name.CompareTo(na))
5478        return sel_tree_clone;        return sel_tree_clone;
5479    }    }
5480      if (proc_tree_clone && PROC) {
5481        TString na = proc_tree_clone->GetName();
5482        if (!name.CompareTo(na))
5483          return proc_tree_clone;
5484      }
5485    return NULL;    return NULL;
5486    
5487  }  }
# Line 4194  void PamLevel2::WriteCloneTrees() { Line 5501  void PamLevel2::WriteCloneTrees() {
5501    for (Int_t i = 0; i < NCLONES; i++) {    for (Int_t i = 0; i < NCLONES; i++) {
5502      if (pam_tree_clone[i]) {      if (pam_tree_clone[i]) {
5503        cout << pam_tree_clone[i]->GetName() << endl;        cout << pam_tree_clone[i]->GetName() << endl;
5504        pam_tree_clone[i]->Write();        pam_tree_clone[i]->Write(pam_tree_clone[i]->GetName(),TObject::kOverwrite);
5505      };      };
5506    }    }
5507      
5508      if ( PROC ){//EMEMEMEM
5509        proc_tree_clone->Write("ProcessingInfo",TObject::kOverwrite);
5510      }
5511    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
5512    
5513  }  }
# Line 4204  void PamLevel2::WriteCloneTrees() { Line 5515  void PamLevel2::WriteCloneTrees() {
5515  /**  /**
5516   * 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.
5517   */   */
 //Int_t PamLevel2::GetEntry(Int_t iee){  
5518  Int_t PamLevel2::GetEntry(Long64_t iee) {  Int_t PamLevel2::GetEntry(Long64_t iee) {
5519    
   //     cout << "-------------------------------------"<<endl;  
   //     cout << "Int_t PamLevel2::GetEntry("<<iee<<")"<<endl;  
   
5520    if (!pam_tree) {    if (!pam_tree) {
5521      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;
5522      return 0;      return 0;
# Line 4223  Int_t PamLevel2::GetEntry(Long64_t iee) Line 5530  Int_t PamLevel2::GetEntry(Long64_t iee)
5530    //    return 0;    //    return 0;
5531    //    }    //    }
5532    
   Long64_t ii = 0;  
5533    //-------------------------------    //-------------------------------
5534    ii = iee;    if (!pam_tree->GetEntry(iee)) {
   if (!pam_tree->GetEntry(ii)) {  
5535      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;
5536      return 0;      return 0;
5537    }    }
# Line 4246  Int_t PamLevel2::GetEntry(Long64_t iee) Line 5551  Int_t PamLevel2::GetEntry(Long64_t iee)
5551    }    }
5552    
5553    //-------------------------------    //-------------------------------
5554    ii = iee;    //
5555    //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii);    if ( fUpdateRunInfo ) UpdateRunInfo(iee); // Emiliano
5556    //    Bool_t UPDATED = UpdateRunInfo(ii);    if (SELLI == 0 || SELLI == 2) irunentry = iee - runfirstentry;
   if ( fUpdateRunInfo ) UpdateRunInfo(ii); // Emiliano  
   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;  
   //    }  
   //     }  
   
5557    
5558    return 1;    return 1;
5559    
# Line 4307  TTree* PamLevel2::GetYodaTree() { Line 5594  TTree* PamLevel2::GetYodaTree() {
5594    //===================================    //===================================
5595    if (irun < 0) {    if (irun < 0) {
5596      cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = " << irun << endl;      cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = " << irun << endl;
5597      //  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;
5598      return NULL;      return NULL;
5599    }    }
5600    Int_t irootnew = run_obj->ID_ROOT_L0;    Int_t irootnew = GetRunInfo()->ID_ROOT_L0;
5601    //      cout << "iroot    "<<iroot<<endl;    if (DBG){
5602    //      cout << "irootnew "<<irootnew<<endl;      cout << "iroot    "<<iroot<<endl;
5603        cout << "irootnew "<<irootnew<<endl;
5604      }
5605    
5606    //===================================    //===================================
5607    // load the level0 file    // load the level0 file
# Line 4350  TTree* PamLevel2::GetYodaTree() { Line 5639  TTree* PamLevel2::GetYodaTree() {
5639      if (!h0_obj)      if (!h0_obj)
5640        h0_obj = new EventHeader();        h0_obj = new EventHeader();
5641      l0_tree->SetBranchAddress("Header", &h0_obj);      l0_tree->SetBranchAddress("Header", &h0_obj);
5642      prevshift = 0;      yprevshift = 0; // yes, yprevshift is the shift in the level0, prevshift is the shift in the level2
5643      //---------------------------------------------------      //---------------------------------------------------
5644      // TRACKER:      // TRACKER:
5645      if (TRK0) {      if (TRK0) {
# Line 4368  TTree* PamLevel2::GetYodaTree() { Line 5657  TTree* PamLevel2::GetYodaTree() {
5657          calo0_obj->Set();          calo0_obj->Set();
5658        };        };
5659        l0_tree->SetBranchAddress("Calorimeter", calo0_obj->GetPointerToCalorimeterEvent());        l0_tree->SetBranchAddress("Calorimeter", calo0_obj->GetPointerToCalorimeterEvent());
       //            cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;  
5660      }      }
5661      //---------------------------------------------------      //---------------------------------------------------
5662      // TOF:      // TOF:
# Line 4382  TTree* PamLevel2::GetYodaTree() { Line 5670  TTree* PamLevel2::GetYodaTree() {
5670    
5671    };    };
5672    
   //     if(!dbc || (dbc && !dbc->IsConnected())){  
   //    cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;  
   //     }  
   
5673    if (TRK0) {    if (TRK0) {
5674      //  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?  
5675      TrkParams::SetCalib(run_obj, dbc);      TrkParams::SetCalib(run_obj, dbc);
5676      TrkParams::LoadCalib();      TrkParams::LoadCalib();
5677      if (!TrkParams::CalibIsLoaded()) {      if (!TrkParams::CalibIsLoaded()) {
# Line 4403  TTree* PamLevel2::GetYodaTree() { Line 5683  TTree* PamLevel2::GetYodaTree() {
5683        dbc=0;        dbc=0;
5684      };      };
5685    }    }
   
   //    cout << l0_tree << endl;  
5686    return l0_tree;    return l0_tree;
   
5687  }  }
5688    
5689  /**  /**
# Line 4414  TTree* PamLevel2::GetYodaTree() { Line 5691  TTree* PamLevel2::GetYodaTree() {
5691   */   */
5692  Int_t PamLevel2::GetYodaEntry() {  Int_t PamLevel2::GetYodaEntry() {
5693    
5694    //    cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;    Long64_t iev = this->GetReadEntry();
   if (!GetYodaTree())  
     return 0;  
5695    
5696    // patch    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
5697    if (irunentry < 0) {    // if it is a full file (not preselected)
5698      //  cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
5699      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;  
5700    
5701    ULong64_t obt = 0;      if (!GetYodaTree()){
5702    ULong64_t pktn = 0;        printf(" PamLevel2::GetYodaEntry() : ERROR no level0 file loaded!\n");
5703    if (GetOrbitalInfo()) {        return 0;
5704      obt = GetOrbitalInfo()->OBT;      }
     pktn = GetOrbitalInfo()->pkt_num;  
   }  
5705    
5706    if (!GetOrbitalInfo() && !ISGP) {      if (irunentry < 0) {
5707      cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo " << endl;        if (DBG) cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
5708      return 0;        //      cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl; // TOGLITOGLI
5709    }        irunentry = 0LL;
5710    if (obt == 0 && pktn == 0 && !ISGP) {      }
5711      cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? " << endl;      //  ---------------------------------
5712      return 0;      //  if file is NOT a preselected file
5713    }      //  ---------------------------------
5714        Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM); // prevshift already included in irunentry
5715    
5716        if (DBG){
5717          cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
5718          cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
5719          cout << " time "<< abstime << endl;
5720        }
5721    
5722        ULong64_t obt = 0;
5723        ULong64_t pktn = 0;
5724        if (GetOrbitalInfo()) {
5725          obt = GetOrbitalInfo()->OBT;
5726          pktn = GetOrbitalInfo()->pkt_num;
5727        }
5728    
5729    // ---------------------------------------------------------------------      if (!GetOrbitalInfo() && !ISGP) {
5730    // ATTENTION!!!        cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo " << endl;
5731    // 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;  
5732      }      }
5733      answer = l0_tree->GetEntry(quellagiusta + (Long64_t) shift + (Long64_t) prevshift);      if (obt == 0 && pktn == 0 && !ISGP) {
5734      shift++;        cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? " << endl;
     if (!GetEventHeader()) {  
       cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader " << endl;  
5735        return 0;        return 0;
5736      }      }
5737    
5738        // ---------------------------------------------------------------------
5739        // ATTENTION!!!
5740        // If data are not pre-processed with cleaner, the level0 tree may contain
5741        // spurious nested physics packets.
5742        // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries
5743        // while level2 tree DOES NOT!!
5744        // This means that "quellagiusta" in these cases is not correct.
5745        // In order to retrieve the correct level0 event, I implemented a check
5746        // of the OBT and pkt-number. In case of mismatch, the level0 entry number
5747        // is shift forward until when the packets match.
5748        // ---------------------------------------------------------------------
5749        Long64_t shift = 0LL;
5750        Long64_t answer = quellagiusta + shift + yprevshift;
5751        Int_t readl0 = 0;
5752        readl0 = l0_tree->GetEntry(answer); // prevshift already included in irunentry
5753    
5754        if (DBG){
5755          printf(" siamo qui shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);
5756        }
5757    
5758    
5759      if (ISGP) {      if (ISGP) {
5760        obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO        obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO
5761        pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO        pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO
5762      }      }
5763    
5764      //  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 ){
5765      //  cout << " L2 --- "<< obt << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;        if ( isSync && shift == 0LL ){
5766      //  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");
5767      //  cout << " obt "<< obt << endl;          cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5768      //  cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;          cout << "\nFor bug reporting instructions, please see for example:\n";
5769      //  cout << " pktn "<< pktn << endl;          cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5770      //  cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;          cout << "  " << endl;
5771      //  printf(" IDRUN %u \n",GetRunInfo()->ID);        }
5772      //        if (shift > 0) {
5773      if (prevshift != 0 && (quellagiusta + (Long64_t) shift) == GetYodaTree()->GetEntries()) {          if (DBG) cout << " PKTNUM  L2 --- " << pktn << " --- L0 --- " << GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
5774        prevshift = 0;          if (DBG)
5775        shift = -1;            cout << "         RUN: ID " << GetRunInfo()->ID << " ID_ROOT_L0 " << run_obj->ID_ROOT_L0 << " ID_RUN_FRAG "
5776      };                 << GetRunInfo()->ID_RUN_FRAG << " EV_FROM " << GetRunInfo()->EV_FROM << endl;
5777            if (DBG)
5778              cout << "         L2 <--> L0 mismatch ( irun " << irun << " irunentry " << irunentry << " shift " << shift
5779                   << " prevshift " << prevshift << " )" << endl;
5780          }
5781          answer = quellagiusta +  shift+ yprevshift;
5782          readl0 = l0_tree->GetEntry(answer);
5783          //      printf(" inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5784    
5785    } while ((obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(        if (!GetEventHeader()) {
5786        GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta + (Long64_t) shift)          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader " << endl;
5787        < GetYodaTree()->GetEntries() && shift < maxshift);          return 0;
5788          }
5789    
5790    if ((quellagiusta + (Long64_t) shift + (Long64_t) prevshift) > GetYodaTree()->GetEntries() || shift == maxshift) {        //
5791      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()) {
5792      return 0;          if (DBG) printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);
5793    }          //        printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5794    //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;          yprevshift = 0LL;
5795    //    return GetYodaTree()->GetEntry(quellagiusta);          shift = -1LL;
5796    if (shift > 1)        };
5797      prevshift += (shift - 1);      
5798          shift++;
5799        }
5800                                      
5801    
5802        if ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()) ){
5803          if ( isSync ){
5804            printf(" PamLevel2::GetYodaEntry() ERROR! sync file but the level0 entry not found AT ALL!!! \n");
5805            cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5806            cout << "\nFor bug reporting instructions, please see for example:\n";
5807            cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5808            cout << "  " << endl;
5809          }
5810          cout << "Int_t PamLevel2::GetYodaEntry() -- WARNING -- " << endl;
5811          cout << " Big trouble here, no such event in Level0 data! (NB maxshift set to " << maxshift << " )" << endl;    
5812          cout << " Nested and/or DarthVader skipped packets in fragmented run? checking and trying to fix " <<endl;
5813          // query the DB for runs containing the event, loop over LEVEL0 files which could contain the level0 event and try to find it
5814          // 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
5815          // connect to db
5816          if (!dbc || (dbc && !dbc->IsConnected())) SetDBConnection(); //Emiliano
5817          //
5818          if (GetOrbitalInfo()){
5819            abstime = GetOrbitalInfo()->absTime;
5820          } else {
5821            printf(" PamLevel2::GetYodaEntry() ERROR! no OrbitalInfo, cannot get the absolute time for event \n");
5822            return 0;
5823          }
5824          // query DB looking for runs containing the processed event
5825          TSQLResult *pResult;
5826          TSQLRow *Row = NULL;
5827          TString myquery = Form("select ID,NEVENTS from GL_RUN where RUNHEADER_TIME<=%lld and RUNTRAILER_TIME>=%lld;",abstime,abstime);
5828          if ( DBG ) printf(" query is %s \n",myquery.Data());
5829          //      printf(" query is %s \n",myquery.Data());// TOGLITOGLI
5830          pResult = dbc->Query(myquery.Data());    
5831          if (!pResult->GetRowCount()){
5832            printf(" PamLevel2::GetYodaEntry() ERROR! event is not included in any run!!! \n");
5833            cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5834            cout << "\nFor bug reporting instructions, please see for example:\n";
5835            cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5836            cout << "  " << endl;
5837            return 0;
5838          }
5839          if ( pResult->GetRowCount() == 1 ){
5840            if (DBG) printf(" PamLevel2::GetYodaEntry() - WARNING - YodaEntry not found but only one run containing the event, it should not happen \n");
5841            //        printf(" PamLevel2::GetYodaEntry() - WARNING - YodaEntry not found but only one run containing the event, it should not happen \n");//TOGLITOGLI
5842          }
5843          for( Int_t ru=0; ru < pResult->GetRowCount(); ru++){ // loop over runs containing the event
5844            if (Row) delete Row;
5845            Row = pResult->Next();  
5846            if( Row == NULL ) break;
5847            UInt_t idrun = (UInt_t)atoll(Row->GetField(0));
5848            UInt_t nev = (UInt_t)atoll(Row->GetField(1));
5849            if (DBG) printf(" inside loop over runs: ru %i idrun %i nev %i \n",ru,idrun,nev);
5850            //        printf(" inside loop over runs: ru %i idrun %i nev %i \n",ru,idrun,nev);//TOGLITOGLI
5851    
5852            // now look for this run in the level2 file, it must be present! code is taken from updateruninfo of course
5853            Bool_t rfound = false;
5854            totrunentry = 0LL;
5855            runfirstentry = 0LL;
5856            for (Int_t r=0; r< run_tree->GetEntries();r++){
5857              run_tree->GetEntry(r);//update runinfo
5858              if ( r > 0 ){
5859                totrunentrymin = totrunentrymax+1;
5860              } else {
5861                totrunentrymin = 0LL;
5862              }
5863              totrunentry += GetRunInfo()->NEVENTS;
5864              totrunentrymax = totrunentry - 1 - prevshift; // prevshift is needed to handle nested+DV_skipped packets
5865              irun = r;        
5866    
5867              if (idrun == GetRunInfo()->ID){
5868                if ( totrunentrymin > iev ){ // there is a shift (nested+DV_skipped packets)
5869                  if (DBG) printf("PamLevel2::GetYodaEntry - unconsistent iev - nevents, probable DBL0-L2 async\n");
5870                  if (DBG) printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);
5871                  //              printf("PamLevel2::GetYodaEntry - unconsistent iev - nevents, probable DBL0-L2 async\n");
5872                  //              printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI
5873                  prevshift += (totrunentrymin-iev); // add the new shift to total shift
5874                  totrunentrymin -= (totrunentrymin-iev); // shift run position min
5875                  totrunentrymax -= (totrunentrymin-iev); // shift run position max
5876                  if (DBG) printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);
5877                  //              printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI
5878                }
5879                runfirstentry = totrunentrymin; // first entry of the run in the level2
5880              
5881    
5882    return answer;              //
5883                if (gltsync)
5884                  delete gltsync; // Emiliano
5885                if (!dbc || (dbc && !dbc->IsConnected()))
5886                  SetDBConnection(); //Emiliano
5887                gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano
5888                if (dbc){
5889                  dbc->Close(); // Emiliano
5890                  delete dbc;
5891                  dbc=0;
5892                }          
5893                if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano
5894                  cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun
5895                       << "  has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl;
5896                  cout
5897                    << "                                                            (NB!! in this case some events could be assigned to a wrong run)"
5898                    << endl;
5899                }
5900                //
5901                if (DBG) printf(" found \n");
5902                //            printf(" found \n");//TOGLITOGLI
5903                rfound = true;
5904                //
5905                break;
5906              }
5907            } // loop over run
5908            if ( !rfound ){
5909              printf(" PamLevel2::GetYodaEntry() ERROR! run is not present in the level2 file!!! \n");
5910              cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5911              cout << "\nFor bug reporting instructions, please see for example:\n";
5912              cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5913              cout << "  " << endl;        
5914              return 0;
5915            }
5916    
5917            // here we got the first run and we can check if it contains the level0 event
5918            if (!GetYodaTree()){
5919              printf(" PamLevel2::GetYodaEntry() : ERROR no level0 file loaded!\n");
5920              return 0;
5921            }      
5922    
5923            // get the current run entry
5924            irunentry = iev - runfirstentry;
5925            if (irunentry < 0) {
5926              if (DBG) cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
5927              //          cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl; // TOGLITOGLI
5928              irunentry = 0LL;
5929            }
5930            //  ---------------------------------
5931            //  if file is NOT a preselected file
5932            //  ---------------------------------
5933            quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM); // prevshift already included in irunentry
5934          
5935            if (DBG){
5936              cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
5937              cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
5938              cout << " time "<< abstime << endl;
5939            }
5940            //        cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
5941            //        cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
5942            //        cout << " time "<< abstime << endl; // TOGLITOGLI
5943          
5944            shift = 0;
5945            answer = quellagiusta + shift + yprevshift; // prevshift already included in irunentry
5946            readl0 = l0_tree->GetEntry(answer); // prevshift already included in irunentry
5947    
5948            if (DBG){
5949              printf(" siamo qua shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);
5950            }
5951            //        printf(" siamo qua shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5952          
5953            while ( (obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta + (Long64_t) shift) < GetYodaTree()->GetEntries() && shift < maxshift ){
5954              if (shift > 0) {
5955                if (DBG) cout << " PKTNUM  L2 --- " << pktn << " --- L0 --- " << GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
5956                if (DBG)
5957                  cout << "         RUN: ID " << GetRunInfo()->ID << " ID_ROOT_L0 " << run_obj->ID_ROOT_L0 << " ID_RUN_FRAG "
5958                       << GetRunInfo()->ID_RUN_FRAG << " EV_FROM " << GetRunInfo()->EV_FROM << endl;
5959                if (DBG)
5960                  cout << "         L2 <--> L0 mismatch ( irun " << irun << " irunentry " << irunentry << " shift " << shift
5961                       << " prevshift " << prevshift << " )" << endl;
5962              }
5963              answer = quellagiusta +  shift+ yprevshift;
5964              readl0 = l0_tree->GetEntry(answer);
5965              //          printf(" inside inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5966            
5967              if (!GetEventHeader()) {
5968                cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader " << endl;
5969                return 0;
5970              }
5971              //
5972              if (yprevshift != 0 && (quellagiusta + (Long64_t) shift) == GetYodaTree()->GetEntries()) {
5973                if (DBG) printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);
5974                //            printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5975                yprevshift = 0;
5976                shift = -1;
5977              };
5978            
5979              shift++;
5980            }
5981          
5982            if ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()) ){
5983              //still not the good run... continue with the nex one!
5984              printf("still not the good run... continue with the nex one!\n");
5985            } else {
5986              if (DBG) cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
5987              //          cout << "LA ENTRY GIUSTA E`: "<<answer<<" (spero...)"<<endl;//TOGLITOGLI
5988              if (shift > 1) yprevshift = (shift - 1);
5989              if (Row) delete Row;
5990              delete pResult;  
5991              if (dbc){
5992                dbc->Close(); // Emiliano
5993                delete dbc;
5994                dbc=0;
5995              }    
5996              il0entry = answer;
5997              return readl0;
5998            }
5999            // perhaps it is all
6000          }// loop over runs containing the event
6001          if (Row) delete Row;
6002          delete pResult;  
6003          if (dbc){
6004            dbc->Close(); // Emiliano
6005            delete dbc;
6006            dbc=0;
6007          }          
6008          // arriving here it means no run found, cannot be! error!
6009          printf(" PamLevel2::GetYodaEntry() ERROR! run is not present in the level0 files!!! \n");
6010          cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
6011          cout << "\nFor bug reporting instructions, please see for example:\n";
6012          cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
6013          cout << "  " << endl;        
6014          return 0;
6015        } else {
6016          if (DBG) cout << "=> LA ENTRY GIUSTA E`: "<<answer<<" (spero...)"<<endl;
6017          //    cout << "=> LA ENTRY GIUSTA E`: "<<answer<<" (spero...)"<<endl;
6018          //    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()) );
6019          if (shift > 1) yprevshift = (shift - 1);
6020          il0entry = answer;
6021          return readl0;
6022        }
6023    
6024        /*  } // if selli 0 || 2
6025      if ( SELLI == 1 && hasL0EE ){
6026        sel_tree->GetEntry(iev);  
6027        Long64_t answer = il0entry;
6028        Int_t readl0 = 0;
6029        readl0 = l0_tree->GetEntry(answer);
6030        return readl0;
6031        }*/
6032      printf(" PamLevel2::GetYodaEntry() ERROR! \n");
6033      cout << " Entry not found! OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
6034      cout << "\nFor bug reporting instructions, please see for example:\n";
6035      cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
6036      cout << "  " << endl;
6037      return 0;
6038  }  }
6039    
6040  /**  /**
6041   * \Brief Set DB connection   * \Brief Set DB connection
6042   */   */
# Line 4611  Long64_t PamLevel2::GetReadEntry() { Line 6129  Long64_t PamLevel2::GetReadEntry() {
6129  void PamLevel2::SetSortingMethod(TString how) {  void PamLevel2::SetSortingMethod(TString how) {
6130    if (howtosort != how) {    if (howtosort != how) {
6131      issorted = false;      issorted = false;
6132        issorted_new = false;
6133    }    }
6134    howtosort = how;    howtosort = how;
6135  }  }

Legend:
Removed from v.1.88  
changed lines
  Added in v.1.110

  ViewVC Help
Powered by ViewVC 1.1.23