CMS 3D CMS Logo

CSJetProducer.cc
Go to the documentation of this file.
3 
4 #include <memory>
5 
8 
9 #include "Math/ProbFuncMathCore.h"
10 
11 #include "fastjet/contrib/ConstituentSubtractor.hh"
12 
13 using namespace std;
14 using namespace reco;
15 using namespace edm;
16 using namespace cms;
17 
18 CSJetProducer::CSJetProducer(edm::ParameterSet const& conf)
19  : VirtualJetProducer(conf),
20  csRParam_(-1.0),
21  csAlpha_(0.),
22  useModulatedRho_(conf.getParameter<bool>("useModulatedRho")),
23  minFlowChi2Prob_(conf.getParameter<double>("minFlowChi2Prob")),
24  maxFlowChi2Prob_(conf.getParameter<double>("maxFlowChi2Prob")) {
25  //get eta range, rho and rhom map
26  etaToken_ = consumes<std::vector<double>>(conf.getParameter<edm::InputTag>("etaMap"));
27  rhoToken_ = consumes<std::vector<double>>(conf.getParameter<edm::InputTag>("rho"));
28  rhomToken_ = consumes<std::vector<double>>(conf.getParameter<edm::InputTag>("rhom"));
29  csRParam_ = conf.getParameter<double>("csRParam");
30  csAlpha_ = conf.getParameter<double>("csAlpha");
31  if (useModulatedRho_)
32  rhoFlowFitParamsToken_ = consumes<std::vector<double>>(conf.getParameter<edm::InputTag>("rhoFlowFitParams"));
33 }
34 
36  // use the default production from one collection
38  //use runAlgorithm of this class
39 
40  //Delete allocated memory. It is allocated every time runAlgorithm is called
41  fjClusterSeq_.reset();
42 }
43 
44 //______________________________________________________________________________
46  // run algorithm
47  if (!doAreaFastjet_ && !doRhoFastjet_) {
48  fjClusterSeq_ = std::make_shared<fastjet::ClusterSequence>(fjInputs_, *fjJetDefinition_);
49  } else if (voronoiRfact_ <= 0) {
51  ClusterSequencePtr(new fastjet::ClusterSequenceArea(fjInputs_, *fjJetDefinition_, *fjAreaDefinition_));
52  } else {
54  new fastjet::ClusterSequenceVoronoiArea(fjInputs_, *fjJetDefinition_, fastjet::VoronoiAreaSpec(voronoiRfact_)));
55  }
56 
57  fjJets_.clear();
58  std::vector<fastjet::PseudoJet> tempJets = fastjet::sorted_by_pt(fjClusterSeq_->inclusive_jets(jetPtMin_));
59 
60  //Get local rho and rhom map
65  iEvent.getByToken(etaToken_, etaRanges);
66  iEvent.getByToken(rhoToken_, rhoRanges);
67  iEvent.getByToken(rhomToken_, rhomRanges);
68  if (useModulatedRho_)
70 
71  //Check if size of eta and background density vectors is the same
72  unsigned int bkgVecSize = etaRanges->size();
73  if (bkgVecSize < 1) {
74  throw cms::Exception("WrongBkgInput") << "Producer needs vector with background estimates\n";
75  }
76  if (bkgVecSize != (rhoRanges->size() + 1) || bkgVecSize != (rhomRanges->size() + 1)) {
77  throw cms::Exception("WrongBkgInput")
78  << "Size of etaRanges (" << bkgVecSize << ") and rhoRanges (" << rhoRanges->size() << ") and/or rhomRanges ("
79  << rhomRanges->size() << ") vectors inconsistent\n";
80  }
81  bool minProb = false;
82  bool maxProb = false;
83  if (useModulatedRho_) {
84  if (!rhoFlowFitParams->empty()) {
85  double val = ROOT::Math::chisquared_cdf_c(rhoFlowFitParams->at(5), rhoFlowFitParams->at(6));
87  maxProb = val < maxFlowChi2Prob_;
88  }
89  }
90 
91  //Allow the background densities to change within the jet
92 
93  for (fastjet::PseudoJet& ijet : tempJets) {
94  //----------------------------------------------------------------------
95  // sift ghosts and particles in the input jet
96  std::vector<fastjet::PseudoJet> particles, ghosts;
97  fastjet::SelectorIsPureGhost().sift(ijet.constituents(), ghosts, particles);
98  unsigned long nParticles = particles.size();
99  if (nParticles == 0)
100  continue; //don't subtract ghost jets
101 
102  //assign rho and rhom to ghosts according to local eta-dependent map + modulation as function of phi
103  for (fastjet::PseudoJet& ighost : ghosts) {
104  double rhoModulationFactor = 1.;
105  double ghostPhi = ighost.phi_std();
106 
107  if (useModulatedRho_) {
108  if (!rhoFlowFitParams->empty()) {
109  if (minProb && maxProb) {
110  rhoModulationFactor = getModulatedRhoFactor(ghostPhi,
111  rhoFlowFitParams->at(2),
112  rhoFlowFitParams->at(4),
113  rhoFlowFitParams->at(1),
114  rhoFlowFitParams->at(3));
115  }
116  }
117  }
118 
119  int32_t ghostPos = -1;
120  auto const ighostEta = ighost.eta();
121  if (ighostEta <= etaRanges->at(0) || bkgVecSize == 1) {
122  ghostPos = 0;
123  } else if (ighostEta >= etaRanges->at(bkgVecSize - 1)) {
124  ghostPos = rhoRanges->size() - 1;
125  } else {
126  for (unsigned int ie = 0; ie < (bkgVecSize - 1); ie++) {
127  if (ighostEta >= etaRanges->at(ie) && ighostEta < etaRanges->at(ie + 1)) {
128  ghostPos = ie;
129  break;
130  }
131  }
132  }
133  double pt = rhoRanges->at(ghostPos) * ighost.area() * rhoModulationFactor;
134  double mass_squared =
135  std::pow(rhoModulationFactor * rhomRanges->at(ghostPos) * ighost.area() + pt, 2) - std::pow(pt, 2);
136  double mass = (mass_squared > 0) ? sqrt(mass_squared) : 0;
137  ighost.reset_momentum_PtYPhiM(pt, ighost.rap(), ighost.phi(), mass);
138  }
139 
140  //----------------------------------------------------------------------
141  //from here use official fastjet contrib package
142 
143  fastjet::contrib::ConstituentSubtractor subtractor;
144  subtractor.set_distance_type(fastjet::contrib::ConstituentSubtractor::deltaR); // distance in eta-phi plane
145  subtractor.set_max_distance(
146  csRParam_); // free parameter for the maximal allowed distance between particle i and ghost k
147  subtractor.set_alpha(
148  csAlpha_); // free parameter for the distance measure (the exponent of particle pt). Note that in older versions of the package alpha was multiplied by two but in newer versions this is not the case anymore
149  subtractor.set_do_mass_subtraction();
150  subtractor.set_remove_all_zero_pt_particles(true);
151 
152  std::vector<fastjet::PseudoJet> subtracted_particles = subtractor.do_subtraction(particles, ghosts);
153 
154  //Create subtracted jets
155  fastjet::PseudoJet subtracted_jet = join(subtracted_particles);
156  if (subtracted_jet.perp() > 0.)
157  fjJets_.push_back(subtracted_jet);
158  }
159  fjJets_ = fastjet::sorted_by_pt(fjJets_);
160 }
161 
163  edm::ParameterSetDescription descCSJetProducer;
165  fillDescriptionsFromCSJetProducer(descCSJetProducer);
167  descCSJetProducer.add<string>("jetCollInstanceName", "");
169  descCSJetProducer.add<bool>("sumRecHits", false);
170 
172  descriptions.add("CSJetProducer", descCSJetProducer);
173 }
174 
176  desc.add<double>("csRParam", -1.);
177  desc.add<double>("csAlpha", 2.);
178  desc.add<bool>("useModulatedRho", false);
179  desc.add<double>("minFlowChi2Prob", 0.05);
180  desc.add<double>("maxFlowChi2Prob", 0.95);
181  desc.add<edm::InputTag>("etaMap", {"hiFJRhoProducer", "mapEtaEdges"});
182  desc.add<edm::InputTag>("rho", {"hiFJRhoProducer", "mapToRho"});
183  desc.add<edm::InputTag>("rhom", {"hiFJRhoProducer", "mapToRhoM"});
184  desc.add<edm::InputTag>("rhoFlowFitParams", {"hiFJRhoFlowModulationProducer", "rhoFlowFitParams"});
185 }
186 
188  const double phi, const double eventPlane2, const double eventPlane3, const double par1, const double par2) {
189  // get the rho modulation as function of phi
190  // flow modulation fit is done in RecoHI/HiJetAlgos/plugins/HiFJRhoFlowModulationProducer
191  return 1. + 2. * par1 * cos(2. * (phi - eventPlane2)) + par2 * cos(3. * (phi - eventPlane3));
192 }
193 
195 // define as cmssw plugin
197 
bTagCommon_cff.etaRanges
etaRanges
Definition: bTagCommon_cff.py:42
cms::CSJetProducer::csAlpha_
double csAlpha_
for constituent subtraction : R parameter
Definition: CSJetProducer.h:40
VirtualJetProducer::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: VirtualJetProducer.cc:264
electrons_cff.bool
bool
Definition: electrons_cff.py:393
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
VirtualJetProducer::ClusterSequencePtr
std::shared_ptr< fastjet::ClusterSequence > ClusterSequencePtr
Definition: VirtualJetProducer.h:73
edm
HLT enums.
Definition: AlignableModifier.h:19
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
cms::CSJetProducer::useModulatedRho_
bool useModulatedRho_
for HI constituent subtraction : alpha (power of pt in metric)
Definition: CSJetProducer.h:42
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
pfMETCorrectionType0_cfi.par1
par1
Definition: pfMETCorrectionType0_cfi.py:48
cms::CSJetProducer::csRParam_
double csRParam_
Definition: CSJetProducer.h:39
edm::Handle
Definition: AssociativeIterator.h:50
VirtualJetProducer::voronoiRfact_
double voronoiRfact_
Definition: VirtualJetProducer.h:170
ecalTrigSettings_cff.particles
particles
Definition: ecalTrigSettings_cff.py:11
VirtualJetProducer::fjClusterSeq_
ClusterSequencePtr fjClusterSeq_
Definition: VirtualJetProducer.h:185
cms::CSJetProducer::rhoToken_
edm::EDGetTokenT< std::vector< double > > rhoToken_
Definition: CSJetProducer.h:47
HLT_FULL_cff.rhoFlowFitParams
rhoFlowFitParams
Definition: HLT_FULL_cff.py:106021
MakerMacros.h
cms::CSJetProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: CSJetProducer.cc:162
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
cms::CSJetProducer::rhoFlowFitParamsToken_
edm::EDGetTokenT< std::vector< double > > rhoFlowFitParamsToken_
Definition: CSJetProducer.h:49
cms::CSJetProducer::maxFlowChi2Prob_
double maxFlowChi2Prob_
flowFit chi2/ndof minimum compatability requirement
Definition: CSJetProducer.h:44
VirtualJetProducer
Definition: VirtualJetProducer.h:35
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
VirtualJetProducer::doRhoFastjet_
bool doRhoFastjet_
Definition: VirtualJetProducer.h:167
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
cms::CSJetProducer
Definition: CSJetProducer.h:24
edm::ParameterSet
Definition: ParameterSet.h:47
cms::CSJetProducer::getModulatedRhoFactor
double getModulatedRhoFactor(double phi, double eventPlane2, double eventPlane3, double par1, double par2)
Definition: CSJetProducer.cc:187
pfMETCorrectionType0_cfi.par2
par2
Definition: pfMETCorrectionType0_cfi.py:49
VirtualJetProducer::jetPtMin_
double jetPtMin_
Definition: VirtualJetProducer.h:155
iEvent
int iEvent
Definition: GenABIO.cc:224
conversionTrackMerger_cfi.minProb
minProb
Definition: conversionTrackMerger_cfi.py:10
cms::CSJetProducer::rhomToken_
edm::EDGetTokenT< std::vector< double > > rhomToken_
Definition: CSJetProducer.h:48
edm::EventSetup
Definition: EventSetup.h:57
VirtualJetProducer::fjAreaDefinition_
AreaDefinitionPtr fjAreaDefinition_
Definition: VirtualJetProducer.h:189
cms::CSJetProducer::runAlgorithm
void runAlgorithm(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: CSJetProducer.cc:45
cms::CSJetProducer::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: CSJetProducer.cc:35
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
heppy_batch.val
val
Definition: heppy_batch.py:351
std
Definition: JetResolutionObject.h:76
cms::CSJetProducer::etaToken_
edm::EDGetTokenT< std::vector< double > > etaToken_
flowFit chi2/ndof minimum compatability requirement
Definition: CSJetProducer.h:46
VirtualJetProducer::doAreaFastjet_
bool doAreaFastjet_
Definition: VirtualJetProducer.h:163
Exception
Definition: hltDiff.cc:246
CSJetProducer.h
VirtualJetProducer::fjJets_
std::vector< fastjet::PseudoJet > fjJets_
Definition: VirtualJetProducer.h:192
VirtualJetProducer::fjJetDefinition_
JetDefPtr fjJetDefinition_
Definition: VirtualJetProducer.h:186
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
JetSpecific.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
cms::CSJetProducer::fillDescriptionsFromCSJetProducer
static void fillDescriptionsFromCSJetProducer(edm::ParameterSetDescription &desc)
Definition: CSJetProducer.cc:175
VirtualJetProducer::fjInputs_
std::vector< fastjet::PseudoJet > fjInputs_
Definition: VirtualJetProducer.h:191
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
VirtualJetProducer::fillDescriptionsFromVirtualJetProducer
static void fillDescriptionsFromVirtualJetProducer(edm::ParameterSetDescription &desc)
Definition: VirtualJetProducer.cc:1016
cms
Namespace of DDCMS conversion namespace.
Definition: ProducerAnalyzer.cc:21
cms::CSJetProducer::minFlowChi2Prob_
double minFlowChi2Prob_
flag to turn on/off flow-modulated rho and rhom
Definition: CSJetProducer.h:43