Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

NtpStRecord.cxx

Go to the documentation of this file.
00001 
00002 // 
00003 // NtpStRecord
00004 //
00005 // NtpStRecord is a standard reconstruction & mc ntuple record.
00006 //
00008 
00009 // C++ 
00010 #include <iostream>
00011 
00012 // ROOT
00013 #include "TClonesArray.h"
00014 
00015 // MINOS headers
00016 #include "Record/RecArrayAllocator.h"
00017 #include "CandNtupleSR/NtpSRSlice.h"
00018 #include "CandNtupleSR/NtpSRCluster.h"
00019 #include "CandNtupleSR/NtpSRShower.h"
00020 #include "CandNtupleSR/NtpSRTrack.h"
00021 #include "CandNtupleSR/NtpSREvent.h"
00022 #include "CandNtupleSR/NtpSRStrip.h"
00023 #include "CandNtupleSR/NtpSRDeadChip.h"
00024 #include "MCNtuple/NtpMCTruth.h"
00025 #include "MCNtuple/NtpMCStdHep.h"
00026 #include "TruthHelperNtuple/NtpTHEvent.h"
00027 #include "TruthHelperNtuple/NtpTHTrack.h"
00028 #include "TruthHelperNtuple/NtpTHShower.h"
00029 #include "MessageService/MsgService.h"
00030 
00031 // Local package headers
00032 #include "StandardNtuple/NtpStRecord.h"
00033 
00034 CVSID("$Id: NtpStRecord.cxx,v 1.15 2008/02/04 02:34:29 schubert Exp $");
00035 
00036 ClassImp(NtpStRecord)
00037 
00038 // put using namespace std after all headers
00039 using namespace std;
00040 
00041 //_____________________________________________________________________________
00042 NtpStRecord::NtpStRecord() : 
00043   RecRecordImp<RecCandHeader>(),vetostp(0),vetoexp(0),deadchips(0),stp(0),
00044    slc(0),clu(0),shw(0),trk(0),evt(0),mc(0),stdhep(0),digihit(0),thstp(0),
00045    thslc(0),thshw(0),thtrk(0),thevt(0) {
00046    // Purpose: Default constructor
00047 
00048   MSG("NtpSt",Msg::kVerbose) << "NtpStRecord def ctor at " << this << endl;
00049   this -> Init();  
00050 }
00051 
00052 //_____________________________________________________________________________
00053 NtpStRecord::NtpStRecord(const RecCandHeader& hdr) : 
00054   RecRecordImp<RecCandHeader>(hdr),vetostp(0),vetoexp(0),deadchips(0),stp(0),slc(0),clu(0),
00055   shw(0),trk(0),evt(0),mc(0),stdhep(0),digihit(0),thstp(0),thslc(0),thshw(0),
00056   thtrk(0),thevt(0) {
00057   // Purpose: Normal constructor
00058 
00059   MSG("NtpSt",Msg::kVerbose) << "NtpStRecord normal ctor at " << this << endl;
00060   this -> Init(); 
00061 }
00062 
00063 //_____________________________________________________________________________
00064 NtpStRecord::~NtpStRecord() {
00065   // Purpose: Destructor
00066 
00067   MSG("NtpSt",Msg::kVerbose) << "NtpStRecord dtor at " << this << endl;
00068   // Release arrays back to TClonesArray pool for reuse
00069   // Allocated memory of stored objects is retrieved via object Clear call
00070   RecArrayAllocator& allocator = RecArrayAllocator::Instance();
00071   if ( vetostp ) { allocator.ReleaseArray(vetostp); vetostp = 0; }
00072   if ( vetoexp ) { allocator.ReleaseArray(vetoexp); vetoexp = 0; }
00073   if ( deadchips ) { allocator.ReleaseArray(deadchips); deadchips = 0; }
00074   if ( stp ) { allocator.ReleaseArray(stp); stp = 0; }
00075   if ( slc ) { allocator.ReleaseArray(slc); slc = 0; }
00076   if ( clu ) { allocator.ReleaseArray(clu); clu = 0; }
00077   if ( shw ) { allocator.ReleaseArray(shw); shw = 0; }
00078   if ( trk ) { allocator.ReleaseArray(trk); trk = 0; }
00079   if ( evt ) { allocator.ReleaseArray(evt); evt = 0; }
00080   if ( mc ) { allocator.ReleaseArray(mc); mc = 0; }
00081   if ( stdhep ) { allocator.ReleaseArray(stdhep); stdhep = 0; }
00082   if ( digihit )  { allocator.ReleaseArray(digihit); digihit = 0; }
00083   if ( thstp ) { allocator.ReleaseArray(thstp); thstp = 0; }
00084   if ( thslc ) { allocator.ReleaseArray(thslc); thslc = 0; }
00085   if ( thshw ) { allocator.ReleaseArray(thshw); thshw = 0; }
00086   if ( thtrk ) { allocator.ReleaseArray(thtrk); thtrk = 0; }
00087   if ( thevt ) { allocator.ReleaseArray(thevt); thevt = 0; }
00088 
00089 }
00090 
00091 //_____________________________________________________________________________
00092 void NtpStRecord::Clear(Option_t* /* option */) {
00093   // Purpose: Clear memory allocated to arrays so that record can
00094   // be reused.  
00095 
00096   detsim.Clear();
00097   if ( vetostp ) { vetostp -> Clear("C"); }
00098   if ( vetoexp ) { vetoexp -> Clear("C"); }
00099   if ( deadchips ) { deadchips->Clear("C"); }
00100   if ( stp ) { stp -> Clear("C"); }
00101   if ( slc ) { slc -> Clear("C"); }
00102   if ( clu ) { clu -> Clear("C"); }
00103   if ( shw ) { shw -> Clear("C"); }
00104   if ( trk ) { trk -> Clear("C"); }
00105   if ( evt ) { evt -> Clear("C"); }
00106   if ( mc ) { mc -> Clear("C"); }
00107   if ( stdhep ) { stdhep -> Clear("C"); }
00108   if ( digihit ) { digihit -> Clear("C"); }  
00109   if ( thstp ) { thstp -> Clear("C"); }
00110   if ( thslc ) { thslc -> Clear("C"); }
00111   if ( thshw ) { thshw -> Clear("C"); }
00112   if ( thtrk ) { thtrk -> Clear("C"); }
00113   if ( thevt ) { thevt -> Clear("C"); }
00114 
00115 }
00116 
00117 //_____________________________________________________________________________
00118 void NtpStRecord::ClearStrips(Option_t* /* option */) {
00119   // Purpose: Clear strip and digihit information to reduce output file size
00120 
00121   // Standard reconstruction
00122   if ( vetostp ) { vetostp -> Clear("C"); } // clear array and contents
00123   if ( vetoexp ) { vetoexp -> Clear("C"); } //clear array and contents 
00124   if ( stp ) { stp -> Clear("C"); } // clear array and contents
00125   if ( slc ) {
00126     TClonesArray& slicearray = *(slc);
00127     for ( int islc = 0; islc <= slicearray.GetLast(); islc++ ) {
00128       NtpSRSlice* ntpslice = dynamic_cast<NtpSRSlice*>(slicearray.At(islc));
00129       ntpslice -> ClearStrips();
00130     }
00131   }
00132 
00133   if ( clu ) {
00134     TClonesArray& clusterarray = *(clu);
00135     for ( int iclu = 0; iclu <= clusterarray.GetLast(); iclu++ ) {
00136       NtpSRCluster* ntpcluster=dynamic_cast<NtpSRCluster*>
00137                                          (clusterarray.At(iclu));
00138       ntpcluster -> ClearStrips();
00139     }
00140   }
00141 
00142   if ( shw ) {
00143     TClonesArray& showerarray = *(shw);
00144     for ( int ishw = 0; ishw <= showerarray.GetLast(); ishw++ ) {
00145       NtpSRShower* ntpshower=dynamic_cast<NtpSRShower*>(showerarray.At(ishw));
00146       ntpshower -> ClearStrips();
00147     }
00148   }
00149 
00150   if ( trk ) {
00151     TClonesArray& trackarray = *(trk);
00152     for ( int itrk = 0; itrk <= trackarray.GetLast(); itrk++ ) {
00153       NtpSRTrack* ntptrack=dynamic_cast<NtpSRTrack*>(trackarray.At(itrk));
00154       ntptrack -> ClearStrips();
00155     }
00156   }
00157 
00158   if ( evt ) {
00159     TClonesArray& eventarray = *(evt);
00160     for ( int ievt = 0; ievt <= eventarray.GetLast(); ievt++ ) {
00161       NtpSREvent* ntpevent=dynamic_cast<NtpSREvent*>(eventarray.At(ievt));
00162       ntpevent -> ClearStrips();
00163     }
00164   }
00165 
00166   // Monte carlo
00167   if ( digihit ) { digihit -> Clear("C"); } // clear array and contents
00168 
00169   // Truth helper
00170   if ( thstp ) { thstp -> Clear("C"); } // clear array and contents
00171 
00172 }
00173 
00174 
00175 //_____________________________________________________________________________
00176 void NtpStRecord::Init() {
00177   // 
00178   // Purpose: Initialize ntuple TClonesArrays
00179   //
00180 
00181   // Set variable in record base class to indicate that it is possible
00182   // to recover dynamic memory using Clear() method for this record type
00183   SetClearable(true);
00184   
00185   RecArrayAllocator& allocator = RecArrayAllocator::Instance();
00186   if ( !vetostp ) vetostp = allocator.GetArray("NtpSRShieldStrip");
00187   if ( !vetoexp ) vetoexp = allocator.GetArray("NtpSRShieldExpected"); 
00188   if ( !deadchips ) deadchips = allocator.GetArray("NtpSRDeadChip");
00189   if ( !stp ) stp = allocator.GetArray("NtpSRStrip");
00190   if ( !slc ) slc = allocator.GetArray("NtpSRSlice");
00191   if ( !clu ) clu = allocator.GetArray("NtpSRCluster");
00192   if ( !shw ) shw = allocator.GetArray("NtpSRShower");
00193   if ( !trk ) trk = allocator.GetArray("NtpSRTrack");
00194   if ( !evt ) evt = allocator.GetArray("NtpSREvent");
00195   if ( !mc )   mc = allocator.GetArray("NtpMCTruth");
00196   if ( !stdhep ) stdhep = allocator.GetArray("NtpMCStdHep");
00197   if ( !digihit ) digihit = allocator.GetArray("NtpMCDigiScintHit");
00198   if ( !thstp ) thstp = allocator.GetArray("NtpTHStrip");
00199   if ( !thslc ) thslc = allocator.GetArray("NtpTHSlice");
00200   if ( !thshw ) thshw = allocator.GetArray("NtpTHShower");
00201   if ( !thtrk ) thtrk = allocator.GetArray("NtpTHTrack");
00202   if ( !thevt ) thevt = allocator.GetArray("NtpTHEvent");
00203 
00204 }
00205 
00206 //_____________________________________________________________________________
00207 std::ostream& NtpStRecord::Print(std::ostream& os) const {
00208   //
00209   // Purpose: Print status of ntuple record on ostream
00210   //
00211 
00212   os << "NtpStRecord::Print" << endl;
00213   RecRecordImp<RecCandHeader>::Print(os);
00214 
00215   return os;
00216 
00217 }
00218 
00219 //_____________________________________________________________________________
00220 void NtpStRecord::Print(Option_t* /* option */) const {
00221   //
00222   // Purpose: Print record in form supported by TObject::Print
00223   //
00224 
00225   Print(std::cout);
00226   return;
00227 
00228 }
00229 
00230 //_____________________________________________________________________________
00231 ReleaseType::Release_t NtpStRecord::GetRelease() const {
00232   //
00233   // Purpose: Return the Official ReleaseType determination of this record
00234   //
00235 
00236   // First try using "modern" method of retrieving release type from 
00237   // job history.  If that fails, try using old method to
00238   // retrieve release type by title.
00239   ReleaseType::Release_t release 
00240              = GetJobHistory().GetProdReleaseType(RecJobHistory::kGMinos |
00241                                                   RecJobHistory::kCand);
00242   if (release != ReleaseType::kUnknown ) return release;
00243     
00244   std::string relName = GetTitle();
00245 
00246   std::string mcinfo = "";
00247   if(GetHeader().GetVldContext().GetSimFlag() == SimFlag::kMC){
00248      mcinfo = "Carrot";
00249      string temp = mchdr.geninfo.codename;
00250      if(temp.size() != 0){   mcinfo = temp;  }
00251   }
00252   return ReleaseType::MakeReleaseType(relName, mcinfo);
00253 
00254 }
00255 
00256 //_____________________________________________________________________________
00257 vector<const NtpSREvent *> NtpStRecord::GetEvents() const {
00258   // Get all events in a record. 
00259 
00260   vector<const NtpSREvent *> events; // empty list of events
00261 
00262   const int nevent = this -> evt -> GetEntriesFast();
00263   if (nevent < 1) return events; // return empty list if no events
00264 
00265    for(int i = 0; i < nevent; ++i) {
00266       const NtpSREvent* ntp_event 
00267                 = dynamic_cast<const NtpSREvent*>(this -> evt -> At(i));
00268       if(!ntp_event) {
00269          MSG("NtpSt", Msg::kWarning) << "Failed to get NtpSREvent pointer at "
00270                                      << i << " index." << endl;
00271          continue;
00272       }
00273       events.push_back(ntp_event);
00274    }
00275    
00276    return events;
00277 }
00278 
00279 //_____________________________________________________________________________
00280 vector<const NtpSRStrip *> NtpStRecord::GetStrips(const int event_index) const{
00281 // Get strips associated with event_index.  
00282 // If event_index < 0 (default) return all strips in record.  
00283 
00284    vector<const NtpSRStrip *> strips; // empty list of strips
00285    
00286    if( event_index >= this -> evt -> GetEntriesFast()) {
00287       MSG("NtpSt",Msg::kWarning) 
00288       << "GetStrips w/event index " << event_index
00289       << "\nis too large for evt array size " << this->evt->GetEntriesFast()
00290       << "." << endl;
00291       return strips; // empty
00292    }
00293 
00294    // if event index < 0, return all strips 
00295    if ( event_index < 0 ) {
00296       //loop over strips in record
00297       for(int i = 0; i < this -> stp -> GetEntriesFast(); ++i) {
00298          const NtpSRStrip *strip  
00299             = dynamic_cast<const NtpSRStrip *>(this -> stp -> At(i));
00300          if(!strip) {
00301             MSG("NtpSt", Msg::kWarning) 
00302             << "Failed to get NtpSRStrip strip at " << event_index << endl;
00303             continue;
00304          }       
00305          strips.push_back(strip);
00306       }
00307       return strips;
00308    }
00309 
00310    // event_index >= 0
00311    const NtpSREvent* ntp_event 
00312      = dynamic_cast<const NtpSREvent*>(this -> evt -> At(event_index));   
00313    if (!ntp_event) {
00314       MSG("NtpSt", Msg::kWarning) << "Failed to get NtpSREvent at "
00315                                   << event_index << " index." << endl;
00316       return strips;
00317    }
00318 
00319    const Int_t *strip_index_array = ntp_event -> stp;   
00320    const Int_t nstrip = ntp_event -> nstrip;
00321 
00322    if ( nstrip < 1 || !strip_index_array ) {
00323       MSG("NtpSt", Msg::kDebug) 
00324       << "NtpStRecord does not have valid strip index array." << endl;
00325       return strips;
00326    }
00327    const int stp_size = this -> stp -> GetEntriesFast();
00328 
00329    //loop over strips in an event
00330    for ( int i = 0; i < nstrip; ++i ) {
00331      const int index = strip_index_array[i];
00332      if (index >= stp_size) {
00333         MSG("NtpSt", Msg::kWarning) << "Invalid strip index " << index 
00334         << " for TClonesArray *stp of size: " << stp_size << endl;
00335         continue;
00336      }
00337      const NtpSRStrip *strip  
00338       = dynamic_cast<const NtpSRStrip *>(this -> stp -> At(index));
00339      if ( !strip ) {
00340        MSG("NtpSt", Msg::kWarning) << "Failed to get NtpSRStrip at " 
00341                                     << index << " index" << endl;
00342        continue;
00343      }
00344       
00345      strips.push_back(strip);
00346    }
00347 
00348    return strips;
00349 }
00350 
00351 //_____________________________________________________________________________
00352 vector<const NtpSRShower *> NtpStRecord::GetShowers(const int event_index)
00353                                                                      const {
00354   // Get showers associated with event_index. 
00355   // If event_index < 0 (default) return all showers in record.
00356 
00357    vector<const NtpSRShower *> showers; // empty list of showers
00358 
00359    if ( event_index >= this -> evt -> GetEntriesFast() ) {
00360       MSG("NtpSt",Msg::kWarning) 
00361       << "GetShowers w/event index " << event_index
00362       << "\nis too large for evt array size " << this->evt->GetEntriesFast()
00363       << "." << endl;
00364       return showers; // empty shower list      
00365    }
00366 
00367    if ( event_index < 0 ) {
00368       //loop over showers in a record
00369       for ( int i = 0; i < this -> shw -> GetEntriesFast(); ++i ) {
00370         const NtpSRShower *shower  
00371                = dynamic_cast<const NtpSRShower *>(this -> shw -> At(i));
00372         if(!shower) {
00373            MSG("NtpSt", Msg::kWarning) << "No NtpSRShower pointer at " 
00374                                        << event_index << " index." << endl;
00375            continue;
00376         }
00377         showers.push_back(shower);
00378      }
00379      return showers; // all showers in record
00380    }
00381 
00382    // event_index >= 0
00383    const NtpSREvent* ntp_event 
00384           = dynamic_cast<const NtpSREvent*>(this -> evt -> At(event_index));   
00385    if(!ntp_event) {
00386       MSG("NtpSt", Msg::kWarning) << "Failed to get NtpSREvent pointer at "
00387                                   << event_index << " index." << endl;
00388       return showers;
00389    }
00390 
00391    const Int_t *shower_index_array = ntp_event -> shw;   
00392    const Int_t nshower = ntp_event -> nshower;
00393 
00394    if(nshower < 1 || !shower_index_array) {
00395       MSG("NtpSt", Msg::kDebug) 
00396       << "NtpStRecord does not have valid shower index array." <<endl;
00397       return showers;
00398    }
00399 
00400    const int shw_size = this -> shw -> GetEntriesFast();
00401 
00402    //loop over showers in an event
00403    for(int i = 0; i < nshower; ++i) {
00404       const int index = shower_index_array[i];
00405       if(index >= shw_size) {
00406          MSG("NtpSt", Msg::kWarning) << "Invalid shower index " << index 
00407          << " for TClonesArray *shw of size: " << shw_size << endl;
00408          continue;
00409       }
00410       const NtpSRShower *shower  
00411                = dynamic_cast<const NtpSRShower *>(this -> shw -> At(index));
00412       if(!shower) {
00413          MSG("NtpSt", Msg::kWarning) << "No NtpSRShower pointer at " 
00414                                      << index << " index." << endl;
00415          continue;
00416       }
00417       
00418       showers.push_back(shower);
00419    }
00420 
00421    return showers;
00422 }
00423 
00424 //_____________________________________________________________________________
00425 vector<const NtpSRTrack *> NtpStRecord::GetTracks(const int event_index) const{
00426   // Get tracks associated with event_index. 
00427   // If event_index < 0 return all tracks in record.
00428 
00429    vector<const NtpSRTrack *> tracks; // empty list of tracks
00430 
00431    if(event_index >= this -> evt -> GetEntriesFast()) {
00432       MSG("NtpSt",Msg::kWarning) 
00433       << "GetTracks w/event index " << event_index
00434       << "\nis too large for evt array size " << this -> evt->GetEntriesFast()
00435       << "." << endl;
00436       return tracks;
00437    }
00438 
00439    if( event_index < 0 ) {
00440      //loop over tracks in a record
00441      for(int i = 0; i < this -> trk -> GetEntriesFast(); ++i) {
00442        const NtpSRTrack *track  
00443                 = dynamic_cast<const NtpSRTrack *>(this -> trk -> At(i));
00444        if (!track) {
00445             MSG("NtpSt", Msg::kWarning) << "No track at " << event_index 
00446             << endl;
00447             continue;
00448        }
00449          
00450        tracks.push_back(track);
00451      }
00452      return tracks; // all tracks in record
00453    }
00454    
00455    // event_index >= 0
00456    const NtpSREvent* ntp_event 
00457             = dynamic_cast<const NtpSREvent*>(this -> evt -> At(event_index));
00458    if(!ntp_event) {
00459      MSG("NtpSt", Msg::kWarning) << "Failed to find NtpSREvent pointer at "
00460                                   << event_index << " index." << endl;
00461       return tracks;
00462    }
00463 
00464    const Int_t *track_index_array = ntp_event -> trk;
00465    const Int_t ntrack = ntp_event -> ntrack;
00466 
00467    if(ntrack < 1 || !track_index_array) {
00468       MSG("NtpSt", Msg::kDebug) 
00469       << "NtpStRecord does not have valid track index array." <<endl;
00470       return tracks;
00471    }
00472 
00473    const int trk_size = this -> trk -> GetEntriesFast();
00474 
00475    //loop over tracks in an event
00476    for(int i = 0; i < ntrack; ++i) {
00477       const int index = track_index_array[i];
00478       if ( index >= trk_size ) {
00479          MSG("NtpSt", Msg::kWarning) << "Invalid track index " << index 
00480          << " for TClonesArray *trk of size: " << trk_size << endl;
00481          continue;
00482       }
00483       const NtpSRTrack *track  
00484           = dynamic_cast<const NtpSRTrack *>(this -> trk -> At(index));
00485       if(!track) {
00486          MSG("NtpSt", Msg::kWarning) 
00487          << "Failed to get NtpSRTrack pointer at " << index << endl;
00488          continue;
00489       }
00490       
00491       tracks.push_back(track);
00492    }
00493 
00494    return tracks;
00495 }
00496 
00497 //_____________________________________________________________________________
00498 const NtpMCTruth* NtpStRecord::GetEventMCTruth(const int event_index) const {
00499   // Get NtpMCTruth entry corresponding to truth helper identified best
00500   // match for specified event_index.
00501 
00502    if(event_index < 0 || event_index >= this -> thevt -> GetEntriesFast()) {
00503       // 1:1 relationship between thevt and evt entries, so treat this
00504       // error seriously  
00505       MSG("NtpSt",Msg::kWarning) 
00506       << "GetEventMCTruth w/event index " << event_index
00507       << "\nis too large for thevt array size " 
00508       << this -> thevt->GetEntriesFast() << "." << endl;
00509       return 0;
00510    }
00511    
00512    const NtpTHEvent* ntp_event 
00513       = dynamic_cast<const NtpTHEvent*>(this -> thevt -> At(event_index));
00514    if(!ntp_event) {
00515       MSG("NtpSt", Msg::kWarning) << "Failed to get NtpTHEvent pointer at "
00516                                   << event_index << " index." << endl;
00517       return 0;
00518    }
00519 
00520    const int mctruth_index = ntp_event -> neumc;
00521    if ( mctruth_index < 0 ) return 0;  // valid response if no best match
00522 
00523    if(  mctruth_index >= this -> mc -> GetEntriesFast() ) {
00524       MSG("NtpSt", Msg::kError) 
00525       << "Invalid thevt.neumc index " << mctruth_index 
00526       << " exceeds bounds of " 
00527       << "mc array, size " << this -> mc -> GetEntriesFast() << endl;
00528       return 0;
00529    }
00530    
00531    const NtpMCTruth *truth  
00532           = dynamic_cast<const NtpMCTruth *>(this -> mc -> At(mctruth_index));
00533    if(!truth) {
00534       MSG("NtpSt", Msg::kDebug) << "No mc truth at " << mctruth_index << endl;
00535    }
00536    
00537    return truth;
00538 }
00539 
00540 //_____________________________________________________________________________
00541 vector<const NtpMCTruth *> NtpStRecord::GetMCTruths() const {
00542   // Get all mc truth events in the record. 
00543 
00544   vector< const NtpMCTruth* > mctruths; // empty list of mctruths
00545 
00546   // Push ptrs to all mc truth entries to output vector 
00547   for ( int imc = 0; imc < mc->GetEntriesFast(); imc++ ) {
00548     const NtpMCTruth* ntpmctruth 
00549                 = dynamic_cast<const NtpMCTruth*>( mc -> At(imc) );
00550     mctruths.push_back(ntpmctruth);
00551   }
00552    
00553   return mctruths;
00554 
00555 }
00556 
00557 //_____________________________________________________________________________
00558 vector<const NtpMCStdHep *> NtpStRecord::GetMCStdHeps(int mctruth_index) const{
00559   // Get stdhep entries associated with mc truth entry mctruth_index. 
00560   // If mctruth_index < 0 (default) return all stdhep entries in record.
00561 
00562   vector<const NtpMCStdHep *> stdheps; // empty list of stdhep entries
00563 
00564   // Determine stdhep indices of interest
00565   Int_t begstdhep_index = -1;
00566   Int_t endstdhep_index = -1;
00567   if ( mctruth_index < 0 ) {
00568     // If mc truth entry has not been specified, sthep indices of interest
00569     // is entire range
00570     begstdhep_index = 0;
00571     endstdhep_index = (stdhep -> GetEntriesFast()) - 1;
00572   }
00573   else {
00574     // stdhep indices of interest are those associated with mctruth_index
00575     if ( mctruth_index >= mc -> GetEntriesFast() ) {
00576       MSG("NtpSt",Msg::kWarning) 
00577              << "GetMCStdHeps w/mc truth array entry " << mctruth_index
00578              << "\nis too large for mc array size " 
00579              << mc -> GetEntriesFast()
00580              << "." << endl;
00581       return stdheps; // empty list of stdhep entries
00582     }
00583     const NtpMCTruth* ntpmctruth 
00584           = dynamic_cast<const NtpMCTruth*>(mc -> At(mctruth_index));
00585     if ( !ntpmctruth ) {
00586       MSG("NtpSt", Msg::kWarning) << "Failed to find NtpMCTruth pointer at "
00587                                   << mctruth_index << " index." << endl;
00588       return stdheps; // empty list of stdhep entries
00589     }
00590 
00591     // set stdhep indices according to this mc entry
00592     begstdhep_index = ntpmctruth->stdhep[0];
00593     endstdhep_index = ntpmctruth->stdhep[1];
00594   }
00595   
00596   if ( begstdhep_index < 0 || endstdhep_index < 0 ) {
00597     // empty stdheps list, don't think this should ever happen legitimately
00598     MSG("NtpSt",Msg::kWarning) << "No stdhep entries associated with "
00599                                << "mctruth_index " << mctruth_index << endl;
00600     return stdheps;
00601   }  
00602  
00603   // Loop over selected stdhep indices and push to output vector 
00604   for ( int istd = begstdhep_index; istd <= endstdhep_index; istd++ ) {
00605     const NtpMCStdHep *ntpstdhep  
00606           = dynamic_cast<const NtpMCStdHep *>( stdhep -> At(istd) );
00607     if ( !ntpstdhep ) {
00608       MSG("NtpSt", Msg::kWarning) << "No stdhep at index " << istd << endl;
00609       continue;
00610     }
00611     stdheps.push_back(ntpstdhep);
00612   }
00613 
00614   return stdheps; // stdhep entries in selected index range
00615 
00616 }
00617 
00618 //_____________________________________________________________________________
00619 vector< const NtpTHEvent* > NtpStRecord::GetTHEvents() const {
00620   // Get all mc truth helper events in the record. 
00621 
00622   vector< const NtpTHEvent* > thevents; 
00623 
00624   // Fill ptrs to all truth helper events to the output vector
00625   for ( int ith = 0; ith < thevt->GetEntriesFast(); ith++ ) {
00626     const NtpTHEvent* ntpthevent 
00627                 = dynamic_cast<const NtpTHEvent*>( thevt -> At(ith) );
00628     thevents.push_back(ntpthevent);
00629   }
00630    
00631   return thevents;
00632 
00633 }
00634 
00635 //_____________________________________________________________________________
00636 vector< const NtpTHTrack* > NtpStRecord::GetTHTracks( int event_index ) const{
00637   // Get truth helper tracks associated with event_index. 
00638   // If event_index < 0 return all truth helper tracks in record.
00639 
00640   vector<const NtpTHTrack *> thtracks; // empty list of tracks
00641 
00642   if ( thtrk->GetEntriesFast() <= 0 ) return thtracks; // no th tracks
00643 
00644   if ( event_index < 0 ) {
00645     // Fill all th tracks to output vector
00646     for ( int ith = 0; ith < thtrk -> GetEntriesFast(); ith++ ) {
00647       const NtpTHTrack *thtrack  
00648             = dynamic_cast<const NtpTHTrack *>(thtrk -> At(ith));
00649       thtracks.push_back(thtrack);
00650     }
00651   }
00652   else {
00653     if ( event_index >= evt -> GetEntriesFast() ) {
00654       MSG("NtpSt",Msg::kWarning) 
00655       << "GetTHTracks w/event index " << event_index
00656       << "\nis too large for evt array size " << evt -> GetEntriesFast()
00657       << "." << endl;
00658       return thtracks; // empty list
00659     }
00660  
00661     std::vector<const NtpSRTrack*> tracks = GetTracks(event_index);
00662     for ( unsigned int itrk = 0; itrk < tracks.size(); itrk++ ) {
00663       const NtpSRTrack* ntptrack = tracks[itrk];
00664       Int_t trkindex = ntptrack->index;
00665       const NtpTHTrack* ntpthtrack = dynamic_cast<const NtpTHTrack*>
00666                                      (thtrk->At(trkindex));
00667       thtracks.push_back(ntpthtrack);
00668     }
00669   }
00670 
00671   return thtracks; // return filled tracks
00672 
00673 }
00674 
00675 //_____________________________________________________________________________
00676 vector< const NtpTHShower* > NtpStRecord::GetTHShowers( int event_index) const{
00677   // Get truth helper showers associated with event_index. 
00678   // If event_index < 0 return all truth helper showers in record.
00679 
00680   vector<const NtpTHShower* > thshowers; // empty list of showers
00681 
00682   if ( thshw->GetEntriesFast() <= 0 ) return thshowers; // no th showers
00683 
00684   if ( event_index < 0 ) {
00685     // Fill all th showers to output vector
00686     for ( int ishw = 0; ishw < thshw -> GetEntriesFast(); ishw++ ) {
00687       const NtpTHShower *thshower  
00688             = dynamic_cast<const NtpTHShower* >(thshw -> At(ishw));
00689       thshowers.push_back(thshower);
00690     }
00691   }
00692   else {
00693     if ( event_index >= evt -> GetEntriesFast() ) {
00694       MSG("NtpSt",Msg::kWarning) 
00695       << "GetTHShowers w/event index " << event_index
00696       << "\nis too large for evt array size " << evt -> GetEntriesFast()
00697       << "." << endl;
00698       return thshowers; // empty list
00699     }
00700  
00701     std::vector<const NtpSRShower*> showers = GetShowers(event_index);
00702     for ( unsigned int ishw = 0; ishw < showers.size(); ishw++ ) {
00703       const NtpSRShower* ntpshower = showers[ishw];
00704       Int_t shwindex = ntpshower->index;
00705       const NtpTHShower* ntpthshower = dynamic_cast<const NtpTHShower*>
00706                                      (thshw->At(shwindex));
00707       thshowers.push_back(ntpthshower);
00708     }
00709   }
00710 
00711   return thshowers; // return filled showers
00712 
00713 }
00714 

Generated on Mon Feb 15 11:07:08 2010 for loon by  doxygen 1.3.9.1