Hall C ROOT/C++ Analyzer (hcana)
THcDC.cxx
Go to the documentation of this file.
1 
15 #include "THcDC.h"
16 #include "THaEvData.h"
17 #include "THaDetMap.h"
18 #include "THcDetectorMap.h"
19 #include "THcGlobals.h"
20 #include "THaCutList.h"
21 #include "THcParmList.h"
22 #include "THcDCTrack.h"
23 #include "VarDef.h"
24 #include "VarType.h"
25 #include "THaTrack.h"
26 #include "TClonesArray.h"
27 #include "TMath.h"
28 #include "TVectorD.h"
29 #include "THaApparatus.h"
30 #include "THcHallCSpectrometer.h"
31 
32 #include <cstring>
33 #include <cstdio>
34 #include <cstdlib>
35 #include <iostream>
36 
37 using namespace std;
38 
39 //_____________________________________________________________________________
41  const char* name, const char* description,
42  THaApparatus* apparatus ) :
43  THaTrackingDetector(name,description,apparatus)
44 {
45  // Constructor
46 
47  fNPlanes = 0; // No planes until we make them
48 
49  fXCenter = NULL;
50  fYCenter = NULL;
51  fMinHits = NULL;
52  fMaxHits = NULL;
53  fMinCombos = NULL;
55 
56  fTdcWinMin = NULL;
57  fTdcWinMax = NULL;
58  fCentralTime = NULL;
59  fNWires = NULL;
60  fNChamber = NULL;
61  fWireOrder = NULL;
62  fDriftTimeSign = NULL;
63  fReadoutTB = NULL;
64  fReadoutLR = NULL;
65 
66  fXPos = NULL;
67  fYPos = NULL;
68  fZPos = NULL;
69  fAlphaAngle = NULL;
70  fBetaAngle = NULL;
71  fGammaAngle = NULL;
72  fPitch = NULL;
73  fCentralWire = NULL;
74  fPlaneTimeZero = NULL;
75  fSigma = NULL;
76 
77  // These should be set to zero (in a parameter file) in order to
78  // replicate historical ENGINE behavior
79  fFixLR = 1;
81  fProjectToChamber = 0; // Use 1 for SOS chambers
82 
83  fDCTracks = new TClonesArray( "THcDCTrack", 20 );
84 
85  fNChamHits = 0;
86  fPlaneEvents = 0;
87 
88  //The version defaults to 0 (old HMS style). 1 is new HMS style and 2 is SHMS style.
89  fVersion = 0;
90 }
91 
92 //_____________________________________________________________________________
93 void THcDC::Setup(const char* name, const char* description)
94 {
95 
96  Bool_t optional = true;
97 
98  // Create the chamber and plane objects using parameters.
99  static const char* const here = "Setup";
100 
101  THaApparatus *app = GetApparatus();
102  if(app) {
103  // cout << app->GetName() << endl;
104  fPrefix[0]=tolower(app->GetName()[0]);
105  fPrefix[1]='\0';
106  } else {
107  cout << "No apparatus found" << endl;
108  fPrefix[0]='\0';
109  }
110 
111  // For now, decide chamber style from the spectrometer name.
112  // Should override with a paramter
113  //cout<<"HMS Style??\t"<<fHMSStyleChambers<<endl;
114  string planenamelist;
115  DBRequest list[]={
116  {"dc_num_planes",&fNPlanes, kInt},
117  {"dc_num_chambers",&fNChambers, kInt},
118  {"dc_tdc_time_per_channel",&fNSperChan, kDouble},
119  {"dc_wire_velocity",&fWireVelocity,kDouble},
120  {"dc_plane_names",&planenamelist, kString},
121  {"dc_version", &fVersion, kInt, 0, optional},
122  {"dc_tdcrefcut", &fTDC_RefTimeCut, kInt, 0, 1},
123  {0}
124  };
125 
126  fTDC_RefTimeCut = 0; // Minimum allowed reference times
127  gHcParms->LoadParmValues((DBRequest*)&list,fPrefix);
128 
129  if(fVersion==0) {
130  fHMSStyleChambers = 1;
131  } else {
132  fHMSStyleChambers = 0;
133  }
134 
135 
136  cout << "Plane Name List: " << planenamelist << endl;
137  cout << "Drift Chambers: " << fNPlanes << " planes in " << fNChambers << " chambers" << endl;
138 
139  vector<string> plane_names = Podd::vsplit(planenamelist);
140 
141  if(plane_names.size() != (UInt_t) fNPlanes) {
142  cout << "ERROR: Number of planes " << fNPlanes << " doesn't agree with number of plane names " << plane_names.size() << endl;
143  // Should quit. Is there an official way to quit?
144  }
145  fPlaneNames = new char* [fNPlanes];
146  for(Int_t i=0;i<fNPlanes;i++) {
147  fPlaneNames[i] = new char[plane_names[i].length()+1];
148  strcpy(fPlaneNames[i], plane_names[i].c_str());
149  }
150 
151  char *desc = new char[strlen(description)+100];
152  char *desc1= new char[strlen(description)+100];
153  fPlanes.clear();
154 
155  for(Int_t i=0;i<fNPlanes;i++) {
156  strcpy(desc, description);
157  strcat(desc, " Plane ");
158  strcat(desc, fPlaneNames[i]);
159 
160  THcDriftChamberPlane* newplane = new THcDriftChamberPlane(fPlaneNames[i], desc, i+1, this);
161  if( !newplane or newplane->IsZombie() ) {
162  Error( Here(here), "Error creating Drift Chamber plane %s. Call expert.", name);
163  MakeZombie();
164  delete [] desc;
165  delete [] desc1;
166  return;
167  }
168  fPlanes.push_back(newplane);
169  newplane->SetDebug(fDebug);
170  // cout << "Created Drift Chamber Plane " << fPlaneNames[i] << ", " << desc << endl;
171 
172  }
173 
174  fChambers.clear();
175  for(UInt_t i=0;i<fNChambers;i++) {
176  sprintf(desc1,"Ch%d",i+1);
177 
178  // Should construct a better chamber name
179  THcDriftChamber* newchamber = new THcDriftChamber(desc1, desc, i+1, this);
180  fChambers.push_back(newchamber);
181  cout << "Created Drift Chamber " << i+1 << ", " << desc1 << endl;
182  newchamber->SetHMSStyleFlag(fHMSStyleChambers); // Tell the chamber its style
183  }
184  delete [] desc;
185  delete [] desc1;
186 }
187 
188 //_____________________________________________________________________________
190  THaTrackingDetector()
191 {
192  // Constructor
193 }
194 
195 //_____________________________________________________________________________
196 THaAnalysisObject::EStatus THcDC::Init( const TDatime& date )
197 {
198  // Register the plane objects with the appropriate chambers.
199  // Trigger ReadDatabase to load the remaining parameters
200  Setup(GetName(), GetTitle()); // Create the subdetectors here
201  EffInit();
202 
203  char EngineDID[] = "xDC";
204  EngineDID[0] = toupper(GetApparatus()->GetName()[0]);
205  if( gHcDetectorMap->FillMap(fDetMap, EngineDID) < 0 ) {
206  static const char* const here = "Init()";
207  Error( Here(here), "Error filling detectormap for %s.", EngineDID );
208  return kInitError;
209  }
210 
211  // Should probably put this in ReadDatabase as we will know the
212  // maximum number of hits after setting up the detector map
213  cout << " DC tdc ref time cut = " << fTDC_RefTimeCut << endl;
214  InitHitList(fDetMap, "THcRawDCHit", fDetMap->GetTotNumChan()+1,
215  fTDC_RefTimeCut, 0);
216 
218 
219  EStatus status;
220  // This triggers call of ReadDatabase and DefineVariables
221  if( (status = THaTrackingDetector::Init( date )) )
222  return fStatus=status;
223 
224  // Initialize planes and add them to chambers
225  for(Int_t ip=0;ip<fNPlanes;ip++) {
226  if((status = fPlanes[ip]->Init( date ))) {
227  return fStatus=status;
228  } else {
229  Int_t chamber=fNChamber[ip];
230  fChambers[chamber-1]->AddPlane(fPlanes[ip]);
231  }
232  }
233  // Initialize chambers
234  for(UInt_t ic=0;ic<fNChambers;ic++) {
235  if((status = fChambers[ic]->Init ( date ))) {
236  return fStatus=status;
237  }
238  }
239  // Retrieve the fiting coefficients
240  fPlaneCoeffs = new Double_t* [fNPlanes];
241  for(Int_t ip=0; ip<fNPlanes;ip++) {
242  fPlaneCoeffs[ip] = fPlanes[ip]->GetPlaneCoef();
243  }
244 
245  fResiduals = new Double_t [fNPlanes];
246  fPos_best = new Double_t [fNPlanes];
247  fLR_best = new Double_t [fNPlanes];
248  fDist_best = new Double_t [fNPlanes];
252 
253 
254  // Replace with what we need for Hall C
255  // const DataDest tmp[NDEST] = {
256  // { &fRTNhit, &fRANhit, fRT, fRT_c, fRA, fRA_p, fRA_c, fROff, fRPed, fRGain },
257  // { &fLTNhit, &fLANhit, fLT, fLT_c, fLA, fLA_p, fLA_c, fLOff, fLPed, fLGain }
258  // };
259  // memcpy( fDataDest, tmp, NDEST*sizeof(DataDest) );
260 
261  fPresentP = 0;
262  THaVar* vpresent = gHaVars->Find(Form("%s.present",GetApparatus()->GetName()));
263  if(vpresent) {
264  fPresentP = (Bool_t *) vpresent->GetValuePointer();
265  }
266  return fStatus = kOK;
267 }
268 
269 //_____________________________________________________________________________
271 {
278  // static const char* const here = "ReadDatabase()";
279 
280  delete [] fXCenter; fXCenter = new Double_t [fNChambers];
281  delete [] fYCenter; fYCenter = new Double_t [fNChambers];
282  delete [] fMinHits; fMinHits = new Int_t [fNChambers];
283  delete [] fMaxHits; fMaxHits = new Int_t [fNChambers];
284  delete [] fMinCombos; fMinCombos = new Int_t [fNChambers];
286 
287  delete [] fTdcWinMin; fTdcWinMin = new Int_t [fNPlanes];
288  delete [] fTdcWinMax; fTdcWinMax = new Int_t [fNPlanes];
289  delete [] fCentralTime; fCentralTime = new Double_t [fNPlanes];
290  delete [] fNWires; fNWires = new Int_t [fNPlanes];
291  delete [] fNChamber; fNChamber = new Int_t [fNPlanes]; // Which chamber is this plane
292  delete [] fWireOrder; fWireOrder = new Int_t [fNPlanes]; // Wire readout order
293  delete [] fDriftTimeSign; fDriftTimeSign = new Int_t [fNPlanes];
294  delete [] fReadoutLR; fReadoutLR = new Int_t [fNPlanes];
295  delete [] fReadoutTB; fReadoutTB = new Int_t [fNPlanes];
296 
297  delete [] fXPos; fXPos = new Double_t [fNPlanes];
298  delete [] fYPos; fYPos = new Double_t [fNPlanes];
299  delete [] fZPos; fZPos = new Double_t [fNPlanes];
300  delete [] fAlphaAngle; fAlphaAngle = new Double_t [fNPlanes];
301  delete [] fBetaAngle; fBetaAngle = new Double_t [fNPlanes];
302  delete [] fGammaAngle; fGammaAngle = new Double_t [fNPlanes];
303  delete [] fPitch; fPitch = new Double_t [fNPlanes];
304  delete [] fCentralWire; fCentralWire = new Double_t [fNPlanes];
305  delete [] fPlaneTimeZero; fPlaneTimeZero = new Double_t [fNPlanes];
306  delete [] fSigma; fSigma = new Double_t [fNPlanes];
307 
308  Bool_t optional = true;
309 
310  DBRequest list[]={
311  {"dc_tdc_time_per_channel",&fNSperChan, kDouble},
312  {"dc_wire_velocity",&fWireVelocity,kDouble},
313 
314  {"dc_xcenter", fXCenter, kDouble, fNChambers},
315  {"dc_ycenter", fYCenter, kDouble, fNChambers},
316  {"min_hit", fMinHits, kInt, fNChambers},
317  {"max_pr_hits", fMaxHits, kInt, fNChambers},
318  {"min_combos", fMinCombos, kInt, fNChambers},
319  {"space_point_criterion", fSpace_Point_Criterion, kDouble, fNChambers},
320 
321  {"dc_tdc_min_win", fTdcWinMin, kInt, (UInt_t)fNPlanes},
322  {"dc_tdc_max_win", fTdcWinMax, kInt, (UInt_t)fNPlanes},
323  {"dc_central_time", fCentralTime, kDouble, (UInt_t)fNPlanes},
324  {"dc_nrwire", fNWires, kInt, (UInt_t)fNPlanes},
325  {"dc_chamber_planes", fNChamber, kInt, (UInt_t)fNPlanes},
326  {"dc_wire_counting", fWireOrder, kInt, (UInt_t)fNPlanes},
327  {"dc_drifttime_sign", fDriftTimeSign, kInt, (UInt_t)fNPlanes},
328  {"dc_readoutLR", fReadoutLR, kInt, (UInt_t)fNPlanes, optional},
329  {"dc_readoutTB", fReadoutTB, kInt, (UInt_t)fNPlanes, optional},
330 
331  {"dc_zpos", fZPos, kDouble, (UInt_t)fNPlanes},
332  {"dc_alpha_angle", fAlphaAngle, kDouble, (UInt_t)fNPlanes},
333  {"dc_beta_angle", fBetaAngle, kDouble, (UInt_t)fNPlanes},
334  {"dc_gamma_angle", fGammaAngle, kDouble, (UInt_t)fNPlanes},
335  {"dc_pitch", fPitch, kDouble, (UInt_t)fNPlanes},
336  {"dc_central_wire", fCentralWire, kDouble, (UInt_t)fNPlanes},
337  {"dc_plane_time_zero", fPlaneTimeZero, kDouble, (UInt_t)fNPlanes},
338  {"dc_sigma", fSigma, kDouble, (UInt_t)fNPlanes},
339  {"single_stub",&fSingleStub, kInt,0,1},
340  {"ntracks_max_fp", &fNTracksMaxFP, kInt,0,1},
341  {"xt_track_criterion", &fXtTrCriterion, kDouble},
342  {"yt_track_criterion", &fYtTrCriterion, kDouble},
343  {"xpt_track_criterion", &fXptTrCriterion, kDouble},
344  {"ypt_track_criterion", &fYptTrCriterion, kDouble},
345  {"dc_fix_lr", &fFixLR, kInt},
346  {"dc_fix_propcorr", &fFixPropagationCorrection, kInt},
347  {"UseNewFindSpacePoints", &fUseNewFindSpacePoints, kInt,0,1},
348  {"UseNewLinkStubs", &fUseNewLinkStubs, kInt,0,1},
349  {"UseNewTrackFit", &fUseNewTrackFit, kInt,0,1},
350  {"debuglinkstubs", &fdebuglinkstubs, kInt},
351  {"debugprintrawdc", &fdebugprintrawdc, kInt},
352  {"debugprintdecodeddc", &fdebugprintdecodeddc, kInt},
353  {"debugflagpr", &fdebugflagpr, kInt},
354  {"debugflagstubs", &fdebugflagstubs, kInt},
355  {"debugtrackprint", &fdebugtrackprint , kInt},
356  {"TrackLargeResidCut", &fTrackLargeResidCut , kDouble,0,1},
357  {0}
358  };
359  fTrackLargeResidCut = -1;
362  fUseNewTrackFit=0;
363  fSingleStub=0;
364  for(Int_t ip=0; ip<fNPlanes;ip++) {
365  fReadoutLR[ip] = 0.0;
366  fReadoutTB[ip] = 0.0;
367  }
368 
369 
370  gHcParms->LoadParmValues((DBRequest*)&list,fPrefix);
371 
372  //Set the default plane x,y positions to those of the chamber
373  for(Int_t ip=0; ip<fNPlanes;ip++) {
374  fXPos[ip] = fXCenter[GetNChamber(ip+1)-1];
375  fYPos[ip] = fYCenter[GetNChamber(ip+1)-1];
376  }
377 
378  //Load the x,y positions of the planes if they exist (overwrites defaults)
379  DBRequest listOpt[]={
380  {"dc_xpos", fXPos, kDouble, (UInt_t)fNPlanes, optional},
381  {"dc_ypos", fYPos, kDouble, (UInt_t)fNPlanes, optional},
382  {0}
383  };
384  gHcParms->LoadParmValues((DBRequest*)&listOpt,fPrefix);
385  if(fNTracksMaxFP <= 0) fNTracksMaxFP = 10;
386  // if(fNTracksMaxFP > HNRACKS_MAX) fNTracksMaxFP = NHTRACKS_MAX;
387  cout << "Plane counts:";
388  for(Int_t i=0;i<fNPlanes;i++) {
389  cout << " " << fNWires[i];
390  }
391  cout << endl;
392 
393  fIsInit = true;
394 
395  return kOK;
396 }
397 
398 //_____________________________________________________________________________
400 {
404  if( mode == kDefine && fIsSetup ) return kOK;
405  fIsSetup = ( mode == kDefine );
406 
407  // Register variables in global list
408 
409  RVarDef vars[] = {
410  { "stubtest", "stub test", "fStubTest" },
411  { "nhit", "Number of DC hits", "fNhits" },
412  { "tnhit", "Number of good DC hits", "fNthits" },
413  { "trawhit", "Number of true raw DC hits", "fN_True_RawHits" },
414  { "ntrack", "Number of Tracks", "fNDCTracks" },
415  { "nsp", "Number of Space Points", "fNSp" },
416  { "track_nsp", "Number of spacepoints in track", "fDCTracks.THcDCTrack.GetNSpacePoints()"},
417  { "track_chisq", "Chisq of track", "fDCTracks.THcDCTrack.GetChisq()"},
418  { "track_nhits", "Number of hits in track", "fDCTracks.THcDCTrack.GetNHits()"},
419  { "track_sp1ID", "CH 1 Spacepoint index", "fDCTracks.THcDCTrack.GetSp1_ID()"},
420  { "track_sp2ID", "CH 2 Spacepoint index", "fDCTracks.THcDCTrack.GetSp2_ID()"},
421  { "track_hitpos", "Position of each hit in track", "fDCTracks.THcDCTrack.THcDCHit.GetPos()"},
422  { "x", "X at focal plane", "fDCTracks.THcDCTrack.GetX()"},
423  { "y", "Y at focal plane", "fDCTracks.THcDCTrack.GetY()"},
424  { "xp", "XP at focal plane", "fDCTracks.THcDCTrack.GetXP()"},
425  { "yp", "YP at focal plane", "fDCTracks.THcDCTrack.GetYP()"},
426  { "x_fp", "X at focal plane (golden track)", "fX_fp_best"},
427  { "y_fp", "Y at focal plane( golden track)", "fY_fp_best"},
428  { "xp_fp", "XP at focal plane (golden track)", "fXp_fp_best"},
429  { "yp_fp", "YP at focal plane(golden track) ", "fYp_fp_best"},
430  { "chisq", "chisq/dof (golden track) ", "fChisq_best"},
431  { "sp1_id", " (golden track) ", "fSp1_ID_best"},
432  { "sp2_id", " (golden track) ", "fSp2_ID_best"},
433  { "InsideDipoleExit", " ","fInSideDipoleExit_best"},
434  { "gtrack_nsp", " Number of space points in golden track ", "fNsp_best"},
435  { "pos_best", "Pos (golden track)", "fPos_best"},
436  { "dist_best", "Dist (golden track)", "fDist_best"},
437  { "lr_best", "LR sign (golden track)", "fLR_best"},
438  { "residual", "Residuals", "fResiduals"},
439  { "residualExclPlane", "Residuals", "fResidualsExclPlane"},
440  { "wireHitDid","Wire did have matched track hit", "fWire_hit_did"},
441  { "wireHitShould", "Wire should have matched track hit", "fWire_hit_should"},
442  { 0 }
443  };
444  return DefineVarsFromList( vars, mode );
445 
446 }
447 
448 //_____________________________________________________________________________
450 {
451  // Destructor. Remove variables from global list.
452 
453  if( fIsSetup )
454  RemoveVariables();
455  if( fIsInit )
456  DeleteArrays();
457 
458  // Delete the plane objects
459  for (vector<THcDriftChamberPlane*>::iterator ip = fPlanes.begin();
460  ip != fPlanes.end(); ++ip) delete *ip;
461  // Delete the chamber objects
462  for (vector<THcDriftChamber*>::iterator ip = fChambers.begin();
463  ip != fChambers.end(); ++ip) delete *ip;
464 
465  delete fDCTracks;
466 }
467 
468 //_____________________________________________________________________________
470 {
471  // Delete member arrays. Used by destructor.
472 
473  delete [] fXCenter; fXCenter = NULL;
474  delete [] fYCenter; fYCenter = NULL;
475  delete [] fMinHits; fMinHits = NULL;
476  delete [] fMaxHits; fMaxHits = NULL;
477  delete [] fMinCombos; fMinCombos = NULL;
479 
480  delete [] fTdcWinMin; fTdcWinMin = NULL;
481  delete [] fTdcWinMax; fTdcWinMax = NULL;
482  delete [] fCentralTime; fCentralTime = NULL;
483  delete [] fNWires; fNWires = NULL;
484  delete [] fNChamber; fNChamber = NULL;
485  delete [] fWireOrder; fWireOrder = NULL;
486  delete [] fDriftTimeSign; fDriftTimeSign = NULL;
487  delete [] fReadoutLR; fReadoutLR = NULL;
488  delete [] fReadoutTB; fReadoutTB = NULL;
489 
490  delete [] fXPos; fXPos = NULL;
491  delete [] fYPos; fYPos = NULL;
492  delete [] fZPos; fZPos = NULL;
493  delete [] fAlphaAngle; fAlphaAngle = NULL;
494  delete [] fBetaAngle; fBetaAngle = NULL;
495  delete [] fGammaAngle; fGammaAngle = NULL;
496  delete [] fPitch; fPitch = NULL;
497  delete [] fCentralWire; fCentralWire = NULL;
498  delete [] fPlaneTimeZero; fPlaneTimeZero = NULL;
499  delete [] fSigma; fSigma = NULL;
500 
501  // Efficiency arrays
502  delete [] fNChamHits; fNChamHits = NULL;
503  delete [] fPlaneEvents; fPlaneEvents = NULL;
504 
505  for( Int_t i = 0; i<fNPlanes; ++i )
506  delete [] fPlaneNames[i];
507  delete [] fPlaneNames;
508 
509  delete [] fPlaneCoeffs; fPlaneCoeffs = 0;
510  delete [] fResiduals; fResiduals = 0;
511  delete [] fDist_best; fDist_best = 0;
512  delete [] fPos_best; fPos_best = 0;
513  delete [] fLR_best; fLR_best = 0;
515  delete [] fWire_hit_did; fWire_hit_did = 0;
516  delete [] fWire_hit_should; fWire_hit_should = 0;
517 }
518 
519 //_____________________________________________________________________________
520 inline
522 {
523  // Reset per-event data.
524  fNDCTracks=0;
525  fStubTest = 0;
526  fNhits = 0;
527  fNthits = 0;
528  fN_True_RawHits=0;
529  fX_fp_best=-10000.;
530  fY_fp_best=-10000.;
531  fXp_fp_best=-10000.;
532  fYp_fp_best=-10000.;
534  fNsp_best=0;
536  for(UInt_t i=0;i<fNChambers;i++) {
537  fChambers[i]->Clear();
538  }
539 
540  for(Int_t i=0;i<fNPlanes;i++) {
541  fResiduals[i] = 1000.0;
542  fPos_best[i] = kBig;
543  fDist_best[i] = kBig;
544  fLR_best[i] = 0;
545  fResidualsExclPlane[i] = 1000.0;
546  fWire_hit_did[i] = 1000.0;
547  fWire_hit_should[i] = 1000.0;
548  }
549 
550  // fTrackProj->Clear();
551 }
552 
553 //_____________________________________________________________________________
554 Int_t THcDC::Decode( const THaEvData& evdata )
555 {
561  ClearEvent();
562  Int_t num_event = evdata.GetEvNum();
563  if (fdebugprintrawdc ||fdebugprintdecodeddc || fdebuglinkstubs || fdebugtrackprint) cout << " event num = " << num_event << endl;
564  // Get the Hall C style hitlist (fRawHitList) for this event
565 
566  Bool_t present = kTRUE; // Suppress reference time warnings
567  if(fPresentP) { // if this spectrometer not part of trigger
568  present = *fPresentP;
569  }
570  fNhits = DecodeToHitList(evdata, !present);
571 
572 
573 
574  if(!gHaCuts->Result("Pedestal_event")) {
575  // Let each plane get its hits
576  Int_t nexthit = 0;
577  for(Int_t ip=0;ip<fNPlanes;ip++) {
578  nexthit = fPlanes[ip]->ProcessHits(fRawHitList, nexthit);
579  fN_True_RawHits += fPlanes[ip]->GetNRawhits();
580 
581  }
582 
583  // fRawHitList is TClones array of THcRawDCHit objects
584  Int_t counter=0;
585  if (fdebugprintrawdc) {
586  cout << " RAW_TOT_HITS = " << fNRawHits << endl;
587  cout << " Hit # " << "Plane " << " Wire " << " Raw TDC " << endl;
588  for(UInt_t ihit = 0; ihit < fNRawHits ; ihit++) {
589  THcRawDCHit* hit = (THcRawDCHit *) fRawHitList->At(ihit);
590  for(UInt_t imhit = 0; imhit < hit->GetRawTdcHit().GetNHits(); imhit++) {
591  counter++;
592  cout << counter << " " << hit->fPlane << " " << hit->fCounter << " " << hit->GetRawTdcHit().GetTimeRaw(imhit) << endl;
593  }
594  }
595  cout << endl;
596  }
597  Eff(); // Accumlate statistics
598  }
599  return fNhits;
600 }
601 
602 //_____________________________________________________________________________
604 {
605  return(0);
606 }
607 
608 //_____________________________________________________________________________
610 {
617  // Subtract starttimes from each plane hit
618  for(Int_t ip=0;ip<fNPlanes;ip++) {
619  fPlanes[ip]->SubtractStartTime();
620  }
621  //
622  // Let each chamber get its hits
623  for(UInt_t ic=0;ic<fNChambers;ic++) {
624  fChambers[ic]->ProcessHits();
625  fNthits += fChambers[ic]->GetNHits();
626  if (fdebugprintdecodeddc)fChambers[ic]->PrintDecode();
627  }
628  //
629  for(UInt_t i=0;i<fNChambers;i++) {
630  if (fUseNewFindSpacePoints)fChambers[i]->NewFindSpacePoints();
631  if (!fUseNewFindSpacePoints) fChambers[i]->FindSpacePoints();
632  fChambers[i]->CorrectHitTimes();
633  fChambers[i]->LeftRight();
634  }
637  // Now link the stubs between chambers
638  if (fUseNewLinkStubs) {
639  NewLinkStubs();
640  } else {
641  LinkStubs();
642  }
643  if(fNDCTracks > 0) {
644  if (!fUseNewTrackFit) TrackFit();
645  // Copy tracks into podd tracks list
646  for(UInt_t itrack=0;itrack<fNDCTracks;itrack++) {
647  if (fUseNewTrackFit) NewTrackFit(itrack);
648  THaTrack* theTrack = NULL;
649  theTrack = AddTrack(tracks, 0.0, 0.0, 0.0, 0.0); // Leaving off trackID
650  // Should we add stubs with AddCluster? Could we do this
651  // by having stubs inherit from cluster
652 
653  THcDCTrack *tr = static_cast<THcDCTrack*>( fDCTracks->At(itrack));
654  theTrack->Set(tr->GetX(), tr->GetY(), tr->GetXP(), tr->GetYP());
655  theTrack->SetFlag((UInt_t) 0);
656  // Need to look at how engine does chi2 and track selection. Reduced?
657  theTrack->SetChi2(tr->GetChisq(),tr->GetNFree());
658  // CalcFocalPlaneCoords. Aren't our tracks already in focal plane coords
659  // We should have some kind of track ID so that the THaTrack can be
660  // associate back with the DC track
661  // Assign the track number
662  theTrack->SetTrkNum(itrack+1);
663  }
665  }
666  //
667  if(fNDCTracks > 0) {
668  THcHallCSpectrometer *spectro = dynamic_cast<THcHallCSpectrometer*>(GetApparatus());
669  for (Int_t it=0;it<tracks.GetLast()+1;it++) {
670  THaTrack* track = static_cast<THaTrack*>( tracks[it] );
671  Double_t xptar=kBig,yptar=kBig,ytar=kBig,delta=kBig;
672  Double_t xtar=0;
673  spectro->CalculateTargetQuantities(track,xtar,xptar,ytar,yptar,delta);
674  // Transfer results to track
675  // No beam raster yet
676  //; In transport coordinates phi = hyptar = dy/dz and theta = hxptar = dx/dz
677  //; but for unknown reasons the yp offset is named htheta_offset
678  //; and the xp offset is named hphi_offset
679 
680  track->SetTarget(0.0, ytar*100.0, xptar, yptar);
681  track->SetDp(delta*100.0); // Percent.
682  Double_t ptemp = spectro->GetPcentral()*(1+track->GetDp()/100.0);
683  track->SetMomentum(ptemp);
684  TVector3 pvect_temp;
685  spectro->TransportToLab(track->GetP(),track->GetTTheta(),track->GetTPhi(),pvect_temp);
686  track->SetPvect(pvect_temp);
687  }
688  }
689  //
690 
692 
693  return 0;
694 }
695 
696 //_____________________________________________________________________________
698 {
699  return 0;
700 }
701 //
702 void THcDC::SetFocalPlaneBestTrack(Int_t golden_track_index)
703 {
704  THcDCTrack *tr1 = static_cast<THcDCTrack*>( fDCTracks->At(golden_track_index));
705  fX_fp_best=tr1->GetX();
706  fY_fp_best=tr1->GetY();
707  fXp_fp_best=tr1->GetXP();
708  fYp_fp_best=tr1->GetYP();
709  THcHallCSpectrometer *app = dynamic_cast<THcHallCSpectrometer*>(GetApparatus());
711  fSp1_ID_best=tr1->GetSp1_ID();
712  fSp2_ID_best=tr1->GetSp2_ID();
713  fChisq_best=tr1->GetChisq();
714  fNsp_best=tr1->GetNSpacePoints();
715  for (UInt_t ihit = 0; ihit < UInt_t (tr1->GetNHits()); ihit++) {
716  THcDCHit *hit = tr1->GetHit(ihit);
717  Int_t plane = hit->GetPlaneNum() - 1;
718  fResiduals[plane] = tr1->GetResidual(plane);
719  fResidualsExclPlane[plane] = tr1->GetResidualExclPlane(plane);
720  fDist_best[plane] = tr1->GetHitDist(ihit);
721  fLR_best[plane] = tr1->GetHitLR(ihit);
722  fPos_best[plane] = hit->GetPos();
723  }
724  EfficiencyPerWire(golden_track_index);
725 }
726 //
727 void THcDC::EfficiencyPerWire(Int_t golden_track_index)
728 {
729  THcDCTrack *tr1 = static_cast<THcDCTrack*>( fDCTracks->At(golden_track_index));
730  Double_t track_pos;
731  for (UInt_t ihit = 0; ihit < UInt_t (tr1->GetNHits()); ihit++) {
732  THcDCHit *hit = tr1->GetHit(ihit);
733  Int_t plane = hit->GetPlaneNum() - 1;
734  track_pos=tr1->GetCoord(plane);
735  Int_t wire_num = hit->GetWireNum();
736  Int_t wire_track_num=round(fPlanes[plane]->CalcWireFromPos(track_pos));
737  if ( (wire_num-wire_track_num) ==0) fWire_hit_did[plane]=wire_num;
738  }
739  for(Int_t ip=0; ip<fNPlanes;ip++) {
740  track_pos=tr1->GetCoord(ip);
741  Int_t wire_should = round(fPlanes[ip]->CalcWireFromPos(track_pos));
742  fWire_hit_should[ip]=wire_should;
743  }
744 }
745 //
747 {
748  for(UInt_t ich=0;ich<fNChambers;ich++) {
749  printf("%s %2d %s %3d %s %3d \n"," chamber = ",fChambers[ich]->GetChamberNum()," number of hits = ",fChambers[ich]->GetNHits()," number of spacepoints = ",fChambers[ich]->GetNSpacePoints());
750  printf("%6s %-8s %-8s %6s %6s \n"," "," "," ","Number","Number");
751  printf("%6s %-8s %-8s %6s %6s \n","Point","x","y"," hits ","combos");
752  TClonesArray* spacepointarray = fChambers[ich]->GetSpacePointsP();
753  for(Int_t isp=0;isp<fChambers[ich]->GetNSpacePoints();isp++) {
754  THcSpacePoint* sp = (THcSpacePoint*)(spacepointarray->At(isp));
755  printf("%5d %8.5f %8.5f %5d %5d \n",isp+1,sp->GetX(),sp->GetY(),sp->GetNHits(),sp->GetCombos()) ;
756  for (Int_t ii=0;ii<sp->GetNHits();ii++) {
757  THcDCHit* hittemp = (THcDCHit*)(sp->GetHit(ii));
758  printf("%3d %3d %3d \n",hittemp->GetPlaneNum(),hittemp->GetWireNum(),hittemp->GetLR());
759  }
760  }
761  }
762 }
763 //
764 //
766 {
767  for(UInt_t ich=0;ich<fNChambers;ich++) {
768  printf("%s %3d \n"," Stub fit results Chamber = ",ich+1);
769  printf("%-5s %-18s %-18s %-18s %-18s\n","point","x_t","y_t","xp_t","yp_t");
770  printf("%-5s %-18s %-18s %-18s %-18s\n"," ","[cm]","[cm]","[cm]","[cm]");
771  TClonesArray* spacepointarray = fChambers[ich]->GetSpacePointsP();
772  for(Int_t isp=0;isp<fChambers[ich]->GetNSpacePoints();isp++) {
773  THcSpacePoint* sp = (THcSpacePoint*)(spacepointarray->At(isp));
774  Double_t *spstubt=sp->GetStubP();
775  printf("%-5d % 15.10e % 15.10e % 15.10e % 15.10e \n",isp+1,spstubt[0],spstubt[1],spstubt[2],spstubt[3]);
776  }
777  }
778 }
779 //
781 {
782  fNDCTracks=0; // Number of Focal Plane tracks found
783  fDCTracks->Delete();
784  if ( fChambers[0]->GetNSpacePoints() >0 && fChambers[1]->GetNSpacePoints() >0 ) {
785  std::vector<THcSpacePoint*> fSp; // vector of spacepoints from ch1 and ch2
786  fNSp=0;
787  fSp.clear();
788  // create array of spacepoints
789  for(UInt_t ich=0;ich<fNChambers;ich++) {
790  Int_t nchamber=fChambers[ich]->GetChamberNum();
791  TClonesArray* spacepointarray = fChambers[ich]->GetSpacePointsP();
792  for(Int_t isp=0;isp<fChambers[ich]->GetNSpacePoints();isp++) {
793  fSp.push_back(static_cast<THcSpacePoint*>(spacepointarray->At(isp)));
794  fSp[fNSp]->fNChamber = nchamber;
795  fSp[fNSp]->fNChamber_spnum = isp;
796  fNSp++;
797  }
798  }
799  //
800  for(Int_t isp1=0;isp1<fChambers[0]->GetNSpacePoints();isp1++) {
801  THcSpacePoint* sp1 = fSp[isp1];
802  Int_t ch1_nsp = fChambers[0]->GetNSpacePoints();
803  Int_t ch2_nsp = fChambers[1]->GetNSpacePoints();
804  for(Int_t isp2=ch1_nsp;isp2<ch1_nsp+ch2_nsp;isp2++) {
805  THcSpacePoint* sp2=fSp[isp2];
806  if (sp1->GetSetStubFlag()&&sp2->GetSetStubFlag()) {
807  Double_t *spstub1=sp1->GetStubP();
808  Double_t *spstub2=sp2->GetStubP();
809  Double_t dposx = spstub1[0] - spstub2[0];
810  Double_t dposy;
811  if(fProjectToChamber) {
812  Double_t y1=spstub1[1]+fChambers[sp1->fNChamber]->GetZPos()*spstub1[3];
813  Double_t y2=spstub2[1]+fChambers[sp2->fNChamber]->GetZPos()*spstub2[3];
814  dposy = y1-y2;
815  } else {
816  dposy = spstub1[1] - spstub2[1];
817  }
818  Double_t dposxp = spstub1[2] - spstub2[2];
819  Double_t dposyp = spstub1[3] - spstub2[3];
820  if((TMath::Abs(dposx) < fXtTrCriterion)
821  && (TMath::Abs(dposy) < fYtTrCriterion)
822  && (TMath::Abs(dposxp) < fXptTrCriterion)
823  && (TMath::Abs(dposyp) < fYptTrCriterion)) {
824  fStubTest = 1;
825  if(fNDCTracks < MAXTRACKS) {
826  THcDCTrack *theDCTrack = new( (*fDCTracks)[fNDCTracks++]) THcDCTrack(fNPlanes);
827  theDCTrack->AddSpacePoint(sp1);
828  theDCTrack->AddSpacePoint(sp2);
829  theDCTrack->SetSp1_ID(sp1->fNChamber_spnum);
830  theDCTrack->SetSp2_ID(sp2->fNChamber_spnum);
831  }
832  }
833  }
834  }// isp2
835  } // isp1
836  //
837  if (fNDCTracks == 0) { // make tracks from all combinations of spacepoints
838  for(Int_t isp1=0;isp1<fChambers[0]->GetNSpacePoints();isp1++) {
839  THcSpacePoint* sp1 = fSp[isp1];
840  Int_t ch1_nsp = fChambers[0]->GetNSpacePoints();
841  Int_t ch2_nsp = fChambers[1]->GetNSpacePoints();
842  for(Int_t isp2=ch1_nsp;isp2<ch1_nsp+ch2_nsp;isp2++) {
843  THcSpacePoint* sp2=fSp[isp2];
844  fStubTest = 1;
845  if(fNDCTracks < MAXTRACKS) {
846  THcDCTrack *theDCTrack = new( (*fDCTracks)[fNDCTracks++]) THcDCTrack(fNPlanes);
847  theDCTrack->AddSpacePoint(sp1);
848  theDCTrack->AddSpacePoint(sp2);
849  theDCTrack->SetSp1_ID(sp1->fNChamber_spnum);
850  theDCTrack->SetSp2_ID(sp2->fNChamber_spnum);
851  }
852  }
853  }
854  }
855  //
856  } // both chambers have spacepoints
857 //
858 
859 }
860 //_____________________________________________________________________________
862 {
878  std::vector<THcSpacePoint*> fSp;
879  fNSp=0;
880  fSp.clear();
881  fSp.reserve(100);
882  fNDCTracks=0; // Number of Focal Plane tracks found
883  fDCTracks->Delete();
884  // Make a vector of pointers to the SpacePoints
885  //if (fChambers[0]->GetNSpacePoints()+fChambers[1]->GetNSpacePoints()>10) return;
886 
887  for(UInt_t ich=0;ich<fNChambers;ich++) {
888  Int_t nchamber=fChambers[ich]->GetChamberNum();
889  TClonesArray* spacepointarray = fChambers[ich]->GetSpacePointsP();
890  for(Int_t isp=0;isp<fChambers[ich]->GetNSpacePoints();isp++) {
891  fSp.push_back(static_cast<THcSpacePoint*>(spacepointarray->At(isp)));
892  fSp[fNSp]->fNChamber = nchamber;
893  fSp[fNSp]->fNChamber_spnum = isp;
894  fNSp++;
895  if (ich==0 && fNSp>50) break;
896  if (fNSp>100) break;
897  }
898  }
899  Double_t stubminx = 999999;
900  Double_t stubminy = 999999;
901  Double_t stubminxp = 999999;
902  Double_t stubminyp = 999999;
903  Int_t stub_tracks[MAXTRACKS];
904  if(fSingleStub==0) {
905  for(Int_t isp1=0;isp1<fNSp-1;isp1++) { // isp1 is index/id in total list of space points
906  THcSpacePoint* sp1 = fSp[isp1];
907  Int_t sptracks=0;
908  // Now make sure this sp is not already used in a sp.
909  // Could this be done by having a sp point to the track it is in?
910  Int_t tryflag=1;
911  for(UInt_t itrack=0;itrack<fNDCTracks;itrack++) {
912  THcDCTrack *theDCTrack = static_cast<THcDCTrack*>( fDCTracks->At(itrack));
913  for(Int_t isp=0;isp<theDCTrack->GetNSpacePoints();isp++) {
914  // isp is index into list of space points attached to theDCTrack
915  if(theDCTrack->GetSpacePoint(isp) == sp1) {
916  tryflag=0;
917  }
918  }
919  }
920  if(tryflag) { // SP not already part of a track
921  Int_t newtrack=1;
922  for(Int_t isp2=isp1+1;isp2<fNSp;isp2++) {
923  THcSpacePoint* sp2=fSp[isp2];
924  if(sp1->fNChamber!=sp2->fNChamber&&sp1->GetSetStubFlag()&&sp2->GetSetStubFlag()) {
925  Double_t *spstub1=sp1->GetStubP();
926  Double_t *spstub2=sp2->GetStubP();
927  Double_t dposx = spstub1[0] - spstub2[0];
928  Double_t dposy;
929  if(fProjectToChamber) { // From SOS s_link_stubs
930  // Since single chamber resolution is ~50mr, and the maximum y`
931  // angle is about 30mr, use differenece between y AT CHAMBERS, rather
932  // than at focal plane. (Project back to chamber, to take out y' uncertainty)
933  // (Should this be done for SHMS and HMS too?)
934  Double_t y1=spstub1[1]+fChambers[sp1->fNChamber]->GetZPos()*spstub1[3];
935  Double_t y2=spstub2[1]+fChambers[sp2->fNChamber]->GetZPos()*spstub2[3];
936  dposy = y1-y2;
937  } else {
938  dposy = spstub1[1] - spstub2[1];
939  }
940  Double_t dposxp = spstub1[2] - spstub2[2];
941  Double_t dposyp = spstub1[3] - spstub2[3];
942 
943  // What is the point of saving these stubmin values. They
944  // Don't seem to be used anywhere except that they can be
945  // printed out if hbypass_track_eff_files is zero.
946  if(TMath::Abs(dposx)<TMath::Abs(stubminx)) stubminx = dposx;
947  if(TMath::Abs(dposy)<TMath::Abs(stubminy)) stubminy = dposy;
948  if(TMath::Abs(dposxp)<TMath::Abs(stubminxp)) stubminxp = dposxp;
949  if(TMath::Abs(dposyp)<TMath::Abs(stubminyp)) stubminyp = dposyp;
950 
951  // if hbypass_track_eff_files == 0 then
952  // Print out each stubminX that is less that its criterion
953 
954  if((TMath::Abs(dposx) < fXtTrCriterion)
955  && (TMath::Abs(dposy) < fYtTrCriterion)
956  && (TMath::Abs(dposxp) < fXptTrCriterion)
957  && (TMath::Abs(dposyp) < fYptTrCriterion)) {
958  if(newtrack) {
959  assert(sptracks==0);
960  fStubTest = 1;
961  //stubtest=1; Used in h_track_tests.f
962  // Make a new track if there are not to many
963  if(fNDCTracks < MAXTRACKS) {
964  sptracks=0; // Number of tracks with this seed
965  stub_tracks[sptracks++] = fNDCTracks;
966  THcDCTrack *theDCTrack = new( (*fDCTracks)[fNDCTracks++]) THcDCTrack(fNPlanes);
967  theDCTrack->AddSpacePoint(sp1);
968  theDCTrack->AddSpacePoint(sp2);
969  if (sp1->fNChamber==1) theDCTrack->SetSp1_ID(sp1->fNChamber_spnum);
970  if (sp1->fNChamber==2) theDCTrack->SetSp2_ID(sp1->fNChamber_spnum);
971  if (sp2->fNChamber==1) theDCTrack->SetSp1_ID(sp2->fNChamber_spnum);
972  if (sp2->fNChamber==2) theDCTrack->SetSp2_ID(sp2->fNChamber_spnum);
973  newtrack = 0; // Make no more tracks in this loop
974  // (But could replace a SP?)
975  } else {
976  if (fHMSStyleChambers) {
977  fNDCTracks=0;
978  return;
979  }
980  }
981  } else {
982  // Check if there is another space point in the same chamber
983  for(Int_t itrack=0;itrack<sptracks;itrack++) {
984  Int_t track=stub_tracks[itrack];
985  THcDCTrack *theDCTrack = static_cast<THcDCTrack*>( fDCTracks->At(track));
986  Int_t spoint=-1;
987  Int_t duppoint=0;
988  for(Int_t isp=0;isp<theDCTrack->GetNSpacePoints();isp++) {
989  // isp is index of space points in theDCTrack
990  if(sp2->fNChamber ==
991  theDCTrack->GetSpacePoint(isp)->fNChamber) {
992  spoint=isp;
993  }
994  if(sp2==theDCTrack->GetSpacePoint(isp)) {
995  duppoint=1;
996  }
997  } // End loop over sp in tracks with isp1
998  // If there is no other space point in this chamber
999  // add this space point to current track(2)
1000  if(!duppoint) {
1001  if(spoint<0) {
1002  theDCTrack->AddSpacePoint(sp2);
1003  if (sp2->fNChamber==1) theDCTrack->SetSp1_ID(sp2->fNChamber_spnum);
1004  if (sp2->fNChamber==2) theDCTrack->SetSp2_ID(sp2->fNChamber_spnum);
1005  } else {
1006  // If there is another point in the same chamber
1007  // in this track create a new track with all the
1008  // same space points except spoint
1009  if(fNDCTracks < MAXTRACKS) {
1010  stub_tracks[sptracks++] = fNDCTracks;
1011  THcDCTrack *newDCTrack = new( (*fDCTracks)[fNDCTracks++]) THcDCTrack(fNPlanes);
1012  for(Int_t isp=0;isp<theDCTrack->GetNSpacePoints();isp++) {
1013  if(isp!=spoint) {
1014  newDCTrack->AddSpacePoint(theDCTrack->GetSpacePoint(isp));
1015  if (theDCTrack->GetSpacePoint(isp)->fNChamber==1) newDCTrack->SetSp1_ID(theDCTrack->GetSpacePoint(isp)->fNChamber_spnum);
1016  if (theDCTrack->GetSpacePoint(isp)->fNChamber==2) newDCTrack->SetSp2_ID(theDCTrack->GetSpacePoint(isp)->fNChamber_spnum);
1017  } else {
1018  newDCTrack->AddSpacePoint(sp2);
1019  if (sp2->fNChamber==1) newDCTrack->SetSp1_ID(sp2->fNChamber_spnum);
1020  if (sp2->fNChamber==2) newDCTrack->SetSp2_ID(sp2->fNChamber_spnum);
1021  } // End check for dup on copy
1022  } // End copy of track
1023  } else {
1024  if (fHMSStyleChambers) {
1025  if (fdebuglinkstubs) cout << "EPIC FAIL 2: Too many tracks found in THcDC::LinkStubs maxtracks = " << MAXTRACKS << endl;
1026  fNDCTracks=0;
1027  return; // Max # of allowed tracks
1028  }
1029  }
1030  } // end if on same chamber
1031  } // end if on duplicate point
1032  } // end for over tracks with isp1
1033  } // else newtrack
1034  } // criterion
1035  } // end test on same chamber
1036  } // end isp2 loop over new space points
1037  } // end test on tryflag
1038  } // end isp1 outer loop over space points
1039  //
1040  //
1041  } else { // Make track out of each single space point
1042  for(Int_t isp=0;isp<fNSp;isp++) {
1043  if(fNDCTracks<MAXTRACKS) {
1044  // Need some constructed t thingy
1045  if (fSp[isp]->GetSetStubFlag()) {
1046  THcDCTrack *newDCTrack = new( (*fDCTracks)[fNDCTracks++]) THcDCTrack(fNPlanes);
1047  newDCTrack->AddSpacePoint(fSp[isp]);
1048  }
1049  } else {
1050  if (fdebuglinkstubs) cout << "EPIC FAIL 3: Too many tracks found in THcDC::LinkStubs" << endl;
1051  fNDCTracks=0;
1052  // Do something here to fail this event
1053  return; // Max # of allowed tracks
1054  }
1055  }
1056  }
1058  if (fdebuglinkstubs) {
1059  cout << " Number of tracks from link stubs = " << fNDCTracks << endl;
1060  printf("%s %s \n","Track","Plane Wire ");
1061  for (UInt_t itrack=0;itrack<fNDCTracks;itrack++) {
1062  THcDCTrack *tempTrack = (THcDCTrack*)( fDCTracks->At(itrack));
1063  printf("%-5d ",itrack+1);
1064  for (Int_t ihit=0;ihit<tempTrack->GetNHits();ihit++) {
1065  THcDCHit* hit=(THcDCHit*)(tempTrack->GetHit(ihit));
1066  printf("%3d %3d",hit->GetPlaneNum(),hit->GetWireNum());
1067  }
1068  printf("\n");
1069  }
1070  }
1071 }
1072 //_____________________________________________________________________________
1073 void THcDC::FitLineToTrack(Int_t TrackHits,Double_t coords[],Int_t planes[],Double_t wiresigma[], Double_t TrackCoord[], Double_t save_ray[])
1074 {
1075  const Int_t raycoeffmap[]={4,5,2,3};
1076  TVectorD TT(4);
1077  TMatrixD AA(4,4);
1078  for(Int_t irayp=0;irayp<NUM_FPRAY;irayp++) {
1079  TT[irayp] = 0.0;
1080  for(Int_t ihit=0;ihit < TrackHits;ihit++) {
1081  TT[irayp] += (coords[ihit]*fPlaneCoeffs[planes[ihit]][raycoeffmap[irayp]])/pow(wiresigma[ihit],2);
1082  }
1083  }
1084  //
1085  for(Int_t irayp=0;irayp<NUM_FPRAY;irayp++) {
1086  for(Int_t jrayp=0;jrayp<NUM_FPRAY;jrayp++) {
1087  AA[irayp][jrayp] = 0.0;
1088  if(jrayp<irayp) { // Symmetric
1089  AA[irayp][jrayp] = AA[jrayp][irayp];
1090  } else {
1091  for(Int_t ihit=0;ihit <TrackHits ;ihit++) {
1092  AA[irayp][jrayp] += fPlaneCoeffs[planes[ihit]][raycoeffmap[irayp]]*
1093  fPlaneCoeffs[planes[ihit]][raycoeffmap[jrayp]]/pow(wiresigma[ihit],2);
1094  } //end ihit loop
1095  }
1096  }
1097  }
1098 
1099  // Solve 4x4 equations
1100  TVectorD dray(NUM_FPRAY);
1101  AA.Invert();
1102  dray = AA*TT;
1103  for(Int_t ir=0;ir<NUM_FPRAY;ir++) save_ray[ir]=dray[ir];
1104  for(Int_t iplane=0;iplane < fNPlanes; iplane++) {
1105  Double_t sumcoord=0.0;
1106  for(Int_t ir=0;ir<NUM_FPRAY;ir++) {
1107  sumcoord += fPlaneCoeffs[iplane][raycoeffmap[ir]]*dray[ir];
1108  }
1109  TrackCoord[iplane]=sumcoord;
1110  }
1111 }
1112 //_____________________________________________________________________________
1113 void THcDC::NewTrackFit(UInt_t TrackIndex)
1114 {
1115  THcDCTrack *tr = static_cast<THcDCTrack*>( fDCTracks->At(TrackIndex));
1116  Double_t minchi2=100000.;
1117  Int_t MAXHITS=12;
1118  Int_t plusminus[MAXHITS];
1119  Int_t plusminusknown[MAXHITS];
1120  Int_t TrackHits = tr->GetNHits();
1121  Double_t coords[TrackHits];
1122  Double_t TrackCoord[TrackHits];
1123  Int_t planes[TrackHits];
1124  Double_t wiresigma[TrackHits];
1125  Double_t save_ray[NUM_FPRAY];
1126  for(Int_t ihit=0;ihit<MAXHITS;ihit++) {
1127  plusminusknown[ihit]=0;
1128  }
1129  Int_t nplusminus=1<<TrackHits;
1130  for(Int_t pmloop=0;pmloop<nplusminus;pmloop++) {
1131  Int_t iswhit = 1;
1132  for(Int_t ihit=0;ihit<TrackHits;ihit++) {
1133  if(plusminusknown[ihit]!=0) {
1134  plusminus[ihit] = plusminusknown[ihit];
1135  } else {
1136  if(pmloop & iswhit) {
1137  plusminus[ihit] = 1;
1138  } else {
1139  plusminus[ihit] = -1;
1140  }
1141  iswhit <<= 1;
1142  }
1143  }
1144  for(Int_t ihit=0;ihit<TrackHits;ihit++) {
1145  THcDCHit* hit=tr->GetHit(ihit);
1146  coords[ihit] =hit->GetPos()+ plusminus[ihit]*tr->GetHitDist(ihit);
1147  planes[ihit] =hit->GetPlaneNum()-1;
1148  wiresigma[ihit] = hit->GetWireSigma();
1149  }
1150  FitLineToTrack(TrackHits,coords,planes,wiresigma,TrackCoord,save_ray);
1151  Double_t chi2 = 0.0;
1152  for(Int_t ihit=0;ihit < TrackHits;ihit++) {
1153  Double_t residual = coords[ihit] - TrackCoord[planes[ihit]];
1154  chi2 += pow(residual/wiresigma[ihit],2);
1155  }
1156  if (chi2 < minchi2) {
1157  minchi2 = chi2;
1158  tr->SetVector(save_ray[0], save_ray[1], 0.0, save_ray[2], save_ray[3]);
1159  for(Int_t ihit=0;ihit < TrackHits;ihit++) {
1160  tr->SetHitLR(ihit, plusminus[ihit]);
1161  tr->SetCoord(planes[ihit], TrackCoord[planes[ihit]]);
1162  Double_t residual = coords[ihit] -TrackCoord[planes[ihit]] ;
1163  tr->SetResidual(planes[ihit], residual);
1164  tr->SetChisq(chi2);
1165  tr->SetNFree(TrackHits - 4);
1166  }
1167  //cout << " fit = " << chi2 << " " << dray[0] << " " << dray[1] << " "<< dray[2] << " "<< dray[3] << " " << endl ;
1168  }
1169  } // pmloop
1170  //
1171  // calculate ray without a plane in track
1172  const Int_t raycoeffmap[]={4,5,2,3};
1173  for(Int_t ihit=0;ihit<TrackHits;ihit++) {
1174  THcDCHit* hit=tr->GetHit(ihit);
1175  coords[ihit] =hit->GetPos()+ tr->GetHitLR(ihit)*tr->GetHitDist(ihit);
1176  planes[ihit] =hit->GetPlaneNum()-1;
1177  wiresigma[ihit] = hit->GetWireSigma();
1178  }
1179  for(Int_t ipl_hit=0;ipl_hit < tr->GetNHits();ipl_hit++) {
1180 
1181 
1182  if(tr->GetNFree() > 0) {
1183  TVectorD TT(NUM_FPRAY);
1185  for(Int_t irayp=0;irayp<NUM_FPRAY;irayp++) {
1186  TT[irayp] = 0.0;
1187  for(Int_t ihit=0;ihit < tr->GetNHits();ihit++) {
1188 
1189 
1190  THcDCHit* hit=tr->GetHit(ihit);
1191 
1192  if (ihit != ipl_hit) {
1193  TT[irayp] += (coords[ihit]*
1194  fPlaneCoeffs[planes[ihit]][raycoeffmap[irayp]])
1195  /pow(hit->GetWireSigma(),2);
1196 
1197  }
1198  }
1199  }
1200  for(Int_t irayp=0;irayp<NUM_FPRAY;irayp++) {
1201  for(Int_t jrayp=0;jrayp<NUM_FPRAY;jrayp++) {
1202  AA[irayp][jrayp] = 0.0;
1203  if(jrayp<irayp) { // Symmetric
1204  AA[irayp][jrayp] = AA[jrayp][irayp];
1205  } else {
1206 
1207  for(Int_t ihit=0;ihit < tr->GetNHits();ihit++) {
1208 
1209  THcDCHit* hit=tr->GetHit(ihit);
1210 
1211 
1212  if (ihit != ipl_hit) {
1213  AA[irayp][jrayp] += fPlaneCoeffs[planes[ihit]][raycoeffmap[irayp]]*
1214  fPlaneCoeffs[planes[ihit]][raycoeffmap[jrayp]]/
1215  pow(hit->GetWireSigma(),2);
1216 
1217  }
1218  }
1219  }
1220  }
1221  }
1222  //
1223  // Solve 4x4 equations
1224  // Should check that it is invertable
1225  TVectorD dray(NUM_FPRAY);
1226  AA.Invert();
1227  dray = AA*TT;
1228  Double_t coord=0.0;
1229  for(Int_t ir=0;ir<NUM_FPRAY;ir++) {
1230  coord += fPlaneCoeffs[planes[ipl_hit]][raycoeffmap[ir]]*dray[ir];
1231  // cout << "ir = " << ir << ", dray[ir] = " << dray[ir] << endl;
1232  }
1233  Double_t residual = coords[ipl_hit] - coord;
1234  tr->SetResidualExclPlane(planes[ipl_hit], residual);
1235  }//Calculate residual without plane
1236  //
1237  }
1238  //
1239 
1240 }
1241 
1242 //_____________________________________________________________________________
1244 {
1249  // Number of ray parameters in focal plane.
1250  const Int_t raycoeffmap[]={4,5,2,3};
1251 
1252  Double_t dummychi2 = 1.0E4;
1253  for(UInt_t itrack=0;itrack<fNDCTracks;itrack++) {
1254  // Double_t chi2 = dummychi2;
1255  // Int_t htrack_fit_num = itrack;
1256  Bool_t CheckResid = kTRUE;
1257  Int_t NLoops=0;
1258  Int_t NLoopsMax=1;
1259  while (CheckResid) {
1260  Int_t MaxResidHitIndex = -1;
1261  Double_t MaxResid = -1000;
1262  THcDCTrack *theDCTrack = static_cast<THcDCTrack*>( fDCTracks->At(itrack));
1263 
1264  Double_t coords[theDCTrack->GetNHits()];
1265  Int_t planes[theDCTrack->GetNHits()];
1266  for(Int_t ihit=0;ihit < theDCTrack->GetNHits();ihit++) {
1267  THcDCHit* hit=theDCTrack->GetHit(ihit);
1268  planes[ihit]=hit->GetPlaneNum()-1;
1269  if(fFixLR) {
1271  coords[ihit] = hit->GetPos()
1272  + theDCTrack->GetHitLR(ihit)*theDCTrack->GetHitDist(ihit);
1273  } else {
1274  coords[ihit] = hit->GetPos()
1275  + theDCTrack->GetHitLR(ihit)*hit->GetDist();
1276  }
1277 
1278  } else {
1280  coords[ihit] = hit->GetPos()
1281  + hit->GetLR()*theDCTrack->GetHitDist(ihit);
1282  } else {
1283  coords[ihit] = hit->GetCoord();
1284  }
1285  }
1286 
1287 
1288  } //end loop over hits
1289 
1290  theDCTrack->SetNFree(theDCTrack->GetNHits() - NUM_FPRAY);
1291  Double_t chi2 = dummychi2;
1292  if(theDCTrack->GetNFree() > 0) {
1293  TVectorD TT(NUM_FPRAY);
1295  for(Int_t irayp=0;irayp<NUM_FPRAY;irayp++) {
1296  TT[irayp] = 0.0;
1297  for(Int_t ihit=0;ihit < theDCTrack->GetNHits();ihit++) {
1298 
1299  THcDCHit* hit=theDCTrack->GetHit(ihit);
1300  TT[irayp] += (coords[ihit]*fPlaneCoeffs[planes[ihit]][raycoeffmap[irayp]])/pow(hit->GetWireSigma(),2);
1301  // if (hit->GetPlaneNum()==5)
1302  // {
1303  // // cout << "Plane: " << hit->GetPlaneNum() << endl;
1304  // //cout << "Wire: " <<hit->GetWireNum() << endl;
1305  // //cout << "Sigma: " << hit->GetWireSigma() << endl;
1306  // }
1307 
1308  } //end hit loop
1309  }
1310  /*
1311  for(Int_t ihit=0;ihit < theDCTrack->GetNHits();ihit++) {
1312  cout << " hit = " << ihit << " " << coords[ihit] << " " << planes[ihit] ;
1313  }
1314  cout << " ****" << endl;
1315  */
1316  for(Int_t irayp=0;irayp<NUM_FPRAY;irayp++) {
1317  for(Int_t jrayp=0;jrayp<NUM_FPRAY;jrayp++) {
1318  AA[irayp][jrayp] = 0.0;
1319  if(jrayp<irayp) { // Symmetric
1320  AA[irayp][jrayp] = AA[jrayp][irayp];
1321  } else {
1322  for(Int_t ihit=0;ihit < theDCTrack->GetNHits();ihit++) {
1323 
1324  THcDCHit* hit=theDCTrack->GetHit(ihit);
1325 
1326 
1327  AA[irayp][jrayp] += fPlaneCoeffs[planes[ihit]][raycoeffmap[irayp]]*
1328  fPlaneCoeffs[planes[ihit]][raycoeffmap[jrayp]]/
1329  pow(hit->GetWireSigma(),2);
1330 
1331  } //end ihit loop
1332  }
1333  }
1334  }
1335 
1336  // Solve 4x4 equations
1337  TVectorD dray(NUM_FPRAY);
1338  // Should check that it is invertable
1339  AA.Invert();
1340  dray = AA*TT;
1341 
1342  // Make sure fCoords, fResiduals, and fDoubleResiduals are clear
1343  for(Int_t iplane=0;iplane < fNPlanes; iplane++) {
1344  Double_t coord=0.0;
1345  for(Int_t ir=0;ir<NUM_FPRAY;ir++) {
1346  coord += fPlaneCoeffs[iplane][raycoeffmap[ir]]*dray[ir];
1347  // cout << "ir = " << ir << ", dray[ir] = " << dray[ir] << endl;
1348  }
1349  theDCTrack->SetCoord(iplane,coord);
1350  }
1351  // Compute Chi2 and residuals
1352  chi2 = 0.0;
1353  for(Int_t ihit=0;ihit < theDCTrack->GetNHits();ihit++) {
1354 
1355  THcDCHit* hit=theDCTrack->GetHit(ihit);
1356 
1357 
1358  Double_t residual = coords[ihit] - theDCTrack->GetCoord(planes[ihit]);
1359  theDCTrack->SetResidual(planes[ihit], residual);
1360  if (abs(residual) > MaxResid) {
1361  MaxResidHitIndex =ihit;
1362  MaxResid = abs(residual);
1363  }
1364 
1365  // double track_coord = theDCTrack->GetCoord(planes[ihit]);
1366 //cout<<planes[ihit]<<"\t"<<track_coord<<"\t"<<coords[ihit]<<"\t"<<residual<<endl;
1367  chi2 += pow(residual/hit->GetWireSigma(),2);
1368 
1369  }
1370 
1371  theDCTrack->SetVector(dray[0], dray[1], 0.0, dray[2], dray[3]);
1372  }
1373  theDCTrack->SetChisq(chi2);
1374  // calculate ray without a plane in track
1375  for(Int_t ipl_hit=0;ipl_hit < theDCTrack->GetNHits();ipl_hit++) {
1376 
1377 
1378  if(theDCTrack->GetNFree() > 0) {
1379  TVectorD TT(NUM_FPRAY);
1381  for(Int_t irayp=0;irayp<NUM_FPRAY;irayp++) {
1382  TT[irayp] = 0.0;
1383  for(Int_t ihit=0;ihit < theDCTrack->GetNHits();ihit++) {
1384 
1385 
1386  THcDCHit* hit=theDCTrack->GetHit(ihit);
1387 
1388  if (ihit != ipl_hit) {
1389  TT[irayp] += (coords[ihit]*
1390  fPlaneCoeffs[planes[ihit]][raycoeffmap[irayp]])
1391  /pow(hit->GetWireSigma(),2);
1392 
1393  }
1394  }
1395  }
1396  for(Int_t irayp=0;irayp<NUM_FPRAY;irayp++) {
1397  for(Int_t jrayp=0;jrayp<NUM_FPRAY;jrayp++) {
1398  AA[irayp][jrayp] = 0.0;
1399  if(jrayp<irayp) { // Symmetric
1400  AA[irayp][jrayp] = AA[jrayp][irayp];
1401  } else {
1402 
1403  for(Int_t ihit=0;ihit < theDCTrack->GetNHits();ihit++) {
1404 
1405  THcDCHit* hit=theDCTrack->GetHit(ihit);
1406 
1407 
1408  if (ihit != ipl_hit) {
1409  AA[irayp][jrayp] += fPlaneCoeffs[planes[ihit]][raycoeffmap[irayp]]*
1410  fPlaneCoeffs[planes[ihit]][raycoeffmap[jrayp]]/
1411  pow(hit->GetWireSigma(),2);
1412 
1413  }
1414  }
1415  }
1416  }
1417  }
1418  //
1419  // Solve 4x4 equations
1420  // Should check that it is invertable
1421  TVectorD dray(NUM_FPRAY);
1422  AA.Invert();
1423  dray = AA*TT;
1424  Double_t coord=0.0;
1425  for(Int_t ir=0;ir<NUM_FPRAY;ir++) {
1426  coord += fPlaneCoeffs[planes[ipl_hit]][raycoeffmap[ir]]*dray[ir];
1427  // cout << "ir = " << ir << ", dray[ir] = " << dray[ir] << endl;
1428  }
1429  Double_t residual = coords[ipl_hit] - coord;
1430  theDCTrack->SetResidualExclPlane(planes[ipl_hit], residual);
1431  }
1432  }
1433  //
1434  if (fTrackLargeResidCut == -1) {
1435  CheckResid = kFALSE;
1436  } else {
1437  CheckResid = kFALSE;
1438  if ( MaxResid > fTrackLargeResidCut) {
1439  CheckResid = kTRUE;
1440  theDCTrack->RemoveHit(MaxResidHitIndex);
1441  }
1442  }
1443  //
1444  if (NLoops == NLoopsMax) CheckResid = kFALSE;
1445  NLoops++;
1446  } // while
1447  } // loop over tracks
1448  //Calculate residual without plane
1449 
1450  // Calculate residuals for each chamber if in single stub mode
1451  // and there was a track found in each chamber
1452  // Specific for two chambers. Can/should it be generalized?
1453 
1454  if(fSingleStub != 0) {
1455  if(fNDCTracks == 2) {
1456  THcDCTrack *theDCTrack1 = static_cast<THcDCTrack*>( fDCTracks->At(0));
1457  THcDCTrack *theDCTrack2 = static_cast<THcDCTrack*>( fDCTracks->At(1));
1458  // Int_t itrack=0;
1459  Int_t ihit=0;
1460  THcDCHit* hit=theDCTrack1->GetHit(ihit);
1461  Int_t plane=hit->GetPlaneNum()-1;
1462  Int_t chamber=fNChamber[plane];
1463  if(chamber==1) {
1464  // itrack=1;
1465  hit=theDCTrack2->GetHit(ihit);
1466  plane=hit->GetPlaneNum()-1;
1467  chamber=fNChamber[plane];
1468  if(chamber==2) {
1469  Double_t ray1[4];
1470  Double_t ray2[4];
1471  theDCTrack1->GetRay(ray1);
1472  theDCTrack2->GetRay(ray2);
1473  // itrack = 1;
1474  // Loop over hits in second chamber
1475  for(Int_t ihit=0;ihit < theDCTrack2->GetNHits();ihit++) {
1476  // Calculate residual in second chamber from first chamber track
1477  THcDCHit* hit=theDCTrack2->GetHit(ihit);
1478  Int_t plane=hit->GetPlaneNum()-1;
1479  Double_t pos = DpsiFun(ray1,plane);
1480  Double_t coord;
1481  if(fFixLR) {
1483  coord = hit->GetPos()
1484  + theDCTrack2->GetHitLR(ihit)*theDCTrack2->GetHitDist(ihit);
1485  } else {
1486  coord = hit->GetPos()
1487  + theDCTrack2->GetHitLR(ihit)*hit->GetDist();
1488  }
1489  } else {
1491  coord = hit->GetPos()
1492  + hit->GetLR()*theDCTrack2->GetHitDist(ihit);
1493  } else {
1494  coord = hit->GetCoord();
1495  }
1496  }
1497  theDCTrack1->SetDoubleResidual(plane,coord - pos);
1498  // hdc_dbl_res(pln) = hdc_double_residual(1,pln) for hists
1499  }
1500  // itrack=0;
1501  // Loop over hits in first chamber
1502  for(Int_t ihit=0;ihit < theDCTrack1->GetNHits();ihit++) {
1503  // Calculate residual in first chamber from second chamber track
1504  THcDCHit* hit=theDCTrack1->GetHit(ihit);
1505  Int_t plane=hit->GetPlaneNum()-1;
1506  Double_t pos = DpsiFun(ray1,plane);
1507  Double_t coord;
1508  if(fFixLR) {
1510  coord = hit->GetPos()
1511  + theDCTrack1->GetHitLR(ihit)*theDCTrack1->GetHitDist(ihit);
1512  } else {
1513  coord = hit->GetPos()
1514  + theDCTrack1->GetHitLR(ihit)*hit->GetDist();
1515  }
1516  } else {
1518  coord = hit->GetPos()
1519  + hit->GetLR()*theDCTrack1->GetHitDist(ihit);
1520  } else {
1521  coord = hit->GetCoord();
1522  }
1523  }
1524  theDCTrack2->SetDoubleResidual(plane,coord - pos);
1525  // hdc_dbl_res(pln) = hdc_double_residual(1,pln) for hists
1526  }
1527  }
1528  }
1529  }
1530  }
1531  //
1532 
1533  //
1534 }
1535 //
1537  printf("%5s %-14s %-14s %-14s %-14s %-10s %-10s \n","Track","x_t","y_t","xp_t","yp_t","chi2","DOF");
1538  printf("%5s %-14s %-14s %-14s %-14s %-10s %-10s \n"," ","[cm]","[cm]","[rad]","[rad]"," "," ");
1539  for(UInt_t itr=0;itr < fNDCTracks;itr++) {
1540  THcDCTrack *theDCTrack = static_cast<THcDCTrack*>( fDCTracks->At(itr));
1541  printf("%-5d %14.6e %14.6e %14.6e %14.6e %10.3e %3d \n", itr+1,theDCTrack->GetX(),theDCTrack->GetY(),theDCTrack->GetXP(),theDCTrack->GetYP(),theDCTrack->GetChisq(),theDCTrack->GetNFree());
1542  }
1543  for(UInt_t itr=0;itr < fNDCTracks;itr++) {
1544  printf("%s %5d \n","Hit info for track number = ",itr+1);
1545  printf("%5s %-15s %-15s %-15s \n","Plane","WIRE_COORD","Fit postiion","Residual");
1546  THcDCTrack *theDCTrack = static_cast<THcDCTrack*>( fDCTracks->At(itr));
1547  for(Int_t ihit=0;ihit < theDCTrack->GetNHits();ihit++) {
1548  THcDCHit* hit=theDCTrack->GetHit(ihit);
1549  Int_t plane=hit->GetPlaneNum()-1;
1550  Double_t coords_temp;
1551  if(fFixLR) {
1553  coords_temp = hit->GetPos()
1554  + theDCTrack->GetHitLR(ihit)*theDCTrack->GetHitDist(ihit);
1555  } else {
1556  coords_temp = hit->GetPos()
1557  + theDCTrack->GetHitLR(ihit)*hit->GetDist();
1558  }
1559  } else {
1561  coords_temp = hit->GetPos()
1562  + hit->GetLR()*theDCTrack->GetHitDist(ihit);
1563  } else {
1564  coords_temp = hit->GetCoord();
1565  }
1566  }
1567  printf("%-5d %15.7e %15.7e %15.7e \n",plane+1,coords_temp,theDCTrack->GetCoord(plane),theDCTrack->GetResidual(plane));
1568  }
1569  }
1570 }
1571 //
1573 {
1592  Double_t infinity = 1.0E+20;
1593  Double_t cinfinity = 1/infinity;
1594  Double_t DpsiFun =
1595  ray[2]*ray[1]*fPlaneCoeffs[plane][0] +
1596  ray[3]*ray[0]*fPlaneCoeffs[plane][1] +
1597  ray[2]*fPlaneCoeffs[plane][2] +
1598  ray[3]*fPlaneCoeffs[plane][3] +
1599  ray[0]*fPlaneCoeffs[plane][4] +
1600  ray[1]*fPlaneCoeffs[plane][5];
1601  Double_t denom = ray[2]*fPlaneCoeffs[plane][6]
1602  + ray[3]*fPlaneCoeffs[plane][7]
1603  + fPlaneCoeffs[plane][8];
1604  if(TMath::Abs(denom) < cinfinity) {
1605  DpsiFun = infinity;
1606  } else {
1607  DpsiFun = DpsiFun/denom;
1608  }
1609  return(DpsiFun);
1610 }
1611 
1612 //_____________________________________________________________________________
1613 Int_t THcDC::End(THaRunBase* run)
1614 {
1615  // EffCalc();
1616  MissReport(Form("%s.%s", GetApparatus()->GetName(), GetName()));
1617  return 0;
1618 }
1619 
1620 //_____________________________________________________________________________
1622 {
1629  delete [] fNChamHits; fNChamHits = new Int_t [fNChambers];
1630  delete [] fPlaneEvents; fPlaneEvents = new Int_t [fNPlanes];
1631 
1632  fTotEvents = 0;
1633  for(UInt_t i=0;i<fNChambers;i++) {
1634  fNChamHits[i] = 0;
1635  }
1636  for(Int_t i=0;i<fNPlanes;i++) {
1637  fPlaneEvents[i] = 0;
1638  }
1639  gHcParms->Define(Form("%sdc_tot_events",fPrefix),"Total DC Events",fTotEvents);
1640  gHcParms->Define(Form("%sdc_cham_hits[%d]",fPrefix,fNChambers),"N events with hits per chamber",*fNChamHits);
1641  gHcParms->Define(Form("%sdc_events[%d]",fPrefix,fNPlanes),"N events with hits per plane",*fPlaneEvents);
1642 }
1643 
1644 //_____________________________________________________________________________
1646 {
1651  fTotEvents++;
1652  for(UInt_t i=0;i<fNChambers;i++) {
1653  if(fChambers[i]->GetNHits()>0) fNChamHits[i]++;
1654  }
1655  for(Int_t i=0;i<fNPlanes;i++) {
1656  if(fPlanes[i]->GetNHits() > 0) fPlaneEvents[i]++;
1657  }
1658  return;
1659 }
1660 
1661 ClassImp(THcDC)
Drift chamber wire hit info.
Definition: THcDCHit.h:16
void SetResidual(Int_t ip, Double_t coord)
Definition: THcDCTrack.h:51
Int_t fNthits
Definition: THcDC.h:121
Int_t GetTimeRaw(UInt_t iHit=0) const
Gets raw TDC time. In channels.
std::string GetName(const std::string &scope_name)
Double_t * fCentralTime
Definition: THcDC.h:158
virtual Int_t FillMap(THaDetMap *detmap, const char *detectorname)
Int_t fNChamber_spnum
Definition: THcSpacePoint.h:80
Int_t fNsp_best
Definition: THcDC.h:124
Int_t fUseNewTrackFit
Definition: THcDC.h:142
char fPrefix[2]
Definition: THcDC.h:104
Double_t fNSperChan
Definition: THcDC.h:133
Bool_t * fPresentP
Definition: THcDC.h:194
Double_t * fPlaneTimeZero
Definition: THcDC.h:175
Double_t fXtTrCriterion
Definition: THcDC.h:137
Int_t fdebugtrackprint
Definition: THcDC.h:93
void SetSp2_ID(Int_t isp2)
Definition: THcDCTrack.h:58
Double_t * fSpace_Point_Criterion
Definition: THcDC.h:151
Double_t * GetStubP()
Definition: THcSpacePoint.h:68
Double_t GetY()
Definition: THcSpacePoint.h:44
Int_t GetLast() const
Double_t * fSigma
Definition: THcDC.h:176
std::vector< THcDriftChamber * > fChambers
Definition: THcDC.h:203
Double_t DpsiFun(Double_t ray[4], Int_t plane)
Definition: THcDC.cxx:1572
Double_t fXp_fp_best
Definition: THcDC.h:181
Int_t fdebugprintrawdc
Definition: THcDC.h:90
void MissReport(const char *name)
Definition: THcHitList.cxx:557
void SetSp1_ID(Int_t isp1)
Definition: THcDCTrack.h:57
Int_t * fTdcWinMin
Definition: THcDC.h:156
Class for a a single Hall C horizontal drift chamber plane.
Int_t fNhits
Definition: THcDC.h:120
virtual void CalculateTargetQuantities(THaTrack *track, Double_t &gbeam_y, Double_t &xptar, Double_t &ytar, Double_t &yptar, Double_t &delta)
Transport focal plane track to target.
Double_t * fResidualsExclPlane
Definition: THcDC.h:129
THcRawTdcHit & GetRawTdcHit()
Double_t fYptTrCriterion
Definition: THcDC.h:140
Int_t fTDC_RefTimeCut
Definition: THcDC.h:96
Double_t fChisq_best
Definition: THcDC.h:183
Int_t fHMSStyleChambers
Definition: THcDC.h:95
void Setup(const char *name, const char *description)
Definition: THcDC.cxx:93
UInt_t GetEvNum() const
Int_t fNPlanes
Definition: THcDC.h:105
Bool_t GetSetStubFlag()
Definition: THcSpacePoint.h:45
int Int_t
Int_t fSingleStub
Definition: THcDC.h:135
UInt_t fNChambers
Definition: THcDC.h:107
bool Bool_t
virtual void RemoveHit(Int_t RemoveHitIndex)
Definition: THcDCTrack.cxx:32
Int_t GetWireNum() const
Definition: THcDCHit.h:36
THcSpacePoint * GetSpacePoint(Int_t i) const
Definition: THcDCTrack.h:31
STL namespace.
void DeleteArrays()
Definition: THcDC.cxx:469
Double_t GetChisq() const
Definition: THcDCTrack.h:48
UInt_t GetNHits() const
Gets the number of set hits.
TClonesArray * fRawHitList
Definition: THcHitList.h:51
Double_t fXptTrCriterion
Definition: THcDC.h:139
Int_t * fDriftTimeSign
Definition: THcDC.h:162
Int_t * fMaxHits
Definition: THcDC.h:149
Int_t fCounter
Definition: THcRawHit.h:55
Double_t * fWire_hit_did
Definition: THcDC.h:130
Float_t delta
Short_t Abs(Short_t d)
Double_t * fZPos
Definition: THcDC.h:169
Analyze a package of horizontal drift chambers.
Definition: THcDC.h:23
virtual EStatus Init(const TDatime &run_time)
Definition: THcDC.cxx:196
virtual Int_t DefineVariables(EMode mode=kDefine)
Definition: THcDC.cxx:399
Int_t fNTracksMaxFP
Definition: THcDC.h:136
Double_t * fLR_best
Definition: THcDC.h:126
virtual void AddSpacePoint(THcSpacePoint *sp)
Definition: THcDCTrack.cxx:40
Double_t GetSp1_ID() const
Definition: THcDCTrack.h:46
Int_t * fNChamber
Definition: THcDC.h:160
Int_t * fMinHits
Definition: THcDC.h:148
void GetRay(Double_t *ray) const
Definition: THcDCTrack.h:41
Double_t fY_fp_best
Definition: THcDC.h:180
Double_t * fCentralWire
Definition: THcDC.h:174
Int_t GetNFree() const
Definition: THcDCTrack.h:36
Int_t GetNHits() const
Definition: THcDCTrack.h:35
Int_t fVersion
Definition: THcDC.h:143
Int_t fFixLR
Definition: THcDC.h:108
void PrintSpacePoints()
Definition: THcDC.cxx:746
THcDC()
Definition: THcDC.cxx:189
virtual Int_t CoarseTrack(TClonesArray &tracks)
Definition: THcDC.cxx:609
double pow(double, double)
Double_t GetHitDist(Int_t ihit)
Definition: THcDCTrack.h:33
Double_t GetX() const
Definition: THcDCTrack.h:42
void PrintTrack()
Definition: THcDC.cxx:1536
Int_t * fTdcWinMax
Definition: THcDC.h:157
tuple app
Double_t * fGammaAngle
Definition: THcDC.h:172
Double_t GetCoord(Int_t ip) const
Definition: THcDCTrack.h:37
Int_t GetHitLR(Int_t ihit)
Definition: THcDCTrack.h:34
Int_t fdebugprintdecodeddc
Definition: THcDC.h:94
Double_t GetCoord() const
Definition: THcDCHit.h:42
Int_t GetPlaneNum() const
Definition: THcDCHit.h:58
UInt_t fNDCTracks
Definition: THcDC.h:99
void EfficiencyPerWire(Int_t golden_track_index)
Definition: THcDC.cxx:727
Double_t * fWire_hit_should
Definition: THcDC.h:131
Double_t fYp_fp_best
Definition: THcDC.h:182
void Error(const char *location, const char *msgfmt,...)
TMatrixT< Double_t > & Invert(Double_t *det=0)
Int_t fStubTest
Definition: THcDC.h:119
Double_t * fYCenter
Definition: THcDC.h:147
Double_t * fYPos
Definition: THcDC.h:168
Int_t fUseNewLinkStubs
Definition: THcDC.h:141
Double_t fYtTrCriterion
Definition: THcDC.h:138
Double_t GetXP() const
Definition: THcDCTrack.h:44
Class representing a single hit DC.
Definition: THcSpacePoint.h:13
void SetHMSStyleFlag(Int_t flag)
void SetChisq(Double_t chi2)
Definition: THcDCTrack.h:56
void InitHitList(THaDetMap *detmap, const char *hitclass, Int_t maxhits, Int_t tdcref_cut=0, Int_t adcref_cut=0)
Save the electronics module to detector mapping and initialize a hit array of hits of class hitclass...
Definition: THcHitList.cxx:65
char ** fPlaneNames
Definition: THcDC.h:106
Double_t * fXCenter
Definition: THcDC.h:146
Int_t GetCombos()
Definition: THcSpacePoint.h:71
Int_t fTotEvents
Definition: THcDC.h:188
void SetFocalPlaneBestTrack(Int_t golden_track_index)
Definition: THcDC.cxx:702
void SetVector(Double_t x, Double_t y, Double_t z, Double_t xp, Double_t yp)
Definition: THcDCTrack.h:54
Int_t * fReadoutLR
Definition: THcDC.h:164
#define NUM_FPRAY
Definition: THcDC.h:18
virtual void Delete(Option_t *option="")
Double_t * fBetaAngle
Definition: THcDC.h:171
void SetDoubleResidual(Int_t ip, Double_t coord)
Definition: THcDCTrack.h:53
Int_t * fNWires
Definition: THcDC.h:159
Int_t GetNChamber(Int_t plane) const
Definition: THcDC.h:45
Int_t * fReadoutTB
Definition: THcDC.h:163
Int_t * fPlaneEvents
Definition: THcDC.h:190
unsigned int UInt_t
char * Form(const char *fmt,...)
void CreateMissReportParms(const char *prefix)
Definition: THcHitList.cxx:544
Bool_t InsideDipoleExitWindow(Double_t x_fp, Double_t xp_fp, Double_t y_fp, Double_t yp_fp)
Int_t fProjectToChamber
Definition: THcDC.h:114
Int_t GetNHits()
Definition: THcSpacePoint.h:41
THcDCHit * GetHit(Int_t ihit)
Definition: THcSpacePoint.h:46
virtual Int_t End(THaRunBase *run=0)
Definition: THcDC.cxx:1613
Bool_t fInSideDipoleExit_best
Definition: THcDC.h:186
Int_t fdebugflagstubs
Definition: THcDC.h:92
tuple list
Definition: SConscript.py:9
Class representing for drift chamber wire (or other device with a single multihit TDC channel per det...
Definition: THcRawDCHit.h:8
const Bool_t kFALSE
virtual Int_t ReadDatabase(const TDatime &date)
Definition: THcDC.cxx:270
Double_t GetY() const
Definition: THcDCTrack.h:43
void LinkStubs()
Definition: THcDC.cxx:861
R__EXTERN class THcDetectorMap * gHcDetectorMap
Definition: THcGlobals.h:12
Double_t GetX()
Definition: THcSpacePoint.h:43
virtual Int_t ApplyCorrections(void)
Definition: THcDC.cxx:603
Double_t GetPos() const
Definition: THcDCHit.h:41
void ClearEvent()
Definition: THcDC.cxx:521
static const UInt_t MAXTRACKS
Definition: THcDC.h:200
Int_t fdebugflagpr
Definition: THcDC.h:91
Double_t GetResidualExclPlane(Int_t ip) const
Definition: THcDCTrack.h:40
Int_t * fWireOrder
Definition: THcDC.h:161
Int_t LoadParmValues(const DBRequest *list, const char *prefix="")
Retrieve parameter values from the parameter cache.
double Double_t
Int_t fUseNewFindSpacePoints
Definition: THcDC.h:88
Int_t * fNChamHits
Definition: THcDC.h:189
Double_t * fResiduals
Definition: THcDC.h:128
Int_t fSp1_ID_best
Definition: THcDC.h:184
Int_t fDebug
Definition: THcParmList.cxx:62
string::size_type pos
Int_t fFixPropagationCorrection
Definition: THcDC.h:110
Int_t * fMinCombos
Definition: THcDC.h:150
Int_t fPlane
Definition: THcRawHit.h:54
void SetCoord(Int_t ip, Double_t coord)
Definition: THcDCTrack.h:50
void PrintStubs()
Definition: THcDC.cxx:765
virtual ~THcDC()
Definition: THcDC.cxx:449
THcDCHit * GetHit(Int_t i) const
Definition: THcDCTrack.h:32
ClassImp(THcDCLookupTTDConv) THcDCLookupTTDConv
void EffInit()
Definition: THcDC.cxx:1621
UInt_t fNRawHits
Definition: THcHitList.h:45
Int_t fN_True_RawHits
Definition: THcDC.h:122
Double_t * fDist_best
Definition: THcDC.h:125
Double_t GetYP() const
Definition: THcDCTrack.h:45
Double_t GetWireSigma() const
Definition: THcDCHit.h:35
void NewTrackFit(UInt_t TrackIndex)
Definition: THcDC.cxx:1113
Double_t GetSp2_ID() const
Definition: THcDCTrack.h:47
virtual Int_t Decode(const THaEvData &)
Definition: THcDC.cxx:554
Int_t GetNSpacePoints() const
Definition: THcDCTrack.h:29
void FitLineToTrack(Int_t TrackHits, Double_t coords[], Int_t planes[], Double_t wiresigma[], Double_t TrackCoord[], Double_t save_ray[])
Definition: THcDC.cxx:1073
void NewLinkStubs()
Definition: THcDC.cxx:780
Double_t * fPos_best
Definition: THcDC.h:127
virtual Int_t FineTrack(TClonesArray &tracks)
Definition: THcDC.cxx:697
void SetHitLR(Int_t ihit, Int_t lrtemp)
Definition: THcDCTrack.h:59
TClonesArray * fDCTracks
Definition: THcDC.h:100
void TrackFit()
Definition: THcDC.cxx:1243
Double_t fX_fp_best
Definition: THcDC.h:179
Subdetector class for a single drift chamber with several planes.
Double_t GetResidual(Int_t ip) const
Definition: THcDCTrack.h:38
R__EXTERN class THcParmList * gHcParms
Definition: THcGlobals.h:11
Double_t ** fPlaneCoeffs
Definition: THcDC.h:177
Int_t fdebuglinkstubs
Definition: THcDC.h:89
TObject * At(Int_t idx) const
Double_t GetDist() const
Definition: THcDCHit.h:40
Double_t fTrackLargeResidCut
Definition: THcDC.h:97
Int_t GetLR()
Definition: THcDCHit.h:55
void Eff()
Definition: THcDC.cxx:1645
Double_t * fPitch
Definition: THcDC.h:173
static const Double_t kBig
Definition: THcFormula.cxx:31
void SetResidualExclPlane(Int_t ip, Double_t coord)
Definition: THcDCTrack.h:52
std::vector< THcDriftChamberPlane * > fPlanes
Definition: THcDC.h:202
const Bool_t kTRUE
void SetNFree(Int_t nfree)
Definition: THcDCTrack.h:49
virtual Int_t DecodeToHitList(const THaEvData &evdata, Bool_t suppress=kFALSE)
Populate the hitlist from the raw event data.
Definition: THcHitList.cxx:191
Double_t fWireVelocity
Definition: THcDC.h:134
Double_t * fAlphaAngle
Definition: THcDC.h:170
Int_t fNSp
Definition: THcDC.h:123
Int_t fSp2_ID_best
Definition: THcDC.h:185
Class representing a track found from linking DC Space points.
Definition: THcDCTrack.h:19
Double_t * fXPos
Definition: THcDC.h:167
A standard Hall C spectrometer apparatus.