Jpp test-rotations-old-57-g407471f53
the software that should make you happy
Loading...
Searching...
No Matches
JMuonFeatures.hh
Go to the documentation of this file.
1#ifndef __JRECONSTRUCTION__JMUONFEATURES__
2#define __JRECONSTRUCTION__JMUONFEATURES__
3
4#include <string>
5#include <iostream>
6#include <iomanip>
7#include <vector>
8#include <algorithm>
9
10#include <map>
11
15
16#include "JTrigger/JHitL0.hh"
17#include "JTrigger/JBuildL0.hh"
18
19#include "JFit/JFitToolkit.hh"
20#include "JFit/JLine1Z.hh"
21#include "JFit/JLine3Z.hh"
22#include "JFit/JModel.hh"
23#include "JFit/JGandalf.hh"
25
30
31#include "JPhysics/JPDFTable.hh"
33#include "JPhysics/JGeane.hh"
34
36
38
40
42
43#include "JTools/JRange.hh"
44
45#include "Jeep/JMessage.hh"
46
47#include "JLang/JVectorize.hh"
48
49
50/**
51 * \author eleguirriec, mdejong
52 */
53
54namespace JRECONSTRUCTION {}
55namespace JPP { using namespace JRECONSTRUCTION; }
56
57namespace JRECONSTRUCTION {
58
62 using JFIT::JRegressor;
63 using JFIT::JLine3Z;
64 using JFIT::JGandalf;
65 using JFIT::JTimeRange;
67
68
69 /**
70 * Wrapper class to add features after the final fit of muon trajectory.
71 *
72 * The JMuonGandalf fit uses one or more start values (usually taken from the output of JMuonSimplex).\n
73 * All hits of which the PMT position lies within a set road width (JMuonGandalfParameters_t::roadWidth_m) and
74 * time is within a set window (JMuonGandalfParameters_t::TMin_ns, JMuonGandalfParameters_t::TMax_ns) around the Cherenkov hypothesis are taken.\n
75 * In case there are multiple hits from the same PMT is the specified window,
76 * the first hit is taken and the other hits are discarded.\n
77 * The PDF is accordingly evaluated, i.e.\ the normalised probability for a first hit at the given time of the hit is taken.
78 * The normalisation is consistently based on the specified time window.\n
79 * Note that this hit selection is unbiased with respect to the PDF of a single PMT.
80 */
83 public JRegressor<JLine3Z, JGandalf>
84 {
88
89 using JRegressor_t::operator();
90
91 /**
92 * Input data type.
93 */
94 struct input_type :
95 public JDAQEventHeader
96 {
97 /**
98 * Default constructor.
99 */
101 {}
102
103
104 /**
105 * Constructor.
106 *
107 * \param header header
108 * \param in start values
109 * \param coverage coverage
110 */
112 const JEvt& in,
113 const coverage_type& coverage) :
114 JDAQEventHeader(header),
115 in(in),
117 {}
118
123 };
124
125 /**
126 * Constructor
127 *
128 * \param parameters parameters
129 * \param storage storage
130 * \param debug debug
131 */
133 const storage_type& storage,
134 const int debug = 0) :
135 JMuonGandalfParameters_t(parameters),
136 JRegressor_t(storage)
137 {
138 using namespace JFIT;
139
140 if (this->getRmax() < roadWidth_m) {
141 roadWidth_m = this->getRmax();
142 }
143
144 JRegressor_t::debug = debug;
145 JRegressor_t::T_ns.setRange(TMin_ns, TMax_ns);
146 JRegressor_t::Vmax_npe = VMax_npe;
147 JRegressor_t::MAXIMUM_ITERATIONS = NMax;
148
149 this->parameters.resize(5);
150
151 this->parameters[0] = JLine3Z::pX();
152 this->parameters[1] = JLine3Z::pY();
153 this->parameters[2] = JLine3Z::pT();
154 this->parameters[3] = JLine3Z::pDX();
155 this->parameters[4] = JLine3Z::pDY();
156
157 }
158
159 /**
160 * Get input data.
161 *
162 * \param router module router
163 * \param summary summary data
164 * \param event event
165 * \param in start values
166 * \param coverage coverage
167 * \return input data
168 */
170 const JSummaryRouter& summary,
171 const JDAQEvent& event,
172 const JEvt& in,
173 const coverage_type& coverage) const
174 {
175 using namespace std;
176 using namespace JTRIGGER;
177
178 const JBuildL0<JHitL0> buildL0;
179
180 input_type input(event.getDAQEventHeader(), in, coverage);
181
182 vector<JHitL0> data;
183
184 buildL0(event, router, true, back_inserter(data));
185
186 for (const auto& hit : data) {
187 input.data.push_back(hit_type(hit, summary.getRate(hit.getPMTIdentifier(), this->R_Hz)));
188 input.mapString[hit.getModuleID()] = router.getModule(hit.getModuleID()).getString();
189 }
190
191 return input;
192 }
193
194
195 /**
196 * Fit function.
197 *
198 * \param input input data
199 * \return fit results
200 */
202 {
203 using namespace std;
204 using namespace JFIT;
205 using namespace JGEOMETRY3D;
206
207 JEvent event(JMUONFEATURES);
208
209 JEvt out;
210
211 const buffer_type& data = input.data;
212
213 // select start values
214
215 JEvt in = input.in;
216
218
219 if (!in.empty()) {
220 in.select(JHistory::is_event(in.begin()->getHistory()));
221 }
222
223 for (JEvt::const_iterator track = in.begin(); track != in.end(); ++track) {
224
225 const JRotation3D R (getDirection(*track));
226 const JLine1Z tz(getPosition (*track).rotate(R), track->getT());
227 JRange<double> Z_m;
228
229 if (track->hasW(JSTART_LENGTH_METRES) &&
230 track->getW(JSTART_LENGTH_METRES) > 0.0) {
231 Z_m = JZRange(ZMin_m, ZMax_m + track->getW(JSTART_LENGTH_METRES));
232 }
233
234 const JModel<JLine1Z> match(tz, roadWidth_m, JRegressor_t::T_ns, Z_m);
235
236 // hit selection based on start value
237
238 buffer_type buffer;
239
240 for (buffer_type::const_iterator i = data.begin(); i != data.end(); ++i) {
241
242 hit_type hit(*i);
243
244 hit.rotate(R);
245
246 if (match(hit)) {
247 buffer.push_back(hit);
248 }
249 }
250
251 // select first hit
252
253 std::map<int, int> mapString = input.mapString;
254
255 std::set<int> stringSet;
256 for (buffer_type::const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
257 auto it = mapString.find((*i).getModuleID());
258 stringSet.insert(it->second);
259 }
260
261 const int number_of_hits = JLANG::getCount(JLANG::make_array(buffer.begin(), buffer.end(), &JHitW0::getPMTIdentifier));
262 const int number_of_doms = JLANG::getCount(JLANG::make_array(buffer.begin(), buffer.end(), &JHitW0::getModuleIdentifier));
263 const int number_of_lines = stringSet.size();
264
265 const int NDF = number_of_hits - this->parameters.size();
266
267 if (NDF > 0) {
268
269 out.push_back(JFit(*track).add(JMUONFEATURES));
270
271 // set additional values
272
273 out.rbegin()->setW(JMUONFEATURES_NUMBER_OF_HITS , number_of_hits);
274 out.rbegin()->setW(JMUONFEATURES_NUMBER_OF_DOMS , number_of_doms);
275 out.rbegin()->setW(JMUONFEATURES_NUMBER_OF_LINES , number_of_lines);
276
277 }
278 }
279
280 // apply default sorter
281
282 sort(out.begin(), out.end(), qualitySorter);
283
284 copy(input.in.begin(), input.in.end(), back_inserter(out));
285
286 return out;
287 }
288
289 };
290}
291
292#endif
293
Coverage of dynamical detector calibration.
Auxiliary methods to evaluate Poisson probabilities and chi2.
Energy loss of muon.
Basic data structure for L0 hit.
Data regression method for JFIT::JLine3Z.
General purpose messaging.
int debug
debug level
Definition JSirene.cc:72
Direct access to module in detector data structure.
Auxiliary methods for PDF calculations.
Auxiliary class to define a range between two values.
Auxiliary methods to convert data members or return values of member methods of a set of objects to a...
int getString() const
Get string number.
Definition JLocation.hh:135
Router for direct addressing of module data in detector data structure.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for set of track fit results.
void select(const JSelector_t &selector)
Select fits.
JFit & add(const int type)
Add event to history.
Fit method based on the Levenberg-Marquardt method.
Definition JGandalf.hh:87
Data structure for fit of straight line paralel to z-axis.
Definition JLine1Z.hh:29
static parameter_type pY()
Definition JLine1Z.hh:181
static parameter_type pX()
Definition JLine1Z.hh:180
static parameter_type pT()
Definition JLine1Z.hh:182
Data structure for fit of straight line in positive z-direction.
Definition JLine3Z.hh:40
static parameter_type pDY()
Definition JLine3Z.hh:320
static parameter_type pDX()
Definition JLine3Z.hh:319
JAxis3D & rotate(const JRotation3D &R)
Rotate axis.
Definition JAxis3D.hh:225
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Auxiliary class for a hit with background rate value.
Definition JHitW0.hh:23
Router for fast addressing of summary data in KM3NETDAQ::JDAQSummaryslice data structure as a functio...
double getRate(const JDAQPMTIdentifier &id) const
Get rate.
Template L0 hit builder.
Definition JBuildL0.hh:38
const JDAQEventHeader & getDAQEventHeader() const
Get DAQ event header.
const JDAQModuleIdentifier & getModuleIdentifier() const
Get Module identifier.
const JDAQPMTIdentifier & getPMTIdentifier() const
Get PMT identifier.
static const int JMUONFEATURES
static const int JMUONFEATURES_NUMBER_OF_LINES
number of lines from JMuonFeatures.cc
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 JMUONFEATURES_NUMBER_OF_HITS
number of hits from JMuonFeatures.cc
static const int JMUONFEATURES_NUMBER_OF_DOMS
number of doms from JMuonFeatures.cc
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163
Auxiliary classes and methods for linear and iterative data regression.
Definition JEnergy.hh:15
JTOOLS::JRange< double > JZRange
Auxiliary classes and methods for 3D geometrical objects and operations.
Definition JAngle3D.hh:19
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition JVectorize.hh:54
size_t getCount(const array_type< T > &buffer, const JCompare_t &compare)
Count number of unique values.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Model fits to data.
JPosition3D getPosition(const JFit &fit)
Get position.
bool qualitySorter(const JFit &first, const JFit &second)
Comparison of fit results.
JDirection3D getDirection(const JFit &fit)
Get direction.
Auxiliary classes and methods for triggering.
Model for fit to acoustics data.
Data structure for coverage of detector by dynamical calibrations.
Definition JCoverage.hh:19
Auxiliary class for historical event.
Definition JHistory.hh:36
Auxiliary class to test history.
Definition JHistory.hh:136
Template definition of a data regressor of given model.
Definition JRegressor.hh:70
input_type(const JDAQEventHeader &header, const JEvt &in, const coverage_type &coverage)
Constructor.
Wrapper class to add features after the final fit of muon trajectory.
JMuonFeatures(const JMuonGandalfParameters_t &parameters, const storage_type &storage, const int debug=0)
Constructor.
JEvt operator()(const input_type &input)
Fit function.
JRegressor< JLine3Z, JGandalf > JRegressor_t
std::vector< hit_type > buffer_type
input_type getInput(const JModuleRouter &router, const JSummaryRouter &summary, const JDAQEvent &event, const JEvt &in, const coverage_type &coverage) const
Get input data.
double TMin_ns
minimal time w.r.t. Cherenkov hypothesis [ns]
double TMax_ns
maximal time w.r.t. Cherenkov hypothesis [ns]
double VMax_npe
maximum number of of photo-electrons