Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_PS_flux.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_PS_flux.cc
4 //
5 //
6 #include <iostream>
7 #include <sstream>
9 
10 using namespace std;
11 using namespace jana;
12 
16 #include <TAGGER/DTAGHHit.h>
17 #include <TAGGER/DTAGHGeometry.h>
18 #include <TAGGER/DTAGMHit.h>
19 #include <TAGGER/DTAGMGeometry.h>
20 #include <PID/DBeamPhoton.h>
21 #include <DAQ/DBeamCurrent.h>
22 
23 #include <JANA/JApplication.h>
24 #include <JANA/JFactory.h>
25 #include <TDirectory.h>
26 #include <TH1.h>
27 #include <TH2.h>
28 
29 const int NC_PSC = DPSGeometry::NUM_COARSE_COLUMNS; // 8: number of PSC modules (counters) per arm
30 const int NC_PS = DPSGeometry::NUM_FINE_COLUMNS; // 145: number of PS columns (tiles) per arm
31 const int NC_TAGH = DTAGHGeometry::kCounterCount; // 274: number of TAGH counters
32 const int NC_TAGM = DTAGMGeometry::kColumnCount; // 102: number of TAGM columns
33 // PS,PSC coincidences
34 static TH1I *psflux_num_events;
35 static TH1F *hFiducialTime;
36 static TH1I *hBeamCurrentTime;
38 static TH2I *hPS_tdiffVsE;
39 static TH2I *hPSC_tdiffVsE;
40 static TH2I *hPSPSC_tdiffVsE;
41 static TH1I *hPS_E;
42 static TH2I *hPS_EVsEuni;
43 // PSC,PS,TAGH coincidences
44 static TH2I *hPSTAGH_tdiffVsEdiff;
45 static TH2I *hPSTAGH_tdiffVsEtagh;
48 static TH2I *hPSTAGH_EdiffVsEtagh;
49 // PSC,PS,TAGM coincidences
50 static TH2I *hPSTAGM_tdiffVsEdiff;
51 static TH2I *hPSTAGM_tdiffVsEtagm;
52 static TH2I *hPSTAGM_tdiffVsColumn;
54 static TH2I *hPSTAGM_EdiffVsEtagm;
55 // PSC,PS,TAG coincidences
56 static TH2I *hPSTAG_tdiffVsEtag;
57 
58 //-------------------------
59 // Routine used to create our JEventProcessor
60 extern "C"{
61  void InitPlugin(JApplication *app){
62  InitJANAPlugin(app);
63  app->AddProcessor(new JEventProcessor_PS_flux());
64 
65  }
66 } // "C"
67 
68 //define static local variable //declared in header file
70 
71 //------------------
72 // JEventProcessor_PS_flux (Constructor)
73 //------------------
75 {
76 
77 }
78 
79 //------------------
80 // ~JEventProcessor_PS_flux (Destructor)
81 //------------------
83 {
84 
85 }
86 
87 //------------------
88 // init
89 //------------------
91 {
92  // energy binning
93  const double Ebw_PS = 0.05;
94  const double Ebl_PS = 5.0;
95  const double Ebh_PS = 13.0;
96  const int NEb_PS = int((Ebh_PS-Ebl_PS)/Ebw_PS);
97  const double Ebw_TAG = 0.1;
98  const double Ebl_TAG = 2.5;
99  const double Ebh_TAG = 10.5;
100  const int NEb_TAG = int((Ebh_TAG-Ebl_TAG)/Ebw_TAG);
101  // time binning
102  const double Tbl_TAG = -100.0;
103  const double Tbh_TAG = 100.0;
104  const int NTb_TAG = 200;
105  // energy difference binning
106  const int NEdb = 200; const double Edbl = -1.0; const double Edbh = 1.0;
107 
108  t_start = -999.;
109  t_end = 0;
110 
111  dRandom = new TRandom3(0);
112 
113  // create root folder for pspair and cd to it, store main dir
114  TDirectory *psFluxDir = gDirectory->mkdir("PS_flux");
115  psFluxDir->cd();
116  // book hists
117  psflux_num_events = new TH1I("psflux_num_events","PS flux number of events",3,0.5,3.5);
118  hFiducialTime = new TH1F("fiducialTime", "Fiducial time", 1, 0, 1);
119  hBeamCurrentTime = new TH1I("beamCurrentTime", "; Event time from DBeamCurrent for all events (seconds)", 1000, 0, 500);
120  hBeamCurrentTimeFiducial = new TH1I("beamCurrentTimeFiducial", "; Event time from DBeamCurrent for fiducial events (seconds)", 1000, 0, 500);
121 
122  //
123  gDirectory->mkdir("PSC_PS")->cd();
124  hPS_E = new TH1I("PS_E","PS pair energy; PS pair energy [GeV]",NEb_PS,Ebl_PS,Ebh_PS);
125  hPS_tdiffVsE = new TH2I("PS_tdiffVsE","PS pair time difference vs. PS pair energy;PS pair energy [GeV];PS pair time difference [ns]",NEb_PS,Ebl_PS,Ebh_PS,200,-10.0,10.0);
126  hPSC_tdiffVsE = new TH2I("PSC_tdiffVsE","PSC pair time difference vs. PS pair energy;PS pair energy [GeV];PSC pair time difference [ns]",NEb_PS,Ebl_PS,Ebh_PS,200,-10.0,10.0);
127  hPSPSC_tdiffVsE = new TH2I("PSPSC_tdiffVsE","PSC/PS pair time difference vs. PS pair energy;PS pair energy [GeV];PSC/PS pair time difference of differences [ns]",NEb_PS,Ebl_PS,Ebh_PS,200,-10.0,10.0);
128  hPS_EVsEuni = new TH2I("PS_EVsEuni","PS pair energy vs. uniform pair energy; PS uniform pair energy [GeV]; PS pair energy [GeV]",NEb_PS,Ebl_PS,Ebh_PS,NEb_PS,Ebl_PS,Ebh_PS);
129  psFluxDir->cd();
130  //
131  gDirectory->mkdir("PSC_PS_TAGH")->cd();
132  hPSTAGH_tdiffVsEdiff = new TH2I("PSTAGH_tdiffVsEdiff","PS pair - TAGH: PS-TAGH time difference vs. PS-TAGH energy difference;E(PS) - E(TAGH) [GeV];PSC/TAGH time difference [ns]",NEdb,Edbl,Edbh,NTb_TAG,Tbl_TAG,Tbh_TAG);
133  hPSTAGH_tdiffVsEtagh = new TH2I("PSTAGH_tdiffVsEtagh","PSC/TAGH time difference vs. TAGH energy; TAGH energy [GeV];PSC/TAGH time difference [ns]",NEb_PS,Ebl_PS,Ebh_PS,NTb_TAG,Tbl_TAG,Tbh_TAG);
134  hPSTAGH_tdiffVsCounter = new TH2I("PSTAGH_tdiffVsCounter","PSC/TAGH time difference vs. TAGH Counter; TAGH Counter;PSC/TAGH time difference [ns]",NC_TAGH,0.5,0.5+NC_TAGH,NTb_TAG,Tbl_TAG,Tbh_TAG);
135  hPSTAGH_EdiffVsTAGHCounterID = new TH2I("PSTAGH_EdiffVsTAGHCounterID","PS pair - TAGH: PS-TAGH energy difference vs. TAGH counter ID;TAGH counter ID;E(PS) - E(TAGH) [GeV]",NC_TAGH,0.5,0.5+NC_TAGH,NEdb,Edbl,Edbh);
136  hPSTAGH_EdiffVsEtagh = new TH2I("PSTAGH_EdiffVsEtagh","PS pair - TAGH: PS-TAGH energy difference vs. TAGH energy;TAGH energy [GeV];E(PS) - E(TAGH) [GeV]",NEb_TAG,Ebl_TAG,Ebh_TAG,NEdb,Edbl,Edbh);
137  psFluxDir->cd();
138  //
139  gDirectory->mkdir("PSC_PS_TAGM")->cd();
140  hPSTAGM_tdiffVsEdiff = new TH2I("PSTAGM_tdiffVsEdiff","PS pair - TAGM: PS-TAGM time difference vs. PS-TAGM energy difference;E(PS) - E(TAGM) [GeV];PSC/TAGM time difference [ns]",NEdb,Edbl,Edbh,NTb_TAG,Tbl_TAG,Tbh_TAG);
141  hPSTAGM_tdiffVsEtagm = new TH2I("PSTAGM_tdiffVsEtagm","PSC/TAGM time difference vs. TAGM energy; TAGM energy [GeV];PSC/TAGM time difference [ns]",NEb_PS,Ebl_PS,Ebh_PS,NTb_TAG,Tbl_TAG,Tbh_TAG);
142  hPSTAGM_tdiffVsColumn = new TH2I("PSTAGM_tdiffVsColumn","PSC/TAGM time difference vs. TAGM Column; TAGM Column;PSC/TAGM time difference [ns]",NC_TAGM,0.5,0.5+NC_TAGM,NTb_TAG,Tbl_TAG,Tbh_TAG);
143  hPSTAGM_EdiffVsTAGMColumn = new TH2I("PSTAGM_EdiffVsTAGMColumn","PS pair - TAGM: PS-TAGM energy difference vs. TAGM column;TAGM column;E(PS) - E(TAGM) [GeV]",NC_TAGM,0.5,0.5+NC_TAGM,NEdb,Edbl,Edbh);
144  hPSTAGM_EdiffVsEtagm = new TH2I("PSTAGM_EdiffVsEtagm","PS pair - TAGM: PS-TAGM energy difference vs. TAGM energy;TAGM energy [GeV];E(PS) - E(TAGM) [GeV]",NEb_PS,Ebl_PS,Ebh_PS,NEdb,Edbl,Edbh);
145  psFluxDir->cd();
146  gDirectory->mkdir("PSC_PS_TAG")->cd();
147  hPSTAG_tdiffVsEtag = new TH2I("PSTAG_tdiffVsEtag","PSC/TAG time difference vs. TAG energy; TAG energy [GeV];PSC/TAG time difference [ns]",NEb_PS,Ebl_PS,Ebh_PS,NTb_TAG,Tbl_TAG,Tbh_TAG);
148  psFluxDir->cd();
149  gDirectory->cd("../");
150 
151  double locNumTAGHhits = 500;
152  double locNumTAGMhits = 200;
153 
154  //TTREE INTERFACE
155  //MUST DELETE WHEN FINISHED: OR ELSE DATA WON'T BE SAVED!!!
156  dTreeInterface = DTreeInterface::Create_DTreeInterface("PSFlux_Tree", "tree_PSFlux.root");
157 
158  //TTREE BRANCHES
159  DTreeBranchRegister locTreeBranchRegister;
160 
161  locTreeBranchRegister.Register_Single<ULong64_t>("EventNumber");
162  locTreeBranchRegister.Register_Single<Bool_t>("IsFiducial");
163  locTreeBranchRegister.Register_Single<Double_t>("PSCtimeL");
164  locTreeBranchRegister.Register_Single<Double_t>("PSCtimeR");
165  locTreeBranchRegister.Register_Single<Double_t>("PStimeL");
166  locTreeBranchRegister.Register_Single<Double_t>("PStimeR");
167  locTreeBranchRegister.Register_Single<Double_t>("PSenergyL");
168  locTreeBranchRegister.Register_Single<Double_t>("PSenergyR");
169  locTreeBranchRegister.Register_Single<Double_t>("PSPairEnergy");
170  locTreeBranchRegister.Register_Single<Double_t>("PSPairEnergyUniform");
171 
172  locTreeBranchRegister.Register_Single<Int_t>("NumTAGMhits");
173  locTreeBranchRegister.Register_FundamentalArray<Double_t>("TAGMenergy", "NumTAGMhits", locNumTAGMhits);
174  locTreeBranchRegister.Register_FundamentalArray<Double_t>("TAGMtime", "NumTAGMhits", locNumTAGMhits);
175  locTreeBranchRegister.Register_FundamentalArray<Int_t>("TAGMcolumn", "NumTAGMhits", locNumTAGMhits);
176 
177  locTreeBranchRegister.Register_Single<Int_t>("NumTAGHhits");
178  locTreeBranchRegister.Register_FundamentalArray<Double_t>("TAGHenergy", "NumTAGHhits", locNumTAGHhits);
179  locTreeBranchRegister.Register_FundamentalArray<Double_t>("TAGHtime", "NumTAGHhits", locNumTAGHhits);
180  locTreeBranchRegister.Register_FundamentalArray<Int_t>("TAGHcounter", "NumTAGHhits", locNumTAGHhits);
181 
182  //REGISTER BRANCHES
183  dTreeInterface->Create_Branches(locTreeBranchRegister);
184 
185  return NOERROR;
186 }
187 
188 //------------------
189 // brun
190 //------------------
191 jerror_t JEventProcessor_PS_flux::brun(JEventLoop *eventLoop, int32_t runnumber)
192 {
193  // This is called whenever the run number changes
194 
195  dBeamCurrentFactory = new DBeamCurrent_factory();
196  dBeamCurrentFactory->init();
197  dBeamCurrentFactory->brun(eventLoop, runnumber);
198 
199  // extract the PS geometry
200  vector<const DPSGeometry*> psGeomVect;
201  eventLoop->Get(psGeomVect);
202  if (psGeomVect.size() < 1)
203  return OBJECT_NOT_AVAILABLE;
204  const DPSGeometry *locPSGeom = psGeomVect[0];
205 
206  // PS pair energy binning
207  double wl_min=0.05,wr_min = 0.05;
208  double Ebw_PS = wl_min + wr_min;
209  const double Ebl_PS = locPSGeom->getElow(0,1) + locPSGeom->getElow(1,1);
210  const double Ebh_PS = locPSGeom->getEhigh(0,NC_PS) + locPSGeom->getEhigh(1,NC_PS);
211  double range = fabs(Ebh_PS-Ebl_PS);
212  int NEb_PS = range/Ebw_PS-int(range/Ebw_PS) < 0.5 ? int(range/Ebw_PS) : int(range/Ebw_PS) + 1;
213  double Elows_PS[NEb_PS+1];
214  for (int i=0;i<NEb_PS+1;i++) {
215  Elows_PS[i] = Ebl_PS + i*Ebw_PS;
216  }
217  // extract the TAGH geometry
218  vector<const DTAGHGeometry*> taghGeomVect;
219  eventLoop->Get(taghGeomVect);
220  if (taghGeomVect.size() < 1)
221  return OBJECT_NOT_AVAILABLE;
222  const DTAGHGeometry& taghGeom = *(taghGeomVect[0]);
223  // get photon energy bin low of each counter for energy histogram binning
224  double Elows_TAGH[NC_TAGH+1];
225  for (int i=0;i<NC_TAGH;i++) {
226  Elows_TAGH[i] = taghGeom.getElow(NC_TAGH-i);
227  }
228  // add the upper limit
229  Elows_TAGH[NC_TAGH] = taghGeom.getEhigh(1);
230  // extract the TAGM geometry
231  vector<const DTAGMGeometry*> tagmGeomVect;
232  eventLoop->Get(tagmGeomVect);
233  if (tagmGeomVect.size() < 1)
234  return OBJECT_NOT_AVAILABLE;
235  const DTAGMGeometry& tagmGeom = *(tagmGeomVect[0]);
236  // get photon energy bin low of each counter for energy histogram binning
237  double Elows_TAGM[NC_TAGM+1];
238  for (int i=0;i<NC_TAGM;i++) {
239  Elows_TAGM[i] = tagmGeom.getElow(NC_TAGM-i);
240  }
241  // add the upper limit
242  Elows_TAGM[NC_TAGM] = tagmGeom.getEhigh(1);
243  //
244  const int NEdiff = 200;
245  double EdiffLows[NEdiff+1];
246  for (int i=0;i<NEdiff+1;i++) {
247  EdiffLows[i] = -1.0 + i*0.01;
248  }
249  const int NTb_PS = 200;
250  double Tlows_PS[NTb_PS+1];
251  for (int i=0;i<=NTb_PS;i++) {
252  Tlows_PS[i] = -10.0+i*0.1;
253  }
254 
255  vector<double> locBeamPeriodVector;
256  eventLoop->GetCalib("PHOTON_BEAM/RF/beam_period", locBeamPeriodVector);
257  dBeamBunchPeriod = locBeamPeriodVector[0];
258 
259  // Since we are filling histograms local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
260  japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
261 
262  // set variable-width energy bins if histogram is empty
263  // PS
264  if (hPS_tdiffVsE->GetEntries()==0) hPS_tdiffVsE->SetBins(NEb_PS,Elows_PS,NTb_PS,Tlows_PS);
265  if (hPSC_tdiffVsE->GetEntries()==0) hPSC_tdiffVsE->SetBins(NEb_PS,Elows_PS,NTb_PS,Tlows_PS);
266  if (hPSPSC_tdiffVsE->GetEntries()==0) hPSPSC_tdiffVsE->SetBins(NEb_PS,Elows_PS,NTb_PS,Tlows_PS);
267  // TAGH
268  if (hPSTAGH_EdiffVsEtagh->GetEntries()==0) hPSTAGH_EdiffVsEtagh->SetBins(NC_TAGH,Elows_TAGH,NEdiff,EdiffLows);
269  // TAGM
270  if (hPSTAGM_EdiffVsEtagm->GetEntries()==0) hPSTAGM_EdiffVsEtagm->SetBins(NC_TAGM,Elows_TAGM,NEdiff,EdiffLows);
271  japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
272 
273  //
274  return NOERROR;
275 }
276 
277 //------------------
278 // evnt
279 //------------------
280 jerror_t JEventProcessor_PS_flux::evnt(JEventLoop *loop, uint64_t eventnumber)
281 {
282  // This is called for every event. Use of common resources like writing
283  // to a file or filling a histogram should be mutex protected. Using
284  // loop->Get(...) to get reconstructed objects (and thereby activating the
285  // reconstruction algorithm) should be done outside of any mutex lock
286  // since multiple threads may call this method at the same time.
287  // coarse PS pairs
288  vector<const DPSCPair*> cpairs;
289  loop->Get(cpairs);
290  // fine PS pairs
291  vector<const DPSPair*> fpairs;
292  loop->Get(fpairs);
293 
294  // tagger hits
295  vector<const DBeamPhoton*> beamPhotons;
296  loop->Get(beamPhotons);
297 
298  // extract the PS geometry
299  vector<const DPSGeometry*> psGeomVect;
300  loop->Get(psGeomVect);
301  if (psGeomVect.size() < 1)
302  return OBJECT_NOT_AVAILABLE;
303  const DPSGeometry *locPSGeom = psGeomVect[0];
304 
305  // beam current and fiducial definition
306  vector<const DBeamCurrent*> beamCurrent;
307  loop->Get(beamCurrent);
308 
309  // get start and end time of events relative to start of run from DBeamCurrent
310  if(!beamCurrent.empty()) {
311  if(t_start < 0.) {
312  t_start = beamCurrent[0]->t;
313  }
314  t_end = beamCurrent[0]->t;
315  }
316 
317  // FILL HISTOGRAMS
318  // Since we are filling histograms local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
319  japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
320  psflux_num_events->Fill(1);
321  if(!beamCurrent.empty()) {
322  hBeamCurrentTime->Fill(beamCurrent[0]->t);
323  if(beamCurrent[0]->is_fiducial) {
324  int timeBin = hBeamCurrentTimeFiducial->FindBin(beamCurrent[0]->t);
325  hBeamCurrentTimeFiducial->SetBinContent(timeBin, 1);
326  }
327  }
328 
329  // PSC coincidences
330  if (cpairs.size()>=1) {
331  // take pair with smallest time difference from sorted vector
332  const DPSCHit* clhit = cpairs[0]->ee.first; // left hit in coarse PS
333  const DPSCHit* crhit = cpairs[0]->ee.second;// right hit in coarse PS
334  double PSC_tdiff = clhit->t-crhit->t;
335  if (fabs(PSC_tdiff) > 6.) {japp->RootFillUnLock(this); return NOERROR;}
336  psflux_num_events->Fill(2);
337 
338  // PSC,PS coincidences
339  if (fpairs.size()>=1) {
340  psflux_num_events->Fill(3);
341  // take pair with smallest time difference from sorted vector
342  const DPSPair::PSClust* flhit = fpairs[0]->ee.first; // left hit in fine PS
343  const DPSPair::PSClust* frhit = fpairs[0]->ee.second; // right hit in fine PS
344 
345  // geometry check for PS/PSC matching
346  if(flhit->column < geomModuleColumn[clhit->module-1][0] || flhit->column > geomModuleColumn[clhit->module-1][1]) {japp->RootFillUnLock(this); return NOERROR;}
347  if(frhit->column < geomModuleColumn[crhit->module-1][0] || frhit->column > geomModuleColumn[crhit->module-1][1]) {japp->RootFillUnLock(this); return NOERROR;}
348 
349  // energy variables with random spread in energy bite
350  // left - arm 0
351  // right - arm 1
352  double E_left_rndm = dRandom->Rndm()*(locPSGeom->getEhigh(0,flhit->column) - locPSGeom->getElow(0,flhit->column)) +
353  locPSGeom->getElow(0,flhit->column);
354  double E_right_rndm = dRandom->Rndm()*(locPSGeom->getEhigh(1,frhit->column)-locPSGeom->getElow(1,frhit->column)) +
355  locPSGeom->getElow(1,frhit->column);
356 
357  double E_pair = flhit->E+frhit->E;
358  double E_pair_uni = E_left_rndm+E_right_rndm;
359  double PS_tdiff = flhit->t-frhit->t;
360 
361  hPS_tdiffVsE->Fill(E_pair,PS_tdiff);
362  hPSC_tdiffVsE->Fill(E_pair,PSC_tdiff);
363  hPSPSC_tdiffVsE->Fill(E_pair, flhit->t-clhit->t);
364  hPS_EVsEuni->Fill(E_pair_uni,E_pair);
365  if(fabs(PS_tdiff) < 0.5*dBeamBunchPeriod && fabs(PSC_tdiff) < 0.5*dBeamBunchPeriod)
366  hPS_E->Fill(E_pair);
367 
368  // Fill PS variables
369  dTreeFillData.Fill_Single<ULong64_t>("EventNumber", eventnumber);
370  if(!beamCurrent.empty())
371  dTreeFillData.Fill_Single<Bool_t>("IsFiducial", beamCurrent[0]->is_fiducial);
372  dTreeFillData.Fill_Single<Double_t>("PSCtimeL", clhit->t);
373  dTreeFillData.Fill_Single<Double_t>("PSCtimeR", crhit->t);
374  dTreeFillData.Fill_Single<Double_t>("PStimeL", flhit->t);
375  dTreeFillData.Fill_Single<Double_t>("PStimeR", frhit->t);
376  dTreeFillData.Fill_Single<Double_t>("PSenergyL", flhit->E);
377  dTreeFillData.Fill_Single<Double_t>("PSenergyR", frhit->E);
378  dTreeFillData.Fill_Single<Double_t>("PSPairEnergy", E_pair);
379  dTreeFillData.Fill_Single<Double_t>("PSPairEnergyUniform", E_pair_uni);
380 
381  int itagm = 0;
382  int itagh = 0;
383  int locTAGMhits = 0;
384  int locTAGHhits = 0;
385 
386  // PSC,PS,TAGH coincidences
387  for(unsigned int i=0; i < beamPhotons.size(); i++) {
388  const DTAGHHit* tag;
389  beamPhotons[i]->GetSingle(tag);
390  if(!tag) continue;
391 
392  // loose cuts on matching
393  double Ediff = E_pair-tag->E;
394  double tdiff_left = clhit->t-tag->t;
395  hPSTAGH_tdiffVsEdiff->Fill(Ediff,tdiff_left);
396 
397  if(fabs(tdiff_left) > 10.*dBeamBunchPeriod || fabs(Ediff) > 4.0)
398  continue;
399 
400  dTreeFillData.Fill_Array<Double_t>("TAGHenergy", tag->E, itagh);
401  dTreeFillData.Fill_Array<Double_t>("TAGHtime", tag->t, itagh);
402  dTreeFillData.Fill_Array<Int_t>("TAGHcounter", tag->counter_id, itagh);
403  itagh++;
404  locTAGHhits++;
405 
406  hPSTAGH_EdiffVsEtagh->Fill(tag->E,Ediff);
407  hPSTAGH_EdiffVsTAGHCounterID->Fill(tag->counter_id,Ediff);
408  if (Ediff < -0.45 || Ediff > 0.15) // cut on energy difference
409  continue;
410  hPSTAGH_tdiffVsEtagh->Fill(tag->E,tdiff_left);
411  hPSTAGH_tdiffVsCounter->Fill(tag->counter_id, tdiff_left);
412  hPSTAG_tdiffVsEtag->Fill(tag->E,tdiff_left);
413  }
414  // PSC,PS,TAGM coincidences
415  for(unsigned int i=0; i < beamPhotons.size(); i++) {
416  const DTAGMHit* tag;
417  beamPhotons[i]->GetSingle(tag);
418  if(!tag) continue;
419 
420  // loose cuts on matching
421  double Ediff = E_pair-tag->E;
422  double tdiff_left = clhit->t-tag->t;
423  hPSTAGM_tdiffVsEdiff->Fill(Ediff,tdiff_left);
424 
425  if(fabs(tdiff_left) > 10.*dBeamBunchPeriod || fabs(Ediff) > 4.0)
426  continue;
427 
428  dTreeFillData.Fill_Array<Double_t>("TAGMenergy", tag->E, itagm);
429  dTreeFillData.Fill_Array<Double_t>("TAGMtime", tag->t, itagm);
430  dTreeFillData.Fill_Array<Int_t>("TAGMcolumn", tag->column, itagm);
431  itagm++;
432  locTAGMhits++;
433 
434  hPSTAGM_EdiffVsEtagm->Fill(tag->E,Ediff);
435  hPSTAGM_EdiffVsTAGMColumn->Fill(tag->column,Ediff);
436  if (Ediff < -0.25 || Ediff > 0.15) // loose cut on energy difference
437  continue;
438  hPSTAGM_tdiffVsEtagm->Fill(tag->E,tdiff_left);
439  hPSTAGM_tdiffVsColumn->Fill(tag->column, tdiff_left);
440  hPSTAG_tdiffVsEtag->Fill(tag->E,tdiff_left);
441  }
442 
443  //FILL TTREE
444  dTreeFillData.Fill_Single<Int_t>("NumTAGMhits", locTAGMhits);
445  dTreeFillData.Fill_Single<Int_t>("NumTAGHhits", locTAGHhits);
446 
447  dTreeInterface->Fill(dTreeFillData);
448  }
449  }
450  //
451  japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
452 
453  return NOERROR;
454 }
455 
456 //------------------
457 // erun
458 //------------------
460 {
461  // This is called whenever the run number changes, before it is
462  // changed to give you a chance to clean up before processing
463  // events from the next run number.
464 
465  //cout<<"t_start = "<<t_start<<" t_end = "<<t_end<<endl;
466  double finalFiducialTime = dBeamCurrentFactory->IntegratedFiducialTime(t_start, t_end);
467  //cout<<endl<<"Fiducial time: "<<finalFiducialTime<<endl;
468  hFiducialTime->SetBinContent(1., finalFiducialTime);
469 
470  return NOERROR;
471 }
472 
473 //------------------
474 // fini
475 //------------------
477 {
478  // Called before program exit after event processing is finished.
479 
480  delete dTreeInterface; //saves trees to file, closes file
481 
482  return NOERROR;
483 }
484 
double t
Definition: DTAGHHit.h:19
static TH2I * hPSTAGM_tdiffVsColumn
double E
Definition: DTAGHHit.h:18
double E
Definition: DTAGMHit.h:18
double getElow(unsigned int counter) const
static TH2I * hPSTAG_tdiffVsEtag
const int NC_PSC
int module
Definition: DPSCHit.h:20
static TH1I * hBeamCurrentTimeFiducial
const float Ebw_PS
void Register_Single(string locBranchName)
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
static TH2I * hPSTAGH_tdiffVsEdiff
static TH2I * hPSC_tdiffVsE
double getEhigh(int arm, int column) const
Definition: DPSGeometry.cc:48
const int NC_TAGM
double t
Definition: DTAGMHit.h:19
double t
Definition: DPSCHit.h:21
static TH2I * hPSTAGM_EdiffVsEtagm
JApplication * japp
double getEhigh(unsigned int column) const
static TH2I * hPS_EVsEuni
static TH2I * hPS_tdiffVsE
jerror_t init(void)
Called once at program start.
static TH1F * hFiducialTime
jerror_t fini(void)
Called after last event of last event source has been processed.
int counter_id
Definition: DTAGHHit.h:20
static DTreeInterface * Create_DTreeInterface(string locTreeName, string locFileName)
InitPlugin_t InitPlugin
const float Ebl_PS
static TH2I * hPSTAGM_EdiffVsTAGMColumn
static TH2I * hPSTAGM_tdiffVsEtagm
static TH1I * psflux_num_events
void Register_FundamentalArray(string locBranchName, string locArraySizeName, size_t locInitialArraySize=10)
const float Ebh_PS
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
static const int NUM_COARSE_COLUMNS
Definition: DPSGeometry.h:25
double getElow(unsigned int column) const
static TH2I * hPSTAGH_EdiffVsTAGHCounterID
double getEhigh(unsigned int counter) const
static TH2I * hPSTAGM_tdiffVsEdiff
const float NEb_PS
const int NC_TAGH
static TH1I * hPS_E
static const unsigned int kColumnCount
Definition: DTAGMGeometry.h:31
int column
Definition: DTAGMHit.h:21
static TH1I * hBeamCurrentTime
static const int NUM_FINE_COLUMNS
Definition: DPSGeometry.h:26
static TH2I * hPSPSC_tdiffVsE
static const unsigned int kCounterCount
Definition: DTAGHGeometry.h:28
static TH2I * hPSTAGH_tdiffVsEtagh
static TH2I * hPSTAGH_EdiffVsEtagh
static TH2I * hPSTAGH_tdiffVsCounter
static thread_local DTreeFillData dTreeFillData
double getElow(int arm, int column) const
Definition: DPSGeometry.cc:40
const int NC_PS