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