| 112 | 
  | 
  | 
| 113 | 
 void PamLevel2::Initialize(){ | 
 void PamLevel2::Initialize(){ | 
| 114 | 
          | 
          | 
 | 
 //     trk2_obj  = TrkLevel2::GetTrkLevel2(); | 
  | 
 | 
 //     trk1_obj  = TrkLevel1::GetTrkLevel1(); | 
  | 
 | 
 //     trkh_obj  = TrkHough::GetTrkHough(); | 
  | 
 | 
 //     calo1_obj = CaloLevel1::GetCaloLevel1(); | 
  | 
 | 
 //     calo2_obj = CaloLevel2::GetCaloLevel2(); | 
  | 
 | 
 //     tof_obj   = ToFLevel2::GetToFLevel2(); | 
  | 
 | 
 //     trig_obj  = TrigLevel2::GetTrigLevel2(); | 
  | 
 | 
 //     s4_obj    = S4Level2::GetS4Level2(); | 
  | 
 | 
 //     nd_obj    = NDLevel2::GetNDLevel2(); | 
  | 
 | 
 //     ac_obj    = AcLevel2::GetAcLevel2(); | 
  | 
 | 
 //     orb_obj   = OrbitalInfo::GetOrbitalInfo(); | 
  | 
 | 
      | 
  | 
| 115 | 
     h0_obj    = 0; | 
     h0_obj    = 0; | 
| 116 | 
     trk0_obj  = 0; | 
     trk0_obj  = 0; | 
| 117 | 
     calo0_obj  = 0; | 
     calo0_obj  = 0; | 
| 186 | 
  | 
  | 
| 187 | 
     SELLI = -1; | 
     SELLI = -1; | 
| 188 | 
  | 
  | 
| 189 | 
  | 
     ISGP = false; | 
| 190 | 
  | 
  | 
| 191 | 
     tsorted=0; | 
     tsorted=0; | 
| 192 | 
     timage=0; | 
     timage=0; | 
| 193 | 
      | 
      | 
| 1908 | 
       // | 
       // | 
| 1909 | 
       // the absolute time is necessary to relate the event with the run | 
       // the absolute time is necessary to relate the event with the run | 
| 1910 | 
       // | 
       // | 
| 1911 | 
       if( !GetOrbitalInfo() ){ | 
       if( !GetOrbitalInfo() && !ISGP){ | 
| 1912 | 
           cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl; | 
           cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl; | 
| 1913 | 
           return(false); | 
           return(false); | 
| 1914 | 
       } | 
       } | 
| 1915 | 
  | 
  | 
| 1916 | 
  | 
       ULong64_t abstime = 0; | 
| 1917 | 
  | 
       if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime; | 
| 1918 | 
  | 
  | 
| 1919 | 
  | 
  | 
| 1920 | 
       // | 
       // | 
| 1921 | 
       // the first time the routine is called, set run search from the beginning | 
       // the first time the routine is called, set run search from the beginning | 
| 1922 | 
       // | 
       // | 
| 1926 | 
           runfirstentry = 0LL; | 
           runfirstentry = 0LL; | 
| 1927 | 
           runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS); | 
           runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS); | 
| 1928 | 
           if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL; | 
           if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL; | 
| 1929 | 
  | 
            | 
| 1930 | 
  | 
           if( ISGP && run->GetEntries()!=1 ){ | 
| 1931 | 
  | 
               cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl; | 
| 1932 | 
  | 
               cout << "** WARNING ** run will not be updated"<<endl; | 
| 1933 | 
  | 
           } | 
| 1934 | 
  | 
  | 
| 1935 | 
       };       | 
       };       | 
| 1936 | 
       // | 
       // | 
