CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
HiFJRhoFlowModulationProducer Class Reference
Inheritance diagram for HiFJRhoFlowModulationProducer:
edm::stream::EDProducer<>

Public Member Functions

 HiFJRhoFlowModulationProducer (const edm::ParameterSet &)
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Member Functions

void beginStream (edm::StreamID) override
 
void endStream () override
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

reco::PFCandidate converter_
 
const bool doEvtPlane_
 
const bool doFreePlaneFit_
 
const bool doJettyExclusion_
 
const int evtPlaneLevel_
 
const edm::EDGetTokenT< reco::EvtPlaneCollectionevtPlaneToken_
 
const double exclusionRadius_
 
int firstFittedVn_
 
std::unique_ptr< TF1 > flowFit_p_
 
const edm::EDGetTokenT< reco::JetViewjetToken_
 
int lastFittedVn_
 
const int minPfCandidatesPerEvent_
 
const double pfCandidateEtaCut_
 
const double pfCandidateMaxPtCut_
 
const double pfCandidateMinPtCut_
 
const edm::EDGetTokenT< pat::PackedCandidateCollectionpfCandidateToken_
 
std::unique_ptr< TF2 > pfWeightFunction_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Definition at line 98 of file HiFJRhoFlowModulationProducer.cc.

Constructor & Destructor Documentation

◆ HiFJRhoFlowModulationProducer()

HiFJRhoFlowModulationProducer::HiFJRhoFlowModulationProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 126 of file HiFJRhoFlowModulationProducer.cc.

References converter_, exclusionRadius_, firstFittedVn_, flowFit_p_, lastFittedVn_, pfLinker_cff::PFCandidate, pfCandidateEtaCut_, pfWeightFunction_, and Pi.

127  : minPfCandidatesPerEvent_(iConfig.getParameter<int>("minPfCandidatesPerEvent")),
128  doEvtPlane_(iConfig.getParameter<bool>("doEvtPlane")),
129  doFreePlaneFit_(iConfig.getParameter<bool>("doFreePlaneFit")),
130  doJettyExclusion_(iConfig.getParameter<bool>("doJettyExclusion")),
131  exclusionRadius_(iConfig.getParameter<double>("exclusionRadius")),
132  evtPlaneLevel_(iConfig.getParameter<int>("evtPlaneLevel")),
133  pfCandidateEtaCut_(iConfig.getParameter<double>("pfCandidateEtaCut")),
134  pfCandidateMinPtCut_(iConfig.getParameter<double>("pfCandidateMinPtCut")),
135  pfCandidateMaxPtCut_(iConfig.getParameter<double>("pfCandidateMaxPtCut")),
136  firstFittedVn_(iConfig.getParameter<int>("firstFittedVn")),
137  lastFittedVn_(iConfig.getParameter<int>("lastFittedVn")),
138  jetToken_(doJettyExclusion_ ? consumes<reco::JetView>(iConfig.getParameter<edm::InputTag>("jetTag"))
140  pfCandidateToken_(consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("pfCandSource"))),
141  evtPlaneToken_(consumes<reco::EvtPlaneCollection>(iConfig.getParameter<edm::InputTag>("EvtPlane"))) {
142  produces<std::vector<double>>("rhoFlowFitParams");
143 
144  // Converter to get PF candidate ID from packed candidates
146 
147  // Sanity check for the fitted flow component input
148  if (firstFittedVn_ < 1)
149  firstFittedVn_ = 2;
150  if (lastFittedVn_ < 1)
151  lastFittedVn_ = 2;
153  int flipper = lastFittedVn_;
155  firstFittedVn_ = flipper;
156  }
157 
158  // Calculate the number of flow components
159  const int nFlow = lastFittedVn_ - firstFittedVn_ + 1;
160 
161  // Define all fit and weight functions
162  TMinuitMinimizer::UseStaticMinuit(false);
163  flowFit_p_ = std::make_unique<TF1>("flowFit", flowFunction, -TMath::Pi(), TMath::Pi(), nFlow * 2 + 3);
164  flowFit_p_->FixParameter(0, nFlow); // The first parameter defines the number of fitted flow components
165  flowFit_p_->FixParameter(1, firstFittedVn_); // The second parameter defines the first fitted flow component
166  pfWeightFunction_ = std::make_unique<TF2>("weightFunction", weightFunction, 0, TMath::Pi(), -5, 5, 2);
167  pfWeightFunction_->SetParameter(0, pfCandidateEtaCut_); // Set the allowed eta range for particle flow candidates
168  pfWeightFunction_->SetParameter(1, exclusionRadius_); // Set the exclusion radius around the jets
169 }
const double Pi
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
const edm::EDGetTokenT< reco::EvtPlaneCollection > evtPlaneToken_
const edm::EDGetTokenT< reco::JetView > jetToken_
const edm::EDGetTokenT< pat::PackedCandidateCollection > pfCandidateToken_

