29 jetsToken( consumes<
edm::
View<
reco::
Jet>>( iConfig.getParameter<
edm::InputTag>(
"srcJets"))),
30 jetCorrectorToken( consumes<
reco::
JetCorrector>( iConfig.getParameter<
edm::InputTag>(
"jec"))),
32 rhoToken( consumes<double>( iConfig.getParameter<
edm::InputTag>(
"srcRho"))),
34 systLabel( iConfig.getParameter<
std::
string>(
"systematicsLabel")),
35 useQC( iConfig.getParameter<
bool>(
"useQualityCuts")),
36 useJetCorr( !iConfig.getParameter<
edm::InputTag>(
"jec").
label().
empty()),
37 produceSyst( systLabel !=
"")
39 produces<edm::ValueMap<float>>(
"qgLikelihood");
40 produces<edm::ValueMap<float>>(
"axis2");
41 produces<edm::ValueMap<int>>(
"mult");
42 produces<edm::ValueMap<float>>(
"ptD");
44 produces<edm::ValueMap<float>>(
"qgLikelihoodSmearedQuark");
45 produces<edm::ValueMap<float>>(
"qgLikelihoodSmearedGluon");
46 produces<edm::ValueMap<float>>(
"qgLikelihoodSmearedAll");
54 std::vector<float>* qgProduct =
new std::vector<float>;
55 std::vector<float>* axis2Product =
new std::vector<float>;
56 std::vector<int>* multProduct =
new std::vector<int>;
57 std::vector<float>* ptDProduct =
new std::vector<float>;
58 std::vector<float>* smearedQuarkProduct =
new std::vector<float>;
59 std::vector<float>* smearedGluonProduct =
new std::vector<float>;
60 std::vector<float>* smearedAllProduct =
new std::vector<float>;
77 bool weStillNeedToCheckJetCandidates =
true;
78 bool weAreUsingPackedCandidates =
false;
79 for(
auto jet = jets->begin();
jet != jets->end(); ++
jet){
80 if(weStillNeedToCheckJetCandidates) {
82 weStillNeedToCheckJetCandidates =
false;
86 float ptD, axis2;
int mult;
87 std::tie(mult, ptD, axis2) =
calcVariables(&*
jet, vertexCollection, weAreUsingPackedCandidates);
93 qgProduct->push_back(qgValue);
99 axis2Product->push_back(axis2);
100 multProduct->push_back(mult);
101 ptDProduct->push_back(ptD);
104 putInEvent(
"qgLikelihood", jets, qgProduct, iEvent);
105 putInEvent(
"axis2", jets, axis2Product, iEvent);
106 putInEvent(
"mult", jets, multProduct, iEvent);
109 putInEvent(
"qgLikelihoodSmearedQuark", jets, smearedQuarkProduct, iEvent);
110 putInEvent(
"qgLikelihoodSmearedGluon", jets, smearedGluonProduct, iEvent);
111 putInEvent(
"qgLikelihoodSmearedAll", jets, smearedAllProduct, iEvent);
117 auto out = std::make_unique<edm::ValueMap<T>>();
119 filler.insert(
jets, product->begin(), product->end());
131 else throw cms::Exception(
"WrongJetCollection",
"Jet constituents are not particle flow candidates");
139 float sum_weight = 0., sum_deta = 0., sum_dphi = 0., sum_deta2 = 0., sum_dphi2 = 0., sum_detadphi = 0., sum_pt = 0.;
144 if(weAreUsingPackedCandidates){
148 if(!(
part->fromPV() > 1 &&
part->trackHighPurity()))
continue;
150 if((
part->dz()*
part->dz())/(
part->dzError()*
part->dzError()) > 25.)
continue;
151 if((
part->dxy()*
part->dxy())/(
part->dxyError()*
part->dxyError()) < 25.) ++mult;
154 if(
part->pt() < 1.0)
continue;
162 auto vtxLead = vC->begin();
163 auto vtxClose = vC->begin();
164 for(
auto vtx = vC->begin();
vtx != vC->end(); ++
vtx){
165 if(fabs(itrk->dz(
vtx->position())) < fabs(itrk->dz(vtxClose->position()))) vtxClose =
vtx;
170 float dz = itrk->dz(vtxClose->position());
171 float d0 = itrk->dxy(vtxClose->position());
172 float dz_sigma_square =
pow(itrk->dzError(),2) +
pow(vtxClose->zError(),2);
173 float d0_sigma_square =
pow(itrk->d0Error(),2) +
pow(vtxClose->xError(),2) +
pow(vtxClose->yError(),2);
174 if(dz*dz/dz_sigma_square > 25.)
continue;
175 if(d0*d0/d0_sigma_square < 25.) ++mult;
178 if(
part->pt() < 1.0)
continue;
183 float deta = daughter->eta() - jet->
eta();
185 float partPt = daughter->pt();
186 float weight = partPt*partPt;
192 sum_deta2 += deta*deta*
weight;
193 sum_detadphi += deta*dphi*
weight;
194 sum_dphi2 += dphi*dphi*
weight;
198 float a = 0.,
b = 0.,
c = 0.;
199 float ave_deta = 0., ave_dphi = 0., ave_deta2 = 0., ave_dphi2 = 0.;
201 ave_deta = sum_deta/sum_weight;
202 ave_dphi = sum_dphi/sum_weight;
203 ave_deta2 = sum_deta2/sum_weight;
204 ave_dphi2 = sum_dphi2/sum_weight;
205 a = ave_deta2 - ave_deta*ave_deta;
206 b = ave_dphi2 - ave_dphi*ave_dphi;
207 c = -(sum_detadphi/sum_weight - ave_deta*ave_dphi);
210 float axis2 = (a+
b-delta > 0 ?
sqrt(0.5*(a+
b-delta)) : 0);
211 float ptD = (sum_weight > 0 ?
sqrt(sum_weight)/sum_pt : 0);
212 return std::make_tuple(mult, ptD, axis2);
223 desc.
add<
bool>(
"useQualityCuts");
225 desc.
add<
edm::InputTag>(
"srcVertexCollection")->setComment(
"Ignored for miniAOD, possible to keep empty");
226 descriptions.
add(
"QGTagger", desc);
constexpr double deltaPhi(double phi1, double phi2)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
bool isNonnull() const
Checks for non-null.
double eta() const final
momentum pseudorapidity
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Base class for all types of Jets.
void putInEvent(const std::string &, const edm::Handle< edm::View< reco::Jet >> &, std::vector< T > *, edm::Event &) const
Function to put product into event.
edm::EDGetTokenT< reco::VertexCollection > vertexToken
std::vector< Vertex > VertexCollection
collection of Vertex objects
double correction(const LorentzVector &fJet) const
get correction using Jet information only
bool isPackedCandidate(const reco::Jet *jet) const
Function to tell us if we are using packedCandidates, only test for first candidate.
QGLikelihoodCalculator * qgLikelihood
float systematicSmearing(edm::ESHandle< QGLikelihoodSystematicsObject > &QGLParamsColl, float pt, float eta, float rho, float qgValue, int qgIndex) const
QGTagger(const edm::ParameterSet &)
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
#define DEFINE_FWK_MODULE(type)
float computeQGLikelihood(edm::ESHandle< QGLikelihoodObject > &QGLParamsColl, float pt, float eta, float rho, std::vector< float > vars) const
Compute likelihood for a jet using the QGLikelihoodObject information and a set of variables...
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Produce qgLikelihood using {mult, ptD, -log(axis2)}.
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Descriptions method.
std::tuple< int, float, float > calcVariables(const reco::Jet *, edm::Handle< reco::VertexCollection > &, bool) const
Calculation of axis2, mult and ptD.
edm::EDGetTokenT< edm::View< reco::Jet > > jetsToken
static TrackQuality qualityByName(const std::string &name)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< double > rhoToken
Particle reconstructed by the particle flow algorithm.
edm::EDGetTokenT< reco::JetCorrector > jetCorrectorToken
virtual std::vector< const reco::Candidate * > getJetConstituentsQuick() const
quick list of constituents
double phi() const final
momentum azimuthal angle
Power< A, B >::type pow(const A &a, const B &b)