Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_BCAL_inv_mass.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DEventProcessor_BCAL_Shower.cc
4 // Created: Fri Oct 10 16:41:18 EDT 2014
5 // Creator: wmcginle (on Linux ifarm1101 2.6.32-220.7.1.el6.x86_64 x86_64)
6 //
7 
9 
10 #include <TLorentzVector.h>
11 #include "TMath.h"
12 
13 #include "JANA/JApplication.h"
14 #include "DANA/DApplication.h"
15 #include "BCAL/DBCALShower.h"
16 #include "BCAL/DBCALTruthShower.h"
17 #include "BCAL/DBCALCluster.h"
18 #include "BCAL/DBCALPoint.h"
19 #include "BCAL/DBCALHit.h"
20 #include "FCAL/DFCALCluster.h"
22 #include "PID/DVertex.h"
23 
24 //#include "TRACKING/DTrackFinder.h"
25 #include "TRIGGER/DTrigger.h"
26 
27 #include <vector>
28 #include <deque>
29 #include <string>
30 #include <iostream>
31 #include <algorithm>
32 #include <stdio.h>
33 #include <stdlib.h>
34 
35 // Routine used to create our DEventProcessor
36 
37 
38 static TH1I* bcal_diphoton_mass_300 = NULL;
39 static TH1I* bcal_diphoton_mass_500 = NULL;
40 static TH1I* bcal_diphoton_mass_700 = NULL;
41 static TH1I* bcal_diphoton_mass_900 = NULL;
42 
43 static TH2I* bcal_diphoton_mass_v_E = NULL;
44 static TH2I* bcal_diphoton_mass_v_z_lowE = NULL;
45 static TH2I* bcal_diphoton_mass_v_z_highE = NULL;
46 
47 static TH1I* bcal_fcal_diphoton_mass_300 = NULL;
48 static TH1I* bcal_fcal_diphoton_mass_500 = NULL;
49 static TH1I* bcal_fcal_diphoton_mass_700 = NULL;
50 static TH1I* bcal_fcal_diphoton_mass_900 = NULL;
51 
52 extern "C"
53 {
54  void InitPlugin(JApplication *locApplication)
55  {
56  InitJANAPlugin(locApplication);
57  locApplication->AddProcessor(new JEventProcessor_BCAL_inv_mass()); //register this plugin
58  }
59 } // "C"
60 
61 //------------------
62 // init
63 //------------------
65 {
66  // This is called once at program startup. If you are creating
67  // and filling historgrams in this plugin, you should lock the
68  // ROOT mutex like this:
69 
70  if(bcal_diphoton_mass_500 != NULL){
71  return NOERROR;
72  }
73 
74  TDirectory *main = gDirectory;
75  gDirectory->mkdir("bcal_inv_mass")->cd();
76 
77  bcal_diphoton_mass_300 = new TH1I("bcal_diphoton_mass_300","bcal diphoton mass (Cluster E > 300 MeV)",100,0.0,1.0);
78  bcal_diphoton_mass_300->GetXaxis()->SetTitle("invariant mass [GeV]");
79  bcal_diphoton_mass_300->GetYaxis()->SetTitle("counts / 10 MeV");
80 
81  bcal_diphoton_mass_500 = new TH1I("bcal_diphoton_mass_500","bcal diphoton mass (Cluster E > 500 MeV)",100,0.0,1.0);
82  bcal_diphoton_mass_500->GetXaxis()->SetTitle("invariant mass [GeV]");
83  bcal_diphoton_mass_500->GetYaxis()->SetTitle("counts / 10 MeV");
84 
85  bcal_diphoton_mass_700 = new TH1I("bcal_diphoton_mass_700","bcal diphoton mass (Cluster E > 700 MeV)",100,0.0,1.0);
86  bcal_diphoton_mass_700->GetXaxis()->SetTitle("invariant mass [GeV]");
87  bcal_diphoton_mass_700->GetYaxis()->SetTitle("counts / 10 MeV");
88 
89  bcal_diphoton_mass_900 = new TH1I("bcal_diphoton_mass_900","bcal diphoton mass (Cluster E > 900 MeV)",100,0.0,1.0);
90  bcal_diphoton_mass_900->GetXaxis()->SetTitle("invariant mass [GeV]");
91  bcal_diphoton_mass_900->GetYaxis()->SetTitle("counts / 10 MeV");
92 
93  bcal_diphoton_mass_v_E = new TH2I("bcal_diphoton_mass_v_E","bcal diphoton mass v E(Both Showers within 100 MeV)",600,0,1.2,100,0,.3);
94  bcal_diphoton_mass_v_E->GetXaxis()->SetTitle("shower energy [GeV]");
95  bcal_diphoton_mass_v_E->GetYaxis()->SetTitle("2#gamma mass [GeV]");
96 
97  bcal_diphoton_mass_v_z_lowE = new TH2I("bcal_diphoton_mass_v_z_lowE","bcal diphoton mass v z(Both showers 300<E<500MeV)",213,0,426,100,0,.3);
98  bcal_diphoton_mass_v_z_lowE->GetXaxis()->SetTitle("shower z [cm]");
99  bcal_diphoton_mass_v_z_lowE->GetYaxis()->SetTitle("2#gamma mass [GeV]");
100 
101  bcal_diphoton_mass_v_z_highE = new TH2I("bcal_diphoton_mass_v_z_highE","bcal diphoton mass v z(Both showers 500<E<700MeV)",213,0,426,100,0,.3);
102  bcal_diphoton_mass_v_z_highE->GetXaxis()->SetTitle("shower z [cm]");
103  bcal_diphoton_mass_v_z_highE->GetYaxis()->SetTitle("2#gamma mass [GeV]");
104 
105  bcal_fcal_diphoton_mass_300 = new TH1I("bcal_fcal_diphoton_mass_300","bcal and fcal diphoton mass (Cluster E > 300 MeV)",100,0.0,1.0);
106  bcal_fcal_diphoton_mass_300->GetXaxis()->SetTitle("invariant mass [GeV]");
107  bcal_fcal_diphoton_mass_300->GetYaxis()->SetTitle("counts / 10 MeV");
108 
109  bcal_fcal_diphoton_mass_500 = new TH1I("bcal_fcal_diphoton_mass_500","bcal and fcal diphoton mass (Cluster E > 500 MeV)",100,0.0,1.0);
110  bcal_fcal_diphoton_mass_500->GetXaxis()->SetTitle("invariant mass [GeV]");
111  bcal_fcal_diphoton_mass_500->GetYaxis()->SetTitle("counts / 10 MeV");
112 
113  bcal_fcal_diphoton_mass_700 = new TH1I("bcal_fcal_diphoton_mass_700","bcal and fcal diphoton mass (Cluster E > 700 MeV)",100,0.0,1.0);
114  bcal_fcal_diphoton_mass_700->GetXaxis()->SetTitle("invariant mass [GeV]");
115  bcal_fcal_diphoton_mass_700->GetYaxis()->SetTitle("counts / 10 MeV");
116 
117  bcal_fcal_diphoton_mass_900 = new TH1I("bcal_fcal_diphoton_mass_900","bcal and fcal diphoton mass (Cluster E > 900 MeV)",100,0.0,1.0);
118  bcal_fcal_diphoton_mass_900->GetXaxis()->SetTitle("invariant mass [GeV]");
119  bcal_fcal_diphoton_mass_900->GetYaxis()->SetTitle("counts / 10 MeV");
120 
121 
122 
123  // ... create historgrams or trees ...
124 
125  // TDirectory *dir = new TDirectoryFile("BCAL","BCAL");
126  // dir->cd();
127 
128  main->cd();
129 
130  return NOERROR;
131 }
132 
133 
134 //------------------
135 // brun
136 //------------------
137 jerror_t JEventProcessor_BCAL_inv_mass::brun(jana::JEventLoop* locEventLoop, int locRunNumber)
138 {
139 
140  return NOERROR;
141 }
142 
143 //------------------
144 // evnt
145 //------------------
146 
147 
148 
149 
150 jerror_t JEventProcessor_BCAL_inv_mass::evnt(jana::JEventLoop* locEventLoop, uint64_t locEventNumber)
151 {
152 
153  // This is called for every event. Use of common resources like writing
154  // to a file or filling a histogram should be mutex protected. Using
155  // locEventLoop->Get(...) to get reconstructed objects (and thereby activating the
156  // reconstruction algorithm) should be done outside of any mutex lock
157  // since multiple threads may call this method at the same time.
158  //
159  // Here's an example:
160  //
161  // vector<const MyDataClass*> mydataclasses;
162  // locEventLoop->Get(mydataclasses);
163  //
164  // japp->RootWriteLock();
165  // ... fill historgrams or trees ...
166  // japp->RootUnLock();
167 
168  // DOCUMENTATION:
169  // ANALYSIS library: https://halldweb1.jlab.org/wiki/index.php/GlueX_Analysis_Software
170 
171  const DTrigger* locTrigger = NULL;
172  locEventLoop->GetSingle(locTrigger);
173  if(locTrigger->Get_L1FrontPanelTriggerBits() != 0)
174  return NOERROR;
175 
176  vector<const DTrackFitter *> fitters;
177  locEventLoop->Get(fitters);
178 
179  if(fitters.size()<1){
180  _DBG_<<"Unable to get a DTrackFinder object!"<<endl;
181  return RESOURCE_UNAVAILABLE;
182  }
183  const DTrackFitter *fitter = fitters[0];
184 
185  vector<const DBCALShower*> locBCALShowers;
186  vector<const DFCALCluster*> locFCALClusters;
187  vector<const DVertex*> kinfitVertex;
188  //const DDetectorMatches* locDetectorMatches = NULL;
189  //locEventLoop->GetSingle(locDetectorMatches);
190  locEventLoop->Get(locBCALShowers);
191  locEventLoop->Get(locFCALClusters);
192  locEventLoop->Get(kinfitVertex);
193 
194  if(locBCALShowers.size() > 15) return NOERROR;
195 
196  vector<const DTrackTimeBased*> locTrackTimeBased;
197  locEventLoop->Get(locTrackTimeBased);
198 
199  vector <const DBCALShower*> matchedShowers;
200  vector <const DFCALCluster*> matchedFCALClusters;
201  vector <const DTrackTimeBased*> matchedTracks;
202  DVector3 mypos(0.0,0.0,0.0);
203 
204  for (unsigned int i=0; i < locTrackTimeBased.size() ; ++i){
205  vector<DTrackFitter::Extrapolation_t>extrapolations=locTrackTimeBased[i]->extrapolations.at(SYS_BCAL);
206  if (extrapolations.size()>0){
207  for (unsigned int j=0; j< locBCALShowers.size(); ++j){
208 
209  double x = locBCALShowers[j]->x;
210  double y = locBCALShowers[j]->y;
211  double z = locBCALShowers[j]->z;
212  DVector3 pos_bcal(x,y,z);
213  double R = pos_bcal.Perp();
214  if (fitter->ExtrapolateToRadius(R,extrapolations,mypos)){
215  //double dPhi = TMath::Abs(mypos.Phi()-pos_bcal.Phi());
216  double dPhi = mypos.Phi()-pos_bcal.Phi();
217  if (dPhi<-M_PI) dPhi+=2.*M_PI;
218  if (dPhi>M_PI) dPhi-=2.*M_PI;
219  double dZ = TMath::Abs(mypos.Z() - z);
220 
221  if(dZ < 30.0 && fabs(dPhi) < 0.18 ) {
222  matchedShowers.push_back(locBCALShowers[j]);
223  matchedTracks.push_back(locTrackTimeBased[i]);
224 
225  }
226  }
227  }
228  }
229  }
230 
231  for(unsigned int i = 0 ; i < locTrackTimeBased.size(); ++i)
232  {
233  vector<DTrackFitter::Extrapolation_t>extrapolations=locTrackTimeBased[i]->extrapolations.at(SYS_FCAL);
234  if (extrapolations.size()>0){
235  for(unsigned int j = 0 ; j < locFCALClusters.size(); ++j)
236  {
237  const DFCALCluster *c1 = locFCALClusters[j];
238  double x = c1->getCentroid().X();
239  double y = c1->getCentroid().Y();
240  double z = c1->getCentroid().Z();
241  DVector3 fcalpos(x,y,z);
242  //cout << " x = " << x << " y = " << y << endl;
243  DVector3 pos=extrapolations[0].position;
244 
245  double diffX = TMath::Abs(x - pos.X());
246  double diffY = TMath::Abs(y - pos.Y());
247  if(diffX < 3.0 && diffY < 3.0)
248  {
249  matchedFCALClusters.push_back(locFCALClusters[j]);
250  }
251  }
252  }
253 
254  }
255 
256  vector <const DChargedTrackHypothesis*> locParticles;
257  double kinfitVertexX = 0.0, kinfitVertexY = 0.0, kinfitVertexZ = 0.0;
258  for (unsigned int i = 0 ; i < kinfitVertex.size(); i++)
259  {
260  kinfitVertexX = kinfitVertex[i]->dSpacetimeVertex.X();
261  kinfitVertexY = kinfitVertex[i]->dSpacetimeVertex.Y();
262  kinfitVertexZ = kinfitVertex[i]->dSpacetimeVertex.Z();
263  //p
264  //kinfitVertexT = kinfitVertex[i]->dSpacetimeVertex.T();
265  }
266 
267  // FILL HISTOGRAMS
268  // Since we are filling histograms local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
269  japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
270 
271  for(unsigned int i=0; i<locBCALShowers.size(); i++)
272  {
273  // if(locDetectorMatches->Get_IsMatchedToTrack(locBCALShowers[i]))
274  // continue;
275  if (find(matchedShowers.begin(), matchedShowers.end(),locBCALShowers[i]) != matchedShowers.end()) continue;
276  const DBCALShower *s1 = locBCALShowers[i];
277  double dx1 = s1->x - kinfitVertexX;
278  double dy1 = s1->y - kinfitVertexY;
279  double dz1 = s1->z - kinfitVertexZ;
280  double z1 = s1->z;
281  double R1 = sqrt(dx1*dx1 + dy1*dy1 + dz1*dz1);
282  double E1 = s1->E;
283  double E1_raw = s1->E_raw;
284  TLorentzVector sh1_p(E1*dx1/R1, E1*dy1/R1, E1*dz1/R1, E1);
285  TLorentzVector sh1_p_raw(E1_raw*dx1/R1, E1_raw*dy1/R1, E1_raw*dz1/R1, E1_raw);
286  for(unsigned int j=i+1; j<locBCALShowers.size(); j++){
287  const DBCALShower *s2 = locBCALShowers[j];
288  if (find(matchedShowers.begin(), matchedShowers.end(),s2) != matchedShowers.end()) continue;
289  double dx2 = s2->x - kinfitVertexX;
290  double dy2 = s2->y - kinfitVertexY;
291  double dz2 = s2->z - kinfitVertexZ; // shift to coordinate relative to center of target
292  double z2 = s2->z;
293  double z_avg = (z1+z2)/2.;
294  double R2 = sqrt(dx2*dx2 + dy2*dy2 + dz2*dz2);
295  double E2 = s2->E;
296  double E2_raw = s2->E_raw;
297  double E_avg = (E1_raw + E2_raw)/2.;
298  TLorentzVector sh2_p(E2*dx2/R2, E2*dy2/R2, E2*dz2/R2, E2);
299  TLorentzVector sh2_p_raw(E2_raw*dx2/R2, E2_raw*dy2/R2, E2_raw*dz2/R2, E2_raw);
300  TLorentzVector ptot = sh1_p+sh2_p;
301  TLorentzVector ptot_raw = sh1_p_raw + sh2_p_raw ;
302  double inv_mass_raw = ptot_raw.M();
303  if(E1_raw>.3&&E2_raw>.3) bcal_diphoton_mass_300->Fill(inv_mass_raw);
304  if(E1_raw>.5&&E2_raw>.5) bcal_diphoton_mass_500->Fill(inv_mass_raw);
305  if(E1_raw>.9&&E2_raw>.9) bcal_diphoton_mass_900->Fill(inv_mass_raw);
306  if(E1_raw>.7&&E2_raw>.7) bcal_diphoton_mass_700->Fill(inv_mass_raw);
307  if(fabs(E1_raw-E2_raw)<.1) bcal_diphoton_mass_v_E->Fill(E_avg,inv_mass_raw);
308  if(fabs(z1-z2)<100. && E1_raw>.3 && E2_raw>.3 && E1_raw<.5 && E2_raw<.5) bcal_diphoton_mass_v_z_lowE->Fill(z_avg,inv_mass_raw);
309  if(fabs(z1-z2)<100. && E1_raw>.5 && E2_raw>.5 && E1_raw<.7 && E2_raw<.7) bcal_diphoton_mass_v_z_highE->Fill(z_avg,inv_mass_raw);
310  }
311  for(unsigned int j=0; j<locFCALClusters.size(); j++){
312  if (find(matchedFCALClusters.begin(), matchedFCALClusters.end(),locFCALClusters[j]) != matchedFCALClusters.end()) continue;
313  const DFCALCluster *cl2 = locFCALClusters[j];
314  double dx2 = cl2->getCentroid().X()-kinfitVertexX;
315  double dy2 = cl2->getCentroid().Y()-kinfitVertexY;
316  double dz2 = cl2->getCentroid().Z()-kinfitVertexZ;
317  double fcal_E = cl2->getEnergy();
318  double R2 = sqrt(dx2*dx2 + dy2*dy2 + dz2*dz2);
319  TLorentzVector cl2_p(fcal_E*dx2/R2, fcal_E*dy2/R2, fcal_E*dz2/R2, fcal_E);
320  TLorentzVector ptot_fcal_bcal = sh1_p_raw + cl2_p;
321  double inv_mass = ptot_fcal_bcal.M();
322  if(E1_raw>.3&&fcal_E>.3) bcal_fcal_diphoton_mass_300->Fill(inv_mass);
323  if(E1_raw>.5&&fcal_E>.5) bcal_fcal_diphoton_mass_500->Fill(inv_mass);
324  if(E1_raw>.7&&fcal_E>.7) bcal_fcal_diphoton_mass_700->Fill(inv_mass);
325  if(E1_raw>.9&&fcal_E>.9) bcal_fcal_diphoton_mass_900->Fill(inv_mass);
326  }
327  }
328 
329 
330  japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
331 
332 
333  /*
334  //Optional: Save event to output REST file. Use this to create skims.
335  dEventWriterREST->Write_RESTEvent(locEventLoop, "BCAL_Shower"); //string is part of output file name
336  */
337 
338  return NOERROR;
339 }
340 
341 //------------------
342 // erun
343 //------------------
345 {
346  // This is called whenever the run number changes, before it is
347  // changed to give you a chance to clean up before processing
348  // events from the next run number.
349 
350  return NOERROR;
351 }
352 
353 //------------------
354 // fini
355 //------------------
357 {
358  // Called before program exit after event processing is finished.
359  return NOERROR;
360 }
361 
static TH1I * bcal_diphoton_mass_900
DVector3 getCentroid() const
Definition: DFCALCluster.h:183
static double E1[100]
bool ExtrapolateToRadius(double R, const vector< Extrapolation_t > &extraps, DVector3 &pos, DVector3 &mom, double &t, double &s) const
The DTrackFitter class is a base class for different charged track fitting algorithms. It does not actually fit the track itself, but provides the interface and some common support features most algorthims will need to implement.
Definition: DTrackFitter.h:61
TVector3 DVector3
Definition: DVector3.h:14
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
#define y
static TH1I * bcal_diphoton_mass_500
uint32_t Get_L1FrontPanelTriggerBits(void) const
jerror_t fini(void)
Called after last event of last event source has been processed.
Definition: GlueX.h:19
Double_t c1[2][NMODULES]
Definition: tw_corr.C:68
JApplication * japp
double getEnergy() const
Definition: DFCALCluster.h:155
InitPlugin_t InitPlugin
static TH1I * bcal_fcal_diphoton_mass_700
static TH2I * bcal_diphoton_mass_v_z_highE
static TH2I * bcal_diphoton_mass_v_E
Definition: GlueX.h:22
#define _DBG_
Definition: HDEVIO.h:12
jerror_t brun(jana::JEventLoop *locEventLoop, int locRunNumber)
Called every time a new run number is detected.
double sqrt(double)
static TH1I * bcal_fcal_diphoton_mass_900
jerror_t init(void)
Called once at program start.
jerror_t evnt(jana::JEventLoop *locEventLoop, uint64_t locEventNumber)
Called every event.
const DTrackFitter * fitter
jerror_t erun(void)
Called every time run number changes, provided brun has been called.
static TH1I * bcal_diphoton_mass_300
static TH2I * bcal_diphoton_mass_v_z_lowE
static TH1I * bcal_fcal_diphoton_mass_500
static TH1I * bcal_fcal_diphoton_mass_300
static TH1I * bcal_diphoton_mass_700
int main(int argc, char *argv[])
Definition: gendoc.cc:6
float E_raw
Definition: DBCALShower.h:18