CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/SimG4CMS/ShowerLibraryProducer/interface/CastorShowerLibraryMaker.h

Go to the documentation of this file.
00001 
00002 //
00003 // File: CastorShowerLibraryMaker.h
00004 // Date: 02/2009 
00005 // Author: Wagner Carvalho (adapted from Panos Katsas code)
00006 // Description: simulation analysis steering code 
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 "G4RunManager.hh"
00020 #include "G4SDManager.hh"
00021 #include "G4Step.hh"
00022 #include "G4Track.hh"
00023 #include "G4Event.hh"
00024 #include "G4PrimaryVertex.hh"
00025 #include "G4VProcess.hh"
00026 #include "G4HCofThisEvent.hh"
00027 #include "G4UserEventAction.hh"
00028 #include "CLHEP/Units/SystemOfUnits.h"
00029 #include "CLHEP/Units/PhysicalConstants.h"
00030 
00031 #include "SimG4Core/Notification/interface/Observer.h"
00032 #include "SimG4Core/Watcher/interface/SimWatcher.h"
00033 
00034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00035 #include "FWCore/ServiceRegistry/interface/Service.h"
00036 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00037 
00038 // Classes for shower library Root file
00039 #include "SimDataFormats/CaloHit/interface/CastorShowerLibraryInfo.h"
00040 #include "SimDataFormats/CaloHit/interface/CastorShowerEvent.h"
00041 
00042 #include <cassert>
00043 #include <iostream>
00044 #include <string>
00045 #include <map>
00046 #include <set>
00047 #include <cmath>
00048 #include <memory>
00049 #include <vector>
00050 
00051 #include <CLHEP/Random/Randomize.h> 
00052 
00053 #include "TROOT.h"
00054 #include "TFile.h"
00055 #include "TH1.h"
00056 #include "TH2.h"
00057 #include "TProfile.h"
00058 #include "TNtuple.h"
00059 #include "TRandom.h"
00060 #include "TLorentzVector.h"
00061 #include "TUnixSystem.h"
00062 #include "TSystem.h"
00063 #include "TMath.h"
00064 #include "TF1.h"
00065 
00066 
00067 class G4Step;
00068 class BeginOfJob;
00069 class BeginOfRun;
00070 class EndOfRun;
00071 class BeginOfEvent;
00072 class EndOfEvent;
00073 
00074 /*
00075 typedef std::vector<std::vector<CastorShowerEvent> > phi_t; //holds N phi bin collection (with M events each)
00076 typedef std::vector<phi_t>                           eta_t; //holds N eta bin collection  
00077 typedef std::vector<eta_t>                           energy_t; //holds N energy bin
00078 */
00079 typedef std::vector<std::vector<std::vector<std::vector<CastorShowerEvent> > > > SLBin3D; // bin in energy, eta and phi
00080 
00081 class CastorShowerLibraryMaker : public SimWatcher,
00082                         public Observer<const BeginOfJob *>, 
00083                         public Observer<const BeginOfRun *>,
00084                         public Observer<const EndOfRun *>,
00085                         public Observer<const BeginOfEvent *>, 
00086                         public Observer<const EndOfEvent *>, 
00087                         public Observer<const G4Step *> {
00088   
00089 public:
00090 
00091   CastorShowerLibraryMaker(const edm::ParameterSet &p);
00092   virtual ~CastorShowerLibraryMaker();
00093 
00094 private:
00095   typedef int ebin;
00096   typedef int etabin;
00097   typedef int phibin;
00098 // private structures
00099   struct ShowerLib {
00100          CastorShowerLibraryInfo SLInfo; // the info
00101          SLBin3D                 SLCollection; // the showers
00102          std::vector<double>     SLEnergyBins;
00103          std::vector<double>     SLEtaBins;
00104          std::vector<double>     SLPhiBins;
00105          unsigned int            nEvtPerBinE;
00106          unsigned int            nEvtPerBinEta;
00107          unsigned int            nEvtPerBinPhi;
00108          std::vector<int>                             nEvtInBinE;
00109          std::vector<std::vector<int> >               nEvtInBinEta;
00110          std::vector<std::vector<std::vector<int> > > nEvtInBinPhi;
00111   }; 
00112 
00113   // observer classes
00114   void update(const BeginOfJob * run);
00115   void update(const BeginOfRun * run);
00116   void update(const EndOfRun * run);
00117   void update(const BeginOfEvent * evt);
00118   void update(const EndOfEvent * evt);
00119   void update(const G4Step * step);
00120 
00121 private:
00122 
00123   void   Finish();
00124 
00125   // Job general parameters
00126   int verbosity;
00127   std::string eventNtFileName;
00128   
00129   unsigned int NPGParticle; // number of particles requested to Particle Gun
00130   std::vector<int> PGParticleIDs; //p. gun particle IDs
00131   bool DoHadSL; // true if hadronic SL should be produced
00132   bool DoEmSL;  // true if electromag. SL should be produced
00133   
00134   // Pointers for user defined class objects to be stored to Root file
00135   CastorShowerLibraryInfo   *emInfo;
00136   CastorShowerLibraryInfo   *hadInfo;
00137   CastorShowerEvent     *emShower;
00138   CastorShowerEvent    *hadShower;
00139   ShowerLib            emSLHolder;
00140   ShowerLib            hadSLHolder;
00141   ShowerLib*           SLShowerptr; // pointer to the current shower collection (above)
00142   std::map<int,std::set<int> > MapOfSecondaries; // map to hold all secondaries ID keyed by
00143                                                  // the PDG code of the primary
00144 
00145 // private methods
00146   int FindEnergyBin(double e);
00147   int FindEtaBin(double eta);
00148   int FindPhiBin(double phi);
00149   bool SLacceptEvent(int, int, int);
00150   bool IsSLReady();
00151   void GetKinematics(G4PrimaryParticle* ,
00152        double& px, double& py, double& pz, double& pInit, double& eta, double& phi);
00153 
00154   std::vector<G4PrimaryParticle*>  GetPrimary(const EndOfEvent * );
00155   bool FillShowerEvent(G4HCofThisEvent* ,CastorShowerEvent*, int);
00156   void InitSLHolder(ShowerLib& );
00157 
00158   void printSLstatus(int , int, int);
00159   int& SLnEvtInBinE(int ebin);
00160   int& SLnEvtInBinEta(int ebin, int etabin);
00161   int& SLnEvtInBinPhi(int ebin, int etabin, int phibin);
00162   bool         SLisEBinFilled(int ebin);
00163   bool         SLisEtaBinFilled(int ebin, int etabin);
00164   bool         SLisPhiBinFilled(int ebin, int etabin, int phibin);
00165 
00166   // Root pointers
00167   TFile* theFile;
00168   TTree* theTree;
00169 
00170   int eventIndex;
00171   int stepIndex;   // ignore, please
00172 
00173 };
00174 
00175 #endif // CastorShowerLibraryMaker_h