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

Diff of /PamelaLevel2/src/PamLevel2.cpp

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

revision 1.82 by mocchiut, Thu Jun 4 15:10:47 2009 UTC revision 1.97 by pam-fi, Fri Oct 17 06:54:11 2014 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  PamTrack::PamTrack(const PamTrack& track) {  PamTrack::PamTrack(const PamTrack& track) {
375    
376    TrkTrack *t = track.trk_track;    TrkTrack *t = track.trk_track;
377      ExtTrack *e = track.trk_ext_track;
378    CaloTrkVar *c = track.calo_track;    CaloTrkVar *c = track.calo_track;
379    ToFTrkVar *o = track.tof_track;    ToFTrkVar *o = track.tof_track;
380    OrbitalInfoTrkVar *r = track.orb_track;    OrbitalInfoTrkVar *r = track.orb_track;
381    
382    trk_track = 0;    trk_ext_track = 0;
383    calo_track = 0;    trk_track     = 0;
384    tof_track = 0;    calo_track    = 0;
385    orb_track = 0;    tof_track     = 0;
386      orb_track     = 0;
387      if(e)
388          trk_ext_track = new ExtTrack(*e);
389    if (t)    if (t)
390      trk_track = new TrkTrack(*t);      trk_track = new TrkTrack(*t);
391    if (c)    if (c)
# Line 334  PamTrack::PamTrack(const PamTrack& track Line 394  PamTrack::PamTrack(const PamTrack& track
394      tof_track = new ToFTrkVar(*o);      tof_track = new ToFTrkVar(*o);
395    if (r)    if (r)
396      orb_track = new OrbitalInfoTrkVar(*r);      orb_track = new OrbitalInfoTrkVar(*r);
397    
398    candeleteobj = 1;    candeleteobj = 1;
399      pscore = 0;
400      iscore = 0;
401    
402  }  }
403  void PamTrack::Clear() {  void PamTrack::Clear(Option_t *option) {
404    
405    //    cout << "PamTrack::Clear() "<<candeleteobj<<endl;  //    cout << "PamTrack::Clear( "<<option<<" ) "<<candeleteobj<<endl;
406    if (candeleteobj) {    if (candeleteobj) {
407          
408        if (trk_ext_track)
409          trk_ext_track->ExtTrack::Clear(option);
410      if (trk_track)      if (trk_track)
411        trk_track->TrkTrack::Clear();        trk_track->TrkTrack::Clear();
412      if (calo_track)      if (calo_track)
# Line 351  void PamTrack::Clear() { Line 417  void PamTrack::Clear() {
417        orb_track->OrbitalInfoTrkVar::Clear();//???        orb_track->OrbitalInfoTrkVar::Clear();//???
418    }    }
419    else {    else {
420        trk_ext_track = 0;
421      trk_track = 0;      trk_track = 0;
422      calo_track = 0;      calo_track = 0;
423      tof_track = 0;      tof_track = 0;
# Line 363  void PamTrack::Clear() { Line 430  void PamTrack::Clear() {
430  void PamTrack::Delete() {  void PamTrack::Delete() {
431    //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;    //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;
432    if (candeleteobj) {    if (candeleteobj) {
433        if (trk_ext_track) {
434          trk_ext_track->ExtTrack::Clear("C");
435          delete trk_ext_track;
436        }
437      if (trk_track) {      if (trk_track) {
438        trk_track->TrkTrack::Clear();        trk_track->TrkTrack::Clear();
439        delete trk_track;        delete trk_track;
# Line 384  void PamTrack::Delete() { Line 455  void PamTrack::Delete() {
455      Clear();      Clear();
456    }    }
457  }  }
458    
459    
460    
461    
462  //--------------------------------------  //--------------------------------------
463  //  //
464  //  //
# Line 394  void PamTrack::Delete() { Line 469  void PamTrack::Delete() {
469  PamLevel2::PamLevel2() {  PamLevel2::PamLevel2() {
470    Initialize();    Initialize();
471  }  }
472  ;  
473    
474  /**  /**
475   * Constructor   * Constructor
# Line 417  PamLevel2::PamLevel2(TString ddir, TStri Line 492  PamLevel2::PamLevel2(TString ddir, TStri
492      GetPamTree(listf, detlist);      GetPamTree(listf, detlist);
493    if (listf)    if (listf)
494      GetRunTree(listf);      GetRunTree(listf);
495      SetMaxShift(-1);
496  }  }
497  ;  
498    
499  PamLevel2::PamLevel2(TString ddir, TList *llist, TString detlist) {  PamLevel2::PamLevel2(TString ddir, TList *llist, TString detlist) {
500    Initialize();    Initialize();
501    GetPamTree(llist, detlist);    GetPamTree(llist, detlist);
502    GetRunTree(llist);    GetRunTree(llist);
503      SetMaxShift(-1);
504  }  }
505  ;  
506  /**  /**
507   * Constructor   * Constructor
508   * @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 512  PamLevel2::PamLevel2(TString ddir, TList
512   */   */
513  PamLevel2::PamLevel2(TString ddir, TString llist) {  PamLevel2::PamLevel2(TString ddir, TString llist) {
514    Initialize();    Initialize();
515    TList* listf = GetListOfLevel2Files(ddir, llist);    TList* listf = GetListOfLevel2Files(ddir, llist);
516      cout << "GetPamTree: "<<endl;
517    GetPamTree(listf, "");    GetPamTree(listf, "");
518      cout << "GetRunTree: "<<endl;
519    GetRunTree(listf);    GetRunTree(listf);
520      SetMaxShift(-1);
521  }  }
522  ;  
523    
524  void PamLevel2::Initialize() {  void PamLevel2::Initialize() {
525    
# Line 452  void PamLevel2::Initialize() { Line 532  void PamLevel2::Initialize() {
532    trkh_obj = 0;    trkh_obj = 0;
533    calo1_obj = 0;    calo1_obj = 0;
534    calo2_obj = 0;    calo2_obj = 0;
535    tof_obj = 0;    tof2_obj = 0;
536    trig_obj = 0;    trig_obj = 0;
537    s4_obj = 0;    s4_obj = 0;
538    nd_obj = 0;    nd_obj = 0;
539    ac_obj = 0;    ac_obj = 0;
540    orb_obj = 0;    orb2_obj = 0;
541    gp_obj = 0;    gp_obj = 0;
542    
543      extAlgFlag=0;
544    
545      trk_ext_obj     = 0;
546      trk_ext_nuc_obj = 0;
547      trk_nuc_obj     = 0;
548      
549      calo_ext_obj     = 0;
550      calo_ext_nuc_obj = 0;
551      calo_nuc_obj     = 0;
552      
553      tof_ext_obj     = 0;
554      tof_ext_nuc_obj = 0;
555      tof_nuc_obj     = 0;
556      
557      orb_ext_obj     = 0;
558      orb_ext_nuc_obj = 0;
559      orb_nuc_obj     = 0;
560    
561      trk2_nuc_obj  = 0;
562      calo2_nuc_obj = 0;
563      tof2_nuc_obj  = 0;
564      orb2_nuc_obj  = 0;
565    
566    
567    run_obj = 0;//new GL_RUN();    run_obj = 0;//new GL_RUN();
568    soft_obj = 0;// Emiliano    soft_obj = 0;// Emiliano
569    irun = -1LL;    irun = -1LL;
570    irunt = -1LL;    irunt = -1LL;
571      totrunentry = 0LL;
572      totrunentrymax = 0LL;
573      totrunentrymin = 0LL;
574    runfirstentry = 0LL;    runfirstentry = 0LL;
575    runlastentry = 0LL;    runlastentry = 0LL;
576    gltsync = 0; // Emiliano    gltsync = 0; // Emiliano
577      fUpdateRunInfo = true; // Emiliano
578      fUseDBinRunInfo = true; // Emiliano
579      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
580      il0entry = 0LL;
581      //  hasL0EE = true;
582    
583    l0_file = NULL;    l0_file = NULL;
584    l0_tree = NULL;    l0_tree = NULL;
# Line 474  void PamLevel2::Initialize() { Line 586  void PamLevel2::Initialize() {
586    dbc = 0;    dbc = 0;
587    
588    prevshift = 0;    prevshift = 0;
589    maxshift = 10; //EMILIANO    yprevshift = 0;
590      maxshift = 10; //EMILIANO now overridden by SetMaxShift(-1) called by constructors
591    
592    run_tree = NULL;    run_tree = NULL;
593    run_tree_clone = NULL;    run_tree_clone = NULL;
# Line 527  void PamLevel2::Initialize() { Line 640  void PamLevel2::Initialize() {
640    ORB = true;    ORB = true;
641    GP = false;    GP = false;
642    
643      EXT = false;
644      NUC = false;
645      trkAlg = "STD";//default tracking algorythm
646    
647    RUN = true;    RUN = true;
648    
649    SELLI = -1;    SELLI = -1;
# Line 537  void PamLevel2::Initialize() { Line 654  void PamLevel2::Initialize() {
654    
655    tsorted = 0;    tsorted = 0;
656    timage = 0;    timage = 0;
657      text = 0 ;
658    
659      tsorted_nuc = 0;
660      timage_nuc = 0;
661      text_nuc = 0 ;
662    
663    howtosort = "+CAL+TOF";    howtosort = "+CAL+TOF";
664    //howtosort = "+TOF";    //howtosort = "+TOF";
# Line 544  void PamLevel2::Initialize() { Line 666  void PamLevel2::Initialize() {
666    
667    issorted = false;    issorted = false;
668    lastsorted = -1;    lastsorted = -1;
669      issorted_new = false;
670      lastsorted_new = -1;
671    
672  }  }
673  ;  ;
# Line 574  void PamLevel2::Delete() { Line 698  void PamLevel2::Delete() {
698      delete calo1_obj;      delete calo1_obj;
699    if (calo2_obj)    if (calo2_obj)
700      delete calo2_obj;      delete calo2_obj;
701    if (tof_obj)    if (tof2_obj)
702      delete tof_obj;      delete tof2_obj;
703    if (trig_obj)    if (trig_obj)
704      delete trig_obj;      delete trig_obj;
705    if (s4_obj)    if (s4_obj)
# Line 584  void PamLevel2::Delete() { Line 708  void PamLevel2::Delete() {
708      delete nd_obj;      delete nd_obj;
709    if (ac_obj)    if (ac_obj)
710      delete ac_obj;      delete ac_obj;
711    if (orb_obj)    if (orb2_obj)
712      delete orb_obj;      delete orb2_obj;
713    if (gp_obj)    if (gp_obj)
714      delete gp_obj;      delete gp_obj;
715    
716      if(trk_nuc_obj)trk_nuc_obj->Delete();
717      if(trk_ext_obj)trk_ext_obj->Delete();
718      if(trk_ext_nuc_obj)trk_ext_nuc_obj->Delete();
719    
720      if(calo_nuc_obj)calo_nuc_obj->Delete();
721      if(calo_ext_obj)calo_ext_obj->Delete();
722      if(calo_ext_nuc_obj)calo_ext_nuc_obj->Delete();
723    
724      if(tof_nuc_obj)tof_nuc_obj->Delete();
725      if(tof_ext_obj)tof_ext_obj->Delete();
726      if(tof_ext_nuc_obj)tof_ext_nuc_obj->Delete();
727    
728      if(orb_nuc_obj)orb_nuc_obj->Delete();
729      if(orb_ext_obj)orb_ext_obj->Delete();
730      if(orb_ext_nuc_obj)orb_ext_nuc_obj->Delete();
731    
732    
733      if(trk2_nuc_obj)trk2_nuc_obj->Delete();;
734      if( calo2_nuc_obj)calo2_nuc_obj->Delete();;
735      if(tof2_nuc_obj)tof2_nuc_obj->Delete();;
736      if(orb2_nuc_obj)orb2_nuc_obj->Delete();;
737      
738    
739    
740    if (tsorted) {    if (tsorted) {
741      tsorted->Delete();      tsorted->Delete();
742      delete tsorted;      delete tsorted;
# Line 597  void PamLevel2::Delete() { Line 745  void PamLevel2::Delete() {
745      timage->Delete();      timage->Delete();
746      delete timage;      delete timage;
747    }    }
748      if (text) {
749        text->Delete();
750        delete text;
751      }
752      if (tsorted_nuc) {
753        tsorted_nuc->Delete();
754        delete tsorted_nuc;
755      }
756      if (timage_nuc) {
757        timage_nuc->Delete();
758        delete timage_nuc;
759      }
760      if (text_nuc) {
761        text_nuc->Delete();
762        delete text_nuc;
763      }
764    
765    
766    
767    if (dbc) {    if (dbc) {
768      dbc->Close();      dbc->Close();
# Line 633  void PamLevel2::Delete() { Line 799  void PamLevel2::Delete() {
799      //      //
800      TIter next2(contents);      TIter next2(contents);
801      TChain *questa = 0;      TChain *questa = 0;
802      while (questa = (TChain*) next2()) {      while ( (questa = (TChain*)next2()) ) {
803        TString name = questa->GetName();        TString name = questa->GetName();
804        questa->Delete();        questa->Delete();
805        questa = NULL;        questa = NULL;
# Line 646  void PamLevel2::Delete() { Line 812  void PamLevel2::Delete() {
812      run_tree->Delete();;      run_tree->Delete();;
813    if (sel_tree)    if (sel_tree)
814      sel_tree->Delete();;      sel_tree->Delete();;
815    for (Int_t i = 0; i < NCLONES; i++)  
816      // The following lines are commented out since they may generate a double delete error
817      // if the file containing the clone trees is closed. This is because the file owns the
818      // clone trees which are written into it, so it will delete them when it is closed; if
819      // also PamLevel2 will try to delete these trees, a double delete error will be generated
820      // when exiting from analysis program. (Nicola 28/11/2011)
821    
822      /*for (Int_t i = 0; i < NCLONES; i++)
823      if (pam_tree_clone[i])      if (pam_tree_clone[i])
824        pam_tree_clone[i]->Delete();;        pam_tree_clone[i]->Delete();;
825    if (run_tree_clone)    if (run_tree_clone)
826      run_tree_clone->Delete();;      run_tree_clone->Delete();;
827    if (sel_tree_clone)    if (sel_tree_clone)
828      sel_tree_clone->Delete();;      sel_tree_clone->Delete();;*/
829    
830    if (irunoffset)    if (irunoffset)
831      delete[] irunoffset;      delete[] irunoffset;
832    
833    
834      Initialize();
835    
836  }  }
837  ;  ;
838    
# Line 690  void PamLevel2::Clear() { Line 866  void PamLevel2::Clear() {
866      calo1_obj->Clear();      calo1_obj->Clear();
867    if (calo2_obj)    if (calo2_obj)
868      calo2_obj->Clear();      calo2_obj->Clear();
869    if (tof_obj)    if (tof2_obj)
870      tof_obj->Clear();      tof2_obj->Clear();
871    if (trig_obj)    if (trig_obj)
872      trig_obj->Clear();      trig_obj->Clear();
873    if (s4_obj)    if (s4_obj)
# Line 700  void PamLevel2::Clear() { Line 876  void PamLevel2::Clear() {
876      nd_obj->Clear();      nd_obj->Clear();
877    if (ac_obj)    if (ac_obj)
878      ac_obj->Clear();      ac_obj->Clear();
879    if (orb_obj)    if (orb2_obj)
880      orb_obj->Clear();      orb2_obj->Clear();
881    if (gp_obj)    if (gp_obj)
882      gp_obj->Clear();      gp_obj->Clear();
883    
884    //    if(sorted_tracks)sorted_tracks->Clear();    //    if(sorted_tracks)sorted_tracks->Clear();
885    //    sorted_tracks.Clear();    //    sorted_tracks.Clear();
886    
887    if (tsorted) {    if(trk_nuc_obj)trk_nuc_obj->Clear();
888      tsorted->Delete();    if(trk_ext_obj)trk_ext_obj->Clear();
889    }    if(trk_ext_nuc_obj)trk_ext_nuc_obj->Clear();
890    if (timage) {  
891      timage->Delete();    if(calo_nuc_obj)calo_nuc_obj->Clear();
892    }    if(calo_ext_obj)calo_ext_obj->Clear();
893      if(calo_ext_nuc_obj)calo_ext_nuc_obj->Clear();
894    
895      if(tof_nuc_obj)tof_nuc_obj->Clear();
896      if(tof_ext_obj)tof_ext_obj->Clear();
897      if(tof_ext_nuc_obj)tof_ext_nuc_obj->Clear();
898    
899      if(orb_nuc_obj)orb_nuc_obj->Clear();
900      if(orb_ext_obj)orb_ext_obj->Clear();
901      if(orb_ext_nuc_obj)orb_ext_nuc_obj->Clear();
902    
903      if(trk2_nuc_obj)trk2_nuc_obj->Clear();;
904      if( calo2_nuc_obj)calo2_nuc_obj->Clear();;
905      if(tof2_nuc_obj)tof2_nuc_obj->Clear();;
906      if(orb2_nuc_obj)orb2_nuc_obj->Clear();;
907    
908      if (tsorted)tsorted->Delete();
909      if (timage)timage->Delete();
910      if (text) text->Delete();
911    
912      if (tsorted_nuc)tsorted_nuc->Delete();
913      if (timage_nuc)timage_nuc->Delete();
914      if (text_nuc) text_nuc->Delete();
915  }  }
916  ;  ;
917    
# Line 747  void PamLevel2::Reset() { Line 945  void PamLevel2::Reset() {
945      //      //
946      TIter next2(contents);      TIter next2(contents);
947      TChain *questa = 0;      TChain *questa = 0;
948      while (questa = (TChain*) next2()) {      while ( (questa = (TChain*) next2()) ) {
949        TString name = questa->GetName();        TString name = questa->GetName();
950        questa->Delete();        questa->Delete();
951        questa = NULL;        questa = NULL;
# Line 778  void PamLevel2::Reset() { Line 976  void PamLevel2::Reset() {
976    trkh_obj = 0;    trkh_obj = 0;
977    calo1_obj = 0;    calo1_obj = 0;
978    calo2_obj = 0;    calo2_obj = 0;
979    tof_obj = 0;    tof2_obj = 0;
980    trig_obj = 0;    trig_obj = 0;
981    s4_obj = 0;    s4_obj = 0;
982    nd_obj = 0;    nd_obj = 0;
983    ac_obj = 0;    ac_obj = 0;
984    orb_obj = 0;    orb2_obj = 0;
985    gp_obj = 0;    gp_obj = 0;
986    
987      trk_ext_obj     = 0;
988      trk_ext_nuc_obj = 0;
989      trk_nuc_obj     = 0;
990      
991      calo_ext_obj     = 0;
992      calo_ext_nuc_obj = 0;
993      calo_nuc_obj     = 0;
994      
995      tof_ext_obj     = 0;
996      tof_ext_nuc_obj = 0;
997      tof_nuc_obj     = 0;
998      
999      orb_ext_obj     = 0;
1000      orb_ext_nuc_obj = 0;
1001      orb_nuc_obj     = 0;
1002    
1003      trk2_nuc_obj  = 0;
1004      calo2_nuc_obj = 0;
1005      tof2_nuc_obj  = 0;
1006      orb2_nuc_obj  = 0;
1007    
1008      trk2_nuc_obj  = 0;
1009      calo2_nuc_obj = 0;
1010      tof2_nuc_obj  = 0;
1011      orb2_nuc_obj  = 0;
1012    //    //
1013    // Reset run pointers    // Reset run pointers
1014    //    //
# Line 792  void PamLevel2::Reset() { Line 1016  void PamLevel2::Reset() {
1016    soft_obj = 0;// Emiliano    soft_obj = 0;// Emiliano
1017    irun = -1;    irun = -1;
1018    irunt = -1;    irunt = -1;
1019      totrunentry = 0LL;
1020      totrunentrymax = 0LL;
1021      totrunentrymin = 0LL;
1022    runfirstentry = 0ULL;    runfirstentry = 0ULL;
1023    runlastentry = 0ULL;    runlastentry = 0ULL;
1024      prevabstime = 0ULL;
1025      prevpktnum = 0;
1026      abstime = 0ULL;
1027      pktnum = 0;
1028      isFragment = false;
1029    //    //
1030    totdltime[0] = 0LL;    totdltime[0] = 0LL;
1031    totdltime[1] = 0LL;    totdltime[1] = 0LL;
# Line 811  Bool_t PamLevel2::IsGood(Bool_t strict) Line 1043  Bool_t PamLevel2::IsGood(Bool_t strict)
1043    if (strict) {    if (strict) {
1044      if (trk2_obj && trk2_obj->UnpackError() != 0)      if (trk2_obj && trk2_obj->UnpackError() != 0)
1045        goodev = false;        goodev = false;
1046      if (tof_obj && tof_obj->unpackError != 0)      if (tof2_obj && tof2_obj->unpackError != 0)
1047        goodev = false;        goodev = false;
1048      if (trig_obj && trig_obj->unpackError != 0)      if (trig_obj && trig_obj->unpackError != 0)
1049        goodev = false;        goodev = false;
# Line 821  Bool_t PamLevel2::IsGood(Bool_t strict) Line 1053  Bool_t PamLevel2::IsGood(Bool_t strict)
1053        goodev = false;        goodev = false;
1054      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)))
1055        goodev = false;        goodev = false;
1056      //  if(orb_obj)      //  if(orb2_obj)
1057    }    }
1058    else {    else {
1059      if (nd_obj && nd_obj->unpackError != 0)      if (nd_obj && nd_obj->unpackError != 0)
# Line 833  Bool_t PamLevel2::IsGood(Bool_t strict) Line 1065  Bool_t PamLevel2::IsGood(Bool_t strict)
1065  }  }
1066  ;  ;
1067    
1068    void PamLevel2::SkipRunInfoUpdate(){
1069      printf("\n\n ******** WARNING ******** \n Skip DB connections, DO NOT USE PamLevel2::GetRunInfo() method! \n\n");
1070      fUpdateRunInfo = false;
1071      this->SetSELLI(2);
1072      printf(" ===============> W A R N I N G <================ \n");
1073      printf(" in case PamLevel2::CreateCloneTrees() will be called \n");
1074      printf(" it will be reverted to PadmeAmidala level2 structure , i.e. NO SELECTIONLIST WILL BE CREATED IN THE NEW LEVEL2 FILE! \n\n");
1075      if ( run_tree_clone ){
1076        printf(" ===============> W A R N I N G <================ \n");
1077        printf(" PamLevel2::SkipRunIndoUpdate or PamLevel2::NoDBconnections() has been called together with PamLevel2::CreateCloneTrees() \n");
1078        printf(" TO AVOID CRASHES call PamLevel2::CreateCloneTrees() after PamLevel2::SkipRunIndoUpdate or PamLevel2::NoDBconnections() \n");    
1079      };
1080    }
1081    
1082    void PamLevel2::SetMaxShift(Int_t sh){
1083      if ( sh >=  0 ){
1084        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");
1085        maxshift = sh;
1086      } else {
1087        ULong64_t nev = GetEntries();
1088        ULong64_t runnev = 0ULL;
1089        for (Int_t r=0; r< run_tree->GetEntries();r++){
1090          run_tree->GetEntry(r);//update runinfo
1091          runnev += GetRunInfo()->NEVENTS;
1092        }
1093        maxshift = (Int_t)(runnev-nev) + 10; // +10 just to be conservative
1094        if ( (runnev-nev) == 0 ) isSync = true;
1095        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);
1096        //    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
1097      }
1098    }
1099    
1100  //--------------------------------------  //--------------------------------------
1101  //  //
1102  //  //
# Line 875  void *PamLevel2::GetPointerTo(const char Line 1139  void *PamLevel2::GetPointerTo(const char
1139      return &calo2_obj;      return &calo2_obj;
1140    };    };
1141    if (!objname.CompareTo("ToFLevel2")) {    if (!objname.CompareTo("ToFLevel2")) {
1142      if (!tof_obj) {      if (!tof2_obj) {
1143        tof_obj = new ToFLevel2();        tof2_obj = new ToFLevel2();
1144        tof_obj->Set();        tof2_obj->Set();
1145      }      }
1146      return &tof_obj;      return &tof2_obj;
1147    };    };
1148    if (!objname.CompareTo("TrigLevel2")) {    if (!objname.CompareTo("TrigLevel2")) {
1149      if (!trig_obj)      if (!trig_obj)
# Line 902  void *PamLevel2::GetPointerTo(const char Line 1166  void *PamLevel2::GetPointerTo(const char
1166      return &ac_obj;      return &ac_obj;
1167    };    };
1168    if (!objname.CompareTo("OrbitalInfo")) {    if (!objname.CompareTo("OrbitalInfo")) {
1169      if (!orb_obj) {      if (!orb2_obj) {
1170        orb_obj = new OrbitalInfo();        orb2_obj = new OrbitalInfo();
1171        orb_obj->Set();        orb2_obj->Set();
1172      }      }
1173      return &orb_obj;      return &orb2_obj;
1174    };    };
1175    //     if(!objname.CompareTo("OrbitalInfo")){    //     if(!objname.CompareTo("OrbitalInfo")){
1176    //    if(!orb_obj)   orb_obj   = new OrbitalInfo();    //    if(!orb2_obj)   orb2_obj   = new OrbitalInfo();
1177    //    return &orb_obj;    //    return &orb2_obj;
1178    //     };    //     };
1179    if (!objname.CompareTo("GPamela")) {    if (!objname.CompareTo("GPamela")) {
1180      if (!gp_obj)      if (!gp_obj)
# Line 974  CaloTrkVar *PamLevel2::GetCaloStoredTrac Line 1238  CaloTrkVar *PamLevel2::GetCaloStoredTrac
1238   */   */
1239  ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno) {  ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno) {
1240    
1241    if (!tof_obj)    if (!tof2_obj)
1242      return 0;      return 0;
1243    
1244    if (tof_obj->ToFLevel2::ntrk() == 0) {    if (tof2_obj->ToFLevel2::ntrk() == 0) {
1245      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"
1246          << endl;          << endl;
1247      return NULL;      return NULL;
# Line 987  ToFTrkVar *PamLevel2::GetToFStoredTrack( Line 1251  ToFTrkVar *PamLevel2::GetToFStoredTrack(
1251    Int_t it_tof = 0;    Int_t it_tof = 0;
1252    
1253    do {    do {
1254      c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);      c = tof2_obj->ToFLevel2::GetToFTrkVar(it_tof);
1255      it_tof++;      it_tof++;
1256    } while (c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());    } while (c && seqno != c->trkseqno && it_tof < tof2_obj->ToFLevel2::ntrk());
1257    
1258    if (!c || seqno != c->trkseqno) {    if (!c || seqno != c->trkseqno) {
1259      c = 0;      c = 0;
# Line 1012  ToFTrkVar *PamLevel2::GetToFStoredTrack( Line 1276  ToFTrkVar *PamLevel2::GetToFStoredTrack(
1276   */   */
1277  OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno) {  OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno) {
1278    
1279    if (!orb_obj)    if (!orb2_obj)
1280      return 0;      return 0;
1281    
1282    if (orb_obj->OrbitalInfo::ntrk() == 0) {    if (orb2_obj->OrbitalInfo::ntrk() == 0) {
1283      //       // TRICK BEGIN      //       // TRICK BEGIN
1284      //       OrbitalInfoTrkVar  *r = new OrbitalInfoTrkVar(); // TEMPORARY TRICK      //       OrbitalInfoTrkVar  *r = new OrbitalInfoTrkVar(); // TEMPORARY TRICK
1285      //       Int_t nn = 0;      //       Int_t nn = 0;
1286      //       TClonesArray &tor = *orb_obj->OrbitalInfoTrk;      //       TClonesArray &tor = *orb2_obj->OrbitalInfoTrk;
1287      //       for(Int_t nt=0; nt < tof_obj->ToFLevel2::ntrk(); nt++){      //       for(Int_t nt=0; nt < tof2_obj->ToFLevel2::ntrk(); nt++){
1288      //  //      //  //
1289      //  ToFTrkVar *ptt = tof_obj->ToFLevel2::GetToFTrkVar(nt);      //  ToFTrkVar *ptt = tof2_obj->ToFLevel2::GetToFTrkVar(nt);
1290      //  if ( ptt->trkseqno != -1  ){      //  if ( ptt->trkseqno != -1  ){
1291      //    //      //    //
1292      //    r->trkseqno = ptt->trkseqno;      //    r->trkseqno = ptt->trkseqno;
# Line 1044  OrbitalInfoTrkVar *PamLevel2::GetOrbital Line 1308  OrbitalInfoTrkVar *PamLevel2::GetOrbital
1308      //       };      //       };
1309      //       delete r;      //       delete r;
1310      //       OrbitalInfoTrkVar *c = 0;      //       OrbitalInfoTrkVar *c = 0;
1311      //       c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(0);      //       c = orb2_obj->OrbitalInfo::GetOrbitalInfoTrkVar(0);
1312      //       return c;      //       return c;
1313      //       //TRICK END      //       //TRICK END
1314      cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo " << seqno      cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo " << seqno
# Line 1056  OrbitalInfoTrkVar *PamLevel2::GetOrbital Line 1320  OrbitalInfoTrkVar *PamLevel2::GetOrbital
1320    Int_t it_tof = 0;    Int_t it_tof = 0;
1321    
1322    do {    do {
1323      c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);      c = orb2_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);
1324      it_tof++;      it_tof++;
1325    } while (c && seqno != c->trkseqno && it_tof < orb_obj->OrbitalInfo::ntrk());    } while (c && seqno != c->trkseqno && it_tof < orb2_obj->OrbitalInfo::ntrk());
1326    
1327    if (!c || seqno != c->trkseqno) {    if (!c || seqno != c->trkseqno) {
1328      c = 0;      c = 0;
# Line 1189  void PamLevel2::SortTracks() { Line 1453  void PamLevel2::SortTracks() {
1453    // create TCloneArrays to store tracks and its images    // create TCloneArrays to store tracks and its images
1454    if (!tsorted)    if (!tsorted)
1455      tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());      tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1456    tsorted->Delete();    tsorted->Clear("C+C");//Delete();
1457    TClonesArray &ttsorted = *tsorted;    TClonesArray &ttsorted = *tsorted;
1458    
1459    if (!timage)    if (!timage)
1460      timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());      timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1461    timage->Delete();    timage->Clear("C+C");//Delete();
1462    TClonesArray &ttimage = *timage;    TClonesArray &ttimage = *timage;
1463    
1464    
1465    
1466    //--------------------------------------------------    //--------------------------------------------------
1467    // retrieve sorting method    // retrieve sorting method
1468    //--------------------------------------------------    //--------------------------------------------------
# Line 1312  void PamLevel2::SortTracks() { Line 1578  void PamLevel2::SortTracks() {
1578        // -----------------------------------------------------------------------------------------        // -----------------------------------------------------------------------------------------
1579        // check the number of hit pmts along the track        // check the number of hit pmts along the track
1580        // on S12 S21 and S32, where paddles are parallel to Y axis        // on S12 S21 and S32, where paddles are parallel to Y axis
1581        if ((use_TOF || use_S1 || use_S2 || use_S3) && !tof_obj) {        if ((use_TOF || use_S1 || use_S2 || use_S3) && !tof2_obj) {
1582          cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but ToFLevel2 not loaded !!!";          cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but ToFLevel2 not loaded !!!";
1583          return;          return;
1584        };        };
# Line 1329  void PamLevel2::SortTracks() { Line 1595  void PamLevel2::SortTracks() {
1595          //          //
1596          Float_t sen = 0.;          Float_t sen = 0.;
1597          for (Int_t ih = 0; ih < op->npmtadc; ih++) {          for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1598            Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));            Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1599            if (pl == 2 || pl == 3 || pl == 4 || pl == 5)            if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
1600              sen += (op->dedx).At(ih);              sen += (op->dedx).At(ih);
1601          };          };
1602          for (Int_t ih = 0; ih < oi->npmtadc; ih++) {          for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1603            Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));            Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1604            if (pl == 2 || pl == 3 || pl == 4 || pl == 5)            if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
1605              sen += (oi->dedx).At(ih);              sen += (oi->dedx).At(ih);
1606          };          };
# Line 1347  void PamLevel2::SortTracks() { Line 1613  void PamLevel2::SortTracks() {
1613            Int_t nz = 6;            Int_t nz = 6;
1614            Float_t zin[6]; // << define TOF z-coordinates            Float_t zin[6]; // << define TOF z-coordinates
1615            for (Int_t ip = 0; ip < nz; ip++)            for (Int_t ip = 0; ip < nz; ip++)
1616              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
1617            Trajectory *tr = new Trajectory(nz, zin);            Trajectory *tr = new Trajectory(nz, zin);
1618            //            //
1619            Int_t nphit_p = 0;            Int_t nphit_p = 0;
# Line 1356  void PamLevel2::SortTracks() { Line 1622  void PamLevel2::SortTracks() {
1622            Float_t enhit_i = 0.;            Float_t enhit_i = 0.;
1623            //            //
1624            for (Int_t ih = 0; ih < op->npmtadc; ih++) {            for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1625              Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));              Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1626              if (pl == 1 || pl == 2 || pl == 5) {              if (pl == 1 || pl == 2 || pl == 5) {
1627                nphit_p++;                nphit_p++;
1628                enhit_p += (op->dedx).At(ih);                enhit_p += (op->dedx).At(ih);
# Line 1367  void PamLevel2::SortTracks() { Line 1633  void PamLevel2::SortTracks() {
1633            //            //
1634            if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {            if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
1635              for (Int_t ih = 0; ih < op->npmtadc; ih++) {              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1636                Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1637                if (pl == 0) {                if (pl == 0) {
1638                  nphit_p++;                  nphit_p++;
1639                  enhit_p += (op->dedx).At(ih);                  enhit_p += (op->dedx).At(ih);
# Line 1376  void PamLevel2::SortTracks() { Line 1642  void PamLevel2::SortTracks() {
1642            };            };
1643            if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {            if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
1644              for (Int_t ih = 0; ih < op->npmtadc; ih++) {              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1645                Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1646                if (pl == 3) {                if (pl == 3) {
1647                  nphit_p++;                  nphit_p++;
1648                  enhit_p += (op->dedx).At(ih);                  enhit_p += (op->dedx).At(ih);
# Line 1385  void PamLevel2::SortTracks() { Line 1651  void PamLevel2::SortTracks() {
1651            };            };
1652            if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {            if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
1653              for (Int_t ih = 0; ih < op->npmtadc; ih++) {              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1654                Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1655                if (pl == 4) {                if (pl == 4) {
1656                  nphit_p++;                  nphit_p++;
1657                  enhit_p += (op->dedx).At(ih);                  enhit_p += (op->dedx).At(ih);
# Line 1394  void PamLevel2::SortTracks() { Line 1660  void PamLevel2::SortTracks() {
1660            };            };
1661    
1662            for (Int_t ih = 0; ih < oi->npmtadc; ih++) {            for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1663              Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));              Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1664              if (pl == 1 || pl == 2 || pl == 5) {              if (pl == 1 || pl == 2 || pl == 5) {
1665                nphit_i++;                nphit_i++;
1666                enhit_i += (op->dedx).At(ih);                enhit_i += (op->dedx).At(ih);
# Line 1405  void PamLevel2::SortTracks() { Line 1671  void PamLevel2::SortTracks() {
1671            //            //
1672            if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {            if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
1673              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1674                Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1675                if (pl == 0) {                if (pl == 0) {
1676                  nphit_i++;                  nphit_i++;
1677                  enhit_i += (op->dedx).At(ih);                  enhit_i += (op->dedx).At(ih);
# Line 1414  void PamLevel2::SortTracks() { Line 1680  void PamLevel2::SortTracks() {
1680            };            };
1681            if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {            if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
1682              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1683                Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1684                if (pl == 3) {                if (pl == 3) {
1685                  nphit_i++;                  nphit_i++;
1686                  enhit_i += (op->dedx).At(ih);                  enhit_i += (op->dedx).At(ih);
# Line 1423  void PamLevel2::SortTracks() { Line 1689  void PamLevel2::SortTracks() {
1689            };            };
1690            if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {            if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
1691              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1692                Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1693                if (pl == 4) {                if (pl == 4) {
1694                  nphit_i++;                  nphit_i++;
1695                  enhit_i += (op->dedx).At(ih);                  enhit_i += (op->dedx).At(ih);
# Line 1467  void PamLevel2::SortTracks() { Line 1733  void PamLevel2::SortTracks() {
1733             cout << "image: npmttdc "<< oi->npmttdc << endl;*/             cout << "image: npmttdc "<< oi->npmttdc << endl;*/
1734    
1735            //      for (Int_t ih=0; ih < op->npmtadc; ih++){            //      for (Int_t ih=0; ih < op->npmtadc; ih++){
1736            //        Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );            //        Int_t pl = tof2_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1737            //        if(pl == 1 || pl == 2 || pl == 5)nphit_p++;            //        if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
1738            //      };            //      };
1739    
1740            //      for (Int_t ih=0; ih < oi->npmtadc; ih++){            //      for (Int_t ih=0; ih < oi->npmtadc; ih++){
1741            //        Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );            //        Int_t pl = tof2_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1742            //        if(pl == 1 || pl == 2 || pl == 5)nphit_i++;            //        if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
1743            //      };            //      };
1744            // --- modified to count tdc signals (more efficient?)            // --- modified to count tdc signals (more efficient?)
1745            // --- and to implement check on tdcflag            // --- and to implement check on tdcflag
1746            for (Int_t ih = 0; ih < op->npmttdc; ih++) {            for (Int_t ih = 0; ih < op->npmttdc; ih++) {
1747              Int_t pl = tof_obj->GetPlaneIndex((op->pmttdc).At(ih));              Int_t pl = tof2_obj->GetPlaneIndex((op->pmttdc).At(ih));
1748              //      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++;
1749              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))
1750                  || (use_S3 && (pl == 4 || pl == 5))) {                  || (use_S3 && (pl == 4 || pl == 5))) {
# Line 1488  void PamLevel2::SortTracks() { Line 1754  void PamLevel2::SortTracks() {
1754            };            };
1755    
1756            for (Int_t ih = 0; ih < oi->npmttdc; ih++) {            for (Int_t ih = 0; ih < oi->npmttdc; ih++) {
1757              Int_t pl = tof_obj->GetPlaneIndex((oi->pmttdc).At(ih));              Int_t pl = tof2_obj->GetPlaneIndex((oi->pmttdc).At(ih));
1758              //      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++;
1759              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))
1760                  || (use_S3 && (pl == 4 || pl == 5))) {                  || (use_S3 && (pl == 4 || pl == 5))) {
# Line 1663  void PamLevel2::SortTracks() { Line 1929  void PamLevel2::SortTracks() {
1929    
1930  }  }
1931  ;  ;
1932    //
1933    //--------------------------------------
1934    /**
1935     * Sort physical (tracker) tracks.
1936     * @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...).
1937     * Sorting cryteria:
1938     * TRK: lower chi**2
1939     * CAL: lower Y spatial residual on the first calorimeter plane
1940     * TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis).
1941     * S1: (ask Emiliano)
1942     * S2: (ask Emiliano)
1943     * S3: (ask Emiliano)
1944     * GP: more GP hits
1945     * The default sorting cryterium is "TOF+CAL".
1946     *
1947     * 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).
1948     *
1949     * New version, with handling of extended tracks and nuclei tracks.
1950     */
1951    void PamLevel2::SortTracksNew() {
1952    
1953      //--------------------------------------------------
1954      //Check if the current event has already been sorted
1955      //--------------------------------------------------
1956      if (issorted_new && lastsorted_new == GetReadEntry()) {
1957          return; //already done for this event
1958      }
1959    
1960    
1961    //  cout << "SORT" << endl;
1962    
1963      //Reset the sort flags, just in case something will go wrong...
1964      issorted_new = false;
1965      lastsorted_new = -1;
1966    
1967      //--------------------------------------------------
1968      // set input variables
1969      //--------------------------------------------------
1970    
1971      TString how = howtosort;
1972      //Save current Object count
1973      Int_t ObjectNumber = TProcessID::GetObjectCount();
1974    
1975    
1976    
1977    
1978      TrkLevel2  * trk2 ;
1979      CaloLevel2 * calo2;
1980      ToFLevel2  * tof2  ;
1981      OrbitalInfo  * orb2 ;
1982      
1983      TClonesArray * trkext ;
1984      TClonesArray * caloext;
1985      TClonesArray * tofext ;
1986      TClonesArray * orbext ;
1987    
1988    
1989    //   cout << "trk2_obj" << trk2_obj<< endl;
1990    //   cout << "trk2_nuc_obj" << trk2_nuc_obj<< endl;
1991    //   cout << " trk_ext_obj "<<trk_ext_obj<< endl;
1992    //   cout << " trk_ext_nuc_obj "<<trk_ext_nuc_obj<< endl;
1993    
1994      //-----------------------------------------------------------
1995      // create/reset TCloneArrays to store tracks and their images
1996      //-----------------------------------------------------------
1997    
1998    //  cout << " PamLevel2::SortTracksNew() --- Clear TClonesArray objects"<<endl;
1999      
2000      // main tracks from standard alg
2001    //   if (!tsorted)
2002    //       tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2003    //   tsorted->Clear("C+C");//Delete();
2004    //   // track images from standard alg
2005    //   if (!timage)
2006    //       timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2007    //   timage->Clear("C+C");//Delete();
2008    //   // tracks from extended algorythm
2009    //   if(EXT && !text)
2010    //       text = new TClonesArray("PamTrack",trk_ext_obj->GetEntries());
2011    //   if(text)text->Clear("C+C");//Delete();
2012    
2013      if(tsorted)delete tsorted;
2014      if(timage) delete timage;
2015      if(text)   delete text;
2016      tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2017      timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2018      text = new TClonesArray("PamTrack",trk_ext_obj->GetEntries());
2019    
2020      //-----------------------------------------------------------
2021      // create/reset TCloneArrays to store tracks and their images
2022      //-----------------------------------------------------------
2023      if(NUC){
2024    
2025          
2026          if(tsorted_nuc)delete tsorted_nuc;
2027          if(timage_nuc) delete timage_nuc;
2028          if(text_nuc)   delete text_nuc;
2029          tsorted_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2030          timage_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2031          text_nuc = new TClonesArray("PamTrack",trk_ext_nuc_obj->GetEntries());
2032    
2033      // main tracks from standard alg
2034    //       if (!tsorted_nuc)
2035    //        tsorted_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2036    //       tsorted_nuc->Clear("C+C");//Delete();
2037    //       // track images from standard alg
2038    //       if (!timage_nuc)
2039    //        timage_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2040    //       timage_nuc->Clear("C+C");//Delete();
2041    //       // tracks from extended algorythm
2042    //       if(EXT && !text_nuc)
2043    //        text_nuc = new TClonesArray("PamTrack",trk_ext_nuc_obj->GetEntries());
2044    //       if(text_nuc)text_nuc->Clear("C+C");//Delete();
2045    
2046      }
2047      //--------------------------------------------------
2048      // retrieve sorting method
2049      //--------------------------------------------------
2050      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
2051      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
2052      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
2053      Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
2054      Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
2055      Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
2056      Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
2057    
2058      if (use_TOF) {
2059        use_S1 = true;
2060        use_S2 = true;
2061        use_S3 = true;
2062      };
2063      if (!CAL2 && use_CAL)
2064        use_CAL = false;
2065      if (!TOF) {
2066        use_TOF = false;
2067        use_S1 = false;
2068        use_S2 = false;
2069        use_S3 = false;
2070      }
2071      if (!GP) {
2072        use_GP = false;
2073      }
2074    
2075      if (!TRK2) {
2076        cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
2077        return;
2078      };
2079    
2080    
2081      ///////////////////////////////////////////////////////////////////////////////////
2082      //
2083      //   sort tracks and fill PamTrack arrays
2084      //
2085      ///////////////////////////////////////////////////////////////////////////////////
2086      for(int doit=0; doit<2; doit++){
2087    
2088    //       cout << "doit "<<doit<<endl;
2089    
2090    
2091          if(doit == 0){
2092    
2093              trk2  = trk2_obj;
2094              calo2 = calo2_obj;
2095              tof2  = tof2_obj;
2096              orb2  = orb2_obj;
2097          
2098              trkext = trk_ext_obj;
2099              caloext = calo_ext_obj;
2100              tofext = tof_ext_obj;
2101              orbext = orb_ext_obj;
2102        
2103          
2104          
2105          
2106    
2107          }else if (doit == 1){
2108    
2109              if(!NUC)break;
2110    
2111          
2112              trk2  = trk2_nuc_obj;
2113              calo2 = calo2_nuc_obj;
2114              tof2  = tof2_nuc_obj;
2115              orb2  = orb2_nuc_obj;
2116          
2117              trkext = trk_ext_nuc_obj;
2118              caloext = calo_ext_nuc_obj;
2119              tofext = tof_ext_nuc_obj;
2120              orbext = orb_ext_nuc_obj;
2121          
2122          
2123          
2124    
2125          }
2126    
2127    //       cout << "trk2" << trk2<<endl;
2128    //       cout << "calo2" << calo2<<endl;
2129    //       cout << "tof2" << tof2<<endl;
2130    //       cout << "orb2" << orb2<<endl;
2131    //       cout << "trkext" <<trkext <<endl;
2132    //       cout << "tofext" << tofext<<endl;
2133    //       cout << "caloext" << caloext<<endl;
2134    //       cout << "orbext" << orbext<<endl;
2135    
2136          TClonesArray &ttext    = (doit==0 ? *text : *text_nuc);
2137          TClonesArray &ttimage  = (doit==0 ? *timage : *timage_nuc);
2138          TClonesArray &ttsorted = (doit==0 ? *tsorted : *tsorted_nuc);
2139      
2140    //       cout << "tsorted + timage "<<doit<<endl;
2141    
2142          //--------------------------------------------------
2143          // loop over "physical" tracks sorted by the tracker
2144          //--------------------------------------------------
2145          for (Int_t i = 0; i < trk2->TrkLevel2::GetNTracks(); i++) {
2146    
2147              TrkTrack *ts = 0;
2148              CaloTrkVar *cs = 0;
2149              ToFTrkVar *os = 0;
2150              OrbitalInfoTrkVar *rs = 0;
2151    
2152              // get tracker tracks
2153              TrkTrack *tp = trk2->GetTrack(i); //tracker
2154              CaloTrkVar *cp = calo2->GetCaloStoredTrack(tp->GetSeqNo());
2155              ToFTrkVar *op = tof2->GetToFStoredTrack(tp->GetSeqNo());
2156              OrbitalInfoTrkVar *rp = orb2->GetOrbitalInfoStoredTrack(tp->GetSeqNo());
2157    
2158              TrkTrack *ti = 0; //tracker (image)
2159              CaloTrkVar *ci = 0;
2160              ToFTrkVar *oi = 0;
2161              OrbitalInfoTrkVar *ri = 0;
2162              //    cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
2163              // if track has an image, check image selection
2164    
2165              Int_t tp_score = 0; //main track sorted by the tracker
2166              Int_t ti_score = 0; //image track
2167              Int_t totp_score = 0; //main track sorted by the tracker
2168              Int_t toti_score = 0; //image track
2169    
2170              if (tp->HasImage()) {
2171    
2172                  ti = trk2->GetTrackImage(i); //tracker (image)
2173                  ci = calo2->GetCaloStoredTrack(ti->GetSeqNo());
2174                  oi = tof2->GetToFStoredTrack(ti->GetSeqNo());
2175                  ri = orb2->GetOrbitalInfoStoredTrack(ti->GetSeqNo());
2176    
2177                  //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
2178    
2179                  //assign starting scores
2180                  tp_score = 0; //main track sorted by the tracker
2181                  ti_score = 0; //image track
2182    
2183                  // -----------------------------------------------------------------------------------------
2184                  // *****************************************************************************************
2185                  // -----------------------------------------------------------------------------------------
2186                  // calorimeter check
2187                  // -----------------------------------------------------------------------------------------
2188                  if (use_CAL && !calo2) {
2189                      cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but CaloLevel2 not loaded !!!";
2190                      return;
2191                  };
2192                  if (use_CAL && !cp && ci) {
2193                      ti_score++;
2194                      toti_score++;
2195                  };
2196                  if (use_CAL && cp && !ci) {
2197                      tp_score++;
2198                      totp_score++;
2199                  };
2200                  if (use_CAL && cp && ci && true) {
2201    
2202                      if (cp->npresh > ci->npresh && true) {
2203                          tp_score++;
2204                          totp_score++;
2205                      };
2206                      if (cp->npresh < ci->npresh && true) {
2207                          ti_score++;
2208                          toti_score++;
2209                      };
2210    
2211                      //    cout << "CALO "<<tp_score<<ti_score<<endl;
2212    
2213                  };
2214                  // -----------------------------------------------------------------------------------------
2215                  // *****************************************************************************************
2216                  // -----------------------------------------------------------------------------------------
2217                  // TOF check
2218                  // -----------------------------------------------------------------------------------------
2219                  // check the number of hit pmts along the track
2220                  // on S12 S21 and S32, where paddles are parallel to Y axis
2221                  if ((use_TOF || use_S1 || use_S2 || use_S3) && !tof2) {
2222                      cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but ToFLevel2 not loaded !!!";
2223                      return;
2224                  };
2225                  //
2226                  if ((use_TOF || use_S1 || use_S2 || use_S3) && !op && oi) {
2227                      ti_score++;
2228                      toti_score++;
2229                  };
2230                  if ((use_TOF || use_S1 || use_S2 || use_S3) && op && !oi) {
2231                      tp_score++;
2232                      totp_score++;
2233                  };
2234                  if ((use_TOF || use_S1 || use_S2 || use_S3) && op && oi) {
2235                      //
2236                      Float_t sen = 0.;
2237                      for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2238                          Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2239                          if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
2240                              sen += (op->dedx).At(ih);
2241                      };
2242                      for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2243                          Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2244                          if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
2245                              sen += (oi->dedx).At(ih);
2246                      };
2247                      //
2248                      if (sen >= sortthr && false) { // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
2249                          //printf(" IS A NUCLEUS! en = %f \n",sen);
2250                          //
2251                          // is a nucleus use a different algorithm
2252                          //
2253                          Int_t nz = 6;
2254                          Float_t zin[6]; // << define TOF z-coordinates
2255                          for (Int_t ip = 0; ip < nz; ip++)
2256                              zin[ip] = tof2->GetZTOF(tof2->GetToFPlaneID(ip)); // << read ToF plane z-coordinates
2257                          Trajectory *tr = new Trajectory(nz, zin);
2258                          //
2259                          Int_t nphit_p = 0;
2260                          Int_t nphit_i = 0;
2261                          Float_t enhit_p = 0.;
2262                          Float_t enhit_i = 0.;
2263                          //
2264                          for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2265                              Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2266                              if (pl == 1 || pl == 2 || pl == 5) {
2267                                  nphit_p++;
2268                                  enhit_p += (op->dedx).At(ih);
2269                              };
2270                          };
2271                          //
2272                          tp->DoTrack2(tr);
2273                          //
2274                          if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
2275                              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2276                                  Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2277                                  if (pl == 0) {
2278                                      nphit_p++;
2279                                      enhit_p += (op->dedx).At(ih);
2280                                  };
2281                              };
2282                          };
2283                          if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
2284                              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2285                                  Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2286                                  if (pl == 3) {
2287                                      nphit_p++;
2288                                      enhit_p += (op->dedx).At(ih);
2289                                  };
2290                              };
2291                          };
2292                          if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
2293                              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2294                                  Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2295                                  if (pl == 4) {
2296                                      nphit_p++;
2297                                      enhit_p += (op->dedx).At(ih);
2298                                  };
2299                              };
2300                          };
2301    
2302                          for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2303                              Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2304                              if (pl == 1 || pl == 2 || pl == 5) {
2305                                  nphit_i++;
2306                                  enhit_i += (op->dedx).At(ih);
2307                              };
2308                          };
2309                          //
2310                          ti->DoTrack2(tr);
2311                          //
2312                          if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
2313                              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2314                                  Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2315                                  if (pl == 0) {
2316                                      nphit_i++;
2317                                      enhit_i += (op->dedx).At(ih);
2318                                  };
2319                              };
2320                          };
2321                          if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
2322                              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2323                                  Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2324                                  if (pl == 3) {
2325                                      nphit_i++;
2326                                      enhit_i += (op->dedx).At(ih);
2327                                  };
2328                              };
2329                          };
2330                          if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
2331                              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2332                                  Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2333                                  if (pl == 4) {
2334                                      nphit_i++;
2335                                      enhit_i += (op->dedx).At(ih);
2336                                  };
2337                              };
2338                          };
2339    
2340                          if ((use_TOF || use_S1 || use_S2 || use_S3) && (nphit_p + nphit_i) != 0 && true) {
2341    
2342                              //        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);
2343                              //        printf(" score p %i score i %i \n",tp_score,ti_score);
2344                              //              if( enhit_p > enhit_i ) tp_score++;
2345                              //              if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
2346                              if (nphit_p > nphit_i)
2347                                  tp_score++;
2348                              if (nphit_p < nphit_i)
2349                                  ti_score++;
2350                              if (nphit_p == nphit_i) {
2351                                  if (enhit_p > enhit_i)
2352                                      tp_score++;
2353                                  else
2354                                      ti_score++;
2355                              };
2356                              //        printf(" dopo score p %i score i %i \n",tp_score,ti_score);
2357                          };
2358                          delete tr;
2359                          //
2360                      }
2361                      else {
2362                          // -------------
2363                          // NOT a NUCLEUS
2364                          // -------------
2365                          //printf(" NOT a NUCLEUS! en = %f \n",sen);
2366    
2367                          Int_t nphit_p = 0;
2368                          Int_t nphit_i = 0;
2369    
2370                          /*                                cout << "track: npmtadc "<< op->npmtadc << endl;
2371                            cout << "track: npmttdc "<< op->npmttdc << endl;
2372                            cout << "image: npmtadc "<< oi->npmtadc << endl;
2373                            cout << "image: npmttdc "<< oi->npmttdc << endl;*/
2374    
2375                          //          for (Int_t ih=0; ih < op->npmtadc; ih++){
2376                          //            Int_t pl = tof2_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
2377                          //            if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
2378                          //          };
2379    
2380                          //          for (Int_t ih=0; ih < oi->npmtadc; ih++){
2381                          //            Int_t pl = tof2_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
2382                          //            if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
2383                          //          };
2384                          // --- modified to count tdc signals (more efficient?)
2385                          // --- and to implement check on tdcflag
2386                          for (Int_t ih = 0; ih < op->npmttdc; ih++) {
2387                              Int_t pl = tof2->GetPlaneIndex((op->pmttdc).At(ih));
2388                              //        if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
2389                              if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
2390                                  || (use_S3 && (pl == 4 || pl == 5))) {
2391                                  if ((op->tdcflag).At(ih) == 0)
2392                                      nphit_p++;
2393                              };
2394                          };
2395    
2396                          for (Int_t ih = 0; ih < oi->npmttdc; ih++) {
2397                              Int_t pl = tof2->GetPlaneIndex((oi->pmttdc).At(ih));
2398                              //        if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;
2399                              if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
2400                                  || (use_S3 && (pl == 4 || pl == 5))) {
2401                                  if ((oi->tdcflag).At(ih) == 0)
2402                                      nphit_i++;
2403                              };
2404                          };
2405    
2406                          if ((nphit_p + nphit_i) != 0 && true) {
2407    
2408                              if (nphit_p != nphit_i) {
2409                                  totp_score += nphit_p;
2410                                  toti_score += nphit_i;
2411                                  tp_score += nphit_p;
2412                                  ti_score += nphit_i;
2413                              };
2414                              //        if     ( nphit_p > nphit_i) tp_score+=nphit_p;
2415                              //        else if( nphit_p < nphit_i) ti_score+=nphit_i;
2416                              //        else ;//niente
2417                          };
2418                      };
2419                      //    cout << "TOF "<<tp_score<<ti_score<<endl;
2420                  };
2421    
2422                  //      if(tp_score == ti_score) use_TRK = true;
2423    
2424    
2425                  // -----------------------------------------------------------------------------------------
2426                  // *****************************************************************************************
2427                  // -----------------------------------------------------------------------------------------
2428                  // tracker check
2429                  // -----------------------------------------------------------------------------------------
2430                  // chi**2 difference is not always large enough to distinguish among
2431                  // the real track and its image.
2432                  // Tracker check will be applied always when calorimeter and tof information is ambiguous.
2433                  // *** MODIFIED ON AUGUST 2007 ***
2434                  if (use_TRK) {
2435                      //    if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
2436                      //    else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
2437    
2438                      // CHECK 1 : number of points along X
2439                      if (tp->GetNX() >= ti->GetNX()) {
2440                          tp_score++;
2441                          totp_score++;
2442                      };
2443                      if (tp->GetNX() <= ti->GetNX()) {
2444                          ti_score++;
2445                          toti_score++;
2446                      };
2447                      // CHECK 2 : number of points along Y
2448                      if (tp->GetNY() >= ti->GetNY()) {
2449                          tp_score++;
2450                          totp_score++;
2451                      };
2452                      if (tp->GetNY() <= ti->GetNY()) {
2453                          ti_score++;
2454                          toti_score++;
2455                      };
2456    
2457                      //    cout << "TRK "<<tp_score<<ti_score<<endl;
2458                  };
2459    
2460                  // -----------------------------------------------------------------------------------------
2461                  // *****************************************************************************************
2462                  // -----------------------------------------------------------------------------------------
2463                  // GPamela check
2464                  // -----------------------------------------------------------------------------------------
2465    
2466                  //---------------------------------------------------
2467                  // count the number of GP hits
2468                  //---------------------------------------------------
2469                  if (use_GP) {
2470                      int ngphits_p = 0;
2471                      int ngphits_i = 0;
2472                      float toll = 0.02; //200 micron
2473                      for (int ih = 0; ih < GetGPamela()->Nthspe; ih++) {
2474                          int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
2475                          if (tp && tp->YGood(ip) && fabs(tp->ym[ip] - GetGPamela()->Yavspe[ih]) < toll && true)
2476                              ngphits_p++;
2477                          if (ti && ti->YGood(ip) && fabs(ti->ym[ip] - GetGPamela()->Yavspe[ih]) < toll && true)
2478                              ngphits_i++;
2479                      }
2480                      if (ngphits_p > ngphits_i && true) {
2481                          tp_score++;
2482                          totp_score++;
2483                      }
2484                      if (ngphits_p < ngphits_i && true) {
2485                          ti_score++;
2486                          toti_score++;
2487                      }
2488                  }
2489    
2490                  // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2491                  // the winner is....
2492                  // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2493                  if (tp_score > ti_score) {
2494    
2495                  }
2496                  else if (tp_score < ti_score) {
2497    
2498                      ts = ti;//its image!!
2499                      cs = ci;
2500                      os = oi;
2501                      rs = ri;
2502                      Int_t totis = toti_score;
2503    
2504                      ti = tp;//its image!!
2505                      ci = cp;
2506                      oi = op;
2507                      ri = rp;
2508    
2509                      tp = ts;//its image!!
2510                      cp = cs;
2511                      op = os;
2512                      rp = rs;
2513    
2514                      toti_score = totp_score;
2515                      totp_score = totis;
2516    
2517                  }
2518                  else {
2519    
2520                      //    cout << "Warning - track image ambiguity not solved" << endl;
2521    
2522                  };
2523    
2524              }
2525              else {
2526                  totp_score = 1;
2527                  toti_score = 0;
2528    
2529                  //            ts = tp;
2530                  //            cs = cp;
2531                  //            os = op;
2532              };
2533    
2534              //    cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
2535              //    sorted_tracks->Add(ts);//save the track in the sorted array
2536              //    sorted_tracks.Add(ts);//save the track in the sorted array
2537              //    sorted_tracks.Add(tp);//save the track in the sorted array
2538              //    cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
2539              //    cout<<"o "<<tp<<endl;
2540              //    cout<<"o "<<cp<<endl;
2541              //    cout<<"o "<<op<<endl;
2542    
2543              new (ttsorted[i]) PamTrack(tp, cp, op, rp);
2544              new (ttimage[i]) PamTrack(ti, ci, oi, ri);
2545    
2546              ((PamTrack*) (ttsorted[i]))->SetPScore(totp_score);
2547              ((PamTrack*) (ttsorted[i]))->SetIScore(toti_score);
2548              ((PamTrack*) (ttimage[i]))->SetPScore(totp_score);
2549              ((PamTrack*) (ttimage[i]))->SetIScore(toti_score);
2550          };
2551    
2552    
2553    
2554    
2555    
2556    //   if (tsorted->GetEntries() != trk2->GetNTracks()) {
2557    //     cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() " << tsorted->GetEntries()
2558    //         << " != trk2->GetNTracks() = " << trk2->GetNTracks() << endl;
2559    //     tsorted->Delete();
2560    //     tsorted = 0;
2561    //     timage->Delete();
2562    //     timage = 0;
2563    //   }
2564    
2565    
2566    //       cout << "text "<<doit<<endl;
2567    
2568    
2569          //--------------------------------------------------
2570          // fill array with extended tracks (this is easy...)
2571          //--------------------------------------------------
2572          if(EXT){
2573              for(int it=0; it<trkext->GetEntries(); it++){
2574                  
2575                  new (ttext[it]) PamTrack((ExtTrack*)(*trkext)[it], (CaloTrkVar*)(*caloext)[it], (ToFTrkVar*)(*tofext)[it], (OrbitalInfoTrkVar*)(*orbext)[it]);
2576                  
2577              }
2578          }
2579          
2580    
2581    
2582      };
2583    
2584    
2585      //Restore Object count
2586      //To save space in the table keeping track of all referenced objects
2587      //We reset the object count to what it was at the beginning of the event.
2588      TProcessID::SetObjectCount(ObjectNumber);
2589    
2590      //Everything went fine so the current event can be tagged as sorted
2591      issorted_new = true;
2592      lastsorted_new = GetReadEntry();
2593    
2594    //   cout << " tsorted "<< tsorted << " "<<(tsorted ? tsorted->GetEntries() : 0)<<endl;
2595    //   cout << " timage  "<< timage  << " "<<(timage  ? timage->GetEntries() : 0)<<endl;
2596    //   cout << " text    "<< text    << " "<<(text    ? text->GetEntries() : 0)<<endl;
2597    
2598    
2599    };
2600  //--------------------------------------  //--------------------------------------
2601  //  //
2602  //  //
# Line 1671  void PamLevel2::SortTracks() { Line 2605  void PamLevel2::SortTracks() {
2605   * 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.
2606   * 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.
2607   */   */
2608    
2609  // TRefArray *PamLevel2::GetTracks(){  // TRefArray *PamLevel2::GetTracks(){
2610    
2611  // //  *-*-*-*-*-*-*-*-*-*-*-*-*  // //  *-*-*-*-*-*-*-*-*-*-*-*-*
# Line 1681  void PamLevel2::SortTracks() { Line 2616  void PamLevel2::SortTracks() {
2616  //     return &sorted_tracks;  //     return &sorted_tracks;
2617    
2618  //  };  //  };
 TClonesArray *PamLevel2::GetTracks() {  
   
   //  *-*-*-*-*-*-*-*-*-*-*-*-*  
   SortTracks();  
   //  *-*-*-*-*-*-*-*-*-*-*-*-*  
2619    
   return tsorted;  
2620    
 }  
 ;  
