StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
picoAnalyzerStandalone.C
1 
26 // C++ headers
27 #include <iostream>
28 
29 // ROOT headers
30 #include "TROOT.h"
31 #include "TFile.h"
32 #include "TChain.h"
33 #include "TTree.h"
34 #include "TSystem.h"
35 #include "TH1.h"
36 #include "TH2.h"
37 #include "TMath.h"
38 
39 // PicoDst headers
40 #include "StPicoDstReader.h"
41 #include "StPicoDst.h"
42 #include "StPicoEvent.h"
43 #include "StPicoTrack.h"
44 #include "StPicoBTofHit.h"
45 #include "StPicoBTowHit.h"
46 #include "StPicoEmcTrigger.h"
47 #include "StPicoBTofPidTraits.h"
48 #include "StPicoTrackCovMatrix.h"
49 #include "StPicoFmsHit.h"
50 #include "StPicoETofHit.h"
51 #include "StPicoEpdHit.h"
52 
53 //_________________
54 int main(int argc, char* argv[]) {
55 
56 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
57  R__LOAD_LIBRARY(libStPicoDst);
58 #else
59  gSystem->Load("../libs/libStPicoDst.so");
60 #endif
61 
62  std::cout << "Hi! Lets do some physics, Master!" << std::endl;
63 
64  const char* fileName;
65  const char* oFileName;
66 
67  switch (argc) {
68  case 3:
69  fileName = argv[1];
70  oFileName = argv[2];
71  break;
72  default:
73  std::cout << "Usage: picoAnalyzerStandalone inputFileName outputFileName.root" << std::endl;
74  return -1;
75  }
76  std::cout << " inputFileName : " << fileName << std::endl;
77  std::cout << " outputFileName: " << oFileName << std::endl;
78 
79  StPicoDstReader* picoReader = new StPicoDstReader(fileName);
80  picoReader->Init();
81 
82  // This is a way if you want to spead up I/O
83  std::cout << "Explicit read status for some branches" << std::endl;
84  picoReader->SetStatus("*",0);
85  picoReader->SetStatus("Event*", 1);
86  picoReader->SetStatus("Track*", 1);
87  picoReader->SetStatus("BTofHit*", 1);
88  picoReader->SetStatus("BTofPidTraits*", 1);
89  picoReader->SetStatus("BTowHit*", 1);
90  picoReader->SetStatus("ETofHit*", 1);
91  picoReader->SetStatus("EpdHit*", 1);
92  //picoReader->SetStatus("EmcTrigger",0);
93  //picoReader->SetStatus("TrackCovMatrix",1);
94  std::cout << "Status has been set" << std::endl;
95 
96  std::cout << "Now I know what to read, Master!" << std::endl;
97 
98  if( !picoReader->chain() ) {
99  std::cout << "No chain has been found." << std::endl;
100  }
101  Long64_t eventsInTree = picoReader->tree()->GetEntries();
102  std::cout << "eventsInTree: " << eventsInTree << std::endl;
103  Long64_t events2read = picoReader->chain()->GetEntries();
104 
105  std::cout << "Number of events to read: " << events2read
106  << std::endl;
107 
108 
109  TFile *oFile = new TFile(oFileName, "recreate");
110 
111  // Histogramming
112  // Event
113  TH1F *hRefMult = new TH1F("hRefMult",
114  "Reference multiplicity;refMult",
115  500, -0.5, 499.5);
116  TH2F *hVtxXvsY = new TH2F("hVtxXvsY",
117  "hVtxXvsY",
118  200,-10.,10.,200,-10.,10.);
119  TH1F *hVtxZ = new TH1F("hVtxZ","hVtxZ",
120  140, -70., 70.);
121 
122  // Track
123  TH1F *hGlobalPtot = new TH1F("hGlobalPtot",
124  "Global track momentum;p (GeV/c)",
125  100, 0., 1. );
126  TH1F *hGlobalPtotCut = new TH1F("hGlobalPtotCut",
127  "Global track momentum after cut;p (GeV/c)",
128  100, 0., 1. );
129  TH1F *hPrimaryPtot = new TH1F("hPrimaryPtot",
130  "Primary track momentum;p (GeV/c)",
131  100, 0., 1. );
132  TH1F *hPrimaryPtotCut = new TH1F("hPrimaryPtotCut",
133  "Primary track momentum after cut;p (GeV/c)",
134  100, 0., 1. );
135  TH1F *hTransvMomentum = new TH1F("hTransvMomentum",
136  "Track transverse momentum;p_{T} (GeV/c)",
137  200, 0., 2.);
138  TH2F *hGlobalPhiVsPt[2];
139  for(int i=0; i<2; i++) {
140  hGlobalPhiVsPt[i] = new TH2F(Form("hGlobalPhiVsPt_%d",i),
141  Form("#phi vs. p_{T} for charge: %d;p_{T} (GeV/c);#phi (rad)", (i==0) ? 1 : -1),
142  300, 0., 3.,
143  630, -3.15, 3.15);
144  }
145  TH1F *hNSigmaPion = new TH1F("hNSigmaPion",
146  "n#sigma(#pi);n#sigma(#pi)",
147  400, -10., 10.);
148  TH1F *hNSigmaElectron = new TH1F("hNSigmaElectron",
149  "n#sigma(e);n#sigma(e)",
150  400,-10.,10.);
151  TH1F *hNSigmaKaon = new TH1F("hNSigmaKaon",
152  "n#sigma(K);n#sigma(K)",
153  400, -10., 10.);
154  TH1F *hNSigmaProton = new TH1F("hNSigmaProton",
155  "n#sigma(p);n#sigma(p)",
156  400, -10., 10.);
157 
158  // BTof pid traits
159  TH1F *hTofBeta = new TH1F("hTofBeta", "BTofPidTraits #beta;#beta",
160  2000, 0., 2.);
161 
162  // BTOF hit
163  TH1F *hBTofTrayHit = new TH1F("hBTofTrayHit","BTof tray number with the hit",
164  120, -0.5, 119.5);
165 
166  // BTOW hit
167  TH1F *hBTowAdc = new TH1F("hBTowAdc","Barrel tower ADC;ADC",500,0.,500);
168 
169  // FMS hit
170  TH1F *hFmsAdc = new TH1F("hFmsAdc","ADC in FMS modules;ADC",1000, 0.,5000);
171 
172  // ETOF hit
173  TH1F *hETofToT = new TH1F("hETofToT","eTOF TOT;Time over threshold (ns)",300, 0.,150);
174 
175  // EPD hit
176  TH1F *hEpdAdc = new TH1F("hEpdAdc","ADC in EPD;ADC",4095, 0., 4095);
177 
178 
179  // Loop over events
180  for(Long64_t iEvent=0; iEvent<events2read; iEvent++) {
181 
182  std::cout << "Working on event #[" << (iEvent+1)
183  << "/" << events2read << "]" << std::endl;
184 
185  Bool_t readEvent = picoReader->readPicoEvent(iEvent);
186  if( !readEvent ) {
187  std::cout << "Something went wrong, Master! Nothing to analyze..."
188  << std::endl;
189  break;
190  }
191 
192  // Retrieve picoDst
193  StPicoDst *dst = picoReader->picoDst();
194 
195  // Retrieve event information
196  StPicoEvent *event = dst->event();
197  if( !event ) {
198  std::cout << "Something went wrong, Master! Event is hiding from me..."
199  << std::endl;
200  break;
201  }
202  hRefMult->Fill( event->refMult() );
203 
204  TVector3 pVtx = event->primaryVertex();
205  hVtxXvsY->Fill( event->primaryVertex().X(), event->primaryVertex().Y() );
206  hVtxZ->Fill( event->primaryVertex().Z() );
207 
208  // Track analysis
209  Int_t nTracks = dst->numberOfTracks();
210  Int_t nMatrices = dst->numberOfTrackCovMatrices();
211  if(nTracks != nMatrices) {
212  //std::cout << "Number of tracks and matrices do not match!" << std::endl;
213  }
214  //std::cout << "Number of tracks in event: " << nTracks << std::endl;
215 
216  // Track loop
217  for(Int_t iTrk=0; iTrk<nTracks; iTrk++) {
218 
219  // Retrieve i-th pico track
220  StPicoTrack *picoTrack = dst->track(iTrk);
221 
222  if(!picoTrack) continue;
223  //std::cout << "Track #[" << (iTrk+1) << "/" << nTracks << "]" << std::endl;
224 
225  hGlobalPtot->Fill( picoTrack->gMom().Mag() );
226  if( picoTrack->isPrimary() ) {
227  hPrimaryPtot->Fill( picoTrack->pMom().Mag() );
228  }
229 
230  // Simple single-track cut
231  if( picoTrack->gMom().Mag() < 0.1 ||
232  picoTrack->gDCA(pVtx).Mag()>50. ) {
233  continue;
234  }
235 
236  hGlobalPtotCut->Fill( picoTrack->gMom().Mag() );
237  if( picoTrack->isPrimary() ) {
238  hPrimaryPtotCut->Fill( picoTrack->pMom().Mag() );
239  }
240  if( picoTrack->charge() > 0 ) {
241  hGlobalPhiVsPt[0]->Fill( picoTrack->gMom().Pt(),
242  picoTrack->gMom().Phi() );
243  }
244  else {
245  hGlobalPhiVsPt[1]->Fill( picoTrack->gMom().Pt(),
246  picoTrack->gMom().Phi() );
247  }
248  hNSigmaElectron->Fill( picoTrack->nSigmaElectron() );
249  hNSigmaPion->Fill( picoTrack->nSigmaPion() );
250  hNSigmaKaon->Fill( picoTrack->nSigmaKaon() );
251  hNSigmaProton->Fill( picoTrack->nSigmaProton() );
252 
253  hTransvMomentum->Fill( picoTrack->gMom().Pt() );
254 
255  // Check if track has TOF signal
256  if( picoTrack->isTofTrack() ) {
257  // Retrieve corresponding trait
258  StPicoBTofPidTraits *trait = dst->btofPidTraits( picoTrack->bTofPidTraitsIndex() );
259  if( !trait ) {
260  std::cout << "O-oh... No BTofPidTrait # " << picoTrack->bTofPidTraitsIndex()
261  << " for track # " << iTrk << std::endl;
262  std::cout << "Check that you turned on the branch!" << std::endl;
263  continue;
264  }
265  // Fill beta
266  hTofBeta->Fill( trait->btofBeta() );
267  } //if( isTofTrack() )
268 
269  } //for(Int_t iTrk=0; iTrk<nTracks; iTrk++)
270 
272  // Hit analysis //
274 
275  // BTOF hits
276  Int_t nBTofHits = dst->numberOfBTofHits();
277  //std::cout << "Number of btofHits in event: " << nBTofHits << std::endl;
278  for(Int_t iHit=0; iHit<nBTofHits; iHit++) {
279  StPicoBTofHit *btofHit = dst->btofHit(iHit);
280  if( !btofHit ) continue;
281  //std::cout << "BTofHit #[" << (iHit+1) << "/" << nBTofHits << "]" << std::endl;
282  hBTofTrayHit->Fill( btofHit->tray() );
283  } //for(Int_t iHit=0; iHit<nBTofHits; iHit++)
284 
285  // BTOW hits
286  Int_t nBTowHits = dst->numberOfBTowHits();
287  for(Int_t iHit=0; iHit<nBTowHits; iHit++) {
288  StPicoBTowHit *btowHit = dst->btowHit(iHit);
289  if( !btowHit ) continue;
290  //std::cout << "BTowHit #[" << (iHit+1) << "/" << nBTowHits << "]" << std::endl;
291  hBTowAdc->Fill( btowHit->adc() );
292  }
293 
294  // FMS hits
295  Int_t nFmsHits = dst->numberOfFmsHits();
296  for(Int_t iHit=0; iHit<nFmsHits; iHit++) {
297  StPicoFmsHit *fmsHit = dst->fmsHit(iHit);
298  if( !fmsHit ) continue;
299  //std::cout << "FmsHit #[" << (iHit+1) << "/" << nFmsHits << "]" << std::endl;
300  hFmsAdc->Fill( fmsHit->adc() );
301  }
302 
303  // ETOF hits
304  Int_t nETofHits = dst->numberOfETofHits();
305  for(Int_t iHit=0; iHit<nETofHits; iHit++) {
306  StPicoETofHit *etofHit = dst->etofHit(iHit);
307  if( !etofHit ) continue;
308  //std::cout << "ETofHit #[" << (iHit+1) << "/" << nETofHits << "]" << std::endl;
309  hETofToT->Fill( etofHit->timeOverThreshold() );
310  }
311 
312  // EPD hits
313  Int_t nEpdHits = dst->numberOfEpdHits();
314  for(Int_t iHit=0; iHit<nEpdHits; iHit++) {
315  StPicoEpdHit *epdHit = dst->epdHit(iHit);
316  if( !epdHit ) continue;
317  //std::cout << "EpdHit #[" << (iHit+1) << "/" << nEpdHits << "]" << std::endl;
318  hEpdAdc->Fill( epdHit->adc() );
319  }
320 
321  } //for(Long64_t iEvent=0; iEvent<events2read; iEvent++)
322 
323  picoReader->Finish();
324  oFile->Write();
325  oFile->Close();
326 
327  std::cout << "I'm done with analysis. We'll have a Nobel Prize, Master!"
328  << std::endl;
329 }
Bool_t isPrimary() const
Return if track is primary.
Definition: StPicoTrack.h:178
static StPicoETofHit * etofHit(Int_t i)
Return pointer to i-th etof hit.
Definition: StPicoDst.h:95
Bool_t readPicoEvent(Long64_t iEvent)
Read next event in the chain.
static UInt_t numberOfFmsHits()
Return number of FMS hits.
Definition: StPicoDst.h:120
Allows to read picoDst file(s)
static UInt_t numberOfBTowHits()
Return number of BTow hits.
Definition: StPicoDst.h:110
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
Holds information about BEMC tower.
Definition: StPicoBTowHit.h:19
static StPicoBTowHit * btowHit(Int_t i)
Return pointer to i-th btow hit.
Definition: StPicoDst.h:71
TChain * chain()
Return pointer to the chain of .picoDst.root files.
Float_t timeOverThreshold() const
Return time over threshold (ns) of eTOF hit.
Definition: StPicoETofHit.h:59
StPicoDst * picoDst()
Return a pointer to picoDst (return NULL if no dst is found)
Int_t adc() const
Return ADC of the tower.
Definition: StPicoBTowHit.h:38
static StPicoEpdHit * epdHit(Int_t i)
Return pointer to i-th epd hit.
Definition: StPicoDst.h:79
Holds information about FMS hit.
Definition: StPicoFmsHit.h:17
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 numberOfEpdHits()
Return number of EPD hits.
Definition: StPicoDst.h:118
static UInt_t numberOfETofHits()
Return number of ETof hits.
Definition: StPicoDst.h:134
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.
Int_t adc() const
ADC value [0,4095].
Definition: StPicoEpdHit.h:79
Float_t nSigmaProton() const
Return nSigma(proton)
Definition: StPicoTrack.h:140
Stores eTOF hit information.
Definition: StPicoETofHit.h:19
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.
static StPicoFmsHit * fmsHit(Int_t i)
Return pointer to i-th fms hit.
Definition: StPicoDst.h:81
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
Int_t adc() const
Return ADC.
Definition: StPicoFmsHit.h:40
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