CachedShowerRegeneratorOG/StationPositionMatrix.h
Go to the documentation of this file.
1 #ifndef _CachedShowerRegeneratorOG_StationPositionMatrix_h_
2 #define _CachedShowerRegeneratorOG_StationPositionMatrix_h_
3 
4 #include <utl/MathConstants.h>
5 #include <sdet/Station.h>
6 #include <sevt/Station.h>
7 
8 
10 
21  class StationInfo {
22  public:
23  StationInfo(const sdet::Station& dStation, sevt::Station& eStation,
24  const double phi, const double dphi,
25  const double r, const double lnSqrR1, const double lnSqrR2,
26  const double area) :
27  fDetStation(&dStation),
28  fEvtStation(&eStation),
29  fR(r),
30  fLnSqrR1(lnSqrR1),
31  fLnSqrR2(lnSqrR2),
32  fResamplingArea(area)
33  {
34  SetPhiRange(phi, dphi);
35  }
36 
37  bool IsInArea(const double phi, const double lnSqrR) const
38  { return IsPhiInRange(phi) && IsLnSqrRInRange(lnSqrR); }
39 
40  bool
41  IsInScaledArea(const double scale, const double phi, const double lnSqrR)
42  const
43  {
44  const double s = std::sqrt(scale);
45  return IsPhiInScaledRange(s, phi) && IsLnSqrRInScaledRange(s, lnSqrR);
46  }
47 
48  const sdet::Station& GetDetStation() const { return *fDetStation; }
49 
50  sevt::Station& GetEvtStation() const { return *fEvtStation; }
51 
52  double GetResamplingArea() const { return fResamplingArea; }
53 
54  double GetPhi1() const { return fPhi1; }
55 
56  double GetPhi2() const { return fPhi2; }
57 
58  double GetR() const { return fR; }
59 
60  double GetLnSqrR1() const { return fLnSqrR1; }
61 
62  double GetLnSqrR2() const { return fLnSqrR2; }
63 
64  void Dump() const;
65 
66  private:
67  void
68  SetPhiRange(const double phi, const double dphi)
69  {
70  fPhi1 = phi - dphi;
71  fPhi2 = phi + dphi;
72  if (fPhi1 < -utl::kPi) {
73  if (fPhi2 > utl::kPi) {
74  fPhi1 = -utl::kPi;
75  fPhi2 = utl::kPi;
76  } else
77  fPhi1 += 2*utl::kPi;
78  } else if (fPhi2 > utl::kPi)
79  fPhi2 -= 2*utl::kPi;
80  }
81 
82  static constexpr bool IsInInterval(const double x, const double a, const double b)
83  { return a <= x && x <= b; }
84 
85  bool IsPhiInRange(const double phi) const
86  { return (fPhi1 < fPhi2) ? IsInInterval(phi, fPhi1, fPhi2) : !IsInInterval(phi, fPhi2, fPhi1); }
87 
88  static constexpr double AbsShift(const double eps, const double a, const double b)
89  { return 0.5*((1 - eps)*a + (1 + eps)*b); }
90 
91  bool
92  IsPhiInScaledRange(const double scale, const double phi)
93  const
94  {
95  if (!IsPhiInRange(phi))
96  return false;
97  double p1 = fPhi1;
98  double p2 = fPhi2;
99  if (fPhi1 > fPhi2) {
100  if (phi < fPhi2)
101  p1 -= utl::kTwoPi;
102  else
103  p2 += utl::kTwoPi;
104  }
105  return IsInInterval(phi, AbsShift(-scale, p1, p2), AbsShift(scale, p1, p2));
106  }
107 
108  bool IsLnSqrRInRange(const double lnSqrR) const
109  { return IsInInterval(lnSqrR, fLnSqrR1, fLnSqrR2); }
110 
111  static
112  std::pair<double, double>
113  RelShift(const double eps, const double a, const double b)
114  {
115  const double ea = std::exp(0.5*a);
116  const double eb = std::exp(0.5*b);
117  const double em = 0.5*(1 - eps);
118  const double ep = 0.5*(1 + eps);
119  return std::make_pair(2*std::log(ep*ea + em*eb), 2*std::log(em*ea + ep*eb));
120  }
121 
122  bool
123  IsLnSqrRInScaledRange(const double scale, const double lnSqrR)
124  const
125  {
126  if (!IsLnSqrRInRange(lnSqrR))
127  return false;
128  const auto lnSqrR12 = RelShift(scale, fLnSqrR1, fLnSqrR2);
129  return IsInInterval(lnSqrR, lnSqrR12.first, lnSqrR12.second);
130  }
131 
134  double fPhi1 = 0;
135  double fPhi2 = 0;
136  double fR = 0;
137  double fLnSqrR1 = 0;
138  double fLnSqrR2 = 0;
139  double fResamplingArea = 0;
140  };
141 
142 
153  using namespace std;
154  using namespace utl;
155 
157  public:
158  typedef vector<StationInfo> StationInfoList;
159  typedef vector<const StationInfo*> StationInfoPtrList;
160 
161  StationPositionMatrix(const double phiGranularity, const double lnSqrRGranularity) :
162  fPhiGranularity(phiGranularity),
163  fLnSqrRGranularity(lnSqrRGranularity)
164  { }
165 
166  void PushBack(const sdet::Station& dStation, sevt::Station& eStation,
167  const double phi, const double dphi,
168  const double r, const double lnSqrR1, const double lnSqrR2,
169  const double area)
170  { fStations.emplace_back(dStation, eStation, phi, dphi, r, lnSqrR1, lnSqrR2, area); }
171 
172  void CreateMatrix(const bool useSpatialStationMatrix = true);
173 
175  { return fStations; }
176 
177  double GetMinLnSqrR() const { return fLnSqrR1; }
178 
179  const StationInfoPtrList&
180  GetInjectionCandidates(const double phi, const double lnSqrR)
181  const
182  {
183  const int iR = GetLnSqrRIndex(lnSqrR);
184  if (iR < 0 || iR >= fNR)
186  const int iPhi = GetPhiIndex(phi);
187  return fStationMatrix[iPhi][iR];
188  }
189 
190  StationInfoPtrList
191  GetInjectionStations(const double phi, const double lnSqrR)
192  const
193  {
194  StationInfoPtrList stations;
195  for (const auto candidate : GetInjectionCandidates(phi, lnSqrR))
196  if (candidate->IsInArea(phi, lnSqrR))
197  stations.push_back(candidate);
198  return stations;
199  }
200 
201  void Clear();
202 
203  void DumpStats() const;
204 
205  private:
206  int
207  GetPhiIndex(const double phi)
208  const
209  {
210  const int i = int((phi + utl::kPi) / fPhiStep);
211  return (i < fNPhi) ? i : fNPhi - 1;
212  }
213 
214  int GetLnSqrRIndex(const double lnSqrR) const
215  { return int((lnSqrR - fLnSqrR1) / fLnSqrRStep); }
216 
217  void Resize(const int nPhi, const int nR);
218 
219  const double fPhiGranularity;
220  const double fLnSqrRGranularity;
221 
222  int fNPhi = 0;
223  double fPhiStep = 0;
224  int fNR = 0;
225  double fLnSqrR1 = 0;
226  double fLnSqrRStep = 0;
227 
229 
230  typedef vector<vector<StationInfoPtrList>> StationMatrix;
232 
233  StationInfoPtrList fEmptyStationInfoPtrList; // can contain all stations in case the matrix is not used
234  };
235 
236 }
237 
238 
239 #endif
Detector description interface for Station-related data.
bool IsInArea(const double phi, const double lnSqrR) const
class to hold data at Station level
constexpr double s
Definition: AugerUnits.h:163
constexpr double kPi
Definition: MathConstants.h:24
return IsPhiInScaledRange(s, phi)&&IsLnSqrRInScaledRange(s
constexpr double kTwoPi
Definition: MathConstants.h:27
double eps
StationPositionMatrix(const double phiGranularity, const double lnSqrRGranularity)
static constexpr double AbsShift(const double eps, const double a, const double b)
Regenerate thinned MC showers.
static std::pair< double, double > RelShift(const double eps, const double a, const double b)
StationInfo(const sdet::Station &dStation, sevt::Station &eStation, const double phi, const double dphi, const double r, const double lnSqrR1, const double lnSqrR2, const double area)
void PushBack(const sdet::Station &dStation, sevt::Station &eStation, const double phi, const double dphi, const double r, const double lnSqrR1, const double lnSqrR2, const double area)
static constexpr bool IsInInterval(const double x, const double a, const double b)

, generated on Tue Sep 26 2023.