Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_ST_online_multi.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_ST_online_multi.cc
4 // Created: Wed Feb 24 08:17:21 EST 2016
5 // Creator: mkamel (on Linux mkamel-NE56R 3.13.0-39-generic x86_64)
6 //
7 
9 #include "TRIGGER/DTrigger.h"
10 
11 using namespace jana;
12 //***************** Declare Two Dimensional Histograms*************
13 static TH2I *h2_st_adc_tdc_multi;
14 static TH2I *h2_st_adc_hit_multi;
15 static TH2I *h2_sector_adc_multip;
16 static TH2I *h2_sector_tdc_multip;
17 static TH2I *h2_sector_hit_multip;
18 static TH2I *h2_adc_unmatched;
19 static TH2I *h2_tdc_unmatched;
20 //***************** Declare One Dimensional Histograms****************
21 static TH1I *h1_adc_sec;
22 static TH1I *h1_tdc_sec;
23 static TH1I *h1_hit_sec;
24 static TH1I *st_num_events;
25 static TH1I *h1_tdc_noMatchTO_adc;
26 static TH1I *h1_adc_noMatchTO_tdc;
27 //***************** Declare Dynamic Arrays of Histograms *************
28 TH1I** h1_ADC_multiplicity = new TH1I*[NCHANNELS];
29 TH1I** h1_TDC_multiplicity = new TH1I*[NCHANNELS];
30 TH1I** h1_hit_multiplicity = new TH1I*[NCHANNELS];
31 TH2I** h2_ADC_TDC_multiplicity = new TH2I*[NCHANNELS];
32 
33 // Routine used to create our JEventProcessor
34 #include <JANA/JApplication.h>
35 #include <JANA/JFactory.h>
36 extern "C"{
37 void InitPlugin(JApplication *app){
38  InitJANAPlugin(app);
39  app->AddProcessor(new JEventProcessor_ST_online_multi());
40 }
41 } // "C"
42 
43 
44 //------------------
45 // JEventProcessor_ST_online_multi (Constructor)
46 //------------------
48 {
49 
50 }
51 
52 //------------------
53 // ~JEventProcessor_ST_online_multi (Destructor)
54 //------------------
56 {
57 
58 }
59 
60 //------------------
61 // init
62 //------------------
64 {
65  // This is called once at program startup. If you are creating
66  // and filling historgrams in this plugin, you should lock the
67  // ROOT mutex like this:
68  //
69  // japp->RootWriteLock();
70  // ... fill historgrams or trees ...
71  // japp->RootUnLock();
72  //
73 
74  //Create root folder for ST and cd to it, store main dir
75  TDirectory *main = gDirectory;
76  gDirectory->mkdir("st_multiplicity")->cd();
77  //Define 1D histograms
78  st_num_events = new TH1I("st_num_events","ST Number of events",1, 0.5, 1.5);
79  h1_adc_sec = new TH1I("h1_adc_sec", "ST fADC250 DigiHit Occupancy; Channel Number; fADC250 Counts", NCHANNELS, 0.5, NCHANNELS + 0.5);
80  h1_tdc_sec = new TH1I("h1_tdc_sec", "ST TDC DigiHit Occupancy; Channel Number; TDC Counts", NCHANNELS, 0.5, NCHANNELS + 0.5);
81  h1_hit_sec = new TH1I("h1_hit_sec", "ST Hit Occupancy; Channel Number; Hit Counts", NCHANNELS, 0.5, NCHANNELS + 0.5);
82 
83  h1_tdc_noMatchTO_adc = new TH1I("h1_tdc_noMatchTO_adc", "TDC not matched to ADC; Channel Number; TDC Counts", NCHANNELS, 0.5, NCHANNELS + 0.5);
84  h1_adc_noMatchTO_tdc = new TH1I("h1_adc_noMatchTO_tdc", "ADC not matched to TDC; Channel Number; ADC Counts", NCHANNELS, 0.5, NCHANNELS + 0.5);
85 
86 
87  // 2D Multiplicity Histos
88  h2_st_adc_tdc_multi = new TH2I("h2_st_adc_tdc_multi", "ST Total Multiplicity: TDC vs ADC; f1TDC Multiplicity; fADC250 Multiplicity", TDC_MULTI_BINS, TDC_MULTI_MIN + 0.5, TDC_MULTI_MAX + 0.5, ADC_MULTI_BINS, ADC_MULTI_MIN + 0.5, ADC_MULTI_MAX + 0.5);
89  h2_st_adc_hit_multi = new TH2I("h2_st_adc_hit_multi", "ST Total Multiplicity: HIT vs ADC; Hit Multiplicity; fADC250 Multiplicity", TDC_MULTI_BINS, TDC_MULTI_MIN + 0.5, TDC_MULTI_MAX + 0.5, ADC_MULTI_BINS, ADC_MULTI_MIN + 0.5, ADC_MULTI_MAX + 0.5);
90 
91  h2_sector_adc_multip = new TH2I("h2_sector_adc_multip", "Sector Multiplicity: per event; Sector; ADC Multiplicity", NCHANNELS, 0.5, NCHANNELS + 0.5, 10, -0.5, 9.5);
92  h2_sector_tdc_multip= new TH2I("h2_sector_tdc_multip", "Sector Multiplicity: per event; Sector; TDC Multiplicity", NCHANNELS, 0.5, NCHANNELS + 0.5, 10, -0.5, 9.5);
93  h2_sector_hit_multip= new TH2I("h2_sector_hit_multip", "Sector Multiplicity: per event; Sector; Hit Multiplicity", NCHANNELS, 0.5, NCHANNELS + 0.5, 10, -0.5, 9.5);
94  h2_adc_unmatched = new TH2I("h2_adc_unmatched", "Unmatched ADC to TDC: per event; Sector; ADC Unmatched Counts", NCHANNELS, 0.5, NCHANNELS + 0.5, 10, -0.5, 9.5);
95  h2_tdc_unmatched = new TH2I("h2_tdc_unmatched", "Unmatched TDC to ADC: per event; Sector; TDC Unmatched Counts", NCHANNELS, 0.5, NCHANNELS + 0.5, 10, -0.5, 9.5);
96  // 1d multiplicity per paddle per event
97  for(int i = 0; i < NCHANNELS; i++)
98  {
99  h1_ADC_multiplicity[i] = new TH1I(Form("h1_multiplicity_%i", i+1), Form("Channel %i, #phi #in [%i^{#circ}, %i^{#circ}]; fADC250 Multiplicity; fADC250 Counts ", i+1, 0+12*i, 12+12*i), 10, -0.5, 9.5);
100  h1_TDC_multiplicity[i] = new TH1I(Form("h1_TDC_multiplicity_%i", i+1), Form("Channel %i, #phi #in [%i^{#circ}, %i^{#circ}]; TDC Multiplicity; TDC Counts ", i+1, 0+12*i, 12+12*i), 10, -0.5, 9.5);
101  h1_hit_multiplicity[i] = new TH1I(Form("h1_hit_multiplicity_%i", i+1), Form("Channel %i, #phi #in [%i^{#circ}, %i^{#circ}]; Hit Multiplicity; Hit Counts ", i+1, 0+12*i, 12+12*i), 10, -0.5, 9.5);
102  // 2d multiplicity per paddle per event
103  h2_ADC_TDC_multiplicity[i] = new TH2I (Form("h2_ADC_TDC_multiplicity_%i", i+1), Form("Channel %i, #phi #in [%i^{#circ}, %i^{#circ}];f1TDC Multiplicity; fADC250 Multiplicity", i+1, 0+12*i, 12+12*i), 10, -0.5, 9.5, 10, -0.5, 9.5);
104 
105  }
106 
107 
108  // cd back to main directory
109  main->cd();
110  return NOERROR;
111 }
112 
113 //------------------
114 // brun
115 //------------------
116 jerror_t JEventProcessor_ST_online_multi::brun(JEventLoop *eventLoop, int32_t runnumber)
117 {
118  // This is called whenever the run number changes
119  return NOERROR;
120 }
121 
122 //------------------
123 // evnt
124 //------------------
125 jerror_t JEventProcessor_ST_online_multi::evnt(JEventLoop *loop, uint64_t eventnumber)
126 {
127  // This is called for every event. Use of common resources like writing
128  // to a file or filling a histogram should be mutex protected. Using
129  // loop->Get(...) to get reconstructed objects (and thereby activating the
130  // reconstruction algorithm) should be done outside of any mutex lock
131  // since multiple threads may call this method at the same time.
132  // Here's an example:
133  //
134  // vector<const MyDataClass*> mydataclasses;
135  // loop->Get(mydataclasses);
136  //
137  // japp->RootWriteLock();
138  // ... fill historgrams or trees ...
139  // japp->RootUnLock();
140  // Get the data objects first so we minimize the time we hold the ROOT mutex lock
141  vector<const DSCDigiHit*> ADC_Digi_Hits; // ST fADC250 DigiHits
142  vector<const DSCTDCDigiHit*> TDC_Digi_Hits; // ST f1TDC DigiHits
143  vector<const DSCHit*> Factory_Hits; // ST hits
144 
145  const DTrigger* locTrigger = NULL;
146  loop->GetSingle(locTrigger);
147  if(locTrigger->Get_L1FrontPanelTriggerBits() != 0)
148  return NOERROR;
149 
150  loop->Get(ADC_Digi_Hits);
151  loop->Get(TDC_Digi_Hits);
152  loop->Get(Factory_Hits);
153  //Get the size of each object
154  int ADC_hits = ADC_Digi_Hits.size();
155  int TDC_hits = TDC_Digi_Hits.size();
156  int FAC_hits = Factory_Hits.size();
157 
158 
159  // FILL HISTOGRAMS
160  // Since we are filling histograms local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
161  japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
162 
163  //reset the counters to zero
164  memset(counter_adc, 0, sizeof(counter_adc));
165  memset(counter_tdc, 0, sizeof(counter_tdc));
166  memset(counter_hit, 0, sizeof(counter_hit));
167  memset(counter_adc_2, 0, sizeof(counter_adc_2));
168  memset(counter_tdc_2, 0, sizeof(counter_tdc_2));
169  memset(counter_adc_unmatched,0, sizeof(counter_adc_unmatched));
170  memset(counter_tdc_unmatched,0, sizeof(counter_tdc_unmatched));
171 //int hit_index;
172  //Fill the number of events histograms
173  if( (ADC_hits > 0) || (TDC_hits > 0) || (FAC_hits > 0) )
174  st_num_events->Fill(1);
175  //Fill 2D multiplicity histos
176  h2_st_adc_tdc_multi->Fill(TDC_hits, ADC_hits);
177  h2_st_adc_hit_multi->Fill(FAC_hits, ADC_hits);
178  //============================= ADC Hits ====================
179  for(int i = 0; i < ADC_hits; i++)
180  {
181  int adc_sector = ADC_Digi_Hits[i]->sector;
182  adc_index = adc_sector - 1;
183  //Fill adc occupancy histo
184  h1_adc_sec->Fill(adc_sector);
185  //multiplicity per paddle per event
186  counter_adc[adc_index] += 1;
187  for(int k = 0; k < TDC_hits; k++)
188  {
189  int tdc_sector = TDC_Digi_Hits[k]->sector;
190  if (adc_sector != tdc_sector)
191  {
192  counter_adc_unmatched[adc_index] +=1;
193  h1_tdc_noMatchTO_adc->Fill(tdc_sector);
194  h1_adc_noMatchTO_tdc->Fill(adc_sector);
195  }
196  }
197  }
198  for(int j=0; j < NCHANNELS; j++)
199  {
200  if (counter_adc[j] != 0)
201  {
202  h1_ADC_multiplicity[j]->Fill(counter_adc[j]);
203  h2_sector_adc_multip->Fill(j+1,counter_adc[j]);
204 
205  if ((counter_adc_unmatched[j] != 0) && (counter_adc_unmatched[j] <= 3))
206  h2_adc_unmatched->Fill(j+1,counter_adc_unmatched[j]);
207  }
208  }
209 
210  //============================= TDC Hits ====================
211  // cout<< "**********************event number = "<< eventnumber <<"*****************************" << endl;
212  for(int k = 0; k < TDC_hits; k++)
213  {
214  int tdc_sector = TDC_Digi_Hits[k]->sector;
215  tdc_index = tdc_sector -1 ;
216  //Fill tdc occupancy histo
217  h1_tdc_sec->Fill(tdc_sector);
218  //multiplicity per paddle per event
219  counter_tdc[tdc_index] += 1;
220  for(int i = 0; i < ADC_hits; i++)
221  {
222  int adc_sector = ADC_Digi_Hits[i]->sector;
223  if (tdc_sector != adc_sector)
224  {
225  counter_tdc_unmatched[tdc_index] +=1;
226  }
227  }
228 
229  }
230  for(int j=0; j < NCHANNELS; j++)
231  {
232  if (counter_tdc[j] != 0)
233  {
234  // cout << "counter_tdc[j] = " << counter_tdc[j] << endl;
235  h1_TDC_multiplicity[j]->Fill(counter_tdc[j]);
236  h2_sector_tdc_multip->Fill(j+1,counter_tdc[j]);
237 
238  if ((counter_tdc_unmatched[j] != 0) && (counter_tdc_unmatched[j] <= 3))
239  h2_tdc_unmatched->Fill(j+1,counter_tdc_unmatched[j]);
240  }
241  }
242  //=========================== ST Factory Hits ====================
243  for(int l = 0; l < FAC_hits; l++)
244  {
245  int hit_sector = Factory_Hits[l]->sector;
246  hit_index = hit_sector -1 ;
247  //Fill tdc occupancy histo
248  h1_hit_sec->Fill(hit_sector);
249  //multiplicity per paddle per event
250  counter_hit[hit_index] += 1;
251  }
252  for(int j=0; j < NCHANNELS; j++)
253  {
254  if (counter_hit[j] != 0)
255  {
256  h1_hit_multiplicity[j]->Fill(counter_hit[j]);
257  h2_sector_hit_multip->Fill(j+1,counter_hit[j]);
258  }
259  }
260  //==================== 2D multiplicity =============================
261  for(int j=0; j < NCHANNELS; j++)
262  {
263  if ((counter_adc[j] != 0) && (counter_tdc[j] != 0))
264  {
265  h2_ADC_TDC_multiplicity[j]->Fill(counter_tdc[j],counter_adc[j]);
266  }
267  }
268 
269  japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
270 
271  return NOERROR;
272 }
273 
274 //------------------
275 // erun
276 //------------------
278 {
279  // This is called whenever the run number changes, before it is
280  // changed to give you a chance to clean up before processing
281  // events from the next run number.
282  return NOERROR;
283 }
284 
285 //------------------
286 // fini
287 //------------------
289 {
290  // Called before program exit after event processing is finished.
291 
292 
293  return NOERROR;
294 }
295 
static TH1I * h1_adc_noMatchTO_tdc
static TH2I * h2_sector_adc_multip
static TH2I * h2_sector_hit_multip
static TH1I * h1_hit_sec
const uint32_t ADC_MULTI_MAX
const Int_t NCHANNELS
jerror_t init(void)
Called once at program start.
uint32_t Get_L1FrontPanelTriggerBits(void) const
JApplication * japp
static TH1I * h1_tdc_noMatchTO_adc
const uint32_t TDC_MULTI_MAX
static TH1I * st_num_events
const uint32_t ADC_MULTI_MIN
TH1I ** h1_hit_multiplicity
static TH2I * h2_st_adc_hit_multi
static TH2I * h2_tdc_unmatched
InitPlugin_t InitPlugin
static TH1I * h1_adc_sec
const uint32_t TDC_MULTI_BINS
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
const uint32_t TDC_MULTI_MIN
const uint32_t ADC_MULTI_BINS
static TH2I * h2_st_adc_tdc_multi
static TH1I * h1_tdc_sec
TH2I ** h2_ADC_TDC_multiplicity
static TH2I * h2_sector_tdc_multip
jerror_t fini(void)
Called after last event of last event source has been processed.
static TH2I * h2_adc_unmatched
TH1I ** h1_ADC_multiplicity
int main(int argc, char *argv[])
Definition: gendoc.cc:6
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
TH1I ** h1_TDC_multiplicity