2621  //--------------------------------------  //--------------------------------------
2622  //  //
2623  //  //
2624  //--------------------------------------  //--------------------------------------
2625    
2626  /**  /**
2627   * Retrieves the it-th Pamela "physical" track.   * Retrieves the it-th Pamela "physical" track.
2628   * It override TrkLevel2::GetTrack(int it).   * It override TrkLevel2::GetTrack(int it).
2629   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
2630   */   */
2631  PamTrack *PamLevel2::GetTrack(int it) {  PamTrack *PamLevel2::GetTrackOld(int it) {
   
   //    if(!trk2_obj) return 0;  
2632    
2633    // //  *-*-*-*+-*-*-*-*-*-*-*-*-*    PamTrack *track = NULL;
   //     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;  
   //     };  
   
   //     return track;  
2634    
   //    cout << "PamLevel2::GetTrack(int it) "<<endl;  
2635    //  *-*-*-*-*-*-*-*-*-*-*-*-*    //  *-*-*-*-*-*-*-*-*-*-*-*-*
2636    SortTracks();    SortTracks();
2637    //  *-*-*-*-*-*-*-*-*-*-*-*-*    //  *-*-*-*-*-*-*-*-*-*-*-*-*
2638    if (!tsorted)    if (!tsorted)
2639      return 0;      return track;
2640    if (!tsorted->GetEntries())    if (!tsorted->GetEntries())
2641      return 0;      return track;
2642    
   PamTrack *track = 0;  
2643    
2644    if (it >= 0 && it < trk2_obj->TrkLevel2::GetNTracks()) {    if (it >= 0 && it < trk2_obj->TrkLevel2::GetNTracks()) {
     //  TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);  
     //  track = GetPamTrackAlong(t);  
     //TClonesArray &t = *(tsorted);  
     //track = (PamTrack*)t[it];  
2645      track = (PamTrack*)((*tsorted)[it]);      track = (PamTrack*)((*tsorted)[it]);
2646    }    }
2647    else {    else {
2648      cout << "PamLevel2::GetTrack(int) : tracker track SeqNo " << it << " does not exist (GetNTracks() = "      cout << "PamLevel2::GetTrackOld(int) : tracker track SeqNo " << it << " does not exist (GetNTracks() = "
2649          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
2650    };    };
2651    
2652    return track;    return track;
2653    
2654    };
2655    
2656    //PamTrack *PamLevel2::GetTrack(int it) { return GetTrack(it,trkAlg); };
2657    
2658    /**
2659     * Retrieves the it-th Pamela "physical" track.
2660     * It override TrkLevel2::GetTrack(int it).
2661     * @param it Track number, ranging from 0 to GetNTracks().
2662     * @param alg Algorythm, see SetTrakingAlgorythm(char *alg) for explanation.
2663     */
2664    PamTrack *PamLevel2::GetTrack(int it, const char* alg) {
2665    
2666        TString s(alg);
2667        if(!s.CompareTo("") ||!s.CompareTo("STD") )return GetTrackOld(it); //old algorythm
2668    
2669    
2670        SortTracksNew();
2671        // >> fill tsorted, timage and text
2672    
2673        if ( ( !s.Contains("EXTF", TString::kIgnoreCase) || !EXT )){ //not forced exteded-alg requested (or exteded-data missing)
2674    
2675            if( s.Contains("NUC")){
2676                if(
2677                    tsorted_nuc &&
2678                    it < tsorted_nuc->GetEntries() &&                             //enough tracks found
2679                    it >= 0 &&                                                //valid index
2680                    true) return (PamTrack*)((*tsorted_nuc)[it]);                 //ok return the track
2681            }else{
2682                if(
2683                    tsorted &&
2684                    it < tsorted->GetEntries() &&                             //enough tracks found
2685                    it >= 0 &&                                                //valid index
2686                    true )return (PamTrack*)((*tsorted)[it]);                 //ok return the track
2687            }
2688    
2689        }
2690        
2691    
2692        /////////////////////////////////////////////////////////////////////////
2693        /// if requested get track from extended algorythm output
2694        /////////////////////////////////////////////////////////////////////////
2695        
2696        if(s.Contains("EXT", TString::kIgnoreCase) && EXT){//if exteded-alg requested
2697            
2698            if(s.Contains("NUC")){
2699                if(
2700                    text_nuc &&
2701                    it < text_nuc->GetEntries() &&                             //enough tracks found
2702                    it >= 0 &&                                                //valid index
2703                    true) return (PamTrack*)((*text_nuc)[it]);
2704            }else{
2705                if(
2706                    text &&
2707                    it < text->GetEntries() &&                             //enough tracks found
2708                    it >= 0 &&                                                //valid index
2709                    true) return (PamTrack*)((*text)[it]);
2710            }
2711    
2712        };
2713        
2714        
2715        cout << "PamTrack *PamLevel2::GetTrack("<<it<<","<<alg<<") -- wrong track number or unrecognised algorithm"<<endl;
2716        
2717        return NULL;
2718    
2719  }  }
2720  ;  ;
2721    TClonesArray *PamLevel2::GetTracks() {
2722    
2723      //  *-*-*-*-*-*-*-*-*-*-*-*-*
2724      SortTracks();
2725      //  *-*-*-*-*-*-*-*-*-*-*-*-*
2726    
2727      return tsorted;
2728    
2729    }
2730    ;
2731    Int_t  PamLevel2::GetNTracks(const char* alg) {
2732    
2733    
2734    //    cout << " trk_nuc_obj->GetEntries() "<<trk_nuc_obj->GetEntries()<<" trk2_nuc_obj->GetNTracks() "<<trk2_nuc_obj->GetNTracks()<<endl;
2735    
2736        TString s(alg);
2737    
2738        if(!s.CompareTo("") || !s.CompareTo("STD"))return trk2_obj->TrkLevel2::GetNTracks(); //standard algorythm
2739            
2740        if(s.Contains("EXTF", TString::kIgnoreCase) && EXT){
2741            if(s.Contains("NUC", TString::kIgnoreCase) && NUC)return trk_ext_nuc_obj->GetEntries();//ok
2742            return trk_ext_obj->GetEntries();//ok
2743        }
2744        if( s.Contains("EXT", TString::kIgnoreCase) && EXT) {
2745            if(s.Contains("NUC", TString::kIgnoreCase) && NUC)
2746                return (trk2_nuc_obj->TrkLevel2::GetNTracks() ?  trk2_nuc_obj->TrkLevel2::GetNTracks() :  trk_ext_nuc_obj->GetEntries() );  
2747            return (trk2_obj->TrkLevel2::GetNTracks() ?  trk2_obj->TrkLevel2::GetNTracks() :  trk_ext_obj->GetEntries() );
2748        }
2749        if(s.Contains("NUC", TString::kIgnoreCase) && NUC )
2750            return trk2_nuc_obj->TrkLevel2::GetNTracks();
2751        
2752        cout << "Int_t  PamLevel2::GetNTracks("<<alg<<") -- unrecognised algorithm"<<endl;
2753    
2754        return 0;
2755    
2756    }
2757    
2758    
2759  //--------------------------------------  //--------------------------------------
2760  //  //
# Line 1757  PamTrack *PamLevel2::GetTrack(int it) { Line 2764  PamTrack *PamLevel2::GetTrack(int it) {
2764   * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().   * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().
2765   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
2766   */   */
2767  PamTrack *PamLevel2::GetTrackImage(int it) {  PamTrack *PamLevel2::GetTrackImageOld(int it) {
2768    
2769    //  *-*-*-*-*-*-*-*-*-*-*-*-*    //  *-*-*-*-*-*-*-*-*-*-*-*-*
2770    SortTracks();    SortTracks();
# Line 1781  PamTrack *PamLevel2::GetTrackImage(int i Line 2788  PamTrack *PamLevel2::GetTrackImage(int i
2788      };      };
2789    }    }
2790    else {    else {
2791      cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo " << it << " does not exist (GetNTracks() = "      cout << "PamLevel2::GetTrackImageOld(int) : Tracker track SeqNo " << it << " does not exist (GetNTracks() = "
2792          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
2793    };    };
2794    
2795    return image;    return image;
2796  }  }
   
 //--------------------------------------  
 //  
 //  
 //--------------------------------------  