Member Function Documentation

◆ beginStream()

void HiFJRhoFlowModulationProducer::beginStream ( edm::StreamID  )
overrideprivate

Definition at line 360 of file HiFJRhoFlowModulationProducer.cc.

360 {}

◆ endStream()

void HiFJRhoFlowModulationProducer::endStream ( )
overrideprivate

Definition at line 363 of file HiFJRhoFlowModulationProducer.cc.

363 {}

◆ fillDescriptions()

void HiFJRhoFlowModulationProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 366 of file HiFJRhoFlowModulationProducer.cc.

References edm::ConfigurationDescriptions::add(), submitPVResolutionJobs::desc, and ProducerED_cfi::InputTag.

366  {
368  desc.add<int>("minPfCandidatesPerEvent", 100);
369  desc.add<bool>("doEvtPlane", false);
370  desc.add<edm::InputTag>("EvtPlane", edm::InputTag("hiEvtPlane"));
371  desc.add<bool>("doJettyExclusion", false);
372  desc.add<double>("exclusionRadius", 0.4);
373  desc.add<bool>("doFreePlaneFit", false);
374  desc.add<edm::InputTag>("jetTag", edm::InputTag("ak4PFJetsForFlow"));
375  desc.add<edm::InputTag>("pfCandSource", edm::InputTag("packedPFCandidates"));
376  desc.add<int>("evtPlaneLevel", 0);
377  desc.add<double>("pfCandidateEtaCut", 1.0);
378  desc.add<double>("pfCandidateMinPtCut", 0.3);
379  desc.add<double>("pfCandidateMaxPtCut", 3.0);
380  desc.add<int>("firstFittedVn", 2);
381  desc.add<int>("lastFittedVn", 3);
382  descriptions.add("hiFJRhoFlowModulationProducer", desc);
383 }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ produce()

void HiFJRhoFlowModulationProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 172 of file HiFJRhoFlowModulationProducer.cc.

References funct::abs(), cms::cuda::assert(), Matriplex::atan2(), converter_, funct::cos(), HLTMuonOfflineAnalyzer_cfi::deltaR2, doEvtPlane_, doFreePlaneFit_, doJettyExclusion_, MillePedeFileConverter_cfg::e, evtPlaneLevel_, evtPlaneToken_, exclusionRadius_, firstFittedVn_, flowFit_p_, hi::HF2, hi::HF3, HiEvtPlane_cfi::hiEvtPlane, iEvent, metsig::jet, PDWG_EXODelayedJetMET_cff::jets, jetToken_, lastFittedVn_, WZElectronSkims53X_cff::max, minPfCandidatesPerEvent_, eostools::move(), mergeVDriftHistosByStation::name, ecaldqm::binning::nPhiBins, hi::NumEPNames, pfCandidateEtaCut_, pfCandidateMaxPtCut_, pfCandidateMinPtCut_, pfCandidateToken_, pfWeightFunction_, Pi, funct::sin(), AlCaHLTBitMon_QueryRunRegistry::string, to_string(), HcalDetIdTransform::transform(), and reco::PFCandidate::translatePdgIdToType().

