11 #include "G4IonTable.hh" 12 #include "G4ParticleDefinition.hh" 13 #include "G4Neutron.hh" 14 #include "G4EmCalculator.hh" 15 #include "G4NistManager.hh" 17 #include "TGeoManager.h" 19 #include "FairLogger.h" 21 #include "ERNDTrack.h" 22 #include "ERBeamDetParticle.h" 23 #include "ERSupport.h" 26 :
ERTask(
"ER ND particle reconstruction.")
33 FairRootManager* ioman = FairRootManager::Instance();
34 if ( ! ioman ) Fatal(
"Init",
"No FairRootManager");
35 fNDTracks = (TClonesArray*) ioman->GetObject(
"NDTrack");
36 if (!fNDTracks) Fatal(
"Init",
"Can`t find collection NDTrack!");
37 fNDParticles =
new TClonesArray(
"ERNDParticle",1000);
38 ioman->Register(
"NDParticle",
"ND particle", fNDParticles, kTRUE);
39 fSetup = ERNDSetup::Instance();
40 fSetup->ReadGeoParamsFromParContainer();
41 fBeamDetParticle = (TClonesArray*) ioman->GetObject(
"BeamDetParticle.");
42 if (!fBeamDetParticle) {
43 LOG(FATAL) <<
"Branch BeamDetParticle not found." << FairLogger::endl;
48 Double_t KineticEnergyOnTarget(
const ERNDTrack& track, Double_t kineticEnergy) {
50 auto backDirection = (track.TargetVertex() - track.
DetectorVertex());
51 backDirection.SetMag(1.);
52 TGeoNode* node = gGeoManager->InitTrack(
54 backDirection.X(), backDirection.Y(), backDirection.Z());
55 Bool_t targetHasPassed = kFALSE;
56 const auto particle = G4Neutron::Definition();
57 while(!gGeoManager->IsOutside()) {
58 gGeoManager->FindNextBoundary();
59 const bool trackInTarget = TString(gGeoManager->GetPath()).Contains(
"target");
60 if (targetHasPassed && !trackInTarget)
62 targetHasPassed = trackInTarget;
63 const auto step = gGeoManager->GetStep();
65 const auto range = trackInTarget ? step / 2 : step;
66 const TString materialName = node->GetMedium()->GetMaterial()->GetName();
67 if (materialName == TString(
"Stilbene")) {
68 node = gGeoManager->Step();
71 const auto* material = G4NistManager::Instance()->FindOrBuildMaterial(materialName.Data());
72 LOG(DEBUG) <<
"[ERNDPID] [CalcEnergyDeposites]" 73 <<
" Calc energy deposite for range " << range <<
" in materail " 74 << materialName <<
" with kinetic energy " << kineticEnergy << FairLogger::endl;
75 const auto deadDeposite = CalcElossIntegralVolStep(kineticEnergy, *particle, *material, range);
76 kineticEnergy += deadDeposite;
77 node = gGeoManager->Step();
82 void ERNDPID::Exec(Option_t* opt) {
85 if (!beamdet_particle) {
89 const Double_t mass = 939.57;
90 const auto calcState = [mass](
const ERNDTrack* track, Double_t kineticEnergy) -> TLorentzVector {
91 const Double_t momentumMag = sqrt(pow(kineticEnergy, 2) + 2 * mass * kineticEnergy);
92 TVector3 direction = (track->
DetectorVertex()-track->TargetVertex());
94 const auto momentum = momentumMag * direction;
95 const Double_t fullEnergy = sqrt(pow(momentumMag, 2)+pow(mass, 2));
96 return TLorentzVector(momentum, fullEnergy);
98 for (Int_t iTrack(0); iTrack < fNDTracks->GetEntriesFast(); iTrack++) {
99 const auto* track =
static_cast<ERNDTrack*
>(fNDTracks->At(iTrack));
100 auto kineticEnergy = track->Edep();
101 TLorentzVector detectorState = calcState(track, kineticEnergy);
102 auto time_on_target = beamdet_particle->time_on_target();
103 auto time = track->Time();
104 auto tof = time - time_on_target;
105 auto distance_between_target_and_detector = (track->
DetectorVertex() - track->TargetVertex()).Mag();
106 auto beta = distance_between_target_and_detector * 1e-2 / (tof * 1e-9) / TMath::C();
108 if(beta <= 0 || beta >= 1) {
109 LOG(DEBUG) <<
"[ERNDPID] Wrong beta " << beta << FairLogger::endl;
112 auto gamma = 1. / TMath::Sqrt(1.- beta * beta);
113 auto p = beta * gamma * mass;
114 auto E = TMath::Sqrt(p * p + mass * mass);
115 TLorentzVector lv(p * TMath::Sin(track->Direction().Theta()) * TMath::Cos(track->Direction().Phi()),
116 p * TMath::Sin(track->Direction().Theta()) * TMath::Sin(track->Direction().Phi()),
117 p * TMath::Cos(track->Direction().Theta()),
119 AddParticle(lv, tof);
124 fNDParticles->Clear();
127 ERNDParticle* ERNDPID::AddParticle(
const TLorentzVector& lv,
float tof) {
128 return new((*fNDParticles)[fNDParticles->GetEntriesFast()])
TVector3 DetectorVertex() const
virtual InitStatus Init()
virtual InitStatus Init()
Base abstract class for all tasks in er.