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