172  {
173  // Get the particle flow candidate collection
174  auto const& pfCands = iEvent.get(pfCandidateToken_);
175 
176  // If we are reading the event plane information for the forest, find the event planes
177  std::array<float, hi::NumEPNames> hiEvtPlane;
178  if (doEvtPlane_) {
179  auto const& evtPlanes = iEvent.get(evtPlaneToken_);
180  assert(evtPlanes.size() == hi::NumEPNames);
181  std::transform(evtPlanes.begin(), evtPlanes.end(), hiEvtPlane.begin(), [this](auto const& ePlane) -> float {
182  return ePlane.angle(evtPlaneLevel_);
183  });
184  }
185 
186  // If jetty regions are excluded from the flow fits, read the jet collection
188  if (doJettyExclusion_) {
189  iEvent.getByToken(jetToken_, jets);
190  }
191 
192  int nFill = 0;
193 
194  // Initialize arrays for event planes
195  // nFlow: Number of flow components in the fit to particle flow condidate distribution
196  const int nFlow = lastFittedVn_ - firstFittedVn_ + 1;
197  double eventPlane[nFlow];
198  for (int iFlow = 0; iFlow < nFlow; iFlow++)
199  eventPlane[iFlow] = -100;
200 
201  // Initialize the output vector with flow fit components
202  // v_n and Psi_n for each fitted flow component, plus overall normalization factor, chi^2 and ndf for flow fit, and the first fitted flow component
203  const int nParamVals = nFlow * 2 + 4;
204  auto rhoFlowFitParamsOut = std::make_unique<std::vector<double>>(nParamVals, 1e-6);
205 
206  // Set the parameters related to flow fit to zero
207  for (int iParameter = 0; iParameter < nFlow * 2 + 1; iParameter++) {
208  rhoFlowFitParamsOut->at(iParameter) = 0;
209  }
210  // Set the first fitted flow component to the last index of the output vector
211  rhoFlowFitParamsOut->at(nFlow * 2 + 3) = firstFittedVn_;
212 
213  // Initialize arrays for manual event plane calculation
214  double eventPlaneCos[nFlow];
215  double eventPlaneSin[nFlow];
216  for (int iFlow = 0; iFlow < nFlow; iFlow++) {
217  eventPlaneCos[iFlow] = 0;
218  eventPlaneSin[iFlow] = 0;
219  }
220 
221  // Define helper variables for looping over particle flow candidates
222  std::vector<bool> pfcuts(pfCands.size(), false);
223  int iCand = -1;
224  double thisPfCandidateWeight = 0;
225  double deltaPhiJetPf = 0;
226  std::vector<double> pfCandidateWeight(pfCands.size(), 1);
227 
228  // Loop over the particle flow candidates
229  for (auto const& pfCandidate : pfCands) {
230  iCand++; // Update the particle flow candidate index
231 
232  // Find the PF candidate ID from the packed candidates collection
233  auto particleFlowCandidateID = converter_.translatePdgIdToType(pfCandidate.pdgId());
234 
235  // This cut selects particle flow candidates that are charged hadrons. The ID numbers are:
236  // 0 = undefined
237  // 1 = charged hadron
238  // 2 = electron
239  // 3 = muon
240  // 4 = photon
241  // 5 = neutral hadron
242  // 6 = HF tower identified as a hadron
243  // 7 = HF tower identified as an EM particle
244  if (particleFlowCandidateID != 1)
245  continue;
246 
247  // Kinematic cuts for particle flow candidate pT and eta
248  if (std::abs(pfCandidate.eta()) > pfCandidateEtaCut_)
249  continue;
250  if (pfCandidate.pt() < pfCandidateMinPtCut_)
251  continue;
252  if (pfCandidate.pt() > pfCandidateMaxPtCut_)
253  continue;
254 
255  nFill++; // Use same nFill criterion with and without jetty region subtraction
256 
257  // If the jetty regions are excluded from the fit, find which particle flow candidates are close to jets
258  thisPfCandidateWeight = 1;
259  if (doJettyExclusion_) {
260  bool isGood = true;
261  for (auto const& jet : *jets) {
262  if (deltaR2(jet, pfCandidate) < exclusionRadius_ * exclusionRadius_) {
263  isGood = false;
264  break;
265  } else {
266  // If the particle flow candidates are not excluded from the fit, check if there are any jets in the same phi-slice as the particle flow candidate. If this is the case, add a weight for the particle flow candidate taking into account the lost acceptance for underlaying event particle flow candidates.
267  deltaPhiJetPf = std::abs(pfCandidate.phi() - jet.phi());
268  if (deltaPhiJetPf > TMath::Pi())
269  deltaPhiJetPf = TMath::Pi() * 2 - deltaPhiJetPf;
270  // Weight currently does not take into account overlapping jets
271  thisPfCandidateWeight += pfWeightFunction_->Eval(deltaPhiJetPf, std::abs(jet.eta()));
272  }
273  }
274  // Do not use this particle flow candidate in the manual event plane calculation
275  if (!isGood) {
276  continue;
277  }
278  }
279 
280  // Update the weight for this particle flow candidate
281  pfCandidateWeight[iCand] = thisPfCandidateWeight;
282 
283  // This particle flow candidate passes all the cuts
284  pfcuts[iCand] = true;
285 
286  // If the event plane is calculated manually, add this particle flow candidate to the calculation
287  if (!doEvtPlane_) {
288  for (int iFlow = 0; iFlow < nFlow; iFlow++) {
289  eventPlaneCos[iFlow] += std::cos((iFlow + firstFittedVn_) * pfCandidate.phi()) * thisPfCandidateWeight;
290  eventPlaneSin[iFlow] += std::sin((iFlow + firstFittedVn_) * pfCandidate.phi()) * thisPfCandidateWeight;
291  }
292  }
293  }
294 
295  // Determine the event plane angle
296  if (!doEvtPlane_) {
297  // Manual calculation for the event plane angle using the particle flow candidates
298  for (int iFlow = 0; iFlow < nFlow; iFlow++) {
299  eventPlane[iFlow] = std::atan2(eventPlaneSin[iFlow], eventPlaneCos[iFlow]) / (iFlow + firstFittedVn_);
300  }
301  } else {
302  // Read the event plane angle determined from the HF calorimeters from the HiForest
303  // Only v2 and v3 are available in the HiForest. This option should not be used if other flow components are fitted
304  int halfWay = nFlow / 2;
305  for (int iFlow = 0; iFlow < halfWay; iFlow++) {
306  eventPlane[iFlow] = hiEvtPlane[hi::HF2];
307  }
308  for (int iFlow = halfWay; iFlow < nFlow; iFlow++) {
309  eventPlane[iFlow] = hiEvtPlane[hi::HF3];
310  }
311  }
312 
313  // Do the flow fit provided that there are enough particle flow candidates in the event and that the event planes have been determined successfully
314  int pfcuts_count = 0;
315  if (nFill >= minPfCandidatesPerEvent_ && eventPlane[0] > -99) {
316  // Create a particle flow candidate phi-histogram
317  const int nPhiBins = std::max(10, nFill / 30);
318  std::string name = "phiTestIEta4_" + std::to_string(iEvent.id().event()) + "_h";
319  std::unique_ptr<TH1F> phi_h = std::make_unique<TH1F>(name.data(), "", nPhiBins, -TMath::Pi(), TMath::Pi());
320  phi_h->SetDirectory(nullptr);
321  for (auto const& pfCandidate : pfCands) {
322  if (pfcuts.at(pfcuts_count)) { // Only use particle flow candidates that pass all cuts
323  phi_h->Fill(pfCandidate.phi(), pfCandidateWeight.at(pfcuts_count));
324  }
325  pfcuts_count++;
326  }
327 
328  // Set initial values for the fit parameters
329  flowFit_p_->SetParameter(2, 10);
330  for (int iFlow = 0; iFlow < nFlow; iFlow++) {
331  flowFit_p_->SetParameter(3 + 2 * iFlow, 0);
332  flowFit_p_->SetParameter(4 + 2 * iFlow, eventPlane[iFlow]);
333  // If we are not allowing the event plane angles to be free parameters in the fit, fix them
334  if (!doFreePlaneFit_) {
335  flowFit_p_->FixParameter(4 + 2 * iFlow, eventPlane[iFlow]);
336  }
337  }
338 
339  // Do the Fourier fit
340  phi_h->Fit(flowFit_p_.get(), "Q SERIAL", "", -TMath::Pi(), TMath::Pi());
341 
342  // Put the fit parameters to the output vector
343  for (int iParameter = 0; iParameter < nFlow * 2 + 1; iParameter++) {
344  rhoFlowFitParamsOut->at(iParameter) = flowFit_p_->GetParameter(iParameter + 2);
345  }
346 
347  // Also add chi2 and ndf information to the output vector
348  rhoFlowFitParamsOut->at(nFlow * 2 + 1) = flowFit_p_->GetChisquare();
349  rhoFlowFitParamsOut->at(nFlow * 2 + 2) = flowFit_p_->GetNDF();
350 
351  phi_h.reset();
352  pfcuts.clear();
353  }
354 
355  // Define the produced output
356  iEvent.put(std::move(rhoFlowFitParamsOut), "rhoFlowFitParams");
357 }
const double Pi
const edm::EDGetTokenT< reco::EvtPlaneCollection > evtPlaneToken_
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
assert(be >=bs)
static std::string to_string(const XMLCh *ch)
int iEvent
Definition: GenABIO.cc:224
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const edm::EDGetTokenT< reco::JetView > jetToken_
ParticleType translatePdgIdToType(int pdgid) const
Definition: PFCandidate.cc:231
static constexpr int nPhiBins
static const int NumEPNames
def move(src, dest)
Definition: eostools.py:511
MPlex< T, D1, D2, N > atan2(const MPlex< T, D1, D2, N > &y, const MPlex< T, D1, D2, N > &x)
Definition: Matriplex.h:648
const edm::EDGetTokenT< pat::PackedCandidateCollection > pfCandidateToken_
unsigned transform(const HcalDetId &id, unsigned transformCode)

