/[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.93 by mocchiut, Thu Jan 16 15:36:32 2014 UTC revision 1.109 by mocchiut, Tue Oct 21 10:08:36 2014 UTC
# 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 520  void PamLevel2::Initialize() { Line 628  void PamLevel2::Initialize() {
628    if (strcmp(pamdbpsw, ""))    if (strcmp(pamdbpsw, ""))
629      psw = pamdbpsw;      psw = pamdbpsw;
630    
631      customString = "";
632    
633    //    sorted_tracks = 0;//new TRefArray();    //    sorted_tracks = 0;//new TRefArray();
634    
635    CAL0 = false;    CAL0 = false;
# Line 536  void PamLevel2::Initialize() { Line 646  void PamLevel2::Initialize() {
646    ND = true;    ND = true;
647    AC = true;    AC = true;
648    ORB = true;    ORB = true;
649      PROC = true;
650    GP = false;    GP = false;
651    
652      EXT = false;
653      NUC = false;
654      trkAlg = "STD";//default tracking algorythm
655    
656    RUN = true;    RUN = true;
657    
658    SELLI = -1;    SELLI = -1;
# Line 548  void PamLevel2::Initialize() { Line 663  void PamLevel2::Initialize() {
663    
664    tsorted = 0;    tsorted = 0;
665    timage = 0;    timage = 0;
666      text = 0 ;
667    
668      tsorted_nuc = 0;
669      timage_nuc = 0;
670      text_nuc = 0 ;
671    
672    howtosort = "+CAL+TOF";    howtosort = "+CAL+TOF";
673    //howtosort = "+TOF";    //howtosort = "+TOF";
# Line 555  void PamLevel2::Initialize() { Line 675  void PamLevel2::Initialize() {
675    
676    issorted = false;    issorted = false;
677    lastsorted = -1;    lastsorted = -1;
678      issorted_new = false;
679      lastsorted_new = -1;
680    
681  }  }
682  ;  ;
# Line 567  void PamLevel2::Delete() { Line 689  void PamLevel2::Delete() {
689      delete run_obj;      delete run_obj;
690    if (soft_obj)    if (soft_obj)
691      delete soft_obj; //Emiliano      delete soft_obj; //Emiliano
692      if (proc_obj)
693        delete proc_obj; //Emiliano
694    
695    //    cout << "void PamLevel2::Clear()"<<endl;    //    cout << "void PamLevel2::Clear()"<<endl;
696    if (h0_obj)    if (h0_obj)
# Line 585  void PamLevel2::Delete() { Line 709  void PamLevel2::Delete() {
709      delete calo1_obj;      delete calo1_obj;
710    if (calo2_obj)    if (calo2_obj)
711      delete calo2_obj;      delete calo2_obj;
712    if (tof_obj)    if (tof2_obj)
713      delete tof_obj;      delete tof2_obj;
714    if (trig_obj)    if (trig_obj)
715      delete trig_obj;      delete trig_obj;
716    if (s4_obj)    if (s4_obj)
# Line 595  void PamLevel2::Delete() { Line 719  void PamLevel2::Delete() {
719      delete nd_obj;      delete nd_obj;
720    if (ac_obj)    if (ac_obj)
721      delete ac_obj;      delete ac_obj;
722    if (orb_obj)    if (orb2_obj)
723      delete orb_obj;      delete orb2_obj;
724    if (gp_obj)    if (gp_obj)
725      delete gp_obj;      delete gp_obj;
726    
727      if(trk_nuc_obj)trk_nuc_obj->Delete();
728      if(trk_ext_obj)trk_ext_obj->Delete();
729      if(trk_ext_nuc_obj)trk_ext_nuc_obj->Delete();
730    
731      if(calo_nuc_obj)calo_nuc_obj->Delete();
732      if(calo_ext_obj)calo_ext_obj->Delete();
733      if(calo_ext_nuc_obj)calo_ext_nuc_obj->Delete();
734    
735      if(tof_nuc_obj)tof_nuc_obj->Delete();
736      if(tof_ext_obj)tof_ext_obj->Delete();
737      if(tof_ext_nuc_obj)tof_ext_nuc_obj->Delete();
738    
739      if(orb_nuc_obj)orb_nuc_obj->Delete();
740      if(orb_ext_obj)orb_ext_obj->Delete();
741      if(orb_ext_nuc_obj)orb_ext_nuc_obj->Delete();
742    
743    
744      if(trk2_nuc_obj)trk2_nuc_obj->Delete();;
745      if( calo2_nuc_obj)calo2_nuc_obj->Delete();;
746      if(tof2_nuc_obj)tof2_nuc_obj->Delete();;
747      if(orb2_nuc_obj)orb2_nuc_obj->Delete();;
748      
749    
750    
751    if (tsorted) {    if (tsorted) {
752      tsorted->Delete();      tsorted->Delete();
753      delete tsorted;      delete tsorted;
# Line 608  void PamLevel2::Delete() { Line 756  void PamLevel2::Delete() {
756      timage->Delete();      timage->Delete();
757      delete timage;      delete timage;
758    }    }
759      if (text) {
760        text->Delete();
761        delete text;
762      }
763      if (tsorted_nuc) {
764        tsorted_nuc->Delete();
765        delete tsorted_nuc;
766      }
767      if (timage_nuc) {
768        timage_nuc->Delete();
769        delete timage_nuc;
770      }
771      if (text_nuc) {
772        text_nuc->Delete();
773        delete text_nuc;
774      }
775    
776    
777    
778    if (dbc) {    if (dbc) {
779      dbc->Close();      dbc->Close();
# Line 675  void PamLevel2::Delete() { Line 841  void PamLevel2::Delete() {
841    if (irunoffset)    if (irunoffset)
842      delete[] irunoffset;      delete[] irunoffset;
843    
844    
845      Initialize();
846    
847  }  }
848  ;  ;
849    
# Line 708  void PamLevel2::Clear() { Line 877  void PamLevel2::Clear() {
877      calo1_obj->Clear();      calo1_obj->Clear();
878    if (calo2_obj)    if (calo2_obj)
879      calo2_obj->Clear();      calo2_obj->Clear();
880    if (tof_obj)    if (tof2_obj)
881      tof_obj->Clear();      tof2_obj->Clear();
882    if (trig_obj)    if (trig_obj)
883      trig_obj->Clear();      trig_obj->Clear();
884    if (s4_obj)    if (s4_obj)
# Line 718  void PamLevel2::Clear() { Line 887  void PamLevel2::Clear() {
887      nd_obj->Clear();      nd_obj->Clear();
888    if (ac_obj)    if (ac_obj)
889      ac_obj->Clear();      ac_obj->Clear();
890    if (orb_obj)    if (orb2_obj)
891      orb_obj->Clear();      orb2_obj->Clear();
892    if (gp_obj)    if (gp_obj)
893      gp_obj->Clear();      gp_obj->Clear();
894      if (proc_obj)
895        proc_obj->Clear();
896    
897    //    if(sorted_tracks)sorted_tracks->Clear();    //    if(sorted_tracks)sorted_tracks->Clear();
898    //    sorted_tracks.Clear();    //    sorted_tracks.Clear();
899    
900    if (tsorted) {    if(trk_nuc_obj)trk_nuc_obj->Clear();
901      tsorted->Delete();    if(trk_ext_obj)trk_ext_obj->Clear();
902    }    if(trk_ext_nuc_obj)trk_ext_nuc_obj->Clear();
903    if (timage) {  
904      timage->Delete();    if(calo_nuc_obj)calo_nuc_obj->Clear();
905    }    if(calo_ext_obj)calo_ext_obj->Clear();
906      if(calo_ext_nuc_obj)calo_ext_nuc_obj->Clear();
907    
908      if(tof_nuc_obj)tof_nuc_obj->Clear();
909      if(tof_ext_obj)tof_ext_obj->Clear();
910      if(tof_ext_nuc_obj)tof_ext_nuc_obj->Clear();
911    
912      if(orb_nuc_obj)orb_nuc_obj->Clear();
913      if(orb_ext_obj)orb_ext_obj->Clear();
914      if(orb_ext_nuc_obj)orb_ext_nuc_obj->Clear();
915    
916      if(trk2_nuc_obj)trk2_nuc_obj->Clear();;
917      if( calo2_nuc_obj)calo2_nuc_obj->Clear();;
918      if(tof2_nuc_obj)tof2_nuc_obj->Clear();;
919      if(orb2_nuc_obj)orb2_nuc_obj->Clear();;
920    
921      if (tsorted)tsorted->Delete();
922      if (timage)timage->Delete();
923      if (text) text->Delete();
924    
925      if (tsorted_nuc)tsorted_nuc->Delete();
926      if (timage_nuc)timage_nuc->Delete();
927      if (text_nuc) text_nuc->Delete();
928  }  }
929  ;  ;
930    
# Line 780  void PamLevel2::Reset() { Line 973  void PamLevel2::Reset() {
973    if (sel_tree)    if (sel_tree)
974      sel_tree->Delete();;      sel_tree->Delete();;
975    sel_tree = NULL;    sel_tree = NULL;
976    
977      if (proc_tree)
978        proc_tree->Delete();
979      proc_tree = NULL;
980    //    //
981    // Close file    // Close file
982    //    //
# Line 796  void PamLevel2::Reset() { Line 993  void PamLevel2::Reset() {
993    trkh_obj = 0;    trkh_obj = 0;
994    calo1_obj = 0;    calo1_obj = 0;
995    calo2_obj = 0;    calo2_obj = 0;
996    tof_obj = 0;    tof2_obj = 0;
997    trig_obj = 0;    trig_obj = 0;
998    s4_obj = 0;    s4_obj = 0;
999    nd_obj = 0;    nd_obj = 0;
1000    ac_obj = 0;    ac_obj = 0;
1001    orb_obj = 0;    orb2_obj = 0;
1002    gp_obj = 0;    gp_obj = 0;
1003      proc_obj = 0;
1004    
1005      trk_ext_obj     = 0;
1006      trk_ext_nuc_obj = 0;
1007      trk_nuc_obj     = 0;
1008      
1009      calo_ext_obj     = 0;
1010      calo_ext_nuc_obj = 0;
1011      calo_nuc_obj     = 0;
1012      
1013      tof_ext_obj     = 0;
1014      tof_ext_nuc_obj = 0;
1015      tof_nuc_obj     = 0;
1016      
1017      orb_ext_obj     = 0;
1018      orb_ext_nuc_obj = 0;
1019      orb_nuc_obj     = 0;
1020    
1021      trk2_nuc_obj  = 0;
1022      calo2_nuc_obj = 0;
1023      tof2_nuc_obj  = 0;
1024      orb2_nuc_obj  = 0;
1025    
1026      trk2_nuc_obj  = 0;
1027      calo2_nuc_obj = 0;
1028      tof2_nuc_obj  = 0;
1029      orb2_nuc_obj  = 0;
1030    //    //
1031    // Reset run pointers    // Reset run pointers
1032    //    //
1033    run_obj = 0;//new GL_RUN();    run_obj = 0;//new GL_RUN();
1034    soft_obj = 0;// Emiliano    soft_obj = 0;// Emiliano
1035      proc_obj = 0;// Emiliano
1036    irun = -1;    irun = -1;
1037    irunt = -1;    irunt = -1;
1038    totrunentry = 0LL;    totrunentry = 0LL;
# Line 837  Bool_t PamLevel2::IsGood(Bool_t strict) Line 1062  Bool_t PamLevel2::IsGood(Bool_t strict)
1062    if (strict) {    if (strict) {
1063      if (trk2_obj && trk2_obj->UnpackError() != 0)      if (trk2_obj && trk2_obj->UnpackError() != 0)
1064        goodev = false;        goodev = false;
1065      if (tof_obj && tof_obj->unpackError != 0)      if (tof2_obj && tof2_obj->unpackError != 0)
1066        goodev = false;        goodev = false;
1067      if (trig_obj && trig_obj->unpackError != 0)      if (trig_obj && trig_obj->unpackError != 0)
1068        goodev = false;        goodev = false;
# Line 847  Bool_t PamLevel2::IsGood(Bool_t strict) Line 1072  Bool_t PamLevel2::IsGood(Bool_t strict)
1072        goodev = false;        goodev = false;
1073      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)))
1074        goodev = false;        goodev = false;
1075      //  if(orb_obj)      //  if(orb2_obj)
1076    }    }
1077    else {    else {
1078      if (nd_obj && nd_obj->unpackError != 0)      if (nd_obj && nd_obj->unpackError != 0)
# Line 878  void PamLevel2::SetMaxShift(Int_t sh){ Line 1103  void PamLevel2::SetMaxShift(Int_t sh){
1103      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");
1104      maxshift = sh;      maxshift = sh;
1105    } else {    } else {
1106      ULong64_t nev = this->GetEntries();      ULong64_t nev = GetEntries();
1107      ULong64_t runnev = 0ULL;      ULong64_t runnev = 0ULL;
1108      for (Int_t r=0; r< run_tree->GetEntries();r++){      for (Int_t r=0; r< run_tree->GetEntries();r++){
1109        run_tree->GetEntry(r);//update runinfo        run_tree->GetEntry(r);//update runinfo
# Line 933  void *PamLevel2::GetPointerTo(const char Line 1158  void *PamLevel2::GetPointerTo(const char
1158      return &calo2_obj;      return &calo2_obj;
1159    };    };
1160    if (!objname.CompareTo("ToFLevel2")) {    if (!objname.CompareTo("ToFLevel2")) {
1161      if (!tof_obj) {      if (!tof2_obj) {
1162        tof_obj = new ToFLevel2();        tof2_obj = new ToFLevel2();
1163        tof_obj->Set();        tof2_obj->Set();
1164      }      }
1165      return &tof_obj;      return &tof2_obj;
1166    };    };
1167    if (!objname.CompareTo("TrigLevel2")) {    if (!objname.CompareTo("TrigLevel2")) {
1168      if (!trig_obj)      if (!trig_obj)
# Line 960  void *PamLevel2::GetPointerTo(const char Line 1185  void *PamLevel2::GetPointerTo(const char
1185      return &ac_obj;      return &ac_obj;
1186    };    };
1187    if (!objname.CompareTo("OrbitalInfo")) {    if (!objname.CompareTo("OrbitalInfo")) {
1188      if (!orb_obj) {      if (!orb2_obj) {
1189        orb_obj = new OrbitalInfo();        orb2_obj = new OrbitalInfo();
1190        orb_obj->Set();        orb2_obj->Set();
1191      }      }
1192      return &orb_obj;      return &orb2_obj;
1193    };    };
1194    //     if(!objname.CompareTo("OrbitalInfo")){    //     if(!objname.CompareTo("OrbitalInfo")){
1195    //    if(!orb_obj)   orb_obj   = new OrbitalInfo();    //    if(!orb2_obj)   orb2_obj   = new OrbitalInfo();
1196    //    return &orb_obj;    //    return &orb2_obj;
1197    //     };    //     };
1198    if (!objname.CompareTo("GPamela")) {    if (!objname.CompareTo("GPamela")) {
1199      if (!gp_obj)      if (!gp_obj)
# Line 982  void *PamLevel2::GetPointerTo(const char Line 1207  void *PamLevel2::GetPointerTo(const char
1207    if (!objname.CompareTo("SoftInfo"))    if (!objname.CompareTo("SoftInfo"))
1208      return &soft_obj; // Emiliano      return &soft_obj; // Emiliano
1209    
1210      if (!objname.CompareTo("ProcInfo")){
1211        if (!proc_obj)
1212          proc_obj = new ProcInfo();    
1213        return &proc_obj; // Emiliano
1214      }
1215    
1216    return NULL;    return NULL;
1217  }  }
1218  ;  ;
# Line 1032  CaloTrkVar *PamLevel2::GetCaloStoredTrac Line 1263  CaloTrkVar *PamLevel2::GetCaloStoredTrac
1263   */   */
1264  ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno) {  ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno) {
1265    
1266    if (!tof_obj)    if (!tof2_obj)
1267      return 0;      return 0;
1268    
1269    if (tof_obj->ToFLevel2::ntrk() == 0) {    if (tof2_obj->ToFLevel2::ntrk() == 0) {
1270      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"
1271          << endl;          << endl;
1272      return NULL;      return NULL;
# Line 1045  ToFTrkVar *PamLevel2::GetToFStoredTrack( Line 1276  ToFTrkVar *PamLevel2::GetToFStoredTrack(
1276    Int_t it_tof = 0;    Int_t it_tof = 0;
1277    
1278    do {    do {
1279      c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);      c = tof2_obj->ToFLevel2::GetToFTrkVar(it_tof);
1280      it_tof++;      it_tof++;
1281    } while (c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());    } while (c && seqno != c->trkseqno && it_tof < tof2_obj->ToFLevel2::ntrk());
1282    
1283    if (!c || seqno != c->trkseqno) {    if (!c || seqno != c->trkseqno) {
1284      c = 0;      c = 0;
# Line 1070  ToFTrkVar *PamLevel2::GetToFStoredTrack( Line 1301  ToFTrkVar *PamLevel2::GetToFStoredTrack(
1301   */   */
1302  OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno) {  OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno) {
1303    
1304    if (!orb_obj)    if (!orb2_obj)
1305      return 0;      return 0;
1306    
1307    if (orb_obj->OrbitalInfo::ntrk() == 0) {    if (orb2_obj->OrbitalInfo::ntrk() == 0) {
1308      //       // TRICK BEGIN      //       // TRICK BEGIN
1309      //       OrbitalInfoTrkVar  *r = new OrbitalInfoTrkVar(); // TEMPORARY TRICK      //       OrbitalInfoTrkVar  *r = new OrbitalInfoTrkVar(); // TEMPORARY TRICK
1310      //       Int_t nn = 0;      //       Int_t nn = 0;
1311      //       TClonesArray &tor = *orb_obj->OrbitalInfoTrk;      //       TClonesArray &tor = *orb2_obj->OrbitalInfoTrk;
1312      //       for(Int_t nt=0; nt < tof_obj->ToFLevel2::ntrk(); nt++){      //       for(Int_t nt=0; nt < tof2_obj->ToFLevel2::ntrk(); nt++){
1313      //  //      //  //
1314      //  ToFTrkVar *ptt = tof_obj->ToFLevel2::GetToFTrkVar(nt);      //  ToFTrkVar *ptt = tof2_obj->ToFLevel2::GetToFTrkVar(nt);
1315      //  if ( ptt->trkseqno != -1  ){      //  if ( ptt->trkseqno != -1  ){
1316      //    //      //    //
1317      //    r->trkseqno = ptt->trkseqno;      //    r->trkseqno = ptt->trkseqno;
# Line 1102  OrbitalInfoTrkVar *PamLevel2::GetOrbital Line 1333  OrbitalInfoTrkVar *PamLevel2::GetOrbital
1333      //       };      //       };
1334      //       delete r;      //       delete r;
1335      //       OrbitalInfoTrkVar *c = 0;      //       OrbitalInfoTrkVar *c = 0;
1336      //       c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(0);      //       c = orb2_obj->OrbitalInfo::GetOrbitalInfoTrkVar(0);
1337      //       return c;      //       return c;
1338      //       //TRICK END      //       //TRICK END
1339      cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo " << seqno      cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo " << seqno
# Line 1114  OrbitalInfoTrkVar *PamLevel2::GetOrbital Line 1345  OrbitalInfoTrkVar *PamLevel2::GetOrbital
1345    Int_t it_tof = 0;    Int_t it_tof = 0;
1346    
1347    do {    do {
1348      c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);      c = orb2_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);
1349      it_tof++;      it_tof++;
1350    } while (c && seqno != c->trkseqno && it_tof < orb_obj->OrbitalInfo::ntrk());    } while (c && seqno != c->trkseqno && it_tof < orb2_obj->OrbitalInfo::ntrk());
1351    
1352    if (!c || seqno != c->trkseqno) {    if (!c || seqno != c->trkseqno) {
1353      c = 0;      c = 0;
# Line 1247  void PamLevel2::SortTracks() { Line 1478  void PamLevel2::SortTracks() {
1478    // create TCloneArrays to store tracks and its images    // create TCloneArrays to store tracks and its images
1479    if (!tsorted)    if (!tsorted)
1480      tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());      tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1481    tsorted->Delete();    tsorted->Clear("C+C");//Delete();
1482    TClonesArray &ttsorted = *tsorted;    TClonesArray &ttsorted = *tsorted;
1483    
1484    if (!timage)    if (!timage)
1485      timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());      timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1486    timage->Delete();    timage->Clear("C+C");//Delete();
1487    TClonesArray &ttimage = *timage;    TClonesArray &ttimage = *timage;
1488    
1489    
1490    
1491    //--------------------------------------------------    //--------------------------------------------------
1492    // retrieve sorting method    // retrieve sorting method
1493    //--------------------------------------------------    //--------------------------------------------------
# Line 1370  void PamLevel2::SortTracks() { Line 1603  void PamLevel2::SortTracks() {
1603        // -----------------------------------------------------------------------------------------        // -----------------------------------------------------------------------------------------
1604        // check the number of hit pmts along the track        // check the number of hit pmts along the track
1605        // on S12 S21 and S32, where paddles are parallel to Y axis        // on S12 S21 and S32, where paddles are parallel to Y axis
1606        if ((use_TOF || use_S1 || use_S2 || use_S3) && !tof_obj) {        if ((use_TOF || use_S1 || use_S2 || use_S3) && !tof2_obj) {
1607          cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but ToFLevel2 not loaded !!!";          cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but ToFLevel2 not loaded !!!";
1608          return;          return;
1609        };        };
# Line 1387  void PamLevel2::SortTracks() { Line 1620  void PamLevel2::SortTracks() {
1620          //          //
1621          Float_t sen = 0.;          Float_t sen = 0.;
1622          for (Int_t ih = 0; ih < op->npmtadc; ih++) {          for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1623            Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));            Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1624            if (pl == 2 || pl == 3 || pl == 4 || pl == 5)            if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
1625              sen += (op->dedx).At(ih);              sen += (op->dedx).At(ih);
1626          };          };
1627          for (Int_t ih = 0; ih < oi->npmtadc; ih++) {          for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1628            Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));            Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1629            if (pl == 2 || pl == 3 || pl == 4 || pl == 5)            if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
1630              sen += (oi->dedx).At(ih);              sen += (oi->dedx).At(ih);
1631          };          };
# Line 1405  void PamLevel2::SortTracks() { Line 1638  void PamLevel2::SortTracks() {
1638            Int_t nz = 6;            Int_t nz = 6;
1639            Float_t zin[6]; // << define TOF z-coordinates            Float_t zin[6]; // << define TOF z-coordinates
1640            for (Int_t ip = 0; ip < nz; ip++)            for (Int_t ip = 0; ip < nz; ip++)
1641              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
1642            Trajectory *tr = new Trajectory(nz, zin);            Trajectory *tr = new Trajectory(nz, zin);
1643            //            //
1644            Int_t nphit_p = 0;            Int_t nphit_p = 0;
# Line 1414  void PamLevel2::SortTracks() { Line 1647  void PamLevel2::SortTracks() {
1647            Float_t enhit_i = 0.;            Float_t enhit_i = 0.;
1648            //            //
1649            for (Int_t ih = 0; ih < op->npmtadc; ih++) {            for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1650              Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));              Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1651              if (pl == 1 || pl == 2 || pl == 5) {              if (pl == 1 || pl == 2 || pl == 5) {
1652                nphit_p++;                nphit_p++;
1653                enhit_p += (op->dedx).At(ih);                enhit_p += (op->dedx).At(ih);
# Line 1425  void PamLevel2::SortTracks() { Line 1658  void PamLevel2::SortTracks() {
1658            //            //
1659            if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {            if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
1660              for (Int_t ih = 0; ih < op->npmtadc; ih++) {              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1661                Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1662                if (pl == 0) {                if (pl == 0) {
1663                  nphit_p++;                  nphit_p++;
1664                  enhit_p += (op->dedx).At(ih);                  enhit_p += (op->dedx).At(ih);
# Line 1434  void PamLevel2::SortTracks() { Line 1667  void PamLevel2::SortTracks() {
1667            };            };
1668            if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {            if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
1669              for (Int_t ih = 0; ih < op->npmtadc; ih++) {              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1670                Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1671                if (pl == 3) {                if (pl == 3) {
1672                  nphit_p++;                  nphit_p++;
1673                  enhit_p += (op->dedx).At(ih);                  enhit_p += (op->dedx).At(ih);
# Line 1443  void PamLevel2::SortTracks() { Line 1676  void PamLevel2::SortTracks() {
1676            };            };
1677            if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {            if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
1678              for (Int_t ih = 0; ih < op->npmtadc; ih++) {              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1679                Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1680                if (pl == 4) {                if (pl == 4) {
1681                  nphit_p++;                  nphit_p++;
1682                  enhit_p += (op->dedx).At(ih);                  enhit_p += (op->dedx).At(ih);
# Line 1452  void PamLevel2::SortTracks() { Line 1685  void PamLevel2::SortTracks() {
1685            };            };
1686    
1687            for (Int_t ih = 0; ih < oi->npmtadc; ih++) {            for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1688              Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));              Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1689              if (pl == 1 || pl == 2 || pl == 5) {              if (pl == 1 || pl == 2 || pl == 5) {
1690                nphit_i++;                nphit_i++;
1691                enhit_i += (op->dedx).At(ih);                enhit_i += (op->dedx).At(ih);
# Line 1463  void PamLevel2::SortTracks() { Line 1696  void PamLevel2::SortTracks() {
1696            //            //
1697            if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {            if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
1698              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1699                Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1700                if (pl == 0) {                if (pl == 0) {
1701                  nphit_i++;                  nphit_i++;
1702                  enhit_i += (op->dedx).At(ih);                  enhit_i += (op->dedx).At(ih);
# Line 1472  void PamLevel2::SortTracks() { Line 1705  void PamLevel2::SortTracks() {
1705            };            };
1706            if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {            if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
1707              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1708                Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1709                if (pl == 3) {                if (pl == 3) {
1710                  nphit_i++;                  nphit_i++;
1711                  enhit_i += (op->dedx).At(ih);                  enhit_i += (op->dedx).At(ih);
# Line 1481  void PamLevel2::SortTracks() { Line 1714  void PamLevel2::SortTracks() {
1714            };            };
1715            if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {            if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
1716              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1717                Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));                Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1718                if (pl == 4) {                if (pl == 4) {
1719                  nphit_i++;                  nphit_i++;
1720                  enhit_i += (op->dedx).At(ih);                  enhit_i += (op->dedx).At(ih);
# Line 1525  void PamLevel2::SortTracks() { Line 1758  void PamLevel2::SortTracks() {
1758             cout << "image: npmttdc "<< oi->npmttdc << endl;*/             cout << "image: npmttdc "<< oi->npmttdc << endl;*/
1759    
1760            //      for (Int_t ih=0; ih < op->npmtadc; ih++){            //      for (Int_t ih=0; ih < op->npmtadc; ih++){
1761            //        Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );            //        Int_t pl = tof2_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1762            //        if(pl == 1 || pl == 2 || pl == 5)nphit_p++;            //        if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
1763            //      };            //      };
1764    
1765            //      for (Int_t ih=0; ih < oi->npmtadc; ih++){            //      for (Int_t ih=0; ih < oi->npmtadc; ih++){
1766            //        Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );            //        Int_t pl = tof2_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1767            //        if(pl == 1 || pl == 2 || pl == 5)nphit_i++;            //        if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
1768            //      };            //      };
1769            // --- modified to count tdc signals (more efficient?)            // --- modified to count tdc signals (more efficient?)
1770            // --- and to implement check on tdcflag            // --- and to implement check on tdcflag
1771            for (Int_t ih = 0; ih < op->npmttdc; ih++) {            for (Int_t ih = 0; ih < op->npmttdc; ih++) {
1772              Int_t pl = tof_obj->GetPlaneIndex((op->pmttdc).At(ih));              Int_t pl = tof2_obj->GetPlaneIndex((op->pmttdc).At(ih));
1773              //      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++;
1774              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))
1775                  || (use_S3 && (pl == 4 || pl == 5))) {                  || (use_S3 && (pl == 4 || pl == 5))) {
# Line 1546  void PamLevel2::SortTracks() { Line 1779  void PamLevel2::SortTracks() {
1779            };            };
1780    
1781            for (Int_t ih = 0; ih < oi->npmttdc; ih++) {            for (Int_t ih = 0; ih < oi->npmttdc; ih++) {
1782              Int_t pl = tof_obj->GetPlaneIndex((oi->pmttdc).At(ih));              Int_t pl = tof2_obj->GetPlaneIndex((oi->pmttdc).At(ih));
1783              //      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++;
1784              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))
1785                  || (use_S3 && (pl == 4 || pl == 5))) {                  || (use_S3 && (pl == 4 || pl == 5))) {
# Line 1721  void PamLevel2::SortTracks() { Line 1954  void PamLevel2::SortTracks() {
1954    
1955  }  }
1956  ;  ;
1957    //
1958    //--------------------------------------
1959    /**
1960     * Sort physical (tracker) tracks.
1961     * @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...).
1962     * Sorting cryteria:
1963     * TRK: lower chi**2
1964     * CAL: lower Y spatial residual on the first calorimeter plane
1965     * TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis).
1966     * S1: (ask Emiliano)
1967     * S2: (ask Emiliano)
1968     * S3: (ask Emiliano)
1969     * GP: more GP hits
1970     * The default sorting cryterium is "TOF+CAL".
1971     *
1972     * 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).
1973     *
1974     * New version, with handling of extended tracks and nuclei tracks.
1975     */
1976    void PamLevel2::SortTracksNew() {
1977    
1978      //--------------------------------------------------
1979      //Check if the current event has already been sorted
1980      //--------------------------------------------------
1981      if (issorted_new && lastsorted_new == GetReadEntry()) {
1982          return; //already done for this event
1983      }
1984    
1985    
1986    //  cout << "SORT" << endl;
1987    
1988      //Reset the sort flags, just in case something will go wrong...
1989      issorted_new = false;
1990      lastsorted_new = -1;
1991    
1992      //--------------------------------------------------
1993      // set input variables
1994      //--------------------------------------------------
1995    
1996      TString how = howtosort;
1997      //Save current Object count
1998      Int_t ObjectNumber = TProcessID::GetObjectCount();
1999    
2000    
2001    
2002    
2003      TrkLevel2  * trk2 ;
2004      CaloLevel2 * calo2;
2005      ToFLevel2  * tof2  ;
2006      OrbitalInfo  * orb2 ;
2007      
2008      TClonesArray * trkext ;
2009      TClonesArray * caloext;
2010      TClonesArray * tofext ;
2011      TClonesArray * orbext ;
2012    
2013    
2014    //   cout << "trk2_obj" << trk2_obj<< endl;
2015    //   cout << "trk2_nuc_obj" << trk2_nuc_obj<< endl;
2016    //   cout << " trk_ext_obj "<<trk_ext_obj<< endl;
2017    //   cout << " trk_ext_nuc_obj "<<trk_ext_nuc_obj<< endl;
2018    
2019      //-----------------------------------------------------------
2020      // create/reset TCloneArrays to store tracks and their images
2021      //-----------------------------------------------------------
2022    
2023    //  cout << " PamLevel2::SortTracksNew() --- Clear TClonesArray objects"<<endl;
2024      
2025      // main tracks from standard alg
2026    //   if (!tsorted)
2027    //       tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2028    //   tsorted->Clear("C+C");//Delete();
2029    //   // track images from standard alg
2030    //   if (!timage)
2031    //       timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2032    //   timage->Clear("C+C");//Delete();
2033    //   // tracks from extended algorythm
2034    //   if(EXT && !text)
2035    //       text = new TClonesArray("PamTrack",trk_ext_obj->GetEntries());
2036    //   if(text)text->Clear("C+C");//Delete();
2037    
2038      if(tsorted)delete tsorted;
2039      if(timage) delete timage;
2040      if(text)   delete text;
2041      tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2042      timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2043      text = new TClonesArray("PamTrack",trk_ext_obj->GetEntries());
2044    
2045      //-----------------------------------------------------------
2046      // create/reset TCloneArrays to store tracks and their images
2047      //-----------------------------------------------------------
2048      if(NUC){
2049    
2050          
2051          if(tsorted_nuc)delete tsorted_nuc;
2052          if(timage_nuc) delete timage_nuc;
2053          if(text_nuc)   delete text_nuc;
2054          tsorted_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2055          timage_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2056          text_nuc = new TClonesArray("PamTrack",trk_ext_nuc_obj->GetEntries());
2057    
2058      // main tracks from standard alg
2059    //       if (!tsorted_nuc)
2060    //        tsorted_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2061    //       tsorted_nuc->Clear("C+C");//Delete();
2062    //       // track images from standard alg
2063    //       if (!timage_nuc)
2064    //        timage_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2065    //       timage_nuc->Clear("C+C");//Delete();
2066    //       // tracks from extended algorythm
2067    //       if(EXT && !text_nuc)
2068    //        text_nuc = new TClonesArray("PamTrack",trk_ext_nuc_obj->GetEntries());
2069    //       if(text_nuc)text_nuc->Clear("C+C");//Delete();
2070    
2071      }
2072      //--------------------------------------------------
2073      // retrieve sorting method
2074      //--------------------------------------------------
2075      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
2076      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
2077      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
2078      Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
2079      Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
2080      Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
2081      Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
2082    
2083      if (use_TOF) {
2084        use_S1 = true;
2085        use_S2 = true;
2086        use_S3 = true;
2087      };
2088      if (!CAL2 && use_CAL)
2089        use_CAL = false;
2090      if (!TOF) {
2091        use_TOF = false;
2092        use_S1 = false;
2093        use_S2 = false;
2094        use_S3 = false;
2095      }
2096      if (!GP) {
2097        use_GP = false;
2098      }
2099    
2100      if (!TRK2) {
2101        cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
2102        return;
2103      };
2104    
2105    
2106      ///////////////////////////////////////////////////////////////////////////////////
2107      //
2108      //   sort tracks and fill PamTrack arrays
2109      //
2110      ///////////////////////////////////////////////////////////////////////////////////
2111      for(int doit=0; doit<2; doit++){
2112    
2113    //       cout << "doit "<<doit<<endl;
2114    
2115    
2116          if(doit == 0){
2117    
2118              trk2  = trk2_obj;
2119              calo2 = calo2_obj;
2120              tof2  = tof2_obj;
2121              orb2  = orb2_obj;
2122          
2123              trkext = trk_ext_obj;
2124              caloext = calo_ext_obj;
2125              tofext = tof_ext_obj;
2126              orbext = orb_ext_obj;
2127        
2128          
2129          
2130          
2131    
2132          }else if (doit == 1){
2133    
2134              if(!NUC)break;
2135    
2136          
2137              trk2  = trk2_nuc_obj;
2138              calo2 = calo2_nuc_obj;
2139              tof2  = tof2_nuc_obj;
2140              orb2  = orb2_nuc_obj;
2141          
2142              trkext = trk_ext_nuc_obj;
2143              caloext = calo_ext_nuc_obj;
2144              tofext = tof_ext_nuc_obj;
2145              orbext = orb_ext_nuc_obj;
2146          
2147          
2148          
2149    
2150          }
2151    
2152    //       cout << "trk2" << trk2<<endl;
2153    //       cout << "calo2" << calo2<<endl;
2154    //       cout << "tof2" << tof2<<endl;
2155    //       cout << "orb2" << orb2<<endl;
2156    //       cout << "trkext" <<trkext <<endl;
2157    //       cout << "tofext" << tofext<<endl;
2158    //       cout << "caloext" << caloext<<endl;
2159    //       cout << "orbext" << orbext<<endl;
2160    
2161          TClonesArray &ttext    = (doit==0 ? *text : *text_nuc);
2162          TClonesArray &ttimage  = (doit==0 ? *timage : *timage_nuc);
2163          TClonesArray &ttsorted = (doit==0 ? *tsorted : *tsorted_nuc);
2164      
2165    //       cout << "tsorted + timage "<<doit<<endl;
2166    
2167          //--------------------------------------------------
2168          // loop over "physical" tracks sorted by the tracker
2169          //--------------------------------------------------
2170          for (Int_t i = 0; i < trk2->TrkLevel2::GetNTracks(); i++) {
2171    
2172              TrkTrack *ts = 0;
2173              CaloTrkVar *cs = 0;
2174              ToFTrkVar *os = 0;
2175              OrbitalInfoTrkVar *rs = 0;
2176    
2177              // get tracker tracks
2178              TrkTrack *tp = trk2->GetTrack(i); //tracker
2179              CaloTrkVar *cp = calo2->GetCaloStoredTrack(tp->GetSeqNo());
2180              ToFTrkVar *op = tof2->GetToFStoredTrack(tp->GetSeqNo());
2181              OrbitalInfoTrkVar *rp = orb2->GetOrbitalInfoStoredTrack(tp->GetSeqNo());
2182    
2183              TrkTrack *ti = 0; //tracker (image)
2184              CaloTrkVar *ci = 0;
2185              ToFTrkVar *oi = 0;
2186              OrbitalInfoTrkVar *ri = 0;
2187              //    cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
2188              // if track has an image, check image selection
2189    
2190              Int_t tp_score = 0; //main track sorted by the tracker
2191              Int_t ti_score = 0; //image track
2192              Int_t totp_score = 0; //main track sorted by the tracker
2193              Int_t toti_score = 0; //image track
2194    
2195              if (tp->HasImage()) {
2196    
2197                  ti = trk2->GetTrackImage(i); //tracker (image)
2198                  ci = calo2->GetCaloStoredTrack(ti->GetSeqNo());
2199                  oi = tof2->GetToFStoredTrack(ti->GetSeqNo());
2200                  ri = orb2->GetOrbitalInfoStoredTrack(ti->GetSeqNo());
2201    
2202                  //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
2203    
2204                  //assign starting scores
2205                  tp_score = 0; //main track sorted by the tracker
2206                  ti_score = 0; //image track
2207    
2208                  // -----------------------------------------------------------------------------------------
2209                  // *****************************************************************************************
2210                  // -----------------------------------------------------------------------------------------
2211                  // calorimeter check
2212                  // -----------------------------------------------------------------------------------------
2213                  if (use_CAL && !calo2) {
2214                      cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but CaloLevel2 not loaded !!!";
2215                      return;
2216                  };
2217                  if (use_CAL && !cp && ci) {
2218                      ti_score++;
2219                      toti_score++;
2220                  };
2221                  if (use_CAL && cp && !ci) {
2222                      tp_score++;
2223                      totp_score++;
2224                  };
2225                  if (use_CAL && cp && ci && true) {
2226    
2227                      if (cp->npresh > ci->npresh && true) {
2228                          tp_score++;
2229                          totp_score++;
2230                      };
2231                      if (cp->npresh < ci->npresh && true) {
2232                          ti_score++;
2233                          toti_score++;
2234                      };
2235    
2236                      //    cout << "CALO "<<tp_score<<ti_score<<endl;
2237    
2238                  };
2239                  // -----------------------------------------------------------------------------------------
2240                  // *****************************************************************************************
2241                  // -----------------------------------------------------------------------------------------
2242                  // TOF check
2243                  // -----------------------------------------------------------------------------------------
2244                  // check the number of hit pmts along the track
2245                  // on S12 S21 and S32, where paddles are parallel to Y axis
2246                  if ((use_TOF || use_S1 || use_S2 || use_S3) && !tof2) {
2247                      cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but ToFLevel2 not loaded !!!";
2248                      return;
2249                  };
2250                  //
2251                  if ((use_TOF || use_S1 || use_S2 || use_S3) && !op && oi) {
2252                      ti_score++;
2253                      toti_score++;
2254                  };
2255                  if ((use_TOF || use_S1 || use_S2 || use_S3) && op && !oi) {
2256                      tp_score++;
2257                      totp_score++;
2258                  };
2259                  if ((use_TOF || use_S1 || use_S2 || use_S3) && op && oi) {
2260                      //
2261                      Float_t sen = 0.;
2262                      for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2263                          Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2264                          if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
2265                              sen += (op->dedx).At(ih);
2266                      };
2267                      for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2268                          Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2269                          if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
2270                              sen += (oi->dedx).At(ih);
2271                      };
2272                      //
2273                      if (sen >= sortthr && false) { // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
2274                          //printf(" IS A NUCLEUS! en = %f \n",sen);
2275                          //
2276                          // is a nucleus use a different algorithm
2277                          //
2278                          Int_t nz = 6;
2279                          Float_t zin[6]; // << define TOF z-coordinates
2280                          for (Int_t ip = 0; ip < nz; ip++)
2281                              zin[ip] = tof2->GetZTOF(tof2->GetToFPlaneID(ip)); // << read ToF plane z-coordinates
2282                          Trajectory *tr = new Trajectory(nz, zin);
2283                          //
2284                          Int_t nphit_p = 0;
2285                          Int_t nphit_i = 0;
2286                          Float_t enhit_p = 0.;
2287                          Float_t enhit_i = 0.;
2288                          //
2289                          for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2290                              Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2291                              if (pl == 1 || pl == 2 || pl == 5) {
2292                                  nphit_p++;
2293                                  enhit_p += (op->dedx).At(ih);
2294                              };
2295                          };
2296                          //
2297                          tp->DoTrack2(tr);
2298                          //
2299                          if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
2300                              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2301                                  Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2302                                  if (pl == 0) {
2303                                      nphit_p++;
2304                                      enhit_p += (op->dedx).At(ih);
2305                                  };
2306                              };
2307                          };
2308                          if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
2309                              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2310                                  Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2311                                  if (pl == 3) {
2312                                      nphit_p++;
2313                                      enhit_p += (op->dedx).At(ih);
2314                                  };
2315                              };
2316                          };
2317                          if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
2318                              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2319                                  Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2320                                  if (pl == 4) {
2321                                      nphit_p++;
2322                                      enhit_p += (op->dedx).At(ih);
2323                                  };
2324                              };
2325                          };
2326    
2327                          for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2328                              Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2329                              if (pl == 1 || pl == 2 || pl == 5) {
2330                                  nphit_i++;
2331                                  enhit_i += (op->dedx).At(ih);
2332                              };
2333                          };
2334                          //
2335                          ti->DoTrack2(tr);
2336                          //
2337                          if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
2338                              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2339                                  Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2340                                  if (pl == 0) {
2341                                      nphit_i++;
2342                                      enhit_i += (op->dedx).At(ih);
2343                                  };
2344                              };
2345                          };
2346                          if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
2347                              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2348                                  Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2349                                  if (pl == 3) {
2350                                      nphit_i++;
2351                                      enhit_i += (op->dedx).At(ih);
2352                                  };
2353                              };
2354                          };
2355                          if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
2356                              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2357                                  Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2358                                  if (pl == 4) {
2359                                      nphit_i++;
2360                                      enhit_i += (op->dedx).At(ih);
2361                                  };
2362                              };
2363                          };
2364    
2365                          if ((use_TOF || use_S1 || use_S2 || use_S3) && (nphit_p + nphit_i) != 0 && true) {
2366    
2367                              //        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);
2368                              //        printf(" score p %i score i %i \n",tp_score,ti_score);
2369                              //              if( enhit_p > enhit_i ) tp_score++;
2370                              //              if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
2371                              if (nphit_p > nphit_i)
2372                                  tp_score++;
2373                              if (nphit_p < nphit_i)
2374                                  ti_score++;
2375                              if (nphit_p == nphit_i) {
2376                                  if (enhit_p > enhit_i)
2377                                      tp_score++;
2378                                  else
2379                                      ti_score++;
2380                              };
2381                              //        printf(" dopo score p %i score i %i \n",tp_score,ti_score);
2382                          };
2383                          delete tr;
2384                          //
2385                      }
2386                      else {
2387                          // -------------
2388                          // NOT a NUCLEUS
2389                          // -------------
2390                          //printf(" NOT a NUCLEUS! en = %f \n",sen);
2391    
2392                          Int_t nphit_p = 0;
2393                          Int_t nphit_i = 0;
2394    
2395                          /*                                cout << "track: npmtadc "<< op->npmtadc << endl;
2396                            cout << "track: npmttdc "<< op->npmttdc << endl;
2397                            cout << "image: npmtadc "<< oi->npmtadc << endl;
2398                            cout << "image: npmttdc "<< oi->npmttdc << endl;*/
2399    
2400                          //          for (Int_t ih=0; ih < op->npmtadc; ih++){
2401                          //            Int_t pl = tof2_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
2402                          //            if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
2403                          //          };
2404    
2405                          //          for (Int_t ih=0; ih < oi->npmtadc; ih++){
2406                          //            Int_t pl = tof2_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
2407                          //            if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
2408                          //          };
2409                          // --- modified to count tdc signals (more efficient?)
2410                          // --- and to implement check on tdcflag
2411                          for (Int_t ih = 0; ih < op->npmttdc; ih++) {
2412                              Int_t pl = tof2->GetPlaneIndex((op->pmttdc).At(ih));
2413                              //        if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
2414                              if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
2415                                  || (use_S3 && (pl == 4 || pl == 5))) {
2416                                  if ((op->tdcflag).At(ih) == 0)
2417                                      nphit_p++;
2418                              };
2419                          };
2420    
2421                          for (Int_t ih = 0; ih < oi->npmttdc; ih++) {
2422                              Int_t pl = tof2->GetPlaneIndex((oi->pmttdc).At(ih));
2423                              //        if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;
2424                              if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
2425                                  || (use_S3 && (pl == 4 || pl == 5))) {
2426                                  if ((oi->tdcflag).At(ih) == 0)
2427                                      nphit_i++;
2428                              };
2429                          };
2430    
2431                          if ((nphit_p + nphit_i) != 0 && true) {
2432    
2433                              if (nphit_p != nphit_i) {
2434                                  totp_score += nphit_p;
2435                                  toti_score += nphit_i;
2436                                  tp_score += nphit_p;
2437                                  ti_score += nphit_i;
2438                              };
2439                              //        if     ( nphit_p > nphit_i) tp_score+=nphit_p;
2440                              //        else if( nphit_p < nphit_i) ti_score+=nphit_i;
2441                              //        else ;//niente
2442                          };
2443                      };
2444                      //    cout << "TOF "<<tp_score<<ti_score<<endl;
2445                  };
2446    
2447                  //      if(tp_score == ti_score) use_TRK = true;
2448    
2449    
2450                  // -----------------------------------------------------------------------------------------
2451                  // *****************************************************************************************
2452                  // -----------------------------------------------------------------------------------------
2453                  // tracker check
2454                  // -----------------------------------------------------------------------------------------
2455                  // chi**2 difference is not always large enough to distinguish among
2456                  // the real track and its image.
2457                  // Tracker check will be applied always when calorimeter and tof information is ambiguous.
2458                  // *** MODIFIED ON AUGUST 2007 ***
2459                  if (use_TRK) {
2460                      //    if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
2461                      //    else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
2462    
2463                      // CHECK 1 : number of points along X
2464                      if (tp->GetNX() >= ti->GetNX()) {
2465                          tp_score++;
2466                          totp_score++;
2467                      };
2468                      if (tp->GetNX() <= ti->GetNX()) {
2469                          ti_score++;
2470                          toti_score++;
2471                      };
2472                      // CHECK 2 : number of points along Y
2473                      if (tp->GetNY() >= ti->GetNY()) {
2474                          tp_score++;
2475                          totp_score++;
2476                      };
2477                      if (tp->GetNY() <= ti->GetNY()) {
2478                          ti_score++;
2479                          toti_score++;
2480                      };
2481    
2482                      //    cout << "TRK "<<tp_score<<ti_score<<endl;
2483                  };
2484    
2485                  // -----------------------------------------------------------------------------------------
2486                  // *****************************************************************************************
2487                  // -----------------------------------------------------------------------------------------
2488                  // GPamela check
2489                  // -----------------------------------------------------------------------------------------
2490    
2491                  //---------------------------------------------------
2492                  // count the number of GP hits
2493                  //---------------------------------------------------
2494                  if (use_GP) {
2495                      int ngphits_p = 0;
2496                      int ngphits_i = 0;
2497                      float toll = 0.02; //200 micron
2498                      for (int ih = 0; ih < GetGPamela()->Nthspe; ih++) {
2499                          int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
2500                          if (tp && tp->YGood(ip) && fabs(tp->ym[ip] - GetGPamela()->Yavspe[ih]) < toll && true)
2501                              ngphits_p++;
2502                          if (ti && ti->YGood(ip) && fabs(ti->ym[ip] - GetGPamela()->Yavspe[ih]) < toll && true)
2503                              ngphits_i++;
2504                      }
2505                      if (ngphits_p > ngphits_i && true) {
2506                          tp_score++;
2507                          totp_score++;
2508                      }
2509                      if (ngphits_p < ngphits_i && true) {
2510                          ti_score++;
2511                          toti_score++;
2512                      }
2513                  }
2514    
2515                  // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2516                  // the winner is....
2517                  // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2518                  if (tp_score > ti_score) {
2519    
2520                  }
2521                  else if (tp_score < ti_score) {
2522    
2523                      ts = ti;//its image!!
2524                      cs = ci;
2525                      os = oi;
2526                      rs = ri;
2527                      Int_t totis = toti_score;
2528    
2529                      ti = tp;//its image!!
2530                      ci = cp;
2531                      oi = op;
2532                      ri = rp;
2533    
2534                      tp = ts;//its image!!
2535                      cp = cs;
2536                      op = os;
2537                      rp = rs;
2538    
2539                      toti_score = totp_score;
2540                      totp_score = totis;
2541    
2542                  }
2543                  else {
2544    
2545                      //    cout << "Warning - track image ambiguity not solved" << endl;
2546    
2547                  };
2548    
2549              }
2550              else {
2551                  totp_score = 1;
2552                  toti_score = 0;
2553    
2554                  //            ts = tp;
2555                  //            cs = cp;
2556                  //            os = op;
2557              };
2558    
2559              //    cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
2560              //    sorted_tracks->Add(ts);//save the track in the sorted array
2561              //    sorted_tracks.Add(ts);//save the track in the sorted array
2562              //    sorted_tracks.Add(tp);//save the track in the sorted array
2563              //    cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
2564              //    cout<<"o "<<tp<<endl;
2565              //    cout<<"o "<<cp<<endl;
2566              //    cout<<"o "<<op<<endl;
2567    
2568              new (ttsorted[i]) PamTrack(tp, cp, op, rp);
2569              new (ttimage[i]) PamTrack(ti, ci, oi, ri);
2570    
2571              ((PamTrack*) (ttsorted[i]))->SetPScore(totp_score);
2572              ((PamTrack*) (ttsorted[i]))->SetIScore(toti_score);
2573              ((PamTrack*) (ttimage[i]))->SetPScore(totp_score);
2574              ((PamTrack*) (ttimage[i]))->SetIScore(toti_score);
2575          };
2576    
2577    
2578    
2579    
2580    
2581    //   if (tsorted->GetEntries() != trk2->GetNTracks()) {
2582    //     cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() " << tsorted->GetEntries()
2583    //         << " != trk2->GetNTracks() = " << trk2->GetNTracks() << endl;
2584    //     tsorted->Delete();
2585    //     tsorted = 0;
2586    //     timage->Delete();
2587    //     timage = 0;
2588    //   }
2589    
2590    
2591    //       cout << "text "<<doit<<endl;
2592    
2593    
2594          //--------------------------------------------------
2595          // fill array with extended tracks (this is easy...)
2596          //--------------------------------------------------
2597          if(EXT){
2598              for(int it=0; it<trkext->GetEntries(); it++){
2599                  
2600                  new (ttext[it]) PamTrack((ExtTrack*)(*trkext)[it], (CaloTrkVar*)(*caloext)[it], (ToFTrkVar*)(*tofext)[it], (OrbitalInfoTrkVar*)(*orbext)[it]);
2601                  
2602              }
2603          }
2604          
2605    
2606    
2607      };
2608    
2609    
2610      //Restore Object count
2611      //To save space in the table keeping track of all referenced objects
2612      //We reset the object count to what it was at the beginning of the event.
2613      TProcessID::SetObjectCount(ObjectNumber);
2614    
2615      //Everything went fine so the current event can be tagged as sorted
2616      issorted_new = true;
2617      lastsorted_new = GetReadEntry();
2618    
2619    //   cout << " tsorted "<< tsorted << " "<<(tsorted ? tsorted->GetEntries() : 0)<<endl;
2620    //   cout << " timage  "<< timage  << " "<<(timage  ? timage->GetEntries() : 0)<<endl;
2621    //   cout << " text    "<< text    << " "<<(text    ? text->GetEntries() : 0)<<endl;
2622    
2623    
2624    };
2625  //--------------------------------------  //--------------------------------------
2626  //  //
2627  //  //
# Line 1729  void PamLevel2::SortTracks() { Line 2630  void PamLevel2::SortTracks() {
2630   * 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.
2631   * 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.
2632   */   */
2633    
2634  // TRefArray *PamLevel2::GetTracks(){  // TRefArray *PamLevel2::GetTracks(){
2635    
2636  // //  *-*-*-*-*-*-*-*-*-*-*-*-*  // //  *-*-*-*-*-*-*-*-*-*-*-*-*
# Line 1739  void PamLevel2::SortTracks() { Line 2641  void PamLevel2::SortTracks() {
2641  //     return &sorted_tracks;  //     return &sorted_tracks;
2642    
2643  //  };  //  };
 TClonesArray *PamLevel2::GetTracks() {  
   
   //  *-*-*-*-*-*-*-*-*-*-*-*-*  
   SortTracks();  
   //  *-*-*-*-*-*-*-*-*-*-*-*-*  
2644    
   return tsorted;  
2645    
 }  
 ;  
