CMS 3D CMS Logo

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
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () 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
 
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::vector< ModuleDescription const * > &modules, 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
 
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

HFShowerPhotonCollection emColl
 
HFShowerLibraryEventInfo evtInfo
 
edm::Service< TFileServicefs
 
HFShowerPhotonCollection hadColl
 
TFile * LibFile
 
TTree * LibTree
 
int nbins
 
int nshowers
 
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)
 
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<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)
 

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 emColl, TFileService::file(), personalPlayback::fp, fs, edm::ParameterSet::getParameter(), hadColl, LibTree, nbins, nshowers, readUserData(), 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 
12  std::string pName = fp.fullPath();
13  if (pName.find(".") == 0)
14  pName.erase(0, 2);
15  theDataFile = pName;
16  readUserData();
17 
18  int bsize = 64000;
19  fs->file().cd();
20  LibTree = new TTree("HFSimHits", "HFSimHits");
21  LibTree->Branch("emParticles", "HFShowerPhotons-emParticles", &emColl, bsize);
22  LibTree->Branch("hadParticles", "HFShowerPhotons-hadParticles", &hadColl, bsize);
23 }
T getParameter(std::string const &) const
edm::Service< TFileService > fs
TFile & file() const
return opened TFile
Definition: TFileService.h:37
HFShowerPhotonCollection hadColl
HFShowerPhotonCollection emColl
HcalForwardLibWriter::~HcalForwardLibWriter ( )
override

Definition at line 25 of file HcalForwardLibWriter.cc.

25 {}

Member Function Documentation

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

Definition at line 27 of file HcalForwardLibWriter.cc.

References emColl, personalPlayback::fn, hadColl, mps_fire::i, createfilelist::int, GetRecoTauVFromDQM_MC_cff::kk, LibTree, dqmiodumpmetadata::n, nbins, AlCaHLTBitMon_QueryRunRegistry::string, OrderedSet::t, theFile, theFileHandle, theTree, x, y, and z.

27  {
28  // Event info
29  std::vector<double> en;
30  double momBin[16] = {2, 3, 5, 7, 10, 15, 20, 30, 50, 75, 100, 150, 250, 350, 500, 1000};
31  for (int i = 0; i < nbins; ++i)
32  en.push_back(momBin[i]);
33 
34  //shower photons
35  int n = theFileHandle.size();
36  // cycle over files ++++++++++++++++++++++++++++++++++++++++++++++++++++
37  for (int i = 0; i < n; ++i) {
38  std::string fn = theFileHandle[i].name;
39  std::string particle = theFileHandle[i].id;
40  TFile* theFile = new TFile(fn.c_str(), "READ");
41  TTree* theTree = (TTree*)gDirectory->Get("g4SimHits/CherenkovPhotons");
42  int nphot = 0;
43  float x[10000];
44  float y[10000];
45  float z[10000];
46  float t[10000];
47  float lambda[10000];
48  int fiberId[10000];
49  for (int kk = 0; kk < 10000; ++kk) {
50  x[kk] = 0.;
51  y[kk] = 0.;
52  z[kk] = 0.;
53  t[kk] = 0.;
54  lambda[kk] = 0.;
55  fiberId[kk] = 0;
56  }
57  theTree->SetBranchAddress("nphot", &nphot);
58  theTree->SetBranchAddress("x", &x);
59  theTree->SetBranchAddress("y", &y);
60  theTree->SetBranchAddress("z", &z);
61  theTree->SetBranchAddress("t", &t);
62  theTree->SetBranchAddress("lambda", &lambda);
63  theTree->SetBranchAddress("fiberId", &fiberId);
64  int nentries = int(theTree->GetEntries());
65  if (nentries > 5000)
66  nentries = 5000;
67  int nbytes = 0;
68  // cycle over showers ====================================================
69  for (int iev = 0; iev < nentries; iev++) {
70  nbytes += theTree->GetEntry(iev);
71  if (particle == "electron") {
72  emColl.clear();
73  } else {
74  hadColl.clear();
75  }
76  float nphot_long = 0;
77  float nphot_short = 0;
78  // cycle over photons in shower -------------------------------------------
79  for (int iph = 0; iph < nphot; ++iph) {
80  if (fiberId[iph] == 1) {
81  nphot_long++;
82  } else {
83  nphot_short++;
84  z[iph] = -z[iph];
85  }
86 
87  HFShowerPhoton::Point pos(x[iph], y[iph], z[iph]);
88  HFShowerPhoton aPhoton(pos, t[iph], lambda[iph]);
89  if (particle == "electron") {
90  emColl.push_back(aPhoton);
91  } else {
92  hadColl.push_back(aPhoton);
93  }
94  }
95  // end of cycle over photons in shower -------------------------------------------
96 
97  // if(iev>0) LibTree->SetBranchStatus("HFShowerLibInfo",0);
98  if (particle == "electron") {
99  LibTree->SetBranchStatus("hadParticles", false);
100  } else {
101  LibTree->SetBranchStatus("emParticles", false);
102  }
103  LibTree->Fill();
104  if (particle == "electron") {
105  emColl.clear();
106  } else {
107  hadColl.clear();
108  }
109  }
110  // end of cycle over showers ====================================================
111  theFile->Close();
112  }
113  // end of cycle over files ++++++++++++++++++++++++++++++++++++++++++++++++++++
114 }
math::XYZPointF Point
point in the space
std::vector< FileHandle > theFileHandle
HFShowerPhotonCollection hadColl
HFShowerPhotonCollection emColl
void HcalForwardLibWriter::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 116 of file HcalForwardLibWriter.cc.

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

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 118 of file HcalForwardLibWriter.cc.

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

