CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/SimG4Core/Application/src/GFlashEMShowerModel.cc

Go to the documentation of this file.
00001 //
00002 // initial setup : E.Barberio & Joanna Weng 
00003 // big changes : Soon Jun & Dongwook Jang
00004 // V.Ivanchenko rename the class, cleanup, and move
00005 //              to SimG4Core/Application - 2012/08/14
00006 //
00007 #include "SimG4Core/Application/interface/SteppingAction.h"
00008 #include "SimG4Core/Application/interface/GFlashEMShowerModel.h"
00009 
00010 #include "SimGeneral/GFlash/interface/GflashEMShowerProfile.h"
00011 #include "SimGeneral/GFlash/interface/GflashHit.h"
00012 
00013 #include "G4Electron.hh"
00014 #include "G4Positron.hh"
00015 #include "G4VProcess.hh"
00016 #include "G4VPhysicalVolume.hh" 
00017 #include "G4LogicalVolume.hh"
00018 #include "G4TransportationManager.hh"
00019 #include "G4EventManager.hh"
00020 #include "G4FastSimulationManager.hh"
00021 #include "G4TouchableHandle.hh"
00022 #include "G4VSensitiveDetector.hh"
00023 
00024 GFlashEMShowerModel::GFlashEMShowerModel(const G4String& modelName, 
00025                                          G4Envelope* envelope, 
00026                                          const edm::ParameterSet& parSet)
00027   : G4VFastSimulationModel(modelName, envelope), theParSet(parSet) 
00028 {
00029   theWatcherOn = parSet.getParameter<bool>("watcherOn");
00030 
00031   theProfile = new GflashEMShowerProfile(parSet);
00032   theRegion  = const_cast<const G4Region*>(envelope); 
00033 
00034   theGflashStep = new G4Step();
00035   theGflashTouchableHandle = new G4TouchableHistory();
00036   theGflashNavigator = new G4Navigator();
00037 
00038 }
00039 
00040 // --------------------------------------------------------------------------
00041 
00042 GFlashEMShowerModel::~GFlashEMShowerModel() 
00043 {
00044   delete theProfile;
00045   delete theGflashStep;
00046 }
00047 
00048 G4bool 
00049 GFlashEMShowerModel::IsApplicable(const G4ParticleDefinition& particleType) 
00050 { 
00051   return ( &particleType == G4Electron::Electron() ||
00052            &particleType == G4Positron::Positron() ); 
00053 }
00054 
00055 // --------------------------------------------------------------------------
00056 G4bool GFlashEMShowerModel::ModelTrigger(const G4FastTrack & fastTrack ) 
00057 {
00058   // Mininum energy cutoff to parameterize
00059   if(fastTrack.GetPrimaryTrack()->GetKineticEnergy() < GeV) { return false; }
00060   if(excludeDetectorRegion(fastTrack)) { return false; }
00061 
00062   // This will be changed accordingly when the way 
00063   // dealing with CaloRegion changes later.
00064   G4TouchableHistory* touch = 
00065     (G4TouchableHistory*)(fastTrack.GetPrimaryTrack()->GetTouchable());
00066   G4VPhysicalVolume* pCurrentVolume = touch->GetVolume();
00067   if( pCurrentVolume == 0) { return false; }
00068 
00069   G4LogicalVolume* lv = pCurrentVolume->GetLogicalVolume();
00070   if(lv->GetRegion() != theRegion) { return false; }
00071   //std::cout << "GFlashEMShowerModel::ModelTrigger: LV " 
00072   //        << lv->GetRegion()->GetName() << std::endl;
00073 
00074   // The parameterization starts inside crystals
00075   //std::size_t pos1 = lv->GetName().find("EBRY");
00076   //std::size_t pos2 = lv->GetName().find("EFRY");
00077   
00078   //std::size_t pos3 = lv->GetName().find("HVQ");
00079   //std::size_t pos4 = lv->GetName().find("HF");
00080   //if(pos1 == std::string::npos && pos2 == std::string::npos &&
00081   //   pos3 == std::string::npos && pos4 == std::string::npos) return false;
00082 
00083   return true;
00084 
00085 }
00086 
00087 // ---------------------------------------------------------------------------
00088 void GFlashEMShowerModel::DoIt(const G4FastTrack& fastTrack, 
00089                                G4FastStep& fastStep) 
00090 {
00091   // Kill the parameterised particle:
00092   fastStep.KillPrimaryTrack();
00093   fastStep.ProposePrimaryTrackPathLength(0.0);
00094 
00095   // Input variables for GFlashEMShowerProfile with showerType = 1,5 
00096   // Shower starts inside crystals
00097   G4double energy = fastTrack.GetPrimaryTrack()->GetKineticEnergy()/GeV;
00098   G4double globalTime = 
00099     fastTrack.GetPrimaryTrack()->GetStep()->GetPostStepPoint()->GetGlobalTime();
00100   G4double charge = 
00101     fastTrack.GetPrimaryTrack()->GetStep()->GetPreStepPoint()->GetCharge();
00102   G4ThreeVector position = fastTrack.GetPrimaryTrack()->GetPosition()/cm;
00103   G4ThreeVector momentum = fastTrack.GetPrimaryTrack()->GetMomentum()/GeV;
00104   G4int showerType = Gflash::findShowerType(position);
00105 
00106   // Do actual parameterization
00107   // The result of parameterization is gflashHitList
00108   theProfile->initialize(showerType,energy,globalTime,charge,
00109                          position,momentum);
00110   theProfile->parameterization();
00111 
00112   // Make hits
00113   makeHits(fastTrack);
00114 }
00115 
00116 // ---------------------------------------------------------------------------
00117 void GFlashEMShowerModel::makeHits(const G4FastTrack& fastTrack) 
00118 {
00119   std::vector<GflashHit>& gflashHitList = theProfile->getGflashHitList();
00120 
00121   theGflashStep->SetTrack(const_cast<G4Track*>(fastTrack.GetPrimaryTrack()));
00122 
00123   theGflashStep->GetPostStepPoint()
00124     ->SetProcessDefinedStep(const_cast<G4VProcess*>(fastTrack.GetPrimaryTrack()
00125          ->GetStep()->GetPostStepPoint()->GetProcessDefinedStep()));
00126   theGflashNavigator->SetWorldVolume(G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume());
00127 
00128   std::vector<GflashHit>::const_iterator spotIter    = gflashHitList.begin();
00129   std::vector<GflashHit>::const_iterator spotIterEnd = gflashHitList.end();
00130 
00131   for(; spotIter != spotIterEnd; spotIter++){
00132 
00133     // Put touchable for each hit so that touchable history 
00134     //     keeps track of each step.
00135     theGflashNavigator->LocateGlobalPointAndUpdateTouchableHandle(spotIter->getPosition(),G4ThreeVector(0,0,0),theGflashTouchableHandle, false);
00136     updateGflashStep(spotIter->getPosition(),spotIter->getTime());
00137 
00138     // If there is a watcher defined in a job and the flag is turned on
00139     if(theWatcherOn) {
00140       SteppingAction* userSteppingAction = (SteppingAction*) G4EventManager::GetEventManager()->GetUserSteppingAction();
00141       userSteppingAction->m_g4StepSignal(theGflashStep);
00142     }
00143 
00144     // Send G4Step information to Hit/Digi if the volume is sensitive
00145     // Copied from G4SteppingManager.cc
00146     
00147     G4VPhysicalVolume* aCurrentVolume = 
00148       theGflashStep->GetPreStepPoint()->GetPhysicalVolume();
00149     if( aCurrentVolume == 0 ) { continue; }
00150 
00151     G4LogicalVolume* lv = aCurrentVolume->GetLogicalVolume();
00152     if(lv->GetRegion() != theRegion) { continue; }
00153 
00154     theGflashStep->GetPreStepPoint()->SetSensitiveDetector(aCurrentVolume->GetLogicalVolume()->GetSensitiveDetector());
00155     G4VSensitiveDetector* aSensitive = theGflashStep->GetPreStepPoint()->GetSensitiveDetector();
00156       
00157     if( aSensitive == 0 ) { continue; }
00158 
00159     theGflashStep->SetTotalEnergyDeposit(spotIter->getEnergy());
00160     aSensitive->Hit(theGflashStep);
00161   }
00162 }
00163 
00164 // ---------------------------------------------------------------------------
00165 void GFlashEMShowerModel::updateGflashStep(const G4ThreeVector& spotPosition, 
00166                                             G4double timeGlobal)
00167 {
00168   theGflashStep->GetPostStepPoint()->SetGlobalTime(timeGlobal);
00169   theGflashStep->GetPreStepPoint()->SetPosition(spotPosition);
00170   theGflashStep->GetPostStepPoint()->SetPosition(spotPosition);
00171   theGflashStep->GetPreStepPoint()->SetTouchableHandle(theGflashTouchableHandle);
00172 }
00173 
00174 // ---------------------------------------------------------------------------
00175 G4bool GFlashEMShowerModel::excludeDetectorRegion(const G4FastTrack& fastTrack)
00176 {
00177   G4bool isExcluded=false;
00178 
00179   //exclude regions where geometry are complicated
00180   //+- one supermodule around the EB/EE boundary: 1.479 +- 0.0174*5 
00181   G4double eta =   fastTrack.GetPrimaryTrack()->GetPosition().pseudoRapidity();
00182   if(std::fabs(eta) > 1.392 && std::fabs(eta) < 1.566) { return true; }
00183 
00184   return isExcluded;
00185 }
00186 
00187 // ---------------------------------------------------------------------------
00188