36 #include <Pythia8/Pythia.h>
41 #include "TLorentzVector.h"
43 #if PYTHIA_VERSION_INTEGER < 8304
70 std::map<int, TH1D*>
h_p;
71 std::map<int, TH1D*>
h_v;
104 pythia =
new Pythia8::Pythia();
119 for (
size_t i = 0;
i <
pids.size(); ++
i) {
123 if (!pdt.isParticle(pid)) {
124 std::cout <<
"ERROR: BAD PARTICLE, pythia is not aware of pid " << pid << std::endl;
130 double m0 = pd->m0();
131 double w = pd->mWidth();
134 mmin = m0 - m0 / 1000.;
135 mmax = m0 + m0 / 1000.;
140 std::stringstream strstr;
141 strstr <<
"mass_" << pid;
142 h_mass[pid] =
new TH1D(strstr.str().c_str(), strstr.str().c_str(), 100, mmin, mmax);
144 h_mass_ref[pid]->SetTitle(h_mass_ref[pid]->GetName());
146 h_mass_ref[pid]->Fill(m0);
148 for (
int b = 1;
b <= h_mass_ref[pid]->GetNbinsX(); ++
b) {
149 double _val = h_mass_ref[pid]->GetBinCenter(
b);
150 h_mass_ref[pid]->SetBinContent(
b, TMath::BreitWigner(_val, m0, w));
156 strstr <<
"p_" << pid;
157 h_p[pid] =
new TH1D(strstr.str().c_str(), strstr.str().c_str(), 100, 0, 20);
161 strstr <<
"v_" << pid;
162 h_v[pid] =
new TH1D(strstr.str().c_str(), strstr.str().c_str(), 100, 0, 1.);
165 double ctau0 = pd->tau0() / 10.;
167 strstr <<
"plt_" << pid;
168 h_plt[pid] =
new TH1D(strstr.str().c_str(), strstr.str().c_str(), 100, 0,
std::min(5. * ctau0, 500.));
169 h_plt_ref[pid] = (TH1D*)(
h_plt[pid]->Clone(strstr.str().c_str()));
170 h_plt_ref[pid]->SetTitle(h_plt_ref[pid]->GetName());
171 for (
int b = 1;
b <= h_plt_ref[pid]->GetNbinsX(); ++
b) {
172 double _val = h_plt_ref[pid]->GetBinCenter(
b);
173 h_plt_ref[pid]->SetBinContent(
b, TMath::Exp(-_val / ctau0));
178 strstr <<
"br_" << pid;
179 h_br[pid] =
new TH1D(strstr.str().c_str(), strstr.str().c_str(), 0, 0, 0);
180 h_br[pid]->SetCanExtend(TH1::kAllAxes);
181 h_br_ref[pid] = (TH1D*)(
h_br[pid]->Clone(strstr.str().c_str()));
184 for (
int d = 0;
d < pd->sizeChannels(); ++
d) {
185 Pythia8::DecayChannel& channel = pd->channel(
d);
186 std::vector<int> prod;
187 for (
int p = 0;
p < channel.multiplicity(); ++
p) {
188 int pId =
abs(channel.product(
p));
191 (pId > 10 && pId != 12 && pId != 14 && pId != 16 && pId != 18 && pId != 21 && (pId < 23 || pId > 40) &&
192 (pId < 81 || pId > 100) && pId != 2101 && pId != 3101 && pId != 3201 && pId != 1103 && pId != 2103 &&
193 pId != 2203 && pId != 3103 && pId != 3203 && pId != 3303);
195 prod.push_back(
abs(channel.product(
p)));
197 std::sort(prod.begin(), prod.end());
199 for (
size_t p = 0;
p < prod.size(); ++
p) {
200 strstr <<
"_" << prod[
p];
203 h_br[pid]->Fill(label.c_str(), 0.);
204 h_br_ref[pid]->Fill(label.c_str(), channel.bRatio());
205 h_br[pid]->SetEntries(0);
211 strstr <<
"originVertexRho_" << pid;
212 h_originVertexRho[pid] =
new TH1D(strstr.str().c_str(), strstr.str().c_str(), 100, 0, 200);
214 strstr <<
"originVertexZ_" << pid;
215 h_originVertexZ[pid] =
new TH1D(strstr.str().c_str(), strstr.str().c_str(), 100, 0, 400);
217 strstr <<
"decayVertexRho_" << pid;
218 h_decayVertexRho[pid] =
new TH1D(strstr.str().c_str(), strstr.str().c_str(), 100, 0, 200);
220 strstr <<
"decayVertexZ_" << pid;
221 h_decayVertexZ[pid] =
new TH1D(strstr.str().c_str(), strstr.str().c_str(), 100, 0, 400);
228 TFile*
f = TFile::Open(
outputFile.c_str(),
"RECREATE");
230 f->mkdir(
"observed");
231 f->mkdir(
"prediction");
232 for (
size_t i = 0;
i <
pids.size(); ++
i) {
264 iEvent.
getByLabel(
"famosSimHits", simvertices);
269 std::map<size_t, std::vector<size_t> > childMap;
270 std::map<size_t, int> parentMap;
271 for (
size_t j = 0;
j < simtracks->size();
j++) {
272 childMap[
j] = std::vector<size_t>();
277 for (
size_t j = 0;
j < simtracks->size();
j++) {
278 size_t childIndex =
j;
286 childMap[parentIndex].push_back(childIndex);
287 parentMap[childIndex] = int(parentIndex);
290 for (
size_t j = 0;
j < simtracks->size();
j++) {
309 if (!childMap[
j].
empty()) {
317 for (std::map<
size_t, std::vector<size_t> >::iterator it = childMap.begin(); it != childMap.end(); ++it) {
319 size_t parentIndex = it->first;
322 std::vector<size_t>& childIndices = it->second;
323 if (childIndices.empty())
330 const SimTrack& child0 = simtracks->at(childIndices[0]);
333 TLorentzVector lv_origin_vertex(origin_vertex.
position().X(),
337 TLorentzVector lv_decay_vertex(decay_vertex.
position().X(),
341 TLorentzVector lv_dist = lv_decay_vertex - lv_origin_vertex;
342 TLorentzVector lv_parent(
344 TVector3 boost = lv_parent.BoostVector();
345 lv_dist.Boost(-boost);
346 h_v[pid]->Fill(boost.Mag());
347 double plt = lv_dist.T();
348 h_plt[pid]->Fill(plt);
351 std::vector<int> prod;
352 for (
size_t d = 0;
d < childIndices.size(); ++
d) {
353 prod.push_back(
abs(simtracks->at(childIndices[
d]).type()));
355 std::sort(prod.begin(), prod.end());
356 std::stringstream strstr;
357 for (
size_t p = 0;
p < prod.size(); ++
p) {
358 strstr <<
"_" << prod[
p];
363 h_br[pid]->Fill(label.c_str(), 1.);
364 h_br_ref[pid]->Fill(label.c_str(), 0.);
std::map< int, TH1D * > h_plt
#define DEFINE_FWK_MODULE(type)
std::map< int, TH1D * > h_originVertexRho
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::map< int, TH1D * > h_plt_ref
std::map< int, TH1D * > h_br_ref
std::map< int, TH1D * > h_br
void analyze(const edm::Event &, const edm::EventSetup &) override
std::map< int, TH1D * > h_originVertexZ
std::map< int, TH1D * > h_p
void addDefault(ParameterSetDescription const &psetDescription)
std::map< int, TH1D * > h_mass
Abs< T >::type abs(const T &t)
const math::XYZTLorentzVectorD & position() const
HepPDT::ParticleData ParticleData
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
std::map< int, TH1D * > h_v
int vertIndex() const
index of the vertex in the Event container (-1 if no vertex)
std::map< int, std::vector< std::string > > knownDecayModes
std::map< int, TH1D * > h_decayVertexZ
T getParameter(std::string const &) const
TestPythiaDecays(const edm::ParameterSet &)
std::map< int, TH1D * > h_decayVertexRho
int type() const
particle type (HEP PDT convension)
~TestPythiaDecays() override
const math::XYZTLorentzVectorD & momentum() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::map< int, TH1D * > h_mass_ref
Pythia8::ParticleDataEntry * ParticleDataEntryPtr