Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_FCAL_TimingOffsets.cc
Go to the documentation of this file.
2 #include <JANA/JApplication.h>
3 #include "FCAL/DFCALShower.h"
4 #include "FCAL/DFCALGeometry.h"
5 #include "FCAL/DFCALHit.h"
6 #include "FCAL/DFCALDigiHit.h"
7 #include "FCAL/DFCALCluster.h"
9 #include "PID/DVertex.h"
10 #include "DVector3.h"
12 #include <TTree.h>
13 #include "DVector3.h"
14 #include "PID/DParticleID.h"
15 #include "GlueX.h"
16 #include <vector>
17 #include <map>
18 #include <deque>
19 #include <string>
20 #include <iostream>
21 #include <algorithm>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <TDirectory.h>
25 #include <TH1I.h>
26 #include <TH2F.h>
27 #include <TProfile.h>
29 #include "TRIGGER/DTrigger.h"
30 
31 #include <thread>
32 
33 using namespace jana;
34 
35 // Routine used to create our JEventProcessor
36 #include <JANA/JApplication.h>
37 #include <JANA/JFactory.h>
38 
39 const int nChan = 2800;
40 
41 // Define Histograms
42 static TH1I* Offsets[nChan];
43 
44 extern "C"{
45  void InitPlugin(JApplication *app){
46  InitJANAPlugin(app);
47  app->AddProcessor(new JEventProcessor_FCAL_TimingOffsets());
48  }
49 } // "C"
50 
51 //------------------
52 // JEventProcessor_FCAL_TimingOffsets (Constructor)
53 //------------------
55 {
56 
57 }
58 
59 //------------------
60 // ~JEventProcessor_FCAL_TimingOffsets (Destructor)
61 //------------------
63 {
64 
65 }
66 
67 //------------------
68 // init
69 //------------------
71 {
72  // This is called once at program startup. If you are creating
73  // and filling historgrams in this plugin, you should lock the
74  // ROOT mutex like this:
75  //
76  TDirectory *main = gDirectory;
77  gDirectory->mkdir("FCAL_TimingOffsets")->cd();
78 
79 
80  for (int i = 0; i < nChan; ++i) {
81  Offsets[i] = new TH1I(Form("Offset_%i",i),Form("Timing Offset for Channel %i",i),800,-50,50);
82  }
83 
84  main->cd();
85  return NOERROR;
86 }
87 
88 //------------------
89 // brun
90 //------------------
91 jerror_t JEventProcessor_FCAL_TimingOffsets::brun(JEventLoop *eventLoop,
92  int32_t runnumber)
93 {
94 
95  // get the FCAL z position from the global geometry interface
96  DApplication *dapp =
97  dynamic_cast<DApplication*>(eventLoop->GetJApplication());
98  const DGeometry *geom = dapp->GetDGeometry(runnumber);
99  if( geom ) {
100 
101  geom->GetFCALZ( m_FCALfront );
102  }
103  else{
104 
105  cerr << "No geometry accessbile." << endl;
106  return RESOURCE_UNAVAILABLE;
107  }
108 
109  return NOERROR;
110 }
111 
112 //------------------
113 // evnt
114 //------------------
115 jerror_t JEventProcessor_FCAL_TimingOffsets::evnt(JEventLoop *eventLoop,
116  uint64_t eventnumber)
117 {
118 
119  // select events with physics events, i.e., not LED and other front panel triggers
120  const DTrigger* locTrigger = NULL;
121  eventLoop->GetSingle(locTrigger);
122  if(locTrigger->Get_L1FrontPanelTriggerBits() != 0)
123  return NOERROR;
124 
125 
126  // we need an FCAL Geometry object
127  vector< const DFCALGeometry* > geomVec;
128  eventLoop->Get( geomVec );
129 
130  if( geomVec.size() != 1 ){
131 
132  cerr << "No geometry accessbile." << endl;
133  return RESOURCE_UNAVAILABLE;
134  }
135 
136  auto fcalGeom = geomVec[0];
137 
138 
139  double FCAL_C_EFFECTIVE = 15.0;
140  DApplication* locApplication = dynamic_cast<DApplication*>(eventLoop->GetJApplication());
141  DGeometry* locGeometry = locApplication->GetDGeometry(eventLoop->GetJEvent().GetRunNumber());
142  double locTargetZCenter = 0.0;
143  locTargetZCenter = locGeometry->GetTargetZ(locTargetZCenter);
144  dTargetCenter.SetXYZ(0.0, 0.0, locTargetZCenter);
145 
146  vector< const DFCALDigiHit* > digiHits;
147  vector< const DFCALHit* > hits;
148  vector<const DEventRFBunch*> locEventRFBunches;
149  vector< const DVertex* > kinfitVertex;
150  vector< const DTrackTimeBased* > locTrackTimeBased;
151  vector < const DFCALShower * > matchedShowers;
152 
153 
154  eventLoop->Get( hits );
155 
156  vector< const DFCALShower* > locFCALShowers;
157 
158  if( hits.size() < 500 ){ // only form clusters and showers if there aren't too many hits
159  eventLoop->Get(locFCALShowers);
160  eventLoop->Get(locEventRFBunches);
161  eventLoop->Get(locTrackTimeBased);
162  }
163 
164  double locStartTime = locEventRFBunches.empty() ? 0.0 : locEventRFBunches[0]->dTime;
165 
166  DVector3 norm(0.0,0.0,-1);
167  DVector3 pos,mom;
168 
169 
170  for (unsigned int i=0; i < locTrackTimeBased.size() ; ++i){
171  vector<DTrackFitter::Extrapolation_t>extrapolations=locTrackTimeBased[i]->extrapolations.at(SYS_FCAL);
172  if (extrapolations.size()>0){
173  for (unsigned int j=0; j< locFCALShowers.size(); ++j){
174 
175  Double_t x = locFCALShowers[j]->getPosition().X();
176  Double_t y = locFCALShowers[j]->getPosition().Y();
177  pos=extrapolations[0].position;
178  Double_t trkmass = locTrackTimeBased[i]->mass();
179  Double_t FOM = TMath::Prob(locTrackTimeBased[i]->chisq, locTrackTimeBased[i]->Ndof);
180  Double_t dRho = sqrt(((pos.X() - x)*(pos.X() - x)) + ((pos.Y() - y)* (pos.Y() - y)));
181 
182  if(trkmass < 0.15 && dRho < 5 && FOM > 0.0001 ) {
183  matchedShowers.push_back(locFCALShowers[j]);
184  }
185  }
186 
187  }
188  }
189 
190 
191 
192 
193 
194  for(unsigned int k=0; k<locFCALShowers.size(); k++)
195  {
196  if (find(matchedShowers.begin(), matchedShowers.end(),locFCALShowers[k]) != matchedShowers.end()) continue;
197 
198 const DFCALShower *s1 = locFCALShowers[k];
199 
200 
201  double pos_corrected_Z = locFCALShowers[k]->getPosition().Z();
202 
203  // Get the clusters from the showers
204  vector <const DFCALCluster *> clusterVector;
205  s1->Get(clusterVector);
206 
207  // Loop over clusters within the shower
208  for (unsigned int iCluster = 0; iCluster < clusterVector.size(); iCluster++){
209  // Get the hits
210  const vector<DFCALCluster::DFCALClusterHit_t> hitVector = clusterVector[iCluster]->GetHits();
211 
212  //Loop over hits
213  for (unsigned int iHit = 0; iHit < 1; iHit++){
214  double hitEnergy = hitVector[iHit].E;
215  if (hitEnergy <= 0.4) continue;
216  double hitTime = hitVector[iHit].t;
217  double tCorr = ( m_FCALfront + DFCALGeometry::blockLength() - pos_corrected_Z )/FCAL_C_EFFECTIVE;
218  hitTime -= tCorr; // Apply the t corection used for the cluster/shower conversion
219 
220  int chanx = hitVector[iHit].x;
221  int chany = hitVector[iHit].y;
222  int ChannelNumber = hitVector[iHit].ch;
223 
224  dFCALblockcenter.SetXYZ(chanx, chany, pos_corrected_Z);
225 
226  double locPathLength = (dFCALblockcenter - dTargetCenter).Mag();
227  double locDeltaT = hitTime - locPathLength/29.9792458 - locStartTime;
228 
229  Offsets[ChannelNumber]->Fill(locDeltaT);
230 
231  }
232  }
233  }
234 
235 
236 
237 
238 
239 
240 
241 
242 
243 return NOERROR;
244 }
245 
246 //------------------
247 // erun
248 //------------------
250 {
251  // This is called whenever the run number changes, before it is
252  // changed to give you a chance to clean up before processing
253  // events from the next run number.
254  return NOERROR;
255 }
256 
257 //------------------
258 // fini
259 //------------------
261 {
262 
263  // Called before program exit after event processing is finished.
264  return NOERROR;
265 }
266 
267 
DApplication * dapp
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
static double blockLength()
Definition: DFCALGeometry.h:50
TVector3 DVector3
Definition: DVector3.h:14
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
#define y
jerror_t init(void)
Called once at program start.
uint32_t Get_L1FrontPanelTriggerBits(void) const
bool GetFCALZ(double &z_fcal) const
z-location of front face of CCAL in cm
Definition: DGeometry.cc:1718
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
InitPlugin_t InitPlugin
DGeometry * GetDGeometry(unsigned int run_number)
Definition: GlueX.h:22
double sqrt(double)
static TH1I * Offsets[nChan]
bool GetTargetZ(double &z_target) const
z-location of center of target
Definition: DGeometry.cc:1933
jerror_t fini(void)
Called after last event of last event source has been processed.
int main(int argc, char *argv[])
Definition: gendoc.cc:6
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.