EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
analysis-vtx.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file analysis-vtx.C
1 
3 {
4  // Import simulated & reconstructed files in a "coherent" way;
5  auto ff = new TFile("simulation.root");
6  auto cbmsim = dynamic_cast<TTree *>(ff->Get("cbmsim"));
7  cbmsim->AddFriend("cbmsim", "reconstruction.root");
8 
9  // Define branches of interest: simulated and reconstructed tracks;
10  auto mcTrackArray = new TClonesArray("PndMCTrack");
11  cbmsim->SetBranchAddress("MCTrack", &mcTrackArray);
12  auto kfTrackArray = new TClonesArray("PndTrack");
13  cbmsim->SetBranchAddress("EicIdealGenTrack", &kfTrackArray);
14  auto rcTrackArray = new TClonesArray("PndPidCandidate");
15  cbmsim->SetBranchAddress("PidChargedCand", &rcTrackArray);
16 
17  // Book 1D dp/p histogram;
18  auto dp = new TH1D("dp", "dp", 100, -20., 20.);
19  auto dfi = new TH1D("dfi", "dfi", 100, -20., 20.);
20  auto dth = new TH1D("dth", "dth", 100, -20., 20.);
21 
22  // Loop through all events; NB: for box-generated events without secondaries
23  // could simply use cbmsim->Project() as well; in general EicEventAssembler
24  // in the reconstruction.C script should be used for "true" physics events
25  // for multi-particle physics events;
26  int nEvents = cbmsim->GetEntries();
27  for(unsigned ev=0; ev<nEvents; ev++) {
28  cbmsim->GetEntry(ev);
29 
30  for(unsigned rc=0; rc<kfTrackArray->GetEntriesFast(); rc++) {
31  auto rctrack = dynamic_cast<PndTrack *>(kfTrackArray->At(rc));
32  // Here the trick comes: GetParamFirst() is defined at the IP bubble location;
33  FairTrackParP vtxpar = rctrack->GetParamFirst();
34 
35  // I hope this is correct?;
36  int mcTrackId = rctrack->GetTrackCandPtr()->getMcTrackId();
37 
38  // Select only the correctly rc->mc identified tracks;
39  if (mcTrackId < 0 || mcTrackId >= mcTrackArray->GetEntriesFast()) continue;
40 
41  // Find MC track associated with this reconstructed track;
42  auto mctrack = dynamic_cast<PndMCTrack *>(mcTrackArray->At(mcTrackId));
43 
44  // Well, for plotting select primary pi- tracks only (see simulation.C);
45  if (mctrack->GetPdgCode() == 211 && mctrack->GetMotherID() == -1) {
46  //printf("%7.3f %7.3f -> %7.3f\n", vtxpar.GetMomentum().Phi(), mctrack->GetMomentum().Phi(),
47  // 1000*(vtxpar.GetMomentum().Phi() - mctrack->GetMomentum().Phi()));
48  printf("%7.3f %7.3f -> %7.3f\n", vtxpar.GetMomentum().Theta(), mctrack->GetMomentum().Theta(),
49  1000*(vtxpar.GetMomentum().Theta() - mctrack->GetMomentum().Theta()));
50 
51  // This is just a dp/p in [%] units;
52  dp->Fill(100.*(vtxpar.GetMomentum().Mag() - mctrack->GetMomentum().Mag())/mctrack->GetMomentum().Mag());
53  } //if
54  } //for rc
55  } //for ev
56 
57  // ROOT plotting magic;
58  gStyle->SetOptStat(0);
59 
60  dp->SetTitle("Momentum resolution");
61 
62  dp->GetXaxis()->SetTitle("(P_{rec} - P_{sim})/P_{sim}, [%]");
63  dp->GetXaxis()->SetTitleOffset(0.9);
64  dp->GetXaxis()->SetLabelFont(52);
65  dp->GetXaxis()->SetLabelSize(0.040);
66  dp->GetXaxis()->SetTitleFont(52);
67  dp->GetXaxis()->SetTitleSize(0.050);
68 
69  dp->GetYaxis()->SetTitle("Events");
70  dp->GetYaxis()->SetTitleOffset(0.7);
71  dp->GetYaxis()->SetLabelFont(52);
72  dp->GetYaxis()->SetLabelSize(0.040);
73  dp->GetYaxis()->SetTitleFont(52);
74  dp->GetYaxis()->SetTitleSize(0.050);
75 
76  dp->Fit("gaus");
77 } // analysis_vtx()