Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_CDC_PerStrawReco.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_CDC_PerStrawReco.cc
4 // Created: Mon Jul 6 13:00:51 EDT 2015
5 // Creator: mstaib (on Linux egbert 2.6.32-504.16.2.el6.x86_64 x86_64)
6 //
7 
9 #include "PID/DChargedTrack.h"
11 #include "HistogramTools.h"
12 
13 using namespace jana;
14 
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_CDC_PerStrawReco());
23 }
24 } // "C"
25 
26 
27 //------------------
28 // JEventProcessor_CDC_PerStrawReco (Constructor)
29 //------------------
31 {
32 
33 }
34 
35 //------------------
36 // ~JEventProcessor_CDC_PerStrawReco (Destructor)
37 //------------------
39 {
40 
41 }
42 
43 //------------------
44 // init
45 //------------------
47 {
48  EXCLUDERING=0;
49  if (gPARMS){
50  gPARMS->SetDefaultParameter("CDCCOSMIC:EXCLUDERING", EXCLUDERING, "Ring Excluded from the fit");
51  gPARMS->SetDefaultParameter("KALMAN:RING_TO_SKIP", EXCLUDERING);
52  }
53  if(EXCLUDERING == 0 ){
54  jout << "Did not set CDCCOSMIC:EXCLUDERING on the command line -- Using Biased fits" << endl;
55  }
56  return NOERROR;
57 }
58 
59 //------------------
60 // brun
61 //------------------
62 jerror_t JEventProcessor_CDC_PerStrawReco::brun(JEventLoop *eventLoop, int32_t runnumber)
63 {
64  DApplication* dapp=dynamic_cast<DApplication*>(eventLoop->GetJApplication());
65  JCalibration *jcalib = dapp->GetJCalibration(runnumber);
66  // This is called whenever the run number changes
67  // Get the straw sag parameters from the database
68  unsigned int numstraws[28]={42,42,54,54,66,66,80,80,93,93,106,106,123,123,
69  135,135,146,146,158,158,170,170,182,182,197,197,
70  209,209};
71  max_sag.clear();
72  sag_phi_offset.clear();
73  vector< map<string, double> > tvals;
74  unsigned int straw_count=0,ring_count=0;
75  if (jcalib->Get("CDC/sag_parameters", tvals)==false){
76  vector<double>temp,temp2;
77  for(unsigned int i=0; i<tvals.size(); i++){
78  map<string, double> &row = tvals[i];
79 
80  temp.push_back(row["offset"]);
81  temp2.push_back(row["phi"]);
82 
83  straw_count++;
84  if (straw_count==numstraws[ring_count]){
85  max_sag.push_back(temp);
86  sag_phi_offset.push_back(temp2);
87  temp.clear();
88  temp2.clear();
89  straw_count=0;
90  ring_count++;
91  }
92  }
93  }
94  return NOERROR;
95 }
96 
97 //------------------
98 // evnt
99 //------------------
100 jerror_t JEventProcessor_CDC_PerStrawReco::evnt(JEventLoop *loop, uint64_t eventnumber)
101 {
102  // Getting the charged tracks will allow us to use the field on data
103  vector <const DChargedTrack *> chargedTrackVector;
104  loop->Get(chargedTrackVector);
105 
106  for (unsigned int iTrack = 0; iTrack < chargedTrackVector.size(); iTrack++){
107 
108  const DChargedTrackHypothesis* bestHypothesis = chargedTrackVector[iTrack]->Get_BestTrackingFOM();
109 
110  // Require Single track events
111  //if (trackCandidateVector.size() != 1) return NOERROR;
112  //const DTrackCandidate* thisTrackCandidate = trackCandidateVector[0];
113  // Cut very loosely on the track quality
114  auto thisTimeBasedTrack = bestHypothesis->Get_TrackTimeBased();
115  if (thisTimeBasedTrack->FOM < 1E-20) continue;
116  if (!thisTimeBasedTrack->IsSmoothed) continue;
117  vector<DTrackFitter::pull_t> pulls = thisTimeBasedTrack->pulls;
118  // Loop over the pulls to get the appropriate information for our ring
119  for (unsigned int i = 0; i < pulls.size(); i++){
120  DTrackFitter::pull_t thisPull = pulls[i];
121  double residual = thisPull.resi;
122  //double error = thisPull.err;
123  double time = thisPull.tcorr;
124  double docaphi = thisPull.docaphi;
125  if (docaphi > TMath::Pi()) docaphi -= 2 * TMath::Pi();
126  double docaz = thisPull.z;
127  double dz = docaz - 92.0;
128  bool isMiddle = false, isDownstream = false;
129  if (docaz > 70.0 && docaz < 110.0) isMiddle = true;
130  if (docaz > 140.0) isDownstream = true;
131  if (!isMiddle && !isDownstream) continue;
132  double predictedDistance = thisPull.d; // This is the DOCA from the track
133  double distance = residual + predictedDistance; // This is the distance from the T-D lookup
134  const DCDCTrackHit* thisCDCHit = thisPull.cdc_hit;
135 
136  if (thisCDCHit == NULL) continue;
137 
138  int ring = thisCDCHit->wire->ring;
139  int straw = thisCDCHit->wire->straw;
140  // Allow for unbiased fits
141  if ( EXCLUDERING != 0 && ring != EXCLUDERING) continue;
142  // Now we have just the unbiased information for the ring we have chosen
143  // Now just make a bunch of histograms to display all of the information
144  char folder[100];
145  sprintf(folder, "Ring %.2i", ring);
146 
147  const char * regionString = "";
148  const char * regionStringPerStraw = "";
149  if (isMiddle) {
150  regionString = "CDCReco_Middle";
151  regionStringPerStraw = "CDCPerStrawReco_Middle";
152  }
153  else if (isDownstream){
154  regionString = "CDCReco_Downstream";
155  regionStringPerStraw = "CDCPerStrawReco_Downstream";
156  }
157 
158 
159  Fill1DHistogram(regionString, folder, "Residuals", residual, "Residuals; Residual [cm]; Entries", 200, -0.05, 0.05);
160  Fill2DHistogram(regionString, folder, "Residual Vs. Momentum",
161  thisTimeBasedTrack->pmag(), residual,
162  "Residual Vs. Momentum; Momentum [GeV/c]; Residual [cm]",
163  50, 0.0, 12.0, 100, -0.05, 0.05);
164  Fill2DHistogram(regionString, folder, "Residual Vs. Theta",
165  thisTimeBasedTrack->momentum().Theta()*TMath::RadToDeg(), residual,
166  "Residual Vs. Theta; Theta [deg]; Residual [cm]",
167  60, 0.0, 180.0, 100, -0.05, 0.05);
168  Fill2DHistogram(regionString, folder, "Residual Vs. Z",
169  dz, residual,
170  "Residual Vs. Z; Z (Measured from CDC center) [cm]; Residual [cm]",
171  100, -75.0, 75.0, 100, -0.05, 0.05);
172  Fill2DHistogram(regionString, folder, "Residual Vs. Tracking FOM",
173  thisTimeBasedTrack->FOM, residual,
174  "Residual Vs. Tracking FOM; Tracking FOM; Residual [cm]",
175  100, 0.0, 1.0, 100, -0.05, 0.05);
176  Fill1DHistogram(regionString, folder, "Drift Time", time, "Drift Time; Drift Time [ns]; Entries", 500, -10, 1500);
177  Fill1DHistogram(regionString, folder, "Drift Distance", distance, "Drift Distance; Drift Distance [cm]; Entries", 250, 0.0, 1.2);
178  Fill1DHistogram(regionString, folder, "Predicted Drift Distance", predictedDistance, "Predicted Drift Distance; Drift Distance [cm]; Entries", 250, 0.0, 1.2);
179 
180  char strawname[100];
181  char strawtitle[256];
182  sprintf(strawname,"Straw %.3i Drift time Vs phi_DOCA", straw);
183  sprintf(strawtitle,"Ring %.2i Straw %.3i Drift time Vs phi_DOCA;#phi_{DOCA};Drift Time [ns]", ring, straw);
184  Fill2DHistogram(regionStringPerStraw,folder,strawname, docaphi, time,
185  strawtitle, 8, -3.14, 3.14, 500, -10, 1500);
186  sprintf(strawname,"Straw %.3i Predicted Drift Distance Vs phi_DOCA", straw);
187  sprintf(strawtitle,"Ring %.2i Straw %.3i Predicted Drift Distance Vs phi_DOCA; #phi_{DOCA};Predicted Distance [cm]", ring, straw);
188  Fill2DHistogram(regionStringPerStraw,folder,strawname, docaphi, predictedDistance,
189  strawtitle, 16, -3.14, 3.14, 400, 0.0, 1.2);
190  char residualname[100];
191  char residualtitle[256];
192  sprintf(residualname,"Straw %.3i Residual", straw);
193  sprintf(residualtitle,"Ring %.2i Straw %.3i Residual;Residual [cm]", ring, straw);
194  Fill1DHistogram(regionStringPerStraw,folder,residualname, residual, residualtitle, 200, -0.05, 0.05);
195  sprintf(residualname,"Straw %.3i Residual Vs. Z", straw);
196  sprintf(residualtitle,"Ring %.2i Straw %.3i Residual;Z [cm]; Residual [cm]", ring, straw);
197  Fill2DHistogram(regionStringPerStraw,folder,residualname,
198  dz,residual,
199  residualtitle,
200  30, -75.0,75.0,200, -0.05, 0.05);
201 
202  //Time to distance relation in bins
203  // Calcuate delta
204  double delta = max_sag[ring - 1][straw - 1]*(1.-dz*dz/5625.)
205  *cos(docaphi + sag_phi_offset[ring - 1][straw - 1]);
206  sprintf(strawname,"Straw %.3i residual Vs delta", straw);
207  sprintf(strawtitle,"Ring %.2i Straw %.3i Residual Vs #delta; #delta [cm]; Residual [cm]",ring, straw);
208  double binwidth = 0.005;
209  if ( 2 * max_sag[ring - 1][straw - 1] > binwidth){
210  Fill2DHistogram(regionStringPerStraw,folder,strawname, delta, residual,
211  strawtitle, Int_t(2 * max_sag[ring - 1][straw - 1] / binwidth), -1 * max_sag[ring - 1][straw - 1], max_sag[ring - 1][straw - 1], 100, -0.05, 0.05);
212  }
213 
214  char binname[150];
215  char bintitle[150];
216  sprintf(binname,"Straw %.3i Predicted Drift Distance Vs. Drift Time", straw);
217  sprintf(bintitle,"Ring %.2i Straw %.3i Predicted Drift Distance Vs. Drift Time", ring, straw);
218  Fill2DHistogram(regionStringPerStraw,folder,binname, time, predictedDistance,
219  bintitle, 250, -50, 200, 250, 0.0, 0.4);
220 
221  sprintf(binname,"Straw %.3i Predicted Drift Distance Vs. delta", straw);
222  sprintf(bintitle,"Ring %.2i Straw %.3i Predicted Drift Distance Vs. #delta;#delta [cm]; Predicted Drift Distance - Nominal Radius [cm]", ring, straw);
223  Fill2DHistogram(regionStringPerStraw,folder,binname, delta, predictedDistance - 0.78,
224  bintitle, 20, -0.25, 0.25, 250, -0.25, 0.25);
225 
226  if (delta > 0){ // Long side of straw
227  sprintf(binname,"Straw %.3i Predicted Drift Distance Vs. Drift Time Positive Delta", straw);
228  sprintf(bintitle,"Ring %.2i Straw %.3i Predicted Drift Distance Vs. Drift Time (Positive Delta)", ring, straw);
229  Fill2DHistogram(regionStringPerStraw,folder,binname, time, predictedDistance,
230  bintitle, 250, -10, 1500, 50, 0.0, 1.2);
231  sprintf(binname,"Straw %.3i Residual Vs. Drift Time Positive Delta", straw);
232  sprintf(bintitle,"Ring %.2i Straw %.3i Residual Vs. Drift Time (Positive Delta)", ring, straw);
233  Fill2DHistogram(regionStringPerStraw,folder,binname, time, residual,
234  bintitle, 100, -10, 1500, 100, -0.05, 0.05);
235  sprintf(binname,"Straw %.3i Residual Positive Delta", straw);
236  sprintf(bintitle,"Ring %.2i Straw %.3i Residual (Positive Delta); Residual [cm]; Entries", ring, straw);
237  Fill1DHistogram(regionStringPerStraw,folder,binname, residual, bintitle, 200, -0.05, 0.05);
238  }
239  else { // Short side of straw
240  sprintf(binname,"Straw %.3i Predicted Drift Distance Vs. Drift Time Negative Delta", straw);
241  sprintf(bintitle,"Ring %.2i Straw %.3i Predicted Drift Distance Vs. Drift Time (Negative Delta)", ring, straw);
242  Fill2DHistogram(regionStringPerStraw,folder,binname, time, predictedDistance,
243  bintitle, 250, -10, 1500, 50, 0.0, 1.2);
244  sprintf(binname,"Straw %.3i Residual Vs. Drift Time Negative Delta", straw);
245  sprintf(bintitle,"Ring %.2i Straw %.3i Residual Vs. Drift Time (Negative Delta)", ring, straw);
246  Fill2DHistogram(regionStringPerStraw,folder,binname, time, residual,
247  bintitle, 100, -10, 1500, 100, -0.05, 0.05);
248  sprintf(binname,"Straw %.3i Residual Negative Delta", straw);
249  sprintf(bintitle,"Ring %.2i Straw %.3i Residual (Negative Delta); Residual [cm]; Entries", ring, straw);
250  Fill1DHistogram(regionStringPerStraw,folder,binname, residual, bintitle, 200, -0.05, 0.05);
251  }
252 
253  Fill2DHistogram(regionString, folder, "Residual Vs. Drift Time", time, residual,
254  "Residual Vs. Drift Time; Drift Time [ns]; Residual [cm]",
255  500, -10, 1500, 100, -0.05, 0.05);
256  Fill2DHistogram(regionString, folder, "Residual Vs. Drift Distance", distance, residual,
257  "Residual Vs. Drift Distance; Drift Distance [cm]; Residual [cm]",
258  50, 0.0, 1.0, 100, -0.05, 0.05);
259  Fill2DHistogram(regionString, folder, "Residual Vs. Predicted Drift Distance", predictedDistance, residual,
260  "Residual Vs. Predicted Drift Distance; Predicted Drift Distance [cm]; Residual [cm]",
261  50, 0.0, 1.0, 100, -0.05, 0.05);
262 
263  Fill2DHistogram(regionString, folder, "Predicted Drift Distance Vs. Drift Time", time, predictedDistance,
264  "Predicted Drift Distance Vs. Drift Time; Drift Time [ns]; Predicted Drift Distance [cm]",
265  500, -10, 1500, 100, 0.0, 1.0);
266 
267  }
268  }
269  return NOERROR;
270 }
271 
272 //------------------
273 // erun
274 //------------------
276 {
277  // This is called whenever the run number changes, before it is
278  // changed to give you a chance to clean up before processing
279  // events from the next run number.
280  return NOERROR;
281 }
282 
283 //------------------
284 // fini
285 //------------------
287 {
288  // Called before program exit after event processing is finished.
289  //SortDirectories();
290  return NOERROR;
291 }
292 
DApplication * dapp
const DCDCWire * wire
Definition: DCDCTrackHit.h:37
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
jerror_t fini(void)
Called after last event of last event source has been processed.
sprintf(text,"Post KinFit Cut")
const DTrackTimeBased * Get_TrackTimeBased(void) const
jerror_t init(void)
Called once at program start.
InitPlugin_t InitPlugin
int straw
Definition: DCDCWire.h:81
const DCDCTrackHit * cdc_hit
Definition: DTrackFitter.h:113
void Fill1DHistogram(const char *plugin, const char *directoryName, const char *name, const double value, const char *title, int nBins, double xmin, double xmax, bool print=false)
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
void Fill2DHistogram(const char *plugin, const char *directoryName, const char *name, const double valueX, const double valueY, const char *title, int nBinsX, double xmin, double xmax, int nBinsY, double ymin, double ymax, bool print=false)
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.
int ring
Definition: DCDCWire.h:80
TH2F * temp