CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
HcalForwardLibWriter Class Reference

#include <HcalForwardLibWriter.h>

Inheritance diagram for HcalForwardLibWriter:
edm::one::EDAnalyzer<> edm::one::EDAnalyzerBase edm::EDConsumerBase

Classes

struct  FileHandle
 

Public Member Functions

 HcalForwardLibWriter (const edm::ParameterSet &)
 
 ~HcalForwardLibWriter () override=default
 
- Public Member Functions inherited from edm::one::EDAnalyzer<>
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESProxyIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const *> const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void beginJob () override
 
void endJob () override
 
int readUserData ()
 

Private Attributes

int bsize
 
int compressionAlgo
 
int compressionLevel
 
TBranch * emBranch
 
HFShowerPhotonCollection emColl
 
HFShowerLibraryEventInfo evtInfo
 
TBranch * hadBranch
 
HFShowerPhotonCollection hadColl
 
TFile * LibFile
 
TTree * LibTree
 
int nbins
 
int nshowers
 
int splitlevel
 
std::string theDataFile
 
TFile * theFile
 
std::vector< FileHandletheFileHandle
 
TTree * theTree
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Definition at line 27 of file HcalForwardLibWriter.h.

Constructor & Destructor Documentation

◆ HcalForwardLibWriter()

HcalForwardLibWriter::HcalForwardLibWriter ( const edm::ParameterSet iConfig)
explicit

Definition at line 4 of file HcalForwardLibWriter.cc.

References bsize, compressionAlgo, compressionLevel, emBranch, emColl, personalPlayback::fp, compareTotals::fs, edm::ParameterSet::getParameter(), hadBranch, hadColl, LibTree, nbins, nshowers, readUserData(), splitlevel, AlCaHLTBitMon_QueryRunRegistry::string, and theDataFile.

