CMS 3D CMS Logo

GflashHadronShowerModel.cc
Go to the documentation of this file.
2 
4 
14 
15 #include "G4EventManager.hh"
16 #include "G4FastSimulationManager.hh"
17 #include "G4TouchableHandle.hh"
18 #include "G4TransportationManager.hh"
19 #include "G4VPhysicalVolume.hh"
20 #include "G4VSensitiveDetector.hh"
21 
22 #include "G4AntiProton.hh"
23 #include "G4KaonMinus.hh"
24 #include "G4KaonPlus.hh"
25 #include "G4PionMinus.hh"
26 #include "G4PionPlus.hh"
27 #include "G4Proton.hh"
28 #include "G4VProcess.hh"
29 
30 #include <vector>
31 
32 using namespace CLHEP;
33 
35  G4Region *envelope,
36  const edm::ParameterSet &parSet)
37  : G4VFastSimulationModel(modelName, envelope), theParSet(parSet) {
38  theWatcherOn = parSet.getParameter<bool>("watcherOn");
39 
47 
48  theGflashStep = new G4Step();
49  theGflashTouchableHandle = new G4TouchableHistory();
50  theGflashNavigator = new G4Navigator();
51 }
52 
54  if (theProfile)
55  delete theProfile;
56  if (theGflashStep)
57  delete theGflashStep;
58 }
59 
60 G4bool GflashHadronShowerModel::IsApplicable(const G4ParticleDefinition &particleType) {
61  return &particleType == G4PionMinus::PionMinusDefinition() || &particleType == G4PionPlus::PionPlusDefinition() ||
62  &particleType == G4KaonMinus::KaonMinusDefinition() || &particleType == G4KaonPlus::KaonPlusDefinition() ||
63  &particleType == G4AntiProton::AntiProtonDefinition() || &particleType == G4Proton::ProtonDefinition();
64 }
65 
66 G4bool GflashHadronShowerModel::ModelTrigger(const G4FastTrack &fastTrack) {
67  // ModelTrigger returns false for Gflash Hadronic Shower Model if it is not
68  // tested from the corresponding wrapper process, GflashHadronWrapperProcess.
69  // Temporarily the track status is set to fPostponeToNextEvent at the wrapper
70  // process before ModelTrigger is really tested for the second time through
71  // PostStepGPIL of enviaged parameterization processes. The better
72  // implmentation may be using via G4VUserTrackInformation of each track, which
73  // requires to modify a geant source code of stepping (G4SteppingManager2)
74 
75  G4bool trigger = false;
76 
77  // mininum energy cutoff to parameterize
78  if (fastTrack.GetPrimaryTrack()->GetKineticEnergy() < Gflash::energyCutOff * CLHEP::GeV)
79  return trigger;
80 
81  // check whether this is called from the normal GPIL or the wrapper process
82  // GPIL
83  if (fastTrack.GetPrimaryTrack()->GetTrackStatus() == fPostponeToNextEvent) {
84  // Shower pameterization start at the first inelastic interaction point
85  G4bool isInelastic = isFirstInelasticInteraction(fastTrack);
86 
87  // Other conditions
88  if (isInelastic) {
89  trigger = (!excludeDetectorRegion(fastTrack));
90  }
91  }
92 
93  return trigger;
94 }
95 
96 void GflashHadronShowerModel::DoIt(const G4FastTrack &fastTrack, G4FastStep &fastStep) {
97  // kill the particle
98  fastStep.KillPrimaryTrack();
99  fastStep.ProposePrimaryTrackPathLength(0.0);
100 
101  // parameterize energy depostion by the particle type
102  G4ParticleDefinition *particleType = fastTrack.GetPrimaryTrack()->GetDefinition();
103 
105  if (particleType == G4KaonMinus::KaonMinusDefinition())
107  else if (particleType == G4KaonPlus::KaonPlusDefinition())
109  else if (particleType == G4AntiProton::AntiProtonDefinition())
111  else if (particleType == G4Proton::ProtonDefinition())
113 
114  // input variables for GflashHadronShowerProfile
115  G4double energy = fastTrack.GetPrimaryTrack()->GetKineticEnergy() / GeV;
116  G4double globalTime = fastTrack.GetPrimaryTrack()->GetStep()->GetPostStepPoint()->GetGlobalTime();
117  G4double charge = fastTrack.GetPrimaryTrack()->GetStep()->GetPreStepPoint()->GetCharge();
118  G4ThreeVector position = fastTrack.GetPrimaryTrack()->GetPosition() / cm;
119  G4ThreeVector momentum = fastTrack.GetPrimaryTrack()->GetMomentum() / GeV;
120  G4int showerType = Gflash::findShowerType(position);
121 
122  theProfile->initialize(showerType, energy, globalTime, charge, position, momentum);
125 
126  // make hits
127  makeHits(fastTrack);
128 }
129 
130 void GflashHadronShowerModel::makeHits(const G4FastTrack &fastTrack) {
131  std::vector<GflashHit> &gflashHitList = theProfile->getGflashHitList();
132 
133  theGflashStep->SetTrack(const_cast<G4Track *>(fastTrack.GetPrimaryTrack()));
134  theGflashStep->GetPostStepPoint()->SetProcessDefinedStep(
135  const_cast<G4VProcess *>(fastTrack.GetPrimaryTrack()->GetStep()->GetPostStepPoint()->GetProcessDefinedStep()));
136  theGflashNavigator->SetWorldVolume(
137  G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume());
138 
139  std::vector<GflashHit>::const_iterator spotIter = gflashHitList.begin();
140  std::vector<GflashHit>::const_iterator spotIterEnd = gflashHitList.end();
141 
142  for (; spotIter != spotIterEnd; spotIter++) {
143  theGflashNavigator->LocateGlobalPointAndUpdateTouchableHandle(
144  spotIter->getPosition(), G4ThreeVector(0, 0, 0), theGflashTouchableHandle, false);
145  updateGflashStep(spotIter->getPosition(), spotIter->getTime());
146 
147  const G4VPhysicalVolume *aCurrentVolume = theGflashStep->GetPreStepPoint()->GetPhysicalVolume();
148  if (aCurrentVolume == nullptr)
149  continue;
150 
151  const G4LogicalVolume *lv = aCurrentVolume->GetLogicalVolume();
152  if (lv->GetRegion()->GetName() != "CaloRegion")
153  continue;
154 
155  theGflashStep->GetPreStepPoint()->SetSensitiveDetector(aCurrentVolume->GetLogicalVolume()->GetSensitiveDetector());
156  G4VSensitiveDetector *aSensitive = theGflashStep->GetPreStepPoint()->GetSensitiveDetector();
157 
158  if (aSensitive == nullptr)
159  continue;
160 
161  G4String nameCalor = aCurrentVolume->GetName();
162  nameCalor.assign(nameCalor, 0, 2);
163  G4double samplingWeight = 1.0;
164  if (nameCalor == "HB") {
165  samplingWeight = Gflash::scaleSensitiveHB;
166  } else if (nameCalor == "HE" || nameCalor == "HT") {
167  samplingWeight = Gflash::scaleSensitiveHE;
168  }
169  theGflashStep->SetTotalEnergyDeposit(spotIter->getEnergy() * samplingWeight);
170 
171  aSensitive->Hit(theGflashStep);
172  }
173 }
174 
175 void GflashHadronShowerModel::updateGflashStep(const G4ThreeVector &spotPosition, G4double timeGlobal) {
176  theGflashStep->GetPostStepPoint()->SetGlobalTime(timeGlobal);
177  theGflashStep->GetPreStepPoint()->SetPosition(spotPosition);
178  theGflashStep->GetPostStepPoint()->SetPosition(spotPosition);
179  theGflashStep->GetPreStepPoint()->SetTouchableHandle(theGflashTouchableHandle);
180 }
181 
182 G4bool GflashHadronShowerModel::isFirstInelasticInteraction(const G4FastTrack &fastTrack) {
183  G4bool isFirst = false;
184 
185  G4StepPoint *preStep = fastTrack.GetPrimaryTrack()->GetStep()->GetPreStepPoint();
186  G4StepPoint *postStep = fastTrack.GetPrimaryTrack()->GetStep()->GetPostStepPoint();
187 
188  G4String procName = postStep->GetProcessDefinedStep()->GetProcessName();
189  G4ParticleDefinition *particleType = fastTrack.GetPrimaryTrack()->GetDefinition();
190 
191  //@@@ this part is still temporary and the cut for the variable ratio should
192  // be optimized later
193 
194  if ((particleType == G4PionPlus::PionPlusDefinition() && procName == "WrappedPionPlusInelastic") ||
195  (particleType == G4PionMinus::PionMinusDefinition() && procName == "WrappedPionMinusInelastic") ||
196  (particleType == G4KaonPlus::KaonPlusDefinition() && procName == "WrappedKaonPlusInelastic") ||
197  (particleType == G4KaonMinus::KaonMinusDefinition() && procName == "WrappedKaonMinusInelastic") ||
198  (particleType == G4AntiProton::AntiProtonDefinition() && procName == "WrappedAntiProtonInelastic") ||
199  (particleType == G4Proton::ProtonDefinition() && procName == "WrappedProtonInelastic")) {
200  // skip to the second interaction if the first inelastic is a quasi-elastic
201  // like interaction
202  //@@@ the cut may be optimized later
203 
204  const G4TrackVector *fSecondaryVector = fastTrack.GetPrimaryTrack()->GetStep()->GetSecondary();
205  G4double leadingEnergy = 0.0;
206 
207  // loop over 'all' secondaries including those produced by continuous
208  // processes.
209  //@@@may require an additional condition only for hadron interaction with
210  // the process name, but it will not change the result anyway
211 
212  for (unsigned int isec = 0; isec < fSecondaryVector->size(); isec++) {
213  G4Track *fSecondaryTrack = (*fSecondaryVector)[isec];
214  G4double secondaryEnergy = fSecondaryTrack->GetKineticEnergy();
215 
216  if (secondaryEnergy > leadingEnergy) {
217  leadingEnergy = secondaryEnergy;
218  }
219  }
220 
221  if ((preStep->GetTotalEnergy() != 0) && (leadingEnergy / preStep->GetTotalEnergy() < Gflash::QuasiElasticLike))
222  isFirst = true;
223 
224  // Fill debugging histograms and check information on secondaries -
225  // remove after final implimentation
226 
227  if (theHisto->getStoreFlag()) {
228  theHisto->preStepPosition->Fill(preStep->GetPosition().getRho() / cm);
229  theHisto->postStepPosition->Fill(postStep->GetPosition().getRho() / cm);
230  theHisto->deltaStep->Fill((postStep->GetPosition() - preStep->GetPosition()).getRho() / cm);
231  theHisto->kineticEnergy->Fill(fastTrack.GetPrimaryTrack()->GetKineticEnergy() / GeV);
232  theHisto->energyLoss->Fill(fabs(fastTrack.GetPrimaryTrack()->GetStep()->GetDeltaEnergy() / GeV));
233  theHisto->energyRatio->Fill(leadingEnergy / preStep->GetTotalEnergy());
234  }
235  }
236  return isFirst;
237 }
238 
239 G4bool GflashHadronShowerModel::excludeDetectorRegion(const G4FastTrack &fastTrack) {
240  const double invcm = 1.0 / CLHEP::cm;
241  G4bool isExcluded = false;
242  int verbosity = theParSet.getUntrackedParameter<int>("Verbosity");
243 
244  // exclude regions where geometry are complicated
245  //+- one supermodule around the EB/EE boundary: 1.479 +- 0.0174*5
246  G4double eta = fastTrack.GetPrimaryTrack()->GetPosition().pseudoRapidity();
247  if (std::fabs(eta) > 1.392 && std::fabs(eta) < 1.566) {
248  if (verbosity > 0) {
249  edm::LogVerbatim("SimGeneralGFlash") << "GflashHadronShowerModel: excluding region of eta = " << eta;
250  }
251  return true;
252  } else {
253  const G4StepPoint *postStep = fastTrack.GetPrimaryTrack()->GetStep()->GetPostStepPoint();
254 
255  Gflash::CalorimeterNumber kCalor = Gflash::getCalorimeterNumber(postStep->GetPosition() * invcm);
256  G4double distOut = 9999.0;
257 
258  // exclude the region where the shower starting point is inside the
259  // preshower
260  if (std::fabs(eta) > Gflash::EtaMin[Gflash::kENCA] &&
261  std::fabs((postStep->GetPosition()).getZ() / CLHEP::cm) < Gflash::Zmin[Gflash::kENCA]) {
262  return true;
263  }
264 
265  //<---the shower starting point is always inside envelopes
266  //@@@exclude the region where the shower starting point is too close to the
267  // end of the hadronic envelopes (may need to be optimized further!)
268  //@@@if we extend parameterization including Magnet/HO, we need to change
269  // this strategy
270  if (kCalor == Gflash::kHB) {
271  distOut = Gflash::Rmax[Gflash::kHB] - postStep->GetPosition().getRho() * invcm;
272  if (distOut < Gflash::MinDistanceToOut)
273  isExcluded = true;
274  } else if (kCalor == Gflash::kHE) {
275  distOut = Gflash::Zmax[Gflash::kHE] - std::fabs(postStep->GetPosition().getZ() * invcm);
276  if (distOut < Gflash::MinDistanceToOut)
277  isExcluded = true;
278  }
279 
280  //@@@remove this print statement later
281  if (isExcluded && verbosity > 0) {
282  G4cout << "GflashHadronShowerModel: skipping kCalor = " << kCalor << " DistanceToOut " << distOut << " from ("
283  << (postStep->GetPosition()).getRho() * invcm << ":" << (postStep->GetPosition()).getZ() * invcm
284  << ") of KE = " << fastTrack.GetPrimaryTrack()->GetKineticEnergy() / CLHEP::GeV << G4endl;
285  }
286  }
287 
288  return isExcluded;
289 }
Log< level::Info, true > LogVerbatim
const double MinDistanceToOut
static GflashHistogram * instance()
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
const double Zmax[kNumberCalorimeter]
GflashKaonMinusShowerProfile * theKaonMinusProfile
GflashAntiProtonShowerProfile * theAntiProtonProfile
G4bool ModelTrigger(const G4FastTrack &) override
void updateGflashStep(const G4ThreeVector &position, G4double time)
void makeHits(const G4FastTrack &fastTrack)
G4bool IsApplicable(const G4ParticleDefinition &) override
T getUntrackedParameter(std::string const &, T const &) const
GflashHadronShowerProfile * theProfile
CalorimeterNumber getCalorimeterNumber(const Gflash3Vector &position)
const double energyCutOff
void DoIt(const G4FastTrack &, G4FastStep &) override
const double EtaMin[kNumberCalorimeter]
isFirst
Definition: cuy.py:418
int findShowerType(const Gflash3Vector &position)
G4TouchableHandle theGflashTouchableHandle
G4bool isFirstInelasticInteraction(const G4FastTrack &fastTrack)
const double Zmin[kNumberCalorimeter]
const double QuasiElasticLike
const double scaleSensitiveHE
G4bool excludeDetectorRegion(const G4FastTrack &fastTrack)
static int position[264][3]
Definition: ReadPGInfo.cc:289
GflashKaonPlusShowerProfile * theKaonPlusProfile
GflashPiKShowerProfile * thePiKProfile
std::vector< GflashHit > & getGflashHitList()
GflashProtonShowerProfile * theProtonProfile
const double Rmax[kNumberCalorimeter]
const double scaleSensitiveHB
void initialize(int showerType, double energy, double globalTime, double charge, Gflash3Vector &position, Gflash3Vector &momentum)
GflashHadronShowerModel(G4String modelName, G4Region *envelope, const edm::ParameterSet &parSet)