39 #include "fastjet/SISConePlugin.hh"
40 #include "fastjet/CMSIterativeConePlugin.hh"
41 #include "fastjet/ATLASConePlugin.hh"
42 #include "fastjet/CDFMidPointPlugin.hh"
57 bool operator()(
const fastjet::PseudoJet & t1,
const fastjet::PseudoJet &
t2 )
const {
58 return t1.perp() > t2.perp();
67 "BasicJet",
"GenJet",
"CaloJet",
"PFJet",
"TrackJet",
"PFClusterJet"
76 if (pos ==
names + LastJetType) {
77 std::string errorMessage=
"Requested jetType not supported: "+name+
"\n";
88 if ( writeCompound_ ) {
89 produces<reco::BasicJetCollection>();
92 if (makeCaloJet(jetTypeE)) {
93 produces<reco::CaloJetCollection>(
tag).setBranchAlias(alias);
95 else if (makePFJet(jetTypeE)) {
96 produces<reco::PFJetCollection>(
tag).setBranchAlias(alias);
98 else if (makeGenJet(jetTypeE)) {
99 produces<reco::GenJetCollection>(
tag).setBranchAlias(alias);
101 else if (makeTrackJet(jetTypeE)) {
102 produces<reco::TrackJetCollection>(
tag).setBranchAlias(alias);
104 else if (makePFClusterJet(jetTypeE)) {
105 produces<reco::PFClusterJetCollection>(
tag).setBranchAlias(alias);
107 else if (makeBasicJet(jetTypeE)) {
108 produces<reco::BasicJetCollection>(
tag).setBranchAlias(alias);
118 : moduleLabel_ (iConfig.getParameter<
string> (
"@module_label"))
119 , src_ (iConfig.getParameter<edm::InputTag>(
"src"))
120 , srcPVs_ (iConfig.getParameter<edm::InputTag>(
"srcPVs"))
121 , jetType_ (iConfig.getParameter<
string> (
"jetType"))
122 , jetAlgorithm_ (iConfig.getParameter<
string> (
"jetAlgorithm"))
123 , rParam_ (iConfig.getParameter<double> (
"rParam"))
124 , inputEtMin_ (iConfig.getParameter<double> (
"inputEtMin"))
125 , inputEMin_ (iConfig.getParameter<double> (
"inputEMin"))
126 , jetPtMin_ (iConfig.getParameter<double> (
"jetPtMin"))
127 , doPVCorrection_(iConfig.getParameter<bool> (
"doPVCorrection"))
128 , restrictInputs_(
false)
129 , maxInputs_(99999999)
130 , doAreaFastjet_ (iConfig.getParameter<bool> (
"doAreaFastjet"))
131 , useExplicitGhosts_(
false)
132 , doAreaDiskApprox_ (
false)
133 , doRhoFastjet_ (iConfig.getParameter<bool> (
"doRhoFastjet"))
135 , doPUOffsetCorr_(iConfig.getParameter<bool> (
"doPUOffsetCorr"))
138 , jetCollInstanceName_ (
"")
139 , writeCompound_ (
false )
151 fastjet::SISConePlugin::SM_pttilde) );
178 <<
"Jet algorithm for VirtualJetProducer is invalid, Abort!\n";
182 if ( iConfig.
exists(
"jetCollInstanceName") ) {
188 throw cms::Exception(
"InvalidInput") <<
"Can only offset correct jets of type CaloJet or BasicJet";
195 edm::LogWarning(
"VirtualJetProducer") <<
"Pile Up correction on; however, pile up type is not specified. Using default... \n";
203 if ( iConfig.
exists(
"useExplicitGhosts") ) {
208 if (iConfig.
exists(
"doAreaDiskApprox")) {
211 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";
216 if (iConfig.
exists(
"voronoiRfact"))
224 double rhoEtaMax=iConfig.
getParameter<
double>(
"Rho_EtaMax");
226 double ghostEtaMax = iConfig.
getParameter<
double>(
"Ghost_EtaMax");
228 int activeAreaRepeats = iConfig.
getParameter<
int> (
"Active_Area_Repeats");
230 double ghostArea = iConfig.
getParameter<
double> (
"GhostArea");
244 if ( iConfig.
exists(
"restrictInputs") ) {
255 if ( iConfig.
exists(
"writeCompound") ) {
272 if ( iConfig.
exists(
"useDeterministicSeed") ) {
278 produces<std::vector<double> >(
"rhos");
279 produces<std::vector<double> >(
"sigmas");
280 produces<double>(
"rho");
281 produces<double>(
"sigma");
306 fastjet::GhostedAreaSpec gas;
307 std::vector<int> seeds(2);
310 gas.set_random_status(seeds);
313 LogDebug(
"VirtualJetProducer") <<
"Entered produce\n";
317 LogDebug(
"VirtualJetProducer") <<
"Adding PV info\n";
320 if (pvCollection->size()>0)
vertex_=pvCollection->begin()->position();
330 LogDebug(
"VirtualJetProducer") <<
"Clear data\n";
341 for (
size_t i = 0;
i < inputsHandle->size(); ++
i) {
342 inputs_.push_back(inputsHandle->ptrAt(
i));
346 for (
size_t i = 0;
i < pfinputsHandleAsFwdPtr->size(); ++
i) {
347 if ( (*pfinputsHandleAsFwdPtr)[
i].ptr().isAvailable() ) {
348 inputs_.push_back( (*pfinputsHandleAsFwdPtr)[
i].ptr() );
350 else if ( (*pfinputsHandleAsFwdPtr)[
i].backPtr().isAvailable() ) {
351 inputs_.push_back( (*pfinputsHandleAsFwdPtr)[
i].backPtr() );
355 LogDebug(
"VirtualJetProducer") <<
"Got inputs\n";
362 LogDebug(
"VirtualJetProducer") <<
"Inputted towers\n";
371 LogDebug(
"VirtualJetProducer") <<
"Subtracted pedestal\n";
381 LogDebug(
"VirtualJetProducer") <<
"Ran algorithm\n";
389 LogDebug(
"VirtualJetProducer") <<
"Do PUOffsetCorr\n";
390 vector<fastjet::PseudoJet> orphanInput;
400 LogDebug(
"VirtualJetProducer") <<
"Wrote jets\n";
409 std::vector<edm::Ptr<reco::Candidate> >::const_iterator inBegin =
inputs_.begin(),
411 for (;
i != inEnd; ++
i ) {
417 if (input->pt() == 0) {
418 edm::LogError(
"NullTransverseMomentum") <<
"dropping input candidate with pt=0";
424 fjInputs_.push_back(fastjet::PseudoJet(ct.px(),ct.py(),ct.pz(),ct.energy()));
434 fjInputs_.push_back(fastjet::PseudoJet(input->px(),input->py(),input->pz(),
444 edm::LogWarning(
"JetRecoTooManyEntries") <<
"Too many inputs in the event, limiting to first " <<
maxInputs_ <<
". Output is suspect.";
467 for (
unsigned int i=0;
i<fjConstituents.size();++
i) {
468 int index = fjConstituents[
i].user_index();
469 if ( index >= 0 && static_cast<unsigned int>(index) <
inputs_.size() )
476 vector<reco::CandidatePtr>
479 vector<reco::CandidatePtr>
result;
480 for (
unsigned int i=0;
i<fjConstituents.size();
i++) {
481 int index = fjConstituents[
i].user_index();
482 if ( index >= 0 && static_cast<unsigned int>(index) <
inputs_.size() ) {
484 result.push_back(candidate);
501 writeJets<reco::CaloJet>(
iEvent, iSetup);
504 writeJets<reco::PFJet>(
iEvent, iSetup);
507 writeJets<reco::GenJet>(
iEvent, iSetup);
510 writeJets<reco::TrackJet>(
iEvent, iSetup);
513 writeJets<reco::PFClusterJet>(
iEvent, iSetup);
516 writeJets<reco::BasicJet>(
iEvent, iSetup);
519 throw cms::Exception(
"InvalidInput") <<
"invalid jet type in VirtualJetProducer\n";
526 writeCompoundJets<reco::CaloJet>(
iEvent, iSetup );
529 writeCompoundJets<reco::PFJet>(
iEvent, iSetup );
532 writeCompoundJets<reco::GenJet>(
iEvent, iSetup );
535 writeCompoundJets<reco::BasicJet>(
iEvent, iSetup );
538 throw cms::Exception(
"InvalidInput") <<
"invalid jet type in CompoundJetProducer\n";
545 template<
typename T >
551 std::vector<fastjet::PseudoJet> fjexcluded_jets;
554 if(fjexcluded_jets.size()>2) fjexcluded_jets.resize(
nExclude_);
557 std::auto_ptr<std::vector<double> > rhos(
new std::vector<double>);
558 std::auto_ptr<std::vector<double> > sigmas(
new std::vector<double>);
561 sigmas->reserve(nEta);
562 fastjet::ClusterSequenceAreaBase
const* clusterSequenceWithArea =
563 dynamic_cast<fastjet::ClusterSequenceAreaBase
const *
> ( &*
fjClusterSeq_ );
566 for(
int ie = 0; ie < nEta; ++ie){
570 fastjet::RangeDefinition range_rho(etamin,etamax);
573 rhos->push_back(bkgestim.
rho());
574 sigmas->push_back(bkgestim.
sigma());
576 iEvent.
put(rhos,
"rhos");
577 iEvent.
put(sigmas,
"sigmas");
579 std::auto_ptr<double>
rho(
new double(0.0));
580 std::auto_ptr<double> sigma(
new double(0.0));
581 double mean_area = 0;
583 fastjet::ClusterSequenceAreaBase
const* clusterSequenceWithArea =
584 dynamic_cast<fastjet::ClusterSequenceAreaBase
const *
> ( &*
fjClusterSeq_ );
591 clusterSequenceWithArea->get_median_rho_and_sigma(*
fjRangeDef_,
false,*rho,*sigma,mean_area);
593 edm::LogError(
"BadRho") <<
"rho value is " << *rho <<
" area:" << mean_area <<
" and n_empty_jets: " << clusterSequenceWithArea->n_empty_jets(*
fjRangeDef_) <<
" with range " <<
fjRangeDef_->description()
594 <<
". Setting rho to rezo.";
597 iEvent.
put(rho,
"rho");
598 iEvent.
put(sigma,
"sigma");
604 using namespace reco;
606 std::auto_ptr<std::vector<T> >
jets(
new std::vector<T>() );
610 std::vector<std::vector<double> > rij(
fjJets_.size());
612 for (
unsigned int ijet=0;ijet<
fjJets_.size();++ijet) {
616 const fastjet::PseudoJet& fjJet =
fjJets_[ijet];
618 std::vector<fastjet::PseudoJet> fjConstituents = fastjet::sorted_by_pt(fjJet.constituents());
620 std::vector<CandidatePtr> constituents =
627 jetArea = fjJet.area();
634 std::vector<double>& distance = rij[ijet];
635 distance.resize(ijet);
636 for (
unsigned jJet = 0; jJet < ijet; ++jJet) {
639 for (
unsigned kJet = 0; kJet < jJet; ++kJet) {
656 constituents, iSetup);
658 jet.setJetArea (jetArea);
667 jets->push_back(jet);
685 std::auto_ptr<std::vector<T> > subjetCollection(
new std::vector<T>() );
690 std::vector< std::vector<int> > indices;
692 std::vector<math::XYZTLorentzVector> p4_hardJets;
694 std::vector<double> area_hardJets;
698 std::vector<fastjet::PseudoJet>::const_iterator it =
fjJets_.begin(),
701 indices.resize(
fjJets_.size() );
702 for ( ; it != iEnd; ++it ) {
703 fastjet::PseudoJet
const & localJet = *it;
704 unsigned int jetIndex = it - iBegin;
707 double localJetArea = 0.0;
709 localJetArea = localJet.area();
711 area_hardJets.push_back( localJetArea );
714 std::vector<fastjet::PseudoJet> constituents;
715 if ( it->has_pieces() ) {
716 constituents = it->pieces();
718 constituents=it->constituents();
722 std::vector<fastjet::PseudoJet>::const_iterator itSubJetBegin = constituents.begin(),
723 itSubJet = itSubJetBegin, itSubJetEnd = constituents.end();
724 for (; itSubJet != itSubJetEnd; ++itSubJet ){
726 fastjet::PseudoJet
const & subjet = *itSubJet;
732 std::vector<reco::CandidatePtr> subjetConstituents;
735 std::vector<fastjet::PseudoJet> subjetFastjetConstituents = subjet.constituents();
736 std::vector<reco::CandidatePtr> constituents =
739 indices[jetIndex].push_back( subjetCollection->size() );
744 double subjetArea = 0.0;
746 subjetArea = itSubJet->area();
748 jet.setJetArea( subjetArea );
749 subjetCollection->push_back( jet );
758 std::vector<math::XYZTLorentzVector>::const_iterator ip4 = p4_hardJets.begin(),
759 ip4Begin = p4_hardJets.begin(),
760 ip4End = p4_hardJets.end();
762 for ( ; ip4 != ip4End; ++ip4 ) {
763 int p4_index = ip4 - ip4Begin;
764 std::vector<int> & ind = indices[p4_index];
765 std::vector<reco::CandidatePtr> i_hardJetConstituents;
767 for( std::vector<int>::const_iterator isub = ind.begin();
768 isub != ind.end(); ++isub ) {
770 i_hardJetConstituents.push_back( candPtr );
774 toput.
setJetArea( area_hardJets[ip4 - ip4Begin] );
775 jetCollection->push_back( toput );
779 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_
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
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
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
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_
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
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?]]
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)
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