SimG4CMS
ShowerLibraryProducer
plugins
HcalForwardLibWriter.cc
Go to the documentation of this file.
1
#include "
SimG4CMS/ShowerLibraryProducer/interface/HcalForwardLibWriter.h
"
2
3
#include "TFile.h"
4
#include "TTree.h"
5
6
HcalForwardLibWriter::HcalForwardLibWriter
(
const
edm::ParameterSet
& iConfig) {
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
}
24
25
HcalForwardLibWriter::~HcalForwardLibWriter
() {}
26
27
void
HcalForwardLibWriter::analyze
(
const
edm::Event
&
iEvent
,
const
edm::EventSetup
& iSetup) {
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
}
115
116
void
HcalForwardLibWriter::beginJob
() {}
117
118
void
HcalForwardLibWriter::endJob
() {
119
fs
->
file
().cd();
120
LibTree
->Write();
121
LibTree
->Print();
122
}
123
124
int
HcalForwardLibWriter::readUserData
(
void
) {
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
}
148
//define this as a plug-in
149
DEFINE_FWK_MODULE
(
HcalForwardLibWriter
);
DDAxes::y
mps_fire.i
i
Definition:
mps_fire.py:355
input
static const std::string input
Definition:
EdmProvDump.cc:48
dqmiodumpmetadata.n
n
Definition:
dqmiodumpmetadata.py:28
HcalForwardLibWriter::hadColl
HFShowerPhotonCollection hadColl
Definition:
HcalForwardLibWriter.h:56
HcalForwardLibWriter::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition:
HcalForwardLibWriter.cc:27
HcalForwardLibWriter::HcalForwardLibWriter
HcalForwardLibWriter(const edm::ParameterSet &)
Definition:
HcalForwardLibWriter.cc:6
TFileService::file
TFile & file() const
return opened TFile
Definition:
TFileService.h:37
pos
Definition:
PixelAliasList.h:18
personalPlayback.fp
fp
Definition:
personalPlayback.py:523
HcalForwardLibWriter::endJob
void endJob() override
Definition:
HcalForwardLibWriter.cc:118
DDAxes::x
HcalForwardLibWriter::theFile
TFile * theFile
Definition:
HcalForwardLibWriter.h:45
HcalForwardLibWriter::theTree
TTree * theTree
Definition:
HcalForwardLibWriter.h:46
edm::FileInPath
Definition:
FileInPath.h:64
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition:
MakerMacros.h:16
DDAxes::z
HcalForwardLibWriter::theFileHandle
std::vector< FileHandle > theFileHandle
Definition:
HcalForwardLibWriter.h:52
GetRecoTauVFromDQM_MC_cff.kk
kk
Definition:
GetRecoTauVFromDQM_MC_cff.py:84
dqmdumpme.k
k
Definition:
dqmdumpme.py:60
OrderedSet.t
t
Definition:
OrderedSet.py:90
HcalForwardLibWriter::LibTree
TTree * LibTree
Definition:
HcalForwardLibWriter.h:48
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
HcalForwardLibWriter
Definition:
HcalForwardLibWriter.h:27
HFShowerPhoton::Point
math::XYZPointF Point
point in the space
Definition:
HFShowerPhoton.h:16
edm::ParameterSet
Definition:
ParameterSet.h:36
HcalForwardLibWriter::FileHandle::name
std::string name
Definition:
HcalForwardLibWriter.h:30
HcalForwardLibWriter::FileHandle::momentum
int momentum
Definition:
HcalForwardLibWriter.h:32
createfilelist.int
int
Definition:
createfilelist.py:10
iEvent
int iEvent
Definition:
GenABIO.cc:224
edm::EventSetup
Definition:
EventSetup.h:57
HcalForwardLibWriter::nbins
int nbins
Definition:
HcalForwardLibWriter.h:42
HcalForwardLibWriter.h
HcalForwardLibWriter::theDataFile
std::string theDataFile
Definition:
HcalForwardLibWriter.h:51
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
HcalForwardLibWriter::~HcalForwardLibWriter
~HcalForwardLibWriter() override
Definition:
HcalForwardLibWriter.cc:25
HcalForwardLibWriter::readUserData
int readUserData()
Definition:
HcalForwardLibWriter.cc:124
HFShowerPhoton
Definition:
HFShowerPhoton.h:13
HcalForwardLibWriter::beginJob
void beginJob() override
Definition:
HcalForwardLibWriter.cc:116
personalPlayback.fn
fn
Definition:
personalPlayback.py:515
HcalForwardLibWriter::FileHandle
Definition:
HcalForwardLibWriter.h:29
HcalForwardLibWriter::emColl
HFShowerPhotonCollection emColl
Definition:
HcalForwardLibWriter.h:55
HcalForwardLibWriter::fs
edm::Service< TFileService > fs
Definition:
HcalForwardLibWriter.h:50
edm::Event
Definition:
Event.h:73
HcalForwardLibWriter::FileHandle::id
std::string id
Definition:
HcalForwardLibWriter.h:31
HcalForwardLibWriter::nshowers
int nshowers
Definition:
HcalForwardLibWriter.h:43
Generated for CMSSW Reference Manual by
1.8.16