2646  //--------------------------------------  //--------------------------------------
2647  //  //
2648  //  //
2649  //--------------------------------------  //--------------------------------------
2650    
2651  /**  /**
2652   * Retrieves the it-th Pamela "physical" track.   * Retrieves the it-th Pamela "physical" track.
2653   * It override TrkLevel2::GetTrack(int it).   * It override TrkLevel2::GetTrack(int it).
2654   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
2655   */   */
2656  PamTrack *PamLevel2::GetTrack(int it) {  PamTrack *PamLevel2::GetTrackOld(int it) {
   
   //    if(!trk2_obj) return 0;  
2657    
2658    // //  *-*-*-*+-*-*-*-*-*-*-*-*-*    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;  
   //     };  
2659    
   //     return track;  
   
   //    cout << "PamLevel2::GetTrack(int it) "<<endl;  
2660    //  *-*-*-*-*-*-*-*-*-*-*-*-*    //  *-*-*-*-*-*-*-*-*-*-*-*-*
2661    SortTracks();    SortTracks();
2662    //  *-*-*-*-*-*-*-*-*-*-*-*-*    //  *-*-*-*-*-*-*-*-*-*-*-*-*
2663    if (!tsorted)    if (!tsorted)
2664      return 0;      return track;
2665    if (!tsorted->GetEntries())    if (!tsorted->GetEntries())
2666      return 0;      return track;
2667    
   PamTrack *track = 0;  
2668    
2669    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];  
2670      track = (PamTrack*)((*tsorted)[it]);      track = (PamTrack*)((*tsorted)[it]);
2671    }    }
2672    else {    else {
2673      cout << "PamLevel2::GetTrack(int) : tracker track SeqNo " << it << " does not exist (GetNTracks() = "      cout << "PamLevel2::GetTrackOld(int) : tracker track SeqNo " << it << " does not exist (GetNTracks() = "
2674          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
2675    };    };
2676    
2677    return track;    return track;
2678    
2679    };
2680    
2681    //PamTrack *PamLevel2::GetTrack(int it) { return GetTrack(it,trkAlg); };
2682    
2683    /**
2684     * Retrieves the it-th Pamela "physical" track.
2685     * It override TrkLevel2::GetTrack(int it).
2686     * @param it Track number, ranging from 0 to GetNTracks().
2687     * @param alg Algorythm, see SetTrakingAlgorythm(char *alg) for explanation.
2688     */
2689    PamTrack *PamLevel2::GetTrack(int it, const char* alg) {
2690    
2691        TString s(alg);
2692        if(!s.CompareTo("") ||!s.CompareTo("STD") )return GetTrackOld(it); //old algorythm
2693    
2694    
2695        SortTracksNew();
2696        // >> fill tsorted, timage and text
2697    
2698        if ( ( !s.Contains("EXTF", TString::kIgnoreCase) || !EXT )){ //not forced exteded-alg requested (or exteded-data missing)
2699    
2700            if( s.Contains("NUC")){
2701                if(
2702                    tsorted_nuc &&
2703                    it < tsorted_nuc->GetEntries() &&                             //enough tracks found
2704                    it >= 0 &&                                                //valid index
2705                    true) return (PamTrack*)((*tsorted_nuc)[it]);                 //ok return the track
2706            }else{
2707                if(
2708                    tsorted &&
2709                    it < tsorted->GetEntries() &&                             //enough tracks found
2710                    it >= 0 &&                                                //valid index
2711                    true )return (PamTrack*)((*tsorted)[it]);                 //ok return the track
2712            }
2713    
2714        }
2715        
2716    
2717        /////////////////////////////////////////////////////////////////////////
2718        /// if requested get track from extended algorythm output
2719        /////////////////////////////////////////////////////////////////////////
2720        
2721        if(s.Contains("EXT", TString::kIgnoreCase) && EXT){//if exteded-alg requested
2722            
2723            if(s.Contains("NUC")){
2724                if(
2725                    text_nuc &&
2726                    it < text_nuc->GetEntries() &&                             //enough tracks found
2727                    it >= 0 &&                                                //valid index
2728                    true) return (PamTrack*)((*text_nuc)[it]);
2729            }else{
2730                if(
2731                    text &&
2732                    it < text->GetEntries() &&                             //enough tracks found
2733                    it >= 0 &&                                                //valid index
2734                    true) return (PamTrack*)((*text)[it]);
2735            }
2736    
2737        };
2738        
2739        
2740        cout << "PamTrack *PamLevel2::GetTrack("<<it<<","<<alg<<") -- wrong track number or unrecognised algorithm"<<endl;
2741        
2742        return NULL;
2743    
2744    }
2745    ;
2746    TClonesArray *PamLevel2::GetTracks() {
2747    
2748      //  *-*-*-*-*-*-*-*-*-*-*-*-*
2749      SortTracks();
2750      //  *-*-*-*-*-*-*-*-*-*-*-*-*
2751    
2752      return tsorted;
2753    
2754  }  }
2755  ;  ;
2756    Int_t  PamLevel2::GetNTracks(const char* alg) {
2757    
2758    
2759    //    cout << " trk_nuc_obj->GetEntries() "<<trk_nuc_obj->GetEntries()<<" trk2_nuc_obj->GetNTracks() "<<trk2_nuc_obj->GetNTracks()<<endl;
2760    
2761        TString s(alg);
2762    
2763        if(!s.CompareTo("") || !s.CompareTo("STD"))return trk2_obj->TrkLevel2::GetNTracks(); //standard algorythm
2764            
2765        if(s.Contains("EXTF", TString::kIgnoreCase) && EXT){
2766            if(s.Contains("NUC", TString::kIgnoreCase) && NUC)return trk_ext_nuc_obj->GetEntries();//ok
2767            return trk_ext_obj->GetEntries();//ok
2768        }
2769        if( s.Contains("EXT", TString::kIgnoreCase) && EXT) {
2770            if(s.Contains("NUC", TString::kIgnoreCase) && NUC)
2771                return (trk2_nuc_obj->TrkLevel2::GetNTracks() ?  trk2_nuc_obj->TrkLevel2::GetNTracks() :  trk_ext_nuc_obj->GetEntries() );  
2772            return (trk2_obj->TrkLevel2::GetNTracks() ?  trk2_obj->TrkLevel2::GetNTracks() :  trk_ext_obj->GetEntries() );
2773        }
2774        if(s.Contains("NUC", TString::kIgnoreCase) && NUC )
2775            return trk2_nuc_obj->TrkLevel2::GetNTracks();
2776        
2777        cout << "Int_t  PamLevel2::GetNTracks("<<alg<<") -- unrecognised algorithm"<<endl;
2778    
2779        return 0;
2780    
2781    }
2782    
2783    
2784  //--------------------------------------  //--------------------------------------
2785  //  //
# Line 1815  PamTrack *PamLevel2::GetTrack(int it) { Line 2789  PamTrack *PamLevel2::GetTrack(int it) {
2789   * 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().
2790   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
2791   */   */
2792  PamTrack *PamLevel2::GetTrackImage(int it) {  PamTrack *PamLevel2::GetTrackImageOld(int it) {
2793    
2794    //  *-*-*-*-*-*-*-*-*-*-*-*-*    //  *-*-*-*-*-*-*-*-*-*-*-*-*
2795    SortTracks();    SortTracks();
# Line 1839  PamTrack *PamLevel2::GetTrackImage(int i Line 2813  PamTrack *PamLevel2::GetTrackImage(int i
2813      };      };
2814    }    }
2815    else {    else {
2816      cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo " << it << " does not exist (GetNTracks() = "      cout << "PamLevel2::GetTrackImageOld(int) : Tracker track SeqNo " << it << " does not exist (GetNTracks() = "
2817          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;          << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
2818    };    };
2819    
2820    return image;    return image;
2821  }  }
2822    /**
2823     * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().
2824     * @param it Track number, ranging from 0 to GetNTracks().
2825     * @param alg Algorythm, see SetTrakingAlgorythm(char *alg) for explanation.
2826     */
2827    PamTrack *PamLevel2::GetTrackImage(int it, const char* alg) {
2828    
2829        TString s(alg);
2830        if(!s.CompareTo("") || !s.CompareTo("STD"))return GetTrackImageOld(it); //old algorythm
2831    
2832    
2833        SortTracksNew();
2834        // >> fill tsorted, timage and text
2835    
2836        if ( ( !s.Contains("EXTF", TString::kIgnoreCase) || !EXT )){ //not forced exteded-alg requested (or exteded-data missing)
2837    
2838            if( s.Contains("NUC")){
2839                if(
2840                    tsorted_nuc &&
2841                    it < tsorted_nuc->GetEntries() &&                             //enough tracks found
2842                    it >= 0 &&                                                //valid index
2843                    true){
2844                    TClonesArray &t = *(tsorted_nuc);
2845                    PamTrack *temp = (PamTrack*) t[it];
2846                    if (temp->GetTrkTrack()->HasImage()) {
2847                        return (PamTrack*)((*timage_nuc)[it]);                 //ok return the track
2848                    }else{
2849                        return NULL;
2850                    }
2851                    
2852                }
2853            }else{
2854                if(
2855                    tsorted &&
2856                    it < tsorted->GetEntries() &&                             //enough tracks found
2857                    it >= 0 &&                                                //valid index
2858                    true ){
2859                    TClonesArray &t = *(tsorted);
2860                    PamTrack *temp = (PamTrack*) t[it];
2861                    if (temp->GetTrkTrack()->HasImage()) {              
2862                        return (PamTrack*)((*timage)[it]);                 //ok return the track
2863                    }else{
2864                        return NULL;
2865                    }
2866                }
2867            }
2868    
2869        }
2870    
2871        cout << "PamTrack *PamLevel2::GetTrackImage("<<it<<","<<alg<<") -- wrong track number or unrecognised algorithm"<<endl;
2872          
2873        return NULL;
2874    
2875    }
2876    ;
2877    
2878  //--------------------------------------  //--------------------------------------
2879  //  //
# Line 1934  TTree *PamLevel2::GetPamTree(TFile *f, T Line 2963  TTree *PamLevel2::GetPamTree(TFile *f, T
2963      if (!Trout)      if (!Trout)
2964        Trout = T;        Trout = T;
2965      else      else
2966        Trout->AddFriend(T);          Trout->AddFriend(T);
2967    }    }
2968    else {    else {
2969      cout << "Tracker      : missing tree" << endl;      cout << "Tracker      : missing tree" << endl;
# Line 2299  TChain *PamLevel2::GetPamTree(TList *fl, Line 3328  TChain *PamLevel2::GetPamTree(TList *fl,
3328    TChain *G = 0;    TChain *G = 0;
3329    
3330    TChain *L = 0;    TChain *L = 0;
3331      TChain *P = 0;
3332    
3333    if (TRK2 || TRK1 || TRKh)    if (TRK2 || TRK1 || TRKh)
3334      T = new TChain("Tracker");      T = new TChain("Tracker");
# Line 2318  TChain *PamLevel2::GetPamTree(TList *fl, Line 3348  TChain *PamLevel2::GetPamTree(TList *fl,
3348      B = new TChain("OrbitalInfo");      B = new TChain("OrbitalInfo");
3349    if (GP)    if (GP)
3350      G = new TChain("h20");      G = new TChain("h20");
3351      if (PROC)
3352        P = new TChain("ProcessingInfo");
3353    L = new TChain("SelectionList");    L = new TChain("SelectionList");
3354    
3355    // loop over files and create chains    // loop over files and create chains
# Line 2345  TChain *PamLevel2::GetPamTree(TList *fl, Line 3377  TChain *PamLevel2::GetPamTree(TList *fl,
3377          B->Add(name);          B->Add(name);
3378        if (GP)        if (GP)
3379          G->Add(name);          G->Add(name);
3380          if (P)
3381            P->Add(name);
3382        if (SELLI == 1)        if (SELLI == 1)
3383          L->Add(name);          L->Add(name);
3384      };       };
3385    };    };
3386    
3387    cout << "done chains\n";    cout << "done data-tree chains  "<<  T->GetNtrees() <<" \n";
3388    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;    cout << "----------------------------------------------------" << endl;
3389    
3390    // -------------------------------------------    // -------------------------------------------
3391    // make friends    // make friends
# Line 2434  TChain *PamLevel2::GetPamTree(TList *fl, Line 3468  TChain *PamLevel2::GetPamTree(TList *fl,
3468    //  =====================================    //  =====================================
3469    //  SET BRANCH-ADDRESS AFTER CHAIN+FRIEND    //  SET BRANCH-ADDRESS AFTER CHAIN+FRIEND
3470    //  =====================================    //  =====================================
3471    SetBranchAddress(Trout);    if( Trout->GetNtrees() )SetBranchAddress(Trout);
3472    
3473    //  ------------------------------------    //  ------------------------------------
3474    //  finally handle selection trees...    //  finally handle selection trees...
3475    //  (it is not friend of pamela tree)    //  (it is not friend of pamela tree)
3476    //  ------------------------------------    //  ------------------------------------
3477    
3478    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;    cout << "----------------------------------------------------" << endl;
3479    
3480    // Selection List    // Selection List
3481    if (L && SELLI == 1) {    if (L && SELLI == 1) {
# Line 2462  TChain *PamLevel2::GetPamTree(TList *fl, Line 3496  TChain *PamLevel2::GetPamTree(TList *fl,
3496      //          if(!Trout)Trout=O;      //          if(!Trout)Trout=O;
3497      //          else Trout->AddFriend("SelectionList");      //          else Trout->AddFriend("SelectionList");
3498      cout << "+SelectionList" << endl;      cout << "+SelectionList" << endl;
3499      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;      cout << "----------------------------------------------------" << endl;
3500    }    }
3501    else {    else {
3502      //  cout << "SelectionList  : missing tree"<<endl;      //  cout << "SelectionList  : missing tree"<<endl;
# Line 2470  TChain *PamLevel2::GetPamTree(TList *fl, Line 3504  TChain *PamLevel2::GetPamTree(TList *fl,
3504        L->Delete();        L->Delete();
3505    };    };
3506    
3507      //ProcessingInfo EM
3508      if ( P && P->GetEntries() ){
3509        cout << "----------------------------------------------------" << endl;
3510        cout << ">>> Found ProcessingInfo <<<" << endl;
3511        //  L->SetBranchAddress("RunEntry",&irun);
3512        P->SetBranchAddress("ProcInfo", &proc_obj);//NEWNEW
3513        proc_tree = P;
3514      } else {
3515        //    proc_tree = new TChain("ProcessingInfo","Log of data processing");
3516        //    proc_tree->Branch("ProcInfo", "ProcInfo", &proc_obj);
3517        cout << "----------------------------------------------------" << endl;
3518        cout << ">>> ProcessingInfo not found, PROC set to false and continue (not 10RED files?)<<<" << endl;
3519        PROC = false;
3520      }
3521    //  --------------------------------------------    //  --------------------------------------------
3522    //  return the pamela chain with all the friends    //  return the pamela chain with all the friends
3523    //  --------------------------------------------    //  --------------------------------------------
3524    
3525    pam_tree = Trout;    pam_tree = Trout;
   
