KaliVeda
Toolkit for HIC analysis
KVGeoImport.cpp
1 //Created by KVClassFactory on Tue Apr 23 13:04:21 2013
2 //Author: John Frankland,,,
3 
4 #include "KVGeoImport.h"
5 #include <KVMultiDetArray.h>
6 #include <KVIonRangeTableMaterial.h>
7 #include <TGeoBBox.h>
8 #include <TPluginManager.h>
9 
10 #include <KVNucleusEvent.h>
11 #include <KVGroup.h>
12 #include <TGeoPhysicalNode.h>
13 #include <KVRangeTableGeoNavigator.h>
14 #include <KVNamedParameter.h>
15 #include <KVDataAnalyser.h>
16 
18 
19 
20 
21 
29 KVGeoImport::KVGeoImport(TGeoManager* g, KVIonRangeTable* r, KVMultiDetArray* m, Bool_t create) : KVGeoNavigator(g), fCreateArray(create), fOrigin(nullptr)
30 {
31  // Import geometry described by TGeoManager into KVMultiDetArray object
32  //
33  // if create=kFALSE, we do not create any detectors etc., but just set up
34  // the required links between the geometry and the existing array detectors
35  //
36  // We change the colours of volumes depending on their material
37 
38  fArray = m;
39  fRangeTable = r;
40  fCurrentTrajectory.SetAddToNodes(kFALSE);
41  fCurrentTrajectory.SetPathInTitle(kFALSE);
42  fCheckDetVolNames = kFALSE;
43 
44  std::map<std::string, EColor> colors;
45  colors["Si"] = EColor(kGray + 1);
46  colors["CsI"] = EColor(kBlue - 8);
47  colors["Al"] = EColor(kGray);
48  colors["Cu"] = EColor(kOrange + 2);
49  TGeoVolume* vol;
50  TIter next(g->GetListOfVolumes());
51  while ((vol = (TGeoVolume*)next())) {
52  TGeoMedium* med = vol->GetMedium();
53  if (!med) continue;
54  TGeoMaterial* mat = med->GetMaterial();
55  if (colors.find(mat->GetName()) != colors.end()) vol->SetLineColor(colors[mat->GetName()]);
56  if (mat->GetDensity() < 0.1) vol->SetTransparency(60);
57  }
58 }
59 
60 
61 
64 
66 {
67  // Destructor
69 }
70 
71 
72 
75 
77 {
78  // All detectors crossed by the particle's trajectory are added to the multidetector
79 
80  KVDetector* detector = GetCurrentDetector();
81  if (!detector) return;
82  detector->GetNode()->SetName(detector->GetName());
83  if (fLastDetector && detector != fLastDetector) {
84  fLastDetector->GetNode()->AddBehind(detector);
85  detector->GetNode()->AddInFront(fLastDetector);
87  }
88  fLastDetector = detector;
89 }
90 
91 
92 
98 
100  Double_t ThetaMin, Double_t PhiMin, Double_t ThetaMax, Double_t PhiMax)
101 {
102  // Scan the geometry in order to find all detectors and detector alignments.
103  // This is done by sending out "particles" from (0,0,0) or (x,y,z) (if SetOrigin(x,y,z) was called)
104  // in all directions between (ThetaMin,ThetaMax) - with respect to Z-axis - and (PhiMin,PhiMax) - cylindrical
105  // angle in the (X,Y)-plane, over a grid of step dTheta in Theta and dPhi in Phi.
106 
107  Int_t ndets0 = fArray->GetDetectors()->GetEntries();
108 
109  KVNucleusEvent EVT;
110  KVEvent* evt = &EVT;
111  auto nuc = evt->AddNucleus();
112  nuc->SetZAandE(1, 1, 1);
113 
114  Info("ImportGeometry",
115  "Importing geometry in angular ranges : Theta=[%f,%f:%f] Phi=[%f,%f:%f]", ThetaMin, ThetaMax, dTheta, PhiMin, PhiMax, dPhi);
116  if (fOrigin)
117  Info("ImportGeometry",
118  "Origin for geometry = (%f,%f,%f)", fOrigin->x(), fOrigin->y(), fOrigin->z());
119  Int_t count = 0;
121  std::cout << "\xd" << "Info in <KVGeoImport::ImportGeometry>: tested " << count << " directions" << std::flush;
122  for (Double_t theta = ThetaMin; theta <= ThetaMax; theta += dTheta) {
123  for (Double_t phi = PhiMin; phi <= PhiMax; phi += dPhi) {
124  nuc->SetTheta(theta);
125  nuc->SetPhi(phi);
126  fLastDetector = nullptr;
127  PropagateEvent(evt, fOrigin);
128  count++;
130  std::cout << "\xd" << "Info in <KVGeoImport::ImportGeometry>: tested " << count << " directions" << std::flush;
131  }
132  }
134  std::cout << "Info in <KVGeoImport::ImportGeometry>: tested " << count << " directions" << std::endl;
135  else
136  std::cout << std::endl;
137 
138  Info("ImportGeometry",
139  "Imported %d detectors into array", fArray->GetDetectors()->GetEntries() - ndets0);
140 
141  // make sure detector nodes are correct
142  TIter next(fArray->GetDetectors());
143  KVDetector* d;
144  while ((d = (KVDetector*)next())) {
145  d->GetNode()->RehashLists();
146  d->SetNameOfArray(fArray->GetName());
147  }
148  // set up all detector node trajectories
150  // create all groups
152 
153  if (fCreateArray) {
155  // Set up internal navigator of array with all informations on detector/
156  // structure name formatting, correspondance lists, etc.
159  for (int i = 0; i < fStrucNameFmt.GetEntries(); i++) {
161  nav->SetStructureNameFormat(fmt->GetName(), fmt->GetString());
162  }
164  nav->AbsorbDetectorPaths(this);
168  }
169 }
170 
171 
172 
174 
176 {
177  fLastDetector = d;
178 }
179 
180 
181 
185 
187 {
188  // Override KVGeoNavigator method
189  // We build the list of all trajectories through the array
190 
192 
193  KVGeoNavigator::PropagateParticle(nuc, TheOrigin);
194 
195  if (fLastDetector && fLastDetector->GetNode()) {
196  if (fCurrentTrajectory.GetN()) {
199  }
201  } else {
203  }
206  fArray->AddTrajectory(tr);
207  }
208  }
209 }
210 
211 
212 
217 
219 {
220  // Add to list of acceptable detector names when scanning geometry
221  // Each detector volume name will be tested; if it doesn't contain
222  // any of the (partial) detector names in the list, it will be ignored
223 
226 }
227 
228 
229 
236 
238 {
239  // Returns pointer to KVDetector corresponding to current location
240  // in geometry. Detector is created and added to array if needed.
241  // We also set up any geometry structure elements (from nodes beginning with "STRUCT_")
242  // Any detector volume with a name not recognised by comparison with the list
243  // fAcceptedDetectorNames (if defined) will be ignored.
244 
245  KVString detector_name;
246  Bool_t multilay;
247  TGeoVolume* detector_volume = GetCurrentDetectorNameAndVolume(detector_name, multilay);
248  // failed to identify current volume as part of a detector
249 
250  if (!detector_volume) return 0;
251  // check volume belongs to us
252  if (fCheckDetVolNames) {
253  int nn = fAcceptedDetectorNames.GetNpar();
254  bool reject_volume = true;
255  for (int i = 0; i < nn; ++i) {
256  if (detector_name.Contains(fAcceptedDetectorNames.GetNameAt(i))) {
257  reject_volume = false;
258  break;
259  }
260  }
261  if (reject_volume) return 0;
262  }
263 
264  // has detector already been built ? if not, do it now
265  KVDetector* det = fArray->GetDetector(detector_name);
266  if (!fCreateArray) {
267  if (det) {
268  // set matrix & shape for entrance window if not done yet
269  if (!det->GetEntranceWindow().ROOTGeo()) {
271  det->SetEntranceWindowShape((TGeoBBox*)GetCurrentVolume()->GetShape());
272  }
273  TString vol_name(GetCurrentVolume()->GetName());
274  if (!multilay || vol_name.BeginsWith("ACTIVE_")) {
275  // set matrix & shape for active layer
277  det->SetActiveLayerShape((TGeoBBox*)GetCurrentVolume()->GetShape());
278  // set full path to physical node as title of detector's node (KVGeoDetectorNode)
279  det->GetNode()->SetTitle(GetCurrentPath());
280  }
281  // add entry to correspondance list between physical nodes and detectors (all layers)
283  }
284  } else {
285  if (!det) {
286  det = BuildDetector(detector_name, detector_volume);
287  if (det) {
288  // Setting the entrance window shape and matrix
289  // ============================================
290  // for consistency, the matrix and shape MUST correspond
291  // i.e. we cannot have the matrix corresponding to the entrance window
292  // of a multilayer detector and the shape corresponding to the
293  // whole detector (all layers) - otherwise, calculation of points
294  // on detector entrance window will be false!
295 // Info("GetCurrentDetector","Setting EW matrix to current matrix:");
296 // GetCurrentMatrix()->Print();
298  det->SetEntranceWindowShape((TGeoBBox*)GetCurrentVolume()->GetShape());
299  TString vol_name(GetCurrentVolume()->GetName());
300  if (!multilay || vol_name.BeginsWith("ACTIVE_")) {
301  // first layer of detector (or only layer) is also active layer
302 // Info("GetCurrentDetector","and also setting active layer matrix to current matrix:");
303 // GetCurrentMatrix()->Print();
305  det->SetActiveLayerShape((TGeoBBox*)GetCurrentVolume()->GetShape());
306  // set full path to physical node as title of detector's node (KVGeoDetectorNode)
307  det->GetNode()->SetTitle(GetCurrentPath());
308  }
309  // add entry to correspondance list between physical nodes and detectors (all layers)
311  fArray->Add(det);
312  Int_t nstruc = CurrentStructures().GetEntries();
313  if (nstruc) {
314  // Build and add geometry structure elements
315  KVGeoStrucElement* ELEM = fArray;
316  for (int i = 0; i < nstruc; i++) {
318  KVGeoStrucElement* nextELEM = ELEM->GetStructure(elem->GetName());
319  if (!nextELEM) {
320  // make new structure
321  nextELEM = new KVGeoStrucElement(elem->GetName(), elem->GetType());
322  nextELEM->SetNumber(elem->GetNumber());
323  ELEM->Add(nextELEM);
324  }
325  ELEM = nextELEM;
326  }
327  // add detector to last structure
328  ELEM->Add(det);
329  }
330  }
331  } else {
332  // Detector already built, are we now in its active layer ?
333  TString vol_name(GetCurrentVolume()->GetName());
334  if (!multilay || vol_name.BeginsWith("ACTIVE_")) {
335 // Info("GetCurrentDetector","Setting active layer matrix to current matrix:");
336 // GetCurrentMatrix()->Print();
338  det->SetActiveLayerShape((TGeoBBox*)GetCurrentVolume()->GetShape());
339  // set full path to physical node as title of detector's node (KVGeoDetectorNode)
340  det->GetNode()->SetTitle(GetCurrentPath());
341  }
342  // add entry to correspondance list between physical nodes and detectors (all layers)
344  }
345  }
346  return det;
347 }
348 
349 
350 
377 
379 {
380  // Create a KVDetector with given name for the given volume
381  //
382  // #### Detector definition in geometry ####
383  // 1. All detector volumes & nodes must have names which begin with **DET_**
384  //
385  // 2. They must be made of materials which are known by the range table fRangeTable.
386  //
387  // 3. For multi-layer detectors, the "active" layer volume/node must have a name beginning with **ACTIVE_**
388  //
389  // 4. The "thickness" of the detector or any layer inside a multilayer detector will be taken as the size of the volume's
390  // shape along its Z-axis (so make sure that you define your detector volumes in this way).
391  //
392  // 5. It is assumed that the natural length units of the geometry are centimetres.
393  //
394  // 6. The name of the KVDetector object created and added to the array will be taken
395  // from the unique full path of the node corresponding to the geometrical positioning
396  // of the detector, see KVGeoNavigator::ExtractDetectorNameFromPath()
397  //
398  // 7. The 'type' of the detector will be set to the name of the material
399  // in the detector's active layer i.e. if active layer material name is "Si",
400  // detector type will be 'Si'
401  //
402  // 8. Default class for all detectors is KVDetector. If you want to use another class
403  // you need to define it using SetDetectorPlugin() method and put the
404  // associated line in your .kvrootrc configuration file.
405 
406 
407  KVDetector* d = 0;
408  TPluginHandler* ph = NULL;
409  if (fDetectorPlugin == "" || !(ph = LoadPlugin("KVDetector", fDetectorPlugin))) {
410  d = new KVDetector;
411  } else {
412  d = (KVDetector*)ph->ExecPlugin(0);
413  }
414 
415  d->SetName(det_name);
416 
417  Int_t nlayer = det_vol->GetNdaughters();
418  if (nlayer) {
419  for (int i = 0; i < nlayer; i++) {
420  AddLayer(d, det_vol->GetNode(i)->GetVolume());
421  }
422  } else
423  AddLayer(d, det_vol);
424  TString type = d->GetActiveLayer()->GetName();
425  //type.ToUpper();
426  d->SetType(type);
427  return d;
428 }
429 
430 
431 
437 
439 {
440  // Add an absorber layer to the detector.
441  //
442  // Volumes representing 'active' layers in detectors must have names
443  // which begin with **ACTIVE_**.
444 
445  TString vnom = vol->GetName();
446  // exclude dead zone layers
447  if (vnom.BeginsWith("DEADZONE")) return;
448  TGeoMaterial* material = vol->GetMaterial();
449  KVIonRangeTableMaterial* irmat = fRangeTable->GetMaterial(material);
450  if (!irmat) {
451  Warning("AddLayer", "Unknown material %s/%s used in layer %s of detector %s",
452  material->GetName(), material->GetTitle(), vol->GetName(), det->GetName());
453  return;
454  }
455  TGeoBBox* sh = dynamic_cast<TGeoBBox*>(vol->GetShape());
456  if (!sh) {
457  Warning("AddLayer", "Unknown shape class %s used in layer %s of detector %s",
458  vol->GetShape()->ClassName(), vol->GetName(), det->GetName());
459  return; // just in case - for now, all shapes derive from TGeoBBox...
460  }
461  Double_t width = 2.*sh->GetDZ(); // thickness in centimetres
462  KVMaterial* absorber;
463  if (irmat->IsGas()) {
464  Double_t p = material->GetPressure();
465  Double_t T = material->GetTemperature();
466  absorber = new KVMaterial(irmat->GetType(), width, p, T);
467  } else
468  absorber = new KVMaterial(irmat->GetType(), width);
469  det->AddAbsorber(absorber);
470  if (vnom.BeginsWith("ACTIVE_")) det->SetActiveLayer(absorber);
471 }
472 
473 
474 
int Int_t
ROOT::R::TRInterface & r
#define SafeDelete(p)
#define d(i)
bool Bool_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
EColor
kGray
kOrange
kBlue
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t g
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Color * colors
virtual const Char_t * GetType() const
Definition: KVBase.h:177
virtual void SetNumber(UInt_t num)
Definition: KVBase.h:216
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
Definition: KVBase.cpp:793
UInt_t GetNumber() const
Definition: KVBase.h:220
static Bool_t IsRunningBatchAnalysis()
Base class for detector geometry description.
Definition: KVDetector.h:160
void AddAbsorber(KVMaterial *)
Definition: KVDetector.cpp:630
const KVPosition & GetEntranceWindow() const
Definition: KVDetector.h:701
void SetActiveLayer(KVMaterial *actif)
Definition: KVDetector.h:285
void SetActiveLayerMatrix(const TGeoHMatrix *)
Set ROOT geometry global matrix transformation to coordinate frame of active layer volume.
KVGeoDetectorNode * GetNode()
Definition: KVDetector.h:326
void SetEntranceWindowMatrix(const TGeoHMatrix *)
Set ROOT geometry global matrix transformation to coordinate frame of entrance window.
void SetEntranceWindowShape(TGeoBBox *)
Set ROOT geometry shape of entrance window.
void SetActiveLayerShape(TGeoBBox *)
Set ROOT geometry shape of active layer volume.
Abstract base class container for multi-particle events.
Definition: KVEvent.h:67
KVNucleus * AddNucleus()
Definition: KVEvent.cpp:109
Path taken by particles through multidetector geometry.
Bool_t Contains(const Char_t *name) const
void ReverseOrder()
Reverse the order of the nodes in the trajectory.
void AddLast(KVGeoDetectorNode *n)
void Clear(Option_t *="")
Clear list of nodes in trajectory.
void AddInFront(KVDetector *)
void AddBehind(KVDetector *)
Import detector array described by ROOT geometry and set up corresponding KVMultiDetArray object.
Definition: KVGeoImport.h:68
KVNameValueList fAcceptedDetectorNames
Definition: KVGeoImport.h:80
KVDetector * GetCurrentDetector()
virtual void ParticleEntersNewVolume(KVNucleus *)
All detectors crossed by the particle's trajectory are added to the multidetector.
Definition: KVGeoImport.cpp:76
KVDetector * BuildDetector(TString det_name, TGeoVolume *det_vol)
KVGeoDNTrajectory fCurrentTrajectory
Definition: KVGeoImport.h:74
Bool_t fCheckDetVolNames
Definition: KVGeoImport.h:81
void AddAcceptedDetectorName(const char *name)
TString fDetectorPlugin
Definition: KVGeoImport.h:73
KVDetector * fLastDetector
Definition: KVGeoImport.h:71
void PropagateParticle(KVNucleus *, TVector3 *TheOrigin=nullptr)
virtual ~KVGeoImport()
Destructor.
Definition: KVGeoImport.cpp:65
KVIonRangeTable * fRangeTable
Definition: KVGeoImport.h:70
void AddLayer(KVDetector *, TGeoVolume *)
KVMultiDetArray * fArray
Definition: KVGeoImport.h:69
TVector3 * fOrigin
Definition: KVGeoImport.h:75
void SetLastDetector(KVDetector *)
Bool_t fCreateArray
Definition: KVGeoImport.h:72
void ImportGeometry(Double_t dTheta=0.1, Double_t dPhi=1.0, Double_t ThetaMin=0.0, Double_t PhiMin=0.0, Double_t ThetaMax=180.0, Double_t PhiMax=360.0)
Definition: KVGeoImport.cpp:99
Link physical path to node in geometry with detector.
Base class for propagation of particles through array geometry.
void SetDetectorNameFormat(const Char_t *fmt)
void PropagateEvent(KVEvent *, TVector3 *TheOrigin=0)
const TGeoHMatrix * GetCurrentMatrix() const
Returns pointer to internal copy of current global transformation matrix.
void AbsorbDetectorPaths(KVGeoNavigator *GN)
KVUniqueNameList fDetectorPaths
correspondance between physical node and detector objects
KVNameValueList fStrucNameFmt
list of user-defined formats for structure names
const TClonesArray & CurrentStructures() const
void SetNameCorrespondanceList(const Char_t *)
TEnv * fDetStrucNameCorrespList
list(s) of correspondance for renaming structures/detectors
virtual void PropagateParticle(KVNucleus *, TVector3 *TheOrigin=0)
TString GetCurrentPath() const
TGeoVolume * GetCurrentVolume() const
KVString fDetNameFmt
user-defined format for detector names
void SetStructureNameFormat(const Char_t *type, const Char_t *fmt)
TGeoVolume * GetCurrentDetectorNameAndVolume(KVString &, Bool_t &)
TGeoManager * GetGeometry() const
Base class describing elements of array geometry.
KVDetector * GetDetector(const Char_t *name) const
Return detector in this structure with given name.
const KVSeqCollection * GetDetectors() const
virtual void Add(KVBase *)
KVGeoStrucElement * GetStructure(const Char_t *name) const
Material for use in energy loss & range calculations.
Abstract base class for calculation of range & energy loss of charged particles in matter.
KVIonRangeTableMaterial * GetMaterial(const Char_t *material) const
Returns pointer to material of given name or type.
Description of physical materials used to construct detectors & targets; interface to range tables.
Definition: KVMaterial.h:94
Base class for describing the geometry of a detector array.
virtual void DeduceIdentificationTelescopesFromGeometry()
void CalculateDetectorSegmentationIndex()
void AddTrajectory(KVGeoDNTrajectory *d)
KVGeoNavigator * GetNavigator() const
void SetGeometry(TGeoManager *)
const TSeqCollection * GetTrajectories() const
void CalculateReconstructionTrajectories()
void AssociateTrajectoriesAndNodes()
void DeduceGroupsFromTrajectories()
KVNamedParameter * GetParameter(Int_t idx) const
return the parameter object with index idx
void SetValue(const Char_t *name, value_type value)
const Char_t * GetNameAt(Int_t idx) const
Int_t GetNpar() const
return the number of stored parameters
Int_t GetEntries() const
A generic named parameter storing values of different types.
const Char_t * GetString() const
An event container for KVNucleus objects.
Description of properties and kinematics of atomic nuclei.
Definition: KVNucleus.h:126
void SetZAandE(Int_t z, Int_t a, Double_t ekin)
Set atomic number, mass number, and kinetic energy in MeV.
Definition: KVNucleus.cpp:736
Bool_t ROOTGeo() const
Returns kTRUE if ROOT geometry is used, kFALSE if not.
Definition: KVPosition.cpp:598
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
virtual void Add(TObject *obj)
virtual Int_t GetEntries() const
TObject * FindObject(const char *name) const override
virtual Double_t GetDZ() const
Double_t GetTemperature() const
Double_t GetPressure() const
virtual Double_t GetDensity() const
TGeoMaterial * GetMaterial() const
TGeoVolume * GetVolume() const
TGeoMedium * GetMedium() const
TGeoMaterial * GetMaterial() const
Int_t GetNdaughters() const
void SetTransparency(Char_t transparency=0)
TGeoNode * GetNode(const char *name) const
void SetLineColor(Color_t lcolor) override
TGeoShape * GetShape() const
virtual void SetTitle(const char *title="")
const char * GetName() const override
const char * GetTitle() const override
virtual void SetName(const char *name)
Int_t GetEntries() const override
virtual const char * ClassName() const
virtual void Warning(const char *method, const char *msgfmt,...) const
virtual void Info(const char *method, const char *msgfmt,...) const
Longptr_t ExecPlugin(int nargs)
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Double_t z() const
Double_t x() const
Double_t y() const
double T(double x)
TMarker m
ClassImp(TPyArg)