Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_BCAL_point_time.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_BCAL_point_time.cc
4 // Created: Fri Apr 8 12:59:18 EDT 2016
5 // Creator: dalton (on Linux gluon109.jlab.org 2.6.32-358.23.2.el6.x86_64 x86_64)
6 //
7 
8 #include <stdint.h>
9 #include <vector>
10 
12 #include <JANA/JApplication.h>
13 #include <JANA/JFactory.h>
14 
15 using namespace std;
16 using namespace jana;
17 
18 #include "BCAL/DBCALPoint.h"
19 #include "TRACKING/DMCThrown.h"
20 //#include <DAQ/DF1TDCHit.h>
21 //#include <DAQ/Df250PulseIntegral.h>
22 //#include <DAQ/JEventSource_EVIO.h>
23 //#include <TTAB/DTranslationTable.h>
24 
25 #include <TDirectory.h>
26 #include <TH2.h>
27 #include <TH1.h>
28 #include <TProfile.h>
29 #include <TProfile2D.h>
30 #include <TTree.h>
31 #include <TStyle.h>
32 #include <TROOT.h>
33 
34 static const double degperrad = 180/3.14159265;
35 
36 static const int nummodule=48;
37 static const int numlayer=4;
38 static const int numsector=4;
39 // root hist pointers
46 static TH1I *point_NVsZ_layer[numlayer];
48 static TH1I *thrown_NVsZ;
49 static TH1I *thrown_NVsTheta;
52 
53 static TH2I *test_coords;
54 
60 
61 // Routine used to create our JEventProcessor
62 extern "C"{
63 void InitPlugin(JApplication *app){
64  InitJANAPlugin(app);
65  app->AddProcessor(new JEventProcessor_BCAL_point_time());
66 }
67 } // "C"
68 
69 
70 //------------------
71 // JEventProcessor_BCAL_point_time (Constructor)
72 //------------------
74 {
75  VERBOSE = 0;
76 
77  if(gPARMS){
78  gPARMS->SetDefaultParameter("BCAL_point_time:VERBOSE", VERBOSE, "BCAL_point_time verbosity level");
79  }
80 }
81 
82 //------------------
83 // ~JEventProcessor_BCAL_point_time (Destructor)
84 //------------------
86 {
87 
88 }
89 
90 //------------------
91 // init
92 //------------------
94 {
95  if (VERBOSE>=1) printf("JEventProcessor_pedestal_online::init()\n");
96 
97  // lock all root operations
98  japp->RootWriteLock();
99 
100  gStyle->SetTitleSize(0.06,"xyz");
101  gStyle->SetTitleSize(0.07,"h");
102  gStyle->SetLabelSize(0.06,"xyz");
103 
104 
105  // create root folder for DAQ and cd to it, store main dir
106  maindir = gDirectory;
107  peddir = maindir->mkdir("bcalpointime");
108  peddir->cd();
109 
110  int timebins = 200;
111  float mintime = -5;
112  float maxtime = 45;
113 
114  int zbins = 100;
115  float minz = -80;
116  float maxz = 350;
117 
118  int thetabins = 120;
119  float mintheta = 10;
120  float maxtheta = 130;
121 
122  int timediffbins = 150;
123  float mintimediff = -30;
124  float maxtimediff = 30;
125 
126  int timesumbins = 150;
127  float mintimesum = 20;
128  float maxtimesum = 60;
129 
130  test_coords = new TH2I("test_coords","test_coords",thetabins,mintheta,maxtheta,zbins,minz,maxz);
131 
132  char histname[255], histtitle[255];
133  for (int j=0; j<numlayer; j++) {
134  if (hitus_TimeVsZ_layer_prof[j] == NULL) {
135  sprintf(histname,"hitus_TimeVsZ_layer%i_prof",j+1);
136  sprintf(histtitle,"arrival time;Z (cm);time (ns)");
137  hitus_TimeVsZ_layer_prof[j] = new TProfile(histname,histtitle,zbins,minz,maxz,mintime,maxtime);
138  //int color = j+1; if (color>2) color++;
139  hitus_TimeVsZ_layer_prof[j]->SetLineColor(j+1);
140  hitus_TimeVsZ_layer_prof[j]->SetMarkerColor(j+1);
141  }
142  }
143  for (int j=0; j<numlayer; j++) {
144  if (hitds_TimeVsZ_layer_prof[j] == NULL) {
145  sprintf(histname,"hitds_TimeVsZ_layer%i_prof",j+1);
146  sprintf(histtitle,"arrival time;Z (cm);time (ns)");
147  hitds_TimeVsZ_layer_prof[j] = new TProfile(histname,histtitle,zbins,minz,maxz,mintime,maxtime);
148  hitds_TimeVsZ_layer_prof[j]->SetLineColor(j+1);
149  hitds_TimeVsZ_layer_prof[j]->SetMarkerColor(j+1);
150  }
151  }
152  for (int j=0; j<numlayer; j++) {
153  if (hit_TimediffVsZ_layer_prof[j] == NULL) {
154  sprintf(histname,"hit_TimediffVsZ_layer%i_prof",j+1);
155  sprintf(histtitle,"end time difference;Z (cm);#Delta t (ns)");
156  hit_TimediffVsZ_layer_prof[j] = new TProfile(histname,histtitle,zbins,minz,maxz,mintimediff,maxtimediff);
157  hit_TimediffVsZ_layer_prof[j]->SetLineColor(j+1);
158  hit_TimediffVsZ_layer_prof[j]->SetMarkerColor(j+1);
159  }
160  }
161  for (int j=0; j<numlayer; j++) {
162  if (hit_TimesumVsZ_layer_prof[j] == NULL) {
163  sprintf(histname,"hit_TimesumVsZ_layer%i_prof",j+1);
164  sprintf(histtitle,"end time sum;Z (cm);#Sigma t (ns)");
165  hit_TimesumVsZ_layer_prof[j] = new TProfile(histname,histtitle,zbins,minz,maxz,mintimesum,maxtimesum);
166  hit_TimesumVsZ_layer_prof[j]->SetLineColor(j+1);
167  hit_TimesumVsZ_layer_prof[j]->SetMarkerColor(j+1);
168  }
169  }
170  for (int j=0; j<numlayer; j++) {
171  if (point_TimeVsZ_layer_prof[j] == NULL) {
172  sprintf(histname,"point_TimeVsZ_layer%i_prof",j+1);
173  sprintf(histtitle,"calculated point time;Z (cm);time (ns)");
174  point_TimeVsZ_layer_prof[j] = new TProfile(histname,histtitle,zbins,minz,maxz,mintime,maxtime);
175  point_TimeVsZ_layer_prof[j]->SetLineColor(j+1);
176  point_TimeVsZ_layer_prof[j]->SetMarkerColor(j+1);
177  }
178  }
179 
180  for (int j=0; j<numlayer; j++) {
181  if (hitus_TimeVsZ_layer[j] == NULL) {
182  sprintf(histname,"hitus_TimeVsZ_layer%i",j+1);
183  sprintf(histtitle,"arrival time upstream [layer %i];Z (cm);time (ns)",j+1);
184  hitus_TimeVsZ_layer[j] = new TH2I(histname,histtitle,260,-120,400,timebins,mintime,maxtime);
185  }
186  }
187  for (int j=0; j<numlayer; j++) {
188  if (hitds_TimeVsZ_layer[j] == NULL) {
189  sprintf(histname,"hitds_TimeVsZ_layer%i",j+1);
190  sprintf(histtitle,"arrival time downstream [layer %i];Z (cm);time (ns)",j+1);
191  hitds_TimeVsZ_layer[j] = new TH2I(histname,histtitle,260,-120,400,timebins,mintime,maxtime);
192  }
193  }
194  for (int j=0; j<numlayer; j++) {
195  if (hit_TimediffVsZ_layer[j] == NULL) {
196  sprintf(histname,"hit_TimediffVsZ_layer%i",j+1);
197  sprintf(histtitle,"end time difference [layer %i];Z (cm);#Delta t (ns)",j+1);
198  hit_TimediffVsZ_layer[j] = new TH2I(histname,histtitle,260,-120,400,timediffbins,mintimediff,maxtimediff);
199  }
200  }
201  for (int j=0; j<numlayer; j++) {
202  if (hit_TimesumVsZ_layer[j] == NULL) {
203  sprintf(histname,"hit_TimesumVsZ_layer%i",j+1);
204  sprintf(histtitle,"end time sum [layer %i];Z (cm);#Delta t (ns)",j+1);
205  hit_TimesumVsZ_layer[j] = new TH2I(histname,histtitle,260,-120,400,timesumbins,mintimesum,maxtimesum);
206  }
207  }
208  for (int j=0; j<numlayer; j++) {
209  if (point_TimeVsZ_layer[j] == NULL) {
210  sprintf(histname,"point_TimeVsZ_layer%i",j+1);
211  sprintf(histtitle,"calculated point time [layer %i];Z (cm);time (ns)",j+1);
212  point_TimeVsZ_layer[j] = new TH2I(histname,histtitle,260,-120,400,timebins,mintime,maxtime);
213  }
214  }
215  sprintf(histname,"thrown_NVsZ");
216  sprintf(histtitle,"number of points;Z (cm)");
217  thrown_NVsZ = new TH1I(histname,histtitle,zbins,minz,maxz);
218  sprintf(histname,"thrown_NVsTheta");
219  sprintf(histtitle,"number of points;#theta_{p} (deg)");
220  thrown_NVsTheta = new TH1I(histname,histtitle,thetabins,mintheta,maxtheta);
221 
222  for (int j=0; j<numlayer; j++) {
223  if (point_NormVsZ_layer[j] == NULL) {
224  sprintf(histname,"point_NormVsZ_layer%i",j+1);
225  sprintf(histtitle,"number of points per thrown particle;Z (cm);points/thrown");
226  point_NormVsZ_layer[j] = new TH1F(histname,histtitle,zbins,minz,maxz);
227  point_NormVsZ_layer[j]->SetLineColor(j+1);
228  }
229  }
230  for (int j=0; j<numlayer; j++) {
231  if (point_NormVsTheta_layer[j] == NULL) {
232  sprintf(histname,"point_NormVsTheta_layer%i",j+1);
233  sprintf(histtitle,"number of points per thrown particle;#theta_{p} (cm);points/thrown");
234  point_NormVsTheta_layer[j] = new TH1F(histname,histtitle,thetabins,mintheta,maxtheta);
235  point_NormVsTheta_layer[j]->SetLineColor(j+1);
236  }
237  }
238  for (int j=0; j<numlayer; j++) {
239  if (point_NVsZ_layer[j] == NULL) {
240  sprintf(histname,"point_NVsZ_layer%i",j+1);
241  sprintf(histtitle,"number of points;Z (cm)");
242  point_NVsZ_layer[j] = new TH1I(histname,histtitle,zbins,minz,maxz);
243  point_NVsZ_layer[j]->SetLineColor(j+1);
244  }
245  }
246  for (int j=0; j<numlayer; j++) {
247  if (point_NVsTheta_layer[j] == NULL) {
248  sprintf(histname,"point_NVsTheta_layer%i",j+1);
249  sprintf(histtitle,"number of points;#theta_{p} (deg)");
250  point_NVsTheta_layer[j] = new TH1I(histname,histtitle,thetabins,mintheta,maxtheta);
251  point_NVsTheta_layer[j]->SetLineColor(j+1);
252  }
253  }
254 
255  // Initialise histograms and variables
256  for (int i=0; i<nummodule; i++) {
257  for (int j=0; j<numlayer; j++) {
258  for (int k=0; k<numsector; k++) {
259  sprintf(histname,"point_TimeVsZ_chan_%02i%02i%02i",i,j,k);
260  sprintf(histtitle,"points [%2i,%2i,%2i];Z (cm);time (ns)",i,j,k);
261  point_TimeVsZ_chan[i][j][k] = new TH2I(histname,histtitle,130,-120,400,timebins/2,mintime,maxtime);
262  }
263  }
264  }
265 
266  // back to main dir
267  maindir->cd();
268 
269  // unlock
270  japp->RootUnLock();
271 
272  return NOERROR;
273 
274 }
275 
276 //------------------
277 // brun
278 //------------------
279 jerror_t JEventProcessor_BCAL_point_time::brun(JEventLoop *eventLoop, int32_t runnumber)
280 {
281  // This is called whenever the run number changes
282 
283  return NOERROR;
284 }
285 
286 //------------------
287 // evnt
288 //------------------
289 jerror_t JEventProcessor_BCAL_point_time::evnt(JEventLoop *loop, uint64_t eventnumber)
290 {
291  vector<const DBCALPoint*> points;
292  vector<const DBCALHit*> hits;
293  vector<const DMCThrown*> thrown;
294 
295  loop->Get(points);
296  loop->Get(thrown);
297 
298  // load BCAL geometry
299  vector<const DBCALGeometry *> BCALGeomVec;
300  loop->Get(BCALGeomVec);
301  if(BCALGeomVec.size() == 0)
302  throw JException("Could not load DBCALGeometry object!");
303  auto locBCALGeom = BCALGeomVec[0];
304 
305 
306  // FILL HISTOGRAMS
307  // Since we are filling histograms local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
308  japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
309 
310  if (peddir!=NULL) peddir->cd();
311 
312  float z_coord = 0;
313  float theta_thrown = 0;
314  unsigned int numthrown = thrown.size();
315  if (VERBOSE>=2) printf("event %i, thrown %i\n",(int)eventnumber,numthrown);
316  if (numthrown==1) {
317  float pz = thrown[0]->pz();
318  float pt = sqrt(thrown[0]->px()*thrown[0]->px() + thrown[0]->py()*thrown[0]->py());
319  float z_p = pz/pt * locBCALGeom->GetBCAL_radii()[0];
320  theta_thrown = degperrad*atan2(pt,pz);
321  //float z_targ = thrown[0]->z();
322  z_coord = z_p;
323  test_coords->Fill(theta_thrown,z_coord);
324  thrown_NVsZ->Fill(z_coord);
325  thrown_NVsTheta->Fill(theta_thrown);
326 
327  } else {
328  if (VERBOSE>=1) printf("Event %6lu numthrown %2i \n",eventnumber,numthrown);
329  japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
330  return NOERROR;
331  }
332 
333  unsigned int numpoints = points.size();
334  if (VERBOSE>=2) printf("event %i, points %i\n",(int)eventnumber,numpoints);
335  // Loop over all objects in this event
336  for(unsigned int pointn=0; pointn<numpoints; pointn++){
337  const DBCALPoint *point = points[pointn];
338  int module = point->module();
339  int layer = point->layer();
340  int sector = point->sector();
341  float time = point->t();
342  // float zpos = point->z();
343  float zpos = z_coord;
344 
345  if (module > nummodule || layer > numlayer || sector > numsector) {
346  printf ("(%i,%i,%i) is greater than (%i,%i,%i)\n",module,layer,sector,nummodule,numlayer,numsector);
347  continue;
348  }
349  if (VERBOSE>=3) printf (" point %2i (%i,%i,%i) %8.2f %8.3f\n",pointn,module,layer,sector,zpos,time);
350  point_TimeVsZ_chan[module-1][layer-1][sector-1]->Fill(zpos,time);
351  point_TimeVsZ_layer[layer-1]->Fill(zpos,time);
352  point_TimeVsZ_layer_prof[layer-1]->Fill(zpos,time);
353  point_NVsZ_layer[layer-1]->Fill(zpos);
354  point_NVsTheta_layer[layer-1]->Fill(theta_thrown);
355 
356  point->Get(hits);
357  unsigned int numhits = hits.size();
358  if (VERBOSE>=2) printf("event %i, hits %i\n",(int)eventnumber,numhits);
359 
360  float ustime=0;
361  float dstime=0;
362  // Loop over all hits
363  for(unsigned int hitn=0; hitn<numhits; hitn++){
364  const DBCALHit *hit = hits[hitn];
365  int module = hit->module;
366  int layer = hit->layer;
367  int sector = hit->sector;
368  int end = hit->end; // 0=US
369  float hittime = hit->t;
370 
371  if (module > nummodule || layer > numlayer || sector > numsector) {
372  printf ("(%i,%i,%i) is greater than (%i,%i,%i)\n",module,layer,sector,nummodule,numlayer,numsector);
373  continue;
374  }
375  if (VERBOSE>=3) printf (" hit %2i (%i,%i,%i,%i) %8.3f\n",hitn,module,layer,sector,end,hittime);
376  if (end==0) {
377  hitus_TimeVsZ_layer[layer-1]->Fill(zpos,hittime);
378  hitus_TimeVsZ_layer_prof[layer-1]->Fill(zpos,hittime);
379  ustime = hittime;
380  }
381  if (end==1) {
382  hitds_TimeVsZ_layer[layer-1]->Fill(zpos,hittime);
383  hitds_TimeVsZ_layer_prof[layer-1]->Fill(zpos,hittime);
384  dstime = hittime;
385  }
386  if (ustime!=0 && dstime!=0) {
387  float timediff = ustime - dstime;
388  float timesum = ustime + dstime;
389  hit_TimediffVsZ_layer[layer-1]->Fill(zpos,timediff);
390  hit_TimediffVsZ_layer_prof[layer-1]->Fill(zpos,timediff);
391  hit_TimesumVsZ_layer[layer-1]->Fill(zpos,timesum);
392  hit_TimesumVsZ_layer_prof[layer-1]->Fill(zpos,timesum);
393  }
394  }
395  }
396 
397 
398 
399  maindir->cd();
400 
401  japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
402 
403 
404  return NOERROR;
405 }
406 
407 //------------------
408 // erun
409 //------------------
411 {
412  // This is called whenever the run number changes, before it is
413  // changed to give you a chance to clean up before processing
414  // events from the next run number.
415 
416  // Since we are filling histograms local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
417  japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
418 
419  int nbins = thrown_NVsZ->GetXaxis()->GetNbins();
420  for (int j=0; j<numlayer; j++) {
421  for (int i=1; i<=nbins; i++) {
422  float points = point_NVsZ_layer[j]->GetBinContent(i);
423  float thrown = thrown_NVsZ->GetBinContent(i);
424  //printf("%i %i %i %i %i\n",nbins,i,j,points, thrown);
425  if (thrown>0) point_NormVsZ_layer[j]->SetBinContent(i,points/thrown);
426 
427  }
428  }
429  nbins = thrown_NVsTheta->GetXaxis()->GetNbins();
430  for (int j=0; j<numlayer; j++) {
431  for (int i=1; i<=nbins; i++) {
432  float points = point_NVsTheta_layer[j]->GetBinContent(i);
433  float thrown = thrown_NVsTheta->GetBinContent(i);
434  if (thrown>0) point_NormVsTheta_layer[j]->SetBinContent(i,points/thrown);
435  }
436  }
437 
438  japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
439 
440  return NOERROR;
441 }
442 
443 //------------------
444 // fini
445 //------------------
447 {
448  // Called before program exit after event processing is finished.
449  return NOERROR;
450 }
451 
static TH1I * thrown_NVsZ
static TH1F * point_NormVsTheta_layer[numlayer]
int module() const
Definition: DBCALPoint.h:64
Int_t layer
static TH2I * hit_TimediffVsZ_layer[numlayer]
int module
Definition: DBCALHit.h:25
sprintf(text,"Post KinFit Cut")
int sector() const
Definition: DBCALPoint.h:66
static TProfile * hit_TimesumVsZ_layer_prof[numlayer]
static TProfile * point_TimeVsZ_layer_prof[numlayer]
jerror_t fini(void)
Called after last event of last event source has been processed.
static const int numsector
int layer
Definition: DBCALHit.h:26
static const int numlayer
static TH1I * point_NVsTheta_layer[numlayer]
static TH2I * hitds_TimeVsZ_layer[numlayer]
int layer() const
Definition: DBCALPoint.h:65
JApplication * japp
DBCALGeometry::End end
Definition: DBCALHit.h:28
static TH2I * hit_TimesumVsZ_layer[numlayer]
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
static TProfile * hitds_TimeVsZ_layer_prof[numlayer]
InitPlugin_t InitPlugin
static const double degperrad
const bool VERBOSE
static TH1I * thrown_NVsTheta
static TProfile * hitus_TimeVsZ_layer_prof[numlayer]
static TH2I * point_TimeVsZ_chan[nummodule][numlayer][numsector]
static TH1I * point_NVsZ_layer[numlayer]
static TH2I * test_coords
float t
Definition: DBCALHit.h:31
TH1D * py[NCHANNELS]
int sector
Definition: DBCALHit.h:27
static TH2I * hitus_TimeVsZ_layer[numlayer]
jerror_t init(void)
Called once at program start.
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
double sqrt(double)
static const int nummodule
static TH1F * point_NormVsZ_layer[numlayer]
float t() const
Definition: DBCALPoint.h:41
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
static TH2I * point_TimeVsZ_layer[numlayer]
printf("string=%s", string)
static TProfile * hit_TimediffVsZ_layer_prof[numlayer]