CMS 3D CMS Logo

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