StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
checkStRefMultCorr.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 checkStRefMultCorr(const char *inFileName = "/star/u/gnigmat/soft/u/prithwish/data/st_physics_adc_16064082_raw_5000007.MuDst.root",
12  const char *oFileName = "oFileForPrithwish.root") {
13 
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("BTofPidTraits",1);
31  std::cout << "Status has been set" << std::endl;
32 
33  std::cout << "Now I know what to read, Master!" << std::endl;
34 
35  if( !picoReader->chain() ) {
36  std::cout << "No chain has been found." << std::endl;
37  std::cout << "Terminating..." << std::endl;
38  exit(0);
39  }
40  Long64_t eventsInTree = picoReader->tree()->GetEntries();
41  std::cout << "eventsInTree: " << eventsInTree << std::endl;
42  Long64_t events2read = picoReader->chain()->GetEntries();
43 
44  std::cout << "Number of events to read: " << events2read << std::endl;
45 
46  // Histogramming
47  // Event
48  TH1F *hRefMult = new TH1F("hRefMult", "Reference multiplicity;refMult", 500, -0.5, 499.5);
49  TH2F *hTofMatchVsRefMultBeforeCut = new TH2F("hTofMatchVsRefMultBeforeCut", ";bTofMatched;refMult",
50  500, -0.5, 499.5, 500, -0.5, 499.5);
51  TH2F *hTofMatchVsRefMultAfterCut = new TH2F("hTofMatchVsRefMultAfterCut", ";bTofMatched;refMult",
52  500, -0.5, 499.5, 500, -0.5, 499.5);
53  TH2F *hWeightVsRefMultCorr = new TH2F("hWeightVsRefMultCorr",";refMult;weight",
54  500, -0.5, 499.5, 125, 0.5, 3.);
55  TH1F *hRefMultCorr = new TH1F("hRefMultCorr", "Corrected reference multiplicity;refMult", 500, -0.5, 499.5);
56  TH1F *hCent16 = new TH1F("hCent16","Centrality bins;Centrality bin", 16, -0.5, 15.5);
57  TH2F *hVtxXvsY = new TH2F("hVtxXvsY", "hVtxXvsY", 200,-10.,10.,200,-10.,10.);
58  TH1F *hVtxZ = new TH1F("hVtxZ","hVtxZ", 210, -210., 210.);
59 
60 
61  // Initialize StRefMultCorr
62  StRefMultCorr *mRefMultCorrUtilFxt = new StRefMultCorr("fxtmult");
63  mRefMultCorrUtilFxt->setVerbose(kFALSE);
64 
65  Int_t counter = 0;
66  Int_t loopSize = 1000;
67  Bool_t verbose = kTRUE;
68 
69  // Loop over events
70  for(Long64_t iEvent=0; iEvent<events2read; iEvent++) {
71 
72  counter++;
73  if ( counter >= loopSize ) {
74  std::cout << "Working on event #[" << (iEvent+1) << "/" << events2read << "]" << std::endl;
75  counter = 0;
76  }
77 
78 
79  Bool_t readEvent = picoReader->readPicoEvent(iEvent);
80  if (!readEvent) {
81  std::cout << "No input was provided" << std::endl;
82  break;
83  }
84 
85  // Retrieve picoDst
86  StPicoDst *dst = picoReader->picoDst();
87 
88  // Retrieve event information
89  StPicoEvent *event = dst->event();
90  if( !event ) {
91  std::cout << "No event was found" << std::endl;
92  break;
93  }
94 
95  Int_t runId = event->runId();
96  mRefMultCorrUtilFxt->init(runId);
97 
98  if (verbose) {
99  std::cout << "Checking bad run";
100  }
101 
102  if ( mRefMultCorrUtilFxt->isBadRun( runId ) ) {
103  if (verbose) {
104  std::cout << "\t[failed]" << std::endl;
105  }
106  continue;
107  }
108  if (verbose) {
109  std::cout << "\t[passed]" << std::endl;
110  }
111 
112  if (verbose) {
113  std::cout << "Checking MB triggers";
114  }
115 
116  // Check trigger (3.2 GeV)
117  if ( !event->isTrigger(680001) ) {
118  if (verbose) {
119  std::cout << "\t[failed]" << std::endl;
120  }
121  continue;
122  }
123  if (verbose) {
124  std::cout << "\t[passed]" << std::endl;
125  }
126 
127  // NOTE: Lets utilize refMult variable instead of fxtMult but will call the proper one from picoEvent
128  Int_t refMult = event->fxtMult();
129  TVector3 pVtx = event->primaryVertex();
130  Int_t nBTofMatched = event->nBTOFMatch();
131  hTofMatchVsRefMultBeforeCut->Fill( nBTofMatched, refMult );
132 
133  // IMPORTANT: vertex position is needed for Au+Au 19.6 GeV 2019
134  if (mRefMultCorrUtilFxt->isPileUpEvent( refMult, nBTofMatched, pVtx.Z() ) ) continue;
135 
136  mRefMultCorrUtilFxt->initEvent(refMult, pVtx.Z(), event->ZDCx());
137 
138  // In case centrality calculation is failed for the given event it will
139  if (mRefMultCorrUtilFxt->getCentralityBin16() < 0 ||
140  mRefMultCorrUtilFxt->getCentralityBin9() < 0) {
141  if (verbose) {
142  std::cout << "\tBad centrality < 0" << std::endl;
143  }
144  continue;
145  }
146 
147  Int_t cent9 = mRefMultCorrUtilFxt->getCentralityBin9(); // 0: 70-80%, 1: 60-70%, ..., 6: 10-20%, 7: 5-10%, 8: 0-5%
148  Int_t cent16 = mRefMultCorrUtilFxt->getCentralityBin16(); // 0: 75-80%, 1: 70-75%, ..., 8: 0-5%
149  Double_t refMultCorr = mRefMultCorrUtilFxt->getRefMultCorr(); // Retrieve corrected refMult value
150  Double_t weight = mRefMultCorrUtilFxt->getWeight(); // Retrieve weight
151 
152  if (verbose) {
153  std::cout << "refMult: " << refMult << " refMultCorr: " << refMultCorr
154  << " cent16: " << cent16 << " cent9: " << cent9
155  << " Total weight: " << weight << " trigger efficiency: "
156  << mRefMultCorrUtilFxt->triggerWeight()
157  << " z: " << pVtx.Z()
158  << " shape weight: " << mRefMultCorrUtilFxt->getShapeWeight_SubVz2Center()
159  << std::endl;
160  }
161 
162  hRefMult->Fill( refMult );
163  hRefMultCorr->Fill( refMultCorr );
164  hCent16->Fill( cent16 );
165  hVtxXvsY->Fill( pVtx.X(), pVtx.Y() );
166  hVtxZ->Fill( pVtx.Z() );
167  hTofMatchVsRefMultAfterCut->Fill( nBTofMatched, refMult );
168  hWeightVsRefMultCorr->Fill(refMultCorr, weight);
169 
170  } //for(Long64_t iEvent=0; iEvent<events2read; iEvent++)
171  picoReader->Finish();
172 
173  TFile *oFile = new TFile(oFileName, "recreate");
174  hRefMult->Write();
175  hRefMultCorr->Write();
176  hCent16->Write();
177  hVtxXvsY->Write();
178  hVtxZ->Write();
179  hTofMatchVsRefMultBeforeCut->Write();
180  hTofMatchVsRefMultAfterCut->Write();
181  hWeightVsRefMultCorr->Write();
182  oFile->Write();
183  oFile->Close();
184 
185  std::cout << "Analysis was finished" << std::endl;
186 }
Bool_t readPicoEvent(Long64_t iEvent)
Read next event in the chain.
Allows to read picoDst file(s)
Int_t runId() const
Return run ID.
Definition: StPicoEvent.h:41
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) ...
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.
StPicoDst * picoDst()
Return a pointer to picoDst (return NULL if no dst is found)
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.
Bool_t isPileUpEvent(Double_t refmult, Double_t ntofmatch, Double_t vz=0.) const
Check if pile-up event.
Definition: StRefMultCorr.h:74
Double_t triggerWeight() const
Trigger efficiency: fit of the Glauber/Data.
Main class that keeps TClonesArrays with main classes.
Definition: StPicoDst.h:40
Bool_t isBadRun(const Int_t RunId)
Check if run is bad.
void Init()
Calls openRead()
TTree * tree()
Return pointer to the current TTree.
Stores global information about the event.
Definition: StPicoEvent.h:24
void Finish()
Close files and finilize.
void setVerbose(const Bool_t &verbose)
Print debug information.
void init(const Int_t RunId)
Initialization of centrality bins etc.