diff --git a/SimG4CMS/Calo/src/HFFibre.cc b/SimG4CMS/Calo/src/HFFibre.cc index 213d7e0b8cf78..e798c0f018d4c 100644 --- a/SimG4CMS/Calo/src/HFFibre.cc +++ b/SimG4CMS/Calo/src/HFFibre.cc @@ -127,7 +127,7 @@ double HFFibre::zShift(const G4ThreeVector& point, int depth, int fromEndAbs) co double zFibre = 0; int ieta = 0; double length = 250 * CLHEP::cm; - double hR = sqrt((point.x()) * (point.x()) + (point.y()) * (point.y())); + double hR = std::sqrt((point.x()) * (point.x()) + (point.y()) * (point.y())); // Defines the Radius bin by radial subdivision if (fromEndAbs >= 0) { diff --git a/SimG4CMS/Calo/src/HFShowerLibrary.cc b/SimG4CMS/Calo/src/HFShowerLibrary.cc index 83dfc65c084c3..d04d513b28531 100644 --- a/SimG4CMS/Calo/src/HFShowerLibrary.cc +++ b/SimG4CMS/Calo/src/HFShowerLibrary.cc @@ -172,7 +172,7 @@ HFShowerLibrary::HFShowerLibrary(const Params& iParams, const FileParams& iFileP } emBranch_ = BranchReader(emBranch, fileFormat, 0, iFileParams.cacheBranches_ ? totEvents_ : 0); size_t offset = 0; - if (fileFormat == FileFormat::kNewV3 or (fileFormat == FileFormat::kNew and fileVersion < 2)) { + if ((fileFormat == FileFormat::kNewV3 && fileVersion < 3) || (fileFormat == FileFormat::kNew && fileVersion < 2)) { //NOTE: for this format, the hadBranch is all empty up to // totEvents_ (which is more like 1/2*GenEntries()) offset = totEvents_; diff --git a/SimG4CMS/ShowerLibraryProducer/interface/HcalForwardLibWriter.h b/SimG4CMS/ShowerLibraryProducer/interface/HcalForwardLibWriter.h deleted file mode 100644 index d8a1e216a6dff..0000000000000 --- a/SimG4CMS/ShowerLibraryProducer/interface/HcalForwardLibWriter.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef SimG4CMS_ShowerLibraryProducer_HcalForwardLibWriter_h -#define SimG4CMS_ShowerLibraryProducer_HcalForwardLibWriter_h - -#include -#include -#include -#include -#include - -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/one/EDAnalyzer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/MessageLogger/interface/MessageLogger.h" - -#include "SimDataFormats/CaloHit/interface/HFShowerPhoton.h" -#include "SimDataFormats/CaloHit/interface/HFShowerLibraryEventInfo.h" -#include "CommonTools/UtilAlgos/interface/TFileService.h" -#include "FWCore/ServiceRegistry/interface/Service.h" - -#include "TFile.h" -#include "TTree.h" - -class HcalForwardLibWriter : public edm::one::EDAnalyzer<> { -public: - struct FileHandle { - std::string name; - std::string id; - int momentum; - }; - explicit HcalForwardLibWriter(const edm::ParameterSet&); - ~HcalForwardLibWriter() override = default; - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - -private: - void beginJob() override; - void analyze(const edm::Event&, const edm::EventSetup&) override; - void endJob() override; - int readUserData(); - int nbins; - int nshowers; - int bsize; - int splitlevel; - int compressionAlgo; - int compressionLevel; - - TFile* theFile; - TTree* theTree; - TFile* LibFile; - TTree* LibTree; - TBranch* emBranch; - TBranch* hadBranch; - - std::string theDataFile; - std::vector theFileHandle; - - HFShowerLibraryEventInfo evtInfo; - HFShowerPhotonCollection emColl; - HFShowerPhotonCollection hadColl; -}; -#endif diff --git a/SimG4CMS/ShowerLibraryProducer/plugins/HcalForwardLibWriter.cc b/SimG4CMS/ShowerLibraryProducer/plugins/HcalForwardLibWriter.cc index ade71d75125ac..c227ccf8f35ae 100644 --- a/SimG4CMS/ShowerLibraryProducer/plugins/HcalForwardLibWriter.cc +++ b/SimG4CMS/ShowerLibraryProducer/plugins/HcalForwardLibWriter.cc @@ -1,6 +1,66 @@ -#include "SimG4CMS/ShowerLibraryProducer/interface/HcalForwardLibWriter.h" +#include +#include +#include +#include +#include + +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "SimDataFormats/CaloHit/interface/HFShowerPhoton.h" +#include "SimDataFormats/CaloHit/interface/HFShowerLibraryEventInfo.h" +#include "CommonTools/UtilAlgos/interface/TFileService.h" +#include "FWCore/ServiceRegistry/interface/Service.h" + +#include "TFile.h" +#include "TTree.h" + +class HcalForwardLibWriter : public edm::one::EDAnalyzer<> { +public: + struct FileHandle { + std::string name; + std::string id; + int momentum; + }; + explicit HcalForwardLibWriter(const edm::ParameterSet&); + ~HcalForwardLibWriter() override {} + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + void beginJob() override; + void analyze(const edm::Event&, const edm::EventSetup&) override; + void endJob() override; + int readUserData(); + int nbins; + int nshowers; + int bsize; + int splitlevel; + int compressionAlgo; + int compressionLevel; + + TFile* theFile; + TTree* theTree; + TFile* LibFile; + TTree* LibTree; + TBranch* emBranch; + TBranch* hadBranch; + std::vector* partsEm; + std::vector* partsHad; + + std::string theDataFile; + std::vector theFileHandle; + + HFShowerLibraryEventInfo evtInfo; + HFShowerPhotonCollection emColl; + HFShowerPhotonCollection hadColl; +}; + HcalForwardLibWriter::HcalForwardLibWriter(const edm::ParameterSet& iConfig) { edm::ParameterSet theParms = iConfig.getParameter("hcalForwardLibWriterParameters"); edm::FileInPath fp = theParms.getParameter("FileName"); @@ -26,8 +86,10 @@ HcalForwardLibWriter::HcalForwardLibWriter(const edm::ParameterSet& iConfig) { //https://root.cern/root/html534/TTree.html // TBranch*Branch(const char* name, const char* classname, void** obj, Int_t bufsize = 32000, Int_t splitlevel = 99) - emBranch = LibTree->Branch("emParticles", "HFShowerPhotons-emParticles", &emColl, bsize, splitlevel); - hadBranch = LibTree->Branch("hadParticles", "HFShowerPhotons-hadParticles", &hadColl, bsize, splitlevel); + partsEm = new std::vector(); + partsHad = new std::vector(); + emBranch = LibTree->Branch("emParticles", &partsEm, bsize, splitlevel); + hadBranch = LibTree->Branch("hadParticles", &partsHad, bsize, splitlevel); } void HcalForwardLibWriter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { @@ -97,10 +159,15 @@ void HcalForwardLibWriter::analyze(const edm::Event& iEvent, const edm::EventSet ngood++; if (ngood > nshowers) continue; + unsigned int nph = nphot; //++ if (particle == "electron") { emColl.clear(); + partsEm->clear(); //++ + partsEm->resize(5 * nph); //++ } else { hadColl.clear(); + partsHad->clear(); //++ + partsHad->resize(5 * nph); //++ } float nphot_long = 0; float nphot_short = 0; @@ -113,23 +180,29 @@ void HcalForwardLibWriter::analyze(const edm::Event& iEvent, const edm::EventSet z[iph] = -z[iph]; } - HFShowerPhoton::Point pos(x[iph], y[iph], z[iph]); - HFShowerPhoton aPhoton(pos, t[iph], lambda[iph]); if (particle == "electron") { - emColl.push_back(aPhoton); + (*partsEm)[iph] = (x[iph]); + (*partsEm)[iph + 1 * nph] = (y[iph]); + (*partsEm)[iph + 2 * nph] = (z[iph]); + (*partsEm)[iph + 3 * nph] = (t[iph]); + (*partsEm)[iph + 4 * nph] = (lambda[iph]); } else { - hadColl.push_back(aPhoton); + (*partsHad)[iph] = (x[iph]); + (*partsHad)[iph + 1 * nph] = (y[iph]); + (*partsHad)[iph + 2 * nph] = (z[iph]); + (*partsHad)[iph + 3 * nph] = (t[iph]); + (*partsHad)[iph + 4 * nph] = (lambda[iph]); } } // end of cycle over photons in shower ------------------------------------------- if (particle == "electron") { - LibTree->SetEntries(nem + 1); + LibTree->SetEntries(nem); emBranch->Fill(); nem++; emColl.clear(); } else { - LibTree->SetEntries(nhad + 1); + LibTree->SetEntries(nhad); nhad++; hadBranch->Fill(); hadColl.clear();