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 , fVolumeID(0)
35 , fPosIn(0.0, 0.0, 0.0, 0.0)
36 , fPosOut(0.0, 0.0, 0.0, 0.0)
37 , fMomIn(0.0, 0.0, 0.0, 0.0)
38 , fMomOut(0.0, 0.0, 0.0, 0.0)
39 , fTime(0.)
40 , fLength(0.)
41 , fELoss(0.)
42 , fPosIndex(0)
43 , fCollection(new TClonesArray("CbmMvdPoint"))
44 , kGeoSaved(kFALSE)
45 , fGeoPar(new TList())
46 , fStationMap()
47 , fmvdHandler(nullptr)
48{
50 fGeoPar->SetName(GetName());
51 fVerboseLevel = 1;
53}
54// -------------------------------------------------------------------------
55
56
57// ----- Standard constructor ------------------------------------------
58CbmMvd::CbmMvd(const char* name, Bool_t active)
59 : FairDetector(name, active, ToIntegralType(ECbmModuleId::kMvd))
60 , fTrackID(0)
61 , fPdg(0)
62 , fVolumeID(0)
63 , fPosIn(0.0, 0.0, 0.0, 0.0)
64 , fPosOut(0.0, 0.0, 0.0, 0.0)
65 , fMomIn(0.0, 0.0, 0.0, 0.0)
66 , fMomOut(0.0, 0.0, 0.0, 0.0)
67 , fTime(0.)
68 , fLength(0.)
69 , fELoss(0.)
70 , fPosIndex(0)
71 , fCollection(new TClonesArray("CbmMvdPoint"))
72 , kGeoSaved(kFALSE)
73 , fGeoPar(new TList())
74 , fStationMap()
75 , fmvdHandler(nullptr)
76{
77 fGeoPar->SetName(GetName());
78 fVerboseLevel = 1;
80}
81// -------------------------------------------------------------------------
82
83
84// ----- Destructor ----------------------------------------------------
86{
87 if (fGeoPar) {
88 fGeoPar->Delete();
89 delete fGeoPar;
90 }
91 if (fCollection) {
92 fCollection->Delete();
93 delete fCollection;
94 }
95}
96// -------------------------------------------------------------------------
97
98
99// ----- Virtual public method ProcessHits ------------------------------
101{
102
103
104 // Store track parameters at entrance of sensitive volume
105 if (gMC->IsTrackEntering()) {
106 fPdg = gMC->TrackPid();
107 fELoss = 0.;
108 fTime = gMC->TrackTime() * 1.0e09;
109 fLength = gMC->TrackLength();
110 gMC->TrackPosition(fPosIn);
111 gMC->TrackMomentum(fMomIn);
112 }
113
114 // Sum energy loss for all steps in the active volume
115 fELoss += gMC->Edep();
116
117 // Set additional parameters at exit of active volume. Create CbmMvdPoint.
118 if (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) {
119 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
120 gMC->TrackPosition(fPosOut);
121 gMC->TrackMomentum(fMomOut);
122 const char* address = gMC->CurrentVolPath();
123
124 TString stAdd(address);
125
126 if (stAdd.Contains("/MVDscripted_0") || stAdd.Contains("/TwoStation_0")) {
128 }
129 else {
130 fVolumeID = vol->getMCid();
131 }
132 if (fELoss == 0.) return kFALSE;
133 AddHit(fTrackID, fPdg, fStationMap[fVolumeID], TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
134 TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()), TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
135 TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()), fTime, fLength, fELoss);
136
137 // Increment number of MvdPoints for this track
138 CbmStack* stack = (CbmStack*) gMC->GetStack();
140
142 }
143
144 return kTRUE;
145}
146// -------------------------------------------------------------------------
147
148
149// ----- Public method BeginEvent --------------------------------------
151// -------------------------------------------------------------------------
152
153
154// ----- Virtual public method EndOfEvent ------------------------------
156{
157 if (fVerboseLevel) Print();
158 // fCollection->Clear();
159 fCollection->Delete();
161}
162// -------------------------------------------------------------------------
163
164
165// ----- Virtual public method Register --------------------------------
166void CbmMvd::Register() { FairRootManager::Instance()->Register("MvdPoint", GetName(), fCollection, kTRUE); }
167// -------------------------------------------------------------------------
168
169
170// ----- Virtual public method GetCollection ---------------------------
171TClonesArray* CbmMvd::GetCollection(Int_t iColl) const
172{
173 if (iColl == 0) return fCollection;
174 else
175 return nullptr;
176}
177// -------------------------------------------------------------------------
178
179
180// ----- Virtual public method Print -----------------------------------
181void CbmMvd::Print(Option_t*) const
182{
183 Int_t nHits = fCollection->GetEntriesFast();
184 LOG(info) << fName << ": " << nHits << " points registered in this event.";
185}
186// -------------------------------------------------------------------------
187
188
189// ----- Virtual public method Reset -----------------------------------
191{
192 // fCollection->Clear();
193 fCollection->Delete();
195}
196// -------------------------------------------------------------------------
197
198
199// ----- Virtual public method CopyClones ------------------------------
200void CbmMvd::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset)
201{
202 Int_t nEntries = cl1->GetEntriesFast();
203 LOG(info) << "CbmMvd: " << nEntries << " entries to add.";
204 TClonesArray& clref = *cl2;
205 CbmMvdPoint* oldpoint = nullptr;
206 for (Int_t i = 0; i < nEntries; i++) {
207 oldpoint = (CbmMvdPoint*) cl1->At(i);
208 Int_t index = oldpoint->GetTrackID() + offset;
209 oldpoint->SetTrackID(index);
210 new (clref[fPosIndex]) CbmMvdPoint(*oldpoint);
211 fPosIndex++;
212 }
213 LOG(info) << "CbmMvd: " << cl2->GetEntriesFast() << " merged entries.";
214}
215// -------------------------------------------------------------------------
216
217// --------Pulic method ConstructGeometry()-----------------------------------------------------------------
219{
220 TString fileName = GetGeometryFileName();
221 if (fileName.EndsWith(".root")) {
222 LOG(info) << "Constructing MVD geometry from ROOT file " << fileName.Data();
224 }
225 else if (fileName.EndsWith(".geo")) {
226 LOG(fatal) << "Don't use old .geo style geometrys for the MVD. Please use "
227 "a .root geometry";
228 }
229 else
230 LOG(fatal) << "Geometry format of MVD file " << fileName.Data() << " not supported.";
231}
232
233
234// ----- Virtual public method ConstructAsciiGeometry -----------------------
236// -------------------------------------------------------------------------
237
238// -------- Public method ConstructRootGeometry ---------------------
239void CbmMvd::ConstructRootGeometry(TGeoMatrix*) // added 05.05.14 by P. Sitzmann
240{
241 FairDetector::ConstructRootGeometry();
242 fmvdHandler->Init(kTRUE);
243 fmvdHandler->Fill();
245 if (fStationMap.size() == 0) LOG(fatal) << "Tried to load MVD Geometry, but didn't succeed to load Sensors";
246 LOG(debug) << "filled mvd StationMap with: " << fStationMap.size() << " new Sensors";
247}
248// -------------------------------------------------------------------------
249
250
251// ----- Private method AddHit --------------------------------------------
252CbmMvdPoint* CbmMvd::AddHit(Int_t trackID, Int_t pdg, Int_t sensorNr, TVector3 posIn, TVector3 posOut, TVector3 momIn,
253 TVector3 momOut, Double_t time, Double_t length, Double_t eLoss)
254{
255 TClonesArray& clref = *fCollection;
256 Int_t size = clref.GetEntriesFast();
257
258 LOG(debug2) << "CbmMvd: Adding Point at (" << posIn.X() << ", " << posIn.Y() << ", " << posIn.Z() << ") cm, sensor "
259 << sensorNr << ", track " << trackID << ", energy loss " << eLoss * 1e06 << " keV";
260 return new (clref[size]) CbmMvdPoint(trackID, pdg, sensorNr, posIn, posOut, momIn, momOut, time, length, eLoss);
261}
262// ----------------------------------------------------------------------------
263
264Bool_t CbmMvd::IsSensitive(const std::string& name)
265{
266 TString tsname = name;
267 if (tsname.Contains("sensorActive") || tsname.Contains("MimosaActive")
268 || (tsname.Contains("mvdstation") && !(tsname.Contains("PartAss")))) {
269 LOG(debug) << "*** Register " << tsname << " as active volume.";
270 return kTRUE;
271 }
272 else if (tsname.EndsWith("-P0")) {
273 // if(fVerboseLevel>1)
274 LOG(debug) << "*** Register " << tsname << " as active volume.";
275
276 return kTRUE;
277 }
278 return kFALSE;
279}
280
281Bool_t CbmMvd::CheckIfSensitive(std::string name) { return IsSensitive(name); }
282// ----------------------------------------------------------------------------
283
284
ClassImp(CbmConverterManager)
XPU_D constexpr auto ToIntegralType(T enumerator) -> typename std::underlying_type< T >::type
Definition CbmDefs.h:29
ECbmModuleId
Definition CbmDefs.h:39
@ kMvd
Micro-Vertex Detector.
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
void Init(Bool_t isSimulation=kFALSE)
Int_t GetIDfromPath(TString path)
std::map< Int_t, Int_t > GetMap()
TLorentzVector fMomOut
Definition CbmMvd.h:138
virtual void BeginEvent()
Definition CbmMvd.cxx:150
virtual void ConstructAsciiGeometry()
Definition CbmMvd.cxx:235
virtual void EndOfEvent()
Definition CbmMvd.cxx:155
Int_t fVolumeID
track particle type
Definition CbmMvd.h:136
virtual Bool_t CheckIfSensitive(std::string name)
Definition CbmMvd.cxx:281
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:252
Int_t fPdg
track index
Definition CbmMvd.h:135
Double32_t fELoss
length
Definition CbmMvd.h:141
TLorentzVector fPosIn
volume id
Definition CbmMvd.h:137
TLorentzVector fPosOut
Definition CbmMvd.h:137
virtual void Print(Option_t *="") const
Definition CbmMvd.cxx:181
TList * fGeoPar
Definition CbmMvd.h:146
virtual void ConstructGeometry()
Definition CbmMvd.cxx:218
Double32_t fLength
time
Definition CbmMvd.h:140
CbmMvdGeoHandler * fmvdHandler
Map from MC volume ID to station number.
Definition CbmMvd.h:149
void ResetParameters()
Definition CbmMvd.h:174
TLorentzVector fMomIn
position
Definition CbmMvd.h:138
virtual TClonesArray * GetCollection(Int_t iColl) const
Definition CbmMvd.cxx:171
TClonesArray * fCollection
Definition CbmMvd.h:144
virtual ~CbmMvd()
Definition CbmMvd.cxx:85
virtual void Reset()
Definition CbmMvd.cxx:190
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Definition CbmMvd.cxx:200
CbmMvd()
Definition CbmMvd.cxx:29
Int_t fPosIndex
energy loss
Definition CbmMvd.h:143
std::map< Int_t, Int_t > fStationMap
List of geometry parameters.
Definition CbmMvd.h:147
virtual void Register()
Definition CbmMvd.cxx:166
Double32_t fTime
momentum
Definition CbmMvd.h:139
virtual void ConstructRootGeometry(TGeoMatrix *shift=nullptr)
Definition CbmMvd.cxx:239
virtual Bool_t ProcessHits(FairVolume *vol=0)
Definition CbmMvd.cxx:100
virtual Bool_t IsSensitive(const std::string &name)
Definition CbmMvd.cxx:264
Int_t fTrackID
Definition CbmMvd.h:134
void AddPoint(ECbmModuleId iDet)
Definition CbmStack.cxx:331