BmnRoot
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
54Bool_t BmnVacWall::ProcessHits(FairVolume* vol)
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
101TClonesArray* BmnVacWall::GetCollection(Int_t iColl) const
102{
103 LOG(debug4) << "BmnVacWall GetCollection method called with iColl: " << iColl;
104 return (iColl == 0) ? fCollection : nullptr;
105}
106
107void BmnVacWall::Print(Option_t*) const
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
148Bool_t BmnVacWall::CheckIfSensitive(std::string name)
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
156FairMCPoint* BmnVacWall::AddHit(FairMCPoint* point)
157{
158 TClonesArray& clref = *fCollection;
159 Int_t size = clref.GetEntriesFast();
160 return new (clref[size]) FairMCPoint(*point);
161}
162
163void BmnVacWall::RemoveHit(Int_t index)
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
@ kVACWALL
virtual void BeginEvent()
virtual ~BmnVacWall()
virtual Bool_t ProcessHits(FairVolume *vol=nullptr)
virtual void Reset()
virtual void ConstructGeometry()
virtual Bool_t CheckIfSensitive(std::string name)
void RemoveHit(Int_t index)
FairMCPoint * AddHit(FairMCPoint *point)
virtual void Initialize()
virtual TClonesArray * GetCollection(Int_t iColl) const
virtual void EndOfEvent()
virtual void Register()
virtual void Print(Option_t *) const