Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_imaging.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_imaging.cc
4 // Created: Thu Nov 9 10:49:12 EST 2017
5 // Creator: staylor (on Linux ifarm1402.jlab.org 3.10.0-327.el7.x86_64 x86_64)
6 //
7 
9 using namespace jana;
10 #include <TDirectory.h>
11 #include <TMatrix.h>
12 
13 #include <PID/DChargedTrack.h>
14 #include <TRACKING/DMCThrown.h>
15 
16 // Routine used to create our JEventProcessor
17 #include <JANA/JApplication.h>
18 #include <JANA/JFactory.h>
19 extern "C"{
20 void InitPlugin(JApplication *app){
21  InitJANAPlugin(app);
22  app->AddProcessor(new JEventProcessor_imaging());
23 }
24 } // "C"
25 
26 
27 //------------------
28 // JEventProcessor_imaging (Constructor)
29 //------------------
31 {
32 
33 }
34 
35 //------------------
36 // ~JEventProcessor_imaging (Destructor)
37 //------------------
39 {
40 
41 }
42 
43 //------------------
44 // init
45 //------------------
47 {
48  MC_RECON_CHECK=false;
49  gPARMS->SetDefaultParameter("IMAGING:MC_RECON_CHECK",MC_RECON_CHECK, "Turn on/off comparison to MC");
50  DEBUG_LEVEL=0;
51  gPARMS->SetDefaultParameter("IMAGING:DEBUG_LEVEL",DEBUG_LEVEL);
52  FIT_CL_CUT=0.05;
53  gPARMS->SetDefaultParameter("IMAGING:FIT_CL_CUT",FIT_CL_CUT, "CL cut for vertex fit");
54  TRACK_CL_CUT=1e-3;
55  gPARMS->SetDefaultParameter("IMAGING:TRACK_CL_CUT",TRACK_CL_CUT, "CL cut for tracks");
56  DOCA_CUT=1.0;
57  gPARMS->SetDefaultParameter("IMAGING:DOCA_CUT",DOCA_CUT, "Maximum doca between tracks");
58 
59 
60  gDirectory->mkdir("Vertexes")->cd();
61 
62  TwoTrackXYZ= new TH3I("TwoTrackXYZ","z vs y vs x",400,-10,10,
63  400,-10,10,140,30,100);
64  TwoTrackXYZ->SetXTitle("x (cm)");
65  TwoTrackXYZ->SetYTitle("y (cm)");
66  TwoTrackXYZ->SetZTitle("z (cm)");
67 
68  TwoTrackZ=new TH1F("TwoTrackZ","z for r<0.5 cm",1000,0,200);
69  TwoTrackZ->SetXTitle("z [cm]");
70 
71  TwoTrackPocaCut=new TH2F("TwoTrackPocaCut","2track POCA,doca cut",4000,0,400,650,0,65);
72  TwoTrackPocaCut->SetXTitle("z (cm)");
73  TwoTrackPocaCut->SetYTitle("r (cm)");
74 
75  TwoTrackXY_at_65cm=new TH2F("TwoTrackXY_at_65cm","y vs x near 65 cm",400,-5,5,400,-5,5);
76  TwoTrackXY_at_65cm->SetXTitle("x [cm]");
77  TwoTrackXY_at_65cm->SetYTitle("y [cm]");
78 
79  TwoTrackDz=new TH1F("TwoTrackDz","#deltaz at x,y vertex",100,-10,10);
80  TwoTrackDz->SetXTitle("#Deltaz [cm]");
81 
82  TwoTrackDoca=new TH1F("TwoTrackDoca","#deltar",1000,0,10);
83  TwoTrackDoca->SetXTitle("d [cm]");
84 
85  if (MC_RECON_CHECK){
86  MCVertexDiff= new TH3I("MCVertexDiff","dz vs dy vs dx",400,-10,10,
87  400,-10,10,400,-10,10);
88  MCVertexDxVsZ= new TH2F("MCVertexDxVsZ","dx vs z",400,0,200,400,-10,10);
89  MCVertexDyVsZ= new TH2F("MCVertexDyVsZ","dy vs z",400,0,200,400,-10,10);
90  MCVertexDzVsZ= new TH2F("MCVertexDzVsZ","dz vs z",400,0,200,400,-10,10);
91  MCVertexDxVsR= new TH2F("MCVertexDxVsR","dx vs R",120,0,60,400,-10,10);
92  MCVertexDyVsR= new TH2F("MCVertexDyVsR","dy vs R",120,0,60,400,-10,10);
93  MCVertexDzVsR= new TH2F("MCVertexDzVsR","dz vs R",120,0,60,400,-10,10);
94  }
95 
96  gDirectory->cd("../");
97 
98  return NOERROR;
99 }
100 
101 //------------------
102 // brun
103 //------------------
104 jerror_t JEventProcessor_imaging::brun(JEventLoop *eventLoop, int32_t runnumber)
105 {
106  // This is called whenever the run number changes
107  DApplication* dapp=dynamic_cast<DApplication*>(eventLoop->GetJApplication());
108  bfield=dapp->GetBfield(runnumber);
109 
110  dIsNoFieldFlag = ((dynamic_cast<const DMagneticFieldMapNoField*>(bfield)) != NULL);
111 
112  eventLoop->GetSingle(dAnalysisUtilities);
113 
114  return NOERROR;
115 }
116 
117 //------------------
118 // evnt
119 //------------------
120 jerror_t JEventProcessor_imaging::evnt(JEventLoop *loop, uint64_t eventnumber)
121 {
122  // This is called for every event. Use of common resources like writing
123  // to a file or filling a histogram should be mutex protected. Using
124  // loop->Get(...) to get reconstructed objects (and thereby activating the
125  // reconstruction algorithm) should be done outside of any mutex lock
126  // since multiple threads may call this method at the same time.
127  // Here's an example:
128  //
129  // vector<const MyDataClass*> mydataclasses;
130  // loop->Get(mydataclasses);
131  //
132  // japp->RootFillLock(this);
133  // ... fill historgrams or trees ...
134  // japp->RootFillUnLock(this);
135 
136  vector<const DChargedTrack*>tracks;
137  loop->Get(tracks);
138  if (tracks.size()<2) return NOERROR;
139 
140  vector<const DMCThrown*>mcthrowns;
141  if (MC_RECON_CHECK){
142  loop->Get(mcthrowns);
143  }
144 
145  japp->RootWriteLock();
146 
147  if (MC_RECON_CHECK && tracks.size()==2){
148  // Check estimate of vertex position relative to thrown vertex for simple
149  // reactions
150  DVector3 truevertex;
151  for (unsigned int i=0;i<mcthrowns.size();i++){
152  if (mcthrowns[i]->parentid==1){
153  truevertex=mcthrowns[i]->position();
154  break;
155  }
156  }
157  const DTrackTimeBased *track1=tracks[0]->Get_BestTrackingFOM()->Get_TrackTimeBased();
158  const DTrackTimeBased *track2=tracks[1]->Get_BestTrackingFOM()->Get_TrackTimeBased();
159  double doca=0.;
160  DVector3 pos1_out,pos2_out;
161  if (dAnalysisUtilities->Calc_DOCA(track1,track2,pos1_out,pos2_out,doca)
162  ==NOERROR){
163  DVector3 vertex=0.5*(pos1_out+pos2_out);
164  DVector3 diff=vertex-truevertex;
165  double ztrue=truevertex.z();
166  double rtrue=truevertex.Perp();
167  MCVertexDiff->Fill(diff.x(),diff.y(),diff.z());
168  MCVertexDxVsZ->Fill(ztrue,diff.x());
169  MCVertexDyVsZ->Fill(ztrue,diff.y());
170  MCVertexDzVsZ->Fill(ztrue,diff.z());
171  MCVertexDxVsR->Fill(rtrue,diff.x());
172  MCVertexDyVsR->Fill(rtrue,diff.y());
173  MCVertexDzVsR->Fill(rtrue,diff.z());
174 
175  }
176  }
177 
178  // For each track make a helical approximation to the trajectory near the
179  // point of closest approach to the beam line, so that the intersection point
180  // of each pair of tracks can be approximated by finding the point of
181  // intersection of two circles closest to the measured POCAs.
182  for (unsigned int i=0;i<tracks.size()-1;i++){
183  const DTrackTimeBased *track1=tracks[i]->Get_BestTrackingFOM()->Get_TrackTimeBased();
184  if (TMath::Prob(track1->chisq,track1->Ndof)>TRACK_CL_CUT){
185  DVector3 pos1=track1->position();
186  DVector3 mom1=track1->momentum();
187 
188  for (unsigned int j=i+1;j<tracks.size();j++){
189  const DTrackTimeBased *track2=tracks[j]->Get_BestTrackingFOM()->Get_TrackTimeBased();
190 
191  if (TMath::Prob(track2->chisq,track2->Ndof)>TRACK_CL_CUT){
192  DVector3 mom2=track2->momentum();
193  DVector3 pos2=track2->position();
194 
195  // Find the positions corresponding to the doca between the two
196  // tracks
197  double doca=1e7,s1=0,s2=0.;
198  DVector3 pos2_out,pos1_out,mom2_out,mom1_out;
199  if (dIsNoFieldFlag){
200  DVector3 dir1=mom1;
201  dir1.SetMag(1.);
202  DVector3 dir2=mom2;
203  dir2.SetMag(1.);
204  doca=dAnalysisUtilities->Calc_DOCA(dir1,dir2,pos1,pos2,pos1_out,
205  pos2_out);
206  }
207  else {
208  dAnalysisUtilities->Calc_DOCA(track1,track2,pos1_out,pos2_out,doca);
209  }
210 
211  TwoTrackDoca->Fill(doca);
212  TwoTrackDz->Fill(pos1_out.z()-pos2_out.z());
213 
214  if (doca<DOCA_CUT){
215  // Use the positions corresponding to the doca of the tracks to
216  // refine the estimate for the vertex position
217  DVector3 myvertex=0.5*(pos1_out+pos2_out);
218 
219  TwoTrackPocaCut->Fill(myvertex.z(),myvertex.Perp());
220  TwoTrackXYZ->Fill(myvertex.x(),myvertex.y(),myvertex.z());
221  if (myvertex.z()>64.5 && myvertex.z()<65.5){
222  TwoTrackXY_at_65cm->Fill(myvertex.x(),myvertex.y());
223  }
224  if (myvertex.Perp()<0.5){
225  TwoTrackZ->Fill(myvertex.z());
226  }
227  } // doca cut
228  } // second track
229  } // second loop over tracks
230  } // first track
231  } // first loop over tracks
232 
233  japp->RootUnLock();
234 
235 
236 
237  return NOERROR;
238 }
239 
240 //------------------
241 // erun
242 //------------------
244 {
245  // This is called whenever the run number changes, before it is
246  // changed to give you a chance to clean up before processing
247  // events from the next run number.
248  return NOERROR;
249 }
250 
251 //------------------
252 // fini
253 //------------------
255 {
256  // Called before program exit after event processing is finished.
257  return NOERROR;
258 }
259 
260 
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
DApplication * dapp
float chisq
Chi-squared for the track (not chisq/dof!)
TVector3 DVector3
Definition: DVector3.h:14
DMagneticFieldMap * GetBfield(unsigned int run_number=1)
jerror_t fini(void)
Called after last event of last event source has been processed.
const DVector3 & position(void) const
jerror_t init(void)
Called once at program start.
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
Definition: track2.h:15
JApplication * japp
TEllipse * e
InitPlugin_t InitPlugin
int Ndof
Number of degrees of freedom in the fit.
const DVector3 & momentum(void) const
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.