Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_TAGH_doubles.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_TAGH_doubles.cc
4 // Created: Fri Apr 29 15:19:27 EDT 2016
5 // Creator: nsparks (on Linux cua2.jlab.org 3.10.0-327.13.1.el7.x86_64 x86_64)
6 //
7 
9 using namespace jana;
10 using namespace std;
11 
12 // Routine used to create our JEventProcessor
13 #include <JANA/JApplication.h>
14 #include <JANA/JFactory.h>
15 
16 #include <TAGGER/DTAGHHit.h>
17 #include <TAGGER/DTAGHGeometry.h>
18 #include <TDirectory.h>
19 #include <TH1.h>
20 #include <TH2.h>
21 
23 const int NmultBins = 200; // number of bins for multiplicity histograms
24 
25 static TH2I *hBM_tdiffVsIDdiff;
26 static TH2I *hAM_tdiffVsIDdiff;
27 static TH1F *hBM1_Occupancy;
28 static TH1F *hBM2_Occupancy;
29 static TH1F *hAM1_Occupancy;
30 static TH1F *hAM2_Occupancy;
31 static TH1F *hAM3_Occupancy;
32 static TH1F *hBM1_Energy;
33 static TH1F *hBM2_Energy;
34 static TH1F *hAM1_Energy;
35 static TH1F *hAM2_Energy;
36 static TH1F *hAM3_Energy;
37 static TH1I *hBM_NHits;
38 static TH1I *hAM_NHits;
39 static TH2I *hBM1_PulseHeightVsID;
40 static TH2I *hBM2_PulseHeightVsID;
41 
42 extern "C"{
43  void InitPlugin(JApplication *app){
44  InitJANAPlugin(app);
45  app->AddProcessor(new JEventProcessor_TAGH_doubles());
46  }
47 } // "C"
48 
49 
50 //------------------
51 // JEventProcessor_TAGH_doubles (Constructor)
52 //------------------
54 {
55 
56 }
57 
58 //------------------
59 // ~JEventProcessor_TAGH_doubles (Destructor)
60 //------------------
62 {
63 
64 }
65 
66 //------------------
67 // init
68 //------------------
70 {
71  // This is called once at program startup.
72  TDirectory *mainDir = gDirectory;
73  TDirectory *taghDir = gDirectory->mkdir("TAGH_doubles");
74  taghDir->cd();
75  gDirectory->mkdir("BeforeMergingDoubles")->cd();
76  hBM_tdiffVsIDdiff = new TH2I("BM_tdiffVsIDdiff","TAGH 2-hit time difference vs. counter ID difference;counter ID difference;time difference [ns]",15,0.5,15.5,200,-5.0,5.0);
77  hBM_NHits = new TH1I("BM_NHits","TAGH multiplicity: All hits, before merging doubles;hits;events",NmultBins,0.5,0.5+NmultBins);
78  hBM1_Occupancy = new TH1F("BM1_Occupancy","TAGH occ.: All hits, before merging doubles;counter (slot) ID;hits / counter",Nslots,0.5,0.5+Nslots);
79  hBM2_Occupancy = new TH1F("BM2_Occupancy","TAGH occ.: Doubles only, before merging doubles;counter (slot) ID;hits / counter",Nslots,0.5,0.5+Nslots);
80  hBM1_Energy = new TH1F("BM1_Energy","TAGH energy: All hits, before merging doubles;photon energy [GeV];hits / counter",180,3.0,12.0);
81  hBM2_Energy = new TH1F("BM2_Energy","TAGH energy: Doubles only, before merging doubles;photon energy [GeV];hits / counter",180,3.0,12.0);
82  hBM1_PulseHeightVsID = new TH2I("BM1_PulseHeightVsID","TAGH ADC pulse height vs. ID: All hits;counter (slot) ID;pulse height",Nslots,0.5,0.5+Nslots,410,0.0,4100.0);
83  hBM2_PulseHeightVsID = new TH2I("BM2_PulseHeightVsID","TAGH ADC pulse height vs. ID: Doubles only;counter (slot) ID;pulse height",Nslots,0.5,0.5+Nslots,410,0.0,4100.0);
84  taghDir->cd();
85  gDirectory->mkdir("AfterMergingDoubles")->cd();
86  hAM_tdiffVsIDdiff = new TH2I("AM_tdiffVsIDdiff","TAGH 2-hit time difference vs. counter ID difference;counter ID difference;time difference [ns]",15,0.5,15.5,200,-5.0,5.0);
87  hAM_NHits = new TH1I("AM_NHits","TAGH multiplicity: All hits, after merging doubles;hits;events",NmultBins,0.5,0.5+NmultBins);
88  hAM1_Occupancy = new TH1F("AM1_Occupancy","TAGH occ.: All hits, after merging doubles;counter (slot) ID;hits / counter",Nslots,0.5,0.5+Nslots);
89  hAM2_Occupancy = new TH1F("AM2_Occupancy","TAGH occ.: Doubles only, after merging doubles;counter (slot) ID;hits / counter",Nslots,0.5,0.5+Nslots);
90  hAM3_Occupancy = new TH1F("AM3_Occupancy","TAGH occ.: Doubles only w/ overlaps, after merging doubles;counter (slot) ID;hits / counter",Nslots,0.5,0.5+Nslots);
91  hAM1_Energy = new TH1F("AM1_Energy","TAGH energy: All hits, after merging doubles;photon energy [GeV];hits / counter",180,3.0,12.0);
92  hAM2_Energy = new TH1F("AM2_Energy","TAGH energy: Doubles only, after merging doubles;photon energy [GeV];hits / counter",180,3.0,12.0);
93  hAM3_Energy = new TH1F("AM3_Energy","TAGH energy: Doubles only w/ overlaps, after merging doubles;photon energy [GeV];hits / counter",180,3.0,12.0);
94  // back to main dir
95  mainDir->cd();
96 
97 return NOERROR;
98 }
99 
100 //------------------
101 // brun
102 //------------------
103 jerror_t JEventProcessor_TAGH_doubles::brun(JEventLoop *eventLoop, int32_t runnumber)
104 {
105  // This is called whenever the run number changes
106  return NOERROR;
107 }
108 
109 //------------------
110 // evnt
111 //------------------
112 jerror_t JEventProcessor_TAGH_doubles::evnt(JEventLoop *loop, uint64_t eventnumber)
113 {
114  // This is called for every event. Use of common resources like writing
115  // to a file or filling a histogram should be mutex protected. Using
116  // loop->Get(...) to get reconstructed objects (and thereby activating the
117  // reconstruction algorithm) should be done outside of any mutex lock
118  // since multiple threads may call this method at the same time.
119 
120  // Get unmerged hits
121  vector<const DTAGHHit*> hits_c;
122  loop->Get(hits_c, "Calib");
123  // Get merged hits
124  vector<const DTAGHHit*> hits;
125  loop->Get(hits);
126 
127  // Extract the TAGH geometry
128  vector<const DTAGHGeometry*> taghGeomVect;
129  loop->Get(taghGeomVect);
130  if (taghGeomVect.size() < 1)
131  return OBJECT_NOT_AVAILABLE;
132  const DTAGHGeometry& taghGeom = *(taghGeomVect[0]);
133 
134  japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
135  // Before merging doubles
136  int BM_NHits = 0;
137  for (const auto& hit : hits_c) {
138  if (!hit->has_TDC||!hit->has_fADC) continue;
139  BM_NHits++;
140  hBM1_Occupancy->Fill(hit->counter_id);
141  hBM1_Energy->Fill(hit->E);
142  hBM1_PulseHeightVsID->Fill(hit->counter_id,hit->pulse_peak);
143  if (hit->is_double) hBM2_Occupancy->Fill(hit->counter_id);
144  if (hit->is_double) hBM2_Energy->Fill(hit->E);
145  if (hit->is_double) hBM2_PulseHeightVsID->Fill(hit->counter_id,hit->pulse_peak);
146  }
147  hBM_NHits->Fill(BM_NHits);
148  for (size_t i = 0; i < hits_c.size(); i++) {
149  const DTAGHHit* hit1 = hits_c[i];
150  if (!hit1->has_TDC||!hit1->has_fADC) continue;
151  for (size_t j = i+1; j < hits_c.size(); j++) {
152  const DTAGHHit* hit2 = hits_c[j];
153  if (!hit2->has_TDC||!hit2->has_fADC) continue;
154  hBM_tdiffVsIDdiff->Fill(abs(hit1->counter_id-hit2->counter_id),hit1->t-hit2->t);
155  }
156  }
157  // After merging doubles
158  int AM_NHits = 0;
159  for (const auto& hit : hits) {
160  if (!hit->has_TDC||!hit->has_fADC) continue;
161  AM_NHits++;
162  bool has_overlap = false;
163  if (hit->counter_id < 274) {
164  double El = taghGeom.getElow(hit->counter_id); double Eh1 = taghGeom.getEhigh(hit->counter_id+1);
165  has_overlap = (Eh1 > El);
166  }
167  hAM1_Occupancy->Fill(hit->counter_id);
168  hAM1_Energy->Fill(hit->E);
169  if (hit->is_double) hAM2_Occupancy->Fill(hit->counter_id);
170  if (hit->is_double) hAM2_Energy->Fill(hit->E);
171  if (hit->is_double && has_overlap) hAM3_Occupancy->Fill(hit->counter_id);
172  if (hit->is_double && has_overlap) hAM3_Energy->Fill(hit->E);
173  }
174  hAM_NHits->Fill(AM_NHits);
175  for (size_t i = 0; i < hits.size(); i++) {
176  const DTAGHHit* hit1 = hits[i];
177  if (!hit1->has_TDC||!hit1->has_fADC) continue;
178  for (size_t j = i+1; j < hits.size(); j++) {
179  const DTAGHHit* hit2 = hits[j];
180  if (!hit2->has_TDC||!hit2->has_fADC) continue;
181  hAM_tdiffVsIDdiff->Fill(abs(hit1->counter_id-hit2->counter_id),hit1->t-hit2->t);
182  }
183  }
184  japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
185 
186 
187  return NOERROR;
188 }
189 
190 //------------------
191 // erun
192 //------------------
194 {
195  // This is called whenever the run number changes, before it is
196  // changed to give you a chance to clean up before processing
197  // events from the next run number.
198  return NOERROR;
199 }
200 
201 //------------------
202 // fini
203 //------------------
205 {
206  // Called before program exit after event processing is finished.
207  return NOERROR;
208 }
double t
Definition: DTAGHHit.h:19
static TH1F * hAM2_Occupancy
static TH1F * hAM3_Occupancy
static TH1F * hBM2_Energy
double getElow(unsigned int counter) const
static TH2I * hBM_tdiffVsIDdiff
bool has_TDC
Definition: DTAGHHit.h:26
static TH1I * hAM_NHits
static TH1F * hAM1_Energy
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
const int NmultBins
TDirectory * mainDir
Definition: p2k_hists.C:2
static TH1F * hAM1_Occupancy
JApplication * japp
static TH2I * hBM1_PulseHeightVsID
int counter_id
Definition: DTAGHHit.h:20
static TH2I * hAM_tdiffVsIDdiff
static TH1I * hBM_NHits
static TH2I * hBM2_PulseHeightVsID
static TH1F * hBM2_Occupancy
InitPlugin_t InitPlugin
static TH1F * hBM1_Energy
static TH1F * hBM1_Occupancy
jerror_t init(void)
Called once at program start.
jerror_t fini(void)
Called after last event of last event source has been processed.
double getEhigh(unsigned int counter) const
const int Nslots
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
bool has_fADC
Definition: DTAGHHit.h:26
static TH1F * hAM3_Energy
static const unsigned int kCounterCount
Definition: DTAGHGeometry.h:28
static TH1F * hAM2_Energy
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.