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
int & SLnEvtInBinEta(int ebin, int etabin)
std::vector< G4PrimaryParticle * > thePrims
bool FillShowerEvent(CaloG4HitCollection *, CastorShowerEvent *, int)
std::map< int, G4ThreeVector > PrimaryPosition
void KillSecondaries(const G4Step *step)
bool SLisEtaBinFilled(int ebin, int etabin)
std::vector< std::vector< std::vector< std::vector< CastorShowerEvent > > > > SLBin3D
std::map< int, std::set< int > > MapOfSecondaries
std::vector< G4PrimaryParticle * > GetPrimary(const G4Event *)
CastorShowerLibraryInfo * hadInfo
std::vector< std::vector< std::vector< int > > > nEvtInBinPhi
CastorShowerLibraryInfo * emInfo
CastorShowerLibraryMaker(const edm::ParameterSet &p)
void GetMissingEnergy(CaloG4HitCollection *, double &, double &)
void GetKinematics(G4PrimaryParticle *, double &px, double &py, double &pz, double &pInit, double &eta, double &phi)
int & SLnEvtInBinPhi(int ebin, int etabin, int phibin)
std::vector< std::vector< int > > nEvtInBinEta
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
bool SLisPhiBinFilled(int ebin, int etabin, int phibin)
std::map< int, G4ThreeVector > PrimaryMomentum
step
Definition: StallMonitor.cc:94
void update(const BeginOfJob *run) override
This routine will be called when the appropriate signal arrives.