BmnRoot
Loading...
Searching...
No Matches
BmnTOF1.cxx
Go to the documentation of this file.
1#include "BmnTOF1.h"
2
3using namespace std;
4
5//--------------------------------------------------------------------------------------------------------------------------------------
7 : fPos()
8 , fMom()
9 , fPosIndex(0)
10 , nan(-10000000)
11{
12 fTofCollection = new TClonesArray("BmnTOF1Point");
13 fVerboseLevel = 1;
14}
15
16//--------------------------------------------------------------------------------------------------------------------------------------
17BmnTOF1::BmnTOF1(const char* name, Bool_t active)
18 : FairDetector(name, active)
19 , fPos()
20 , fMom()
21 , fPosIndex(0)
22 , nan(-10000000)
23{
24 fTofCollection = new TClonesArray("BmnTOF1Point");
25 fVerboseLevel = 1;
26}
27
28//--------------------------------------------------------------------------------------------------------------------------------------
30{
31 fTofCollection->Delete();
32 delete fTofCollection;
33}
34
35//--------------------------------------------------------------------------------------------------------------------------------------
37{
38 FairDetector::Initialize();
39 // FairRun* sim = FairRun::Instance();
40 // FairRuntimeDb* rtdb = sim->GetRuntimeDb();
41}
42
43//--------------------------------------------------------------------------------------------------------------------------------------
45
46//--------------------------------------------------------------------------------------------------------------------------------------
47Bool_t BmnTOF1::ProcessHits(FairVolume* vol)
48{
49 // Set parameters at entrance of volume. Reset ELoss.
50 if (gMC->IsTrackEntering()) {
51 fELoss = 0.;
52 fTime = gMC->TrackTime() * 1.0e09;
53 fLength = gMC->TrackLength();
54 gMC->TrackPosition(fPos);
55 gMC->TrackMomentum(fMom);
56 }
57
58 // Sum energy loss for all steps in the active volume
59 fELoss += gMC->Edep();
60
61 // Create TofPoint at exit of active volume
62 if (fELoss > 0 && (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared())) {
63 Int_t fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
64 assert(fTrackID >= 0);
65
66 Int_t region = 0, detector, strip;
67 gMC->CurrentVolOffID(0, strip);
68 gMC->CurrentVolOffID(1, detector);
69
70 Int_t fVolumeID = BmnTOF1Point::GetVolumeUID(region, detector, strip);
71
72 AddPoint(fTrackID, kTOF1, TVector3(fPos.X(), fPos.Y(), fPos.Z()), TVector3(fMom.Px(), fMom.Py(), fMom.Pz()),
73 fTime, fLength, fELoss, fVolumeID);
74 ((CbmStack*)gMC->GetStack())->AddPoint(kTOF1);
75
76 ResetParameters();
77 }
78
79 return kTRUE;
80}
81
82//--------------------------------------------------------------------------------------------------------------------------------------
84{
85 if (fVerboseLevel)
86 Print("");
87 Reset();
88}
89
90//--------------------------------------------------------------------------------------------------------------------------------------
92{
93 FairRootManager::Instance()->Register("TOF400Point", "TOF400", fTofCollection, kTRUE);
94}
95
96//--------------------------------------------------------------------------------------------------------------------------------------
97TClonesArray* BmnTOF1::GetCollection(Int_t iColl) const
98{
99 if (iColl == 0)
100 return fTofCollection;
101
102 return nullptr;
103}
104
105//--------------------------------------------------------------------------------------------------------------------------------------
106void BmnTOF1::Print(Option_t*) const
107{
108 Int_t nHits = fTofCollection->GetEntriesFast();
109 cout << "-I- BmnTOF400: " << nHits << " points registered in this event.\n";
110
111 if (fVerboseLevel > 1)
112 for (Int_t i = 0; i < nHits; i++)
113 (*fTofCollection)[i]->Print();
114}
115
116//--------------------------------------------------------------------------------------------------------------------------------------
118{
119 fTofCollection->Delete();
120 fPosIndex = 0;
121}
122
123//--------------------------------------------------------------------------------------------------------------------------------------
124// guarda in FairRootManager::CopyClones
125void BmnTOF1::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset)
126{
127 Int_t nEntries = cl1->GetEntriesFast();
128 // cout << "-I- BmnTOF1: " << nEntries << " entries to add." << endl;
129 TClonesArray& clref = *cl2;
130 BmnTOF1Point* oldpoint = NULL;
131
132 for (Int_t i = 0; i < nEntries; i++) {
133 oldpoint = (BmnTOF1Point*)cl1->At(i);
134 Int_t index = oldpoint->GetTrackID() + offset;
135 oldpoint->SetTrackID(index);
136 new (clref[fPosIndex]) BmnTOF1Point(*oldpoint);
137 fPosIndex++;
138 }
139
140 cout << " -I- BmnTOF400: " << cl2->GetEntriesFast() << " merged entries." << endl;
141}
142
143//--------------------------------------------------------------------------------------------------------------------------------------
145{
146 TString fileName = GetGeometryFileName();
147 if (fileName.EndsWith(".root")) {
148 LOG(info) << "Constructing TOF400 geometry from ROOT file " << fileName.Data();
149 ConstructRootGeometry();
150 } else if (fileName.EndsWith(".geo")) {
151 LOG(info) << "Constructing TOF400 geometry from ASCII file " << fileName.Data();
153 } else
154 LOG(fatal) << "Geometry format of TOF400 file " << fileName.Data() << " not supported.";
155}
156
157//--------------------------------------------------------------------------------------------------------------------------------------
159{
160 FairGeoLoader* geoLoad = FairGeoLoader::Instance();
161 FairGeoInterface* geoFace = geoLoad->getGeoInterface();
162 BmnTOF1Geo* TOF1Geo = new BmnTOF1Geo();
163 TOF1Geo->setGeomFile(GetGeometryFileName());
164 geoFace->addGeoModule(TOF1Geo);
165
166 Bool_t rc = geoFace->readSet(TOF1Geo);
167 if (rc)
168 TOF1Geo->create(geoLoad->getGeoBuilder());
169 TList* volList = TOF1Geo->getListOfVolumes();
170
171 // store geo parameter
172 FairRun* fRun = FairRun::Instance();
173 FairRuntimeDb* rtdb = FairRun::Instance()->GetRuntimeDb();
174 BmnTOF1GeoPar* par = (BmnTOF1GeoPar*)(rtdb->getContainer("BmnTOF1GeoPar"));
175 TObjArray* fSensNodes = par->GetGeoSensitiveNodes();
176 TObjArray* fPassNodes = par->GetGeoPassiveNodes();
177
178 TListIter iter(volList);
179 FairGeoNode* node = nullptr;
180 FairGeoVolume* aVol = nullptr;
181
182 while ((node = (FairGeoNode*)iter.Next())) {
183 aVol = dynamic_cast<FairGeoVolume*>(node);
184
185 if (node->isSensitive())
186 fSensNodes->AddLast(aVol);
187 else
188 fPassNodes->AddLast(aVol);
189 }
190
191 par->setChanged();
192 par->setInputVersion(fRun->GetRunId(), 1);
193 ProcessNodes(volList);
194}
195
196//--------------------------------------------------------------------------------------------------------------------------------------
197Bool_t BmnTOF1::CheckIfSensitive(std::string name)
198{
199 TString tsname = name;
200 if (tsname.Contains("Active"))
201 return kTRUE;
202
203 return kFALSE;
204}
205
206//--------------------------------------------------------------------------------------------------------------------------------------
208 Int_t detID,
209 TVector3 pos,
210 TVector3 mom,
211 Double_t time,
212 Double_t length,
213 Double_t eLoss,
214 Int_t volUID)
215{
216 return new ((*fTofCollection)[fTofCollection->GetEntriesFast()])
217 BmnTOF1Point(trackID, detID, pos, mom, time, length, eLoss, volUID);
218}
int i
Definition P4_F32vec4.h:22
@ kTOF1
TObjArray * GetGeoSensitiveNodes()
TObjArray * GetGeoPassiveNodes()
Int_t GetVolumeUID() const
virtual void Print(Option_t *) const
Definition BmnTOF1.cxx:106
virtual void Reset()
Definition BmnTOF1.cxx:117
virtual ~BmnTOF1()
Definition BmnTOF1.cxx:29
virtual void ConstructAsciiGeometry()
Definition BmnTOF1.cxx:158
virtual void EndOfEvent()
Definition BmnTOF1.cxx:83
virtual Bool_t ProcessHits(FairVolume *vol=nullptr)
Definition BmnTOF1.cxx:47
virtual TClonesArray * GetCollection(Int_t iColl) const
Definition BmnTOF1.cxx:97
virtual void Initialize()
Definition BmnTOF1.cxx:36
virtual void ConstructGeometry()
Definition BmnTOF1.cxx:144
BmnTOF1()
Definition BmnTOF1.cxx:6
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Definition BmnTOF1.cxx:125
BmnTOF1Point * AddPoint(Int_t trackID, Int_t detID, TVector3 pos, TVector3 mom, Double_t tof, Double_t length, Double_t eLoss, Int_t volUID)
Definition BmnTOF1.cxx:207
virtual void Register()
Definition BmnTOF1.cxx:91
virtual void BeginEvent()
Definition BmnTOF1.cxx:44
virtual Bool_t CheckIfSensitive(std::string name)
Definition BmnTOF1.cxx:197
STL namespace.