Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_TAGM_clusters.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_TAGM_clusters.cc
4 // Created: Tue Jul 5 21:19:22 EDT 2016
5 // Creator: barnes (on Linux gluey.phys.uconn.edu 2.6.32-573.22.1.el6.x86_64 x86_64)
6 //
7 
9 using namespace jana;
10 
11 #include <TH1.h>
12 #include <TH2.h>
13 #include <TDirectory.h>
14 
15 #include <TAGGER/DTAGMGeometry.h>
16 #include <TAGGER/DTAGMHit.h>
17 
19 
20 static TH1D *h_occupancy_b; // occupancy before merging
21 static TH1D *h_occupancy_a; // occupancy after merging
22 static TH1D *h_occupancy_ind; // occupancy of ind. channels
23 static TH1I *h_deltaT[10]; // delta T of neighbors before merging
24 static TH1I *h_mult_b; // multiplicity before merging
25 static TH1I *h_mult_a; // multiplicity after merging
26 static TH1I *h_E_b; // energy before merging
27 static TH1I *h_E_a; // energy after merging
28 
29 // Routine used to create our JEventProcessor
30 #include <JANA/JApplication.h>
31 #include <JANA/JFactory.h>
32 extern "C"{
33 void InitPlugin(JApplication *app){
34  InitJANAPlugin(app);
35  app->AddProcessor(new JEventProcessor_TAGM_clusters());
36 }
37 } // "C"
38 
39 
40 //------------------
41 // JEventProcessor_TAGM_clusters (Constructor)
42 //------------------
44 {
45 
46 }
47 
48 //------------------
49 // ~JEventProcessor_TAGM_clusters (Destructor)
50 //------------------
52 {
53 
54 }
55 
56 //------------------
57 // init
58 //------------------
60 {
61  // This is called once at program startup.
62 
63  TDirectory *mainDir = gDirectory;
64  TDirectory *tagmDir = gDirectory->mkdir("TAGM_clusters");
65  tagmDir->cd();
66  // Before
67  gDirectory->mkdir("Before")->cd();
68  h_occupancy_b = new TH1D("occupancy_b","Histogram of occupancy",NCOLUMNS,1,NCOLUMNS+1);
69  h_mult_b = new TH1I("mult_b","Multiplicity before",40,0.,40.);
70  h_E_b = new TH1I("E_b","Energy before merging",110,8.2,9.3);
71  for (uint32_t i = 0; i < 10; ++i)
72  {
73  h_deltaT[i] = new TH1I(Form("deltaT_%i",i+1),
74  Form("#Deltat of neighboring hits, group %i",i+1),
75  100,-10.,10.);
76  }
77 
78  tagmDir->cd();
79 
80  // After
81  gDirectory->mkdir("After")->cd();
82  h_occupancy_a = new TH1D("occupancy_a","Histogram of occupancy",NCOLUMNS,1,NCOLUMNS+1);
83  h_mult_a = new TH1I("mult_a","Multiplicity after",40,0.,40.);
84  h_E_a = new TH1I("E_a","Energy after merging",110,8.2,9.3);
85 
86  tagmDir->cd();
87 
88  h_occupancy_ind = new TH1D("occupancy_ind","Histogram of occupancy",20,1,21);
89  // back to main dir
90  mainDir->cd();
91 
92  return NOERROR;
93 }
94 
95 //------------------
96 // brun
97 //------------------
98 jerror_t JEventProcessor_TAGM_clusters::brun(JEventLoop *eventLoop, int32_t runnumber)
99 {
100  // This is called whenever the run number changes
101  return NOERROR;
102 }
103 
104 //------------------
105 // evnt
106 //------------------
107 jerror_t JEventProcessor_TAGM_clusters::evnt(JEventLoop *loop, uint64_t eventnumber)
108 {
109  // This is called for every event. Use of common resources like writing
110  // to a file or filling a histogram should be mutex protected. Using
111  // loop->Get(...) to get reconstructed objects (and thereby activating the
112  // reconstruction algorithm) should be done outside of any mutex lock
113  // since multiple threads may call this method at the same time.
114  // Here's an example:
115  //
116  // vector<const MyDataClass*> mydataclasses;
117  // loop->Get(mydataclasses);
118  //
119  // japp->RootFillLock(this);
120  // ... fill historgrams or trees ...
121  // japp->RootFillUnLock(this);
122 
123  vector<const DTAGMHit*> tagm_hits;
124  loop->Get(tagm_hits, "Calib");
125  vector<const DTAGMHit*> tagm_merged_hits;
126  loop->Get(tagm_merged_hits);
127 
128  japp->RootFillLock(this);
129 
130  // Get occupancies and multiplicities before merging
131  int mult_b = 0;
132  for (uint32_t i = 0; i < tagm_hits.size(); ++i)
133  {
134  if (!tagm_hits[i]->has_fADC) continue;
135  if (tagm_hits[i]->row > 0) continue;
136 
137  h_occupancy_b->Fill(tagm_hits[i]->column);
138  h_E_b->Fill(tagm_hits[i]->E);
139  mult_b++;
140  }
141  h_mult_b->Fill(mult_b);
142 
143  // Get occupancies and multiplicities after merging
144  int mult_a = 0;
145  for (uint32_t i = 0; i < tagm_merged_hits.size(); ++i)
146  {
147  if (!tagm_merged_hits[i]->has_fADC) continue;
148  if (tagm_merged_hits[i]->row > 0)
149  {
150  int col = tagm_merged_hits[i]->column;
151  int row = tagm_merged_hits[i]->row;
152  if (col == 9)
153  h_occupancy_ind->Fill(row);
154  else if (col == 27)
155  h_occupancy_ind->Fill(5+row);
156  else if (col == 81)
157  h_occupancy_ind->Fill(10+row);
158  else if (col == 99)
159  h_occupancy_ind->Fill(15+row);
160  continue;
161  }
162 
163  h_occupancy_a->Fill(tagm_merged_hits[i]->column);
164  h_E_a->Fill(tagm_merged_hits[i]->E);
165  mult_a++;
166  }
167  h_mult_a->Fill(mult_a);
168 
169  // Check time differences between pre-merge neighbors
170  set<uint32_t> locColUsedSoFar;
171  for (uint32_t i = 0; i < tagm_hits.size(); ++i)
172  {
173  if (!tagm_hits[i]->has_fADC) continue;
174  if (tagm_hits[i]->row > 0) continue;
175 
176  // check if column has been paired
177  if (locColUsedSoFar.find(tagm_hits[i]->column) != locColUsedSoFar.end()) continue;
178 
179  for (uint32_t j = i+1; j < tagm_hits.size(); ++j)
180  {
181  if (!tagm_hits[j]->has_fADC) continue;
182  if (tagm_hits[j]->row > 0) continue;
183 
184  int diff = tagm_hits[i]->column - tagm_hits[j]->column;
185  double deltaT = tagm_hits[i]->t - tagm_hits[j]->t;
186  if (fabs(diff) == 1)
187  {
188  if (tagm_hits[i]->column < 11)
189  h_deltaT[0]->Fill(deltaT);
190  else if (tagm_hits[i]->column < 21)
191  h_deltaT[1]->Fill(deltaT);
192  else if (tagm_hits[i]->column < 31)
193  h_deltaT[2]->Fill(deltaT);
194  else if (tagm_hits[i]->column < 41)
195  h_deltaT[3]->Fill(deltaT);
196  else if (tagm_hits[i]->column < 51)
197  h_deltaT[4]->Fill(deltaT);
198  else if (tagm_hits[i]->column < 61)
199  h_deltaT[5]->Fill(deltaT);
200  else if (tagm_hits[i]->column < 71)
201  h_deltaT[6]->Fill(deltaT);
202  else if (tagm_hits[i]->column < 81)
203  h_deltaT[7]->Fill(deltaT);
204  else if (tagm_hits[i]->column < 91)
205  h_deltaT[8]->Fill(deltaT);
206  else
207  h_deltaT[9]->Fill(deltaT);
208  }
209  if (fabs(diff) == 1 && fabs(deltaT) <= 5)
210  {
211  locColUsedSoFar.insert(tagm_hits[j]->column);
212  break;
213  }
214  }
215  }
216 
217  japp->RootFillUnLock(this);
218 
219  return NOERROR;
220 }
221 
222 //------------------
223 // erun
224 //------------------
226 {
227  // This is called whenever the run number changes, before it is
228  // changed to give you a chance to clean up before processing
229  // events from the next run number.
230  return NOERROR;
231 }
232 
233 //------------------
234 // fini
235 //------------------
237 {
238  // Called before program exit after event processing is finished.
239  return NOERROR;
240 }
241 
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
static TH1I * h_mult_a
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
TDirectory * mainDir
Definition: p2k_hists.C:2
JApplication * japp
jerror_t fini(void)
Called after last event of last event source has been processed.
InitPlugin_t InitPlugin
static TH1D * h_occupancy_a
const uint32_t NCOLUMNS
static TH1I * h_mult_b
static TH1D * h_occupancy_b
static TH1I * h_deltaT[10]
static TH1I * h_E_a
jerror_t init(void)
Called once at program start.
static const unsigned int kColumnCount
Definition: DTAGMGeometry.h:31
static TH1I * h_E_b
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
static TH1D * h_occupancy_ind