41 #include "fastjet/SISConePlugin.hh" 42 #include "fastjet/CMSIterativeConePlugin.hh" 43 #include "fastjet/ATLASConePlugin.hh" 44 #include "fastjet/CDFMidPointPlugin.hh" 51 #include <vdt/vdtMath.h> 59 bool operator()(
const fastjet::PseudoJet & t1,
const fastjet::PseudoJet &
t2 )
const {
60 return t1.perp2() > t2.perp2();
69 "BasicJet",
"GenJet",
"CaloJet",
"PFJet",
"TrackJet",
"PFClusterJet" 78 if (pos ==
names + LastJetType) {
79 std::string errorMessage=
"Requested jetType not supported: "+name+
"\n";
90 if ( writeCompound_ ) {
91 produces<reco::BasicJetCollection>();
94 if (makeCaloJet(jetTypeE)) {
95 produces<reco::CaloJetCollection>(
tag).setBranchAlias(alias);
97 else if (makePFJet(jetTypeE)) {
98 produces<reco::PFJetCollection>(
tag).setBranchAlias(alias);
100 else if (makeGenJet(jetTypeE)) {
101 produces<reco::GenJetCollection>(
tag).setBranchAlias(alias);
103 else if (makeTrackJet(jetTypeE)) {
104 produces<reco::TrackJetCollection>(
tag).setBranchAlias(alias);
106 else if (makePFClusterJet(jetTypeE)) {
107 produces<reco::PFClusterJetCollection>(
tag).setBranchAlias(alias);
109 else if (makeBasicJet(jetTypeE)) {
110 produces<reco::BasicJetCollection>(
tag).setBranchAlias(alias);
120 : moduleLabel_ (iConfig.getParameter<
string> (
"@module_label"))
121 , src_ (iConfig.getParameter<
edm::InputTag>(
"src"))
122 , srcPVs_ (iConfig.getParameter<
edm::InputTag>(
"srcPVs"))
123 , jetType_ (iConfig.getParameter<
string> (
"jetType"))
124 , jetAlgorithm_ (iConfig.getParameter<
string> (
"jetAlgorithm"))
125 , rParam_ (iConfig.getParameter<double> (
"rParam"))
126 , inputEtMin_ (iConfig.getParameter<double> (
"inputEtMin"))
127 , inputEMin_ (iConfig.getParameter<double> (
"inputEMin"))
128 , jetPtMin_ (iConfig.getParameter<double> (
"jetPtMin"))
129 , doPVCorrection_(iConfig.getParameter<bool> (
"doPVCorrection"))
130 , restrictInputs_(
false)
131 , maxInputs_(99999999)
132 , doAreaFastjet_ (iConfig.getParameter<bool> (
"doAreaFastjet"))
133 , useExplicitGhosts_(
false)
134 , doAreaDiskApprox_ (
false)
135 , doRhoFastjet_ (iConfig.getParameter<bool> (
"doRhoFastjet"))
137 , doPUOffsetCorr_(iConfig.getParameter<bool> (
"doPUOffsetCorr"))
140 , jetCollInstanceName_ (
"")
141 , writeCompound_ (
false )
143 , fromHTTTopJetProducer_(0)
155 fastjet::SISConePlugin::SM_pttilde) );
182 <<
"Jet algorithm for VirtualJetProducer is invalid, Abort!\n";
186 if ( iConfig.
exists(
"jetCollInstanceName") ) {
196 edm::LogWarning(
"VirtualJetProducer") <<
"Pile Up correction on; however, pile up type is not specified. Using default... \n";
204 if ( iConfig.
exists(
"useExplicitGhosts") ) {
209 if (iConfig.
exists(
"doAreaDiskApprox")) {
212 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";
217 if (iConfig.
exists(
"voronoiRfact"))
225 double rhoEtaMax=iConfig.
getParameter<
double>(
"Rho_EtaMax");
227 double ghostEtaMax = iConfig.
getParameter<
double>(
"Ghost_EtaMax");
229 int activeAreaRepeats = iConfig.
getParameter<
int> (
"Active_Area_Repeats");
231 double ghostArea = iConfig.
getParameter<
double> (
"GhostArea");
245 if ( iConfig.
exists(
"restrictInputs") ) {
256 if ( iConfig.
exists(
"writeCompound") ) {
273 if ( iConfig.
exists(
"useDeterministicSeed") ) {
274 useDeterministicSeed_ = iConfig.
getParameter<
bool>(
"useDeterministicSeed");
278 if ( iConfig.
exists(
"verbosity" ) ) {
282 produces<std::vector<double> >(
"rhos");
283 produces<std::vector<double> >(
"sigmas");
284 produces<double>(
"rho");
285 produces<double>(
"sigma");
314 fastjet::GhostedAreaSpec gas;
315 std::vector<int> seeds(2);
316 unsigned int runNum_uint = static_cast <
unsigned int> (iEvent.
id().
run());
317 unsigned int evNum_uint = static_cast <
unsigned int> (iEvent.
id().
event());
320 gas.set_random_status(seeds);
323 LogDebug(
"VirtualJetProducer") <<
"Entered produce\n";
327 LogDebug(
"VirtualJetProducer") <<
"Adding PV info\n";
330 if (pvCollection->size()>0)
vertex_=pvCollection->begin()->position();
340 LogDebug(
"VirtualJetProducer") <<
"Clear data\n";
353 if ( inputsHandle->
size() == 0) {
357 for (
size_t i = 0;
i < inputsHandle->
size(); ++
i) {
363 if ( pfinputsHandleAsFwdPtr->size() == 0) {
367 for (
size_t i = 0;
i < pfinputsHandleAsFwdPtr->size(); ++
i) {
368 if ( (*pfinputsHandleAsFwdPtr)[
i].ptr().isAvailable() ) {
369 inputs_.push_back( (*pfinputsHandleAsFwdPtr)[
i].ptr() );
371 else if ( (*pfinputsHandleAsFwdPtr)[
i].backPtr().isAvailable() ) {
372 inputs_.push_back( (*pfinputsHandleAsFwdPtr)[
i].backPtr() );
377 if ( packedinputsHandleAsFwdPtr->size() == 0) {
381 for (
size_t i = 0;
i < packedinputsHandleAsFwdPtr->size(); ++
i) {
382 if ( (*packedinputsHandleAsFwdPtr)[
i].ptr().isAvailable() ) {
383 inputs_.push_back( (*packedinputsHandleAsFwdPtr)[
i].ptr() );
385 else if ( (*packedinputsHandleAsFwdPtr)[
i].backPtr().isAvailable() ) {
386 inputs_.push_back( (*packedinputsHandleAsFwdPtr)[
i].backPtr() );
391 LogDebug(
"VirtualJetProducer") <<
"Got inputs\n";
398 LogDebug(
"VirtualJetProducer") <<
"Inputted towers\n";
407 LogDebug(
"VirtualJetProducer") <<
"Subtracted pedestal\n";
417 LogDebug(
"VirtualJetProducer") <<
"Ran algorithm\n";
425 LogDebug(
"VirtualJetProducer") <<
"Do PUOffsetCorr\n";
426 vector<fastjet::PseudoJet> orphanInput;
436 LogDebug(
"VirtualJetProducer") <<
"Wrote jets\n";
452 auto inBegin =
inputs_.begin(),
454 for (;
i != inEnd; ++
i ) {
469 fjInputs_.emplace_back(ct.px(),ct.py(),ct.pz(),ct.energy());
489 edm::LogWarning(
"JetRecoTooManyEntries") <<
"Too many inputs in the event, limiting to first " <<
maxInputs_ <<
". Output is suspect.";
512 for (
unsigned int i=0;
i<fjConstituents.size();++
i) {
513 int index = fjConstituents[
i].user_index();
514 if ( index >= 0 && static_cast<unsigned int>(index) <
inputs_.size() )
521 vector<reco::CandidatePtr>
524 vector<reco::CandidatePtr>
result; result.reserve(fjConstituents.size()/2);
525 for (
unsigned int i=0;
i<fjConstituents.size();
i++) {
526 auto index = fjConstituents[
i].user_index();
545 writeJets<reco::CaloJet>(
iEvent, iSetup);
548 writeJets<reco::PFJet>(
iEvent, iSetup);
551 writeJets<reco::GenJet>(
iEvent, iSetup);
554 writeJets<reco::TrackJet>(
iEvent, iSetup);
557 writeJets<reco::PFClusterJet>(
iEvent, iSetup);
560 writeJets<reco::BasicJet>(
iEvent, iSetup);
563 throw cms::Exception(
"InvalidInput") <<
"invalid jet type in VirtualJetProducer\n";
570 writeCompoundJets<reco::CaloJet>(
iEvent, iSetup );
573 writeCompoundJets<reco::PFJet>(
iEvent, iSetup );
576 writeCompoundJets<reco::GenJet>(
iEvent, iSetup );
579 writeCompoundJets<reco::BasicJet>(
iEvent, iSetup );
582 throw cms::Exception(
"InvalidInput") <<
"invalid jet type in CompoundJetProducer\n";
589 template<
typename T >
590 struct Area {
static float get(
T const &) {
return 0;}};
594 return jet.getSpecific().mTowersArea;
599 template<
typename T >
611 std::vector<fastjet::PseudoJet> fjexcluded_jets;
614 if(fjexcluded_jets.size()>2) fjexcluded_jets.resize(
nExclude_);
617 auto rhos = std::make_unique<std::vector<double>>();
618 auto sigmas = std::make_unique<std::vector<double>>();
621 sigmas->reserve(nEta);
622 fastjet::ClusterSequenceAreaBase
const* clusterSequenceWithArea =
623 dynamic_cast<fastjet::ClusterSequenceAreaBase
const *
> ( &*
fjClusterSeq_ );
625 if (clusterSequenceWithArea ==
nullptr ){
627 throw cms::Exception(
"LogicError")<<
"fjClusterSeq is not initialized while inputs are present\n ";
630 for(
int ie = 0; ie <
nEta; ++ie){
634 fastjet::RangeDefinition range_rho(etamin,etamax);
637 rhos->push_back(bkgestim.
rho());
638 sigmas->push_back(bkgestim.
sigma());
644 auto rho = std::make_unique<double>(0.0);
645 auto sigma = std::make_unique<double>(0.0);
646 double mean_area = 0;
648 fastjet::ClusterSequenceAreaBase
const* clusterSequenceWithArea =
649 dynamic_cast<fastjet::ClusterSequenceAreaBase
const *
> ( &*
fjClusterSeq_ );
656 if (clusterSequenceWithArea ==
nullptr ){
658 throw cms::Exception(
"LogicError")<<
"fjClusterSeq is not initialized while inputs are present\n ";
661 clusterSequenceWithArea->get_median_rho_and_sigma(*
fjRangeDef_,
false,*
rho,*
sigma,mean_area);
663 edm::LogError(
"BadRho") <<
"rho value is " << *
rho <<
" area:" << mean_area <<
" and n_empty_jets: " << clusterSequenceWithArea->n_empty_jets(*
fjRangeDef_) <<
" with range " <<
fjRangeDef_->description()
664 <<
". Setting rho to rezo.";
675 using namespace reco;
678 auto jets = std::make_unique<std::vector<T>>(
fjJets_.size());
681 using RIJ = std::pair<double,double>;
685 for (
unsigned int ijet=0;ijet<
fjJets_.size();++ijet) {
686 rij[ijet] = &rijStorage[
k]; k+=ijet;
693 for (
unsigned int ijet=0;ijet<
fjJets_.size();++ijet) {
694 auto &
jet = (*jets)[ijet];
696 const fastjet::PseudoJet& fjJet =
fjJets_[ijet];
698 std::vector<fastjet::PseudoJet>
const & fjConstituents = fastjet::sorted_by_pt(fjJet.constituents());
700 std::vector<CandidatePtr>
const & constituents =
getConstituents(fjConstituents);
711 constituents, iSetup);
712 phiJ[ijet] =
jet.phi();
713 etaJ[ijet] =
jet.eta();
717 for (
unsigned int ijet=0;ijet<
fjJets_.size();++ijet) {
721 const auto & fjJet =
fjJets_[ijet];
723 jetArea = fjJet.area();
730 for (
unsigned jJet = 0; jJet < ijet; ++jJet) {
733 jetArea -=distance[jJet].second;
734 for (
unsigned kJet = 0; kJet < jJet; ++kJet) {
736 distance[jJet].
second, distance[kJet].second, rij[jJet][kJet].second);
741 auto &
jet = (*jets)[ijet];
742 jet.setJetArea (jetArea);
763 std::cout <<
"<VirtualJetProducer::writeCompoundJets (moduleLabel = " <<
moduleLabel_ <<
")>:" << std::endl;
767 auto jetCollection = std::make_unique<reco::BasicJetCollection>();
769 auto subjetCollection = std::make_unique<std::vector<T>>();
774 std::vector< std::vector<int> > indices;
776 std::vector<math::XYZTLorentzVector> p4_hardJets;
778 std::vector<double> area_hardJets;
781 std::vector<fastjet::PseudoJet>::const_iterator it =
fjJets_.begin(),
784 indices.resize(
fjJets_.size() );
785 for ( ; it != iEnd; ++it ) {
786 fastjet::PseudoJet
const & localJet = *it;
787 unsigned int jetIndex = it - iBegin;
790 double localJetArea = 0.0;
792 localJetArea = localJet.area();
794 area_hardJets.push_back( localJetArea );
797 std::vector<fastjet::PseudoJet> constituents;
798 if ( it->has_pieces() ) {
799 constituents = it->pieces();
800 }
else if ( it->has_constituents() ) {
801 constituents = it->constituents();
804 std::vector<fastjet::PseudoJet>::const_iterator itSubJetBegin = constituents.begin(),
805 itSubJet = itSubJetBegin, itSubJetEnd = constituents.end();
806 for (; itSubJet != itSubJetEnd; ++itSubJet ){
808 fastjet::PseudoJet
const & subjet = *itSubJet;
810 std::cout <<
"subjet #" << (itSubJet - itSubJetBegin) <<
": Pt = " << subjet.pt() <<
", eta = " << subjet.eta() <<
", phi = " << subjet.phi() <<
", mass = " << subjet.m()
811 <<
" (#constituents = " << subjet.constituents().size() <<
")" << std::endl;
812 std::vector<fastjet::PseudoJet> subjet_constituents = subjet.constituents();
813 int idx_constituent = 0;
814 for ( std::vector<fastjet::PseudoJet>::const_iterator constituent = subjet_constituents.begin();
815 constituent != subjet_constituents.end(); ++constituent ) {
816 if ( constituent->pt() < 1.e-3 )
continue;
817 std::cout <<
" constituent #" << idx_constituent <<
": Pt = " << constituent->pt() <<
", eta = " << constituent->eta() <<
", phi = " << constituent->phi() <<
"," 818 <<
" mass = " << constituent->m() << std::endl;
824 std::cout <<
"subjet #" << (itSubJet - itSubJetBegin) <<
": Pt = " << subjet.pt() <<
", eta = " << subjet.eta() <<
", phi = " << subjet.phi() <<
", mass = " << subjet.m()
825 <<
" (#constituents = " << subjet.constituents().size() <<
")" << std::endl;
826 std::vector<fastjet::PseudoJet> subjet_constituents = subjet.constituents();
827 int idx_constituent = 0;
828 for ( std::vector<fastjet::PseudoJet>::const_iterator constituent = subjet_constituents.begin();
829 constituent != subjet_constituents.end(); ++constituent ) {
830 if ( constituent->pt() < 1.e-3 )
continue;
831 std::cout <<
" constituent #" << idx_constituent <<
": Pt = " << constituent->pt() <<
", eta = " << constituent->eta() <<
", phi = " << constituent->phi() <<
"," 832 <<
" mass = " << constituent->m() << std::endl;
841 std::vector<reco::CandidatePtr> subjetConstituents;
844 std::vector<fastjet::PseudoJet> subjetFastjetConstituents = subjet.constituents();
845 std::vector<reco::CandidatePtr> constituents =
848 indices[jetIndex].push_back( subjetCollection->size() );
853 double subjetArea = 0.0;
855 subjetArea = itSubJet->area();
857 jet.setJetArea( subjetArea );
858 subjetCollection->push_back( jet );
866 std::vector<math::XYZTLorentzVector>::const_iterator ip4 = p4_hardJets.begin(),
867 ip4Begin = p4_hardJets.begin(),
868 ip4End = p4_hardJets.end();
870 for ( ; ip4 != ip4End; ++ip4 ) {
871 int p4_index = ip4 - ip4Begin;
872 std::vector<int> & ind = indices[p4_index];
873 std::vector<reco::CandidatePtr> i_hardJetConstituents;
875 for( std::vector<int>::const_iterator isub = ind.begin();
876 isub != ind.end(); ++isub ) {
878 i_hardJetConstituents.push_back( candPtr );
882 toput.
setJetArea( area_hardJets[ip4 - ip4Begin] );
883 jetCollection->push_back( toput );
boost::shared_ptr< fastjet::AreaDefinition > AreaDefinitionPtr
void writeJets(edm::Event &iEvent, edm::EventSetup const &iSetup)
T getParameter(std::string const &) const
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
reco::Particle::Point vertex_
Jets made from CaloTowers.
virtual void addHTTTopJetTagInfoCollection(edm::Event &iEvent, const edm::EventSetup &iSetup, edm::OrphanHandle< reco::BasicJetCollection > &oh)
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
Ptr< value_type > ptrAt(size_type i) 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
void swap(Association< C > &lhs, Association< C > &rhs)
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
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_
bool fromHTTTopJetProducer_
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)
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_