CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Classes | 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
 
- 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)
 

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
 
edm::Service< TFileServicefs
 
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
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- 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< B > consumes (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 () noexcept
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag) noexcept
 
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 ( const edm::ParameterSet iConfig)
explicit

Definition at line 6 of file HcalForwardLibWriter.cc.

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

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

Definition at line 34 of file HcalForwardLibWriter.cc.

34 {}

Member Function Documentation

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

Implements edm::one::EDAnalyzerBase.

Definition at line 36 of file HcalForwardLibWriter.cc.

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

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

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 137 of file HcalForwardLibWriter.cc.

137 {}
void HcalForwardLibWriter::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 139 of file HcalForwardLibWriter.cc.

References TFileService::file(), fs, and LibTree.

139  {
140  fs->file().cd();
141  LibTree->Write();
142  LibTree->Print();
143 }
edm::Service< TFileService > fs
TFile & file() const
return opened TFile
Definition: TFileService.h:37
int HcalForwardLibWriter::readUserData ( void  )
private

Definition at line 145 of file HcalForwardLibWriter.cc.

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

Referenced by HcalForwardLibWriter().

145  {
146  std::ifstream input(theDataFile.c_str());
147  if (input.fail()) {
148  return 0;
149  }
150  std::string theFileName, thePID;
151  int mom;
152  int k = 0;
153  while (!input.eof()) {
154  input >> theFileName >> thePID >> mom;
155  if (!input.fail()) {
156  FileHandle aFile;
157  aFile.name = theFileName;
158  aFile.id = thePID;
159  aFile.momentum = mom;
160  theFileHandle.push_back(aFile);
161  ++k;
162  } else {
163  input.clear();
164  }
165  input.ignore(999, '\n');
166  }
167  return k;
168 }
static std::string const input
Definition: EdmProvDump.cc:47
std::vector< FileHandle > theFileHandle

Member Data Documentation

int HcalForwardLibWriter::bsize
private

Definition at line 44 of file HcalForwardLibWriter.h.

Referenced by HcalForwardLibWriter().

int HcalForwardLibWriter::compressionAlgo
private

Definition at line 46 of file HcalForwardLibWriter.h.

Referenced by HcalForwardLibWriter().

int HcalForwardLibWriter::compressionLevel
private

Definition at line 47 of file HcalForwardLibWriter.h.

Referenced by HcalForwardLibWriter().

TBranch* HcalForwardLibWriter::emBranch
private

Definition at line 53 of file HcalForwardLibWriter.h.

Referenced by analyze(), and HcalForwardLibWriter().

HFShowerPhotonCollection HcalForwardLibWriter::emColl
private

Definition at line 61 of file HcalForwardLibWriter.h.

Referenced by analyze(), and HcalForwardLibWriter().

HFShowerLibraryEventInfo HcalForwardLibWriter::evtInfo
private

Definition at line 60 of file HcalForwardLibWriter.h.

edm::Service<TFileService> HcalForwardLibWriter::fs
private

Definition at line 56 of file HcalForwardLibWriter.h.

Referenced by endJob(), and HcalForwardLibWriter().

TBranch* HcalForwardLibWriter::hadBranch
private

Definition at line 54 of file HcalForwardLibWriter.h.

Referenced by analyze(), and HcalForwardLibWriter().

HFShowerPhotonCollection HcalForwardLibWriter::hadColl
private

Definition at line 62 of file HcalForwardLibWriter.h.

Referenced by analyze(), and HcalForwardLibWriter().

TFile* HcalForwardLibWriter::LibFile
private

Definition at line 51 of file HcalForwardLibWriter.h.

TTree* HcalForwardLibWriter::LibTree
private

Definition at line 52 of file HcalForwardLibWriter.h.

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

int HcalForwardLibWriter::nbins
private

Definition at line 42 of file HcalForwardLibWriter.h.

Referenced by analyze(), and HcalForwardLibWriter().

int HcalForwardLibWriter::nshowers
private

Definition at line 43 of file HcalForwardLibWriter.h.

Referenced by analyze(), and HcalForwardLibWriter().

int HcalForwardLibWriter::splitlevel
private

Definition at line 45 of file HcalForwardLibWriter.h.

Referenced by HcalForwardLibWriter().

std::string HcalForwardLibWriter::theDataFile
private

Definition at line 57 of file HcalForwardLibWriter.h.

Referenced by HcalForwardLibWriter(), and readUserData().

TFile* HcalForwardLibWriter::theFile
private

Definition at line 49 of file HcalForwardLibWriter.h.

Referenced by analyze().

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

Definition at line 58 of file HcalForwardLibWriter.h.

Referenced by analyze(), and readUserData().

TTree* HcalForwardLibWriter::theTree
private

Definition at line 50 of file HcalForwardLibWriter.h.

Referenced by analyze().