Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_BCAL_ADC_4ns.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_BCAL_ADC_4ns.cc
4 // Created: Fri Jul 21 10:41:38 EDT 2017
5 // Creator: dalton (on Linux gluon106.jlab.org 2.6.32-642.3.1.el6.x86_64 x86_64)
6 //
7 /*************************************
8  This plugin is designed to calibrate the TDC times for the BCAL.make the histograms necessary to
9  in order to extract the ADC 4 ns offsets for each channel.
10  *************************************/
11 
13 #include "HistogramTools.h"
14 #include "BCAL/DBCALHit.h"
15 #include "BCAL/DBCALTDCHit.h"
16 #include "BCAL/DBCALCluster.h"
17 #include "BCAL/DBCALDigiHit.h"
18 #include "BCAL/DBCALPoint.h"
19 #include "BCAL/DBCALUnifiedHit.h"
20 #include "BCAL/DBCALGeometry.h"
21 #include "DANA/DStatusBits.h"
22 #include "PID/DChargedTrack.h"
23 #include "PID/DEventRFBunch.h"
24 #include "PID/DDetectorMatches.h"
25 #include "PID/DNeutralShower.h"
26 #include "PID/DVertex.h"
28 #include "TRIGGER/DL1Trigger.h"
29 
30 using namespace jana;
31 
32 
33 // Routine used to create our JEventProcessor
34 #include <JANA/JApplication.h>
35 #include <JANA/JFactory.h>
36 extern "C"{
37 void InitPlugin(JApplication *app){
38  InitJANAPlugin(app);
39  app->AddProcessor(new JEventProcessor_BCAL_ADC_4ns());
40 }
41 } // "C"
42 
43 
44 //------------------
45 // JEventProcessor_BCAL_ADC_4ns (Constructor)
46 //------------------
48 {
49 
50 }
51 
52 //------------------
53 // ~JEventProcessor_BCAL_ADC_4ns (Destructor)
54 //------------------
56 {
57 
58 }
59 
60 //------------------
61 // init
62 //------------------
64 {
65  // This is called once at program startup.
66 
67  return NOERROR;
68 }
69 
70 //------------------
71 // brun
72 //------------------
73 jerror_t JEventProcessor_BCAL_ADC_4ns::brun(JEventLoop *eventLoop, int32_t runnumber)
74 {
75  // This is called whenever the run number changes
76  return NOERROR;
77 }
78 
79 //------------------
80 // evnt
81 //------------------
82 jerror_t JEventProcessor_BCAL_ADC_4ns::evnt(JEventLoop *loop, uint64_t eventnumber)
83 {
84  // First check that this is not a font panel trigger or no trigger
85  bool goodtrigger=1;
86  const DL1Trigger *trig = NULL;
87  try {
88  loop->GetSingle(trig);
89  } catch (...) {}
90  if (trig) {
91  if (trig->fp_trig_mask){
92  goodtrigger=0;
93  }
94  }
95  if (!goodtrigger) {
96  return NOERROR;
97  }
98 
99  const DEventRFBunch *thisRFBunch = NULL;
100  loop->GetSingle(thisRFBunch);
101 
102  vector <const DChargedTrack *> chargedTrackVector;
103  loop->Get(chargedTrackVector);
104 
105  for (unsigned int iTrack = 0; iTrack < chargedTrackVector.size(); iTrack++){
106  // get charge and choose pion hypothesis as most likely
107  int charge = chargedTrackVector[iTrack]->Get_Charge();
108  char q[2];
109  const DChargedTrackHypothesis* bestHypothesis;
110  if (charge>0) {
111  bestHypothesis = chargedTrackVector[iTrack]->Get_Hypothesis(PiPlus);
112  sprintf(q,"+");
113  } else {
114  bestHypothesis = chargedTrackVector[iTrack]->Get_Hypothesis(PiMinus);
115  sprintf(q,"-");
116  }
117  if (bestHypothesis == NULL) continue;
118  // Now from this hypothesis we can get the detector matches to the BCAL
119  const DBCALShowerMatchParams* bcalMatch = bestHypothesis->Get_BCALShowerMatchParams();
120  if (bcalMatch == NULL) continue;
121  const DSCHitMatchParams* scMatch = bestHypothesis->Get_SCHitMatchParams();
122  if (scMatch == NULL) continue;
123  DVector3 position = bestHypothesis->position();
124 
125  // We also need the reference trajectory, which is buried deep in there
126  const DTrackTimeBased *timeBasedTrack = nullptr;
127  bestHypothesis->GetSingle(timeBasedTrack);
128  const DReferenceTrajectory *rt = timeBasedTrack->rt;
129  if (timeBasedTrack->FOM < 0.0027) continue; // 3-sigma cut on tracking FOM
130 
131  if (timeBasedTrack->Ndof < 10) continue; // CDC: 5 params in fit, 10 dof => [15 hits]; FDC [10 hits]
132 
133  // Get the shower from the match
134  const DBCALShower *thisShower = bcalMatch->dBCALShower;
135 
136  // Fill histograms based on the shower
137  char title[200];
138  DVector3 proj_pos = rt->GetLastDOCAPoint();
139  double pathLength, flightTime;
140 
141  // Get the points from the shower
142  vector <const DBCALPoint*> pointVector;
143  thisShower->Get(pointVector);
144 
145  // Loop over the points within the cluster
146  for (unsigned int iPoint = 0; iPoint < pointVector.size(); iPoint++){
147  const DBCALPoint *thisPoint = pointVector[iPoint];
148  if (thisPoint->E() < 0.05) continue; // The timing is known not to be great for very low energy, so only use our best info
149  double rpoint = thisPoint->r();
150 
151  float zminhall = 0;
152  float zmaxhall = 450;
153  if (rt->GetIntersectionWithRadius(rpoint,proj_pos, &pathLength, &flightTime)==NOERROR){
154  // Now proj_pos contains the projected position of the track at this particular point within the BCAL
155  char channame[255];
156  sprintf(channame, "M%02iL%iS%i", thisPoint->module(), thisPoint->layer(), thisPoint->sector());
157  double trackHitZ = proj_pos.z();
158 
159  vector <const DBCALHit*> hitVector;
160  thisPoint->Get(hitVector);
161 
162  //double Deltat = thisPoint->t_US() - thisPoint->t_DS();
163  double Deltat = hitVector[0]->t_raw - hitVector[1]->t_raw;
164  if (hitVector[0]->end==1) Deltat = -Deltat;
165 
166  sprintf(title, "%s Z_{Track} vs #Delta t;#Delta t = t_{US}-t_{DS};Z_{Track} [cm]", channame);
167  Fill2DHistogram ("BCAL_ADC_Deltat", "ZvsDeltat", channame, Deltat, trackHitZ, title,
168  480, -30, 30, 250, zminhall, zmaxhall);
169  }
170  }
171  }
172  return NOERROR;
173 }
174 
175 //------------------
176 // erun
177 //------------------
179 {
180  // This is called whenever the run number changes, before it is
181  // changed to give you a chance to clean up before processing
182  // events from the next run number.
183  return NOERROR;
184 }
185 
186 //------------------
187 // fini
188 //------------------
190 {
191  // Called before program exit after event processing is finished.
192  return NOERROR;
193 }
194 
int module() const
Definition: DBCALPoint.h:64
TVector3 DVector3
Definition: DVector3.h:14
uint32_t fp_trig_mask
Definition: DL1Trigger.h:19
sprintf(text,"Post KinFit Cut")
DVector3 GetLastDOCAPoint(void) const
int sector() const
Definition: DBCALPoint.h:66
const DVector3 & position(void) const
jerror_t fini(void)
Called after last event of last event source has been processed.
trig[33-1]
int layer() const
Definition: DBCALPoint.h:65
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
float E() const
Definition: DBCALPoint.h:38
InitPlugin_t InitPlugin
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
jerror_t init(void)
Called once at program start.
int Ndof
Number of degrees of freedom in the fit.
void Fill2DHistogram(const char *plugin, const char *directoryName, const char *name, const double valueX, const double valueY, const char *title, int nBinsX, double xmin, double xmax, int nBinsY, double ymin, double ymax, bool print=false)
shared_ptr< const DSCHitMatchParams > Get_SCHitMatchParams(void) const
jerror_t GetIntersectionWithRadius(double R, DVector3 &mypos, double *s=NULL, double *t=NULL, DVector3 *dir=NULL) const
shared_ptr< const DBCALShowerMatchParams > Get_BCALShowerMatchParams(void) const
float r() const
Definition: DBCALPoint.h:62
const DBCALShower * dBCALShower