Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:58

0001 // -*- C++ -*-
0002 //
0003 // Package:     HelpfulWatchers
0004 // Class  :     EcalTBH4Trigger
0005 //
0006 /**\class EcalTBH4Trigger EcalTBH4Trigger.h
0007  SimG4Core/HelpfulWatchers/interface/EcalTBH4Trigger.h
0008 
0009  Description: Simulates ECALTBH4 trigger an throw exception in case of non
0010  triggering event
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 
0018 // system include files
0019 #include <sstream>
0020 
0021 // user include files
0022 #include "SimG4Core/Notification/interface/BeginOfEvent.h"
0023 #include "SimG4Core/Notification/interface/EndOfEvent.h"
0024 #include "SimG4Core/Notification/interface/Observer.h"
0025 #include "SimG4Core/Notification/interface/SimG4Exception.h"
0026 #include "SimG4Core/Watcher/interface/SimWatcher.h"
0027 #include "SimG4Core/Watcher/interface/SimWatcherFactory.h"
0028 
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030 #include "FWCore/PluginManager/interface/ModuleDef.h"
0031 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 
0034 #include "G4Step.hh"
0035 #include "G4VProcess.hh"
0036 #include "G4VTouchable.hh"
0037 
0038 #include <CLHEP/Units/SystemOfUnits.h>
0039 
0040 class EcalTBH4Trigger : public SimWatcher,
0041                         public Observer<const BeginOfEvent *>,
0042                         public Observer<const G4Step *>,
0043                         public Observer<const EndOfEvent *> {
0044 public:
0045   EcalTBH4Trigger(const edm::ParameterSet &pSet)
0046       : m_verbose(pSet.getUntrackedParameter<bool>("verbose", false)),
0047         nTriggeredEvents_(0),
0048         trigEvents_(pSet.getUntrackedParameter<int>("trigEvents", -1)) {}
0049   // virtual ~EcalTBH4Trigger();
0050 
0051   // ---------- const member functions ---------------------
0052 
0053   // ---------- static member functions --------------------
0054 
0055   // ---------- member functions ---------------------------
0056   void update(const BeginOfEvent *anEvent) override;
0057   void update(const G4Step *iStep) override;
0058   void update(const EndOfEvent *anEvent) override;
0059 
0060 private:
0061   // ---------- member data --------------------------------
0062   bool m_verbose;
0063   bool m_passedTrg1;
0064   bool m_passedTrg3;
0065   bool m_passedTrg4;
0066   bool m_passedTrg5;
0067   bool m_passedTrg6;
0068   int nTriggeredEvents_;
0069   int trigEvents_;
0070 };
0071 
0072 void EcalTBH4Trigger::update(const BeginOfEvent *anEvent) {
0073   m_passedTrg1 = false;
0074   m_passedTrg3 = false;
0075   m_passedTrg4 = false;
0076   m_passedTrg5 = false;
0077   m_passedTrg6 = false;
0078 }
0079 
0080 void EcalTBH4Trigger::update(const G4Step *iStep) {
0081   if (trigEvents_ >= 0 && nTriggeredEvents_ >= trigEvents_)
0082     throw SimG4Exception("Number of needed trigger events reached in ECALTBH4");
0083 
0084   const G4StepPoint *pre = iStep->GetPreStepPoint();
0085   const G4StepPoint *post = iStep->GetPostStepPoint();
0086   if (m_verbose) {
0087     std::ostringstream st1;
0088     st1 << "++ signal G4Step";
0089     const G4VTouchable *touch = iStep->GetPreStepPoint()->GetTouchable();
0090     // Get name and copy numbers
0091     if (touch->GetHistoryDepth() > 0) {
0092       for (int ii = 0; ii <= touch->GetHistoryDepth(); ii++) {
0093         st1 << "EcalTBH4::Level " << ii << ": " << touch->GetVolume(ii)->GetName() << "[" << touch->GetReplicaNumber(ii)
0094             << "]";
0095       }
0096     }
0097     edm::LogVerbatim("EcalTBInfo") << st1.str();
0098 
0099     std::ostringstream st2;
0100     const G4Track *theTrack = iStep->GetTrack();
0101     const G4ThreeVector &pos = post->GetPosition();
0102     st2 << "( " << pos.x() << "," << pos.y() << "," << pos.z() << ") ";
0103     st2 << " released energy (MeV) " << iStep->GetTotalEnergyDeposit() / CLHEP::MeV;
0104     if (theTrack) {
0105       const G4ThreeVector mom = theTrack->GetMomentum();
0106       st2 << " track length (cm) " << theTrack->GetTrackLength() / CLHEP::cm << " particle type "
0107           << theTrack->GetDefinition()->GetParticleName() << " momentum "
0108           << "( " << mom.x() << "," << mom.y() << "," << mom.z() << ") ";
0109       if (theTrack->GetCreatorProcess()) {
0110         st2 << " created by " << theTrack->GetCreatorProcess()->GetProcessName();
0111       }
0112     }
0113     if (post->GetPhysicalVolume()) {
0114       st2 << " " << pre->GetPhysicalVolume()->GetName() << "->" << post->GetPhysicalVolume()->GetName();
0115     }
0116     edm::LogVerbatim("EcalTBInfo") << st2.str();
0117   }
0118 
0119   if (post && post->GetPhysicalVolume()) {
0120     if (!m_passedTrg1 && post->GetPhysicalVolume()->GetName() == "TRG1")
0121       m_passedTrg1 = true;
0122     if (!m_passedTrg3 && post->GetPhysicalVolume()->GetName() == "TRG3")
0123       m_passedTrg3 = true;
0124     if (!m_passedTrg4 && post->GetPhysicalVolume()->GetName() == "TRG4")
0125       m_passedTrg4 = true;
0126     if (!m_passedTrg5 && post->GetPhysicalVolume()->GetName() == "TRG5")
0127       m_passedTrg5 = true;
0128     if (!m_passedTrg6 && post->GetPhysicalVolume()->GetName() == "TRG6")
0129       m_passedTrg6 = true;
0130     if (post->GetPhysicalVolume()->GetName() == "CMSSE")  // Exiting TBH4BeamLine
0131       if (!(m_passedTrg1 && m_passedTrg6))                // Trigger defined as Trg4 && Trg6
0132         throw SimG4Exception("Event is not triggered by ECALTBH4");
0133   }
0134 
0135   /*     if (!m_enteringTBH4BeamLine && ( post->GetPhysicalVolume()->GetName()
0136    * ==  */
0137 }
0138 
0139 void EcalTBH4Trigger::update(const EndOfEvent *anEvent) {
0140   edm::LogVerbatim("EcalTBInfo") << "++ signal BeginOfEvent ";
0141   nTriggeredEvents_++;
0142 }
0143 
0144 DEFINE_SIMWATCHER(EcalTBH4Trigger);