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 
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< fastjet::PseudoJet > fjJets_
double csAlpha_
for constituent subtraction : R parameter
Definition: CSJetProducer.h:40
bool useModulatedRho_
for HI constituent subtraction : alpha (power of pt in metric)
Definition: CSJetProducer.h:42
std::shared_ptr< fastjet::ClusterSequence > ClusterSequencePtr
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< std::vector< double > > rhoToken_
Definition: CSJetProducer.h:47
edm::EDGetTokenT< std::vector< double > > rhoFlowFitParamsToken_
Definition: CSJetProducer.h:49
double maxFlowChi2Prob_
flowFit chi2/ndof minimum compatability requirement
Definition: CSJetProducer.h:44
std::vector< fastjet::PseudoJet > fjInputs_
int iEvent
Definition: GenABIO.cc:224
ClusterSequencePtr fjClusterSeq_
T sqrt(T t)
Definition: SSEVec.h:19
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
double getModulatedRhoFactor(double phi, double eventPlane2, double eventPlane3, double par1, double par2)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Namespace of DDCMS conversion namespace.
edm::EDGetTokenT< std::vector< double > > etaToken_
flowFit chi2/ndof minimum compatability requirement
Definition: CSJetProducer.h:46
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
void runAlgorithm(edm::Event &iEvent, const edm::EventSetup &iSetup) override
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< std::vector< double > > rhomToken_
Definition: CSJetProducer.h:48
fixed size matrix
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
HLT enums.
AreaDefinitionPtr fjAreaDefinition_
static void fillDescriptionsFromVirtualJetProducer(edm::ParameterSetDescription &desc)
static void fillDescriptionsFromCSJetProducer(edm::ParameterSetDescription &desc)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
double minFlowChi2Prob_
flag to turn on/off flow-modulated rho and rhom
Definition: CSJetProducer.h:43