/[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.91 by mocchiut, Thu Dec 15 08:54:12 2011 UTC revision 1.100 by mocchiut, Fri Oct 17 15:58:09 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 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    this->SetMaxShift(-1);    SetMaxShift(-1);
496  }  }
497    
498    
# Line 425  PamLevel2::PamLevel2(TString ddir, TList Line 500  PamLevel2::PamLevel2(TString ddir, TList
500    Initialize();    Initialize();
501    GetPamTree(llist, detlist);    GetPamTree(llist, detlist);
502    GetRunTree(llist);    GetRunTree(llist);
503    this->SetMaxShift(-1);    SetMaxShift(-1);
504  }  }
505    
506  /**  /**
# Line 437  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    this->SetMaxShift(-1);    SetMaxShift(-1);
521  }  }
522    
523    
# Line 455  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      proc_obj = 0;// Emiliano
570    irun = -1LL;    irun = -1LL;
571    irunt = -1LL;    irunt = -1LL;
572    totrunentry = 0LL;    totrunentry = 0LL;
# Line 474  void PamLevel2::Initialize() { Line 576  void PamLevel2::Initialize() {
576    runlastentry = 0LL;    runlastentry = 0LL;
577    gltsync = 0; // Emiliano    gltsync = 0; // Emiliano
578    fUpdateRunInfo = true; // Emiliano    fUpdateRunInfo = true; // Emiliano
579      fUseDBinRunInfo = true; // Emiliano
580      fDiscarded = false; //EM
581    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    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
582    il0entry = 0LL;    il0entry = 0LL;
583    //  hasL0EE = true;    //  hasL0EE = true;
# Line 489  void PamLevel2::Initialize() { Line 593  void PamLevel2::Initialize() {
593    
594    run_tree = NULL;    run_tree = NULL;
595    run_tree_clone = NULL;    run_tree_clone = NULL;
596    
597      proc_tree = NULL;
598      proc_tree_clone = NULL;
599    
600    sel_tree = NULL;    sel_tree = NULL;
601    sel_tree_clone = NULL;    sel_tree_clone = NULL;
602    
# Line 536  void PamLevel2::Initialize() { Line 644  void PamLevel2::Initialize() {
644    ND = true;    ND = true;
645    AC = true;    AC = true;
646    ORB = true;    ORB = true;
647      PROC = true;
648    GP = false;    GP = false;
649    
650      EXT = false;
651      NUC = false;
652      trkAlg = "STD";//default tracking algorythm
653    
654    RUN = true;    RUN = true;
655    
656    SELLI = -1;    SELLI = -1;
# Line 548  void PamLevel2::Initialize() { Line 661  void PamLevel2::Initialize() {
661    
662    tsorted = 0;    tsorted = 0;
663    timage = 0;    timage = 0;
664      text = 0 ;
665    
666      tsorted_nuc = 0;
667      timage_nuc = 0;
668      text_nuc = 0 ;
669    
670    howtosort = "+CAL+TOF";    howtosort = "+CAL+TOF";
671    //howtosort = "+TOF";    //howtosort = "+TOF";
# Line 555  void PamLevel2::Initialize() { Line 673  void PamLevel2::Initialize() {
673    
674    issorted = false;    issorted = false;
675    lastsorted = -1;    lastsorted = -1;
676      issorted_new = false;
677      lastsorted_new = -1;
678    
679  }  }
680  ;  ;
# Line 567  void PamLevel2::Delete() { Line 687  void PamLevel2::Delete() {
687      delete run_obj;      delete run_obj;
688    if (soft_obj)    if (soft_obj)
689      delete soft_obj; //Emiliano      delete soft_obj; //Emiliano
690      if (proc_obj)
691        delete proc_obj; //Emiliano
692    
693    //    cout << "void PamLevel2::Clear()"<<endl;    //    cout << "void PamLevel2::Clear()"<<endl;
694    if (h0_obj)    if (h0_obj)
# Line 585  void PamLevel2::Delete() { Line 707  void PamLevel2::Delete() {
707      delete calo1_obj;      delete calo1_obj;
708    if (calo2_obj)    if (calo2_obj)
709      delete calo2_obj;      delete calo2_obj;
710    if (tof_obj)    if (tof2_obj)
711      delete tof_obj;      delete tof2_obj;
712    if (trig_obj)    if (trig_obj)
713      delete trig_obj;      delete trig_obj;
714    if (s4_obj)    if (s4_obj)
# Line 595  void PamLevel2::Delete() { Line 717  void PamLevel2::Delete() {
717      delete nd_obj;      delete nd_obj;
718    if (ac_obj)    if (ac_obj)
719      delete ac_obj;      delete ac_obj;
720    if (orb_obj)    if (orb2_obj)
721      delete orb_obj;      delete orb2_obj;
722    if (gp_obj)    if (gp_obj)
723      delete gp_obj;      delete gp_obj;
724    
725      if(trk_nuc_obj)trk_nuc_obj->Delete();
726      if(trk_ext_obj)trk_ext_obj->Delete();
727      if(trk_ext_nuc_obj)trk_ext_nuc_obj->Delete();
728    
729      if(calo_nuc_obj)calo_nuc_obj->Delete();
730      if(calo_ext_obj)calo_ext_obj->Delete();
731      if(calo_ext_nuc_obj)calo_ext_nuc_obj->Delete();
732    
733      if(tof_nuc_obj)tof_nuc_obj->Delete();
734      if(tof_ext_obj)tof_ext_obj->Delete();
735      if(tof_ext_nuc_obj)tof_ext_nuc_obj->Delete();
736    
737      if(orb_nuc_obj)orb_nuc_obj->Delete();
738      if(orb_ext_obj)orb_ext_obj->Delete();
739      if(orb_ext_nuc_obj)orb_ext_nuc_obj->Delete();
740    
741    
742      if(trk2_nuc_obj)trk2_nuc_obj->Delete();;
743      if( calo2_nuc_obj)calo2_nuc_obj->Delete();;
744      if(tof2_nuc_obj)tof2_nuc_obj->Delete();;
745      if(orb2_nuc_obj)orb2_nuc_obj->Delete();;
746      
747    
748    
749    if (tsorted) {    if (tsorted) {
750      tsorted->Delete();      tsorted->Delete();
751      delete tsorted;      delete tsorted;
# Line 608  void PamLevel2::Delete() { Line 754  void PamLevel2::Delete() {
754      timage->Delete();      timage->Delete();
755      delete timage;      delete timage;
756    }    }
757      if (text) {
758        text->Delete();
759        delete text;
760      }
761      if (tsorted_nuc) {
762        tsorted_nuc->Delete();
763        delete tsorted_nuc;
764      }
765      if (timage_nuc) {
766        timage_nuc->Delete();
767        delete timage_nuc;
768      }
769      if (text_nuc) {
770        text_nuc->Delete();
771        delete text_nuc;
772      }
773    
774    
775    
776    if (dbc) {    if (dbc) {
777      dbc->Close();      dbc->Close();
# Line 675  void PamLevel2::Delete() { Line 839  void PamLevel2::Delete() {
839    if (irunoffset)    if (irunoffset)
840      delete[] irunoffset;      delete[] irunoffset;
841    
842    
843      Initialize();
844    
845  }  }
846  ;  ;
847    
# Line 708  void PamLevel2::Clear() { Line 875  void PamLevel2::Clear() {
875      calo1_obj->Clear();      calo1_obj->Clear();
876    if (calo2_obj)    if (calo2_obj)
877      calo2_obj->Clear();      calo2_obj->Clear();
878    if (tof_obj)    if (tof2_obj)
879      tof_obj->Clear();      tof2_obj->Clear();
880    if (trig_obj)    if (trig_obj)
881      trig_obj->Clear();      trig_obj->Clear();
882    if (s4_obj)    if (s4_obj)
# Line 718  void PamLevel2::Clear() { Line 885  void PamLevel2::Clear() {
885      nd_obj->Clear();      nd_obj->Clear();
886    if (ac_obj)    if (ac_obj)
887      ac_obj->Clear();      ac_obj->Clear();
888    if (orb_obj)    if (orb2_obj)
889      orb_obj->Clear();      orb2_obj->Clear();
890    if (gp_obj)    if (gp_obj)
891      gp_obj->Clear();      gp_obj->Clear();
892      if (proc_obj)
893        proc_obj->Clear();
894    
895    //    if(sorted_tracks)sorted_tracks->Clear();    //    if(sorted_tracks)sorted_tracks->Clear();
896    //    sorted_tracks.Clear();    //    sorted_tracks.Clear();
897    
898    if (tsorted) {    if(trk_nuc_obj)trk_nuc_obj->Clear();
899      tsorted->Delete();    if(trk_ext_obj)trk_ext_obj->Clear();
900    }    if(trk_ext_nuc_obj)trk_ext_nuc_obj->Clear();
901    if (timage) {  
902      timage->Delete();    if(calo_nuc_obj)calo_nuc_obj->Clear();
903    }    if(calo_ext_obj)calo_ext_obj->Clear();
904      if(calo_ext_nuc_obj)calo_ext_nuc_obj->Clear();
905    
906      if(tof_nuc_obj)tof_nuc_obj->Clear();
907      if(tof_ext_obj)tof_ext_obj->Clear();
908      if(tof_ext_nuc_obj)tof_ext_nuc_obj->Clear();
909    
910      if(orb_nuc_obj)orb_nuc_obj->Clear();
911      if(orb_ext_obj)orb_ext_obj->Clear();
912      if(orb_ext_nuc_obj)orb_ext_nuc_obj->Clear();
913    
914      if(trk2_nuc_obj)trk2_nuc_obj->Clear();;
915      if( calo2_nuc_obj)calo2_nuc_obj->Clear();;
916      if(tof2_nuc_obj)tof2_nuc_obj->Clear();;
917      if(orb2_nuc_obj)orb2_nuc_obj->Clear();;
918    
919      if (tsorted)tsorted->Delete();
920      if (timage)timage->Delete();
921      if (text) text->Delete();
922    
923      if (tsorted_nuc)tsorted_nuc->Delete();
924      if (timage_nuc)timage_nuc->Delete();
925      if (text_nuc) text_nuc->Delete();
926  }  }
927  ;  ;
928    
# Line 796  void PamLevel2::Reset() { Line 987  void PamLevel2::Reset() {
987    trkh_obj = 0;    trkh_obj = 0;
988    calo1_obj = 0;    calo1_obj = 0;
989    calo2_obj = 0;    calo2_obj = 0;
990    tof_obj = 0;    tof2_obj = 0;
991    trig_obj = 0;    trig_obj = 0;
992    s4_obj = 0;    s4_obj = 0;
993    nd_obj = 0;    nd_obj = 0;
994    ac_obj = 0;    ac_obj = 0;
995    orb_obj = 0;    orb2_obj = 0;
996    gp_obj = 0;    gp_obj = 0;
997      proc_obj = 0;
998    
999      trk_ext_obj     = 0;
1000      trk_ext_nuc_obj = 0;
1001      trk_nuc_obj     = 0;
1002      
1003      calo_ext_obj     = 0;
1004      calo_ext_nuc_obj = 0;
1005      calo_nuc_obj     = 0;
1006      
1007      tof_ext_obj     = 0;
1008      tof_ext_nuc_obj = 0;
1009      tof_nuc_obj     = 0;
1010      
1011      orb_ext_obj     = 0;
1012      orb_ext_nuc_obj = 0;
1013      orb_nuc_obj     = 0;
1014    
1015      trk2_nuc_obj  = 0;
1016      calo2_nuc_obj = 0;
1017      tof2_nuc_obj  = 0;
1018      orb2_nuc_obj  = 0;
1019    
1020      trk2_nuc_obj  = 0;
1021      calo2_nuc_obj = 0;
1022      tof2_nuc_obj  = 0;
1023      orb2_nuc_obj  = 0;
1024    //    //
1025    // Reset run pointers    // Reset run pointers
1026    //    //
1027    run_obj = 0;//new GL_RUN();    run_obj = 0;//new GL_RUN();
1028    soft_obj = 0;// Emiliano    soft_obj = 0;// Emiliano
1029      proc_obj = 0;// Emiliano
1030    irun = -1;    irun = -1;
1031    irunt = -1;    irunt = -1;
1032    totrunentry = 0LL;    totrunentry = 0LL;
# Line 837  Bool_t PamLevel2::IsGood(Bool_t strict) Line 1056  Bool_t PamLevel2::IsGood(Bool_t strict)
1056    if (strict) {    if (strict) {
1057      if (trk2_obj && trk2_obj->UnpackError() != 0)      if (trk2_obj && trk2_obj->UnpackError() != 0)
1058        goodev = false;        goodev = false;
1059      if (tof_obj && tof_obj->unpackError != 0)      if (tof2_obj && tof2_obj->unpackError != 0)
1060        goodev = false;        goodev = false;
1061      if (trig_obj && trig_obj->unpackError != 0)      if (trig_obj && trig_obj->unpackError != 0)
1062        goodev = false;        goodev = false;
# Line 847  Bool_t PamLevel2::IsGood(Bool_t strict) Line 1066  Bool_t PamLevel2::IsGood(Bool_t strict)
1066        goodev = false;        goodev = false;
1067      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)))
1068        goodev = false;        goodev = false;
1069      //  if(orb_obj)      //  if(orb2_obj)
1070    }    }
1071    else {    else {
1072      if (nd_obj && nd_obj->unpackError != 0)      if (nd_obj && nd_obj->unpackError != 0)
# Line 878  void PamLevel2::SetMaxShift(Int_t sh){ Line 1097  void PamLevel2::SetMaxShift(Int_t sh){
1097      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");      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");
1098      maxshift = sh;      maxshift = sh;
1099    } else {    } else {
1100      ULong64_t nev = this->GetEntries();      ULong64_t nev = GetEntries();
1101      ULong64_t runnev = 0ULL;      ULong64_t runnev = 0ULL;
1102      for (Int_t r=0; r< run_tree->GetEntries();r++){      for (Int_t r=0; r< run_tree->GetEntries();r++){
1103        run_tree->GetEntry(r);//update runinfo        run_tree->GetEntry(r);//update runinfo
# Line 933  void *PamLevel2::GetPointerTo(const char Line 1152  void *PamLevel2::GetPointerTo(const char
1152      return &calo2_obj;      return &calo2_obj;
1153    };    };
1154    if (!objname.CompareTo("ToFLevel2")) {    if (!objname.CompareTo("ToFLevel2")) {
1155      if (!tof_obj) {      if (!tof2_obj) {
1156        tof_obj = new ToFLevel2();        tof2_obj = new ToFLevel2();
1157        tof_obj->Set();        tof2_obj->Set();
1158      }      }
1159      return &tof_obj;      return &tof2_obj;
1160    };    };
1161    if (!objname.CompareTo("TrigLevel2")) {    if (!objname.CompareTo("TrigLevel2")) {
1162      if (!trig_obj)      if (!trig_obj)
# Line 960  void *PamLevel2::GetPointerTo(const char Line 1179  void *PamLevel2::GetPointerTo(const char
1179      return &ac_obj;      return &ac_obj;
1180    };    };
1181    if (!objname.CompareTo("OrbitalInfo")) {    if (!objname.CompareTo("OrbitalInfo")) {
1182      if (!orb_obj) {      if (!orb2_obj) {
1183        orb_obj = new OrbitalInfo();        orb2_obj = new OrbitalInfo();
1184        orb_obj->Set();        orb2_obj->Set();
1185      }      }
1186      return &orb_obj;      return &orb2_obj;
1187    };    };
1188    //     if(!objname.CompareTo("OrbitalInfo")){    //     if(!objname.CompareTo("OrbitalInfo")){
1189    //    if(!orb_obj)   orb_obj   = new OrbitalInfo();    //    if(!orb2_obj)   orb2_obj   = new OrbitalInfo();
1190    //    return &orb_obj;    //    return &orb2_obj;
1191    //     };    //     };
1192    if (!objname.CompareTo("GPamela")) {    if (!objname.CompareTo("GPamela")) {
1193      if (!gp_obj)      if (!gp_obj)
# Line 982  void *PamLevel2::GetPointerTo(const char Line 1201  void *PamLevel2::GetPointerTo(const char
1201    if (!objname.CompareTo("SoftInfo"))    if (!objname.CompareTo("SoftInfo"))
1202      return &soft_obj; // Emiliano      return &soft_obj; // Emiliano
1203    
1204      if (!objname.CompareTo("ProcessingInfo")){
1205        if (!proc_obj)
1206          proc_obj = new ProcInfo();    
1207        return &proc_obj; // Emiliano
1208      }
1209    
1210    return NULL;    return NULL;
1211  }  }
1212  ;  ;
# Line 1032  CaloTrkVar *PamLevel2::GetCaloStoredTrac Line 1257  CaloTrkVar *PamLevel2::GetCaloStoredTrac
1257   */   */
1258  ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno) {  ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno) {
1259    
1260    if (!tof_obj)    if (!tof2_obj)
1261      return 0;      return 0;
1262    
1263    if (tof_obj->ToFLevel2::ntrk() == 0) {    if (tof2_obj->ToFLevel2::ntrk() == 0) {
1264      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"
1265          << endl;          << endl;
1266      return NULL;      return NULL;
# Line 1045  ToFTrkVar *PamLevel2::GetToFStoredTrack( Line 1270  ToFTrkVar *PamLevel2::GetToFStoredTrack(
1270    Int_t it_tof = 0;    Int_t it_tof = 0;
1271    
1272    do {    do {
1273      c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);      c = tof2_obj->ToFLevel2::GetToFTrkVar(it_tof);
1274      it_tof++;      it_tof++;
1275    } while (c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());    } while (c && seqno != c->trkseqno && it_tof < tof2_obj->ToFLevel2::ntrk());
1276    
1277    if (!c || seqno != c->trkseqno) {    if (!c || seqno != c->trkseqno) {
1278      c = 0;      c = 0;
# Line 1070  ToFTrkVar *PamLevel2::GetToFStoredTrack( Line 1295  ToFTrkVar *PamLevel2::GetToFStoredTrack(
1295   */   */
1296  OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno) {  OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno) {
1297    
1298    if (!orb_obj)    if (!orb2_obj)
1299      return 0;      return 0;
1300    
1301    if (orb_obj->OrbitalInfo::ntrk() == 0) {    if (orb2_obj->OrbitalInfo::ntrk() == 0) {
1302      //       // TRICK BEGIN      //       // TRICK BEGIN
1303      //       OrbitalInfoTrkVar  *r = new OrbitalInfoTrkVar(); // TEMPORARY TRICK      //       OrbitalInfoTrkVar  *r = new OrbitalInfoTrkVar(); // TEMPORARY TRICK
1304      //       Int_t nn = 0;      //       Int_t nn = 0;
1305      //       TClonesArray &tor = *orb_obj->OrbitalInfoTrk;      //       TClonesArray &tor = *orb2_obj->OrbitalInfoTrk;
1306      //       for(Int_t nt=0; nt < tof_obj->ToFLevel2::ntrk(); nt++){      //       for(Int_t nt=0; nt < tof2_obj->ToFLevel2::ntrk(); nt++){
1307      //  //      //  //
1308      //  ToFTrkVar *ptt = tof_obj->ToFLevel2::GetToFTrkVar(nt);      //  ToFTrkVar *ptt = tof2_obj->ToFLevel2::GetToFTrkVar(nt);
1309      //  if ( ptt->trkseqno != -1  ){      //  if ( ptt->trkseqno != -1  ){
1310      //    //      //    //
1311      //    r->trkseqno = ptt->trkseqno;      //    r->trkseqno = ptt->trkseqno;
# Line 1102  OrbitalInfoTrkVar *PamLevel2::GetOrbital Line 1327  OrbitalInfoTrkVar *PamLevel2::GetOrbital
1327      //       };      //       };
1328      //       delete r;      //       delete r;
1329      //       OrbitalInfoTrkVar *c = 0;      //       OrbitalInfoTrkVar *c = 0;
1330      //       c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(0);      //       c = orb2_obj->OrbitalInfo::GetOrbitalInfoTrkVar(0);
1331      //       return c;      //       return c;
1332      //       //TRICK END      //       //TRICK END
1333      cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo " << seqno      cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo " << seqno
# Line 1114  OrbitalInfoTrkVar *PamLevel2::GetOrbital Line 1339  OrbitalInfoTrkVar *PamLevel2::GetOrbital
1339    Int_t it_tof = 0;    Int_t it_tof = 0;
1340    
1341    do {    do {
1342      c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);      c = orb2_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);
1343      it_tof++;      it_tof++;
1344    } while (c && seqno != c->trkseqno && it_tof < orb_obj->OrbitalInfo::ntrk());    } while (c && seqno != c->trkseqno && it_tof < orb2_obj->OrbitalInfo::ntrk());
1345    
1346    if (!c || seqno != c->trkseqno) {    if (!c || seqno != c->trkseqno) {
1347      c = 0;      c = 0;
# Line 1247  void PamLevel2::SortTracks() { Line 1472  void PamLevel2::SortTracks() {
1472    // create TCloneArrays to store tracks and its images    // create TCloneArrays to store tracks and its images
1473    if (!tsorted)    if (!tsorted)
1474      tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());      tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1475    tsorted->Delete();    tsorted->Clear("C+C");//Delete();
1476    TClonesArray &ttsorted = *tsorted;    TClonesArray &ttsorted = *tsorted;
1477    
1478    if (!timage)    if (!timage)
1479      timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());      timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1480    timage->Delete();    timage->Clear("C+C");//Delete();
1481    TClonesArray &ttimage = *timage;    TClonesArray &ttimage = *timage;
1482    
1483    
1484    
1485    //--------------------------------------------------    //--------------------------------------------------
1486    // retrieve sorting method    // retrieve sorting method
1487    //--------------------------------------------------    //--------------------------------------------------
# Line 1370  void PamLevel2::SortTracks() { Line 1597  void PamLevel2::SortTracks() {
1597        // -----------------------------------------------------------------------------------------        // -----------------------------------------------------------------------------------------
1598        // check the number of hit pmts along the track        // check the number of hit pmts along the track
1599        // on S12 S21 and S32, where paddles are parallel to Y axis        // on S12 S21 and S32, where paddles are parallel to Y axis
1600        if ((use_TOF || use_S1 || use_S2 || use_S3) && !tof_obj) {        if ((use_TOF || use_S1 || use_S2 || use_S3) && !tof2_obj) {
1601          cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but ToFLevel2 not loaded !!!";          cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but ToFLevel2 not loaded !!!";
1602          return;          return;
1603        };        };
# Line 1387  void PamLevel2::SortTracks() { Line 1614  void PamLevel2::SortTracks() {
1614          //          //
1615          Float_t sen = 0.;          Float_t sen = 0.;
1616          for (Int_t ih = 0; ih < op->npmtadc; ih++) {          for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1617            Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));            Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1618            if (pl == 2 || pl == 3 || pl == 4 || pl == 5)            if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
1619              sen += (op->dedx).At(ih);              sen += (op->dedx).At(ih);
1620          };          };
1621          for (Int_t ih = 0; ih < oi->npmtadc; ih++) {          for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1622            Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));            Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1623            if (pl == 2 || pl == 3 || pl == 4 || pl == 5)            if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
1624              sen += (oi->dedx).At(ih);              sen += (oi->dedx).At(ih);
1625          };          };
# Line 1405  void PamLevel2::SortTracks() { Line 1632  void PamLevel2::SortTracks() {
1632            Int_t nz = 6;            Int_t nz = 6;
1633            Float_t zin[6]; // << define TOF z-coordinates            Float_t zin[6]; // << define TOF z-coordinates
1634            for (Int_t ip = 0; ip < nz; ip++)            for (Int_t ip = 0; ip < nz; ip++)
1635              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
1636            Trajectory *tr = new Trajectory(nz, zin);            Trajectory *tr = new Trajectory(nz, zin);
1637            //            //
1638            Int_t nphit_p = 0;            Int_t nphit_p = 0;
# Line 1414  void PamLevel2::SortTracks() { Line 1641  void PamLevel2::SortTracks() {
1641            Float_t enhit_i = 0.;            Float_t enhit_i = 0.;
1642            //            //
1643            for (Int_t ih = 0; ih < op->npmtadc; ih++) {            for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1644              Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));              Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1645              if (pl == 1 || pl == 2 || pl == 5) {              if (pl == 1 || pl == 2 || pl == 5) {
1646                nphit_p++;                nphit_p++;
1647                enhit_p += (op->dedx).At(ih);                enhit_p += (op->dedx).At(ih);
# Line 1425  void PamLevel2::SortTracks() { Line 1652  void PamLevel2::SortTracks() {
1652            //            //
1653            if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {            if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
1654              for (Int_t ih = 0; ih < op->npmtadc; ih++) {              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1655                Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1656                if (pl == 0) {                if (pl == 0) {
1657                  nphit_p++;                  nphit_p++;
1658                  enhit_p += (op->dedx).At(ih);                  enhit_p += (op->dedx).At(ih);
# Line 1434  void PamLevel2::SortTracks() { Line 1661  void PamLevel2::SortTracks() {
1661            };            };
1662            if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {            if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
1663              for (Int_t ih = 0; ih < op->npmtadc; ih++) {              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1664                Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1665                if (pl == 3) {                if (pl == 3) {
1666                  nphit_p++;                  nphit_p++;
1667                  enhit_p += (op->dedx).At(ih);                  enhit_p += (op->dedx).At(ih);
# Line 1443  void PamLevel2::SortTracks() { Line 1670  void PamLevel2::SortTracks() {
1670            };            };
1671            if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {            if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
1672              for (Int_t ih = 0; ih < op->npmtadc; ih++) {              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1673                Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1674                if (pl == 4) {                if (pl == 4) {
1675                  nphit_p++;                  nphit_p++;
1676                  enhit_p += (op->dedx).At(ih);                  enhit_p += (op->dedx).At(ih);
# Line 1452  void PamLevel2::SortTracks() { Line 1679  void PamLevel2::SortTracks() {
1679            };            };
1680    
1681            for (Int_t ih = 0; ih < oi->npmtadc; ih++) {            for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1682              Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));              Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1683              if (pl == 1 || pl == 2 || pl == 5) {              if (pl == 1 || pl == 2 || pl == 5) {
1684                nphit_i++;                nphit_i++;
1685                enhit_i += (op->dedx).At(ih);                enhit_i += (op->dedx).At(ih);
# Line 1463  void PamLevel2::SortTracks() { Line 1690  void PamLevel2::SortTracks() {
1690            //            //
1691            if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {            if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
1692              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1693                Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1694                if (pl == 0) {                if (pl == 0) {
1695                  nphit_i++;                  nphit_i++;
1696                  enhit_i += (op->dedx).At(ih);                  enhit_i += (op->dedx).At(ih);
# Line 1472  void PamLevel2::SortTracks() { Line 1699  void PamLevel2::SortTracks() {
1699            };            };
1700            if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {            if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
1701              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1702                Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1703                if (pl == 3) {                if (pl == 3) {
1704                  nphit_i++;                  nphit_i++;
1705                  enhit_i += (op->dedx).At(ih);                  enhit_i += (op->dedx).At(ih);
# Line 1481  void PamLevel2::SortTracks() { Line 1708  void PamLevel2::SortTracks() {
1708            };            };
1709            if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {            if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
1710              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1711                Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1712                if (pl == 4) {                if (pl == 4) {
1713                  nphit_i++;                  nphit_i++;
1714                  enhit_i += (op->dedx).At(ih);                  enhit_i += (op->dedx).At(ih);
# Line 1525  void PamLevel2::SortTracks() { Line 1752  void PamLevel2::SortTracks() {
1752             cout << "image: npmttdc "<< oi->npmttdc << endl;*/             cout << "image: npmttdc "<< oi->npmttdc << endl;*/
1753    
1754            //      for (Int_t ih=0; ih < op->npmtadc; ih++){            //      for (Int_t ih=0; ih < op->npmtadc; ih++){
1755            //        Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );            //        Int_t pl = tof2_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1756            //        if(pl == 1 || pl == 2 || pl == 5)nphit_p++;            //        if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
1757            //      };            //      };
1758    
1759            //      for (Int_t ih=0; ih < oi->npmtadc; ih++){            //      for (Int_t ih=0; ih < oi->npmtadc; ih++){
1760            //        Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );            //        Int_t pl = tof2_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1761            //        if(pl == 1 || pl == 2 || pl == 5)nphit_i++;            //        if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
1762            //      };            //      };
1763            // --- modified to count tdc signals (more efficient?)            // --- modified to count tdc signals (more efficient?)
1764            // --- and to implement check on tdcflag            // --- and to implement check on tdcflag
1765            for (Int_t ih = 0; ih < op->npmttdc; ih++) {            for (Int_t ih = 0; ih < op->npmttdc; ih++) {
1766              Int_t pl = tof_obj->GetPlaneIndex((op->pmttdc).At(ih));              Int_t pl = tof2_obj->GetPlaneIndex((op->pmttdc).At(ih));
1767              //      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++;
1768              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))
1769                  || (use_S3 && (pl == 4 || pl == 5))) {                  || (use_S3 && (pl == 4 || pl == 5))) {
# Line 1546  void PamLevel2::SortTracks() { Line 1773  void PamLevel2::SortTracks() {
1773            };            };
1774    
1775            for (Int_t ih = 0; ih < oi->npmttdc; ih++) {            for (Int_t ih = 0; ih < oi->npmttdc; ih++) {
1776              Int_t pl = tof_obj->GetPlaneIndex((oi->pmttdc).At(ih));              Int_t pl = tof2_obj->GetPlaneIndex((oi->pmttdc).At(ih));
1777              //      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++;
1778              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))
1779                  || (use_S3 && (pl == 4 || pl == 5))) {                  || (use_S3 && (pl == 4 || pl == 5))) {
# Line 1721  void PamLevel2::SortTracks() { Line 1948  void PamLevel2::SortTracks() {
1948    
1949  }  }
1950  ;  ;
1951    //
1952    //--------------------------------------
1953    /**
1954     * Sort physical (tracker) tracks.
1955     * @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...).
1956     * Sorting cryteria:
1957     * TRK: lower chi**2
1958     * CAL: lower Y spatial residual on the first calorimeter plane
1959     * TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis).
1960     * S1: (ask Emiliano)
1961     * S2: (ask Emiliano)
1962     * S3: (ask Emiliano)
1963     * GP: more GP hits
1964     * The default sorting cryterium is "TOF+CAL".
1965     *
1966     * 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).
1967     *
1968     * New version, with handling of extended tracks and nuclei tracks.
1969     */
1970    void PamLevel2::SortTracksNew() {
1971    
1972      //--------------------------------------------------
1973      //Check if the current event has already been sorted
1974      //--------------------------------------------------
1975      if (issorted_new && lastsorted_new == GetReadEntry()) {
1976          return; //already done for this event
1977      }
1978    
1979    
1980    //  cout << "SORT" << endl;
1981    
1982      //Reset the sort flags, just in case something will go wrong...
1983      issorted_new = false;
1984      lastsorted_new = -1;
1985    
1986      //--------------------------------------------------
1987      // set input variables
1988      //--------------------------------------------------
1989    
1990      TString how = howtosort;
1991      //Save current Object count
1992      Int_t ObjectNumber = TProcessID::GetObjectCount();
1993    
1994    
1995    
1996    
1997      TrkLevel2  * trk2 ;
1998      CaloLevel2 * calo2;
1999      ToFLevel2  * tof2  ;
2000      OrbitalInfo  * orb2 ;
2001      
2002      TClonesArray * trkext ;
2003      TClonesArray * caloext;
2004      TClonesArray * tofext ;
2005      TClonesArray * orbext ;
2006    
2007    
2008    //   cout << "trk2_obj" << trk2_obj<< endl;
2009    //   cout << "trk2_nuc_obj" << trk2_nuc_obj<< endl;
2010    //   cout << " trk_ext_obj "<<trk_ext_obj<< endl;
2011    //   cout << " trk_ext_nuc_obj "<<trk_ext_nuc_obj<< endl;
2012    
2013      //-----------------------------------------------------------
2014      // create/reset TCloneArrays to store tracks and their images
2015      //-----------------------------------------------------------
2016    
2017    //  cout << " PamLevel2::SortTracksNew() --- Clear TClonesArray objects"<<endl;
2018      
2019      // main tracks from standard alg
2020    //   if (!tsorted)
2021    //       tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2022    //   tsorted->Clear("C+C");//Delete();
2023    //   // track images from standard alg
2024    //   if (!timage)
2025    //       timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2026    //   timage->Clear("C+C");//Delete();
2027    //   // tracks from extended algorythm
2028    //   if(EXT && !text)
2029    //       text = new TClonesArray("PamTrack",trk_ext_obj->GetEntries());
2030    //   if(text)text->Clear("C+C");//Delete();
2031    
2032      if(tsorted)delete tsorted;
2033      if(timage) delete timage;
2034      if(text)   delete text;
2035      tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2036      timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2037      text = new TClonesArray("PamTrack",trk_ext_obj->GetEntries());
2038    
2039      //-----------------------------------------------------------
2040      // create/reset TCloneArrays to store tracks and their images
2041      //-----------------------------------------------------------
2042      if(NUC){
2043    
2044          
2045          if(tsorted_nuc)delete tsorted_nuc;
2046          if(timage_nuc) delete timage_nuc;
2047          if(text_nuc)   delete text_nuc;
2048          tsorted_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2049          timage_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2050          text_nuc = new TClonesArray("PamTrack",trk_ext_nuc_obj->GetEntries());
2051    
2052      // main tracks from standard alg
2053    //       if (!tsorted_nuc)
2054    //        tsorted_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2055    //       tsorted_nuc->Clear("C+C");//Delete();
2056    //       // track images from standard alg
2057    //       if (!timage_nuc)
2058    //        timage_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2059    //       timage_nuc->Clear("C+C");//Delete();
2060    //       // tracks from extended algorythm
2061    //       if(EXT && !text_nuc)
2062    //        text_nuc = new TClonesArray("PamTrack",trk_ext_nuc_obj->GetEntries());
2063    //       if(text_nuc)text_nuc->Clear("C+C");//Delete();
2064    
2065      }
2066      //--------------------------------------------------
2067      // retrieve sorting method
2068      //--------------------------------------------------
2069      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
2070      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
2071      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
2072      Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
2073      Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
2074      Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
2075      Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
2076    
2077      if (use_TOF) {
2078        use_S1 = true;
2079        use_S2 = true;
2080        use_S3 = true;
2081      };
2082      if (!CAL2 && use_CAL)
2083        use_CAL = false;
2084      if (!TOF) {
2085        use_TOF = false;
2086        use_S1 = false;
2087        use_S2 = false;
2088        use_S3 = false;
2089      }
2090      if (!GP) {
2091        use_GP = false;
2092      }
2093    
2094      if (!TRK2) {
2095        cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
2096        return;
2097      };
2098    
2099    
2100      ///////////////////////////////////////////////////////////////////////////////////
2101      //
2102      //   sort tracks and fill PamTrack arrays
2103      //
2104      ///////////////////////////////////////////////////////////////////////////////////
2105      for(int doit=0; doit<2; doit++){
2106    
2107    //       cout << "doit "<<doit<<endl;
2108    
2109    
2110          if(doit == 0){
2111    
2112              trk2  = trk2_obj;
2113              calo2 = calo2_obj;
2114              tof2  = tof2_obj;
2115              orb2  = orb2_obj;
2116          
2117              trkext = trk_ext_obj;
2118              caloext = calo_ext_obj;
2119              tofext = tof_ext_obj;
2120              orbext = orb_ext_obj;
2121        
2122          
2123          
2124          
2125    
2126          }else if (doit == 1){
2127    
2128              if(!NUC)break;
2129    
2130          
2131              trk2  = trk2_nuc_obj;
2132              calo2 = calo2_nuc_obj;
2133              tof2  = tof2_nuc_obj;
2134              orb2  = orb2_nuc_obj;
2135          
2136              trkext = trk_ext_nuc_obj;
2137              caloext = calo_ext_nuc_obj;
2138              tofext = tof_ext_nuc_obj;
2139              orbext = orb_ext_nuc_obj;
2140          
2141          
2142          
2143    
2144          }
2145    
2146    //       cout << "trk2" << trk2<<endl;
2147    //       cout << "calo2" << calo2<<endl;
2148    //       cout << "tof2" << tof2<<endl;
2149    //       cout << "orb2" << orb2<<endl;
2150    //       cout << "trkext" <<trkext <<endl;
2151    //       cout << "tofext" << tofext<<endl;
2152    //       cout << "caloext" << caloext<<endl;
2153    //       cout << "orbext" << orbext<<endl;
2154    
2155          TClonesArray &ttext    = (doit==0 ? *text : *text_nuc);
2156          TClonesArray &ttimage  = (doit==0 ? *timage : *timage_nuc);
2157          TClonesArray &ttsorted = (doit==0 ? *tsorted : *tsorted_nuc);
2158      
2159    //       cout << "tsorted + timage "<<doit<<endl;
2160    
2161          //--------------------------------------------------
2162          // loop over "physical" tracks sorted by the tracker
2163          //--------------------------------------------------
2164          for (Int_t i = 0; i < trk2->TrkLevel2::GetNTracks(); i++) {
2165    
2166              TrkTrack *ts = 0;
2167              CaloTrkVar *cs = 0;
2168              ToFTrkVar *os = 0;
2169              OrbitalInfoTrkVar *rs = 0;
2170    
2171              // get tracker tracks
2172              TrkTrack *tp = trk2->GetTrack(i); //tracker
2173              CaloTrkVar *cp = calo2->GetCaloStoredTrack(tp->GetSeqNo());
2174              ToFTrkVar *op = tof2->GetToFStoredTrack(tp->GetSeqNo());
2175              OrbitalInfoTrkVar *rp = orb2->GetOrbitalInfoStoredTrack(tp->GetSeqNo());
2176    
2177              TrkTrack *ti = 0; //tracker (image)
2178              CaloTrkVar *ci = 0;
2179              ToFTrkVar *oi = 0;
2180              OrbitalInfoTrkVar *ri = 0;
2181              //    cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
2182              // if track has an image, check image selection
2183    
2184              Int_t tp_score = 0; //main track sorted by the tracker
2185              Int_t ti_score = 0; //image track
2186              Int_t totp_score = 0; //main track sorted by the tracker
2187              Int_t toti_score = 0; //image track
2188    
2189              if (tp->HasImage()) {
2190    
2191                  ti = trk2->GetTrackImage(i); //tracker (image)
2192                  ci = calo2->GetCaloStoredTrack(ti->GetSeqNo());
2193                  oi = tof2->GetToFStoredTrack(ti->GetSeqNo());
2194                  ri = orb2->GetOrbitalInfoStoredTrack(ti->GetSeqNo());
2195    
2196                  //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
2197    
2198                  //assign starting scores
2199                  tp_score = 0; //main track sorted by the tracker
2200                  ti_score = 0; //image track
2201    
2202                  // -----------------------------------------------------------------------------------------
2203                  // *****************************************************************************************
2204                  // -----------------------------------------------------------------------------------------
2205                  // calorimeter check
2206                  // -----------------------------------------------------------------------------------------
2207                  if (use_CAL && !calo2) {
2208                      cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but CaloLevel2 not loaded !!!";
2209                      return;
2210                  };
2211                  if (use_CAL && !cp && ci) {
2212                      ti_score++;
2213                      toti_score++;
2214                  };
2215                  if (use_CAL && cp && !ci) {
2216                      tp_score++;
2217                      totp_score++;
2218                  };
2219                  if (use_CAL && cp && ci && true) {
2220    
2221                      if (cp->npresh > ci->npresh && true) {
2222                          tp_score++;
2223                          totp_score++;
2224                      };
2225                      if (cp->npresh < ci->npresh && true) {
2226                          ti_score++;
2227                          toti_score++;
2228                      };
2229    
2230                      //    cout << "CALO "<<tp_score<<ti_score<<endl;
2231    
2232                  };
2233                  // -----------------------------------------------------------------------------------------
2234                  // *****************************************************************************************
2235                  // -----------------------------------------------------------------------------------------
2236                  // TOF check
2237                  // -----------------------------------------------------------------------------------------
2238                  // check the number of hit pmts along the track
2239                  // on S12 S21 and S32, where paddles are parallel to Y axis
2240                  if ((use_TOF || use_S1 || use_S2 || use_S3) && !tof2) {
2241                      cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but ToFLevel2 not loaded !!!";
2242                      return;
2243                  };
2244                  //
2245                  if ((use_TOF || use_S1 || use_S2 || use_S3) && !op && oi) {
2246                      ti_score++;
2247                      toti_score++;
2248                  };
2249                  if ((use_TOF || use_S1 || use_S2 || use_S3) && op && !oi) {
2250                      tp_score++;
2251                      totp_score++;
2252                  };
2253                  if ((use_TOF || use_S1 || use_S2 || use_S3) && op && oi) {
2254                      //
2255                      Float_t sen = 0.;
2256                      for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2257                          Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2258                          if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
2259                              sen += (op->dedx).At(ih);
2260                      };
2261                      for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2262                          Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2263                          if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
2264                              sen += (oi->dedx).At(ih);
2265                      };
2266                      //
2267                      if (sen >= sortthr && false) { // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
2268                          //printf(" IS A NUCLEUS! en = %f \n",sen);
2269                          //
2270                          // is a nucleus use a different algorithm
2271                          //
2272                          Int_t nz = 6;
2273                          Float_t zin[6]; // << define TOF z-coordinates
2274                          for (Int_t ip = 0; ip < nz; ip++)
2275                              zin[ip] = tof2->GetZTOF(tof2->GetToFPlaneID(ip)); // << read ToF plane z-coordinates
2276                          Trajectory *tr = new Trajectory(nz, zin);
2277                          //
2278                          Int_t nphit_p = 0;
2279                          Int_t nphit_i = 0;
2280                          Float_t enhit_p = 0.;
2281                          Float_t enhit_i = 0.;
2282                          //
2283                          for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2284                              Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2285                              if (pl == 1 || pl == 2 || pl == 5) {
2286                                  nphit_p++;
2287                                  enhit_p += (op->dedx).At(ih);
2288                              };
2289                          };
2290                          //
2291                          tp->DoTrack2(tr);
2292                          //
2293                          if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
2294                              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2295                                  Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2296                                  if (pl == 0) {
2297                                      nphit_p++;
2298                                      enhit_p += (op->dedx).At(ih);
2299                                  };
2300                              };
2301                          };
2302                          if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
2303                              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2304                                  Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2305                                  if (pl == 3) {
2306                                      nphit_p++;
2307                                      enhit_p += (op->dedx).At(ih);
2308                                  };
2309                              };
2310                          };
2311                          if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
2312                              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2313                                  Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2314                                  if (pl == 4) {
2315                                      nphit_p++;
2316                                      enhit_p += (op->dedx).At(ih);
2317                                  };
2318                              };
2319                          };
2320    
2321                          for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2322                              Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2323                              if (pl == 1 || pl == 2 || pl == 5) {
2324                                  nphit_i++;
2325                                  enhit_i += (op->dedx).At(ih);
2326                              };
2327                          };
2328                          //
2329                          ti->DoTrack2(tr);
2330                          //
2331                          if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
2332                              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2333                                  Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2334                                  if (pl == 0) {
2335                                      nphit_i++;
2336                                      enhit_i += (op->dedx).At(ih);
2337                                  };
2338                              };
2339                          };
2340                          if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
2341                              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2342                                  Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2343                                  if (pl == 3) {
2344                                      nphit_i++;
2345                                      enhit_i += (op->dedx).At(ih);
2346                                  };
2347                              };
2348                          };
2349                          if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
2350                              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2351                                  Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2352                                  if (pl == 4) {
2353                                      nphit_i++;
2354                                      enhit_i += (op->dedx).At(ih);
2355                                  };
2356                              };
2357                          };
2358    
2359                          if ((use_TOF || use_S1 || use_S2 || use_S3) && (nphit_p + nphit_i) != 0 && true) {
2360    
2361                              //        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);
2362                              //        printf(" score p %i score i %i \n",tp_score,ti_score);
2363                              //              if( enhit_p > enhit_i ) tp_score++;
2364                              //              if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
2365                              if (nphit_p > nphit_i)
2366                                  tp_score++;
2367                              if (nphit_p < nphit_i)
2368                                  ti_score++;
2369                              if (nphit_p == nphit_i) {
2370                                  if (enhit_p > enhit_i)
2371                                      tp_score++;
2372                                  else
2373                                      ti_score++;
2374                              };
2375                              //        printf(" dopo score p %i score i %i \n",tp_score,ti_score);
2376                          };
2377                          delete tr;
2378                          //
2379                      }
2380                      else {
2381                          // -------------
2382                          // NOT a NUCLEUS
2383                          // -------------
2384                          //printf(" NOT a NUCLEUS! en = %f \n",sen);
2385    
2386                          Int_t nphit_p = 0;
2387                          Int_t nphit_i = 0;
2388    
2389                          /*                                cout << "track: npmtadc "<< op->npmtadc << endl;
2390                            cout << "track: npmttdc "<< op->npmttdc << endl;
2391                            cout << "image: npmtadc "<< oi->npmtadc << endl;
2392                            cout << "image: npmttdc "<< oi->npmttdc << endl;*/
2393    
2394                          //          for (Int_t ih=0; ih < op->npmtadc; ih++){
2395                          //            Int_t pl = tof2_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
2396                          //            if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
2397                          //          };
2398    
2399                          //          for (Int_t ih=0; ih < oi->npmtadc; ih++){
2400                          //            Int_t pl = tof2_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
2401                          //            if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
2402                          //          };
2403                          // --- modified to count tdc signals (more efficient?)
2404                          // --- and to implement check on tdcflag
2405                          for (Int_t ih = 0; ih < op->npmttdc; ih++) {
2406                              Int_t pl = tof2->GetPlaneIndex((op->pmttdc).At(ih));
2407                              //        if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
2408                              if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
2409                                  || (use_S3 && (pl == 4 || pl == 5))) {
2410                                  if ((op->tdcflag).At(ih) == 0)
2411                                      nphit_p++;
2412                              };
2413                          };
2414    
2415                          for (Int_t ih = 0; ih < oi->npmttdc; ih++) {
2416                              Int_t pl = tof2->GetPlaneIndex((oi->pmttdc).At(ih));
2417                              //        if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;
2418                              if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
2419                                  || (use_S3 && (pl == 4 || pl == 5))) {
2420                                  if ((oi->tdcflag).At(ih) == 0)
2421                                      nphit_i++;
2422                              };
2423                          };
2424    
2425                          if ((nphit_p + nphit_i) != 0 && true) {
2426    
2427                              if (nphit_p != nphit_i) {
2428                                  totp_score += nphit_p;
2429                                  toti_score += nphit_i;
2430                                  tp_score += nphit_p;
2431                                  ti_score += nphit_i;
2432                              };
2433                              //        if     ( nphit_p > nphit_i) tp_score+=nphit_p;
2434                              //        else if( nphit_p < nphit_i) ti_score+=nphit_i;
2435                              //        else ;//niente
2436                          };
2437                      };
2438                      //    cout << "TOF "<<tp_score<<ti_score<<endl;
2439                  };
2440    
2441                  //      if(tp_score == ti_score) use_TRK = true;
2442    
2443    
2444                  // -----------------------------------------------------------------------------------------
2445                  // *****************************************************************************************
2446                  // -----------------------------------------------------------------------------------------
2447                  // tracker check
2448                  // -----------------------------------------------------------------------------------------
2449                  // chi**2 difference is not always large enough to distinguish among
2450                  // the real track and its image.
2451                  // Tracker check will be applied always when calorimeter and tof information is ambiguous.
2452                  // *** MODIFIED ON AUGUST 2007 ***
2453                  if (use_TRK) {
2454                      //    if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
2455                      //    else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
2456    
2457                      // CHECK 1 : number of points along X
2458                      if (tp->GetNX() >= ti->GetNX()) {
2459                          tp_score++;
2460                          totp_score++;
2461                      };
2462                      if (tp->GetNX() <= ti->GetNX()) {
2463                          ti_score++;
2464                          toti_score++;
2465                      };
2466                      // CHECK 2 : number of points along Y
2467                      if (tp->GetNY() >= ti->GetNY()) {
2468                          tp_score++;
2469                          totp_score++;
2470                      };
2471                      if (tp->GetNY() <= ti->GetNY()) {
2472                          ti_score++;
2473                          toti_score++;
2474                      };
2475    
2476                      //    cout << "TRK "<<tp_score<<ti_score<<endl;
2477                  };
2478    
2479                  // -----------------------------------------------------------------------------------------
2480                  // *****************************************************************************************
2481                  // -----------------------------------------------------------------------------------------
2482                  // GPamela check
2483                  // -----------------------------------------------------------------------------------------
2484    
2485                  //---------------------------------------------------
2486                  // count the number of GP hits
2487                  //---------------------------------------------------
2488                  if (use_GP) {
2489                      int ngphits_p = 0;
2490                      int ngphits_i = 0;
2491                      float toll = 0.02; //200 micron
2492                      for (int ih = 0; ih < GetGPamela()->Nthspe; ih++) {
2493                          int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
2494                          if (tp && tp->YGood(ip) && fabs(tp->ym[ip] - GetGPamela()->Yavspe[ih]) < toll && true)
2495                              ngphits_p++;
2496                          if (ti && ti->YGood(ip) && fabs(ti->ym[ip] - GetGPamela()->Yavspe[ih]) < toll && true)
2497                              ngphits_i++;
2498                      }
2499                      if (ngphits_p > ngphits_i && true) {
2500                          tp_score++;
2501                          totp_score++;
2502                      }
2503                      if (ngphits_p < ngphits_i && true) {
2504                          ti_score++;
2505                          toti_score++;
2506                      }
2507                  }
2508    
2509                  // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2510                  // the winner is....
2511                  // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2512                  if (tp_score > ti_score) {
2513    
2514                  }
2515                  else if (tp_score < ti_score) {
2516    
2517                      ts = ti;//its image!!
2518                      cs = ci;
2519                      os = oi;
2520                      rs = ri;
2521                      Int_t totis = toti_score;
2522    
2523                      ti = tp;//its image!!
2524                      ci = cp;
2525                      oi = op;
2526                      ri = rp;
2527    
2528                      tp = ts;//its image!!
2529                      cp = cs;
2530                      op = os;
2531                      rp = rs;
2532    
2533                      toti_score = totp_score;
2534                      totp_score = totis;
2535    
2536                  }
2537                  else {
2538    
2539                      //    cout << "Warning - track image ambiguity not solved" << endl;
2540    
2541                  };
2542    
2543              }
2544              else {
2545                  totp_score = 1;
2546                  toti_score = 0;
2547    
2548                  //            ts = tp;
2549                  //            cs = cp;
2550                  //            os = op;
2551              };
2552    
2553              //    cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
2554              //    sorted_tracks->Add(ts);//save the track in the sorted array
2555              //    sorted_tracks.Add(ts);//save the track in the sorted array
2556              //    sorted_tracks.Add(tp);//save the track in the sorted array
2557              //    cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
2558              //    cout<<"o "<<tp<<endl;
2559              //    cout<<"o "<<cp<<endl;
2560              //    cout<<"o "<<op<<endl;
2561    
2562              new (ttsorted[i]) PamTrack(tp, cp, op, rp);
2563              new (ttimage[i]) PamTrack(ti, ci, oi, ri);
2564    
2565              ((PamTrack*) (ttsorted[i]))->SetPScore(totp_score);
2566              ((PamTrack*) (ttsorted[i]))->SetIScore(toti_score);
2567              ((PamTrack*) (ttimage[i]))->SetPScore(totp_score);
2568              ((PamTrack*) (ttimage[i]))->SetIScore(toti_score);
2569          };
2570    
2571    
2572    
2573    
2574    
2575    //   if (tsorted->GetEntries() != trk2->GetNTracks()) {
2576    //     cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() " << tsorted->GetEntries()
2577    //         << " != trk2->GetNTracks() = " << trk2->GetNTracks() << endl;
2578    //     tsorted->Delete();
2579    //     tsorted = 0;
2580    //     timage->Delete();
2581    //     timage = 0;
2582    //   }
2583    
2584    
2585    //       cout << "text "<<doit<<endl;
2586    
2587    
2588          //--------------------------------------------------
2589          // fill array with extended tracks (this is easy...)
2590          //--------------------------------------------------
2591          if(EXT){
2592              for(int it=0; it<trkext->GetEntries(); it++){
2593                  
2594                  new (ttext[it]) PamTrack((ExtTrack*)(*trkext)[it], (CaloTrkVar*)(*caloext)[it], (ToFTrkVar*)(*tofext)[it], (OrbitalInfoTrkVar*)(*orbext)[it]);
2595                  
2596              }
2597          }
2598          
2599    
2600    
2601      };
2602    
2603    
2604      //Restore Object count
2605      //To save space in the table keeping track of all referenced objects
2606      //We reset the object count to what it was at the beginning of the event.
2607      TProcessID::SetObjectCount(ObjectNumber);
2608    
2609      //Everything went fine so the current event can be tagged as sorted
2610      issorted_new = true;
2611      lastsorted_new = GetReadEntry();
2612    
2613    //   cout << " tsorted "<< tsorted << " "<<(tsorted ? tsorted->GetEntries() : 0)<<endl;
2614    //   cout << " timage  "<< timage  << " "<<(timage  ? timage->GetEntries() : 0)<<endl;
2615    //   cout << " text    "<< text    << " "<<(text    ? text->GetEntries() : 0)<<endl;
2616    
2617    
2618    };
2619  //--------------------------------------  //--------------------------------------
2620  //  //
2621  //  //
# Line 1729  void PamLevel2::SortTracks() { Line 2624  void PamLevel2::SortTracks() {
2624   * 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.
2625   * 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.
2626   */   */
2627    
2628  // TRefArray *PamLevel2::GetTracks(){  // TRefArray *PamLevel2::GetTracks(){
2629    
2630  // //  *-*-*-*-*-*-*-*-*-*-*-*-*  // //  *-*-*-*-*-*-*-*-*-*-*-*-*
# Line 1739  void PamLevel2::SortTracks() { Line 2635  void PamLevel2::SortTracks() {
2635  //     return &sorted_tracks;  //     return &sorted_tracks;
2636    
2637  //  };  //  };
 TClonesArray *PamLevel2::GetTracks() {  
2638    
   //  *-*-*-*-*-*-*-*-*-*-*-*-*  
   SortTracks();  
   //  *-*-*-*-*-*-*-*-*-*-*-*-*  
2639    
   return tsorted;  
   
 }  
 ;  
