StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
checkStRefMultCorrOO.C
1 // ROOT headers
2 #include "TH1.h"
3 #include "TChain.h"
4 #include "TSystem.h"
5 #include "TFile.h"
6 
7 // C++ headers
8 #include <iostream>
9 
10 // Macro name
11 void checkStRefMultCorrOO(const char *inFileName,
12  const char *oFileName = "oTest.root") {
13  const bool bUseRefMult6 = false; // use refMult6 for centrality definition, otherwise use totnMIP
14  gROOT->LoadMacro("$STAR/StRoot/StMuDSTMaker/COMMON/macros/loadSharedLibraries.C");
15  loadSharedLibraries();
16  gSystem->Load("StPicoEvent");
17  gSystem->Load("StRefMultCorr");
18 
19  std::cout << "Hi! Lets do some physics, Master!" << std::endl;
20 
21  StPicoDstReader* picoReader = new StPicoDstReader(inFileName);
22  picoReader->Init();
23 
24  //Long64_t events2read = picoReader->chain()->GetEntries();
25 
26  // This is a way if you want to spead up IO
27  std::cout << "Explicit read status for some branches" << std::endl;
28  picoReader->SetStatus("*",0);
29  picoReader->SetStatus("Event",1);
30  picoReader->SetStatus("Track*",1);
31  picoReader->SetStatus("BTofPidTraits",1);
32  picoReader->SetStatus("EpdHit*",1);
33  std::cout << "Status has been set" << std::endl;
34 
35  std::cout << "Now I know what to read, Master!" << std::endl;
36 
37  if( !picoReader->chain() ) {
38  std::cout << "No chain has been found." << std::endl;
39  std::cout << "Terminating..." << std::endl;
40  exit(0);
41  }
42  Long64_t eventsInTree = picoReader->tree()->GetEntries();
43  std::cout << "eventsInTree: " << eventsInTree << std::endl;
44  Long64_t events2read = picoReader->chain()->GetEntries();
45 
46  std::cout << "Number of events to read: " << events2read << std::endl;
47 
48  // Histogramming
49  // Event
50  TH1F *hRefMult = new TH1F(Form("h%s",(bUseRefMult6)?"RefMult6":"TotnMIP"), Form("Reference multiplicity;%s",(bUseRefMult6)?"refMult6":"totnMIP"), 1000, -0.5, 999.5);
51  TH2F *hTofMatchVsRefMult6BeforeCut = new TH2F("hTofMatchVsRefMult6BeforeCut", ";bTofMatched;refMult6",
52  500, -0.5, 499.5, 500, -0.5, 499.5);
53  TH2F *hTofMatchVsRefMult6AfterCut = new TH2F("hTofMatchVsRefMult6AfterCut", ";bTofMatched;refMult6",
54  500, -0.5, 499.5, 500, -0.5, 499.5);
55  TH2F *hTofMatchVsTotnMIPBeforeCut = new TH2F("hTofMatchVsTotnMIPBeforeCut", ";bTofMatched;totnMIP",
56  500, -0.5, 499.5, 1000, -0.5, 999.5);
57  TH2F *hTofMatchVsTotnMIPAfterCut = new TH2F("hTofMatchVsTotnMIPAfterCut", ";bTofMatched;totnMIP",
58  500, -0.5, 499.5, 1000, -0.5, 999.5);
59  TH2F *hWeightVsRefMultCorr = new TH2F(Form("hWeightVs%sCorr",(bUseRefMult6)?"RefMult6":"TotnMIP"),Form(";%s;weight",(bUseRefMult6)?"refMult6":"totnMIP"),
60  1000, -0.5, 999.5, 125, 0.5, 3.);
61  TH1F *hRefMultCorr = new TH1F(Form("h%sCorr",(bUseRefMult6)?"RefMult6":"TotnMIP"), Form("Corrected reference multiplicity;%s",(bUseRefMult6)?"refMult6":"totnMIP"), 1000, -0.5, 999.5);
62  TH1F *hCent16 = new TH1F("hCent16","Centrality bins;Centrality bin", 16, -0.5, 15.5);
63  TH2F *hVtxXvsY = new TH2F("hVtxXvsY", "hVtxXvsY", 200,-10.,10.,200,-10.,10.);
64  TH1F *hVtxZ = new TH1F("hVtxZ","hVtxZ", 210, -210., 210.);
65 
66 
67  // Initialize StRefMultCorr
68  StRefMultCorr *mRefMultCorrUtil = NULL;
69  if (bUseRefMult6) mRefMultCorrUtil = new StRefMultCorr("refmult6"); // refmult6-based centrality
70  else mRefMultCorrUtil = new StRefMultCorr("totnmip"); // totnMIP-based centrality
71  mRefMultCorrUtil->setVerbose(kFALSE);
72 
73  Int_t counter = 0;
74  Int_t loopSize = 1000;
75  Bool_t verbose = kTRUE;
76 
77  // Loop over events
78  for(Long64_t iEvent=0; iEvent<events2read; iEvent++) {
79 
80  counter++;
81  if ( counter >= loopSize ) {
82  std::cout << "Working on event #[" << (iEvent+1) << "/" << events2read << "]" << std::endl;
83  counter = 0;
84  }
85 
86 
87  Bool_t readEvent = picoReader->readPicoEvent(iEvent);
88  if (!readEvent) {
89  std::cout << "No input was provided" << std::endl;
90  break;
91  }
92 
93  // Retrieve picoDst
94  StPicoDst *dst = picoReader->picoDst();
95 
96  // Retrieve event information
97  StPicoEvent *event = dst->event();
98  if( !event ) {
99  std::cout << "No event was found" << std::endl;
100  break;
101  }
102 
103  // Event vertex selection
104  TVector3 pVtx = event->primaryVertex();
105  if (fabs(pVtx.Z()) > 30.) continue;
106  if (sqrt(pow(pVtx.X(),2.)+pow(pVtx.Y(),2.)) > 2.) continue;
107  Int_t runId = event->runId();
108  mRefMultCorrUtil->init(runId);
109 
110  if (verbose) {
111  std::cout << "Checking bad run";
112  }
113 
114  if ( mRefMultCorrUtil->isBadRun( runId ) ) {
115  if (verbose) {
116  std::cout << "\t[failed]" << std::endl;
117  }
118  continue;
119  }
120  if (verbose) {
121  std::cout << "\t[passed]" << std::endl;
122  }
123 
124  if (verbose) {
125  std::cout << "Checking MB triggers";
126  }
127 
128  // Check trigger (production_OO_200GeV_2021)
129  if ( !event->isTrigger(860001) && !event->isTrigger(860002)) {
130  if (verbose) {
131  std::cout << "\t[failed]" << std::endl;
132  }
133  continue;
134  }
135  if (verbose) {
136  std::cout << "\t[passed]" << std::endl;
137  }
138 
139  // NOTE: the refMult6 and totnMIP are defined as follows
140  Int_t refMult6 = 0;
141  for ( UInt_t iTrk=0; iTrk<dst->numberOfTracks(); iTrk++ ) {
142  StPicoTrack* track = dst->track( iTrk );
143  if ( !track ) continue;
144  if ( !track->isPrimary() ) continue;
145  if ( TMath::Abs( track->pMom().Eta() ) > 1.5 ) continue;
146  if ( track->pPt() >= 2.0 ) continue;
147  if ( track->pPt() <= 0.2 ) continue;
148  if ( track->gDCA(event->primaryVertex()).Mag() >= 3. ) continue;
149  if ( track->nHitsFit() <= 15 ) continue;
150  if ( (Double_t)track->nHitsFit() / track->nHitsPoss() <= 0.52 ) continue;
151  refMult6++;
152  } // for ( UInt_t iTrk=0; iTrk<dst->numberOfTracks(); iTrk++ )
153  Double_t totnMIP = 0.;
154  Int_t nEpdHits = dst->numberOfEpdHits();
155  for(Int_t iHit=0; iHit<nEpdHits; iHit++) {
156  StPicoEpdHit *epdHit = dst->epdHit(iHit);
157  if( !epdHit ) continue;
158  if (epdHit->nMIP() > 6.) totnMIP += 6.;
159  else if (epdHit->nMIP() < 0.3) continue;
160  else totnMIP += epdHit->nMIP();
161  } // for(Int_t iHit=0; iHit<nEpdHits; iHit++)
162 
163  Int_t nBTofMatched = event->nBTOFMatch();
164  hTofMatchVsRefMult6BeforeCut->Fill( nBTofMatched, refMult6 );
165  hTofMatchVsTotnMIPBeforeCut->Fill( nBTofMatched, totnMIP );
166 
167  // IMPORTANT: both refmult6 and totnMIP are needed for d+Au and O+O Run21 pileup rejection
168  if (mRefMultCorrUtil->isPileUpEvent( refMult6, nBTofMatched, pVtx.Z(), totnMIP ) ) continue;
169 
170  if (bUseRefMult6) mRefMultCorrUtil->initEvent(refMult6, pVtx.Z()); // refmult6-based centrality
171  else mRefMultCorrUtil->initEvent(totnMIP, pVtx.Z()); // totnMIP-based centrality
172 
173  // In case centrality calculation is failed for the given event it will
174  if (mRefMultCorrUtil->getCentralityBin16() < 0 ||
175  mRefMultCorrUtil->getCentralityBin9() < 0) {
176  if (verbose) {
177  std::cout << "\tBad centrality < 0" << std::endl;
178  }
179  continue;
180  }
181 
182  Int_t cent9 = mRefMultCorrUtil->getCentralityBin9(); // 0: 70-80%, 1: 60-70%, ..., 6: 10-20%, 7: 5-10%, 8: 0-5%
183  Int_t cent16 = mRefMultCorrUtil->getCentralityBin16(); // 0: 75-80%, 1: 70-75%, ..., 8: 0-5%
184  Double_t refMultCorr = mRefMultCorrUtil->getRefMultCorr(); // Retrieve corrected refmult value
185  Double_t weight = mRefMultCorrUtil->getWeight(); // Retrieve weight
186 
187  if (verbose) {
188  std::cout << "refMult: " << Form("%d",(bUseRefMult6) ? refMult6 : totnMIP) << " refMultCorr: " << refMultCorr
189  << " cent16: " << cent16 << " cent9: " << cent9
190  << " Total weight: " << weight << " trigger efficiency: "
191  << mRefMultCorrUtil->triggerWeight()
192  << " z: " << pVtx.Z()
193  << " shape weight: " << mRefMultCorrUtil->getShapeWeight_SubVz2Center()
194  << std::endl;
195  }
196 
197  hRefMult->Fill( (bUseRefMult6) ? refMult6 : totnMIP );
198  hRefMultCorr->Fill( refMultCorr );
199  hCent16->Fill( cent16 );
200  hVtxXvsY->Fill( pVtx.X(), pVtx.Y() );
201  hVtxZ->Fill( pVtx.Z() );
202  hTofMatchVsRefMult6AfterCut->Fill( nBTofMatched, refMult6 );
203  hTofMatchVsTotnMIPAfterCut->Fill( nBTofMatched, totnMIP );
204  hWeightVsRefMultCorr->Fill(refMultCorr, weight);
205 
206  } //for(Long64_t iEvent=0; iEvent<events2read; iEvent++)
207  picoReader->Finish();
208 
209  TFile *oFile = new TFile(oFileName, "recreate");
210  hRefMult->Write();
211  hRefMultCorr->Write();
212  hWeightVsRefMultCorr->Write();
213  hCent16->Write();
214  hVtxXvsY->Write();
215  hVtxZ->Write();
216  hTofMatchVsRefMult6BeforeCut->Write();
217  hTofMatchVsRefMult6AfterCut->Write();
218  hTofMatchVsTotnMIPBeforeCut->Write();
219  hTofMatchVsTotnMIPAfterCut->Write();
220  oFile->Write();
221  oFile->Close();
222 
223  std::cout << "Analysis was finished" << std::endl;
224 }
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)
Int_t getCentralityBin9() const
Get 9 centrality bins (10% increment except for 0-5 and 5-10)
Double_t getShapeWeight_SubVz2Center() const
Shape reweighting of refmult: ratio of refMult in each Vz bin to that in the center (|Vz|&lt;10cm) ...
Float_t pPt() const
Return transverse momentum (GeV/c) of the primary track.
Definition: StPicoTrack.h:72
Int_t getCentralityBin16() const
Get 16 centrality bins (5% increment, 0-5, 5-10, ..., 75-80)
TChain * chain()
Return pointer to the chain of .picoDst.root files.
Int_t nHitsPoss() const
Return number of hits possible.
Definition: StPicoTrack.h:110
StPicoDst * picoDst()
Return a pointer to picoDst (return NULL if no dst is found)
static StPicoEpdHit * epdHit(Int_t i)
Return pointer to i-th epd hit.
Definition: StPicoDst.h:79
Double_t getRefMultCorr() const
Get corrected multiplicity, correction as a function of primary z-vertex.
static StPicoEvent * event()
Return pointer to current StPicoEvent (class holding the event wise information)
Definition: StPicoDst.h:63
Double_t getWeight() const
Total weighting factor: incorporates shape and trigger efficiency weights.
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
Double_t triggerWeight() const
Trigger efficiency: fit of the Glauber/Data.
static UInt_t numberOfEpdHits()
Return number of EPD hits.
Definition: StPicoDst.h:118
static UInt_t numberOfTracks()
Return number of tracks.
Definition: StPicoDst.h:104
Main class that keeps TClonesArrays with main classes.
Definition: StPicoDst.h:40
TVector3 pMom() const
Return momentum (GeV/c) of the primary track. Return (0,0,0) if not primary track.
Definition: StPicoTrack.h:62
Bool_t isBadRun(const Int_t RunId)
Check if run is bad.
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 nHitsFit() const
Return number of hits fit.
Definition: StPicoTrack.h:106
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
Float_t nMIP() const
Definition: StPicoEpdHit.h:104
Bool_t isPileUpEvent(Double_t refmult, Double_t ntofmatch, Double_t vz=0., Double_t totnMIP=-999.) const
Check if pile-up event.
void Finish()
Close files and finilize.
void setVerbose(const Bool_t &verbose)
Print debug information.
TVector3 primaryVertex() const
Return primary vertex position.
Definition: StPicoEvent.h:52
void init(const Int_t RunId)
Initialization of centrality bins etc.