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