FairRoot/PandaRoot
PndLmdIdealFitTask.cxx
Go to the documentation of this file.
1 //-----------------------------------------------------------
2 //
3 // Description:
4 // 3D Straight Line fitter
5 //
6 // Author List:
7 // Mathias Michel
8 //
9 //-----------------------------------------------------------
10 
11 // This Class' Header ------------------
12 #include "PndLmdIdealFitTask.h"
13 
14 // C/C++ Headers ----------------------
15 #include <iostream>
16 
17 // Collaborating Class Headers --------
18 #include "FairRootManager.h"
19 #include "PndLinTrack.h"
20 #include "PndSdsClusterStrip.h"
21 #include "PndSdsDigiStrip.h"
22 #include "PndSdsHit.h"
23 #include "PndSdsMCPoint.h"
24 #include "TClonesArray.h"
25 #include "TrackData/PndTrackCand.h"
27 
28 #include "TFile.h"
29 #include "TGeoManager.h"
30 #include "TGeoTrack.h"
31 #include "TLorentzVector.h"
32 
33 // Fit Classes -----------
34 #include <TMath.h>
35 #include <TRandom2.h>
36 #include <TVector3.h>
37 //#include <TStyle.h>
38 //#include <TCanvas.h>
39 #include <Math/Vector3D.h>
40 #include <TF2.h>
41 #include <TH1.h>
42 #include <TMatrixTSym.h>
43 #include <TPolyLine3D.h>
44 #include <TVirtualFitter.h>
45 
46 using namespace ROOT::Math;
47 using namespace std;
48 
50 
51 PndLmdIdealFitTask::PndLmdIdealFitTask() : FairTask("3D-Ideal-Straight-Line") {
52  fTCandBranchName = "LMDTrackCand";
53  fRecoBranchName = "LMDHitsStrip";
54  fMCPointBranchName = "LMDPoint";
55  fDigiBranchName = "LMDStripDigis";
56  fClustBranchName = "LMDStripClusterCand";
57 }
58 
60 
62  // Get ROOT Manager
63  FairRootManager* ioman = FairRootManager::Instance();
64 
65  if (ioman == 0) {
66  Error("PndLmdLinFitTask::Init", "RootManager not instantiated!");
67  return kERROR;
68  }
69 
70  // Get input collection
71  fTCandArray = (TClonesArray*)ioman->GetObject(fTCandBranchName);
72 
73  if (fTCandArray == 0) {
74  Error("PndLmdLinFitTask::Init", "trackcand-array not found!");
75  return kERROR;
76  }
77 
78  fRecoArray = (TClonesArray*)ioman->GetObject(fRecoBranchName);
79 
80  if (fRecoArray == 0) {
81  Error("PndLmdLinFitTask::Init", "reco-array not found!");
82  return kERROR;
83  }
84 
85  fMCPointArray = (TClonesArray*)ioman->GetObject(fMCPointBranchName);
86 
87  if (fMCPointArray == 0) {
88  Error("PndLmdLinFitTask::Init", "MCPoint-array not found!");
89  return kERROR;
90  }
91 
92  fDigiArray = (TClonesArray*)ioman->GetObject(fDigiBranchName);
93 
94  if (fDigiArray == 0) {
95  Error("PndLmdLinFitTask::Init", "digi-array not found!");
96  return kERROR;
97  }
98 
99  fClustArray = (TClonesArray*)ioman->GetObject(fClustBranchName);
100 
101  if (fClustArray == 0) {
102  Error("PndLmdLinFitTask::Init", "clust-array not found!");
103  return kERROR;
104  }
105 
106  fTrackArray = new TClonesArray("PndLinTrack");
107  ioman->Register("LMDTrack", "PndLmd", fTrackArray, kTRUE);
108 
109  std::cout << "-I- PndLmdLinFitTask: Initialisation successfull" << std::endl;
110 
111  return kSUCCESS;
112 }
113 
114 void PndLmdIdealFitTask::Exec(Option_t*) {
115  std::cout << "PndLmdLinFitTask::Exec" << std::endl;
116  // Reset output Array
117  if (fTrackArray == 0) Fatal("PndLmdLinFitTask::Exec", "No TrackArray");
118  fTrackArray->Delete();
119 
120  Int_t ntcand = fTCandArray->GetEntriesFast();
121 
122  // Detailed output
123  if (fVerbose > 1)
124  std::cout << " -I- PndLmdLinFitTask: contains " << ntcand
125  << " RhoCandidates" << std::endl;
126  if (fVerbose > 2) {
127  std::cout << " Detailed Debug info on the candidates:" << std::endl;
128  unsigned int index = 12345; // detid=12345, //[R.K.03/2017] unused
129  // variable
130  for (Int_t itr = 0; itr < ntcand; ++itr) {
131  PndTrackCand* trcnd = (PndTrackCand*)fTCandArray->At(itr);
132  std::cout << "TrackCand no. " << itr << " has " << trcnd->GetNHits()
133  << " hits." << std::endl;
134  std::cout << "Point: \t Index: " << std::endl;
135  for (unsigned int ihit = 0; ihit < trcnd->GetNHits();
136  ihit++) { // fill Graph
137  PndTrackCandHit theHit = trcnd->GetSortedHit(ihit); // get hit
138  index = theHit.GetHitId();
139  // detid = theHit.GetDetId(); //[R.K.03/2017] unused variable
140  std::cout << ihit << "\t" << index << std::endl;
141  }
142  }
143  }
144 
145  // Cut evil event
146  // if(ntcand>20){
147  // std::cout<<"ntcand="<<ntcand<<" Evil Event! skipping"<<std::endl;
148  // return;
149  //}
150 
151  // Find MC-Track
152  // ------------------------------------------------------------------------------
153  if (fVerbose > 1)
154  std::cout << " -I- PndLmdIdealFitTask: start Fitting " << std::endl;
155 
156  for (Int_t track = 0; track < ntcand; track++) {
157  PndTrackCand* trcnd = (PndTrackCand*)fTCandArray->At(track);
158  const int numPts = trcnd->GetNHits(); // read how many points in this track
159  int fhit = ((PndTrackCandHit)trcnd->GetSortedHit(0)).GetHitId();
160  int lhit = ((PndTrackCandHit)trcnd->GetSortedHit(numPts - 1)).GetHitId();
161 
162  if (fVerbose > 2)
163  std::cout << "Track: " << track << " Points: " << numPts << std::endl;
164 
165  PndTrackCandHit none = trcnd->GetSortedHit(0);
166  PndSdsHit* firstHit = (PndSdsHit*)fRecoArray->At(none.GetHitId());
167  PndSdsClusterStrip* clust =
169  PndSdsDigiStrip* astripdigi =
170  (PndSdsDigiStrip*)fDigiArray->At(clust->GetDigiIndex(0));
171  PndSdsMCPoint* firstPoint =
172  (PndSdsMCPoint*)fMCPointArray->At(astripdigi->GetIndex());
173 
174  TVector3 trueTrack;
175  firstPoint->Momentum(trueTrack);
176  TVector3 truePos = firstPoint->GetPosition();
177 
178  // PndLinTrack* trackfit = new PndLinTrack("Lumi", truePos.Z(), truePos.X(),
179  // trueTrack.X()/trueTrack.Z(), truePos.Y(), trueTrack.Y()/trueTrack.Z(),
180  // 0, 0, 0, 0,
181  // 0, fhit, lhit, track);
182  PndLinTrack* trackfit =
183  new PndLinTrack("Lumi", truePos.X(), trueTrack.X() / trueTrack.Z(),
184  truePos.Y(), trueTrack.Y() / trueTrack.Z(), truePos.Z(),
185  trueTrack.Z(), 0, fhit, lhit, track);
186 
187  new ((*fTrackArray)[track]) PndLinTrack(*(trackfit)); // save Track
188 
189  } // end of TCand's
190 
191  // Done--------------------------------------------------------------------------------------
192 
193  std::cout << "Fitting done" << std::endl;
194 
195  return;
196 }
197 
TClonesArray * fTCandArray
int fVerbose
Definition: poormantracks.C:24
Int_t GetIndex(int i=0) const
Definition: PndSdsDigi.h:63
PndTrackCandHit GetSortedHit(UInt_t i)
Definition: PndTrackCand.h:54
Class for digitised strip hits.
virtual void Exec(Option_t *opt)
TClonesArray * fTrackArray
TClonesArray * fRecoArray
Int_t GetDigiIndex(Int_t i) const
Definition: PndSdsCluster.h:40
Double_t
PndMCTrack * track
Definition: anaLmdCluster.C:89
TClonesArray * fMCPointArray
static Double_t fz0
TVector3 GetPosition() const
Definition: PndSdsMCPoint.h:90
TClonesArray * fClustArray
TClonesArray * fDigiArray
UInt_t GetNHits() const
Definition: PndTrackCand.h:59
ClassImp(PndAnaContFact)
Int_t GetClusterIndex() const
Definition: PndSdsHit.h:94
Int_t GetHitId() const
virtual InitStatus Init()