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