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"
16 using namespace TauSpinner;
23 isReco_(pset.getParameter<bool>(
"isReco"))
24 ,isTauolaConfigured_(pset.getParameter<bool>(
"isTauolaConfigured" ))
25 ,isLHPDFConfigured_(pset.getParameter<bool>(
"isLHPDFConfigured" ))
26 ,LHAPDFname_(pset.getUntrackedParameter(
"LHAPDFname",(string)(
"MSTW2008nnlo90cl.LHgrid")))
27 ,CMSEnergy_(pset.getParameter<double>(
"CMSEnergy"))
28 ,gensrc_(pset.getParameter<edm::
InputTag>(
"gensrc"))
29 ,MotherPDGID_(pset.getUntrackedParameter(
"MotherPDGID",(int)(-1)))
30 ,Ipol_(pset.getUntrackedParameter(
"Ipol",(int)(0)))
31 ,nonSM2_(pset.getUntrackedParameter(
"nonSM2",(int)(0)))
32 ,nonSMN_(pset.getUntrackedParameter(
"nonSMN",(int)(0)))
33 ,roundOff_(pset.getUntrackedParameter(
"roundOff",(double)(0.01)))
35 produces<bool>(
"TauSpinnerWTisValid").setBranchAlias(
"TauSpinnerWTisValid");
36 produces<double>(
"TauSpinnerWT").setBranchAlias(
"TauSpinnerWT");
37 produces<double>(
"TauSpinnerWTFlip").setBranchAlias(
"TauSpinnerWTFlip");
38 produces<double>(
"TauSpinnerWThplus").setBranchAlias(
"TauSpinnerWThplus");
39 produces<double>(
"TauSpinnerWThminus").setBranchAlias(
"TauSpinnerWThminus");
48 <<
"The RandomNumberProducer module requires the RandomNumberGeneratorService\n"
49 "which appears to be absent. Please add that service to your configuration\n"
50 "or remove the modules that require it." << std::endl;
56 Tauolapp::Tauola::initialize();
76 SimpleParticle
X,
tau, tau2;
77 std::vector<SimpleParticle> tau_daughters, tau_daughters2;
85 const HepMC::GenEvent* Evt = EvtHandle->GetEvent() ;
91 if(
abs(X.pdgid())==24 ||
abs(X.pdgid())==37 ){
92 TLorentzVector tau_1r(0,0,0,0);
93 TLorentzVector tau_1(tau.px(),tau.py(),tau.pz(),tau.e());
94 for(
unsigned int i=0;
i<tau_daughters.size();
i++){
95 tau_1r+=TLorentzVector(tau_daughters.at(
i).px(),tau_daughters.at(
i).py(),tau_daughters.at(
i).pz(),tau_daughters.at(
i).e());
98 WT = TauSpinner::calculateWeightFromParticlesWorHpn(X, tau, tau2, tau_daughters);
103 else if( X.pdgid()==25 || X.pdgid()==36 || X.pdgid()==22 || X.pdgid()==23 ){
104 TLorentzVector tau_1r(0,0,0,0), tau_2r(0,0,0,0);
105 TLorentzVector tau_1(tau.px(),tau.py(),tau.pz(),tau.e()), tau_2(tau2.px(),tau2.py(),tau2.pz(),tau2.e());
106 for(
unsigned int i=0;
i<tau_daughters.size();
i++){
107 tau_1r+=TLorentzVector(tau_daughters.at(
i).px(),tau_daughters.at(
i).py(),tau_daughters.at(
i).pz(),tau_daughters.at(
i).e());
109 for(
unsigned int i=0;
i<tau_daughters2.size();
i++){
110 tau_2r+=TLorentzVector(tau_daughters2.at(
i).px(),tau_daughters2.at(
i).py(),tau_daughters2.at(
i).pz(),tau_daughters2.at(
i).e());
114 WT = TauSpinner::calculateWeightFromParticlesH(X, tau, tau2, tau_daughters,tau_daughters2);
117 if(X.pdgid()==25 || X.pdgid()==22 || X.pdgid()==23 ){
118 if(X.pdgid()==25) X.setPdgid(23);
119 if( X.pdgid()==22 || X.pdgid()==23 ) X.setPdgid(25);
121 double WTother=TauSpinner::calculateWeightFromParticlesH(X, tau, tau2, tau_daughters,tau_daughters2);
127 cout<<
"TauSpinner: WARNING: Unexpected PDG for tau mother: "<<X.pdgid()<<endl;
132 if(!(0<=WT && WT<10)){isValid=
false; WT=1.0; WTFlip=1.0;}
133 std::auto_ptr<bool> TauSpinnerWeightisValid(
new bool);
134 *TauSpinnerWeightisValid =isValid;
135 e.
put(TauSpinnerWeightisValid,
"TauSpinnerWTisValid");
138 std::auto_ptr<double> TauSpinnerWeight(
new double);
139 *TauSpinnerWeight =WT;
140 e.
put(TauSpinnerWeight,
"TauSpinnerWT");
143 std::auto_ptr<double> TauSpinnerWeightFlip(
new double);
144 *TauSpinnerWeightFlip =WTFlip;
145 e.
put(TauSpinnerWeightFlip,
"TauSpinnerWTFlip");
149 if(polSM<0.0 && polSM!=-999 && isValid) WThplus=0;
150 std::auto_ptr<double> TauSpinnerWeighthplus(
new double);
151 *TauSpinnerWeighthplus = WThplus;
152 e.
put(TauSpinnerWeighthplus,
"TauSpinnerWThplus");
156 if(polSM>0.0&& polSM!=-999 && isValid) WThminus=0;
157 std::auto_ptr<double> TauSpinnerWeighthminus(
new double);
158 *TauSpinnerWeighthminus = WThminus;
159 e.
put(TauSpinnerWeighthminus,
"TauSpinnerWThminus");
169 std::vector<SimpleParticle> &tau_daughters,std::vector<SimpleParticle> &tau2_daughters){
172 for(reco::GenParticleCollection::const_iterator itr = genParticles->begin(); itr!= genParticles->end(); ++itr){
173 int pdgid=
abs(itr->pdgId());
174 if(pdgid==24 || pdgid==37 || pdgid ==25 || pdgid==36 || pdgid==22 || pdgid==23 ){
180 unsigned int ntau(0),ntauornu(0);
181 for(
unsigned int i=0;
i<itr->numberOfDaughters();
i++){
185 if(ntau==0 &&
abs(dau->
pdgId())==15){
198 if((ntau==2 && ntauornu==2) || (ntau==1 && ntauornu==2)){
199 X.setPx(itr->p4().Px());
200 X.setPy(itr->p4().Py());
201 X.setPz(itr->p4().Pz());
202 X.setE (itr->p4().E());
203 X.setPdgid(itr->pdgId());
204 tau.setPx(recotau1->
p4().Px());
205 tau.setPy(recotau1->
p4().Py());
206 tau.setPz(recotau1->
p4().Pz());
207 tau.setE (recotau1->
p4().E());
208 tau.setPdgid(recotau1->
pdgId());
210 tau2.setPx(recotau2->
p4().Px());
211 tau2.setPy(recotau2->
p4().Py());
212 tau2.setPz(recotau2->
p4().Pz());
213 tau2.setE (recotau2->
p4().E());
214 tau2.setPdgid(recotau2->
pdgId());
245 SimpleParticle tp(Particle->
p4().Px(), Particle->
p4().Py(), Particle->
p4().Pz(), Particle->
p4().E(), Particle->
pdgId());
246 daughters.push_back(tp);
258 <<
"TauSpinnerCMS::flat: Attempt to generate random number when engine pointer is null\n"
259 <<
"This might mean that the code was modified to generate a random number outside the\n"
260 <<
"event and beginLuminosityBlock methods, which is not allowed.\n";
virtual int pdgId() const
PDG identifier.
void GetLastSelf(const reco::GenParticle *Particle)
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
#define DEFINE_FWK_MODULE(type)
bool isFirst(const reco::GenParticle *Particle)
int readParticlesFromHepMC(const HepMC::GenEvent *event, SimpleParticle &X, SimpleParticle &tau, SimpleParticle &tau2, std::vector< SimpleParticle > &tau_daughters, std::vector< SimpleParticle > &tau2_daughters)
static CLHEP::HepRandomEngine * fRandomEngine
void GetRecoDaughters(const reco::GenParticle *Particle, std::vector< TauSpinner::SimpleParticle > &daughters, int parentpdgid)
static bool isTauSpinnerConfigure
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
virtual size_t numberOfMothers() const
number of mothers
virtual size_t numberOfDaughters() const
number of daughters
virtual const Candidate * daughter(size_type) const
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
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 CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
virtual int pdgId() const =0
PDG identifier.
virtual void produce(edm::Event &, const edm::EventSetup &)
virtual void endRun(const edm::Run &, const edm::EventSetup &)
TauSpinnerCMS(const edm::ParameterSet &)
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
virtual const Candidate * mother(size_type=0) const
return mother at a given position, i = 0, ... numberOfMothers() - 1 (read only mode) ...