Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DEventProcessor_pulls_tree.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DEventProcessor_pulls_tree.cc
4 // Created: Fri Feb 19 13:04:29 EST 2010
5 // Creator: davidl (on Darwin harriet.jlab.org 9.8.0 i386)
6 //
7 
8 #include <PID/DChargedTrack.h>
11 #include <TRACKING/DMCThrown.h>
12 
14 using namespace jana;
15 
16 
17 // Routine used to create our DEventProcessor
18 #include <JANA/JApplication.h>
19 extern "C"{
20 void InitPlugin(JApplication *app){
21  InitJANAPlugin(app);
22  app->AddProcessor(new DEventProcessor_pulls_tree());
23 }
24 } // "C"
25 
26 
27 //------------------
28 // DEventProcessor_pulls_tree (Constructor)
29 //------------------
31 {
32  pthread_mutex_init(&mutex, NULL);
33 
34  fitter = NULL;
35 }
36 
37 //------------------
38 // ~DEventProcessor_pulls_tree (Destructor)
39 //------------------
41 {
42 
43 }
44 
45 //------------------
46 // init
47 //------------------
49 {
50  pullWB_ptr = &pullWB;
51  pullTB_ptr = &pullTB;
52 
53  pullsWB = new TTree("pullsWB","Wire-based hits");
54  pullsWB->Branch("W","pull_t",&pullWB_ptr);
55 
56  pullsTB = new TTree("pullsTB","Time-based hits");
57  pullsTB->Branch("W","pull_t",&pullTB_ptr);
58 
59  return NOERROR;
60 }
61 
62 //------------------
63 // brun
64 //------------------
65 jerror_t DEventProcessor_pulls_tree::brun(JEventLoop *eventLoop, int32_t runnumber)
66 {
67  RECALCULATE_CHISQ = false;
68 
69  gPARMS->SetDefaultParameter("RECALCULATE_CHISQ", RECALCULATE_CHISQ, "Recalculate Chisq, Ndof, and pulls based on track parameters and hits rather than use what's recorded in track objects");
70 
71  return NOERROR;
72 }
73 
74 //------------------
75 // evnt
76 //------------------
77 jerror_t DEventProcessor_pulls_tree::evnt(JEventLoop *loop, uint64_t eventnumber)
78 {
79  vector<const DChargedTrack*> tracks;
80  const DMCThrown * thrown_single=NULL;
81  fitter=NULL;
82 
83  try{
84  loop->Get(tracks);
85  loop->GetSingle(thrown_single);
86  loop->GetSingle(fitter, "ALT1"); // use ALT1 as the stand-alone chisq calculator
87  }catch(...){
88  //return NOERROR;
89  }
90 
91  // Although we are only filling objects local to this plugin, TTree::Fill() periodically writes to file: Global ROOT lock
92  japp->RootWriteLock(); //ACQUIRE ROOT LOCK
93 
94  for(unsigned int i=0; i<tracks.size(); i++){
95 
96  // Initialize in case these don't get set below
97  pullWB.pthrown.SetXYZ(0,0,0);
98  pullTB.pthrown.SetXYZ(0,0,0);
99 
100  if(tracks[i]->hypotheses.size()>0){
101  const DTrackTimeBased *tbtrk = tracks[i]->hypotheses[0];
102  if(tbtrk){
103 
104  // Try filling in pthrown. First, by looking for an
105  // associated object, then by checking if thrown_single
106  // is not NULL. The latter case being for single
107  // track events, the former for when DTrackTimeBased::THROWN
108  // is used.
109  const DMCThrown *thrown;
110  tbtrk->GetSingle(thrown);
111  if(!thrown)thrown = thrown_single;
112  if(thrown){
113  const DVector3 &x = thrown->momentum();
114  pullTB.pthrown.SetXYZ(x.X(), x.Y(), x.Z());
115  }
116 
117  // Copy chisq/Ndof/pull values to local variables in case we need to
118  // replace them with ones we recalculate
119  double chisq = tbtrk->chisq;
120  int Ndof = tbtrk->Ndof;
121  vector<DTrackFitter::pull_t> pulls = tbtrk->pulls;
122 
123  // Optionally replace chisq values
124  if(RECALCULATE_CHISQ){
125  RecalculateChisq(DTrackFitter::kTimeBased, tbtrk, chisq, Ndof, pulls);
126  }
127 
128  pullTB.eventnumber = eventnumber;
129  pullTB.trk_chisq = chisq;
130  pullTB.trk_Ndof = Ndof;
131 
132  for(unsigned int j=0; j<pulls.size(); j++){
133  pullTB.resi = pulls[j].resi;
134  pullTB.err = pulls[j].err;
135  pullTB.s = pulls[j].s;
136  pullTB.pull = pullTB.resi/pullTB.err;
137  pullsTB->Fill();
138  }
139 
140  const DTrackWireBased* wbtrk;
141  tbtrk->GetSingle(wbtrk);
142 
143  if(wbtrk){
144  pullWB.eventnumber = eventnumber;
145  pullWB.trk_chisq = wbtrk->chisq;
146  pullWB.trk_Ndof = wbtrk->Ndof;
147 
148  // See comment above for TB tracks
149  const DMCThrown *thrown;
150  wbtrk->GetSingle(thrown);
151  if(!thrown)thrown = thrown_single;
152  if(thrown){
153  const DVector3 &x = thrown->momentum();
154  pullWB.pthrown.SetXYZ(x.X(), x.Y(), x.Z());
155  }
156 
157  for(unsigned int j=0; j<wbtrk->pulls.size(); j++){
158  pullWB.resi = wbtrk->pulls[j].resi;
159  pullWB.err = wbtrk->pulls[j].err;
160  pullWB.s = wbtrk->pulls[j].s;
161  pullWB.pull = pullWB.resi/pullWB.err;
162  pullsWB->Fill();
163  }
164  }
165  }
166  }
167  }
168 
169  japp->RootUnLock(); //RELEASE ROOT LOCK
170 
171  return NOERROR;
172 }
173 
174 //------------------
175 // erun
176 //------------------
178 {
179  // Any final calculations on histograms (like dividing them)
180  // should be done here. This may get called more than once.
181  return NOERROR;
182 }
183 
184 //------------------
185 // fini
186 //------------------
188 {
189  // Called at very end. This will be called only once
190 
191  return NOERROR;
192 }
193 
194 //------------------
195 // RecalculateChisq
196 //------------------
197 void DEventProcessor_pulls_tree::RecalculateChisq(DTrackFitter::fit_type_t fit_type, const DKinematicData *kd, double &chisq, int &Ndof, vector<DTrackFitter::pull_t> &pulls)
198 {
199  if(!fitter){
200  _DBG_<<"DTrackFitter:ALT1 not available when RECALCULATE_CHISQ is set!"<<endl;
201  return;
202  }
203 
204 
205 }
206 
float chisq
Chi-squared for the track (not chisq/dof!)
float chisq
Chi-squared for the track (not chisq/dof!)
TVector3 DVector3
Definition: DVector3.h:14
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
jerror_t fini(void)
Called after last event of last event source has been processed.
JApplication * japp
vector< DTrackFitter::pull_t > pulls
Holds pulls used in chisq calc. (not including off-diagonals)
InitPlugin_t InitPlugin
#define _DBG_
Definition: HDEVIO.h:12
int Ndof
Number of degrees of freedom in the fit.
int Ndof
Number of degrees of freedom in the fit.
vector< DTrackFitter::pull_t > pulls
Holds pulls used in chisq calc. (not including off-diagonals)
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
const DVector3 & momentum(void) const
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
const DTrackFitter * fitter
jerror_t init(void)
Called once at program start.
void RecalculateChisq(DTrackFitter::fit_type_t fit_type, const DKinematicData *kd, double &chisq, int &Ndof, vector< DTrackFitter::pull_t > &pulls)