CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/SimG4CMS/EcalTestBeam/src/EcalTBH4BeamSD.cc

Go to the documentation of this file.
00001 
00002 // File: EcalTBH4BeamSD.cc
00003 // Description: Sensitive Detector class for electromagnetic calorimeters
00005 #include "SimG4CMS/EcalTestBeam/interface/EcalTBH4BeamSD.h"
00006 #include "Geometry/EcalTestBeam/interface/EcalHodoscopeNumberingScheme.h"
00007 #include "Geometry/EcalCommonData/interface/EcalBaseNumber.h"
00008 #include "DetectorDescription/Core/interface/DDFilter.h"
00009 #include "DetectorDescription/Core/interface/DDFilteredView.h"
00010 #include "DetectorDescription/Core/interface/DDSolid.h"
00011 #include "DetectorDescription/Core/interface/DDSplit.h"
00012 #include "DetectorDescription/Core/interface/DDValue.h"
00013 
00014 #include "Geometry/EcalCommonData/interface/EcalBaseNumber.h"
00015 
00016 #include "G4Step.hh"
00017 #include "G4Track.hh"
00018 #include "G4VProcess.hh"
00019 
00020 EcalTBH4BeamSD::EcalTBH4BeamSD(G4String name, const DDCompactView & cpv,
00021                                SensitiveDetectorCatalog & clg, 
00022                                edm::ParameterSet const & p, 
00023                                const SimTrackManager* manager) : 
00024   CaloSD(name, cpv, clg, p, manager), numberingScheme(0) {
00025   
00026   edm::ParameterSet m_EcalTBH4BeamSD = p.getParameter<edm::ParameterSet>("EcalTBH4BeamSD");
00027   useBirk= m_EcalTBH4BeamSD.getParameter<bool>("UseBirkLaw");
00028   birk1  = m_EcalTBH4BeamSD.getParameter<double>("BirkC1")*(g/(MeV*cm2));
00029   birk2  = m_EcalTBH4BeamSD.getParameter<double>("BirkC2");
00030   birk3  = m_EcalTBH4BeamSD.getParameter<double>("BirkC3");
00031 
00032   EcalNumberingScheme* scheme=0;
00033   if     (name == "EcalTBH4BeamHits") { 
00034     scheme = dynamic_cast<EcalNumberingScheme*>(new EcalHodoscopeNumberingScheme());
00035   } 
00036   else {edm::LogWarning("EcalTBSim") << "EcalTBH4BeamSD: ReadoutName not supported\n";}
00037 
00038   if (scheme)  setNumberingScheme(scheme);
00039   edm::LogInfo("EcalTBSim") << "Constructing a EcalTBH4BeamSD  with name " 
00040                             << GetName();
00041   edm::LogInfo("EcalTBSim") << "EcalTBH4BeamSD:: Use of Birks law is set to  " 
00042                             << useBirk << "        with three constants kB = "
00043                             << birk1 << ", C1 = " << birk2 << ", C2 = " 
00044                             << birk3;
00045 }
00046 
00047 EcalTBH4BeamSD::~EcalTBH4BeamSD() {
00048   if (numberingScheme) delete numberingScheme;
00049 }
00050 
00051 double EcalTBH4BeamSD::getEnergyDeposit(G4Step * aStep) {
00052   
00053   if (aStep == NULL) {
00054     return 0;
00055   } else {
00056     preStepPoint        = aStep->GetPreStepPoint();
00057     G4String nameVolume = preStepPoint->GetPhysicalVolume()->GetName();
00058 
00059     // take into account light collection curve for crystals
00060     double weight = 1.;
00061     if (useBirk)   weight *= getAttenuation(aStep, birk1, birk2, birk3);
00062     double edep   = aStep->GetTotalEnergyDeposit() * weight;
00063     LogDebug("EcalTBSim") << "EcalTBH4BeamSD:: " << nameVolume
00064                         <<" Light Collection Efficiency " << weight 
00065                         << " Weighted Energy Deposit " << edep/MeV << " MeV";
00066     return edep;
00067   } 
00068 }
00069 
00070 uint32_t EcalTBH4BeamSD::setDetUnitId(G4Step * aStep) { 
00071   getBaseNumber(aStep);
00072   return (numberingScheme == 0 ? 0 : numberingScheme->getUnitID(theBaseNumber));
00073 }
00074 
00075 void EcalTBH4BeamSD::setNumberingScheme(EcalNumberingScheme* scheme) {
00076   if (scheme != 0) {
00077     edm::LogInfo("EcalTBSim") << "EcalTBH4BeamSD: updates numbering scheme for " 
00078                             << GetName() << "\n";
00079     if (numberingScheme) delete numberingScheme;
00080     numberingScheme = scheme;
00081   }
00082 }
00083 
00084 
00085 void EcalTBH4BeamSD::getBaseNumber(const G4Step* aStep) {
00086 
00087   theBaseNumber.reset();
00088   const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
00089   int theSize = touch->GetHistoryDepth()+1;
00090   if ( theBaseNumber.getCapacity() < theSize ) theBaseNumber.setSize(theSize);
00091   //Get name and copy numbers
00092   if ( theSize > 1 ) {
00093     for (int ii = 0; ii < theSize ; ii++) {
00094       theBaseNumber.addLevel(touch->GetVolume(ii)->GetName(),touch->GetReplicaNumber(ii));
00095       LogDebug("EcalTBSim") << "EcalTBH4BeamSD::getBaseNumber(): Adding level " << ii 
00096                             << ": " << touch->GetVolume(ii)->GetName() << "["
00097                             << touch->GetReplicaNumber(ii) << "]";
00098     }
00099   }
00100 }