diff --git a/MELA/interface/MELACandidate.h b/MELA/interface/MELACandidate.h index 0dd0c26f..da5b4b3e 100755 --- a/MELA/interface/MELACandidate.h +++ b/MELA/interface/MELACandidate.h @@ -41,6 +41,9 @@ class MELACandidate : public MELAParticle{ const std::vector& getAssociatedJets()const; const std::vector& getAssociatedTops()const; + std::vector getAssociatedSortedVs(); + std::vector getAssociatedSortedVs()const; + void getRelatedParticles(std::vector& particles); TLorentzVector getAlternativeVMomentum(int index)const; diff --git a/MELA/interface/MELAParticle.h b/MELA/interface/MELAParticle.h index 781db2ca..98cfa7be 100755 --- a/MELA/interface/MELAParticle.h +++ b/MELA/interface/MELAParticle.h @@ -58,6 +58,8 @@ class MELAParticle{ std::vector& getDaughters(){ return daughters; } const std::vector& getMothers()const{ return mothers; } const std::vector& getDaughters()const{ return daughters; } + bool hasMother(MELAParticle const* part) const; + bool hasDaughter(MELAParticle const* part) const; double charge()const; double m()const{ return p4.M(); } @@ -84,7 +86,7 @@ class MELAParticle{ MELAParticle& operator+=(const TLorentzVector& mom){ p4 += mom; return *this; } // Helper functions - static bool checkParticleExists(MELAParticle* myParticle, std::vector& particleArray); + static bool checkParticleExists(MELAParticle const* myParticle, std::vector const& particleArray); }; diff --git a/MELA/src/MELACandidate.cc b/MELA/src/MELACandidate.cc index ca241607..646b57ef 100755 --- a/MELA/src/MELACandidate.cc +++ b/MELA/src/MELACandidate.cc @@ -1,3 +1,4 @@ +#include #include #include #include "MELACandidate.h" @@ -190,6 +191,31 @@ const std::vector& MELACandidate::getAssociatedPhotons()const{ re const std::vector& MELACandidate::getAssociatedJets()const{ return associatedJets; } const std::vector& MELACandidate::getAssociatedTops()const{ return associatedTops; } +std::vector MELACandidate::getAssociatedSortedVs(){ + std::vector res; + std::vector::iterator itBegin; + std::vector::iterator itEnd=sortedVs.end(); + for (std::vector::iterator it=sortedVs.begin(); it!=itEnd; it++){ + bool doSkip=false; + for (auto const& dau:sortedDaughters){ if ((*it)->hasDaughter(dau)){ doSkip=true; break; } } + if (!doSkip){ itBegin=it; break; } + } + std::copy(itBegin, itEnd, std::back_inserter(res)); + return res; +} +std::vector MELACandidate::getAssociatedSortedVs()const{ + std::vector res; + std::vector::const_iterator itBegin; + std::vector::const_iterator itEnd=sortedVs.cend(); + for (std::vector::const_iterator it=sortedVs.cbegin(); it!=itEnd; it++){ + bool doSkip=false; + for (auto const& dau:sortedDaughters){ if ((*it)->hasDaughter(dau)){ doSkip=true; break; } } + if (!doSkip){ itBegin=it; break; } + } + std::copy(itBegin, itEnd, std::back_inserter(res)); + return res; +} + void MELACandidate::sortDaughtersInitial(){ bool beginWithIdPair = ( selfDecayMode==TVar::CandidateDecay_ZZ diff --git a/MELA/src/MELAParticle.cc b/MELA/src/MELAParticle.cc index 693bb5ca..0cbae053 100755 --- a/MELA/src/MELAParticle.cc +++ b/MELA/src/MELAParticle.cc @@ -81,6 +81,9 @@ void MELAParticle::getRelatedParticles(std::vector& particles){ if (!checkParticleExists(this, particles)) particles.push_back(this); } +bool MELAParticle::hasMother(MELAParticle const* part) const{ return MELAParticle::checkParticleExists(part, mothers); } +bool MELAParticle::hasDaughter(MELAParticle const* part) const{ return MELAParticle::checkParticleExists(part, daughters); } + double MELAParticle::charge()const{ double cpos=0; if (isAWBoson(id) || abs(id)==37 || abs(id)==2212 || abs(id)==211 || abs(id)==321 || abs(id)==411 || abs(id)==521) cpos = 1.; @@ -107,7 +110,7 @@ void MELAParticle::boost(const TVector3& vec, bool boostAll){ << std::endl; } -bool MELAParticle::checkParticleExists(MELAParticle* myParticle, std::vector& particleArray){ - for (auto& part : particleArray){ if (part==myParticle) return true; } +bool MELAParticle::checkParticleExists(MELAParticle const* myParticle, std::vector const& particleArray){ + for (MELAParticle* const& part : particleArray){ if (part==myParticle) return true; } return false; } diff --git a/MELA/src/Mela.cc b/MELA/src/Mela.cc index 90d000c9..e30f4040 100755 --- a/MELA/src/Mela.cc +++ b/MELA/src/Mela.cc @@ -952,13 +952,15 @@ void Mela::computeP( } if (myVerbosity_>=TVar::DEBUG){ // Summarize the integrated particles MELAout << "Mela::computeP: hs, Phi1 are now " << hs_val << " " << phi1_val << endl; - for (unsigned int idau=0; idau #include #include +#include #include #include #include @@ -2029,9 +2030,9 @@ bool TUtil::MCFM_SetupParticleCouplings( if (useQQVVQQany){ // Special case if using qqZZ/VVqq* if (verbosity>=TVar::DEBUG) MELAout << "TUtil::MCFM_SetupParticleCouplings: Setting up mother labels for MCFM:"; for (int ip=0; ip=TVar::DEBUG) MELAout << " " << *idmot << "=" << strplabel[ip]; + const int& idmot = mela_event.pMothers.at(ip).first; + if (!PDGHelpers::isAnUnknownJet(idmot)) strplabel[ip]=TUtil::GetMCFMParticleLabel(idmot, false, useQQVVQQany); + if (verbosity>=TVar::DEBUG) MELAout << " " << idmot << "=" << strplabel[ip]; // No need to check unknown parton case, already "pp" } if (verbosity>=TVar::DEBUG) MELAout << endl; @@ -6329,7 +6330,7 @@ double TUtil::VHiggsMatEl( } if (verbosity>=TVar::DEBUG){ MELAout << "TUtil::VHiggsMatEl: Incoming partons to compute for the ME template:" << endl; - for (unsigned int ip=0; ip=TVar::DEBUG){ MELAout << "TUtil::VHiggsMatEl: Outgoing particles to compute for the ME template:" << endl; - for (unsigned int op=0; op=TVar::DEBUG) MELAout << "\tIncoming " << vh_ids[0] << "," << vh_ids[1] << " -> " << vh_ids[2] << endl; @@ -6396,9 +6397,9 @@ double TUtil::VHiggsMatEl( double Vckmsq_in = pow(__modparameters_MOD_ckmbare(&(vh_ids[0]), &(vh_ids[1])), 2); if (verbosity>=TVar::DEBUG) MELAout << "\tNeed to divide the ME by |VCKM_incoming|**2 = " << Vckmsq_in << endl; - for (unsigned int op=0; op=TVar::DEBUG) MELAout << "\t\tOutgoing " << vh_ids[3] << " -> " << vh_ids[5] << "," << vh_ids[6] << endl; @@ -6498,7 +6499,7 @@ double TUtil::VHiggsMatEl( incomingPartons.push_back(pair(-MYIDUP_prod[1], MYIDUP_prod[1])); // -id2, id2 if (verbosity>=TVar::DEBUG){ MELAout << "TUtil::VHiggsMatEl: Incoming partons to compute for the ME template:" << endl; - for (unsigned int ip=0; ip Gamma + H should also have the id of the Z! if (verbosity>=TVar::DEBUG) MELAout << "\tIncoming " << vh_ids[0] << "," << vh_ids[1] << " -> " << vh_ids[2] << endl; // Scale for the incoming state is 1 - for (unsigned int op=0; op=TVar::DEBUG) MELAout << "TUtil::GetBoostedParticleVectors: aVhypo!=0 case start" << endl; - int nsortedvsstart=(melaCand->getDecayMode()!=TVar::CandidateDecay_Stable ? 2 : 0); - for (int iv=nsortedvsstart; ivgetNSortedVs(); iv++){ // Loop over associated Vs - MELAParticle* Vdau = melaCand->getSortedV(iv); + vector asortedVs = melaCand->getAssociatedSortedVs(); + for (MELAParticle* Vdau:asortedVs){ // Loop over associated Vs if (Vdau!=0){ bool doAdd=false; int idV = Vdau->id; if ((abs(idV)==aVhypo || idV==0) && Vdau->getNDaughters()>0 && Vdau->passSelection){ // If the V is unknown or compatible with the requested hypothesis doAdd=true; - for (int ivd=0; ivdgetNDaughters(); ivd++){ // Loop over the daughters of V - MELAParticle* Vdau_i = Vdau->getDaughter(ivd); + for (MELAParticle* Vdau_i:Vdau->getDaughters()){ // Loop over the daughters of V if (Vdau_i==0){ doAdd=false; break; } else if ( (mela_event.nRequested_AssociatedLeptons==0 && (PDGHelpers::isALepton(Vdau_i->id) || PDGHelpers::isANeutrino(Vdau_i->id))) @@ -7488,11 +7487,9 @@ void TUtil::GetBoostedParticleVectors( if (verbosity>=TVar::DEBUG) MELAout << "TUtil::GetBoostedParticleVectors: candidateVs size = " << candidateVs.size() << endl; // Pick however many candidates necessary to fill up the requested number of jets or lepton(+)neutrinos - for (unsigned int iv=0; ivgetNDaughters(); ivd++){ // Loop over the daughters of V - MELAParticle* part = Vdau->getDaughter(ivd); + for (MELAParticle* part:Vdau->getDaughters()){ // Loop over the daughters of V if ( part->passSelection && @@ -7536,7 +7533,7 @@ void TUtil::GetBoostedParticleVectors( associated_tmp.at(associated_tmp.size()-1).second = corrPair.first; } } - for (unsigned int ias=0; ias=TVar::DEBUG) MELAout << "TUtil::GetBoostedParticleVectors: aVhypo!=0 case associated.size=" << associated.size() << endl; @@ -7547,8 +7544,7 @@ void TUtil::GetBoostedParticleVectors( if (code%TVar::kUseAssociated_Leptons==0){ SimpleParticleCollection_t associated_tmp; - for (int ip=0; ipgetNAssociatedLeptons(); ip++){ - MELAParticle* part = melaCand->getAssociatedLepton(ip); + for (MELAParticle* part:melaCand->getAssociatedLeptons()){ if (part!=0 && part->passSelection && nsatisfied_lnusid, part->p4)); @@ -7579,13 +7575,12 @@ void TUtil::GetBoostedParticleVectors( associated_tmp.at(associated_tmp.size()-1).second = corrPair.first; } } - for (unsigned int ias=0; iasgetNAssociatedJets(); ip++){ - MELAParticle* part = melaCand->getAssociatedJet(ip); + for (MELAParticle* part:melaCand->getAssociatedJets()){ if (part!=0 && part->passSelection && nsatisfied_jetsid, part->p4)); @@ -7616,14 +7611,13 @@ void TUtil::GetBoostedParticleVectors( associated_tmp.at(associated_tmp.size()-1).second = corrPair.first; } } - for (unsigned int ias=0; iasgetNAssociatedPhotons(); ip++){ - MELAParticle* part = melaCand->getAssociatedPhoton(ip); + for (MELAParticle* part:melaCand->getAssociatedPhotons()){ if (part!=0 && part->passSelection && nsatisfied_gammasid, part->p4)); @@ -7648,8 +7642,7 @@ void TUtil::GetBoostedParticleVectors( if (code%TVar::kUseAssociated_StableTops==0 && code%TVar::kUseAssociated_UnstableTops==0 && verbosity>=TVar::INFO) MELAerr << "TUtil::GetBoostedParticleVectors: Stable and unstable tops are not supported at the same time!" << endl; else if (code%TVar::kUseAssociated_StableTops==0 || code%TVar::kUseAssociated_UnstableTops==0){ - for (int itop=0; itopgetNAssociatedTops(); itop++){ - MELATopCandidate* theTop = melaCand->getAssociatedTop(itop); + for (MELATopCandidate* theTop:melaCand->getAssociatedTops()){ if (theTop!=0 && theTop->passSelection){ vector* particleArray; if (theTop->id==6) particleArray = &tops; @@ -7665,8 +7658,7 @@ void TUtil::GetBoostedParticleVectors( if (verbosity>=TVar::DEBUG){ MELAout << "TUtil::GetBoostedParticleVectors: tops.size=" << tops.size() << ", topbars.size=" << topbars.size() << ", unknowntops.size=" << unknowntops.size() << endl; } // Fill the stable/unstable top arrays - for (unsigned int itop=0; itopid, theTop->p4)); @@ -7686,8 +7678,7 @@ void TUtil::GetBoostedParticleVectors( if (vdaughters.size()==3) topDaughters.push_back(vdaughters); } } - for (unsigned int itop=0; itopid, theTop->p4)); @@ -7708,48 +7699,46 @@ void TUtil::GetBoostedParticleVectors( } else break; } - if (unknowntops.size()!=0){ // Loops over te unknown-id tops - // Fill tops, then antitops from the unknown tops - for (unsigned int itop=0; itopid, theTop->p4)); - } - else if (code%TVar::kUseAssociated_StableTops==0 && nsatisfied_antitopsid, theTop->p4)); - } - // t, then tb cases with daughters needed - else if (code%TVar::kUseAssociated_UnstableTops==0 && nsatisfied_topsgetLightQuark(); - MELAParticle* Wf = theTop->getWFermion(); - MELAParticle* Wfb = theTop->getWAntifermion(); - if (bottom!=0) vdaughters.push_back(SimpleParticle_t(bottom->id, bottom->p4)); - if (Wf!=0) vdaughters.push_back(SimpleParticle_t(Wf->id, Wf->p4)); - if (Wfb!=0) vdaughters.push_back(SimpleParticle_t(Wfb->id, Wfb->p4)); - - TUtil::adjustTopDaughters(vdaughters); // Adjust top daughter kinematics - if (vdaughters.size()==3) topDaughters.push_back(vdaughters); - } - else if (code%TVar::kUseAssociated_UnstableTops==0 && nsatisfied_antitopsgetLightQuark(); - MELAParticle* Wf = theTop->getWFermion(); - MELAParticle* Wfb = theTop->getWAntifermion(); - if (bottom!=0) vdaughters.push_back(SimpleParticle_t(bottom->id, bottom->p4)); - if (Wf!=0) vdaughters.push_back(SimpleParticle_t(Wf->id, Wf->p4)); - if (Wfb!=0) vdaughters.push_back(SimpleParticle_t(Wfb->id, Wfb->p4)); - - TUtil::adjustTopDaughters(vdaughters); // Adjust top daughter kinematics - if (vdaughters.size()==3) antitopDaughters.push_back(vdaughters); - } + // Loop over the unknown-id tops + // Fill tops, then antitops from the unknown tops + for (MELATopCandidate* theTop:unknowntops){ + // t, then tb cases with no daughters needed + if (code%TVar::kUseAssociated_StableTops==0 && nsatisfied_topsid, theTop->p4)); + } + else if (code%TVar::kUseAssociated_StableTops==0 && nsatisfied_antitopsid, theTop->p4)); + } + // t, then tb cases with daughters needed + else if (code%TVar::kUseAssociated_UnstableTops==0 && nsatisfied_topsgetLightQuark(); + MELAParticle* Wf = theTop->getWFermion(); + MELAParticle* Wfb = theTop->getWAntifermion(); + if (bottom!=0) vdaughters.push_back(SimpleParticle_t(bottom->id, bottom->p4)); + if (Wf!=0) vdaughters.push_back(SimpleParticle_t(Wf->id, Wf->p4)); + if (Wfb!=0) vdaughters.push_back(SimpleParticle_t(Wfb->id, Wfb->p4)); + + TUtil::adjustTopDaughters(vdaughters); // Adjust top daughter kinematics + if (vdaughters.size()==3) topDaughters.push_back(vdaughters); + } + else if (code%TVar::kUseAssociated_UnstableTops==0 && nsatisfied_antitopsgetLightQuark(); + MELAParticle* Wf = theTop->getWFermion(); + MELAParticle* Wfb = theTop->getWAntifermion(); + if (bottom!=0) vdaughters.push_back(SimpleParticle_t(bottom->id, bottom->p4)); + if (Wf!=0) vdaughters.push_back(SimpleParticle_t(Wf->id, Wf->p4)); + if (Wfb!=0) vdaughters.push_back(SimpleParticle_t(Wfb->id, Wfb->p4)); + + TUtil::adjustTopDaughters(vdaughters); // Adjust top daughter kinematics + if (vdaughters.size()==3) antitopDaughters.push_back(vdaughters); } } @@ -7767,12 +7756,12 @@ void TUtil::GetBoostedParticleVectors( /***** BOOSTS TO THE CORRECT PT=0 FRAME *****/ // Gather all final state particles collected for this frame TLorentzVector pTotal(0, 0, 0, 0); - for (unsigned int ip=0; ip0.){ TVector3 boostV(-qX/qE, -qY/qE, 0.); - for (unsigned int ip=0; ip=TVar::DEBUG){