PandaRoot
PndFtsHoughTrackerTask.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
32 #ifndef PndFtsHoughTrackerTask_H
33 #define PndFtsHoughTrackerTask_H
34 
35 #include "PndPersistencyTask.h"
36 #include <cmath>
37 #include <vector>
38 #include "Rtypes.h" // for Double_t, Int_t, etc
39 #include <iostream>
40 
41 #include "TVector3.h"
42 #include "PndFtsHit.h"
43 #include "TClonesArray.h"
44 #include "PndFtsTube.h"
45 
47 class PndFtsHoughSpace;
48 class PndGeoFtsPar;
49 class FairField;
50 
51 // For error reporting
52 #include "TString.h"
53 #include <stdexcept>
54 // for debugging
55 #include "FairMCPoint.h"
56 
58  public:
67  };
68 
74  PndFtsHoughTrackerTask(Int_t verbose = 0, Bool_t persistence = kTRUE);
77 
79  virtual void SetParContainers();
81  virtual InitStatus Init();
83  virtual InitStatus ReInit();
84 
88  virtual void Exec(Option_t *opt);
90  virtual void FinishEvent();
91 
93  virtual void Finish();
94 
95  //----------
96  // SETTERS
97  //----------
98  void SetVerbose(Int_t verbose) { fVerbose = verbose; };
99  void SetPersistence(Bool_t val) { SetPersistency(val); };
100  void SetSaveDebugInfo(Int_t saveDebugInfo) { fSaveDebugInfo = saveDebugInfo; };
101  // void SetTrackOutput(TString name = "FTSTrkHough") { fTracksArrayName = name; };
102 
103  //----------
104  // GETTERS
105  //----------
106  Int_t GetVerbose() const { return fVerbose; };
107  Int_t GetSaveDebugInfo() const { return fSaveDebugInfo; };
108  UInt_t GetEventNr() const { return fEventNr; };
109 
110  //-----------
111  // DATA ACCESS TO FTS
112  //-----------
116  Int_t GetNFtsHits() const { return fFtsHitArray->GetEntriesFast(); };
121  const PndFtsHit *GetFtsHit(UInt_t hitId) const
122  {
123  if (hitId >= (UInt_t)GetNFtsHits())
124  throwError("GetFtsHit: hitId is too large.");
125  // TClonesArray *ftsHitArray= (TClonesArray *)FairRootManager::Instance()->GetObject("FTSHit");
126  const PndFtsHit *myHit = (PndFtsHit *)fFtsHitArray->At(hitId);
127  if (0 == myHit)
128  throwError("GetFtsHit was not able to get the hit.");
129  return myHit;
130  };
131  Int_t getMcTruthIdForHitId(UInt_t hitId) const
132  {
133  const PndFtsHit *const ftsHit = GetFtsHit(hitId);
134  Int_t mcPointId = ftsHit->GetRefIndex();
135  if (0 > mcPointId)
136  throwError("getMcTruthIdForHitId: negative mcPointId.");
137  FairMCPoint *myPoint = (FairMCPoint *)(fFtsMcPoints->At(mcPointId));
138  if (0 == myPoint)
139  throwError("getMcTruthIdForHitId: Could not get point belonging to hit.");
140  Int_t mcTrackId = myPoint->GetTrackID();
141  if (mcTrackId < 0)
142  throwError("getMcTruthIdForHitId: negative mcTrackId.");
143  return mcTrackId;
144  }
149  const PndFtsTube *GetFtsTube(const PndFtsHit *const myHit) const
150  {
151  Int_t tubeID = myHit->GetTubeID();
152  const PndFtsTube *tube = (PndFtsTube *)fFtsTubeArray->At(tubeID);
153  return tube;
154  }
159  const TVector3 GetFtsHitPosErrors(const PndFtsHit *const ftsHit) const;
164  const TMatrixT<Double_t> GetFtsHitCovMatrix(const PndFtsHit *const ftsHit) const;
171  Int_t getFtsBranchId() const { return fFtsBranchId; };
178  TClonesArray *getFtsHitArrayPtr() const { return fFtsHitArray; };
179 
180  //-----------
181  // DATA ACCESS TO B FIELD
182  //-----------
183  FairField *getMagneticFieldPtr() const { return fField; };
184 
185  FairLogger *fLogger;
186 
187  protected:
188  // for writing out histograms for debugging
189  // void InitOutFileForDebugging();
190  // void AddNewEventToOutFileForDebugging(UInt_t eventNr);
191  // TFile* fOutFile;
192 
193  //--------
194  // General
195  //--------
196 
197  //--------
198  // Input
199  //--------
200  Int_t fFtsBranchId;
201  TClonesArray *fFtsHitArray;
202  TClonesArray *fFtsMcPoints;
203 
213  TClonesArray *fFtsTubeArray;
214 
216  FairField *fField;
217 
218  //--------
219  // Output
220  //--------
222  TClonesArray *fTrackCands;
223  TClonesArray *fTracks;
224  // TClonesArray *fHoughTrackCands; ///< @brief Array of found track cands in PndFtsHoughTrackCand (only for debugging)
225  /* @brief Not used.
226  *
227  * The idea was to use this in order to write out the Hough spaces to the root file.
228  * Due to bad performance this is not used. Instead, I write it out as pictures directly.
229  */
230  // TClonesArray *fHoughSpaces;
231 
232  //-------
233  // Debug
234  //-------
236  UInt_t fEventNr;
237 
238  void throwError(const TString s) const { throw std::runtime_error(s.Data()); };
239 
241  {
242  for (int iHit1 = 0; iHit1 < GetNFtsHits(); ++iHit1) {
243  const PndFtsHit *const myHit1 = GetFtsHit(iHit1);
244 
245  const Int_t tubeIdHit1 = myHit1->GetTubeID();
246 
247  for (int iHit2 = iHit1 + 1; iHit2 < GetNFtsHits(); ++iHit2) {
248  const PndFtsHit *const myHit2 = GetFtsHit(iHit2);
249 
250  const Int_t tubeIdHit2 = myHit2->GetTubeID();
251 
252  if (tubeIdHit1 == tubeIdHit2)
253  std::cout << "Event " << GetEventNr() << "tubeID1=" << tubeIdHit1 << " tubeID2=" << tubeIdHit2 << ": HitIdx " << iHit1 << " and HitIdx " << iHit2 << " are duplicate!\n";
254  }
255 
256  } // for loop over all hits
257  };
258 
259  // TODO: I don't think I need the copy constructor and the operator=
262 
264 };
265 
266 #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:81
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.