| 1937 | 
        if ( irun == run->GetEntries()-1LL &&  | 
       if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO | 
| 1938 | 
            !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME &&  | 
       // | 
| 1939 | 
              GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME)  | 
       if ( irun == run->GetEntries()-1LL &&  | 
| 1940 | 
  | 
            !(abstime >= GetRunInfo()->RUNHEADER_TIME &&  | 
| 1941 | 
  | 
              abstime <= GetRunInfo()->RUNTRAILER_TIME)  | 
| 1942 | 
             ){ | 
             ){ | 
| 1943 | 
          irun = -1LL; | 
          irun = -1LL; | 
| 1944 | 
          runfirstentry = 0LL; | 
          runfirstentry = 0LL; | 
| 1949 | 
       // | 
       // | 
| 1950 | 
       bool fromfirst = true; | 
       bool fromfirst = true; | 
| 1951 | 
       // | 
       // | 
| 1952 | 
       while ( !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME && GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){ | 
       while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){ | 
| 1953 | 
 //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){ | 
 //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){ | 
| 1954 | 
           irun++; | 
           irun++; | 
| 1955 | 
           run->GetEntry(irun); | 
           run->GetEntry(irun); | 
| 1959 | 
 //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl; | 
 //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl; | 
| 1960 | 
 //        cout << "runfirstentry "<<runfirstentry<<endl; | 
 //        cout << "runfirstentry "<<runfirstentry<<endl; | 
| 1961 | 
           //      printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS))); | 
           //      printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS))); | 
| 1962 | 
           //      printf(" abstime %u trailertime %u \n",GetOrbitalInfo()->absTime,GetRunInfo()->RUNTRAILER_TIME); | 
           //      printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME); | 
| 1963 | 
           //      printf(" IDRUN %u \n",GetRunInfo()->ID); | 
           //      printf(" IDRUN %u \n",GetRunInfo()->ID); | 
| 1964 | 
           // | 
           // | 
| 1965 | 
 //        prevshift = 0; | 
 //        prevshift = 0; | 
| 1966 | 
           // | 
           // | 
| 1967 | 
           if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME && GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME)){ | 
           if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)){ | 
| 1968 | 
               printf(" resetting irun  (it should NOT happen!!!)\n"); | 
               printf(" resetting irun  (it should NOT happen!!!)\n"); | 
| 1969 | 
               fromfirst = false; | 
               fromfirst = false; | 
| 1970 | 
               irun = 0; | 
               irun = 0; | 
| 1977 | 
       }; | 
       }; | 
| 1978 | 
       // | 
       // | 
| 1979 | 
       if (  | 
       if (  | 
| 1980 | 
            !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME &&  | 
            !(abstime >= GetRunInfo()->RUNHEADER_TIME &&  | 
| 1981 | 
              GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME)  | 
              abstime <= GetRunInfo()->RUNTRAILER_TIME)  | 
| 1982 | 
           ) { | 
           ) { | 
| 1983 | 
           printf(" Something very wrong here: cannot find RUN containing absolute time %u \n",GetOrbitalInfo()->absTime); | 
           printf(" Something very wrong here: cannot find RUN containing absolute time %u \n",abstime); | 
| 1984 | 
           return false; | 
           return false; | 
| 1985 | 
       } | 
       } | 
| 1986 | 
       // | 
       // | 
| 2031 | 
     // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- | 
     // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- | 
