CbmRoot
Loading...
Searching...
No Matches
CbmMust.cxx
Go to the documentation of this file.
1/* Copyright (C) 2025 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Radoslaw Karabowicz [committer] */
4
6// CbmMust source file
7//
8// Class for simulation of MUST
9//
10// authors: Radoslaw Karabowicz, GSI, 2024
11//
12// modified from CbmMust by Nafija Ibrisimovic in 2023
14
15#include "CbmMust.h"
16
17#include "CbmDefs.h"
18#include "CbmGeometryUtils.h"
19#include "CbmMustAddress.h"
20#include "CbmStack.h"
21
22#include <FairGeoInterface.h>
23#include <FairGeoLoader.h>
24#include <FairGeoNode.h>
25#include <FairGeoRootBuilder.h>
26#include <FairLogger.h>
27#include <FairRootManager.h>
28#include <FairRun.h>
29#include <FairRuntimeDb.h>
30#include <FairVolume.h>
31
32#include <TClonesArray.h>
33#include <TGeoMatrix.h>
34#include <TGeoMedium.h>
35#include <TGeoTube.h>
36#include <TGeoVolume.h>
37#include <TLorentzVector.h>
38#include <TObjArray.h>
39#include <TParticle.h>
40#include <TVirtualMC.h>
41
42#include <iostream>
43
44using std::string;
45
46// ----- Default constructor -------------------------------------------
48// -------------------------------------------------------------------------
49
50// ----- Standard constructor ------------------------------------------
51CbmMust::CbmMust(const char* name, Bool_t active) : FairDetector(name, active) { fVerboseLevel = 0; }
52// -------------------------------------------------------------------------
53
54// ----- Destructor ----------------------------------------------------
56{
57 if (fMustPoints) {
58 fMustPoints->Delete();
59 delete fMustPoints;
60 }
61}
62// -------------------------------------------------------------------------
63
64// ----- Public method ProcessHits --------------------------------------
66{
67
68 if (TVirtualMC::GetMC()->TrackCharge() != 0.) {
69
70 if (TVirtualMC::GetMC()->IsTrackEntering()) {
71 fTrackValid = kTRUE;
72
73 // Set parameters at entrance of volume. Reset ELoss.
74 fELoss = 0.;
75 TVirtualMC::GetMC()->TrackPosition(fPosIn);
76 TVirtualMC::GetMC()->TrackMomentum(fMomIn);
77 }
78
79 // Sum energy loss for all steps in the active volume
80 fELoss += TVirtualMC::GetMC()->Edep();
81
82 // Create CbmMustPoint at exit of active volume -- but not into the wire
83 if (TVirtualMC::GetMC()->IsTrackExiting() && fTrackValid == kTRUE) {
84 fTrackValid = kFALSE;
85 int trackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber();
86
87 if (trackID != 0) {
88 if (fVerboseLevel > 2) LOG(info) << "[MUST] test Vol----------" << vol->getMCid();
89 if (fVerboseLevel > 2) LOG(info) << "trackID-----" << trackID;
90 }
91
92 double trackTime = TVirtualMC::GetMC()->TrackTime() * 1.0e09;
93 double trackLength = TVirtualMC::GetMC()->TrackLength();
94 TLorentzVector posOut{0, 0, 0, 0};
95 TLorentzVector momOut{0, 0, 0, 0};
96 TVirtualMC::GetMC()->TrackPosition(posOut);
97 TVirtualMC::GetMC()->TrackMomentum(momOut);
98
99 string volPath(TVirtualMC::GetMC()->CurrentVolPath());
100
101 LOG(debug) << " --> " << volPath;
102 string tubeName = volPath.substr(volPath.find("strawAssembly_") + 14, 8);
103 int statId = 0;
104 int layerId = atoi(tubeName.substr(1, 2).c_str()) - 1;
105 int moduleId = atoi(tubeName.substr(3, 2).c_str()) - 1;
106 int tubeId = atoi(tubeName.substr(5, 3).c_str()) - 1;
107
108 uint32_t address = CbmMustAddress::GetAddress(statId, layerId, moduleId, tubeId);
109
110 LOG(debug) << " l/m/t = " << layerId << "/" << moduleId << "/" << tubeId;
111
112 AddPoint(trackID, address, TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
113 TVector3(posOut.X(), posOut.Y(), posOut.Z()), TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
114 TVector3(momOut.Px(), momOut.Py(), momOut.Pz()), trackTime, trackLength, fELoss);
115
116 if (trackID != 0) {
117 if (fVerboseLevel > 2) LOG(info) << "AddPoint CbmMust.cxx= " << trackID;
118 }
119
120 // Increment number of stt points for TParticle
121 CbmStack* stack = static_cast<CbmStack*>(TVirtualMC::GetMC()->GetStack());
124 }
125 }
126
127 return kTRUE;
128}
129// -------------------------------------------------------------------------
130
131// ----- Public method EndOfEvent --------------------------------------
133{
134 if (fVerboseLevel) Print();
135 fMustPoints->Delete();
136}
137// -------------------------------------------------------------------------
138
139// ----- Public method Register ----------------------------------------
140void CbmMust::Register() { FairRootManager::Instance()->Register("MUSTPoint", "Must", fMustPoints, kTRUE); }
141// -------------------------------------------------------------------------
142
143// ----- Public method Print -------------------------------------------
144void CbmMust::Print(Option_t*) const
145{
146 Int_t nPoints = fMustPoints->GetEntriesFast();
147
148 LOG(info) << " CbmMust: " << nPoints << " points registered in this event.";
149
150 if (fVerboseLevel > 1)
151 for (Int_t i = 0; i < nPoints; i++)
152 (*fMustPoints)[i]->Print();
153}
154// -------------------------------------------------------------------------
155
156// ----- Public method Reset -------------------------------------------
158{
159 fMustPoints->Delete();
161}
162// -------------------------------------------------------------------------
163
165{
166 LOG(info) << " -I- Initializing CbmMust()";
167
168 // Check once if TVirtualMC::GetMC()->GetStack really returns a CbmStack such that
169 // we can use later a static_cast<>
170 // Stop execution if not
171 CbmStack* stack = dynamic_cast<CbmStack*>(TVirtualMC::GetMC()->GetStack());
172 if (!stack) {
173 LOG(fatal) << "TVirtualMC::GetMC()->GetStack() doesn't return the expected CbmStack";
174 }
175
176 FairDetector::Initialize();
177}
178
179// ----- Public method ConstructGeometry -------------------------------
181{
182 TString fileName = GetGeometryFileName();
183
184 // --- Only ROOT geometries are supported
185 if (fileName.EndsWith(".root")) {
186 LOG(info) << "Importing MUST geometry from ROOT file " << fileName.Data();
187 TGeoCombiTrans* fCombiTrans = NULL;
188 Cbm::GeometryUtils::ImportRootGeometry(fgeoName, this, fCombiTrans);
189 return;
190 }
191 else {
192 LOG(fatal) << "Unknown geometry format";
193 }
194}
195// -------------------------------------------------------------------------
196
197// ----- Private method AddPoint -----------------------------------------
198CbmMustPoint* CbmMust::AddPoint(Int_t trackID, uint32_t address, TVector3 posIn, TVector3 posOut, TVector3 momIn,
199 TVector3 momOut, Double_t time, Double_t length, Double_t eLoss)
200{
201 TClonesArray& clref = *fMustPoints;
202
203 Int_t size = clref.GetEntriesFast();
204
205 CbmMustPoint* pointnew =
206 new (clref[size]) CbmMustPoint(trackID, address, posIn, posOut, momIn, momOut, time, length, eLoss);
207 LOG(debug) << pointnew->GetStationId() << " - " << pointnew->GetLayerId() << " - " << pointnew->GetModuleId() << " - "
208 << pointnew->GetTubeId();
209
210 return pointnew;
211}
212// -------------------------------------------------------------------------
@ kMust
MuSt detection system.
Definition CbmDefs.h:53
static constexpr size_t size()
Definition KfSimdPseudo.h:2
int Int_t
bool Bool_t
static uint32_t GetAddress(int32_t station=0, int32_t layer=0, int32_t module=0, int32_t tube=0)
Int_t GetTubeId() const
Int_t GetModuleId() const
Int_t GetLayerId() const
Int_t GetStationId() const
virtual Bool_t ProcessHits(FairVolume *vol=0) override
Definition CbmMust.cxx:65
virtual void Print(Option_t *="") const override
Definition CbmMust.cxx:144
Double_t fELoss
momentum
Definition CbmMust.h:109
virtual void ConstructGeometry() override
Definition CbmMust.cxx:180
virtual ~CbmMust()
Definition CbmMust.cxx:55
void ResetParameters()
Definition CbmMust.h:135
TLorentzVector fPosIn
Definition CbmMust.h:107
Bool_t fTrackValid
Array of CbmMustPoints.
Definition CbmMust.h:114
virtual void Reset() override
Definition CbmMust.cxx:157
virtual void Register() override
Definition CbmMust.cxx:140
virtual void Initialize() override
Definition CbmMust.cxx:164
TClonesArray * fMustPoints
energy loss
Definition CbmMust.h:111
virtual void EndOfEvent() override
Definition CbmMust.cxx:132
TLorentzVector fMomIn
entry position in global frame
Definition CbmMust.h:108
CbmMustPoint * AddPoint(Int_t trackID, uint32_t address, TVector3 posIn, TVector3 posOut, TVector3 momIn, TVector3 momOut, Double_t time, Double_t length, Double_t eLoss)
Definition CbmMust.cxx:198
CbmMust()
Definition CbmMust.cxx:47
void AddPoint(ECbmModuleId iDet)
Definition CbmStack.cxx:331
void ImportRootGeometry(TString &filename, FairModule *mod, TGeoMatrix *mat)