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();
159 fELoss +=gMC->Edep();
166 time += gMC->TrackTime() * 1.0e09;
168 if ( gMC->IsTrackStop() || gMC->IsTrackDisappeared() ) {
170 part = gMC->GetStack()->GetCurrentTrack();
171 charge = part->GetPDG()->Charge() / 3. ;
174 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
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);
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);
196 if ( gMC->IsTrackExiting()) {
198 part = gMC->GetStack()->GetCurrentTrack();
201 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
202 time += gMC->TrackTime() * 1.0e09;
203 length += gMC->TrackLength();
205 fELoss +=gMC->Edep();
213 gMC->TrackPosition(tPos);
214 gMC->TrackMomentum(tMom);
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);
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);
229 Int_t points = gMC->GetStack()->GetCurrentTrack()->GetMother(1);
230 points = ( points & ( ~ (1<<30) ) ) | (1 << 30);
232 gMC->GetStack()->GetCurrentTrack()->SetMother(1,points);
273 if (fVerboseLevel)
Print();
279 FairRootManager::Instance()->Register(
"HodoPoint",
"Hodo", fHodoCollection, kTRUE);
284 if (iColl == 0)
return fHodoCollection;
290 Int_t nHits = fHodoCollection->GetEntriesFast();
291 cout <<
"-I- BmnHodo: " << nHits <<
" points registered in this event." << endl;
293 if (fVerboseLevel > 1)
294 for (Int_t
i = 0;
i < nHits;
i++) (*fHodoCollection)[
i]->Print();
299 fHodoCollection->Delete();
304 TString fileName = GetGeometryFileName();
305 if (fileName.EndsWith(
".root")) {
306 LOG(info) <<
"Constructing Hodo geometry from ROOT file " << fileName.Data();
307 ConstructRootGeometry();
309 LOG(fatal) <<
"Geometry format of Hodo file " << fileName.Data() <<
" not supported.";
314 TString tsname =
name;
315 if (tsname.Contains(
"sens"))
return kTRUE;
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);
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()