| 2032 | 
     if(SELLI==0){ | 
     if(SELLI==0){ | 
| 2033 | 
  | 
  | 
| 2034 | 
  | 
         ULong64_t abstime = 0; | 
| 2035 | 
  | 
         ULong64_t obt     = 0; | 
| 2036 | 
  | 
         if( GetOrbitalInfo() ){ | 
| 2037 | 
  | 
             abstime = GetOrbitalInfo()->absTime; | 
| 2038 | 
  | 
             obt     = GetOrbitalInfo()->OBT; | 
| 2039 | 
  | 
         } | 
| 2040 | 
         // --------------------------------------------------------------- | 
         // --------------------------------------------------------------- | 
| 2041 | 
         // the absolute time is necessary to relate the event with the run | 
         // the absolute time is necessary to relate the event with the run | 
| 2042 | 
         // --------------------------------------------------------------- | 
         // --------------------------------------------------------------- | 
| 2043 | 
         if( !GetOrbitalInfo() ){ | 
         if( !GetOrbitalInfo() && !ISGP ){ | 
| 2044 | 
             cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl; | 
             cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl; | 
| 2045 | 
             return(false); | 
             return(false); | 
| 2046 | 
         } | 
         } | 
| 2053 | 
             irunentry = 0; | 
             irunentry = 0; | 
| 2054 | 
             prevshift = 0; | 
             prevshift = 0; | 
| 2055 | 
             run_tree->GetEntry(irun); | 
             run_tree->GetEntry(irun); | 
| 2056 | 
  | 
  | 
| 2057 | 
  | 
             if( ISGP && run_tree->GetEntries()!=1 ){ | 
| 2058 | 
  | 
                 cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl; | 
| 2059 | 
  | 
                 cout << "** WARNING ** run will not be updated"<<endl; | 
| 2060 | 
  | 
             } | 
| 2061 | 
         };       | 
         };       | 
| 2062 | 
  | 
  | 
| 2063 | 
  | 
         // ----------------------------------------------------------------------- | 
| 2064 | 
  | 
         // if it is simulation, assigh abstime by end (temporaneo!!!) | 
| 2065 | 
  | 
         // ----------------------------------------------------------------------- | 
| 2066 | 
  | 
         if(ISGP){ | 
| 2067 | 
  | 
             abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO | 
| 2068 | 
  | 
             obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO | 
| 2069 | 
  | 
         } | 
| 2070 | 
         // | 
         // | 
| 2071 | 
         bool fromfirst = true; // first loop over runs | 
         bool fromfirst = true; // first loop over runs | 
| 2072 | 
  | 
  | 
| 2080 | 
         while (  | 
         while (  | 
| 2081 | 
             ( | 
             ( | 
| 2082 | 
                 ( | 
                 ( | 
| 2083 | 
                     !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s) | 
                     !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s) | 
| 2084 | 
                       GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME) &&  | 
                       abstime <= GetRunInfo()->RUNTRAILER_TIME) &&  | 
| 2085 | 
                     !(GetOrbitalInfo()->OBT >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms) | 
                     !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms) | 
| 2086 | 
                       GetOrbitalInfo()->OBT <= GetRunInfo()->RUNTRAILER_OBT) | 
                       obt <= GetRunInfo()->RUNTRAILER_OBT) | 
| 2087 | 
                     )  | 
                     )  | 
| 2088 | 
                 || GetRunInfo()->NEVENTS==0  | 
                 || GetRunInfo()->NEVENTS==0  | 
| 2089 | 
                 || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) | 
                 || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) | 
| 3199 | 
  | 
  | 
| 3200 | 
 //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl; | 
 //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl; | 
| 3201 | 
 //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl; | 
 //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl; | 
| 3202 | 
 //     cout << " time "<< GetOrbitalInfo()->absTime << endl; | 
 //     cout << " time "<< abstime << endl; | 
| 3203 | 
 //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl; | 
 //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl; | 
| 3204 | 
      | 
      | 
| 3205 | 
     if( !GetOrbitalInfo() ){ | 
     ULong64_t obt     = 0; | 
| 3206 | 
  | 
     ULong64_t pktn    = 0; | 
| 3207 | 
  | 
     if( GetOrbitalInfo() ){  | 
| 3208 | 
  | 
         obt     = GetOrbitalInfo()->OBT; | 
| 3209 | 
  | 
         pktn    = GetOrbitalInfo()->pkt_num; | 
| 3210 | 
  | 
     } | 
| 3211 | 
  | 
  | 
| 3212 | 
  | 
     if( !GetOrbitalInfo() && !ISGP){ | 
| 3213 | 
         cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl; | 
         cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl; | 
| 3214 | 
         return 0; | 
         return 0; | 
| 3215 | 
     } | 
     } | 
