EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stvector.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file stvector.C
1 
2 //
3 // State vector extraction script; allows one to get access to the MC
4 // (truth) and reconstructed track parameterizations at the locations of
5 // detector planes where a given track produced hits;
6 //
7 
8 void stvector()
9 {
10  // Load basic libraries;
11  gROOT->Macro("$VMCWORKDIR/gconfig/rootlogon.C");
12 
13  // Import simulated & reconstructed files in a "coherent" way;
14  TFile *ff = new TFile("simulation.root");
15  TTree *cbmsim = ff->Get("cbmsim");
16  cbmsim->AddFriend("cbmsim", "reconstruction.root");
17 
18  // Define branches of interest: simulated and reconstructed tracks;
19  TClonesArray *mcTrackArray = new TClonesArray("PndMCTrack");
20  cbmsim->SetBranchAddress("MCTrack", &mcTrackArray);
21  TClonesArray *rcTrackArray = new TClonesArray("PndPidCandidate");
22  cbmsim->SetBranchAddress("PidChargedCand", &rcTrackArray);
23 
24  // Loop through all events; NB: for box-generated events without secondaries
25  // could simply use cbmsim->Project() as well; in general EicEventAssembler
26  // in the reconstruction.C script should be used for "true" physics events
27  // for multi-particle physics events;
28  int nEvents = cbmsim->GetEntries();
29  for(unsigned ev=0; ev<nEvents; ev++) {
30  cbmsim->GetEntry(ev);
31 
32  // Loop through all reconstructed tracks;
33  for(unsigned rc=0; rc<rcTrackArray->GetEntriesFast(); rc++) {
34  PndPidCandidate *rctrack = rcTrackArray->At(rc);
35 
36  // Loop through ALL the stored parameterizations and print out MC (Monte-Carlo)
37  // and RC (reconstructed) {x,p} pairs of 3D vectors (position and momentum);
38  for(unsigned ih=0; ih<rctrack->GetParameterizationCount(); ih++) {
40 
41  TVector3 mcpos = par->GetMoCaPosition(), mcmom = par->GetMoCaMomentum();
42  TVector3 rcpos = par->GetRecoPosition(), rcmom = par->GetRecoMomentum();
43  //printf("%2d (REC) -> V: %7.3f %7.3f %7.3f [cm] & P: %7.3f %7.3f %7.3f [GeV/c]\n",
44  // ih, rcpos.X(), rcpos.Y(), rcpos.Z(), rcmom.X(), rcmom.Y(), rcmom.Z());
45  //printf(" ( MC) %7.3f %7.3f %7.3f & %7.3f %7.3f %7.3f\n\n",
46  // mcpos.X(), mcpos.Y(), mcpos.Z(), mcmom.X(), mcmom.Y(), mcmom.Z());
47  } //for ih
48 
49  // Find a parameterization the closest to a given Z-position along the beam line
50  // (which is in this case 105cm - silicon plane #5 counting from 0, see tracker.C
51  // script with the geometry description); if a given track did NOT produce a hit
52  // in this particular plane (missed it, in other words), the below sequence of
53  // calls will find some other closest hit parameterization, so one needs to watch
54  // out and place a tight enough cut either on the mcpos.Z() value explicitly or
55  // on the par->DistanceToPlane(plxx, plnx) return value);
56  {
57  // A 3D plane parameterization in space - a point and a normal vector along the
58  // beam line direction;
59  TVector3 plxx(0.0, 0.0, 105.0), plnx(0.0, 0.0, 1.0);
60  NaiveTrackParameterization *par = rctrack->GetNearestParameterization(plxx, plnx);
61 
62  if (par) {
63  TVector3 mcpos = par->GetMoCaPosition(), mcmom = par->GetMoCaMomentum();
64  TVector3 rcpos = par->GetRecoPosition(), rcmom = par->GetRecoMomentum();
65  printf("Hit-to-plane distance: %7.2f [cm]\n", par->DistanceToPlane(plxx, plnx));
66  printf(" (REC) -> V: %7.3f %7.3f %7.3f [cm] & P: %7.3f %7.3f %7.3f [GeV/c]\n",
67  rcpos.X(), rcpos.Y(), rcpos.Z(), rcmom.X(), rcmom.Y(), rcmom.Z());
68  printf(" ( MC) %7.3f %7.3f %7.3f & %7.3f %7.3f %7.3f\n\n",
69  mcpos.X(), mcpos.Y(), mcpos.Z(), mcmom.X(), mcmom.Y(), mcmom.Z());
70  }
71  else
72  // Can hardly happen (fitter would not be started on such a track);
73  printf(" ---> No hits!\n");
74  }
75  } //for rc
76  } //for ev
77 } // stvector()