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.perp() > t2.perp();
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") ) {
187 throw cms::Exception(
"InvalidInput") <<
"Can only offset correct jets of type CaloJet or BasicJet";
194 edm::LogWarning(
"VirtualJetProducer") <<
"Pile Up correction on; however, pile up type is not specified. Using default... \n";
202 if ( iConfig.
exists(
"useExplicitGhosts") ) {
207 if (iConfig.
exists(
"doAreaDiskApprox")) {
210 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";
215 if (iConfig.
exists(
"voronoiRfact"))
223 double rhoEtaMax=iConfig.
getParameter<
double>(
"Rho_EtaMax");
225 double ghostEtaMax = iConfig.
getParameter<
double>(
"Ghost_EtaMax");
227 int activeAreaRepeats = iConfig.
getParameter<
int> (
"Active_Area_Repeats");
229 double ghostArea = iConfig.
getParameter<
double> (
"GhostArea");
243 if ( iConfig.
exists(
"restrictInputs") ) {
254 if ( iConfig.
exists(
"writeCompound") ) {
271 if ( iConfig.
exists(
"useDeterministicSeed") ) {
276 if ( iConfig.
exists(
"verbosity" ) ) {
280 produces<std::vector<double> >(
"rhos");
281 produces<std::vector<double> >(
"sigmas");
282 produces<double>(
"rho");
283 produces<double>(
"sigma");
308 fastjet::GhostedAreaSpec gas;
309 std::vector<int> seeds(2);
312 gas.set_random_status(seeds);
315 LogDebug(
"VirtualJetProducer") <<
"Entered produce\n";
319 LogDebug(
"VirtualJetProducer") <<
"Adding PV info\n";
322 if (pvCollection->size()>0)
vertex_=pvCollection->begin()->position();
332 LogDebug(
"VirtualJetProducer") <<
"Clear data\n";
344 for (
size_t i = 0;
i < inputsHandle->size(); ++
i) {
345 inputs_.push_back(inputsHandle->ptrAt(
i));
349 for (
size_t i = 0;
i < pfinputsHandleAsFwdPtr->size(); ++
i) {
350 if ( (*pfinputsHandleAsFwdPtr)[
i].ptr().isAvailable() ) {
351 inputs_.push_back( (*pfinputsHandleAsFwdPtr)[
i].ptr() );
353 else if ( (*pfinputsHandleAsFwdPtr)[
i].backPtr().isAvailable() ) {
354 inputs_.push_back( (*pfinputsHandleAsFwdPtr)[
i].backPtr() );
358 LogDebug(
"VirtualJetProducer") <<
"Got inputs\n";
365 LogDebug(
"VirtualJetProducer") <<
"Inputted towers\n";
374 LogDebug(
"VirtualJetProducer") <<
"Subtracted pedestal\n";
384 LogDebug(
"VirtualJetProducer") <<
"Ran algorithm\n";
392 LogDebug(
"VirtualJetProducer") <<
"Do PUOffsetCorr\n";
393 vector<fastjet::PseudoJet> orphanInput;
403 LogDebug(
"VirtualJetProducer") <<
"Wrote jets\n";
412 std::vector<edm::Ptr<reco::Candidate> >::const_iterator inBegin =
inputs_.begin(),
414 for (;
i != inEnd; ++
i ) {
420 if (input->pt() == 0) {
421 edm::LogError(
"NullTransverseMomentum") <<
"dropping input candidate with pt=0";
427 fjInputs_.push_back(fastjet::PseudoJet(ct.px(),ct.py(),ct.pz(),ct.energy()));
437 fjInputs_.push_back(fastjet::PseudoJet(input->px(),input->py(),input->pz(),
447 edm::LogWarning(
"JetRecoTooManyEntries") <<
"Too many inputs in the event, limiting to first " <<
maxInputs_ <<
". Output is suspect.";
470 for (
unsigned int i=0;
i<fjConstituents.size();++
i) {
471 int index = fjConstituents[
i].user_index();
472 if ( index >= 0 && static_cast<unsigned int>(index) <
inputs_.size() )
479 vector<reco::CandidatePtr>
482 vector<reco::CandidatePtr>
result;
483 for (
unsigned int i=0;
i<fjConstituents.size();
i++) {
484 int index = fjConstituents[
i].user_index();
485 if ( index >= 0 && static_cast<unsigned int>(index) <
inputs_.size() ) {
487 result.push_back(candidate);
504 writeJets<reco::CaloJet>(
iEvent, iSetup);
507 writeJets<reco::PFJet>(
iEvent, iSetup);
510 writeJets<reco::GenJet>(
iEvent, iSetup);
513 writeJets<reco::TrackJet>(
iEvent, iSetup);
516 writeJets<reco::PFClusterJet>(
iEvent, iSetup);
519 writeJets<reco::BasicJet>(
iEvent, iSetup);
522 throw cms::Exception(
"InvalidInput") <<
"invalid jet type in VirtualJetProducer\n";
529 writeCompoundJets<reco::CaloJet>(
iEvent, iSetup );
532 writeCompoundJets<reco::PFJet>(
iEvent, iSetup );
535 writeCompoundJets<reco::GenJet>(
iEvent, iSetup );
538 writeCompoundJets<reco::BasicJet>(
iEvent, iSetup );
541 throw cms::Exception(
"InvalidInput") <<
"invalid jet type in CompoundJetProducer\n";
548 template<
typename T >
549 struct Area {
static float get(
T const &) {
return 0;}};
553 return jet.getSpecific().mTowersArea;
558 template<
typename T >
570 std::vector<fastjet::PseudoJet> fjexcluded_jets;
573 if(fjexcluded_jets.size()>2) fjexcluded_jets.resize(
nExclude_);
576 std::auto_ptr<std::vector<double> > rhos(
new std::vector<double>);
577 std::auto_ptr<std::vector<double> > sigmas(
new std::vector<double>);
580 sigmas->reserve(nEta);
581 fastjet::ClusterSequenceAreaBase
const* clusterSequenceWithArea =
582 dynamic_cast<fastjet::ClusterSequenceAreaBase
const *
> ( &*
fjClusterSeq_ );
585 for(
int ie = 0; ie < nEta; ++ie){
589 fastjet::RangeDefinition range_rho(etamin,etamax);
592 rhos->push_back(bkgestim.
rho());
593 sigmas->push_back(bkgestim.
sigma());
595 iEvent.
put(rhos,
"rhos");
596 iEvent.
put(sigmas,
"sigmas");
598 std::auto_ptr<double>
rho(
new double(0.0));
599 std::auto_ptr<double> sigma(
new double(0.0));
600 double mean_area = 0;
602 fastjet::ClusterSequenceAreaBase
const* clusterSequenceWithArea =
603 dynamic_cast<fastjet::ClusterSequenceAreaBase
const *
> ( &*
fjClusterSeq_ );
610 clusterSequenceWithArea->get_median_rho_and_sigma(*
fjRangeDef_,
false,*rho,*sigma,mean_area);
612 edm::LogError(
"BadRho") <<
"rho value is " << *rho <<
" area:" << mean_area <<
" and n_empty_jets: " << clusterSequenceWithArea->n_empty_jets(*
fjRangeDef_) <<
" with range " <<
fjRangeDef_->description()
613 <<
". Setting rho to rezo.";
616 iEvent.
put(rho,
"rho");
617 iEvent.
put(sigma,
"sigma");
623 using namespace reco;
625 std::auto_ptr<std::vector<T> >
jets(
new std::vector<T>() );
629 using RIJ = std::pair<double,double>;
630 std::vector<std::vector<RIJ> > rij(
fjJets_.size());
633 auto etaFromXYZ = [](
float x,
float y,
float z)->
float {
float t(
z/
std::sqrt(
x*
x+
y*
y));
return vdt::fast_logf(t +
std::sqrt(t*t+1.
f));};
634 for (
auto ijet=0U;ijet<
fjJets_.size();++ijet) {
638 phiJ[ijet] = vdt::fast_atan2(y,x);
639 etaJ[ijet] =etaFromXYZ(x,y,z);
641 for (
unsigned int ijet=0;ijet<
fjJets_.size();++ijet) {
645 const fastjet::PseudoJet& fjJet =
fjJets_[ijet];
647 std::vector<fastjet::PseudoJet> fjConstituents = fastjet::sorted_by_pt(fjJet.constituents());
649 std::vector<CandidatePtr> constituents =
655 jetArea = fjJet.area();
662 std::vector<RIJ>& distance = rij[ijet];
663 distance.resize(ijet);
664 for (
unsigned jJet = 0; jJet < ijet; ++jJet) {
667 jetArea -=distance[jJet].second;
668 for (
unsigned kJet = 0; kJet < jJet; ++kJet) {
670 distance[jJet].
second, distance[kJet].second, rij[jJet][kJet].second);
686 constituents, iSetup);
688 jet.setJetArea (jetArea);
700 jets->push_back(jet);
711 std::cout <<
"<VirtualJetProducer::writeCompoundJets (moduleLabel = " <<
moduleLabel_ <<
")>:" << std::endl;
717 std::auto_ptr<std::vector<T> > subjetCollection(
new std::vector<T>() );
722 std::vector< std::vector<int> > indices;
724 std::vector<math::XYZTLorentzVector> p4_hardJets;
726 std::vector<double> area_hardJets;
729 std::vector<fastjet::PseudoJet>::const_iterator it =
fjJets_.begin(),
732 indices.resize(
fjJets_.size() );
733 for ( ; it != iEnd; ++it ) {
734 fastjet::PseudoJet
const & localJet = *it;
735 unsigned int jetIndex = it - iBegin;
738 double localJetArea = 0.0;
740 localJetArea = localJet.area();
742 area_hardJets.push_back( localJetArea );
745 std::vector<fastjet::PseudoJet> constituents;
746 if ( it->has_pieces() ) {
747 constituents = it->pieces();
748 }
else if ( it->has_constituents() ) {
749 constituents = it->constituents();
752 std::vector<fastjet::PseudoJet>::const_iterator itSubJetBegin = constituents.begin(),
753 itSubJet = itSubJetBegin, itSubJetEnd = constituents.end();
754 for (; itSubJet != itSubJetEnd; ++itSubJet ){
756 fastjet::PseudoJet
const & subjet = *itSubJet;
758 std::cout <<
"subjet #" << (itSubJet - itSubJetBegin) <<
": Pt = " << subjet.pt() <<
", eta = " << subjet.eta() <<
", phi = " << subjet.phi() <<
", mass = " << subjet.m()
759 <<
" (#constituents = " << subjet.constituents().size() <<
")" << std::endl;
760 std::vector<fastjet::PseudoJet> subjet_constituents = subjet.constituents();
761 int idx_constituent = 0;
762 for ( std::vector<fastjet::PseudoJet>::const_iterator constituent = subjet_constituents.begin();
763 constituent != subjet_constituents.end(); ++constituent ) {
764 if ( constituent->pt() < 1.e-3 )
continue;
765 std::cout <<
" constituent #" << idx_constituent <<
": Pt = " << constituent->pt() <<
", eta = " << constituent->eta() <<
", phi = " << constituent->phi() <<
","
766 <<
" mass = " << constituent->m() << std::endl;
772 std::cout <<
"subjet #" << (itSubJet - itSubJetBegin) <<
": Pt = " << subjet.pt() <<
", eta = " << subjet.eta() <<
", phi = " << subjet.phi() <<
", mass = " << subjet.m()
773 <<
" (#constituents = " << subjet.constituents().size() <<
")" << std::endl;
774 std::vector<fastjet::PseudoJet> subjet_constituents = subjet.constituents();
775 int idx_constituent = 0;
776 for ( std::vector<fastjet::PseudoJet>::const_iterator constituent = subjet_constituents.begin();
777 constituent != subjet_constituents.end(); ++constituent ) {
778 if ( constituent->pt() < 1.e-3 )
continue;
779 std::cout <<
" constituent #" << idx_constituent <<
": Pt = " << constituent->pt() <<
", eta = " << constituent->eta() <<
", phi = " << constituent->phi() <<
","
780 <<
" mass = " << constituent->m() << std::endl;
789 std::vector<reco::CandidatePtr> subjetConstituents;
792 std::vector<fastjet::PseudoJet> subjetFastjetConstituents = subjet.constituents();
793 std::vector<reco::CandidatePtr> constituents =
796 indices[jetIndex].push_back( subjetCollection->size() );
801 double subjetArea = 0.0;
803 subjetArea = itSubJet->area();
805 jet.setJetArea( subjetArea );
806 subjetCollection->push_back( jet );
814 std::vector<math::XYZTLorentzVector>::const_iterator ip4 = p4_hardJets.begin(),
815 ip4Begin = p4_hardJets.begin(),
816 ip4End = p4_hardJets.end();
818 for ( ; ip4 != ip4End; ++ip4 ) {
819 int p4_index = ip4 - ip4Begin;
820 std::vector<int> & ind = indices[p4_index];
821 std::vector<reco::CandidatePtr> i_hardJetConstituents;
823 for( std::vector<int>::const_iterator isub = ind.begin();
824 isub != ind.end(); ++isub ) {
826 i_hardJetConstituents.push_back( candPtr );
830 toput.
setJetArea( area_hardJets[ip4 - ip4Begin] );
831 jetCollection->push_back( toput );
835 iEvent.
put( jetCollection);
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
reco::Particle::Point vertex_
Jets made from CaloTowers.
static const HistoName names[]
math::PtEtaPhiMLorentzVector p4(double vtxZ) const
virtual std::vector< reco::CandidatePtr > getConstituents(const std::vector< fastjet::PseudoJet > &fjConstituents)
std::vector< fastjet::PseudoJet > fjJets_
virtual void inputTowers()
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)
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
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
static const char * names[]
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()
T const * get() const
Returns C++ pointer to the item.
const T & max(const T &a, const T &b)
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="")
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 getByLabel(InputTag const &tag, Handle< PROD > &result) const
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
double rho()
synonym for median rho [[do we have this? Both?]]
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
double sigma()
get the sigma
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
math::XYZTLorentzVector LorentzVector
Lorentz vector.
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::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