1 #ifndef SiStripHitEfficiencyHelpers_H 2 #define SiStripHitEfficiencyHelpers_H 8 #include <fmt/printf.h> 19 #include "TEfficiency.h" 28 k_LayersAtTOBEnd = 10,
29 k_LayersAtTIDEnd = 13,
30 k_LayersAtTECEnd = 22,
32 k_END_OF_LAYS_AND_RINGS = 35
38 enum projections { k_vs_LUMI = 0, k_vs_PU = 1, k_vs_BX = 2, k_SIZE = 3 };
40 const std::array<std::string, projections::k_SIZE> projFolder = {{
"VsLumi",
"VsPu",
"VsBx"}};
41 const std::array<std::string, projections::k_SIZE> projFoundHisto = {
42 {
"layerfound_vsLumi_layer_",
"layerfound_vsPU_layer_",
"foundVsBx_layer"}};
43 const std::array<std::string, projections::k_SIZE> projTotalHisto = {
44 {
"layertotal_vsLumi_layer_",
"layertotal_vsPU_layer_",
"totalVsBx_layer"}};
45 const std::array<std::string, projections::k_SIZE> projTitle = {{
"Inst Lumi",
"Pile-Up",
"Bunch Crossing"}};
46 const std::array<std::string, projections::k_SIZE> projXtitle = {
47 {
"instantaneous luminosity [Hz/cm^{2}]",
"Pile-Up events",
"Bunch Crossing number"}};
53 while ((start_pos =
str.find(from, start_pos)) != std::string::npos) {
54 str.replace(start_pos, from.length(),
to);
55 start_pos +=
to.length();
59 inline unsigned int checkLayer(
unsigned int iidd,
const TrackerTopology* tTopo) {
60 switch (
DetId(iidd).subdetId()) {
64 return tTopo->
tobLayer(iidd) + bounds::k_LayersAtTIBEnd;
66 return tTopo->
tidWheel(iidd) + bounds::k_LayersAtTOBEnd;
68 return tTopo->
tecWheel(iidd) + bounds::k_LayersAtTIDEnd;
70 return bounds::k_LayersStart;
74 inline std::string layerName(
unsigned int k,
const bool showRings,
const unsigned int nTEClayers) {
76 if (
k > bounds::k_LayersStart &&
k <= bounds::k_LayersAtTIBEnd) {
78 }
else if (
k > bounds::k_LayersAtTIBEnd &&
k <= bounds::k_LayersAtTOBEnd) {
79 return fmt::format(
"TOB L{:d}",
k - bounds::k_LayersAtTIBEnd);
80 }
else if (
k > bounds::k_LayersAtTOBEnd &&
k <= bounds::k_LayersAtTIDEnd) {
81 return fmt::format(
"TID {0}{1:d}", ringlabel,
k - bounds::k_LayersAtTOBEnd);
82 }
else if (
k > bounds::k_LayersAtTIDEnd &&
k <= bounds::k_LayersAtTIDEnd + nTEClayers) {
83 return fmt::format(
"TEC {0}{1:d}", ringlabel,
k - bounds::k_LayersAtTIDEnd);
85 return "should never be here!";
89 inline std::string layerSideName(Long_t
k,
const bool showRings,
const unsigned int nTEClayers) {
91 if (
k > bounds::k_LayersStart &&
k <= bounds::k_LayersAtTIBEnd) {
93 }
else if (
k > bounds::k_LayersAtTIBEnd &&
k <= bounds::k_LayersAtTOBEnd) {
94 return fmt::format(
"TOB L{:d}",
k - bounds::k_LayersAtTIBEnd);
95 }
else if (
k > bounds::k_LayersAtTOBEnd &&
k < 14) {
96 return fmt::format(
"TID- {0}{1:d}", ringlabel,
k - bounds::k_LayersAtTOBEnd);
97 }
else if (
k > 13 &&
k < 17) {
99 }
else if (
k > 16 &&
k < 17 + nTEClayers) {
101 }
else if (
k > 16 + nTEClayers) {
102 return fmt::format(
"TEC+ {0}{1:d}", ringlabel,
k - 16 - nTEClayers);
104 return "shoud never be here!";
113 double consistency = separation /
error;
117 inline bool isDoubleSided(
unsigned int iidd,
const TrackerTopology* tTopo) {
119 switch (
DetId(iidd).subdetId()) {
137 inline bool check2DPartner(
unsigned int iidd,
const std::vector<TrajectoryMeasurement>& traj) {
138 unsigned int partner_iidd = 0;
139 bool found2DPartner =
false;
141 if ((iidd & 0x3) == 1)
142 partner_iidd = iidd + 1;
143 if ((iidd & 0x3) == 2)
144 partner_iidd = iidd - 1;
147 for (
const auto& tm : traj) {
148 if (tm.recHit()->geographicalId().rawId() == partner_iidd) {
149 found2DPartner =
true;
152 return found2DPartner;
155 inline bool isInBondingExclusionZone(
156 unsigned int iidd,
unsigned int TKlayers,
double yloc,
double yErr,
const TrackerTopology* tTopo) {
157 constexpr
float exclusionWidth = 0.4;
158 constexpr
float TOBexclusion = 0.0;
159 constexpr
float TECexRing5 = -0.89;
160 constexpr
float TECexRing6 = -0.56;
161 constexpr
float TECexRing7 = 0.60;
165 const int ringnumber = ((iidd >> 5) & 0x7);
169 if ((TKlayers >= 5 && TKlayers < 11) || ((
subdetector == 6) && ((ringnumber >= 5) && (ringnumber <= 7)))) {
171 float highzone = 0.0;
173 float higherr = yloc + 5.0 * yErr;
174 float lowerr = yloc - 5.0 * yErr;
175 if (TKlayers >= 5 && TKlayers < 11) {
177 highzone = TOBexclusion + exclusionWidth;
178 lowzone = TOBexclusion - exclusionWidth;
179 }
else if (ringnumber == 5) {
181 highzone = TECexRing5 + exclusionWidth;
182 lowzone = TECexRing5 - exclusionWidth;
183 }
else if (ringnumber == 6) {
185 highzone = TECexRing6 + exclusionWidth;
186 lowzone = TECexRing6 - exclusionWidth;
187 }
else if (ringnumber == 7) {
189 highzone = TECexRing7 + exclusionWidth;
190 lowzone = TECexRing7 - exclusionWidth;
193 if ((highzone <= higherr) && (highzone >= lowerr))
195 if ((lowzone >= lowerr) && (lowzone <= higherr))
197 if ((higherr <= highzone) && (higherr >= lowzone))
199 if ((lowerr >= lowzone) && (lowerr <= highzone))
209 ClusterInfo(
float xRes,
float xResPull,
float xLoc) : xResidual(xRes), xResidualPull(xResPull), xLocal(xLoc) {}
212 inline float calcPhi(
float x,
float y) {
214 if ((
x >= 0) && (
y >= 0))
215 phi = std::atan(
y /
x);
216 else if ((
x >= 0) && (
y <= 0))
218 else if ((
x <= 0) && (
y >= 0))
227 inline TProfile* computeEff(
const TH1F*
num,
const TH1F* denum,
const std::string nameHist) {
230 TProfile* efficHist =
new TProfile(
name.c_str(),
232 denum->GetXaxis()->GetNbins(),
233 denum->GetXaxis()->GetXmin(),
234 denum->GetXaxis()->GetXmax());
236 for (
int i = 1;
i <= denum->GetNbinsX();
i++) {
237 double nNum =
num->GetBinContent(
i);
238 double nDenum = denum->GetBinContent(
i);
239 if (nDenum == 0 || nNum == 0) {
244 <<
"Alert! specific bin's num is bigger than denum " <<
i <<
" " << nNum <<
" " << nDenum;
247 const double effVal = nNum / nDenum;
248 efficHist->SetBinContent(
i, effVal);
249 efficHist->SetBinEntries(
i, 1);
250 const double errLo = TEfficiency::ClopperPearson((
int)nDenum, (
int)nNum, 0.683,
false);
251 const double errUp = TEfficiency::ClopperPearson((
int)nDenum, (
int)nNum, 0.683,
true);
252 const double errVal = (effVal - errLo > errUp - effVal) ? effVal - errLo : errUp - effVal;
253 efficHist->SetBinError(
i,
sqrt(effVal * effVal + errVal * errVal));
255 LogDebug(
"SiStripHitEfficiencyHelpers") << __PRETTY_FUNCTION__ <<
" " << nameHist <<
" bin:" <<
i 256 <<
" err:" <<
sqrt(effVal * effVal + errVal * errVal);
261 inline Measurement1D computeCPEfficiency(
const double num,
const double den) {
263 const double effVal =
num / den;
264 const double errLo = TEfficiency::ClopperPearson((
int)den, (
int)
num, 0.683,
false);
265 const double errUp = TEfficiency::ClopperPearson((
int)den, (
int)
num, 0.683,
true);
266 const double errVal = (effVal - errLo > errUp - effVal) ? effVal - errLo : errUp - effVal;
std::pair< LocalPoint, LocalError > LocalValues
unsigned int tobLayer(const DetId &id) const
unsigned int tidWheel(const DetId &id) const
unsigned int tecWheel(const DetId &id) const
unsigned int tecRing(const DetId &id) const
ring id
Abs< T >::type abs(const T &t)
unsigned int tidRing(const DetId &id) const
unsigned int tibLayer(const DetId &id) const
Log< level::Warning, false > LogWarning