118  {
119  fs->file().cd();
120  LibTree->Write();
121  LibTree->Print();
122 }
edm::Service< TFileService > fs
TFile & file() const
return opened TFile
Definition: TFileService.h:37
int HcalForwardLibWriter::readUserData ( void  )
private

Definition at line 124 of file HcalForwardLibWriter.cc.

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

Referenced by HcalForwardLibWriter().

124  {
125  std::ifstream input(theDataFile.c_str());
126  if (input.fail()) {
127  return 0;
128  }
129  std::string theFileName, thePID;
130  int mom;
131  int k = 0;
132  while (!input.eof()) {
133  input >> theFileName >> thePID >> mom;
134  if (!input.fail()) {
135  FileHandle aFile;
136  aFile.name = theFileName;
137  aFile.id = thePID;
138  aFile.momentum = mom;
139  theFileHandle.push_back(aFile);
140  ++k;
141  } else {
142  input.clear();
143  }
144  input.ignore(999, '\n');
145  }
146  return k;
147 }
static std::string const input
Definition: EdmProvDump.cc:48
std::vector< FileHandle > theFileHandle

Member Data Documentation

HFShowerPhotonCollection HcalForwardLibWriter::emColl
private

Definition at line 55 of file HcalForwardLibWriter.h.

Referenced by analyze(), and HcalForwardLibWriter().

HFShowerLibraryEventInfo HcalForwardLibWriter::evtInfo
private

Definition at line 54 of file HcalForwardLibWriter.h.

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

Definition at line 50 of file HcalForwardLibWriter.h.

Referenced by endJob(), and HcalForwardLibWriter().

HFShowerPhotonCollection HcalForwardLibWriter::hadColl
private

Definition at line 56 of file HcalForwardLibWriter.h.

Referenced by analyze(), and HcalForwardLibWriter().

TFile* HcalForwardLibWriter::LibFile
private

Definition at line 47 of file HcalForwardLibWriter.h.

TTree* HcalForwardLibWriter::LibTree
private

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

std::string HcalForwardLibWriter::theDataFile
private

Definition at line 51 of file HcalForwardLibWriter.h.

Referenced by HcalForwardLibWriter(), and readUserData().

TFile* HcalForwardLibWriter::theFile
private

Definition at line 45 of file HcalForwardLibWriter.h.

Referenced by analyze().

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

Definition at line 52 of file HcalForwardLibWriter.h.

Referenced by analyze(), and readUserData().

TTree* HcalForwardLibWriter::theTree
private

Definition at line 46 of file HcalForwardLibWriter.h.

Referenced by analyze().