Jpp 21.0.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JMuonStart.hh
Go to the documentation of this file.
1#ifndef __JRECONSTRUCTION__JMUONSTART__
2#define __JRECONSTRUCTION__JMUONSTART__
3
4#include <string>
5#include <istream>
6#include <ostream>
7#include <iomanip>
8#include <vector>
9#include <set>
10#include <map>
11#include <algorithm>
12#include <cmath>
13
17
21
23
24#include "JTrigger/JHitL0.hh"
25#include "JTrigger/JHitR1.hh"
26#include "JTrigger/JBuildL0.hh"
27
29
30#include "JFit/JLine1Z.hh"
32#include "JFit/JFitToolkit.hh"
33#include "JFit/JModel.hh"
34#include "JFit/JNPEHit.hh"
35
41
43#include "JPhysics/JK40Rates.hh"
44
45#include "JLang/JComparator.hh"
46#include "JLang/JPredicate.hh"
47
48
49/**
50 * \author mdejong, azegarelli, scelli
51 */
52namespace JRECONSTRUCTION {}
53namespace JPP { using namespace JRECONSTRUCTION; }
54
55namespace JRECONSTRUCTION {
56
62 using JFIT::JRegressor;
63 using JFIT::JEnergy;
66
67
68 /**
69 * Auxiliary class to determine start and end position of muon trajectory.
70 */
71 class JMuonStart :
73 public JRegressor<JEnergy>
74 {
75 public:
79
80 using JRegressor_t::operator();
81
82 /**
83 * Input data type.
84 */
85 struct input_type :
86 public JDAQEventHeader
87 {
88 /**
89 * Default constructor.
90 */
94
95
96 /**
97 * Constructor.
98 *
99 * \param header header
100 * \param in start values
101 * \param coverage coverage
102 */
104 const JEvt& in,
105 const coverage_type& coverage) :
106 JDAQEventHeader(header),
107 in(in),
109 {}
110
114 };
115
116
117 /**
118 * Constructor.
119 *
120 * \param parameters parameters
121 * \param storage storage
122 * \param rates_Hz K40 rates [Hz]
123 * \param debug debug
124 */
126 const storage_type& storage,
127 const JK40Rates& rates_Hz,
128 const int debug = 0):
129 JMuonStartParameters_t(parameters),
130 JRegressor_t(storage),
132 {
133 if (this->getRmax() < parameters.roadWidth_m) {
134 roadWidth_m = this->getRmax();
135 }
136
137 JRegressor_t::debug = debug;
138 }
139
140
141 /**
142 * Get input data.
143 *
144 * \param router module router
145 * \param summary summary data
146 * \param event event
147 * \param in start values
148 * \param coverage coverage
149 * \return input data
150 */
152 const JSummaryRouter& summary,
153 const JDAQEvent& event,
154 const JEvt& in,
155 const coverage_type& coverage) const
156 {
157 using namespace std;
158 using namespace JTRIGGER;
159
160 input_type input(event.getDAQEventHeader(), in, coverage);
161
162 const JBuildL0 <JHitR0> buildL0;
164
165 const JDAQTimeslice timeslice(event, true);
166
167 JSuperFrame2D<JHit> buffer;
168
169 for (JDAQTimeslice::const_iterator i = timeslice.begin(); i != timeslice.end(); ++i) {
170
171 if (router.hasModule(i->getModuleID())) {
172
173 buffer(*i, router.getModule(i->getModuleID()));
174
175 buildL0(buffer, back_inserter(data[i->getModuleID()]));
176 }
177 }
178
179 for (const auto& module : router.getReference()) {
180 if (!module.empty()) {
181 input.data.push_back(module_type(module, summary.getSummaryFrame(module.getID(), rates_Hz.getSinglesRate()), data[module.getID()]));
182 }
183 }
184
185 return input;
186 }
187
188
189 /**
190 * Fit function.
191 *
192 * \param input input data
193 * \return fit results
194 */
196 {
197 using namespace std;
198 using namespace JPP;
199
200 JEvent event(JMUONSTART);
201
202 JEvt out;
203
204 // select start values
205
206 JEvt in = input.in;
207
208 sort(in.begin(), in.end(), qualitySorter);
209
210 if (numberOfPrefits != 0 && numberOfPrefits < in.size()) {
211
212 JEvt::iterator __end = next(in.begin(), numberOfPrefits);
213
214 if (numberOfPostfits > 0) {
215
216 __end = gridify(__end, in.end(), numberOfPostfits);
217 }
218
219 in.erase(__end, in.end());
220 }
221
222 if (!in.empty()) {
223 in.select(JHistory::is_event(in.begin()->getHistory()));
224 }
225
226 const JStart start(Pmin1, Pmin2, Nmax2);
227
228 struct JHit_t {
229
230 double getZ() const { return z; }
231 double getP() const { return p; }
232
233 double z;
234 double p;
235 };
236
237 for (JEvt::const_iterator track = in.begin(); track != in.end(); ++track) {
238
239 const JRotation3D R (getDirection(*track));
240 const JLine1Z tz(getPosition (*track).rotate(R), track->getT());
241
242 vector<JHit_t> data;
243
244 for (const auto& module : input.data) {
245
246 JPosition3D pos(module->getPosition());
247
248 pos.transform(R, tz.getPosition());
249
250 if (pos.getX() <= roadWidth_m) {
251
252 const double z = pos.getZ() - pos.getX() / getTanThetaC();
253 const double t = tz .getT() + (pos.getZ() + pos.getX() * getKappaC()) * getInverseSpeedOfLight();
254
255 const double p = module.getProbability(rates_Hz.getMultiplesRates(), T_ns + t);
256
257 data.push_back({ z, p });
258 }
259 }
260
261 double Zmin = 0.0; // start position
262 double Zmax = 0.0; // end position
263
264 if (!data.empty()) {
265
266 sort(data.begin(), data.end(), make_comparator(&JHit_t::getZ));
267
268 vector<JHit_t>::const_iterator q1 = start.find(data. begin(), data. end());
269 vector<JHit_t>::const_reverse_iterator q2 = start.find(data.rbegin(), data.rend());
270
271 if (q1 != data.end() && q2 != data.rend()) {
272
273 vector<JHit_t>::const_iterator p1 = q1; if (p1 != data. begin()) { --p1; }
274 vector<JHit_t>::const_reverse_iterator p2 = q2; if (p2 != data.rbegin()) { --p2; }
275
276 Zmin = 0.5 * (p1->getZ() + q1->getZ());
277 Zmax = 0.5 * (p2->getZ() + q2->getZ());
278 }
279 }
280
281 JFit fit = *track;
282
283 fit.push_back(event());
284
285 out.push_back(fit);
286
287 // set additional values
288
289 out.rbegin()->setW(JSTART_ZMIN_M, Zmin);
290 out.rbegin()->setW(JSTART_ZMAX_M, Zmax);
291 out.rbegin()->setW(JSTART_LENGTH_METRES, Zmax - Zmin);
292 out.rbegin()->setW(JPP_COVERAGE_ORIENTATION, input.coverage.orientation);
293 out.rbegin()->setW(JPP_COVERAGE_POSITION, input.coverage.position);
294 }
295
296 // apply default sorter
297
298 sort(out.begin(), out.end(), qualitySorter);
299
300 copy(input.in.begin(), input.in.end(), back_inserter(out));
301
302 return out;
303 }
304
305
307 };
308}
309
310#endif
Coverage of dynamical detector calibration.
Auxiliary class to extract a subset of optical modules from a detector.
Data structure for detector geometry and calibration.
TPaveText * p1
Data regression method for JFIT::JEnergy.
Auxiliary methods to evaluate Poisson probabilities and chi2.
Basic data structure for L0 hit.
Reduced data structure for L1 hit.
int debug
debug level
Definition JSirene.cc:74
Direct access to module in detector data structure.
Physics constants.
Auxiliary method to locate start and end point of muon trajectory.
Router for direct addressing of module data in detector data structure.
bool hasModule(const JModuleIdentifier &id) const
Has module.
const JModule & getModule(const JModuleIdentifier &id) const
Get module parameters.
Data structure for a composite optical module.
Definition JModule.hh:76
Data structure for fit of energy.
Data structure for set of track fit results.
void select(const JSelector_t &selector)
Select fits.
Data structure for track fit results with history and optional associated values.
Data structure for fit of straight line paralel to z-axis.
Definition JLine1Z.hh:29
double getT(const JVector3D &pos) const
Get arrival time of Cherenkov light at given position.
Definition JLine1Z.hh:114
Data structure for position in three dimensions.
void transform(const JRotation3D &R, const JVector3D &pos)
Transform position.
JPosition3D & rotate(const JRotation3D &R)
Rotate.
const JPosition3D & getPosition() const
Get position.
double getZ() const
Get z position.
Definition JVector3D.hh:115
double getX() const
Get x position.
Definition JVector3D.hh:94
const JClass_t & getReference() const
Get reference to object.
Definition JReference.hh:38
Auxiliary class to determine start and end position of muon trajectory.
Definition JMuonStart.hh:74
input_type getInput(const JModuleRouter &router, const JSummaryRouter &summary, const JDAQEvent &event, const JEvt &in, const coverage_type &coverage) const
Get input data.
std::vector< module_type > detector_type
Definition JMuonStart.hh:78
JEvt operator()(const input_type &input)
Fit function.
JRegressor< JEnergy > JRegressor_t
Definition JMuonStart.hh:76
JMuonStart(const JMuonStartParameters_t &parameters, const storage_type &storage, const JK40Rates &rates_Hz, const int debug=0)
Constructor.
Router for fast addressing of summary data in KM3NETDAQ::JDAQSummaryslice data structure as a functio...
const JDAQSummaryFrame & getSummaryFrame(const JDAQModuleIdentifier &module) const
Get summary frame.
2-dimensional frame with time calibrated data from one optical module.
const JDAQEventHeader & getDAQEventHeader() const
Get DAQ event header.
Data storage class for rate measurements of all PMTs in one module.
static const int JSTART_ZMAX_M
end position of track see JRECONSTRUCTION::JMuonStart
static const int JPP_COVERAGE_POSITION
coverage of dynamic position calibration of this event
static const int JSTART_LENGTH_METRES
distance between projected positions on the track of optical modules for which the response does not ...
static const int JSTART_ZMIN_M
start position of track see JRECONSTRUCTION::JMuonStart
static const int JPP_COVERAGE_ORIENTATION
coverage of dynamic orientation calibration of this event
double getP(const double E1, const double E2, const double ED, const int M_min, const int M_max)
Get coincidence probability of two PMTs within one module due to random background.
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
double getKappaC()
Get average R-dependence of arrival time of Cherenkov light (a.k.a.
const double getInverseSpeedOfLight()
Get inverse speed of light.
double getTanThetaC()
Get average tangent of Cherenkov angle of water corresponding to group velocity.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JPosition3D getPosition(const JFit &fit)
Get position.
void copy(const JFIT::JEvt::const_iterator __begin, const JFIT::JEvt::const_iterator __end, Evt &out)
Copy tracks.
bool qualitySorter(const JFit &first, const JFit &second)
Comparison of fit results.
JDirection3D getDirection(const JFit &fit)
Get direction.
JEvt::iterator gridify(JEvt::iterator __begin, JEvt::iterator __end, const int N)
Gridify set of fits.
Auxiliary classes and methods for triggering.
Data structure for coverage of detector by dynamical calibrations.
Definition JCoverage.hh:19
double position
coverage of detector by available position calibration [0,1]
Definition JCoverage.hh:42
double orientation
coverage of detector by available orientation calibration [0,1]
Definition JCoverage.hh:41
Auxiliary class for historical event.
Definition JHistory.hh:40
Auxiliary class to test history.
Definition JHistory.hh:157
Template definition of a data regressor of given model.
Definition JRegressor.hh:70
Auxiliary class for K40 rates.
Definition JK40Rates.hh:41
double getSinglesRate() const
Get singles rate.
Definition JK40Rates.hh:71
Auxiliary class for handling module response.
Definition JModuleL0.hh:45
Data structure for fit parameters.
int Nmax2
maximal number for twofold observations
double Pmin1
minimal probability single observation
double Pmin2
minimal probability for twofold observations
input_type(const JDAQEventHeader &header, const JEvt &in, const coverage_type &coverage)
Constructor.
Auxiliary class for start or end point evaluation.
Definition JStart.hh:21
T find(T __begin, T __end) const
Get start point of muon trajectory.
Definition JStart.hh:77
Auxiliary class to set-up Hit.
Definition JSirene.hh:60