2797  /**  /**
2798   * Get the Pamela detector trees in a single file and make them friends.   * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().
2799   * @param f TFile pointer   * @param it Track number, ranging from 0 to GetNTracks().
2800   * @param detlist String to select trees to be included   * @param alg Algorythm, see SetTrakingAlgorythm(char *alg) for explanation.
2801   * @return Pointer to a TTree   */
2802    PamTrack *PamLevel2::GetTrackImage(int it, const char* alg) {
2803    
2804        TString s(alg);
2805        if(!s.CompareTo("") || !s.CompareTo("STD"))return GetTrackImageOld(it); //old algorythm
2806    
2807    
2808        SortTracksNew();
2809        // >> fill tsorted, timage and text
2810    
2811        if ( ( !s.Contains("EXTF", TString::kIgnoreCase) || !EXT )){ //not forced exteded-alg requested (or exteded-data missing)
2812    
2813            if( s.Contains("NUC")){
2814                if(
2815                    tsorted_nuc &&
2816                    it < tsorted_nuc->GetEntries() &&                             //enough tracks found
2817                    it >= 0 &&                                                //valid index
2818                    true){
2819                    TClonesArray &t = *(tsorted_nuc);
2820                    PamTrack *temp = (PamTrack*) t[it];
2821                    if (temp->GetTrkTrack()->HasImage()) {
2822                        return (PamTrack*)((*timage_nuc)[it]);                 //ok return the track
2823                    }else{
2824                        return NULL;
2825                    }
2826                    
2827                }
2828            }else{
2829                if(
2830                    tsorted &&
2831                    it < tsorted->GetEntries() &&                             //enough tracks found
2832                    it >= 0 &&                                                //valid index
2833                    true ){
2834                    TClonesArray &t = *(tsorted);
2835                    PamTrack *temp = (PamTrack*) t[it];
2836                    if (temp->GetTrkTrack()->HasImage()) {              
2837                        return (PamTrack*)((*timage)[it]);                 //ok return the track
2838                    }else{
2839                        return NULL;
2840                    }
2841                }
2842            }
2843    
2844        }
2845    
2846        cout << "PamTrack *PamLevel2::GetTrackImage("<<it<<","<<alg<<") -- wrong track number or unrecognised algorithm"<<endl;
2847          
2848        return NULL;
2849    
2850    }
2851    ;
2852    
2853    //--------------------------------------
2854    //
2855    //
2856    //--------------------------------------
2857    /**
2858     * Get the Pamela detector trees in a single file and make them friends.
2859     * @param f TFile pointer
2860     * @param detlist String to select trees to be included
2861     * @return Pointer to a TTree
2862   */   */
2863  TTree *PamLevel2::GetPamTree(TFile *f, TString detlist) {  TTree *PamLevel2::GetPamTree(TFile *f, TString detlist) {
2864    
# Line 1876  TTree *PamLevel2::GetPamTree(TFile *f, T Line 2938  TTree *PamLevel2::GetPamTree(TFile *f, T
2938      if (!Trout)      if (!Trout)
2939        Trout = T;        Trout = T;
2940      else      else
2941        Trout->AddFriend(T);          Trout->AddFriend(T);
2942    }    }
2943    else {    else {
2944      cout << "Tracker      : missing tree" << endl;      cout << "Tracker      : missing tree" << endl;
# Line 2113  TList* PamLevel2::GetListOfLevel2Files(T Line 3175  TList* PamLevel2::GetListOfLevel2Files(T
3175          if (file.EndsWith(".root")) {          if (file.EndsWith(".root")) {
3176            TString filedir;            TString filedir;
3177            cout << ddir << endl;            cout << ddir << endl;
3178            if (ddir != "") {            if ( ddir != "" ) {
3179              filedir = ddir; // take the input dir              filedir = ddir; // take the input dir
3180            }            }
3181            else {            else {
# Line 2121  TList* PamLevel2::GetListOfLevel2Files(T Line 3183  TList* PamLevel2::GetListOfLevel2Files(T
3183              filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir              filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir
3184            };            };
3185            filedir.Append("/");            filedir.Append("/");
3186            char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir), gSystem->BaseName(file));            //          char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir), gSystem->BaseName(file));
3187              char *fullpath = gSystem->ConcatFileName(filedir.Data(), gSystem->BaseName(file));
3188            contents->Add(new TSystemFile(fullpath, gSystem->DirName(fullpath)));// add file to the list            contents->Add(new TSystemFile(fullpath, gSystem->DirName(fullpath)));// add file to the list
3189            cout << fullpath << endl;            cout << fullpath << endl;
3190            delete fullpath;            delete fullpath;
# Line 2288  TChain *PamLevel2::GetPamTree(TList *fl, Line 3351  TChain *PamLevel2::GetPamTree(TList *fl,
3351          G->Add(name);          G->Add(name);
3352        if (SELLI == 1)        if (SELLI == 1)
3353          L->Add(name);          L->Add(name);
3354      };       };
3355    };    };
3356    
3357    cout << "done chains\n";    cout << "done data-tree chains  "<<  T->GetNtrees() <<" \n";
3358    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;    cout << "----------------------------------------------------" << endl;
3359    
3360    // -------------------------------------------    // -------------------------------------------
3361    // make friends    // make friends
# Line 2375  TChain *PamLevel2::GetPamTree(TList *fl, Line 3438  TChain *PamLevel2::GetPamTree(TList *fl,
3438    //  =====================================    //  =====================================
3439    //  SET BRANCH-ADDRESS AFTER CHAIN+FRIEND    //  SET BRANCH-ADDRESS AFTER CHAIN+FRIEND
3440    //  =====================================    //  =====================================
3441    SetBranchAddress(Trout);    if( Trout->GetNtrees() )SetBranchAddress(Trout);
3442    
3443    //  ------------------------------------    //  ------------------------------------
3444    //  finally handle selection trees...    //  finally handle selection trees...
3445    //  (it is not friend of pamela tree)    //  (it is not friend of pamela tree)
3446    //  ------------------------------------    //  ------------------------------------
3447    
3448    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;    cout << "----------------------------------------------------" << endl;
3449    
3450    // Selection List    // Selection List
3451    if (L && SELLI == 1) {    if (L && SELLI == 1) {
# Line 2392  TChain *PamLevel2::GetPamTree(TList *fl, Line 3455  TChain *PamLevel2::GetPamTree(TList *fl,
3455      cout << "SelectionList: set branch address RunEntry" << endl;      cout << "SelectionList: set branch address RunEntry" << endl;
3456      L->SetBranchAddress("EventEntry", &irunentry);      L->SetBranchAddress("EventEntry", &irunentry);
3457      cout << "SelectionList: set branch address EventEntry" << endl;      cout << "SelectionList: set branch address EventEntry" << endl;
3458        /*    if ( L->GetBranch("L0EventEntry") ){
3459          hasL0EE = true;
3460          L->SetBranchAddress("L0EventEntry", &il0entry);
3461          cout << "SelectionList: set branch address L0EventEntry" << endl;
3462        } else {
3463          hasL0EE = false; // backward compatibility with old preselected files...
3464          }*/
3465      sel_tree = L;      sel_tree = L;
3466      //          if(!Trout)Trout=O;      //          if(!Trout)Trout=O;
3467      //          else Trout->AddFriend("SelectionList");      //          else Trout->AddFriend("SelectionList");
3468      cout << "+SelectionList" << endl;      cout << "+SelectionList" << endl;
3469      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;      cout << "----------------------------------------------------" << endl;
3470    }    }
3471    else {    else {
3472      //  cout << "SelectionList  : missing tree"<<endl;      //  cout << "SelectionList  : missing tree"<<endl;
# Line 2422  TChain *PamLevel2::GetPamTree(TList *fl, Line 3492  TChain *PamLevel2::GetPamTree(TList *fl,
3492   */   */
3493  void PamLevel2::SetBranchAddress(TTree *t) {  void PamLevel2::SetBranchAddress(TTree *t) {
3494    
3495    TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");  //   TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
3496    TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");  //   TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
3497    TRKh = TRKh & t->GetBranchStatus("TrkHough");  //   TRKh = TRKh & t->GetBranchStatus("TrkHough");
3498    CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");  //   CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
3499    CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");  //   CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
3500    TOF = TOF & t->GetBranchStatus("ToFLevel2");  //   TOF = TOF & t->GetBranchStatus("ToFLevel2");
3501    TRG = TRG & t->GetBranchStatus("TrigLevel2");  //   TRG = TRG & t->GetBranchStatus("TrigLevel2");
3502    S4 = S4 & t->GetBranchStatus("S4Level2");  //   S4 = S4 & t->GetBranchStatus("S4Level2");
3503    ND = ND & t->GetBranchStatus("NDLevel2");  //   ND = ND & t->GetBranchStatus("NDLevel2");
3504    AC = AC & t->GetBranchStatus("AcLevel2");  //   AC = AC & t->GetBranchStatus("AcLevel2");
3505    ORB = ORB & t->GetBranchStatus("OrbitalInfo");  //   ORB = ORB & t->GetBranchStatus("OrbitalInfo");
3506    GP = GP & t->GetBranchStatus("h20");  //   GP = GP & t->GetBranchStatus("h20");
3507    
3508    
3509    // Tracker    // Tracker
3510    if (TRK1) {    if (TRK1) {
# Line 2443  void PamLevel2::SetBranchAddress(TTree * Line 3514  void PamLevel2::SetBranchAddress(TTree *
3514    if (TRK2) {    if (TRK2) {
3515      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));
3516      cout << "Tracker      : set branch address TrkLevel2" << endl;      cout << "Tracker      : set branch address TrkLevel2" << endl;
3517        NUC = t->GetBranchStatus("TrackNuclei");
3518        EXT = t->GetBranchStatus("RecoveredTrack") && (NUC ? t->GetBranchStatus("RecoveredTrackNuclei"): true );    
3519    };    };
3520    if (TRKh) {    if (TRKh) {
3521      t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));      t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
# Line 2503  void PamLevel2::SetBranchAddress(TTree * Line 3576  void PamLevel2::SetBranchAddress(TTree *
3576    
3577      cout << "h20          : set branch address GPamela " << endl;      cout << "h20          : set branch address GPamela " << endl;
3578    };    };
3579      if(NUC){
3580          
3581          cout << "Found nuclei-track branches" << endl;
3582    
3583          if( !trk_nuc_obj )trk_nuc_obj = new TClonesArray("TrkTrack");
3584          if( !calo_nuc_obj)calo_nuc_obj= new TClonesArray("CaloTrkVar");
3585          if( !tof_nuc_obj)tof_nuc_obj= new TClonesArray("ToFTrkVar");
3586          if( !orb_nuc_obj)orb_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3587          if (TRK2)t->                          SetBranchAddress("TrackNuclei",&trk_nuc_obj);
3588          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("TrackNuclei",&calo_nuc_obj);
3589          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("TrackNuclei",&tof_nuc_obj);
3590          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("TrackNuclei",&orb_nuc_obj);
3591    
3592          ///copy the vector content inside a "fake" object (all aother info are missing)    
3593    
3594          if( !trk2_nuc_obj )trk2_nuc_obj =  new TrkLevel2();
3595          if( !calo2_nuc_obj )calo2_nuc_obj =  new CaloLevel2();
3596          if( !tof2_nuc_obj )tof2_nuc_obj =  new ToFLevel2();
3597          if( !orb2_nuc_obj )orb2_nuc_obj =  new OrbitalInfo();
3598    //       *(trk2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*trk_nuc_obj);
3599    //       *(calo2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*calo_nuc_obj);
3600    //       *(tof2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*tof_nuc_obj);
3601    //       *(orb2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*orb_nuc_obj);
3602    
3603          trk2_nuc_obj->SetTrackArray(  trk_nuc_obj  );
3604          calo2_nuc_obj->SetTrackArray( calo_nuc_obj );
3605          tof2_nuc_obj->SetTrackArray(  tof_nuc_obj  );
3606          orb2_nuc_obj->SetTrackArray(  orb_nuc_obj  );
3607    
3608          
3609      }    
3610    
3611      if(EXT){
3612          
3613          cout << "Found extended tracking algorythm branches" << endl;
3614    
3615          if( !trk_ext_obj )trk_ext_obj = new TClonesArray("ExtTrack");
3616          if( !calo_ext_obj)calo_ext_obj= new TClonesArray("CaloTrkVar");
3617          if( !tof_ext_obj)tof_ext_obj= new TClonesArray("ToFTrkVar");
3618          if( !orb_ext_obj)orb_ext_obj= new TClonesArray("OrbitalInfoTrkVar");
3619          
3620          if (TRK2)t->                          SetBranchAddress("RecoveredTrack",&trk_ext_obj);
3621          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrack",&calo_ext_obj);
3622          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrack",&tof_ext_obj);
3623          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrack",&orb_ext_obj);
3624    
3625        
3626          if(NUC){
3627              if( !trk_ext_nuc_obj )trk_ext_nuc_obj = new TClonesArray("ExtTrack");
3628              if( !calo_ext_nuc_obj)calo_ext_nuc_obj= new TClonesArray("CaloTrkVar");
3629              if( !tof_ext_nuc_obj)tof_ext_nuc_obj= new TClonesArray("ToFTrkVar");
3630              if( !orb_ext_nuc_obj)orb_ext_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3631              if (TRK2)t->                          SetBranchAddress("RecoveredTrackNuclei",&trk_ext_nuc_obj);
3632              if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrackNuclei",&calo_ext_nuc_obj);
3633              if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrackNuclei",&tof_ext_nuc_obj);
3634              if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrackNuclei",&orb_ext_nuc_obj);
3635          }
3636      }    
3637  }  }
3638  /**  /**
3639   * Set branch addresses for Pamela friend trees   * Set branch addresses for Pamela friend trees
# Line 2527  void PamLevel2::SetBranchAddress(TChain Line 3657  void PamLevel2::SetBranchAddress(TChain
3657    if (TRK2) {    if (TRK2) {
3658      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
3659      cout << "Tracker      : set branch address TrkLevel2" << endl;      cout << "Tracker      : set branch address TrkLevel2" << endl;
3660        NUC = t->GetBranchStatus("TrackNuclei");
3661        EXT = t->GetBranchStatus("RecoveredTrack") && (NUC ? t->GetBranchStatus("RecoveredTrackNuclei"): true );
3662    };    };
3663    if (TRK1) {    if (TRK1) {
3664      t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));      t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
# Line 2540  void PamLevel2::SetBranchAddress(TChain Line 3672  void PamLevel2::SetBranchAddress(TChain
3672    // Calorimeter    // Calorimeter
3673    if (CAL2) {    if (CAL2) {
3674      t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));      t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
3675      cout << "Calorimeter  : set branch address CaloLevel2" << endl;      cout << "Calorimeter  : set branch address CaloLevel2" << endl;    
3676    };    };
3677    if (CAL1) {    if (CAL1) {
3678      t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));      t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
# Line 2598  void PamLevel2::SetBranchAddress(TChain Line 3730  void PamLevel2::SetBranchAddress(TChain
3730    //    cout << "SelectionList: set branch address EventEntry"<<endl;    //    cout << "SelectionList: set branch address EventEntry"<<endl;
3731    
3732    //     }    //     }
3733      if(NUC){
3734          
3735          cout << "Found nuclei-track branches" << endl;
3736    
3737          if( !trk_nuc_obj )trk_nuc_obj = new TClonesArray("TrkTrack");
3738          if( !calo_nuc_obj)calo_nuc_obj= new TClonesArray("CaloTrkVar");
3739          if( !tof_nuc_obj)tof_nuc_obj= new TClonesArray("ToFTrkVar");
3740          if( !orb_nuc_obj)orb_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3741          if (TRK2)t->                          SetBranchAddress("TrackNuclei",&trk_nuc_obj);
3742          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("TrackNuclei",&calo_nuc_obj);
3743          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("TrackNuclei",&tof_nuc_obj);
3744          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("TrackNuclei",&orb_nuc_obj);
3745          
3746          ///copy the vector content inside a "fake" object (all aother info are missing)    
3747    
3748          if( !trk2_nuc_obj )trk2_nuc_obj =  new TrkLevel2();
3749          if( !calo2_nuc_obj )calo2_nuc_obj =  new CaloLevel2();
3750          if( !tof2_nuc_obj )tof2_nuc_obj =  new ToFLevel2();
3751          if( !orb2_nuc_obj )orb2_nuc_obj =  new OrbitalInfo();
3752    
3753    //       *(trk2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*trk_nuc_obj);
3754    //       *(calo2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*calo_nuc_obj);
3755    //       *(tof2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*tof_nuc_obj);
3756    //       *(orb2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*orb_nuc_obj);
3757          trk2_nuc_obj->SetTrackArray(  trk_nuc_obj  );
3758          calo2_nuc_obj->SetTrackArray( calo_nuc_obj );
3759          tof2_nuc_obj->SetTrackArray(  tof_nuc_obj  );
3760          orb2_nuc_obj->SetTrackArray(  orb_nuc_obj  );
3761    
3762      }    
3763      if(EXT){
3764          
3765          cout << "Found extended tracking algorythm branches" << endl;
3766    
3767          t->SetBranchAddress("extAlgFlag",&extAlgFlag);
3768    
3769          if( !trk_ext_obj )trk_ext_obj = new TClonesArray("ExtTrack");
3770          if( !calo_ext_obj)calo_ext_obj= new TClonesArray("CaloTrkVar");
3771          if( !tof_ext_obj)tof_ext_obj= new TClonesArray("ToFTrkVar");
3772          if( !orb_ext_obj)orb_ext_obj= new TClonesArray("OrbitalInfoTrkVar");
3773          
3774          if (TRK2)t->                          SetBranchAddress("RecoveredTrack",&trk_ext_obj);
3775          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrack",&calo_ext_obj);
3776          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrack",&tof_ext_obj);
3777          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrack",&orb_ext_obj);
3778          
3779          if(NUC){
3780              if( !trk_ext_nuc_obj )trk_ext_nuc_obj = new TClonesArray("ExtTrack");
3781              if( !calo_ext_nuc_obj)calo_ext_nuc_obj= new TClonesArray("CaloTrkVar");
3782              if( !tof_ext_nuc_obj)tof_ext_nuc_obj= new TClonesArray("ToFTrkVar");
3783              if( !orb_ext_nuc_obj)orb_ext_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3784              if (TRK2)t->                          SetBranchAddress("RecoveredTrackNuclei",&trk_ext_nuc_obj);
3785              if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrackNuclei",&calo_ext_nuc_obj);
3786              if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrackNuclei",&tof_ext_nuc_obj);
3787              if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrackNuclei",&orb_ext_nuc_obj);
3788          }
3789      }    
3790      
3791  }  }
3792    
3793    /**
3794     * Set the tracking algorythm
3795     * @param alg String to choose the track.
3796     * "" --> take the output of the standard tracking algorythm
3797     * "STD" --> take the output of the standard tracking algorythm
3798     * "NUC" --> take the output of the standard tracking algorythm for nuclei cluster selection
3799     * "EXT" --> in case the standard tracking algorythm has not found any track, take the output of the extended one
3800     * "EXTF" --> force the extended tracking algorythm
3801     * "NUCEXT" --> as "EXT", but for nuclei
3802     * "NUCEXTF" --> as "EXTF", but for nuclei
3803     */
3804    // void PamLevel2::SetTrackingAlgorythm(const char *alg){
3805    
3806    
3807    //     TString s(alg);
3808    //     if(s.Contains("NUC", TString::kIgnoreCase) && !NUC)
3809    //      cout << "Warning! NUC algorythm requested, but branches are missing"<<endl;
3810    //     if(s.Contains("EXT", TString::kIgnoreCase) && !EXT)
3811    //      cout << "Warning! EXT algorythm requested, but branches are missing"<<endl;;
3812                
3813    //     trkAlg = alg;
3814    
3815    // };
3816    // const char* PamLevel2::GetTrackingAlgorythm(){
3817    
3818    
3819    //     cout<<endl<<" Implemented tracking algorythm: ";
3820    //     cout<<endl<<"  \"\" or \"STD\"  --> take the output of the standard tracking algorythm";
3821    //     cout<<endl<<"  \"NUC\"      --> take the output of the standard tracking algorythm for nuclei cluster selection";
3822    //     cout<<endl<<"  \"EXT\"      --> in case the standard tracking algorythm has not found any track,";
3823    //     cout<<endl<<"                 take the output of the extended one";
3824    //     cout<<endl<<"  \"EXTF\"     --> force the extended tracking algorythm";
3825    //     cout<<endl<<"  \"NUCEXT\"   --> as \"EXT\", but for nuclei ";
3826    //     cout<<endl<<"  \"NUCEXTF\"  --> as \"EXTF\", but for nuclei";
3827    
3828    //     cout<<endl;
3829    //     cout<<" <<Currently set algorythm>> "<<trkAlg<<endl;
3830    //     cout<<endl;
3831    
3832    //     return trkAlg;
3833    // };
3834    
3835    
3836    
3837  //--------------------------------------  //--------------------------------------
3838  //  //
3839  //  //
# Line 2634  TChain *PamLevel2::GetRunTree(TList *fl) Line 3867  TChain *PamLevel2::GetRunTree(TList *fl)
3867      };      };
3868    }    }
3869    
3870      cout << "done run chain  "<<  R->GetNtrees() <<" \n";
3871    
3872    
3873    if (RUN && R->GetNtrees()) {    if (RUN && R->GetNtrees()) {
3874    
3875      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
# Line 2673  TChain *PamLevel2::GetRunTree(TList *fl) Line 3909  TChain *PamLevel2::GetRunTree(TList *fl)
3909      cout << "----------------------------------------------------" << endl;      cout << "----------------------------------------------------" << endl;
3910    
3911    }    }
3912    else {  //   else {
3913      delete R;  //     delete R;
3914      R = 0;  //     R = 0;
3915    }  //   }
3916    
3917    run_tree = R;    run_tree = R;
3918    
# Line 2715  TTree *PamLevel2::GetRunTree(TFile *f) { Line 3951  TTree *PamLevel2::GetRunTree(TFile *f) {
3951    return T;    return T;
3952    
3953  }  }
 /**  
  * 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;  
   //  
 }  
 ;  
3954    
3955  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) {  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) {
3956    
3957      if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - inside\n");
3958    
3959    if (!run_tree) {    if (!run_tree) {
3960      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;
3961      return false;      return false;
# Line 2865  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 3965  Bool_t PamLevel2::UpdateRunInfo(Long64_t
3965      return (false);      return (false);
3966    }    }
3967    
3968    
3969    Int_t oldrun = irun; // store current run index    Int_t oldrun = irun; // store current run index
3970    
3971    // -----------------------------------------------------------------------    // -----------------------------------------------------------------------
# Line 2874  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 3975  Bool_t PamLevel2::UpdateRunInfo(Long64_t
3975    if (irun < 0) {    if (irun < 0) {
3976      irun = 0LL;      irun = 0LL;
3977      irunt = 0LL;      irunt = 0LL;
3978      irunentry = 0;      totrunentry = 0LL;
3979        totrunentrymin = 0LL;
3980        totrunentrymax = 0LL;
3981        irunentry = 0LL;
3982        il0entry = 0LL;
3983      prevshift = 0;      prevshift = 0;
3984        yprevshift = 0;
3985        prevabstime = 0;
3986        prevpktnum = 0;
3987        abstime = 0ULL;
3988        pktnum = 0;
3989        isFragment = false;
3990      run_tree->GetEntry(irun);      run_tree->GetEntry(irun);
3991      if (!GetOrbitalInfo())      if (!GetOrbitalInfo())
3992        cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated " << endl;        cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated " << endl;
3993      if (gltsync)      if ( fUseDBinRunInfo ){
3994        delete gltsync; //Emiliano        if (gltsync)
3995      if (!dbc || (dbc && !dbc->IsConnected()))          delete gltsync; //Emiliano
3996        SetDBConnection(); //Emiliano        if (!dbc || (dbc && !dbc->IsConnected()))
3997      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
3998      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)
3999        dbc->Close();// Emiliano        if (dbc){
4000        dbc=0;          dbc->Close();// Emiliano
4001      };          delete dbc;
4002    };          dbc=0;
4003          }
4004        }
4005      }
4006    // ---------------------------------------------------------------    // ---------------------------------------------------------------
4007    // retrieve OBT and absolute time of the event    // retrieve OBT and absolute time of the event
4008    // ---------------------------------------------------------------    // ---------------------------------------------------------------
   ULong64_t abstime = 0LL;  
   //    ULong64_t obt     = 0LL; // Emiliano  
4009    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
4010      prevabstime = abstime;
4011      prevpktnum = pktnum;
4012    if (GetOrbitalInfo()) {    if (GetOrbitalInfo()) {
4013      abstime = GetOrbitalInfo()->absTime;      abstime = GetOrbitalInfo()->absTime;
4014      obt = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano      if ( fUseDBinRunInfo ) obt = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano
4015        pktnum = GetOrbitalInfo()->pkt_num; // Emiliano
4016    }    }
4017    else {    else {
4018      abstime = GetRunInfo()->RUNHEADER_TIME;      abstime = GetRunInfo()->RUNHEADER_TIME;
4019      obt = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano      if ( fUseDBinRunInfo ) obt = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano
4020        pktnum = GetRunInfo()->RUNHEADER_PKT; // Emiliano
4021      }
4022    
4023      if (DBG){
4024        printf("0abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4025        printf("0        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4026        printf("0        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4027        if ( fUseDBinRunInfo ) printf("0        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4028        printf("0        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4029        printf("0        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);
4030    }    }
4031    
4032    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# Line 2922  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4047  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4047      }      }
4048    
4049      //      //
4050      bool fromfirst = true; // first loop over runs      bool a = true;
4051        bool b = true;
4052        if ( fUseDBinRunInfo ){
4053          a = false;    
4054          b = false;
4055          if ( obt < gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) ) a = true;
4056          if ( obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ) b = true;
4057        }
4058        if ( iev < totrunentrymin || iev > totrunentrymax // entry is outside run limits
4059             || iev == 0 // or it is the first entry
4060             || (!isSync && (
4061                             (abstime <= GetRunInfo()->RUNHEADER_TIME && a ) // or it is outside obt limits (and abstime limits for security reasons)
4062                             || (abstime >= GetRunInfo()->RUNTRAILER_TIME && b ) ))// or it is outside obt limits (and abstime limits for security reasons)
4063             ){ // check on abstime and obt needed to handle nested+DV_skipped packets
4064          
4065          // check for a new run (ma prima il primo!)
4066          if (DBG){
4067            printf("1abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4068            printf("1        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4069            printf("1        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4070            if ( fUseDBinRunInfo ) printf("1        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4071            printf("1        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4072            printf("1        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);
4073          }
4074          //        printf("1abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4075          //        printf("1        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4076          //        printf("1        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4077          //        printf("1        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4078          //        printf("1        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4079          //        printf("1        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);//TOGLITOGLI
4080    
4081      // ------------------------------------------------------        totrunentry = 0LL;
4082      // loop over runs to find the one that contains the event        runfirstentry = 0LL;
4083      // ------------------------------------------------------        for (Int_t r=0; r< run_tree->GetEntries();r++){
4084      while ((          // -------------------------------------------------------------------
4085      //          (          // save the index of the first entry of the run, relative to pam_tree,
4086      //              !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)          // and read a new run
4087      //                abstime <= GetRunInfo()->RUNTRAILER_TIME) &&          // -------------------------------------------------------------------
4088      //              !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)          run_tree->GetEntry(r);//update runinfo
4089      //                obt <= GetRunInfo()->RUNTRAILER_OBT)          if ( r > 0 ){
4090      //              )            totrunentrymin = totrunentrymax+1;
4091            } else {
4092      !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s)            totrunentrymin = 0LL;
4093          abstime <= GetRunInfo()->RUNTRAILER_TIME) || !(obt >= gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) && // additional check on OBT (ms) // Emiliano          }
4094          obt <= gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) // Emiliano          totrunentry += GetRunInfo()->NEVENTS;
4095          || GetRunInfo()->NEVENTS == 0          totrunentrymax = totrunentry - 1 - prevshift; // prevshift is needed to handle nested+DV_skipped packets
4096      //          || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento          irun = r;        
4097          || !(irunentry <= GetRunInfo()->NEVENTS - 1 - prevshift)) && irun < run_tree->GetEntries()) {          if ( fUseDBinRunInfo ){
4098              a = false;    
4099        //            if( !(abstime >= GetRunInfo()->RUNHEADER_TIME &&abstime <= GetRunInfo()->RUNTRAILER_TIME)  )cout << "ABS TIME "<<abstime << " " <<GetRunInfo()->RUNTRAILER_TIME <<endl;            b = false;
4100        //            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;
4101        //            if( GetRunInfo()->NEVENTS==0  )cout <<"GetRunInfo()->NEVENTS==0 "<<endl;            if ( obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ) b = true;
4102        //            if( !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift) ) cout << "irunentry > "<<GetRunInfo()->NEVENTS-1-prevshift << endl;          }
4103        // - - - - - - - - - - - - -          if ( (iev >= totrunentrymin && iev <= totrunentrymax) || // entry is inside run limits
4104        // irunentry = position of current entry, relative to the run               ( !isSync &&
4105        // 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)
4106        // - - - - - - - - - - - - -                   && abstime <= GetRunInfo()->RUNTRAILER_TIME && b))  // or it is inside obt limits (and abstime limits for security reasons)
4107                 ){ // check on abstime and obt needed to handle nested+DV_skipped packets
4108        // -----------------------------------------            if ( totrunentrymin > iev ){ // there is a shift (nested+DV_skipped packets)
4109        // store dead and live-time of previous run              if ( !isSync ){
4110        // -----------------------------------------                if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - unconsistent iev - nevents, probable DBL0-L2 async\n");
4111        //            if(SELLI==0){                if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);
4112        if (SELLI != 2) {                //              printf("PamLevel2::UpdateRunInfo(Long64_t) - unconsistent iev - nevents, probable DBL0-L2 async\n");
4113          if (fromfirst) {                //              printf("PamLevel2::UpdateRunInfo(Long64_t) - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI
4114            if (oldrun == irun) {                prevshift += (totrunentrymin-iev); // add the new shift to total shift
4115              /// decrement counters                totrunentrymin -= (totrunentrymin-iev); // shift run position min
4116              if (GetTrigLevel2()) {                totrunentrymax -= (totrunentrymin-iev); // shift run position max
4117                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);
4118                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
4119              }              } else {
4120              totdltime[2]--; //event counter                printf(" PamLevel2::UpdateRunInfo(Long64_t) ERROR! sync file but unconsistent totrunetrymin %lld and iev %lld!!! \n",totrunentrymin,iev);
4121              if (DBG) {                cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
4122                cout << endl;                cout << "\nFor bug reporting instructions, please see for example:\n";
4123                cout << "n.events     : " << totdltime[2] << endl;                cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
4124                cout << "RUN LIVE-TIME: " << totdltime[0] * 0.16 << " ms" << endl;                cout << "  " << endl;
               cout << "RUN DEAD-TIME: " << totdltime[1] * 0.01 << " ms" << endl;  
4125              }              }
4126            }            }
4127            else {            runfirstentry = totrunentrymin; // first entry of the run in the level2
4128              totdltime[0] = 0;//live-time            
4129              totdltime[1] = 0;//dead-time  
4130              totdltime[2] = 0; //event counter            //
4131              if (DBG)            if ( fUseDBinRunInfo ){
4132                cout << " *** JUMP RUN *** irun " << irun << endl;              if (gltsync)
4133                  delete gltsync; // Emiliano
4134                if (!dbc || (dbc && !dbc->IsConnected()))
4135                  SetDBConnection(); //Emiliano
4136                gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano
4137                TrkParams::Set(GetRunInfo(), dbc);
4138                if (dbc){
4139                  dbc->Close(); // Emiliano
4140                  delete dbc;
4141                  dbc=0;
4142                }          
4143                if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano
4144                  cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun
4145                       << "  has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl;
4146                  cout
4147                    << "                                                            (NB!! in this case some events could be assigned to a wrong run)"
4148                    << endl;
4149                }
4150            }            }
4151            /// add an entry            //
4152            if (run_tree_clone)            if (DBG) printf(" found \n");
4153              if (run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())            //          printf(" found \n");//TOGLITOGLI
4154                run_tree_clone->GetBranch("DeadLiveTime")->Fill();            //
4155            /// reset counters            break;
4156            }
4157          } // loop over run
4158          
4159          // --------------------------------------
4160          // if there was no need to update the run
4161          // ---> exit with FALSE
4162          // --------------------------------------
4163          if (irun == oldrun){
4164            if (DBG) printf(" no new run \n");
4165            //        printf(" no new run \n");//TOGLITOGLI
4166            return (false);
4167          }      
4168          // --------------------------------------
4169          // ... otherwise
4170          // ---> exit with TRUE
4171          // --------------------------------------
4172    
4173          if (SELLI != 2) {
4174            /// decrement counters since this event belongs to a new run
4175            if (GetTrigLevel2()) {
4176              totdltime[0] -= GetTrigLevel2()->dltime[0];//live-time
4177              totdltime[1] -= GetTrigLevel2()->dltime[1];//dead-time
4178            }
4179            totdltime[2]--; //event counter
4180            if (DBG) {
4181              cout << endl;
4182              cout << "n.events     : " << totdltime[2] << endl;
4183              cout << "RUN LIVE-TIME: " << totdltime[0] * 0.16 << " ms" << endl;
4184              cout << "RUN DEAD-TIME: " << totdltime[1] * 0.01 << " ms" << endl;
4185            }
4186            // add an entry
4187            if (run_tree_clone && totdltime[2] > 0)
4188              if (run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
4189                run_tree_clone->GetBranch("DeadLiveTime")->Fill();
4190            // reset counters
4191            if ( totdltime[2] > 0 ){
4192            if (GetTrigLevel2()) {            if (GetTrigLevel2()) {
4193              totdltime[0] = GetTrigLevel2()->dltime[0];//live-time              totdltime[0] = GetTrigLevel2()->dltime[0];//live-time
4194              totdltime[1] = 0; //dead-time              totdltime[1] = 0; //dead-time
# Line 2991  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4196  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4196            totdltime[2] = 1; //event counter            totdltime[2] = 1; //event counter
4197          }          }
4198        }        }
       //            }  
4199    
4200        irun++;        if (DBG){
4201        // ------------------------------------          cout << endl << " ))))) UPDATE RUN INFO (((((  @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun
4202        // if the end of run tree is reached...               << endl;        
4203        // ------------------------------------          printf("2abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4204        if (irun == run_tree->GetEntries()) {          printf("2        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4205          if (!fromfirst) {          printf("2        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4206            // -----------------------------------------------------          if ( fUseDBinRunInfo ) printf("2        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4207            // if it happened already once and the run was not found          printf("2        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4208            // ---> 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;  
4209        }        }
4210        // -------------------------------------------------------------------        //        printf("2abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4211        // 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);
4212        // and read a new run        //        printf("2        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4213        // -------------------------------------------------------------------        //        printf("2        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4214        if (irun > 0)        //        printf("2        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4215          runfirstentry += (GetRunInfo()->NEVENTS) - prevshift;        //        printf("2        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);//TOGLITOGLI
4216        irunentry = 0;  
4217        prevshift = 0;        return (true);
4218        run_tree->GetEntry(irun);//update runinfo      } // need for run upgrade
4219        irunt = irun - irunoffset[run_tree->GetTreeNumber()];      if (DBG) printf("return false\n");
4220        if (gltsync)      return (false);
4221          delete gltsync; // Emiliano    }// SELLI = 0 SELLI = 2
4222        if (!dbc || (dbc && !dbc->IsConnected()))    
         SetDBConnection(); //Emiliano  
       gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano  
       if (dbc){  
         dbc->Close(); // Emiliano  
         dbc=0;  
       };  
       if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano  
         cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun  
             << "  has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl;  
         cout  
             << "                                                            (NB!! in this case some events are assigned to a wrong run)"  
             << endl;  
       }  
       //            if(hasfrag &&  fragid != GetRunInfo()->ID){  
       //                cout << "... where is the next fragment ??"<<endl;  
       //            }  
     };  
   
     // --------------------------------------  
     // if there was no need to update the run  
     // ---> exit with FALSE  
     // --------------------------------------  
     if (irun == oldrun)  
       return (false);  
   
     // --------------------------------------  
     // ... otherwise  
     // --------------------------------------  
   
   
     // --------------------------------------  
     // ---> exit with TRUE  
     // --------------------------------------  
     if (DBG)  
       cout << endl << " ))))) UPDATE RUN INFO (((((  @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun  
           << endl;  
     // ----------------------------------------------------  
     // update the tracker parameters  
     // (non ho trovato nessun altro modo sicuro di farlo...)  
     // ----------------------------------------------------  
     if (!dbc || (dbc && !dbc->IsConnected()))  
       SetDBConnection();  
     TrkParams::Set(GetRunInfo(), dbc);  
     if (dbc){  
       dbc->Close();  
       dbc=0;  
     };  
   
     // ----------------------------------------------------  
     // then check if the run has a fragment  
     // in this case we have to switch to the next fragment  
     // when the end of the first fragment is reached  
     // ----------------------------------------------------  
     if (GetRunInfo()->ID_RUN_FRAG != 0 &&  
     //      GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&  
         DBG && true) {  
       cout << "* fragment *" << endl;  
     }  
   
     return (true);  
   };  
4223    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
4224    // if it is a preselected file (there is SelectionList)    // if it is a preselected file (there is SelectionList)
4225    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# Line 3165  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4294  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4294        // update the tracker parameters        // update the tracker parameters
4295        // (non ho trovato nessun altro modo sicuro di farlo...)        // (non ho trovato nessun altro modo sicuro di farlo...)
4296        // ----------------------------------------------------        // ----------------------------------------------------
4297        if (!dbc || (dbc && !dbc->IsConnected()))        if ( fUseDBinRunInfo ){
4298          SetDBConnection();          if (!dbc || (dbc && !dbc->IsConnected()))
4299        TrkParams::Set(GetRunInfo(), dbc);            SetDBConnection();
4300        if (dbc){          TrkParams::Set(GetRunInfo(), dbc);
4301          dbc->Close();          if (dbc){
4302          dbc=0;            dbc->Close();
4303        };            delete dbc;
4304              dbc=0;
4305            }
4306          }
4307        //            cout << endl;        //            cout << endl;
4308        prevshift = 0;        prevshift = 0;
4309          yprevshift = 0;
4310        return true;        return true;
4311      }      }
4312      return false;      return false;
# Line 3182  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4315  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4315    return false;    return false;
4316    //    //
4317  }  }
4318  ;  
4319    /**
4320     * Update the runinfo informations (to be used to have Run infos event by event basis)
4321     * @param run Pointer to the chain/tree which contains run infos
4322     * @return true if a new run has been read, false if it is still the same run
4323     */
4324    Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) {
4325      return (UpdateRunInfo(iev));
4326    }
4327    
4328  /**  /**
4329   * 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)
4330   * @param run Pointer to the chain/tree which contains run infos   * @param run Pointer to the chain/tree which contains run infos
# Line 3191  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4333  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4333  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev) {  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev) {
4334    return (UpdateRunInfo((TChain*) run, iev));    return (UpdateRunInfo((TChain*) run, iev));
4335  }  }
4336  ;  
4337    
4338  //--------------------------------------  //--------------------------------------
4339  //  //
# Line 4022  void PamLevel2::CreateCloneTrees(TFile * Line 5164  void PamLevel2::CreateCloneTrees(TFile *
5164      //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");      //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
5165      sel_tree_clone->Branch("RunEntry", &irunt, "runentry/L");//NEWNEW      sel_tree_clone->Branch("RunEntry", &irunt, "runentry/L");//NEWNEW
5166      sel_tree_clone->Branch("EventEntry", &irunentry, "eventry/L");      sel_tree_clone->Branch("EventEntry", &irunentry, "eventry/L");
5167        //    if ( hasL0EE ) sel_tree_clone->Branch("L0EventEntry", &il0entry, "l0eventry/L");
5168    };    };
5169    
5170    Int_t i = 0;    Int_t i = 0;
# Line 4041  void PamLevel2::CreateCloneTrees(TFile * Line 5184  void PamLevel2::CreateCloneTrees(TFile *
5184        pam_tree_clone[i]->Branch("TrkHough", "TrkHough", GetPointerTo("TrkHough"));        pam_tree_clone[i]->Branch("TrkHough", "TrkHough", GetPointerTo("TrkHough"));
5185        cout << "Tracker      : branch TrkHough" << endl;        cout << "Tracker      : branch TrkHough" << endl;
5186      };      };
5187        if(NUC){
5188            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&trk_nuc_obj);
5189            cout << "Tracker      : branch TrackNuclei" << endl;    
5190        }
5191        if(EXT){
5192            pam_tree_clone[i]->Branch("extAlgFlag",&extAlgFlag,"extAlgFlag/I");
5193            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&trk_ext_obj);
5194            cout << "Tracker      : branch RecoveredTrack" << endl;
5195            if(NUC){
5196                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&trk_ext_nuc_obj);
5197                cout << "Tracker      : branch RecoveredTrackNuclei" << endl;                  
5198            }
5199        }
5200    
5201      i++;      i++;
5202    }    }
5203    
# Line 4055  void PamLevel2::CreateCloneTrees(TFile * Line 5212  void PamLevel2::CreateCloneTrees(TFile *
5212        pam_tree_clone[i]->Branch("CaloLevel2", "CaloLevel2", GetPointerTo("CaloLevel2"));        pam_tree_clone[i]->Branch("CaloLevel2", "CaloLevel2", GetPointerTo("CaloLevel2"));
5213        cout << "Calorimeter  : branch CaloLevel2" << endl;        cout << "Calorimeter  : branch CaloLevel2" << endl;
5214      };      };
5215        if(NUC){
5216            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&calo_nuc_obj);
5217            cout << "Calorimeter  : branch TrackNuclei" << endl;    
5218        }
5219        if(EXT){
5220            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&calo_ext_obj);
5221            cout << "Calorimeter  : branch RecoveredTrack" << endl;
5222            if(NUC){
5223                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&calo_ext_nuc_obj);
5224                cout << "Calorimeter  : branch RecoveredTrackNuclei" << endl;                  
5225            }
5226        }
5227      i++;      i++;
5228    }    }
5229    
# Line 4063  void PamLevel2::CreateCloneTrees(TFile * Line 5232  void PamLevel2::CreateCloneTrees(TFile *
5232      pam_tree_clone[i] = new TTree("ToF", "PAMELA ToF level2 data ");      pam_tree_clone[i] = new TTree("ToF", "PAMELA ToF level2 data ");
5233      pam_tree_clone[i]->Branch("ToFLevel2", "ToFLevel2", GetPointerTo("ToFLevel2"));      pam_tree_clone[i]->Branch("ToFLevel2", "ToFLevel2", GetPointerTo("ToFLevel2"));
5234      cout << "ToF          : branch ToFLevel2" << endl;      cout << "ToF          : branch ToFLevel2" << endl;
5235        if(NUC){
5236            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&tof_nuc_obj);
5237            cout << "ToF          : branch TrackNuclei" << endl;    
5238        }
5239        if(EXT){
5240            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&tof_ext_obj);
5241            cout << "ToF          : branch RecoveredTrack" << endl;
5242            if(NUC){
5243                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&tof_ext_nuc_obj);
5244                cout << "ToF          : branch RecoveredTrackNuclei" << endl;                  
5245            }
5246        }
5247      i++;      i++;
5248    };    };
5249    // Trigger    // Trigger
# Line 4098  void PamLevel2::CreateCloneTrees(TFile * Line 5279  void PamLevel2::CreateCloneTrees(TFile *
5279      pam_tree_clone[i] = new TTree("OrbitalInfo", "PAMELA orbital info  ");      pam_tree_clone[i] = new TTree("OrbitalInfo", "PAMELA orbital info  ");
5280      pam_tree_clone[i]->Branch("OrbitalInfo", "OrbitalInfo", GetPointerTo("OrbitalInfo"));      pam_tree_clone[i]->Branch("OrbitalInfo", "OrbitalInfo", GetPointerTo("OrbitalInfo"));
5281      cout << "OrbitalInfo  : branch OrbitalInfo" << endl;      cout << "OrbitalInfo  : branch OrbitalInfo" << endl;
5282        if(NUC){
5283            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&orb_nuc_obj);
5284            cout << "OrbitalInfo  : branch TrackNuclei" << endl;    
5285        }
5286        if(EXT){
5287            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&orb_ext_obj);
5288            cout << "OrbitalInfo  : branch RecoveredTrack" << endl;
5289            if(NUC){
5290                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&orb_ext_nuc_obj);
5291                cout << "OrbitalInfo  : branch RecoveredTrackNuclei" << endl;                  
5292            }
5293        }
5294      i++;      i++;
5295    };    };
5296    // GPamela    // GPamela
5297    if (GP) {    if (GP) {
5298      pam_tree_clone[i] = new TTree("h20", "GPAMELA info ");      pam_tree_clone[i] = new TTree("h20", "GPAMELA info ");
5299      pam_tree_clone[i]->Branch("GPamela", "GPamela", GetPointerTo("GPamela"), 32000, 1);//split      pam_tree_clone[i]->Branch("GPamela", "GPamela", GetPointerTo("GPamela"), 32000, 1);//split
5300      cout << "OrbitalInfo  : branch OrbitalInfo" << endl;      cout << "GPamela  : branch GPamela" << endl;
5301      i++;      i++;
5302    };    };
5303    
5304    
5305    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
5306    
5307  }  }
# Line 4177  void PamLevel2::WriteCloneTrees() { Line 5372  void PamLevel2::WriteCloneTrees() {
5372  /**  /**
5373   * 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.
5374   */   */
 //Int_t PamLevel2::GetEntry(Int_t iee){  
