EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
analysis.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file analysis.C
1 
2 void analysis()
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 rcTrackArray = new TClonesArray("PndPidCandidate");
13  cbmsim->SetBranchAddress("PidChargedCand", &rcTrackArray);
14 
15  // Book 1D dp/p histogram;
16  auto dp = new TH1D("dp", "dp", 100, -20., 20.);
17 
18  // Loop through all events; NB: for box-generated events without secondaries
19  // could simply use cbmsim->Project() as well; in general EicEventAssembler
20  // in the reconstruction.C script should be used for "true" physics events
21  // for multi-particle physics events;
22  int nEvents = cbmsim->GetEntries();
23  for(unsigned ev=0; ev<nEvents; ev++) {
24  cbmsim->GetEntry(ev);
25 
26  // Loop through all reconstructed tracks of a given event;
27  for(unsigned rc=0; rc<rcTrackArray->GetEntriesFast(); rc++) {
28  auto rctrack = dynamic_cast<PndPidCandidate *>(rcTrackArray->At(rc));
29  int mcTrackId = rctrack->GetMcIndex();
30 
31  // Select only the correctly rc->mc identified tracks;
32  if (mcTrackId < 0 || mcTrackId >= mcTrackArray->GetEntriesFast()) continue;
33 
34  // Find MC track associated with this reconstructed track;
35  auto mctrack = dynamic_cast<PndMCTrack *>(mcTrackArray->At(mcTrackId));
36 
37  // Well, for plotting select primary pi- tracks only (see simulation.C);
38  if (mctrack->GetPdgCode() == 211 && mctrack->GetMotherID() == -1)
39  // This is just a dp/p in [%] units;
40  dp->Fill(100.*(rctrack->GetMomentum().Mag() - mctrack->GetMomentum().Mag())/mctrack->GetMomentum().Mag());
41  } //for rc
42  } //for ev
43 
44  // ROOT plotting magic;
45  gStyle->SetOptStat(0);
46 
47  dp->SetTitle("Momentum resolution");
48 
49  dp->GetXaxis()->SetTitle("(P_{rec} - P_{sim})/P_{sim}, [%]");
50  dp->GetXaxis()->SetTitleOffset(0.9);
51  dp->GetXaxis()->SetLabelFont(52);
52  dp->GetXaxis()->SetLabelSize(0.040);
53  dp->GetXaxis()->SetTitleFont(52);
54  dp->GetXaxis()->SetTitleSize(0.050);
55 
56  dp->GetYaxis()->SetTitle("Events");
57  dp->GetYaxis()->SetTitleOffset(0.7);
58  dp->GetYaxis()->SetLabelFont(52);
59  dp->GetYaxis()->SetLabelSize(0.040);
60  dp->GetYaxis()->SetTitleFont(52);
61  dp->GetYaxis()->SetTitleSize(0.050);
62 
63  dp->Fit("gaus");
64 } // analysis()