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"
17#include "TGeoMCGeometry.h"
18#include "TGeoManager.h"
19#include "TLorentzVector.h"
22#include "TVirtualMC.h"
26#include "FairRuntimeDb.h"
28#include "TParticlePDG.h"
32 fHodoCollection =
new TClonesArray(
"BmnHodoPoint");
35 fHodoStickSensVolId=0;
40 : FairDetector(
name, active) {
41 fHodoCollection =
new TClonesArray(
"BmnHodoPoint");
44 fHodoStickSensVolId=0;
50 if (fHodoCollection) {
51 fHodoCollection->Delete();
52 delete fHodoCollection;
60 FairDetector::Initialize();
61 FairRun* sim = FairRun::Instance();
62 FairRuntimeDb* rtdb = sim->GetRuntimeDb();
64 fHodoStickSensVolId = gMC->VolId(
"hodo_stick_sens");
83 Int_t nofHits = fHodoCollection->GetEntriesFast();
84 for (Int_t
i=0;
i<nofHits;
i++) {
97 Int_t copyNoStickSens;
98 Int_t copyNoSTICKSENSCom, copyNoSTICKCom;
101 TLorentzVector tPos1, tMom1;
102 TLorentzVector tPos, tMom;
104 Int_t sticksens, stick;
113 Double_t BirkConst = 12.6;
117 if (gMC->CurrentVolID(copyNoStickSens) != fHodoStickSensVolId)
122 ivol = vol->getMCid();
124 if (gMC->CurrentVolID(copyNoStickSens) == fHodoStickSensVolId)
126 gMC->CurrentVolOffID(0, sticksens);
127 gMC->CurrentVolOffID(1, stick);
128 copyNoSTICKSENSCom = sticksens; copyNoSTICKCom = stick;
133 if (gMC->IsTrackEntering()) {
141 TLorentzVector PosIn;
142 gMC->TrackPosition(PosIn);
143 fPos.SetXYZ(PosIn.X(), PosIn.Y(), PosIn.Z());
145 TLorentzVector MomIn;
146 gMC->TrackMomentum(MomIn);
147 fMom.SetXYZ(MomIn.Px(), MomIn.Py(), MomIn.Pz());
149 fTime = gMC->TrackTime() * 1.0e09;
150 fLength = gMC->TrackLength();
153 if ( gMC->IsTrackInside()) {
155 gMC->TrackPosition(tPos);
156 gMC->TrackMomentum(tMom);
157 length += gMC->TrackStep();
161 if(gMC->TrackStep()>0) QCF = 1.+(BirkConst/gMC->TrackStep())*gMC->Edep();
163 fELoss +=(gMC->Edep())/QCF;
165 time += gMC->TrackTime() * 1.0e09;
167 if ( gMC->IsTrackStop() || gMC->IsTrackDisappeared() ) {
169 part = gMC->GetStack()->GetCurrentTrack();
170 charge = part->GetPDG()->Charge() / 3. ;
173 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
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);
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);
195 if ( gMC->IsTrackExiting()) {
197 part = gMC->GetStack()->GetCurrentTrack();
200 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
201 time += gMC->TrackTime() * 1.0e09;
202 length += gMC->TrackLength();
206 if(gMC->TrackStep()>0) QCF = 1.+(BirkConst/gMC->TrackStep())*gMC->Edep();
208 fELoss +=(gMC->Edep())/QCF;
210 gMC->TrackPosition(tPos);
211 gMC->TrackMomentum(tMom);
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);
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);
226 Int_t points = gMC->GetStack()->GetCurrentTrack()->GetMother(1);
227 points = ( points & ( ~ (1<<30) ) ) | (1 << 30);
229 gMC->GetStack()->GetCurrentTrack()->SetMother(1,points);
270 if (fVerboseLevel)
Print();
276 FairRootManager::Instance()->Register(
"HodoPoint",
"Hodo", fHodoCollection, kTRUE);
281 if (iColl == 0)
return fHodoCollection;
287 Int_t nHits = fHodoCollection->GetEntriesFast();
288 cout <<
"-I- BmnHodo: " << nHits <<
" points registered in this event." << endl;
290 if (fVerboseLevel > 1)
291 for (Int_t
i = 0;
i < nHits;
i++) (*fHodoCollection)[
i]->Print();
296 fHodoCollection->Delete();
301 TString fileName = GetGeometryFileName();
302 if (fileName.EndsWith(
".root")) {
303 LOG(info) <<
"Constructing Hodo geometry from ROOT file " << fileName.Data();
304 ConstructRootGeometry();
306 LOG(fatal) <<
"Geometry format of Hodo file " << fileName.Data() <<
" not supported.";
311 TString tsname =
name;
312 if (tsname.Contains(
"sens"))
return kTRUE;
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);
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
virtual Bool_t CheckIfSensitive(std::string name)
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)
virtual void Print(Option_t *) const
virtual void ConstructGeometry()
BmnHodoPoint * GetHit(Int_t i) const
virtual void Initialize()
virtual Bool_t ProcessHits(FairVolume *vol=0)
virtual void EndOfEvent()