BmnRoot 26.10.0-19-g6979a6c6
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnFD.cxx
Go to the documentation of this file.
1#include "BmnFD.h"
2
3#include "BmnFDGeo.h"
4#include "BmnFDPoint.h"
5#include "CbmStack.h"
6#include "FairGeoInterface.h"
7#include "FairGeoLoader.h"
8#include "FairGeoNode.h"
9#include "FairGeoRootBuilder.h"
10#include "FairMCPoint.h"
11#include "FairRootManager.h"
12#include "FairVolume.h"
13#include "TClonesArray.h"
14#include "TGeoArb8.h"
15#include "TGeoMCGeometry.h"
16#include "TGeoManager.h"
17#include "TLorentzVector.h"
18#include "TParticle.h"
19#include "TVector3.h"
20#include "TVirtualMC.h"
21
22#include <iostream>
23// add on for debug
24// #include "FairGeoG3Builder.h"
25#include "FairRun.h"
26#include "FairRuntimeDb.h"
27#include "TObjArray.h"
28#include "TParticlePDG.h"
29
30// ----- Default constructor -------------------------------------------
32{
33 fFDCollection = new TClonesArray("BmnFDPoint");
34 volDetector = 0;
35 fPosIndex = 0;
36 // fpreflag = 0;
37 // fpostflag = 0;
38 // fEventID=-1;
39 fVerboseLevel = 1;
40}
41// -------------------------------------------------------------------------
42
43// ----- Standard constructor ------------------------------------------
44BmnFD::BmnFD(const char* name, Bool_t active)
45 : FairDetector(name, active)
46{
47 fFDCollection = new TClonesArray("BmnFDPoint");
48 fPosIndex = 0;
49 volDetector = 0;
50 // fpreflag = 0;
51 // fpostflag = 0;
52 // fEventID=-1;
53 fVerboseLevel = 1;
54}
55// -------------------------------------------------------------------------
56
57// ----- Destructor ----------------------------------------------------
59{
60 if (fFDCollection) {
61 fFDCollection->Delete();
62 delete fFDCollection;
63 }
64}
65// -------------------------------------------------------------------------
66
67// ----- Public method Intialize ---------------------------------------
69{
70 // Init function
71
72 FairDetector::Initialize();
73 // FairRun* sim = FairRun::Instance();
74 // FairRuntimeDb* rtdb=sim->GetRuntimeDb();
75}
76// -------------------------------------------------------------------------
78{
79 // Begin of the event
80}
81
82// ----- Public method ProcessHits --------------------------------------
83Bool_t BmnFD::ProcessHits(FairVolume* vol)
84{
85
86 // if (TMath::Abs(gMC->TrackCharge()) <= 0) return kFALSE;
87
88 static const Double_t dP = 1.032;
89 static const Double_t BirkC1 = 0.013 / dP;
90 static const Double_t BirkC2 = 9.6e-6 / (dP * dP);
91
92 static Double_t lightYield;
93 static Double_t timeIn;
94 static Double_t timeOut;
95 static Double_t lengthtrack;
96 // static Double_t de_dx;
97
98 Int_t ivol = vol->getMCid();
99 // TLorentzVector tPos1, tMom1;
100 // TLorentzVector tPos, tMom;
101
102 // #define EDEBUG
103#ifdef EDEBUG
104 static Int_t lEDEBUGcounter = 0;
105 if (lEDEBUGcounter < 1)
106 std::cout << "EDEBUG-- BmnBd1::ProcessHits: entered" << gMC->CurrentVolPath() << endl;
107#endif
108
109 if (gMC->IsTrackEntering()) {
110
112
113 fELoss = 0.;
114 fIsPrimary = 0;
115 fCharge = -1;
116 fPdgId = 0;
117 lightYield = 0.;
118 lengthtrack = 0.;
119
120 TLorentzVector PosIn;
121 gMC->TrackPosition(PosIn);
122 fPosIn.SetXYZ(PosIn.X(), PosIn.Y(), PosIn.Z());
123
124 TLorentzVector MomIn;
125 gMC->TrackMomentum(MomIn);
126 fMomIn.SetXYZ(MomIn.Px(), MomIn.Py(), MomIn.Pz());
127
128 timeIn = gMC->TrackTime() * 1.0e09;
129
130#ifdef EDEBUG
131 // gMC->TrackPosition(tPos1);
132 // gMC->TrackMomentum(tMom1);
133#endif
134
135 TParticle* part = 0;
136 part = gMC->GetStack()->GetCurrentTrack();
137
138 if (part) {
139 fIsPrimary = (Int_t)part->IsPrimary();
140 fCharge = (Int_t)part->GetPDG()->Charge() / 3.;
141 fPdgId = (Int_t)part->GetPdgCode();
142 }
143 }
144
145 if (gMC->TrackCharge() != 0) {
146 Double_t BirkC1Mod = 0;
147
148 if (TMath::Abs(gMC->TrackCharge()) >= 2)
149
150 BirkC1Mod = BirkC1 * 7.2 / 12.6;
151 else
152 BirkC1Mod = BirkC1;
153 if (gMC->TrackStep() > 0) {
154
155 Double_t dedxcm = gMC->Edep() * 1000. / gMC->TrackStep(); //[MeV/cm]
156 Double_t curLightYield = gMC->Edep() * 1000. / (1. + BirkC1Mod * dedxcm + BirkC2 * dedxcm * dedxcm);
157 curLightYield /= 1000.; //[GeV]
158 lightYield += curLightYield;
159 }
160 }
161
162 Double_t eLoss = gMC->Edep();
163 if (eLoss > 0)
164 fELoss += eLoss;
165
166 Double_t slengthtrack = gMC->TrackStep();
167 lengthtrack += slengthtrack;
168
169 if ((gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) && (fELoss > 0)) {
170 TLorentzVector PosOut;
171 gMC->TrackPosition(PosOut);
172 fPosOut.SetXYZ(PosOut.X(), PosOut.Y(), PosOut.Z());
173
174 TLorentzVector MomOut;
175 gMC->TrackMomentum(MomOut);
176 fMomOut.SetXYZ(MomOut.Px(), MomOut.Py(), MomOut.Pz());
177
178 timeOut = gMC->TrackTime() * 1.0e09;
179
180#ifndef EDEBUG
181
182 if (fELoss == 0.)
183 return kFALSE;
184
185#endif
186
187 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
188
189 Double_t time = gMC->TrackTime() * 1.0e09;
190 Double_t length = gMC->TrackLength();
191
192 Int_t copyNo;
193 /*Int_t ivol1 = */ gMC->CurrentVolID(copyNo);
194
195 Int_t iCell;
196 gMC->CurrentVolOffID(1, iCell);
197
198#ifdef EDEBUG
199 if (lEDEBUGcounter < 100) {
200 std::cout << "EDEBUG-- BmnFD::ProcessHits: TrackID:" << fTrackID <<
201 // " ELoss: " << fELoss <<
202 // " particle: " << (part->GetName()) <<
203 " " << gMC->CurrentVolPath() << " " << tPos.Z() <<
204 // " " << (gMC->GetStack()->GetCurrentTrack()->GetMother(1)) <<
205 " " << ivol << "==" << gMC->CurrentVolID(copyNo) << "," << copyNo << " "
206 << gMC->CurrentVolOffID(1, iCell) << " " << iCell << " " << gMC->CurrentVolOffName(1) << " "
207 << gMC->CurrentVolOffName(0) <<
208 // " " << vol->getRealName() << " " << gMC->CurrentVolPath() <<
209 // " ivol,iCell,copyNo= " << ivol << ","<< iCell << ","<< copyNo <<
210 // " " << vol->getRealName() << " "<< gMC->CurrentVolName() << " "<< gMC->CurrentVolPath() <<
211 // " " << ivol << ","<< vol->getVolumeId() << " : "<< gMC->CurrentVolID(copyNo) << ","<< copyNo <<
212 // " "<< gMC->CurrentVolOffName(2) << " "<< gMC->CurrentVolOffName(3) <<
213 std::endl;
214 lEDEBUGcounter++;
215 }
216
217 AddHit(fTrackID, ivol, copyNo, fPosIn, fPosOut, fMomIn, fMomOut, time, length, fELoss, fIsPrimary, fCharge,
218 fPdgId, lightYield, timeIn, timeOut, lengthtrack);
219#else
220
221 AddHit(fTrackID, ivol, copyNo, fPosIn, fPosOut, fMomIn, fMomOut, time, length, fELoss, fIsPrimary, fCharge,
222 fPdgId, lightYield, timeIn, timeOut, lengthtrack);
223#endif
224
225 //// Int_t points = gMC->GetStack()->GetCurrentTrack()->GetMother(1);
226 // Int_t nBdPoints = (points & (1<<30)) >> 30;
227 // nBdPoints ++;
228 // if (nBdPoints > 1) nBdPoints = 1;
229 // points = ( points & ( ~ (1<<30) ) ) | (nBdPoints << 30);
230 //// points = ( points & ( ~ (1<<30) ) ) | (1 << 30);
231 //// gMC->GetStack()->GetCurrentTrack()->SetMother(1,points);
232
233 ((CbmStack*)gMC->GetStack())->AddPoint(kFD);
234 }
235
236 return kTRUE;
237
238#undef EDEBUG
239}
240
241// ----- Public method EndOfEvent -----------------------------------------
243{
244 if (fVerboseLevel)
245 Print("");
246 Reset();
247}
248
249// ----- Public method Register -------------------------------------------
251{
252 FairRootManager::Instance()->Register("FDPoint", "FD", fFDCollection, kTRUE);
253}
254
255// ----- Public method GetCollection --------------------------------------
257{
258 if (iColl == 0)
259 return fFDCollection;
260
261 return NULL;
262}
263
264// ----- Public method Print ----------------------------------------------
266{
267 Int_t nHits = fFDCollection->GetEntriesFast();
268 cout << "-I- BmnFD: " << nHits << " points registered in this event." << endl;
269
270 if (fVerboseLevel > 1)
271 for (Int_t i = 0; i < nHits; i++)
272 (*fFDCollection)[i]->Print();
273}
274
275// ----- Public method Reset ----------------------------------------------
277{
278 fFDCollection->Delete();
279
280 fPosIndex = 0;
281}
282
283// guarda in FairRootManager::CopyClones
284// ----- Public method CopyClones -----------------------------------------
286{
287 Int_t nEntries = cl1->GetEntriesFast();
288 // cout << "-I- BmnFD: " << nEntries << " entries to add." << endl;
289 TClonesArray& clref = *cl2;
290 BmnFDPoint* oldpoint = NULL;
291 for (Int_t i = 0; i < nEntries; i++) {
292 oldpoint = (BmnFDPoint*)cl1->At(i);
293 Int_t index = oldpoint->GetTrackID() + offset;
294 oldpoint->SetTrackID(index);
295 new (clref[fPosIndex]) BmnFDPoint(*oldpoint);
296 fPosIndex++;
297 }
298 cout << " -I- BmnFD: " << cl2->GetEntriesFast() << " merged entries." << endl;
299}
300
301//--------------------------------------------------------------------------------------------------------------------------------------
303{
304 TString fileName = GetGeometryFileName();
305 if (fileName.EndsWith(".root")) {
306 LOG(info) << "Constructing FD geometry from ROOT file " << fileName.Data();
307 ConstructRootGeometry();
308 } else if (fileName.EndsWith(".geo")) {
309 LOG(info) << "Constructing FD geometry from ASCII file " << fileName.Data();
311 } else
312 LOG(fatal) << "Geometry format of FD file " << fileName.Data() << " not supported.";
313}
314//--------------------------------------------------------------------------------------------------------------------------------------
316{
317 FairGeoLoader* geoLoad = FairGeoLoader::Instance();
318 FairGeoInterface* geoFace = geoLoad->getGeoInterface();
319 BmnFDGeo* FDGeo = new BmnFDGeo();
320 FDGeo->setGeomFile(GetGeometryFileName());
321 geoFace->addGeoModule(FDGeo);
322
323 Bool_t rc = geoFace->readSet(FDGeo);
324 if (rc)
325 FDGeo->create(geoLoad->getGeoBuilder());
326 TList* volList = FDGeo->getListOfVolumes();
327
328 // store geo parameter
329 FairRun* fRun = FairRun::Instance();
330 FairRuntimeDb* rtdb = FairRun::Instance()->GetRuntimeDb();
331 BmnFDGeoPar* par = (BmnFDGeoPar*)(rtdb->getContainer("BmnFDGeoPar"));
332 TObjArray* fSensNodes = par->GetGeoSensitiveNodes();
333 TObjArray* fPassNodes = par->GetGeoPassiveNodes();
334
335 TListIter iter(volList);
336 FairGeoNode* node = nullptr;
337 FairGeoVolume* aVol = nullptr;
338
339 while ((node = (FairGeoNode*)iter.Next())) {
340 aVol = dynamic_cast<FairGeoVolume*>(node);
341
342 if (node->isSensitive())
343 fSensNodes->AddLast(aVol);
344 else
345 fPassNodes->AddLast(aVol);
346 }
347
348 par->setChanged();
349 par->setInputVersion(fRun->GetRunId(), 1);
350 ProcessNodes(volList);
351}
352
353//--------------------------------------------------------------------------------------------------------------------------------------
354
356{
357 TString tsname = name;
358 if (tsname.Contains("Active"))
359 return kTRUE;
360
361 return kFALSE;
362}
363//-------------------------------------------------------------------------
364
365// ----- Private method AddHit --------------------------------------------
367 Int_t detID,
368 Int_t copyNo,
369 TVector3 posIn,
370 TVector3 posOut,
371 TVector3 momIn,
372 TVector3 momOut,
373 Double_t time,
374 Double_t length,
375 Double_t eLoss,
376 Bool_t isPrimary,
377 Double_t charge,
378 Int_t pdgId,
379 Double_t lightYield,
380 Double_t timeIn,
381 Double_t timeOut,
382 Double_t lengthtrack)
383{
384
385 TClonesArray& clref = *fFDCollection;
386 Int_t size = clref.GetEntriesFast();
387 return new (clref[size]) BmnFDPoint(trackID, detID, copyNo, posIn, posOut, momIn, momOut, time, length, eLoss,
388 isPrimary, charge, pdgId, lightYield, timeIn, timeOut, lengthtrack);
389}
@ kFD
int i
Definition P4_F32vec4.h:22
bool Bool_t
int Int_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
TObjArray * GetGeoSensitiveNodes()
Definition BmnFDGeoPar.h:21
TObjArray * GetGeoPassiveNodes()
Definition BmnFDGeoPar.h:22
BmnFD()
Default constructor.
Definition BmnFD.cxx:31
Double32_t fELoss
length
Definition BmnFD.h:123
virtual void ConstructGeometry()
Virtual method Construct geometry.
Definition BmnFD.cxx:302
TVector3 fMomOut
momentum (in)
Definition BmnFD.h:120
virtual void Register()
Virtual method Register.
Definition BmnFD.cxx:250
virtual Bool_t CheckIfSensitive(std::string name)
Definition BmnFD.cxx:355
virtual ~BmnFD()
Destructor.
Definition BmnFD.cxx:58
virtual TClonesArray * GetCollection(Int_t iColl) const
Accessor to the hit collection.
Definition BmnFD.cxx:256
virtual void BeginEvent()
Definition BmnFD.cxx:77
virtual void Print(Option_t *) const
Virtual method Print.
Definition BmnFD.cxx:265
Int_t fPosIndex
energy loss
Definition BmnFD.h:124
Int_t volDetector
Definition BmnFD.h:125
virtual void ConstructAsciiGeometry()
Definition BmnFD.cxx:315
virtual void Reset()
Virtual method Reset.
Definition BmnFD.cxx:276
Int_t fTrackID
Definition BmnFD.h:114
virtual void Initialize()
Virtual method Initialize Initialises detector.
Definition BmnFD.cxx:68
TVector3 fMomIn
position (out)
Definition BmnFD.h:119
Double_t fCharge
is track primary?
Definition BmnFD.h:127
virtual void EndOfEvent()
Virtual method EndOfEvent.
Definition BmnFD.cxx:242
TClonesArray * fFDCollection
Definition BmnFD.h:130
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Virtual method CopyClones.
Definition BmnFD.cxx:285
TVector3 fPosOut
position (in)
Definition BmnFD.h:118
Int_t fIsPrimary
MC volume ID of MUO.
Definition BmnFD.h:126
Int_t fPdgId
track charge
Definition BmnFD.h:128
TVector3 fPosIn
volume id
Definition BmnFD.h:117
void ResetParameters()
length
Definition BmnFD.h:142
BmnFDPoint * AddHit(Int_t trackID, Int_t detID, Int_t copyNo, TVector3 posIn, TVector3 posOut, TVector3 momIn, TVector3 momOut, Double_t tof, Double_t length, Double_t eLoss, Bool_t isPrimary, Double_t charge, Int_t pdgId, Double_t lightYield, Double_t timeIn, Double_t timeOut, Double_t lengthtrack)
Definition BmnFD.cxx:366
virtual Bool_t ProcessHits(FairVolume *vol=0)
Virtual method ProcessHits.
Definition BmnFD.cxx:83
CbmStack.h.
Definition CbmStack.h:43
TObject * Next() override
Double_t Y() const
Double_t Px() const
Double_t Pz() const
Double_t X() const
Double_t Py() const
Double_t Z() const
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
void AddLast(TObject *obj) override
Double_t Charge() const
Int_t GetPdgCode() const
TParticlePDG * GetPDG(Int_t mode=0) const
Bool_t IsPrimary() const
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
const char * Data() const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Double_t Abs(Double_t d)