BmnRoot
Loading...
Searching...
No Matches
BmnHodo.cxx
Go to the documentation of this file.
1#include "BmnHodo.h"
2
3#include "BmnHodoGeo.h"
4#include "BmnHodoPoint.h"
5#include "CbmStack.h"
6#include "FairGeoInterface.h"
7#include "FairGeoLoader.h"
8#include "FairGeoNode.h"
9#include "FairGeoRootBuilder.h"
10#include "FairMCPoint.h"
11#include "FairRootManager.h"
12#include "FairVolume.h"
13#include "TClonesArray.h"
14#include "TGeoArb8.h"
15#include "TGeoMCGeometry.h"
16#include "TGeoManager.h"
17#include "TLorentzVector.h"
18#include "TParticle.h"
19#include "TVector3.h"
20#include "TVirtualMC.h"
21
22#include <iostream>
23// add on for debug
24// #include "FairGeoG3Builder.h"
25#include "FairRun.h"
26#include "FairRuntimeDb.h"
27#include "TObjArray.h"
28#include "TParticlePDG.h"
29
30// ----- Default constructor -------------------------------------------
32{
33 fHodoCollection = new TClonesArray("BmnHodoPoint");
34 volDetector = 0;
35 fEventID = -1;
36 fHodoStickSensVolId = 0;
37}
38
39// ----- Standard constructor ------------------------------------------
40BmnHodo::BmnHodo(const char* name, Bool_t active)
41 : FairDetector(name, active)
42{
43 fHodoCollection = new TClonesArray("BmnHodoPoint");
44 volDetector = 0;
45 fEventID = -1;
46 fHodoStickSensVolId = 0;
47 fVerboseLevel = 1;
48}
49
50// ----- Destructor ----------------------------------------------------
52{
53 if (fHodoCollection) {
54 fHodoCollection->Delete();
55 delete fHodoCollection;
56 }
57}
58
59// ----- Public method Intialize ---------------------------------------
61{
62 // Init function
63
64 FairDetector::Initialize();
65 // FairRun* sim = FairRun::Instance();
66 // FairRuntimeDb* rtdb = sim->GetRuntimeDb();
67
68 fHodoStickSensVolId = gMC->VolId("hodo_stick_sens");
69}
70
71// -------------------------------------------------------------------------
73{
74 // Returns the hit for the specified layer.
75 // ---
76
77 return (BmnHodoPoint*)fHodoCollection->At(i);
78}
79
80//_____________________________________________________________________________
81BmnHodoPoint* BmnHodo::GetHit(Int_t sticksens, Int_t stick) const
82{
83 // Returns the hit for the specified vsc and module.
84 // ---
85
86 BmnHodoPoint* hit;
87 Int_t nofHits = fHodoCollection->GetEntriesFast();
88 for (Int_t i = 0; i < nofHits; i++) {
89 hit = GetHit(i);
90 if (hit->GetCopy() == sticksens && hit->GetCopyMother() == stick)
91 return hit;
92 }
93
94 return 0;
95}
96
97// ----- Public method ProcessHits --------------------------------------
98Bool_t BmnHodo::ProcessHits(FairVolume* vol)
99{
102 Int_t copyNoStickSens;
103 Int_t copyNoSTICKSENSCom, copyNoSTICKCom;
104
105 Int_t ivol;
106 TLorentzVector tPos1, tMom1;
107 TLorentzVector tPos, tMom;
108
109 Int_t sticksens, stick;
110
111 Double_t time = 0;
112 Double_t length = 0;
113
114 // TParticle* part;
115 // Double_t charge;
116
117 // Double_t QCF=1; //quenching for Birk
118 // Double_t BirkConst = 12.6; //0.126 mm/MeV for polystyrene
119 // 0.126 *(0.1/0.001) = 12.6 cm/GeV
120 //(0.126 mm/MeV - from Wikipedia, 0.07943mm/MeV є– in Geant4)
121
122 if (gMC->CurrentVolID(copyNoStickSens) != fHodoStickSensVolId)
123 return kFALSE;
124
125 ivol = vol->getMCid();
126
127 if (gMC->CurrentVolID(copyNoStickSens) == fHodoStickSensVolId) {
128 gMC->CurrentVolOffID(0, sticksens);
129 gMC->CurrentVolOffID(1, stick);
130 copyNoSTICKSENSCom = sticksens;
131 copyNoSTICKCom = stick;
132 }
133
134 // cout <<"2_1_0 " << ivol <<" " <<gMC->CurrentVolOffName(2) << " " <<gMC->CurrentVolOffName(1) << " " <<
135 // gMC->CurrentVolOffName(0) <<std::endl;
136
137 if (gMC->IsTrackEntering()) {
138
139 ResetParameters();
140
141 fELoss = 0.;
142 time = 0.;
143 length = 0.;
144
145 TLorentzVector PosIn;
146 gMC->TrackPosition(PosIn);
147 fPos.SetXYZ(PosIn.X(), PosIn.Y(), PosIn.Z());
148
149 TLorentzVector MomIn;
150 gMC->TrackMomentum(MomIn);
151 fMom.SetXYZ(MomIn.Px(), MomIn.Py(), MomIn.Pz());
152
153 fTime = gMC->TrackTime() * 1.0e09;
154 fLength = gMC->TrackLength();
155 } // if (gMC->IsTrackEntering())
156
157 if (gMC->IsTrackInside()) {
158
159 gMC->TrackPosition(tPos);
160 gMC->TrackMomentum(tMom);
161 length += gMC->TrackStep();
162
163 fELoss += gMC->Edep();
164 /*
165//Birk corrections
166 if(gMC->TrackStep()>0) QCF = 1.+(BirkConst/gMC->TrackStep())*gMC->Edep();
167 else QCF = 1;
168 fELoss +=(gMC->Edep())/QCF;
169 */
170 time += gMC->TrackTime() * 1.0e09; // nsec
171
172 if (gMC->IsTrackStop() || gMC->IsTrackDisappeared()) {
173
174 // part = gMC->GetStack()->GetCurrentTrack();
175 // charge = part->GetPDG()->Charge() / 3. ;
176
177 // Create BmnZdcPoint
178 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
179 // time = gMC->TrackTime() * 1.0e09;
180 // length = gMC->TrackLength();
181 // gMC->TrackPosition(tPos);
182 // gMC->TrackMomentum(tMom);
183 // gMC->CurrentVolOffID(2, module);
184 // gMC->CurrentVolOffID(1, slice);
185
186 if (fELoss > 0) {
187 if (copyNoSTICKSENSCom == sticksens && copyNoSTICKCom == stick) {
188 if (!GetHit(sticksens, stick)) {
189 AddHit(fTrackID, ivol, sticksens, stick, TVector3(tPos.X(), tPos.Y(), tPos.Z()),
190 TVector3(tMom.Px(), tMom.Py(), tMom.Pz()), time, length, fELoss);
191 } else {
192 GetHit(sticksens, stick)
193 ->AddSTICK(fTrackID, ivol, sticksens, stick, TVector3(tPos.X(), tPos.Y(), tPos.Z()),
194 TVector3(tMom.Px(), tMom.Py(), tMom.Pz()), time, length, fELoss);
195 }
196 } // if(copyNoSLICECom==slice && copyNoCELLCom==cell)
197
198 } // if(fELoss>0)
199 } // if ( gMC->IsTrackStop() || gMC->IsTrackDisappeared() )
200 } // if ( gMC->IsTrackInside())
201
202 if (gMC->IsTrackExiting()) {
203 // part = gMC->GetStack()->GetCurrentTrack();
204
205 // Create BmnZdcPoint
206 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
207 time += gMC->TrackTime() * 1.0e09;
208 length += gMC->TrackLength();
209
210 fELoss += gMC->Edep();
211 /*
212//Birk corrections
213 if(gMC->TrackStep()>0) QCF = 1.+(BirkConst/gMC->TrackStep())*gMC->Edep();
214 else QCF = 1;
215 fELoss +=(gMC->Edep())/QCF;
216 */
217
218 gMC->TrackPosition(tPos);
219 gMC->TrackMomentum(tMom);
220
221 if (fELoss > 0) {
222 if (copyNoSTICKSENSCom == sticksens && copyNoSTICKCom == stick) {
223 if (!GetHit(sticksens, stick)) {
224 AddHit(fTrackID, ivol, sticksens, stick, TVector3(tPos.X(), tPos.Y(), tPos.Z()),
225 TVector3(tMom.Px(), tMom.Py(), tMom.Pz()), time, length, fELoss);
226 } else {
227 GetHit(sticksens, stick)
228 ->AddSTICK(fTrackID, ivol, sticksens, stick, TVector3(tPos.X(), tPos.Y(), tPos.Z()),
229 TVector3(tMom.Px(), tMom.Py(), tMom.Pz()), time, length, fELoss);
230 }
231 } // if(copyNoSLICECom==slice && copyNoCELLCom==cell)
232
233 } // if(fELoss>0)
234 } // if ( gMC->IsTrackExiting()) {
235
236 Int_t points = gMC->GetStack()->GetCurrentTrack()->GetMother(1);
237 points = (points & (~(1 << 30))) | (1 << 30);
238
239 gMC->GetStack()->GetCurrentTrack()->SetMother(1, points);
240
241 ((CbmStack*)gMC->GetStack())->AddPoint(kHODO);
242
243 /*//S.Merts
244 Int_t ivol = vol->getMCid();
245 if (gMC->IsTrackEntering()) {
246 ResetParameters();
247
248 fELoss = 0.;
249
250 TLorentzVector PosIn;
251 gMC->TrackPosition(PosIn);
252 fPos.SetXYZ(PosIn.X(), PosIn.Y(), PosIn.Z());
253
254 TLorentzVector MomIn;
255 gMC->TrackMomentum(MomIn);
256 fMom.SetXYZ(MomIn.Px(), MomIn.Py(), MomIn.Pz());
257
258 fTime = gMC->TrackTime() * 1.0e09;
259 fLength = gMC->TrackLength();
260 }
261
262 fELoss += gMC->Edep();
263 if (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) {
264 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
265 fVolumeID = vol->getMCid();
266 if (fELoss == 0.) {
267 return kFALSE;
268 }
269 AddHit(fTrackID, fVolumeID, fPos, fMom, fTime, fLength, fELoss);
270
271 ((CbmStack*)gMC->GetStack())->AddPoint(kHODO);
272 }
273*/
274 return kTRUE;
275}
276
277// ----- Public method EndOfEvent -----------------------------------------
279{
280 if (fVerboseLevel)
281 Print("");
282 Reset();
283}
284
285// ----- Public method Register -------------------------------------------
287{
288 FairRootManager::Instance()->Register("HodoPoint", "Hodo", fHodoCollection, kTRUE);
289}
290
291// ----- Public method GetCollection --------------------------------------
292TClonesArray* BmnHodo::GetCollection(Int_t iColl) const
293{
294 if (iColl == 0)
295 return fHodoCollection;
296 return NULL;
297}
298
299// ----- Public method Print ----------------------------------------------
300void BmnHodo::Print(Option_t*) const
301{
302 Int_t nHits = fHodoCollection->GetEntriesFast();
303 cout << "-I- BmnHodo: " << nHits << " points registered in this event." << endl;
304
305 if (fVerboseLevel > 1)
306 for (Int_t i = 0; i < nHits; i++)
307 (*fHodoCollection)[i]->Print();
308}
309
310// ----- Public method Reset ----------------------------------------------
312{
313 fHodoCollection->Delete();
314}
315
316//-----------------------------------------------------------------------------
318{
319 TString fileName = GetGeometryFileName();
320 if (fileName.EndsWith(".root")) {
321 LOG(info) << "Constructing Hodo geometry from ROOT file " << fileName.Data();
322 ConstructRootGeometry();
323 } else
324 LOG(fatal) << "Geometry format of Hodo file " << fileName.Data() << " not supported.";
325}
326
327// ----- Private method AddHit --------------------------------------------
329 Int_t detID,
330 Int_t copyNo,
331 Int_t copyNoMother,
332 TVector3 pos,
333 TVector3 mom,
334 Double_t time,
335 Double_t length,
336 Double_t eLoss)
337{
338 TClonesArray& clref = *fHodoCollection;
339 Int_t size = clref.GetEntriesFast();
340 return new (clref[size]) BmnHodoPoint(trackID, detID, copyNo, copyNoMother, pos, mom, time, length, eLoss);
341}
int i
Definition P4_F32vec4.h:22
@ kHODO
Short_t GetCopy() const
void AddSTICK(Int_t trackID, Int_t detID, Int_t idsticksens, Int_t idstick, TVector3 pos, TVector3 mom, Double_t dt, Double_t dl, Double_t de)
Short_t GetCopyMother() const
virtual TClonesArray * GetCollection(Int_t iColl) const
Definition BmnHodo.cxx:292
virtual void Reset()
Definition BmnHodo.cxx:311
virtual void Register()
Definition BmnHodo.cxx:286
BmnHodoPoint * AddHit(Int_t trackID, Int_t detID, Int_t copyNo, Int_t copyNoMother, TVector3 pos, TVector3 mom, Double_t tof, Double_t length, Double_t eLoss)
Definition BmnHodo.cxx:328
virtual void Print(Option_t *) const
Definition BmnHodo.cxx:300
virtual void ConstructGeometry()
Definition BmnHodo.cxx:317
BmnHodoPoint * GetHit(Int_t i) const
Definition BmnHodo.cxx:72
virtual void Initialize()
Definition BmnHodo.cxx:60
virtual Bool_t ProcessHits(FairVolume *vol=0)
Definition BmnHodo.cxx:98
virtual void EndOfEvent()
Definition BmnHodo.cxx:278
BmnHodo()
Definition BmnHodo.cxx:31
virtual ~BmnHodo()
Definition BmnHodo.cxx:51