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  int chi2index = rhoFlowFitParams->size() - 3;
86  double val = ROOT::Math::chisquared_cdf_c(rhoFlowFitParams->at(chi2index), rhoFlowFitParams->at(chi2index + 1));
88  maxProb = val < maxFlowChi2Prob_;
89  }
90  }
91 
92  //Allow the background densities to change within the jet
93 
94  for (fastjet::PseudoJet& ijet : tempJets) {
95  //----------------------------------------------------------------------
96  // sift ghosts and particles in the input jet
97  std::vector<fastjet::PseudoJet> particles, ghosts;
98  fastjet::SelectorIsPureGhost().sift(ijet.constituents(), ghosts, particles);
99  unsigned long nParticles = particles.size();
100  if (nParticles == 0)
101  continue; //don't subtract ghost jets
102 
103  //assign rho and rhom to ghosts according to local eta-dependent map + modulation as function of phi
104  for (fastjet::PseudoJet& ighost : ghosts) {
105  double rhoModulationFactor = 1.;
106  double ghostPhi = ighost.phi_std();
107 
108  if (useModulatedRho_) {
109  if (!rhoFlowFitParams->empty()) {
110  if (minProb && maxProb) {
111  rhoModulationFactor = getModulatedRhoFactor(ghostPhi, rhoFlowFitParams);
112  }
113  }
114  }
115 
116  int32_t ghostPos = -1;
117  auto const ighostEta = ighost.eta();
118  if (ighostEta <= etaRanges->at(0) || bkgVecSize == 1) {
119  ghostPos = 0;
120  } else if (ighostEta >= etaRanges->at(bkgVecSize - 1)) {
121  ghostPos = rhoRanges->size() - 1;
122  } else {
123  for (unsigned int ie = 0; ie < (bkgVecSize - 1); ie++) {
124  if (ighostEta >= etaRanges->at(ie) && ighostEta < etaRanges->at(ie + 1)) {
125  ghostPos = ie;
126  break;
127  }
128  }
129  }
130  double pt = rhoRanges->at(ghostPos) * ighost.area() * rhoModulationFactor;
131  double mass_squared =
132  std::pow(rhoModulationFactor * rhomRanges->at(ghostPos) * ighost.area() + pt, 2) - std::pow(pt, 2);
133  double mass = (mass_squared > 0) ? sqrt(mass_squared) : 0;
134  ighost.reset_momentum_PtYPhiM(pt, ighost.rap(), ighost.phi(), mass);
135  }
136 
137  //----------------------------------------------------------------------
138  //from here use official fastjet contrib package
139 
140  fastjet::contrib::ConstituentSubtractor subtractor;
141  subtractor.set_distance_type(fastjet::contrib::ConstituentSubtractor::deltaR); // distance in eta-phi plane
142  subtractor.set_max_distance(
143  csRParam_); // free parameter for the maximal allowed distance between particle i and ghost k
144  subtractor.set_alpha(
145  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
146  subtractor.set_do_mass_subtraction();
147  subtractor.set_remove_all_zero_pt_particles(true);
148 
149  std::vector<fastjet::PseudoJet> subtracted_particles = subtractor.do_subtraction(particles, ghosts);
150 
151  //Create subtracted jets
152  fastjet::PseudoJet subtracted_jet = join(subtracted_particles);
153  if (subtracted_jet.perp() > jetPtMin_)
154  fjJets_.push_back(subtracted_jet);
155  }
156  fjJets_ = fastjet::sorted_by_pt(fjJets_);
157 }
158 
160  edm::ParameterSetDescription descCSJetProducer;
162  fillDescriptionsFromCSJetProducer(descCSJetProducer);
164  descCSJetProducer.add<string>("jetCollInstanceName", "");
166  descCSJetProducer.add<bool>("sumRecHits", false);
167 
169  descriptions.add("CSJetProducer", descCSJetProducer);
170 }
171 
173  desc.add<double>("csRParam", -1.);
174  desc.add<double>("csAlpha", 2.);
175  desc.add<bool>("useModulatedRho", false);
176  desc.add<double>("minFlowChi2Prob", 0.05);
177  desc.add<double>("maxFlowChi2Prob", 0.95);
178  desc.add<edm::InputTag>("etaMap", {"hiFJRhoProducer", "mapEtaEdges"});
179  desc.add<edm::InputTag>("rho", {"hiFJRhoProducer", "mapToRho"});
180  desc.add<edm::InputTag>("rhom", {"hiFJRhoProducer", "mapToRhoM"});
181  desc.add<edm::InputTag>("rhoFlowFitParams", {"hiFJRhoFlowModulationProducer", "rhoFlowFitParams"});
182 }
183 
184 double CSJetProducer::getModulatedRhoFactor(const double phi, const edm::Handle<std::vector<double>>& flowComponents) {
185  // get the rho modulation as function of phi
186  // flow modulation fit is done in RecoHI/HiJetAlgos/plugins/HiFJRhoFlowModulationProducer
187  int nFlow = (flowComponents->size() - 4) / 2;
188  double modulationValue = 1;
189  double firstFlowComponent = flowComponents->at(nFlow * 2 + 3);
190  for (int iFlow = 0; iFlow < nFlow; iFlow++) {
191  modulationValue += 2.0 * flowComponents->at(2 * iFlow + 1) *
192  cos((iFlow + firstFlowComponent) * (phi - flowComponents->at(2 * iFlow + 2)));
193  }
194  return modulationValue;
195 }
196 
198 // define as cmssw plugin
200 
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)
constexpr int pow(int x)
Definition: conifer.h:24
double getModulatedRhoFactor(const double phi, const edm::Handle< std::vector< double >> &flowParameters)
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
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)
double minFlowChi2Prob_
flag to turn on/off flow-modulated rho and rhom
Definition: CSJetProducer.h:43