CbmRoot
Loading...
Searching...
No Matches
CbmTrd.cxx
Go to the documentation of this file.
1/* Copyright (C) 2004-2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese, Florian Uhlig [committer], Andrey Lebedev, Adrian Meyer-Ahrens, David Emschermann */
4
11#include "CbmTrd.h"
12
13#include "CbmGeometryUtils.h"
14#include "CbmStack.h"
15#include "CbmTrdGeoHandler.h"
16#include "CbmTrdPoint.h"
17
18#include "FairGeoInterface.h"
19#include "FairGeoLoader.h"
20#include "FairGeoMedia.h"
21#include "FairGeoNode.h"
22#include "FairGeoVolume.h"
23#include "FairRootManager.h"
24#include "FairRun.h"
25#include "FairRuntimeDb.h"
26#include "FairVolume.h"
27#include <Logger.h>
28
29#include "TClonesArray.h"
30#include "TGeoManager.h"
31#include "TGeoMaterial.h"
32#include "TGeoMatrix.h"
33#include "TMath.h"
34#include "TObjArray.h"
35#include "TVirtualMC.h"
36
37// ----- Default constructor ----------------------------------------------
39 : FairDetector("TRD", kTRUE, ToIntegralType(ECbmModuleId::kTrd))
40 , fPosIn()
41 , fMomIn()
42 , fPosOut()
43 , fMomOut()
44 , fTime(0)
45 , fLength(0)
46 , fELoss(0)
47 , fPosIndex(0)
48 , fTrdPoints(new TClonesArray("CbmTrdPoint"))
49 , fGeoHandler(new CbmTrdGeoHandler())
50 , fUseGlobalPhysicsProcesses(kFALSE)
51 , fCombiTrans(nullptr)
52{
53 fVerboseLevel = 1;
54}
55// ----------------------------------------------------------------------------
56
57
58// ----- Standard constructor ---------------------------------------------
59CbmTrd::CbmTrd(const char* name, Bool_t active)
60 : FairDetector(name, active, ToIntegralType(ECbmModuleId::kTrd))
61 , fPosIn()
62 , fMomIn()
63 , fPosOut()
64 , fMomOut()
65 , fTime(0)
66 , fLength(0)
67 , fELoss(0)
68 , fPosIndex(0)
69 , fTrdPoints(new TClonesArray("CbmTrdPoint"))
70 , fGeoHandler(new CbmTrdGeoHandler())
71 , fUseGlobalPhysicsProcesses(kFALSE)
72 , fCombiTrans(nullptr)
73{
74 fVerboseLevel = 1;
75}
76// ----------------------------------------------------------------------------
77
78
79// ----- Destructor -------------------------------------------------------
81{
82 if (fTrdPoints) {
83 fTrdPoints->Delete();
84 delete fTrdPoints;
85 }
86 if (fGeoHandler) { delete fGeoHandler; }
87}
88// ----------------------------------------------------------------------------
89
90
91// ----- Initialize -------------------------------------------------------
93{
94 FairDetector::Initialize();
95
96 // Initialize the CbmTrdGeoHandler helper class from the
97 // TVirtualMC interface
98 Bool_t isSimulation = kTRUE;
99 fGeoHandler->Init(isSimulation);
100}
101// ----------------------------------------------------------------------------
102
103
104// ----- SetSpecialPhysicsCuts --------------------------------------------
106{
107 FairRun* fRun = FairRun::Instance();
108
109 // Setting the properties for the TRDgas is only tested
110 // with TGeant3, so we check for the simulation engine
111 // and change the standard properties only for TGeant3
112 if (strcmp(fRun->GetName(), "TGeant3") == 0) {
113
114 // Get Material Id and some material properties from
115 // the geomanager
116 Int_t mat = gGeoManager->GetMaterialIndex("TRDgas");
117 TGeoMaterial* trdgas = gGeoManager->GetMaterial(mat);
118 trdgas->Print();
119 Double_t mass = trdgas->GetA();
120 Double_t charge = trdgas->GetZ();
121
122 // Get the material properties for material with id+1
123 // (of-by-one problem) from the Virtual Monte Carlo
124 Int_t matIdVMC = mat + 1;
125
126 TString name = "";
127 Double_t a = 0.;
128 Double_t z = 0.;
129 Double_t dens = 0.;
130 Double_t radl = 0.;
131 Double_t inter = 0.;
132 TArrayD par;
133
134 gMC->GetMaterial(matIdVMC, name, a, z, dens, radl, inter, par);
135
136 // Check if the material properties are the same for TGeoManager
137 // and TVirtualMC. If not stop the execution of the simulation.
138 // This is done to stop the program whenever the
139 // of-by-one problem is fixed in the Virtual Monte Carlo
140 if ((TMath::Abs(mass - a) > 0.0001) || (TMath::Abs(charge - z)) > 0.0001) {
141 LOG(fatal) << "**********************************";
142 LOG(fatal) << TMath::Abs(mass - a) << " , " << TMath::Abs(charge - z);
143 LOG(fatal) << "Parameters from Geomanager:";
144 trdgas->Print();
145 LOG(fatal) << "Parameters from Virtual Montecarlo:";
146 LOG(fatal) << "Name " << name << " Aeff=" << a << " Zeff=" << z;
147 Fatal("CbmTrd::SetSpecialPhysicsCuts", "Material parameters different between TVirtualMC and TGeomanager");
148 }
149
150 // Set new properties, physics cuts etc. for the TRDgas
152 LOG(info) << "Using special parameters for TRDgas";
153 gMC->Gstpar(matIdVMC, "STRA", 1.0);
154 gMC->Gstpar(matIdVMC, "PAIR", 1.0);
155 gMC->Gstpar(matIdVMC, "COMP", 1.0);
156 gMC->Gstpar(matIdVMC, "PHOT", 1.0);
157 gMC->Gstpar(matIdVMC, "LOSS", 2.0);
158 //gMC->Gstpar(matIdVMC,"PFIS",0.0);
159 gMC->Gstpar(matIdVMC, "ANNI", 1.0);
160 gMC->Gstpar(matIdVMC, "BREM", 1.0);
161 gMC->Gstpar(matIdVMC, "HADR", 1.0);
162 //gMC->Gstpar(matIdVMC,"MUNU",1.0);
163 gMC->Gstpar(matIdVMC, "DCAY", 1.0);
164 gMC->Gstpar(matIdVMC, "MULS", 1.0);
165 //gMC->Gstpar(matIdVMC,"LABS",0.0);
166 gMC->Gstpar(matIdVMC, "DRAY", 1.0);
167 gMC->Gstpar(matIdVMC, "RAYL", 1.0);
168 }
169 else
170 LOG(info) << "!! Using global parameters for TRDgas";
171
172 // cut values
173 gMC->Gstpar(matIdVMC, "CUTELE", 10.e-6);
174 gMC->Gstpar(matIdVMC, "CUTGAM", 10.e-6);
175 gMC->Gstpar(matIdVMC, "CUTNEU", 10.e-4);
176 gMC->Gstpar(matIdVMC, "CUTHAD", 10.e-4);
177 gMC->Gstpar(matIdVMC, "CUTMUO", 10.e-6);
178 gMC->Gstpar(matIdVMC, "BCUTE", 10.e-6);
179 gMC->Gstpar(matIdVMC, "BCUTM", 10.e-6);
180 gMC->Gstpar(matIdVMC, "DCUTE", 10.e-6);
181 gMC->Gstpar(matIdVMC, "DCUTM", 10.e-6);
182 gMC->Gstpar(matIdVMC, "PPCUTM", -1.);
183 }
184}
185// ----------------------------------------------------------------------------
186
187
188// ----- Public method ProcessHits ----------------------------------------
189Bool_t CbmTrd::ProcessHits(FairVolume*)
190{
191 // Set parameters at entrance of volume. Reset ELoss.
192 if (gMC->IsTrackEntering()) {
193 fELoss = 0.;
194 fTime = gMC->TrackTime() * 1.0e09;
195 fLength = gMC->TrackLength();
196 gMC->TrackPosition(fPosIn);
197 gMC->TrackMomentum(fMomIn);
198 }
199
200 // Sum energy loss for all steps in the active volume
201 fELoss += gMC->Edep();
202
203 // Create CbmTrdPoint at exit of active volume
204 if (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) {
205
206 gMC->TrackPosition(fPosOut);
207 gMC->TrackMomentum(fMomOut);
208
209 if (fELoss == 0.) return kFALSE; // no neutrals
210
211 Int_t trackId = gMC->GetStack()->GetCurrentTrackNumber();
212 Int_t moduleAddress = fGeoHandler->GetModuleAddress();
213
214 Int_t size = fTrdPoints->GetEntriesFast();
215 new ((*fTrdPoints)[size])
216 CbmTrdPoint(trackId, moduleAddress, TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
217 TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()), TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()),
218 TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()), fTime, fLength, fELoss);
219
220 // Increment number of trd points in TParticle
221 CbmStack* stack = (CbmStack*) gMC->GetStack();
223
225 }
226
227 return kTRUE;
228}
229// ----------------------------------------------------------------------------
230
231
232// ----- Public method EndOfEvent -----------------------------------------
234{
235 if (fVerboseLevel) Print();
236 fTrdPoints->Delete();
237 fPosIndex = 0;
238}
239// ----------------------------------------------------------------------------
240
241
242// ----- Public method Register -------------------------------------------
243void CbmTrd::Register() { FairRootManager::Instance()->Register("TrdPoint", "Trd", fTrdPoints, kTRUE); }
244// ----------------------------------------------------------------------------
245
246
247// ----- Public method GetCollection --------------------------------------
248TClonesArray* CbmTrd::GetCollection(Int_t iColl) const
249{
250 if (iColl == 0) return fTrdPoints;
251 else
252 return NULL;
253}
254// ----------------------------------------------------------------------------
255
256
257// ----- Public method Print ----------------------------------------------
258void CbmTrd::Print(Option_t*) const
259{
260 Int_t nHits = fTrdPoints->GetEntriesFast();
261 LOG(info) << fName << ": " << nHits << " points registered in this event.";
262
263 if (fVerboseLevel > 1) {
264 for (Int_t i = 0; i < nHits; i++) {
265 (*fTrdPoints)[i]->Print();
266 }
267 }
268}
269// ----------------------------------------------------------------------------
270
271
272// ----- Public method Reset ----------------------------------------------
274{
275 fTrdPoints->Delete();
277}
278// ----------------------------------------------------------------------------
279
280
281// ----- Public method CopyClones -----------------------------------------
282void CbmTrd::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset)
283{
284 Int_t nEntries = cl1->GetEntriesFast();
285 LOG(info) << "CbmTrd: " << nEntries << " entries to add.";
286 TClonesArray& clref = *cl2;
287 for (Int_t i = 0; i < nEntries; i++) {
288 CbmTrdPoint* oldpoint = (CbmTrdPoint*) cl1->At(i);
289 Int_t index = oldpoint->GetTrackID() + offset;
290 oldpoint->SetTrackID(index);
291 new (clref[fPosIndex]) CbmTrdPoint(*oldpoint);
292 fPosIndex++;
293 }
294 LOG(info) << "CbmTrd: " << cl2->GetEntriesFast() << " merged entries.";
295}
296// ----------------------------------------------------------------------------
297
298
299// ----- ConstructGeometry --------------------------------------------------
301{
302 TString fileName = GetGeometryFileName();
303 if (fileName.EndsWith(".root")) { ConstructRootGeometry(); }
304 else {
305 LOG(fatal) << "Geometry format of TRD file " << fileName.Data() << " not supported.";
306 }
307}
308// ----------------------------------------------------------------------------
309
310//__________________________________________________________________________
312{
314 LOG(info) << "Importing TRD geometry from ROOT file " << fgeoName.Data();
316 }
317 else {
318 LOG(info) << "Constructing TRD geometry from ROOT file " << fgeoName.Data();
319 FairModule::ConstructRootGeometry();
320 }
321}
322
323// ----- CheckIfSensitive -------------------------------------------------
324Bool_t CbmTrd::IsSensitive(const std::string& name)
325{
326 TString tsname = name;
327 if (tsname.EqualTo("gas")) {
328 LOG(debug) << "CbmTrd::CheckIfSensitive: Register active volume: " << tsname;
329 return kTRUE;
330 }
331 return kFALSE;
332}
333// ----------------------------------------------------------------------------
334
335Bool_t CbmTrd::CheckIfSensitive(std::string name) { return IsSensitive(name); }
336
ClassImp(CbmConverterManager)
XPU_D constexpr auto ToIntegralType(T enumerator) -> typename std::underlying_type< T >::type
Definition CbmDefs.h:29
ECbmModuleId
Definition CbmDefs.h:39
@ kTrd
Transition Radiation Detector.
Helper class to extract information from the GeoManager.
Defines the active detector TRD. Constructs the geometry and registers MCPoints.
static constexpr size_t size()
Definition KfSimdPseudo.h:2
void AddPoint(ECbmModuleId iDet)
Definition CbmStack.cxx:331
void Init(Bool_t isSimulation=kFALSE)
Int_t GetModuleAddress()
Return module address calculated based on the current node in the TGeoManager.
Defines the active detector TRD. Constructs the geometry and registers MCPoints.
Definition CbmTrd.h:34
Bool_t CheckIfSensitive(std::string name)
Definition CbmTrd.cxx:335
TGeoMatrix * fCombiTrans
weather to follow the global switch for physics cuts for the TRDgas
Definition CbmTrd.h:125
virtual void EndOfEvent()
If verbosity level is set, print hit collection at the end of the event and resets it afterwards.
Definition CbmTrd.cxx:233
Double32_t fLength
time
Definition CbmTrd.h:116
virtual void Print(Option_t *="") const
Screen output of hit collection.
Definition CbmTrd.cxx:258
TLorentzVector fMomIn
position at entrance
Definition CbmTrd.h:112
CbmTrdGeoHandler * fGeoHandler
MC point collection.
Definition CbmTrd.h:121
virtual Bool_t IsSensitive(const std::string &name)
Definition CbmTrd.cxx:324
Bool_t fUseGlobalPhysicsProcesses
Interface to gMC and gGeoManager.
Definition CbmTrd.h:123
virtual void ConstructGeometry()
Constructs the TRD geometry.
Definition CbmTrd.cxx:300
virtual void Reset()
Clears the hit collection.
Definition CbmTrd.cxx:273
virtual ~CbmTrd()
Destructor.
Definition CbmTrd.cxx:80
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Copies the hit collection with a given track index offset.
Definition CbmTrd.cxx:282
CbmTrd()
Default constructor.
Definition CbmTrd.cxx:38
Double32_t fELoss
length
Definition CbmTrd.h:117
void ResetParameters()
Transformation matrix for geometry positioning.
Definition CbmTrd.h:141
virtual void ConstructRootGeometry(TGeoMatrix *shift=NULL)
Definition CbmTrd.cxx:311
TLorentzVector fMomOut
position at exit
Definition CbmTrd.h:114
virtual TClonesArray * GetCollection(Int_t iColl) const
Accessor to the hit collection.
Definition CbmTrd.cxx:248
virtual void SetSpecialPhysicsCuts()
Definition CbmTrd.cxx:105
virtual void Register()
Registers the hit collection in the ROOT manager.
Definition CbmTrd.cxx:243
TClonesArray * fTrdPoints
position index
Definition CbmTrd.h:120
Double32_t fTime
momentum at exit
Definition CbmTrd.h:115
virtual void Initialize()
Definition CbmTrd.cxx:92
Int_t fPosIndex
energy loss
Definition CbmTrd.h:118
TLorentzVector fPosOut
momentum at entrance
Definition CbmTrd.h:113
virtual Bool_t ProcessHits(FairVolume *vol=NULL)
Defines the action to be taken when a step is inside the active volume. Creates CbmTrdPoints and adds...
Definition CbmTrd.cxx:189
TLorentzVector fPosIn
Definition CbmTrd.h:111
Bool_t IsNewGeometryFile(TString &filename)
void ImportRootGeometry(TString &filename, FairModule *mod, TGeoMatrix *mat)