CMS 3D CMS Logo

CastorShowerLibraryMaker.h
Go to the documentation of this file.
1 //
3 // File: CastorShowerLibraryMaker.h
4 // Date: 02/2009
5 // Author: Wagner Carvalho (adapted from Panos Katsas code)
6 // Description: simulation analysis steering code
7 //
9 #undef debug
10 #ifndef CastorShowerLibraryMaker_h
11 #define CastorShowerLibraryMaker_h
12 
18 
20 
21 #include "G4RunManager.hh"
22 #include "G4SDManager.hh"
23 #include "G4Step.hh"
24 #include "G4Track.hh"
25 #include "G4Event.hh"
26 #include "G4PrimaryVertex.hh"
27 #include "G4VProcess.hh"
28 #include "G4HCofThisEvent.hh"
29 #include "G4UserEventAction.hh"
30 #include "CLHEP/Units/SystemOfUnits.h"
31 #include "CLHEP/Units/PhysicalConstants.h"
32 
35 
39 
40 // Classes for shower library Root file
43 
44 #include <cassert>
45 #include <iostream>
46 #include <string>
47 #include <map>
48 #include <set>
49 #include <cmath>
50 #include <memory>
51 #include <vector>
52 
53 #include <CLHEP/Random/Randomize.h>
54 
55 #include "TROOT.h"
56 #include "TFile.h"
57 #include "TH1.h"
58 #include "TH2.h"
59 #include "TProfile.h"
60 #include "TNtuple.h"
61 #include "TRandom.h"
62 #include "TLorentzVector.h"
63 #include "TUnixSystem.h"
64 #include "TSystem.h"
65 #include "TMath.h"
66 #include "TF1.h"
67 
68 class G4Step;
69 class BeginOfJob;
70 class BeginOfRun;
71 class EndOfRun;
72 class BeginOfEvent;
73 class EndOfEvent;
74 
75 /*
76 typedef std::vector<std::vector<CastorShowerEvent> > phi_t; //holds N phi bin collection (with M events each)
77 typedef std::vector<phi_t> eta_t; //holds N eta bin collection
78 typedef std::vector<eta_t> energy_t; //holds N energy bin
79 */
80 typedef std::vector<std::vector<std::vector<std::vector<CastorShowerEvent> > > > SLBin3D; // bin in energy, eta and phi
81 
83  public Observer<const BeginOfJob*>,
84  public Observer<const BeginOfRun*>,
85  public Observer<const EndOfRun*>,
86  public Observer<const BeginOfEvent*>,
87  public Observer<const EndOfEvent*>,
88  public Observer<const G4Step*> {
89 public:
91  ~CastorShowerLibraryMaker() override;
92 
93 private:
94  typedef int ebin;
95  typedef int etabin;
96  typedef int phibin;
97  // private structures
98  struct ShowerLib {
100  SLBin3D SLCollection; // the showers
101  std::vector<double> SLEnergyBins;
102  std::vector<double> SLEtaBins;
103  std::vector<double> SLPhiBins;
104  unsigned int nEvtPerBinE;
105  unsigned int nEvtPerBinEta;
106  unsigned int nEvtPerBinPhi;
107  std::vector<int> nEvtInBinE;
108  std::vector<std::vector<int> > nEvtInBinEta;
109  std::vector<std::vector<std::vector<int> > > nEvtInBinPhi;
110  };
111 
112  // observer classes
113  void update(const BeginOfJob* run) override;
114  void update(const BeginOfRun* run) override;
115  void update(const EndOfRun* run) override;
116  void update(const BeginOfEvent* evt) override;
117  void update(const EndOfEvent* evt) override;
118  void update(const G4Step* step) override;
119 
120 private:
121  void Finish();
122 
123  // Job general parameters
126 
127  unsigned int NPGParticle; // number of particles requested to Particle Gun
128  std::vector<int> PGParticleIDs; //p. gun particle IDs
129  bool DoHadSL; // true if hadronic SL should be produced
130  bool DoEmSL; // true if electromag. SL should be produced
131  bool InsideCastor; // true if particle step inside CASTOR
132  bool DeActivatePhysicsProcess; //cfg parameter: True if phys. proc. should be off from IP to Castor
133  std::vector<G4PrimaryParticle*> thePrims; // list of primaries for this event
134 
135  // Pointers for user defined class objects to be stored to Root file
142  ShowerLib* SLShowerptr; // pointer to the current shower collection (above)
143  std::map<int, std::set<int> > MapOfSecondaries; // map to hold all secondaries ID keyed by
144  // the PDG code of the primary
145 
146  std::map<int, G4ThreeVector> PrimaryMomentum;
147  std::map<int, G4ThreeVector> PrimaryPosition;
148  double MaxEta; // limits the eta region, the lower limit is given by the SL bins
149  double MaxPhi; // limits the phi region, the lower limit is given by the SL bins
150  // private methods
151  int FindEnergyBin(double e);
152  int FindEtaBin(double eta);
153  int FindPhiBin(double phi);
154  bool SLacceptEvent(int, int, int);
155  bool IsSLReady();
156  void GetKinematics(G4PrimaryParticle*, double& px, double& py, double& pz, double& pInit, double& eta, double& phi);
157  void GetKinematics(int, double& px, double& py, double& pz, double& pInit, double& eta, double& phi);
158 
159  std::vector<G4PrimaryParticle*> GetPrimary(const G4Event*);
161  void InitSLHolder(ShowerLib&);
162 
163  void printSLstatus(int, int, int);
164  int& SLnEvtInBinE(int ebin);
165  int& SLnEvtInBinEta(int ebin, int etabin);
166  int& SLnEvtInBinPhi(int ebin, int etabin, int phibin);
167  bool SLisEBinFilled(int ebin);
168  bool SLisEtaBinFilled(int ebin, int etabin);
169  bool SLisPhiBinFilled(int ebin, int etabin, int phibin);
170  void KillSecondaries(const G4Step* step);
171  void GetMissingEnergy(CaloG4HitCollection*, double&, double&);
172 
173  // Root pointers
174  TFile* theFile;
175  TTree* theTree;
176 
178  int stepIndex; // ignore, please
179 };
180 
181 #endif // CastorShowerLibraryMaker_h
CastorShowerLibraryMaker::thePrims
std::vector< G4PrimaryParticle * > thePrims
Definition: CastorShowerLibraryMaker.h:133
CastorShowerLibraryMaker::PGParticleIDs
std::vector< int > PGParticleIDs
Definition: CastorShowerLibraryMaker.h:128
CastorShowerLibraryMaker::FillShowerEvent
bool FillShowerEvent(CaloG4HitCollection *, CastorShowerEvent *, int)
Definition: CastorShowerLibraryMaker.cc:886
Observer
Definition: Observer.h:23
CastorShowerLibraryMaker::ShowerLib::nEvtPerBinE
unsigned int nEvtPerBinE
Definition: CastorShowerLibraryMaker.h:104
BeginOfJob.h
step
step
Definition: StallMonitor.cc:94
CastorShowerLibraryMaker::etabin
int etabin
Definition: CastorShowerLibraryMaker.h:95
CastorShowerLibraryMaker::SLShowerptr
ShowerLib * SLShowerptr
Definition: CastorShowerLibraryMaker.h:142
CastorShowerLibraryMaker::SLnEvtInBinPhi
int & SLnEvtInBinPhi(int ebin, int etabin, int phibin)
Definition: CastorShowerLibraryMaker.cc:983
CaloG4HitCollection.h
multPhiCorr_741_25nsDY_cfi.py
py
Definition: multPhiCorr_741_25nsDY_cfi.py:12
CastorShowerLibraryMaker::ShowerLib::nEvtPerBinEta
unsigned int nEvtPerBinEta
Definition: CastorShowerLibraryMaker.h:105
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
CastorShowerLibraryMaker::ShowerLib::nEvtPerBinPhi
unsigned int nEvtPerBinPhi
Definition: CastorShowerLibraryMaker.h:106
CastorShowerLibraryMaker::printSLstatus
void printSLstatus(int, int, int)
Definition: CastorShowerLibraryMaker.cc:819
CastorShowerLibraryMaker::ebin
int ebin
Definition: CastorShowerLibraryMaker.h:94
CastorShowerLibraryMaker::~CastorShowerLibraryMaker
~CastorShowerLibraryMaker() override
Definition: CastorShowerLibraryMaker.cc:141
EndOfEvent.h
CastorShowerLibraryMaker::IsSLReady
bool IsSLReady()
Definition: CastorShowerLibraryMaker.cc:718
CastorShowerLibraryMaker::InsideCastor
bool InsideCastor
Definition: CastorShowerLibraryMaker.h:131
CastorShowerLibraryMaker::eventNtFileName
std::string eventNtFileName
Definition: CastorShowerLibraryMaker.h:125
CastorShowerLibraryMaker::GetKinematics
void GetKinematics(G4PrimaryParticle *, double &px, double &py, double &pz, double &pInit, double &eta, double &phi)
Definition: CastorShowerLibraryMaker.cc:764
Observer.h
CastorShowerLibraryMaker::emSLHolder
ShowerLib emSLHolder
Definition: CastorShowerLibraryMaker.h:140
CastorShowerLibraryMaker::hadSLHolder
ShowerLib hadSLHolder
Definition: CastorShowerLibraryMaker.h:141
CastorShowerLibraryMaker::SLnEvtInBinEta
int & SLnEvtInBinEta(int ebin, int etabin)
Definition: CastorShowerLibraryMaker.cc:975
CastorShowerLibraryMaker::SLisEBinFilled
bool SLisEBinFilled(int ebin)
Definition: CastorShowerLibraryMaker.cc:990
BeginOfRun.h
CastorShowerLibraryInfo
Definition: CastorShowerLibraryInfo.h:41
CastorShowerLibraryMaker::stepIndex
int stepIndex
Definition: CastorShowerLibraryMaker.h:178
CastorShowerLibraryMaker
Definition: CastorShowerLibraryMaker.h:82
SimWatcher.h
CastorShowerLibraryMaker::MaxPhi
double MaxPhi
Definition: CastorShowerLibraryMaker.h:149
Service.h
PVValHelper::eta
Definition: PVValidationHelpers.h:69
CastorShowerLibraryMaker::KillSecondaries
void KillSecondaries(const G4Step *step)
Definition: CastorShowerLibraryMaker.cc:1017
CastorShowerLibraryMaker::verbosity
int verbosity
Definition: CastorShowerLibraryMaker.h:124
CastorShowerLibraryMaker::ShowerLib::SLInfo
CastorShowerLibraryInfo SLInfo
Definition: CastorShowerLibraryMaker.h:99
BeginOfJob
Definition: BeginOfJob.h:8
CastorShowerLibraryMaker::update
void update(const BeginOfJob *run) override
This routine will be called when the appropriate signal arrives.
Definition: CastorShowerLibraryMaker.cc:148
CastorShowerLibraryMaker::SLisEtaBinFilled
bool SLisEtaBinFilled(int ebin, int etabin)
Definition: CastorShowerLibraryMaker.cc:999
EndOfEvent
Definition: EndOfEvent.h:6
CastorShowerLibraryMaker::hadInfo
CastorShowerLibraryInfo * hadInfo
Definition: CastorShowerLibraryMaker.h:137
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CastorShowerLibraryMaker::ShowerLib::nEvtInBinPhi
std::vector< std::vector< std::vector< int > > > nEvtInBinPhi
Definition: CastorShowerLibraryMaker.h:109
TFileService.h
CastorShowerLibraryMaker::emInfo
CastorShowerLibraryInfo * emInfo
Definition: CastorShowerLibraryMaker.h:136
edm::ParameterSet
Definition: ParameterSet.h:36
CastorShowerLibraryMaker::FindEnergyBin
int FindEnergyBin(double e)
Definition: CastorShowerLibraryMaker.cc:648
CastorShowerLibraryMaker::MapOfSecondaries
std::map< int, std::set< int > > MapOfSecondaries
Definition: CastorShowerLibraryMaker.h:143
CastorShowerLibraryMaker::ShowerLib::nEvtInBinEta
std::vector< std::vector< int > > nEvtInBinEta
Definition: CastorShowerLibraryMaker.h:108
CastorShowerLibraryMaker::ShowerLib
Definition: CastorShowerLibraryMaker.h:98
CastorShowerEvent
Definition: CastorShowerEvent.h:15
BeginOfEvent.h
CastorShowerLibraryMaker::PrimaryPosition
std::map< int, G4ThreeVector > PrimaryPosition
Definition: CastorShowerLibraryMaker.h:147
CastorShowerLibraryMaker::PrimaryMomentum
std::map< int, G4ThreeVector > PrimaryMomentum
Definition: CastorShowerLibraryMaker.h:146
CastorShowerLibraryMaker::hadShower
CastorShowerEvent * hadShower
Definition: CastorShowerLibraryMaker.h:139
CastorShowerLibraryMaker::DeActivatePhysicsProcess
bool DeActivatePhysicsProcess
Definition: CastorShowerLibraryMaker.h:132
CastorShowerLibraryMaker::theTree
TTree * theTree
Definition: CastorShowerLibraryMaker.h:175
BeginOfEvent
Definition: BeginOfEvent.h:6
CastorShowerLibraryMaker::emShower
CastorShowerEvent * emShower
Definition: CastorShowerLibraryMaker.h:138
BeginOfRun
Definition: BeginOfRun.h:6
EndOfRun
Definition: EndOfRun.h:6
SimWatcher
Definition: SimWatcher.h:33
CastorShowerLibraryMaker::eventIndex
int eventIndex
Definition: CastorShowerLibraryMaker.h:177
CastorShowerLibraryMaker::SLacceptEvent
bool SLacceptEvent(int, int, int)
Definition: CastorShowerLibraryMaker.cc:865
CastorShowerLibraryMaker::FindEtaBin
int FindEtaBin(double eta)
Definition: CastorShowerLibraryMaker.cc:672
CastorShowerLibraryInfo.h
CastorShowerLibraryMaker::ShowerLib::SLPhiBins
std::vector< double > SLPhiBins
Definition: CastorShowerLibraryMaker.h:103
EndOfRun.h
DDAxes::phi
multPhiCorr_741_25nsDY_cfi.px
px
Definition: multPhiCorr_741_25nsDY_cfi.py:10
CastorShowerLibraryMaker::SLisPhiBinFilled
bool SLisPhiBinFilled(int ebin, int etabin, int phibin)
Definition: CastorShowerLibraryMaker.cc:1008
writedatasetfile.run
run
Definition: writedatasetfile.py:27
CastorShowerLibraryMaker::ShowerLib::SLEtaBins
std::vector< double > SLEtaBins
Definition: CastorShowerLibraryMaker.h:102
CastorShowerLibraryMaker::GetMissingEnergy
void GetMissingEnergy(CaloG4HitCollection *, double &, double &)
Definition: CastorShowerLibraryMaker.cc:1027
CastorShowerLibraryMaker::NPGParticle
unsigned int NPGParticle
Definition: CastorShowerLibraryMaker.h:127
CastorShowerLibraryMaker::DoEmSL
bool DoEmSL
Definition: CastorShowerLibraryMaker.h:130
CastorShowerLibraryMaker::FindPhiBin
int FindPhiBin(double phi)
Definition: CastorShowerLibraryMaker.cc:694
CastorShowerLibraryMaker::theFile
TFile * theFile
Definition: CastorShowerLibraryMaker.h:174
CastorShowerLibraryMaker::MaxEta
double MaxEta
Definition: CastorShowerLibraryMaker.h:148
CastorShowerLibraryMaker::InitSLHolder
void InitSLHolder(ShowerLib &)
Definition: CastorShowerLibraryMaker.cc:97
CastorShowerLibraryMaker::GetPrimary
std::vector< G4PrimaryParticle * > GetPrimary(const G4Event *)
Definition: CastorShowerLibraryMaker.cc:783
CastorShowerLibraryMaker::CastorShowerLibraryMaker
CastorShowerLibraryMaker(const edm::ParameterSet &p)
Definition: CastorShowerLibraryMaker.cc:38
CaloG4HitCollection
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
Definition: CaloG4HitCollection.h:11
SLBin3D
std::vector< std::vector< std::vector< std::vector< CastorShowerEvent > > > > SLBin3D
Definition: CastorShowerLibraryMaker.h:73
CastorShowerLibraryMaker::SLnEvtInBinE
int & SLnEvtInBinE(int ebin)
Definition: CastorShowerLibraryMaker.cc:967
ParameterSet.h
CastorShowerLibraryMaker::DoHadSL
bool DoHadSL
Definition: CastorShowerLibraryMaker.h:129
CastorShowerLibraryMaker::ShowerLib::SLEnergyBins
std::vector< double > SLEnergyBins
Definition: CastorShowerLibraryMaker.h:101
CastorShowerLibraryMaker::ShowerLib::SLCollection
SLBin3D SLCollection
Definition: CastorShowerLibraryMaker.h:100
CastorShowerLibraryMaker::ShowerLib::nEvtInBinE
std::vector< int > nEvtInBinE
Definition: CastorShowerLibraryMaker.h:107
CastorShowerLibraryMaker::Finish
void Finish()
Definition: CastorShowerLibraryMaker.cc:633
CastorShowerLibraryMaker::phibin
int phibin
Definition: CastorShowerLibraryMaker.h:96
CastorShowerEvent.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37