PandaRoot
PndGeoHandling.h
Go to the documentation of this file.
1 
27 #ifndef PNDGEOHANDLING_H
28 #define PNDGEOHANDLING_H
29 
30 #include "PndSensorNamePar.h"
31 #include "PndSensorNameIdMap.h"
32 
33 #include "FairRun.h"
34 #include "FairRuntimeDb.h"
35 #include "FairTask.h"
36 
37 #include "TGeoManager.h"
38 #include "TGeoMatrix.h"
39 #include "TString.h"
40 #include "TVector3.h"
41 #include "TMatrixD.h"
42 
43 #include <string>
44 #include <iostream>
45 #include <vector>
46 
47 class PndGeoHandling : public FairTask {
48  public:
51  PndGeoHandling();
52  static PndGeoHandling *Instance();
53 
54  static void Destroy()
55  {
56  if (fInstance) {
57  delete fInstance;
58  fInstance = nullptr;
59  }
60  }
61 
62  // PndGeoHandling(TGeoManager* aGeoMan);
63  PndGeoHandling(TString mcFile, TString parFile);
64  PndGeoHandling(Int_t runID, TString parFile);
65  PndGeoHandling(PndSensorNamePar *SensorNamePar);
66 
67  virtual ~PndGeoHandling(){};
68 
69  virtual void SetParContainers();
70 
71  // static PndGeoHandling* Instance();
72 
73  // TString GetCurrentID(); ///< returns the ID of the current node
74  // TString GetID(TString path); ///< for a given TGeoManager-path the ID is returned
75  // TString GetPath(TString id); ///< for a given ID the path is returned
76 
77  TString GetPath(Int_t shortID);
78  Int_t GetShortID(TString path);
79 
80  TString GetVolumeID(TString name);
81  std::vector<TString> GetNamesLevel(Int_t level, TString startPath = ""); //, bool fullPath = false); //[R.K.03/2017] unused variable
82  void GetOUVPath(TString path, TVector3 &o, TVector3 &u, TVector3 &v);
83  // void GetOUVId(TString id, TVector3& o, TVector3& u, TVector3& v); ///< for a volume given by its ID the o, u, v vectors for the plane are returned
84  void GetOUVShortId(Int_t shortId, TVector3 &o, TVector3 &u, TVector3 &v)
85  {
86  if (fSensorNamePar != 0)
87  GetOUVPath(GetPath(shortId), o, u, v);
88  }
89 
90  TGeoHMatrix *GetMatrixPath(TString path);
91  // TGeoHMatrix* GetMatrixId(TString id);
92  TGeoHMatrix *GetMatrixShortId(Int_t shortId) { return GetMatrixPath(GetPath(shortId)); }
93 
94  // TVector3 GetSensorDimensionsId(TString id);
95  TVector3 GetSensorDimensionsPath(TString path);
96  TVector3 GetSensorDimensionsShortId(Int_t shortId) { return GetSensorDimensionsPath(GetPath(shortId)); }
97 
98  // TVector3 MasterToLocalId(const TVector3& master, const TString& id);
99  TVector3 MasterToLocalPath(const TVector3 &master, const TString &id);
100  TVector3 MasterToLocalShortId(const TVector3 &master, const Int_t &shortId) { return MasterToLocalPath(master, GetPath(shortId)); }
101 
102  // TVector3 LocalToMasterId(const TVector3& local, const TString& id);
103  TVector3 LocalToMasterPath(const TVector3 &local, const TString &id);
104  TVector3 LocalToMasterShortId(const TVector3 &local, const Int_t &shortId) { return LocalToMasterPath(local, GetPath(shortId)); }
105 
106  // TODO: Recheck the error calculation for 3-vectors
107  // TMatrixD MasterToLocalErrorsId(const TMatrixD& master, const TString& id);
108  TMatrixD MasterToLocalErrorsPath(const TMatrixD &master, const TString &id);
109  TMatrixD MasterToLocalErrorsShortId(const TMatrixD &master, const Int_t &shortId) { return MasterToLocalErrorsPath(master, GetPath(shortId)); }
110 
111  // TMatrixD LocalToMasterErrorsId(const TMatrixD& local, const TString& id);
112  TMatrixD LocalToMasterErrorsPath(const TMatrixD &local, const TString &id);
113  TMatrixD LocalToMasterErrorsShortId(const TMatrixD &local, const Int_t &shortId) { return LocalToMasterErrorsPath(local, GetPath(shortId)); }
114 
116 
117  void SetVerbose(Int_t v) { fVerbose = v; }
118  void SetGeoManager(TGeoManager *geo) { fGeoMan = geo; };
119  void SetSensorNamePar(PndSensorNamePar *par) { fSensorNamePar = par; }
120 
121  // Bool_t cd(TString id); ///< as the cd command of TGeoManager just with the ID
122  Bool_t cd(Int_t id);
123  void FillLevelNames();
124 
125  TString FindNodePath(TGeoNode *node);
126  void DiveDownToNode(TGeoNode *node);
127  void cd(TGeoNode *node);
128 
129  void DiveDownToNodeContainingString(TString name);
130 
131  void CreateUniqueSensorId(TString startName, std::vector<std::string> listOfSensitives);
132  bool VolumeIsSensitive(
133  TString &path,
134  std::vector<std::string> &listOfSensitives);
135 
137  {
138  if (fSensorNamePar)
139  fSensorNamePar->Print();
140  }
141 
142  TObjArray *GetSensorNames()
143  {
144  if (fSensorNamePar != nullptr)
145  return fSensorNamePar->GetSensorNames();
146  else
147  return nullptr;
148  }
149 
150  std::vector<TString> GetSensorNamesWithString(TString value)
151  {
152  if (fSensorNamePar != nullptr)
153  return fSensorNamePar->GetSensorNamesWithString(value);
154  else {
155  std::vector<TString> empty;
156  return empty;
157  }
158  }
159 
160  Int_t GetRunId(TString mcFile);
161  void GetGeoManager();
162  TGeoManager *GetGeoMan() { return fGeoMan; }
163  void GetSensorNamePar();
164  void FillSensorMap() { fSensorNamePar->FillMap(); }
165  void InitRuntimeDb(TString parFileName);
166 
167  PndGeoHandling &operator=(const PndGeoHandling &) { return *this; }
168 
169  void CreateUniqueSensorId(const TString &startName, const std::vector<std::string> &listOfSensitives, PndSensorNameIdMap *idmap);
170 
171  protected:
172  Int_t GetIdForSensor(TString &sensName) const;
173 
174  InitStatus Init()
175  {
176  fSensorNamePar->FillMap();
177  return kSUCCESS;
178  }
179 
180  virtual InitStatus ReInit()
181  {
182  fGeoMan = 0;
183  fGeoMan = gGeoManager;
184  return kSUCCESS;
185  }
186 
187  private:
188  static PndGeoHandling *fInstance;
190  : FairTask(), fGeoMan(gh.fGeoMan), fSensorNamePar(gh.fSensorNamePar), fRtdb(gh.fRtdb), fLevelNames(gh.fLevelNames), fLevel(gh.fLevel), fFullPath(gh.fFullPath),
191  fRunId(gh.fRunId), fVerbose(gh.fVerbose)
192  {
193  }
194 
195  void DiveDownToFillSensNamePar(std::vector<std::string> listOfSensitives);
196 
197  TGeoManager *fGeoMan{nullptr};
198  PndSensorNamePar *fSensorNamePar{nullptr};
199  FairRuntimeDb *fRtdb{nullptr};
200  // static PndGeoHandling* fGeoHandlingInstance;
201 
202  std::vector<TString> fLevelNames{};
203  Int_t fLevel{0};
204  bool fFullPath{true};
205  Int_t fRunId{0};
206  Int_t fVerbose{0};
207 
208  PndSensorNameIdMap *fCurrentIdMap{nullptr};
209 
210  ClassDef(PndGeoHandling, 3);
211 };
212 
213 #endif
TString FindNodePath(TGeoNode *node)
Int_t GetRunId(TString mcFile)
void SetGeoManager(TGeoManager *geo)
void GetGeoManager()
void DiveDownToNode(TGeoNode *node)
virtual InitStatus ReInit()
void DiveDownToNodeContainingString(TString name)
runs through the GeoManager until a path is found with a substring which matches to the given string ...
void SetSensorNamePar(PndSensorNamePar *par)
void GetOUVShortId(Int_t shortId, TVector3 &o, TVector3 &u, TVector3 &v)
virtual ~PndGeoHandling()
std::vector< TString > GetSensorNamesWithString(TString identifier)
static void Destroy()
void CreateUniqueSensorId(TString startName, std::vector< std::string > listOfSensitives)
Has to be called during simulation to create unique sensor id.
static PndGeoHandling * Instance()
TVector3 GetSensorDimensionsPath(TString path)
TVector3 MasterToLocalPath(const TVector3 &master, const TString &id)
void FillLevelNames()
fills vector<TString> fLevelNames with the names (or the paths) of the volumes down to the level give...
TMatrixD MasterToLocalErrorsShortId(const TMatrixD &master, const Int_t &shortId)
std::vector< TString > GetSensorNamesWithString(TString value)
std::vector< TString > GetNamesLevel(Int_t level, TString startPath="")
TString GetPath(Int_t shortID)
for a given shortID the path is returned
__m128 v
Definition: P4_F32vec4.h:3
TVector3 GetSensorDimensionsShortId(Int_t shortId)
TGeoHMatrix * GetMatrixShortId(Int_t shortId)
TMatrixD LocalToMasterErrorsShortId(const TMatrixD &local, const Int_t &shortId)
Class to access the naming information of the MVD.
TString GetVolumeID(TString name)
returns the volume ID for a given volume name
void PrintSensorNames()
Base class for NameIdMaps used by the EmcGeoHandling singleton to retrieve a detector id from a name ...
void GetOUVPath(TString path, TVector3 &o, TVector3 &u, TVector3 &v)
for a volume given by its path the o, u, v vectors for the plane are returned
TMatrixD GetCurrentRotationMatrix()
void InitRuntimeDb(TString parFileName)
TMatrixD LocalToMasterErrorsPath(const TMatrixD &local, const TString &id)
Bool_t cd(Int_t id)
as the cd command of TGeoManager just with the ID
TObjArray * GetSensorNames()
Int_t GetIdForSensor(TString &sensName) const
Int_t GetShortID(TString path)
for a given path the (unique) position of the sensor path in the fSensorNamePar-List is given...
TVector3 LocalToMasterPath(const TVector3 &local, const TString &id)
TVector3 MasterToLocalShortId(const TVector3 &master, const Int_t &shortId)
TMatrixD MasterToLocalErrorsPath(const TMatrixD &master, const TString &id)
void SetVerbose(Int_t v)
bool VolumeIsSensitive(TString &path, std::vector< std::string > &listOfSensitives)
Checks if the path contains a substring which matches one of the given strings in listOfSensitives...
virtual void SetParContainers()
PndGeoHandling & operator=(const PndGeoHandling &)
TGeoManager * GetGeoMan()
InitStatus Init()
TVector3 LocalToMasterShortId(const TVector3 &local, const Int_t &shortId)
TGeoHMatrix * GetMatrixPath(TString path)
void GetSensorNamePar()
TObjArray * GetSensorNames() const
TMatrixT< double > TMatrixD
Definition: PndLmdDim.h:52
PndGeoHandling()
default constructor. Has to be called in SetParContainers if the support of shortId is needed...
Unique match between SensorID and path in TGeoManager.