3526    return Trout;    return Trout;
3527  }  }
3528    
# Line 2488  TChain *PamLevel2::GetPamTree(TList *fl, Line 3535  TChain *PamLevel2::GetPamTree(TList *fl,
3535   */   */
3536  void PamLevel2::SetBranchAddress(TTree *t) {  void PamLevel2::SetBranchAddress(TTree *t) {
3537    
3538    TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");  //   TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
3539    TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");  //   TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
3540    TRKh = TRKh & t->GetBranchStatus("TrkHough");  //   TRKh = TRKh & t->GetBranchStatus("TrkHough");
3541    CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");  //   CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
3542    CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");  //   CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
3543    TOF = TOF & t->GetBranchStatus("ToFLevel2");  //   TOF = TOF & t->GetBranchStatus("ToFLevel2");
3544    TRG = TRG & t->GetBranchStatus("TrigLevel2");  //   TRG = TRG & t->GetBranchStatus("TrigLevel2");
3545    S4 = S4 & t->GetBranchStatus("S4Level2");  //   S4 = S4 & t->GetBranchStatus("S4Level2");
3546    ND = ND & t->GetBranchStatus("NDLevel2");  //   ND = ND & t->GetBranchStatus("NDLevel2");
3547    AC = AC & t->GetBranchStatus("AcLevel2");  //   AC = AC & t->GetBranchStatus("AcLevel2");
3548    ORB = ORB & t->GetBranchStatus("OrbitalInfo");  //   ORB = ORB & t->GetBranchStatus("OrbitalInfo");
3549    GP = GP & t->GetBranchStatus("h20");  //   GP = GP & t->GetBranchStatus("h20");
3550    
3551    
3552    // Tracker    // Tracker
3553    if (TRK1) {    if (TRK1) {
# Line 2509  void PamLevel2::SetBranchAddress(TTree * Line 3557  void PamLevel2::SetBranchAddress(TTree *
3557    if (TRK2) {    if (TRK2) {
3558      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));
3559      cout << "Tracker      : set branch address TrkLevel2" << endl;      cout << "Tracker      : set branch address TrkLevel2" << endl;
3560        NUC = t->GetBranchStatus("TrackNuclei");
3561        EXT = t->GetBranchStatus("RecoveredTrack") && (NUC ? t->GetBranchStatus("RecoveredTrackNuclei"): true );    
3562    };    };
3563    if (TRKh) {    if (TRKh) {
3564      t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));      t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
# Line 2569  void PamLevel2::SetBranchAddress(TTree * Line 3619  void PamLevel2::SetBranchAddress(TTree *
3619    
3620      cout << "h20          : set branch address GPamela " << endl;      cout << "h20          : set branch address GPamela " << endl;
3621    };    };
3622      if(NUC){
3623          
3624          cout << "Found nuclei-track branches" << endl;
3625    
3626          if( !trk_nuc_obj )trk_nuc_obj = new TClonesArray("TrkTrack");
3627          if( !calo_nuc_obj)calo_nuc_obj= new TClonesArray("CaloTrkVar");
3628          if( !tof_nuc_obj)tof_nuc_obj= new TClonesArray("ToFTrkVar");
3629          if( !orb_nuc_obj)orb_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3630          if (TRK2)t->                          SetBranchAddress("TrackNuclei",&trk_nuc_obj);
3631          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("TrackNuclei",&calo_nuc_obj);
3632          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("TrackNuclei",&tof_nuc_obj);
3633          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("TrackNuclei",&orb_nuc_obj);
3634    
3635          ///copy the vector content inside a "fake" object (all aother info are missing)    
3636    
3637          if( !trk2_nuc_obj )trk2_nuc_obj =  new TrkLevel2();
3638          if( !calo2_nuc_obj )calo2_nuc_obj =  new CaloLevel2();
3639          if( !tof2_nuc_obj )tof2_nuc_obj =  new ToFLevel2();
3640          if( !orb2_nuc_obj )orb2_nuc_obj =  new OrbitalInfo();
3641    //       *(trk2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*trk_nuc_obj);
3642    //       *(calo2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*calo_nuc_obj);
3643    //       *(tof2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*tof_nuc_obj);
3644    //       *(orb2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*orb_nuc_obj);
3645    
3646          trk2_nuc_obj->SetTrackArray(  trk_nuc_obj  );
3647          calo2_nuc_obj->SetTrackArray( calo_nuc_obj );
3648          tof2_nuc_obj->SetTrackArray(  tof_nuc_obj  );
3649          orb2_nuc_obj->SetTrackArray(  orb_nuc_obj  );
3650    
3651          
3652      }    
3653    
3654      if(EXT){
3655          
3656          cout << "Found extended tracking algorythm branches" << endl;
3657    
3658          if( !trk_ext_obj )trk_ext_obj = new TClonesArray("ExtTrack");
3659          if( !calo_ext_obj)calo_ext_obj= new TClonesArray("CaloTrkVar");
3660          if( !tof_ext_obj)tof_ext_obj= new TClonesArray("ToFTrkVar");
3661          if( !orb_ext_obj)orb_ext_obj= new TClonesArray("OrbitalInfoTrkVar");
3662          
3663          if (TRK2)t->                          SetBranchAddress("RecoveredTrack",&trk_ext_obj);
3664          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrack",&calo_ext_obj);
3665          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrack",&tof_ext_obj);
3666          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrack",&orb_ext_obj);
3667    
3668        
3669          if(NUC){
3670              if( !trk_ext_nuc_obj )trk_ext_nuc_obj = new TClonesArray("ExtTrack");
3671              if( !calo_ext_nuc_obj)calo_ext_nuc_obj= new TClonesArray("CaloTrkVar");
3672              if( !tof_ext_nuc_obj)tof_ext_nuc_obj= new TClonesArray("ToFTrkVar");
3673              if( !orb_ext_nuc_obj)orb_ext_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3674              if (TRK2)t->                          SetBranchAddress("RecoveredTrackNuclei",&trk_ext_nuc_obj);
3675              if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrackNuclei",&calo_ext_nuc_obj);
3676              if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrackNuclei",&tof_ext_nuc_obj);
3677              if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrackNuclei",&orb_ext_nuc_obj);
3678          }
3679      }    
3680  }  }
3681  /**  /**
3682   * Set branch addresses for Pamela friend trees   * Set branch addresses for Pamela friend trees
# Line 2593  void PamLevel2::SetBranchAddress(TChain Line 3700  void PamLevel2::SetBranchAddress(TChain
3700    if (TRK2) {    if (TRK2) {
3701      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
3702      cout << "Tracker      : set branch address TrkLevel2" << endl;      cout << "Tracker      : set branch address TrkLevel2" << endl;
3703        NUC = t->GetBranchStatus("TrackNuclei");
3704        EXT = t->GetBranchStatus("RecoveredTrack") && (NUC ? t->GetBranchStatus("RecoveredTrackNuclei"): true );
3705    };    };
3706    if (TRK1) {    if (TRK1) {
3707      t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));      t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
# Line 2606  void PamLevel2::SetBranchAddress(TChain Line 3715  void PamLevel2::SetBranchAddress(TChain
3715    // Calorimeter    // Calorimeter
3716    if (CAL2) {    if (CAL2) {
3717      t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));      t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
3718      cout << "Calorimeter  : set branch address CaloLevel2" << endl;      cout << "Calorimeter  : set branch address CaloLevel2" << endl;    
3719    };    };
3720    if (CAL1) {    if (CAL1) {
3721      t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));      t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
# Line 2664  void PamLevel2::SetBranchAddress(TChain Line 3773  void PamLevel2::SetBranchAddress(TChain
3773    //    cout << "SelectionList: set branch address EventEntry"<<endl;    //    cout << "SelectionList: set branch address EventEntry"<<endl;
3774    
3775    //     }    //     }
3776      if(NUC){
3777          
3778          cout << "Found nuclei-track branches" << endl;
3779    
3780          if( !trk_nuc_obj )trk_nuc_obj = new TClonesArray("TrkTrack");
3781          if( !calo_nuc_obj)calo_nuc_obj= new TClonesArray("CaloTrkVar");
3782          if( !tof_nuc_obj)tof_nuc_obj= new TClonesArray("ToFTrkVar");
3783          if( !orb_nuc_obj)orb_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3784          if (TRK2)t->                          SetBranchAddress("TrackNuclei",&trk_nuc_obj);
3785          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("TrackNuclei",&calo_nuc_obj);
3786          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("TrackNuclei",&tof_nuc_obj);
3787          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("TrackNuclei",&orb_nuc_obj);
3788          
3789          ///copy the vector content inside a "fake" object (all aother info are missing)    
3790    
3791          if( !trk2_nuc_obj )trk2_nuc_obj =  new TrkLevel2();
3792          if( !calo2_nuc_obj )calo2_nuc_obj =  new CaloLevel2();
3793          if( !tof2_nuc_obj )tof2_nuc_obj =  new ToFLevel2();
3794          if( !orb2_nuc_obj )orb2_nuc_obj =  new OrbitalInfo();
3795    
3796    //       *(trk2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*trk_nuc_obj);
3797    //       *(calo2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*calo_nuc_obj);
3798    //       *(tof2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*tof_nuc_obj);
3799    //       *(orb2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*orb_nuc_obj);
3800          trk2_nuc_obj->SetTrackArray(  trk_nuc_obj  );
3801          calo2_nuc_obj->SetTrackArray( calo_nuc_obj );
3802          tof2_nuc_obj->SetTrackArray(  tof_nuc_obj  );
3803          orb2_nuc_obj->SetTrackArray(  orb_nuc_obj  );
3804    
3805      }    
3806      if(EXT){
3807          
3808          cout << "Found extended tracking algorythm branches" << endl;
3809    
3810          t->SetBranchAddress("extAlgFlag",&extAlgFlag);
3811    
3812          if( !trk_ext_obj )trk_ext_obj = new TClonesArray("ExtTrack");
3813          if( !calo_ext_obj)calo_ext_obj= new TClonesArray("CaloTrkVar");
3814          if( !tof_ext_obj)tof_ext_obj= new TClonesArray("ToFTrkVar");
3815          if( !orb_ext_obj)orb_ext_obj= new TClonesArray("OrbitalInfoTrkVar");
3816          
3817          if (TRK2)t->                          SetBranchAddress("RecoveredTrack",&trk_ext_obj);
3818          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrack",&calo_ext_obj);
3819          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrack",&tof_ext_obj);
3820          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrack",&orb_ext_obj);
3821          
3822          if(NUC){
3823              if( !trk_ext_nuc_obj )trk_ext_nuc_obj = new TClonesArray("ExtTrack");
3824              if( !calo_ext_nuc_obj)calo_ext_nuc_obj= new TClonesArray("CaloTrkVar");
3825              if( !tof_ext_nuc_obj)tof_ext_nuc_obj= new TClonesArray("ToFTrkVar");
3826              if( !orb_ext_nuc_obj)orb_ext_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3827              if (TRK2)t->                          SetBranchAddress("RecoveredTrackNuclei",&trk_ext_nuc_obj);
3828              if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrackNuclei",&calo_ext_nuc_obj);
3829              if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrackNuclei",&tof_ext_nuc_obj);
3830              if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrackNuclei",&orb_ext_nuc_obj);
3831          }
3832      }    
3833      
3834  }  }
3835    
3836    /**
3837     * Set the tracking algorythm
3838     * @param alg String to choose the track.
3839     * "" --> take the output of the standard tracking algorythm
3840     * "STD" --> take the output of the standard tracking algorythm
3841     * "NUC" --> take the output of the standard tracking algorythm for nuclei cluster selection
3842     * "EXT" --> in case the standard tracking algorythm has not found any track, take the output of the extended one
3843     * "EXTF" --> force the extended tracking algorythm
3844     * "NUCEXT" --> as "EXT", but for nuclei
3845     * "NUCEXTF" --> as "EXTF", but for nuclei
3846     */
3847    // void PamLevel2::SetTrackingAlgorythm(const char *alg){
3848    
3849    
3850    //     TString s(alg);
3851    //     if(s.Contains("NUC", TString::kIgnoreCase) && !NUC)
3852    //      cout << "Warning! NUC algorythm requested, but branches are missing"<<endl;
3853    //     if(s.Contains("EXT", TString::kIgnoreCase) && !EXT)
3854    //      cout << "Warning! EXT algorythm requested, but branches are missing"<<endl;;
3855                
3856    //     trkAlg = alg;
3857    
3858    // };
3859    // const char* PamLevel2::GetTrackingAlgorythm(){
3860    
3861    
3862    //     cout<<endl<<" Implemented tracking algorythm: ";
3863    //     cout<<endl<<"  \"\" or \"STD\"  --> take the output of the standard tracking algorythm";
3864    //     cout<<endl<<"  \"NUC\"      --> take the output of the standard tracking algorythm for nuclei cluster selection";
3865    //     cout<<endl<<"  \"EXT\"      --> in case the standard tracking algorythm has not found any track,";
3866    //     cout<<endl<<"                 take the output of the extended one";
3867    //     cout<<endl<<"  \"EXTF\"     --> force the extended tracking algorythm";
3868    //     cout<<endl<<"  \"NUCEXT\"   --> as \"EXT\", but for nuclei ";
3869    //     cout<<endl<<"  \"NUCEXTF\"  --> as \"EXTF\", but for nuclei";
3870    
3871    //     cout<<endl;
3872    //     cout<<" <<Currently set algorythm>> "<<trkAlg<<endl;
3873    //     cout<<endl;
3874    
3875    //     return trkAlg;
3876    // };
3877    
3878    
3879    
3880  //--------------------------------------  //--------------------------------------
3881  //  //
3882  //  //
# Line 2700  TChain *PamLevel2::GetRunTree(TList *fl) Line 3910  TChain *PamLevel2::GetRunTree(TList *fl)
3910      };      };
3911    }    }
3912    
3913      cout << "done run chain  "<<  R->GetNtrees() <<" \n";
3914    
3915    
3916    if (RUN && R->GetNtrees()) {    if (RUN && R->GetNtrees()) {
3917    
3918      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
# Line 2739  TChain *PamLevel2::GetRunTree(TList *fl) Line 3952  TChain *PamLevel2::GetRunTree(TList *fl)
3952      cout << "----------------------------------------------------" << endl;      cout << "----------------------------------------------------" << endl;
3953    
3954    }    }
3955    else {  //   else {
3956      delete R;  //     delete R;
3957      R = 0;  //     R = 0;
3958    }  //   }
3959    
3960    run_tree = R;    run_tree = R;
3961    
# Line 2820  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4033  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4033      run_tree->GetEntry(irun);      run_tree->GetEntry(irun);
4034      if (!GetOrbitalInfo())      if (!GetOrbitalInfo())
4035        cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated " << endl;        cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated " << endl;
4036      if (gltsync)      if ( fUseDBinRunInfo ){
4037        delete gltsync; //Emiliano        if (gltsync)
4038      if (!dbc || (dbc && !dbc->IsConnected()))          delete gltsync; //Emiliano
4039        SetDBConnection(); //Emiliano        if (!dbc || (dbc && !dbc->IsConnected()))
4040      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
4041      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)
4042        dbc->Close();// Emiliano        if (dbc){
4043        delete dbc;          dbc->Close();// Emiliano
4044        dbc=0;          delete dbc;
4045      };          dbc=0;
4046    };        }
4047        }
4048      }
4049    // ---------------------------------------------------------------    // ---------------------------------------------------------------
4050    // retrieve OBT and absolute time of the event    // retrieve OBT and absolute time of the event
4051    // ---------------------------------------------------------------    // ---------------------------------------------------------------
# Line 2839  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4054  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4054    prevpktnum = pktnum;    prevpktnum = pktnum;
4055    if (GetOrbitalInfo()) {    if (GetOrbitalInfo()) {
4056      abstime = GetOrbitalInfo()->absTime;      abstime = GetOrbitalInfo()->absTime;
4057      obt = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano      if ( fUseDBinRunInfo ) obt = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano
4058      pktnum = GetOrbitalInfo()->pkt_num; // Emiliano      pktnum = GetOrbitalInfo()->pkt_num; // Emiliano
4059    }    }
4060    else {    else {
4061      abstime = GetRunInfo()->RUNHEADER_TIME;      abstime = GetRunInfo()->RUNHEADER_TIME;
4062      obt = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano      if ( fUseDBinRunInfo ) obt = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano
4063      pktnum = GetRunInfo()->RUNHEADER_PKT; // Emiliano      pktnum = GetRunInfo()->RUNHEADER_PKT; // Emiliano
4064    }    }
4065    
# Line 2852  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4067  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4067      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);
4068      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);
4069      printf("0        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);      printf("0        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4070      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));
4071      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);
4072      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);
4073    }    }
# Line 2875  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4090  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4090      }      }
4091    
4092      //      //
4093        bool a = true;
4094        bool b = true;
4095        if ( fUseDBinRunInfo ){
4096          a = false;    
4097          b = false;
4098          if ( obt < gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) ) a = true;
4099          if ( obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ) b = true;
4100        }
4101      if ( iev < totrunentrymin || iev > totrunentrymax // entry is outside run limits      if ( iev < totrunentrymin || iev > totrunentrymax // entry is outside run limits
4102           || iev == 0 // or it is the first entry           || iev == 0 // or it is the first entry
4103           || (!isSync && (           || (!isSync && (
4104                           (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)
4105                           || (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)
4106           ){ // check on abstime and obt needed to handle nested+DV_skipped packets           ){ // check on abstime and obt needed to handle nested+DV_skipped packets
4107                
4108        // 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 4110  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4110          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);
4111          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);
4112          printf("1        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);          printf("1        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4113          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));
4114          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);
4115          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);
4116        }        }
# Line 2914  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4137  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4137          totrunentry += GetRunInfo()->NEVENTS;          totrunentry += GetRunInfo()->NEVENTS;
4138          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
4139          irun = r;                  irun = r;        
4140            if ( fUseDBinRunInfo ){
4141              a = false;    
4142              b = false;
4143              if ( obt < gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) ) a = true;
4144              if ( obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ) b = true;
4145            }
4146          if ( (iev >= totrunentrymin && iev <= totrunentrymax) || // entry is inside run limits          if ( (iev >= totrunentrymin && iev <= totrunentrymax) || // entry is inside run limits
4147               ( !isSync &&               ( !isSync &&
4148                 ( 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)
4149                   && 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)
4150               ){ // check on abstime and obt needed to handle nested+DV_skipped packets               ){ // check on abstime and obt needed to handle nested+DV_skipped packets
4151            if ( totrunentrymin > iev ){ // there is a shift (nested+DV_skipped packets)            if ( totrunentrymin > iev ){ // there is a shift (nested+DV_skipped packets)
4152              if ( !isSync ){              if ( !isSync ){
# Line 2943  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4171  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4171                        
4172    
4173            //            //
4174            if (gltsync)            if ( fUseDBinRunInfo ){
4175              delete gltsync; // Emiliano              if (gltsync)
4176            if (!dbc || (dbc && !dbc->IsConnected()))                delete gltsync; // Emiliano
4177              SetDBConnection(); //Emiliano              if (!dbc || (dbc && !dbc->IsConnected()))
4178            gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano                SetDBConnection(); //Emiliano
4179            TrkParams::Set(GetRunInfo(), dbc);              gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano
4180            if (dbc){              TrkParams::Set(GetRunInfo(), dbc);
4181              dbc->Close(); // Emiliano              if (dbc){
4182              delete dbc;                dbc->Close(); // Emiliano
4183              dbc=0;                delete dbc;
4184            }                          dbc=0;
4185            if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano              }          
4186              cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun              if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano
4187                   << "  has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl;                cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun
4188              cout                     << "  has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl;
4189                << "                                                            (NB!! in this case some events could be assigned to a wrong run)"                cout
4190                << endl;                  << "                                                            (NB!! in this case some events could be assigned to a wrong run)"
4191                    << endl;
4192                }
4193            }            }
4194            //            //
4195            if (DBG) printf(" found \n");            if (DBG) printf(" found \n");
# Line 3016  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4246  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4246          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);
4247          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);
4248          printf("2        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);          printf("2        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4249          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));
4250          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);
4251          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);
4252        }        }
# Line 3107  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 4337  Bool_t PamLevel2::UpdateRunInfo(Long64_t
4337        // update the tracker parameters        // update the tracker parameters
4338        // (non ho trovato nessun altro modo sicuro di farlo...)        // (non ho trovato nessun altro modo sicuro di farlo...)
4339        // ----------------------------------------------------        // ----------------------------------------------------
4340        if (!dbc || (dbc && !dbc->IsConnected()))        if ( fUseDBinRunInfo ){
4341          SetDBConnection();          if (!dbc || (dbc && !dbc->IsConnected()))
4342        TrkParams::Set(GetRunInfo(), dbc);            SetDBConnection();
4343        if (dbc){          TrkParams::Set(GetRunInfo(), dbc);
4344          dbc->Close();          if (dbc){
4345          delete dbc;            dbc->Close();
4346          dbc=0;            delete dbc;
4347        };            dbc=0;
4348            }
4349          }
4350        //            cout << endl;        //            cout << endl;
4351        prevshift = 0;        prevshift = 0;
4352        yprevshift = 0;        yprevshift = 0;
# Line 3382  void PamLevel2::GetWhichTrees(TFile* f) Line 4614  void PamLevel2::GetWhichTrees(TFile* f)
4614    //    cout << "Checking file: "<<f->GetName()<<endl;    //    cout << "Checking file: "<<f->GetName()<<endl;
4615    if (!f || f->IsZombie()) {    if (!f || f->IsZombie()) {
4616      cout << "File: " << f->GetName() << " Non valid root file" << endl;      cout << "File: " << f->GetName() << " Non valid root file" << endl;
4617        fDiscarded = true;
4618      return;      return;
4619    }    }
4620    
# Line 3588  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4821  Bool_t PamLevel2::CheckLevel2File(TStrin
4821    TFile *f = new TFile(name.Data());    TFile *f = new TFile(name.Data());
4822    if (!f || f->IsZombie()) {    if (!f || f->IsZombie()) {
4823      cout << "File: " << f->GetName() << " discarded ---- Non valid root file" << endl;      cout << "File: " << f->GetName() << " discarded ---- Non valid root file" << endl;
4824        fDiscarded = true;
4825      return false;      return false;
4826    }    }
4827    //    cout << "Get list of keys: "<<f<<endl;    //    cout << "Get list of keys: "<<f<<endl;
# Line 3626  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4860  Bool_t PamLevel2::CheckLevel2File(TStrin
4860          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4861            cout << "File: " << f->GetName() << " discarded ---- SelectionList tree has " << nevt            cout << "File: " << f->GetName() << " discarded ---- SelectionList tree has " << nevt
4862                << " events instead of " << nev << endl;                << " events instead of " << nev << endl;
4863              fDiscarded = true;
4864            return false;            return false;
4865          }          }
4866          nev = nevt;          nev = nevt;
# Line 3640  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4875  Bool_t PamLevel2::CheckLevel2File(TStrin
4875          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4876            cout << "File: " << f->GetName() << " discarded ---- Trigger tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- Trigger tree has " << nevt << " events instead of "
4877                << nev << endl;                << nev << endl;
4878              fDiscarded = true;
4879            return false;            return false;
4880          }          }
4881          nev = nevt;          nev = nevt;
# Line 3653  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4889  Bool_t PamLevel2::CheckLevel2File(TStrin
4889          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4890            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
4891                << endl;                << endl;
4892              fDiscarded = true;
4893            return false;            return false;
4894          }          }
4895          nev = nevt;          nev = nevt;
# Line 3666  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4903  Bool_t PamLevel2::CheckLevel2File(TStrin
4903          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4904            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
4905                << endl;                << endl;
4906              fDiscarded = true;
4907            return false;            return false;
4908          }          }
4909          nev = nevt;          nev = nevt;
# Line 3680  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4918  Bool_t PamLevel2::CheckLevel2File(TStrin
4918          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4919            cout << "File: " << f->GetName() << " discarded ---- NeutronD tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- NeutronD tree has " << nevt << " events instead of "
4920                << nev << endl;                << nev << endl;
4921              fDiscarded = true;
4922            return false;            return false;
4923          }          }
4924          nev = nevt;          nev = nevt;
# Line 3693  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4932  Bool_t PamLevel2::CheckLevel2File(TStrin
4932          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4933            cout << "File: " << f->GetName() << " discarded ---- Anticounter tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- Anticounter tree has " << nevt << " events instead of "
4934                << nev << endl;                << nev << endl;
4935              fDiscarded = true;
4936            return false;            return false;
4937          }          }
4938          nev = nevt;          nev = nevt;
# Line 3706  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4946  Bool_t PamLevel2::CheckLevel2File(TStrin
4946          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4947            cout << "File: " << f->GetName() << " discarded ---- OrbitalInfo tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- OrbitalInfo tree has " << nevt << " events instead of "
4948                << nev << endl;                << nev << endl;
4949              fDiscarded = true;
4950            return false;            return false;
4951          }          }
4952          nev = nevt;          nev = nevt;
# Line 3719  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4960  Bool_t PamLevel2::CheckLevel2File(TStrin
4960          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4961            cout << "File: " << f->GetName() << " discarded ---- Tracker tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- Tracker tree has " << nevt << " events instead of "
4962                << nev << endl;                << nev << endl;
4963              fDiscarded = true;
4964            return false;            return false;
4965          }          }
4966          nev = nevt;          nev = nevt;
# Line 3742  Bool_t PamLevel2::CheckLevel2File(TStrin Line 4984  Bool_t PamLevel2::CheckLevel2File(TStrin
4984          if (nev && nevt != nev) {          if (nev && nevt != nev) {
4985            cout << "File: " << f->GetName() << " discarded ---- Calorimeter tree has " << nevt << " events instead of "            cout << "File: " << f->GetName() << " discarded ---- Calorimeter tree has " << nevt << " events instead of "
4986                << nev << endl;                << nev << endl;
4987              fDiscarded = true;
4988            return false;            return false;
4989          }          }
4990          nev = nevt;          nev = nevt;
# Line 3764  Bool_t PamLevel2::CheckLevel2File(TStrin Line 5007  Bool_t PamLevel2::CheckLevel2File(TStrin
5007          if (nev && nevt != nev) {          if (nev && nevt != nev) {
5008            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
5009                << endl;                << endl;
5010              fDiscarded = true;
5011            return false;            return false;
5012          }          }
5013          nev = nevt;          nev = nevt;
# Line 3776  Bool_t PamLevel2::CheckLevel2File(TStrin Line 5020  Bool_t PamLevel2::CheckLevel2File(TStrin
5020      SELLI = (Int_t) SELLI__ok;      SELLI = (Int_t) SELLI__ok;
5021    if (SELLI == 0 && SELLI__ok) {    if (SELLI == 0 && SELLI__ok) {
5022      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;
5023        fDiscarded = true;
5024      return false;      return false;
5025    }    }
5026    if (SELLI == 1 && !SELLI__ok) {    if (SELLI == 1 && !SELLI__ok) {
5027      cout << "File: " << f->GetName() << " discarded ---- SelectionList missing" << endl;      cout << "File: " << f->GetName() << " discarded ---- SelectionList missing" << endl;
5028        fDiscarded = true;
5029      return false;      return false;
5030    }    }
5031    
# Line 3818  Bool_t PamLevel2::CheckLevel2File(TStrin Line 5064  Bool_t PamLevel2::CheckLevel2File(TStrin
5064    
5065    if (CAL1 && !CAL1__ok) {    if (CAL1 && !CAL1__ok) {
5066      cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel1 branch" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel1 branch" << endl;
5067        fDiscarded = true;
5068      return false;      return false;
5069    };    };
5070    if (CAL2 && !CAL2__ok) {    if (CAL2 && !CAL2__ok) {
5071      cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel2 branch" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel2 branch" << endl;
5072        fDiscarded = true;
5073      return false;      return false;
5074    };    };
5075    if (TRK2 && !TRK2__ok) {    if (TRK2 && !TRK2__ok) {
5076      cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel2 branch" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel2 branch" << endl;
5077        fDiscarded = true;
5078      return false;      return false;
5079    };    };
5080    if (TRK1 && !TRK1__ok) {    if (TRK1 && !TRK1__ok) {
5081      cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel1 branch" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel1 branch" << endl;
5082        fDiscarded = true;
5083      return false;      return false;
5084    };    };
5085    if (TRKh && !TRKh__ok) {    if (TRKh && !TRKh__ok) {
5086      cout << "File: " << f->GetName() << " discarded ---- Missing TrkHough branch" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing TrkHough branch" << endl;
5087        fDiscarded = true;
5088      return false;      return false;
5089    };    };
5090    if (ORB && !ORB__ok) {    if (ORB && !ORB__ok) {
5091      cout << "File: " << f->GetName() << " discarded ---- Missing ORB tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing ORB tree" << endl;
5092        fDiscarded = true;
5093      return false;      return false;
5094    };    };
5095    if (AC && !AC__ok) {    if (AC && !AC__ok) {
5096      cout << "File: " << f->GetName() << " discarded ---- Missing AC tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing AC tree" << endl;
5097        fDiscarded = true;
5098      return false;      return false;
5099    };    };
5100    if (S4 && !S4__ok) {    if (S4 && !S4__ok) {
5101      cout << "File: " << f->GetName() << " discarded ---- Missing S4 tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing S4 tree" << endl;
5102        fDiscarded = true;
5103      return false;      return false;
5104    };    };
5105    if (TOF && !TOF__ok) {    if (TOF && !TOF__ok) {
5106      cout << "File: " << f->GetName() << " discarded ---- Missing ToF tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing ToF tree" << endl;
5107        fDiscarded = true;
5108      return false;      return false;
5109    };    };
5110    
5111    if (ND && !ND__ok) {    if (ND && !ND__ok) {
5112      cout << "File: " << f->GetName() << " discarded ---- Missing ND tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing ND tree" << endl;
5113        fDiscarded = true;
5114      return false;      return false;
5115    };    };
5116    if (TRG && !TRG__ok) {    if (TRG && !TRG__ok) {
5117      cout << "File: " << f->GetName() << " discarded ---- Missing Trigger tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing Trigger tree" << endl;
5118        fDiscarded = true;
5119      return false;      return false;
5120    };    };
5121    if (GP && !GP__ok) {    if (GP && !GP__ok) {
5122      cout << "File: " << f->GetName() << " discarded ---- Missing h20 tree" << endl;      cout << "File: " << f->GetName() << " discarded ---- Missing h20 tree" << endl;
5123        fDiscarded = true;
5124      return false;      return false;
5125    };    };
5126    
# Line 3962  void PamLevel2::CreateCloneTrees(TFile * Line 5220  void PamLevel2::CreateCloneTrees(TFile *
5220      //  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;
5221      run_tree_clone->Fill();      run_tree_clone->Fill();
5222    }    }
5223    cout << "----------------------------------------------------" << endl;    //
5224      // replicate processinginfo tree
5225      //
5226      if ( PROC ){ // EMEMEM
5227        proc_tree_clone = new TTree("ProcessingInfo","Log of data processing");
5228        proc_tree_clone->Branch("ProcInfo", "ProcInfo", GetPointerTo("ProcInfo"));
5229        cout << "ProcessingInfo: branch ProcessingInfo" << endl;  
5230        // ------------------
5231        // replicate processinginfo tree
5232        // ------------------
5233        //    cout << "----------------------------------------------------"<<endl;
5234        //    cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
5235        for (Int_t i = 0; i < proc_tree->GetEntries(); i++) {
5236          proc_tree->GetEntry(i);
5237          //      cout << i<< "\t | "<<endl;
5238          proc_tree_clone->Fill();
5239        }
5240        if ( SELLI != 2 ){      
5241          proc_obj->runID = 0;
5242          TTimeStamp *dt = new TTimeStamp();
5243          proc_obj->date = dt->AsString();
5244          delete dt;
5245          proc_obj->commandLine = Form("PamelaLevel2 was called: CAL2 %i CAL1 %i CAL0 %i TRK2 %i TRK1 %i TRKh %i TRK0 %i TOF %i TOF0 %i TRG %i \n                                            S4 %i ND %i AC %i ORB %i GP %i EXT %i NUC %i RUN %i ISGP %i SELLI %i \n Custom string   = %s",CAL2,CAL1,CAL0,TRK2,TRK1,TRKh,TRK0,TOF,TOF0,TRG,S4,ND,AC,ORB,GP,EXT,NUC,RUN,ISGP,SELLI,customString.Data());
5246          proc_obj->outputFilename = ofile->GetName();
5247          proc_obj->localDir = gSystem->WorkingDirectory();
5248          proc_obj->uname = gSystem->GetFromPipe("uname -a");
5249          if (!dbc || (dbc && !dbc->IsConnected())) SetDBConnection();
5250          proc_obj->DB = Form("mysql://%s/%s",dbc->GetHost(),dbc->GetDB());
5251          dbc->Close();
5252          proc_tree_clone->Fill();
5253        }
5254        cout << "----------------------------------------------------" << endl;
5255      }
5256    // ------------------------------------    // ------------------------------------
5257    // add branch with dead and live times    // add branch with dead and live times
5258    // ------------------------------------    // ------------------------------------
# Line 3995  void PamLevel2::CreateCloneTrees(TFile * Line 5284  void PamLevel2::CreateCloneTrees(TFile *
5284        pam_tree_clone[i]->Branch("TrkHough", "TrkHough", GetPointerTo("TrkHough"));        pam_tree_clone[i]->Branch("TrkHough", "TrkHough", GetPointerTo("TrkHough"));
5285        cout << "Tracker      : branch TrkHough" << endl;        cout << "Tracker      : branch TrkHough" << endl;
5286      };      };
5287        if(NUC){
5288            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&trk_nuc_obj);
5289            cout << "Tracker      : branch TrackNuclei" << endl;    
5290        }
5291        if(EXT){
5292            pam_tree_clone[i]->Branch("extAlgFlag",&extAlgFlag,"extAlgFlag/I");
5293            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&trk_ext_obj);
5294            cout << "Tracker      : branch RecoveredTrack" << endl;
5295            if(NUC){
5296                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&trk_ext_nuc_obj);
5297                cout << "Tracker      : branch RecoveredTrackNuclei" << endl;                  
5298            }
5299        }
5300    
5301      i++;      i++;
5302    }    }
5303    
# Line 4009  void PamLevel2::CreateCloneTrees(TFile * Line 5312  void PamLevel2::CreateCloneTrees(TFile *
5312        pam_tree_clone[i]->Branch("CaloLevel2", "CaloLevel2", GetPointerTo("CaloLevel2"));        pam_tree_clone[i]->Branch("CaloLevel2", "CaloLevel2", GetPointerTo("CaloLevel2"));
5313        cout << "Calorimeter  : branch CaloLevel2" << endl;        cout << "Calorimeter  : branch CaloLevel2" << endl;
5314      };      };
5315        if(NUC){
5316            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&calo_nuc_obj);
5317            cout << "Calorimeter  : branch TrackNuclei" << endl;    
5318        }
5319        if(EXT){
5320            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&calo_ext_obj);
5321            cout << "Calorimeter  : branch RecoveredTrack" << endl;
5322            if(NUC){
5323                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&calo_ext_nuc_obj);
5324                cout << "Calorimeter  : branch RecoveredTrackNuclei" << endl;                  
5325            }
5326        }
5327      i++;      i++;
5328    }    }
5329    
# Line 4017  void PamLevel2::CreateCloneTrees(TFile * Line 5332  void PamLevel2::CreateCloneTrees(TFile *
5332      pam_tree_clone[i] = new TTree("ToF", "PAMELA ToF level2 data ");      pam_tree_clone[i] = new TTree("ToF", "PAMELA ToF level2 data ");
5333      pam_tree_clone[i]->Branch("ToFLevel2", "ToFLevel2", GetPointerTo("ToFLevel2"));      pam_tree_clone[i]->Branch("ToFLevel2", "ToFLevel2", GetPointerTo("ToFLevel2"));
5334      cout << "ToF          : branch ToFLevel2" << endl;      cout << "ToF          : branch ToFLevel2" << endl;
5335        if(NUC){
5336            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&tof_nuc_obj);
5337            cout << "ToF          : branch TrackNuclei" << endl;    
5338        }
5339        if(EXT){
5340            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&tof_ext_obj);
5341            cout << "ToF          : branch RecoveredTrack" << endl;
5342            if(NUC){
5343                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&tof_ext_nuc_obj);
5344                cout << "ToF          : branch RecoveredTrackNuclei" << endl;                  
5345            }
5346        }
5347      i++;      i++;
5348    };    };
5349    // Trigger    // Trigger
# Line 4052  void PamLevel2::CreateCloneTrees(TFile * Line 5379  void PamLevel2::CreateCloneTrees(TFile *
5379      pam_tree_clone[i] = new TTree("OrbitalInfo", "PAMELA orbital info  ");      pam_tree_clone[i] = new TTree("OrbitalInfo", "PAMELA orbital info  ");
5380      pam_tree_clone[i]->Branch("OrbitalInfo", "OrbitalInfo", GetPointerTo("OrbitalInfo"));      pam_tree_clone[i]->Branch("OrbitalInfo", "OrbitalInfo", GetPointerTo("OrbitalInfo"));
5381      cout << "OrbitalInfo  : branch OrbitalInfo" << endl;      cout << "OrbitalInfo  : branch OrbitalInfo" << endl;
5382        if(NUC){
5383            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&orb_nuc_obj);
5384            cout << "OrbitalInfo  : branch TrackNuclei" << endl;    
5385        }
5386        if(EXT){
5387            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&orb_ext_obj);
5388            cout << "OrbitalInfo  : branch RecoveredTrack" << endl;
5389            if(NUC){
5390                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&orb_ext_nuc_obj);
5391                cout << "OrbitalInfo  : branch RecoveredTrackNuclei" << endl;                  
5392            }
5393        }
5394      i++;      i++;
5395    };    };
5396    // GPamela    // GPamela
# Line 4061  void PamLevel2::CreateCloneTrees(TFile * Line 5400  void PamLevel2::CreateCloneTrees(TFile *
5400      cout << "GPamela  : branch GPamela" << endl;      cout << "GPamela  : branch GPamela" << endl;
5401      i++;      i++;
5402    };    };
5403    
5404    
5405    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
5406    
5407  }  }
# Line 4102  TTree* PamLevel2::GetCloneTree(TString n Line 5443  TTree* PamLevel2::GetCloneTree(TString n
5443      if (!name.CompareTo(na))      if (!name.CompareTo(na))
5444        return sel_tree_clone;        return sel_tree_clone;
5445    }    }
5446      if (proc_tree_clone && PROC) {
5447        TString na = proc_tree_clone->GetName();
5448        if (!name.CompareTo(na))
5449          return proc_tree_clone;
5450      }
5451    return NULL;    return NULL;
5452    
5453  }  }
# Line 4121  void PamLevel2::WriteCloneTrees() { Line 5467  void PamLevel2::WriteCloneTrees() {
5467    for (Int_t i = 0; i < NCLONES; i++) {    for (Int_t i = 0; i < NCLONES; i++) {
5468      if (pam_tree_clone[i]) {      if (pam_tree_clone[i]) {
5469        cout << pam_tree_clone[i]->GetName() << endl;        cout << pam_tree_clone[i]->GetName() << endl;
5470        pam_tree_clone[i]->Write();        pam_tree_clone[i]->Write(pam_tree_clone[i]->GetName(),TObject::kOverwrite);
5471      };      };
5472    }    }
5473      
5474      if ( PROC ){//EMEMEMEM
5475        proc_tree_clone->Write("ProcessingInfo",TObject::kOverwrite);
5476      }
5477    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
5478    
5479  }  }
# Line 4745  Long64_t PamLevel2::GetReadEntry() { Line 6095  Long64_t PamLevel2::GetReadEntry() {
6095  void PamLevel2::SetSortingMethod(TString how) {  void PamLevel2::SetSortingMethod(TString how) {
6096    if (howtosort != how) {    if (howtosort != how) {
6097      issorted = false;      issorted = false;
6098        issorted_new = false;
6099    }    }
6100    howtosort = how;    howtosort = how;
6101  }  }

Legend:
Removed from v.1.93  
changed lines
  Added in v.1.109

  ViewVC Help
Powered by ViewVC 1.1.23