Project
Loading...
Searching...
No Matches
Detector.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
16#include <TVirtualMC.h> // for TVirtualMC, gMC
19#include "Field/MagneticField.h"
21#include "TString.h" // for TString
22#include "TGeoManager.h"
23
24using std::cout;
25using std::endl;
26using std::fstream;
27using std::ios;
28using std::ostream;
29
30using namespace o2::base;
31using namespace o2::detectors;
32
33Float_t Detector::mDensityFactor = 1.0;
34std::vector<int> o2::base::Detector::sDetId2HitBitIndex{}; // initialize empty vector
35
36Detector::Detector() : FairDetector(), mMapMaterial(), mMapMedium() {}
37Detector::Detector(const char* name, Bool_t Active)
38 : FairDetector(name, Active, DetID(name)), mMapMaterial(), mMapMedium()
39{
40}
41
42Detector::Detector(const Detector& rhs) = default;
43
44Detector::~Detector() = default;
45
47{
48 // check assignment to self
49 if (this == &rhs) {
50 return *this;
51 }
52
53 // base class assignment
54 FairDetector::operator=(rhs);
55
56 return *this;
57}
58
59void Detector::Material(Int_t imat, const char* name, Float_t a, Float_t z, Float_t dens, Float_t radl, Float_t absl,
60 Float_t* buf, Int_t nwbuf)
61{
63 mgr.Material(GetName(), imat, name, a, z, dens, radl, absl, buf, nwbuf);
64}
65
66void Detector::Mixture(Int_t imat, const char* name, Float_t* a, Float_t* z, Float_t dens, Int_t nlmat, Float_t* wmat)
67{
69 mgr.Mixture(GetName(), imat, name, a, z, dens, nlmat, wmat);
70}
71
72void Detector::Medium(Int_t numed, const char* name, Int_t nmat, Int_t isvol, Int_t ifield, Float_t fieldm,
73 Float_t tmaxfd, Float_t stemax, Float_t deemax, Float_t epsil, Float_t stmin, Float_t* ubuf,
74 Int_t nbuf)
75{
77 mgr.Medium(GetName(), numed, name, nmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf);
78}
79
80void Detector::SpecialCuts(Int_t numed, const std::initializer_list<std::pair<ECut, Float_t>>& parIDValMap)
81{
82 auto& mgr = MaterialManager::Instance();
83 mgr.SpecialCuts(GetName(), numed, parIDValMap);
84}
85
86void Detector::SpecialCut(Int_t numed, ECut parID, Float_t val)
87{
88 auto& mgr = MaterialManager::Instance();
89 mgr.SpecialCut(GetName(), numed, parID, val);
90}
91
92void Detector::SpecialProcesses(Int_t numed, const std::initializer_list<std::pair<EProc, int>>& parIDValMap)
93{
94 auto& mgr = MaterialManager::Instance();
95 mgr.SpecialProcesses(GetName(), numed, parIDValMap);
96}
97
98void Detector::SpecialProcess(Int_t numed, EProc parID, int val)
99{
100 auto& mgr = MaterialManager::Instance();
101 mgr.SpecialProcess(GetName(), numed, parID, val);
102}
103
104void Detector::Matrix(Int_t& nmat, Float_t theta1, Float_t phi1, Float_t theta2, Float_t phi2, Float_t theta3,
105 Float_t phi3) const
106{
107 TVirtualMC::GetMC()->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3);
108}
109
110void Detector::defineWrapperVolume(Int_t id, Double_t rmin, Double_t rmax, Double_t zspan) {}
112void Detector::defineLayer(const Int_t nlay, const double phi0, const Double_t r, const Int_t nladd, const Int_t nmod,
113 const Double_t lthick, const Double_t dthick, const UInt_t dettypeID, const Int_t buildLevel)
114{
115}
116
117void Detector::defineLayerTurbo(Int_t nlay, Double_t phi0, Double_t r, Int_t nladd, Int_t nmod, Double_t width,
118 Double_t tilt, Double_t lthick, Double_t dthick, UInt_t dettypeID, Int_t buildLevel)
119{
120}
121
123{
124 // default implementation for physics cuts setting (might still be overriden by detectors)
125 // we try to read an external text file supposed to be installed
126 // in a standard directory
127 // ${O2_ROOT}/share/Detectors/DETECTORNAME/simulation/data/simcuts.dat
128 LOG(info) << "Setting special cuts for " << GetName();
129 const char* aliceO2env = std::getenv("O2_ROOT");
130 std::string inputFile;
131 if (aliceO2env) {
132 inputFile = std::string(aliceO2env);
133 }
134 inputFile += "/share/Detectors/" + std::string(GetName()) + "/simulation/data/simcuts.dat";
136 matmgr.loadCutsAndProcessesFromFile(GetName(), inputFile.c_str());
137
138 // TODO:
139 // foresee possibility to read from local (non-installed) file or
140 // via command line
141}
142
143void Detector::initFieldTrackingParams(int& integration, float& maxfield)
144{
145 // set reasonable default values
146 integration = 2;
147 maxfield = 10;
148 auto vmc = TVirtualMC::GetMC();
149 if (vmc) {
150 auto field = vmc->GetMagField();
151 // see if we can query the o2 field
152 if (auto o2field = dynamic_cast<o2::field::MagneticField*>(field)) {
153 integration = o2field->Integral(); // default integration method?
154 maxfield = o2field->Max();
155 return;
156 }
157 }
158 LOG(info) << "No magnetic field found; using default tracking values " << integration << " " << maxfield
159 << " to initialize media\n";
160}
161
162TClonesArray* Detector::GetCollection(int) const
163{
164 LOG(warning) << "GetCollection interface no longer supported";
165 LOG(warning) << "Use the GetHits function on invidiual detectors";
166 return nullptr;
167}
168
170{
171 LOG(warning) << "Alignable volumes are not yet defined for " << GetName();
172}
173
175{
176}
177
179{
180 // register this volume with FairRoot
181 this->FairModule::AddSensitiveVolume(const_cast<TGeoVolume*>(vol));
182 // retrieve the VMC Monte Carlo ID for this volume
183 const int volid = TVirtualMC::GetMC()->VolId(vol->GetName());
184 if (volid <= 0) {
185 LOG(error) << "Could not retrieve VMC volume ID for " << vol->GetName();
186 }
187 return volid;
188}
189
191{
192 // we need to fetch the TGeoVolume which is needed for FairRoot
193 auto vol = gGeoManager->GetVolume(name.c_str());
194 if (!vol) {
195 LOG(error) << "Volume " << name << " not found in geometry; Cannot register sensitive volume";
196 return -1;
197 }
199}
200
201#include <fairmq/Message.h>
202#include <fairmq/Parts.h>
203#include <fairmq/Channel.h>
204namespace o2::base
205{
206// this goes into the source
207void attachMessageBufferToParts(fair::mq::Parts& parts, fair::mq::Channel& channel, void* data, TClass* cl)
208{
209 auto msg = channel.Transport()->CreateMessage(4096, fair::mq::Alignment{64});
210 // This will serialize the data directly into the message buffer, without any further
211 // buffer or copying. Notice how the message will have 8 bytes of header and then
212 // the serialized data as TBufferFile. In principle one could construct a serialized TMessage payload
213 // however I did not manage to get it to work for every case.
216 parts.AddPart(std::move(msg));
217}
218void attachDetIDHeaderMessage(int id, fair::mq::Channel& channel, fair::mq::Parts& parts)
219{
220 std::unique_ptr<fair::mq::Message> message(channel.NewSimpleMessage(id));
221 parts.AddPart(std::move(message));
222}
223void attachShmMessage(void* hits_ptr, fair::mq::Channel& channel, fair::mq::Parts& parts, bool* busy_ptr)
224{
225 struct shmcontext {
226 int id;
227 void* object_ptr;
228 bool* busy_ptr;
229 };
230
231 auto& instance = o2::utils::ShmManager::Instance();
232 shmcontext info{instance.getShmID(), hits_ptr, busy_ptr};
233 LOG(debug) << "-- SHM SEND --";
234 LOG(debug) << "-- OBJ PTR -- " << info.object_ptr << " ";
235 assert(instance.isPointerOk(info.object_ptr));
236
237 std::unique_ptr<fair::mq::Message> message(channel.NewSimpleMessage(info));
238 parts.AddPart(std::move(message));
239}
240void* decodeShmCore(fair::mq::Parts& dataparts, int index, bool*& busy)
241{
242 auto rawmessage = std::move(dataparts.At(index));
243 struct shmcontext {
244 int id;
245 void* object_ptr;
246 bool* busy_ptr;
247 };
248
249 shmcontext* info = (shmcontext*)rawmessage->GetData();
250
251 busy = info->busy_ptr;
252 return info->object_ptr;
253}
254
255void* decodeTMessageCore(fair::mq::Parts& dataparts, int index)
256{
257 auto rawmessage = std::move(dataparts.At(index));
258 o2::framework::FairInputTBuffer buffer((char*)rawmessage->GetData(), rawmessage->GetSize());
259 buffer.InitMap();
260 auto* cl = buffer.ReadClass();
261 buffer.SetBufferOffset(0);
262 buffer.ResetMap();
263 return buffer.ReadObjectAny(cl);
264}
265
266} // namespace o2::base
Definition of the Detector class.
ClassImp(IdPath)
Definition of the MagF class.
std::ostringstream debug
void SpecialProcess(Int_t numed, EProc parID, int val)
Set process by name and value.
Definition Detector.cxx:98
int registerSensitiveVolumeAndGetVolID(std::string const &name)
Definition Detector.cxx:190
~Detector() override
Default Destructor.
Definition Detector.cxx:87
Detector & operator=(const Detector &)
Definition Detector.cxx:46
virtual void defineLayerTurbo(Int_t nlay, Double_t phi0, Double_t r, Int_t nladd, Int_t nmod, Double_t width, Double_t tilt, Double_t lthick=0., Double_t dthick=0., UInt_t detType=0, Int_t buildFlag=0)
Definition Detector.cxx:117
TClonesArray * GetCollection(int iColl) const final
Definition Detector.cxx:162
virtual void fillParallelWorld() const
fill parallel geometry with sensitive volumes of detector
Definition Detector.cxx:174
void SpecialCuts(Int_t numed, const std::initializer_list< std::pair< ECut, Float_t > > &parIDValMap)
Custom processes and transport cuts.
Definition Detector.cxx:80
void SpecialCut(Int_t numed, ECut parID, Float_t val)
Set cut by name and value.
Definition Detector.cxx:86
void SpecialProcesses(Int_t numed, const std::initializer_list< std::pair< EProc, int > > &parIDValMap)
Definition Detector.cxx:92
void Matrix(Int_t &nmat, Float_t theta1, Float_t phi1, Float_t theta2, Float_t phi2, Float_t theta3, Float_t phi3) const
Definition Detector.cxx:104
Detector()
Default Constructor.
Definition Detector.cxx:36
virtual void setNumberOfWrapperVolumes(Int_t n)
Books arrays for wrapper volumes.
Definition Detector.cxx:111
void Mixture(Int_t imat, const char *name, Float_t *a, Float_t *z, Float_t dens, Int_t nlmat, Float_t *wmat)
Definition Detector.cxx:66
virtual void addAlignableVolumes() const
declare alignable volumes of detector
Definition Detector.cxx:169
void Medium(Int_t numed, const char *name, Int_t nmat, Int_t isvol, Int_t ifield, Float_t fieldm, Float_t tmaxfd, Float_t stemax, Float_t deemax, Float_t epsil, Float_t stmin, Float_t *ubuf=nullptr, Int_t nbuf=0)
Definition Detector.cxx:72
void SetSpecialPhysicsCuts() override
Definition Detector.cxx:122
static void initFieldTrackingParams(int &mode, float &maxfield)
Definition Detector.cxx:143
virtual void defineWrapperVolume(Int_t id, Double_t rmin, Double_t rmax, Double_t zspan)
Sets per wrapper volume parameters.
Definition Detector.cxx:110
virtual void defineLayer(Int_t nlay, Double_t phi0, Double_t r, Int_t nladd, Int_t nmod, Double_t lthick=0., Double_t dthick=0., UInt_t detType=0, Int_t buildFlag=0)
void Material(Int_t imat, const char *name, Float_t a, Float_t z, Float_t dens, Float_t radl, Float_t absl, Float_t *buf=nullptr, Int_t nwbuf=0)
Definition Detector.cxx:59
static MaterialManager & Instance()
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:58
static ShmManager & Instance()
Definition ShmManager.h:61
GLdouble n
Definition glcorearb.h:1982
GLuint buffer
Definition glcorearb.h:655
GLuint index
Definition glcorearb.h:781
GLuint const GLchar * name
Definition glcorearb.h:781
GLint GLsizei width
Definition glcorearb.h:270
GLboolean * data
Definition glcorearb.h:298
GLuint GLfloat * val
Definition glcorearb.h:1582
GLuint GLsizei const GLchar * message
Definition glcorearb.h:2517
GLboolean r
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition glcorearb.h:2514
GLuint id
Definition glcorearb.h:650
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
void attachShmMessage(void *hitsptr, fair::mq::Channel &channel, fair::mq::Parts &parts, bool *busy_ptr)
Definition Detector.cxx:223
ECut
cuts available
EProc
processes available
void * decodeTMessageCore(fair::mq::Parts &dataparts, int index)
Definition Detector.cxx:255
void attachMessageBufferToParts(fair::mq::Parts &parts, fair::mq::Channel &channel, void *data, TClass *cl)
Definition Detector.cxx:207
void * decodeShmCore(fair::mq::Parts &dataparts, int index, bool *&busy)
Definition Detector.cxx:240
void attachDetIDHeaderMessage(int id, fair::mq::Channel &channel, fair::mq::Parts &parts)
Definition Detector.cxx:218
static void serialize(o2::framework::FairOutputTBuffer &msg, const TObject *input)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
uint64_t const void const *restrict const msg
Definition x9.h:153