CbmRoot
CbmMultiscatteringModel.cxx
Go to the documentation of this file.
1 /*
2  *====================================================================
3  *
4  * CBM Multiscattering Model
5  *
6  * Authors: V.Vovchenko
7  *
8  * e-mail :
9  *
10  *====================================================================
11  *
12  * Multiscattering model parameter extraction, works well only for 4-pi MC data atm
13  *
14  *====================================================================
15  */
16 
18 #include "CbmL1Def.h"
19 
20 
21 #include "CbmKFTrack.h"
22 #include "CbmKFVertex.h"
23 #include "CbmStsTrack.h"
24 
25 #include "TClonesArray.h"
26 #include "TDirectory.h"
27 #include "TFile.h"
28 #include "TMath.h"
29 
30 #include "TCanvas.h"
31 #include "TGraphErrors.h"
32 #include "TH1F.h"
33 #include "TH2F.h"
34 #include "TSpline.h"
35 
36 #include "L1Field.h"
37 
38 #include "CbmVertex.h"
39 
40 #include "TStopwatch.h"
41 #include <cmath>
42 #include <cstdio>
43 #include <iostream>
44 #include <map>
45 
46 #include "CbmMCTrack.h"
47 #include "CbmTrackMatchNew.h"
48 //for particle ID from global track
49 #include "CbmGlobalTrack.h"
50 #include "CbmRichRing.h"
51 #include "CbmTofHit.h"
52 #include "CbmTrdTrack.h"
53 #include "TDatabasePDG.h"
54 //for RICH identification
55 #include "TSystem.h"
56 // #include "CbmRichElectronIdAnn.h"
57 
58 #include "CbmL1PFFitter.h"
59 
60 #include "KFPTrackVector.h"
61 #include "KFParticleTopoReconstructor.h"
62 
63 #include "MultiscatteringModel.h"
64 
65 
66 using std::ios;
67 using std::vector;
68 
69 using namespace std;
70 
72 
74  Int_t recoLevel,
75  Int_t /*iVerbose*/,
76  TString Mode,
77  Int_t EventStats,
78  KFParticleTopoReconstructor* tr,
79  Float_t ekin_)
80  : CbmModelBase(tr)
81  ,
82  //ekin(ekin_),
83  //fusePID(usePID),
84  ekin(ekin_)
85  , p0cm(5.)
86  , ycm(1.)
87  , fUpdate(true)
88  , fusePID(true)
89  , fRecoLevel(recoLevel)
90  , fTrackNumber(1)
91  , fEventStats(EventStats)
92  , events(0)
93  , fModeName(Mode)
94  , outfileName("")
95  , histodir(0)
96  , flistMCTracks(0)
97  , IndexSigt(0)
98  , IndexSigz(0)
99  , IndexQz(0)
100  , IndexPt(0)
101  , IndexPz(0)
102  , IndexY(0)
103  , IndexModelPt(0)
104  , IndexModelPz(0)
105  , IndexModelY(0)
106  , IndexYPt(0)
107  , IndexModelYPt(0)
108  , pullsigt(0)
109  , pullsigz(0)
110  , pullqz(0)
111  , sigts()
112  , sigzs()
113  , qzs()
114  ,
115  //fTrackNumber(trackNumber),
116  //flistStsTracks(0),
117  //flistStsTracksMatch(0),
118  //fPrimVtx(0),
119  //flsitGlobalTracks(0),
120  //flistTofHits(0),
121  PPDG(2212)
122  , paramsGlobal()
123  , paramsLocal()
124  , totalGlobal(0)
125  , totalLocal(0)
126  , kProtonMass(0.938271998)
127  , model(0)
128 // flistRichRings(0),
129 // flistTrdTracks(0),
130 
131 {
132  // fModeName = Mode;
133  // fEventStats = EventStats;
134 
135  //events = 0;
136  sigts.resize(0);
137  sigzs.resize(0);
138  qzs.resize(0);
139 
140  // PPDG = 2212;
141  // kProtonMass = 0.938271998;
142 
143  //PDGtoIndex.clear();
144 
145  TDirectory* currentDir = gDirectory;
146 
147  //std::cout << 0.128 << "\t" << mtTall->Eval(0.128) << endl;
148  //gDirectory->mkdir("KFModelParameters");
149  gDirectory->cd("Models");
150 
151  histodir = gDirectory;
152 
153  gDirectory->mkdir("MultiscatteringModel");
154  gDirectory->cd("MultiscatteringModel");
155  gDirectory->mkdir(fModeName);
156  gDirectory->cd(fModeName);
157  //gDirectory->mkdir("All tracks");
158  //gDirectory->cd("All tracks");
159  TString tname = "PerEvent";
160  if (fEventStats != 1)
161  tname =
162  TString("Each ") + TString::Itoa(fEventStats, 10) + TString(" events");
163  gDirectory->mkdir(tname);
164  gDirectory->cd(tname);
165  //for(int part=0;part<p_sz;++part) {
166  //gDirectory->mkdir(p_names[part]);
167  //gDirectory->cd(p_names[part]);
168  int CurrentIndex = 0;
169 
170  IndexSigt = CurrentIndex;
171  histo1D[CurrentIndex] =
172  new TH1F("sigma_t", "Event-by-event sigma_t", 300, 0., 3.);
173  histo1D[CurrentIndex]->SetXTitle("sigma_t (GeV)");
174  histo1D[CurrentIndex]->SetYTitle("Entries");
175  CurrentIndex++;
176 
177 
178  IndexSigz = CurrentIndex;
179  histo1D[CurrentIndex] =
180  new TH1F("sigma_z", "Event-by-event sigma_z", 300, 0., 15.);
181  histo1D[CurrentIndex]->SetXTitle("sigma_z (GeV)");
182  histo1D[CurrentIndex]->SetYTitle("Entries");
183  CurrentIndex++;
184 
185 
186  IndexQz = CurrentIndex;
187  histo1D[CurrentIndex] = new TH1F("Qz", "Event-by-event Qz", 300, 0., 10.);
188  histo1D[CurrentIndex]->SetXTitle("Q_{z} (GeV)");
189  histo1D[CurrentIndex]->SetYTitle("Entries");
190  CurrentIndex++;
191 
192  IndexPt = CurrentIndex;
193  histo1D[CurrentIndex] = new TH1F("f(p_{t})", "pt distribution", 300, 0., 5.);
194  histo1D[CurrentIndex]->SetXTitle("p_{t} (GeV)");
195  histo1D[CurrentIndex]->SetYTitle("Entries");
196  CurrentIndex++;
197 
198  IndexPz = CurrentIndex;
199  histo1D[CurrentIndex] =
200  new TH1F("f(p_{z})", "pz distribution", 300, -20., 20.);
201  histo1D[CurrentIndex]->SetXTitle("p_{z} (GeV)");
202  histo1D[CurrentIndex]->SetYTitle("Entries");
203  CurrentIndex++;
204 
205  IndexY = CurrentIndex;
206  histo1D[CurrentIndex] =
207  new TH1F("dN/dy", "rapidity distribution", 300, -10., 10.);
208  histo1D[CurrentIndex]->SetXTitle("y");
209  histo1D[CurrentIndex]->SetYTitle("Entries");
210  CurrentIndex++;
211 
212 
213  IndexModelPt = CurrentIndex;
214  histo1D[CurrentIndex] =
215  new TH1F("Model f(p_{t})", "Model pt distribution", 300, 0., 5.);
216  histo1D[CurrentIndex]->SetXTitle("p_{t} (GeV)");
217  histo1D[CurrentIndex]->SetYTitle("Entries");
218  CurrentIndex++;
219 
220  IndexModelPz = CurrentIndex;
221  histo1D[CurrentIndex] =
222  new TH1F("Model f(p_{z})", "Model pz distribution", 300, -20., 20.);
223  histo1D[CurrentIndex]->SetXTitle("p_{z} (GeV)");
224  histo1D[CurrentIndex]->SetYTitle("Entries");
225  CurrentIndex++;
226 
227  IndexModelY = CurrentIndex;
228  histo1D[CurrentIndex] =
229  new TH1F("Model dN/dy", "Model rapidity distribution", 300, -10., 10.);
230  histo1D[CurrentIndex]->SetXTitle("y");
231  histo1D[CurrentIndex]->SetYTitle("Entries");
232  CurrentIndex++;
233 
234  CurrentIndex = 0;
235  IndexYPt = CurrentIndex;
236  histo2D[CurrentIndex] =
237  new TH2F("y-pt", "y-pt distribution", 100, -3., 3., 100, 0., 5.);
238  histo2D[CurrentIndex]->SetXTitle("y");
239  histo2D[CurrentIndex]->SetYTitle("p_t (GeV)");
240  CurrentIndex++;
241 
242  IndexModelYPt = CurrentIndex;
243  histo2D[CurrentIndex] = new TH2F(
244  "Model y-pt", "Model y-pt distribution", 100, -3., 3., 100, 0., 5.);
245  histo2D[CurrentIndex]->SetXTitle("y");
246  histo2D[CurrentIndex]->SetYTitle("p_t (GeV)");
247  CurrentIndex++;
248 
249  gDirectory->cd("..");
250  gDirectory->cd("..");
251  gDirectory->cd("..");
252 
253  gDirectory = currentDir;
254 
255  double pbeam = sqrt((kProtonMass + ekin) * (kProtonMass + ekin)
257  double betacm = pbeam / (2. * kProtonMass + ekin);
258  ycm = 0.5 * log((1. + betacm) / (1. - betacm));
259 
260  double ssqrt = sqrt(2. * kProtonMass * (ekin + 2. * kProtonMass));
261  p0cm = sqrt(0.25 * ssqrt * ssqrt - kProtonMass * kProtonMass);
262 
263  std::cout << "ekin = " << ekin << "\n";
264  std::cout << "ycm = " << ycm << "\n";
265 
266  events = 0;
267 
268  paramsLocal.resize(3);
269  paramsGlobal.resize(3);
270  for (int i = 0; i < 3; ++i) {
271  paramsLocal[i] = paramsGlobal[i] = 0.;
272  }
273  totalGlobal = totalLocal = 0;
274 
275 
276  model = new MultiscatteringModel();
277 }
278 
280  if (model != NULL) delete model;
281 }
282 
283 void CbmMultiscatteringModel::ReInit(FairRootManager* fManger) {
284  flistMCTracks = dynamic_cast<TClonesArray*>(fManger->GetObject("MCTrack"));
285 }
286 
288  //ReInit();
289 }
290 
292  if (fRecoLevel == -1 && !flistMCTracks) return;
293  if (fRecoLevel != -1 && !fTopoReconstructor) return;
294 
296 
297  events++;
298 
299  if (events % fEventStats == 0) {
300 
301  std::cout << paramsLocal[0] / totalLocal << "\t"
302  << paramsLocal[1] / totalLocal << "\t"
303  << paramsLocal[2] / totalLocal << "\n";
304  double sigt = model->GetSigt(paramsLocal[0] / totalLocal);
305  double sigz =
307  double qz =
309 
310  histo1D[IndexSigt]->Fill(sigt);
311  histo1D[IndexSigz]->Fill(sigz);
312  histo1D[IndexQz]->Fill(p0cm - qz);
313 
314  std::cout << "sigt = " << sigt << "\n";
315  std::cout << "sigz = " << sigz << "\n";
316  std::cout << "qz = " << p0cm - qz << "\n";
317 
318  events = 0;
319  for (int i = 0; i < 3; ++i) {
320  paramsLocal[i] = 0.;
321  }
322  totalLocal = 0;
323  }
324 }
325 
327 
328  double sigt = model->GetSigt(paramsGlobal[0] / totalGlobal);
329  double sigz = model->GetSigz(paramsGlobal[1] / totalGlobal,
331  double qz =
333  std::cout << "sigt = " << sigt << "\n";
334  std::cout << "sigz = " << sigz << "\n";
335  std::cout << "qz = " << p0cm - qz << "\n";
336 
337  histo1D[IndexPt]->Scale(1. / totalGlobal
338  / histo1D[IndexPt]->GetXaxis()->GetBinWidth(1));
339  histo1D[IndexPz]->Scale(1. / totalGlobal
340  / histo1D[IndexPz]->GetXaxis()->GetBinWidth(1));
341  histo1D[IndexY]->Scale(1. / totalGlobal
342  / histo1D[IndexY]->GetXaxis()->GetBinWidth(1));
343  histo2D[IndexYPt]->Scale(1. / totalGlobal
344  / histo2D[IndexYPt]->GetXaxis()->GetBinWidth(1)
345  / histo2D[IndexYPt]->GetYaxis()->GetBinWidth(1));
346 
347  for (int n = 0; n < histo1D[IndexModelPt]->GetNbinsX(); n++) {
348  histo1D[IndexModelPt]->SetBinContent(
349  n, model->fpt(histo1D[IndexModelPt]->GetXaxis()->GetBinCenter(n), sigt));
350  }
351 
352  for (int n = 0; n < histo1D[IndexModelPz]->GetNbinsX(); n++) {
353  histo1D[IndexModelPz]->SetBinContent(
354  n,
355  model->fpz(histo1D[IndexModelPz]->GetXaxis()->GetBinCenter(n), sigz, qz));
356  }
357 
358  for (int n = 0; n < histo1D[IndexModelY]->GetNbinsX(); n++) {
359  histo1D[IndexModelY]->SetBinContent(
360  n,
361  model->dndy(histo1D[IndexModelY]->GetXaxis()->GetBinCenter(n),
362  kProtonMass,
363  sigt,
364  sigz,
365  qz));
366  }
367 
368  for (int nx = 0; nx < histo2D[IndexModelYPt]->GetNbinsX(); nx++) {
369  for (int ny = 0; ny < histo2D[IndexModelYPt]->GetNbinsY(); ny++) {
370  histo2D[IndexModelYPt]->SetBinContent(
371  nx,
372  ny,
373  model->fypt(histo2D[IndexModelYPt]->GetXaxis()->GetBinCenter(nx),
374  histo2D[IndexModelYPt]->GetYaxis()->GetBinCenter(ny),
375  kProtonMass,
376  sigt,
377  sigz,
378  qz));
379  }
380  }
381 }
382 
384  bool UpdateGlobal) {
385  if (RecoLevel == -1) {
386  vector<CbmMCTrack> vRTracksMC;
387  int nTracksMC = flistMCTracks->GetEntries();
388  std::cout << "MC tracks: " << nTracksMC << "\n";
389  vRTracksMC.resize(nTracksMC);
390  for (int iTr = 0; iTr < nTracksMC; iTr++)
391  //vRTracksMC[iTr] = *( (CbmMCTrack*) flistMCTracks->At(iTr));
392  vRTracksMC[iTr] = *(static_cast<CbmMCTrack*>(flistMCTracks->At(iTr)));
393 
394  for (int iTr = 0; iTr < nTracksMC; iTr++) {
395  //for(unsigned int part=0;part<ParticlePDGsTrack.size();++part) {
396  if (vRTracksMC[iTr].GetPdgCode() == PPDG
397  && vRTracksMC[iTr].GetMotherId() == -1) {
398  totalLocal++;
399  double pt = vRTracksMC[iTr].GetPt();
400  double ty = vRTracksMC[iTr].GetRapidity() - ycm;
401  double pz =
402  TMath::Sqrt(vRTracksMC[iTr].GetMass() * vRTracksMC[iTr].GetMass()
403  + pt * pt)
404  * TMath::SinH(ty);
405  paramsLocal[0] += pt;
406  paramsLocal[1] += pz * pz;
407  paramsLocal[2] += pz * pz * pz * pz;
408  if (UpdateGlobal) {
409  totalGlobal++;
410  paramsGlobal[0] += pt;
411  paramsGlobal[1] += pz * pz;
412  paramsGlobal[2] += pz * pz * pz * pz;
413  }
414  histo1D[IndexPt]->Fill(pt);
415  histo1D[IndexPz]->Fill(pz);
416  histo1D[IndexY]->Fill(ty);
417  histo2D[IndexYPt]->Fill(ty, pt);
418  }
419  //}
420  }
421  } else {
422  for (int itype = 2; itype <= 3; ++itype) {
423  const KFPTrackVector& tr = fTopoReconstructor->GetTracks()[itype];
424  const kfvector_int& pdgs = tr.PDG();
425  for (unsigned int ind = 0; ind < pdgs.size(); ++ind) {
426  int iPDG = pdgs[ind];
427  //for(unsigned int part=0;part<ParticlePDGsTrack.size();++part) {
428  if (iPDG == PPDG) {
429  totalLocal++;
430  double pt = tr.Pt(ind);
431  double p = tr.P(ind);
432  double m = TDatabasePDG::Instance()->GetParticle(iPDG)->Mass();
433  double p0 = TMath::Sqrt(m * m + p * p);
434  double ty = 0.5 * log((p0 + p) / (p0 - p)) - ycm;
435  double pz = TMath::Sqrt(m * m + pt * pt) * TMath::SinH(ty);
436  paramsLocal[0] += pt;
437  paramsLocal[1] += pz * pz;
438  paramsLocal[2] += pz * pz * pz * pz;
439  if (UpdateGlobal) {
440  totalGlobal++;
441  paramsGlobal[0] += pt;
442  paramsGlobal[1] += pz * pz;
443  paramsGlobal[2] += pz * pz * pz * pz;
444  }
445  histo1D[IndexPt]->Fill(pt);
446  histo1D[IndexPz]->Fill(pz);
447  histo1D[IndexY]->Fill(ty);
448  histo2D[IndexYPt]->Fill(ty, pt);
449  }
450  //}
451  }
452  }
453  }
454 }
MultiscatteringModel::fypt
double fypt(double y, double pt, double m, double sigt, double sigz, double qz)
Definition: MultiscatteringModel.h:55
MultiscatteringModel::GetSigt
double GetSigt(double apt)
Definition: MultiscatteringModel.h:18
CbmModelBase::fTopoReconstructor
KFParticleTopoReconstructor * fTopoReconstructor
Definition: CbmModelBase.h:42
CbmMultiscatteringModel::IndexPt
int IndexPt
Definition: CbmMultiscatteringModel.h:82
CbmVertex.h
CbmMultiscatteringModel::histo2D
TH2F * histo2D[nHisto2D]
Definition: CbmMultiscatteringModel.h:90
CbmMultiscatteringModel::IndexModelY
int IndexModelY
Definition: CbmMultiscatteringModel.h:83
ClassImp
ClassImp(CbmMultiscatteringModel) CbmMultiscatteringModel
Definition: CbmMultiscatteringModel.cxx:71
CbmMultiscatteringModel::CalculateAveragesInEvent
void CalculateAveragesInEvent(int RecoLevel, bool UpdateGlobal=0)
Definition: CbmMultiscatteringModel.cxx:383
L1Field.h
CbmMultiscatteringModel::IndexPz
int IndexPz
Definition: CbmMultiscatteringModel.h:82
sqrt
friend F32vec4 sqrt(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:41
CbmMultiscatteringModel::paramsLocal
std::vector< double > paramsLocal
Definition: CbmMultiscatteringModel.h:96
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
MultiscatteringModel::GetSigz
double GetSigz(double apz2, double apz4)
Definition: MultiscatteringModel.h:20
CbmMultiscatteringModel::IndexSigt
int IndexSigt
Definition: CbmMultiscatteringModel.h:82
CbmMultiscatteringModel::histo1D
TH1F * histo1D[nHisto1D]
Definition: CbmMultiscatteringModel.h:85
CbmGlobalTrack.h
CbmMultiscatteringModel
Definition: CbmMultiscatteringModel.h:38
CbmMultiscatteringModel::paramsGlobal
std::vector< double > paramsGlobal
Definition: CbmMultiscatteringModel.h:96
CbmMultiscatteringModel::totalLocal
int totalLocal
Definition: CbmMultiscatteringModel.h:97
CbmMultiscatteringModel::Finish
virtual void Finish()
Definition: CbmMultiscatteringModel.cxx:326
CbmMultiscatteringModel::totalGlobal
int totalGlobal
Definition: CbmMultiscatteringModel.h:97
CbmRichRing.h
CbmMultiscatteringModel::IndexY
int IndexY
Definition: CbmMultiscatteringModel.h:82
CbmMultiscatteringModel::kProtonMass
double kProtonMass
Definition: CbmMultiscatteringModel.h:99
CbmMultiscatteringModel::ycm
Float_t ycm
Definition: CbmMultiscatteringModel.h:65
CbmMultiscatteringModel::flistMCTracks
TClonesArray * flistMCTracks
Definition: CbmMultiscatteringModel.h:79
CbmMultiscatteringModel::IndexModelYPt
int IndexModelYPt
Definition: CbmMultiscatteringModel.h:88
CbmL1Def.h
CbmMultiscatteringModel.h
CbmStsTrack.h
Data class for STS tracks.
CbmMultiscatteringModel::IndexModelPt
int IndexModelPt
Definition: CbmMultiscatteringModel.h:82
CbmMultiscatteringModel::fRecoLevel
Int_t fRecoLevel
Definition: CbmMultiscatteringModel.h:68
CbmMultiscatteringModel::IndexModelPz
int IndexModelPz
Definition: CbmMultiscatteringModel.h:83
MultiscatteringModel::fpz
double fpz(double pz, double sigz, double qz)
Definition: MultiscatteringModel.h:38
log
friend F32vec4 log(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:135
CbmTrackMatchNew.h
CbmMultiscatteringModel::IndexYPt
int IndexYPt
Definition: CbmMultiscatteringModel.h:88
CbmL1PFFitter.h
MultiscatteringModel::fpt
double fpt(double pt, double sigt)
Definition: MultiscatteringModel.h:34
CbmMultiscatteringModel::~CbmMultiscatteringModel
~CbmMultiscatteringModel()
Definition: CbmMultiscatteringModel.cxx:279
MultiscatteringModel.h
CbmKFTrack.h
MultiscatteringModel::GetQz
double GetQz(double apz2, double apz4)
Definition: MultiscatteringModel.h:28
CbmMultiscatteringModel::p0cm
Float_t p0cm
Definition: CbmMultiscatteringModel.h:64
CbmModelBase
Definition: CbmModelBase.h:25
CbmMultiscatteringModel::CbmMultiscatteringModel
CbmMultiscatteringModel(Int_t recoLevel=-1, Int_t iVerbose=1, TString Mode="MC", Int_t EventStats=1, KFParticleTopoReconstructor *tr=0, Float_t ekin_=25.)
CbmMultiscatteringModel::Exec
virtual void Exec()
Definition: CbmMultiscatteringModel.cxx:291
CbmMultiscatteringModel::fEventStats
Int_t fEventStats
Definition: CbmMultiscatteringModel.h:70
CbmMCTrack.h
CbmMultiscatteringModel::PPDG
int PPDG
Definition: CbmMultiscatteringModel.h:95
CbmMCTrack
Definition: CbmMCTrack.h:34
m
__m128 m
Definition: L1/vectors/P4_F32vec4.h:26
CbmMultiscatteringModel::Init
virtual void Init()
Definition: CbmMultiscatteringModel.cxx:287
CbmMultiscatteringModel::IndexSigz
int IndexSigz
Definition: CbmMultiscatteringModel.h:82
CbmMultiscatteringModel::model
MultiscatteringModel * model
Definition: CbmMultiscatteringModel.h:105
CbmTrdTrack.h
kProtonMass
const Double_t kProtonMass
Definition: CbmPhsdGenerator.cxx:31
CbmMultiscatteringModel::events
Int_t events
Definition: CbmMultiscatteringModel.h:71
CbmMultiscatteringModel::ReInit
virtual void ReInit(FairRootManager *fManger)
Definition: CbmMultiscatteringModel.cxx:283
CbmMultiscatteringModel::IndexQz
int IndexQz
Definition: CbmMultiscatteringModel.h:82
CbmKFVertex.h
MultiscatteringModel::dndy
double dndy(double y, double m, double sigt, double sigz, double qz)
Definition: MultiscatteringModel.h:44
MultiscatteringModel
Definition: MultiscatteringModel.h:10