CMS 3D CMS Logo

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