diff --git a/SimG4CMS/ShowerLibraryProducer/interface/CastorShowerLibraryMaker.h b/SimG4CMS/ShowerLibraryProducer/interface/CastorShowerLibraryMaker.h deleted file mode 100644 index 39b064d4b9058..0000000000000 --- a/SimG4CMS/ShowerLibraryProducer/interface/CastorShowerLibraryMaker.h +++ /dev/null @@ -1,181 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// -// File: CastorShowerLibraryMaker.h -// Date: 02/2009 -// Author: Wagner Carvalho (adapted from Panos Katsas code) -// Description: simulation analysis steering code -// -/////////////////////////////////////////////////////////////////////////////// -#undef debug -#ifndef CastorShowerLibraryMaker_h -#define CastorShowerLibraryMaker_h - -#include "SimG4Core/Notification/interface/BeginOfJob.h" -#include "SimG4Core/Notification/interface/BeginOfRun.h" -#include "SimG4Core/Notification/interface/EndOfRun.h" -#include "SimG4Core/Notification/interface/BeginOfEvent.h" -#include "SimG4Core/Notification/interface/EndOfEvent.h" - -#include "SimG4CMS/Calo/interface/CaloG4HitCollection.h" - -#include "G4RunManager.hh" -#include "G4SDManager.hh" -#include "G4Step.hh" -#include "G4Track.hh" -#include "G4Event.hh" -#include "G4PrimaryVertex.hh" -#include "G4VProcess.hh" -#include "G4HCofThisEvent.hh" -#include "G4UserEventAction.hh" -#include "CLHEP/Units/SystemOfUnits.h" -#include "CLHEP/Units/PhysicalConstants.h" - -#include "SimG4Core/Notification/interface/Observer.h" -#include "SimG4Core/Watcher/interface/SimWatcher.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/ServiceRegistry/interface/Service.h" -#include "CommonTools/UtilAlgos/interface/TFileService.h" - -// Classes for shower library Root file -#include "SimDataFormats/CaloHit/interface/CastorShowerLibraryInfo.h" -#include "SimDataFormats/CaloHit/interface/CastorShowerEvent.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "TROOT.h" -#include "TFile.h" -#include "TH1.h" -#include "TH2.h" -#include "TProfile.h" -#include "TNtuple.h" -#include "TRandom.h" -#include "TLorentzVector.h" -#include "TUnixSystem.h" -#include "TSystem.h" -#include "TMath.h" -#include "TF1.h" - -class G4Step; -class BeginOfJob; -class BeginOfRun; -class EndOfRun; -class BeginOfEvent; -class EndOfEvent; - -/* -typedef std::vector > phi_t; //holds N phi bin collection (with M events each) -typedef std::vector eta_t; //holds N eta bin collection -typedef std::vector energy_t; //holds N energy bin -*/ -typedef std::vector > > > SLBin3D; // bin in energy, eta and phi - -class CastorShowerLibraryMaker : public SimWatcher, - public Observer, - public Observer, - public Observer, - public Observer, - public Observer, - public Observer { -public: - CastorShowerLibraryMaker(const edm::ParameterSet& p); - ~CastorShowerLibraryMaker() override; - -private: - typedef int ebin; - typedef int etabin; - typedef int phibin; - // private structures - struct ShowerLib { - CastorShowerLibraryInfo SLInfo; // the info - SLBin3D SLCollection; // the showers - std::vector SLEnergyBins; - std::vector SLEtaBins; - std::vector SLPhiBins; - unsigned int nEvtPerBinE; - unsigned int nEvtPerBinEta; - unsigned int nEvtPerBinPhi; - std::vector nEvtInBinE; - std::vector > nEvtInBinEta; - std::vector > > nEvtInBinPhi; - }; - - // observer classes - void update(const BeginOfJob* run) override; - void update(const BeginOfRun* run) override; - void update(const EndOfRun* run) override; - void update(const BeginOfEvent* evt) override; - void update(const EndOfEvent* evt) override; - void update(const G4Step* step) override; - -private: - void Finish(); - - // Job general parameters - int verbosity; - std::string eventNtFileName; - - unsigned int NPGParticle; // number of particles requested to Particle Gun - std::vector PGParticleIDs; //p. gun particle IDs - bool DoHadSL; // true if hadronic SL should be produced - bool DoEmSL; // true if electromag. SL should be produced - bool InsideCastor; // true if particle step inside CASTOR - bool DeActivatePhysicsProcess; //cfg parameter: True if phys. proc. should be off from IP to Castor - std::vector thePrims; // list of primaries for this event - - // Pointers for user defined class objects to be stored to Root file - CastorShowerLibraryInfo* emInfo; - CastorShowerLibraryInfo* hadInfo; - CastorShowerEvent* emShower; - CastorShowerEvent* hadShower; - ShowerLib emSLHolder; - ShowerLib hadSLHolder; - ShowerLib* SLShowerptr; // pointer to the current shower collection (above) - std::map > MapOfSecondaries; // map to hold all secondaries ID keyed by - // the PDG code of the primary - - std::map PrimaryMomentum; - std::map PrimaryPosition; - double MaxEta; // limits the eta region, the lower limit is given by the SL bins - double MaxPhi; // limits the phi region, the lower limit is given by the SL bins - // private methods - int FindEnergyBin(double e); - int FindEtaBin(double eta); - int FindPhiBin(double phi); - bool SLacceptEvent(int, int, int); - bool IsSLReady(); - void GetKinematics(G4PrimaryParticle*, double& px, double& py, double& pz, double& pInit, double& eta, double& phi); - void GetKinematics(int, double& px, double& py, double& pz, double& pInit, double& eta, double& phi); - - std::vector GetPrimary(const G4Event*); - bool FillShowerEvent(CaloG4HitCollection*, CastorShowerEvent*, int); - void InitSLHolder(ShowerLib&); - - void printSLstatus(int, int, int); - int& SLnEvtInBinE(int ebin); - int& SLnEvtInBinEta(int ebin, int etabin); - int& SLnEvtInBinPhi(int ebin, int etabin, int phibin); - bool SLisEBinFilled(int ebin); - bool SLisEtaBinFilled(int ebin, int etabin); - bool SLisPhiBinFilled(int ebin, int etabin, int phibin); - void KillSecondaries(const G4Step* step); - void GetMissingEnergy(CaloG4HitCollection*, double&, double&); - - // Root pointers - TFile* theFile; - TTree* theTree; - - int eventIndex; - int stepIndex; // ignore, please -}; - -#endif // CastorShowerLibraryMaker_h diff --git a/SimG4CMS/ShowerLibraryProducer/interface/HcalForwardAnalysis.h b/SimG4CMS/ShowerLibraryProducer/interface/HcalForwardAnalysis.h deleted file mode 100644 index 5923dddb7cf94..0000000000000 --- a/SimG4CMS/ShowerLibraryProducer/interface/HcalForwardAnalysis.h +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef ShowerLibraryProducer_HcalForwardAnalysis_h -#define ShowerLibraryProducer_HcalForwardAnalysis_h - -#include -#include -#include -#include - -// user include files -#include "SimG4Core/Watcher/interface/SimProducer.h" -#include "SimG4Core/Notification/interface/Observer.h" - -#include "SimG4CMS/ShowerLibraryProducer/interface/FiberG4Hit.h" -#include "SimG4CMS/ShowerLibraryProducer/interface/HFShowerG4Hit.h" - -#include "FWCore/ServiceRegistry/interface/Service.h" -#include "CommonTools/UtilAlgos/interface/TFileService.h" - -#include "G4Step.hh" -#include "G4Track.hh" -#include "G4ThreeVector.hh" - -#include "TFile.h" -#include "TTree.h" - -#include -#include - -class BeginOfRun; -class BeginOfEvent; -class EndOfEvent; - -class HcalForwardAnalysis : public SimProducer, - public Observer, - public Observer, - public Observer, - public Observer { -public: - struct Photon { - Photon(int id, float X, float Y, float Z, float T, float Lambda) - : fiberId(id), x(X), y(Y), z(Z), t(T), lambda(Lambda) {} - int fiberId; - float x; - float y; - float z; - float t; - float lambda; - }; - - HcalForwardAnalysis(const edm::ParameterSet& p); - HcalForwardAnalysis(const HcalForwardAnalysis&) = delete; // stop default - const HcalForwardAnalysis& operator=(const HcalForwardAnalysis&) = delete; - ~HcalForwardAnalysis() override; - - void produce(edm::Event&, const edm::EventSetup&) override; - -private: - void init(); - - // observer methods - void update(const BeginOfRun* run) override; - void update(const BeginOfEvent* evt) override; - void update(const G4Step* step) override; - void update(const EndOfEvent* evt) override; - // void write(const EndOfRun * run); - - //User methods - void setPhotons(const EndOfEvent* evt); - //void fillEvent(PHcalForwardLibInfo&); - void fillEvent(); - void parseDetId(int id, int& tower, int& cell, int& fiber); - void clear(); - - edm::Service theFile; - TTree* theTree; - int theEventCounter; - int count; - int evNum; - float x[10000], y[10000], z[10000], t[10000], lambda[10000]; - float primX, primY, primZ, primT; - float primMomX, primMomY, primMomZ; - int nphot; - int fiberId[10000]; - std::vector thePhotons; - std::vector theNames; - bool fillt; -}; -#endif diff --git a/SimG4CMS/ShowerLibraryProducer/src/CastorShowerLibraryMaker.cc b/SimG4CMS/ShowerLibraryProducer/plugins/CastorShowerLibraryMaker.cc similarity index 80% rename from SimG4CMS/ShowerLibraryProducer/src/CastorShowerLibraryMaker.cc rename to SimG4CMS/ShowerLibraryProducer/plugins/CastorShowerLibraryMaker.cc index 3c5229d594ab6..100a94aa362f8 100644 --- a/SimG4CMS/ShowerLibraryProducer/src/CastorShowerLibraryMaker.cc +++ b/SimG4CMS/ShowerLibraryProducer/plugins/CastorShowerLibraryMaker.cc @@ -12,28 +12,174 @@ // Adapted by W. Carvalho , 02/2009 // ////////////////////////////////////////////////////////////// + +#include "CommonTools/UtilAlgos/interface/TFileService.h" +#include "DataFormats/Math/interface/Point3D.h" + #include "FWCore/Utilities/interface/EDMException.h" #include "FWCore/Utilities/interface/Exception.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ServiceRegistry/interface/Service.h" + +// Classes for shower library Root file +#include "SimDataFormats/CaloHit/interface/CastorShowerLibraryInfo.h" +#include "SimDataFormats/CaloHit/interface/CastorShowerEvent.h" + #include "SimG4Core/Notification/interface/SimG4Exception.h" +#include "SimG4Core/Notification/interface/BeginOfJob.h" +#include "SimG4Core/Notification/interface/BeginOfRun.h" +#include "SimG4Core/Notification/interface/EndOfRun.h" +#include "SimG4Core/Notification/interface/BeginOfEvent.h" +#include "SimG4Core/Notification/interface/EndOfEvent.h" +#include "SimG4Core/Notification/interface/Observer.h" +#include "SimG4Core/Watcher/interface/SimWatcher.h" + #include "SimG4CMS/Calo/interface/CaloG4Hit.h" #include "SimG4CMS/Calo/interface/CaloG4HitCollection.h" -#include "DataFormats/Math/interface/Point3D.h" -#include "SimG4CMS/ShowerLibraryProducer/interface/CastorShowerLibraryMaker.h" #include "SimG4CMS/Forward/interface/CastorNumberingScheme.h" -#include "SimDataFormats/CaloHit/interface/CastorShowerEvent.h" +#include "G4RunManager.hh" +#include "G4SDManager.hh" +#include "G4Step.hh" +#include "G4Track.hh" +#include "G4Event.hh" +#include "G4PrimaryVertex.hh" +#include "G4VProcess.hh" +#include "G4HCofThisEvent.hh" +#include "G4UserEventAction.hh" +#include "CLHEP/Random/Randomize.h" +#include "CLHEP/Units/SystemOfUnits.h" +#include "CLHEP/Units/PhysicalConstants.h" #include "CLHEP/Units/GlobalSystemOfUnits.h" #include "CLHEP/Units/GlobalPhysicalConstants.h" +#include "TROOT.h" #include "TFile.h" +#include "TH1.h" +#include "TH2.h" +#include "TProfile.h" +#include "TNtuple.h" +#include "TRandom.h" +#include "TLorentzVector.h" +#include "TUnixSystem.h" +#include "TSystem.h" +#include "TMath.h" +#include "TF1.h" + +#include #include +#include +#include #include +#include +#include #include -#include -#include +#include +#include + +typedef std::vector > > > SLBin3D; // bin in energy, eta and phi + +class CastorShowerLibraryMaker : public SimWatcher, + public Observer, + public Observer, + public Observer, + public Observer, + public Observer, + public Observer { +public: + CastorShowerLibraryMaker(const edm::ParameterSet& p); + ~CastorShowerLibraryMaker() override; + +private: + typedef int ebin; + typedef int etabin; + typedef int phibin; + // private structures + struct ShowerLib { + CastorShowerLibraryInfo SLInfo; // the info + SLBin3D SLCollection; // the showers + std::vector SLEnergyBins; + std::vector SLEtaBins; + std::vector SLPhiBins; + unsigned int nEvtPerBinE; + unsigned int nEvtPerBinEta; + unsigned int nEvtPerBinPhi; + std::vector nEvtInBinE; + std::vector > nEvtInBinEta; + std::vector > > nEvtInBinPhi; + }; + + // observer classes + void update(const BeginOfJob* run) override; + void update(const BeginOfRun* run) override; + void update(const EndOfRun* run) override; + void update(const BeginOfEvent* evt) override; + void update(const EndOfEvent* evt) override; + void update(const G4Step* step) override; + +private: + void Finish(); + + // Job general parameters + int verbosity; + std::string eventNtFileName; + + unsigned int NPGParticle; // number of particles requested to Particle Gun + std::vector PGParticleIDs; //p. gun particle IDs + bool DoHadSL; // true if hadronic SL should be produced + bool DoEmSL; // true if electromag. SL should be produced + bool InsideCastor; // true if particle step inside CASTOR + bool DeActivatePhysicsProcess; //cfg parameter: True if phys. proc. should be off from IP to Castor + std::vector thePrims; // list of primaries for this event + + // Pointers for user defined class objects to be stored to Root file + CastorShowerLibraryInfo* emInfo; + CastorShowerLibraryInfo* hadInfo; + CastorShowerEvent* emShower; + CastorShowerEvent* hadShower; + ShowerLib emSLHolder; + ShowerLib hadSLHolder; + ShowerLib* SLShowerptr; // pointer to the current shower collection (above) + std::map > MapOfSecondaries; // map to hold all secondaries ID keyed by + // the PDG code of the primary + + std::map PrimaryMomentum; + std::map PrimaryPosition; + double MaxEta; // limits the eta region, the lower limit is given by the SL bins + double MaxPhi; // limits the phi region, the lower limit is given by the SL bins + // private methods + int FindEnergyBin(double e); + int FindEtaBin(double eta); + int FindPhiBin(double phi); + bool SLacceptEvent(int, int, int); + bool IsSLReady(); + void GetKinematics(G4PrimaryParticle*, double& px, double& py, double& pz, double& pInit, double& eta, double& phi); + void GetKinematics(int, double& px, double& py, double& pz, double& pInit, double& eta, double& phi); + + std::vector GetPrimary(const G4Event*); + bool FillShowerEvent(CaloG4HitCollection*, CastorShowerEvent*, int); + void InitSLHolder(ShowerLib&); + + void printSLstatus(int, int, int); + int& SLnEvtInBinE(int ebin); + int& SLnEvtInBinEta(int ebin, int etabin); + int& SLnEvtInBinPhi(int ebin, int etabin, int phibin); + bool SLisEBinFilled(int ebin); + bool SLisEtaBinFilled(int ebin, int etabin); + bool SLisPhiBinFilled(int ebin, int etabin, int phibin); + void KillSecondaries(const G4Step* step); + void GetMissingEnergy(CaloG4HitCollection*, double&, double&); + + // Root pointers + TFile* theFile; + TTree* theTree; + + int eventIndex; + int stepIndex; // ignore, please +}; CastorShowerLibraryMaker::CastorShowerLibraryMaker(const edm::ParameterSet& p) : NPGParticle(0), @@ -210,10 +356,10 @@ void CastorShowerLibraryMaker::update(const BeginOfRun* run) { // If no data are written, because e.g. the branch is disabled, // the number of bytes returned is 0. // if(flag==-1) { - // edm::LogInfo("CastorAnalyzer") << " WARNING: Error writing to Branch \"CastorShowerLibInfo\" \n" ; + // edm::LogVerbatim("CastorAnalyzer") << " WARNING: Error writing to Branch \"CastorShowerLibInfo\" \n" ; // } else // if(flag==0) { - // edm::LogInfo("CastorAnalyzer") << " WARNING: No data written to Branch \"CastorShowerLibInfo\" \n" ; + // edm::LogVerbatim("CastorAnalyzer") << " WARNING: No data written to Branch \"CastorShowerLibInfo\" \n" ; // } // Initialize "accounting" variables @@ -287,7 +433,7 @@ void CastorShowerLibraryMaker::update(const BeginOfEvent* evt) { } */ if (!accept) - edm::LogInfo("CastorShowerLibraryMaker") + edm::LogVerbatim("CastorShowerLibraryMaker") << "Event not accepted for ebin=" << ebin << ",etabin=" << etabin << ",phibin=" << phibin << std::endl; } else { accept = true; @@ -401,7 +547,7 @@ void CastorShowerLibraryMaker::update(const G4Step* aStep) { */ /* if(aStep->IsFirstStepInVolume()) { - edm::LogInfo("CastorShowerLibraryMaker") << "CastorShowerLibraryMaker::update(const G4Step * aStep):" + edm::LogVerbatim("CastorShowerLibraryMaker") << "CastorShowerLibraryMaker::update(const G4Step * aStep):" << "\n IsFirstStepInVolume , " << "time = " << aStep->GetTrack()->GetGlobalTime() ; } @@ -428,7 +574,7 @@ void CastorShowerLibraryMaker::update(const EndOfEvent* evt) { std::cout << "CastorShowerLibraryMaker: End of Event: " << eventIndex << std::endl; // Get the pointer to the primary particle if (thePrims.empty()) { - edm::LogInfo("CastorShowerLibraryMaker") << "No valid primary particle found. Skipping event" << std::endl; + edm::LogVerbatim("CastorShowerLibraryMaker") << "No valid primary particle found. Skipping event" << std::endl; return; } // access to the G4 hit collections @@ -436,10 +582,10 @@ void CastorShowerLibraryMaker::update(const EndOfEvent* evt) { int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID("CastorFI"); CaloG4HitCollection* theCAFI = (CaloG4HitCollection*)allHC->GetHC(CAFIid); if (verbosity) - edm::LogInfo("CastorShowerLibraryMaker") << " update(*evt) --> accessed all HC "; - edm::LogInfo("CastorShowerLibraryMaker") << "Found " << theCAFI->entries() << " hits in G4HitCollection"; + edm::LogVerbatim("CastorShowerLibraryMaker") << " update(*evt) --> accessed all HC "; + edm::LogVerbatim("CastorShowerLibraryMaker") << "Found " << theCAFI->entries() << " hits in G4HitCollection"; if (theCAFI->entries() == 0) { - edm::LogInfo("CastorShowerLibraryMaker") << "\n Empty G4HitCollection"; + edm::LogVerbatim("CastorShowerLibraryMaker") << "\n Empty G4HitCollection"; return; } @@ -449,7 +595,7 @@ void CastorShowerLibraryMaker::update(const EndOfEvent* evt) { for (unsigned int i = 0; i < thePrims.size(); i++) { G4PrimaryParticle* thePrim = thePrims.at(i); if (!thePrim) { - edm::LogInfo("CastorShowerLibraryMaker") << "nullptr Pointer to the primary" << std::endl; + edm::LogVerbatim("CastorShowerLibraryMaker") << "nullptr Pointer to the primary" << std::endl; continue; } // Check primary particle type @@ -464,7 +610,7 @@ void CastorShowerLibraryMaker::update(const EndOfEvent* evt) { SLShowerptr = &hadSLHolder; SLType = "Hadronic"; } - edm::LogInfo("CastorShowerLibraryMaker") << "\n Primary (thePrim) trackID is " << thePrim->GetTrackID() << "\n"; + edm::LogVerbatim("CastorShowerLibraryMaker") << "\n Primary (thePrim) trackID is " << thePrim->GetTrackID() << "\n"; // Obtain primary particle's initial momentum (pInit) double px = 0., py = 0., pz = 0., pInit = 0., eta = 0., phi = 0.; @@ -472,7 +618,7 @@ void CastorShowerLibraryMaker::update(const EndOfEvent* evt) { // Check if current event falls into any bin // first: energy if (pInit == 0) { - edm::LogInfo("CastorShowerLibraryMaker") << "Primary did not hit CASTOR" << std::endl; + edm::LogVerbatim("CastorShowerLibraryMaker") << "Primary did not hit CASTOR" << std::endl; continue; } int ebin = FindEnergyBin(pInit); @@ -481,7 +627,7 @@ void CastorShowerLibraryMaker::update(const EndOfEvent* evt) { std::cout << SLType << std::endl; printSLstatus(ebin, etabin, phibin); if (!SLacceptEvent(ebin, etabin, phibin)) { - edm::LogInfo("CastorShowerLibraryMaker") + edm::LogVerbatim("CastorShowerLibraryMaker") << "Event not accepted for ebin=" << ebin << ",etabin=" << etabin << ",phibin=" << phibin << "(" << pInit << "," << eta << "," << phi << ")" << std::endl; continue; @@ -490,7 +636,7 @@ void CastorShowerLibraryMaker::update(const EndOfEvent* evt) { // event passed. Fill the vector accordingly // // Look for the Hit Collection - edm::LogInfo("CastorShowerLibraryMaker") + edm::LogVerbatim("CastorShowerLibraryMaker") << "\n CastorShowerLibraryMaker::update(EndOfEvent * evt) - event #" << (*evt)()->GetEventID(); /* @@ -507,7 +653,7 @@ void CastorShowerLibraryMaker::update(const EndOfEvent* evt) { if (FillShowerEvent(theCAFI, shower, particleType)) { // Primary particle information /* - edm::LogInfo("CastorShowerLibraryMaker") << "New SL event: Primary = " << particleType + edm::LogVerbatim("CastorShowerLibraryMaker") << "New SL event: Primary = " << particleType << "; Energy = " << pInit << "; Eta = " << eta << "; Phi = " << phi << "; Nhits = " << shower->getNhit() << std::endl; */ @@ -651,7 +797,7 @@ int CastorShowerLibraryMaker::FindEnergyBin(double energy) { // returns -1 if ouside valid range // if (!SLShowerptr) { - edm::LogInfo("CastorShowerLibraryMaker") << "\n\nFindEnergyBin can be called only after BeginOfEvent\n\n"; + edm::LogVerbatim("CastorShowerLibraryMaker") << "\n\nFindEnergyBin can be called only after BeginOfEvent\n\n"; throw SimG4Exception("\n\nnullptr Pointer to the shower library.\n\n"); } const std::vector& SLenergies = SLShowerptr->SLEnergyBins; @@ -675,7 +821,7 @@ int CastorShowerLibraryMaker::FindEtaBin(double eta) { // returns -1 if ouside valid range // if (!SLShowerptr) { - edm::LogInfo("CastorShowerLibraryMaker") << "\n\nFindEtaBin can be called only after BeginOfEvent\n\n"; + edm::LogVerbatim("CastorShowerLibraryMaker") << "\n\nFindEtaBin can be called only after BeginOfEvent\n\n"; throw SimG4Exception("\n\nnullptr Pointer to the shower library.\n\n"); } const std::vector& SLetas = SLShowerptr->SLEtaBins; @@ -699,7 +845,7 @@ int CastorShowerLibraryMaker::FindPhiBin(double phi) { // needs protection in case phi is outside range -pi,pi // if (!SLShowerptr) { - edm::LogInfo("CastorShowerLibraryMaker") << "\n\nFindPhiBin can be called only after BeginOfEvent\n\n"; + edm::LogVerbatim("CastorShowerLibraryMaker") << "\n\nFindPhiBin can be called only after BeginOfEvent\n\n"; throw SimG4Exception("\n\nnullptr Pointer to the shower library.\n\n"); } const std::vector& SLphis = SLShowerptr->SLPhiBins; @@ -718,7 +864,7 @@ int CastorShowerLibraryMaker::FindPhiBin(double phi) { bool CastorShowerLibraryMaker::IsSLReady() { // at this point, the pointer to the shower library should be nullptr if (SLShowerptr) { - edm::LogInfo("CastorShowerLibraryMaker") << "\n\nIsSLReady must be called when a new event starts.\n\n"; + edm::LogVerbatim("CastorShowerLibraryMaker") << "\n\nIsSLReady must be called when a new event starts.\n\n"; throw SimG4Exception("\n\nNOT nullptr Pointer to the shower library.\n\n"); } // it is enough to check if all the energy bin is filled @@ -786,16 +932,17 @@ std::vector CastorShowerLibraryMaker::GetPrimary(const G4Eve std::vector thePrims; G4PrimaryParticle* thePrim = nullptr; G4int nvertex = evt->GetNumberOfPrimaryVertex(); - edm::LogInfo("CastorShowerLibraryMaker") << "Event has " << nvertex << " vertex"; + edm::LogVerbatim("CastorShowerLibraryMaker") << "Event has " << nvertex << " vertex"; if (nvertex != 1) { - edm::LogInfo("CastorShowerLibraryMaker") << "CastorShowerLibraryMaker::GetPrimary ERROR: no vertex"; + edm::LogVerbatim("CastorShowerLibraryMaker") << "CastorShowerLibraryMaker::GetPrimary ERROR: no vertex"; return thePrims; } for (int i = 0; i < nvertex; i++) { G4PrimaryVertex* avertex = evt->GetPrimaryVertex(i); if (avertex == nullptr) { - edm::LogInfo("CastorShowerLibraryMaker") << "CastorShowerLibraryMaker::GetPrimary ERROR: pointer to vertex = 0"; + edm::LogVerbatim("CastorShowerLibraryMaker") + << "CastorShowerLibraryMaker::GetPrimary ERROR: pointer to vertex = 0"; continue; } unsigned int npart = avertex->GetNumberOfParticle(); @@ -818,7 +965,7 @@ std::vector CastorShowerLibraryMaker::GetPrimary(const G4Eve } void CastorShowerLibraryMaker::printSLstatus(int ebin, int etabin, int phibin) { if (!SLShowerptr) { - edm::LogInfo("CastorShowerLibraryInfo") << "nullptr shower pointer. Printing both"; + edm::LogVerbatim("CastorShowerLibraryInfo") << "nullptr shower pointer. Printing both"; std::cout << "Electromagnetic" << std::endl; SLShowerptr = &emSLHolder; this->printSLstatus(ebin, etabin, phibin); @@ -864,7 +1011,7 @@ void CastorShowerLibraryMaker::printSLstatus(int ebin, int etabin, int phibin) { } bool CastorShowerLibraryMaker::SLacceptEvent(int ebin, int etabin, int phibin) { if (SLShowerptr == nullptr) { - edm::LogInfo("CastorShowerLibraryMaker::SLacceptEvent:") << "Error. nullptr pointer to CastorShowerEvent"; + edm::LogVerbatim("CastorShowerLibraryMaker::SLacceptEvent:") << "Error. nullptr pointer to CastorShowerEvent"; return false; } if (ebin < 0 || ebin >= int(SLShowerptr->SLEnergyBins.size())) @@ -898,7 +1045,7 @@ bool CastorShowerLibraryMaker::FillShowerEvent(CaloG4HitCollection* theCAFI, Cas } */ if (!shower) { - edm::LogInfo("CastorShowerLibraryMaker") << "Error. nullptr pointer to CastorShowerEvent"; + edm::LogVerbatim("CastorShowerLibraryMaker") << "Error. nullptr pointer to CastorShowerEvent"; return false; } @@ -913,7 +1060,7 @@ bool CastorShowerLibraryMaker::FillShowerEvent(CaloG4HitCollection* theCAFI, Cas int hit_particleID = aHit->getTrackID(); if (MapOfSecondaries[ipart].find(hit_particleID) == MapOfSecondaries[ipart].end()) { if (verbosity) - edm::LogInfo("CastorShowerLibraryMaker") << "Skipping hit from trackID " << hit_particleID; + edm::LogVerbatim("CastorShowerLibraryMaker") << "Skipping hit from trackID " << hit_particleID; continue; } volumeID = aHit->getUnitID(); @@ -925,15 +1072,15 @@ bool CastorShowerLibraryMaker::FillShowerEvent(CaloG4HitCollection* theCAFI, Cas entry = aHit->getEntry(); position = aHit->getPosition(); if (verbosity) - edm::LogInfo("CastorShowerLibraryMaker") << "\n side , sector , module = " << zside << " , " << sector << " , " - << zmodule << "\n nphotons = " << hitEnergy; + edm::LogVerbatim("CastorShowerLibraryMaker") << "\n side , sector , module = " << zside << " , " << sector + << " , " << zmodule << "\n nphotons = " << hitEnergy; if (verbosity) - edm::LogInfo("CastorShowerLibraryMaker") + edm::LogVerbatim("CastorShowerLibraryMaker") << "\n packIndex = " << theCastorNumScheme->packIndex(zside, sector, zmodule); if (verbosity && time > 100.) { - edm::LogInfo("CastorShowerLibraryMaker") + edm::LogVerbatim("CastorShowerLibraryMaker") << "\n nentries = " << nentries << "\n time[" << ihit << "] = " << time << "\n trackID[" << ihit << "] = " << aHit->getTrackID() << "\n volumeID[" << ihit << "] = " << volumeID << "\n nphotons[" << ihit << "] = " << hitEnergy << "\n side, sector, module = " << zside << ", " << sector << ", " << zmodule @@ -941,7 +1088,7 @@ bool CastorShowerLibraryMaker::FillShowerEvent(CaloG4HitCollection* theCAFI, Cas << "," << entry.y() << "," << entry.z(); } if (verbosity) - edm::LogInfo("CastorShowerLibraryMaker") << "\n Incident Energy = " << aHit->getIncidentEnergy() << " \n"; + edm::LogVerbatim("CastorShowerLibraryMaker") << "\n Incident Energy = " << aHit->getIncidentEnergy() << " \n"; // CaloG4Hit information shower->setDetID(volumeID); @@ -952,7 +1099,8 @@ bool CastorShowerLibraryMaker::FillShowerEvent(CaloG4HitCollection* theCAFI, Cas } // Write number of hits to CastorShowerEvent instance if (nHits == 0) { - edm::LogInfo("CastorShowerLibraryMaker") << "No hits found for this track (trackID=" << ipart << ")." << std::endl; + edm::LogVerbatim("CastorShowerLibraryMaker") + << "No hits found for this track (trackID=" << ipart << ")." << std::endl; if (theCastorNumScheme) delete theCastorNumScheme; return false; @@ -966,7 +1114,7 @@ bool CastorShowerLibraryMaker::FillShowerEvent(CaloG4HitCollection* theCAFI, Cas } int& CastorShowerLibraryMaker::SLnEvtInBinE(int ebin) { if (!SLShowerptr) { - edm::LogInfo("CastorShowerLibraryMaker") << "\n\nSLnEvtInBinE can be called only after BeginOfEvent\n\n"; + edm::LogVerbatim("CastorShowerLibraryMaker") << "\n\nSLnEvtInBinE can be called only after BeginOfEvent\n\n"; throw SimG4Exception("\n\nnullptr Pointer to the shower library."); } return SLShowerptr->nEvtInBinE.at(ebin); @@ -974,7 +1122,7 @@ int& CastorShowerLibraryMaker::SLnEvtInBinE(int ebin) { int& CastorShowerLibraryMaker::SLnEvtInBinEta(int ebin, int etabin) { if (!SLShowerptr) { - edm::LogInfo("CastorShowerLibraryMaker") << "\n\nSLnEvtInBinEta can be called only after BeginOfEvent\n\n"; + edm::LogVerbatim("CastorShowerLibraryMaker") << "\n\nSLnEvtInBinEta can be called only after BeginOfEvent\n\n"; throw SimG4Exception("\n\nnullptr Pointer to the shower library."); } return SLShowerptr->nEvtInBinEta.at(ebin).at(etabin); @@ -982,14 +1130,14 @@ int& CastorShowerLibraryMaker::SLnEvtInBinEta(int ebin, int etabin) { int& CastorShowerLibraryMaker::SLnEvtInBinPhi(int ebin, int etabin, int phibin) { if (!SLShowerptr) { - edm::LogInfo("CastorShowerLibraryMaker") << "\n\nSLnEvtInBinPhi can be called only after BeginOfEvent\n\n"; + edm::LogVerbatim("CastorShowerLibraryMaker") << "\n\nSLnEvtInBinPhi can be called only after BeginOfEvent\n\n"; throw SimG4Exception("\n\nnullptr Pointer to the shower library."); } return SLShowerptr->nEvtInBinPhi.at(ebin).at(etabin).at(phibin); } bool CastorShowerLibraryMaker::SLisEBinFilled(int ebin) { if (!SLShowerptr) { - edm::LogInfo("CastorShowerLibraryMaker") << "\n\nSLisEBinFilled can be called only after BeginOfEvent\n\n"; + edm::LogVerbatim("CastorShowerLibraryMaker") << "\n\nSLisEBinFilled can be called only after BeginOfEvent\n\n"; throw SimG4Exception("\n\nnullptr Pointer to the shower library."); } if (SLShowerptr->nEvtInBinE.at(ebin) < (int)SLShowerptr->nEvtPerBinE) @@ -998,7 +1146,7 @@ bool CastorShowerLibraryMaker::SLisEBinFilled(int ebin) { } bool CastorShowerLibraryMaker::SLisEtaBinFilled(int ebin, int etabin) { if (!SLShowerptr) { - edm::LogInfo("CastorShowerLibraryMaker") << "\n\nSLisEtaBinFilled can be called only after BeginOfEvent\n\n"; + edm::LogVerbatim("CastorShowerLibraryMaker") << "\n\nSLisEtaBinFilled can be called only after BeginOfEvent\n\n"; throw SimG4Exception("\n\nnullptr Pointer to the shower library."); } if (SLShowerptr->nEvtInBinEta.at(ebin).at(etabin) < (int)SLShowerptr->nEvtPerBinEta) @@ -1007,7 +1155,7 @@ bool CastorShowerLibraryMaker::SLisEtaBinFilled(int ebin, int etabin) { } bool CastorShowerLibraryMaker::SLisPhiBinFilled(int ebin, int etabin, int phibin) { if (!SLShowerptr) { - edm::LogInfo("CastorShowerLibraryMaker") << "\n\nSLisPhiBinFilled can be called only after BeginOfEvent\n\n"; + edm::LogVerbatim("CastorShowerLibraryMaker") << "\n\nSLisPhiBinFilled can be called only after BeginOfEvent\n\n"; throw SimG4Exception("\n\nnullptr Pointer to the shower library."); } if (SLShowerptr->nEvtInBinPhi.at(ebin).at(etabin).at(phibin) < (int)SLShowerptr->nEvtPerBinPhi) @@ -1044,3 +1192,8 @@ void CastorShowerLibraryMaker::GetMissingEnergy(CaloG4HitCollection* theCAFI, do } } } + +#include "SimG4Core/Watcher/interface/SimWatcherFactory.h" +#include "FWCore/PluginManager/interface/ModuleDef.h" + +DEFINE_SIMWATCHER(CastorShowerLibraryMaker); diff --git a/SimG4CMS/ShowerLibraryProducer/src/HcalForwardAnalysis.cc b/SimG4CMS/ShowerLibraryProducer/plugins/HcalForwardAnalysis.cc similarity index 78% rename from SimG4CMS/ShowerLibraryProducer/src/HcalForwardAnalysis.cc rename to SimG4CMS/ShowerLibraryProducer/plugins/HcalForwardAnalysis.cc index fbe711ab42025..065576cb74392 100644 --- a/SimG4CMS/ShowerLibraryProducer/src/HcalForwardAnalysis.cc +++ b/SimG4CMS/ShowerLibraryProducer/plugins/HcalForwardAnalysis.cc @@ -2,27 +2,95 @@ #include #include #include +#include +#include // user include files -#include "SimG4CMS/ShowerLibraryProducer/interface/HcalForwardAnalysis.h" - -#include "SimG4Core/Notification/interface/BeginOfRun.h" -#include "SimG4Core/Notification/interface/BeginOfEvent.h" -#include "SimG4Core/Notification/interface/EndOfEvent.h" - #include "DataFormats/Math/interface/Point3D.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/EventSetup.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "SimG4Core/Notification/interface/BeginOfRun.h" +#include "SimG4Core/Notification/interface/BeginOfEvent.h" +#include "SimG4Core/Notification/interface/EndOfEvent.h" +#include "SimG4Core/Watcher/interface/SimProducer.h" +#include "SimG4Core/Notification/interface/Observer.h" + +#include "SimG4CMS/ShowerLibraryProducer/interface/FiberG4Hit.h" +#include "SimG4CMS/ShowerLibraryProducer/interface/HFShowerG4Hit.h" +#include "G4HCofThisEvent.hh" #include "G4SDManager.hh" +#include "G4Step.hh" +#include "G4Track.hh" +#include "G4ThreeVector.hh" #include "G4VProcess.hh" -#include "G4HCofThisEvent.hh" #include "CLHEP/Units/GlobalSystemOfUnits.h" #include "CLHEP/Units/GlobalPhysicalConstants.h" +#include "TFile.h" +#include "TTree.h" + +//#define EDM_ML_DEBUG + +class HcalForwardAnalysis : public SimProducer, + public Observer, + public Observer, + public Observer, + public Observer { +public: + struct Photon { + Photon(int id, float X, float Y, float Z, float T, float Lambda) + : fiberId(id), x(X), y(Y), z(Z), t(T), lambda(Lambda) {} + int fiberId; + float x; + float y; + float z; + float t; + float lambda; + }; + + HcalForwardAnalysis(const edm::ParameterSet& p); + HcalForwardAnalysis(const HcalForwardAnalysis&) = delete; // stop default + const HcalForwardAnalysis& operator=(const HcalForwardAnalysis&) = delete; + ~HcalForwardAnalysis() override; + + void produce(edm::Event&, const edm::EventSetup&) override; + +private: + void init(); + + // observer methods + void update(const BeginOfRun* run) override; + void update(const BeginOfEvent* evt) override; + void update(const G4Step* step) override; + void update(const EndOfEvent* evt) override; + // void write(const EndOfRun * run); + + //User methods + void setPhotons(const EndOfEvent* evt); + //void fillEvent(PHcalForwardLibInfo&); + void fillEvent(); + void parseDetId(int id, int& tower, int& cell, int& fiber); + void clear(); + + edm::Service theFile; + TTree* theTree; + int theEventCounter; + int count; + int evNum; + float x[10000], y[10000], z[10000], t[10000], lambda[10000]; + float primX, primY, primZ, primT; + float primMomX, primMomY, primMomZ; + int nphot; + int fiberId[10000]; + std::vector thePhotons; + std::vector theNames; + bool fillt; +}; + HcalForwardAnalysis::HcalForwardAnalysis(const edm::ParameterSet& p) { edm::ParameterSet m_SLP = p.getParameter("HFShowerLibraryProducer"); theNames = m_SLP.getParameter >("Names"); @@ -85,7 +153,9 @@ void HcalForwardAnalysis::update(const BeginOfRun* run) { void HcalForwardAnalysis::update(const BeginOfEvent* evt) { evNum = (*evt)()->GetEventID(); clear(); +#ifdef EDM_ML_DEBUG edm::LogVerbatim("HcalForwardLib") << "HcalForwardAnalysis: =====> Begin of event = " << evNum; +#endif } void HcalForwardAnalysis::update(const G4Step* aStep) {} @@ -94,7 +164,9 @@ void HcalForwardAnalysis::update(const EndOfEvent* evt) { count++; //fill the buffer +#ifdef EDM_ML_DEBUG edm::LogVerbatim("HcalForwardLib") << "HcalForwardAnalysis::Fill event " << (*evt)()->GetEventID(); +#endif setPhotons(evt); int iEvt = (*evt)()->GetEventID(); @@ -114,6 +186,7 @@ void HcalForwardAnalysis::setPhotons(const EndOfEvent* evt) { FiberG4HitsCollection* theHC; // Look for the Hit Collection of HCal G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent(); +#ifdef EDM_ML_DEBUG edm::LogVerbatim("HcalForwardLib") << "HcalForwardAnalysis:: Has " << allHC->GetNumberOfCollections() << " collections"; for (int k = 0; k < allHC->GetNumberOfCollections(); ++k) { @@ -122,22 +195,29 @@ void HcalForwardAnalysis::setPhotons(const EndOfEvent* evt) { edm::LogVerbatim("HcalForwardLib") << "Collecttion[" << k << "] " << allHC->GetHC(k) << " " << name << ":" << nameSD; } +#endif std::string sdName = theNames[0]; //name for fiber hits idHC = G4SDManager::GetSDMpointer()->GetCollectionID(sdName); theHC = (FiberG4HitsCollection*)allHC->GetHC(idHC); +#ifdef EDM_ML_DEBUG edm::LogVerbatim("HcalForwardLib") << "HcalForwardAnalysis::setPhotons() Hit Collection for " << sdName << " of ID " << idHC << " is obtained at " << theHC; +#endif std::vector ShortFiberPhotons; std::vector LongFiberPhotons; LongFiberPhotons.clear(); ShortFiberPhotons.clear(); if (idHC >= 0 && theHC != nullptr) { int thehc_entries = theHC->entries(); +#ifdef EDM_ML_DEBUG edm::LogVerbatim("HcalForwardLib") << "FiberhitSize " << thehc_entries; +#endif for (j = 0; j < thehc_entries; j++) { FiberG4Hit* aHit = (*theHC)[j]; std::vector thePhotonsFromHit = aHit->photon(); +#ifdef EDM_ML_DEBUG edm::LogVerbatim("HcalForwardLib") << "Fiberhit " << j << " has " << thePhotonsFromHit.size() << " photons."; +#endif int fTowerId = -1; int fCellId = -1; int fFiberId = -1; @@ -148,13 +228,17 @@ void HcalForwardAnalysis::setPhotons(const EndOfEvent* evt) { if (aHit->depth() == 2) ShortFiberPhotons.push_back(thePhotonsFromHit[iph]); } +#ifdef EDM_ML_DEBUG edm::LogVerbatim("HcalForwardLib") << "HcalForwardAnalysis::setPhotons() NbPhotons " << thePhotonsFromHit.size() << " towerId " << fTowerId << " cellId " << fCellId << " fiberId " << fFiberId << " depth " << aHit->depth(); +#endif } } else { fillt = false; +#ifdef EDM_ML_DEBUG edm::LogVerbatim("HcalForwardLib") << "HcalForwardAnalysis::setPhotons(): No Photons!"; +#endif return; } edm::LogVerbatim("HcalForwardLib") << "HcalForwardAnalysis::setPhotons() LongFibPhotons: " << LongFiberPhotons.size() @@ -181,9 +265,11 @@ void HcalForwardAnalysis::setPhotons(const EndOfEvent* evt) { int thec_hc_entries = theChamberHC->entries(); for (j = 0; j < thec_hc_entries; ++j) { HFShowerG4Hit* aHit = (*theChamberHC)[j]; +#ifdef EDM_ML_DEBUG edm::LogVerbatim("HcalForwardLib") << "HcalForwardAnalysis::setPhotons() Chamber Hit id " << aHit->hitId() << " track id " << aHit->trackId() << " prim. pos. " << aHit->globalPosition() << " prom mom. dir. " << aHit->primaryMomDir() << " time " << aHit->time(); +#endif primPosOnSurf.SetXYZ(aHit->globalPosition().x(), aHit->globalPosition().y(), aHit->globalPosition().z()); primMomDirOnSurf.SetXYZ(aHit->primaryMomDir().x(), aHit->primaryMomDir().y(), aHit->primaryMomDir().z()); primTimeOnSurf = aHit->time(); @@ -251,9 +337,9 @@ void HcalForwardAnalysis::setPhotons(const EndOfEvent* evt) { } void HcalForwardAnalysis::fillEvent() { - /* - edm::LogVerbatim("HcalForwardLib") << "HcalForwardAnalysis: =====> filledEvent"; - */ +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("HcalForwardLib") << "HcalForwardAnalysis: =====> filledEvent"; +#endif nphot = int(thePhotons.size()); for (int i = 0; i < nphot; ++i) { x[i] = thePhotons[i].x; @@ -287,3 +373,8 @@ void HcalForwardAnalysis::clear() { thePhotons.clear(); } + +#include "SimG4Core/Watcher/interface/SimWatcherFactory.h" +#include "FWCore/PluginManager/interface/ModuleDef.h" + +DEFINE_SIMWATCHER(HcalForwardAnalysis); diff --git a/SimG4CMS/ShowerLibraryProducer/plugins/module.cc b/SimG4CMS/ShowerLibraryProducer/plugins/module.cc deleted file mode 100644 index 15c81e10041e8..0000000000000 --- a/SimG4CMS/ShowerLibraryProducer/plugins/module.cc +++ /dev/null @@ -1,7 +0,0 @@ -#include "SimG4CMS/ShowerLibraryProducer/interface/HcalForwardAnalysis.h" -#include "SimG4CMS/ShowerLibraryProducer/interface/CastorShowerLibraryMaker.h" -#include "SimG4Core/Watcher/interface/SimWatcherFactory.h" -#include "FWCore/PluginManager/interface/ModuleDef.h" - -DEFINE_SIMWATCHER(HcalForwardAnalysis); -DEFINE_SIMWATCHER(CastorShowerLibraryMaker); diff --git a/SimG4CMS/Tracker/plugins/module.cc b/SimG4CMS/Tracker/plugins/module.cc deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/SimG4CMS/Tracker/src/TrackerG4SimHitNumberingScheme.cc b/SimG4CMS/Tracker/src/TrackerG4SimHitNumberingScheme.cc index 8276f307fb42f..59d139473557b 100644 --- a/SimG4CMS/Tracker/src/TrackerG4SimHitNumberingScheme.cc +++ b/SimG4CMS/Tracker/src/TrackerG4SimHitNumberingScheme.cc @@ -9,7 +9,7 @@ #include "G4TouchableHistory.hh" #include "G4VSensitiveDetector.hh" -//#define DEBUG +//#define EDM_ML_DEBUG TrackerG4SimHitNumberingScheme::TrackerG4SimHitNumberingScheme(const GeometricDet& det) : alreadySet_(false), geomDet_(&det) {} @@ -55,7 +55,7 @@ void TrackerG4SimHitNumberingScheme::buildAll() { void TrackerG4SimHitNumberingScheme::touchToNavStory(const G4VTouchable* v, TrackerG4SimHitNumberingScheme::Nav_Story& st) { -#ifdef DEBUG +#ifdef EDM_ML_DEBUG std::vector debugint; std::vector debugstring; #endif @@ -65,13 +65,13 @@ void TrackerG4SimHitNumberingScheme::touchToNavStory(const G4VTouchable* v, if (dd4hep::dd::noNamespace(v->GetVolume(k)->GetLogicalVolume()->GetName()) != "TOBInactive") { st.emplace_back( std::pair(v->GetVolume(k)->GetCopyNo(), v->GetVolume(k)->GetLogicalVolume()->GetName())); -#ifdef DEBUG +#ifdef EDM_ML_DEBUG debugint.emplace_back(v->GetVolume(k)->GetCopyNo()); debugstring.emplace_back(v->GetVolume(k)->GetLogicalVolume()->GetName()); #endif } } -#ifdef DEBUG +#ifdef EDM_ML_DEBUG LogDebug("TrackerSimDebugNumbering") << " G4 TrackerG4SimHitNumberingScheme " << debugint; for (u_int32_t jj = 0; jj < debugstring.size(); jj++) LogDebug("TrackerSimDebugNumbering") << " " << debugstring[jj]; @@ -85,7 +85,7 @@ unsigned int TrackerG4SimHitNumberingScheme::g4ToNumberingScheme(const G4VToucha TrackerG4SimHitNumberingScheme::Nav_Story st; touchToNavStory(v, st); -#ifdef DEBUG +#ifdef EDM_ML_DEBUG dumpG4VPV(v); LogDebug("TrackerSimDebugNumbering") << " Returning: " << directMap_[st]; #endif