FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairDetector.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 // -------------------------------------------------------------------------
9 // ----- FairDetector source file -----
10 // ----- Created 06/01/04 by M. Al-Turany/ D. Bertini -----
11 // -------------------------------------------------------------------------
12 
13 #include "FairDetector.h"
14 
15 #include "FairGeoNode.h" // for FairGeoNode
16 #include "FairLogger.h" // for FairLogger, MESSAGE_ORIGIN
17 #include "FairModule.h" // for FairModule::svList, etc
18 #include "FairRootManager.h"
19 #include "FairVolume.h" // for FairVolume
20 
21 #include <TFolder.h> // for TFolder
22 #include <TGeoManager.h> // for gGeoManager
23 #include <TList.h> // for TList
24 #include <TObject.h> // for TObject
25 #include <TROOT.h> // for TROOT, gROOT
26 #include <TRefArray.h> // for TRefArray
27 #include <TString.h> // for TString
28 #include <TVirtualMC.h> // for TVirtualMC
29 
30 FairDetector::FairDetector(const char* Name, Bool_t Active, Int_t DetId)
31  : FairModule(Name, "FAIR Detector", Active)
32  , fDetId(DetId)
33  , fLogger(FairLogger::GetLogger())
34 {
35  flGeoPar = new TList();
36  TString lname(GetName());
37  lname += "GeoPar";
38  flGeoPar->SetName(lname.Data());
39  fGeoSaved = kFALSE;
40 }
41 
43  : FairModule(rhs)
44  , fDetId(rhs.fDetId)
45  , fLogger(rhs.fLogger)
46 {}
47 
49 
51 {
52  // check assignment to self
53  if (this == &rhs)
54  return *this;
55 
56  // base class assignment
58 
59  // assignment operator
60  fDetId = rhs.fDetId;
61  fLogger = rhs.fLogger;
62 
63  return *this;
64 }
65 
67  : fDetId(0)
68  , fLogger(FairLogger::GetLogger())
69 {}
70 
71 // -------------------------------------------------------------------------
72 
74 {
75  LOG(info) << "FairDetector::DefineSensitiveVolumes";
76  TObjArray* volumes = gGeoManager->GetListOfVolumes();
77  TIter next(volumes);
78  TGeoVolume* volume;
79  while ((volume = static_cast<TGeoVolume*>(next()))) {
80  if (IsSensitive(volume->GetName())) {
81  LOG(debug) << "Sensitive Volume " << volume->GetName();
82  AddSensitiveVolume(volume);
83  }
84  }
85 }
86 
87 // -------------------------------------------------------------------------
88 
90 {
91  // Registers hits collection in Root manager;
92  // sets sensitive volumes.
93  // ---
94 
95  // Define sensitive volumes if in MT
96  if (gMC->IsMT()) {
97  std::cout << "Define sensitive volume " << std::endl;
99  }
100 
101  Int_t NoOfEntries = svList->GetEntries();
102  Int_t fMCid;
103  FairGeoNode* fN;
104  TString cutName;
105  TString copysign = "#";
106  for (Int_t i = 0; i < NoOfEntries; i++) {
107  FairVolume* aVol = static_cast<FairVolume*>(svList->At(i));
108  cutName = aVol->GetName();
109  Ssiz_t pos = cutName.Index(copysign, 1);
110  if (pos > 1) {
111  cutName.Resize(pos);
112  }
113  if (aVol->getModId() == GetModId()) {
114  fMCid = TVirtualMC::GetMC()->VolId(cutName.Data());
115  aVol->setMCid(fMCid);
116  fN = aVol->getGeoNode();
117  if (fN) {
118  fN->setMCid(fMCid);
119  }
120  }
121  }
122 
123  // Initialize cached pointer to MC (on master in sequential mode)
124  fMC = TVirtualMC::GetMC();
125 }
126 
128 {
129  if (!fGeoSaved) {
130  LOG(info) << "Detector: " << GetName() << " Geometry parameters saved ... ";
131  TFolder* mf = dynamic_cast<TFolder*>(gROOT->FindObjectAny(FairRootManager::GetFolderName()));
132  TFolder* stsf = nullptr;
133  if (mf) {
134  stsf = dynamic_cast<TFolder*>(mf->FindObjectAny(GetName()));
135  }
136  if (stsf) {
137  TFolder* newf = stsf->AddFolder("Parameters", "Detector parameters", nullptr);
138  newf->Add(flGeoPar);
139  }
140  fGeoSaved = kTRUE;
141  }
142 }
143 
void AddSensitiveVolume(TGeoVolume *v)
Definition: FairModule.cxx:294
virtual void see Tutorial4 for examples LOG(warn)<< "This function is deprecated. Use FairAlignmentHandler instead
FairDetector & operator=(const FairDetector &)
static thread_local TRefArray * svList
Definition: FairModule.h:137
FairGeoNode * getGeoNode()
Definition: FairVolume.h:60
ClassImp(FairEventBuilder)
Bool_t fGeoSaved
list of Detector Geometry parameters
Definition: FairModule.h:163
Int_t getModId()
Definition: FairVolume.h:39
TVirtualMC * fMC
flag for initialisation
Definition: FairModule.h:164
virtual void Initialize()
void setMCid(Int_t MCid)
Definition: FairGeoVolume.h:65
FairModule & operator=(const FairModule &)
Definition: FairModule.cxx:149
void DefineSensitiveVolumes()
TList * flGeoPar
Definition: FairModule.h:162
void SaveGeoParams()
FairLogger * fLogger
Definition: FairDetector.h:111
static char * GetFolderName()
virtual Bool_t IsSensitive(const std::string &name)
Definition: FairModule.cxx:559
virtual ~FairDetector()
void setMCid(Int_t id)
Definition: FairVolume.h:59
Int_t GetModId()
Definition: FairModule.h:111