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