JetEvent.cxx

Go to the documentation of this file.
00001 // A JetEvent emulates 2 detectors A and B producing each
00002 // a TClonesArray of Hit objects.
00003 // A TClonesArray  of Track objects is built with Hits objects
00004 // of detectors A and B. Eack Track object has a TRefArray of hits.
00005 // A TClonesArray of Jets is made with a subset of the Track objects
00006 // also stored in a TRefArray.
00007 // see $ROOTSYS/tutorials/jets.C for an example creating a Tree
00008 // with JetEvents.
00009       
00010 #include "TMath.h"   
00011 #include "TRandom.h"   
00012 #include "JetEvent.h"
00013 
00014 ClassImp(Jet)
00015 ClassImp(Track)
00016 ClassImp(Hit)
00017 ClassImp(JetEvent)
00018 
00019 TClonesArray *JetEvent::fgJets   = 0;
00020 TClonesArray *JetEvent::fgTracks = 0;
00021 TClonesArray *JetEvent::fgHitsA  = 0;
00022 TClonesArray *JetEvent::fgHitsB  = 0;
00023 
00024 //______________________________________________________________________________
00025 JetEvent::JetEvent()
00026 {
00027    // Create a JetEvent object.
00028    // When the constructor is invoked for the first time, the class static
00029    // variables fgxxx are 0 and the TClonesArray fgxxx are created.
00030 
00031    if (!fgTracks) fgTracks = new TClonesArray("Track", 100);
00032    if (!fgJets)   fgJets   = new TClonesArray("Jet", 10);
00033    if (!fgHitsA)  fgHitsA  = new TClonesArray("Hit", 10000);
00034    if (!fgHitsB)  fgHitsB  = new TClonesArray("Hit", 1000);
00035    fJets   = fgJets;
00036    fTracks = fgTracks;
00037    fHitsA  = fgHitsA;
00038    fHitsB  = fgHitsB;
00039 }
00040 
00041 //______________________________________________________________________________
00042 JetEvent::~JetEvent()
00043 {
00044    Reset();
00045 }
00046 
00047 //______________________________________________________________________________
00048 void JetEvent::Build(Int_t jetm, Int_t trackm, Int_t hitam, Int_t hitbm) {
00049    //Build one event
00050    
00051    //Save current Object count
00052    Int_t ObjectNumber = TProcessID::GetObjectCount();
00053    Clear();
00054 
00055    Hit *hit;
00056    Track *track;
00057    Jet *jet;
00058    fNjet   = fNtrack = fNhitA  = fNhitB  = 0;
00059    
00060    fVertex.SetXYZ(gRandom->Gaus(0,0.1),
00061                   gRandom->Gaus(0,0.2),
00062                   gRandom->Gaus(0,10));
00063       
00064    Int_t njets = (Int_t)gRandom->Gaus(jetm,1); if (njets < 1) njets = 1;
00065    for (Int_t j=0;j<njets;j++) {
00066       jet = AddJet();
00067       jet->fPt = gRandom->Gaus(0,10);
00068       jet->fPhi = 2*TMath::Pi()*gRandom->Rndm();
00069       Int_t ntracks = (Int_t)gRandom->Gaus(trackm,3); if (ntracks < 1) ntracks = 1;
00070       for (Int_t t=0;t<ntracks;t++) {
00071          track = AddTrack();
00072          track->fPx = gRandom->Gaus(0,1);
00073          track->fPy = gRandom->Gaus(0,1);
00074          track->fPz = gRandom->Gaus(0,5);
00075          jet->fTracks.Add(track);
00076          Int_t nhitsA = (Int_t)gRandom->Gaus(hitam,5);
00077          for (Int_t ha=0;ha<nhitsA;ha++) {
00078             hit = AddHitA();
00079             hit->fX = 10000*j + 100*t +ha;
00080             hit->fY = 10000*j + 100*t +ha+0.1;
00081             hit->fZ = 10000*j + 100*t +ha+0.2;
00082             track->fHits.Add(hit);
00083          }
00084          Int_t nhitsB = (Int_t)gRandom->Gaus(hitbm,2);
00085          for (Int_t hb=0;hb<nhitsB;hb++) {
00086             hit = AddHitB();
00087             hit->fX = 20000*j + 100*t +hb+0.3;
00088             hit->fY = 20000*j + 100*t +hb+0.4;
00089             hit->fZ = 20000*j + 100*t +hb+0.5;
00090             track->fHits.Add(hit);
00091          }
00092          track->fNhit = nhitsA + nhitsB;
00093       }
00094    }         
00095   //Restore Object count 
00096   //To save space in the table keeping track of all referenced objects
00097   //we assume that our events do not address each other. We reset the 
00098   //object count to what it was at the beginning of the event.
00099   TProcessID::SetObjectCount(ObjectNumber);
00100 }
00101 
00102 
00103 //______________________________________________________________________________
00104 Jet *JetEvent::AddJet()
00105 {
00106    // Add a new Jet to the list of tracks for this event.
00107 
00108    TClonesArray &jets = *fJets;
00109    Jet *jet = new(jets[fNjet++]) Jet();
00110    return jet;
00111 }
00112 
00113 
00114 //______________________________________________________________________________
00115 Track *JetEvent::AddTrack()
00116 {
00117    // Add a new track to the list of tracks for this event.
00118 
00119    TClonesArray &tracks = *fTracks;
00120    Track *track = new(tracks[fNtrack++]) Track();
00121    return track;
00122 }
00123 
00124 
00125 //______________________________________________________________________________
00126 Hit *JetEvent::AddHitA()
00127 {
00128    // Add a new hit to the list of hits in detector A
00129 
00130    TClonesArray &hitsA = *fHitsA;
00131    Hit *hit = new(hitsA[fNhitA++]) Hit();
00132    return hit;
00133 }
00134 
00135 //______________________________________________________________________________
00136 Hit *JetEvent::AddHitB()
00137 {
00138    // Add a new hit to the list of hits in detector B
00139 
00140    TClonesArray &hitsB = *fHitsB;
00141    Hit *hit = new(hitsB[fNhitB++]) Hit();
00142    return hit;
00143 }
00144 
00145 //______________________________________________________________________________
00146 void JetEvent::Clear(Option_t *option)
00147 {
00148    fJets->Clear(option);
00149    fTracks->Clear(option);
00150    fHitsA->Clear(option);
00151    fHitsB->Clear(option);
00152 }
00153 
00154 //______________________________________________________________________________
00155 void JetEvent::Reset(Option_t *)
00156 {
00157 // Static function to reset all static objects for this event
00158 
00159    delete fgJets;   fgJets = 0;
00160    delete fgTracks; fgTracks = 0;
00161    delete fgHitsA;  fgHitsA = 0;
00162    delete fgHitsB;  fgHitsB = 0;
00163 }
00164 
00165 
00166 
00167 
00168 
00169 

Generated on Tue Jul 5 15:45:11 2011 for ROOT_528-00b_version by  doxygen 1.5.1