CbmRoot
CbmImpactParameterModel.cxx
Go to the documentation of this file.
1 /*
2  *====================================================================
3  *
4  * CBM impact parameter extraction
5  *
6  * Authors: V.Vovchenko
7  *
8  * e-mail :
9  *
10  *====================================================================
11  *
12  * Extraction of event impact parameter from total participant electric charge, based on Glauber model predictions
13  *
14  *====================================================================
15  */
16 
18 #include "CbmL1Def.h"
19 
20 
21 //#include "KFParticleFinder.h"
22 //#include "KFParticleSIMD.h"
23 #include "CbmKFTrack.h"
24 #include "CbmKFVertex.h"
25 #include "CbmStsTrack.h"
26 
27 #include "TClonesArray.h"
28 #include "TDirectory.h"
29 #include "TFile.h"
30 #include "TMath.h"
31 
32 #include "TCanvas.h"
33 #include "TGraphErrors.h"
34 #include "TH1F.h"
35 #include "TH2F.h"
36 #include "TSpline.h"
37 
38 #include "L1Field.h"
39 
40 #include "CbmVertex.h"
41 
42 #include "TStopwatch.h"
43 #include <cmath>
44 #include <cstdio>
45 #include <iostream>
46 #include <map>
47 
48 //#include "CbmTrackMatch.h"
49 #include "CbmMCTrack.h"
50 #include "CbmTrackMatchNew.h"
51 //for particle ID from global track
52 #include "CbmGlobalTrack.h"
53 #include "CbmRichRing.h"
54 #include "CbmTofHit.h"
55 #include "CbmTrdTrack.h"
56 #include "TDatabasePDG.h"
57 //for RICH identification
58 #include "TSystem.h"
59 // #include "CbmRichElectronIdAnn.h"
60 
61 #include "CbmL1PFFitter.h"
62 
63 #include "FairMCEventHeader.h"
64 #include "KFPTrackVector.h"
65 #include "KFParticleTopoReconstructor.h"
66 
67 #include "ImpactParameterModel.h"
68 
69 
70 using std::ios;
71 using std::vector;
72 
73 using namespace std;
74 
76 
78  Int_t recoLevel,
79  Int_t
80  /*iVerbose*/,
81  TString Mode,
82  KFParticleTopoReconstructor* tr,
83  Float_t ekin_,
84  TString InputTable)
85  : CbmModelBase(tr)
86  ,
87  //ekin(ekin_),
88  //fusePID(usePID),
89  ekin(ekin_)
90  , p0cm(5.)
91  , ycm(2.)
92  , fUpdate(true)
93  , fusePID(true)
94  , fRecoLevel(recoLevel)
95  , fTrackNumber(0)
96  , fEventStats(1)
97  , events(0)
98  , fModeName(Mode)
99  , outfileName("")
100  ,
101  //fTrackNumber(trackNumber),
102  //flistStsTracks(0),
103  //flistStsTracksMatch(0),
104  //fPrimVtx(0),
105  // fUseWidth(useWidth),
106  // fUseStatistics(useStatistics),
107  // fRadius(rad),
108  //flsitGlobalTracks(0),
109  //flistTofHits(0),
110  histodir(0)
111  , flistMCTracks(0)
112  , MCEvent(0)
113  , Indexb(0)
114  , IndexNwp(0)
115  , IndexNpe(0)
116  , IndexbMC(0)
117  , Indexbpe(0)
118  , IndexbpeMC(0)
119  , Indexbdiff(0)
120  , Indexbres(0)
121  , Indexbpull(0)
122  , totalEvents(0)
123  , PPDG(2212)
124  , kProtonMass(0.938271998)
125  ,
126  // fCor(0.62)
127  fCor(0.40)
128  , model(NULL)
129 // flistRichRings(0),
130 // flistTrdTracks(0),
131 
132 {
133  // fModeName = Mode;
134 
135  // events = 0;
136 
137  // PPDG = 2212;
138  // kProtonMass = 0.938271998;
139 
140  //PDGtoIndex.clear();
141 
142  TDirectory* currentDir = gDirectory;
143 
144  gDirectory->cd("Models");
145 
146  histodir = gDirectory;
147 
148  gDirectory->mkdir("ImpactParameterModel");
149  gDirectory->cd("ImpactParameterModel");
150  gDirectory->mkdir(fModeName);
151  gDirectory->cd(fModeName);
152  //gDirectory->mkdir("All tracks");
153  //gDirectory->cd("All tracks");
154  TString tname = "PerEvent";
155  //if (fEventStats!=1) tname = TString("Each ") + TString::Itoa(fEventStats, 10) + TString(" events");
156  gDirectory->mkdir(tname);
157  gDirectory->cd(tname);
158  int CurrentIndex = 0;
159 
160  Indexb = CurrentIndex;
161  histo1D[CurrentIndex] =
162  new TH1F("Impact parameter", "Event-by-event b", 30, 0., 15.);
163  histo1D[CurrentIndex]->SetXTitle("b (fm)");
164  histo1D[CurrentIndex]->SetYTitle("Entries");
165  CurrentIndex++;
166 
167  IndexbMC = CurrentIndex;
168  histo1D[CurrentIndex] =
169  new TH1F("Impact parameter MC", "Event-by-event b MC", 30, 0., 15.);
170  histo1D[CurrentIndex]->SetXTitle("b (fm)");
171  histo1D[CurrentIndex]->SetYTitle("Entries");
172  CurrentIndex++;
173 
174 
175  IndexNwp = CurrentIndex;
176  histo1D[CurrentIndex] = new TH1F("Total electric charge",
177  "Event-by-event electric charge",
178  201,
179  -0.5,
180  200.5);
181  histo1D[CurrentIndex]->SetXTitle("Q");
182  histo1D[CurrentIndex]->SetYTitle("Entries");
183  CurrentIndex++;
184 
185  IndexNpe = CurrentIndex;
186  histo1D[CurrentIndex] = new TH1F(
187  "Electric charge", "Event-by-event electric charge", 1000, 0.5, 1000.5);
188  histo1D[CurrentIndex]->SetXTitle("Event");
189  histo1D[CurrentIndex]->SetYTitle("Np");
190  CurrentIndex++;
191 
192  Indexbpe = CurrentIndex;
193  histo1D[CurrentIndex] = new TH1F("Event-by-event impact parameter reco",
194  "Event-by-event impact parameter reco",
195  1000,
196  0.5,
197  1000.5);
198  histo1D[CurrentIndex]->SetXTitle("Event");
199  histo1D[CurrentIndex]->SetYTitle("b (fm)");
200  CurrentIndex++;
201 
202  IndexbpeMC = CurrentIndex;
203  histo1D[CurrentIndex] = new TH1F("Event-by-event impact parameter MC",
204  "Event-by-event impact parameter MC",
205  1000,
206  0.5,
207  1000.5);
208  histo1D[CurrentIndex]->SetXTitle("Event");
209  histo1D[CurrentIndex]->SetYTitle("b (fm)");
210  CurrentIndex++;
211 
212  Indexbdiff = CurrentIndex;
213  histo1D[CurrentIndex] =
214  new TH1F("Impact parameter diff", "Event-by-event b diff", 150, -10., 10.);
215  histo1D[CurrentIndex]->SetXTitle("b-b_{MC} (fm)");
216  histo1D[CurrentIndex]->SetYTitle("Entries");
217  CurrentIndex++;
218 
219  Indexbres = CurrentIndex;
220  histo1D[CurrentIndex] =
221  new TH1F("Impact parameter res", "Event-by-event b res", 30, -1., 1.);
222  histo1D[CurrentIndex]->SetXTitle("b_{res}");
223  histo1D[CurrentIndex]->SetYTitle("Entries");
224  CurrentIndex++;
225 
226  Indexbpull = CurrentIndex;
227  histo1D[CurrentIndex] =
228  new TH1F("Impact parameter pull", "Event-by-event b pull", 75, -5., 5.);
229  histo1D[CurrentIndex]->SetXTitle("b_{pull}");
230  histo1D[CurrentIndex]->SetYTitle("Entries");
231  CurrentIndex++;
232  gDirectory->cd("..");
233  gDirectory->cd("..");
234  gDirectory->cd("..");
235 
236  gDirectory = currentDir;
237 
238  double pbeam = sqrt((kProtonMass + ekin) * (kProtonMass + ekin)
240  double betacm = pbeam / (2. * kProtonMass + ekin);
241  ycm = 0.5 * log((1. + betacm) / (1. - betacm));
242 
243  double ssqrt = sqrt(2. * kProtonMass * (ekin + 2. * kProtonMass));
244  p0cm = sqrt(0.25 * ssqrt * ssqrt - kProtonMass * kProtonMass);
245 
246  std::cout << "ekin = " << ekin << "\n";
247  std::cout << "ycm = " << ycm << "\n";
248 
249  events = 0;
250 
251  TString work = getenv("VMCWORKDIR");
252  TString dir = work + "/KF/KFModelParameters/ImpactParameterModel/";
253 
254  model = new ImpactParameterModel(std::string((dir + InputTable).Data()));
255 
256  totalEvents = 0;
257 }
258 
260  if (model != NULL) delete model;
261 }
262 
263 void CbmImpactParameterModel::ReInit(FairRootManager* fManger) {
264  flistMCTracks = dynamic_cast<TClonesArray*>(fManger->GetObject("MCTrack"));
265  MCEvent =
266  dynamic_cast<FairMCEventHeader*>(fManger->GetObject("MCEventHeader."));
267 }
268 
270  //ReInit();
271 }
272 
274  if (fRecoLevel == -1 && !flistMCTracks) return;
275  if (fRecoLevel != -1 && !fTopoReconstructor) return;
276 
278 
279 
280  totalEvents++;
281  events++;
282  if (fRecoLevel == -1) {
283  std::cout << charge << " " << model->getB(charge) << "\n";
284  histo1D[Indexb]->Fill(model->getB(charge));
285  if (MCEvent) histo1D[IndexbMC]->Fill(MCEvent->GetB());
286  histo1D[IndexNwp]->Fill(charge);
287  histo1D[IndexNpe]->Fill(totalEvents, charge);
288  histo1D[Indexbpe]->Fill(totalEvents, model->getB(charge));
289  histo1D[Indexbpe]->SetBinError(totalEvents, model->getBerror(charge));
290  if (MCEvent) {
291  histo1D[IndexbpeMC]->Fill(totalEvents, MCEvent->GetB());
292  histo1D[IndexbpeMC]->SetBinError(totalEvents, 1.e-4);
293  }
294  if (MCEvent) {
295  histo1D[Indexbdiff]->Fill(model->getB(charge) - MCEvent->GetB());
296  histo1D[Indexbres]->Fill((model->getB(charge) - MCEvent->GetB())
297  / MCEvent->GetB());
298  histo1D[Indexbpull]->Fill((model->getB(charge) - MCEvent->GetB())
299  / model->getBerror(charge));
300  }
301  } else {
302  std::cout << charge / fCor << " " << model->getB(charge / fCor) << "\n";
303  histo1D[Indexb]->Fill(model->getB(charge / fCor));
304  if (MCEvent) histo1D[IndexbMC]->Fill(MCEvent->GetB());
305  histo1D[IndexNwp]->Fill(charge / fCor);
306  histo1D[IndexNpe]->Fill(totalEvents, charge / fCor);
307  histo1D[Indexbpe]->Fill(totalEvents, model->getB(charge / fCor));
308  histo1D[Indexbpe]->SetBinError(totalEvents,
309  model->getBerror(charge / fCor));
310  if (MCEvent) {
311  histo1D[IndexbpeMC]->Fill(totalEvents, MCEvent->GetB());
312  histo1D[IndexbpeMC]->SetBinError(totalEvents, 1.e-4);
313  }
314  if (MCEvent) {
315  histo1D[Indexbdiff]->Fill(model->getB(charge / fCor) - MCEvent->GetB());
316  histo1D[Indexbres]->Fill((model->getB(charge / fCor) - MCEvent->GetB())
317  / MCEvent->GetB());
318  histo1D[Indexbpull]->Fill((model->getB(charge / fCor) - MCEvent->GetB())
319  / model->getBerror(charge / fCor));
320  }
321  }
322 }
323 
325 
327  int ret = 0;
328  if (RecoLevel == -1) {
329  vector<CbmMCTrack> vRTracksMC;
330  int nTracksMC = flistMCTracks->GetEntries();
331  std::cout << "MC tracks: " << nTracksMC << "\n";
332  vRTracksMC.resize(nTracksMC);
333  for (int iTr = 0; iTr < nTracksMC; iTr++)
334  // vRTracksMC[iTr] = *( (CbmMCTrack*) flistMCTracks->At(iTr));
335  vRTracksMC[iTr] = *(static_cast<CbmMCTrack*>(flistMCTracks->At(iTr)));
336 
337  for (int iTr = 0; iTr < nTracksMC; iTr++) {
338  if (vRTracksMC[iTr].GetMotherId() == -1) {
339  double pt = vRTracksMC[iTr].GetPt();
340  if (pt > 1.e-4) {
341  ret += vRTracksMC[iTr].GetCharge() / 3;
342  } else {
343  }
344  }
345  }
346  } else {
347  for (int itype = 2; itype <= 3; ++itype) {
348  const KFPTrackVector& tr = fTopoReconstructor->GetTracks()[itype];
349  const kfvector_int& pdgs = tr.PDG();
350  for (unsigned int ind = 0; ind < pdgs.size(); ++ind) {
351  int iPDG = pdgs[ind];
352  if ((iPDG > 0 && iPDG < 10000) || (iPDG < 0 && iPDG > -10000)) {
353  ret += TDatabasePDG::Instance()->GetParticle(iPDG)->Charge() / 3;
354  }
355  }
356  }
357  }
358  return ret;
359 }
CbmImpactParameterModel::model
ImpactParameterModel * model
Definition: CbmImpactParameterModel.h:103
CbmModelBase::fTopoReconstructor
KFParticleTopoReconstructor * fTopoReconstructor
Definition: CbmModelBase.h:42
CbmVertex.h
CbmImpactParameterModel::Finish
virtual void Finish()
Definition: CbmImpactParameterModel.cxx:324
ImpactParameterModel.h
CbmImpactParameterModel::Exec
virtual void Exec()
Definition: CbmImpactParameterModel.cxx:273
ImpactParameterModel::getB
double getB(int Nchg)
Definition: ImpactParameterModel.h:20
L1Field.h
sqrt
friend F32vec4 sqrt(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:41
CbmImpactParameterModel::Indexb
int Indexb
Definition: CbmImpactParameterModel.h:88
CbmGlobalTrack.h
CbmRichRing.h
CbmImpactParameterModel::ReInit
virtual void ReInit(FairRootManager *fManger)
Definition: CbmImpactParameterModel.cxx:263
ImpactParameterModel
Definition: ImpactParameterModel.h:11
CbmImpactParameterModel::Init
virtual void Init()
Definition: CbmImpactParameterModel.cxx:269
CbmImpactParameterModel::~CbmImpactParameterModel
~CbmImpactParameterModel()
Definition: CbmImpactParameterModel.cxx:259
CbmL1Def.h
CbmStsTrack.h
Data class for STS tracks.
CbmImpactParameterModel::IndexNpe
int IndexNpe
Definition: CbmImpactParameterModel.h:88
CbmImpactParameterModel::MCEvent
FairMCEventHeader * MCEvent
Definition: CbmImpactParameterModel.h:84
CbmImpactParameterModel::totalEvents
int totalEvents
Definition: CbmImpactParameterModel.h:93
log
friend F32vec4 log(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:135
CbmTrackMatchNew.h
CbmImpactParameterModel::CbmImpactParameterModel
CbmImpactParameterModel(Int_t recoLevel=-1, Int_t iVerbose=1, TString Mode="MC", KFParticleTopoReconstructor *tr=0, Float_t ekin_=25., TString InputTable="Npvsb-AuAu.dat")
ClassImp
ClassImp(CbmImpactParameterModel) CbmImpactParameterModel
Definition: CbmImpactParameterModel.cxx:75
CbmL1PFFitter.h
CbmImpactParameterModel::Indexbpe
int Indexbpe
Definition: CbmImpactParameterModel.h:88
CbmImpactParameterModel::histo1D
TH1F * histo1D[nHisto1D]
Definition: CbmImpactParameterModel.h:91
CbmKFTrack.h
CbmModelBase
Definition: CbmModelBase.h:25
ImpactParameterModel::getBerror
double getBerror(int Nchg)
Definition: ImpactParameterModel.h:29
CbmImpactParameterModel.h
CbmImpactParameterModel::events
Int_t events
Definition: CbmImpactParameterModel.h:74
CbmImpactParameterModel
Definition: CbmImpactParameterModel.h:39
CbmMCTrack.h
CbmImpactParameterModel::flistMCTracks
TClonesArray * flistMCTracks
Definition: CbmImpactParameterModel.h:81
CbmImpactParameterModel::Indexbres
int Indexbres
Definition: CbmImpactParameterModel.h:89
CbmMCTrack
Definition: CbmMCTrack.h:34
CbmImpactParameterModel::fRecoLevel
Int_t fRecoLevel
Definition: CbmImpactParameterModel.h:71
CbmImpactParameterModel::CalculateTotalChargeInEvent
int CalculateTotalChargeInEvent(int RecoLevel)
Definition: CbmImpactParameterModel.cxx:326
CbmTrdTrack.h
CbmImpactParameterModel::IndexbMC
int IndexbMC
Definition: CbmImpactParameterModel.h:88
CbmImpactParameterModel::Indexbdiff
int Indexbdiff
Definition: CbmImpactParameterModel.h:88
kProtonMass
const Double_t kProtonMass
Definition: CbmPhsdGenerator.cxx:31
CbmImpactParameterModel::IndexNwp
int IndexNwp
Definition: CbmImpactParameterModel.h:88
CbmKFVertex.h
CbmImpactParameterModel::Indexbpull
int Indexbpull
Definition: CbmImpactParameterModel.h:89
CbmImpactParameterModel::fCor
double fCor
Definition: CbmImpactParameterModel.h:97
CbmImpactParameterModel::IndexbpeMC
int IndexbpeMC
Definition: CbmImpactParameterModel.h:88