Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:06

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: HcalTB06BeamSD.cc
0003 // Description: Sensitive Detector class for beam counters in TB06 setup
0004 ///////////////////////////////////////////////////////////////////////////////
0005 
0006 #include "SimG4Core/Notification/interface/TrackInformation.h"
0007 #include "SimDataFormats/HcalTestBeam/interface/HcalTestBeamNumbering.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "FWCore/Utilities/interface/Exception.h"
0011 #include "SimG4CMS/HcalTestBeam/interface/HcalTB06BeamSD.h"
0012 
0013 #include "G4Step.hh"
0014 #include "G4Track.hh"
0015 #include "G4Material.hh"
0016 #include "CLHEP/Units/GlobalSystemOfUnits.h"
0017 
0018 //#define EDM_ML_DEBUG
0019 
0020 HcalTB06BeamSD::HcalTB06BeamSD(const std::string& name,
0021                                const HcalTB06BeamParameters* es,
0022                                const SensitiveDetectorCatalog& clg,
0023                                edm::ParameterSet const& p,
0024                                const SimTrackManager* manager)
0025     : CaloSD(name, clg, p, manager), hcalBeamPar_(es) {
0026   // Values from NIM 80 (1970) 239-244: as implemented in Geant3
0027   edm::ParameterSet m_HC = p.getParameter<edm::ParameterSet>("HcalTB06BeamSD");
0028   useBirk_ = m_HC.getParameter<bool>("UseBirkLaw");
0029   birk1_ = m_HC.getParameter<double>("BirkC1") * (CLHEP::g / (CLHEP::MeV * CLHEP::cm2));
0030   birk2_ = m_HC.getParameter<double>("BirkC2");
0031   birk3_ = m_HC.getParameter<double>("BirkC3");
0032 
0033 #ifdef EDM_ML_DEBUG
0034   edm::LogVerbatim("HcalTBSim") << "HcalTB06BeamSD:: Use of Birks law is set to " << useBirk_
0035                                 << "  with three constants kB = " << birk1_ << ", C1 = " << birk2_
0036                                 << ", C2 = " << birk3_;
0037 #endif
0038 }
0039 
0040 HcalTB06BeamSD::~HcalTB06BeamSD() {}
0041 
0042 double HcalTB06BeamSD::getEnergyDeposit(const G4Step* aStep) {
0043   double destep = aStep->GetTotalEnergyDeposit();
0044   double weight = 1;
0045   if (useBirk_ && aStep->GetPreStepPoint()->GetMaterial()->GetName() == static_cast<G4String>(hcalBeamPar_->material_))
0046     weight *= getAttenuation(aStep, birk1_, birk2_, birk3_);
0047 #ifdef EDM_ML_DEBUG
0048   edm::LogVerbatim("HcalTBSim") << "HcalTB06BeamSD: Detector "
0049                                 << aStep->GetPreStepPoint()->GetTouchable()->GetVolume()->GetName() << " weight "
0050                                 << weight;
0051 #endif
0052   return weight * destep;
0053 }
0054 
0055 uint32_t HcalTB06BeamSD::setDetUnitId(const G4Step* aStep) {
0056   const G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
0057   const G4VTouchable* touch = preStepPoint->GetTouchable();
0058   std::string name = static_cast<std::string>(preStepPoint->GetPhysicalVolume()->GetName());
0059 
0060   int det = 1;
0061   int lay = 0, x = 0, y = 0;
0062   if (!isItWireChamber(name)) {
0063     lay = (touch->GetReplicaNumber(0));
0064   } else {
0065     det = 2;
0066     lay = (touch->GetReplicaNumber(1));
0067     G4ThreeVector localPoint = setToLocal(preStepPoint->GetPosition(), touch);
0068     x = (int)(localPoint.x() / (0.2 * mm));
0069     y = (int)(localPoint.y() / (0.2 * mm));
0070   }
0071 
0072   return HcalTestBeamNumbering::packIndex(det, lay, x, y);
0073 }
0074 
0075 bool HcalTB06BeamSD::isItWireChamber(const std::string& name) {
0076   std::vector<std::string>::const_iterator it = hcalBeamPar_->wchambers_.begin();
0077   for (; it != hcalBeamPar_->wchambers_.end(); it++)
0078     if (name == *it)
0079       return true;
0080   return false;
0081 }