File indexing completed on 2025-04-17 23:03:07
0001
0002
0003
0004
0005
0006
0007 #include "DataFormats/Math/interface/Point3D.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010
0011 #include "SimG4CMS/Calo/interface/CaloG4Hit.h"
0012 #include "SimG4CMS/Calo/interface/CaloG4HitCollection.h"
0013 #include "FWCore/ServiceRegistry/interface/Service.h"
0014 #include "FWCore/ServiceRegistry/interface/Service.h"
0015 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0016 #include "SimG4CMS/Forward/interface/ZdcNumberingScheme.h"
0017
0018 #include "SimG4Core/Notification/interface/BeginOfJob.h"
0019 #include "SimG4Core/Notification/interface/BeginOfRun.h"
0020 #include "SimG4Core/Notification/interface/EndOfRun.h"
0021 #include "SimG4Core/Notification/interface/BeginOfEvent.h"
0022 #include "SimG4Core/Notification/interface/EndOfEvent.h"
0023 #include "SimG4Core/Notification/interface/Observer.h"
0024 #include "SimG4Core/Watcher/interface/SimWatcher.h"
0025 #include "SimG4Core/Notification/interface/Observer.h"
0026
0027 #include "G4SDManager.hh"
0028 #include "G4Step.hh"
0029 #include "G4Track.hh"
0030 #include "G4Event.hh"
0031 #include "G4PrimaryVertex.hh"
0032 #include "G4VProcess.hh"
0033 #include "G4HCofThisEvent.hh"
0034 #include "G4UserEventAction.hh"
0035
0036 #include <CLHEP/Units/SystemOfUnits.h>
0037 #include <CLHEP/Units/GlobalPhysicalConstants.h>
0038 #include <CLHEP/Random/Randomize.h>
0039
0040 #include "TFile.h"
0041 #include "TTree.h"
0042
0043 #include <cassert>
0044 #include <cmath>
0045 #include <iostream>
0046 #include <iomanip>
0047 #include <map>
0048 #include <string>
0049 #include <vector>
0050
0051 class ZdcTestTreeAnalysis : public SimWatcher,
0052 public Observer<const BeginOfJob*>,
0053 public Observer<const BeginOfRun*>,
0054 public Observer<const EndOfRun*>,
0055 public Observer<const BeginOfEvent*>,
0056 public Observer<const EndOfEvent*>,
0057 public Observer<const G4Step*> {
0058 public:
0059 ZdcTestTreeAnalysis(const edm::ParameterSet& p);
0060 ~ZdcTestTreeAnalysis() override;
0061
0062 private:
0063
0064 void update(const BeginOfJob* run) override;
0065 void update(const BeginOfRun* run) override;
0066 void update(const EndOfRun* run) override;
0067 void update(const BeginOfEvent* evt) override;
0068 void update(const EndOfEvent* evt) override;
0069 void update(const G4Step* step) override;
0070
0071 int verbosity_;
0072 TTree* theTree;
0073 int eventIndex, nhits;
0074 int fiberID[2000], npeem[2000], npehad[2000], time[2000];
0075 };
0076
0077 ZdcTestTreeAnalysis::ZdcTestTreeAnalysis(const edm::ParameterSet& p) {
0078 edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("ZdcTestTreeAnalysis");
0079 verbosity_ = m_Anal.getParameter<int>("Verbosity");
0080 }
0081
0082 ZdcTestTreeAnalysis::~ZdcTestTreeAnalysis() {}
0083
0084
0085 void ZdcTestTreeAnalysis::update(const BeginOfJob* job) {
0086
0087 if (verbosity_ > 0)
0088 edm::LogVerbatim("ZdcTestTreeAnalysis") << "ZdcTestTreeAnalysis::Beggining of job";
0089 edm::Service<TFileService> theFile;
0090 theTree = theFile->make<TTree>("CherenkovPhotons", "Cherenkov Photons");
0091 theTree->Branch("nhits", &nhits, "nhits/I");
0092 theTree->Branch("fiberID", fiberID, "fiberID/I");
0093 theTree->Branch("npeem", npeem, "npeem/I");
0094 theTree->Branch("npehad", npehad, "npehad/I");
0095 theTree->Branch("time", time, "time/I");
0096 };
0097
0098
0099 void ZdcTestTreeAnalysis::update(const BeginOfRun* run) {
0100
0101
0102 if (verbosity_ > 0)
0103 edm::LogVerbatim("ZdcTestTreeAnalysis") << "\nZdcTestTreeAnalysis: Begining of Run";
0104
0105 eventIndex = 0;
0106 }
0107
0108 void ZdcTestTreeAnalysis::update(const BeginOfEvent* evt) {
0109 if (verbosity_ > 0)
0110 edm::LogVerbatim("ZdcTestTreeAnalysis") << "ZdcTest: Processing Event Number: " << eventIndex;
0111 eventIndex++;
0112 }
0113
0114
0115 void ZdcTestTreeAnalysis::update(const G4Step* aStep) {}
0116
0117
0118 void ZdcTestTreeAnalysis::update(const EndOfEvent* evt) {
0119
0120 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
0121 if (verbosity_ > 0)
0122 edm::LogVerbatim("ZdcTestTreeAnalysis") << " accessed all HC";
0123
0124 int theZDCHCid = G4SDManager::GetSDMpointer()->GetCollectionID("ZDCHITS");
0125 if (verbosity_ > 0)
0126 edm::LogVerbatim("ZdcTestTreeAnalysis") << " - theZDCHCid = " << theZDCHCid;
0127
0128 CaloG4HitCollection* theZDCHC = (CaloG4HitCollection*)allHC->GetHC(theZDCHCid);
0129 if (verbosity_ > 0)
0130 edm::LogVerbatim("ZdcTestTreeAnalysis") << " - theZDCHC = " << theZDCHC;
0131
0132 int nentries = theZDCHC->entries();
0133 if (verbosity_ > 0)
0134 edm::LogVerbatim("ZdcTestTreeAnalysis") << " theZDCHC has " << nentries << " entries";
0135
0136 if (nentries > 0) {
0137 for (int ihit = 0; ihit < nentries; ihit++) {
0138 CaloG4Hit* aHit = (*theZDCHC)[ihit];
0139 fiberID[ihit] = aHit->getUnitID();
0140 npeem[ihit] = aHit->getEM();
0141 npehad[ihit] = aHit->getHadr();
0142 time[ihit] = aHit->getTimeSliceID();
0143
0144 if (verbosity_ > 1)
0145 edm::LogVerbatim("ZdcTestTreeAnalysis")
0146 << " entry #" << ihit << ": fiaberID=0x" << std::hex << fiberID[ihit] << std::dec
0147 << "; npeem=" << npeem[ihit] << "; npehad[ihit]=" << npehad << " time=" << time[ihit];
0148 }
0149 }
0150 nhits = nentries;
0151 theTree->Fill();
0152 }
0153
0154 void ZdcTestTreeAnalysis::update(const EndOfRun* run) {}
0155
0156 #include "SimG4Core/Watcher/interface/SimWatcherFactory.h"
0157 #include "FWCore/PluginManager/interface/ModuleDef.h"
0158
0159 DEFINE_SIMWATCHER(ZdcTestTreeAnalysis);