Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00009 #undef debug
00010 #ifndef CastorShowerLibraryMaker_h
00011 #define CastorShowerLibraryMaker_h
00012
00013 #include "SimG4Core/Notification/interface/BeginOfJob.h"
00014 #include "SimG4Core/Notification/interface/BeginOfRun.h"
00015 #include "SimG4Core/Notification/interface/EndOfRun.h"
00016 #include "SimG4Core/Notification/interface/BeginOfEvent.h"
00017 #include "SimG4Core/Notification/interface/EndOfEvent.h"
00018
00019 #include "SimG4CMS/Calo/interface/CaloG4HitCollection.h"
00020
00021 #include "G4RunManager.hh"
00022 #include "G4SDManager.hh"
00023 #include "G4Step.hh"
00024 #include "G4Track.hh"
00025 #include "G4Event.hh"
00026 #include "G4PrimaryVertex.hh"
00027 #include "G4VProcess.hh"
00028 #include "G4HCofThisEvent.hh"
00029 #include "G4UserEventAction.hh"
00030 #include "CLHEP/Units/SystemOfUnits.h"
00031 #include "CLHEP/Units/PhysicalConstants.h"
00032
00033 #include "SimG4Core/Notification/interface/Observer.h"
00034 #include "SimG4Core/Watcher/interface/SimWatcher.h"
00035
00036 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00037 #include "FWCore/ServiceRegistry/interface/Service.h"
00038 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00039
00040
00041 #include "SimDataFormats/CaloHit/interface/CastorShowerLibraryInfo.h"
00042 #include "SimDataFormats/CaloHit/interface/CastorShowerEvent.h"
00043
00044 #include <cassert>
00045 #include <iostream>
00046 #include <string>
00047 #include <map>
00048 #include <set>
00049 #include <cmath>
00050 #include <memory>
00051 #include <vector>
00052
00053 #include <CLHEP/Random/Randomize.h>
00054
00055 #include "TROOT.h"
00056 #include "TFile.h"
00057 #include "TH1.h"
00058 #include "TH2.h"
00059 #include "TProfile.h"
00060 #include "TNtuple.h"
00061 #include "TRandom.h"
00062 #include "TLorentzVector.h"
00063 #include "TUnixSystem.h"
00064 #include "TSystem.h"
00065 #include "TMath.h"
00066 #include "TF1.h"
00067
00068
00069 class G4Step;
00070 class BeginOfJob;
00071 class BeginOfRun;
00072 class EndOfRun;
00073 class BeginOfEvent;
00074 class EndOfEvent;
00075
00076
00077
00078
00079
00080
00081 typedef std::vector<std::vector<std::vector<std::vector<CastorShowerEvent> > > > SLBin3D;
00082
00083 class CastorShowerLibraryMaker : public SimWatcher,
00084 public Observer<const BeginOfJob *>,
00085 public Observer<const BeginOfRun *>,
00086 public Observer<const EndOfRun *>,
00087 public Observer<const BeginOfEvent *>,
00088 public Observer<const EndOfEvent *>,
00089 public Observer<const G4Step *> {
00090
00091 public:
00092
00093 CastorShowerLibraryMaker(const edm::ParameterSet &p);
00094 virtual ~CastorShowerLibraryMaker();
00095
00096 private:
00097 typedef int ebin;
00098 typedef int etabin;
00099 typedef int phibin;
00100
00101 struct ShowerLib {
00102 CastorShowerLibraryInfo SLInfo;
00103 SLBin3D SLCollection;
00104 std::vector<double> SLEnergyBins;
00105 std::vector<double> SLEtaBins;
00106 std::vector<double> SLPhiBins;
00107 unsigned int nEvtPerBinE;
00108 unsigned int nEvtPerBinEta;
00109 unsigned int nEvtPerBinPhi;
00110 std::vector<int> nEvtInBinE;
00111 std::vector<std::vector<int> > nEvtInBinEta;
00112 std::vector<std::vector<std::vector<int> > > nEvtInBinPhi;
00113 };
00114
00115
00116 void update(const BeginOfJob * run);
00117 void update(const BeginOfRun * run);
00118 void update(const EndOfRun * run);
00119 void update(const BeginOfEvent * evt);
00120 void update(const EndOfEvent * evt);
00121 void update(const G4Step * step);
00122
00123 private:
00124
00125 void Finish();
00126
00127
00128 int verbosity;
00129 std::string eventNtFileName;
00130
00131 unsigned int NPGParticle;
00132 std::vector<int> PGParticleIDs;
00133 bool DoHadSL;
00134 bool DoEmSL;
00135 bool InsideCastor;
00136 bool DeActivatePhysicsProcess;
00137 std::vector<G4PrimaryParticle*> thePrims;
00138
00139
00140 CastorShowerLibraryInfo *emInfo;
00141 CastorShowerLibraryInfo *hadInfo;
00142 CastorShowerEvent *emShower;
00143 CastorShowerEvent *hadShower;
00144 ShowerLib emSLHolder;
00145 ShowerLib hadSLHolder;
00146 ShowerLib* SLShowerptr;
00147 std::map<int,std::set<int> > MapOfSecondaries;
00148
00149
00150 std::map<int,G4ThreeVector> PrimaryMomentum;
00151 std::map<int,G4ThreeVector> PrimaryPosition;
00152 double MaxEta;
00153 double MaxPhi;
00154
00155 int FindEnergyBin(double e);
00156 int FindEtaBin(double eta);
00157 int FindPhiBin(double phi);
00158 bool SLacceptEvent(int, int, int);
00159 bool IsSLReady();
00160 void GetKinematics(G4PrimaryParticle* ,
00161 double& px, double& py, double& pz, double& pInit, double& eta, double& phi);
00162 void GetKinematics(int ,
00163 double& px, double& py, double& pz, double& pInit, double& eta, double& phi);
00164
00165 std::vector<G4PrimaryParticle*> GetPrimary(const G4Event * );
00166 bool FillShowerEvent(CaloG4HitCollection* ,CastorShowerEvent*, int);
00167 void InitSLHolder(ShowerLib& );
00168
00169 void printSLstatus(int , int, int);
00170 int& SLnEvtInBinE(int ebin);
00171 int& SLnEvtInBinEta(int ebin, int etabin);
00172 int& SLnEvtInBinPhi(int ebin, int etabin, int phibin);
00173 bool SLisEBinFilled(int ebin);
00174 bool SLisEtaBinFilled(int ebin, int etabin);
00175 bool SLisPhiBinFilled(int ebin, int etabin, int phibin);
00176 void KillSecondaries(const G4Step * step);
00177 void GetMissingEnergy(CaloG4HitCollection* ,double& ,double& );
00178
00179
00180 TFile* theFile;
00181 TTree* theTree;
00182
00183 int eventIndex;
00184 int stepIndex;
00185
00186 };
00187
00188 #endif // CastorShowerLibraryMaker_h