FairRoot/PandaRoot
PndFtsHoughTrackerTask.h
Go to the documentation of this file.
1 
24 #ifndef PndFtsHoughTrackerTask_H
25 #define PndFtsHoughTrackerTask_H
26 
27 #include "PndPersistencyTask.h"
28 #include <cmath>
29 #include <vector>
30 #include "Rtypes.h" // for Double_t, Int_t, etc
31 #include <iostream>
32 
33 #include "TVector3.h"
34 #include "PndFtsHit.h"
35 #include "TClonesArray.h"
36 #include "PndFtsTube.h"
37 
39 class PndFtsHoughSpace;
40 class PndGeoFtsPar;
41 class FairField;
42 
43 // For error reporting
44 #include "TString.h"
45 #include <stdexcept>
46 // for debugging
47 #include "FairMCPoint.h"
48 
50 {
51 public:
53 
54 
60  PndFtsHoughTrackerTask(Int_t verbose=0, Bool_t persistence=kTRUE);
63 
65  virtual void SetParContainers();
67  virtual InitStatus Init();
69  virtual InitStatus ReInit();
70 
71 
75  virtual void Exec(Option_t* opt);
77  virtual void FinishEvent();
78 
80  virtual void Finish();
81 
82  //----------
83  // SETTERS
84  //----------
85  void SetVerbose(Int_t verbose){ fVerbose = verbose;};
87  void SetSaveDebugInfo(Int_t saveDebugInfo){ fSaveDebugInfo = saveDebugInfo;};
88  // void SetTrackOutput(TString name = "FTSTrkHough") { fTracksArrayName = name; };
89 
90  //----------
91  // GETTERS
92  //----------
93  Int_t GetVerbose() const { return fVerbose; };
94  Int_t GetSaveDebugInfo() const { return fSaveDebugInfo; };
95  UInt_t GetEventNr() const { return fEventNr; };
96 
97 
98 
99  //-----------
100  //DATA ACCESS TO FTS
101  //-----------
105  Int_t GetNFtsHits() const { return fFtsHitArray->GetEntriesFast(); };
110  const PndFtsHit* GetFtsHit(UInt_t hitId) const {
111  if ( hitId >= (UInt_t)GetNFtsHits() ) throwError("GetFtsHit: hitId is too large.");
112  // TClonesArray *ftsHitArray= (TClonesArray *)FairRootManager::Instance()->GetObject("FTSHit");
113  const PndFtsHit *myHit = (PndFtsHit*) fFtsHitArray->At(hitId);
114  if (0 == myHit) throwError("GetFtsHit was not able to get the hit.");
115  return myHit;
116  };
117  Int_t getMcTruthIdForHitId(UInt_t hitId) const {
118  const PndFtsHit *const ftsHit = GetFtsHit(hitId);
119  Int_t mcPointId=ftsHit->GetRefIndex();
120  if(0 > mcPointId) throwError("getMcTruthIdForHitId: negative mcPointId.");
121  FairMCPoint* myPoint = (FairMCPoint*)(fFtsMcPoints->At(mcPointId));
122  if(0==myPoint) throwError("getMcTruthIdForHitId: Could not get point belonging to hit.");
123  Int_t mcTrackId = myPoint->GetTrackID();
124  if(mcTrackId<0) throwError("getMcTruthIdForHitId: negative mcTrackId.");
125  return mcTrackId;
126  }
131  const PndFtsTube* GetFtsTube(const PndFtsHit *const myHit) const {
132  Int_t tubeID = myHit->GetTubeID();
133  const PndFtsTube *tube = (PndFtsTube*) fFtsTubeArray->At(tubeID);
134  return tube;
135  }
140  const TVector3 GetFtsHitPosErrors(const PndFtsHit *const ftsHit) const;
145  const TMatrixT<Double_t> GetFtsHitCovMatrix(const PndFtsHit *const ftsHit) const;
152  Int_t getFtsBranchId() const { return fFtsBranchId; };
159  TClonesArray* getFtsHitArrayPtr() const { return fFtsHitArray; };
160 
161 
162 
163  //-----------
164  //DATA ACCESS TO B FIELD
165  //-----------
166  FairField* getMagneticFieldPtr() const { return fField; };
167 
168 
169  FairLogger* fLogger;
170 
171 
172 protected:
173  // for writing out histograms for debugging
174  // void InitOutFileForDebugging();
175  // void AddNewEventToOutFileForDebugging(UInt_t eventNr);
176  // TFile* fOutFile;
177 
178  //--------
179  // General
180  //--------
181 
182  //--------
183  // Input
184  //--------
185  Int_t fFtsBranchId;
186  TClonesArray *fFtsHitArray;
187  TClonesArray* fFtsMcPoints;
188 
189 
199  TClonesArray *fFtsTubeArray;
200 
202  FairField* fField;
203 
204 
205  //--------
206  // Output
207  //--------
209  TClonesArray *fTrackCands;
210  TClonesArray *fTracks;
211  // TClonesArray *fHoughTrackCands; ///< @brief Array of found track cands in PndFtsHoughTrackCand (only for debugging)
212  /* @brief Not used.
213  *
214  * The idea was to use this in order to write out the Hough spaces to the root file.
215  * Due to bad performance this is not used. Instead, I write it out as pictures directly.
216  */
217  //TClonesArray *fHoughSpaces;
218 
219  //-------
220  // Debug
221  //-------
223  UInt_t fEventNr;
224 
225  void throwError(const TString s) const{ throw std::runtime_error(s.Data()); };
226 
228  {
229  for (int iHit1 = 0; iHit1 < GetNFtsHits(); ++iHit1)
230  {
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  {
237  const PndFtsHit *const myHit2 = GetFtsHit(iHit2);
238 
239  const Int_t tubeIdHit2 = myHit2->GetTubeID();
240 
241  if ( tubeIdHit1 == tubeIdHit2 ) 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 
248  // TODO: I don't think I need the copy constructor and the operator=
251 
253 };
254 
255 #endif
virtual InitStatus ReInit()
ReInitiliazation of task when the runID changes.
int fVerbose
Definition: poormantracks.C:24
UInt_t fEventNr
Event number for debugging purposes.
virtual void Finish()
Writes output to root file, I guess. Called at the end of the run.
Int_t getMcTruthIdForHitId(UInt_t hitId) const
FairField * fField
For B field access.
Interface between PandaRoot (data input and output) and PndFtsHoughTrackFinder (implementation of PR ...
Double_t val[nBoxes][nFEBox]
Definition: createCalib.C:11
#define verbose
TLorentzVector s
Definition: Pnd2DStar.C:50
ClassDef(PndFtsHoughTrackerTask, 1)
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 SetPersistency(Bool_t val=kTRUE)
TClonesArray * fFtsHitArray
Input array of PndFtsHit.
TClonesArray * fTracks
Array of found tracks in PndTrack (for output)
TClonesArray * getFtsHitArrayPtr() const
Returns pointer to the hit array in which FTS hits are saved as PndFtsHit. Try not to use it...
FairField * getMagneticFieldPtr() const
void SetSaveDebugInfo(Int_t saveDebugInfo)
Int_t GetTubeID() const
Definition: PndFtsHit.h:70
void throwError(const TString s) const
For error reporting.
Int_t GetNFtsHits() const
Returns the event number.
virtual void FinishEvent()
When is this executed? After each event?
Int_t fFtsBranchId
Detector Id of FTS.
TClonesArray * fFtsMcPoints
Input array of McPoints.
Int_t GetSaveDebugInfo() const
Returns the verbosity level.
TString fTracksArrayName
Branch name where to store the Track candidates.
PndFtsHoughTrackerTask(Int_t verbose=0, Bool_t persistence=kTRUE)
Constructor with flags. Can also be used as standard constructor.
virtual void SetParContainers()
Loads the parameter container from the runtime database.
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.
void SetVerbose(Int_t verbose)
PndGeoFtsPar * fFtsParameters
Needed for FTS map creator.
virtual InitStatus Init()
Initialization of task at the beginning of a run.
const PndFtsHit * GetFtsHit(UInt_t hitId) const
Returns pointer to the hit with index hitId in the FTS hit array.
const PndFtsTube * GetFtsTube(const PndFtsHit *const myHit) const
Returns pointer to the FTS tube corresponding to input FTS hit.
Class for saving a FTS track cand. for Hough transform based FTS PR.
PndFtsHoughTrackerTask operator=(const PndFtsHoughTrackerTask &)
virtual void Exec(Option_t *opt)
Executed for each event.
Int_t fSaveDebugInfo
Debug information will be created if &gt;0.
UInt_t GetEventNr() const
Returns the save debug flag.
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 ...
TClonesArray * fFtsTubeArray
Input array of PndFtsTube (map of FTS tubes).
Int_t getFtsBranchId() const
Returns detector Id of FTS. Try not to use it.
TClonesArray * fTrackCands
Array of found track candidates in PndTrackCand (for output)