36 #include "fastjet/SISConePlugin.hh"
37 #include "fastjet/CMSIterativeConePlugin.hh"
38 #include "fastjet/ATLASConePlugin.hh"
39 #include "fastjet/CDFMidPointPlugin.hh"
46 #include <vdt/vdtMath.h>
54 bool operator()(
const fastjet::PseudoJet & t1,
const fastjet::PseudoJet & t2 )
const {
55 return t1.perp() > t2.perp();
64 "BasicJet",
"GenJet",
"CaloJet",
"PFJet",
"TrackJet",
"PFClusterJet"
73 if (pos ==
names + LastJetType) {
74 std::string errorMessage=
"Requested jetType not supported: "+name+
"\n";
85 if ( writeCompound_ ) {
86 produces<reco::BasicJetCollection>();
89 if (makeCaloJet(jetTypeE)) {
90 produces<reco::CaloJetCollection>(
tag).setBranchAlias(alias);
92 else if (makePFJet(jetTypeE)) {
93 produces<reco::PFJetCollection>(
tag).setBranchAlias(alias);
95 else if (makeGenJet(jetTypeE)) {
96 produces<reco::GenJetCollection>(
tag).setBranchAlias(alias);
98 else if (makeTrackJet(jetTypeE)) {
99 produces<reco::TrackJetCollection>(
tag).setBranchAlias(alias);
101 else if (makePFClusterJet(jetTypeE)) {
102 produces<reco::PFClusterJetCollection>(
tag).setBranchAlias(alias);
104 else if (makeBasicJet(jetTypeE)) {
105 produces<reco::BasicJetCollection>(
tag).setBranchAlias(alias);
116 , src_ (iConfig.getParameter<edm::InputTag>(
"src"))
117 , srcPVs_ (iConfig.getParameter<edm::InputTag>(
"srcPVs"))
118 , jetType_ (iConfig.getParameter<
string> (
"jetType"))
119 , jetAlgorithm_ (iConfig.getParameter<
string> (
"jetAlgorithm"))
120 , rParam_ (iConfig.getParameter<double> (
"rParam"))
121 , inputEtMin_ (iConfig.getParameter<double> (
"inputEtMin"))
122 , inputEMin_ (iConfig.getParameter<double> (
"inputEMin"))
123 , jetPtMin_ (iConfig.getParameter<double> (
"jetPtMin"))
124 , doPVCorrection_(iConfig.getParameter<bool> (
"doPVCorrection"))
125 , restrictInputs_(
false)
126 , maxInputs_(99999999)
127 , doAreaFastjet_ (iConfig.getParameter<bool> (
"doAreaFastjet"))
128 , useExplicitGhosts_(
false)
129 , doAreaDiskApprox_ (
false)
130 , doRhoFastjet_ (iConfig.getParameter<bool> (
"doRhoFastjet"))
132 , doPUOffsetCorr_(iConfig.getParameter<bool> (
"doPUOffsetCorr"))
135 , jetCollInstanceName_ (
"")
136 , writeCompound_ (
false )
149 fastjet::SISConePlugin::SM_pttilde) );
176 <<
"Jet algorithm for VirtualJetProducer is invalid, Abort!\n";
180 if ( iConfig.
exists(
"jetCollInstanceName") ) {
186 throw cms::Exception(
"InvalidInput") <<
"Can only offset correct jets of type CaloJet or BasicJet";
193 edm::LogWarning(
"VirtualJetProducer") <<
"Pile Up correction on; however, pile up type is not specified. Using default... \n";
201 if ( iConfig.
exists(
"useExplicitGhosts") ) {
206 if (iConfig.
exists(
"doAreaDiskApprox")) {
209 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";
214 if (iConfig.
exists(
"voronoiRfact"))
222 double rhoEtaMax=iConfig.
getParameter<
double>(
"Rho_EtaMax");
224 double ghostEtaMax = iConfig.
getParameter<
double>(
"Ghost_EtaMax");
226 int activeAreaRepeats = iConfig.
getParameter<
int> (
"Active_Area_Repeats");
228 double ghostArea = iConfig.
getParameter<
double> (
"GhostArea");
242 if ( iConfig.
exists(
"restrictInputs") ) {
253 if ( iConfig.
exists(
"writeCompound") ) {
270 if ( iConfig.
exists(
"useDeterministicSeed") ) {
275 if ( iConfig.
exists(
"verbosity" ) ) {
279 produces<std::vector<double> >(
"rhos");
280 produces<std::vector<double> >(
"sigmas");
281 produces<double>(
"rho");
282 produces<double>(
"sigma");
310 fastjet::GhostedAreaSpec gas;
311 std::vector<int> seeds(2);
314 gas.set_random_status(seeds);
317 LogDebug(
"VirtualJetProducer") <<
"Entered produce\n";
321 LogDebug(
"VirtualJetProducer") <<
"Adding PV info\n";
324 if (pvCollection->size()>0)
vertex_=pvCollection->begin()->position();
334 LogDebug(
"VirtualJetProducer") <<
"Clear data\n";
346 for (
size_t i = 0;
i < inputsHandle->size(); ++
i) {
347 inputs_.push_back(inputsHandle->ptrAt(
i));
351 for (
size_t i = 0;
i < pfinputsHandleAsFwdPtr->size(); ++
i) {
352 if ( (*pfinputsHandleAsFwdPtr)[
i].ptr().isAvailable() ) {
353 inputs_.push_back( (*pfinputsHandleAsFwdPtr)[
i].ptr() );
355 else if ( (*pfinputsHandleAsFwdPtr)[
i].backPtr().isAvailable() ) {
356 inputs_.push_back( (*pfinputsHandleAsFwdPtr)[
i].backPtr() );
360 LogDebug(
"VirtualJetProducer") <<
"Got inputs\n";
367 LogDebug(
"VirtualJetProducer") <<
"Inputted towers\n";
376 LogDebug(
"VirtualJetProducer") <<
"Subtracted pedestal\n";
386 LogDebug(
"VirtualJetProducer") <<
"Ran algorithm\n";
394 LogDebug(
"VirtualJetProducer") <<
"Do PUOffsetCorr\n";
395 vector<fastjet::PseudoJet> orphanInput;
405 LogDebug(
"VirtualJetProducer") <<
"Wrote jets\n";
414 std::vector<edm::Ptr<reco::Candidate> >::const_iterator inBegin =
inputs_.begin(),
416 for (;
i != inEnd; ++
i ) {
423 if (input->pt() == 0) {
424 edm::LogError(
"NullTransverseMomentum") <<
"dropping input candidate with pt=0";
430 fjInputs_.push_back(fastjet::PseudoJet(ct.px(),ct.py(),ct.pz(),ct.energy()));
440 fjInputs_.push_back(fastjet::PseudoJet(input->px(),input->py(),input->pz(),
450 edm::LogWarning(
"JetRecoTooManyEntries") <<
"Too many inputs in the event, limiting to first " <<
maxInputs_ <<
". Output is suspect.";
473 for (
unsigned int i=0;
i<fjConstituents.size();++
i) {
474 int index = fjConstituents[
i].user_index();
475 if ( index >= 0 && static_cast<unsigned int>(index) <
inputs_.size() )
482 vector<reco::CandidatePtr>
485 vector<reco::CandidatePtr>
result;
486 for (
unsigned int i=0;
i<fjConstituents.size();
i++) {
487 int index = fjConstituents[
i].user_index();
488 if ( index >= 0 && static_cast<unsigned int>(index) <
inputs_.size() ) {
490 result.push_back(candidate);
507 writeJets<reco::CaloJet>(
iEvent, iSetup);
510 writeJets<reco::PFJet>(
iEvent, iSetup);
513 writeJets<reco::GenJet>(
iEvent, iSetup);
516 writeJets<reco::TrackJet>(
iEvent, iSetup);
519 writeJets<reco::PFClusterJet>(
iEvent, iSetup);
522 writeJets<reco::BasicJet>(
iEvent, iSetup);
525 throw cms::Exception(
"InvalidInput") <<
"invalid jet type in VirtualJetProducer\n";
532 writeCompoundJets<reco::CaloJet>(
iEvent, iSetup );
535 writeCompoundJets<reco::PFJet>(
iEvent, iSetup );
538 writeCompoundJets<reco::GenJet>(
iEvent, iSetup );
541 writeCompoundJets<reco::BasicJet>(
iEvent, iSetup );
544 throw cms::Exception(
"InvalidInput") <<
"invalid jet type in CompoundJetProducer\n";
551 template<
typename T >
552 struct Area {
static float get(
T const &) {
return 0;}};
556 return jet.getSpecific().mTowersArea;
561 template<
typename T >
573 std::vector<fastjet::PseudoJet> fjexcluded_jets;
576 if(fjexcluded_jets.size()>2) fjexcluded_jets.resize(
nExclude_);
579 std::auto_ptr<std::vector<double> > rhos(
new std::vector<double>);
580 std::auto_ptr<std::vector<double> > sigmas(
new std::vector<double>);
583 sigmas->reserve(nEta);
584 fastjet::ClusterSequenceAreaBase
const* clusterSequenceWithArea =
585 dynamic_cast<fastjet::ClusterSequenceAreaBase
const *
> ( &*
fjClusterSeq_ );
588 for(
int ie = 0; ie < nEta; ++ie){
592 fastjet::RangeDefinition range_rho(etamin,etamax);
595 rhos->push_back(bkgestim.
rho());
596 sigmas->push_back(bkgestim.
sigma());
598 iEvent.
put(rhos,
"rhos");
599 iEvent.
put(sigmas,
"sigmas");
601 std::auto_ptr<double>
rho(
new double(0.0));
602 std::auto_ptr<double> sigma(
new double(0.0));
603 double mean_area = 0;
605 fastjet::ClusterSequenceAreaBase
const* clusterSequenceWithArea =
606 dynamic_cast<fastjet::ClusterSequenceAreaBase
const *
> ( &*
fjClusterSeq_ );
613 clusterSequenceWithArea->get_median_rho_and_sigma(*
fjRangeDef_,
false,*rho,*sigma,mean_area);
615 edm::LogError(
"BadRho") <<
"rho value is " << *rho <<
" area:" << mean_area <<
" and n_empty_jets: " << clusterSequenceWithArea->n_empty_jets(*
fjRangeDef_) <<
" with range " <<
fjRangeDef_->description()
616 <<
". Setting rho to rezo.";
619 iEvent.
put(rho,
"rho");
620 iEvent.
put(sigma,
"sigma");
626 using namespace reco;
628 std::auto_ptr<std::vector<T> >
jets(
new std::vector<T>() );
632 using RIJ = std::pair<double,double>;
633 std::vector<std::vector<RIJ> > rij(
fjJets_.size());
637 for (
auto ijet=0U;ijet<
fjJets_.size();++ijet) {
641 phiJ[ijet] = vdt::fast_atan2(y,x);
642 etaJ[ijet] =etaFromXYZ(x,y,z);
644 for (
unsigned int ijet=0;ijet<
fjJets_.size();++ijet) {
648 const fastjet::PseudoJet& fjJet =
fjJets_[ijet];
650 std::vector<fastjet::PseudoJet> fjConstituents = fastjet::sorted_by_pt(fjJet.constituents());
652 std::vector<CandidatePtr> constituents =
658 jetArea = fjJet.area();
665 std::vector<RIJ>& distance = rij[ijet];
666 distance.resize(ijet);
667 for (
unsigned jJet = 0; jJet < ijet; ++jJet) {
670 jetArea -=distance[jJet].second;
671 for (
unsigned kJet = 0; kJet < jJet; ++kJet) {
673 distance[jJet].
second, distance[kJet].second, rij[jJet][kJet].second);
689 constituents, iSetup);
691 jet.setJetArea (jetArea);
704 jets->push_back(jet);
715 std::cout <<
"<VirtualJetProducer::writeCompoundJets (moduleLabel = " <<
moduleLabel_ <<
")>:" << std::endl;
721 std::auto_ptr<std::vector<T> > subjetCollection(
new std::vector<T>() );
726 std::vector< std::vector<int> > indices;
728 std::vector<math::XYZTLorentzVector> p4_hardJets;
730 std::vector<double> area_hardJets;
733 std::vector<fastjet::PseudoJet>::const_iterator it =
fjJets_.begin(),
736 indices.resize(
fjJets_.size() );
737 for ( ; it != iEnd; ++it ) {
738 fastjet::PseudoJet
const & localJet = *it;
739 unsigned int jetIndex = it - iBegin;
742 double localJetArea = 0.0;
744 localJetArea = localJet.area();
746 area_hardJets.push_back( localJetArea );
749 std::vector<fastjet::PseudoJet> constituents;
750 if ( it->has_pieces() ) {
751 constituents = it->pieces();
752 }
else if ( it->has_constituents() ) {
753 constituents = it->constituents();
756 std::vector<fastjet::PseudoJet>::const_iterator itSubJetBegin = constituents.begin(),
757 itSubJet = itSubJetBegin, itSubJetEnd = constituents.end();
758 for (; itSubJet != itSubJetEnd; ++itSubJet ){
760 fastjet::PseudoJet
const & subjet = *itSubJet;
762 std::cout <<
"subjet #" << (itSubJet - itSubJetBegin) <<
": Pt = " << subjet.pt() <<
", eta = " << subjet.eta() <<
", phi = " << subjet.phi() <<
", mass = " << subjet.m()
763 <<
" (#constituents = " << subjet.constituents().size() <<
")" << std::endl;
764 std::vector<fastjet::PseudoJet> subjet_constituents = subjet.constituents();
765 int idx_constituent = 0;
766 for ( std::vector<fastjet::PseudoJet>::const_iterator constituent = subjet_constituents.begin();
767 constituent != subjet_constituents.end(); ++constituent ) {
768 if ( constituent->pt() < 1.e-3 )
continue;
769 std::cout <<
" constituent #" << idx_constituent <<
": Pt = " << constituent->pt() <<
", eta = " << constituent->eta() <<
", phi = " << constituent->phi() <<
","
770 <<
" mass = " << constituent->m() << std::endl;
776 std::cout <<
"subjet #" << (itSubJet - itSubJetBegin) <<
": Pt = " << subjet.pt() <<
", eta = " << subjet.eta() <<
", phi = " << subjet.phi() <<
", mass = " << subjet.m()
777 <<
" (#constituents = " << subjet.constituents().size() <<
")" << std::endl;
778 std::vector<fastjet::PseudoJet> subjet_constituents = subjet.constituents();
779 int idx_constituent = 0;
780 for ( std::vector<fastjet::PseudoJet>::const_iterator constituent = subjet_constituents.begin();
781 constituent != subjet_constituents.end(); ++constituent ) {
782 if ( constituent->pt() < 1.e-3 )
continue;
783 std::cout <<
" constituent #" << idx_constituent <<
": Pt = " << constituent->pt() <<
", eta = " << constituent->eta() <<
", phi = " << constituent->phi() <<
","
784 <<
" mass = " << constituent->m() << std::endl;
793 std::vector<reco::CandidatePtr> subjetConstituents;
796 std::vector<fastjet::PseudoJet> subjetFastjetConstituents = subjet.constituents();
797 std::vector<reco::CandidatePtr> constituents =
800 indices[jetIndex].push_back( subjetCollection->size() );
805 double subjetArea = 0.0;
807 subjetArea = itSubJet->area();
809 jet.setJetArea( subjetArea );
810 subjetCollection->push_back( jet );
818 std::vector<math::XYZTLorentzVector>::const_iterator ip4 = p4_hardJets.begin(),
819 ip4Begin = p4_hardJets.begin(),
820 ip4End = p4_hardJets.end();
822 for ( ; ip4 != ip4End; ++ip4 ) {
823 int p4_index = ip4 - ip4Begin;
824 std::vector<int> & ind = indices[p4_index];
825 std::vector<reco::CandidatePtr> i_hardJetConstituents;
827 for( std::vector<int>::const_iterator isub = ind.begin();
828 isub != ind.end(); ++isub ) {
830 i_hardJetConstituents.push_back( candPtr );
834 toput.
setJetArea( area_hardJets[ip4 - ip4Begin] );
835 jetCollection->push_back( toput );
839 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
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()
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.
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_
double deltaR2(const T1 &t1, const T2 &t2)
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_
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
double rho()
synonym for median rho [[do we have this? Both?]]
edm::EDGetTokenT< std::vector< edm::FwdPtr< reco::PFCandidate > > > input_candidatefwdptr_token_
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
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