Main Page | Compound List | File List | Compound Members | File Members | Related Pages

McEvent.cxx

Go to the documentation of this file.
00001 // File and Version Information:
00002 //      $Header: /nfs/slac/g/glast/ground/cvs/mcRootData/src/McEvent.cxx,v 1.33 2007/03/07 19:22:00 heather Exp $
00003 //
00004 // Description:
00005 // The McEvent class contains general information about a Monte Carlo
00006 // Event, (Run/Event numbers, etc) as well as a list of McParticle
00007 // instances generated during the simulated event.
00008 //                                                
00009 // Authors:  Dan Flath and Heather Kelly                       
00010 
00011 #include <mcRootData/McEvent.h>
00012 #include <commonRootData/RootDataUtil.h>
00013 #include "TString.h"
00014 #include "Riostream.h"
00015 
00016 #include "McObjectManager.h"
00017 
00018 // Allocate the TObjArrays just once
00019 TObjArray *McEvent::m_staticParticleCol = 0;
00020 TObjArray *McEvent::m_staticPositionHitCol = 0;
00021 TObjArray *McEvent::m_staticIntegratingHitCol = 0;
00022 TObjArray *McEvent::m_staticTrajectoryCol = 0;
00023 TObjArray *McEvent::m_staticTkrStripCol = 0;
00024 
00025 static const TString sourceUnknownStr = "NotStored";
00026 
00027 ClassImp(McEvent)
00028 
00029 McEvent::McEvent() : 
00030 m_eventId(0), m_runId(0), m_sourceName(sourceUnknownStr)
00031 {
00032     if (!m_staticParticleCol) m_staticParticleCol = new TObjArray();
00033     m_particleCol = m_staticParticleCol;
00034     
00035     if (!m_staticPositionHitCol) m_staticPositionHitCol = new TObjArray();
00036     m_positionHitCol = m_staticPositionHitCol;
00037     
00038     if (!m_staticTkrStripCol) m_staticTkrStripCol = new TObjArray();
00039     m_tkrStripCol = m_staticTkrStripCol;
00040     
00041     if (!m_staticIntegratingHitCol) m_staticIntegratingHitCol = new TObjArray();
00042     m_integratingHitCol = m_staticIntegratingHitCol;
00043     
00044     if (!m_staticTrajectoryCol) m_staticTrajectoryCol = new TObjArray();
00045     m_trajectoryCol = m_staticTrajectoryCol;
00046 }
00047 
00048 McEvent::~McEvent() {
00049     
00050     if (m_particleCol == m_staticParticleCol) m_staticParticleCol = 0;
00051     m_particleCol->Clear();  // We don't own these objects
00052     delete m_particleCol;
00053     m_particleCol = 0;
00054 
00055     if (m_positionHitCol == m_staticPositionHitCol) m_staticPositionHitCol = 0;
00056     m_positionHitCol->Clear();
00057     delete m_positionHitCol;
00058     m_positionHitCol = 0;
00059 
00060     if (m_tkrStripCol == m_staticTkrStripCol) m_staticTkrStripCol = 0;
00061     m_tkrStripCol->Clear();
00062     delete m_tkrStripCol;
00063     m_tkrStripCol = 0;
00064 
00065     if(m_integratingHitCol == m_staticIntegratingHitCol) m_staticIntegratingHitCol = 0;
00066     m_integratingHitCol->Clear();
00067     delete m_integratingHitCol;
00068     m_integratingHitCol = 0;
00069 
00070     if (m_trajectoryCol == m_staticTrajectoryCol) m_staticTrajectoryCol = 0;
00071     m_trajectoryCol->Clear();
00072     delete m_trajectoryCol;
00073     m_trajectoryCol = 0;
00074 
00075     m_sourceName = sourceUnknownStr;
00076 
00077     delete McObjectManager::getPointer();
00078 }
00079 
00080 void McEvent::initialize(UInt_t nEvent, UInt_t nRun, 
00081                          Int_t sourceId, UInt_t sequence, Double_t timestamp,
00082                          const TString& str) {
00083     m_eventId = nEvent;
00084     m_runId = nRun;
00085     m_sourceId = sourceId;
00086     m_sequence = sequence;
00087     m_timeStamp = timestamp;
00088     m_sourceName = str;
00089     return;
00090 }
00091 
00092 
00093 void McEvent::Clear(Option_t *option) {
00094     
00095 
00096     m_eventId = 0;
00097     m_runId = 0;
00098     m_sourceName = sourceUnknownStr;
00099     
00100     if (option) {
00101         TString optStr(option);
00102         if (optStr.CompareTo("ALL")==0) {
00103             if (m_particleCol)       m_particleCol->Clear();
00104             if (m_positionHitCol)    m_positionHitCol->Clear();
00105             if (m_integratingHitCol) m_integratingHitCol->Clear();
00106             if (m_trajectoryCol)     m_trajectoryCol->Clear();
00107             return;
00108         }
00109     }
00110 
00111     // Tell the MC object manager to reset its iterators
00112     McObjectManager::getPointer()->Delete();
00113 
00114     if (m_particleCol) {
00115         m_particleCol->Clear();
00116     }
00117 
00118     if (m_positionHitCol) {
00119         m_positionHitCol->Clear();
00120    }
00121 
00122     if (m_tkrStripCol)
00123     {
00124         m_tkrStripCol->SetOwner();
00125         m_tkrStripCol->Clear();
00126     }
00127 
00128     if (m_integratingHitCol) {
00129         m_integratingHitCol->Clear();
00130     }
00131 
00132     if (m_trajectoryCol) 
00133     {
00134         m_trajectoryCol->Clear();
00135     }
00136 }
00137 
00138 void McEvent::Print(Option_t *option) const {
00139     using namespace std;
00140     TObject::Print(option);
00141     std::cout.precision(2);
00142     std::cout << "Run: " << m_runId << " Event: " << m_eventId << std::endl;
00143     std::cout << "SourceName: " << m_sourceName << std::endl;
00144     std::cout << m_particleCol->GetEntries() << " McParticles" << std::endl;
00145     std::cout << m_positionHitCol->GetEntries() << " McPositionHits" << std::endl;
00146     std::cout << m_integratingHitCol->GetEntries() 
00147         << " McIntegratingHits" << std::endl;
00148     std::cout << m_trajectoryCol->GetEntries() << " McTrajectories" << std::endl;
00149 }
00150 
00151 
00152 void McEvent::addMcParticle(McParticle *part) {   
00153     m_particleCol->Add(part);
00154     return;
00155 }
00156 
00157 McParticle* McEvent::getMcParticle(UInt_t index) const {
00158     return ((McParticle*)m_particleCol->At(index));
00159 }
00160 
00161 void McEvent::addMcPositionHit(McPositionHit *hit) {
00162     m_positionHitCol->Add(hit);
00163     return;
00164 }
00165 
00166 McPositionHit* McEvent::getMcPositionHit(UInt_t index) const {
00167 
00168     return ((McPositionHit*)m_positionHitCol->At(index));
00169 }
00170 
00171 void McEvent::addMcTkrStrip(McTkrStrip *strip) {
00172     m_tkrStripCol->Add(strip);
00173     return;
00174 }
00175 
00176 McTkrStrip* McEvent::getMcTkrStrip(UInt_t index) const {
00177 
00178     return ((McTkrStrip*)m_tkrStripCol->At(index));
00179 }
00180 
00181 void McEvent::addMcIntegratingHit(McIntegratingHit *hit) {
00182     m_integratingHitCol->Add(hit);
00183     return;
00184 }
00185 
00186 McIntegratingHit* McEvent::getMcIntegratingHit(UInt_t index) const {
00187     return ((McIntegratingHit*)m_integratingHitCol->At(index));
00188 }
00189 
00190 void McEvent::addMcTrajectory(McTrajectory *hit) {
00191     m_trajectoryCol->Add(hit);
00192     return;
00193 }
00194 
00195 McTrajectory* McEvent::getMcTrajectory(UInt_t index) const {
00196 
00197     return ((McTrajectory*)m_trajectoryCol->At(index));
00198 }
00199 
00200 
00201 //======================================================
00202 // For Unit Tests
00203 //======================================================
00204 
00205 // DC: I CANNOT MAKE THE USUAL Fake() and CompareInRange(),
00206 // because McEvent is designed as a singleton.
00207 
00208 const UInt_t NUM_ENTRIES = 5 ;
00209 const Int_t SOURCE_ID = 7 ;
00210 const UInt_t SEQUENCE = 4 ;
00211     
00212 void McEvent::Fake( Int_t ievent, Int_t irun, Float_t randNum ) {
00213 
00214 
00215     Clear() ;
00216     
00217     //DC : it is strange that in McEvent ievent and irun
00218     //are unsigned, and not in the usual Fake. I should
00219     //have a look at all kinds of events, and either
00220     //change McEvent or Fake
00221     initialize(ievent,irun,SOURCE_ID,SEQUENCE,ievent*1.0, sourceUnknownStr) ;
00222         
00223     UInt_t ientry ;
00224     for ( ientry=0 ; ientry<NUM_ENTRIES ; ++ientry ) {
00225             
00226         McParticle * mcPart = new McParticle();
00227         mcPart->Fake(ievent,ientry,randNum) ;
00228         addMcParticle(mcPart) ;
00229             
00230         McPositionHit * posHit = new McPositionHit() ;
00231         posHit->Fake(ievent,ientry,randNum) ;
00232         addMcPositionHit(posHit) ;
00233             
00234         McIntegratingHit *intHit = new McIntegratingHit();
00235         intHit->Fake(ievent,ientry,randNum) ;
00236         intHit->addEnergyItem(1.5,mcPart,mcPart->getFinalPosition()) ;
00237         addMcIntegratingHit(intHit) ;
00238         
00239         McTrajectory *trajectory = new McTrajectory() ;
00240         trajectory->Fake(ievent,ientry,randNum) ;
00241         addMcTrajectory(trajectory) ;
00242     }
00243 }
00244 
00245 Bool_t McEvent::CompareToFake( Int_t iEvent, Int_t iRun, Float_t randNum ) {
00246 
00247     bool result = true ;
00248         
00249     result = rootdatautil::CompareInRange(getEventId(),(UInt_t)iEvent,"EventId") && result ;
00250     result = rootdatautil::CompareInRange(getRunId(),(UInt_t)iRun,"RunId") && result ;
00251     result = rootdatautil::CompareInRange(getSourceId(),SOURCE_ID,"SourceId") && result ;
00252     result = rootdatautil::CompareInRange(getSequence(),SEQUENCE,"Sequence") && result ;
00253     result = rootdatautil::CompareInRange(getTimeStamp(),iEvent*1.0,"TimeStamp") && result ;
00254     result = rootdatautil::CompareInRange(getSourceName(),sourceUnknownStr.Data(),"SourceName") && result ;
00255         
00256     TObjArray refParticleCol ;
00257     TObjArray refPositionHitCol ;
00258     TObjArray refIntHitCol ;
00259     TObjArray refTrajectoryCol ;
00260 
00261     UInt_t iEntry ;
00262     for ( iEntry=0 ; iEntry<NUM_ENTRIES ; ++iEntry ) {
00263         
00264         McParticle * particle = getMcParticle(iEntry) ;
00265         
00266         McParticle * mcPart = new McParticle();
00267         mcPart->Fake(iEvent,iEntry,randNum) ;
00268         refParticleCol.Add(mcPart) ;
00269         
00270         McPositionHit * posHit = new McPositionHit() ;
00271         posHit->Fake(iEvent,iEntry,randNum) ;
00272         refPositionHitCol.Add(posHit) ;
00273         
00274         McIntegratingHit *intHit = new McIntegratingHit();
00275         intHit->Fake(iEvent,iEntry,randNum) ;
00276         intHit->addEnergyItem(1.5,particle,particle->getFinalPosition()) ;
00277         refIntHitCol.Add(intHit) ;
00278         
00279         McTrajectory *trajectory = new McTrajectory() ;
00280         trajectory->Fake(iEvent,iEntry,randNum) ;
00281         refTrajectoryCol.Add(trajectory) ;
00282     
00283     }
00284     
00285     result = rootdatautil::TObjArrayCompareInRange<McParticle>(getMcParticleCol(),&refParticleCol,"McParticle") && result ;
00286     result = rootdatautil::TObjArrayCompareInRange<McPositionHit>(getMcPositionHitCol(),&refPositionHitCol,"McPositionHit") && result ;
00287     result = rootdatautil::TObjArrayCompareInRange<McIntegratingHit>(getMcIntegratingHitCol(),&refIntHitCol,"McIntegratingHit") && result ;
00288     result = rootdatautil::TObjArrayCompareInRange<McTrajectory>(getMcTrajectoryCol(),&refTrajectoryCol,"McTrajectory") && result ;
00289 
00290     std::string name = "McEvent" ;
00291         
00292     if (!result) {
00293         if ( name == "" ) {
00294             std::cout<<"Comparison ERROR for "<<ClassName()<<std::endl ;
00295         }
00296         else {
00297             std::cout<<"Comparison ERROR for "<<name<<std::endl ;
00298         }
00299     }
00300     return result ;
00301 
00302 }
00303 
00304 //#define COMPARE_IN_RANGE(att) rootdatautil::CompareInRange(get ## att(),ref.get ## att(),#att)
00305 //#define COMPARE_TOBJ_ARRAY_IN_RANGE(T) rootdatautil::TObjArrayCompareInRange<T>(get ## T ## Col(),ref.get ## T ## Col(),#T)
00306 //
00307 //Bool_t McEvent::CompareInRange( const McEvent & ref, const std::string & name ) {
00308 //
00309 //    bool result = true ;
00310 //
00311 //    result = COMPARE_IN_RANGE(EventId) && result ;
00312 //    result = COMPARE_IN_RANGE(RunId) && result ;
00313 //    result = COMPARE_IN_RANGE(SourceId) && result ;
00314 //    result = COMPARE_IN_RANGE(Sequence) && result ;
00315 //    result = COMPARE_IN_RANGE(TimeStamp) && result ;
00316 //
00317 //    result = COMPARE_TOBJ_ARRAY_IN_RANGE(McParticle) && result ;
00318 //    result = COMPARE_TOBJ_ARRAY_IN_RANGE(McPositionHit) && result ;
00319 //    result = COMPARE_TOBJ_ARRAY_IN_RANGE(McIntegratingHit) && result ;
00320 //    result = COMPARE_TOBJ_ARRAY_IN_RANGE(McTrajectory) && result ;
00321 //
00322 //    if (!result) {
00323 //        if ( name == "" ) {
00324 //            std::cout<<"Comparison ERROR for "<<ClassName()<<std::endl ;
00325 //        }
00326 //        else {
00327 //            std::cout<<"Comparison ERROR for "<<name<<std::endl ;
00328 //        }
00329 //    }
00330 //    return result ;
00331 //
00332 //}
00333 

Generated on Tue Dec 11 16:28:53 2007 by doxygen 1.3.3