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"))
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;
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(
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);
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;
162 e.put(
std::move(TauSpinnerWeight),
"TauSpinnerWT");
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) {
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) {
210 recotau1 = static_cast<const reco::GenParticle *>(dau);
213 }
else if ((ntau == 1 &&
abs(dau->
pdgId()) == 15) ||
abs(dau->
pdgId()) == 16) {
214 recotau2 = static_cast<const reco::GenParticle *>(dau);
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());
236 tau2.setPx(recotau2->
p4().Px());
237 tau2.setPy(recotau2->
p4().Py());
238 tau2.setPz(recotau2->
p4().Pz());
239 tau2.setE(recotau2->
p4().E());
251 for (
unsigned int i = 0;
i <
Particle->numberOfDaughters();
i++) {
261 for (
unsigned int i = 0;
i <
Particle->numberOfMothers();
i++) {
279 for (
unsigned int i = 0;
i <
Particle->numberOfDaughters();
i++) {
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";