CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GflashEMShowerModel.cc
Go to the documentation of this file.
1 //
2 // initial setup : E.Barberio & Joanna Weng
3 // big changes : Soon Jun & Dongwook Jang
4 //
7 
10 
11 #include "G4Electron.hh"
12 #include "G4Positron.hh"
13 #include "G4VProcess.hh"
14 #include "G4VPhysicalVolume.hh"
15 #include "G4LogicalVolume.hh"
16 #include "G4TransportationManager.hh"
17 #include "G4EventManager.hh"
18 #include "G4FastSimulationManager.hh"
19 #include "G4TouchableHandle.hh"
20 #include "G4VSensitiveDetector.hh"
21 
22 GflashEMShowerModel::GflashEMShowerModel(G4String modelName, G4Envelope* envelope, edm::ParameterSet parSet)
23  : G4VFastSimulationModel(modelName, envelope), theParSet(parSet) {
24 
25  theWatcherOn = parSet.getParameter<bool>("watcherOn");
26 
27  theProfile = new GflashEMShowerProfile(parSet);
28 
29  theGflashStep = new G4Step();
30  theGflashTouchableHandle = new G4TouchableHistory();
31  theGflashNavigator = new G4Navigator();
32 
33 }
34 
35 // -----------------------------------------------------------------------------------
36 
38 
39  if(theProfile) delete theProfile;
40  if(theGflashStep) delete theGflashStep;
41 }
42 
43 G4bool GflashEMShowerModel::IsApplicable(const G4ParticleDefinition& particleType) {
44 
45  return ( &particleType == G4Electron::ElectronDefinition() ||
46  &particleType == G4Positron::PositronDefinition() );
47 
48 }
49 
50 // -----------------------------------------------------------------------------------
51 G4bool GflashEMShowerModel::ModelTrigger(const G4FastTrack & fastTrack ) {
52 
53  // Mininum energy cutoff to parameterize
54  if(fastTrack.GetPrimaryTrack()->GetKineticEnergy() < 1.0*GeV) return false;
55  if(excludeDetectorRegion(fastTrack)) return false;
56 
57  G4bool trigger = fastTrack.GetPrimaryTrack()->GetDefinition() == G4Electron::ElectronDefinition() ||
58  fastTrack.GetPrimaryTrack()->GetDefinition() == G4Positron::PositronDefinition();
59 
60  if(!trigger) return false;
61 
62  // This will be changed accordingly when the way dealing with CaloRegion changes later.
63  G4TouchableHistory* touch = (G4TouchableHistory*)(fastTrack.GetPrimaryTrack()->GetTouchable());
64  G4VPhysicalVolume* pCurrentVolume = touch->GetVolume();
65  if( pCurrentVolume == 0) return false;
66 
67  G4LogicalVolume* lv = pCurrentVolume->GetLogicalVolume();
68  if(lv->GetRegion()->GetName() != "CaloRegion") return false;
69 
70  // The parameterization starts inside crystals
71  std::size_t pos1 = lv->GetName().find("EBRY");
72  std::size_t pos2 = lv->GetName().find("EFRY");
73  /*
74  std::size_t pos3 = lv->GetName().find("HVQ");
75  std::size_t pos4 = lv->GetName().find("HF");
76  if(pos1 == std::string::npos && pos2 == std::string::npos &&
77  pos3 == std::string::npos && pos4 == std::string::npos) return false;
78  */
79  //@@@for now, HF is not a part of Gflash Envelopes
80  if(pos1 == std::string::npos && pos2 == std::string::npos ) return false;
81 
82  return true;
83 
84 }
85 
86 
87 // -----------------------------------------------------------------------------------
88 void GflashEMShowerModel::DoIt(const G4FastTrack& fastTrack, G4FastStep& fastStep) {
89 
90  // Kill the parameterised particle:
91  fastStep.KillPrimaryTrack();
92  fastStep.ProposePrimaryTrackPathLength(0.0);
93 
94  //input variables for GflashEMShowerProfile with showerType = 1,5 (shower starts inside crystals)
95  G4double energy = fastTrack.GetPrimaryTrack()->GetKineticEnergy()/GeV;
96  G4double globalTime = fastTrack.GetPrimaryTrack()->GetStep()->GetPostStepPoint()->GetGlobalTime();
97  G4double charge = fastTrack.GetPrimaryTrack()->GetStep()->GetPreStepPoint()->GetCharge();
98  G4ThreeVector position = fastTrack.GetPrimaryTrack()->GetPosition() / cm;
99  G4ThreeVector momentum = fastTrack.GetPrimaryTrack()->GetMomentum()/GeV;
100  G4int showerType = Gflash::findShowerType(position);
101 
102  // Do actual parameterization. The result of parameterization is gflashHitList
103  theProfile->initialize(showerType,energy,globalTime,charge,position,momentum);
105 
106  //make hits
107  makeHits(fastTrack);
108 }
109 
110 void GflashEMShowerModel::makeHits(const G4FastTrack& fastTrack) {
111 
112  std::vector<GflashHit>& gflashHitList = theProfile->getGflashHitList();
113 
114  theGflashStep->SetTrack(const_cast<G4Track*>(fastTrack.GetPrimaryTrack()));
115 
116  theGflashStep->GetPostStepPoint()->SetProcessDefinedStep(const_cast<G4VProcess*>
117  (fastTrack.GetPrimaryTrack()->GetStep()->GetPostStepPoint()->GetProcessDefinedStep()));
118  theGflashNavigator->SetWorldVolume(G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume());
119 
120  std::vector<GflashHit>::const_iterator spotIter = gflashHitList.begin();
121  std::vector<GflashHit>::const_iterator spotIterEnd = gflashHitList.end();
122 
123  for( ; spotIter != spotIterEnd; spotIter++){
124 
125  //put touchable for each hit so that touchable history keeps track of each step.
126  theGflashNavigator->LocateGlobalPointAndUpdateTouchableHandle(spotIter->getPosition(),G4ThreeVector(0,0,0),
127  theGflashTouchableHandle, false);
128  updateGflashStep(spotIter->getPosition(),spotIter->getTime());
129 
130  // if there is a watcher defined in a job and the flag is turned on
131  if(theWatcherOn) {
132  SteppingAction* userSteppingAction = (SteppingAction*) G4EventManager::GetEventManager()->GetUserSteppingAction();
133  userSteppingAction->m_g4StepSignal(theGflashStep);
134  }
135 
136  // Send G4Step information to Hit/Digi if the volume is sensitive
137  // Copied from G4SteppingManager.cc
138 
139  G4VPhysicalVolume* aCurrentVolume = theGflashStep->GetPreStepPoint()->GetPhysicalVolume();
140  if( aCurrentVolume == 0 ) continue;
141 
142  G4LogicalVolume* lv = aCurrentVolume->GetLogicalVolume();
143  if(lv->GetRegion()->GetName() != "CaloRegion") continue;
144 
145  theGflashStep->GetPreStepPoint()->SetSensitiveDetector(aCurrentVolume->GetLogicalVolume()->GetSensitiveDetector());
146  G4VSensitiveDetector* aSensitive = theGflashStep->GetPreStepPoint()->GetSensitiveDetector();
147 
148  if( aSensitive == 0 ) continue;
149 
150  theGflashStep->SetTotalEnergyDeposit(spotIter->getEnergy());
151  aSensitive->Hit(theGflashStep);
152  }
153 
154 }
155 
156 void GflashEMShowerModel::updateGflashStep(G4ThreeVector spotPosition, G4double timeGlobal)
157 {
158  theGflashStep->GetPostStepPoint()->SetGlobalTime(timeGlobal);
159  theGflashStep->GetPreStepPoint()->SetPosition(spotPosition);
160  theGflashStep->GetPostStepPoint()->SetPosition(spotPosition);
161  theGflashStep->GetPreStepPoint()->SetTouchableHandle(theGflashTouchableHandle);
162 }
163 
164 // -----------------------------------------------------------------------------------
165 G4bool GflashEMShowerModel::excludeDetectorRegion(const G4FastTrack& fastTrack) {
166 
167  G4bool isExcluded=false;
168 
169  //exclude regions where geometry are complicated
170  //+- one supermodule around the EB/EE boundary: 1.479 +- 0.0174*5
171  G4double eta = fastTrack.GetPrimaryTrack()->GetPosition().pseudoRapidity() ;
172  if(std::fabs(eta) > 1.392 && std::fabs(eta) < 1.566) return true;
173 
174  return isExcluded;
175 }
176 
177 /*
178 G4int GflashEMShowerModel::findShowerType(const G4FastTrack& fastTrack)
179 {
180  // Initialization of longitudinal and lateral parameters for
181  // hadronic showers. Simulation of the intrinsic fluctuations
182 
183  // type of hadron showers subject to the shower starting point (ssp)
184  // showerType = -1 : default (invalid)
185  // showerType = 0 : ssp before EBRY (barrel crystal)
186  // showerType = 1 : ssp inside EBRY
187  // showerType = 2 : ssp after EBRY before HB
188  // showerType = 3 : ssp inside HB
189  // showerType = 4 : ssp before EFRY (endcap crystal)
190  // showerType = 5 : ssp inside EFRY
191  // showerType = 6 : ssp after EFRY before HE
192  // showerType = 7 : ssp inside HE
193 
194  G4TouchableHistory* touch = (G4TouchableHistory*)(fastTrack.GetPrimaryTrack()->GetTouchable());
195  G4LogicalVolume* lv = touch->GetVolume()->GetLogicalVolume();
196 
197  std::size_t pos1 = lv->GetName().find("EBRY");
198  std::size_t pos11 = lv->GetName().find("EWAL");
199  std::size_t pos12 = lv->GetName().find("EWRA");
200  std::size_t pos2 = lv->GetName().find("EFRY");
201 
202  G4ThreeVector position = fastTrack.GetPrimaryTrack()->GetPosition()/cm;
203  Gflash::CalorimeterNumber kCalor = Gflash::getCalorimeterNumber(position);
204 
205  G4int showerType = -1;
206 
207  //central
208  if (kCalor == Gflash::kESPM || kCalor == Gflash::kHB ) {
209 
210  G4double posRho = position.getRho();
211 
212  if(pos1 != std::string::npos || pos11 != std::string::npos || pos12 != std::string::npos ) {
213  showerType = 1;
214  }
215  else {
216  if(kCalor == Gflash::kESPM) {
217  showerType = 2;
218  if( posRho < Gflash::Rmin[Gflash::kESPM]+ Gflash::ROffCrystalEB ) showerType = 0;
219  }
220  else showerType = 3;
221  }
222 
223  }
224  //forward
225  else if (kCalor == Gflash::kENCA || kCalor == Gflash::kHE) {
226  if(pos2 != std::string::npos) {
227  showerType = 5;
228  }
229  else {
230  if(kCalor == Gflash::kENCA) {
231  showerType = 6;
232  if(fabs(position.getZ()) < Gflash::Zmin[Gflash::kENCA] + Gflash::ZOffCrystalEE) showerType = 4;
233  }
234  else showerType = 7;
235  }
236  //@@@need z-dependent correction on the mean energy reponse
237  }
238 
239  return showerType;
240 }
241 */
T getParameter(std::string const &) const
std::vector< GflashHit > & getGflashHitList()
SimActivityRegistry::G4StepSignal m_g4StepSignal
void DoIt(const G4FastTrack &, G4FastStep &)
G4bool excludeDetectorRegion(const G4FastTrack &fastTrack)
void updateGflashStep(G4ThreeVector position, G4double time)
G4TouchableHandle theGflashTouchableHandle
T eta() const
double charge(const std::vector< uint8_t > &Ampls)
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
int findShowerType(const Gflash3Vector position)
GflashEMShowerProfile * theProfile
void initialize(int showerType, double energy, double globalTime, double charge, Gflash3Vector &position, Gflash3Vector &momentum)
G4bool IsApplicable(const G4ParticleDefinition &)
G4Navigator * theGflashNavigator
void makeHits(const G4FastTrack &fastTrack)
GflashEMShowerModel(G4String name, G4Envelope *env, edm::ParameterSet parSet)
G4bool ModelTrigger(const G4FastTrack &)