5375  Int_t PamLevel2::GetEntry(Long64_t iee) {  Int_t PamLevel2::GetEntry(Long64_t iee) {
5376    
   //     cout << "-------------------------------------"<<endl;  
   //     cout << "Int_t PamLevel2::GetEntry("<<iee<<")"<<endl;  
   
5377    if (!pam_tree) {    if (!pam_tree) {
5378      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;
5379      return 0;      return 0;
# Line 4196  Int_t PamLevel2::GetEntry(Long64_t iee) Line 5387  Int_t PamLevel2::GetEntry(Long64_t iee)
5387    //    return 0;    //    return 0;
5388    //    }    //    }
5389    
   Long64_t ii = 0;  
5390    //-------------------------------    //-------------------------------
5391    ii = iee;    if (!pam_tree->GetEntry(iee)) {
   if (!pam_tree->GetEntry(ii)) {  
5392      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;
5393      return 0;      return 0;
5394    }    }
# Line 4219  Int_t PamLevel2::GetEntry(Long64_t iee) Line 5408  Int_t PamLevel2::GetEntry(Long64_t iee)
5408    }    }
5409    
5410    //-------------------------------    //-------------------------------
5411    ii = iee;    //
5412    //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii);    if ( fUpdateRunInfo ) UpdateRunInfo(iee); // Emiliano
5413    //    Bool_t UPDATED = UpdateRunInfo(ii);    if (SELLI == 0 || SELLI == 2) irunentry = iee - runfirstentry;
   UpdateRunInfo(ii);  
   if (SELLI == 0 || SELLI == 2)  
     irunentry = iee - runfirstentry;  
   //    if(UPDATED && run_tree_clone)run_tree_clone->Fill();  
   
   //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;  
   
   //     cout << "irunentry     "<<irunentry << endl;  
   //     cout << "runfirstentry "<<runfirstentry << endl;  
   //     cout << "nevents       "<<GetRunInfo()->NEVENTS<< endl;  
   
   //     if( TRK0 || CAL0 || TOF0 ){  
   //    if( !GetYodaEntry( ) ){  
   //        cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<<endl;  
   //        return 0;  
   //    }  
   //     }  
   
5414    
5415    return 1;    return 1;
5416    
# Line 4280  TTree* PamLevel2::GetYodaTree() { Line 5451  TTree* PamLevel2::GetYodaTree() {
5451    //===================================    //===================================
5452    if (irun < 0) {    if (irun < 0) {
5453      cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = " << irun << endl;      cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = " << irun << endl;
5454      //  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;
5455      return NULL;      return NULL;
5456    }    }
5457    Int_t irootnew = run_obj->ID_ROOT_L0;    Int_t irootnew = GetRunInfo()->ID_ROOT_L0;
5458    //      cout << "iroot    "<<iroot<<endl;    if (DBG){
5459    //      cout << "irootnew "<<irootnew<<endl;      cout << "iroot    "<<iroot<<endl;
5460        cout << "irootnew "<<irootnew<<endl;
5461      }
5462    
5463    //===================================    //===================================
5464    // load the level0 file    // load the level0 file
# Line 4323  TTree* PamLevel2::GetYodaTree() { Line 5496  TTree* PamLevel2::GetYodaTree() {
5496      if (!h0_obj)      if (!h0_obj)
5497        h0_obj = new EventHeader();        h0_obj = new EventHeader();
5498      l0_tree->SetBranchAddress("Header", &h0_obj);      l0_tree->SetBranchAddress("Header", &h0_obj);
5499      prevshift = 0;      yprevshift = 0; // yes, yprevshift is the shift in the level0, prevshift is the shift in the level2
5500      //---------------------------------------------------      //---------------------------------------------------
5501      // TRACKER:      // TRACKER:
5502      if (TRK0) {      if (TRK0) {
# Line 4341  TTree* PamLevel2::GetYodaTree() { Line 5514  TTree* PamLevel2::GetYodaTree() {
5514          calo0_obj->Set();          calo0_obj->Set();
5515        };        };
5516        l0_tree->SetBranchAddress("Calorimeter", calo0_obj->GetPointerToCalorimeterEvent());        l0_tree->SetBranchAddress("Calorimeter", calo0_obj->GetPointerToCalorimeterEvent());
       //            cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;  
5517      }      }
5518      //---------------------------------------------------      //---------------------------------------------------
5519      // TOF:      // TOF:
# Line 4350  TTree* PamLevel2::GetYodaTree() { Line 5522  TTree* PamLevel2::GetYodaTree() {
5522      }      }
5523    
5524      dbc->Close(); // EMILIANO, do not leave open connections, open only when needed      dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
5525        delete dbc;
5526      dbc=0;      dbc=0;
5527    
5528    };    };
5529    
   //     if(!dbc || (dbc && !dbc->IsConnected())){  
   //    cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;  
   //     }  
   
