Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DEventProcessor_DCdEdxStudy_tree.cc
Go to the documentation of this file.
2 
3 // The executable should define the ROOTfile global variable. It will
4 // be automatically linked when dlopen is called.
5 extern TFile *ROOTfile;
6 
7 // Routine used to create our DEventProcessor
8 extern "C"{
9 void InitPlugin(JApplication *app){
10  InitJANAPlugin(app);
11  app->AddProcessor(new DEventProcessor_DCdEdxStudy_tree());
12 }
13 } // "C"
14 
15 
16 //------------------
17 // init
18 //------------------
20 {
21 
23  dPluginTree_DCdEdxInformation = new TTree("dPluginTree_DCdEdxInformation", "DC dEdx Information");
24  dPluginTree_DCdEdxInformation->Branch("dPluginBranch_DCdEdxInformation", "DCdEdxInformation", &dDCdEdxInformation);
25 
26  return NOERROR;
27 }
28 
29 //------------------
30 // brun
31 //------------------
32 jerror_t DEventProcessor_DCdEdxStudy_tree::brun(JEventLoop *eventLoop, int32_t runnumber)
33 {
34 
35  return NOERROR;
36 }
37 
38 //------------------
39 // evnt
40 //------------------
41 jerror_t DEventProcessor_DCdEdxStudy_tree::evnt(JEventLoop *loop, uint64_t eventnumber)
42 {
43  // Get the particle ID algorithms
44  vector<const DParticleID *> locPIDAlgorithms;
45  eventLoop->Get(locPIDAlgorithms);
46  if(locPIDAlgorithms.size() < 1){
47  _DBG_<<"Unable to get a DParticleID object! NO PID will be done!"<<endl;
48  return RESOURCE_UNAVAILABLE;
49  }
50  // Drop the const qualifier from the DParticleID pointer (I'm surely going to hell for this!)
51  locPIDAlgorithm = const_cast<DParticleID*>(locPIDAlgorithms[0]);
52 
53  // Warn user if something happened that caused us NOT to get a locPIDAlgorithm object pointer
54  if(!locPIDAlgorithm){
55  _DBG_<<"Unable to get a DParticleID object! NO PID will be done!"<<endl;
56  return RESOURCE_UNAVAILABLE;
57  }
58 
59  vector<const DMCThrown*> locDMCThrownVector;
60  const DMCThrown *locDMCThrown;
61  loop->Get(locDMCThrownVector);
62 
63  vector<const DChargedTrackHypothesis*> locChargedTrackHypothesisVector;
64  const DChargedTrackHypothesis *locChargedTrackHypothesis;
65  loop->Get(locChargedTrackHypothesisVector);
66 
67  const DTrackTimeBased *locTrackTimeBased;
68 
69  Particle_t locThrownPID, locReconstructedPID;
70  float locThrownMass, locMomentum, locBeta;
71 
72  if(locDMCThrownVector.size() != 1)
73  return NOERROR; //routine assumes only one thrown track (matching not performed!)
74  if(locChargedTrackHypothesisVector.size() == 0)
75  return NOERROR;
76  locDMCThrown = locDMCThrownVector[0];
77  locThrownPID = Particle_t(locDMCThrown->type);
78  locThrownMass = ParticleMass(locThrownPID);
79 
80  bool locPIDMatchFlag = false;
81  for(unsigned int loc_i = 0; loc_i < locChargedTrackHypothesisVector.size(); loc_i++){
82  locChargedTrackHypothesis = locChargedTrackHypothesisVector[loc_i];
83  locTrackTimeBased = locChargedTrackHypothesis->dTrackTimeBased;
84  locReconstructedPID = locChargedTrackHypothesis->dPID;
85  if(locReconstructedPID == locThrownPID){
86  locPIDMatchFlag = true;
87  break;
88  }
89  }
90  if(locPIDMatchFlag == false)
91  locTrackTimeBased = locChargedTrackHypothesisVector[0]->dTrackTimeBased;
92 
93  locMomentum = locTrackTimeBased->momentum().Mag();
94  locBeta = locMomentum/sqrt(locThrownMass*locThrownMass + locMomentum*locMomentum);
95 
96  // Although we are only filling objects local to this plugin, TTree::Fill() periodically writes to file: Global ROOT lock
97  japp->RootWriteLock(); //ACQUIRE ROOT LOCK
98 
99  //low-momentum & beta protons are reconstructed as low-momentum but high-beta pions
100  dDCdEdxInformation->dBeta = locBeta;
101  dDCdEdxInformation->dMomentum = locMomentum;
102  dDCdEdxInformation->dTheta = locTrackTimeBased->momentum().Theta();
103  dDCdEdxInformation->dVertexZ = locTrackTimeBased->z();
104 
105  dDCdEdxInformation->ddEdx_FDC = locTrackTimeBased->ddEdx_FDC; //units of GeV/cm
106  dDCdEdxInformation->ddx_FDC = locTrackTimeBased->ddx_FDC;
108  dDCdEdxInformation->ddEdx_CDC = locTrackTimeBased->ddEdx_CDC; //units of GeV/cm
109  dDCdEdxInformation->ddx_CDC = locTrackTimeBased->ddx_CDC;
111 
112  dDCdEdxInformation->dChiSq_DCdEdx = locChargedTrackHypothesis->dChiSq_DCdEdx;
113  dDCdEdxInformation->dNDF_DCdEdx = locChargedTrackHypothesis->dNDF_DCdEdx;
116 
117  japp->RootUnLock(); //RELEASE ROOT LOCK
118 
119  return NOERROR;
120 }
121 
122 //------------------
123 // erun
124 //------------------
126 {
127  // Any final calculations on histograms (like dividing them)
128  // should be done here. This may get called more than once.
129  return NOERROR;
130 }
131 
132 //------------------
133 // fini
134 //------------------
136 {
137  return NOERROR;
138 }
139 
TFile * ROOTfile
jerror_t evnt(JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
double z(void) const
JApplication * japp
InitPlugin_t InitPlugin
#define _DBG_
Definition: HDEVIO.h:12
jerror_t fini(void)
Called after last event of last event source has been processed.
static double ParticleMass(Particle_t p)
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
double sqrt(double)
jerror_t init(void)
Called once at program start.
unsigned int dNDF_DCdEdx
const DVector3 & momentum(void) const
unsigned int dNumHitsUsedFordEdx_FDC
int type
GEANT particle ID.
Definition: DMCThrown.h:20
jerror_t brun(JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
unsigned int dNumHitsUsedFordEdx_FDC
unsigned int dNumHitsUsedFordEdx_CDC
unsigned int dNumHitsUsedFordEdx_CDC
Particle_t
Definition: particleType.h:12