CMS 3D CMS Logo

LumiCalculator.cc
Go to the documentation of this file.
1 #ifndef RecoLuminosity_LumiProducer_LumiCalculator_h
2 #define RecoLuminosity_LumiProducer_LumiCalculator_h
14 #include <boost/regex.hpp>
15 #include <iostream>
16 #include <map>
21  unsigned int prescale;
22 };
23 struct l1PerBitInfo {
25  unsigned int prescale;
26 };
27 struct MyPerLumiInfo {
28  unsigned int lsnum;
29  float livefraction;
30  float intglumi;
31  unsigned long long deadcount;
32 };
33 
35 public:
36  explicit LumiCalculator(edm::ParameterSet const& pset);
37  ~LumiCalculator() override;
38 
39 private:
40  void beginJob() override;
41  void beginRun(const edm::Run& run, const edm::EventSetup& c) override;
42  void analyze(edm::Event const& e, edm::EventSetup const& c) override;
43  void endLuminosityBlock(edm::LuminosityBlock const& lumiBlock, edm::EventSetup const& c) override;
44  void endRun(edm::Run const&, edm::EventSetup const&) override;
45  void endJob() override;
46  std::vector<std::string> splitpathstr(const std::string& strValue, const std::string separator);
48  std::multimap<std::string, std::string> trgpathMmap_; //key:hltpath,value:l1bit
49  std::map<std::string, hltPerPathInfo> hltmap_;
50  std::map<std::string, l1PerBitInfo> l1map_; //
51  std::vector<MyPerLumiInfo> perrunlumiinfo_;
52 
53 private:
56  unsigned int currentlumi_;
57 }; //end class
58 
59 // -----------------------------------------------------------------
60 
61 LumiCalculator::LumiCalculator(edm::ParameterSet const& pset) : log_(new edm::LogInfo("LumiReport")), currentlumi_(0) {
62  showTrgInfo_ = pset.getUntrackedParameter<bool>("showTriggerInfo", false);
63  consumes<LumiSummary, edm::InLumi>(edm::InputTag("lumiProducer", ""));
64  consumes<LumiSummaryRunHeader, edm::InRun>(edm::InputTag("lumiProducer", ""));
65 }
66 
67 // -----------------------------------------------------------------
68 
70  delete log_;
71  log_ = nullptr;
72 }
73 
74 // -----------------------------------------------------------------
75 
77 
78 // -----------------------------------------------------------------
79 
81 
82 // -----------------------------------------------------------------
83 
85  //std::cout<<"I'm in run number "<<run.run()<<std::endl;
86  //if(!hltConfig_.init("HLT")){
87  // throw cms::Exception("HLT process cannot be initialized");
88  //}
89  bool changed(true);
90  const std::string processname("HLT");
91  if (!hltConfig_.init(run, c, processname, changed)) {
92  throw cms::Exception("HLT process cannot be initialized");
93  }
94  perrunlumiinfo_.clear();
95  trgpathMmap_.clear();
96  hltmap_.clear();
97  l1map_.clear();
98  //hltConfig_.dump("processName");
99  //hltConfig_.dump("TableName");
100  //hltConfig_.dump("Triggers");
101  //hltConfig_.dump("Modules");
102  if (showTrgInfo_) {
103  *log_ << "======Trigger Configuration Overview======\n";
104  *log_ << "Run " << run.run() << " Trigger Table : " << hltConfig_.tableName() << "\n";
105  }
106  unsigned int totaltrg = hltConfig_.size();
107  for (unsigned int t = 0; t < totaltrg; ++t) {
109  std::vector<std::string> numpathmodules = hltConfig_.moduleLabels(hltname);
110  if (showTrgInfo_) {
111  *log_ << t << " HLT path\t" << hltname << "\n";
112  }
114  hlt.prescale = 1;
115  hltmap_.insert(std::make_pair(hltname, hlt));
116  std::vector<std::string>::iterator hltpathBeg = numpathmodules.begin();
117  std::vector<std::string>::iterator hltpathEnd = numpathmodules.end();
118  unsigned int mycounter = 0;
119  for (std::vector<std::string>::iterator numpathmodule = hltpathBeg; numpathmodule != hltpathEnd; ++numpathmodule) {
120  if (hltConfig_.moduleType(*numpathmodule) != "HLTLevel1GTSeed") {
121  continue;
122  }
123  ++mycounter;
124 
125  edm::ParameterSet l1GTPSet = hltConfig_.modulePSet(*numpathmodule);
126  std::string l1pathname = l1GTPSet.getParameter<std::string>("L1SeedsLogicalExpression");
127  //*log_<<"numpathmodule "<< *numpathmodule <<" : l1pathname "<<l1pathname<<"\n";
128  if (mycounter > 1) {
129  if (showTrgInfo_) {
130  *log_ << "\tskip and erase previous seeds : multiple L1SeedsLogicalExpressions per hlt path\n";
131  }
132  //erase all previously calculated seeds for this path
133  trgpathMmap_.erase(hltname);
134  continue;
135  }
136  if (l1pathname.find("(") != std::string::npos) {
137  if (showTrgInfo_) {
138  *log_ << " L1SeedsLogicalExpression(Complex)\t" << l1pathname << "\n";
139  *log_ << "\tskip:contain complex logic\n";
140  }
141  continue;
142  } else if (l1pathname.find("OR") != std::string::npos) {
143  if (showTrgInfo_) {
144  *log_ << " L1SeedsLogicalExpression(ORed)\t" << l1pathname << "\n";
145  }
146  std::vector<std::string> seeds = splitpathstr(l1pathname, " OR ");
147  if (seeds.size() > 2) {
148  if (showTrgInfo_) {
149  *log_ << "\tskip:contain >1 OR\n";
150  }
151  continue;
152  } else {
153  for (std::vector<std::string>::iterator i = seeds.begin(); i != seeds.end(); ++i) {
154  if (!i->empty() && showTrgInfo_)
155  *log_ << "\t\tseed: " << *i << "\n";
156  if (i == seeds.begin()) { //for now we take the first one from OR
157  trgpathMmap_.insert(std::make_pair(hltname, *i));
158  }
159  }
160  }
161  } else if (l1pathname.find("AND") != std::string::npos) {
162  if (showTrgInfo_) {
163  *log_ << " L1SeedsLogicalExpression(ANDed)\t" << l1pathname << "\n";
164  }
165  std::vector<std::string> seeds = splitpathstr(l1pathname, " AND ");
166  if (seeds.size() > 2) {
167  if (showTrgInfo_) {
168  *log_ << "\tskip:contain >1 AND\n";
169  }
170  continue;
171  } else {
172  for (std::vector<std::string>::iterator i = seeds.begin(); i != seeds.end(); ++i) {
173  if (!i->empty() && showTrgInfo_)
174  *log_ << "\t\tseed: " << *i << "\n";
175  if (i == seeds.begin()) { //for now we take the first one
176  trgpathMmap_.insert(std::make_pair(hltname, *i));
177  }
178  }
179  }
180  } else {
181  if (showTrgInfo_) {
182  *log_ << " L1SeedsLogicalExpression(ONE)\t" << l1pathname << "\n";
183  }
184  if (splitpathstr(l1pathname, " NOT ").size() > 1) {
185  if (showTrgInfo_) {
186  *log_ << "\tskip:contain NOT\n";
187  }
188  continue;
189  }
190  trgpathMmap_.insert(std::make_pair(hltname, l1pathname));
191  }
192  }
193  }
194  if (showTrgInfo_) {
195  *log_ << "================\n";
196  }
197 }
198 
199 // -----------------------------------------------------------------
204  //std::cout<<"I'm in lumi block "<<lumiBlock.id()<<std::endl;
205 
207  lumiBlock.getByLabel("lumiProducer", lumiSummary);
208 
209  edm::Handle<LumiSummaryRunHeader> lumiSummaryRH;
210  lumiBlock.getRun().getByLabel("lumiProducer", lumiSummaryRH);
211 
213  l.lsnum = lumiBlock.id().luminosityBlock();
214 
215  //
216  //collect lumi.
217  //
218  l.deadcount = lumiSummary->deadcount();
219  l.intglumi = lumiSummary->avgInsDelLumi() * 93.244;
220  l.livefraction = lumiSummary->liveFrac();
221 
222  *log_ << "====== Lumi Section " << lumiBlock.id().luminosityBlock() << " ======\n";
223  *log_ << "\t Luminosity " << l.intglumi << "\n";
224  *log_ << "\t Dead count " << l.deadcount << "\n";
225  *log_ << "\t Deadtime corrected Luminosity " << l.intglumi * l.livefraction << "\n";
226 
227  //
228  //print correlated hlt-l1 info, only if you ask
229  //
230  if (showTrgInfo_) {
231  std::map<std::string, hltPerPathInfo>::iterator hltit;
232  std::map<std::string, hltPerPathInfo>::iterator hltitBeg = hltmap_.begin();
233  std::map<std::string, hltPerPathInfo>::iterator hltitEnd = hltmap_.end();
234 
235  typedef std::pair<std::multimap<std::string, std::string>::iterator,
236  std::multimap<std::string, std::string>::iterator>
237  TRGMAPIT;
238  unsigned int c = 0;
239  for (hltit = hltitBeg; hltit != hltitEnd; ++hltit) {
240  std::string hltname = hltit->first;
241  *log_ << c << " HLT path " << hltname << " , prescale : " << hltit->second.prescale << "\n";
242  TRGMAPIT ppp;
243  ppp = trgpathMmap_.equal_range(hltname);
244  if (ppp.first == ppp.second) {
245  *log_ << " no L1\n";
246  }
247  for (std::multimap<std::string, std::string>::iterator mit = ppp.first; mit != ppp.second; ++mit) {
248  std::string l1name = mit->second;
249  *log_ << " L1 name : " << l1name;
250  LumiSummary::L1 l1result = lumiSummary->l1info(lumiSummaryRH->getL1Index(l1name));
251  *log_ << " prescale : " << l1result.prescale << "\n";
252  *log_ << "\n";
253  }
254  ++c;
255  }
256  }
257  //
258  //accumulate hlt counts. Absent for now
259  //
265  //
266  //accumulate l1 counts
267  //
268  size_t n = lumiSummary->nTriggerLine();
269  for (size_t i = 0; i < n; ++i) {
270  std::string l1bitname = lumiSummaryRH->getL1Name(lumiSummary->l1info(i).triggernameidx);
271  l1PerBitInfo t;
272  if (currentlumi_ == 0) {
273  t.prescale = lumiSummary->l1info(i).prescale;
274  l1map_.insert(std::make_pair(l1bitname, t));
275  }
276  }
277 
278  perrunlumiinfo_.push_back(l);
279 
280  ++currentlumi_;
281 }
282 
283 // -----------------------------------------------------------------
301  //std::cout<<"valid trigger lines "<<trgpathMmap_.size()<<std::endl;
302  //std::cout<<"total lumi lines "<<perrunlumiinfo_.size()<<std::endl;
303  std::vector<MyPerLumiInfo>::const_iterator lumiIt;
304  std::vector<MyPerLumiInfo>::const_iterator lumiItBeg = perrunlumiinfo_.begin();
305  std::vector<MyPerLumiInfo>::const_iterator lumiItEnd = perrunlumiinfo_.end();
306  float recorded = 0.0;
307 
308  *log_ << "================ Run Summary " << run.run() << "================\n";
309  for (lumiIt = lumiItBeg; lumiIt != lumiItEnd; ++lumiIt) { //loop over LS
310  recorded += lumiIt->intglumi * lumiIt->livefraction;
311  }
312  *log_ << " CMS Recorded Lumi (e+27cm^-2) : " << recorded << "\n";
313  *log_ << " Effective Lumi (e+27cm^-2) per trigger path: "
314  << "\n\n";
315  std::multimap<std::string, std::string>::iterator it;
316  std::multimap<std::string, std::string>::iterator itBeg = trgpathMmap_.begin();
317  std::multimap<std::string, std::string>::iterator itEnd = trgpathMmap_.end();
318  unsigned int cc = 0;
319  for (it = itBeg; it != itEnd; ++it) {
320  *log_ << " " << cc << " " << it->first << " - " << it->second << " : ";
321  ++cc;
322  std::map<std::string, hltPerPathInfo>::const_iterator hltIt = hltmap_.find(it->first);
323  if (hltIt == hltmap_.end()) {
324  std::cout << "HLT path " << it->first << " not found" << std::endl;
325  *log_ << "\n";
326  continue;
327  }
328  std::map<std::string, l1PerBitInfo>::const_iterator l1It = l1map_.find(it->second);
329  if (l1It == l1map_.end()) {
330  std::cout << "L1 bit " << it->second << " not found" << std::endl;
331  *log_ << "\n";
332  continue;
333  }
334  unsigned int hltprescale = hltIt->second.prescale;
335  unsigned int l1prescale = l1It->second.prescale;
336  if (hltprescale != 0 && l1prescale != 0) {
337  float effectiveLumi = recorded / (hltprescale * l1prescale);
338  *log_ << effectiveLumi << "\n";
339  } else {
340  *log_ << "0 prescale exception\n";
341  continue;
342  }
343  *log_ << "\n";
344  }
345 }
346 
347 // -----------------------------------------------------------------
349 
350 std::vector<std::string> LumiCalculator::splitpathstr(const std::string& strValue, const std::string separator) {
351  std::vector<std::string> vecstrResult;
352  boost::regex re(separator);
353  boost::sregex_token_iterator p(strValue.begin(), strValue.end(), re, -1);
354  boost::sregex_token_iterator end;
355  while (p != end) {
356  vecstrResult.push_back(*p++);
357  }
358  return vecstrResult;
359 }
360 
362 #endif
Handle.h
LumiSummary::L1::prescale
unsigned int prescale
Definition: LumiSummary.h:26
LumiSummaryRunHeader::getL1Name
std::string getL1Name(unsigned int idx) const
Get L1 name at given position.
Definition: LumiSummaryRunHeader.h:57
mps_fire.i
i
Definition: mps_fire.py:355
LumiCalculator::currentlumi_
unsigned int currentlumi_
Definition: LumiCalculator.cc:56
MessageLogger.h
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
HLTConfigProvider::moduleType
const std::string moduleType(const std::string &module) const
C++ class name of module.
Definition: HLTConfigProvider.h:103
LumiSummaryRunHeader::getL1Index
unsigned int getL1Index(const std::string &name) const
Get index of given L1 trigger-name. Returns -1 if not found.
Definition: LumiSummaryRunHeader.cc:27
LumiCalculator::perrunlumiinfo_
std::vector< MyPerLumiInfo > perrunlumiinfo_
Definition: LumiCalculator.cc:51
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::Run
Definition: Run.h:45
LuminosityBlock.h
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::LogInfo
Definition: MessageLogger.h:254
LumiCalculator::hltConfig_
HLTConfigProvider hltConfig_
Definition: LumiCalculator.cc:47
EDAnalyzer.h
LumiSummary::L1
Definition: LumiSummary.h:22
edm::Handle
Definition: AssociativeIterator.h:50
LumiCalculator::~LumiCalculator
~LumiCalculator() override
Definition: LumiCalculator.cc:69
LumiCalculator::LumiCalculator
LumiCalculator(edm::ParameterSet const &pset)
Definition: LumiCalculator.cc:61
end
#define end
Definition: vmac.h:39
edm::EDAnalyzer
Definition: EDAnalyzer.h:29
mps_merge.separator
string separator
Definition: mps_merge.py:79
HLTConfigProvider::moduleLabels
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
Definition: HLTConfigProvider.h:75
MakerMacros.h
edmLumisInFiles.recorded
recorded
Definition: edmLumisInFiles.py:32
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Run.h
l1PerBitInfo::l1PerBitInfo
l1PerBitInfo()
Definition: LumiCalculator.cc:24
MyPerLumiInfo::deadcount
unsigned long long deadcount
Definition: LumiCalculator.cc:31
OrderedSet.t
t
Definition: OrderedSet.py:90
EDGetToken.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLTConfigProvider::size
unsigned int size() const
number of trigger paths in trigger table
Definition: HLTConfigProvider.h:62
LumiCalculator::hltmap_
std::map< std::string, hltPerPathInfo > hltmap_
Definition: LumiCalculator.cc:49
InitialStep_cff.seeds
seeds
Definition: InitialStep_cff.py:232
HLTScalers_cfi.processname
processname
Definition: HLTScalers_cfi.py:12
HLTConfigProvider::modulePSet
const edm::ParameterSet & modulePSet(const std::string &module) const
ParameterSet of module.
Definition: HLTConfigProvider.h:112
LumiCalculator::analyze
void analyze(edm::Event const &e, edm::EventSetup const &c) override
Definition: LumiCalculator.cc:76
edm::ParameterSet
Definition: ParameterSet.h:36
LumiCalculator::showTrgInfo_
bool showTrgInfo_
Definition: LumiCalculator.cc:55
Event.h
LumiCalculator
Definition: LumiCalculator.cc:34
edm::LuminosityBlockID::luminosityBlock
LuminosityBlockNumber_t luminosityBlock() const
Definition: LuminosityBlockID.h:42
edm::LuminosityBlockBase::id
LuminosityBlockID id() const
Definition: LuminosityBlockBase.h:44
hltPerPathInfo::hltPerPathInfo
hltPerPathInfo()
Definition: LumiCalculator.cc:20
HLTConfigProvider::tableName
const std::string & tableName() const
HLT ConfDB table name.
Definition: HLTConfigProvider.h:59
bphysicsOniaDQM_cfi.lumiSummary
lumiSummary
Definition: bphysicsOniaDQM_cfi.py:8
hltPerPathInfo::prescale
unsigned int prescale
Definition: LumiCalculator.cc:21
edm::EventSetup
Definition: EventSetup.h:57
MyPerLumiInfo
Definition: LumiCalculator.cc:27
LumiCalculator::endRun
void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: LumiCalculator.cc:284
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
HLTConfigProvider.h
edm::LuminosityBlock::getRun
Run const & getRun() const
Definition: LuminosityBlock.h:106
cc
prescale
Definition: PrescaleEventFilter.cc:32
LumiCalculator::beginRun
void beginRun(const edm::Run &run, const edm::EventSetup &c) override
Definition: LumiCalculator.cc:84
l1PerBitInfo::prescale
unsigned int prescale
Definition: LumiCalculator.cc:25
InputTag.h
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:193
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
LumiCalculator::log_
edm::LogInfo * log_
Definition: LumiCalculator.cc:54
HLTConfigProvider
Definition: HLTConfigProvider.h:28
writedatasetfile.run
run
Definition: writedatasetfile.py:27
hltPerPathInfo
Definition: LumiCalculator.cc:19
HLTConfigProvider::init
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d'tor
Definition: HLTConfigProvider.cc:36
LumiCalculator::endLuminosityBlock
void endLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c) override
Definition: LumiCalculator.cc:200
l1PerBitInfo
Definition: LumiCalculator.cc:23
Exception
Definition: hltDiff.cc:246
LumiSummary.h
MyPerLumiInfo::livefraction
float livefraction
Definition: LumiCalculator.cc:29
LumiCalculator::endJob
void endJob() override
Definition: LumiCalculator.cc:348
MyPerLumiInfo::lsnum
unsigned int lsnum
Definition: LumiCalculator.cc:28
MyPerLumiInfo::intglumi
float intglumi
Definition: LumiCalculator.cc:30
HLTConfigProvider::triggerName
const std::string & triggerName(unsigned int triggerIndex) const
Definition: HLTConfigProvider.h:69
LumiSummaryRunHeader.h
edm::Run::getByLabel
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: Run.h:280
ParameterSet.h
edm::Event
Definition: Event.h:73
LumiCalculator::l1map_
std::map< std::string, l1PerBitInfo > l1map_
Definition: LumiCalculator.cc:50
LumiCalculator::splitpathstr
std::vector< std::string > splitpathstr(const std::string &strValue, const std::string separator)
Definition: LumiCalculator.cc:350
LumiCalculator::trgpathMmap_
std::multimap< std::string, std::string > trgpathMmap_
Definition: LumiCalculator.cc:48
edm::LuminosityBlock::getByLabel
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: LuminosityBlock.h:281
edm::InputTag
Definition: InputTag.h:15
LumiCalculator::beginJob
void beginJob() override
Definition: LumiCalculator.cc:80
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
ValidationMatrix.hlt
hlt
Definition: ValidationMatrix.py:459
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37