Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:29:49

0001 #ifndef HelpfulWatchers_SimTracer_h
0002 #define HelpfulWatchers_SimTracer_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     HelpfulWatchers
0006 // Class  :     SimTracer
0007 //
0008 /**\class SimTracer SimTracer.h SimG4Core/HelpfulWatchers/interface/SimTracer.h
0009 
0010  Description: Prints a message for each Oscar signal
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:
0018 //         Created:  Tue Nov 22 16:41:33 EST 2005
0019 //
0020 
0021 // system include files
0022 #include <iostream>
0023 
0024 // user include files
0025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0026 #include "G4Step.hh"
0027 #include "SimG4Core/Notification/interface/Observer.h"
0028 #include "SimG4Core/Watcher/interface/SimWatcher.h"
0029 
0030 // forward declarations
0031 class DDDWorld;
0032 class BeginOfJob;
0033 class BeginOfRun;
0034 class BeginOfEvent;
0035 class BeginOfTrack;
0036 class G4Step;
0037 
0038 class EndOfRun;
0039 class EndOfEvent;
0040 class EndOfTrack;
0041 
0042 #define OBSERVES(type) \
0043 public                 \
0044   Observer<const type *>
0045 #define UPDATE(type) \
0046   void update(const type *) override { std::cout << "++ signal " #type << std::endl; }
0047 class SimTracer : public SimWatcher,
0048                   OBSERVES(DDDWorld),
0049                   OBSERVES(BeginOfJob),
0050                   OBSERVES(BeginOfRun),
0051                   OBSERVES(BeginOfEvent),
0052                   OBSERVES(BeginOfTrack),
0053                   OBSERVES(G4Step),
0054                   OBSERVES(EndOfRun),
0055                   OBSERVES(EndOfEvent),
0056                   OBSERVES(EndOfTrack) {
0057 public:
0058   SimTracer(const edm::ParameterSet &pSet) : m_verbose(pSet.getUntrackedParameter<bool>("verbose", false)) {}
0059   // virtual ~SimTracer();
0060 
0061   // ---------- const member functions ---------------------
0062 
0063   // ---------- static member functions --------------------
0064 
0065   // ---------- member functions ---------------------------
0066   UPDATE(DDDWorld)
0067   UPDATE(BeginOfJob)
0068   UPDATE(BeginOfRun)
0069   UPDATE(BeginOfEvent)
0070   UPDATE(BeginOfTrack)
0071   void update(const G4Step *iStep) override {
0072     std::cout << "++ signal G4Step ";
0073     if (m_verbose) {
0074       const G4StepPoint *post = iStep->GetPostStepPoint();
0075       const G4ThreeVector &pos = post->GetPosition();
0076       std::cout << "( " << pos.x() << "," << pos.y() << "," << pos.z() << ") ";
0077       if (post->GetPhysicalVolume()) {
0078         std::cout << post->GetPhysicalVolume()->GetName();
0079       }
0080     }
0081     std::cout << std::endl;
0082   }
0083   // UPDATE(G4Step)
0084   UPDATE(EndOfRun)
0085   UPDATE(EndOfEvent)
0086   UPDATE(EndOfTrack)
0087 
0088 private:
0089   // SimTracer(const SimTracer&); // stop default
0090 
0091   // const SimTracer& operator=(const SimTracer&); // stop default
0092 
0093   // ---------- member data --------------------------------
0094   bool m_verbose;
0095 };
0096 
0097 #endif