Project
Loading...
Searching...
No Matches
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
30FairDetector::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
std::ostringstream debug
ClassImp(FairDetector)
int32_t i
uint16_t pos
Definition RawData.h:3
FairDetector & operator=(const FairDetector &)
FairLogger * fLogger
void DefineSensitiveVolumes()
virtual ~FairDetector()
virtual void Initialize()
FairModule & operator=(const FairModule &)
Int_t GetModId()
Definition FairModule.h:108
Bool_t fGeoSaved
list of Detector Geometry parameters
Definition FairModule.h:159
void AddSensitiveVolume(TGeoVolume *v)
TList * flGeoPar
Definition FairModule.h:158
TVirtualMC * fMC
flag for initialisation
Definition FairModule.h:160
virtual Bool_t IsSensitive(const std::string &name)
static thread_local TRefArray * svList
Definition FairModule.h:133
static const char * GetFolderName()
void setMCid(Int_t id)
Definition FairVolume.h:59
Int_t getModId()
Definition FairVolume.h:39
FairGeoNode * getGeoNode()
Definition FairVolume.h:60
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"