EventMT.cxx

Go to the documentation of this file.
00001 // @(#)root/test:$Id: EventMT.cxx 36320 2010-10-12 19:00:12Z brun $
00002 // Author: Rene Brun   19/08/96
00003 
00004 ////////////////////////////////////////////////////////////////////////
00005 //
00006 //                       Event and Track classes
00007 //                       =======================
00008 //
00009 //  The Event class is a naive/simple example of an event structure.
00010 //     public:
00011 //        char           fType[20];
00012 //        char          *fEventName;         //run+event number in character format
00013 //        Int_t          fNtrack;
00014 //        Int_t          fNseg;
00015 //        Int_t          fNvertex;
00016 //        UInt_t         fFlag;
00017 //        Double32_t     fTemperature;
00018 //        Int_t          fMeasures[10];
00019 //        Double32_t     fMatrix[4][4];
00020 //        Double32_t    *fClosestDistance; //[fNvertex] indexed array! 
00021 //        EventHeader    fEvtHdr;
00022 //        TClonesArray  *fTracks;
00023 //        TRefArray     *fHighPt;            //array of High Pt tracks only
00024 //        TRefArray     *fMuons;             //array of Muon tracks only
00025 //        TRef           fLastTrack;         //pointer to last track
00026 //        TRef           fHistoWeb;          //EXEC:GetHistoWeb reference to an histogram in a TWebFile
00027 //        TH1F          *fH;
00028 //        TBits          fTriggerBits;       //Bits triggered by this event.
00029 //
00030 //   The EventHeader class has 3 data members (integers):
00031 //     public:
00032 //        Int_t          fEvtNum;
00033 //        Int_t          fRun;
00034 //        Int_t          fDate;
00035 //
00036 //
00037 //   The Event data member fTracks is a pointer to a TClonesArray.
00038 //   It is an array of a variable number of tracks per event.
00039 //   Each element of the array is an object of class Track with the members:
00040 //     private:
00041 //        Float_t      fPx;           //X component of the momentum
00042 //        Float_t      fPy;           //Y component of the momentum
00043 //        Float_t      fPz;           //Z component of the momentum
00044 //        Float_t      fRandom;       //A random track quantity
00045 //        Float_t      fMass2;        //The mass square of this particle
00046 //        Float_t      fBx;           //X intercept at the vertex
00047 //        Float_t      fBy;           //Y intercept at the vertex
00048 //        Float_t      fMeanCharge;   //Mean charge deposition of all hits of this track
00049 //        Float_t      fXfirst;       //X coordinate of the first point
00050 //        Float_t      fXlast;        //X coordinate of the last point
00051 //        Float_t      fYfirst;       //Y coordinate of the first point
00052 //        Float_t      fYlast;        //Y coordinate of the last point
00053 //        Float_t      fZfirst;       //Z coordinate of the first point
00054 //        Float_t      fZlast;        //Z coordinate of the last point
00055 //        Double32_t   fCharge;       //Charge of this track
00056 //        Double32_t   fVertex[3];    //Track vertex position
00057 //        Int_t        fNpoint;       //Number of points for this track
00058 //        Short_t      fValid;        //Validity criterion
00059 //        Int_t        fNsp;          //Number of points for this track with a special value
00060 //        Double32_t  *fPointValue;   //[fNsp] a special quantity for some point.
00061 //        TBits        fTriggerBits;  //Bits triggered by this track.
00062 //
00063 //   An example of a batch program to use the Event/Track classes is given
00064 //   in this directory: MainEvent.
00065 //   Look also in the same directory at the following macros:
00066 //     - eventa.C  an example how to read the tree
00067 //     - eventb.C  how to read events conditionally
00068 //
00069 //   During the processing of the event (optionally) also a large number
00070 //   of histograms can be filled. The creation and handling of the
00071 //   histograms is taken care of by the HistogramManager class.
00072 //
00073 //   This version of the Event class is a simplified version suitable for
00074 //   use in a multi-threads environment as all Event objects are
00075 //   independent from each other.
00076 //
00077 ////////////////////////////////////////////////////////////////////////
00078 
00079 #include "TRandom.h"
00080 #include "TDirectory.h"
00081 #include "TProcessID.h"
00082 
00083 #include "Event.h"
00084 
00085 
00086 ClassImp(EventHeader)
00087 ClassImp(Event)
00088 ClassImp(Track)
00089 ClassImp(HistogramManager)
00090 
00091 //______________________________________________________________________________
00092 Event::Event() : fIsValid(kFALSE)
00093 {
00094    // Create an Event object.
00095 
00096    fTracks = new TClonesArray("Track", 1000);
00097    fHighPt = new TRefArray;
00098    fMuons  = new TRefArray;
00099    fNtrack = 0;
00100    fH      = 0;
00101    Int_t i0,i1;
00102    for (i0 = 0; i0 < 4; i0++) {
00103       for (i1 = 0; i1 < 4; i1++) {
00104          fMatrix[i0][i1] = 0.0;
00105       }
00106    }
00107    for (i0 = 0; i0 <10; i0++) fMeasures[i0] = 0;
00108    for (i0 = 0; i0 <20; i0++) fType[i0] = 0;
00109    fClosestDistance = 0;
00110    fEventName = 0;
00111    fWebHistogram.SetAction(this);
00112 }
00113 
00114 //______________________________________________________________________________
00115 Event::~Event()
00116 {
00117    Clear();
00118    delete fH; fH = 0;
00119    delete fHighPt; fHighPt = 0;
00120    delete fMuons;  fMuons = 0;
00121    delete [] fClosestDistance;
00122    if (fEventName) delete [] fEventName;
00123 }
00124 
00125 //______________________________________________________________________________
00126 void Event::Build(Int_t ev, Int_t arg5, Float_t ptmin) {
00127   fIsValid = kTRUE;
00128   char etype[20];
00129   Float_t sigmat, sigmas;
00130   gRandom->Rannor(sigmat,sigmas);
00131   Int_t ntrack   = Int_t(arg5 +arg5*sigmat/120.);
00132   Float_t random = gRandom->Rndm(1);
00133 
00134   //Save current Object count
00135   Int_t ObjectNumber = TProcessID::GetObjectCount();
00136   Clear();
00137   fHighPt->Delete();
00138   fMuons->Delete();
00139   
00140   Int_t nch = 15;
00141   if (ev >= 100)   nch += 3;
00142   if (ev >= 10000) nch += 3;
00143   if (fEventName) delete [] fEventName;
00144   fEventName = new char[nch];
00145   sprintf(fEventName,"Event%d_Run%d",ev,200);
00146   sprintf(etype,"type%d",ev%5);
00147   SetType(etype);
00148   SetHeader(ev, 200, 960312, random);
00149   SetNseg(Int_t(10*ntrack+20*sigmas));
00150   SetNvertex(Int_t(1+20*gRandom->Rndm()));
00151   SetFlag(UInt_t(random+0.5));
00152   SetTemperature(random+20.);
00153 
00154   for(UChar_t m = 0; m < 10; m++) {
00155      SetMeasure(m, Int_t(gRandom->Gaus(m,m+1)));
00156   }
00157   for(UChar_t i0 = 0; i0 < 4; i0++) {
00158     for(UChar_t i1 = 0; i1 < 4; i1++) {
00159        SetMatrix(i0,i1,gRandom->Gaus(i0*i1,1));
00160     }
00161   }
00162 
00163   fTriggerBits.SetBitNumber((UInt_t)(64*gRandom->Rndm(1)));
00164   fTriggerBits.SetBitNumber((UInt_t)(64*gRandom->Rndm(1)));
00165   fTriggerBits.SetBitNumber((UInt_t)(64*gRandom->Rndm(1)));
00166 
00167   //  Create and Fill the Track objects
00168   for (Int_t t = 0; t < ntrack; t++) AddTrack(random,ptmin);
00169   
00170   //Restore Object count 
00171   //To save space in the table keeping track of all referenced objects
00172   //we assume that our events do not address each other. We reset the 
00173   //object count to what it was at the beginning of the event.
00174   TProcessID::SetObjectCount(ObjectNumber);
00175 }  
00176 
00177 //______________________________________________________________________________
00178 Track *Event::AddTrack(Float_t random, Float_t ptmin)
00179 {
00180    // Add a new track to the list of tracks for this event.
00181    // To avoid calling the very time consuming operator new for each track,
00182    // the standard but not well know C++ operator "new with placement"
00183    // is called. If tracks[i] is 0, a new Track object will be created
00184    // otherwise the previous Track[i] will be overwritten.
00185 
00186    TClonesArray &tracks = *fTracks;
00187    Track *track = new(tracks[fNtrack++]) Track(random);
00188    //Save reference to last Track in the collection of Tracks
00189    fLastTrack = track;
00190    //Save reference in fHighPt if track is a high Pt track
00191    if (track->GetPt() > ptmin)   fHighPt->Add(track);
00192    //Save reference in fMuons if track is a muon candidate
00193    if (track->GetMass2() < 0.11) fMuons->Add(track);
00194    return track;
00195 }
00196 
00197 //______________________________________________________________________________
00198 void Event::Clear(Option_t * /*option*/)
00199 {
00200    fTracks->Clear("C"); //will also call Track::Clear
00201    fHighPt->Delete();
00202    fMuons->Delete();
00203    fTriggerBits.Clear();
00204 }
00205 
00206 ///______________________________________________________________________________
00207 void Event::SetHeader(Int_t i, Int_t run, Int_t date, Float_t random)
00208 {
00209    fNtrack = 0;
00210    fEvtHdr.Set(i, run, date);
00211    fH = new TH1F("hstat","Event Histogram",100,0,1);
00212    fH->Fill(random);
00213 }
00214 
00215 //______________________________________________________________________________
00216 void Event::SetMeasure(UChar_t which, Int_t what) {
00217    if (which<10) fMeasures[which] = what;
00218 }
00219 
00220 //______________________________________________________________________________
00221 void Event::SetRandomVertex() {
00222    // This delete is to test the relocation of variable length array
00223    if (fClosestDistance) delete [] fClosestDistance;
00224    if (!fNvertex) {
00225       fClosestDistance = 0;
00226       return;
00227    }
00228    fClosestDistance = new Double32_t[fNvertex];
00229    for (Int_t k = 0; k < fNvertex; k++ ) {
00230       fClosestDistance[k] = gRandom->Gaus(1,1);
00231    }
00232 }
00233 
00234 //______________________________________________________________________________
00235 Track::Track(const Track &orig) : TObject(orig)
00236 {
00237    // Copy a track object
00238 
00239    fPx = orig.fPx;
00240    fPy = orig.fPy;
00241    fPz = orig.fPx; 
00242    fRandom = orig.fRandom;
00243    fMass2 = orig.fMass2;
00244    fBx = orig.fBx;
00245    fBy = orig.fBy;
00246    fMeanCharge = orig.fMeanCharge;
00247    fXfirst = orig.fXfirst;
00248    fXlast  = orig.fXlast;
00249    fYfirst = orig.fYfirst;
00250    fYlast  = orig.fYlast;
00251    fZfirst = orig.fZfirst;
00252    fZlast  = orig.fZlast;
00253    fCharge = orig.fCharge;
00254 
00255    fVertex[0] = orig.fVertex[0];
00256    fVertex[1] = orig.fVertex[1];
00257    fVertex[2] = orig.fVertex[2];
00258    fNpoint = orig.fNpoint;
00259    fNsp = orig.fNsp;
00260    if (fNsp) {
00261       fPointValue = new Double32_t[fNsp];
00262       for(int i=0; i<fNsp; i++) {
00263          fPointValue[i] = orig.fPointValue[i];
00264       }
00265    } else {
00266       fPointValue = 0;
00267    }
00268    fValid  = orig.fValid;
00269 
00270    fTriggerBits = orig.fTriggerBits;
00271 
00272 }
00273 
00274 //______________________________________________________________________________
00275 Track::Track(Float_t random) : TObject(),fTriggerBits(64)
00276 {
00277    // Create a track object.
00278    // Note that in this example, data members do not have any physical meaning.
00279 
00280    Float_t a,b,px,py;
00281    gRandom->Rannor(px,py);
00282    fPx = px;
00283    fPy = py;
00284    fPz = TMath::Sqrt(px*px+py*py);
00285    fRandom = 1000*random;
00286    if (fRandom < 10) fMass2 = 0.106;
00287    else if (fRandom < 100) fMass2 = 0.8;
00288    else if (fRandom < 500) fMass2 = 4.5;
00289    else if (fRandom < 900) fMass2 = 8.9;
00290    else  fMass2 = 9.8;
00291    gRandom->Rannor(a,b);
00292    fBx = 0.1*a;
00293    fBy = 0.1*b;
00294    fMeanCharge = 0.01*gRandom->Rndm(1);
00295    gRandom->Rannor(a,b);
00296    fXfirst = a*10;
00297    fXlast  = b*10;
00298    gRandom->Rannor(a,b);
00299    fYfirst = a*12;
00300    fYlast  = b*16;
00301    gRandom->Rannor(a,b);
00302    fZfirst = 50 + 5*a;
00303    fZlast  = 200 + 10*b;
00304    fCharge = Double32_t(Int_t(3*gRandom->Rndm(1)) - 1);
00305 
00306    fTriggerBits.SetBitNumber((UInt_t)(64*gRandom->Rndm(1)));
00307    fTriggerBits.SetBitNumber((UInt_t)(64*gRandom->Rndm(1)));
00308    fTriggerBits.SetBitNumber((UInt_t)(64*gRandom->Rndm(1)));
00309 
00310    fVertex[0] = gRandom->Gaus(0,0.1);
00311    fVertex[1] = gRandom->Gaus(0,0.2);
00312    fVertex[2] = gRandom->Gaus(0,10);
00313    fNpoint = Int_t(60+10*gRandom->Rndm(1));
00314    fNsp = Int_t(3*gRandom->Rndm(1));
00315    if (fNsp) {
00316       fPointValue = new Double32_t[fNsp];
00317       for(int i=0; i<fNsp; i++) {
00318          fPointValue[i] = i+1;
00319       }
00320    } else {
00321       fPointValue = 0;
00322    }
00323    fValid  = Int_t(0.6+gRandom->Rndm(1));
00324 }
00325 
00326 //______________________________________________________________________________
00327 void Track::Clear(Option_t * /*option*/)
00328 {
00329    fTriggerBits.Clear(); 
00330    delete [] fPointValue; 
00331    fPointValue=0; 
00332 }
00333 
00334 //______________________________________________________________________________
00335 HistogramManager::HistogramManager(TDirectory *dir)
00336 {
00337    // Create histogram manager object. Histograms will be created
00338    // in the "dir" directory.
00339 
00340    // Save current directory and cd to "dir".
00341    TDirectory *saved = gDirectory;
00342    dir->cd();
00343 
00344    fNtrack      = new TH1F("hNtrack",    "Ntrack",100,575,625);
00345    fNseg        = new TH1F("hNseg",      "Nseg",100,5800,6200);
00346    fTemperature = new TH1F("hTemperature","Temperature",100,19.5,20.5);
00347    fPx          = new TH1F("hPx",        "Px",100,-4,4);
00348    fPy          = new TH1F("hPy",        "Py",100,-4,4);
00349    fPz          = new TH1F("hPz",        "Pz",100,0,5);
00350    fRandom      = new TH1F("hRandom",    "Random",100,0,1000);
00351    fMass2       = new TH1F("hMass2",     "Mass2",100,0,12);
00352    fBx          = new TH1F("hBx",        "Bx",100,-0.5,0.5);
00353    fBy          = new TH1F("hBy",        "By",100,-0.5,0.5);
00354    fMeanCharge  = new TH1F("hMeanCharge","MeanCharge",100,0,0.01);
00355    fXfirst      = new TH1F("hXfirst",    "Xfirst",100,-40,40);
00356    fXlast       = new TH1F("hXlast",     "Xlast",100,-40,40);
00357    fYfirst      = new TH1F("hYfirst",    "Yfirst",100,-40,40);
00358    fYlast       = new TH1F("hYlast",     "Ylast",100,-40,40);
00359    fZfirst      = new TH1F("hZfirst",    "Zfirst",100,0,80);
00360    fZlast       = new TH1F("hZlast",     "Zlast",100,0,250);
00361    fCharge      = new TH1F("hCharge",    "Charge",100,-1.5,1.5);
00362    fNpoint      = new TH1F("hNpoint",    "Npoint",100,50,80);
00363    fValid       = new TH1F("hValid",     "Valid",100,0,1.2);
00364 
00365    // cd back to original directory
00366    saved->cd();
00367 }
00368 
00369 //______________________________________________________________________________
00370 HistogramManager::~HistogramManager()
00371 {
00372    // Clean up all histograms.
00373 
00374    // Nothing to do. Histograms will be deleted when the directory
00375    // in which tey are stored is closed.
00376 }
00377 
00378 //______________________________________________________________________________
00379 void HistogramManager::Hfill(Event *event)
00380 {
00381    // Fill histograms.
00382 
00383    fNtrack->Fill(event->GetNtrack());
00384    fNseg->Fill(event->GetNseg());
00385    fTemperature->Fill(event->GetTemperature());
00386 
00387    for (Int_t itrack = 0; itrack < event->GetNtrack(); itrack++) {
00388       Track *track = (Track*)event->GetTracks()->UncheckedAt(itrack);
00389       fPx->Fill(track->GetPx());
00390       fPy->Fill(track->GetPy());
00391       fPz->Fill(track->GetPz());
00392       fRandom->Fill(track->GetRandom());
00393       fMass2->Fill(track->GetMass2());
00394       fBx->Fill(track->GetBx());
00395       fBy->Fill(track->GetBy());
00396       fMeanCharge->Fill(track->GetMeanCharge());
00397       fXfirst->Fill(track->GetXfirst());
00398       fXlast->Fill(track->GetXlast());
00399       fYfirst->Fill(track->GetYfirst());
00400       fYlast->Fill(track->GetYlast());
00401       fZfirst->Fill(track->GetZfirst());
00402       fZlast->Fill(track->GetZlast());
00403       fCharge->Fill(track->GetCharge());
00404       fNpoint->Fill(track->GetNpoint());
00405       fValid->Fill(track->GetValid());
00406    }
00407 }

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