CMS 3D CMS Logo

FFTJetPileupAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FFTJetPileupAnalyzer
4 // Class: FFTJetPileupAnalyzer
5 //
13 //
14 // Original Author: Igor Volobouev
15 // Created: Thu Apr 21 15:52:11 CDT 2011
16 //
17 //
18 
19 #include <cassert>
20 #include <sstream>
21 #include <numeric>
22 
23 #include "TNtuple.h"
24 
25 // user include files
32 
34 #include <TH2D.h>
38 
40 
42 
44 
46 
47 #define init_param(type, varname) varname(ps.getParameter<type>(#varname))
48 
49 //
50 // class declaration
51 //
53 public:
54  explicit FFTJetPileupAnalyzer(const edm::ParameterSet&);
55  FFTJetPileupAnalyzer() = delete;
58  ~FFTJetPileupAnalyzer() override;
59 
60 private:
61  // The following method should take all necessary info from
62  // PileupSummaryInfo and fill out the ntuple
63  void analyzePileup(const std::vector<PileupSummaryInfo>& pInfo);
64 
65  void beginJob() override;
66  void analyze(const edm::Event&, const edm::EventSetup&) override;
67  void endJob() override;
68 
76 
85 
97 
98  double vertexNdofCut;
100 
101  std::vector<float> ntupleData;
102  TNtuple* nt;
103  int totalNpu;
104  int totalNPV;
105  unsigned long counter;
106 };
107 
108 //
109 // constructors and destructor
110 //
130  init_param(double, vertexNdofCut),
131  init_param(double, crazyEnergyCut),
132  nt(nullptr),
133  totalNpu(-1),
134  totalNPV(-1),
135  counter(0) {
137  pileupToken = consumes<std::vector<PileupSummaryInfo> >(pileupLabel);
138 
139  if (collectHistos)
140  histoToken = consumes<TH2D>(histoLabel);
141 
142  if (collectSummaries)
143  summaryToken = consumes<reco::FFTJetPileupSummary>(summaryLabel);
144 
145  if (collectFastJetRho) {
146  fastJetRhoToken = consumes<double>(fastJetRhoLabel);
147  fastJetSigmaToken = consumes<double>(fastJetSigmaLabel);
148  }
149 
150  if (collectGrids)
151  gridToken = consumes<reco::DiscretizedEnergyFlow>(gridLabel);
152 
153  if (collectGridDensity)
154  etSumToken = consumes<std::pair<double, double> >(histoLabel);
155 
156  if (collectVertexInfo)
157  srcPVsToken = consumes<reco::VertexCollection>(srcPVs);
158 }
159 
161 
162 //
163 // member functions
164 //
165 void FFTJetPileupAnalyzer::analyzePileup(const std::vector<PileupSummaryInfo>& info) {
166  const unsigned nBx = info.size();
167  if (collectPileup)
168  ntupleData.push_back(static_cast<float>(nBx));
169 
170  double sumpt_Lo = 0.0, sumpt_Hi = 0.0;
171  totalNpu = 0;
172 
173  int npu_by_Bx[3] = {
174  0,
175  };
176  double sumpt_Lo_by_Bx[3] =
177  {
178  0.0,
179  },
180  sumpt_Hi_by_Bx[3] = {
181  0.0,
182  };
183 
184  if (verbosePileupInfo)
185  std::cout << "\n**** Pileup info begin" << std::endl;
186 
187  bool isCrazy = false;
188  for (unsigned ibx = 0; ibx < nBx; ++ibx) {
189  const PileupSummaryInfo& puInfo(info[ibx]);
190 
191  const int bx = puInfo.getBunchCrossing();
192  const int npu = puInfo.getPU_NumInteractions();
193  const std::vector<float>& lopt(puInfo.getPU_sumpT_lowpT());
194  const std::vector<float>& hipt(puInfo.getPU_sumpT_highpT());
195  const double losum = std::accumulate(lopt.begin(), lopt.end(), 0.0);
196  const double hisum = std::accumulate(hipt.begin(), hipt.end(), 0.0);
197 
198  if (losum >= crazyEnergyCut)
199  isCrazy = true;
200  if (hisum >= crazyEnergyCut)
201  isCrazy = true;
202 
203  totalNpu += npu;
204  sumpt_Lo += losum;
205  sumpt_Hi += hisum;
206 
207  const unsigned idx = bx < 0 ? 0U : (bx == 0 ? 1U : 2U);
208  npu_by_Bx[idx] += npu;
209  sumpt_Lo_by_Bx[idx] += losum;
210  sumpt_Hi_by_Bx[idx] += hisum;
211 
212  if (verbosePileupInfo)
213  std::cout << "ibx " << ibx << " bx " << bx << " npu " << npu << " losum " << losum << " hisum " << hisum
214  << std::endl;
215  }
216 
217  if (verbosePileupInfo)
218  std::cout << "**** Pileup info end\n" << std::endl;
219 
220  if (isCrazy) {
221  totalNpu = -1;
222  sumpt_Lo = 0.0;
223  sumpt_Hi = 0.0;
224  for (unsigned ibx = 0; ibx < 3; ++ibx) {
225  npu_by_Bx[ibx] = -1;
226  sumpt_Lo_by_Bx[ibx] = 0.0;
227  sumpt_Hi_by_Bx[ibx] = 0.0;
228  }
229  }
230 
231  if (collectPileup) {
232  ntupleData.push_back(totalNpu);
233  ntupleData.push_back(sumpt_Lo);
234  ntupleData.push_back(sumpt_Hi);
235  }
236 
237  if (collectOOTPileup)
238  for (unsigned ibx = 0; ibx < 3; ++ibx) {
239  ntupleData.push_back(npu_by_Bx[ibx]);
240  ntupleData.push_back(sumpt_Lo_by_Bx[ibx]);
241  ntupleData.push_back(sumpt_Hi_by_Bx[ibx]);
242  }
243 }
244 
245 // ------------ method called once each job just before starting event loop
247  // Come up with the list of variables
248  std::string vars = "cnt:run:event";
249  if (collectPileup)
250  vars += ":nbx:npu:sumptLowCut:sumptHiCut";
251  if (collectOOTPileup) {
252  vars += ":npu_negbx:sumptLowCut_negbx:sumptHiCut_negbx";
253  vars += ":npu_0bx:sumptLowCut_0bx:sumptHiCut_0bx";
254  vars += ":npu_posbx:sumptLowCut_posbx:sumptHiCut_posbx";
255  }
256  if (collectSummaries)
257  vars += ":estimate:pileup:uncert:uncertCode";
258  if (collectFastJetRho)
259  vars += ":fjrho:fjsigma";
260  if (collectGridDensity)
261  vars += ":gridEtDensity:gridEtDensityMixed";
262  if (collectVertexInfo)
263  vars += ":nPV";
264 
265  // Book the ntuple
267  nt = fs->make<TNtuple>(ntupleName.c_str(), ntupleTitle.c_str(), vars.c_str());
268  ntupleData.reserve(nt->GetNvar());
269 }
270 
271 // ------------ method called to for each event ------------
273  ntupleData.clear();
274  ntupleData.push_back(counter);
275  totalNpu = -1;
276  totalNPV = -1;
277 
278  edm::RunNumber_t const runnumber = iEvent.id().run();
279  edm::EventNumber_t const eventnumber = iEvent.id().event();
280  ntupleData.push_back(runnumber);
281  ntupleData.push_back(eventnumber);
282 
283  // Get pileup information from the pile-up information module
286  if (iEvent.getByToken(pileupToken, puInfo))
287  analyzePileup(*puInfo);
288  else {
289  if (collectPileup) {
290  ntupleData.push_back(-1);
291  ntupleData.push_back(-1);
292  ntupleData.push_back(0.f);
293  ntupleData.push_back(0.f);
294  }
295  if (collectOOTPileup)
296  for (unsigned ibx = 0; ibx < 3; ++ibx) {
297  ntupleData.push_back(-1);
298  ntupleData.push_back(0.f);
299  ntupleData.push_back(0.f);
300  }
301  }
302  }
303 
304  if (collectHistos) {
306  iEvent.getByToken(histoToken, input);
307 
309  TH2D* copy = new TH2D(*input);
310 
311  std::ostringstream os;
312  os << copy->GetName() << '_' << counter << '_' << totalNpu << '_' << runnumber << '_' << eventnumber;
313  const std::string& newname(os.str());
314  copy->SetNameTitle(newname.c_str(), newname.c_str());
315 
316  copy->SetDirectory(fs->getBareDirectory());
317  }
318 
319  if (collectSummaries) {
321  iEvent.getByToken(summaryToken, summary);
322 
323  ntupleData.push_back(summary->uncalibratedQuantile());
324  ntupleData.push_back(summary->pileupRho());
325  ntupleData.push_back(summary->pileupRhoUncertainty());
326  ntupleData.push_back(summary->uncertaintyCode());
327  }
328 
329  if (collectFastJetRho) {
330  edm::Handle<double> fjrho, fjsigma;
331  iEvent.getByToken(fastJetRhoToken, fjrho);
332  iEvent.getByToken(fastJetSigmaToken, fjsigma);
333 
334  ntupleData.push_back(*fjrho);
335  ntupleData.push_back(*fjsigma);
336  }
337 
338  if (collectGrids) {
340  iEvent.getByToken(gridToken, input);
341 
342  // Make sure the input grid is reasonable
343  const double* data = input->data();
344  assert(data);
345  assert(input->phiBin0Edge() == 0.0);
346  const unsigned nEta = input->nEtaBins();
347  const unsigned nPhi = input->nPhiBins();
348 
349  // Generate a name for the output histogram
350  std::ostringstream os;
351  os << "FFTJetGrid_" << counter << '_' << totalNpu << '_' << runnumber << '_' << eventnumber;
352  const std::string& newname(os.str());
353 
354  // Make a histogram and copy the grid data into it
356  TH2F* h =
357  fs->make<TH2F>(newname.c_str(), newname.c_str(), nEta, input->etaMin(), input->etaMax(), nPhi, 0.0, 2.0 * M_PI);
358  h->GetXaxis()->SetTitle("Eta");
359  h->GetYaxis()->SetTitle("Phi");
360  h->GetZaxis()->SetTitle("Transverse Energy");
361 
362  for (unsigned ieta = 0; ieta < nEta; ++ieta)
363  for (unsigned iphi = 0; iphi < nPhi; ++iphi)
364  h->SetBinContent(ieta + 1U, iphi + 1U, data[ieta * nPhi + iphi]);
365  }
366 
367  if (collectGridDensity) {
369  iEvent.getByToken(etSumToken, etSum);
370 
371  ntupleData.push_back(etSum->first);
372  ntupleData.push_back(etSum->second);
373  }
374 
375  if (collectVertexInfo) {
377  iEvent.getByToken(srcPVsToken, pvCollection);
378  totalNPV = 0;
379  if (!pvCollection->empty())
380  for (reco::VertexCollection::const_iterator pv = pvCollection->begin(); pv != pvCollection->end(); ++pv) {
381  const double ndof = pv->ndof();
382  if (!pv->isFake() && ndof > vertexNdofCut)
383  ++totalNPV;
384  }
385  ntupleData.push_back(totalNPV);
386  }
387 
388  assert(ntupleData.size() == static_cast<unsigned>(nt->GetNvar()));
389  nt->Fill(&ntupleData[0]);
390 
391  ++counter;
392 }
393 
394 // ------------ method called once each job just after ending the event loop
396 
397 //define this as a plug-in
FFTJetPileupAnalyzer::collectPileup
bool collectPileup
Definition: FFTJetPileupAnalyzer.cc:91
edm::RunNumber_t
unsigned int RunNumber_t
Definition: RunLumiEventNumber.h:14
counter
Definition: counter.py:1
Handle.h
PileupSummaryInfo.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
fftjetpfpileupcleaner_cfi.vertexNdofCut
vertexNdofCut
Definition: fftjetpfpileupcleaner_cfi.py:51
input
static const std::string input
Definition: EdmProvDump.cc:48
fftjetpileupanalyzer_cfi.collectSummaries
collectSummaries
Definition: fftjetpileupanalyzer_cfi.py:46
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
HLT_FULL_cff.nEta
nEta
Definition: HLT_FULL_cff.py:6585
FFTJetPileupAnalyzer::collectFastJetRho
bool collectFastJetRho
Definition: FFTJetPileupAnalyzer.cc:90
nt
int nt
Definition: AMPTWrapper.h:42
edm::EDGetTokenT< TH2D >
edm
HLT enums.
Definition: AlignableModifier.h:19
gather_cfg.cout
cout
Definition: gather_cfg.py:144
RunLumiEventNumber.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
FFTJetPileupAnalyzer
Definition: FFTJetPileupAnalyzer.cc:52
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
fftjetpileupanalyzer_cfi.fastJetRhoLabel
fastJetRhoLabel
Definition: fftjetpileupanalyzer_cfi.py:24
cms::cuda::assert
assert(be >=bs)
fftjetpileupanalyzer_cfi.collectOOTPileup
collectOOTPileup
Definition: fftjetpileupanalyzer_cfi.py:43
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:153
PileupSummaryInfo::getPU_sumpT_lowpT
const std::vector< float > & getPU_sumpT_lowpT() const
Definition: PileupSummaryInfo.h:66
FFTJetPileupAnalyzer::histoToken
edm::EDGetTokenT< TH2D > histoToken
Definition: FFTJetPileupAnalyzer.cc:77
EDAnalyzer.h
FFTJetPileupAnalyzer::collectHistos
bool collectHistos
Definition: FFTJetPileupAnalyzer.cc:88
edm::Handle
Definition: AssociativeIterator.h:50
fftjetpileupanalyzer_cfi.collectPileup
collectPileup
Definition: fftjetpileupanalyzer_cfi.py:42
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
FFTJetPileupAnalyzer::collectGrids
bool collectGrids
Definition: FFTJetPileupAnalyzer.cc:93
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
FFTJetPileupAnalyzer::collectSummaries
bool collectSummaries
Definition: FFTJetPileupAnalyzer.cc:89
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
ndof
Definition: HIMultiTrackSelector.h:49
MakerMacros.h
fftjetpileupanalyzer_cfi.collectFastJetRho
collectFastJetRho
Definition: fftjetpileupanalyzer_cfi.py:45
fftjetpileupanalyzer_cfi.crazyEnergyCut
crazyEnergyCut
Definition: fftjetpileupanalyzer_cfi.py:55
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
FFTJetPileupAnalyzer::beginJob
void beginJob() override
Definition: FFTJetPileupAnalyzer.cc:246
vars
vars
Definition: DeepTauId.cc:164
Service.h
FFTJetPileupAnalyzer::FFTJetPileupAnalyzer
FFTJetPileupAnalyzer()=delete
fftjetpileupanalyzer_cfi.verbosePileupInfo
verbosePileupInfo
Definition: fftjetpileupanalyzer_cfi.py:50
FFTJetPileupAnalyzer::srcPVs
edm::InputTag srcPVs
Definition: FFTJetPileupAnalyzer.cc:74
FFTJetPileupAnalyzer::gridLabel
edm::InputTag gridLabel
Definition: FFTJetPileupAnalyzer.cc:73
init_param
#define init_param(type, varname)
Definition: FFTJetPileupAnalyzer.cc:47
FFTJetPileupAnalyzer::~FFTJetPileupAnalyzer
~FFTJetPileupAnalyzer() override
Definition: FFTJetPileupAnalyzer.cc:160
edm::EventNumber_t
unsigned long long EventNumber_t
Definition: RunLumiEventNumber.h:12
anotherprimaryvertexanalyzer_cfi.pvCollection
pvCollection
Definition: anotherprimaryvertexanalyzer_cfi.py:4
FFTJetPileupAnalyzer::pileupLabel
std::string pileupLabel
Definition: FFTJetPileupAnalyzer.cc:75
h
FFTJetPileupAnalyzer::gridToken
edm::EDGetTokenT< reco::DiscretizedEnergyFlow > gridToken
Definition: FFTJetPileupAnalyzer.cc:81
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
FFTJetPileupAnalyzer::collectGridDensity
bool collectGridDensity
Definition: FFTJetPileupAnalyzer.cc:94
FFTJetPileupSummary.h
FFTJetPileupAnalyzer::crazyEnergyCut
double crazyEnergyCut
Definition: FFTJetPileupAnalyzer.cc:99
TFileService.h
FFTJetPileupAnalyzer::ntupleData
std::vector< float > ntupleData
Definition: FFTJetPileupAnalyzer.cc:101
FFTJetPileupAnalyzer::endJob
void endJob() override
Definition: FFTJetPileupAnalyzer.cc:395
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
FFTJetPileupAnalyzer::collectVertexInfo
bool collectVertexInfo
Definition: FFTJetPileupAnalyzer.cc:95
edm::ParameterSet
Definition: ParameterSet.h:47
fftjetpileupanalyzer_cfi.ntupleName
ntupleName
Definition: fftjetpileupanalyzer_cfi.py:37
Event.h
FFTJetPileupAnalyzer::fastJetSigmaToken
edm::EDGetTokenT< double > fastJetSigmaToken
Definition: FFTJetPileupAnalyzer.cc:80
cond::runnumber
Definition: Time.h:19
HLT_FULL_cff.nPhi
nPhi
Definition: HLT_FULL_cff.py:6586
edm::Service< TFileService >
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
iEvent
int iEvent
Definition: GenABIO.cc:224
FFTJetPileupAnalyzer::summaryLabel
edm::InputTag summaryLabel
Definition: FFTJetPileupAnalyzer.cc:70
edmLumisInFiles.summary
summary
Definition: edmLumisInFiles.py:39
FFTJetPileupAnalyzer::verbosePileupInfo
bool verbosePileupInfo
Definition: FFTJetPileupAnalyzer.cc:96
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
fftjetpileupanalyzer_cfi.fastJetSigmaLabel
fastJetSigmaLabel
Definition: fftjetpileupanalyzer_cfi.py:25
fftjetpileupanalyzer_cfi.collectVertexInfo
collectVertexInfo
Definition: fftjetpileupanalyzer_cfi.py:49
FFTJetPileupAnalyzer::counter
unsigned long counter
Definition: FFTJetPileupAnalyzer.cc:105
PileupSummaryInfo::getBunchCrossing
const int getBunchCrossing() const
Definition: PileupSummaryInfo.h:73
edm::EventSetup
Definition: EventSetup.h:58
fftjetpileupanalyzer_cfi.collectGridDensity
collectGridDensity
Definition: fftjetpileupanalyzer_cfi.py:48
FFTJetPileupAnalyzer::nt
TNtuple * nt
Definition: FFTJetPileupAnalyzer.cc:102
TFileService::make
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PileupSummaryInfo::getPU_sumpT_highpT
const std::vector< float > & getPU_sumpT_highpT() const
Definition: PileupSummaryInfo.h:67
VertexFwd.h
FFTJetPileupAnalyzer::collectOOTPileup
bool collectOOTPileup
Definition: FFTJetPileupAnalyzer.cc:92
FFTJetPileupAnalyzer::totalNPV
int totalNPV
Definition: FFTJetPileupAnalyzer.cc:104
std
Definition: JetResolutionObject.h:76
fftjetpileupanalyzer_cfi.collectGrids
collectGrids
Definition: fftjetpileupanalyzer_cfi.py:47
TFileService::getBareDirectory
TDirectory * getBareDirectory(const std::string &subdir="") const
Definition: TFileService.h:52
Vertex.h
FFTJetPileupAnalyzer::srcPVsToken
edm::EDGetTokenT< reco::VertexCollection > srcPVsToken
Definition: FFTJetPileupAnalyzer.cc:82
Frameworkfwd.h
PileupSummaryInfo::getPU_NumInteractions
const int getPU_NumInteractions() const
Definition: PileupSummaryInfo.h:62
FFTJetPileupAnalyzer::fastJetSigmaLabel
edm::InputTag fastJetSigmaLabel
Definition: FFTJetPileupAnalyzer.cc:72
fftjetpileupanalyzer_cfi.gridLabel
gridLabel
Definition: fftjetpileupanalyzer_cfi.py:28
FFTJetPileupAnalyzer::vertexNdofCut
double vertexNdofCut
Definition: FFTJetPileupAnalyzer.cc:98
FFTJetPileupAnalyzer::fastJetRhoToken
edm::EDGetTokenT< double > fastJetRhoToken
Definition: FFTJetPileupAnalyzer.cc:79
HLT_FULL_cff.srcPVs
srcPVs
Definition: HLT_FULL_cff.py:8669
FFTJetPileupAnalyzer::ntupleTitle
std::string ntupleTitle
Definition: FFTJetPileupAnalyzer.cc:87
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
FFTJetPileupAnalyzer::operator=
FFTJetPileupAnalyzer & operator=(const FFTJetPileupAnalyzer &)=delete
DiscretizedEnergyFlow.h
FFTJetPileupAnalyzer::histoLabel
edm::InputTag histoLabel
Definition: FFTJetPileupAnalyzer.cc:69
fftjetpileupanalyzer_cfi.summaryLabel
summaryLabel
Definition: fftjetpileupanalyzer_cfi.py:18
ParameterSet.h
fftjetproducer_cfi.pileupLabel
pileupLabel
Definition: fftjetproducer_cfi.py:226
edm::Event
Definition: Event.h:73
FFTJetPileupAnalyzer::pileupToken
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > pileupToken
Definition: FFTJetPileupAnalyzer.cc:83
FFTJetPileupAnalyzer::summaryToken
edm::EDGetTokenT< reco::FFTJetPileupSummary > summaryToken
Definition: FFTJetPileupAnalyzer.cc:78
fftjetimagerecorder_cfi.histoLabel
histoLabel
Definition: fftjetimagerecorder_cfi.py:12
FFTJetPileupAnalyzer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: FFTJetPileupAnalyzer.cc:272
FFTJetPileupAnalyzer::ntupleName
std::string ntupleName
Definition: FFTJetPileupAnalyzer.cc:86
edm::InputTag
Definition: InputTag.h:15
fftjetpileupanalyzer_cfi.ntupleTitle
ntupleTitle
Definition: fftjetpileupanalyzer_cfi.py:38
FFTJetPileupAnalyzer::etSumToken
edm::EDGetTokenT< std::pair< double, double > > etSumToken
Definition: FFTJetPileupAnalyzer.cc:84
FFTJetPileupAnalyzer::analyzePileup
void analyzePileup(const std::vector< PileupSummaryInfo > &pInfo)
Definition: FFTJetPileupAnalyzer.cc:165
fftjetpileupanalyzer_cfi.collectHistos
collectHistos
Definition: fftjetpileupanalyzer_cfi.py:41
PileupSummaryInfo
Definition: PileupSummaryInfo.h:22
FFTJetPileupAnalyzer::totalNpu
int totalNpu
Definition: FFTJetPileupAnalyzer.cc:103
FFTJetPileupAnalyzer::fastJetRhoLabel
edm::InputTag fastJetRhoLabel
Definition: FFTJetPileupAnalyzer.cc:71