forked from pwittich/mictest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinInfoUtils.h
64 lines (51 loc) · 2.32 KB
/
BinInfoUtils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef _bininfoutils_
#define _bininfoutils_
// could #include "TMath.h", but then this is problematic for non root running. This compiles and runs without tmath.h
#include <cmath>
#include <vector>
#include "Config.h"
#include <iostream>
typedef std::pair<int, int> BinInfo;
typedef std::vector<std::vector<BinInfo>> BinInfoLayerMap;
typedef std::vector<BinInfoLayerMap> BinInfoMap;
inline float downPhi(float phi)
{
while (phi >= Config::PI) {phi-=Config::TwoPI;}
return phi;
}
inline float upPhi(float phi)
{
while (phi <= -Config::PI) {phi+=Config::TwoPI;}
return phi;
}
inline float normalizedPhi(float phi)
{
// return std::fmod(phi, (float) Config::PI); // return phi +pi out of phase for |phi| beyond boundary!
if (std::abs(phi)>=Config::PI) {phi = (phi>0 ? downPhi(phi) : upPhi(phi));}
return phi;
}
inline int getPhiPartition(float phi)
{
//assume phi is between -PI and PI
// if (!(fabs(phi)<Config::PI)) std::cout << "anomalous phi=" << phi << std::endl;
// const float phiPlusPi = std::fmod(phi+Config::PI,Config::TwoPI); // normaliztion done here
const float phiPlusPi = phi+Config::PI;
int bin = phiPlusPi*Config::fPhiFactor;
// theoretically these checks below should be taken care of by normalizedPhi, however...
// these condition checks appeared in very bizarre corner case where propagated phi == pi != Config::PI in check of normalizedPhi (but not unexpected... comparing float point numbers)
// i.e. delta on floating point check smaller than comparison... making what should be bin = nPhiPart - 1 instead bin = nPhiPart (out of bounds!!) ...or worse if unsigned bin < 0, bin == int max!
if (bin<0) bin = 0;
else if (bin>=Config::nPhiPart) bin = Config::nPhiPart - 1;
return bin;
}
inline int getEtaPartition(float eta)
{
const float etaPlusEtaDet = eta + Config::fEtaDet;
int bin = (etaPlusEtaDet * Config::nEtaPart) / (Config::fEtaFull); // ten bins for now ... update if changed in Event.cc
// use this check instead of normalizedEta()... directly bin into first/last bins eta of range of detector
if (bin<0) bin = 0;
else if (bin>=Config::nEtaPart) bin = Config::nEtaPart - 1;
return bin;
}
std::vector<int> getCandHitIndices(const int &, const int &, const int &, const int &, const BinInfoLayerMap &);
#endif