StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
makeMuDstQA.C
1 //Xianglei Zhu
2 //Skeleton embedding MuDST analysis macro with StMuDSTMaker
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 "StMuDSTMaker/COMMON/StMuDstMaker.h"
21 #include "StMuDSTMaker/COMMON/StMuDst.h"
22 #include "StMuDSTMaker/COMMON/StMuEvent.h"
23 #include "StMuDSTMaker/COMMON/StMuTrack.h"
24 #include "StMuDSTMaker/COMMON/StMuMcTrack.h"
25 #include "StMuDSTMaker/COMMON/StMuMcVertex.h"
26 #include "StMuDSTMaker/COMMON/StMuPrimaryVertex.h"
27 #include "StBTofHeader.h"
28 #include "StThreeVectorF.hh"
29 #include "StPhysicalHelixD.hh"
30 #endif
31 
32 void makeMuDstQA(TString InputFileList, Int_t nFiles = 1, Int_t nEvents = 0, TString OutputFile = "test.histo.root" );
33 
34 void makeMuDstQA(TString InputFileList, Int_t nFiles, Int_t nEvents, TString OutputFile )
35 {
36 
37  // Load libraries for CINT mode
38 #ifdef __CINT__
39  gROOT -> Macro("loadMuDst.C");
40 #endif
41 
42  // List of member links in the chain
43  StChain* chain = new StChain ;
44 
45  StMuDstMaker* muDstMaker = new StMuDstMaker(0,0,"",InputFileList,"MuDst",nFiles) ;
46 
47  // ---------------- modify here according to your QA purpose --------------------------
48  // Turn off everything but Primary tracks in order to speed up the analysis and eliminate IO
49  muDstMaker -> SetStatus("*",0) ; // Turn off all branches
50  muDstMaker -> SetStatus("MuEvent",1) ; // Turn on the Event data (esp. Event number)
51  muDstMaker -> SetStatus("PrimaryVertices",1) ; // Turn on the primary track data
52  muDstMaker -> SetStatus("PrimaryTracks",1) ; // Turn on the primary track data
53  muDstMaker -> SetStatus("GlobalTracks",1) ; // Turn on the global track data
54  muDstMaker -> SetStatus("CovGlobTrack",1); // to fix the refmult in Run14!!!
55  muDstMaker -> SetStatus("MCAll",1) ; // Turn on the McVertex/McTrack data
56  muDstMaker -> SetStatus("BTofHeader",1) ; // Turn on the btof data
57  muDstMaker -> SetDebug(0) ; // Turn off Debug information
58 
59  if ( nEvents == 0 ) nEvents = 10000000 ; // Take all events in nFiles if nEvents = 0
60 
61  // ---------------- modify here according to your QA purpose --------------------------
62  TFile *tags_output = new TFile( OutputFile, "recreate" ) ;
63  tags_output->cd();
64 
65  //book histograms or trees if you need
66  TH1F *hPhiMc = new TH1F("hPhiMc","Phi of Mc tracks",200,-TMath::Pi(),TMath::Pi());
67  TH1F *hPtMc = new TH1F("hPtMc","Pt of Mc tracks",200,0,5.0);
68  TH1F *hSelPtMc = new TH1F("hSelPtMc","Pt of selected Mc tracks",38,0.2,4.0);
69  TH1F *hEtaMc = new TH1F("hEtaMc","Eta of Mc tracks",200,-2.0,2.0);
70  TH1F *hPhi = new TH1F("hPhi","Phi of matched RC tracks",200,-TMath::Pi(),TMath::Pi());
71  TH1F *hPt = new TH1F("hPt","Pt of matched RC tracks",200,0,5.0);
72  TH1F *hSelPt = new TH1F("hSelPt","Pt of selected matched RC tracks",38,0.2,4.0);
73  TH1F *hEffPt = new TH1F("hEffPt","Efficiency in pt bins",38,0.2,4.0);
74  TH1F *hEta = new TH1F("hEta","Eta of matched RC tracks",200,-2.0,2.0);
75  hEffPt->Sumw2();
76  hSelPt->Sumw2();
77  hSelPtMc->Sumw2();
78 
79  // ---------------- end of histogram and tree booking --------------------------------
80 
81  // Loop over the links in the chain
82  Int_t iInit = chain -> Init() ;
83  if (iInit) chain->FatalErr(iInit,"on init");
84 
85  // chain -> EventLoop(1,nEvents) ; //will output lots of useless debugging info.
86  Int_t istat = 0, i = 1;
87  while (i <= nEvents && istat != 2) {
88  if(i%10==0)cout << endl << "== Event " << i << " start ==" << endl;
89  chain->Clear();
90  istat = chain->Make(i);
91 
92  if (istat == 2)
93  cout << "Last event processed. Status = " << istat << endl;
94  if (istat == 3)
95  cout << "Error event processed. Status = " << istat << endl;
96  i++;
97 
98  if(istat != kStOK)continue; //skip those suspectible events
99 
100  // ---------------- modify here according to your QA purpose --------------------------
101  //cout<<"In event #. "<<i-1<<" Maker status "<<istat<<endl;
102 
103  StMuDst* mMuDst = muDstMaker->muDst();
104  if(!mMuDst) {
105  LOG_WARN << " No MuDst " << endm; continue;
106  }
107 
108  StMuEvent* mMuEvent = mMuDst->event();
109  if(!mMuEvent) {
110  LOG_WARN << " No MuEvent " << endm; continue;
111  }
112 
113  //-----------------------------------------------------------------------------
114  //vertex selection
115  int const originalVertexId = mMuDst->currentVertexIndex();
116  StMuPrimaryVertex* selectedVertex = nullptr;
117  // choose the default vertex, i.e. the first vertex
118  mMuDst->setVertexIndex(0);
119  selectedVertex = mMuDst->primaryVertex();
120  // fall back to default vertex if no vertex is selected in the algorithm above.
121  // should skip this event in the event cuts below.
122  if ( ! selectedVertex ){
123  LOG_INFO << "Vertex is not valid" << endm;
124  //cout<<originalVertexId<<endl;
125  mMuDst->setVertexIndex(originalVertexId);
126  }
127  //end of vertex selection
128  //------------------------------------------------------------------------------
129 
130  //vertex is not selected
131  if ( ! selectedVertex ) continue;
132  //trigger
133  if ( ! mMuEvent->triggerIdCollection().nominal().isTrigger(610001) && ! mMuEvent->triggerIdCollection().nominal().isTrigger(610011) && ! mMuEvent->triggerIdCollection().nominal().isTrigger(610021) && ! mMuEvent->triggerIdCollection().nominal().isTrigger(610031) && ! mMuEvent->triggerIdCollection().nominal().isTrigger(610041) && ! mMuEvent->triggerIdCollection().nominal().isTrigger(610051) ) continue ;
134  //Vz
135  if ( fabs(mMuEvent->primaryVertexPosition().z()) > 75.0 ) continue ;
136  //Vr
137  if ( mMuEvent->primaryVertexPosition().perp() > 2.0 ) continue ;
138 
139  //fill MC histograms
140  //The MC arrays in MuDST
141  TClonesArray *MuMcVertices = mMuDst->mcArray(0);
142  Int_t NoMuMcVertices = MuMcVertices->GetEntriesFast();
143  TClonesArray *MuMcTracks = mMuDst->mcArray(1);
144  Int_t NoMuMcTracks = MuMcTracks->GetEntriesFast();
145  LOG_INFO <<"# of MC tracks = "<< NoMuMcTracks <<" # of MC vertices = "<< NoMuMcVertices << endm;
146  if (! NoMuMcVertices || ! NoMuMcTracks) {
147  LOG_WARN << "Ev. " << i << " has no MC information ==> skip it" << endm;
148  continue;
149  }
150  Int_t nMc = 0;
151 
152  // Loop for MC tracks
153  for(Int_t itrk=0; itrk<NoMuMcTracks; itrk++){
154  StMuMcTrack *mcTrack = (StMuMcTrack *) MuMcTracks->UncheckedAt(itrk);
155  if (! mcTrack) continue;
156 
157  // Select only Triggered Mc Vertex, i.e. the MC track should originate from PV (IdVx=1)
158  Int_t IdVx = mcTrack->IdVx();
159  if (IdVx != 1) continue;
160 
161  const int Gid = mcTrack->GePid();
162 
163  nMc++; // # of MC tracks
164  if(Gid==11){//k+
165  hPtMc->Fill(mcTrack->Pxyz().perp());
166  hPhiMc->Fill(mcTrack->Pxyz().phi());
167  hEtaMc->Fill(mcTrack->Pxyz().pseudoRapidity());
168  if(fabs(mcTrack->Pxyz().pseudoRapidity())<0.5)hSelPtMc->Fill(mcTrack->Pxyz().perp());
169  }
170  else {
171  LOG_WARN << "Gid: "<<Gid<<" in Ev. "<<i<<endm;
172  }
173  }
174 
175  //fill Event QA histograms
176  TObjArray* tracks = muDstMaker->muDst()->primaryTracks() ;
177  TObjArrayIter GetTracks(tracks) ;
178  StMuTrack* ptrack ;
179  while ( ( ptrack = (StMuTrack*)GetTracks.Next() ) )
180  {
181  if (ptrack->idTruth() <= 0 || ptrack->idTruth() > NoMuMcTracks) {
182  //cout << "Illegal idTruth " << ptrack->idTruth() << " The track is ignored" << endl;
183  continue;
184  }
185  StMuMcTrack *mcTrack = (StMuMcTrack *) MuMcTracks->UncheckedAt(ptrack->idTruth()-1);
186  if (!mcTrack) {
187  LOG_WARN << "Inconsistency in mcArray(1), ignored" << endm;
188  continue;
189  }
190  if (mcTrack->Id() != ptrack->idTruth()) {
191  LOG_WARN << "Mismatched idTruth " << ptrack->idTruth() << " and mcTrack Id " << mcTrack->Id()
192  << " this track is ignored" << endm;
193  }
194  Int_t idMcVx = mcTrack->IdVx();
195  while (idMcVx != 1) {
196  StMuMcVertex *mcVertex = (StMuMcVertex *) MuMcVertices->UncheckedAt(idMcVx-1);
197  Int_t idMcTrack = mcVertex->IdParTrk();
198  if (! idMcTrack) break;
199  StMuMcTrack *mcTrackP = (StMuMcTrack *) MuMcTracks->UncheckedAt(idMcTrack-1);
200  idMcVx = mcTrackP->IdVx();
201  if (! idMcVx) break;
202  }
203  if (idMcVx != 1) continue; //this MC track is not eventually originated from PV
204 
205  if(mcTrack->GePid() != 11) continue;
206  if(mcTrack->IdVx() != 1) {
207  LOG_WARN<<"mc track may not directly originate from PV!"<<endm;
208  }
209  if(ptrack->qaTruth()<50.) continue;
210 
211  if(ptrack->nHits()<=15)continue;
212  if(ptrack->flag()<=0)continue;
213  if(abs(ptrack->charge())!=1) continue;
214 
215  StThreeVectorF p = ptrack->p();
216  hPhi->Fill(p.phi());
217  hPt->Fill(p.perp());
218  hEta->Fill(p.pseudoRapidity());
219  if(fabs(p.pseudoRapidity())<0.5)hSelPt->Fill(p.perp());
220  //end of the filling
221  }
222  }
223  hEffPt->Divide(hSelPt,hSelPtMc,1,1,"B");
224 
225  if (nEvents > 1) chain -> Finish() ;
226 
227  if(tags_output!=NULL) tags_output -> Write() ;
228  if(tags_output!=NULL) tags_output -> Close() ;
229  //flush(tags_output);
230  delete tags_output;
231 
232  // Cleanup
233  delete chain ;
234 }
static StMuPrimaryVertex * primaryVertex()
return pointer to current primary vertex
Definition: StMuDst.h:322
StThreeVectorF primaryVertexPosition(int vtx_id=-1) const
The StMuDst is supposed to be structured in &#39;physical events&#39;. Therefore there is only 1 primary vert...
Definition: StMuEvent.cxx:221
StMuDst * muDst()
Definition: StMuDstMaker.h:425
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StChain.cxx:77
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Definition: TDataSet.cxx:893
virtual Int_t Finish()
Definition: StChain.cxx:85
short flag() const
Returns flag, (see StEvent manual for type information)
Definition: StMuTrack.h:230
Short_t charge() const
Returns charge.
Definition: StMuTrack.h:255
const StThreeVectorF & p() const
Returns 3-momentum at dca to primary vertex.
Definition: StMuTrack.h:259
static TObjArray * primaryTracks()
returns pointer to a list of tracks belonging to the selected primary vertex
Definition: StMuDst.h:301
virtual Int_t Make()
Definition: StChain.cxx:110
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
Definition: Stypes.h:40
UShort_t nHits() const
Bingchu.
Definition: StMuTrack.h:237
static Int_t currentVertexIndex()
Get the index number of the current primary vertex.
Definition: StMuDst.h:260
static void setVertexIndex(Int_t vtx_id)
Set the index number of the current primary vertex (used by both primaryTracks() functions and for St...
Definition: StMuDst.cxx:273