CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Validation/Geometry/src/MaterialBudgetHcal.cc

Go to the documentation of this file.
00001 #include "Validation/Geometry/interface/MaterialBudgetHcal.h"
00002 
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/EventSetup.h"
00005 #include "FWCore/Framework/interface/ESTransientHandle.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 
00008 #include "SimG4Core/Notification/interface/BeginOfJob.h"
00009 #include "SimG4Core/Notification/interface/BeginOfTrack.h"
00010 #include "SimG4Core/Notification/interface/EndOfTrack.h"
00011 
00012 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00013 #include "DetectorDescription/Core/interface/DDCompactView.h"
00014 
00015 #include "G4Step.hh"
00016 #include "G4Track.hh"
00017 
00018 #include <iostream>
00019 
00020 MaterialBudgetHcal::MaterialBudgetHcal(const edm::ParameterSet& p): 
00021   theHistoHcal(0), theHistoCastor(0) {
00022   
00023   edm::ParameterSet m_p = p.getParameter<edm::ParameterSet>("MaterialBudgetHcal");
00024   rMax        = m_p.getUntrackedParameter<double>("RMax", 4.5)*m;
00025   zMax        = m_p.getUntrackedParameter<double>("ZMax", 13.0)*m;
00026   bool doHcal = m_p.getUntrackedParameter<bool>("DoHCAL", true);
00027   edm::LogInfo("MaterialBudget") << "MaterialBudgetHcal initialized with rMax "
00028                                  << rMax << " mm and zMax " << zMax << " mm"
00029                                  << " doHcal is set to " << doHcal;
00030   if (doHcal)   theHistoHcal   = new MaterialBudgetHcalHistos(m_p);
00031   else          theHistoCastor = new MaterialBudgetCastorHistos(m_p);
00032 }
00033 
00034 MaterialBudgetHcal::~MaterialBudgetHcal() {
00035   if (theHistoHcal)   delete theHistoHcal;
00036   if (theHistoCastor) delete theHistoCastor;
00037 }
00038 
00039 void MaterialBudgetHcal::update(const BeginOfJob* job) {
00040   //----- Check that selected volumes are indeed part of the geometry
00041   // Numbering From DDD
00042   edm::ESTransientHandle<DDCompactView> pDD;
00043   (*job)()->get<IdealGeometryRecord>().get(pDD);
00044   if (theHistoHcal)   theHistoHcal->fillBeginJob((*pDD));
00045 
00046 }
00047 
00048 void MaterialBudgetHcal::update(const BeginOfTrack* trk) {
00049 
00050   const G4Track * aTrack = (*trk)(); // recover G4 pointer if wanted
00051   if (theHistoHcal)   theHistoHcal->fillStartTrack(aTrack);
00052   if (theHistoCastor) theHistoCastor->fillStartTrack(aTrack);
00053 }
00054  
00055 void MaterialBudgetHcal::update(const G4Step* aStep) {
00056 
00057   //---------- each step
00058   if (theHistoHcal)   theHistoHcal->fillPerStep(aStep);
00059   if (theHistoCastor) theHistoCastor->fillPerStep(aStep);
00060 
00061   //----- Stop tracking after selected position
00062   if (stopAfter(aStep)) {
00063     G4Track* track = aStep->GetTrack();
00064     track->SetTrackStatus( fStopAndKill );
00065   }
00066 }
00067 
00068 
00069 void MaterialBudgetHcal::update(const EndOfTrack* trk) {
00070 
00071   if (theHistoHcal)   theHistoHcal->fillEndTrack();
00072   if (theHistoCastor) theHistoCastor->fillEndTrack();
00073 }
00074 
00075 bool MaterialBudgetHcal::stopAfter(const G4Step* aStep) {
00076 
00077   G4ThreeVector hitPoint    = aStep->GetPreStepPoint()->GetPosition();
00078   double        rr = hitPoint.perp();
00079   double        zz = std::abs(hitPoint.z());
00080 
00081   if (rr > rMax || zz > zMax) {
00082     LogDebug("MaterialBudget") << " MaterialBudgetHcal::StopAfter R = " << rr
00083                                << " and Z = " << zz;
00084     return true;
00085   } else {
00086     return false;
00087   }
00088 }