BmnRoot
Loading...
Searching...
No Matches
BmnHodo_noBirk.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 /*
161//Birk corrections
162 if(gMC->TrackStep()>0) QCF = 1.+(BirkConst/gMC->TrackStep())*gMC->Edep();
163 else QCF = 1;
164 fELoss +=(gMC->Edep())/QCF;
165 */
166 time += gMC->TrackTime() * 1.0e09;//nsec
167
168 if ( gMC->IsTrackStop() || gMC->IsTrackDisappeared() ) {
169
170 part = gMC->GetStack()->GetCurrentTrack();
171 charge = part->GetPDG()->Charge() / 3. ;
172
173// Create BmnZdcPoint
174 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
175 //time = gMC->TrackTime() * 1.0e09;
176 //length = gMC->TrackLength();
177 //gMC->TrackPosition(tPos);
178 //gMC->TrackMomentum(tMom);
179 //gMC->CurrentVolOffID(2, module);
180 //gMC->CurrentVolOffID(1, slice);
181
182 if(fELoss>0) {
183 if(copyNoSTICKSENSCom==sticksens && copyNoSTICKCom==stick) {
184 if ( !GetHit(sticksens,stick) ) {
185 AddHit(fTrackID, ivol, sticksens, stick, TVector3(tPos.X(), tPos.Y(), tPos.Z()),TVector3(tMom.Px(), tMom.Py(), tMom.Pz()),time, length, fELoss);
186 }
187 else {
188 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);
189 }
190 }//if(copyNoSLICECom==slice && copyNoCELLCom==cell)
191
192 }//if(fELoss>0)
193 }//if ( gMC->IsTrackStop() || gMC->IsTrackDisappeared() )
194 }//if ( gMC->IsTrackInside())
195
196 if ( gMC->IsTrackExiting()) {
197
198 part = gMC->GetStack()->GetCurrentTrack();
199
200// Create BmnZdcPoint
201 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
202 time += gMC->TrackTime() * 1.0e09;
203 length += gMC->TrackLength();
204
205 fELoss +=gMC->Edep();
206 /*
207//Birk corrections
208 if(gMC->TrackStep()>0) QCF = 1.+(BirkConst/gMC->TrackStep())*gMC->Edep();
209 else QCF = 1;
210 fELoss +=(gMC->Edep())/QCF;
211 */
212
213 gMC->TrackPosition(tPos);
214 gMC->TrackMomentum(tMom);
215
216 if(fELoss>0) {
217 if(copyNoSTICKSENSCom==sticksens && copyNoSTICKCom==stick) {
218 if ( !GetHit(sticksens,stick) ) {
219 AddHit(fTrackID, ivol, sticksens, stick, TVector3(tPos.X(), tPos.Y(), tPos.Z()),TVector3(tMom.Px(), tMom.Py(), tMom.Pz()),time, length, fELoss);
220 }
221 else {
222 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);
223 }
224 }//if(copyNoSLICECom==slice && copyNoCELLCom==cell)
225
226 }//if(fELoss>0)
227 }//if ( gMC->IsTrackExiting()) {
228
229 Int_t points = gMC->GetStack()->GetCurrentTrack()->GetMother(1);
230 points = ( points & ( ~ (1<<30) ) ) | (1 << 30);
231
232 gMC->GetStack()->GetCurrentTrack()->SetMother(1,points);
233
234 ((CbmStack*)gMC->GetStack())->AddPoint(kSCWALL);
235
236
237 /*//S.Merts
238 Int_t ivol = vol->getMCid();
239 if (gMC->IsTrackEntering()) {
240 ResetParameters();
241
242 fELoss = 0.;
243
244 TLorentzVector PosIn;
245 gMC->TrackPosition(PosIn);
246 fPos.SetXYZ(PosIn.X(), PosIn.Y(), PosIn.Z());
247
248 TLorentzVector MomIn;
249 gMC->TrackMomentum(MomIn);
250 fMom.SetXYZ(MomIn.Px(), MomIn.Py(), MomIn.Pz());
251
252 fTime = gMC->TrackTime() * 1.0e09;
253 fLength = gMC->TrackLength();
254 }
255
256 fELoss += gMC->Edep();
257 if (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) {
258 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
259 fVolumeID = vol->getMCid();
260 if (fELoss == 0.) {
261 return kFALSE;
262 }
263 AddHit(fTrackID, fVolumeID, fPos, fMom, fTime, fLength, fELoss);
264
265 ((CbmStack*)gMC->GetStack())->AddPoint(kHODO);
266 }
267*/
268 return kTRUE;
269}
270
271// ----- Public method EndOfEvent -----------------------------------------
272void BmnHodo::EndOfEvent() {
273 if (fVerboseLevel) Print();
274 Reset();
275}
276
277// ----- Public method Register -------------------------------------------
278void BmnHodo::Register() {
279 FairRootManager::Instance()->Register("HodoPoint", "Hodo", fHodoCollection, kTRUE);
280}
281
282// ----- Public method GetCollection --------------------------------------
283TClonesArray* BmnHodo::GetCollection(Int_t iColl) const {
284 if (iColl == 0) return fHodoCollection;
285 return NULL;
286}
287
288// ----- Public method Print ----------------------------------------------
289void BmnHodo::Print() const {
290 Int_t nHits = fHodoCollection->GetEntriesFast();
291 cout << "-I- BmnHodo: " << nHits << " points registered in this event." << endl;
292
293 if (fVerboseLevel > 1)
294 for (Int_t i = 0; i < nHits; i++) (*fHodoCollection)[i]->Print();
295}
296
297// ----- Public method Reset ----------------------------------------------
298void BmnHodo::Reset() {
299 fHodoCollection->Delete();
300}
301
302//-----------------------------------------------------------------------------
304 TString fileName = GetGeometryFileName();
305 if (fileName.EndsWith(".root")) {
306 LOG(info) << "Constructing Hodo geometry from ROOT file " << fileName.Data();
307 ConstructRootGeometry();
308 } else
309 LOG(fatal) << "Geometry format of Hodo file " << fileName.Data() << " not supported.";
310}
311
312//-----------------------------------------------------------------------------
313Bool_t BmnHodo::CheckIfSensitive(std::string name) {
314 TString tsname = name;
315 if (tsname.Contains("sens")) return kTRUE;
316 return kFALSE;
317}
318
319// ----- Private method AddHit --------------------------------------------
320BmnHodoPoint* 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) {
321 TClonesArray& clref = *fHodoCollection;
322 Int_t size = clref.GetEntriesFast();
323 return new (clref[size]) BmnHodoPoint(trackID, detID, copyNo, copyNoMother, pos, mom, time, length, eLoss);
324}
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