CbmRoot
Loading...
Searching...
No Matches
CbmMvd.cxx
Go to the documentation of this file.
1/* Copyright (C) 2004-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer], Florian Uhlig, Philipp Sitzmann */
4
5// -------------------------------------------------------------------------
6// ----- CbmMvd source file -----
7// ----- Created 26/07/04 by V. Friese -----
8// -------------------------------------------------------------------------
9#include "CbmMvd.h"
10
11#include "CbmDefs.h" // for ToIntegralType, ECbmModuleId
12#include "CbmMvdGeoHandler.h" // for CbmMvdGeoHandler
13#include "CbmMvdPoint.h" // for CbmMvdPoint
14#include "CbmStack.h" // for CbmStack
15
16#include <FairRootManager.h> // for FairRootManager
17#include <FairVolume.h> // for FairVolume
18#include <Logger.h> // for Logger, LOG
19
20#include <TClonesArray.h> // for TClonesArray
21#include <TList.h> // for TList
22#include <TString.h> // for TString, operator<<
23#include <TVirtualMC.h> // for TVirtualMC, gMC
24#include <TVirtualMCStack.h> // for TVirtualMCStack
25
26#include <string> // for allocator
27
28// ----- Default constructor -------------------------------------------
30 // : CbmMvd("MVD", kTRUE, kMvd)
31 : FairDetector("MVD", kTRUE, ToIntegralType(ECbmModuleId::kMvd))
32 , fTrackID(0)
33 , fPdg(0)
34 , fGeoFlag(0)
35 , fVolumeID(0)
36 , fPosIn(0.0, 0.0, 0.0, 0.0)
37 , fPosOut(0.0, 0.0, 0.0, 0.0)
38 , fMomIn(0.0, 0.0, 0.0, 0.0)
39 , fMomOut(0.0, 0.0, 0.0, 0.0)
40 , fTime(0.)
41 , fLength(0.)
42 , fELoss(0.)
43 , fPosIndex(0)
44 , fCollection(new TClonesArray("CbmMvdPoint"))
45 , kGeoSaved(kFALSE)
46 , fGeoPar(new TList())
47 , fStationMap()
48 , fmvdHandler(nullptr)
49{
51 fGeoPar->SetName(GetName());
52 fVerboseLevel = 1;
54}
55// -------------------------------------------------------------------------
56
57
58// ----- Standard constructor ------------------------------------------
59CbmMvd::CbmMvd(const char* name, Bool_t active)
60 : FairDetector(name, active, ToIntegralType(ECbmModuleId::kMvd))
61 , fTrackID(0)
62 , fPdg(0)
63 , fGeoFlag(0)
64 , fVolumeID(0)
65 , fPosIn(0.0, 0.0, 0.0, 0.0)
66 , fPosOut(0.0, 0.0, 0.0, 0.0)
67 , fMomIn(0.0, 0.0, 0.0, 0.0)
68 , fMomOut(0.0, 0.0, 0.0, 0.0)
69 , fTime(0.)
70 , fLength(0.)
71 , fELoss(0.)
72 , fPosIndex(0)
73 , fCollection(new TClonesArray("CbmMvdPoint"))
74 , kGeoSaved(kFALSE)
75 , fGeoPar(new TList())
76 , fStationMap()
77 , fmvdHandler(nullptr)
78{
79 fGeoPar->SetName(GetName());
80 fVerboseLevel = 1;
82}
83// -------------------------------------------------------------------------
84
85
86// ----- Destructor ----------------------------------------------------
88{
89 if (fGeoPar) {
90 fGeoPar->Delete();
91 delete fGeoPar;
92 }
93 if (fCollection) {
94 fCollection->Delete();
95 delete fCollection;
96 }
97}
98// -------------------------------------------------------------------------
99
100
101// ----- Virtual public method ProcessHits ------------------------------
103{
104
105 // Store track parameters at entrance of sensitive volume
106 if (gMC->IsTrackEntering()) {
107 fPdg = gMC->TrackPid();
108 fELoss = 0.;
109 fTime = gMC->TrackTime() * 1.0e09;
110 fLength = gMC->TrackLength();
111 gMC->TrackPosition(fPosIn);
112 gMC->TrackMomentum(fMomIn);
113 }
114
115 // Sum energy loss for all steps in the active volume
116 fELoss += gMC->Edep();
117
118 // Set additional parameters at exit of active volume. Create CbmMvdPoint.
119 if (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) {
120 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
121 gMC->TrackPosition(fPosOut);
122 gMC->TrackMomentum(fMomOut);
123 const char* address = gMC->CurrentVolPath();
124
125 TString stAdd(address);
126
127 if (stAdd.Contains("/MVDscripted_0") || stAdd.Contains("/TwoStation_0") || stAdd.Contains("v25a_mcbm")) {
128 fVolumeID = fmvdHandler->GetIDfromPath(stAdd);
129 }
130 else {
131 fVolumeID = vol->getMCid();
132 }
133 if (fELoss == 0.) return kFALSE;
134 AddHit(fTrackID, fPdg, fStationMap[fVolumeID], TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
135 TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()), TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
136 TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()), fTime, fLength, fELoss);
137
138 // Increment number of MvdPoints for this track
139 CbmStack* stack = (CbmStack*) gMC->GetStack();
141
143 }
144
145 return kTRUE;
146}
147// -------------------------------------------------------------------------
148
149
150// ----- Public method BeginEvent --------------------------------------
152// -------------------------------------------------------------------------
153
154
155// ----- Virtual public method EndOfEvent ------------------------------
157{
158 if (fVerboseLevel) Print();
159 // fCollection->Clear();
160 fCollection->Delete();
162}
163// -------------------------------------------------------------------------
164
165
166// ----- Virtual public method Register --------------------------------
167void CbmMvd::Register() { FairRootManager::Instance()->Register("MvdPoint", GetName(), fCollection, kTRUE); }
168// -------------------------------------------------------------------------
169
170
171// ----- Virtual public method GetCollection ---------------------------
172TClonesArray* CbmMvd::GetCollection(Int_t iColl) const
173{
174 if (iColl == 0) return fCollection;
175 else
176 return nullptr;
177}
178// -------------------------------------------------------------------------
179
180
181// ----- Virtual public method Print -----------------------------------
182void CbmMvd::Print(Option_t*) const
183{
184 Int_t nHits = fCollection->GetEntriesFast();
185 LOG(info) << fName << ": " << nHits << " points registered in this event.";
186}
187// -------------------------------------------------------------------------
188
189
190// ----- Virtual public method Reset -----------------------------------
192{
193 // fCollection->Clear();
194 fCollection->Delete();
196}
197// -------------------------------------------------------------------------
198
199
200// ----- Virtual public method CopyClones ------------------------------
201void CbmMvd::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset)
202{
203 Int_t nEntries = cl1->GetEntriesFast();
204 LOG(info) << "CbmMvd: " << nEntries << " entries to add.";
205 TClonesArray& clref = *cl2;
206 CbmMvdPoint* oldpoint = nullptr;
207 for (Int_t i = 0; i < nEntries; i++) {
208 oldpoint = (CbmMvdPoint*) cl1->At(i);
209 Int_t index = oldpoint->GetTrackID() + offset;
210 oldpoint->SetTrackID(index);
211 new (clref[fPosIndex]) CbmMvdPoint(*oldpoint);
212 fPosIndex++;
213 }
214 LOG(info) << "CbmMvd: " << cl2->GetEntriesFast() << " merged entries.";
215}
216// -------------------------------------------------------------------------
217
218// --------Pulic method ConstructGeometry()-----------------------------------------------------------------
220{
221 TString fileName = GetGeometryFileName();
222 if (fileName.Contains("mcbm")) {
223 fGeoFlag = 1;
224 LOG(info) << "mcbm geometry found ";
225 }
226
227 if (fileName.EndsWith(".root")) {
228 LOG(info) << "Constructing MVD geometry from ROOT file " << fileName.Data();
230 }
231 else if (fileName.EndsWith(".geo")) {
232 LOG(fatal) << "Don't use old .geo style geometrys for the MVD. Please use "
233 "a .root geometry";
234 }
235 else
236 LOG(fatal) << "Geometry format of MVD file " << fileName.Data() << " not supported.";
237}
238
239
240// ----- Virtual public method ConstructAsciiGeometry -----------------------
242// -------------------------------------------------------------------------
243
244// -------- Public method ConstructRootGeometry ---------------------
245//void CbmMvd::ConstructRootGeometry(TGeoMatrix*) // added 05.05.14 by P. Sitzmann
246void CbmMvd::ConstructRootGeometry() // added 05.05.14 by P. Sitzmann
247{
248 LOG(info) << "1";
249 FairDetector::ConstructRootGeometry();
250 LOG(info) << "2";
251 fmvdHandler->Init(kTRUE, fGeoFlag);
252 LOG(info) << "3";
253 fmvdHandler->Fill();
254 LOG(info) << "4";
255 fStationMap = fmvdHandler->GetMap();
256 LOG(info) << "5";
257 LOG(info) << "Station Map size " << fStationMap.size();
258 if (fStationMap.size() == 0) LOG(fatal) << "Tried to load MVD Geometry, but didn't succeed to load Sensors";
259 LOG(info) << "filled mvd StationMap with: " << fStationMap.size() << " new Sensors";
260}
261// -------------------------------------------------------------------------
262
263
264// ----- Private method AddHit --------------------------------------------
265CbmMvdPoint* CbmMvd::AddHit(Int_t trackID, Int_t pdg, Int_t sensorNr, TVector3 posIn, TVector3 posOut, TVector3 momIn,
266 TVector3 momOut, Double_t time, Double_t length, Double_t eLoss)
267{
268 TClonesArray& clref = *fCollection;
269 Int_t size = clref.GetEntriesFast();
270
271 LOG(debug2) << "CbmMvd: Adding Point at (" << posIn.X() << ", " << posIn.Y() << ", " << posIn.Z() << ") cm, sensor "
272 << sensorNr << ", track " << trackID << ", energy loss " << eLoss * 1e06 << " keV";
273 return new (clref[size]) CbmMvdPoint(trackID, pdg, sensorNr, posIn, posOut, momIn, momOut, time, length, eLoss);
274}
275// ----------------------------------------------------------------------------
276
277Bool_t CbmMvd::IsSensitive(const std::string& name)
278{
279 TString tsname = name;
280 if (tsname.Contains("sensorActive") || tsname.Contains("MimosaActive")
281 || (tsname.Contains("mvdstation") && !(tsname.Contains("PartAss")))) {
282 LOG(debug) << "*** Register " << tsname << " as active volume.";
283 return kTRUE;
284 }
285 else if (tsname.EndsWith("-P0")) {
286 // if(fVerboseLevel>1)
287 LOG(debug) << "*** Register " << tsname << " as active volume.";
288
289 return kTRUE;
290 }
291 return kFALSE;
292}
293
294Bool_t CbmMvd::CheckIfSensitive(std::string name) { return IsSensitive(name); }
295// ----------------------------------------------------------------------------
296
297
ClassImp(CbmConverterManager)
XPU_D constexpr auto ToIntegralType(T enumerator) -> typename std::underlying_type< T >::type
Converts an element of enum class to its underlying integral type.
Definition CbmDefs.h:33
ECbmModuleId
Enumerator for module Identifiers.
Definition CbmDefs.h:45
@ kMvd
Micro-Vertex Detector.
Definition CbmDefs.h:47
Helper class to extract information from the GeoManager. Addapted from TrdGeoHandler byFlorian Uhlig ...
static constexpr size_t size()
Definition KfSimdPseudo.h:2
int Int_t
bool Bool_t
TLorentzVector fMomOut
Definition CbmMvd.h:139
virtual void BeginEvent()
Definition CbmMvd.cxx:151
virtual void ConstructAsciiGeometry()
Definition CbmMvd.cxx:241
virtual void ConstructRootGeometry()
Definition CbmMvd.cxx:246
virtual void EndOfEvent()
Definition CbmMvd.cxx:156
Int_t fVolumeID
track particle type
Definition CbmMvd.h:137
virtual Bool_t CheckIfSensitive(std::string name)
Definition CbmMvd.cxx:294
CbmMvdPoint * AddHit(Int_t trackID, Int_t pdg, Int_t sensorNr, TVector3 posIn, TVector3 pos_out, TVector3 momIn, TVector3 momOut, Double_t time, Double_t length, Double_t eLoss)
Definition CbmMvd.cxx:265
Int_t fPdg
track index
Definition CbmMvd.h:136
Double32_t fELoss
length
Definition CbmMvd.h:142
TLorentzVector fPosIn
volume id
Definition CbmMvd.h:138
TLorentzVector fPosOut
Definition CbmMvd.h:138
virtual void Print(Option_t *="") const
Definition CbmMvd.cxx:182
Bool_t kGeoSaved
The hit collection.
Definition CbmMvd.h:146
TList * fGeoPar
Definition CbmMvd.h:147
virtual void ConstructGeometry()
Definition CbmMvd.cxx:219
Double32_t fLength
time
Definition CbmMvd.h:141
CbmMvdGeoHandler * fmvdHandler
Definition CbmMvd.h:151
void ResetParameters()
Definition CbmMvd.h:176
TLorentzVector fMomIn
position
Definition CbmMvd.h:139
virtual TClonesArray * GetCollection(Int_t iColl) const
Definition CbmMvd.cxx:172
TClonesArray * fCollection
Definition CbmMvd.h:145
virtual ~CbmMvd()
Definition CbmMvd.cxx:87
virtual void Reset()
Definition CbmMvd.cxx:191
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Definition CbmMvd.cxx:201
CbmMvd()
Definition CbmMvd.cxx:29
Int_t fGeoFlag
Map from MC volume ID to station number.
Definition CbmMvd.h:149
Int_t fPosIndex
energy loss
Definition CbmMvd.h:144
std::map< Int_t, Int_t > fStationMap
List of geometry parameters.
Definition CbmMvd.h:148
virtual void Register()
Definition CbmMvd.cxx:167
Double32_t fTime
momentum
Definition CbmMvd.h:140
virtual Bool_t ProcessHits(FairVolume *vol=0)
Definition CbmMvd.cxx:102
virtual Bool_t IsSensitive(const std::string &name)
Definition CbmMvd.cxx:277
Int_t fTrackID
Definition CbmMvd.h:135
void AddPoint(ECbmModuleId iDet)
Definition CbmStack.cxx:331