StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PicoDstAnalyzer.C
1 
16 // This is needed for calling standalone classes (not needed on RACF)
17 #define _VANILLA_ROOT_
18 
19 // C++ headers
20 #include <iostream>
21 
22 // ROOT headers
23 #include "TROOT.h"
24 #include "TFile.h"
25 #include "TChain.h"
26 #include "TTree.h"
27 #include "TSystem.h"
28 #include "TH1.h"
29 #include "TH2.h"
30 #include "TMath.h"
31 
32 // PicoDst headers
33 #include "../StPicoDstReader.h"
34 #include "../StPicoDst.h"
35 #include "../StPicoEvent.h"
36 #include "../StPicoTrack.h"
37 #include "../StPicoBTofHit.h"
38 #include "../StPicoBTowHit.h"
39 #include "../StPicoEmcTrigger.h"
40 #include "../StPicoBTofPidTraits.h"
41 #include "../StPicoTrackCovMatrix.h"
42 
43 // Load libraries (for ROOT_VERSTION_CODE >= 393215)
44 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
45 R__LOAD_LIBRARY(../libStPicoDst)
46 #endif
47 
48 // inFile - is a name of name.picoDst.root file or a name
49 // of a name.lis(t) files that contains a list of
50 // name1.picoDst.root files
51 
52 //_________________
53 void PicoDstAnalyzer(const Char_t *inFile = "../files/st_physics_12126101_raw_3040006.picoDst.root") {
54 
55  std::cout << "Hi! Lets do some physics, Master!" << std::endl;
56 
57  StPicoDstReader* picoReader = new StPicoDstReader(inFile);
58  picoReader->Init();
59 
60  //Long64_t events2read = picoReader->chain()->GetEntries();
61 
62  // This is a way if you want to spead up IO
63  std::cout << "Explicit read status for some branches" << std::endl;
64  picoReader->SetStatus("*",0);
65  picoReader->SetStatus("Event",1);
66  picoReader->SetStatus("Track",1);
67  picoReader->SetStatus("BTofHit",1);
68  picoReader->SetStatus("BTofPidTraits",1);
69  //picoReader->SetStatus("BTowHit",0);
70  //picoReader->SetStatus("EmcTrigger",0);
71  //picoReader->SetStatus("TrackCovMatrix",1);
72  std::cout << "Status has been set" << std::endl;
73 
74  std::cout << "Now I know what to read, Master!" << std::endl;
75 
76  if( !picoReader->chain() ) {
77  std::cout << "No chain has been found." << std::endl;
78  }
79  Long64_t eventsInTree = picoReader->tree()->GetEntries();
80  std::cout << "eventsInTree: " << eventsInTree << std::endl;
81  Long64_t events2read = picoReader->chain()->GetEntries();
82 
83  std::cout << "Number of events to read: " << events2read
84  << std::endl;
85 
86  // Histogramming
87  // Event
88  TH1F *hRefMult = new TH1F("hRefMult",
89  "Reference multiplicity;refMult",
90  500, -0.5, 499.5);
91  TH2F *hVtxXvsY = new TH2F("hVtxXvsY",
92  "hVtxXvsY",
93  200,-10.,10.,200,-10.,10.);
94  TH1F *hVtxZ = new TH1F("hVtxZ","hVtxZ",
95  140, -70., 70.);
96 
97  // Track
98  TH1F *hGlobalPtot = new TH1F("hGlobalPtot",
99  "Global track momentum;p (GeV/c)",
100  100, 0., 1. );
101  TH1F *hGlobalPtotCut = new TH1F("hGlobalPtotCut",
102  "Global track momentum after cut;p (GeV/c)",
103  100, 0., 1. );
104  TH1F *hPrimaryPtot = new TH1F("hPrimaryPtot",
105  "Primary track momentum;p (GeV/c)",
106  100, 0., 1. );
107  TH1F *hPrimaryPtotCut = new TH1F("hPrimaryPtotCut",
108  "Primary track momentum after cut;p (GeV/c)",
109  100, 0., 1. );
110  TH1F *hTransvMomentum = new TH1F("hTransvMomentum",
111  "Track transverse momentum;p_{T} (GeV/c)",
112  200, 0., 2.);
113  TH2F *hGlobalPhiVsPt[2];
114  for(int i=0; i<2; i++) {
115  hGlobalPhiVsPt[i] = new TH2F(Form("hGlobalPhiVsPt_%d",i),
116  Form("#phi vs. p_{T} for charge: %d;p_{T} (GeV/c);#phi (rad)", (i==0) ? 1 : -1),
117  300, 0., 3.,
118  630, -3.15, 3.15);
119  }
120  TH1F *hNSigmaPion = new TH1F("hNSigmaPion",
121  "n#sigma(#pi);n#sigma(#pi)",
122  400, -10., 10.);
123  TH1F *hNSigmaElectron = new TH1F("hNSigmaElectron",
124  "n#sigma(e);n#sigma(e)",
125  400,-10.,10.);
126  TH1F *hNSigmaKaon = new TH1F("hNSigmaKaon",
127  "n#sigma(K);n#sigma(K)",
128  400, -10., 10.);
129  TH1F *hNSigmaProton = new TH1F("hNSigmaProton",
130  "n#sigma(p);n#sigma(p)",
131  400, -10., 10.);
132 
133  // TofPidTrait
134  TH1F *hTofBeta = new TH1F("hTofBeta",
135  "BTofPidTraits #beta;#beta",
136  2000, 0., 2.);
137 
138  // TofHit
139  TH1F *hBTofTrayHit = new TH1F("hBTofTrayHit","BTof tray number with the hit",
140  120, -0.5, 119.5);
141 
142 
143  // Loop over events
144  for(Long64_t iEvent=0; iEvent<events2read; iEvent++) {
145 
146  std::cout << "Working on event #[" << (iEvent+1)
147  << "/" << events2read << "]" << std::endl;
148 
149  Bool_t readEvent = picoReader->readPicoEvent(iEvent);
150  if( !readEvent ) {
151  std::cout << "Something went wrong, Master! Nothing to analyze..."
152  << std::endl;
153  break;
154  }
155 
156  // Retrieve picoDst
157  StPicoDst *dst = picoReader->picoDst();
158 
159  // Retrieve event information
160  StPicoEvent *event = dst->event();
161  if( !event ) {
162  std::cout << "Something went wrong, Master! Event is hiding from me..."
163  << std::endl;
164  break;
165  }
166  hRefMult->Fill( event->refMult() );
167 
168  TVector3 pVtx = event->primaryVertex();
169  hVtxXvsY->Fill( event->primaryVertex().X(), event->primaryVertex().Y() );
170  hVtxZ->Fill( event->primaryVertex().Z() );
171 
172  // Track analysis
173  Int_t nTracks = dst->numberOfTracks();
174  Int_t nMatrices = dst->numberOfTrackCovMatrices();
175  if(nTracks != nMatrices) {
176  //std::cout << "Number of tracks and matrices do not match!" << std::endl;
177  }
178  //std::cout << "Number of tracks in event: " << nTracks << std::endl;
179 
180  // Track loop
181  for(Int_t iTrk=0; iTrk<nTracks; iTrk++) {
182 
183  // Retrieve i-th pico track
184  StPicoTrack *picoTrack = dst->track(iTrk);
185 
186  if(!picoTrack) continue;
187  //std::cout << "Track #[" << (iTrk+1) << "/" << nTracks << "]" << std::endl;
188 
189  hGlobalPtot->Fill( picoTrack->gMom().Mag() );
190  if( picoTrack->isPrimary() ) {
191  hPrimaryPtot->Fill( picoTrack->pMom().Mag() );
192  }
193 
194  // Simple single-track cut
195  if( picoTrack->gMom().Mag() < 0.1 ||
196  picoTrack->gDCA(pVtx).Mag()>50. ) {
197  continue;
198  }
199 
200  hGlobalPtotCut->Fill( picoTrack->gMom().Mag() );
201  if( picoTrack->isPrimary() ) {
202  hPrimaryPtotCut->Fill( picoTrack->pMom().Mag() );
203  }
204  if( picoTrack->charge() > 0 ) {
205  hGlobalPhiVsPt[0]->Fill( picoTrack->gMom().Pt(),
206  picoTrack->gMom().Phi() );
207  }
208  else {
209  hGlobalPhiVsPt[1]->Fill( picoTrack->gMom().Pt(),
210  picoTrack->gMom().Phi() );
211  }
212  hNSigmaElectron->Fill( picoTrack->nSigmaElectron() );
213  hNSigmaPion->Fill( picoTrack->nSigmaPion() );
214  hNSigmaKaon->Fill( picoTrack->nSigmaKaon() );
215  hNSigmaProton->Fill( picoTrack->nSigmaProton() );
216 
217  hTransvMomentum->Fill( picoTrack->gMom().Pt() );
218 
219  // Check if track has TOF signal
220  if( picoTrack->isTofTrack() ) {
221  // Retrieve corresponding trait
222  StPicoBTofPidTraits *trait = dst->btofPidTraits( picoTrack->bTofPidTraitsIndex() );
223  if( !trait ) {
224  std::cout << "O-oh... No BTofPidTrait # " << picoTrack->bTofPidTraitsIndex()
225  << " for track # " << iTrk << std::endl;
226  std::cout << "Check that you turned on the branch!" << std::endl;
227  continue;
228  }
229  // Fill beta
230  hTofBeta->Fill( trait->btofBeta() );
231  } //if( isTofTrack() )
232 
233  } //for(Int_t iTrk=0; iTrk<nTracks; iTrk++)
234 
235  // Hit analysis
236  Int_t nBTofHits = dst->numberOfBTofHits();
237  //std::cout << "Number of btofHits in event: " << nBTofHits << std::endl;
238 
239  // Hit loop
240  for(Int_t iHit=0; iHit<nBTofHits; iHit++) {
241 
242  StPicoBTofHit *btofHit = dst->btofHit(iHit);
243  if( !btofHit ) continue;
244  hBTofTrayHit->Fill( btofHit->tray() );
245  } //for(Int_t iHit=0; iHit<nBTofHits; iHit++)
246 
247 
248 
249  } //for(Long64_t iEvent=0; iEvent<events2read; iEvent++)
250 
251  picoReader->Finish();
252 
253  std::cout << "I'm done with analysis. We'll have a Nobel Prize, Master!"
254  << std::endl;
255 }
Bool_t isPrimary() const
Return if track is primary.
Definition: StPicoTrack.h:178
Bool_t readPicoEvent(Long64_t iEvent)
Read next event in the chain.
Allows to read picoDst file(s)
Float_t nSigmaKaon() const
Return nSigma(kaon)
Definition: StPicoTrack.h:138
Int_t tray() const
Return tray number.
Definition: StPicoBTofHit.h:39
Float_t nSigmaPion() const
Return nSigma(pion)
Definition: StPicoTrack.h:136
TChain * chain()
Return pointer to the chain of .picoDst.root files.
StPicoDst * picoDst()
Return a pointer to picoDst (return NULL if no dst is found)
Float_t btofBeta() const
Return beta (compression = beta * 20000)
TVector3 gMom() const
Return momentum (GeV/c) of the global tracks at the point of DCA to the primary vertex.
Definition: StPicoTrack.h:64
static StPicoEvent * event()
Return pointer to current StPicoEvent (class holding the event wise information)
Definition: StPicoDst.h:63
void SetStatus(const Char_t *branchNameRegex, Int_t enable)
Set enable/disable branch matching when reading picoDst.
Holds information about track parameters.
Definition: StPicoTrack.h:35
static UInt_t numberOfTracks()
Return number of tracks.
Definition: StPicoDst.h:104
Float_t nSigmaElectron() const
Return nSigma(electron)
Definition: StPicoTrack.h:142
Stores BTOF hit information.
Definition: StPicoBTofHit.h:18
Main class that keeps TClonesArrays with main classes.
Definition: StPicoDst.h:40
static StPicoBTofHit * btofHit(Int_t i)
Return pointer to i-th btof hit.
Definition: StPicoDst.h:73
TVector3 pMom() const
Return momentum (GeV/c) of the primary track. Return (0,0,0) if not primary track.
Definition: StPicoTrack.h:62
void Init()
Calls openRead()
static StPicoTrack * track(Int_t i)
Return pointer to i-th track.
Definition: StPicoDst.h:65
TTree * tree()
Return pointer to the current TTree.
Float_t nSigmaProton() const
Return nSigma(proton)
Definition: StPicoTrack.h:140
Float_t gDCA(Float_t pVtxX, Float_t pVtxY, Float_t pVtxZ) const
Return distance in xyz direction (cm) between the (x,y,z) point and the DCA point to primary vertex...
Stores global information about the event.
Definition: StPicoEvent.h:24
Bool_t isTofTrack() const
Return if track has TOF hit.
Definition: StPicoTrack.h:167
static UInt_t numberOfTrackCovMatrices()
Return number of track covariance matrices.
Definition: StPicoDst.h:128
void Finish()
Close files and finilize.
Int_t bTofPidTraitsIndex() const
Return index to the corresponding BTOF PID trait.
Definition: StPicoTrack.h:183
static UInt_t numberOfBTofHits()
Return number of BTof hits.
Definition: StPicoDst.h:112
TVector3 primaryVertex() const
Return primary vertex position.
Definition: StPicoEvent.h:52
static StPicoBTofPidTraits * btofPidTraits(Int_t i)
Return pointer to i-th btof pidTraits.
Definition: StPicoDst.h:85
Short_t charge() const
Return charge of the track (encoded in nHitsFit as: nHitsFit * charge)
Definition: StPicoTrack.h:102