Member Data Documentation

◆ converter_

reco::PFCandidate HiFJRhoFlowModulationProducer::converter_
private

Definition at line 124 of file HiFJRhoFlowModulationProducer.cc.

Referenced by HiFJRhoFlowModulationProducer(), and produce().

◆ doEvtPlane_

const bool HiFJRhoFlowModulationProducer::doEvtPlane_
private

Definition at line 109 of file HiFJRhoFlowModulationProducer.cc.

Referenced by produce().

◆ doFreePlaneFit_

const bool HiFJRhoFlowModulationProducer::doFreePlaneFit_
private

Definition at line 110 of file HiFJRhoFlowModulationProducer.cc.

Referenced by produce().

◆ doJettyExclusion_

const bool HiFJRhoFlowModulationProducer::doJettyExclusion_
private

Definition at line 111 of file HiFJRhoFlowModulationProducer.cc.

Referenced by produce().

◆ evtPlaneLevel_

const int HiFJRhoFlowModulationProducer::evtPlaneLevel_
private

Definition at line 113 of file HiFJRhoFlowModulationProducer.cc.

Referenced by produce().

◆ evtPlaneToken_

const edm::EDGetTokenT<reco::EvtPlaneCollection> HiFJRhoFlowModulationProducer::evtPlaneToken_
private