5530    if (TRK0) {    if (TRK0) {
5531      //  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?  
5532      TrkParams::SetCalib(run_obj, dbc);      TrkParams::SetCalib(run_obj, dbc);
5533      TrkParams::LoadCalib();      TrkParams::LoadCalib();
5534      if (!TrkParams::CalibIsLoaded()) {      if (!TrkParams::CalibIsLoaded()) {
# Line 4371  TTree* PamLevel2::GetYodaTree() { Line 5536  TTree* PamLevel2::GetYodaTree() {
5536      };      };
5537      if(dbc){      if(dbc){
5538        dbc->Close(); // EMILIANO, do not leave open connections, open only when needed        dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
5539          delete dbc;
5540        dbc=0;        dbc=0;
5541      };      };
5542    }    }
   
   //    cout << l0_tree << endl;  
5543    return l0_tree;    return l0_tree;
   
5544  }  }
5545    
5546  /**  /**
# Line 4385  TTree* PamLevel2::GetYodaTree() { Line 5548  TTree* PamLevel2::GetYodaTree() {
5548   */   */
5549  Int_t PamLevel2::GetYodaEntry() {  Int_t PamLevel2::GetYodaEntry() {
5550    
5551    //    cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;    Long64_t iev = this->GetReadEntry();
   if (!GetYodaTree())  
     return 0;  
5552    
5553    // patch    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
5554    if (irunentry < 0) {    // if it is a full file (not preselected)
5555      //  cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
5556      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;  
5557    
5558    ULong64_t obt = 0;      if (!GetYodaTree()){
5559    ULong64_t pktn = 0;        printf(" PamLevel2::GetYodaEntry() : ERROR no level0 file loaded!\n");
5560    if (GetOrbitalInfo()) {        return 0;
5561      obt = GetOrbitalInfo()->OBT;      }
     pktn = GetOrbitalInfo()->pkt_num;  
   }  
5562    
5563    if (!GetOrbitalInfo() && !ISGP) {      if (irunentry < 0) {
5564      cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo " << endl;        if (DBG) cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
5565      return 0;        //      cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl; // TOGLITOGLI
5566    }        irunentry = 0LL;
5567    if (obt == 0 && pktn == 0 && !ISGP) {      }
5568      cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? " << endl;      //  ---------------------------------
5569      return 0;      //  if file is NOT a preselected file
5570    }      //  ---------------------------------
5571        Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM); // prevshift already included in irunentry
5572    
5573        if (DBG){
5574          cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
5575          cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
5576          cout << " time "<< abstime << endl;
5577        }
5578    
5579        ULong64_t obt = 0;
5580        ULong64_t pktn = 0;
5581        if (GetOrbitalInfo()) {
5582          obt = GetOrbitalInfo()->OBT;
5583          pktn = GetOrbitalInfo()->pkt_num;
5584        }
5585    
5586    // ---------------------------------------------------------------------      if (!GetOrbitalInfo() && !ISGP) {
5587    // ATTENTION!!!        cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo " << endl;
5588    // 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;  
5589      }      }
5590      answer = l0_tree->GetEntry(quellagiusta + (Long64_t) shift + (Long64_t) prevshift);      if (obt == 0 && pktn == 0 && !ISGP) {
5591      shift++;        cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? " << endl;
     if (!GetEventHeader()) {  
       cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader " << endl;  
5592        return 0;        return 0;
5593      }      }
5594    
5595        // ---------------------------------------------------------------------
5596        // ATTENTION!!!
5597        // If data are not pre-processed with cleaner, the level0 tree may contain
5598        // spurious nested physics packets.
5599        // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries
5600        // while level2 tree DOES NOT!!
5601        // This means that "quellagiusta" in these cases is not correct.
5602        // In order to retrieve the correct level0 event, I implemented a check
5603        // of the OBT and pkt-number. In case of mismatch, the level0 entry number
5604        // is shift forward until when the packets match.
5605        // ---------------------------------------------------------------------
5606        Long64_t shift = 0LL;
5607        Long64_t answer = quellagiusta + shift + yprevshift;
5608        Int_t readl0 = 0;
5609        readl0 = l0_tree->GetEntry(answer); // prevshift already included in irunentry
5610    
5611        if (DBG){
5612          printf(" siamo qui shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);
5613        }
5614    
5615    
5616      if (ISGP) {      if (ISGP) {
5617        obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO        obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO
5618        pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO        pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO
5619      }      }
5620    
5621      //  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 ){
5622      //  cout << " L2 --- "<< obt << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;        if ( isSync && shift == 0LL ){
5623      //  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");
5624      //  cout << " obt "<< obt << endl;          cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5625      //  cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;          cout << "\nFor bug reporting instructions, please see for example:\n";
5626      //  cout << " pktn "<< pktn << endl;          cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5627      //  cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;          cout << "  " << endl;
5628      //  printf(" IDRUN %u \n",GetRunInfo()->ID);        }
5629      //        if (shift > 0) {
5630      if (prevshift != 0 && (quellagiusta + (Long64_t) shift) == GetYodaTree()->GetEntries()) {          if (DBG) cout << " PKTNUM  L2 --- " << pktn << " --- L0 --- " << GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
5631        prevshift = 0;          if (DBG)
5632        shift = -1;            cout << "         RUN: ID " << GetRunInfo()->ID << " ID_ROOT_L0 " << run_obj->ID_ROOT_L0 << " ID_RUN_FRAG "
5633      };                 << GetRunInfo()->ID_RUN_FRAG << " EV_FROM " << GetRunInfo()->EV_FROM << endl;
5634            if (DBG)
5635              cout << "         L2 <--> L0 mismatch ( irun " << irun << " irunentry " << irunentry << " shift " << shift
5636                   << " prevshift " << prevshift << " )" << endl;
5637          }
5638          answer = quellagiusta +  shift+ yprevshift;
5639          readl0 = l0_tree->GetEntry(answer);
5640          //      printf(" inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5641    
5642          if (!GetEventHeader()) {
5643            cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader " << endl;
5644            return 0;
5645          }
5646    
5647    } while ((obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(        //
5648        GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta + (Long64_t) shift)        if (yprevshift != 0 && (quellagiusta + (Long64_t) shift) == GetYodaTree()->GetEntries()) {
5649        < GetYodaTree()->GetEntries() && shift < maxshift);          if (DBG) printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);
5650            //        printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5651            yprevshift = 0LL;
5652            shift = -1LL;
5653          };
5654        
5655          shift++;
5656        }
5657                                      
5658    
5659    if ((quellagiusta + (Long64_t) shift + (Long64_t) prevshift) > GetYodaTree()->GetEntries() || shift == maxshift) {      if ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()) ){
5660      cout << " Big trouble here, no such event in Level0 data! (NB maxshift set to " << maxshift << " )" << endl;        if ( isSync ){
5661      return 0;          printf(" PamLevel2::GetYodaEntry() ERROR! sync file but the level0 entry not found AT ALL!!! \n");
5662    }          cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5663    //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;          cout << "\nFor bug reporting instructions, please see for example:\n";
5664    //    return GetYodaTree()->GetEntry(quellagiusta);          cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5665    if (shift > 1)          cout << "  " << endl;
5666      prevshift += (shift - 1);        }
5667          cout << "Int_t PamLevel2::GetYodaEntry() -- WARNING -- " << endl;
5668          cout << " Big trouble here, no such event in Level0 data! (NB maxshift set to " << maxshift << " )" << endl;    
5669          cout << " Nested and/or DarthVader skipped packets in fragmented run? checking and trying to fix " <<endl;
5670          // query the DB for runs containing the event, loop over LEVEL0 files which could contain the level0 event and try to find it
5671          // 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
5672          // connect to db
5673          if (!dbc || (dbc && !dbc->IsConnected())) SetDBConnection(); //Emiliano
5674          //
5675          if (GetOrbitalInfo()){
5676            abstime = GetOrbitalInfo()->absTime;
5677          } else {
5678            printf(" PamLevel2::GetYodaEntry() ERROR! no OrbitalInfo, cannot get the absolute time for event \n");
5679            return 0;
5680          }
5681          // query DB looking for runs containing the processed event
5682          TSQLResult *pResult;
5683          TSQLRow *Row = NULL;
5684          TString myquery = Form("select ID,NEVENTS from GL_RUN where RUNHEADER_TIME<=%lld and RUNTRAILER_TIME>=%lld;",abstime,abstime);
5685          if ( DBG ) printf(" query is %s \n",myquery.Data());
5686          //      printf(" query is %s \n",myquery.Data());// TOGLITOGLI
5687          pResult = dbc->Query(myquery.Data());    
5688          if (!pResult->GetRowCount()){
5689            printf(" PamLevel2::GetYodaEntry() ERROR! event is not included in any run!!! \n");
5690            cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5691            cout << "\nFor bug reporting instructions, please see for example:\n";
5692            cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5693            cout << "  " << endl;
5694            return 0;
5695          }
5696          if ( pResult->GetRowCount() == 1 ){
5697            if (DBG) printf(" PamLevel2::GetYodaEntry() - WARNING - YodaEntry not found but only one run containing the event, it should not happen \n");
5698            //        printf(" PamLevel2::GetYodaEntry() - WARNING - YodaEntry not found but only one run containing the event, it should not happen \n");//TOGLITOGLI
5699          }
5700          for( Int_t ru=0; ru < pResult->GetRowCount(); ru++){ // loop over runs containing the event
5701            if (Row) delete Row;
5702            Row = pResult->Next();  
5703            if( Row == NULL ) break;
5704            UInt_t idrun = (UInt_t)atoll(Row->GetField(0));
5705            UInt_t nev = (UInt_t)atoll(Row->GetField(1));
5706            if (DBG) printf(" inside loop over runs: ru %i idrun %i nev %i \n",ru,idrun,nev);
5707            //        printf(" inside loop over runs: ru %i idrun %i nev %i \n",ru,idrun,nev);//TOGLITOGLI
5708    
5709            // now look for this run in the level2 file, it must be present! code is taken from updateruninfo of course
5710            Bool_t rfound = false;
5711            totrunentry = 0LL;
5712            runfirstentry = 0LL;
5713            for (Int_t r=0; r< run_tree->GetEntries();r++){
5714              run_tree->GetEntry(r);//update runinfo
5715              if ( r > 0 ){
5716                totrunentrymin = totrunentrymax+1;
5717              } else {
5718                totrunentrymin = 0LL;
5719              }
5720              totrunentry += GetRunInfo()->NEVENTS;
5721              totrunentrymax = totrunentry - 1 - prevshift; // prevshift is needed to handle nested+DV_skipped packets
5722              irun = r;        
5723    
5724              if (idrun == GetRunInfo()->ID){
5725                if ( totrunentrymin > iev ){ // there is a shift (nested+DV_skipped packets)
5726                  if (DBG) printf("PamLevel2::GetYodaEntry - unconsistent iev - nevents, probable DBL0-L2 async\n");
5727                  if (DBG) printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);
5728                  //              printf("PamLevel2::GetYodaEntry - unconsistent iev - nevents, probable DBL0-L2 async\n");
5729                  //              printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI
5730                  prevshift += (totrunentrymin-iev); // add the new shift to total shift
5731                  totrunentrymin -= (totrunentrymin-iev); // shift run position min
5732                  totrunentrymax -= (totrunentrymin-iev); // shift run position max
5733                  if (DBG) printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);
5734                  //              printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI
5735                }
5736                runfirstentry = totrunentrymin; // first entry of the run in the level2
5737              
5738    
5739    return answer;              //
5740                if (gltsync)
5741                  delete gltsync; // Emiliano
5742                if (!dbc || (dbc && !dbc->IsConnected()))
5743                  SetDBConnection(); //Emiliano
5744                gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano
5745                if (dbc){
5746                  dbc->Close(); // Emiliano
5747                  delete dbc;
5748                  dbc=0;
5749                }          
5750                if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano
5751                  cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun
5752                       << "  has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl;
5753                  cout
5754                    << "                                                            (NB!! in this case some events could be assigned to a wrong run)"
5755                    << endl;
5756                }
5757                //
5758                if (DBG) printf(" found \n");
5759                //            printf(" found \n");//TOGLITOGLI
5760                rfound = true;
5761                //
5762                break;
5763              }
5764            } // loop over run
5765            if ( !rfound ){
5766              printf(" PamLevel2::GetYodaEntry() ERROR! run is not present in the level2 file!!! \n");
5767              cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5768              cout << "\nFor bug reporting instructions, please see for example:\n";
5769              cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5770              cout << "  " << endl;        
5771              return 0;
5772            }
5773    
5774            // here we got the first run and we can check if it contains the level0 event
5775            if (!GetYodaTree()){
5776              printf(" PamLevel2::GetYodaEntry() : ERROR no level0 file loaded!\n");
5777              return 0;
5778            }      
5779    
5780            // get the current run entry
5781            irunentry = iev - runfirstentry;
5782            if (irunentry < 0) {
5783              if (DBG) cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
5784              //          cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl; // TOGLITOGLI
5785              irunentry = 0LL;
5786            }
5787            //  ---------------------------------
5788            //  if file is NOT a preselected file
5789            //  ---------------------------------
5790            quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM); // prevshift already included in irunentry
5791          
5792            if (DBG){
5793              cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
5794              cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
5795              cout << " time "<< abstime << endl;
5796            }
5797            //        cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
5798            //        cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
5799            //        cout << " time "<< abstime << endl; // TOGLITOGLI
5800          
5801            shift = 0;
5802            answer = quellagiusta + shift + yprevshift; // prevshift already included in irunentry
5803            readl0 = l0_tree->GetEntry(answer); // prevshift already included in irunentry
5804    
5805            if (DBG){
5806              printf(" siamo qua shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);
5807            }
5808            //        printf(" siamo qua shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5809          
5810            while ( (obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta + (Long64_t) shift) < GetYodaTree()->GetEntries() && shift < maxshift ){
5811              if (shift > 0) {
5812                if (DBG) cout << " PKTNUM  L2 --- " << pktn << " --- L0 --- " << GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
5813                if (DBG)
5814                  cout << "         RUN: ID " << GetRunInfo()->ID << " ID_ROOT_L0 " << run_obj->ID_ROOT_L0 << " ID_RUN_FRAG "
5815                       << GetRunInfo()->ID_RUN_FRAG << " EV_FROM " << GetRunInfo()->EV_FROM << endl;
5816                if (DBG)
5817                  cout << "         L2 <--> L0 mismatch ( irun " << irun << " irunentry " << irunentry << " shift " << shift
5818                       << " prevshift " << prevshift << " )" << endl;
5819              }
5820              answer = quellagiusta +  shift+ yprevshift;
5821              readl0 = l0_tree->GetEntry(answer);
5822              //          printf(" inside inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5823            
5824              if (!GetEventHeader()) {
5825                cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader " << endl;
5826                return 0;
5827              }
5828              //
5829              if (yprevshift != 0 && (quellagiusta + (Long64_t) shift) == GetYodaTree()->GetEntries()) {
5830                if (DBG) printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);
5831                //            printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5832                yprevshift = 0;
5833                shift = -1;
5834              };
5835            
5836              shift++;
5837            }
5838          
5839            if ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()) ){
5840              //still not the good run... continue with the nex one!
5841              printf("still not the good run... continue with the nex one!\n");
5842            } else {
5843              if (DBG) cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
5844              //          cout << "LA ENTRY GIUSTA E`: "<<answer<<" (spero...)"<<endl;//TOGLITOGLI
5845              if (shift > 1) yprevshift = (shift - 1);
5846              if (Row) delete Row;
5847              delete pResult;  
5848              if (dbc){
5849                dbc->Close(); // Emiliano
5850                delete dbc;
5851                dbc=0;
5852              }    
5853              il0entry = answer;
5854              return readl0;
5855            }
5856            // perhaps it is all
5857          }// loop over runs containing the event
5858          if (Row) delete Row;
5859          delete pResult;  
5860          if (dbc){
5861            dbc->Close(); // Emiliano
5862            delete dbc;
5863            dbc=0;
5864          }          
5865          // arriving here it means no run found, cannot be! error!
5866          printf(" PamLevel2::GetYodaEntry() ERROR! run is not present in the level0 files!!! \n");
5867          cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5868          cout << "\nFor bug reporting instructions, please see for example:\n";
5869          cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5870          cout << "  " << endl;        
5871          return 0;
5872        } else {
5873          if (DBG) cout << "=> LA ENTRY GIUSTA E`: "<<answer<<" (spero...)"<<endl;
5874          //    cout << "=> LA ENTRY GIUSTA E`: "<<answer<<" (spero...)"<<endl;
5875          //    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()) );
5876          if (shift > 1) yprevshift = (shift - 1);
5877          il0entry = answer;
5878          return readl0;
5879        }
5880    
5881        /*  } // if selli 0 || 2
5882      if ( SELLI == 1 && hasL0EE ){
5883        sel_tree->GetEntry(iev);  
5884        Long64_t answer = il0entry;
5885        Int_t readl0 = 0;
5886        readl0 = l0_tree->GetEntry(answer);
5887        return readl0;
5888        }*/
5889      printf(" PamLevel2::GetYodaEntry() ERROR! \n");
5890      cout << " Entry not found! OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5891      cout << "\nFor bug reporting instructions, please see for example:\n";
5892      cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5893      cout << "  " << endl;
5894      return 0;
5895  }  }
5896    
5897  /**  /**
5898   * \Brief Set DB connection   * \Brief Set DB connection
5899   */   */
# Line 4582  Long64_t PamLevel2::GetReadEntry() { Line 5986  Long64_t PamLevel2::GetReadEntry() {
5986  void PamLevel2::SetSortingMethod(TString how) {  void PamLevel2::SetSortingMethod(TString how) {
5987    if (howtosort != how) {    if (howtosort != how) {
5988      issorted = false;      issorted = false;
5989        issorted_new = false;
5990    }    }
5991    howtosort = how;    howtosort = how;
5992  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.23