PandaRoot
PndGeoHandling.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 
39 #ifndef PNDGEOHANDLING_H
40 #define PNDGEOHANDLING_H
41 
42 #include "PndSensorNamePar.h"
43 #include "PndSensorNameIdMap.h"
44 
45 #include "FairRun.h"
46 #include "FairRuntimeDb.h"
47 #include "FairTask.h"
48 
49 #include "TGeoManager.h"
50 #include "TGeoMatrix.h"
51 #include "TString.h"
52 #include "TVector3.h"
53 #include "TMatrixD.h"
54 
55 #include <string>
56 #include <iostream>
57 #include <vector>
58 
59 class PndGeoHandling : public FairTask {
60  public:
63  PndGeoHandling();
64  static PndGeoHandling *Instance();
65 
66  static void Destroy()
67  {
68  if (fInstance) {
69  delete fInstance;
70  fInstance = nullptr;
71  }
72  }
73 
74  // PndGeoHandling(TGeoManager* aGeoMan);
75  PndGeoHandling(TString mcFile, TString parFile);
76  PndGeoHandling(Int_t runID, TString parFile);
77  PndGeoHandling(PndSensorNamePar *SensorNamePar);
78 
79  virtual ~PndGeoHandling(){};
80 
81  virtual void SetParContainers();
82 
83  // static PndGeoHandling* Instance();
84 
85  // TString GetCurrentID(); ///< returns the ID of the current node
86  // TString GetID(TString path); ///< for a given TGeoManager-path the ID is returned
87  // TString GetPath(TString id); ///< for a given ID the path is returned
88 
89  TString GetPath(Int_t shortID);
90  Int_t GetShortID(TString path);
91 
92  TString GetVolumeID(TString name);
93  std::vector<TString> GetNamesLevel(Int_t level, TString startPath = ""); //, bool fullPath = false); //[R.K.03/2017] unused variable
94  void GetOUVPath(TString path, TVector3 &o, TVector3 &u, TVector3 &v);
95  // 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
96  void GetOUVShortId(Int_t shortId, TVector3 &o, TVector3 &u, TVector3 &v)
97  {
98  if (fSensorNamePar != 0)
99  GetOUVPath(GetPath(shortId), o, u, v);
100  }
101 
102  TGeoHMatrix *GetMatrixPath(TString path);
103  // TGeoHMatrix* GetMatrixId(TString id);
104  TGeoHMatrix *GetMatrixShortId(Int_t shortId) { return GetMatrixPath(GetPath(shortId)); }
105 
106  // TVector3 GetSensorDimensionsId(TString id);
107  TVector3 GetSensorDimensionsPath(TString path);
108  TVector3 GetSensorDimensionsShortId(Int_t shortId) { return GetSensorDimensionsPath(GetPath(shortId)); }
109 
110  // TVector3 MasterToLocalId(const TVector3& master, const TString& id);
111  TVector3 MasterToLocalPath(const TVector3 &master, const TString &id);
112  TVector3 MasterToLocalShortId(const TVector3 &master, const Int_t &shortId) { return MasterToLocalPath(master, GetPath(shortId)); }
113 
114  // TVector3 LocalToMasterId(const TVector3& local, const TString& id);
115  TVector3 LocalToMasterPath(const TVector3 &local, const TString &id);
116  TVector3 LocalToMasterShortId(const TVector3 &local, const Int_t &shortId) { return LocalToMasterPath(local, GetPath(shortId)); }
117 
118  // TODO: Recheck the error calculation for 3-vectors
119  // TMatrixD MasterToLocalErrorsId(const TMatrixD& master, const TString& id);
120  TMatrixD MasterToLocalErrorsPath(const TMatrixD &master, const TString &id);
121  TMatrixD MasterToLocalErrorsShortId(const TMatrixD &master, const Int_t &shortId) { return MasterToLocalErrorsPath(master, GetPath(shortId)); }
122 
123  // TMatrixD LocalToMasterErrorsId(const TMatrixD& local, const TString& id);
124  TMatrixD LocalToMasterErrorsPath(const TMatrixD &local, const TString &id);
125  TMatrixD LocalToMasterErrorsShortId(const TMatrixD &local, const Int_t &shortId) { return LocalToMasterErrorsPath(local, GetPath(shortId)); }
126 
128 
129  void SetVerbose(Int_t v) { fVerbose = v; }
130  void SetGeoManager(TGeoManager *geo) { fGeoMan = geo; };
131  void SetSensorNamePar(PndSensorNamePar *par) { fSensorNamePar = par; }
132 
133  // Bool_t cd(TString id); ///< as the cd command of TGeoManager just with the ID
134  Bool_t cd(Int_t id);
135  void FillLevelNames();
136 
137  TString FindNodePath(TGeoNode *node);
138  void DiveDownToNode(TGeoNode *node);
139  void cd(TGeoNode *node);
140 
141  void DiveDownToNodeContainingString(TString name);
142 
143  void CreateUniqueSensorId(TString startName, std::vector<std::string> listOfSensitives);
144  bool VolumeIsSensitive(
145  TString &path,
146  std::vector<std::string> &listOfSensitives);
147 
149  {
150  if (fSensorNamePar)
151  fSensorNamePar->Print();
152  }
153 
154  TObjArray *GetSensorNames()
155  {
156  if (fSensorNamePar != nullptr)
157  return fSensorNamePar->GetSensorNames();
158  else
159  return nullptr;
160  }
161 
162  std::vector<TString> GetSensorNamesWithString(TString value)
163  {
164  if (fSensorNamePar != nullptr)
165  return fSensorNamePar->GetSensorNamesWithString(value);
166  else {
167  std::vector<TString> empty;
168  return empty;
169  }
170  }
171 
172  Int_t GetRunId(TString mcFile);
173  void GetGeoManager();
174  TGeoManager *GetGeoMan() { return fGeoMan; }
175  void GetSensorNamePar();
176  void FillSensorMap() { fSensorNamePar->FillMap(); }
177  void InitRuntimeDb(TString parFileName);
178 
179  PndGeoHandling &operator=(const PndGeoHandling &) { return *this; }
180 
181  void CreateUniqueSensorId(const TString &startName, const std::vector<std::string> &listOfSensitives, PndSensorNameIdMap *idmap);
182 
183  protected:
184  Int_t GetIdForSensor(TString &sensName) const;
185 
186  InitStatus Init()
187  {
188  fSensorNamePar->FillMap();
189  return kSUCCESS;
190  }
191 
192  virtual InitStatus ReInit()
193  {
194  fGeoMan = 0;
195  fGeoMan = gGeoManager;
196  return kSUCCESS;
197  }
198 
199  private:
200  static PndGeoHandling *fInstance;
202  : FairTask(), fGeoMan(gh.fGeoMan), fSensorNamePar(gh.fSensorNamePar), fRtdb(gh.fRtdb), fLevelNames(gh.fLevelNames), fLevel(gh.fLevel), fFullPath(gh.fFullPath),
203  fRunId(gh.fRunId), fVerbose(gh.fVerbose)
204  {
205  }
206 
207  void DiveDownToFillSensNamePar(std::vector<std::string> listOfSensitives);
208 
209  TGeoManager *fGeoMan{nullptr};
210  PndSensorNamePar *fSensorNamePar{nullptr};
211  FairRuntimeDb *fRtdb{nullptr};
212  // static PndGeoHandling* fGeoHandlingInstance;
213 
214  std::vector<TString> fLevelNames{};
215  Int_t fLevel{0};
216  bool fFullPath{true};
217  Int_t fRunId{0};
218  Int_t fVerbose{0};
219 
220  PndSensorNameIdMap *fCurrentIdMap{nullptr};
221 
222  ClassDef(PndGeoHandling, 3);
223 };
224 
225 #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:15
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:64
PndGeoHandling()
default constructor. Has to be called in SetParContainers if the support of shortId is needed...
Unique match between SensorID and path in TGeoManager.