BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnVacWall.cxx
Go to the documentation of this file.
1#include "BmnVacWall.h"
2
3#include "CbmStack.h"
4#include "FairRootManager.h"
5#include "FairRun.h"
6#include "FairRuntimeDb.h"
7#include "FairVolume.h"
8#include "TGeoManager.h"
9#include "TLorentzVector.h"
10#include "TParticle.h"
11#include "TVirtualMC.h"
12
13#include <iostream>
14
16 : FairDetector("BmnVacWall", true)
17 , fGeoHandler(new BmnZdcGeo())
18 , fCollection(new TClonesArray("FairMCPoint"))
19{
20 LOG(debug4) << "BmnVacWall default constructor called";
21}
22
23BmnVacWall::BmnVacWall(const char* name, Bool_t active)
24 : FairDetector(name, active)
25 , fGeoHandler(new BmnZdcGeo())
26 , fCollection(new TClonesArray("FairMCPoint"))
27{
28 LOG(debug4) << "BmnVacWall constructor called with name: " << name << " and active: " << active;
29}
30
32{
33 LOG(debug4) << "BmnVacWall destructor called";
34 if (fCollection) {
35 fCollection->Delete();
36 delete fCollection;
37 }
38 delete fGeoHandler;
39}
40
42{
43 LOG(debug4) << "BmnVacWall Initialize method called";
44 FairDetector::Initialize();
45 // FairRun* sim = FairRun::Instance();
46 // FairRuntimeDb* rtdb = sim->GetRuntimeDb();
47}
48
50{
51 LOG(debug4) << "BmnVacWall BeginEvent method called";
52}
53
55{
56 LOG(debug2) << "BmnVacWall ProcessHits method called for event " << gMC->CurrentEvent();
57 if (!CheckIfSensitive(gMC->CurrentVolName())) {
58 return kFALSE;
59 }
60
61 Int_t trackID = gMC->GetStack()->GetCurrentTrackNumber();
62 int plane_id;
63 gMC->CurrentVolOffID(0, plane_id); // planeNb 1-6
64 if (gMC->IsTrackEntering()) {
65 // Initializing new hit
66 FairMCPoint* newPoint = new FairMCPoint();
67 newPoint->SetEventID(gMC->CurrentEvent());
68 newPoint->SetTrackID(trackID);
69 newPoint->SetDetectorID(plane_id);
70 TLorentzVector tPos, tMom;
71 gMC->TrackPosition(tPos); // Position at entrance
72 gMC->TrackMomentum(tMom); // Momentum at entrance
73 newPoint->SetPosition(TVector3(tPos.X(), tPos.Y(), tPos.Z()));
74 newPoint->SetMomentum(TVector3(tMom.X(), tMom.Y(), tMom.Z()));
75 newPoint->SetTime(gMC->TrackTime() * 1.0e09); // Time of flight
76 newPoint->SetLength(gMC->TrackLength()); // Length of the current track from its origin (in cm)
77
78 // Inserting new hit
79 AddHit(newPoint);
80 ((CbmStack*)gMC->GetStack())->AddPoint(kVACWALL);
81 }
82 return kTRUE;
83}
84
86{
87 LOG(debug4) << "BmnVacWall EndOfEvent method called";
88 Print("");
89 Reset();
90}
91
93{
94 LOG(debug4) << "BmnVacWall Register method called";
95 if (!FairRootManager::Instance()->GetObject("VacWallPoint"))
96 FairRootManager::Instance()->Register("VacWallPoint", "VacWall", fCollection, kTRUE);
97 else
98 LOG(debug4) << "VacWallPoint Already registered";
99}
100
102{
103 LOG(debug4) << "BmnVacWall GetCollection method called with iColl: " << iColl;
104 return (iColl == 0) ? fCollection : nullptr;
105}
106
108{
109 LOG(debug4) << "BmnVacWall Print method called";
110 Int_t nHits = fCollection->GetEntriesFast();
111 std::cout << "-I- BmnVacWall: " << nHits << " points registered in event " << gMC->CurrentEvent() << std::endl;
112
113 if (FairLogger::GetLogger()->IsLogNeeded(fair::Severity::debug2)) {
114 for (Int_t i = 0; i < nHits; i++) {
115 (*fCollection)[i]->Print();
116 }
117 }
118}
119
121{
122 LOG(debug4) << "BmnVacWall Reset method called";
123 fCollection->Delete();
124}
125
127{
128 LOG(debug4) << "BmnVacWall ConstructGeometry method called";
129 TString fileName = GetGeometryFileName();
130 if (fileName.EndsWith(".root")) {
131 LOG(info) << Form("Constructing VacWall geometry from ROOT file %s", fileName.Data());
132 ConstructRootGeometry();
133 }
134
135 FairGeoLoader* geoLoad = FairGeoLoader::Instance();
136 FairGeoInterface* geoFace = geoLoad->getGeoInterface();
137 fGeoHandler->setGeomFile(GetGeometryFileName());
138 geoFace->addGeoModule(fGeoHandler);
139
140 Bool_t rc = geoFace->readSet(fGeoHandler);
141 if (rc)
142 fGeoHandler->create(geoLoad->getGeoBuilder());
143 TList* volList = fGeoHandler->getListOfVolumes();
144
145 ProcessNodes(volList);
146}
147
149{
150 LOG(debug4) << "BmnVacWall CheckIfSensitive method called with name: " << name;
151 TString tsname = name.c_str();
152 // zdc legacy
153 return tsname.Contains("zdc01s") || tsname.Contains("zdc01s_after") || tsname.Contains("ScH");
154}
155
157{
158 TClonesArray& clref = *fCollection;
159 Int_t size = clref.GetEntriesFast();
160 return new (clref[size]) FairMCPoint(*point);
161}
162
164{
165 if (index < 0 || index >= fCollection->GetEntriesFast()) {
166 LOG(debug4) << "BmnVacWall RemoveHit method index: " << index << " out of range.";
167 return;
168 }
169 fCollection->RemoveAt(index);
170 fCollection->Compress(); // This method will remove NULL pointers from the array
171}
int i
Definition P4_F32vec4.h:22
bool Bool_t
int Int_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
const char Option_t
char * Form(const char *fmt,...)
@ kVACWALL
virtual void BeginEvent()
Called at the beginning of each event.
TClonesArray * fCollection
Definition BmnVacWall.h:78
virtual ~BmnVacWall()
Destructor.
virtual Bool_t ProcessHits(FairVolume *vol=nullptr)
Processes hits and creates FairMCPoints.
virtual void Reset()
Clears the hit collection.
virtual void ConstructGeometry()
Constructs geometry from files.
BmnZdcGeo * fGeoHandler
Definition BmnVacWall.h:77
virtual Bool_t CheckIfSensitive(std::string name)
Checks whether a volume is sensitive based on its name.
void RemoveHit(Int_t index)
Remove hit from hits collection by index.
FairMCPoint * AddHit(FairMCPoint *point)
Adds the hit to hits collection.
virtual void Initialize()
Initialises detector and FairRun.
BmnVacWall()
Default constructor.
virtual TClonesArray * GetCollection(Int_t iColl) const
Accessor to the hit collection.
virtual void EndOfEvent()
Called at the end of each event.
virtual void Register()
Registers the hit collection in the ROOT manager.
virtual void Print(Option_t *) const
Screen output of hit collection.
CbmStack.h.
Definition CbmStack.h:43
Double_t Y() const
Double_t X() const
Double_t Z() const
Int_t GetEntriesFast() 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