CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
HcalForwardLibWriter Class Reference
Inheritance diagram for HcalForwardLibWriter:
edm::one::EDAnalyzer<> edm::one::EDAnalyzerBase edm::EDConsumerBase

Classes

struct  FileHandle
 

Public Member Functions

 HcalForwardLibWriter (const edm::ParameterSet &)
 
 ~HcalForwardLibWriter () override
 
- 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
 
std::vector< float > * partsEm
 
std::vector< float > * partsHad
 
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 24 of file HcalForwardLibWriter.cc.

Constructor & Destructor Documentation

◆ HcalForwardLibWriter()

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

Definition at line 64 of file HcalForwardLibWriter.cc.

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

64  {
65  edm::ParameterSet theParms = iConfig.getParameter<edm::ParameterSet>("hcalForwardLibWriterParameters");
66  edm::FileInPath fp = theParms.getParameter<edm::FileInPath>("FileName");
67  nbins = theParms.getParameter<int>("Nbins");
68  nshowers = theParms.getParameter<int>("Nshowers");
69  bsize = theParms.getParameter<int>("BufSize");
70  splitlevel = theParms.getParameter<int>("SplitLevel");
71  compressionAlgo = theParms.getParameter<int>("CompressionAlgo");
72  compressionLevel = theParms.getParameter<int>("CompressionLevel");
73 
74  std::string pName = fp.fullPath();
75  if (pName.find('.') == 0)
76  pName.erase(0, 2);
77  theDataFile = pName;
78  readUserData();
79 
81  fs->file().cd();
82  fs->file().SetCompressionAlgorithm(compressionAlgo);
83  fs->file().SetCompressionLevel(compressionLevel);
84 
85  LibTree = new TTree("HFSimHits", "HFSimHits");
86 
87  //https://root.cern/root/html534/TTree.html
88  // TBranch*Branch(const char* name, const char* classname, void** obj, Int_t bufsize = 32000, Int_t splitlevel = 99)
89  partsEm = new std::vector<float>();
90  partsHad = new std::vector<float>();
91  emBranch = LibTree->Branch("emParticles", &partsEm, bsize, splitlevel);
92  hadBranch = LibTree->Branch("hadParticles", &partsHad, bsize, splitlevel);
93 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< float > * partsEm
std::vector< float > * partsHad

◆ ~HcalForwardLibWriter()

HcalForwardLibWriter::~HcalForwardLibWriter ( )
inlineoverride

Definition at line 32 of file HcalForwardLibWriter.cc.

32 {}

Member Function Documentation

◆ analyze()

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

Implements edm::one::EDAnalyzerBase.

Definition at line 107 of file HcalForwardLibWriter.cc.

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

107  {
108  // Event info
109  std::vector<double> en;
110  double momBin[16] = {2, 3, 5, 7, 10, 15, 20, 30, 50, 75, 100, 150, 250, 350, 500, 1000};
111  en.reserve(nbins);
112  for (int i = 0; i < nbins; ++i)
113  en.push_back(momBin[i]);
114 
115  int nem = 0;
116  int nhad = 0;
117 
118  //shower photons
119  int n = theFileHandle.size();
120  // cycle over files ++++++++++++++++++++++++++++++++++++++++++++++++++++
121  for (int i = 0; i < n; ++i) {
122  std::string fn = theFileHandle[i].name;
123  std::string particle = theFileHandle[i].id;
124 
125  // edm::LogVerbatim("HcalSim") << "*** Input file " << i << " " << fn;
126 
127  TFile* theFile = new TFile(fn.c_str(), "READ");
128  TTree* theTree = (TTree*)gDirectory->Get("g4SimHits/CherenkovPhotons");
129  int nphot = 0;
130 
131  const int size = 10000;
132  if (nshowers > size) {
133  edm::LogError("HcalForwardLibWriter") << "Too big Nshowers number";
134  return;
135  }
136 
137  float x[size] = {0.};
138  float y[size] = {0.};
139  float z[size] = {0.};
140  float t[size] = {0.};
141  float lambda[size] = {0.};
142  int fiberId[size] = {0};
143  float primZ; // added
144 
145  theTree->SetBranchAddress("nphot", &nphot);
146  theTree->SetBranchAddress("x", &x);
147  theTree->SetBranchAddress("y", &y);
148  theTree->SetBranchAddress("z", &z);
149  theTree->SetBranchAddress("t", &t);
150  theTree->SetBranchAddress("lambda", &lambda);
151  theTree->SetBranchAddress("fiberId", &fiberId);
152  theTree->SetBranchAddress("primZ", &primZ); // added
153  int nentries = int(theTree->GetEntries());
154  int ngood = 0;
155  // cycle over showers ====================================================
156  for (int iev = 0; iev < nentries; iev++) {
157  if (primZ < 990.)
158  continue; // exclude showers with interactions in front of HF (1m of air)
159  ngood++;
160  if (ngood > nshowers)
161  continue;
162  unsigned int nph = nphot; //++
163  if (particle == "electron") {
164  emColl.clear();
165  partsEm->clear(); //++
166  partsEm->resize(5 * nph); //++
167  } else {
168  hadColl.clear();
169  partsHad->clear(); //++
170  partsHad->resize(5 * nph); //++
171  }
172  float nphot_long = 0;
173  float nphot_short = 0;
174  // cycle over photons in shower -------------------------------------------
175  for (int iph = 0; iph < nphot; ++iph) {
176  if (fiberId[iph] == 1) {
177  nphot_long++;
178  } else {
179  nphot_short++;
180  z[iph] = -z[iph];
181  }
182 
183  if (particle == "electron") {
184  (*partsEm)[iph] = (x[iph]);
185  (*partsEm)[iph + 1 * nph] = (y[iph]);
186  (*partsEm)[iph + 2 * nph] = (z[iph]);
187  (*partsEm)[iph + 3 * nph] = (t[iph]);
188  (*partsEm)[iph + 4 * nph] = (lambda[iph]);
189  } else {
190  (*partsHad)[iph] = (x[iph]);
191  (*partsHad)[iph + 1 * nph] = (y[iph]);
192  (*partsHad)[iph + 2 * nph] = (z[iph]);
193  (*partsHad)[iph + 3 * nph] = (t[iph]);
194  (*partsHad)[iph + 4 * nph] = (lambda[iph]);
195  }
196  }
197  // end of cycle over photons in shower -------------------------------------------
198 
199  if (particle == "electron") {
200  LibTree->SetEntries(nem);
201  emBranch->Fill();
202  nem++;
203  emColl.clear();
204  } else {
205  LibTree->SetEntries(nhad);
206  nhad++;
207  hadBranch->Fill();
208  hadColl.clear();
209  }
210  }
211  // end of cycle over showers ====================================================
212  theFile->Close();
213  }
214  // end of cycle over files ++++++++++++++++++++++++++++++++++++++++++++++++++++
215 }
size
Write out results.
TkSoAView< TrackerTraits > HitToTuple< TrackerTraits > const *__restrict__ int32_t int32_t int iev
Log< level::Error, false > LogError
std::vector< float > * partsEm
std::vector< float > * partsHad
std::vector< FileHandle > theFileHandle
HFShowerPhotonCollection hadColl
HFShowerPhotonCollection emColl

◆ beginJob()

void HcalForwardLibWriter::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 217 of file HcalForwardLibWriter.cc.

217 {}

◆ endJob()

void HcalForwardLibWriter::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 219 of file HcalForwardLibWriter.cc.

References compareTotals::fs, and LibTree.

219  {
221  fs->file().cd();
222  LibTree->Write();
223  LibTree->Print();
224 }

◆ fillDescriptions()

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

Definition at line 95 of file HcalForwardLibWriter.cc.

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

95  {
97  desc.add<edm::FileInPath>("FileName", edm::FileInPath("SimG4CMS/ShowerLibraryProducer/data/fileList.txt"));
98  desc.add<int>("Nbins", 16);
99  desc.add<int>("Nshowers", 10000);
100  desc.add<int>("BufSize", 1);
101  desc.add<int>("SplitLevel", 2);
102  desc.add<int>("CompressionAlgo", 4);
103  desc.add<int>("CompressionLevel", 4);
104  descriptions.add("hcalForwardLibWriterParameters", desc);
105 }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ readUserData()

int HcalForwardLibWriter::readUserData ( void  )
private

Definition at line 226 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().

226  {
227  std::ifstream input(theDataFile.c_str());
228  if (input.fail()) {
229  return 0;
230  }
231  std::string theFileName, thePID;
232  int mom;
233  int k = 0;
234  while (!input.eof()) {
235  input >> theFileName >> thePID >> mom;
236  if (!input.fail()) {
237  FileHandle aFile;
238  aFile.name = theFileName;
239  aFile.id = thePID;
240  aFile.momentum = mom;
241  theFileHandle.push_back(aFile);
242  ++k;
243  } else {
244  input.clear();
245  }
246  input.ignore(999, '\n');
247  }
248  return k;
249 }
static std::string const input
Definition: EdmProvDump.cc:50
std::vector< FileHandle > theFileHandle

Member Data Documentation

◆ bsize

int HcalForwardLibWriter::bsize
private

Definition at line 42 of file HcalForwardLibWriter.cc.

Referenced by HcalForwardLibWriter().

◆ compressionAlgo

int HcalForwardLibWriter::compressionAlgo
private

Definition at line 44 of file HcalForwardLibWriter.cc.

Referenced by HcalForwardLibWriter().

◆ compressionLevel

int HcalForwardLibWriter::compressionLevel
private

Definition at line 45 of file HcalForwardLibWriter.cc.

Referenced by HcalForwardLibWriter().

◆ emBranch

TBranch* HcalForwardLibWriter::emBranch
private

Definition at line 51 of file HcalForwardLibWriter.cc.

Referenced by analyze(), and HcalForwardLibWriter().

◆ emColl

HFShowerPhotonCollection HcalForwardLibWriter::emColl
private

Definition at line 60 of file HcalForwardLibWriter.cc.

Referenced by analyze().

◆ evtInfo

HFShowerLibraryEventInfo HcalForwardLibWriter::evtInfo
private

Definition at line 59 of file HcalForwardLibWriter.cc.

◆ hadBranch

TBranch* HcalForwardLibWriter::hadBranch
private

Definition at line 52 of file HcalForwardLibWriter.cc.

Referenced by analyze(), and HcalForwardLibWriter().

◆ hadColl

HFShowerPhotonCollection HcalForwardLibWriter::hadColl
private

Definition at line 61 of file HcalForwardLibWriter.cc.

Referenced by analyze().

◆ LibFile

TFile* HcalForwardLibWriter::LibFile
private

Definition at line 49 of file HcalForwardLibWriter.cc.

◆ LibTree

TTree* HcalForwardLibWriter::LibTree
private

Definition at line 50 of file HcalForwardLibWriter.cc.

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

◆ nbins

int HcalForwardLibWriter::nbins
private

Definition at line 40 of file HcalForwardLibWriter.cc.

Referenced by analyze(), and HcalForwardLibWriter().

◆ nshowers

int HcalForwardLibWriter::nshowers
private

Definition at line 41 of file HcalForwardLibWriter.cc.

Referenced by analyze(), and HcalForwardLibWriter().

◆ partsEm

std::vector<float>* HcalForwardLibWriter::partsEm
private

Definition at line 53 of file HcalForwardLibWriter.cc.

Referenced by analyze(), and HcalForwardLibWriter().

◆ partsHad

std::vector<float>* HcalForwardLibWriter::partsHad
private

Definition at line 54 of file HcalForwardLibWriter.cc.

Referenced by analyze(), and HcalForwardLibWriter().

◆ splitlevel

int HcalForwardLibWriter::splitlevel
private

Definition at line 43 of file HcalForwardLibWriter.cc.

Referenced by HcalForwardLibWriter().

◆ theDataFile

std::string HcalForwardLibWriter::theDataFile
private

Definition at line 56 of file HcalForwardLibWriter.cc.

Referenced by HcalForwardLibWriter(), and readUserData().

◆ theFile

TFile* HcalForwardLibWriter::theFile
private

Definition at line 47 of file HcalForwardLibWriter.cc.

Referenced by analyze().

◆ theFileHandle

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

Definition at line 57 of file HcalForwardLibWriter.cc.

Referenced by analyze(), and readUserData().

◆ theTree

TTree* HcalForwardLibWriter::theTree
private

Definition at line 48 of file HcalForwardLibWriter.cc.

Referenced by analyze().