CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/SimG4CMS/EcalTestBeam/interface/EcalTBH4Trigger.h

Go to the documentation of this file.
00001 #ifndef HelpfulWatchers_EcalTBH4Trigger_h
00002 #define HelpfulWatchers_EcalTBH4Trigger_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     HelpfulWatchers
00006 // Class  :     EcalTBH4Trigger
00007 // 
00016 // $Id: EcalTBH4Trigger.h,v 1.1 2007/03/19 17:21:49 fabiocos Exp $
00017 //
00018 
00019 // system include files
00020 #include <iostream>
00021 
00022 // user include files
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 // forward declarations
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                         //OBSERVES(DDDWorld),
00048                         //OBSERVES(BeginOfJob),
00049                         //OBSERVES(BeginOfRun),
00050                         OBSERVES(BeginOfEvent),
00051                         //OBSERVES(BeginOfTrack),
00052                         OBSERVES(G4Step),
00053                         //OBSERVES(EndOfRun),
00054                         OBSERVES(EndOfEvent)
00055      //,
00056      //OBSERVES(EndOfTrack)
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   //virtual ~EcalTBH4Trigger();
00064   
00065   // ---------- const member functions ---------------------
00066 
00067   // ---------- static member functions --------------------
00068   
00069   // ---------- member functions ---------------------------
00070   //  UPDATEH4(DDDWorld)
00071   //UPDATEH4(BeginOfJob)
00072   //UPDATEH4(BeginOfRun)
00073     //  UPDATEH4(BeginOfEvent)
00074   void update(const BeginOfEvent* anEvent) 
00075     {
00076       //      std::cout <<"++ signal BeginOfEvent " ;
00077       //      m_enteringTBH4BeamLine=false;
00078       //      m_exitingTBH4BeamLine=false;
00079       //      m_passedTrigger=false;
00080       m_passedTrg1=false;
00081       m_passedTrg3=false;
00082       m_passedTrg4=false;
00083       m_passedTrg5=false;
00084       m_passedTrg6=false;
00085     } 
00086 
00087   //  UPDATEH4(BeginOfTrack)
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         //Get name and copy numbers
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") //Exiting TBH4BeamLine
00140             if (! (m_passedTrg1 && m_passedTrg6) ) // Trigger defined as Trg4 && Trg6
00141               throw SimG4Exception("Event is not triggered by ECALTBH4");
00142       }
00143     
00144 /*     if (!m_enteringTBH4BeamLine && ( post->GetPhysicalVolume()->GetName() ==  */
00145 
00146 }
00147 //UPDATEH4(G4Step)
00148 //UPDATEH4(EndOfRun)
00149 //UPDATEH4(EndOfEvent)
00150   void update(const EndOfEvent* anEvent) 
00151     {
00152       //      std::cout <<"++ signal BeginOfEvent " ;
00153       //      m_enteringTBH4BeamLine=false;
00154       //      m_exitingTBH4BeamLine=false;
00155       //      m_passedTrigger=false;
00156       nTriggeredEvents_++;
00157     } 
00158 //UPDATEH4(EndOfTrack)
00159 
00160    private:
00161      //EcalTBH4Trigger(const EcalTBH4Trigger&); // stop default
00162 
00163      //const EcalTBH4Trigger& operator=(const EcalTBH4Trigger&); // stop default
00164 
00165      // ---------- member data --------------------------------
00166  bool m_verbose;
00167 // bool m_enteringTBH4BeamLine; 
00168 // bool m_exitingTBH4BeamLine; 
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  // bool m_passedTrigger; 
00177 };
00178 
00179 
00180 #endif