|
| 1 | +/////////////////////////////////////////////////////////////////////////////// |
| 2 | +// File: ZdcTestTreeAnalysis.cc |
| 3 | +// Date: 04.25 Lev Kheyn |
| 4 | +// Description: simulation analysis code to make a tree needed for making |
| 5 | +// shower library for ZDC |
| 6 | +/////////////////////////////////////////////////////////////////////////////// |
| 7 | +#include "DataFormats/Math/interface/Point3D.h" |
| 8 | +#include "FWCore/MessageLogger/interface/MessageLogger.h" |
| 9 | +#include "FWCore/ParameterSet/interface/ParameterSet.h" |
| 10 | + |
| 11 | +#include "SimG4CMS/Calo/interface/CaloG4Hit.h" |
| 12 | +#include "SimG4CMS/Calo/interface/CaloG4HitCollection.h" |
| 13 | +#include "FWCore/ServiceRegistry/interface/Service.h" |
| 14 | +#include "FWCore/ServiceRegistry/interface/Service.h" |
| 15 | +#include "CommonTools/UtilAlgos/interface/TFileService.h" |
| 16 | +#include "SimG4CMS/Forward/interface/ZdcNumberingScheme.h" |
| 17 | + |
| 18 | +#include "SimG4Core/Notification/interface/BeginOfJob.h" |
| 19 | +#include "SimG4Core/Notification/interface/BeginOfRun.h" |
| 20 | +#include "SimG4Core/Notification/interface/EndOfRun.h" |
| 21 | +#include "SimG4Core/Notification/interface/BeginOfEvent.h" |
| 22 | +#include "SimG4Core/Notification/interface/EndOfEvent.h" |
| 23 | +#include "SimG4Core/Notification/interface/Observer.h" |
| 24 | +#include "SimG4Core/Watcher/interface/SimWatcher.h" |
| 25 | +#include "SimG4Core/Notification/interface/Observer.h" |
| 26 | + |
| 27 | +#include "G4SDManager.hh" |
| 28 | +#include "G4Step.hh" |
| 29 | +#include "G4Track.hh" |
| 30 | +#include "G4Event.hh" |
| 31 | +#include "G4PrimaryVertex.hh" |
| 32 | +#include "G4VProcess.hh" |
| 33 | +#include "G4HCofThisEvent.hh" |
| 34 | +#include "G4UserEventAction.hh" |
| 35 | + |
| 36 | +#include <CLHEP/Units/SystemOfUnits.h> |
| 37 | +#include <CLHEP/Units/GlobalPhysicalConstants.h> |
| 38 | +#include <CLHEP/Random/Randomize.h> |
| 39 | + |
| 40 | +#include "TFile.h" |
| 41 | +#include "TTree.h" |
| 42 | + |
| 43 | +#include <cassert> |
| 44 | +#include <cmath> |
| 45 | +#include <iostream> |
| 46 | +#include <iomanip> |
| 47 | +#include <map> |
| 48 | +#include <string> |
| 49 | +#include <vector> |
| 50 | + |
| 51 | +class ZdcTestTreeAnalysis : public SimWatcher, |
| 52 | + public Observer<const BeginOfJob*>, |
| 53 | + public Observer<const BeginOfRun*>, |
| 54 | + public Observer<const EndOfRun*>, |
| 55 | + public Observer<const BeginOfEvent*>, |
| 56 | + public Observer<const EndOfEvent*>, |
| 57 | + public Observer<const G4Step*> { |
| 58 | +public: |
| 59 | + ZdcTestTreeAnalysis(const edm::ParameterSet& p); |
| 60 | + ~ZdcTestTreeAnalysis() override; |
| 61 | + |
| 62 | +private: |
| 63 | + // observer classes |
| 64 | + void update(const BeginOfJob* run) override; |
| 65 | + void update(const BeginOfRun* run) override; |
| 66 | + void update(const EndOfRun* run) override; |
| 67 | + void update(const BeginOfEvent* evt) override; |
| 68 | + void update(const EndOfEvent* evt) override; |
| 69 | + void update(const G4Step* step) override; |
| 70 | + |
| 71 | + int verbosity_; |
| 72 | + TTree* theTree; |
| 73 | + int eventIndex, nhits; |
| 74 | + int fiberID[2000], npeem[2000], npehad[2000], time[2000]; |
| 75 | +}; |
| 76 | + |
| 77 | +ZdcTestTreeAnalysis::ZdcTestTreeAnalysis(const edm::ParameterSet& p) { |
| 78 | + edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("ZdcTestTreeAnalysis"); |
| 79 | + verbosity_ = m_Anal.getParameter<int>("Verbosity"); |
| 80 | +} |
| 81 | + |
| 82 | +ZdcTestTreeAnalysis::~ZdcTestTreeAnalysis() {} |
| 83 | + |
| 84 | +// &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& |
| 85 | +void ZdcTestTreeAnalysis::update(const BeginOfJob* job) { |
| 86 | + //job |
| 87 | + if (verbosity_ > 0) |
| 88 | + edm::LogVerbatim("ZdcTestTreeAnalysis") << "ZdcTestTreeAnalysis::Beggining of job"; |
| 89 | + edm::Service<TFileService> theFile; |
| 90 | + theTree = theFile->make<TTree>("CherenkovPhotons", "Cherenkov Photons"); |
| 91 | + theTree->Branch("nhits", &nhits, "nhits/I"); |
| 92 | + theTree->Branch("fiberID", fiberID, "fiberID/I"); |
| 93 | + theTree->Branch("npeem", npeem, "npeem/I"); |
| 94 | + theTree->Branch("npehad", npehad, "npehad/I"); |
| 95 | + theTree->Branch("time", time, "time/I"); |
| 96 | +}; |
| 97 | + |
| 98 | +//==================================================================== per RUN |
| 99 | +void ZdcTestTreeAnalysis::update(const BeginOfRun* run) { |
| 100 | + //run |
| 101 | + |
| 102 | + if (verbosity_ > 0) |
| 103 | + edm::LogVerbatim("ZdcTestTreeAnalysis") << "\nZdcTestTreeAnalysis: Begining of Run"; |
| 104 | + |
| 105 | + eventIndex = 0; |
| 106 | +} |
| 107 | + |
| 108 | +void ZdcTestTreeAnalysis::update(const BeginOfEvent* evt) { |
| 109 | + if (verbosity_ > 0) |
| 110 | + edm::LogVerbatim("ZdcTestTreeAnalysis") << "ZdcTest: Processing Event Number: " << eventIndex; |
| 111 | + eventIndex++; |
| 112 | +} |
| 113 | + |
| 114 | +//================================================================================================ |
| 115 | +void ZdcTestTreeAnalysis::update(const G4Step* aStep) {} |
| 116 | + |
| 117 | +//================================================================================================ |
| 118 | +void ZdcTestTreeAnalysis::update(const EndOfEvent* evt) { |
| 119 | + // access to the G4 hit collections |
| 120 | + G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent(); |
| 121 | + if (verbosity_ > 0) |
| 122 | + edm::LogVerbatim("ZdcTestTreeAnalysis") << " accessed all HC"; |
| 123 | + |
| 124 | + int theZDCHCid = G4SDManager::GetSDMpointer()->GetCollectionID("ZDCHITS"); |
| 125 | + if (verbosity_ > 0) |
| 126 | + edm::LogVerbatim("ZdcTestTreeAnalysis") << " - theZDCHCid = " << theZDCHCid; |
| 127 | + |
| 128 | + CaloG4HitCollection* theZDCHC = (CaloG4HitCollection*)allHC->GetHC(theZDCHCid); |
| 129 | + if (verbosity_ > 0) |
| 130 | + edm::LogVerbatim("ZdcTestTreeAnalysis") << " - theZDCHC = " << theZDCHC; |
| 131 | + |
| 132 | + int nentries = theZDCHC->entries(); |
| 133 | + if (verbosity_ > 0) |
| 134 | + edm::LogVerbatim("ZdcTestTreeAnalysis") << " theZDCHC has " << nentries << " entries"; |
| 135 | + |
| 136 | + if (nentries > 0) { |
| 137 | + for (int ihit = 0; ihit < nentries; ihit++) { |
| 138 | + CaloG4Hit* aHit = (*theZDCHC)[ihit]; |
| 139 | + fiberID[ihit] = aHit->getUnitID(); |
| 140 | + npeem[ihit] = aHit->getEM(); |
| 141 | + npehad[ihit] = aHit->getHadr(); |
| 142 | + time[ihit] = aHit->getTimeSliceID(); |
| 143 | + |
| 144 | + if (verbosity_ > 1) |
| 145 | + edm::LogVerbatim("ZdcTestTreeAnalysis") |
| 146 | + << " entry #" << ihit << ": fiaberID=0x" << std::hex << fiberID[ihit] << std::dec |
| 147 | + << "; npeem=" << npeem[ihit] << "; npehad[ihit]=" << npehad << " time=" << time[ihit]; |
| 148 | + } |
| 149 | + } |
| 150 | + nhits = nentries; |
| 151 | + theTree->Fill(); |
| 152 | +} |
| 153 | + |
| 154 | +void ZdcTestTreeAnalysis::update(const EndOfRun* run) {} |
| 155 | + |
| 156 | +#include "SimG4Core/Watcher/interface/SimWatcherFactory.h" |
| 157 | +#include "FWCore/PluginManager/interface/ModuleDef.h" |
| 158 | + |
| 159 | +DEFINE_SIMWATCHER(ZdcTestTreeAnalysis); |
0 commit comments