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 
69 class G4Step;
70 class BeginOfJob;
71 class BeginOfRun;
72 class EndOfRun;
73 class BeginOfEvent;
74 class EndOfEvent;
75 
76 /*
77 typedef std::vector<std::vector<CastorShowerEvent> > phi_t; //holds N phi bin collection (with M events each)
78 typedef std::vector<phi_t> eta_t; //holds N eta bin collection
79 typedef std::vector<eta_t> energy_t; //holds N energy bin
80 */
81 typedef std::vector<std::vector<std::vector<std::vector<CastorShowerEvent> > > > SLBin3D; // bin in energy, eta and phi
82 
84  public Observer<const BeginOfJob *>,
85  public Observer<const BeginOfRun *>,
86  public Observer<const EndOfRun *>,
87  public Observer<const BeginOfEvent *>,
88  public Observer<const EndOfEvent *>,
89  public Observer<const G4Step *> {
90 
91 public:
92 
94  virtual ~CastorShowerLibraryMaker();
95 
96 private:
97  typedef int ebin;
98  typedef int etabin;
99  typedef int phibin;
100 // private structures
101  struct ShowerLib {
103  SLBin3D SLCollection; // the showers
104  std::vector<double> SLEnergyBins;
105  std::vector<double> SLEtaBins;
106  std::vector<double> SLPhiBins;
107  unsigned int nEvtPerBinE;
108  unsigned int nEvtPerBinEta;
109  unsigned int nEvtPerBinPhi;
110  std::vector<int> nEvtInBinE;
111  std::vector<std::vector<int> > nEvtInBinEta;
112  std::vector<std::vector<std::vector<int> > > nEvtInBinPhi;
113  };
114 
115  // observer classes
116  void update(const BeginOfJob * run);
117  void update(const BeginOfRun * run);
118  void update(const EndOfRun * run);
119  void update(const BeginOfEvent * evt);
120  void update(const EndOfEvent * evt);
121  void update(const G4Step * step);
122 
123 private:
124 
125  void Finish();
126 
127  // Job general parameters
130 
131  unsigned int NPGParticle; // number of particles requested to Particle Gun
132  std::vector<int> PGParticleIDs; //p. gun particle IDs
133  bool DoHadSL; // true if hadronic SL should be produced
134  bool DoEmSL; // true if electromag. SL should be produced
135  bool InsideCastor; // true if particle step inside CASTOR
136  bool DeActivatePhysicsProcess; //cfg parameter: True if phys. proc. should be off from IP to Castor
137  std::vector<G4PrimaryParticle*> thePrims; // list of primaries for this event
138 
139  // Pointers for user defined class objects to be stored to Root file
146  ShowerLib* SLShowerptr; // pointer to the current shower collection (above)
147  std::map<int,std::set<int> > MapOfSecondaries; // map to hold all secondaries ID keyed by
148  // the PDG code of the primary
149 
150  std::map<int,G4ThreeVector> PrimaryMomentum;
151  std::map<int,G4ThreeVector> PrimaryPosition;
152  double MaxEta; // limits the eta region, the lower limit is given by the SL bins
153  double MaxPhi; // limits the phi region, the lower limit is given by the SL bins
154 // private methods
155  int FindEnergyBin(double e);
156  int FindEtaBin(double eta);
157  int FindPhiBin(double phi);
158  bool SLacceptEvent(int, int, int);
159  bool IsSLReady();
160  void GetKinematics(G4PrimaryParticle* ,
161  double& px, double& py, double& pz, double& pInit, double& eta, double& phi);
162  void GetKinematics(int ,
163  double& px, double& py, double& pz, double& pInit, double& eta, double& phi);
164 
165  std::vector<G4PrimaryParticle*> GetPrimary(const G4Event * );
167  void InitSLHolder(ShowerLib& );
168 
169  void printSLstatus(int , int, int);
170  int& SLnEvtInBinE(int ebin);
171  int& SLnEvtInBinEta(int ebin, int etabin);
172  int& SLnEvtInBinPhi(int ebin, int etabin, int phibin);
173  bool SLisEBinFilled(int ebin);
174  bool SLisEtaBinFilled(int ebin, int etabin);
175  bool SLisPhiBinFilled(int ebin, int etabin, int phibin);
176  void KillSecondaries(const G4Step * step);
177  void GetMissingEnergy(CaloG4HitCollection* ,double& ,double& );
178 
179  // Root pointers
180  TFile* theFile;
181  TTree* theTree;
182 
184  int stepIndex; // ignore, please
185 
186 };
187 
188 #endif // CastorShowerLibraryMaker_h
int & SLnEvtInBinEta(int ebin, int etabin)
std::vector< G4PrimaryParticle * > thePrims
bool FillShowerEvent(CaloG4HitCollection *, CastorShowerEvent *, int)
void KillSecondaries(const G4Step *step)
bool SLisEtaBinFilled(int ebin, int etabin)
std::vector< std::vector< std::vector< std::vector< CastorShowerEvent > > > > SLBin3D
std::vector< G4PrimaryParticle * > GetPrimary(const G4Event *)
CastorShowerLibraryInfo * hadInfo
std::map< int, G4ThreeVector > PrimaryMomentum
std::map< int, G4ThreeVector > PrimaryPosition
std::vector< std::vector< std::vector< int > > > nEvtInBinPhi
std::map< int, std::set< int > > MapOfSecondaries
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
void update(const BeginOfJob *run)
This routine will be called when the appropriate signal arrives.
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
bool SLisPhiBinFilled(int ebin, int etabin, int phibin)
step