Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_TPOL_online.cc
Go to the documentation of this file.
1 #include <stdint.h>
2 #include <vector>
3 
5 #include <JANA/JApplication.h>
6 
7 using namespace std;
8 using namespace jana;
9 
10 #include <DAQ/Df250WindowRawData.h>
11 #include <DAQ/Df250PulseData.h>
12 #include <TRIGGER/DL1Trigger.h>
14 #include <TPOL/DTPOLHit.h>
15 #include <TPOL/DTPOLHit_factory.h>
16 
17 #include <TDirectory.h>
18 #include <TH1.h>
19 #include <TH2.h>
20 #include <TProfile.h>
21 
22 // root hist pointers
24 const int NmultBins = 25; // number of bins for multiplicity histograms
25 static TH1I *tpol_num_events;
26 static TH1I *hRaw_NHits;
27 static TH1I *hHit_NHits;
28 static TH1I *hHit_Occupancy;
29 static TH1F *hHit_Phi;
30 static TH1I *hHit_Peak;
31 static TH2I *hHit_PeakVsSector;
32 static TH1I *hHit_Integral;
33 static TH2I *hHit_IntegralVsSector;
34 static TH1I *hHit_Time;
35 static TH2I *hHit_TimeVsSector;
36 static TH2F *hHit_TimeVsPhi;
37 static TH2I *hHit_TimeVsPeak;
38 static TH2I *hHit_TimeVsIntegral;
39 
40 static TH1I *hDigiHit_NHits;
42 static TH1I *hDigiHit_Pedestal;
43 static TProfile *hDigiHit_PedestalVsSector;
45 static TH1I *hDigiHit_PulseNumber;
47 static TH1I *hDigiHit_Occupancy;
48 static TH1I *hDigiHit_RawPeak;
50 static TH1I *hDigiHit_RawIntegral;
53 static TH2I *hDigiHit_PeakVsSector;
56 static TH1I *hDigiHit_PulseTime;
57 static TH1I *hDigiHit_Time;
58 static TH2I *hDigiHit_TimeVsSector;
59 static TH2I *hDigiHit_TimeVsPeak;
61 //----------------------------------------------------------------------------------
62 
63 
64 // Routine used to create our JEventProcessor
65 extern "C"{
66  void InitPlugin(JApplication *app){
67  InitJANAPlugin(app);
68  app->AddProcessor(new JEventProcessor_TPOL_online());
69  }
70 }
71 
72 
73 //----------------------------------------------------------------------------------
74 
75 
77 }
78 
79 
80 //----------------------------------------------------------------------------------
81 
82 
84 }
85 
86 
87 //----------------------------------------------------------------------------------
88 
90 
91  // create root folder for TPOL and cd to it, store main dir
92  TDirectory *mainDir = gDirectory;
93  TDirectory *tpolDir = gDirectory->mkdir("TPOL");
94  tpolDir->cd();
95  // book hists
96  tpol_num_events = new TH1I("tpol_num_events","TPOL number of events",1,0.5,1.5);
97  hRaw_NHits = new TH1I("Raw_NHits",";TPOL raw hit multiplicity;raw hits;events",NmultBins,0.5,0.5+NmultBins);
98  // hit-level hists (after calibration)
99  gDirectory->mkdir("Hit")->cd();
100  hHit_NHits = new TH1I("Hit_NHits","TPOL hit multiplicity;hits;events",NmultBins,0.5,0.5+NmultBins);
101  hHit_Occupancy = new TH1I("Hit_Occupancy","TPOL occupancy;sector;hits / sector",Nsectors,0.5,0.5+Nsectors);
102  hHit_Phi = new TH1F("Hit_Phi","TPOL azimuthal angle;triplet azimuthal angle [degrees];hits / sector",Nsectors,0.0,360.0);
103  hHit_Peak = new TH1I("Hit_Peak","TPOL fADC pulse peak;pulse peak;hits",410,0.0,4100.0);
104  hHit_PeakVsSector = new TH2I("Hit_PeakVsSector","TPOL fADC pulse peak vs. sector;sector;pulse peak",Nsectors,0.5,0.5+Nsectors,410,0.0,4100.0);
105  hHit_Integral = new TH1I("Hit_Integral","TPOL fADC pulse integral;pulse integral;hits",1000,0.0,30000.0);
106  hHit_IntegralVsSector = new TH2I("Hit_IntegralVsSector","TPOL fADC pulse integral vs. sector;sector;pulse integral",Nsectors,0.5,0.5+Nsectors,1000,0.0,30000.0);
107  hHit_Time = new TH1I("Hit_Time","TPOL time;time [ns];hits / 2 ns",400,-400.0,400.0);
108  hHit_TimeVsSector = new TH2I("Hit_TimeVsSector","TPOL time vs. sector;sector;time [ns]",Nsectors,0.5,0.5+Nsectors,400,-400.0,400.0);
109  hHit_TimeVsPhi = new TH2F("Hit_TimeVsPhi","TPOL time vs. phi;#phi [degrees];time [ns]",Nsectors,0.0,360.0,400,-400.0,400.0);
110  hHit_TimeVsIntegral = new TH2I("Hit_TimeVsIntegral","TPOL time vs. integral;pulse integral;time [ns]",500,0.0,30000.0,400,-400.0,400.0);
111  hHit_TimeVsPeak = new TH2I("Hit_TimeVsPeak","TPOL time vs. peak;pulse peak;time [ns]",410,0.0,4100.0,400,-400.0,400.0);
112  // digihit-level hists
113  tpolDir->cd();
114  gDirectory->mkdir("DigiHit")->cd();
115  hDigiHit_NHits = new TH1I("DigiHit_NfadcHits","TPOL fADC hit multiplicity;raw hits;events",NmultBins,0.5,0.5+NmultBins);
116  hDigiHit_NSamplesPedestal = new TH1I("DigiHit_NSamplesPedestal","TPOL fADC pedestal samples;pedestal samples;raw hits",50,-0.5,49.5);
117  hDigiHit_Pedestal = new TH1I("DigiHit_Pedestal","TPOL fADC pedestals;pedestal [fADC counts];raw hits",200,0.0,200.0);
118  hDigiHit_PedestalVsSector = new TProfile("DigiHit_PedestalVsSector","TPOL pedestal vs. sector;sector;average pedestal [fADC counts]",Nsectors,0.5,0.5+Nsectors,"s");
119  hDigiHit_QualityFactor = new TH1I("DigiHit_QualityFactor","TPOL fADC quality factor;quality factor;raw hits",4,-0.5,3.5);
120  hDigiHit_PulseNumber = new TH1I("DigiHit_PulseNumber","TPOL fADC pulse number;pulse number;raw hits",4,-0.5,3.5);
121  hDigiHit_PulseNumberVsSector = new TH2I("DigiHit_PulseNumberVsSector","TPOL fADC pulse number vs. sector;sector;pulse number;raw hits",Nsectors,0.5,0.5+Nsectors,4,-0.5,3.5);
122  hDigiHit_Occupancy = new TH1I("DigiHit_fadcOccupancy","TPOL fADC hit occupancy;sector;raw hits / counter",Nsectors,0.5,0.5+Nsectors);
123  hDigiHit_RawPeak = new TH1I("DigiHit_RawPeak","TPOL fADC pulse peak (raw);pulse peak (raw);raw hits",410,0.0,4100.0);
124  hDigiHit_RawPeakVsSector = new TH2I("DigiHit_RawPeakVsSector","TPOL fADC pulse peak (raw) vs. sector;sector;pulse peak (raw)",Nsectors,0.5,0.5+Nsectors,410,0.0,4100.0);
125  hDigiHit_RawIntegral = new TH1I("DigiHit_RawIntegral","TPOL fADC pulse integral (raw);pulse integral (raw);raw hits",1000,0.0,30000.0);
126  hDigiHit_RawIntegralVsSector = new TH2I("DigiHit_RawIntegralVsSector","TPOL fADC pulse integral (raw) vs. sector;sector;pulse integral (raw)",Nsectors,0.5,0.5+Nsectors,1000,0.0,30000.0);
127  hDigiHit_NSamplesIntegral = new TH1I("DigiHit_NSamplesIntegral","TPOL fADC integral samples;integral samples;raw hits",60,-0.5,59.5);
128  hDigiHit_PeakVsSector = new TH2I("DigiHit_PeakVsSector","TPOL fADC pulse peak vs. sector;sector;pulse peak",Nsectors,0.5,0.5+Nsectors,410,0.0,4100.0);
129  hDigiHit_IntegralVsPeak = new TH2I("DigiHit_IntegralVsPeak","TPOL fADC pulse integral vs. peak;pulse peak;pulse integral",410,0.0,4100.0,1000,0.0,30000.0);
130  hDigiHit_IntegralVsSector = new TH2I("DigiHit_IntegralVsSector","TPOL fADC pulse integral vs. sector;sector;pulse integral",Nsectors,0.5,0.5+Nsectors,1000,0.0,30000.0);
131  hDigiHit_PulseTime = new TH1I("DigiHit_PulseTime","TPOL fADC pulse time;pulse time [62.5 ps];raw hits",1000,0.0,6500.0);
132  hDigiHit_Time = new TH1I("DigiHit_Time","TPOL fADC pulse time;pulse time [ns];raw hits / 2 ns",200,0.0,400.0);
133  hDigiHit_TimeVsSector = new TH2I("DigiHit_TimeVsSector","TPOL fADC pulse time vs. sector;sector;pulse time [ns]",Nsectors,0.5,0.5+Nsectors,200,0.0,400.0);
134  hDigiHit_TimeVsPeak = new TH2I("DigiHit_TimeVsPeak","TPOL time vs. peak;pulse peak;time [ns]",410,0.0,4100.0,200,0.0,400.0);
135  hDigiHit_TimeVsIntegral = new TH2I("DigiHit_fadcTimeVsIntegral","TPOL fADC pulse time vs. integral;pulse integral;pulse time [ns]",500,0.0,30000.0,200,0.0,400.0);
136  // back to main dir
137  mainDir->cd();
138 
139  return NOERROR;
140 }
141 
142 //----------------------------------------------------------------------------------
143 
144 
145 jerror_t JEventProcessor_TPOL_online::brun(JEventLoop *eventLoop, int32_t runnumber) {
146  // This is called whenever the run number changes
147  return NOERROR;
148 }
149 
150 
151 //----------------------------------------------------------------------------------
152 
153 
154 jerror_t JEventProcessor_TPOL_online::evnt(JEventLoop *eventLoop, uint64_t eventnumber) {
155  // This is called for every event. Use of common resources like writing
156  // to a file or filling a histogram should be mutex protected. Using
157  // loop-Get(...) to get reconstructed objects (and thereby activating the
158  // reconstruction algorithm) should be done outside of any mutex lock
159  // since multiple threads may call this method at the same time.
160  const DL1Trigger *trig_words = nullptr;
161  uint32_t trig_mask, fp_trig_mask;
162  try {
163  eventLoop->GetSingle(trig_words);
164  } catch(...) {};
165  if (trig_words != nullptr) {
166  trig_mask = trig_words->trig_mask;
167  fp_trig_mask = trig_words->fp_trig_mask;
168  }
169  else {
170  trig_mask = 0;
171  fp_trig_mask = 0;
172  }
173  int trig_bits = fp_trig_mask > 0 ? 10 + fp_trig_mask:trig_mask;
174  // Select PS-triggered events
175  if (trig_bits != 8) {
176  return NOERROR;
177  }
178  vector<const DTPOLHit*> hits;
179  eventLoop->Get(hits);
180  vector<const DTPOLSectorDigiHit*> sdhits;
181  eventLoop->Get(sdhits);
182  vector<const Df250WindowRawData*> windowrawdata;
183  eventLoop->Get(windowrawdata);
184 
185  // Cache pulse data objects
186  map< const DTPOLSectorDigiHit*, const Df250PulseData* > pd_cache;
187  for (const auto& hit : sdhits) {
188  const Df250PulseData* pd = nullptr;
189  hit->GetSingle(pd);
190  pd_cache[hit] = pd;
191  }
192 
193  // FILL HISTOGRAMS
194  // Since we are filling histograms local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
195  japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
196 
197  int NHits = 0;
198  for (const auto& wrd : windowrawdata) {
199  if (wrd->rocid == 84
200  &&
201  (wrd->slot == 13 || wrd->slot == 14)) {
202  NHits++;
203  }
204  }
205  hRaw_NHits->Fill(NHits);
206 
207  if (sdhits.size() > 0) tpol_num_events->Fill(1);
208 
209  hDigiHit_NHits->Fill(sdhits.size());
210  for (const auto& hit : sdhits) {
211  double ped = (double)hit->pedestal/hit->nsamples_pedestal;
212  hDigiHit_NSamplesPedestal->Fill(hit->nsamples_pedestal);
213  hDigiHit_RawPeak->Fill(hit->pulse_peak);
214  hDigiHit_Pedestal->Fill(ped);
215  if (ped == 0.0 || hit->pulse_peak == 0) continue;
216  hDigiHit_PedestalVsSector->Fill(hit->sector,ped);
217  hDigiHit_Occupancy->Fill(hit->sector);
218  hDigiHit_RawPeakVsSector->Fill(hit->sector,hit->pulse_peak);
219  hDigiHit_RawIntegral->Fill(hit->pulse_integral);
220  hDigiHit_RawIntegralVsSector->Fill(hit->sector,hit->pulse_integral);
221  hDigiHit_NSamplesIntegral->Fill(hit->nsamples_integral);
222  double pI = hit->pulse_integral-hit->nsamples_integral*ped;
223  hDigiHit_IntegralVsSector->Fill(hit->sector,pI);
224  hDigiHit_IntegralVsPeak->Fill(hit->pulse_peak-ped,pI);
225  hDigiHit_PeakVsSector->Fill(hit->sector,hit->pulse_peak-ped);
226  hDigiHit_PulseTime->Fill(hit->pulse_time);
227  double t_ns = 0.0625*hit->pulse_time;
228  hDigiHit_Time->Fill(t_ns);
229  hDigiHit_TimeVsSector->Fill(hit->sector,t_ns);
230  hDigiHit_TimeVsPeak->Fill(hit->pulse_peak-ped,t_ns);
231  hDigiHit_TimeVsIntegral->Fill(pI,t_ns);
232  hDigiHit_QualityFactor->Fill(hit->QF);
233  const Df250PulseData* pd = pd_cache[hit];
234  int pN = (pd != nullptr) ? pd->pulse_number : -1;
235  if (pN > -1) hDigiHit_PulseNumber->Fill(pN);
236  if (pN > -1) hDigiHit_PulseNumberVsSector->Fill(hit->sector,pN);
237  }
238 
239  hHit_NHits->Fill(hits.size());
240  for (const auto& hit : hits) {
241  hHit_Occupancy->Fill(hit->sector);
242  hHit_Phi->Fill(hit->phi);
243  hHit_Integral->Fill(hit->integral);
244  hHit_IntegralVsSector->Fill(hit->sector,hit->integral);
245  hHit_Peak->Fill(hit->pulse_peak);
246  hHit_PeakVsSector->Fill(hit->sector,hit->pulse_peak);
247  hHit_Time->Fill(hit->t);
248  hHit_TimeVsSector->Fill(hit->sector,hit->t);
249  hHit_TimeVsPhi->Fill(hit->phi,hit->t);
250  hHit_TimeVsIntegral->Fill(hit->integral,hit->t);
251  hHit_TimeVsPeak->Fill(hit->pulse_peak,hit->t);
252  }
253 
254  japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
255 
256  return NOERROR;
257 }
258 //----------------------------------------------------------------------------------
259 
260 
262  // This is called whenever the run number changes, before it is
263  // changed to give you a chance to clean up before processing
264  // events from the next run number.
265  return NOERROR;
266 }
267 
268 
269 //----------------------------------------------------------------------------------
270 
271 
273  // Called before program exit after event processing is finished.
274  return NOERROR;
275 }
276 
277 //----------------------------------------------------------------------------------
278 //----------------------------------------------------------------------------------
static TH2F * hHit_TimeVsPhi
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
static TH1I * hDigiHit_NSamplesPedestal
static TH1I * hHit_NHits
if(locHist_BCALShowerPhiVsZ!=NULL)
static TH2I * hHit_PeakVsSector
uint32_t trig_mask
Definition: DL1Trigger.h:18
uint32_t fp_trig_mask
Definition: DL1Trigger.h:19
static TH2I * hHit_TimeVsIntegral
static TH1I * hHit_Peak
static TH2I * hDigiHit_PeakVsSector
static TH2I * hDigiHit_RawIntegralVsSector
static TH1I * hDigiHit_RawIntegral
static TH2I * hHit_TimeVsSector
static TH2I * hDigiHit_TimeVsPeak
static TH1F * hHit_Phi
static TH1I * hDigiHit_NHits
const int Nsectors
static TH1I * hDigiHit_Occupancy
const int NmultBins
TDirectory * mainDir
Definition: p2k_hists.C:2
static TH1I * hHit_Occupancy
JApplication * japp
static TH2I * hHit_IntegralVsSector
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
static TH1I * hDigiHit_NSamplesIntegral
static TH1I * hRaw_NHits
static TH2I * hDigiHit_RawPeakVsSector
InitPlugin_t InitPlugin
static TH2I * hHit_TimeVsPeak
static TH1I * hDigiHit_PulseNumber
static TH1I * hDigiHit_QualityFactor
static TH2I * hDigiHit_PulseNumberVsSector
static TH1I * hHit_Integral
jerror_t init(void)
Called once at program start.
static TH2I * hDigiHit_IntegralVsPeak
static TH2I * hDigiHit_TimeVsIntegral
static TH2I * hDigiHit_TimeVsSector
static TH2I * hDigiHit_IntegralVsSector
static TH1I * hDigiHit_RawPeak
static TProfile * hDigiHit_PedestalVsSector
static TH1I * hDigiHit_PulseTime
static TH1I * hHit_Time
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
static TH1I * hDigiHit_Time
jerror_t fini(void)
Called after last event of last event source has been processed.
uint32_t pulse_number
pulse number for this channel, this event starting from 0
static TH1I * hDigiHit_Pedestal
static const int NSECTORS
static TH1I * tpol_num_events