Go to the documentation of this file.00001 #ifndef HelpfulWatchers_EcalTBH4Trigger_h
00002 #define HelpfulWatchers_EcalTBH4Trigger_h
00003
00004
00005
00006
00007
00016
00017
00018
00019
00020 #include <iostream>
00021
00022
00023 #include "SimG4Core/Notification/interface/Observer.h"
00024 #include "SimG4Core/Watcher/interface/SimWatcher.h"
00025 #include "SimG4Core/Notification/interface/SimG4Exception.h"
00026
00027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00028
00029 #include "G4Step.hh"
00030 #include "G4VProcess.hh"
00031 #include "G4VTouchable.hh"
00032
00033
00034 class DDDWorld;
00035 class BeginOfJob;
00036 class BeginOfRun;
00037 class BeginOfEvent;
00038 class BeginOfTrack;
00039
00040 class EndOfRun;
00041 class EndOfEvent;
00042 class EndOfTrack;
00043
00044 #define OBSERVES(type) public Observer<const type*>
00045 #define UPDATEH4(type) void update(const type*) { }
00046 class EcalTBH4Trigger : public SimWatcher,
00047
00048
00049
00050 OBSERVES(BeginOfEvent),
00051
00052 OBSERVES(G4Step),
00053
00054 OBSERVES(EndOfEvent)
00055
00056
00057 {
00058
00059 public:
00060 EcalTBH4Trigger(const edm::ParameterSet& pSet) :
00061 m_verbose(pSet.getUntrackedParameter<bool>("verbose",false)), nTriggeredEvents_(0), trigEvents_(pSet.getUntrackedParameter<int>("trigEvents",-1)) {
00062 }
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 void update(const BeginOfEvent* anEvent)
00075 {
00076
00077
00078
00079
00080 m_passedTrg1=false;
00081 m_passedTrg3=false;
00082 m_passedTrg4=false;
00083 m_passedTrg5=false;
00084 m_passedTrg6=false;
00085 }
00086
00087
00088 void update(const G4Step* iStep)
00089 {
00090 if (trigEvents_ >= 0 && nTriggeredEvents_ >= trigEvents_)
00091 throw SimG4Exception("Number of needed trigger events reached in ECALTBH4");
00092
00093 const G4StepPoint* pre = iStep->GetPreStepPoint();
00094 const G4StepPoint* post = iStep->GetPostStepPoint();
00095 if(m_verbose) {
00096 std::cout <<"++ signal G4Step" ;
00097 const G4VTouchable* touch = iStep->GetPreStepPoint()->GetTouchable();
00098
00099 if (touch->GetHistoryDepth() > 0) {
00100 for (int ii = 0; ii <= touch->GetHistoryDepth() ; ii++) {
00101 std::cout << "EcalTBH4::Level " << ii
00102 << ": " << touch->GetVolume(ii)->GetName() << "["
00103 << touch->GetReplicaNumber(ii) << "]";
00104 }
00105 }
00106 std::cout <<std::endl;
00107 const G4Track* theTrack = iStep->GetTrack();
00108 const G4ThreeVector pos = post->GetPosition();
00109 std::cout << "( "<<pos.x()<<","<<pos.y()<<","<<pos.z()<<") ";
00110 std::cout << " released energy (MeV) " << iStep->GetTotalEnergyDeposit()/MeV ;
00111 if (theTrack)
00112 {
00113 const G4ThreeVector mom = theTrack->GetMomentum();
00114 std::cout << " track length (cm) " << theTrack->GetTrackLength()/cm
00115 << " particle type " << theTrack->GetDefinition()->GetParticleName()
00116 << " momentum " << "( "<<mom.x()<<","<<mom.y()<<","<<mom.z()<<") ";
00117 if (theTrack->GetCreatorProcess())
00118 std::cout << " created by " << theTrack->GetCreatorProcess()->GetProcessName();
00119 }
00120 if(post->GetPhysicalVolume()) {
00121 std::cout << " " << pre->GetPhysicalVolume()->GetName() << "->" << post->GetPhysicalVolume()->GetName();
00122 }
00123 std::cout <<std::endl;
00124 }
00125
00126 if (post && post->GetPhysicalVolume())
00127 {
00128
00129 if (!m_passedTrg1 && post->GetPhysicalVolume()->GetName() == "TRG1")
00130 m_passedTrg1 = true;
00131 if (!m_passedTrg3 && post->GetPhysicalVolume()->GetName() == "TRG3")
00132 m_passedTrg3 = true;
00133 if (!m_passedTrg4 && post->GetPhysicalVolume()->GetName() == "TRG4")
00134 m_passedTrg4 = true;
00135 if (!m_passedTrg5 && post->GetPhysicalVolume()->GetName() == "TRG5")
00136 m_passedTrg5 = true;
00137 if (!m_passedTrg6 && post->GetPhysicalVolume()->GetName() == "TRG6")
00138 m_passedTrg6 = true;
00139 if (post->GetPhysicalVolume()->GetName() == "CMSSE")
00140 if (! (m_passedTrg1 && m_passedTrg6) )
00141 throw SimG4Exception("Event is not triggered by ECALTBH4");
00142 }
00143
00144
00145
00146 }
00147
00148
00149
00150 void update(const EndOfEvent* anEvent)
00151 {
00152
00153
00154
00155
00156 nTriggeredEvents_++;
00157 }
00158
00159
00160 private:
00161
00162
00163
00164
00165
00166 bool m_verbose;
00167
00168
00169 bool m_passedTrg1;
00170 bool m_passedTrg3;
00171 bool m_passedTrg4;
00172 bool m_passedTrg5;
00173 bool m_passedTrg6;
00174 int nTriggeredEvents_;
00175 int trigEvents_;
00176
00177 };
00178
00179
00180 #endif