7 #include <FairDetector.h>
8 #include <FairLogger.h>
9 #include <FairRootManager.h>
10 #include <FairVolume.h>
12 #include <TClonesArray.h>
13 #include <TGeoManager.h>
14 #include <TLorentzVector.h>
16 #include <TVirtualMC.h>
17 #include <TVirtualMCStack.h>
25 : FairDetector(
"AtSiArray", kTRUE,
kAtSiArray), fTrackID(-1), fVolumeID(-1), fPos(), fMom(), fTime(-1.),
26 fLength(-1.), fELoss(-1), fPosIndex(-1), fAtSiArrayPointCollection(new TClonesArray(
"AtSiPoint")), fELossAcc(-1)
32 : FairDetector(name, active,
kAtSiArray), fTrackID(-1), fVolumeID(-1), fPos(), fMom(), fTime(-1.), fLength(-1.),
33 fELoss(-1), fPosIndex(-1), fAtSiArrayPointCollection(new TClonesArray(
"AtSiPoint")), fELossAcc(-1)
40 if (fAtSiArrayPointCollection) {
41 fAtSiArrayPointCollection->Delete();
42 delete fAtSiArrayPointCollection;
48 FairDetector::Initialize();
57 auto *stack =
dynamic_cast<AtStack *
>(TVirtualMC::GetMC()->GetStack());
58 std::pair<Int_t, Int_t> AZ;
60 fVolName = gMC->CurrentVolName();
63 LOG(debug) <<
"In AtSiArray::ProcessHits";
65 if (TVirtualMC::GetMC()->IsTrackEntering()) {
68 fTime = TVirtualMC::GetMC()->TrackTime() * 1.0e09;
69 fLength = TVirtualMC::GetMC()->TrackLength();
70 TVirtualMC::GetMC()->TrackPosition(fPosIn);
71 TVirtualMC::GetMC()->TrackMomentum(fMomIn);
73 std::cout <<
" AtSiArray: Track is entering "
75 LOG(INFO) <<
" HELIOS: First hit in Volume " << fVolName;
76 LOG(INFO) <<
" Particle : " << gMC->ParticleName(gMC->TrackPid());
77 LOG(INFO) <<
" PID PdG : " << gMC->TrackPid();
78 LOG(INFO) <<
" Atomic Mass : " << AZ.first;
79 LOG(INFO) <<
" Atomic Number : " << AZ.second;
80 LOG(INFO) <<
" Volume ID " << gMC->CurrentVolID(VolumeID);
81 LOG(INFO) <<
" Track ID : " << fTrackID;
82 LOG(INFO) <<
" Position In : " << fPosIn.X() <<
" " << fPosIn.Y() <<
" " << fPosIn.Z() << std::endl;
83 LOG(INFO) <<
" Position Out : " << fPosOut.X() <<
" " << fPosOut.Y() <<
" " << fPosOut.Z() << std::endl;
84 LOG(INFO) <<
" Momentum In: " << fMomIn.X() <<
" " << fMomIn.Y() <<
" " << fMomIn.Z() << std::endl;
93 fELoss = TVirtualMC::GetMC()->Edep();
95 gMC->TrackPosition(fPosIn);
96 gMC->TrackMomentum(fMomIn);
97 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
98 fVolumeID = vol->getMCid();
99 fTime = gMC->TrackTime() * 1.0e09;
100 fLength = gMC->TrackLength();
103 if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop() ||
104 TVirtualMC::GetMC()->IsTrackDisappeared()) {
105 fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber();
106 fVolumeID = vol->getMCid();
107 TVirtualMC::GetMC()->TrackPosition(fPosOut);
108 TVirtualMC::GetMC()->TrackMomentum(fMomOut);
114 if (gMC->IsTrackExiting()) {
116 const Double_t *oldpos =
nullptr;
117 const Double_t *olddirection =
nullptr;
119 Double_t newdirection[3];
122 gGeoManager->FindNode(fPosOut.X(), fPosOut.Y(), fPosOut.Z());
123 oldpos = gGeoManager->GetCurrentPoint();
124 olddirection = gGeoManager->GetCurrentDirection();
126 for (Int_t i = 0; i < 3; i++) {
127 newdirection[i] = -1 * olddirection[i];
130 gGeoManager->SetCurrentDirection(newdirection);
132 safety = gGeoManager->GetSafeDistance();
134 gGeoManager->SetCurrentDirection(-newdirection[0], -newdirection[1], -newdirection[2]);
136 for (Int_t i = 0; i < 3; i++) {
137 newpos[i] = oldpos[i] - (3 * safety * olddirection[i]);
140 fPosOut.SetX(newpos[0]);
141 fPosOut.SetY(newpos[1]);
142 fPosOut.SetZ(newpos[2]);
144 std::cout <<
" AtSiArray: Track is exiting "
146 LOG(INFO) <<
" HELIOS: First hit in Volume " << fVolName;
147 LOG(INFO) <<
" Particle : " << gMC->ParticleName(gMC->TrackPid());
148 LOG(INFO) <<
" PID PdG : " << gMC->TrackPid();
149 LOG(INFO) <<
" Atomic Mass : " << AZ.first;
150 LOG(INFO) <<
" Atomic Number : " << AZ.second;
151 LOG(INFO) <<
" Volume ID " << gMC->CurrentVolID(VolumeID);
152 LOG(INFO) <<
" Track ID : " << fTrackID;
153 LOG(INFO) <<
" Position In : " << fPosIn.X() <<
" " << fPosIn.Y() <<
" " << fPosIn.Z() << std::endl;
154 LOG(INFO) <<
" Position Out : " << fPosOut.X() <<
" " << fPosOut.Y() <<
" " << fPosOut.Z() << std::endl;
155 LOG(INFO) <<
" Momentum In: " << fMomIn.X() <<
" " << fMomIn.Y() <<
" " << fMomIn.Z() << std::endl;
156 LOG(INFO) <<
" Momentum Out: " << fMomOut.X() <<
" " << fMomOut.Y() <<
" " << fMomOut.Z() << std::endl;
182 AddHit(fTrackID, fVolumeID, fVolName, fDetCopyID, TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
183 TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()), TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
184 TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()), fTime, fLength, fELoss, 0.0, 0.0, AZ.first, AZ.second);
194 fAtSiArrayPointCollection->Clear();
206 FairRootManager::Instance()->Register(
"AtSiArrayPoint",
"AtSiArray", fAtSiArrayPointCollection, kTRUE);
212 return fAtSiArrayPointCollection;
220 fAtSiArrayPointCollection->Clear();
225 Int_t nHits = fAtSiArrayPointCollection->GetEntriesFast();
226 LOG(INFO) <<
"Si Array: " << nHits <<
" points registered in this event";
231 TString fileName = GetGeometryFileName();
232 if (fileName.EndsWith(
".geo")) {
233 LOG(INFO) <<
"Constructing Si Array geometry from ASCII file " << fileName;
235 }
else if (fileName.EndsWith(
".root")) {
236 LOG(INFO) <<
"Constructing Si Array geometry from ROOT file " << fileName;
237 ConstructRootGeometry();
239 std::cout <<
"Geometry format not supported." << std::endl;
246 TString tsname = name;
247 if (tsname.Contains(
"silicon")) {
248 LOG(INFO) <<
" Si Array geometry: Sensitive volume found: " << tsname;
257 TClonesArray &clref = *fAtSiArrayPointCollection;
258 Int_t size = clref.GetEntriesFast();
259 return new (clref[size])
AtSiPoint(trackID, detID, pos, mom, time, length, eLoss);
264 TVector3 posOut, TVector3 momIn, TVector3 momOut, Double_t time, Double_t length,
265 Double_t eLoss, Double_t EIni, Double_t AIni, Int_t A, Int_t Z)
267 TClonesArray &clref = *fAtSiArrayPointCollection;
268 Int_t size = clref.GetEntriesFast();
272 if (fVerboseLevel > 1)
273 LOG(INFO) <<
"Si Array: Adding Point at (" << posIn.X() <<
", " << posIn.Y() <<
", " << posIn.Z()
274 <<
") cm, detector " << detID <<
", track " << trackID <<
", energy loss " << eLoss * 1e06 <<
" keV";
276 return new (clref[size])
AtSiPoint(trackID, detID, posIn, posOut, momIn, momOut, time, length, eLoss, VolName,
277 detCopyID, EIni, AIni, A, Z);
282 Int_t A = PdG_Code / 10 % 1000;
283 Int_t Z = PdG_Code / 10000 % 1000;
285 std::pair<Int_t, Int_t> nucleus;
287 if (PdG_Code == 2212) {
290 }
else if (PdG_Code == 2112) {