Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_PS_timing.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_PS_timing.cc
4 // Created: Sat Nov 21 17:21:28 EST 2015
5 // Creator: nsparks (on Linux cua2.jlab.org 3.10.0-327.el7.x86_64 x86_64)
6 //
7 
9 
10 using namespace std;
11 using namespace jana;
12 
15 #include <TAGGER/DTAGHHit.h>
16 #include <RF/DRFTime.h>
17 
18 // Routine used to create our JEventProcessor
19 #include <JANA/JApplication.h>
20 #include <JANA/JFactory.h>
21 #include <TDirectory.h>
22 #include <TH1.h>
23 #include <TH2.h>
24 
25 const int NC_PSC = 16; // number of PSC modules (counters)
26 const int NC_PS = 290; // number of PS columns (tiles)
27 const int NC_TAGH = 274; // number of TAGH counter slots
28 
31 static TH2I *hPSRF_adcTimeDiffVsID;
33 
34 extern "C"{
35  void InitPlugin(JApplication *app){
36  InitJANAPlugin(app);
37  app->AddProcessor(new JEventProcessor_PS_timing());
38  }
39 } // "C"
40 
41 
42 //------------------
43 // JEventProcessor_PS_timing (Constructor)
44 //------------------
46 {
47 
48 }
49 
50 //------------------
51 // ~JEventProcessor_PS_timing (Destructor)
52 //------------------
54 {
55 
56 }
57 
58 //------------------
59 // init
60 //------------------
62 {
63  // This is called once at program startup. If you are creating
64  // and filling historgrams in this plugin, you should lock the
65  // ROOT mutex like this:
66 
67  const double Tl = -200.0;
68  const double Th = 600.0;
69  const int NTb = 8000;
70  TDirectory *mainDir = gDirectory;
71  TDirectory *psDir = gDirectory->mkdir("PS_timing");
72  psDir->cd();
73  hPSC_tdcadcTimeDiffVsID = new TH2I("PSC_tdcadcTimeDiffVsID","PSC TDC-ADC time difference vs. counter ID;counter ID;time(TDC) - time(ADC) [ns]",NC_PSC,0.5,0.5+NC_PSC,NTb,Tl,Th);
74  hPSCRF_tdcTimeDiffVsID = new TH2I("PSCRF_tdcTimeDiffVsID","PSC-RF TDC time difference vs. counter ID;counter ID;time(TDC) - time(RF) [ns]",NC_PSC,0.5,0.5+NC_PSC,NTb,Tl,Th);
75  hPSRF_adcTimeDiffVsID = new TH2I("PSRF_adcTimeDiffVsID","PS-RF ADC time difference vs. counter ID;counter ID;time(ADC) - time(RF) [ns]",NC_PS,0.5,0.5+NC_PS,NTb,Tl,Th);
76  hTAGHRF_tdcTimeDiffVsID = new TH2I("TAGHRF_tdcTimeDiffVsID","TAGH-RF TDC time difference vs. counter ID;counter ID;time(TDC) - time(RF) [ns]",NC_TAGH,0.5,0.5+NC_TAGH,NTb,Tl,Th);
77  mainDir->cd();
78 
79  return NOERROR;
80 }
81 
82 //------------------
83 // brun
84 //------------------
85 jerror_t JEventProcessor_PS_timing::brun(JEventLoop *eventLoop, int32_t runnumber)
86 {
87  // This is called whenever the run number changes
88  return NOERROR;
89 }
90 
91 //------------------
92 // evnt
93 //------------------
94 jerror_t JEventProcessor_PS_timing::evnt(JEventLoop *loop, uint64_t eventnumber)
95 {
96  // This is called for every event. Use of common resources like writing
97  // to a file or filling a histogram should be mutex protected. Using
98  // loop->Get(...) to get reconstructed objects (and thereby activating the
99  // reconstruction algorithm) should be done outside of any mutex lock
100  // since multiple threads may call this method at the same time.
101  vector<const DPSCPair*> cpairs;
102  loop->Get(cpairs);
103  vector<const DPSPair*> fpairs;
104  loop->Get(fpairs);
105 
106  vector<const DTAGHHit*> taghhits;
107  loop->Get(taghhits, "Calib");
108 
109  const DRFTime* rfTime = nullptr;
110  vector <const DRFTime*> rfTimes;
111  loop->Get(rfTimes, "PSC");
112  if (rfTimes.size() > 0)
113  rfTime = rfTimes[0];
114  else
115  return NOERROR;
116 
117  // FILL HISTOGRAMS
118  // Since we are filling histograms local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
119  japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
120 
121  double t_RF = rfTime->dTime;
122  if (cpairs.size() >= 1) { // PSC
123  const DPSCHit* clhit = cpairs[0]->ee.first; // left hit in coarse PS
124  const DPSCHit* crhit = cpairs[0]->ee.second;// right hit in coarse PS
125  hPSC_tdcadcTimeDiffVsID->Fill(clhit->module,clhit->t-clhit->time_fadc);
126  hPSCRF_tdcTimeDiffVsID->Fill(clhit->module,clhit->t-t_RF);
127  hPSC_tdcadcTimeDiffVsID->Fill(crhit->module+8,crhit->t-crhit->time_fadc);
128  hPSCRF_tdcTimeDiffVsID->Fill(crhit->module+8,crhit->t-t_RF);
129  for (const auto& h : taghhits) hTAGHRF_tdcTimeDiffVsID->Fill(h->counter_id,h->t-t_RF);
130  if (fpairs.size() >= 1) { // PS
131  const DPSPair::PSClust* flhit = fpairs[0]->ee.first; // left hit in fine PS
132  const DPSPair::PSClust* frhit = fpairs[0]->ee.second; // right hit in fine PS
133  hPSRF_adcTimeDiffVsID->Fill(flhit->column,flhit->t_tile-t_RF);
134  hPSRF_adcTimeDiffVsID->Fill(frhit->column+145,frhit->t_tile-t_RF);
135  }
136  }
137 
138  japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
139 
140  return NOERROR;
141 }
142 
143 //------------------
144 // erun
145 //------------------
147 {
148  // This is called whenever the run number changes, before it is
149  // changed to give you a chance to clean up before processing
150  // events from the next run number.
151  return NOERROR;
152 }
153 
154 //------------------
155 // fini
156 //------------------
158 {
159  // Called before program exit after event processing is finished.
160  return NOERROR;
161 }
162 
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
const int NC_PSC
int module
Definition: DPSCHit.h:20
static TH2I * hTAGHRF_tdcTimeDiffVsID
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
double dTime
Definition: DRFTime.h:24
TDirectory * mainDir
Definition: p2k_hists.C:2
double t
Definition: DPSCHit.h:21
double t_tile
Definition: DPSPair.h:29
JApplication * japp
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
static TH2I * hPSC_tdcadcTimeDiffVsID
InitPlugin_t InitPlugin
static TH2I * hPSRF_adcTimeDiffVsID
static TH2I * hPSCRF_tdcTimeDiffVsID
jerror_t fini(void)
Called after last event of last event source has been processed.
const int NC_TAGH
jerror_t init(void)
Called once at program start.
double time_fadc
Definition: DPSCHit.h:25
const int NC_PS