Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SimG4CMS/Calo/src/HFFibre.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion SimG4CMS/Calo/src/HFShowerLibrary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
64 changes: 0 additions & 64 deletions SimG4CMS/ShowerLibraryProducer/interface/HcalForwardLibWriter.h

This file was deleted.

91 changes: 82 additions & 9 deletions SimG4CMS/ShowerLibraryProducer/plugins/HcalForwardLibWriter.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,66 @@
#include "SimG4CMS/ShowerLibraryProducer/interface/HcalForwardLibWriter.h"
#include <memory>
#include <string>
#include <fstream>
#include <utility>
#include <vector>

#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<float>* partsEm;
std::vector<float>* partsHad;

std::string theDataFile;
std::vector<FileHandle> theFileHandle;

HFShowerLibraryEventInfo evtInfo;
HFShowerPhotonCollection emColl;
HFShowerPhotonCollection hadColl;
};

HcalForwardLibWriter::HcalForwardLibWriter(const edm::ParameterSet& iConfig) {
edm::ParameterSet theParms = iConfig.getParameter<edm::ParameterSet>("hcalForwardLibWriterParameters");
edm::FileInPath fp = theParms.getParameter<edm::FileInPath>("FileName");
Expand All @@ -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<float>();
partsHad = new std::vector<float>();
emBranch = LibTree->Branch("emParticles", &partsEm, bsize, splitlevel);
hadBranch = LibTree->Branch("hadParticles", &partsHad, bsize, splitlevel);
}

void HcalForwardLibWriter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down