1 |
#include "UserCode/L1RpcTriggerAnalysis/interface/DetEfficiencyManager.h"
|
2 |
#include <algorithm>
|
3 |
#include <iostream>
|
4 |
|
5 |
struct LessDE_detId {
|
6 |
bool operator()(const DetEfficiency& d1, const DetEfficiency& d2) { return d1.detId() < d2.detId(); }
|
7 |
};
|
8 |
struct LessDE_efficiency {
|
9 |
bool operator()(const DetEfficiency& d1, const DetEfficiency& d2) { return d1.efficiency() < d2.efficiency(); }
|
10 |
};
|
11 |
|
12 |
void DetEfficiencyManager::addDetSimHit(uint32_t rawId)
|
13 |
{
|
14 |
checkDet(rawId)->addSimHit();
|
15 |
}
|
16 |
|
17 |
void DetEfficiencyManager::addDetHit(uint32_t rawId)
|
18 |
{
|
19 |
checkDet(rawId)->addHit();
|
20 |
}
|
21 |
|
22 |
void DetEfficiencyManager::addDetMuon(uint32_t rawId)
|
23 |
{
|
24 |
checkDet(rawId)->addMuon();
|
25 |
}
|
26 |
|
27 |
unsigned int DetEfficiencyManager::allDetHit() const
|
28 |
{
|
29 |
unsigned int result = 0;
|
30 |
|
31 |
for (std::vector<DetEfficiency>::const_iterator it = theDets.begin(); it < theDets.end(); ++it) {
|
32 |
if (!it->isDummy()) result += it->numberOfHits();
|
33 |
}
|
34 |
return result;
|
35 |
}
|
36 |
|
37 |
unsigned int DetEfficiencyManager::allDetMuon() const
|
38 |
{
|
39 |
unsigned int result = 0;
|
40 |
|
41 |
for (std::vector<DetEfficiency>::const_iterator it = theDets.begin(); it < theDets.end(); ++it) {
|
42 |
if (!it->isDummy()) result += it->numberOfMuons();
|
43 |
}
|
44 |
return result;
|
45 |
}
|
46 |
|
47 |
std::vector<DetEfficiency>::iterator DetEfficiencyManager::checkDet(uint32_t rawId)
|
48 |
{
|
49 |
DetEfficiency candid(rawId);
|
50 |
std::vector<DetEfficiency>::iterator lb =
|
51 |
std::lower_bound(theDets.begin(), theDets.end(), candid, LessDE_detId());
|
52 |
if (lb != theDets.end() && (candid.detId() == lb->detId()) ) return lb;
|
53 |
else return theDets.insert(lb, candid);
|
54 |
}
|
55 |
|
56 |
void DetEfficiencyManager::print() const {
|
57 |
std::vector<DetEfficiency> sorted = theDets;
|
58 |
std::sort(sorted.begin(), sorted.end(), LessDE_efficiency());
|
59 |
uint32_t nHits = 0;
|
60 |
uint32_t nDets = 0;
|
61 |
for (std::vector<DetEfficiency>::const_iterator it = sorted.begin(); it < sorted.end(); ++it) {
|
62 |
if (!it->isDummy()) {
|
63 |
nHits += it->numberOfHits();
|
64 |
nDets += it->numberOfMuons();
|
65 |
}
|
66 |
std::cout << it->print() << std::endl;
|
67 |
}
|
68 |
std::cout <<" TOTAL EFFICIENCY FROM ROLLS: "<<nHits<<"/"<<nDets<<" = " << nHits/double(nDets) << std::endl;
|
69 |
}
|