CMS 3D CMS Logo

L1AnalysisEvent.cc
Go to the documentation of this file.
2 
5 
6 #include <string>
7 #include <iostream>
8 #include <sys/stat.h>
9 
14  bool useAvgVtx,
15  double maxWeight,
16  edm::ConsumesCollector&& iConsumes)
17  : fillHLT_(true), doPUWeights_(false), useAvgVtx_(useAvgVtx), maxAllowedWeight_(maxWeight), lumiWeights_() {
18  pileupSummaryInfoToken_ = iConsumes.consumes<std::vector<PileupSummaryInfo>>(edm::InputTag("addPileupInfo"));
19  // check PU files exists, and reweight if they do
20  struct stat buf;
21  if ((stat(puMCFile.c_str(), &buf) != -1) && (stat(puDataFile.c_str(), &buf) != -1)) {
23  doPUWeights_ = true;
24  } else {
25  edm::LogWarning("L1Prompt") << "No PU reweighting inputs - not going to calculate weights" << std::endl;
26  }
27 }
28 
30 
32  event_.run = e.id().run();
33  event_.event = e.id().event();
34  event_.time = e.time().value();
35  event_.bx = e.bunchCrossing(); //overwritten by EVM info until fixed by fw
36  event_.lumi = e.luminosityBlock();
37  event_.orbit = e.orbitNumber(); //overwritten by EVM info until fixed by fw
38 
39  if (!hlt_.isUninitialized()) {
41  e.getByToken(hlt_, hltresults);
42  const edm::TriggerNames& TrigNames_ = e.triggerNames(*hltresults);
43  const int ntrigs = hltresults->size();
44 
45  for (int itr = 0; itr < ntrigs; itr++) {
46  TString trigName = TrigNames_.triggerName(itr);
47  if (!hltresults->accept(itr))
48  continue;
49  event_.hlt.push_back(trigName);
50  }
51  }
52 
53  // do PU re-weighting for MC only
54  double weight = 1.;
55 
56  if (doPUWeights_ && (!e.eventAuxiliary().isRealData())) {
58  e.getByLabel(edm::InputTag("addPileupInfo"), puInfo);
59 
60  if (puInfo.isValid()) {
61  std::vector<PileupSummaryInfo>::const_iterator pvi;
62 
63  float npv = -1;
64  for (pvi = puInfo->begin(); pvi != puInfo->end(); ++pvi) {
65  int bx = pvi->getBunchCrossing();
66 
67  if (bx == 0) {
68  npv = useAvgVtx_ ? pvi->getTrueNumInteractions() : pvi->getPU_NumInteractions();
69  continue;
70  }
71  }
72 
73  weight = lumiWeights_.weight(npv);
74  if (maxAllowedWeight_ > 0. && weight > maxAllowedWeight_)
75  weight = maxAllowedWeight_;
76  }
77  }
78 
79  if (!e.eventAuxiliary().isRealData()) {
81  e.getByToken(pileupSummaryInfoToken_, puInfo);
82  if (puInfo.isValid()) {
83  for (std::vector<PileupSummaryInfo>::const_iterator pvi = puInfo->begin(); pvi != puInfo->end(); pvi++) {
84  int bx = pvi->getBunchCrossing();
85  if (bx == 0) {
86  event_.nPV = pvi->getPU_NumInteractions();
87  event_.nPV_True = pvi->getTrueNumInteractions();
88  }
89  }
90  }
91  }
92 
93  event_.puWeight = weight;
94 }
PileupSummaryInfo.h
L1Analysis::L1AnalysisEvent::pileupSummaryInfoToken_
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > pileupSummaryInfoToken_
Definition: L1AnalysisEvent.h:54
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
HLTBitAnalyser_cfi.hltresults
hltresults
Definition: HLTBitAnalyser_cfi.py:13
edm::EDGetTokenT< edm::TriggerResults >
mps_merge.weight
weight
Definition: mps_merge.py:88
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
edm::EDGetTokenT::isUninitialized
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
l1EventTree_cfi.puDataHist
puDataHist
Definition: l1EventTree_cfi.py:8
L1Analysis::L1AnalysisEvent::L1AnalysisEvent
L1AnalysisEvent(std::string puMCFile, std::string puMCHist, std::string puDataFile, std::string puDataHist, bool useAvgVtx, double maxWeight, edm::ConsumesCollector &&)
Definition: L1AnalysisEvent.cc:10
edm::Handle< edm::TriggerResults >
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
l1EventTree_cfi.useAvgVtx
useAvgVtx
Definition: l1EventTree_cfi.py:9
l1EventTree_cfi.puMCFile
puMCFile
Definition: l1EventTree_cfi.py:5
L1Analysis::L1AnalysisEvent::doPUWeights_
bool doPUWeights_
Definition: L1AnalysisEvent.h:47
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EgHLTOffTrigSelection_cfi.trigName
trigName
Definition: EgHLTOffTrigSelection_cfi.py:8
funct::true
true
Definition: Factorize.h:173
L1AnalysisEvent.h
event_
void event_()
L1Analysis::L1AnalysisEvent::Set
void Set(const edm::Event &e, const edm::EDGetTokenT< edm::TriggerResults > &hlt_)
Definition: L1AnalysisEvent.cc:31
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
edm::TriggerNames::triggerName
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:50
l1EventTree_cfi.puDataFile
puDataFile
Definition: l1EventTree_cfi.py:6
L1Analysis::L1AnalysisEvent::lumiWeights_
edm::LumiReWeighting lumiWeights_
Definition: L1AnalysisEvent.h:52
edm::TriggerNames
Definition: TriggerNames.h:55
L1Analysis::L1AnalysisEvent::~L1AnalysisEvent
~L1AnalysisEvent()
Definition: L1AnalysisEvent.cc:29
edm_modernize_messagelogger.stat
stat
Definition: edm_modernize_messagelogger.py:27
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
l1EventTree_cfi.puMCHist
puMCHist
Definition: l1EventTree_cfi.py:7
edm::LumiReWeighting
Definition: LumiReWeighting.h:105
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
weight
Definition: weight.py:1
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37