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;
26 ,isReco_(pset.getParameter<bool>(
"isReco"))
27 ,isTauolaConfigured_(pset.getParameter<bool>(
"isTauolaConfigured" ))
28 ,isLHPDFConfigured_(pset.getParameter<bool>(
"isLHPDFConfigured" ))
29 ,LHAPDFname_(pset.getUntrackedParameter(
"LHAPDFname",(
string)(
"MSTW2008nnlo90cl.LHgrid")))
30 ,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)))
41 produces<bool>(
"TauSpinnerWTisValid").setBranchAlias(
"TauSpinnerWTisValid");
42 produces<double>(
"TauSpinnerWT").setBranchAlias(
"TauSpinnerWT");
43 produces<double>(
"TauSpinnerWTFlip").setBranchAlias(
"TauSpinnerWTFlip");
44 produces<double>(
"TauSpinnerWThplus").setBranchAlias(
"TauSpinnerWThplus");
45 produces<double>(
"TauSpinnerWThminus").setBranchAlias(
"TauSpinnerWThminus");
91 SimpleParticle
X,
tau, tau2;
92 std::vector<SimpleParticle> tau_daughters, tau_daughters2;
101 HepMC::GenEvent *Evt =
new HepMC::GenEvent(*(evt->GetEvent()));
107 if(
abs(X.pdgid())==24 ||
abs(X.pdgid())==37 ){
108 TLorentzVector tau_1r(0,0,0,0);
109 TLorentzVector tau_1(tau.px(),tau.py(),tau.pz(),tau.e());
110 for(
unsigned int i=0;
i<tau_daughters.size();
i++){
111 tau_1r+=TLorentzVector(tau_daughters.at(
i).px(),tau_daughters.at(
i).py(),tau_daughters.at(
i).pz(),tau_daughters.at(
i).e());
113 if(fabs(tau_1r.M()-tau_1.M())<
roundOff_){
114 WT = TauSpinner::calculateWeightFromParticlesWorHpn(X, tau, tau2, tau_daughters);
119 else if( X.pdgid()==25 || X.pdgid()==36 || X.pdgid()==22 || X.pdgid()==23 ){
120 TLorentzVector tau_1r(0,0,0,0), tau_2r(0,0,0,0);
121 TLorentzVector tau_1(tau.px(),tau.py(),tau.pz(),tau.e()), tau_2(tau2.px(),tau2.py(),tau2.pz(),tau2.e());
122 for(
unsigned int i=0;
i<tau_daughters.size();
i++){
123 tau_1r+=TLorentzVector(tau_daughters.at(
i).px(),tau_daughters.at(
i).py(),tau_daughters.at(
i).pz(),tau_daughters.at(
i).e());
125 for(
unsigned int i=0;
i<tau_daughters2.size();
i++){
126 tau_2r+=TLorentzVector(tau_daughters2.at(
i).px(),tau_daughters2.at(
i).py(),tau_daughters2.at(
i).pz(),tau_daughters2.at(
i).e());
130 WT = TauSpinner::calculateWeightFromParticlesH(X, tau, tau2, tau_daughters,tau_daughters2);
133 if(X.pdgid()==25 || X.pdgid()==22 || X.pdgid()==23 ){
134 if(X.pdgid()==25) X.setPdgid(23);
135 if( X.pdgid()==22 || X.pdgid()==23 ) X.setPdgid(25);
137 double WTother=TauSpinner::calculateWeightFromParticlesH(X, tau, tau2, tau_daughters,tau_daughters2);
143 cout<<
"TauSpinner: WARNING: Unexpected PDG for tau mother: "<<X.pdgid()<<endl;
148 if(!(0<=WT && WT<10)){isValid=
false; WT=1.0; WTFlip=1.0;}
149 std::auto_ptr<bool> TauSpinnerWeightisValid(
new bool);
150 *TauSpinnerWeightisValid =isValid;
151 e.
put(TauSpinnerWeightisValid,
"TauSpinnerWTisValid");
154 std::auto_ptr<double> TauSpinnerWeight(
new double);
155 *TauSpinnerWeight =WT;
156 e.
put(TauSpinnerWeight,
"TauSpinnerWT");
159 std::auto_ptr<double> TauSpinnerWeightFlip(
new double);
160 *TauSpinnerWeightFlip =WTFlip;
161 e.
put(TauSpinnerWeightFlip,
"TauSpinnerWTFlip");
165 if(polSM<0.0 && polSM!=-999 && isValid) WThplus=0;
166 std::auto_ptr<double> TauSpinnerWeighthplus(
new double);
167 *TauSpinnerWeighthplus = WThplus;
168 e.
put(TauSpinnerWeighthplus,
"TauSpinnerWThplus");
172 if(polSM>0.0&& polSM!=-999 && isValid) WThminus=0;
173 std::auto_ptr<double> TauSpinnerWeighthminus(
new double);
174 *TauSpinnerWeighthminus = WThminus;
175 e.
put(TauSpinnerWeighthminus,
"TauSpinnerWThminus");
184 std::vector<SimpleParticle> &tau_daughters,std::vector<SimpleParticle> &tau2_daughters){
187 for(reco::GenParticleCollection::const_iterator itr = genParticles->begin(); itr!= genParticles->end(); ++itr){
188 int pdgid=
abs(itr->pdgId());
189 if(pdgid==24 || pdgid==37 || pdgid ==25 || pdgid==36 || pdgid==22 || pdgid==23 ){
195 unsigned int ntau(0),ntauornu(0);
196 for(
unsigned int i=0;
i<itr->numberOfDaughters();
i++){
200 if(ntau==0 &&
abs(dau->
pdgId())==15){
213 if((ntau==2 && ntauornu==2) || (ntau==1 && ntauornu==2)){
214 X.setPx(itr->p4().Px());
215 X.setPy(itr->p4().Py());
216 X.setPz(itr->p4().Pz());
217 X.setE (itr->p4().E());
218 X.setPdgid(itr->pdgId());
219 tau.setPx(recotau1->
p4().Px());
220 tau.setPy(recotau1->
p4().Py());
221 tau.setPz(recotau1->
p4().Pz());
222 tau.setE (recotau1->
p4().E());
223 tau.setPdgid(recotau1->
pdgId());
225 tau2.setPx(recotau2->
p4().Px());
226 tau2.setPy(recotau2->
p4().Py());
227 tau2.setPz(recotau2->
p4().Pz());
228 tau2.setE (recotau2->
p4().E());
229 tau2.setPdgid(recotau2->
pdgId());
260 SimpleParticle tp(Particle->
p4().Px(), Particle->
p4().Py(), Particle->
p4().Pz(), Particle->
p4().E(), Particle->
pdgId());
261 daughters.push_back(tp);
274 <<
"TauSpinnerCMS::flat: Attempt to generate random number when engine pointer is null\n"
275 <<
"This might mean that the code was modified to generate a random number outside the\n"
276 <<
"event and beginLuminosityBlock methods, which is not allowed.\n";
static AlgebraicMatrix initialize()
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) ...
edm::EDGetTokenT< edm::HepMCProduct > hepmcCollectionToken_
virtual const LorentzVector & p4() const GCC11_FINAL
four-momentum Lorentz vector
bool getByToken(EDGetToken token, Handle< PROD > &result) const
virtual int pdgId() const GCC11_FINAL
PDG identifier.
#define DEFINE_FWK_MODULE(type)
virtual void initialize()
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)
virtual void produce(edm::Event &, const edm::EventSetup &) overridefinal
static const std::string kTauola
static CLHEP::HepRandomEngine * fRandomEngine
edm::EDGetTokenT< reco::GenParticleCollection > GenParticleCollectionToken_
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 void beginJob() overridefinal
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) ...
virtual void endLuminosityBlockProduce(edm::LuminosityBlock &lumiSeg, const edm::EventSetup &iSetup)
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.
virtual void endRun(const edm::Run &, const edm::EventSetup &)
return(e1-e2)*(e1-e2)+dp *dp
TauSpinnerCMS(const edm::ParameterSet &)
StreamID streamID() const
virtual void endJob() overridefinal
virtual const Candidate * mother(size_type=0) const
return mother at a given position, i = 0, ... numberOfMothers() - 1 (read only mode) ...