Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_FCAL_invmass.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_FCAL_invmass.cc
4 // Created: Tue May 31 09:44:35 EDT 2016
5 // Creator: adesh (on Linux ifarm1101 2.6.32-431.el6.x86_64 x86_64)
6 //
7 
9 #include <TLorentzVector.h>
10 #include "TMath.h"
11 #include "JANA/JApplication.h"
12 #include "DANA/DApplication.h"
13 #include "FCAL/DFCALShower.h"
14 #include "FCAL/DFCALCluster.h"
15 #include "FCAL/DFCALHit.h"
17 #include "PID/DVertex.h"
18 #include "GlueX.h"
19 #include <vector>
20 #include <deque>
21 #include <string>
22 #include <iostream>
23 #include <algorithm>
24 #include <stdio.h>
25 #include <stdlib.h>
26 
27 static TH1I* InvMass1 = NULL;
28 static TH1I* InvMass2 = NULL;
29 static TH1I* InvMass3 = NULL;
30 static TH1I* InvMass4 = NULL;
31 static TH1I* InvMass5 = NULL;
32 static TH1I* InvMass6 = NULL;
33 static TH1I* InvMass7 = NULL;
34 static TH1I* InvMass8 = NULL;
35 static TH1I* InvMass9 = NULL;
36 static TH2I* hits2D_pi0 = NULL;
37 static TH1I* qualCut_05 = NULL;
38 static TH1I* qualCut_03 = NULL;
39 static TH1I* qualCut_00 = NULL;
40 
41 
42 extern "C"
43 {
44  void InitPlugin(JApplication *locApplication)
45  {
46  InitJANAPlugin(locApplication);
47  locApplication->AddProcessor(new JEventProcessor_FCAL_invmass()); //register this plugin
48  }
49 } // "C"
50 
51 //------------------
52 // init
53 //------------------
55 {
56 
57  if(InvMass1 && InvMass2 != NULL){
58  japp->RootUnLock();
59  return NOERROR;
60  }
61 
62  TDirectory *main = gDirectory;
63  gDirectory->mkdir("FCAL_invmass")->cd();
64 
65  InvMass1 = new TH1I("InvMass1","Shower E. > 500 MeV;Invariant Mass [GeV]; Counts / 1 MeV ",500,0.0,0.5);
66 
67  InvMass2 = new TH1I("InvMass2","Shower E. > 1000 MeV;Invariant Mass [GeV]; Counts / 1 MeV ",500,0.0,0.5);
68 
69  InvMass3 = new TH1I("InvMass3"," 500 MeV < Shower E. < 900 MeV ;Invariant Mass [GeV]; Counts / 1 MeV ",500,0.0,0.5);
70 
71  InvMass4 = new TH1I("InvMass4"," 900 MeV < Shower E. < 1400 MeV ;Invariant Mass [GeV]; Counts / 1 MeV ",500,0.0,0.5);
72 
73  InvMass5 = new TH1I("InvMass5"," 1400 MeV < Shower E. < 1900 MeV ;Invariant Mass [GeV]; Counts / 1 MeV ",500,0.0,0.5);
74 
75  InvMass6 = new TH1I("InvMass6"," 1900 MeV < Shower E. < 2400 MeV ;Invariant Mass [GeV]; Counts / 1 MeV ",500,0.0,0.5);
76 
77  InvMass7 = new TH1I("InvMass7"," 2400 MeV < Shower E. < 2900 MeV ;Invariant Mass [GeV]; Counts / 1 MeV ",500,0.0,0.5);
78 
79  InvMass8 = new TH1I("InvMass8"," 2900 MeV < Shower E. < 3400 MeV ;Invariant Mass [GeV]; Counts / 1 MeV ",500,0.0,0.5);
80 
81  InvMass9 = new TH1I("InvMass9"," 3400 MeV < Shower E. < 3900 MeV ;Invariant Mass [GeV]; Counts / 1 MeV ",500,0.0,0.5);
82 
83  hits2D_pi0 = new TH2I( "hits2D_pi0", "FCAL Pi0 Shower Hits; X [4 cm] ; Y [4 cm]", 61, -30, 30, 61, -30, 30 );
84 
85  qualCut_00 = new TH1I("qualCut_00", "Quality > 0 ; Invariant MAss [GeV]; Counts / 1 MeV", 500, 0.0, 0.5);
86 
87  qualCut_03 = new TH1I("qualCut_03", "Quality > 0.3 ; Invariant MAss [GeV]; Counts / 1 MeV", 500, 0.0, 0.5);
88 
89  qualCut_05 = new TH1I("qualCut_05", "Quality > 0.5 ; Invariant MAss [GeV]; Counts / 1 MeV", 500, 0.0, 0.5);
90 
91  main->cd();
92 
93 
94  return NOERROR;
95 }
96 
97 
98 
99 //------------------
100 // brun
101 //------------------
102 jerror_t JEventProcessor_FCAL_invmass::brun(jana::JEventLoop* locEventLoop, int32_t locRunNumber)
103 {
104  DApplication* locApplication = dynamic_cast<DApplication*>(locEventLoop->GetJApplication());
105  double z_target; double z_fcal;
106  const DGeometry* dgeom = locApplication->GetDGeometry(locRunNumber);
107 
108  dgeom->GetTargetZ(z_target);
109  dgeom->GetFCALZ(z_fcal);
110 
111  z_diff = z_fcal - z_target;
112 
113  return NOERROR;
114 }
115 
116 jerror_t JEventProcessor_FCAL_invmass::evnt(jana::JEventLoop* locEventLoop, uint64_t locEventNumber)
117 {
118  map< const DFCALShower*, double > showerQualityMap;
119  vector< const DNeutralShower* > neutralShowers;
120  vector< const DFCALHit*> hits;
121 
122  vector< const DFCALShower* > locFCALShowers;
123  vector< const DVertex* > kinfitVertex;
124  vector< const DTrackTimeBased* > locTrackTimeBased;
125 
126  locEventLoop->Get( hits );
127 
128  if( hits.size() <= 500 ){ // only form clusters and showers if there aren't too many hits
129 
130  locEventLoop->Get(locFCALShowers);
131  locEventLoop->Get(kinfitVertex);
132  locEventLoop->Get(locTrackTimeBased);
133  locEventLoop->Get( neutralShowers );
134  }
135 
136  for( size_t i = 0; i < neutralShowers.size(); ++i ){
137 
138  if( neutralShowers[i]->dDetectorSystem == SYS_FCAL ){
139 
140  const DFCALShower* fcalShower = dynamic_cast< const DFCALShower* >( neutralShowers[i]->dBCALFCALShower );
141  showerQualityMap[fcalShower] = neutralShowers[i]->dQuality;
142  }
143  }
144 
145 
146  vector < const DFCALShower * > matchedShowers;
147  vector < const DTrackTimeBased* > matchedTracks;
148  vector <const DChargedTrackHypothesis*> locParticles;
149 
150 
151  Double_t kinfitVertexX = 0.0, kinfitVertexY = 0.0, kinfitVertexZ = 0.0;
152 
153  for (unsigned int i = 0 ; i < kinfitVertex.size(); i++)
154  {
155  kinfitVertexX = kinfitVertex[i]->dSpacetimeVertex.X();
156  kinfitVertexY = kinfitVertex[i]->dSpacetimeVertex.Y();
157  kinfitVertexZ = kinfitVertex[i]->dSpacetimeVertex.Z();
158  }
159 
160  DVector3 norm(0.0,0.0,-1);
161  DVector3 pos,mom;
162 
163  for (unsigned int i=0; i < locTrackTimeBased.size() ; ++i){
164  if(locTrackTimeBased[i]->extrapolations.size() < SYS_FCAL ) continue;
165  vector<DTrackFitter::Extrapolation_t>extrapolations=locTrackTimeBased[i]->extrapolations.at(SYS_FCAL);
166  if (extrapolations.size()>0){
167  for (unsigned int j=0; j< locFCALShowers.size(); ++j){
168 
169  Double_t x = locFCALShowers[j]->getPosition().X();
170  Double_t y = locFCALShowers[j]->getPosition().Y();
171  Double_t z = locFCALShowers[j]->getPosition().Z();
172 
173  DVector3 pos_FCAL(x,y,z);
174  pos=extrapolations[0].position;
175  Double_t trkmass = locTrackTimeBased[i]->mass();
176  Double_t FOM = TMath::Prob(locTrackTimeBased[i]->chisq, locTrackTimeBased[i]->Ndof);
177  Double_t dRho = sqrt(((pos.X() - x)*(pos.X() - x)) + ((pos.Y() - y)* (pos.Y() - y)));
178 
179  if(trkmass < 0.15 && dRho < 5 && FOM > 0.01 ) {
180  matchedShowers.push_back(locFCALShowers[j]);
181  matchedTracks.push_back(locTrackTimeBased[i]);
182 
183  }
184  }
185 
186  }
187  }
188 
189  // japp->RootWriteLock();
190  japp->RootFillLock(this);
191  if (locFCALShowers.size() >=2) {
192 
193  for(unsigned int i=0; i<locFCALShowers.size(); i++)
194  {
195  if (find(matchedShowers.begin(), matchedShowers.end(),locFCALShowers[i]) != matchedShowers.end()) continue;
196 
197  const DFCALShower *s1 = locFCALShowers[i];
198 
199  vector<const DFCALCluster*> associated_clusters1;
200 
201  s1->Get(associated_clusters1);
202  Double_t dx1 = s1->getPosition().X() - kinfitVertexX;
203  Double_t dy1 = s1->getPosition().Y() - kinfitVertexY;
204  Double_t dz1 = s1->getPosition().Z() - kinfitVertexZ;
205 
206  Double_t R1 = sqrt(dx1*dx1 + dy1*dy1 + dz1*dz1);
207  Double_t E1 = s1->getEnergy();
208  Double_t t1 = s1->getTime();
209  TLorentzVector sh1_p(E1*dx1/R1, E1*dy1/R1, E1*dz1/R1, E1);
210 
211  for(unsigned int j=i+1; j<locFCALShowers.size(); j++){
212 
213  const DFCALShower *s2 = locFCALShowers[j];
214  if (find(matchedShowers.begin(), matchedShowers.end(),s2) != matchedShowers.end()) continue;
215 
216  vector<const DFCALCluster*> associated_clusters2;
217  s2->Get(associated_clusters2);
218  Double_t dx2 = s2->getPosition().X() - kinfitVertexX;
219  Double_t dy2 = s2->getPosition().Y() - kinfitVertexY;
220  Double_t dz2 = s2->getPosition().Z() - kinfitVertexZ;
221 
222 
223  qualH = showerQualityMap[s2];
224  qualL = showerQualityMap[s1];
225 
226 
227  Double_t R2 = sqrt(dx2*dx2 + dy2*dy2 + dz2*dz2);
228  Double_t E2 = s2->getEnergy();
229  Double_t t2 = s2->getTime();
230 
231  TLorentzVector sh2_p(E2*dx2/R2, E2*dy2/R2, E2*dz2/R2, E2);
232  TLorentzVector ptot = sh1_p+sh2_p;
233  Double_t inv_mass = ptot.M();
234 
235 
236  if( qualH > 0 && qualL > 0 )
237  qualCut_00->Fill(inv_mass);
238 
239  if( qualH > 0.3 && qualL > 0.3 )
240  qualCut_03->Fill(inv_mass);
241 
242  if( qualH > 0.5 && qualL > 0.5 )
243  qualCut_05->Fill(inv_mass);
244 
245 
246  if(E1 > 0.5 && E2 > 0.5 && s1->getPosition().Pt() > 20*k_cm && s2->getPosition().Pt() > 20*k_cm && (fabs (t1-t2) < 10) ) InvMass1->Fill(inv_mass);
247  if(E1 > 1.0 && E2 > 1.0 && s1->getPosition().Pt() > 20*k_cm && s2->getPosition().Pt() > 20*k_cm && (fabs (t1-t2) < 10)) InvMass2->Fill(inv_mass);
248 
249  if((E1 > 0.5 && E1 < 0.9) && (E2 > 0.5 && E2 < 0.9) && s1->getPosition().Pt() > 20*k_cm && s2->getPosition().Pt() > 20*k_cm && (fabs (t1-t2) < 10)) InvMass3->Fill(inv_mass);
250 
251  if((E1 > 0.9 && E1 < 1.4) && (E2 > 0.9 && E2 < 1.4) && s1->getPosition().Pt() > 20*k_cm && s2->getPosition().Pt() > 20*k_cm && (fabs (t1-t2) < 10)) InvMass4->Fill(inv_mass);
252 
253  if((E1 > 1.4 && E1 < 1.9) && (E2 > 1.4 && E2 < 1.9) && s1->getPosition().Pt() > 20*k_cm && s2->getPosition().Pt() > 20*k_cm && (fabs (t1-t2) < 10)) InvMass5->Fill(inv_mass);
254 
255  if((E1 > 1.9 && E1 < 2.4) && (E2 > 1.9 && E2 < 2.4) && s1->getPosition().Pt() > 20*k_cm && s2->getPosition().Pt() > 20*k_cm && (fabs (t1-t2) < 10)) InvMass6->Fill(inv_mass);
256 
257  if((E1 > 2.4 && E1 < 2.9) && (E2 > 2.4 && E2 < 2.9) && s1->getPosition().Pt() > 20*k_cm && s2->getPosition().Pt() > 20*k_cm && (fabs (t1-t2) < 10)) InvMass7->Fill(inv_mass);
258 
259  if((E1 > 2.9 && E1 < 3.4) && (E2 > 2.9 && E2 < 3.4) && s1->getPosition().Pt() > 20*k_cm && s2->getPosition().Pt() > 20*k_cm && (fabs (t1-t2) < 10)) InvMass8->Fill(inv_mass);
260 
261  if((E1 > 3.4 && E1 < 3.9) && (E2 > 3.4 && E2 < 3.9) && s1->getPosition().Pt() > 20*k_cm && s2->getPosition().Pt() > 20*k_cm && (fabs (t1-t2) < 10)) InvMass9->Fill(inv_mass);
262 
263 
264  for(unsigned int loc_j = 0; loc_j < associated_clusters1.size(); loc_j++)
265  {
266  for(unsigned int loc_jj = 0; loc_jj < associated_clusters2.size(); loc_jj++)
267  {
268 
269  vector< DFCALCluster::DFCALClusterHit_t > hits1 = associated_clusters1[loc_j]->GetHits();
270  vector< DFCALCluster::DFCALClusterHit_t > hits2 = associated_clusters2[loc_jj]->GetHits();
271 
272  Int_t numhits_per_cluster1 = associated_clusters1[loc_j]->GetNHits();
273  Int_t numhits_per_cluster2 = associated_clusters2[loc_jj]->GetNHits();
274 
275 
276  // Get hits per block for pi0 candidate shower
277 
278  for( int i = 0; i < numhits_per_cluster1; ++i ){
279  int my_x = hits1[i].x ;
280  int my_y = hits1[i].y ;
281 
282  if (inv_mass > 0.11 && inv_mass < 0.16 && E1 > 1 && E2 > 1 && s1->getPosition().Pt() > 20*k_cm && s2->getPosition().Pt() > 20*k_cm && (fabs (t1-t2) < 10)){
283  hits2D_pi0->Fill(my_x/4,my_y/4,1);
284  }
285  }
286 
287  for( int i = 0; i < numhits_per_cluster2; ++i ){
288  int my_x = hits2[i].x ;
289  int my_y = hits2[i].y ;
290 
291  if (inv_mass > 0.11 && inv_mass < 0.16 && E1 > 1 && E2 > 1 && s1->getPosition().Pt() > 20*k_cm && s2->getPosition().Pt() > 20*k_cm && (fabs (t1-t2) < 10)){
292  hits2D_pi0->Fill(my_x/4,my_y/4,1);
293  }
294  }
295  }
296  }
297  }
298  }
299  }
300  //japp->RootUnLock();
301 
302  japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
303 
304  return NOERROR;
305 }
306 
307 //------------------
308 // erun
309 //------------------
311 {
312  // This is called whenever the run number changes, before it is
313  // changed to give you a chance to clean up before processing
314  // events from the next run number.
315 
316  return NOERROR;
317 }
318 
319 
320 
321 //------------------
322 // fini
323 //------------------
325 {
326  // Called before program exit after event processing is finished.
327  return NOERROR;
328 }
329 
330 
double getEnergy() const
Definition: DFCALShower.h:156
static double E1[100]
static TH1I * InvMass5
static TH1I * InvMass4
TVector3 DVector3
Definition: DVector3.h:14
static TH1I * qualCut_00
static TH1I * InvMass1
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
double getTime() const
Definition: DFCALShower.h:161
#define y
static TH1I * InvMass2
jerror_t brun(jana::JEventLoop *locEventLoop, int32_t locRunNumber)
Called every time a new run number is detected.
static TH1I * InvMass6
static TH1I * InvMass3
bool GetFCALZ(double &z_fcal) const
z-location of front face of CCAL in cm
Definition: DGeometry.cc:1718
JApplication * japp
jerror_t fini(void)
Called after last event of last event source has been processed.
jerror_t erun(void)
Called every time run number changes, provided brun has been called.
static TH1I * qualCut_03
jerror_t init(void)
Called once at program start.
const double k_cm
Definition: units.h:14
InitPlugin_t InitPlugin
TLatex * t1
DGeometry * GetDGeometry(unsigned int run_number)
Definition: GlueX.h:22
double sqrt(double)
static TH2I * hits2D_pi0
static TH1I * InvMass9
jerror_t evnt(jana::JEventLoop *locEventLoop, uint64_t locEventNumber)
Called every event.
DVector3 getPosition() const
Definition: DFCALShower.h:151
bool GetTargetZ(double &z_target) const
z-location of center of target
Definition: DGeometry.cc:1933
static TH1I * InvMass7
int main(int argc, char *argv[])
Definition: gendoc.cc:6
static TH1I * InvMass8
static TH1I * qualCut_05