er  dev
ERDecay.cxx
1 /********************************************************************************
2  * Copyright (C) Joint Institute for Nuclear Research *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8  #include "ERDecay.h"
9 
10 #include <iostream>
11 
12 #include "TVirtualMC.h"
13 #include "TLorentzVector.h"
14 #include "TMCProcess.h"
15 #include "TGeoManager.h"
16 #include "TGeoVolume.h"
17 #include "TGeoBBox.h"
18 #include "TRandom3.h"
19 
20 #include "FairRunSim.h"
21 #include "FairLogger.h"
22 
23 //#include "ERTarget.h"
24 #include "ERMCEventHeader.h" //for ERMCEventHeader
25 
26 //--------------------------------------------------------------------------------------------------
27 ERDecay::ERDecay(TString name)
28 : fName(name),
29  fInteractionVolumeName(""),
30  fNuclearInteractionLength(0.),
31  // fInteractProbability(0.),
32  fNormalizingProbability(0.),
33  fIsInterationPointFound(kFALSE)
34 {
35  fRnd1 = new TRandom3();
36  fRnd2 = new TRandom3();
37  fRnd = new TRandom3();
38 }
39 //--------------------------------------------------------------------------------------------------
40 ERDecay::~ERDecay(){
41 }
42 
43 void ERDecay::SetInputIon(Int_t A, Int_t Z, Int_t Q){
44  FairRunSim* run = FairRunSim::Instance();
45  fInputIonName = fName + TString("_InputIon");
46  FairIon* ion = new FairIon(fInputIonName,A,Z,Q);
47  run->AddNewIon(ion);
48 }
49 
50 void ERDecay::SetUniformPos(Double_t a, Double_t b){
51  fUniform = kTRUE;
52  fUniformA = a;
53  fUniformB = b;
54 }
55 
56 void ERDecay::SetExponentialPos(Double_t start, Double_t tau){
57  fExponential = kTRUE;
58  fExponentialStart = start;
59  fExponentialTau = tau;
60 }
61 
62 void ERDecay::BeginEvent(){
63  fDecayFinish = kFALSE;
64  if (fUniform){
65  fDecayPosZ = fRnd->Uniform(fUniformA, fUniformB);
66  }
67  if (fExponential){
68  fDecayPosZ = fExponentialStart + fRnd->Exp(fExponentialTau);
69  }
70 }
71 
72 void ERDecay::FinishEvent(){
73 }
74 
75 Bool_t ERDecay::Init(){
76  if (fInputIonName == ""){
77  LOG(FATAL) << "Input ion not defined!" << FairLogger::endl;
78  return kFALSE;
79  }
80 
81  fInputIonPDG = TDatabasePDG::Instance()->GetParticle(fInputIonName);
82  if ( ! fInputIonPDG ) {
83  LOG(FATAL) << "Input ion not found in pdg database!" << FairLogger::endl;
84  return kFALSE;
85  }
86 
87  return kTRUE;
88 }
89 
90 void ERDecay::AddParticleToStack(Int_t pdg, TLorentzVector pos, TLorentzVector state){
91  Int_t newTrackNb;
92  gMC->GetStack()->PushTrack(1,gMC->GetStack()->GetCurrentTrackNumber(), pdg,
93  state.Px(),state.Py(),state.Pz(),state.E(),
94  pos.X(), pos.Y(), pos.Z(),
95  gMC->TrackTime(), 0., 0., 0.,
96  kPDecay, newTrackNb, fInputIonPDG->Mass(),0);
97  LOG(DEBUG) << "ERDecay: Added output particle with ID = " << newTrackNb << " PDG = " << pdg
98  << "; pos=(" << pos.X() << "," << pos.Y() << "," << pos.Z()
99  << "); mom=(" << state.Px() << "," << state.Py() << "," << state.Pz() << ")" << FairLogger::endl;
100 }
101 //--------------------------------------------------------------------------------------------------
102 void ERDecay::SetMaxPathLength(Double_t pathLength) {
103  fNormalizingProbability = 1 - TMath::Exp(-pathLength / fNuclearInteractionLength);
104 }
105 //--------------------------------------------------------------------------------------------------
106 void ERDecay::CalculateTargetParameters() {
107  LOG(DEBUG) << "ERDecay: calculated parameters " << FairLogger::endl;
108  if (fInteractionVolumeName != "") {
109  TGeoVolume* vol = gGeoManager->FindVolumeFast(fInteractionVolumeName);
110  TGeoBBox* shape = (TGeoBBox*)vol->GetShape(); // we use conversion of shape type to TGeoBBox because all shape types in ROOT inherited from TGeoBBox;
111  Double_t boundX = 2 * shape->GetDX();
112  Double_t boundY = 2 * shape->GetDY();
113  Double_t boundZ = 2 * shape->GetDZ();
114  LOG(DEBUG) << "ERDecay: bounding box x = " << boundX
115  << "; y = " << boundY
116  << "; z = " << boundZ << FairLogger::endl;
117  // fTargetBoundBoxDiagonal = TMath::Sqrt(boundX*boundX + boundY*boundY + boundZ*boundZ);
118  // fNormalizingProbability = 1 - TMath::Exp(-fTargetBoundBoxDiagonal / fNuclearInteractionLength);
119  }
120 }
121 //--------------------------------------------------------------------------------------------------
123  if (!fIsInterationPointFound) {
124  gGeoManager->FindNextBoundary(); // find a step to a next boudary along current track direction
125  Double_t distToNextBoundary = gGeoManager->GetStep(); // get calculated step
126  LOG(DEBUG) << "[ERDecay::FindInteractionPoint] distance to a next boundary "
127  << distToNextBoundary << FairLogger::endl;
128  Double_t interactionProbNextBound = 1 - TMath::Exp(-distToNextBoundary /
129  fNuclearInteractionLength);
130  Double_t interactProbability = interactionProbNextBound / fNormalizingProbability; // the interaction probability in current direction in the defined volume
131  if (interactProbability > 1) {
132  LOG(ERROR) << "[ERDecay::FindInteractionPoint] interaction probability "
133  << "in current direction more then 1, "
134  << "incorrect normalizing respect to maximum path length in an interaction volume"
135  << FairLogger::endl;
136  }
137  LOG(DEBUG) << "[ERDecay::FindInteractionPoint] interaction probability in current direction "
138  << interactProbability
139  << "; normalizing probability is " << fNormalizingProbability << FairLogger::endl;
140  if (fRnd1->Uniform(0, 1) > interactProbability) {
141  LOG(DEBUG) << "Interaction hasn't happened with defined Interaction length and max path length"
142  << FairLogger::endl;
143  return kFALSE;
144  } else {
145  fDistanceToInteractPoint = -TMath::Log(1 - fRnd2->Uniform(0, interactionProbNextBound))
146  * fNuclearInteractionLength;
147  LOG(DEBUG) << "[ERDecay::FindInteractionPoint] distance to an interaction point "
148  << "in current direction " << fDistanceToInteractPoint << FairLogger::endl;
149  fIsInterationPointFound = kTRUE;
150  return kTRUE;
151  }
152  }
153 }
154 //--------------------------------------------------------------------------------------------------
155 ClassImp(ERDecay)
void SetMaxPathLength(Double_t pathLength)
Defines maximum path length for particles in the volume that is defined in SetInteractionVolumeName()...
Definition: ERDecay.cxx:102
Bool_t FindInteractionPoint()
Definition: ERDecay.cxx:122