StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
makePicoDstQA.C
1 //Xianglei Zhu
2 //Skeleton embedding PicoDst analysis macro with StPicoDstMaker
3 //Run it with the wrapper in ACLIC mode, CINT mode for debug ONLY
4 
5 #ifndef __CINT__
6 #include "TROOT.h"
7 #include "TSystem.h"
8 #include <iostream>
9 #include "TH1.h"
10 #include "TH2.h"
11 #include "TH3.h"
12 #include "TFile.h"
13 #include "TTree.h"
14 #include "TChain.h"
15 #include "TTreeHelper.h"
16 #include "TDatime.h"
17 #include "StarRoot/TUnixTime.h"
18 #include "StChain.h"
19 #include "StMessMgr.h"
20 #include "StPicoEvent/StPicoDst.h"
21 #include "StPicoEvent/StPicoEvent.h"
22 #include "StPicoEvent/StPicoTrack.h"
23 #include "StPicoEvent/StPicoMcTrack.h"
24 #include "StPicoEvent/StPicoMcVertex.h"
25 #include "StPicoEvent/StPicoArrays.h"
26 #include "StPicoEvent/StPicoBTofPidTraits.h"
27 #include "StPicoDstMaker/StPicoDstMaker.h"
28 #include "StBTofHeader.h"
29 #include "StThreeVectorF.hh"
30 #include "StPhysicalHelixD.hh"
31 #endif
32 
33 void makePicoDstQA(TString InputFileList, Int_t nFiles = 1, Int_t nEvents = 0, TString OutputFile = "test.histo.root" );
34 
35 void makePicoDstQA(TString InputFileList, Int_t nFiles, Int_t nEvents, TString OutputFile )
36 {
37 
38  // Load libraries for CINT mode
39 #ifdef __CINT__
40  gROOT -> Macro("loadMuDst.C");
41  gSystem->Load("StPicoEvent");
42  gSystem->Load("StPicoDstMaker");
43 #endif
44 
45  // List of member links in the chain
46  StChain* chain = new StChain ;
47 
48  StPicoDstMaker* picoDstMaker = new StPicoDstMaker(StPicoDstMaker::IoRead,InputFileList,"picoDst");
49 
50  if ( nEvents == 0 ) nEvents = 10000000 ; // Take all events in nFiles if nEvents = 0
51 
52  // ---------------- modify here according to your QA purpose --------------------------
53  TFile *tags_output = new TFile( OutputFile, "recreate" ) ;
54  tags_output->cd();
55 
56  //book histograms or trees if you need
57  TH1F *hPhiMc = new TH1F("hPhiMc","Phi of Mc tracks",200,-TMath::Pi(),TMath::Pi());
58  TH1F *hPtMc = new TH1F("hPtMc","Pt of Mc tracks",200,0,5.0);
59  TH1F *hSelPtMc = new TH1F("hSelPtMc","Pt of selected Mc tracks",38,0.2,4.0);
60  TH1F *hEtaMc = new TH1F("hEtaMc","Eta of Mc tracks",200,-2.0,2.0);
61  TH1F *hPhi = new TH1F("hPhi","Phi of matched RC tracks",200,-TMath::Pi(),TMath::Pi());
62  TH1F *hPt = new TH1F("hPt","Pt of matched RC tracks",200,0,5.0);
63  TH1F *hSelPt = new TH1F("hSelPt","Pt of selected matched RC tracks",38,0.2,4.0);
64  TH1F *hEffPt = new TH1F("hEffPt","Efficiency in pt bins",38,0.2,4.0);
65  TH1F *hEta = new TH1F("hEta","Eta of matched RC tracks",200,-2.0,2.0);
66  hEffPt->Sumw2();
67  hSelPt->Sumw2();
68  hSelPtMc->Sumw2();
69 
70  // ---------------- end of histogram and tree booking --------------------------------
71 
72  // Loop over the links in the chain
73  Int_t iInit = chain -> Init() ;
74  if (iInit) chain->FatalErr(iInit,"on init");
75 
76  // chain -> EventLoop(1,nEvents) ; //will output lots of useless debugging info.
77  Int_t istat = 0, i = 1;
78  while (i <= nEvents && istat != 2) {
79  if(i%10==0)cout << endl << "== Event " << i << " start ==" << endl;
80  chain->Clear();
81  istat = chain->Make(i);
82 
83  if (istat == 2)
84  cout << "Last event processed. Status = " << istat << endl;
85  if (istat == 3)
86  cout << "Error event processed. Status = " << istat << endl;
87  i++;
88 
89  if(istat != kStOK)continue; //skip those suspectible events
90 
91  // ---------------- modify here according to your QA purpose --------------------------
92  //cout<<"In event #. "<<i-1<<" Maker status "<<istat<<endl;
93 
94  StPicoDst* mPicoDst = picoDstMaker->picoDst();
95  if(!mPicoDst) {
96  LOG_WARN << " No PicoDst " << endm; continue;
97  }
98 
99  StPicoEvent* mPicoEvent = mPicoDst->event();
100  if(!mPicoEvent) {
101  LOG_WARN << " No PicoEvent " << endm; continue;
102  }
103 
104  //trigger
105  if ( ! mPicoEvent->isTrigger(610001) && ! mPicoEvent->isTrigger(610011) && ! mPicoEvent->isTrigger(610021) && ! mPicoEvent->isTrigger(610031) && ! mPicoEvent->isTrigger(610041) && ! mPicoEvent->isTrigger(610051) ) continue ;
106  //Vz
107  if ( fabs(mPicoEvent->primaryVertex().Z()) > 75.0 ) continue ;
108  //Vr
109  if ( mPicoEvent->primaryVertex().Perp() > 2.0 ) continue ;
110 
111  //fill MC histograms
112  //The MC arrays in PicoDst
113  Int_t NoMuMcVertices = mPicoDst->numberOfMcVertices();
114  Int_t NoMuMcTracks = mPicoDst->numberOfMcTracks();
115  LOG_INFO <<"# of MC tracks = "<< NoMuMcTracks <<" # of MC vertices = "<< NoMuMcVertices << endm;
116  if (! NoMuMcVertices || ! NoMuMcTracks) {
117  LOG_WARN << "Ev. " << i << " has no MC information ==> skip it" << endm;
118  continue;
119  }
120  Int_t nMc = 0;
121 
122  // Loop for MC tracks
123  for(Int_t itrk=0; itrk<NoMuMcTracks; itrk++){
124  StPicoMcTrack *mcTrack = (StPicoMcTrack *) mPicoDst->mcTrack(itrk);
125  if (! mcTrack) continue;
126 
127  // Select only Triggered Mc Vertex, i.e. the MC track should originate from PV (IdVx=1)
128  Int_t IdVx = mcTrack->idVtxStart();
129  if (IdVx != 1) continue;
130 
131  const int Gid = mcTrack->geantId();
132 
133  nMc++; // # of MC tracks
134  if(Gid==11){//k+
135  hPtMc->Fill(mcTrack->p().Perp());
136  hPhiMc->Fill(mcTrack->p().Phi());
137  hEtaMc->Fill(mcTrack->p().PseudoRapidity());
138  if(fabs(mcTrack->p().PseudoRapidity())<0.5)hSelPtMc->Fill(mcTrack->p().Perp());
139  }
140  else {
141  LOG_WARN << "Gid: "<<Gid<<" in Ev. "<<i<<endm;
142  }
143  }
144 
145  //fill Event QA histograms
146  Int_t nTracks = mPicoDst->numberOfTracks();
147  StPicoTrack* ptrack ;
148  for(Int_t i=0; i<nTracks; i++) // Main loop for Iterating over tracks
149  {
150  ptrack = mPicoDst->track(i); // Pointer to a track
151  if(!ptrack->isPrimary())continue;
152 
153  if (ptrack->idTruth() <= 0 || ptrack->idTruth() > NoMuMcTracks) {
154  //cout << "Illegal idTruth " << ptrack->idTruth() << " The track is ignored" << endl;
155  continue;
156  }
157  StPicoMcTrack *mcTrack = (StPicoMcTrack *) mPicoDst->mcTrack(ptrack->idTruth()-1);
158  if (!mcTrack) {
159  LOG_WARN << "Inconsistency in mcArray(1), ignored" << endm;
160  continue;
161  }
162  if (mcTrack->id() != ptrack->idTruth()) {
163  LOG_WARN << "Mismatched idTruth " << ptrack->idTruth() << " and mcTrack Id " << mcTrack->id()
164  << " this track is ignored" << endm;
165  }
166  Int_t idMcVx = mcTrack->idVtxStart();
167  while (idMcVx != 1) {
168  StPicoMcVertex *mcVertex = (StPicoMcVertex *) mPicoDst->mcVertex(idMcVx-1);
169  Int_t idMcTrack = mcVertex->idOfParentTrack();
170  if (! idMcTrack) break;
171  StPicoMcTrack *mcTrackP = (StPicoMcTrack *) mPicoDst->mcTrack(idMcTrack-1);
172  idMcVx = mcTrackP->idVtxStart();
173  if (! idMcVx) break;
174  }
175  if (idMcVx != 1) continue; //this MC track is not eventually originated from PV
176 
177  if(mcTrack->geantId() != 11) continue;
178  if(mcTrack->idVtxStart() != 1) {
179  LOG_WARN<<"mc track may not directly originate from PV!"<<endm;
180  }
181  if(ptrack->qaTruth()<50.) continue;
182 
183  if(ptrack->nHits()<=15)continue;
184  //if(ptrack->flag()<=0)continue;
185  if(abs(ptrack->charge())!=1) continue;
186 
187  TVector3 p = ptrack->pMom();
188  hPhi->Fill(p.Phi());
189  hPt->Fill(p.Perp());
190  hEta->Fill(p.PseudoRapidity());
191  if(fabs(p.PseudoRapidity())<0.5)hSelPt->Fill(p.Perp());
192  //end of the filling
193  }
194  }
195  hEffPt->Divide(hSelPt,hSelPtMc,1,1,"B");
196 
197  if (nEvents > 1) chain -> Finish() ;
198 
199  if(tags_output!=NULL) tags_output -> Write() ;
200  if(tags_output!=NULL) tags_output -> Close() ;
201  //flush(tags_output);
202  delete tags_output;
203 
204  // Cleanup
205  delete chain ;
206 }
static StPicoMcTrack * mcTrack(Int_t i)
Return pointer to i-th MC track.
Definition: StPicoDst.h:101
Bool_t isPrimary() const
Return if track is primary.
Definition: StPicoTrack.h:178
Class that converts MuDst into PicoDst.
Holds information about Monte Carlo vertex.
Int_t geantId() const
Return particle ID defined by GEANT (accordingly to GPART)
Definition: StPicoMcTrack.h:60
Int_t idOfParentTrack() const
ID of the parent track.
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StChain.cxx:77
bool isTrigger(unsigned int) const
Int_t id() const
Return MC track ID (GEANT track ID)
Definition: StPicoMcTrack.h:56
static StPicoEvent * event()
Return pointer to current StPicoEvent (class holding the event wise information)
Definition: StPicoDst.h:63
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Definition: TDataSet.cxx:893
Holds information about track parameters.
Definition: StPicoTrack.h:35
virtual Int_t Finish()
Definition: StChain.cxx:85
static UInt_t numberOfTracks()
Return number of tracks.
Definition: StPicoDst.h:104
Main class that keeps TClonesArrays with main classes.
Definition: StPicoDst.h:40
StPicoDst * picoDst()
Returns null pointer if no StPicoDst.
Int_t idVtxStart() const
ID of start MC vertex.
Definition: StPicoMcTrack.h:80
TVector3 pMom() const
Return momentum (GeV/c) of the primary track. Return (0,0,0) if not primary track.
Definition: StPicoTrack.h:62
virtual Int_t Make()
Definition: StChain.cxx:110
Holds information about Monte Carlo track parameters.
Definition: StPicoMcTrack.h:32
static StPicoTrack * track(Int_t i)
Return pointer to i-th track.
Definition: StPicoDst.h:65
static StPicoMcVertex * mcVertex(Int_t i)
Return pointer to i-th MC vertex.
Definition: StPicoDst.h:99
Definition: Stypes.h:40
Int_t qaTruth() const
Qualtiy of the MC track.
Definition: StPicoTrack.h:205
TVector3 p() const
Return track three-momentum.
Definition: StPicoMcTrack.h:64
Stores global information about the event.
Definition: StPicoEvent.h:24
Int_t idTruth() const
Index of the corresponding MC track.
Definition: StPicoTrack.h:203
Int_t nHits() const
Return number of hits.
Definition: StPicoTrack.h:104
TVector3 primaryVertex() const
Return primary vertex position.
Definition: StPicoEvent.h:52
static UInt_t numberOfMcVertices()
Return number of MC vertices.
Definition: StPicoDst.h:138
Short_t charge() const
Return charge of the track (encoded in nHitsFit as: nHitsFit * charge)
Definition: StPicoTrack.h:102
static UInt_t numberOfMcTracks()
Return number of MC tracks.
Definition: StPicoDst.h:140