4 #include "Tauola/Tauola.h"
5 #include "TauSpinner/tau_reweight_lib.h"
6 #include "TauSpinner/Tauola_wrapper.h"
8 #include "TLorentzVector.h"
10 #include "CLHEP/Random/RandomEngine.h"
17 using namespace TauSpinner;
25 isReco_(pset.getParameter<bool>(
"isReco")),
26 isTauolaConfigured_(pset.getParameter<bool>(
"isTauolaConfigured")),
27 isLHPDFConfigured_(pset.getParameter<bool>(
"isLHPDFConfigured")),
28 LHAPDFname_(pset.getUntrackedParameter(
"LHAPDFname", (
string)(
"MSTW2008nnlo90cl.LHgrid"))),
29 CMSEnergy_(pset.getParameter<double>(
"CMSEnergy"))
31 gensrc_(pset.getParameter<edm::
InputTag>(
"gensrc")),
32 MotherPDGID_(pset.getUntrackedParameter(
"MotherPDGID", (int)(-1))),
33 Ipol_(pset.getUntrackedParameter(
"Ipol", (int)(0))),
34 nonSM2_(pset.getUntrackedParameter(
"nonSM2", (int)(0))),
35 nonSMN_(pset.getUntrackedParameter(
"nonSMN", (int)(0))),
36 roundOff_(pset.getUntrackedParameter(
"roundOff", (double)(0.01))) {
40 produces<bool>(
"TauSpinnerWTisValid").setBranchAlias(
"TauSpinnerWTisValid");
41 produces<double>(
"TauSpinnerWT").setBranchAlias(
"TauSpinnerWT");
42 produces<double>(
"TauSpinnerWTFlip").setBranchAlias(
"TauSpinnerWTFlip");
43 produces<double>(
"TauSpinnerWThplus").setBranchAlias(
"TauSpinnerWThplus");
44 produces<double>(
"TauSpinnerWThminus").setBranchAlias(
"TauSpinnerWThminus");
82 Tauolapp::Tauola::setRandomGenerator(
84 Tauolapp::jaki_.ktom = 1;
88 SimpleParticle
X,
tau, tau2;
89 std::vector<SimpleParticle> tau_daughters, tau_daughters2;
103 if (
abs(X.pdgid()) == 24 ||
abs(X.pdgid()) == 37) {
104 TLorentzVector tau_1r(0, 0, 0, 0);
105 TLorentzVector tau_1(tau.px(), tau.py(), tau.pz(), tau.e());
106 for (
unsigned int i = 0;
i < tau_daughters.size();
i++) {
107 tau_1r += TLorentzVector(
108 tau_daughters.at(
i).px(), tau_daughters.at(
i).py(), tau_daughters.at(
i).pz(), tau_daughters.at(
i).e());
110 if (fabs(tau_1r.M() - tau_1.M()) <
roundOff_) {
111 WT = TauSpinner::calculateWeightFromParticlesWorHpn(
112 X, tau, tau2, tau_daughters);
113 polSM = getTauSpin();
114 WTFlip = (2.0 - WT) / WT;
116 }
else if (X.pdgid() == 25 || X.pdgid() == 36 || X.pdgid() == 22 || X.pdgid() == 23) {
117 TLorentzVector tau_1r(0, 0, 0, 0), tau_2r(0, 0, 0, 0);
118 TLorentzVector tau_1(tau.px(), tau.py(), tau.pz(), tau.e()), tau_2(tau2.px(), tau2.py(), tau2.pz(), tau2.e());
119 for (
unsigned int i = 0;
i < tau_daughters.size();
i++) {
120 tau_1r += TLorentzVector(
121 tau_daughters.at(
i).px(), tau_daughters.at(
i).py(), tau_daughters.at(
i).pz(), tau_daughters.at(
i).e());
123 for (
unsigned int i = 0;
i < tau_daughters2.size();
i++) {
124 tau_2r += TLorentzVector(tau_daughters2.at(
i).px(),
125 tau_daughters2.at(
i).py(),
126 tau_daughters2.at(
i).pz(),
127 tau_daughters2.at(
i).e());
130 if (fabs(tau_1r.M() - tau_1.M()) <
roundOff_ && fabs(tau_2r.M() - tau_2.M()) <
roundOff_) {
131 WT = TauSpinner::calculateWeightFromParticlesH(X, tau, tau2, tau_daughters, tau_daughters2);
133 polSM = getTauSpin();
134 if (X.pdgid() == 25 || X.pdgid() == 22 || X.pdgid() == 23) {
137 if (X.pdgid() == 22 || X.pdgid() == 23)
140 double WTother = TauSpinner::calculateWeightFromParticlesH(X, tau, tau2, tau_daughters, tau_daughters2);
141 WTFlip = WTother / WT;
145 cout <<
"TauSpinner: WARNING: Unexpected PDG for tau mother: " << X.pdgid() << endl;
150 if (!(0 <= WT && WT < 10)) {
155 std::unique_ptr<bool> TauSpinnerWeightisValid(
new bool);
156 *TauSpinnerWeightisValid =
isValid;
157 e.
put(
std::move(TauSpinnerWeightisValid),
"TauSpinnerWTisValid");
160 std::unique_ptr<double> TauSpinnerWeight(
new double);
161 *TauSpinnerWeight = WT;
165 std::unique_ptr<double> TauSpinnerWeightFlip(
new double);
166 *TauSpinnerWeightFlip = WTFlip;
167 e.
put(
std::move(TauSpinnerWeightFlip),
"TauSpinnerWTFlip");
171 if (polSM < 0.0 && polSM != -999 && isValid)
173 std::unique_ptr<double> TauSpinnerWeighthplus(
new double);
174 *TauSpinnerWeighthplus = WThplus;
175 e.
put(
std::move(TauSpinnerWeighthplus),
"TauSpinnerWThplus");
178 double WThminus = WT;
179 if (polSM > 0.0 && polSM != -999 && isValid)
181 std::unique_ptr<double> TauSpinnerWeighthminus(
new double);
182 *TauSpinnerWeighthminus = WThminus;
183 e.
put(
std::move(TauSpinnerWeighthminus),
"TauSpinnerWThminus");
190 SimpleParticle &tau2,
191 std::vector<SimpleParticle> &tau_daughters,
192 std::vector<SimpleParticle> &tau2_daughters) {
195 for (reco::GenParticleCollection::const_iterator itr = genParticles->begin(); itr != genParticles->end(); ++itr) {
196 int pdgid =
abs(itr->pdgId());
197 if (pdgid == 24 || pdgid == 37 || pdgid == 25 || pdgid == 36 || pdgid == 22 || pdgid == 23) {
204 unsigned int ntau(0), ntauornu(0);
205 for (
unsigned int i = 0;
i < itr->numberOfDaughters();
i++) {
209 if (ntau == 0 &&
abs(dau->
pdgId()) == 15) {
213 }
else if ((ntau == 1 &&
abs(dau->
pdgId()) == 15) ||
abs(dau->
pdgId()) == 16) {
224 if ((ntau == 2 && ntauornu == 2) || (ntau == 1 && ntauornu == 2)) {
225 X.setPx(itr->p4().Px());
226 X.setPy(itr->p4().Py());
227 X.setPz(itr->p4().Pz());
228 X.setE(itr->p4().E());
229 X.setPdgid(itr->pdgId());
230 tau.setPx(recotau1->
p4().Px());
231 tau.setPy(recotau1->
p4().Py());
232 tau.setPz(recotau1->
p4().Pz());
233 tau.setE(recotau1->
p4().E());
234 tau.setPdgid(recotau1->
pdgId());
236 tau2.setPx(recotau2->
p4().Px());
237 tau2.setPy(recotau2->
p4().Py());
238 tau2.setPz(recotau2->
p4().Pz());
239 tau2.setE(recotau2->
p4().E());
240 tau2.setPdgid(recotau2->
pdgId());
271 std::vector<SimpleParticle> &daughters,
275 Particle->
p4().Px(), Particle->
p4().Py(), Particle->
p4().Pz(), Particle->
p4().E(), Particle->
pdgId());
276 daughters.push_back(
tp);
288 <<
"TauSpinnerCMS::flat: Attempt to generate random number when engine pointer is null\n"
289 <<
"This might mean that the code was modified to generate a random number outside the\n"
290 <<
"event and beginLuminosityBlock methods, which is not allowed.\n";
static AlgebraicMatrix initialize()
void GetLastSelf(const reco::GenParticle *Particle)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
const Candidate * mother(size_type=0) const override
return mother at a given position, i = 0, ... numberOfMothers() - 1 (read only mode) ...
edm::EDGetTokenT< edm::HepMCProduct > hepmcCollectionToken_
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
void produce(edm::Event &, const edm::EventSetup &) final
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
virtual void initialize()
bool isFirst(const reco::GenParticle *Particle)
size_t numberOfDaughters() const override
number of daughters
static const std::string kTauola
size_t numberOfMothers() const override
number of mothers
static CLHEP::HepRandomEngine * fRandomEngine
const LorentzVector & p4() const final
four-momentum Lorentz vector
edm::EDGetTokenT< reco::GenParticleCollection > GenParticleCollectionToken_
int pdgId() const final
PDG identifier.
void GetRecoDaughters(const reco::GenParticle *Particle, std::vector< TauSpinner::SimpleParticle > &daughters, int parentpdgid)
static bool isTauSpinnerConfigure
Abs< T >::type abs(const T &t)
int readParticlesfromReco(edm::Event &e, TauSpinner::SimpleParticle &X, TauSpinner::SimpleParticle &tau, TauSpinner::SimpleParticle &tau2, std::vector< TauSpinner::SimpleParticle > &tau_daughters, std::vector< TauSpinner::SimpleParticle > &tau2_daughters)
virtual int pdgId() const =0
PDG identifier.
int readParticlesFromHepMC(const HepMC::GenEvent *event, TauSpinner::SimpleParticle &X, TauSpinner::SimpleParticle &tau, TauSpinner::SimpleParticle &tau2, std::vector< TauSpinner::SimpleParticle > &tau_daughters, std::vector< TauSpinner::SimpleParticle > &tau2_daughters)
TauSpinnerCMS(const edm::ParameterSet &)
StreamID streamID() const
const Candidate * daughter(size_type) const override
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...