2640  //--------------------------------------  //--------------------------------------
2641  //  //
2642  //  //
2643  //--------------------------------------  //--------------------------------------
2644    
2645  /**  /**
2646   * Retrieves the it-th Pamela "physical" track.   * Retrieves the it-th Pamela "physical" track.
2647   * It override TrkLevel2::GetTrack(int it).   * It override TrkLevel2::GetTrack(int it).
2648   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
2649   */   */
2650  PamTrack *PamLevel2::GetTrack(int it) {  PamTrack *PamLevel2::GetTrackOld(int it) {
   
   //    if(!trk2_obj) return 0;  
2651    
2652    // //  *-*-*-*+-*-*-*-*-*-*-*-*-*    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;  
2653    
   //    cout << "PamLevel2::GetTrack(int it) "<<endl;  
2654    //  *-*-*-*-*-*-*-*-*-*-*-*-*    //  *-*-*-*-*-*-*-*-*-*-*-*-*
2655    SortTracks();    SortTracks();
2656    //  *-*-*-*-*-*-*-*-*-*-*-*-*    //  *-*-*-*-*-*-*-*-*-*-*-*-*
2657    if (!tsorted)    if (!tsorted)
2658      return 0;      return track;
2659    if (!tsorted->GetEntries())    if (!tsorted->GetEntries())
2660      return 0;      return track;
2661    
   PamTrack *track = 0;  
2662    
2663    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];  
2664      track = (PamTrack*)((*tsorted)[it]);      track = (PamTrack*)((*tsorted)[it]);
2665    }    }
2666    else {    else {
2667      cout << "PamLevel2::GetTrack(int) : tracker track SeqNo " << it << " does not exist (GetNTracks() = "      cout << "PamLevel2::GetTrackOld(int) : tracker track SeqNo " << it << " does not exist (GetNTracks() = "
2668          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
2669    };    };
2670    
2671    return track;    return track;
2672    
2673    };
2674    
2675    //PamTrack *PamLevel2::GetTrack(int it) { return GetTrack(it,trkAlg); };
2676    
2677    /**
2678     * Retrieves the it-th Pamela "physical" track.
2679     * It override TrkLevel2::GetTrack(int it).
2680     * @param it Track number, ranging from 0 to GetNTracks().
2681     * @param alg Algorythm, see SetTrakingAlgorythm(char *alg) for explanation.
2682     */
2683    PamTrack *PamLevel2::GetTrack(int it, const char* alg) {
2684    
2685        TString s(alg);
2686        if(!s.CompareTo("") ||!s.CompareTo("STD") )return GetTrackOld(it); //old algorythm
2687    
2688    
2689        SortTracksNew();
2690        // >> fill tsorted, timage and text
2691    
2692        if ( ( !s.Contains("EXTF", TString::kIgnoreCase) || !EXT )){ //not forced exteded-alg requested (or exteded-data missing)
2693    
2694            if( s.Contains("NUC")){
2695                if(
2696                    tsorted_nuc &&
2697                    it < tsorted_nuc->GetEntries() &&                             //enough tracks found
2698                    it >= 0 &&                                                //valid index
2699                    true) return (PamTrack*)((*tsorted_nuc)[it]);                 //ok return the track
2700            }else{
2701                if(
2702                    tsorted &&
2703                    it < tsorted->GetEntries() &&                             //enough tracks found
2704                    it >= 0 &&                                                //valid index
2705                    true )return (PamTrack*)((*tsorted)[it]);                 //ok return the track
2706            }
2707    
2708        }
2709        
2710    
2711        /////////////////////////////////////////////////////////////////////////
2712        /// if requested get track from extended algorythm output
2713        /////////////////////////////////////////////////////////////////////////
2714        
2715        if(s.Contains("EXT", TString::kIgnoreCase) && EXT){//if exteded-alg requested
2716            
2717            if(s.Contains("NUC")){
2718                if(
2719                    text_nuc &&
2720                    it < text_nuc->GetEntries() &&                             //enough tracks found
2721                    it >= 0 &&                                                //valid index
2722                    true) return (PamTrack*)((*text_nuc)[it]);
2723            }else{
2724                if(
2725                    text &&
2726                    it < text->GetEntries() &&                             //enough tracks found
2727                    it >= 0 &&                                                //valid index
2728                    true) return (PamTrack*)((*text)[it]);
2729            }
2730    
2731        };
2732        
2733        
2734        cout << "PamTrack *PamLevel2::GetTrack("<<it<<","<<alg<<") -- wrong track number or unrecognised algorithm"<<endl;
2735        
2736        return NULL;
2737    
2738    }
2739    ;
2740    TClonesArray *PamLevel2::GetTracks() {
2741    
2742      //  *-*-*-*-*-*-*-*-*-*-*-*-*
2743      SortTracks();
2744      //  *-*-*-*-*-*-*-*-*-*-*-*-*
2745    
2746      return tsorted;
2747    
2748  }  }
2749  ;  ;
2750    Int_t  PamLevel2::GetNTracks(const char* alg) {
2751    
2752    
2753    //    cout << " trk_nuc_obj->GetEntries() "<<trk_nuc_obj->GetEntries()<<" trk2_nuc_obj->GetNTracks() "<<trk2_nuc_obj->GetNTracks()<<endl;
2754    
2755        TString s(alg);
2756    
2757        if(!s.CompareTo("") || !s.CompareTo("STD"))return trk2_obj->TrkLevel2::GetNTracks(); //standard algorythm
2758            
2759        if(s.Contains("EXTF", TString::kIgnoreCase) && EXT){
2760            if(s.Contains("NUC", TString::kIgnoreCase) && NUC)return trk_ext_nuc_obj->GetEntries();//ok
2761            return trk_ext_obj->GetEntries();//ok
2762        }
2763        if( s.Contains("EXT", TString::kIgnoreCase) && EXT) {
2764            if(s.Contains("NUC", TString::kIgnoreCase) && NUC)
2765                return (trk2_nuc_obj->TrkLevel2::GetNTracks() ?  trk2_nuc_obj->TrkLevel2::GetNTracks() :  trk_ext_nuc_obj->GetEntries() );  
2766            return (trk2_obj->TrkLevel2::GetNTracks() ?  trk2_obj->TrkLevel2::GetNTracks() :  trk_ext_obj->GetEntries() );
2767        }
2768        if(s.Contains("NUC", TString::kIgnoreCase) && NUC )
2769            return trk2_nuc_obj->TrkLevel2::GetNTracks();
2770        
2771        cout << "Int_t  PamLevel2::GetNTracks("<<alg<<") -- unrecognised algorithm"<<endl;
2772    
2773        return 0;
2774    
2775    }
2776    
2777    
2778  //--------------------------------------  //--------------------------------------
2779  //  //
# Line 1815  PamTrack *PamLevel2::GetTrack(int it) { Line 2783  PamTrack *PamLevel2::GetTrack(int it) {
2783   * 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().
2784   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
2785   */   */
2786  PamTrack *PamLevel2::GetTrackImage(int it) {  PamTrack *PamLevel2::GetTrackImageOld(int it) {
2787    
2788    //  *-*-*-*-*-*-*-*-*-*-*-*-*    //  *-*-*-*-*-*-*-*-*-*-*-*-*
2789    SortTracks();    SortTracks();
# Line 1839  PamTrack *PamLevel2::GetTrackImage(int i Line 2807  PamTrack *PamLevel2::GetTrackImage(int i
2807      };      };
2808    }    }
2809    else {    else {
2810      cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo " << it << " does not exist (GetNTracks() = "      cout << "PamLevel2::GetTrackImageOld(int) : Tracker track SeqNo " << it << " does not exist (GetNTracks() = "
2811          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
2812    };    };
2813    
2814    return image;    return image;
2815  }  }
2816    /**
2817     * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().
2818     * @param it Track number, ranging from 0 to GetNTracks().
2819     * @param alg Algorythm, see SetTrakingAlgorythm(char *alg) for explanation.
2820     */
2821    PamTrack *PamLevel2::GetTrackImage(int it, const char* alg) {
2822    
2823        TString s(alg);
2824        if(!s.CompareTo("") || !s.CompareTo("STD"))return GetTrackImageOld(it); //old algorythm
2825    
2826    
2827        SortTracksNew();
2828        // >> fill tsorted, timage and text
2829    
2830        if ( ( !s.Contains("EXTF", TString::kIgnoreCase) || !EXT )){ //not forced exteded-alg requested (or exteded-data missing)
2831    
2832            if( s.Contains("NUC")){
2833                if(
2834                    tsorted_nuc &&
2835                    it < tsorted_nuc->GetEntries() &&                             //enough tracks found
2836                    it >= 0 &&                                                //valid index
2837                    true){
2838                    TClonesArray &t = *(tsorted_nuc);
2839                    PamTrack *temp = (PamTrack*) t[it];
2840                    if (temp->GetTrkTrack()->HasImage()) {
2841                        return (PamTrack*)((*timage_nuc)[it]);                 //ok return the track
2842                    }else{
2843                        return NULL;
2844                    }
2845                    
2846                }
2847            }else{
2848                if(
2849                    tsorted &&
2850                    it < tsorted->GetEntries() &&                             //enough tracks found
2851                    it >= 0 &&                                                //valid index
2852                    true ){
2853                    TClonesArray &t = *(tsorted);
2854                    PamTrack *temp = (PamTrack*) t[it];
2855                    if (temp->GetTrkTrack()->HasImage()) {              
2856                        return (PamTrack*)((*timage)[it]);                 //ok return the track
2857                    }else{
2858                        return NULL;
2859                    }
2860                }
2861            }
2862    
2863        }
2864    
2865        cout << "PamTrack *PamLevel2::GetTrackImage("<<it<<","<<alg<<") -- wrong track number or unrecognised algorithm"<<endl;
2866          
2867        return NULL;
2868    
2869    }
2870    ;
2871    
2872  //--------------------------------------  //--------------------------------------
2873  //  //
# Line 1934  TTree *PamLevel2::GetPamTree(TFile *f, T Line 2957  TTree *PamLevel2::GetPamTree(TFile *f, T
2957      if (!Trout)      if (!Trout)
2958        Trout = T;        Trout = T;
2959      else      else
2960        Trout->AddFriend(T);          Trout->AddFriend(T);
2961    }    }
2962    else {    else {
2963      cout << "Tracker      : missing tree" << endl;      cout << "Tracker      : missing tree" << endl;
# Line 2299  TChain *PamLevel2::GetPamTree(TList *fl, Line 3322  TChain *PamLevel2::GetPamTree(TList *fl,
3322    TChain *G = 0;    TChain *G = 0;
3323    
3324    TChain *L = 0;    TChain *L = 0;
3325      TChain *P = 0;
3326    
3327    if (TRK2 || TRK1 || TRKh)    if (TRK2 || TRK1 || TRKh)
3328      T = new TChain("Tracker");      T = new TChain("Tracker");
# Line 2318  TChain *PamLevel2::GetPamTree(TList *fl, Line 3342  TChain *PamLevel2::GetPamTree(TList *fl,
3342      B = new TChain("OrbitalInfo");      B = new TChain("OrbitalInfo");
3343    if (GP)    if (GP)
3344      G = new TChain("h20");      G = new TChain("h20");
3345      if (PROC)
3346        P = new TChain("ProcessingInfo");
3347    L = new TChain("SelectionList");    L = new TChain("SelectionList");
3348    
3349    // loop over files and create chains    // loop over files and create chains
# Line 2345  TChain *PamLevel2::GetPamTree(TList *fl, Line 3371  TChain *PamLevel2::GetPamTree(TList *fl,
3371          B->Add(name);          B->Add(name);
3372        if (GP)        if (GP)
3373          G->Add(name);          G->Add(name);
3374          if (P)
3375            P->Add(name);
3376        if (SELLI == 1)        if (SELLI == 1)
3377          L->Add(name);          L->Add(name);
3378      };       };
3379    };    };
3380    
3381    cout << "done chains\n";    cout << "done data-tree chains  "<<  T->GetNtrees() <<" \n";
3382    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;    cout << "----------------------------------------------------" << endl;
3383    
3384    // -------------------------------------------    // -------------------------------------------
3385    // make friends    // make friends
# Line 2434  TChain *PamLevel2::GetPamTree(TList *fl, Line 3462  TChain *PamLevel2::GetPamTree(TList *fl,
3462    //  =====================================    //  =====================================
3463    //  SET BRANCH-ADDRESS AFTER CHAIN+FRIEND    //  SET BRANCH-ADDRESS AFTER CHAIN+FRIEND
3464    //  =====================================    //  =====================================
3465    SetBranchAddress(Trout);    if( Trout->GetNtrees() )SetBranchAddress(Trout);
3466    
3467    //  ------------------------------------    //  ------------------------------------
3468    //  finally handle selection trees...    //  finally handle selection trees...
3469    //  (it is not friend of pamela tree)    //  (it is not friend of pamela tree)
3470    //  ------------------------------------    //  ------------------------------------
3471    
3472    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;    cout << "----------------------------------------------------" << endl;
3473    
3474    // Selection List    // Selection List
3475    if (L && SELLI == 1) {    if (L && SELLI == 1) {
# Line 2462  TChain *PamLevel2::GetPamTree(TList *fl, Line 3490  TChain *PamLevel2::GetPamTree(TList *fl,
3490      //          if(!Trout)Trout=O;      //          if(!Trout)Trout=O;
3491      //          else Trout->AddFriend("SelectionList");      //          else Trout->AddFriend("SelectionList");
3492      cout << "+SelectionList" << endl;      cout << "+SelectionList" << endl;
3493      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;      cout << "----------------------------------------------------" << endl;
3494    }    }
3495    else {    else {
3496      //  cout << "SelectionList  : missing tree"<<endl;      //  cout << "SelectionList  : missing tree"<<endl;
# Line 2470  TChain *PamLevel2::GetPamTree(TList *fl, Line 3498  TChain *PamLevel2::GetPamTree(TList *fl,
3498        L->Delete();        L->Delete();
3499    };    };
3500    
3501      //ProcessingInfo EM
3502      if ( P && P->GetEntries() ){
3503        cout << "----------------------------------------------------" << endl;
3504        cout << ">>> Found ProcessingInfo <<<" << endl;
3505        //  L->SetBranchAddress("RunEntry",&irun);
3506        P->SetBranchAddress("ProcInfo", &proc_obj);//NEWNEW
3507      }
3508    //  --------------------------------------------    //  --------------------------------------------
3509    //  return the pamela chain with all the friends    //  return the pamela chain with all the friends
3510    //  --------------------------------------------    //  --------------------------------------------
# Line 2488  TChain *PamLevel2::GetPamTree(TList *fl, Line 3523  TChain *PamLevel2::GetPamTree(TList *fl,
3523   */   */
3524  void PamLevel2::SetBranchAddress(TTree *t) {  void PamLevel2::SetBranchAddress(TTree *t) {
3525    
3526    TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");  //   TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
3527    TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");  //   TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
3528    TRKh = TRKh & t->GetBranchStatus("TrkHough");  //   TRKh = TRKh & t->GetBranchStatus("TrkHough");
3529    CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");  //   CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
3530    CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");  //   CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
3531    TOF = TOF & t->GetBranchStatus("ToFLevel2");  //   TOF = TOF & t->GetBranchStatus("ToFLevel2");
3532    TRG = TRG & t->GetBranchStatus("TrigLevel2");  //   TRG = TRG & t->GetBranchStatus("TrigLevel2");
3533    S4 = S4 & t->GetBranchStatus("S4Level2");  //   S4 = S4 & t->GetBranchStatus("S4Level2");
3534    ND = ND & t->GetBranchStatus("NDLevel2");  //   ND = ND & t->GetBranchStatus("NDLevel2");
3535    AC = AC & t->GetBranchStatus("AcLevel2");  //   AC = AC & t->GetBranchStatus("AcLevel2");
3536    ORB = ORB & t->GetBranchStatus("OrbitalInfo");  //   ORB = ORB & t->GetBranchStatus("OrbitalInfo");
3537    GP = GP & t->GetBranchStatus("h20");  //   GP = GP & t->GetBranchStatus("h20");
3538    
3539    
3540    // Tracker    // Tracker
3541    if (TRK1) {    if (TRK1) {
# Line 2509  void PamLevel2::SetBranchAddress(TTree * Line 3545  void PamLevel2::SetBranchAddress(TTree *
3545    if (TRK2) {    if (TRK2) {
3546      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));
3547      cout << "Tracker      : set branch address TrkLevel2" << endl;      cout << "Tracker      : set branch address TrkLevel2" << endl;
3548        NUC = t->GetBranchStatus("TrackNuclei");
3549        EXT = t->GetBranchStatus("RecoveredTrack") && (NUC ? t->GetBranchStatus("RecoveredTrackNuclei"): true );    
3550    };    };
3551    if (TRKh) {    if (TRKh) {
3552      t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));      t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
# Line 2569  void PamLevel2::SetBranchAddress(TTree * Line 3607  void PamLevel2::SetBranchAddress(TTree *
3607    
3608      cout << "h20          : set branch address GPamela " << endl;      cout << "h20          : set branch address GPamela " << endl;
3609    };    };
3610      if(NUC){
3611          
3612          cout << "Found nuclei-track branches" << endl;
3613    
3614          if( !trk_nuc_obj )trk_nuc_obj = new TClonesArray("TrkTrack");
3615          if( !calo_nuc_obj)calo_nuc_obj= new TClonesArray("CaloTrkVar");
3616          if( !tof_nuc_obj)tof_nuc_obj= new TClonesArray("ToFTrkVar");
3617          if( !orb_nuc_obj)orb_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3618          if (TRK2)t->                          SetBranchAddress("TrackNuclei",&trk_nuc_obj);
3619          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("TrackNuclei",&calo_nuc_obj);
3620          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("TrackNuclei",&tof_nuc_obj);
3621          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("TrackNuclei",&orb_nuc_obj);
3622    
3623          ///copy the vector content inside a "fake" object (all aother info are missing)    
3624    
3625          if( !trk2_nuc_obj )trk2_nuc_obj =  new TrkLevel2();
3626          if( !calo2_nuc_obj )calo2_nuc_obj =  new CaloLevel2();
3627          if( !tof2_nuc_obj )tof2_nuc_obj =  new ToFLevel2();
3628          if( !orb2_nuc_obj )orb2_nuc_obj =  new OrbitalInfo();
3629    //       *(trk2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*trk_nuc_obj);
3630    //       *(calo2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*calo_nuc_obj);
3631    //       *(tof2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*tof_nuc_obj);
3632    //       *(orb2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*orb_nuc_obj);
3633    
3634          trk2_nuc_obj->SetTrackArray(  trk_nuc_obj  );
3635          calo2_nuc_obj->SetTrackArray( calo_nuc_obj );
3636          tof2_nuc_obj->SetTrackArray(  tof_nuc_obj  );
3637          orb2_nuc_obj->SetTrackArray(  orb_nuc_obj  );
3638    
3639          
3640      }    
3641    
3642      if(EXT){
3643          
3644          cout << "Found extended tracking algorythm branches" << endl;
3645    
3646          if( !trk_ext_obj )trk_ext_obj = new TClonesArray("ExtTrack");
3647          if( !calo_ext_obj)calo_ext_obj= new TClonesArray("CaloTrkVar");
3648          if( !tof_ext_obj)tof_ext_obj= new TClonesArray("ToFTrkVar");
3649          if( !orb_ext_obj)orb_ext_obj= new TClonesArray("OrbitalInfoTrkVar");
3650          
3651          if (TRK2)t->                          SetBranchAddress("RecoveredTrack",&trk_ext_obj);
3652          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrack",&calo_ext_obj);
3653          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrack",&tof_ext_obj);
3654          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrack",&orb_ext_obj);
3655    
3656        
3657          if(NUC){
3658              if( !trk_ext_nuc_obj )trk_ext_nuc_obj = new TClonesArray("ExtTrack");
3659              if( !calo_ext_nuc_obj)calo_ext_nuc_obj= new TClonesArray("CaloTrkVar");
3660              if( !tof_ext_nuc_obj)tof_ext_nuc_obj= new TClonesArray("ToFTrkVar");
3661              if( !orb_ext_nuc_obj)orb_ext_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3662              if (TRK2)t->                          SetBranchAddress("RecoveredTrackNuclei",&trk_ext_nuc_obj);
3663              if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrackNuclei",&calo_ext_nuc_obj);
3664              if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrackNuclei",&tof_ext_nuc_obj);
3665              if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrackNuclei",&orb_ext_nuc_obj);
3666          }
3667      }    
3668  }  }
3669  /**  /**
3670   * Set branch addresses for Pamela friend trees   * Set branch addresses for Pamela friend trees
# Line 2593  void PamLevel2::SetBranchAddress(TChain Line 3688  void PamLevel2::SetBranchAddress(TChain
3688    if (TRK2) {    if (TRK2) {
3689      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
3690      cout << "Tracker      : set branch address TrkLevel2" << endl;      cout << "Tracker      : set branch address TrkLevel2" << endl;
3691        NUC = t->GetBranchStatus("TrackNuclei");
3692        EXT = t->GetBranchStatus("RecoveredTrack") && (NUC ? t->GetBranchStatus("RecoveredTrackNuclei"): true );
3693    };    };
3694    if (TRK1) {    if (TRK1) {
3695      t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));      t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
# Line 2606  void PamLevel2::SetBranchAddress(TChain Line 3703  void PamLevel2::SetBranchAddress(TChain
3703    // Calorimeter    // Calorimeter
3704    if (CAL2) {    if (CAL2) {
3705      t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));      t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
3706      cout << "Calorimeter  : set branch address CaloLevel2" << endl;      cout << "Calorimeter  : set branch address CaloLevel2" << endl;    
3707    };    };
3708    if (CAL1) {    if (CAL1) {
3709      t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));      t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
# Line 2664  void PamLevel2::SetBranchAddress(TChain Line 3761  void PamLevel2::SetBranchAddress(TChain
3761    //    cout << "SelectionList: set branch address EventEntry"<<endl;    //    cout << "SelectionList: set branch address EventEntry"<<endl;
3762    
3763    //     }    //     }
3764      if(NUC){
3765          
3766          cout << "Found nuclei-track branches" << endl;
3767    
3768          if( !trk_nuc_obj )trk_nuc_obj = new TClonesArray("TrkTrack");
3769          if( !calo_nuc_obj)calo_nuc_obj= new TClonesArray("CaloTrkVar");
3770          if( !tof_nuc_obj)tof_nuc_obj= new TClonesArray("ToFTrkVar");
3771          if( !orb_nuc_obj)orb_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3772          if (TRK2)t->                          SetBranchAddress("TrackNuclei",&trk_nuc_obj);
3773          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("TrackNuclei",&calo_nuc_obj);
3774          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("TrackNuclei",&tof_nuc_obj);
3775          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("TrackNuclei",&orb_nuc_obj);
3776          
3777          ///copy the vector content inside a "fake" object (all aother info are missing)    
3778    
3779          if( !trk2_nuc_obj )trk2_nuc_obj =  new TrkLevel2();
3780          if( !calo2_nuc_obj )calo2_nuc_obj =  new CaloLevel2();
3781          if( !tof2_nuc_obj )tof2_nuc_obj =  new ToFLevel2();
3782          if( !orb2_nuc_obj )orb2_nuc_obj =  new OrbitalInfo();
3783    
3784    //       *(trk2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*trk_nuc_obj);
3785    //       *(calo2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*calo_nuc_obj);
3786    //       *(tof2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*tof_nuc_obj);
3787    //       *(orb2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*orb_nuc_obj);
3788          trk2_nuc_obj->SetTrackArray(  trk_nuc_obj  );
3789          calo2_nuc_obj->SetTrackArray( calo_nuc_obj );
3790          tof2_nuc_obj->SetTrackArray(  tof_nuc_obj  );
3791          orb2_nuc_obj->SetTrackArray(  orb_nuc_obj  );
3792    
3793      }    
3794      if(EXT){
3795          
3796          cout << "Found extended tracking algorythm branches" << endl;
3797    
3798          t->SetBranchAddress("extAlgFlag",&extAlgFlag);
3799    
3800          if( !trk_ext_obj )trk_ext_obj = new TClonesArray("ExtTrack");
3801          if( !calo_ext_obj)calo_ext_obj= new TClonesArray("CaloTrkVar");
3802          if( !tof_ext_obj)tof_ext_obj= new TClonesArray("ToFTrkVar");
3803          if( !orb_ext_obj)orb_ext_obj= new TClonesArray("OrbitalInfoTrkVar");
3804          
3805          if (TRK2)t->                          SetBranchAddress("RecoveredTrack",&trk_ext_obj);
3806          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrack",&calo_ext_obj);
3807          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrack",&tof_ext_obj);
3808          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrack",&orb_ext_obj);
3809          
3810          if(NUC){
3811              if( !trk_ext_nuc_obj )trk_ext_nuc_obj = new TClonesArray("ExtTrack");
3812              if( !calo_ext_nuc_obj)calo_ext_nuc_obj= new TClonesArray("CaloTrkVar");
3813              if( !tof_ext_nuc_obj)tof_ext_nuc_obj= new TClonesArray("ToFTrkVar");
3814              if( !orb_ext_nuc_obj)orb_ext_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3815              if (TRK2)t->                          SetBranchAddress("RecoveredTrackNuclei",&trk_ext_nuc_obj);
3816              if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrackNuclei",&calo_ext_nuc_obj);
3817              if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrackNuclei",&tof_ext_nuc_obj);
3818              if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrackNuclei",&orb_ext_nuc_obj);
3819          }
3820      }    
3821      
3822  }  }
3823    
3824    /**
3825     * Set the tracking algorythm
3826     * @param alg String to choose the track.
3827     * "" --> take the output of the standard tracking algorythm
3828     * "STD" --> take the output of the standard tracking algorythm
3829     * "NUC" --> take the output of the standard tracking algorythm for nuclei cluster selection
3830     * "EXT" --> in case the standard tracking algorythm has not found any track, take the output of the extended one
3831     * "EXTF" --> force the extended tracking algorythm
3832     * "NUCEXT" --> as "EXT", but for nuclei
3833     * "NUCEXTF" --> as "EXTF", but for nuclei
3834     */
3835    // void PamLevel2::SetTrackingAlgorythm(const char *alg){
3836    
3837    
3838    //     TString s(alg);
3839    //     if(s.Contains("NUC", TString::kIgnoreCase) && !NUC)
3840    //      cout << "Warning! NUC algorythm requested, but branches are missing"<<endl;
3841    //     if(s.Contains("EXT", TString::kIgnoreCase) && !EXT)
3842    //      cout << "Warning! EXT algorythm requested, but branches are missing"<<endl;;
3843                
3844    //     trkAlg = alg;
3845    
3846    // };
3847    // const char* PamLevel2::GetTrackingAlgorythm(){
3848    
3849    
3850    //     cout<<endl<<" Implemented tracking algorythm: ";
3851    //     cout<<endl<<"  \"\" or \"STD\"  --> take the output of the standard tracking algorythm";
3852    //     cout<<endl<<"  \"NUC\"      --> take the output of the standard tracking algorythm for nuclei cluster selection";
3853    //     cout<<endl<<"  \"EXT\"      --> in case the standard tracking algorythm has not found any track,";
3854    //     cout<<endl<<"                 take the output of the extended one";
3855    //     cout<<endl<<"  \"EXTF\"     --> force the extended tracking algorythm";
3856    //     cout<<endl<<"  \"NUCEXT\"   --> as \"EXT\", but for nuclei ";
3857    //     cout<<endl<<"  \"NUCEXTF\"  --> as \"EXTF\", but for nuclei";
3858    
3859    //     cout<<endl;
3860    //     cout<<" <<Currently set algorythm>> "<<trkAlg<<endl;
3861    //     cout<<endl;
3862    
3863    //     return trkAlg;
3864    // };
3865    
3866    
3867    
3868  //--------------------------------------  //--------------------------------------
3869  //  //
3870  //  //
# Line 2700  TChain *PamLevel2::GetRunTree(TList *fl) Line 3898  TChain *PamLevel2::GetRunTree(TList *fl)
3898      };      };
3899    }    }
3900    
3901      cout << "done run chain  "<<  R->GetNtrees() <<" \n";
3902    
3903    
3904    if (RUN && R->GetNtrees()) {    if (RUN && R->GetNtrees()) {
3905    
3906      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
# Line 2739  TChain *PamLevel2::GetRunTree(TList *fl) Line 3940  TChain *PamLevel2::GetRunTree(TList *fl)
3940      cout << "----------------------------------------------------" << endl;      cout << "----------------------------------------------------" << endl;
3941    
3942    }    }
3943    else {  //   else {
3944      delete R;  //     delete R;
3945      R = 0;  //     R = 0;
3946    }  //   }
3947    
3948    run_tree = R;    run_tree = R;
3949    
# Line 2820  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4021  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4021      run_tree->GetEntry(irun);      run_tree->GetEntry(irun);
4022      if (!GetOrbitalInfo())      if (!GetOrbitalInfo())
4023        cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated " << endl;        cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated " << endl;
4024      if (gltsync)      if ( fUseDBinRunInfo ){
4025        delete gltsync; //Emiliano        if (gltsync)
4026      if (!dbc || (dbc && !dbc->IsConnected()))          delete gltsync; //Emiliano
4027        SetDBConnection(); //Emiliano        if (!dbc || (dbc && !dbc->IsConnected()))
4028      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
4029      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)
4030        dbc->Close();// Emiliano        if (dbc){
4031        delete dbc;          dbc->Close();// Emiliano
4032        dbc=0;          delete dbc;
4033      };          dbc=0;
4034    };        }
4035        }
4036      }
4037    // ---------------------------------------------------------------    // ---------------------------------------------------------------
4038    // retrieve OBT and absolute time of the event    // retrieve OBT and absolute time of the event
4039    // ---------------------------------------------------------------    // ---------------------------------------------------------------
# Line 2839  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4042  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4042    prevpktnum = pktnum;    prevpktnum = pktnum;
4043    if (GetOrbitalInfo()) {    if (GetOrbitalInfo()) {
4044      abstime = GetOrbitalInfo()->absTime;      abstime = GetOrbitalInfo()->absTime;
4045      obt = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano      if ( fUseDBinRunInfo ) obt = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano
4046      pktnum = GetOrbitalInfo()->pkt_num; // Emiliano      pktnum = GetOrbitalInfo()->pkt_num; // Emiliano
4047    }    }
4048    else {    else {
4049      abstime = GetRunInfo()->RUNHEADER_TIME;      abstime = GetRunInfo()->RUNHEADER_TIME;
4050      obt = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano      if ( fUseDBinRunInfo ) obt = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano
4051      pktnum = GetRunInfo()->RUNHEADER_PKT; // Emiliano      pktnum = GetRunInfo()->RUNHEADER_PKT; // Emiliano
4052    }    }
4053    
# Line 2852  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4055  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4055      printf("0abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);      printf("0abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4056      printf("0        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);      printf("0        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4057      printf("0        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);      printf("0        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4058      printf("0        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));      if ( fUseDBinRunInfo ) printf("0        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4059      printf("0        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);      printf("0        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4060      printf("0        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);      printf("0        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);
4061    }    }
# Line 2875  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4078  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4078      }      }
4079    
4080      //      //
4081        bool a = true;
4082        bool b = true;
4083        if ( fUseDBinRunInfo ){
4084          a = false;    
4085          b = false;
4086          if ( obt < gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) ) a = true;
4087          if ( obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ) b = true;
4088        }
4089      if ( iev < totrunentrymin || iev > totrunentrymax // entry is outside run limits      if ( iev < totrunentrymin || iev > totrunentrymax // entry is outside run limits
4090           || iev == 0 // or it is the first entry           || iev == 0 // or it is the first entry
4091           || (!isSync && (           || (!isSync && (
4092                           (abstime <= GetRunInfo()->RUNHEADER_TIME && obt < gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) ) // or it is outside obt limits (and abstime limits for security reasons)                           (abstime <= GetRunInfo()->RUNHEADER_TIME && a ) // or it is outside obt limits (and abstime limits for security reasons)
4093                           || (abstime >= GetRunInfo()->RUNTRAILER_TIME && obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ) ))// or it is outside obt limits (and abstime limits for security reasons)                           || (abstime >= GetRunInfo()->RUNTRAILER_TIME && b ) ))// or it is outside obt limits (and abstime limits for security reasons)
4094           ){ // check on abstime and obt needed to handle nested+DV_skipped packets           ){ // check on abstime and obt needed to handle nested+DV_skipped packets
4095                
4096        // check for a new run (ma prima il primo!)        // check for a new run (ma prima il primo!)
# Line 2887  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4098  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4098          printf("1abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);          printf("1abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4099          printf("1        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);          printf("1        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4100          printf("1        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);          printf("1        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4101          printf("1        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));          if ( fUseDBinRunInfo ) printf("1        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4102          printf("1        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);          printf("1        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4103          printf("1        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);          printf("1        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);
4104        }        }
# Line 2914  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4125  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4125          totrunentry += GetRunInfo()->NEVENTS;          totrunentry += GetRunInfo()->NEVENTS;
4126          totrunentrymax = totrunentry - 1 - prevshift; // prevshift is needed to handle nested+DV_skipped packets          totrunentrymax = totrunentry - 1 - prevshift; // prevshift is needed to handle nested+DV_skipped packets
4127          irun = r;                  irun = r;        
4128            if ( fUseDBinRunInfo ){
4129              a = false;    
4130              b = false;
4131              if ( obt < gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) ) a = true;
4132              if ( obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ) b = true;
4133            }
4134          if ( (iev >= totrunentrymin && iev <= totrunentrymax) || // entry is inside run limits          if ( (iev >= totrunentrymin && iev <= totrunentrymax) || // entry is inside run limits
4135               ( !isSync &&               ( !isSync &&
4136                 ( abstime >= GetRunInfo()->RUNHEADER_TIME  && obt >= gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) // or it is inside obt limits (and abstime limits for security reasons)                 ( abstime >= GetRunInfo()->RUNHEADER_TIME  && a // or it is inside obt limits (and abstime limits for security reasons)
4137                   && abstime <= GetRunInfo()->RUNTRAILER_TIME && obt <= gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)))  // or it is inside obt limits (and abstime limits for security reasons)                   && abstime <= GetRunInfo()->RUNTRAILER_TIME && b))  // or it is inside obt limits (and abstime limits for security reasons)
4138               ){ // check on abstime and obt needed to handle nested+DV_skipped packets               ){ // check on abstime and obt needed to handle nested+DV_skipped packets
4139            if ( totrunentrymin > iev ){ // there is a shift (nested+DV_skipped packets)            if ( totrunentrymin > iev ){ // there is a shift (nested+DV_skipped packets)
4140              if ( !isSync ){              if ( !isSync ){
# Line 2943  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4159  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4159                        
4160    
4161            //            //
4162            if (gltsync)            if ( fUseDBinRunInfo ){
4163              delete gltsync; // Emiliano              if (gltsync)
4164            if (!dbc || (dbc && !dbc->IsConnected()))                delete gltsync; // Emiliano
4165              SetDBConnection(); //Emiliano              if (!dbc || (dbc && !dbc->IsConnected()))
4166            gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano                SetDBConnection(); //Emiliano
4167            if (dbc){              gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano
4168              dbc->Close(); // Emiliano              TrkParams::Set(GetRunInfo(), dbc);
4169              delete dbc;              if (dbc){
4170              dbc=0;                dbc->Close(); // Emiliano
4171            }                          delete dbc;
4172            if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano                dbc=0;
4173              cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun              }          
4174                   << "  has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl;              if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano
4175              cout                cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun
4176                << "                                                            (NB!! in this case some events could be assigned to a wrong run)"                     << "  has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl;
4177                << endl;                cout
4178                    << "                                                            (NB!! in this case some events could be assigned to a wrong run)"
4179                    << endl;
4180                }
4181            }            }
4182            //            //
4183            if (DBG) printf(" found \n");            if (DBG) printf(" found \n");
# Line 3015  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4234  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4234          printf("2abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);          printf("2abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4235          printf("2        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);          printf("2        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4236          printf("2        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);          printf("2        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4237          printf("2        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));          if ( fUseDBinRunInfo ) printf("2        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4238          printf("2        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);          printf("2        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4239          printf("2        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);          printf("2        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);
4240        }        }
# Line 3106  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4325  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4325        // update the tracker parameters        // update the tracker parameters
4326        // (non ho trovato nessun altro modo sicuro di farlo...)        // (non ho trovato nessun altro modo sicuro di farlo...)
4327        // ----------------------------------------------------        // ----------------------------------------------------
4328        if (!dbc || (dbc && !dbc->IsConnected()))        if ( fUseDBinRunInfo ){
4329          SetDBConnection();          if (!dbc || (dbc && !dbc->IsConnected()))
4330        TrkParams::Set(GetRunInfo(), dbc);            SetDBConnection();
4331        if (dbc){          TrkParams::Set(GetRunInfo(), dbc);
4332          dbc->Close();          if (dbc){
4333          delete dbc;            dbc->Close();
4334          dbc=0;            delete dbc;
4335        };            dbc=0;
4336            }
4337          }
4338        //            cout << endl;        //            cout << endl;
4339        prevshift = 0;        prevshift = 0;
4340        yprevshift = 0;        yprevshift = 0;
# Line 3381  void PamLevel2::GetWhichTrees(TFile* f) Line 4602  void PamLevel2::GetWhichTrees(TFile* f)
4602    //    cout << "Checking file: "<<f->GetName()<<endl;    //    cout << "Checking file: "<<f->GetName()<<endl;
4603    if (!f || f->IsZombie()) {    if (!f || f->IsZombie()) {
4604      cout << "File: " << f->GetName() << " Non valid root file" << endl;      cout << "File: " << f->GetName() << " Non valid root file" << endl;
4605        fDiscarded = true;
4606      return;      return;
4607    }    }
4608    
# Line 3587  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4809  Bool_t PamLevel2::CheckLevel2File(TStrin
4809    TFile *f = new TFile(name.Data());    TFile *f = new TFile(name.Data());
4810    if (!f || f->IsZombie()) {    if (!f || f->IsZombie()) {
4811      cout << "File: " << f->GetName() << " discarded ---- Non valid root file" << endl;      cout << "File: " << f->GetName() << " discarded ---- Non valid root file" << endl;
4812        fDiscarded = true;
4813      return false;      return false;
4814    }    }
4815    //    cout << "Get list of keys: "<<f<<endl;    //    cout << "Get list of keys: "<<f<<endl;
# Line 3625  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4848  Bool_t PamLevel2::CheckLevel2File(TStrin
4848          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4849            cout << "File: " << f->GetName() << " discarded ---- SelectionList tree has " << nevt            cout << "File: " << f->GetName() << " discarded ---- SelectionList tree has " << nevt
4850                << " events instead of " << nev << endl;                << " events instead of " << nev << endl;
4851              fDiscarded = true;
4852            return false;            return false;
4853          }          }
4854          nev = nevt;          nev = nevt;
# Line 3639  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4863  Bool_t PamLevel2::CheckLevel2File(TStrin
4863          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4864            cout << "File: " << f->GetName() << " discarded ---- Trigger tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- Trigger tree has " << nevt << " events instead of "
4865                << nev << endl;                << nev << endl;
4866              fDiscarded = true;
4867            return false;            return false;
4868          }          }
4869          nev = nevt;          nev = nevt;
# Line 3652  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4877  Bool_t PamLevel2::CheckLevel2File(TStrin
4877          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4878            cout << "File: " << f->GetName() << " discarded ---- ToF tree has " << nevt << " events instead of " << nev            cout << "File: " << f->GetName() << " discarded ---- ToF tree has " << nevt << " events instead of " << nev
4879                << endl;                << endl;
4880              fDiscarded = true;
4881            return false;            return false;
4882          }          }
4883          nev = nevt;          nev = nevt;
# Line 3665  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4891  Bool_t PamLevel2::CheckLevel2File(TStrin
4891          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4892            cout << "File: " << f->GetName() << " discarded ---- S4 tree has " << nevt << " events instead of " << nev            cout << "File: " << f->GetName() << " discarded ---- S4 tree has " << nevt << " events instead of " << nev
4893                << endl;                << endl;
4894              fDiscarded = true;
4895            return false;            return false;
4896          }          }
4897          nev = nevt;          nev = nevt;
# Line 3679  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4906  Bool_t PamLevel2::CheckLevel2File(TStrin
4906          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4907            cout << "File: " << f->GetName() << " discarded ---- NeutronD tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- NeutronD tree has " << nevt << " events instead of "
4908                << nev << endl;                << nev << endl;
4909              fDiscarded = true;
4910            return false;            return false;
4911          }          }
4912          nev = nevt;          nev = nevt;
# Line 3692  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4920  Bool_t PamLevel2::CheckLevel2File(TStrin
4920          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4921            cout << "File: " << f->GetName() << " discarded ---- Anticounter tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- Anticounter tree has " << nevt << " events instead of "
4922                << nev << endl;                << nev << endl;
4923              fDiscarded = true;
4924            return false;            return false;
4925          }          }
4926          nev = nevt;          nev = nevt;
# Line 3705  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4934  Bool_t PamLevel2::CheckLevel2File(TStrin
4934          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4935            cout << "File: " << f->GetName() << " discarded ---- OrbitalInfo tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- OrbitalInfo tree has " << nevt << " events instead of "
4936                << nev << endl;                << nev << endl;
4937              fDiscarded = true;
4938            return false;            return false;
4939          }          }
4940          nev = nevt;          nev = nevt;
# Line 3718  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4948  Bool_t PamLevel2::CheckLevel2File(TStrin
4948          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4949            cout << "File: " << f->GetName() << " discarded ---- Tracker tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- Tracker tree has " << nevt << " events instead of "
4950                << nev << endl;                << nev << endl;
4951              fDiscarded = true;
4952            return false;            return false;
4953          }          }
4954          nev = nevt;          nev = nevt;
# Line 3741  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4972  Bool_t PamLevel2::CheckLevel2File(TStrin
4972          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4973            cout << "File: " << f->GetName() << " discarded ---- Calorimeter tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- Calorimeter tree has " << nevt << " events instead of "
4974                << nev << endl;                << nev << endl;
4975              fDiscarded = true;
4976            return false;            return false;
4977          }          }
4978          nev = nevt;          nev = nevt;
# Line 3763  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4995  Bool_t PamLevel2::CheckLevel2File(TStrin
4995          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4996            cout << "File: " << f->GetName() << " discarded ---- h20 tree has " << nevt << " events instead of " << nev            cout << "File: " << f->GetName() << " discarded ---- h20 tree has " << nevt << " events instead of " << nev
4997                << endl;                << endl;
4998              fDiscarded = true;
4999            return false;            return false;
5000          }          }
5001          nev = nevt;          nev = nevt;
# Line 3775  Bool_t PamLevel2::CheckLevel2File(TStrin Line 5008  Bool_t PamLevel2::CheckLevel2File(TStrin
5008      SELLI = (Int_t) SELLI__ok;      SELLI = (Int_t) SELLI__ok;
5009    if (SELLI == 0 && SELLI__ok) {    if (SELLI == 0 && SELLI__ok) {
5010      cout << "File: " << f->GetName() << " discarded ---- found SelectionList (it is not a full-event file)" << endl;      cout << "File: " << f->GetName() << " discarded ---- found SelectionList (it is not a full-event file)" << endl;
5011        fDiscarded = true;
5012      return false;      return false;
5013    }    }
5014    if (SELLI == 1 && !SELLI__ok) {    if (SELLI == 1 && !SELLI__ok) {
5015      cout << "File: " << f->GetName() << " discarded ---- SelectionList missing" << endl;      cout << "File: " << f->GetName() << " discarded ---- SelectionList missing" << endl;
5016        fDiscarded = true;
5017      return false;      return false;
5018    }    }
5019    
# Line 3817  Bool_t PamLevel2::CheckLevel2File(TStrin Line 5052  Bool_t PamLevel2::CheckLevel2File(TStrin
5052    
5053    if (CAL1 && !CAL1__ok) {    if (CAL1 && !CAL1__ok) {
5054      cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel1 branch" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel1 branch" << endl;
5055        fDiscarded = true;
5056      return false;      return false;
5057    };    };
5058    if (CAL2 && !CAL2__ok) {    if (CAL2 && !CAL2__ok) {
5059      cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel2 branch" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel2 branch" << endl;
5060        fDiscarded = true;
5061      return false;      return false;
5062    };    };
5063    if (TRK2 && !TRK2__ok) {    if (TRK2 && !TRK2__ok) {
5064      cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel2 branch" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel2 branch" << endl;
5065        fDiscarded = true;
5066      return false;      return false;
5067    };    };
5068    if (TRK1 && !TRK1__ok) {    if (TRK1 && !TRK1__ok) {
5069      cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel1 branch" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel1 branch" << endl;
5070        fDiscarded = true;
5071      return false;      return false;
5072    };    };
5073    if (TRKh && !TRKh__ok) {    if (TRKh && !TRKh__ok) {
5074      cout << "File: " << f->GetName() << " discarded ---- Missing TrkHough branch" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing TrkHough branch" << endl;
5075        fDiscarded = true;
5076      return false;      return false;
5077    };    };
5078    if (ORB && !ORB__ok) {    if (ORB && !ORB__ok) {
5079      cout << "File: " << f->GetName() << " discarded ---- Missing ORB tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing ORB tree" << endl;
5080        fDiscarded = true;
5081      return false;      return false;
5082    };    };
5083    if (AC && !AC__ok) {    if (AC && !AC__ok) {
5084      cout << "File: " << f->GetName() << " discarded ---- Missing AC tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing AC tree" << endl;
5085        fDiscarded = true;
5086      return false;      return false;
5087    };    };
5088    if (S4 && !S4__ok) {    if (S4 && !S4__ok) {
5089      cout << "File: " << f->GetName() << " discarded ---- Missing S4 tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing S4 tree" << endl;
5090        fDiscarded = true;
5091      return false;      return false;
5092    };    };
5093    if (TOF && !TOF__ok) {    if (TOF && !TOF__ok) {
5094      cout << "File: " << f->GetName() << " discarded ---- Missing ToF tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing ToF tree" << endl;
5095        fDiscarded = true;
5096      return false;      return false;
5097    };    };
5098    
5099    if (ND && !ND__ok) {    if (ND && !ND__ok) {
5100      cout << "File: " << f->GetName() << " discarded ---- Missing ND tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing ND tree" << endl;
5101        fDiscarded = true;
5102      return false;      return false;
5103    };    };
5104    if (TRG && !TRG__ok) {    if (TRG && !TRG__ok) {
5105      cout << "File: " << f->GetName() << " discarded ---- Missing Trigger tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing Trigger tree" << endl;
5106        fDiscarded = true;
5107      return false;      return false;
5108    };    };
5109    if (GP && !GP__ok) {    if (GP && !GP__ok) {
5110      cout << "File: " << f->GetName() << " discarded ---- Missing h20 tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing h20 tree" << endl;
5111        fDiscarded = true;
5112      return false;      return false;
5113    };    };
5114    
# Line 3961  void PamLevel2::CreateCloneTrees(TFile * Line 5208  void PamLevel2::CreateCloneTrees(TFile *
5208      //  cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;      //  cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;
5209      run_tree_clone->Fill();      run_tree_clone->Fill();
5210    }    }
5211    cout << "----------------------------------------------------" << endl;    if ( PROC ){
5212        proc_tree_clone->Branch("ProcessingInfo", "ProcInfo", GetPointerTo("ProcessingInfo"));
5213        cout << "ProcessingInfo: branch ProcessingInfo" << endl;  
5214        // ------------------
5215        // replicate processinginfo tree
5216        // ------------------
5217        //    cout << "----------------------------------------------------"<<endl;
5218        //    cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
5219        for (Int_t i = 0; i < proc_tree->GetEntries(); i++) {
5220          proc_tree->GetEntry(i);
5221          //        cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;
5222          proc_tree_clone->Fill();
5223        }
5224        if ( SELLI != 2 || true ){      
5225          proc_obj->runID = 0;
5226          TTimeStamp *dt = new TTimeStamp();
5227          proc_obj->date = dt->AsString();
5228          delete dt;
5229          proc_obj->commandLine = Form("PamelaLevel2 was called");
5230          proc_obj->outputFilename = "";
5231          proc_obj->localDir = gSystem->WorkingDirectory();
5232          proc_obj->uname = gSystem->GetFromPipe("uname -a");
5233          proc_obj->DB = Form("mysql://%s/%s",dbc->GetHost(),dbc->GetDB());
5234          proc_tree_clone->Fill();
5235        }
5236        cout << "----------------------------------------------------" << endl;
5237      }
5238    // ------------------------------------    // ------------------------------------
5239    // add branch with dead and live times    // add branch with dead and live times
5240    // ------------------------------------    // ------------------------------------
# Line 3994  void PamLevel2::CreateCloneTrees(TFile * Line 5266  void PamLevel2::CreateCloneTrees(TFile *
5266        pam_tree_clone[i]->Branch("TrkHough", "TrkHough", GetPointerTo("TrkHough"));        pam_tree_clone[i]->Branch("TrkHough", "TrkHough", GetPointerTo("TrkHough"));
5267        cout << "Tracker      : branch TrkHough" << endl;        cout << "Tracker      : branch TrkHough" << endl;
5268      };      };
5269        if(NUC){
5270            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&trk_nuc_obj);
5271            cout << "Tracker      : branch TrackNuclei" << endl;    
5272        }
5273        if(EXT){
5274            pam_tree_clone[i]->Branch("extAlgFlag",&extAlgFlag,"extAlgFlag/I");
5275            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&trk_ext_obj);
5276            cout << "Tracker      : branch RecoveredTrack" << endl;
5277            if(NUC){
5278                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&trk_ext_nuc_obj);
5279                cout << "Tracker      : branch RecoveredTrackNuclei" << endl;                  
5280            }
5281        }
5282    
5283      i++;      i++;
5284    }    }
5285    
# Line 4008  void PamLevel2::CreateCloneTrees(TFile * Line 5294  void PamLevel2::CreateCloneTrees(TFile *
5294        pam_tree_clone[i]->Branch("CaloLevel2", "CaloLevel2", GetPointerTo("CaloLevel2"));        pam_tree_clone[i]->Branch("CaloLevel2", "CaloLevel2", GetPointerTo("CaloLevel2"));
5295        cout << "Calorimeter  : branch CaloLevel2" << endl;        cout << "Calorimeter  : branch CaloLevel2" << endl;
5296      };      };
5297        if(NUC){
5298            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&calo_nuc_obj);
5299            cout << "Calorimeter  : branch TrackNuclei" << endl;    
5300        }
5301        if(EXT){
5302            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&calo_ext_obj);
5303            cout << "Calorimeter  : branch RecoveredTrack" << endl;
5304            if(NUC){
5305                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&calo_ext_nuc_obj);
5306                cout << "Calorimeter  : branch RecoveredTrackNuclei" << endl;                  
5307            }
5308        }
5309      i++;      i++;
5310    }    }
5311    
# Line 4016  void PamLevel2::CreateCloneTrees(TFile * Line 5314  void PamLevel2::CreateCloneTrees(TFile *
5314      pam_tree_clone[i] = new TTree("ToF", "PAMELA ToF level2 data ");      pam_tree_clone[i] = new TTree("ToF", "PAMELA ToF level2 data ");
5315      pam_tree_clone[i]->Branch("ToFLevel2", "ToFLevel2", GetPointerTo("ToFLevel2"));      pam_tree_clone[i]->Branch("ToFLevel2", "ToFLevel2", GetPointerTo("ToFLevel2"));
5316      cout << "ToF          : branch ToFLevel2" << endl;      cout << "ToF          : branch ToFLevel2" << endl;
5317        if(NUC){
5318            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&tof_nuc_obj);
5319            cout << "ToF          : branch TrackNuclei" << endl;    
5320        }
5321        if(EXT){
5322            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&tof_ext_obj);
5323            cout << "ToF          : branch RecoveredTrack" << endl;
5324            if(NUC){
5325                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&tof_ext_nuc_obj);
5326                cout << "ToF          : branch RecoveredTrackNuclei" << endl;                  
5327            }
5328        }
5329      i++;      i++;
5330    };    };
5331    // Trigger    // Trigger
# Line 4051  void PamLevel2::CreateCloneTrees(TFile * Line 5361  void PamLevel2::CreateCloneTrees(TFile *
5361      pam_tree_clone[i] = new TTree("OrbitalInfo", "PAMELA orbital info  ");      pam_tree_clone[i] = new TTree("OrbitalInfo", "PAMELA orbital info  ");
5362      pam_tree_clone[i]->Branch("OrbitalInfo", "OrbitalInfo", GetPointerTo("OrbitalInfo"));      pam_tree_clone[i]->Branch("OrbitalInfo", "OrbitalInfo", GetPointerTo("OrbitalInfo"));
5363      cout << "OrbitalInfo  : branch OrbitalInfo" << endl;      cout << "OrbitalInfo  : branch OrbitalInfo" << endl;
5364        if(NUC){
5365            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&orb_nuc_obj);
5366            cout << "OrbitalInfo  : branch TrackNuclei" << endl;    
5367        }
5368        if(EXT){
5369            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&orb_ext_obj);
5370            cout << "OrbitalInfo  : branch RecoveredTrack" << endl;
5371            if(NUC){
5372                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&orb_ext_nuc_obj);
5373                cout << "OrbitalInfo  : branch RecoveredTrackNuclei" << endl;                  
5374            }
5375        }
5376      i++;      i++;
5377    };    };
5378    // GPamela    // GPamela
# Line 4060  void PamLevel2::CreateCloneTrees(TFile * Line 5382  void PamLevel2::CreateCloneTrees(TFile *
5382      cout << "GPamela  : branch GPamela" << endl;      cout << "GPamela  : branch GPamela" << endl;
5383      i++;      i++;
5384    };    };
5385    
5386    
5387    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
5388    
5389  }  }
# Line 4101  TTree* PamLevel2::GetCloneTree(TString n Line 5425  TTree* PamLevel2::GetCloneTree(TString n
5425      if (!name.CompareTo(na))      if (!name.CompareTo(na))
5426        return sel_tree_clone;        return sel_tree_clone;
5427    }    }
5428      if (proc_tree_clone && PROC) {
5429        TString na = proc_tree_clone->GetName();
5430        if (!name.CompareTo(na))
5431          return proc_tree_clone;
5432      }
5433    return NULL;    return NULL;
5434    
5435  }  }
# Line 4120  void PamLevel2::WriteCloneTrees() { Line 5449  void PamLevel2::WriteCloneTrees() {
5449    for (Int_t i = 0; i < NCLONES; i++) {    for (Int_t i = 0; i < NCLONES; i++) {
5450      if (pam_tree_clone[i]) {      if (pam_tree_clone[i]) {
5451        cout << pam_tree_clone[i]->GetName() << endl;        cout << pam_tree_clone[i]->GetName() << endl;
5452        pam_tree_clone[i]->Write();        pam_tree_clone[i]->Write(pam_tree_clone[i]->GetName(),TObject::kOverwrite);
5453      };      };
5454    }    }
5455      
5456      if ( PROC ){
5457        proc_tree_clone->Write("ProcessingInfo",TObject::kOverwrite);
5458      }
5459    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
5460    
5461  }  }
# Line 4385  Int_t PamLevel2::GetYodaEntry() { Line 5718  Int_t PamLevel2::GetYodaEntry() {
5718          cout << "  " << endl;          cout << "  " << endl;
5719        }        }
5720        if (shift > 0) {        if (shift > 0) {
5721          cout << " PKTNUM  L2 --- " << pktn << " --- L0 --- " << GetEventHeader()->GetPscuHeader()->GetCounter() << endl;          if (DBG) cout << " PKTNUM  L2 --- " << pktn << " --- L0 --- " << GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
5722          if (DBG)          if (DBG)
5723            cout << "         RUN: ID " << GetRunInfo()->ID << " ID_ROOT_L0 " << run_obj->ID_ROOT_L0 << " ID_RUN_FRAG "            cout << "         RUN: ID " << GetRunInfo()->ID << " ID_ROOT_L0 " << run_obj->ID_ROOT_L0 << " ID_RUN_FRAG "
5724                 << GetRunInfo()->ID_RUN_FRAG << " EV_FROM " << GetRunInfo()->EV_FROM << endl;                 << GetRunInfo()->ID_RUN_FRAG << " EV_FROM " << GetRunInfo()->EV_FROM << endl;
# Line 4567  Int_t PamLevel2::GetYodaEntry() { Line 5900  Int_t PamLevel2::GetYodaEntry() {
5900                
5901          while ( (obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta + (Long64_t) shift) < GetYodaTree()->GetEntries() && shift < maxshift ){          while ( (obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta + (Long64_t) shift) < GetYodaTree()->GetEntries() && shift < maxshift ){
5902            if (shift > 0) {            if (shift > 0) {
5903              cout << " PKTNUM  L2 --- " << pktn << " --- L0 --- " << GetEventHeader()->GetPscuHeader()->GetCounter() << endl;              if (DBG) cout << " PKTNUM  L2 --- " << pktn << " --- L0 --- " << GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
5904              if (DBG)              if (DBG)
5905                cout << "         RUN: ID " << GetRunInfo()->ID << " ID_ROOT_L0 " << run_obj->ID_ROOT_L0 << " ID_RUN_FRAG "                cout << "         RUN: ID " << GetRunInfo()->ID << " ID_ROOT_L0 " << run_obj->ID_ROOT_L0 << " ID_RUN_FRAG "
5906                     << GetRunInfo()->ID_RUN_FRAG << " EV_FROM " << GetRunInfo()->EV_FROM << endl;                     << GetRunInfo()->ID_RUN_FRAG << " EV_FROM " << GetRunInfo()->EV_FROM << endl;
# Line 4744  Long64_t PamLevel2::GetReadEntry() { Line 6077  Long64_t PamLevel2::GetReadEntry() {
6077  void PamLevel2::SetSortingMethod(TString how) {  void PamLevel2::SetSortingMethod(TString how) {
6078    if (howtosort != how) {    if (howtosort != how) {
6079      issorted = false;      issorted = false;
6080        issorted_new = false;
6081    }    }
6082    howtosort = how;    howtosort = how;
6083  }  }

Legend:
Removed from v.1.91  
changed lines
  Added in v.1.100

  ViewVC Help
Powered by ViewVC 1.1.23