| 3216 | 
     if( GetOrbitalInfo()->OBT==0 && GetOrbitalInfo()->pkt_num==0 ){ | 
     if( obt==0 && pktn==0 && !ISGP ){ | 
| 3217 | 
         cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<<endl;  | 
         cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<<endl;  | 
| 3218 | 
         return 0; | 
         return 0; | 
| 3219 | 
     } | 
     } | 
| 3235 | 
     Int_t maxshift = 10; | 
     Int_t maxshift = 10; | 
| 3236 | 
     do{ | 
     do{ | 
| 3237 | 
         if(shift>0){      | 
         if(shift>0){      | 
| 3238 | 
             cout << " PKTNUM  L2 --- "<< GetOrbitalInfo()->pkt_num << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl; | 
             cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl; | 
| 3239 | 
             cout << "         RUN: ID "<< GetRunInfo()->ID << " ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<" ID_RUN_FRAG "<<GetRunInfo()->ID_RUN_FRAG << " EV_FROM "<<GetRunInfo()->EV_FROM  <<endl; | 
             cout << "         RUN: ID "<< GetRunInfo()->ID << " ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<" ID_RUN_FRAG "<<GetRunInfo()->ID_RUN_FRAG << " EV_FROM "<<GetRunInfo()->EV_FROM  <<endl; | 
| 3240 | 
             cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl; | 
             cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl; | 
| 3241 | 
         } | 
         } | 
| 3245 | 
             cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl; | 
             cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl; | 
| 3246 | 
             return 0; | 
             return 0; | 
| 3247 | 
         } | 
         } | 
| 3248 | 
 //      cout << "PKTNUM "<<shift<<" ==  L2 --- "<< GetOrbitalInfo()->pkt_num << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl; | 
  | 
| 3249 | 
 //      cout << " L2 --- "<< GetOrbitalInfo()->OBT << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl; | 
         if(ISGP){ | 
| 3250 | 
  | 
             obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO | 
| 3251 | 
  | 
             pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO | 
| 3252 | 
  | 
         } | 
| 3253 | 
  | 
  | 
| 3254 | 
  | 
 //      cout << "PKTNUM "<<shift<<" ==  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl; | 
| 3255 | 
  | 
 //      cout << " L2 --- "<< obt << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl; | 
| 3256 | 
 //      if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;  | 
 //      if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;  | 
| 3257 | 
 //      cout << " GetOrbitalInfo()->OBT "<< GetOrbitalInfo()->OBT << endl; | 
 //      cout << " obt "<< obt << endl; | 
| 3258 | 
 //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl; | 
 //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl; | 
| 3259 | 
 //      cout << " GetOrbitalInfo()->pkt_num "<< GetOrbitalInfo()->pkt_num << endl; | 
 //      cout << " pktn "<< pktn << endl; | 
| 3260 | 
 //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl; | 
 //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl; | 
| 3261 | 
 //      printf(" IDRUN %u \n",GetRunInfo()->ID); | 
 //      printf(" IDRUN %u \n",GetRunInfo()->ID); | 
| 3262 | 
 // | 
 // | 
| 3265 | 
           shift = -1; | 
           shift = -1; | 
| 3266 | 
         }; | 
         }; | 
| 3267 | 
  | 
  | 
| 3268 | 
     }while( ( GetOrbitalInfo()->OBT != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || GetOrbitalInfo()->pkt_num != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift); | 
     }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||  | 
| 3269 | 
  | 
               pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())       )  | 
| 3270 | 
  | 
             && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift); | 
| 3271 | 
  | 
  | 
| 3272 | 
     if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) { | 
     if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) { | 
| 3273 | 
         cout << " Big trouble here, no such event in Level0 data! " <<endl; | 
         cout << " Big trouble here, no such event in Level0 data! " <<endl; |