CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/SimG4Core/CustomPhysics/plugins/RHStopTracer.cc

Go to the documentation of this file.
00001 #include "RHStopTracer.h"
00002 
00003 #include "SimG4Core/Notification/interface/BeginOfRun.h"
00004 #include "SimG4Core/Notification/interface/BeginOfEvent.h"
00005 #include "SimG4Core/Notification/interface/BeginOfTrack.h"
00006 #include "SimG4Core/Notification/interface/EndOfTrack.h"
00007 #include "SimG4Core/Notification/interface/TrackInformation.h"
00008 #include "SimG4Core/Application/interface/TrackingAction.h"
00009 
00010 #include "FWCore/Framework/interface/Event.h"
00011   
00012 #include "G4Track.hh"
00013 #include "G4Run.hh"
00014 #include "G4Event.hh"
00015 
00016 
00017 RHStopTracer::RHStopTracer(edm::ParameterSet const & p) {
00018   edm::ParameterSet parameters = p.getParameter<edm::ParameterSet>("RHStopTracer");
00019   mDebug = parameters.getUntrackedParameter<bool>("verbose", false);
00020   mStopRegular = parameters.getUntrackedParameter<bool>("stopRegularParticles", false);
00021   mTraceEnergy = 1000 * parameters.getUntrackedParameter<double>("traceEnergy", 1.e20); // GeV->KeV
00022   mTraceParticleNameRegex = parameters.getParameter<std::string>("traceParticle");
00023   produces< std::vector<std::string> >("StoppedParticlesName");
00024   produces< std::vector<float> >("StoppedParticlesX");
00025   produces< std::vector<float> >("StoppedParticlesY");
00026   produces< std::vector<float> >("StoppedParticlesZ");
00027   produces< std::vector<float> >("StoppedParticlesTime");
00028 
00029   if (mDebug) {
00030     std::cout << "RHStopTracer::RHStopTracer->" 
00031               << mTraceParticleNameRegex << '/' << mTraceEnergy << std::endl;
00032   }
00033 }
00034 
00035 RHStopTracer::~RHStopTracer() {
00036 }
00037 
00038 void RHStopTracer::update (const BeginOfRun * fRun) {
00039   if (mDebug) 
00040     std::cout << "RHStopTracer::update-> begin of the run " << (*fRun)()->GetRunID () << std::endl; 
00041 }
00042 
00043 void RHStopTracer::update (const BeginOfEvent * fEvent) {
00044   if (mDebug) 
00045     std::cout << "RHStopTracer::update-> begin of the event " << (*fEvent)()->GetEventID () << std::endl; 
00046 }
00047 
00048 void RHStopTracer::update (const BeginOfTrack * fTrack) {
00049   const G4Track* track = (*fTrack)();
00050   if ((track->GetMomentum().mag()> mTraceEnergy) || matched (track->GetDefinition()->GetParticleName())) {
00051     if (mDebug)
00052     std::cout << "RHStopTracer::update-> new track: ID/Name/mass/Parent: " 
00053               << track->GetTrackID() << '/' << track->GetDefinition()->GetParticleName() << '/' 
00054               << track->GetDefinition()->GetPDGMass() << '/' << track->GetParentID()
00055               << std::endl
00056               << " position X/Y/Z: " << track->GetPosition().x() << '/' 
00057               << track->GetPosition().y() << '/' <<  track->GetPosition().z()
00058               << " R/phi: " << track->GetPosition().perp() << '/' << track->GetPosition().phi()
00059               << std::endl
00060               << "    px/py/pz/p=" << track->GetMomentum().x() << '/' 
00061               << track->GetMomentum().y() << '/' << track->GetMomentum().z() << '/'<< track->GetMomentum().mag() 
00062               << std::endl;
00063   }
00064   if (mStopRegular && !matched (track->GetDefinition()->GetParticleName())) { // kill regular particles
00065     const_cast<G4Track*>(track)->SetTrackStatus(fStopAndKill);
00066   }
00067 }
00068 
00069 void RHStopTracer::update (const EndOfTrack * fTrack) {
00070   const G4Track* track = (*fTrack)();
00071   if ((track->GetMomentum().mag()> mTraceEnergy) || matched (track->GetDefinition()->GetParticleName())) {
00072     if (mDebug)
00073     std::cout << "RHStopTracer::update-> stop track: ID/Name/mass/Parent: " 
00074               << track->GetTrackID() << '/' << track->GetDefinition()->GetParticleName() << '/' 
00075               << track->GetDefinition()->GetPDGMass() << '/' << track->GetParentID()
00076               << std::endl
00077               << " position X/Y/Z: " << track->GetPosition().x() << '/' 
00078               << track->GetPosition().y() << '/' <<  track->GetPosition().z()
00079               << " R/phi: " << track->GetPosition().perp() << '/' << track->GetPosition().phi()
00080               << std::endl 
00081               << "    px/py/pz/p=" << track->GetMomentum().x() << '/' 
00082               << track->GetMomentum().y() << '/' << track->GetMomentum().z() << '/'<< track->GetMomentum().mag() 
00083               << std::endl;
00084     if (track->GetMomentum().mag () < 0.001) {
00085       mStopPoints.push_back (StopPoint (track->GetDefinition()->GetParticleName(),
00086                                         track->GetPosition().x(),
00087                                         track->GetPosition().y(),
00088                                         track->GetPosition().z(),
00089                                         track->GetGlobalTime()));
00090     }
00091   }
00092 }
00093 
00094 bool RHStopTracer::matched (const std::string& fName) const {
00095   return boost::regex_match (fName, mTraceParticleNameRegex);
00096 }
00097 
00098  void RHStopTracer::produce(edm::Event& fEvent, const edm::EventSetup&) {
00099   if (mDebug) {
00100     std::cout << "RHStopTracer::produce->" << std::endl;
00101   }
00102    std::auto_ptr<std::vector<std::string> > names (new std::vector<std::string>); 
00103    std::auto_ptr<std::vector<float> > xs (new std::vector<float>);
00104    std::auto_ptr<std::vector<float> > ys (new std::vector<float>);
00105    std::auto_ptr<std::vector<float> > zs (new std::vector<float>);
00106    std::auto_ptr<std::vector<float> > ts (new std::vector<float>);
00107 
00108    std::vector <StopPoint>::const_iterator stopPoint = mStopPoints.begin ();
00109    for (;  stopPoint != mStopPoints.end(); ++stopPoint) {
00110      names->push_back (stopPoint->name);
00111      xs->push_back (stopPoint->x);
00112      ys->push_back (stopPoint->y);
00113      zs->push_back (stopPoint->z);
00114      ts->push_back (stopPoint->t);
00115    }
00116    fEvent.put (names, "StoppedParticlesName");
00117    fEvent.put (xs, "StoppedParticlesX");
00118    fEvent.put (ys, "StoppedParticlesY");
00119    fEvent.put (zs, "StoppedParticlesZ");
00120    fEvent.put (ts, "StoppedParticlesTime");
00121    mStopPoints.clear ();
00122  }