4  {
5  edm::ParameterSet theParms = iConfig.getParameter<edm::ParameterSet>("hcalForwardLibWriterParameters");
6  edm::FileInPath fp = theParms.getParameter<edm::FileInPath>("FileName");
7  nbins = theParms.getParameter<int>("Nbins");
8  nshowers = theParms.getParameter<int>("Nshowers");
9  bsize = theParms.getParameter<int>("BufSize");
10  splitlevel = theParms.getParameter<int>("SplitLevel");
11  compressionAlgo = theParms.getParameter<int>("CompressionAlgo");
12  compressionLevel = theParms.getParameter<int>("CompressionLevel");
13 
14  std::string pName = fp.fullPath();
15  if (pName.find('.') == 0)
16  pName.erase(0, 2);
17  theDataFile = pName;
18  readUserData();
19 
21  fs->file().cd();
22  fs->file().SetCompressionAlgorithm(compressionAlgo);
23  fs->file().SetCompressionLevel(compressionLevel);
24 
25  LibTree = new TTree("HFSimHits", "HFSimHits");
26 
27  //https://root.cern/root/html534/TTree.html
28  // TBranch*Branch(const char* name, const char* classname, void** obj, Int_t bufsize = 32000, Int_t splitlevel = 99)
29  emBranch = LibTree->Branch("emParticles", "HFShowerPhotons-emParticles", &emColl, bsize, splitlevel);
30  hadBranch = LibTree->Branch("hadParticles", "HFShowerPhotons-hadParticles", &hadColl, bsize, splitlevel);
31 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
HFShowerPhotonCollection hadColl
HFShowerPhotonCollection emColl

◆ ~HcalForwardLibWriter()

HcalForwardLibWriter::~HcalForwardLibWriter ( )
overridedefault

Member Function Documentation

◆ analyze()

void HcalForwardLibWriter::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivatevirtual

Implements edm::one::EDAnalyzerBase.

Definition at line 45 of file HcalForwardLibWriter.cc.

References emBranch, emColl, personalPlayback::fn, hadBranch, hadColl, mps_fire::i, iev, createfilelist::int, LibTree, dqmiodumpmetadata::n, nbins, nshowers, findQualityFiles::size, AlCaHLTBitMon_QueryRunRegistry::string, submitPVValidationJobs::t, theFile, theFileHandle, theTree, x, y, and z.

45  {
46  // Event info
47  std::vector<double> en;
48  double momBin[16] = {2, 3, 5, 7, 10, 15, 20, 30, 50, 75, 100, 150, 250, 350, 500, 1000};
49  en.reserve(nbins);
50  for (int i = 0; i < nbins; ++i)
51  en.push_back(momBin[i]);
52 
53  int nem = 0;
54  int nhad = 0;
55 
56  //shower photons
57  int n = theFileHandle.size();
58  // cycle over files ++++++++++++++++++++++++++++++++++++++++++++++++++++
59  for (int i = 0; i < n; ++i) {
60  std::string fn = theFileHandle[i].name;
61  std::string particle = theFileHandle[i].id;
62 
63  // edm::LogVerbatim("HcalSim") << "*** Input file " << i << " " << fn;
64 
65  TFile* theFile = new TFile(fn.c_str(), "READ");
66  TTree* theTree = (TTree*)gDirectory->Get("g4SimHits/CherenkovPhotons");
67  int nphot = 0;
68 
69  const int size = 10000;
70  if (nshowers > size) {
71  edm::LogError("HcalForwardLibWriter") << "Too big Nshowers number";
72  return;
73  }
74 
75  float x[size] = {0.};
76  float y[size] = {0.};
77  float z[size] = {0.};
78  float t[size] = {0.};
79  float lambda[size] = {0.};
80  int fiberId[size] = {0};
81  float primZ; // added
82 
83  theTree->SetBranchAddress("nphot", &nphot);
84  theTree->SetBranchAddress("x", &x);
85  theTree->SetBranchAddress("y", &y);
86  theTree->SetBranchAddress("z", &z);
87  theTree->SetBranchAddress("t", &t);
88  theTree->SetBranchAddress("lambda", &lambda);
89  theTree->SetBranchAddress("fiberId", &fiberId);
90  theTree->SetBranchAddress("primZ", &primZ); // added
91  int nentries = int(theTree->GetEntries());
92  int ngood = 0;
93  int nbytes = 0;
94  // cycle over showers ====================================================
95  for (int iev = 0; iev < nentries; iev++) {
96  nbytes += theTree->GetEntry(iev);
97  if (primZ < 990.)
98  continue; // exclude showers with interactions in front of HF (1m of air)
99  ngood++;
100  if (ngood > nshowers)
101  continue;
102  if (particle == "electron") {
103  emColl.clear();
104  } else {
105  hadColl.clear();
106  }
107  float nphot_long = 0;
108  float nphot_short = 0;
109  // cycle over photons in shower -------------------------------------------
110  for (int iph = 0; iph < nphot; ++iph) {
111  if (fiberId[iph] == 1) {
112  nphot_long++;
113  } else {
114  nphot_short++;
115  z[iph] = -z[iph];
116  }
117 
118  HFShowerPhoton::Point pos(x[iph], y[iph], z[iph]);
119  HFShowerPhoton aPhoton(pos, t[iph], lambda[iph]);
120  if (particle == "electron") {
121  emColl.push_back(aPhoton);
122  } else {
123  hadColl.push_back(aPhoton);
124  }
125  }
126  // end of cycle over photons in shower -------------------------------------------
127 
128  if (particle == "electron") {
129  LibTree->SetEntries(nem + 1);
130  emBranch->Fill();
131  nem++;
132  emColl.clear();
133  } else {
134  LibTree->SetEntries(nhad + 1);
135  nhad++;
136  hadBranch->Fill();
137  hadColl.clear();
138  }
139  }
140  // end of cycle over showers ====================================================
141  theFile->Close();
142  }
143  // end of cycle over files ++++++++++++++++++++++++++++++++++++++++++++++++++++
144 }
size
Write out results.
math::XYZPointF Point
point in the space
Log< level::Error, false > LogError
HitContainer const *__restrict__ TkSoA const *__restrict__ Quality const *__restrict__ CAHitNtupletGeneratorKernelsGPU::HitToTuple const *__restrict__ int32_t int32_t int iev
std::vector< FileHandle > theFileHandle
HFShowerPhotonCollection hadColl
HFShowerPhotonCollection emColl

◆ beginJob()

void HcalForwardLibWriter::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 146 of file HcalForwardLibWriter.cc.

146 {}

◆ endJob()

void HcalForwardLibWriter::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 148 of file HcalForwardLibWriter.cc.

References compareTotals::fs, and LibTree.

148  {
150  fs->file().cd();
151  LibTree->Write();
152  LibTree->Print();
153 }

◆ fillDescriptions()

void HcalForwardLibWriter::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 33 of file HcalForwardLibWriter.cc.

References edm::ConfigurationDescriptions::add(), and submitPVResolutionJobs::desc.

33  {
35  desc.add<edm::FileInPath>("FileName", edm::FileInPath("SimG4CMS/ShowerLibraryProducer/data/fileList.txt"));
36  desc.add<int>("Nbins", 16);
37  desc.add<int>("Nshowers", 10000);
38  desc.add<int>("BufSize", 1);
39  desc.add<int>("SplitLevel", 2);
40  desc.add<int>("CompressionAlgo", 4);
41  desc.add<int>("CompressionLevel", 4);
42  descriptions.add("hcalForwardLibWriterParameters", desc);
43 }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ readUserData()

int HcalForwardLibWriter::readUserData ( void  )
private

Definition at line 155 of file HcalForwardLibWriter.cc.

References HcalForwardLibWriter::FileHandle::id, input, dqmdumpme::k, HcalForwardLibWriter::FileHandle::momentum, HcalForwardLibWriter::FileHandle::name, AlCaHLTBitMon_QueryRunRegistry::string, theDataFile, and theFileHandle.

Referenced by HcalForwardLibWriter().

155  {
156  std::ifstream input(theDataFile.c_str());
157  if (input.fail()) {
158  return 0;
159  }
160  std::string theFileName, thePID;
161  int mom;
162  int k = 0;
163  while (!input.eof()) {
164  input >> theFileName >> thePID >> mom;
165  if (!input.fail()) {
166  FileHandle aFile;
167  aFile.name = theFileName;
168  aFile.id = thePID;
169  aFile.momentum = mom;
170  theFileHandle.push_back(aFile);
171  ++k;
172  } else {
173  input.clear();
174  }
175  input.ignore(999, '\n');
176  }
177  return k;
178 }
static std::string const input
Definition: EdmProvDump.cc:47
std::vector< FileHandle > theFileHandle

Member Data Documentation

◆ bsize

int HcalForwardLibWriter::bsize
private

Definition at line 45 of file HcalForwardLibWriter.h.

Referenced by HcalForwardLibWriter().

◆ compressionAlgo

int HcalForwardLibWriter::compressionAlgo
private

Definition at line 47 of file HcalForwardLibWriter.h.

Referenced by HcalForwardLibWriter().

◆ compressionLevel

int HcalForwardLibWriter::compressionLevel
private

Definition at line 48 of file HcalForwardLibWriter.h.

Referenced by HcalForwardLibWriter().

◆ emBranch

TBranch* HcalForwardLibWriter::emBranch
private

Definition at line 54 of file HcalForwardLibWriter.h.

Referenced by analyze(), and HcalForwardLibWriter().

◆ emColl

HFShowerPhotonCollection HcalForwardLibWriter::emColl
private

Definition at line 61 of file HcalForwardLibWriter.h.

Referenced by analyze(), and HcalForwardLibWriter().

◆ evtInfo

HFShowerLibraryEventInfo HcalForwardLibWriter::evtInfo
private

Definition at line 60 of file HcalForwardLibWriter.h.

◆ hadBranch

TBranch* HcalForwardLibWriter::hadBranch
private

Definition at line 55 of file HcalForwardLibWriter.h.

Referenced by analyze(), and HcalForwardLibWriter().

◆ hadColl

HFShowerPhotonCollection HcalForwardLibWriter::hadColl
private

Definition at line 62 of file HcalForwardLibWriter.h.

Referenced by analyze(), and HcalForwardLibWriter().

◆ LibFile

TFile* HcalForwardLibWriter::LibFile
private

Definition at line 52 of file HcalForwardLibWriter.h.

◆ LibTree

TTree* HcalForwardLibWriter::LibTree
private

Definition at line 53 of file HcalForwardLibWriter.h.

Referenced by analyze(), endJob(), and HcalForwardLibWriter().

◆ nbins

int HcalForwardLibWriter::nbins
private

Definition at line 43 of file HcalForwardLibWriter.h.

Referenced by analyze(), and HcalForwardLibWriter().

◆ nshowers

int HcalForwardLibWriter::nshowers
private

Definition at line 44 of file HcalForwardLibWriter.h.

Referenced by analyze(), and HcalForwardLibWriter().

◆ splitlevel

int HcalForwardLibWriter::splitlevel
private

Definition at line 46 of file HcalForwardLibWriter.h.

Referenced by HcalForwardLibWriter().

◆ theDataFile

std::string HcalForwardLibWriter::theDataFile
private

Definition at line 57 of file HcalForwardLibWriter.h.

Referenced by HcalForwardLibWriter(), and readUserData().

◆ theFile

TFile* HcalForwardLibWriter::theFile
private

Definition at line 50 of file HcalForwardLibWriter.h.

Referenced by analyze().

◆ theFileHandle

std::vector<FileHandle> HcalForwardLibWriter::theFileHandle
private

Definition at line 58 of file HcalForwardLibWriter.h.

Referenced by analyze(), and readUserData().

◆ theTree

TTree* HcalForwardLibWriter::theTree
private

Definition at line 51 of file HcalForwardLibWriter.h.

Referenced by analyze().