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