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 ------------------------------
100Bool_t CbmMvd::ProcessHits(FairVolume* vol)
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")) { fVolumeID = fmvdHandler->GetIDfromPath(stAdd); }
127 else {
128 fVolumeID = vol->getMCid();
129 }
130 if (fELoss == 0.) return kFALSE;
131 AddHit(fTrackID, fPdg, fStationMap[fVolumeID], TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
132 TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()), TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
133 TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()), fTime, fLength, fELoss);
134
135 // Increment number of MvdPoints for this track
136 CbmStack* stack = (CbmStack*) gMC->GetStack();
138
140 }
141
142 return kTRUE;
143}
144// -------------------------------------------------------------------------
145
146
147// ----- Public method BeginEvent --------------------------------------
149// -------------------------------------------------------------------------
150
151
152// ----- Virtual public method EndOfEvent ------------------------------
154{
155 if (fVerboseLevel) Print();
156 // fCollection->Clear();
157 fCollection->Delete();
159}
160// -------------------------------------------------------------------------
161
162
163// ----- Virtual public method Register --------------------------------
164void CbmMvd::Register() { FairRootManager::Instance()->Register("MvdPoint", GetName(), fCollection, kTRUE); }
165// -------------------------------------------------------------------------
166
167
168// ----- Virtual public method GetCollection ---------------------------
169TClonesArray* CbmMvd::GetCollection(Int_t iColl) const
170{
171 if (iColl == 0) return fCollection;
172 else
173 return nullptr;
174}
175// -------------------------------------------------------------------------
176
177
178// ----- Virtual public method Print -----------------------------------
179void CbmMvd::Print(Option_t*) const
180{
181 Int_t nHits = fCollection->GetEntriesFast();
182 LOG(info) << fName << ": " << nHits << " points registered in this event.";
183}
184// -------------------------------------------------------------------------
185
186
187// ----- Virtual public method Reset -----------------------------------
189{
190 // fCollection->Clear();
191 fCollection->Delete();
193}
194// -------------------------------------------------------------------------
195
196
197// ----- Virtual public method CopyClones ------------------------------
198void CbmMvd::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset)
199{
200 Int_t nEntries = cl1->GetEntriesFast();
201 LOG(info) << "CbmMvd: " << nEntries << " entries to add.";
202 TClonesArray& clref = *cl2;
203 CbmMvdPoint* oldpoint = nullptr;
204 for (Int_t i = 0; i < nEntries; i++) {
205 oldpoint = (CbmMvdPoint*) cl1->At(i);
206 Int_t index = oldpoint->GetTrackID() + offset;
207 oldpoint->SetTrackID(index);
208 new (clref[fPosIndex]) CbmMvdPoint(*oldpoint);
209 fPosIndex++;
210 }
211 LOG(info) << "CbmMvd: " << cl2->GetEntriesFast() << " merged entries.";
212}
213// -------------------------------------------------------------------------
214
215// --------Pulic method ConstructGeometry()-----------------------------------------------------------------
217{
218 TString fileName = GetGeometryFileName();
219 if (fileName.EndsWith(".root")) {
220 LOG(info) << "Constructing MVD geometry from ROOT file " << fileName.Data();
222 }
223 else if (fileName.EndsWith(".geo")) {
224 LOG(fatal) << "Don't use old .geo style geometrys for the MVD. Please use "
225 "a .root geometry";
226 }
227 else
228 LOG(fatal) << "Geometry format of MVD file " << fileName.Data() << " not supported.";
229}
230
231
232// ----- Virtual public method ConstructAsciiGeometry -----------------------
234// -------------------------------------------------------------------------
235
236// -------- Public method ConstructRootGeometry ---------------------
237void CbmMvd::ConstructRootGeometry(TGeoMatrix*) // added 05.05.14 by P. Sitzmann
238{
239 FairDetector::ConstructRootGeometry();
240 fmvdHandler->Init(kTRUE);
241 fmvdHandler->Fill();
243 if (fStationMap.size() == 0) LOG(fatal) << "Tried to load MVD Geometry, but didn't succeed to load Sensors";
244 LOG(debug) << "filled mvd StationMap with: " << fStationMap.size() << " new Sensors";
245}
246// -------------------------------------------------------------------------
247
248
249// ----- Private method AddHit --------------------------------------------
250CbmMvdPoint* CbmMvd::AddHit(Int_t trackID, Int_t pdg, Int_t sensorNr, TVector3 posIn, TVector3 posOut, TVector3 momIn,
251 TVector3 momOut, Double_t time, Double_t length, Double_t eLoss)
252{
253 TClonesArray& clref = *fCollection;
254 Int_t size = clref.GetEntriesFast();
255
256 LOG(debug2) << "CbmMvd: Adding Point at (" << posIn.X() << ", " << posIn.Y() << ", " << posIn.Z() << ") cm, sensor "
257 << sensorNr << ", track " << trackID << ", energy loss " << eLoss * 1e06 << " keV";
258 return new (clref[size]) CbmMvdPoint(trackID, pdg, sensorNr, posIn, posOut, momIn, momOut, time, length, eLoss);
259}
260// ----------------------------------------------------------------------------
261
262Bool_t CbmMvd::IsSensitive(const std::string& name)
263{
264 TString tsname = name;
265 if (tsname.Contains("sensorActive") || tsname.Contains("MimosaActive")
266 || (tsname.Contains("mvdstation") && !(tsname.Contains("PartAss")))) {
267 LOG(debug) << "*** Register " << tsname << " as active volume.";
268 return kTRUE;
269 }
270 else if (tsname.EndsWith("-P0")) {
271 // if(fVerboseLevel>1)
272 LOG(debug) << "*** Register " << tsname << " as active volume.";
273
274 return kTRUE;
275 }
276 return kFALSE;
277}
278
279Bool_t CbmMvd::CheckIfSensitive(std::string name) { return IsSensitive(name); }
280// ----------------------------------------------------------------------------
281
282
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
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:148
virtual void ConstructAsciiGeometry()
Definition CbmMvd.cxx:233
virtual void EndOfEvent()
Definition CbmMvd.cxx:153
Int_t fVolumeID
track particle type
Definition CbmMvd.h:136
virtual Bool_t CheckIfSensitive(std::string name)
Definition CbmMvd.cxx:279
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:250
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:179
TList * fGeoPar
Definition CbmMvd.h:146
virtual void ConstructGeometry()
Definition CbmMvd.cxx:216
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:169
TClonesArray * fCollection
Definition CbmMvd.h:144
virtual ~CbmMvd()
Definition CbmMvd.cxx:85
virtual void Reset()
Definition CbmMvd.cxx:188
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Definition CbmMvd.cxx:198
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:164
Double32_t fTime
momentum
Definition CbmMvd.h:139
virtual void ConstructRootGeometry(TGeoMatrix *shift=nullptr)
Definition CbmMvd.cxx:237
virtual Bool_t ProcessHits(FairVolume *vol=0)
Definition CbmMvd.cxx:100
virtual Bool_t IsSensitive(const std::string &name)
Definition CbmMvd.cxx:262
Int_t fTrackID
Definition CbmMvd.h:134
void AddPoint(ECbmModuleId iDet)
Definition CbmStack.cxx:331