Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DEventProcessor_fcal_charged.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DEventProcessor_fcal_charged.cc
4 // Modified version of BCAL_Eff
5 //
6 
8 
9 #include <TLorentzVector.h>
10 #include "TMath.h"
11 
12 #include "DANA/DApplication.h"
13 #include "BCAL/DBCALShower.h"
14 #include "BCAL/DBCALTruthShower.h"
15 #include "BCAL/DBCALCluster.h"
16 #include "BCAL/DBCALPoint.h"
17 #include "BCAL/DBCALHit.h"
18 #include "FCAL/DFCALShower.h"
19 #include "FCAL/DFCALCluster.h"
20 #include "TRACKING/DMCThrown.h"
22 //#include "TRACKING/DTrackFinder.h"
23 #include "GlueX.h"
24 
25 #include "BCAL/DBCALGeometry.h"
26 #include "FCAL/DFCALGeometry.h"
27 
28 #include "TOF/DTOFPoint.h"
29 #include "DVector3.h"
30 #include <vector>
31 #include <deque>
32 #include <string>
33 #include <iostream>
34 #include <algorithm>
35 #include <stdio.h>
36 #include <stdlib.h>
37 
39 
40 
41 static TH1I* h1_stats = NULL;
42 static TH1I* h1_deltaX = NULL;
43 static TH1I* h1_deltaY = NULL;
44 static TH1I* h1_deltaX_tof = NULL;
45 static TH1I* h1_deltaY_tof = NULL;
46 static TH1I* h1_Efcal = NULL;
47 static TH1I* h1_Ebcal = NULL;
48 static TH1I* h1_tfcal = NULL;
49 static TH1I* h1_intOverPeak = NULL;
50 
51 static TH1I* h1_N9 = NULL;
52 static TH1I* h1_E9 = NULL;
53 static TH1I* h1_t9 = NULL;
54 static TH1I* h1_t9sigma = NULL;
55 static TH1I* h1_N1 = NULL;
56 static TH1I* h1_E1 = NULL;
57 static TH1I* h1_t1 = NULL;
58 static TH1I* h1_t1sigma = NULL;
59 
60 static TH2I* h2_dEdx_vsp = NULL;
61 static TH2I* h2_dEdx9_vsp = NULL;
62 static TH2I* h2_YvsX9 = NULL;
63 static TH2I* h2_YvsXcheck = NULL;
64 static TH2I* h2_YvsX1 = NULL;
65 static TH2I* h2_E9vsp = NULL;
66 static TH2I* h2_E1vsp = NULL;
67 static TH2I* h2_E2vsp = NULL;
68 static TH2I* h2_E1vspPos = NULL;
69 static TH2I* h2_dEdxvsE9 = NULL;
70 static TH2I* h2_intOverPeak_vsEfcal = NULL;
71 static TH2I* h2_E1_vsintOverPeak = NULL;
72 static TH2I* h2_E1peak_vsp = NULL;
73 static TH2I* h2_E1vsRlocal = NULL;
74 static TH2I* h2_E9_vsTheta = NULL;
75 static TH2I* h2_E9_vsPhi = NULL;
76 static TH2I* h2_E1_vsTheta = NULL;
77 static TH2I* h2_E1_vsPhi = NULL;
78 static TH2D* h2_E9_vsThetaPhiw = NULL;
79 static TH2D* h2_E1_vsThetaPhiw = NULL;
80 static TH2D* h2_E1_vsThetaPhi = NULL;
81 
82 
83 
84 
85 // Routine used to create our DEventProcessor
86 
87 extern "C"
88 {
89  void InitPlugin(JApplication *locApplication)
90  {
91  InitJANAPlugin(locApplication);
92  locApplication->AddProcessor(new DEventProcessor_fcal_charged()); //register this plugin
93  }
94 } // "C"
95 
96 //------------------
97 // init
98 //------------------
100 {
101  // First thread to get here makes all histograms. If one pointer is
102  // already not NULL, assume all histograms are defined and return now
103  if(h1_deltaX != NULL){
104  printf ("TEST>> DEventProcessor_fcal_charged::init - Other threads continue\n");
105  return NOERROR;
106  }
107 
108 
109  // ... create historgrams or trees ...
110 
111  // TDirectory *dir = new TDirectoryFile("FCAL","FCAL");
112  // dir->cd();
113  // create root folder for bcal and cd to it, store main dir
114  TDirectory *main = gDirectory;
115  gDirectory->mkdir("fcal_charged")->cd();
116 
117 
118  // double pi0_mass = 0.1349766;
119  int const nbins=100;
120 
121  h1_stats = new TH1I("h1_stats", "Run Statistics", 20,0,20);
122 
123  h1_deltaX = new TH1I("h1_deltaX", "Fcal X - Track X", nbins,-25,25);
124  h1_deltaX->SetXTitle("Fcal - Track X (cm)");
125  h1_deltaX->SetYTitle("counts");
126  h1_deltaY = new TH1I("h1_deltaY", "Fcal Y - Track X", nbins,-25,25);
127  h1_deltaY->SetXTitle("Fcal - Track Y (cm)");
128  h1_deltaY->SetYTitle("counts");
129 
130  h1_deltaX_tof = new TH1I("h1_deltaX_tof", "TOF X - Track X E1", nbins,-25,25);
131  h1_deltaX_tof->SetXTitle("TOF X - Track X (cm)");
132  h1_deltaX_tof->SetYTitle("counts");
133  h1_deltaY_tof = new TH1I("h1_deltaY_tof", "TOF Y - Track Y E1", nbins,-25,25);
134  h1_deltaY_tof->SetXTitle("TOF Y - Track Y (cm)");
135  h1_deltaY_tof->SetYTitle("counts");
136 
137  h1_Ebcal = new TH1I("h1_Ebcal", "Sum of point energy", nbins,0,1);
138  h1_Ebcal->SetXTitle("Bcal point energy (GeV)");
139  h1_Ebcal->SetYTitle("counts");
140 
141  h1_Efcal = new TH1I("h1_Efcal", "Hit energy", nbins,0,4);
142  h1_Efcal->SetXTitle("Fcal hit energy (GeV)");
143  h1_Efcal->SetYTitle("counts");
144  h1_tfcal = new TH1I("h1_tfcal", "Hit time", 250,-25,225);
145  h1_tfcal->SetXTitle("Fcal hit time (ns)");
146  h1_tfcal->SetYTitle("counts");
147  h1_intOverPeak = new TH1I("h1_intOverPeak", "Hit intOverPeak",nbins,0,25);
148  h1_intOverPeak->SetXTitle("Fcal hit intOverPeak");
149  h1_intOverPeak->SetYTitle("counts");
150 
151  h2_dEdx_vsp = new TH2I("h2_dEdx_vsp", "Track dEdx vs p",nbins,0,4,nbins,0,10);
152  h2_dEdx_vsp->SetXTitle("p (GeV/c)");
153  h2_dEdx_vsp->SetYTitle("dEdx (keV/cm)");
154  h2_dEdx9_vsp = new TH2I("h2_dEdx9_vsp", "Track dEdx9 vs p",nbins,0,4,nbins,0,10);
155  h2_dEdx9_vsp->SetXTitle("p (GeV/c)");
156  h2_dEdx9_vsp->SetYTitle("dEdx (keV/cm)");
157 
158  h1_N9 = new TH1I("h1_N9", "Hit N9",25,0,25);
159  h1_N9->SetXTitle("Number of Hits N9");
160  h1_N9->SetYTitle("counts");
161  h1_E9 = new TH1I("h1_E9", "Energy E9",nbins,0,2);
162  h1_E9->SetXTitle("Energy E9 (GeV)");
163  h1_E9->SetYTitle("counts");
164  h1_t9 = new TH1I("h1_t9", "Time t9",250,-25,225);
165  h1_t9->SetXTitle("Time t9 (ns)");
166  h1_t9->SetYTitle("counts");
167  h1_t9sigma = new TH1I("h1_t9sigma", "Time t9sigma",nbins,0,10);
168  h1_t9sigma->SetXTitle("Time spread t9sigma (ns)");
169  h1_t9sigma->SetYTitle("counts");
170 
171  h2_YvsX9 = new TH2I("h2_YvsX9", "Hit position Y vs X, E9",240,-120,120,240,-120,120);
172  h2_YvsX9->SetXTitle("X (cm)");
173  h2_YvsX9->SetYTitle("Y (cm)");
174  h2_YvsXcheck = new TH2I("h2_YvsXcheck", "Delta Hit Y vs X Checkered",nbins,-5,5,nbins,-5,5);
175  h2_YvsXcheck->SetXTitle("X (cm)");
176  h2_YvsXcheck->SetYTitle("Y (cm)");
177  h2_E1vsRlocal = new TH2I("h2_E1vsRlocal", "E1 vs Rtrk rel to Block center (cm)",nbins,0,5,nbins,0,4);
178  h2_E1vsRlocal->SetXTitle("Rlocal (cm)");
179  h2_E1vsRlocal->SetYTitle("E1 (GeV)");
180  h2_E9vsp = new TH2I("h2_E9vsp", "E9 vs p",nbins,0,4,nbins,0,4);
181  h2_E9vsp->SetXTitle("p (GeV)");
182  h2_E9vsp->SetYTitle("E9 (GeV)");
183  h2_dEdxvsE9 = new TH2I("h2_dEdxvsE9", "dEdx vs E9 energy",nbins,0,4,nbins,0,4);
184  h2_dEdxvsE9->SetXTitle("E9 (GeV)");
185  h2_dEdxvsE9->SetYTitle("dEdx (keV/cm)");
186 
187  h1_N1 = new TH1I("h1_N1", "Hit N1",25,0,25);
188  h1_N1->SetXTitle("Number of Hits N1");
189  h1_N1->SetYTitle("counts");
190  h1_E1 = new TH1I("h1_E1", "Energy E1",nbins,0,2);
191  h1_E1->SetXTitle("Energy E1 (GeV)");
192  h1_E1->SetYTitle("counts");
193  h1_t1 = new TH1I("h1_t1", "Time t1",250,-25,225);
194  h1_t1->SetXTitle("Time t1 (ns)");
195  h1_t1->SetYTitle("counts");
196  h1_t1sigma = new TH1I("h1_t1sigma", "Time t1sigma",nbins,0,10);
197  h1_t1sigma->SetXTitle("Time spread t1sigma (ns)");
198  h1_t1sigma->SetYTitle("counts");
199 
200  h2_YvsX1 = new TH2I("h2_YvsX1", "Hit position Y vs X, E1",240,-120,120,240,-120,120);
201  h2_YvsX1->SetXTitle("X (cm)");
202  h2_YvsX1->SetYTitle("Y (cm)");
203  h2_E1vsp = new TH2I("h2_E1vsp", "E1 vs p",nbins,0,4,nbins,0,4);
204  h2_E1vsp->SetXTitle("p (GeV)");
205  h2_E1vsp->SetYTitle("E1 (GeV)");
206  h2_E2vsp = new TH2I("h2_E2vsp", "E2 vs p",nbins,0,4,nbins,0,4);
207  h2_E2vsp->SetXTitle("p (GeV)");
208  h2_E2vsp->SetYTitle("E2 (GeV)");
209  h2_E1vspPos = new TH2I("h2_E1vspPos", "E1 vs p Q>0",nbins,0,4,nbins,0,4);
210  h2_E1vspPos->SetXTitle("p (GeV)");
211  h2_E1vspPos->SetYTitle("E1 (GeV)");
212  h2_E1peak_vsp = new TH2I("h2_E1peak_vsp", "E1peak*6 vs p",nbins,0,4,nbins,0,4);
213  h2_E1peak_vsp->SetXTitle("p (GeV)");
214  h2_E1peak_vsp->SetYTitle("E1 peak*6(GeV)");
215  h2_intOverPeak_vsEfcal = new TH2I("h2_intOverPeak_vsEfcal", "intOverPeak vs Efcal",nbins,0,1,nbins,0,25);
216  h2_intOverPeak_vsEfcal->SetXTitle("Efcal (GeV)");
217  h2_intOverPeak_vsEfcal->SetYTitle("IntOverPeak");
218  h2_E1_vsintOverPeak = new TH2I("h2_E1_vsintOverPeak", "E1 vs intOverPeak",nbins,0,25,nbins,0,4);
219  h2_E1_vsintOverPeak->SetXTitle("IntOverPeak");
220  h2_E1_vsintOverPeak->SetYTitle("E1 (GeV)");
221 
222  h2_E9_vsTheta = new TH2I("h2_E9_vsTheta", "E9 vs Theta",90,0,30,nbins,0,4);
223  h2_E9_vsTheta->SetXTitle("Theta (deg)");
224  h2_E9_vsTheta->SetYTitle("E9 (GeV)");
225  h2_E1_vsTheta = new TH2I("h2_E1_vsTheta", "E1 vs Theta",90,0,30,nbins,0,4);
226  h2_E1_vsTheta->SetXTitle("Theta (deg)");
227  h2_E1_vsTheta->SetYTitle("E1 (GeV)");
228  h2_E9_vsPhi = new TH2I("h2_E9_vsPhi", "E9 vs Phi",90,-180,180,nbins,0,4);
229  h2_E9_vsPhi->SetXTitle("Phi (deg)");
230  h2_E9_vsPhi->SetYTitle("E9 (GeV)");
231  h2_E1_vsPhi = new TH2I("h2_E1_vsPhi", "E1 vs Phi",90,-180,180,nbins,0,4);
232  h2_E1_vsPhi->SetXTitle("Phi (deg)");
233  h2_E1_vsPhi->SetYTitle("E1 (GeV)");
234 
235  h2_E9_vsThetaPhiw = new TH2D("h2_E9_vsThetaPhiw", "E9 vs ThetaPhiw",90,-180,180,90,0,30);
236  h2_E9_vsThetaPhiw->SetXTitle("Phi (deg)");
237  h2_E9_vsThetaPhiw->SetYTitle("Theta (deg)");
238  h2_E1_vsThetaPhi = new TH2D("h2_E1_vsThetaPhi", "Unity vs ThetaPhi",90,-180,180,90,0,30);
239  h2_E1_vsThetaPhi->SetXTitle("Phi (deg)");
240  h2_E1_vsThetaPhi->SetYTitle("Theta (deg)");
241  h2_E1_vsThetaPhiw = new TH2D("h2_E1_vsThetaPhiw", "E1 vs ThetaPhiw",90,-180,180,90,0,30);
242  h2_E1_vsThetaPhiw->SetXTitle("Phi (deg)");
243  h2_E1_vsThetaPhiw->SetYTitle("Theta (deg)");
244 
245  // back to main dir
246  printf ("TEST>> DEventProcessor_fcal_charged::init - First thread created histograms\n");
247  main->cd();
248 
249  return NOERROR;
250 }
251 
252 
253 //------------------
254 // brun
255 //------------------
256 jerror_t DEventProcessor_fcal_charged::brun(jana::JEventLoop* locEventLoop, int locRunNumber)
257 {
258  // This is called whenever the run number changes
259  //BCAL_Neutrals->Fill();
260  //cout << " run number = " << RunNumber << endl;
261  /*
262  //Optional: Retrieve REST writer for writing out skims
263  locEventLoop->GetSingle(dEventWriterREST);
264  */
265 
266  //vector<const DTrackFinder *> finders;
267  //locEventLoop->Get(finders);
268  //finder = const_cast<DTrackFinder*>(finders[0]);
269 
270  /*
271  //Recommeded: Create output ROOT TTrees (nothing is done if already created)
272  locEventLoop->GetSingle(dEventWriterROOT);
273  dEventWriterROOT->Create_DataTrees(locEventLoop);
274  */
275 
276  return NOERROR;
277 }
278 
279 //------------------
280 // evnt
281 //------------------
282 
283 
284 jerror_t DEventProcessor_fcal_charged::evnt(jana::JEventLoop* locEventLoop, int locEventNumber)
285 {
286 
287  // This is called for every event. Use of common resources like writing
288  // to a file or filling a histogram should be mutex protected. Using
289  // locEventLoop->Get(...) to get reconstructed objects (and thereby activating the
290  // reconstruction algorithm) should be done outside of any mutex lock
291  // since multiple threads may call this method at the same time.
292  //
293  // Here's an example:
294  //
295  // vector<const MyDataClass*> mydataclasses;
296  // locEventLoop->Get(mydataclasses);
297  //
298  // japp->RootWriteLock();
299  // ... fill historgrams or trees ...
300  // japp->RootUnLock();
301 
302  // DOCUMENTATION:
303  // ANALYSIS library: https://halldweb1.jlab.org/wiki/index.php/GlueX_Analysis_Software
304 
305  vector<const DFCALShower*> locFCALShowers;
306  vector<const DBCALPoint*> bcalpoints;
307  vector<const DTOFPoint*> tofpoints;
308  vector<const DFCALHit*> fcalhits;
309  vector<const DFCALCluster*> locFCALClusters;
310  vector<const DVertex*> kinfitVertex;
311  //const DDetectorMatches* locDetectorMatches = NULL;
312  //locEventLoop->GetSingle(locDetectorMatches);
313  locEventLoop->Get(locFCALShowers);
314  locEventLoop->Get(bcalpoints);;
315  locEventLoop->Get(tofpoints);
316  locEventLoop->Get(fcalhits);
317  locEventLoop->Get(locFCALClusters);
318  locEventLoop->Get(kinfitVertex);
319 
320  vector<const DChargedTrack*> locChargedTrack;
321  locEventLoop->Get(locChargedTrack);
322 
323  DVector3 trkpos(0.0,0.0,0.0);
324  DVector3 proj_mom(0.0,0.0,0.0);
325  DVector3 trkpos_tof(0.0,0.0,0.0);
326  DVector3 proj_mom_tof(0.0,0.0,0.0);
327  Double_t zfcal=638;
328  Double_t ztof=618.8;
329  DVector3 fcal_origin(0.0,0.0,zfcal);
330  DVector3 fcal_normal(0.0,0.0,1.0);
331  DVector3 tof_origin(0.0,0.0,ztof);
332  DVector3 tof_normal(0.0,0.0,1.0);
333 
334  /* Double_t Lfcal=45.;
335  Double_t zfcal_back=zfcal+Lfcal;
336  DVector3 trkpos_fcal_back(0.0,0.0,0.0);;
337  DVector3 proj_mom_back(0.0,0.0,0.0);
338  DVector3 fcal_origin_back(0.0,0.0,zfcal_back);
339  DVector3 fcal_normal_back(0.0,0.0,1.0);*/
340 
341  if (locEventNumber%100 == 0) printf ("EventNumber=%d\n",locEventNumber);
342 
343  // FILL HISTOGRAMS
344  // Since we are filling histograms local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
345  japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
346 
347  double p;
348  double dEdx;
349  double pmin=1;
350 
351 
352  for (unsigned int i=0; i < locChargedTrack.size() ; ++i){
353  const DChargedTrack *ctrk = locChargedTrack[i];
354  const DChargedTrackHypothesis *bestctrack = ctrk->Get_BestFOM();
355  vector<const DTrackTimeBased*> locTrackTimeBased;
356  bestctrack->Get(locTrackTimeBased); // locTrackTimeBased[0] contains the best FOM track
357 
358  double FOM = TMath::Prob(locTrackTimeBased[0]->chisq, locTrackTimeBased[0]->Ndof);
359 
360  // get intersection with fcal front face and backface;
361  vector<DTrackFitter::Extrapolation_t>extrapolations=locTrackTimeBased[0]->extrapolations.at(SYS_FCAL);
362  if (extrapolations.size()>0){
363  trkpos=extrapolations[0].position;
364  h1_stats->Fill(0);
365 
366  vector<DTrackFitter::Extrapolation_t>tof_extrapolations=locTrackTimeBased[0]->extrapolations.at(SYS_TOF);
367  if (tof_extrapolations.size()==0) continue;
368  h1_stats->Fill(1);
369  trkpos_tof=tof_extrapolations[0].position;
370 
371  // sum up all energy and Bcal and keep only if likely BCAL trigger
372 
373  float bcal_energy = 0;
374  for (unsigned int j=0; j < bcalpoints.size(); ++j) {
375  bcal_energy += bcalpoints[j]->E();
376  }
377  if (bcal_energy < 0.15) {
378  continue; // require that bcal be sufficient for trigger
379  }
380  h1_Ebcal->Fill(bcal_energy);
381  h1_stats->Fill(2);
382 
383 
384  double q = locTrackTimeBased[0]->charge();
385  p = locTrackTimeBased[0]->momentum().Mag();
386  double trkmass = locTrackTimeBased[0]->mass();
387 
388  double radius = sqrt(trkpos.X()*trkpos.X() + trkpos.Y()*trkpos.Y()); // distance of track from beamline
389  dEdx = (locTrackTimeBased[0]->dNumHitsUsedFordEdx_CDC >= locTrackTimeBased[0]->dNumHitsUsedFordEdx_FDC) ? locTrackTimeBased[0]->ddEdx_CDC_amp : locTrackTimeBased[0]->ddEdx_FDC;
390  dEdx *= 1e6; // convert to keV
391  if(!(trkmass < 0.15 && FOM>0.01 && radius>20)) {
392  continue; // select tracks of interest
393  }
394  h1_stats->Fill(3);
395 
396  if (! (p>pmin)) {
397  continue; // require minimum momentum to pion analyzis
398  }
399  h1_stats->Fill (4);
400 
401  h2_dEdx_vsp->Fill(p,dEdx);
402  // use position at the back of fcal // asume zero field out here
403  // double xfcal_back = trkpos.X() + proj_mom.X()*Lfcal/proj_mom.Z();
404  // double yfcal_back = trkpos.Y() + proj_mom.Y()*Lfcal/proj_mom.Z();
405  double trkposX = trkpos.X();
406  double trkposY = trkpos.Y();
407  int trkrow = fcalgeom.row((float)trkposY);
408  int trkcol = fcalgeom.column((float)trkposX);
409  double dX_tof = 10000;
410  double dY_tof = 10000;
411  double dR_tof = 10000;
412 
413  // get tof matches
414 
415  for (unsigned int j=0; j < tofpoints.size(); ++j) {
416  double tofx = 10000;
417  double tofy = 10000;
418  if (tofpoints[j]->Is_XPositionWellDefined() && tofpoints[j]->Is_YPositionWellDefined()) {
419  DVector3 pos_tof = tofpoints[j]->pos;
420  tofx = pos_tof.X();
421  tofy = pos_tof.Y();
422  printf ("Event=%d tofx=%f, tofy=%f, trkx=%f, trky=%f \n",locEventNumber,tofx,tofy,trkposX,trkposY);
423  double dX_tof1 = tofx - trkpos_tof.X();
424  double dY_tof1 = tofy - trkpos_tof.Y();
425  if (sqrt(dX_tof1*dX_tof1 + dY_tof1*dY_tof1) < dR_tof) {
426  dX_tof = dX_tof1;
427  dY_tof = dY_tof1;
428  dR_tof = sqrt(dX_tof*dX_tof + dY_tof*dY_tof);
429  }
430  }
431  }
432 
433  printf ("\n1 Event=%d dX_tof=%f, DY_tof=%f, trkx=%f, trky=%f \n",locEventNumber,dX_tof,dY_tof,trkposX,trkposY);
434  if ( !(abs(dX_tof)<10 && abs(dY_tof)<10) ) continue;
435 
436  h1_stats->Fill(5);
437  printf ("2 Event=%d dX_tof=%f, DY_tof=%f, trkx=%f, trky=%f \n",locEventNumber,dX_tof,dY_tof,trkposX,trkposY);
438  printf ("Event=%d trkmass=%f radius=%f p=%f dEdx=%g,trkrow=%d trkcol=%d x=%f y=%f z=%f\n",locEventNumber,trkmass,radius,p,dEdx,trkrow,trkcol,trkposX,trkposY,trkpos.Z());
439 
440  // get components of p at FCAL
441  // double theta = proj_mom.Theta()*TVector3::RAD2DEG;
442  double theta = proj_mom.Theta()*180./M_PI;
443  double phi = proj_mom.Phi()*180./M_PI;
444  printf ("Event=%d p=%f,theta=%f, phi=%f\n",locEventNumber,p,theta,phi);
445 
446 
447  // loop over fcal hits
448 
449  double E9=0; // energy, x, y of 9 blocks surrounding track
450  double E9peak=0;
451  double x9=0;
452  double y9=0;
453  double t9=0;
454  double t9sq=0;
455  double t9sigma=0;
456  int N9=0;
457  int Delta_block=2; // =1 for 3x3, =2 for 5x5
458  //int row_E1=-1000;
459  //int col_E1=-1000;
460  //int drow_E1=1000;
461  //int dcol_E1=1000;
462  double dX_E1=-1000;
463  double dY_E1=-1000;
464 
465  int row_offset = 0; // offset actual row to look for randoms
466  int col_offset = 0;
467  trkrow += row_offset;
468  trkcol += col_offset;
469 
470  for (unsigned int j=0; j < fcalhits.size(); ++j) {
471  int row = fcalhits[j]->row;
472  int col = fcalhits[j]->column;
473  double x = fcalhits[j]->x;
474  double y = fcalhits[j]->y;
475  double Efcal = fcalhits[j]->E;
476  double tfcal= fcalhits[j]->t;
477  double intOverPeak = fcalhits[j]->intOverPeak;
478  // printf ("Event=%d row=%d col=%d x=%f y=%f Efcal=%f tfcal=%f intOverPeak=%f\n",locEventNumber,row,col,x,y,Efcal,tfcal,intOverPeak);
479 
480  // fill histograms
481  int drow = abs(row - trkrow);
482  int dcol = abs(col - trkcol);
483 
484  h1_deltaX->Fill(x - trkposX);
485  h1_deltaY->Fill(y - trkposY);
486  h1_Efcal->Fill(Efcal);
487  h1_tfcal->Fill(tfcal);
488  h1_intOverPeak->Fill(intOverPeak);
489  h2_intOverPeak_vsEfcal->Fill(Efcal,intOverPeak);
490 
491  // select hits
492  if (drow<=Delta_block && dcol<=Delta_block && (tfcal>-15 && tfcal<50) && (intOverPeak>2.5 && intOverPeak<9)) {
493  // if (drow<=Delta_block && dcol<=Delta_block && (tfcal>-15 && tfcal<50)) {
494  E9 += Efcal;
495  E9peak += Efcal*6/intOverPeak; // factor of 6 so that E9peak ~ E9
496  x9 += x;
497  y9 += y;
498  t9 += tfcal;
499  t9sq += tfcal*tfcal;
500  N9 += 1;
501 
502  //save for later
503  //row_E1 = row;
504  //col_E1 = col;
505  //drow_E1 = drow;
506  //dcol_E1 = dcol;
507  dX_E1 = x - trkposX;
508  dY_E1 = y - trkposY;
509  printf ("Event=%d, trkposX=%f, trkposY=%f, dX_E1=%f, dY_E1=%f\n",locEventNumber,trkposX,trkposY,dX_E1,dY_E1);
510  }
511 
512  } // end loop over fcal hits
513 
514  x9 = N9>0? x9/N9 : 0;
515  y9 = N9>0? y9/N9 : 0;
516  t9 = N9>0? t9/N9 : 0;
517  t9sigma = N9>0? sqrt(t9sq/N9 - t9*t9): 0;
518  // printf ("\nEvent=%d N9=%d E9=%f x9=%f y9=%f t9=%f t9sigma=%f\n",locEventNumber,N9,E9,x9,y9,t9,t9sigma);
519 
520 
521  h1_stats->Fill(6);
522  if (E9 > 0.8 && theta<4) continue;
523  h1_stats->Fill(7);
524  if (N9>0) {
525  h1_N9->Fill(N9);
526  h1_E9->Fill(E9);
527  h1_t9->Fill(t9);
528  h1_t9sigma->Fill(t9sigma);
529  h2_YvsX9->Fill(trkposX,trkposY);
530  h2_dEdx9_vsp->Fill(p,dEdx);
531  h2_E9vsp->Fill(p,E9);
532  h2_dEdxvsE9->Fill(E9,dEdx);
533  h1_stats->Fill(8);
534  h2_E9_vsThetaPhiw->Fill(phi,theta,E9);
535  h2_E9_vsTheta->Fill(theta,E9);
536  h2_E9_vsPhi->Fill(phi,E9);
537  }
538  if (N9==1) {
539  h1_N1->Fill(N9);
540  h1_E1->Fill(E9);
541  h1_t1->Fill(t9);
542  h1_t1sigma->Fill(t9sigma);
543  h2_YvsX1->Fill(trkposX,trkposY);
544  h2_E1vsp->Fill(p,E9);
545  if (q > 0) h2_E1vspPos->Fill(p,E9);
546  h2_E1peak_vsp->Fill(p,E9peak);
547  h2_E1_vsintOverPeak->Fill(E9*6/E9peak,E9); // note that this only works because a single cell fires
548  h1_deltaX_tof->Fill(dX_tof);
549  h1_deltaY_tof->Fill(dY_tof);
550  h1_stats->Fill(9);
551  h2_E1_vsThetaPhi->Fill(phi,theta);
552  h2_E1_vsThetaPhiw->Fill(phi,theta,E9);
553  h2_E1_vsTheta->Fill(theta,E9);
554  h2_E1_vsPhi->Fill(phi,E9);
555  double Rlocal = sqrt(dX_E1*dX_E1 + dY_E1*dY_E1);
556  h2_E1vsRlocal->Fill(Rlocal,E9);
557  // if (((row_E1%2==0 && col_E1%2==0) || (row_E1%2==1 && col_E1%2==1)) ) h2_YvsXcheck->Fill(dX_E1,dY_E1);
558  h2_YvsXcheck->Fill(dX_E1,dY_E1);
559  }
560  if (N9==1 || N9==2) {
561  h2_E2vsp->Fill(p,E9);
562  h1_stats->Fill(10);
563  }
564 
565 
566 
567  } // end track intersection if statement
568  }
569 
570  japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
571 
572 
573  /*
574  //Optional: Save event to output REST file. Use this to create skims.
575  dEventWriterREST->Write_RESTEvent(locEventLoop, "FCAL_Shower"); //string is part of output file name
576  */
577 
578  return NOERROR;
579 }
580 
581 //------------------
582 // erun
583 //------------------
585 {
586  // This is called whenever the run number changes, before it is
587  // changed to give you a chance to clean up before processing
588  // events from the next run number.
589 
590 
591  return NOERROR;
592 }
593 
594 //------------------
595 // fini
596 //------------------
598 {
599  // Called before program exit after event processing is finished.
600 
601  return NOERROR;
602 }
603 
static TH2I * h2_E1peak_vsp
jerror_t erun(void)
Called every time run number changes, provided brun has been called.
static TH2D * h2_E1_vsThetaPhi
static TH2I * h2_E1_vsPhi
TVector3 DVector3
Definition: DVector3.h:14
static TH1I * h1_E9
static TH2I * h2_YvsXcheck
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
static TH1I * h1_deltaY_tof
#define y
static TH1I * h1_Efcal
static TH1I * h1_deltaY
JApplication * japp
static TH1I * h1_t9sigma
static TH1I * h1_tfcal
static TH2I * h2_intOverPeak_vsEfcal
static TH2I * h2_E9_vsPhi
static TH2D * h2_E9_vsThetaPhiw
static TH1I * h1_stats
InitPlugin_t InitPlugin
Definition: GlueX.h:20
static TH2I * h2_YvsX1
static TH2I * h2_dEdx9_vsp
static TH1I * h1_t9
Definition: GlueX.h:22
static TH2I * h2_E9vsp
static TH1I * h1_N1
static TH2I * h2_E1vsp
DFCALGeometry fcalgeom
static TH2I * h2_E1vspPos
static TH2I * h2_E1vsRlocal
jerror_t init(void)
Called once at program start.
int column(int channel) const
Definition: DFCALGeometry.h:65
double sqrt(double)
static TH1I * h1_intOverPeak
jerror_t fini(void)
Called after last event of last event source has been processed.
static TH2I * h2_E9_vsTheta
static TH2I * h2_dEdxvsE9
static TH2D * h2_E1_vsThetaPhiw
static TH2I * h2_YvsX9
static TH1I * h1_Ebcal
jerror_t brun(jana::JEventLoop *locEventLoop, int locRunNumber)
Called every time a new run number is detected.
const DChargedTrackHypothesis * Get_BestFOM(void) const
Definition: DChargedTrack.h:69
int row(int channel) const
Definition: DFCALGeometry.h:64
static TH2I * h2_E1_vsTheta
static TH2I * h2_E1_vsintOverPeak
printf("string=%s", string)
static TH1I * h1_deltaX_tof
static TH1I * h1_deltaX
static TH1I * h1_E1
static TH2I * h2_E2vsp
static TH1I * h1_t1
static TH2I * h2_dEdx_vsp
jerror_t evnt(jana::JEventLoop *locEventLoop, int locEventNumber)
Called every event.
int main(int argc, char *argv[])
Definition: gendoc.cc:6
static TH1I * h1_N9
static TH1I * h1_t1sigma