PandaRoot
PndFtsHoughTrackerTask.h
Go to the documentation of this file.
1 
20 #ifndef PndFtsHoughTrackerTask_H
21 #define PndFtsHoughTrackerTask_H
22 
23 #include "PndPersistencyTask.h"
24 #include <cmath>
25 #include <vector>
26 #include "Rtypes.h" // for Double_t, Int_t, etc
27 #include <iostream>
28 
29 #include "TVector3.h"
30 #include "PndFtsHit.h"
31 #include "TClonesArray.h"
32 #include "PndFtsTube.h"
33 
35 class PndFtsHoughSpace;
36 class PndGeoFtsPar;
37 class FairField;
38 
39 // For error reporting
40 #include "TString.h"
41 #include <stdexcept>
42 // for debugging
43 #include "FairMCPoint.h"
44 
46  public:
55  };
56 
62  PndFtsHoughTrackerTask(Int_t verbose = 0, Bool_t persistence = kTRUE);
65 
67  virtual void SetParContainers();
69  virtual InitStatus Init();
71  virtual InitStatus ReInit();
72 
76  virtual void Exec(Option_t *opt);
78  virtual void FinishEvent();
79 
81  virtual void Finish();
82 
83  //----------
84  // SETTERS
85  //----------
86  void SetVerbose(Int_t verbose) { fVerbose = verbose; };
87  void SetPersistence(Bool_t val) { SetPersistency(val); };
88  void SetSaveDebugInfo(Int_t saveDebugInfo) { fSaveDebugInfo = saveDebugInfo; };
89  // void SetTrackOutput(TString name = "FTSTrkHough") { fTracksArrayName = name; };
90 
91  //----------
92  // GETTERS
93  //----------
94  Int_t GetVerbose() const { return fVerbose; };
95  Int_t GetSaveDebugInfo() const { return fSaveDebugInfo; };
96  UInt_t GetEventNr() const { return fEventNr; };
97 
98  //-----------
99  // DATA ACCESS TO FTS
100  //-----------
104  Int_t GetNFtsHits() const { return fFtsHitArray->GetEntriesFast(); };
109  const PndFtsHit *GetFtsHit(UInt_t hitId) const
110  {
111  if (hitId >= (UInt_t)GetNFtsHits())
112  throwError("GetFtsHit: hitId is too large.");
113  // TClonesArray *ftsHitArray= (TClonesArray *)FairRootManager::Instance()->GetObject("FTSHit");
114  const PndFtsHit *myHit = (PndFtsHit *)fFtsHitArray->At(hitId);
115  if (0 == myHit)
116  throwError("GetFtsHit was not able to get the hit.");
117  return myHit;
118  };
119  Int_t getMcTruthIdForHitId(UInt_t hitId) const
120  {
121  const PndFtsHit *const ftsHit = GetFtsHit(hitId);
122  Int_t mcPointId = ftsHit->GetRefIndex();
123  if (0 > mcPointId)
124  throwError("getMcTruthIdForHitId: negative mcPointId.");
125  FairMCPoint *myPoint = (FairMCPoint *)(fFtsMcPoints->At(mcPointId));
126  if (0 == myPoint)
127  throwError("getMcTruthIdForHitId: Could not get point belonging to hit.");
128  Int_t mcTrackId = myPoint->GetTrackID();
129  if (mcTrackId < 0)
130  throwError("getMcTruthIdForHitId: negative mcTrackId.");
131  return mcTrackId;
132  }
137  const PndFtsTube *GetFtsTube(const PndFtsHit *const myHit) const
138  {
139  Int_t tubeID = myHit->GetTubeID();
140  const PndFtsTube *tube = (PndFtsTube *)fFtsTubeArray->At(tubeID);
141  return tube;
142  }
147  const TVector3 GetFtsHitPosErrors(const PndFtsHit *const ftsHit) const;
152  const TMatrixT<Double_t> GetFtsHitCovMatrix(const PndFtsHit *const ftsHit) const;
159  Int_t getFtsBranchId() const { return fFtsBranchId; };
166  TClonesArray *getFtsHitArrayPtr() const { return fFtsHitArray; };
167 
168  //-----------
169  // DATA ACCESS TO B FIELD
170  //-----------
171  FairField *getMagneticFieldPtr() const { return fField; };
172 
173  FairLogger *fLogger;
174 
175  protected:
176  // for writing out histograms for debugging
177  // void InitOutFileForDebugging();
178  // void AddNewEventToOutFileForDebugging(UInt_t eventNr);
179  // TFile* fOutFile;
180 
181  //--------
182  // General
183  //--------
184 
185  //--------
186  // Input
187  //--------
188  Int_t fFtsBranchId;
189  TClonesArray *fFtsHitArray;
190  TClonesArray *fFtsMcPoints;
191 
201  TClonesArray *fFtsTubeArray;
202 
204  FairField *fField;
205 
206  //--------
207  // Output
208  //--------
210  TClonesArray *fTrackCands;
211  TClonesArray *fTracks;
212  // TClonesArray *fHoughTrackCands; ///< @brief Array of found track cands in PndFtsHoughTrackCand (only for debugging)
213  /* @brief Not used.
214  *
215  * The idea was to use this in order to write out the Hough spaces to the root file.
216  * Due to bad performance this is not used. Instead, I write it out as pictures directly.
217  */
218  // TClonesArray *fHoughSpaces;
219 
220  //-------
221  // Debug
222  //-------
224  UInt_t fEventNr;
225 
226  void throwError(const TString s) const { throw std::runtime_error(s.Data()); };
227 
229  {
230  for (int iHit1 = 0; iHit1 < GetNFtsHits(); ++iHit1) {
231  const PndFtsHit *const myHit1 = GetFtsHit(iHit1);
232 
233  const Int_t tubeIdHit1 = myHit1->GetTubeID();
234 
235  for (int iHit2 = iHit1 + 1; iHit2 < GetNFtsHits(); ++iHit2) {
236  const PndFtsHit *const myHit2 = GetFtsHit(iHit2);
237 
238  const Int_t tubeIdHit2 = myHit2->GetTubeID();
239 
240  if (tubeIdHit1 == tubeIdHit2)
241  std::cout << "Event " << GetEventNr() << "tubeID1=" << tubeIdHit1 << " tubeID2=" << tubeIdHit2 << ": HitIdx " << iHit1 << " and HitIdx " << iHit2 << " are duplicate!\n";
242  }
243 
244  } // for loop over all hits
245  };
246 
247  // TODO: I don't think I need the copy constructor and the operator=
250 
252 };
253 
254 #endif
virtual void FinishEvent()
When is this executed? After each event?
const TVector3 GetFtsHitPosErrors(const PndFtsHit *const ftsHit) const
Returns the position error (based on FTS straw geometry) for the hit with index hitId in the FTS hit ...
virtual InitStatus ReInit()
ReInitiliazation of task when the runID changes.
Int_t GetTubeID() const
Definition: PndFtsHit.h:69
UInt_t fEventNr
Event number for debugging purposes.
const PndFtsTube * GetFtsTube(const PndFtsHit *const myHit) const
Returns pointer to the FTS tube corresponding to input FTS hit.
FairField * fField
For B field access.
virtual void Exec(Option_t *opt)
Executed for each event.
Interface between PandaRoot (data input and output) and PndFtsHoughTrackFinder (implementation of PR ...
Int_t GetSaveDebugInfo() const
Returns the verbosity level.
ClassDef(PndFtsHoughTrackerTask, 1)
const PndFtsHit * GetFtsHit(UInt_t hitId) const
Returns pointer to the hit with index hitId in the FTS hit array.
void SetPersistency(Bool_t val=kTRUE)
TClonesArray * fFtsHitArray
Input array of PndFtsHit.
TClonesArray * fTracks
Array of found tracks in PndTrack (for output)
void SetSaveDebugInfo(Int_t saveDebugInfo)
UInt_t GetEventNr() const
Returns the save debug flag.
Int_t getMcTruthIdForHitId(UInt_t hitId) const
Int_t fFtsBranchId
Detector Id of FTS.
TClonesArray * fFtsMcPoints
Input array of McPoints.
TString fTracksArrayName
Branch name where to store the Track candidates.
FairField * getMagneticFieldPtr() const
PndFtsHoughTrackerTask(Int_t verbose=0, Bool_t persistence=kTRUE)
Constructor with flags. Can also be used as standard constructor.
Class for Hough space based on TH2S (for the moment). Saves the hits which enter this Hough space and...
FairLogger * fLogger
Returns pointer to the B field.
const TMatrixT< Double_t > GetFtsHitCovMatrix(const PndFtsHit *const ftsHit) const
Returns the position covariance matrix (based on FTS straw geometry) for the hit with index hitId in ...
void SetVerbose(Int_t verbose)
virtual void Finish()
Writes output to root file, I guess. Called at the end of the run.
PndGeoFtsPar * fFtsParameters
Needed for FTS map creator.
~PndFtsHoughTrackerTask()
Destructor.
Int_t getFtsBranchId() const
Returns detector Id of FTS. Try not to use it.
void throwError(const TString s) const
For error reporting.
TClonesArray * getFtsHitArrayPtr() const
Returns pointer to the hit array in which FTS hits are saved as PndFtsHit. Try not to use it...
Class for saving a FTS track cand. for Hough transform based FTS PR.
virtual InitStatus Init()
Initialization of task at the beginning of a run.
Int_t GetNFtsHits() const
Returns the event number.
PndFtsHoughTrackerTask operator=(const PndFtsHoughTrackerTask &)
Int_t fSaveDebugInfo
Debug information will be created if >0.
TClonesArray * fFtsTubeArray
Input array of PndFtsTube (map of FTS tubes).
TClonesArray * fTrackCands
Array of found track candidates in PndTrackCand (for output)
virtual void SetParContainers()
Loads the parameter container from the runtime database.