Definition at line 121 of file HiFJRhoFlowModulationProducer.cc.

Referenced by produce().

◆ exclusionRadius_

const double HiFJRhoFlowModulationProducer::exclusionRadius_
private

Definition at line 112 of file HiFJRhoFlowModulationProducer.cc.

Referenced by HiFJRhoFlowModulationProducer(), and produce().

◆ firstFittedVn_

int HiFJRhoFlowModulationProducer::firstFittedVn_
private

Definition at line 117 of file HiFJRhoFlowModulationProducer.cc.

Referenced by HiFJRhoFlowModulationProducer(), and produce().

◆ flowFit_p_

std::unique_ptr<TF1> HiFJRhoFlowModulationProducer::flowFit_p_
private

Definition at line 122 of file HiFJRhoFlowModulationProducer.cc.

Referenced by HiFJRhoFlowModulationProducer(), and produce().

◆ jetToken_

const edm::EDGetTokenT<reco::JetView> HiFJRhoFlowModulationProducer::jetToken_
private

Definition at line 119 of file HiFJRhoFlowModulationProducer.cc.

Referenced by produce().

◆ lastFittedVn_

int HiFJRhoFlowModulationProducer::lastFittedVn_
private

Definition at line 118 of file HiFJRhoFlowModulationProducer.cc.

Referenced by HiFJRhoFlowModulationProducer(), and produce().

◆ minPfCandidatesPerEvent_

const int HiFJRhoFlowModulationProducer::minPfCandidatesPerEvent_
private

Definition at line 108 of file HiFJRhoFlowModulationProducer.cc.

Referenced by produce().

◆ pfCandidateEtaCut_

const double HiFJRhoFlowModulationProducer::pfCandidateEtaCut_
private

Definition at line 114 of file HiFJRhoFlowModulationProducer.cc.

Referenced by HiFJRhoFlowModulationProducer(), and produce().

◆ pfCandidateMaxPtCut_

const double HiFJRhoFlowModulationProducer::pfCandidateMaxPtCut_
private

Definition at line 116 of file HiFJRhoFlowModulationProducer.cc.

Referenced by produce().

◆ pfCandidateMinPtCut_

const double HiFJRhoFlowModulationProducer::pfCandidateMinPtCut_
private

Definition at line 115 of file HiFJRhoFlowModulationProducer.cc.

Referenced by produce().

◆ pfCandidateToken_

const edm::EDGetTokenT<pat::PackedCandidateCollection> HiFJRhoFlowModulationProducer::pfCandidateToken_
private

Definition at line 120 of file HiFJRhoFlowModulationProducer.cc.

Referenced by produce().

◆ pfWeightFunction_

std::unique_ptr<TF2> HiFJRhoFlowModulationProducer::pfWeightFunction_
private

Definition at line 123 of file HiFJRhoFlowModulationProducer.cc.

Referenced by HiFJRhoFlowModulationProducer(), and produce().