37 #include "fastjet/SISConePlugin.hh"
38 #include "fastjet/CMSIterativeConePlugin.hh"
39 #include "fastjet/ATLASConePlugin.hh"
40 #include "fastjet/CDFMidPointPlugin.hh"
47 #include <vdt/vdtMath.h>
55 bool operator()(
const fastjet::PseudoJet & t1,
const fastjet::PseudoJet &
t2 )
const {
56 return t1.perp2() > t2.perp2();
65 "BasicJet",
"GenJet",
"CaloJet",
"PFJet",
"TrackJet",
"PFClusterJet"
74 if (pos ==
names + LastJetType) {
75 std::string errorMessage=
"Requested jetType not supported: "+name+
"\n";
86 if ( writeCompound_ ) {
87 produces<reco::BasicJetCollection>();
90 if (makeCaloJet(jetTypeE)) {
91 produces<reco::CaloJetCollection>(
tag).setBranchAlias(alias);
93 else if (makePFJet(jetTypeE)) {
94 produces<reco::PFJetCollection>(
tag).setBranchAlias(alias);
96 else if (makeGenJet(jetTypeE)) {
97 produces<reco::GenJetCollection>(
tag).setBranchAlias(alias);
99 else if (makeTrackJet(jetTypeE)) {
100 produces<reco::TrackJetCollection>(
tag).setBranchAlias(alias);
102 else if (makePFClusterJet(jetTypeE)) {
103 produces<reco::PFClusterJetCollection>(
tag).setBranchAlias(alias);
105 else if (makeBasicJet(jetTypeE)) {
106 produces<reco::BasicJetCollection>(
tag).setBranchAlias(alias);
117 , src_ (iConfig.getParameter<edm::
InputTag>(
"src"))
118 , srcPVs_ (iConfig.getParameter<edm::
InputTag>(
"srcPVs"))
119 , jetType_ (iConfig.getParameter<
string> (
"jetType"))
120 , jetAlgorithm_ (iConfig.getParameter<
string> (
"jetAlgorithm"))
121 , rParam_ (iConfig.getParameter<double> (
"rParam"))
122 , inputEtMin_ (iConfig.getParameter<double> (
"inputEtMin"))
123 , inputEMin_ (iConfig.getParameter<double> (
"inputEMin"))
124 , jetPtMin_ (iConfig.getParameter<double> (
"jetPtMin"))
125 , doPVCorrection_(iConfig.getParameter<bool> (
"doPVCorrection"))
126 , restrictInputs_(
false)
127 , maxInputs_(99999999)
128 , doAreaFastjet_ (iConfig.getParameter<bool> (
"doAreaFastjet"))
129 , useExplicitGhosts_(
false)
130 , doAreaDiskApprox_ (
false)
131 , doRhoFastjet_ (iConfig.getParameter<bool> (
"doRhoFastjet"))
133 , doPUOffsetCorr_(iConfig.getParameter<bool> (
"doPUOffsetCorr"))
136 , jetCollInstanceName_ (
"")
137 , writeCompound_ (
false )
150 fastjet::SISConePlugin::SM_pttilde) );
177 <<
"Jet algorithm for VirtualJetProducer is invalid, Abort!\n";
181 if ( iConfig.
exists(
"jetCollInstanceName") ) {
191 edm::LogWarning(
"VirtualJetProducer") <<
"Pile Up correction on; however, pile up type is not specified. Using default... \n";
199 if ( iConfig.
exists(
"useExplicitGhosts") ) {
204 if (iConfig.
exists(
"doAreaDiskApprox")) {
207 throw cms::Exception(
"Conflicting area calculations") <<
"Both the calculation of jet area via fastjet and via an analytical disk approximation have been requested. Please decide on one.\n";
212 if (iConfig.
exists(
"voronoiRfact"))
220 double rhoEtaMax=iConfig.
getParameter<
double>(
"Rho_EtaMax");
222 double ghostEtaMax = iConfig.
getParameter<
double>(
"Ghost_EtaMax");
224 int activeAreaRepeats = iConfig.
getParameter<
int> (
"Active_Area_Repeats");
226 double ghostArea = iConfig.
getParameter<
double> (
"GhostArea");
240 if ( iConfig.
exists(
"restrictInputs") ) {
251 if ( iConfig.
exists(
"writeCompound") ) {
268 if ( iConfig.
exists(
"useDeterministicSeed") ) {
273 if ( iConfig.
exists(
"verbosity" ) ) {
277 produces<std::vector<double> >(
"rhos");
278 produces<std::vector<double> >(
"sigmas");
279 produces<double>(
"rho");
280 produces<double>(
"sigma");
309 fastjet::GhostedAreaSpec gas;
310 std::vector<int> seeds(2);
311 unsigned int runNum_uint = static_cast <
unsigned int> (iEvent.
id().
run());
312 unsigned int evNum_uint = static_cast <
unsigned int> (iEvent.
id().
event());
315 gas.set_random_status(seeds);
318 LogDebug(
"VirtualJetProducer") <<
"Entered produce\n";
322 LogDebug(
"VirtualJetProducer") <<
"Adding PV info\n";
325 if (pvCollection->size()>0)
vertex_=pvCollection->begin()->position();
335 LogDebug(
"VirtualJetProducer") <<
"Clear data\n";
348 if ( inputsHandle->size() == 0) {
352 for (
size_t i = 0;
i < inputsHandle->size(); ++
i) {
353 inputs_.push_back(inputsHandle->ptrAt(
i));
358 if ( pfinputsHandleAsFwdPtr->size() == 0) {
362 for (
size_t i = 0;
i < pfinputsHandleAsFwdPtr->size(); ++
i) {
363 if ( (*pfinputsHandleAsFwdPtr)[
i].ptr().isAvailable() ) {
364 inputs_.push_back( (*pfinputsHandleAsFwdPtr)[
i].ptr() );
366 else if ( (*pfinputsHandleAsFwdPtr)[
i].backPtr().isAvailable() ) {
367 inputs_.push_back( (*pfinputsHandleAsFwdPtr)[
i].backPtr() );
372 if ( packedinputsHandleAsFwdPtr->size() == 0) {
376 for (
size_t i = 0;
i < packedinputsHandleAsFwdPtr->size(); ++
i) {
377 if ( (*packedinputsHandleAsFwdPtr)[
i].ptr().isAvailable() ) {
378 inputs_.push_back( (*packedinputsHandleAsFwdPtr)[
i].ptr() );
380 else if ( (*packedinputsHandleAsFwdPtr)[
i].backPtr().isAvailable() ) {
381 inputs_.push_back( (*packedinputsHandleAsFwdPtr)[
i].backPtr() );
386 LogDebug(
"VirtualJetProducer") <<
"Got inputs\n";
393 LogDebug(
"VirtualJetProducer") <<
"Inputted towers\n";
402 LogDebug(
"VirtualJetProducer") <<
"Subtracted pedestal\n";
412 LogDebug(
"VirtualJetProducer") <<
"Ran algorithm\n";
420 LogDebug(
"VirtualJetProducer") <<
"Do PUOffsetCorr\n";
421 vector<fastjet::PseudoJet> orphanInput;
431 LogDebug(
"VirtualJetProducer") <<
"Wrote jets\n";
447 auto inBegin =
inputs_.begin(),
449 for (;
i != inEnd; ++
i ) {
464 fjInputs_.emplace_back(ct.px(),ct.py(),ct.pz(),ct.energy());
484 edm::LogWarning(
"JetRecoTooManyEntries") <<
"Too many inputs in the event, limiting to first " <<
maxInputs_ <<
". Output is suspect.";
507 for (
unsigned int i=0;
i<fjConstituents.size();++
i) {
508 int index = fjConstituents[
i].user_index();
509 if ( index >= 0 && static_cast<unsigned int>(index) <
inputs_.size() )
516 vector<reco::CandidatePtr>
519 vector<reco::CandidatePtr>
result; result.reserve(fjConstituents.size()/2);
520 for (
unsigned int i=0;
i<fjConstituents.size();
i++) {
521 auto index = fjConstituents[
i].user_index();
540 writeJets<reco::CaloJet>(
iEvent, iSetup);
543 writeJets<reco::PFJet>(
iEvent, iSetup);
546 writeJets<reco::GenJet>(
iEvent, iSetup);
549 writeJets<reco::TrackJet>(
iEvent, iSetup);
552 writeJets<reco::PFClusterJet>(
iEvent, iSetup);
555 writeJets<reco::BasicJet>(
iEvent, iSetup);
558 throw cms::Exception(
"InvalidInput") <<
"invalid jet type in VirtualJetProducer\n";
565 writeCompoundJets<reco::CaloJet>(
iEvent, iSetup );
568 writeCompoundJets<reco::PFJet>(
iEvent, iSetup );
571 writeCompoundJets<reco::GenJet>(
iEvent, iSetup );
574 writeCompoundJets<reco::BasicJet>(
iEvent, iSetup );
577 throw cms::Exception(
"InvalidInput") <<
"invalid jet type in CompoundJetProducer\n";
584 template<
typename T >
585 struct Area {
static float get(
T const &) {
return 0;}};
589 return jet.getSpecific().mTowersArea;
594 template<
typename T >
606 std::vector<fastjet::PseudoJet> fjexcluded_jets;
609 if(fjexcluded_jets.size()>2) fjexcluded_jets.resize(
nExclude_);
612 std::auto_ptr<std::vector<double> > rhos(
new std::vector<double>);
613 std::auto_ptr<std::vector<double> > sigmas(
new std::vector<double>);
616 sigmas->reserve(nEta);
617 fastjet::ClusterSequenceAreaBase
const* clusterSequenceWithArea =
618 dynamic_cast<fastjet::ClusterSequenceAreaBase
const *
> ( &*
fjClusterSeq_ );
620 if (clusterSequenceWithArea ==
nullptr ){
622 throw cms::Exception(
"LogicError")<<
"fjClusterSeq is not initialized while inputs are present\n ";
625 for(
int ie = 0; ie <
nEta; ++ie){
629 fastjet::RangeDefinition range_rho(etamin,etamax);
632 rhos->push_back(bkgestim.
rho());
633 sigmas->push_back(bkgestim.
sigma());
636 iEvent.
put(rhos,
"rhos");
637 iEvent.
put(sigmas,
"sigmas");
639 std::auto_ptr<double>
rho(
new double(0.0));
640 std::auto_ptr<double> sigma(
new double(0.0));
641 double mean_area = 0;
643 fastjet::ClusterSequenceAreaBase
const* clusterSequenceWithArea =
644 dynamic_cast<fastjet::ClusterSequenceAreaBase
const *
> ( &*
fjClusterSeq_ );
651 if (clusterSequenceWithArea ==
nullptr ){
653 throw cms::Exception(
"LogicError")<<
"fjClusterSeq is not initialized while inputs are present\n ";
656 clusterSequenceWithArea->get_median_rho_and_sigma(*
fjRangeDef_,
false,*rho,*sigma,mean_area);
658 edm::LogError(
"BadRho") <<
"rho value is " << *rho <<
" area:" << mean_area <<
" and n_empty_jets: " << clusterSequenceWithArea->n_empty_jets(*
fjRangeDef_) <<
" with range " <<
fjRangeDef_->description()
659 <<
". Setting rho to rezo.";
663 iEvent.
put(rho,
"rho");
664 iEvent.
put(sigma,
"sigma");
670 using namespace reco;
673 auto jets = std::make_unique<std::vector<T>>(
fjJets_.size());
676 using RIJ = std::pair<double,double>;
680 for (
unsigned int ijet=0;ijet<
fjJets_.size();++ijet) {
681 rij[ijet] = &rijStorage[
k];
k+=ijet;
688 for (
unsigned int ijet=0;ijet<
fjJets_.size();++ijet) {
689 auto &
jet = (*jets)[ijet];
691 const fastjet::PseudoJet& fjJet =
fjJets_[ijet];
693 std::vector<fastjet::PseudoJet>
const & fjConstituents = fastjet::sorted_by_pt(fjJet.constituents());
695 std::vector<CandidatePtr>
const & constituents =
getConstituents(fjConstituents);
706 constituents, iSetup);
707 phiJ[ijet] =
jet.phi();
708 etaJ[ijet] =
jet.eta();
712 for (
unsigned int ijet=0;ijet<
fjJets_.size();++ijet) {
716 const auto & fjJet =
fjJets_[ijet];
718 jetArea = fjJet.area();
725 for (
unsigned jJet = 0; jJet < ijet; ++jJet) {
728 jetArea -=distance[jJet].second;
729 for (
unsigned kJet = 0; kJet < jJet; ++kJet) {
731 distance[jJet].
second, distance[kJet].second, rij[jJet][kJet].second);
736 auto &
jet = (*jets)[ijet];
737 jet.setJetArea (jetArea);
758 std::cout <<
"<VirtualJetProducer::writeCompoundJets (moduleLabel = " <<
moduleLabel_ <<
")>:" << std::endl;
764 std::auto_ptr<std::vector<T> > subjetCollection(
new std::vector<T>() );
769 std::vector< std::vector<int> > indices;
771 std::vector<math::XYZTLorentzVector> p4_hardJets;
773 std::vector<double> area_hardJets;
776 std::vector<fastjet::PseudoJet>::const_iterator it =
fjJets_.begin(),
779 indices.resize(
fjJets_.size() );
780 for ( ; it != iEnd; ++it ) {
781 fastjet::PseudoJet
const & localJet = *it;
782 unsigned int jetIndex = it - iBegin;
785 double localJetArea = 0.0;
787 localJetArea = localJet.area();
789 area_hardJets.push_back( localJetArea );
792 std::vector<fastjet::PseudoJet> constituents;
793 if ( it->has_pieces() ) {
794 constituents = it->pieces();
795 }
else if ( it->has_constituents() ) {
796 constituents = it->constituents();
799 std::vector<fastjet::PseudoJet>::const_iterator itSubJetBegin = constituents.begin(),
800 itSubJet = itSubJetBegin, itSubJetEnd = constituents.end();
801 for (; itSubJet != itSubJetEnd; ++itSubJet ){
803 fastjet::PseudoJet
const & subjet = *itSubJet;
805 std::cout <<
"subjet #" << (itSubJet - itSubJetBegin) <<
": Pt = " << subjet.pt() <<
", eta = " << subjet.eta() <<
", phi = " << subjet.phi() <<
", mass = " << subjet.m()
806 <<
" (#constituents = " << subjet.constituents().size() <<
")" << std::endl;
807 std::vector<fastjet::PseudoJet> subjet_constituents = subjet.constituents();
808 int idx_constituent = 0;
809 for ( std::vector<fastjet::PseudoJet>::const_iterator constituent = subjet_constituents.begin();
810 constituent != subjet_constituents.end(); ++constituent ) {
811 if ( constituent->pt() < 1.e-3 )
continue;
812 std::cout <<
" constituent #" << idx_constituent <<
": Pt = " << constituent->pt() <<
", eta = " << constituent->eta() <<
", phi = " << constituent->phi() <<
","
813 <<
" mass = " << constituent->m() << std::endl;
819 std::cout <<
"subjet #" << (itSubJet - itSubJetBegin) <<
": Pt = " << subjet.pt() <<
", eta = " << subjet.eta() <<
", phi = " << subjet.phi() <<
", mass = " << subjet.m()
820 <<
" (#constituents = " << subjet.constituents().size() <<
")" << std::endl;
821 std::vector<fastjet::PseudoJet> subjet_constituents = subjet.constituents();
822 int idx_constituent = 0;
823 for ( std::vector<fastjet::PseudoJet>::const_iterator constituent = subjet_constituents.begin();
824 constituent != subjet_constituents.end(); ++constituent ) {
825 if ( constituent->pt() < 1.e-3 )
continue;
826 std::cout <<
" constituent #" << idx_constituent <<
": Pt = " << constituent->pt() <<
", eta = " << constituent->eta() <<
", phi = " << constituent->phi() <<
","
827 <<
" mass = " << constituent->m() << std::endl;
836 std::vector<reco::CandidatePtr> subjetConstituents;
839 std::vector<fastjet::PseudoJet> subjetFastjetConstituents = subjet.constituents();
840 std::vector<reco::CandidatePtr> constituents =
843 indices[jetIndex].push_back( subjetCollection->size() );
848 double subjetArea = 0.0;
850 subjetArea = itSubJet->area();
852 jet.setJetArea( subjetArea );
853 subjetCollection->push_back( jet );
861 std::vector<math::XYZTLorentzVector>::const_iterator ip4 = p4_hardJets.begin(),
862 ip4Begin = p4_hardJets.begin(),
863 ip4End = p4_hardJets.end();
865 for ( ; ip4 != ip4End; ++ip4 ) {
866 int p4_index = ip4 - ip4Begin;
867 std::vector<int> & ind = indices[p4_index];
868 std::vector<reco::CandidatePtr> i_hardJetConstituents;
870 for( std::vector<int>::const_iterator isub = ind.begin();
871 isub != ind.end(); ++isub ) {
873 i_hardJetConstituents.push_back( candPtr );
877 toput.
setJetArea( area_hardJets[ip4 - ip4Begin] );
878 jetCollection->push_back( toput );
882 iEvent.
put( jetCollection);
boost::shared_ptr< fastjet::AreaDefinition > AreaDefinitionPtr
void writeJets(edm::Event &iEvent, edm::EventSetup const &iSetup)
void swap(ora::Record &rh, ora::Record &lh)
T getParameter(std::string const &) const
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) const
reco::Particle::Point vertex_
Jets made from CaloTowers.
static const HistoName names[]
math::PtEtaPhiMLorentzVector p4(double vtxZ) const
edm::EDGetTokenT< reco::CandidateView > input_candidateview_token_
virtual std::vector< reco::CandidatePtr > getConstituents(const std::vector< fastjet::PseudoJet > &fjConstituents)
std::vector< fastjet::PseudoJet > fjJets_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
virtual void inputTowers()
edm::EDGetTokenT< std::vector< edm::FwdPtr< pat::PackedCandidate > > > input_packedcandidatefwdptr_token_
Base class for all types of Jets.
boost::shared_ptr< fastjet::JetDefinition::Plugin > PluginPtr
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::string puSubtractorName_
std::vector< double > puCenters_
virtual void copyConstituents(const std::vector< fastjet::PseudoJet > &fjConstituents, reco::Jet *jet)
Jets made from CaloTowers.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
virtual void runAlgorithm(edm::Event &iEvent, const edm::EventSetup &iSetup)=0
static std::string const input
void writeCompoundJets(edm::Event &iEvent, edm::EventSetup const &iSetup)
function template to write out the outputs
bool operator()(const fastjet::PseudoJet &t1, const fastjet::PseudoJet &t2) const
boost::shared_ptr< fastjet::RangeDefinition > RangeDefPtr
U second(std::pair< T, U > const &p)
bool makePFJet(const JetType::Type &fTag)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
virtual bool isAnomalousTower(reco::CandidatePtr input)
virtual void setJetArea(float fArea)
set jet area
std::vector< fastjet::PseudoJet > fjInputs_
std::string jetCollInstanceName_
boost::shared_ptr< PileUpSubtractor > subtractor_
double intersection(double r12)
std::vector< edm::Ptr< reco::Candidate > > inputs_
virtual ~VirtualJetProducer()
auto const T2 &decltype(t1.eta()) t2
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
ClusterSequencePtr fjClusterSeq_
virtual void makeProduces(std::string s, std::string tag="")
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
math::XYZPoint Point
point in the space
std::string jetAlgorithm_
void set_excluded_jets(const std::vector< PseudoJet > &excluded_jets)
boost::shared_ptr< fastjet::JetDefinition > JetDefPtr
bool useDeterministicSeed_
std::auto_ptr< AnomalousTower > anomalousTowerDef_
ActiveAreaSpecPtr fjActiveArea_
edm::EDGetTokenT< reco::VertexCollection > input_vertex_token_
double rho()
synonym for median rho [[do we have this? Both?]]
edm::EDGetTokenT< std::vector< edm::FwdPtr< reco::PFCandidate > > > input_candidatefwdptr_token_
static const char *const names[]
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
double sigma()
get the sigma
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
VirtualJetProducer(const edm::ParameterSet &iConfig)
boost::shared_ptr< fastjet::GhostedAreaSpec > ActiveAreaSpecPtr
void addDaughter(const CandidatePtr &)
add a daughter via a reference
AreaDefinitionPtr fjAreaDefinition_
virtual void output(edm::Event &iEvent, edm::EventSetup const &iSetup)
volatile std::atomic< bool > shutdown_flag false
bool makeCaloJet(const JetType::Type &fTag)
static Type byName(const std::string &name)
T get(const Candidate &c)
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
bool doFastJetNonUniform_
math::PtEtaPhiELorentzVectorF LorentzVector
math::XYZPoint Point
point in the space
void writeSpecific(reco::CaloJet &jet, reco::Particle::LorentzVector const &p4, reco::Particle::Point const &point, std::vector< reco::CandidatePtr > const &constituents, edm::EventSetup const &c)
JetDefPtr fjJetDefinition_
std::vector< BasicJet > BasicJetCollection
collection of BasicJet objects