Jpp  17.3.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
18 #include "JDetector/JDetector.hh"
21 
22 #include "JTrigger/JHitL0.hh"
23 #include "JTrigger/JHitR1.hh"
24 #include "JTrigger/JBuildL0.hh"
25 
27 
28 #include "JFit/JLine1Z.hh"
29 #include "JFit/JEnergyRegressor.hh"
30 #include "JFit/JFitToolkit.hh"
31 #include "JFit/JModel.hh"
32 #include "JFit/JNPEHit.hh"
33 #include "JFit/JEnergy.hh"
34 #include "JFit/JMEstimator.hh"
35 
36 #include "JReconstruction/JEvt.hh"
40 
41 #include "JPhysics/JConstants.hh"
42 #include "JPhysics/JK40Rates.hh"
43 
44 #include "JLang/JComparator.hh"
45 #include "JLang/JPredicate.hh"
46 
47 
48 /**
49  * \author mdejong, azegarelli, scelli
50  */
51 namespace JRECONSTRUCTION {}
52 namespace JPP { using namespace JRECONSTRUCTION; }
53 
54 namespace JRECONSTRUCTION {
55 
57  using JDETECTOR::JModule;
59  using JFIT::JRegressor;
60  using JFIT::JEnergy;
61  using JPHYSICS::JK40Rates;
62  using JPHYSICS::JRateL1_t;
64 
65  /**
66  * Get probability of given response in optical module due to random background.
67  *
68  * \param module module
69  * \param frame summary frame
70  * \param R_Hz multiples rates [Hz]
71  * \param T_ns time window [ns]
72  * \param top list of indentifiers of PMTs with hit in given module
73  * \return probability
74  */
75  inline double getProbability(const JModule& module,
76  const JDAQSummaryFrame& frame,
77  const JRateL1_t& R_Hz,
78  const double T_ns,
79  const std::multiset<int>& top)
80  {
81  using namespace std;
82  using namespace JPP;
83  using namespace KM3NETDAQ;
84 
85  size_t N = 0; // number of active PMTs
86  size_t M = 0; // multiplicity
87  double R = 0.0; // total rate
88 
89  for (size_t i = 0; i != module.size(); ++i) {
90 
91  if (getDAQStatus(frame, module, i) &&
92  getPMTStatus(frame, module, i) &&
93  !module.getPMT(i).has(PMT_DISABLE)) {
94 
95  N += 1;
96  M += top.count(i);
97  R += frame.getRate(i);
98  }
99  }
100 
101  if (N > 0)
102  return JFIT::getProbability(N, M, JK40Rates(R/N, R_Hz), T_ns);
103  else
104  return (M == 0 ? 1.0 : 0.0);
105  }
106 
107 
108  /**
109  * Auxiliary class to determine start and end position of muon trajectory.
110  */
111  class JMuonStart :
112  public JMuonStartParameters_t,
113  public JRegressor<JEnergy>
114  {
115  public:
119 
120  using JRegressor_t::operator();
121 
122  /**
123  * Constructor.
124  *
125  * \param parameters parameters
126  * \param router module router
127  * \param summary summary router
128  * \param pdfFile PDF file
129  * \param rates_Hz K40 rates [Hz]
130  * \param debug debug
131  */
133  const JModuleRouter& router,
134  const JSummaryRouter& summary,
135  const std::string& pdfFile,
136  const JK40Rates& rates_Hz,
137  const int debug = 0):
138  JMuonStartParameters_t(parameters),
139  JRegressor_t(pdfFile),
140  router(router),
141  summary(summary),
142  rates_Hz(rates_Hz),
143  debug(debug)
144  {
146  JRegressor_t::T_ns.setRange(parameters.TMin_ns, parameters.TMax_ns);
147 
148  if (this->getRmax() < parameters.roadWidth_m) {
149  roadWidth_m = this->getRmax();
150  }
151  }
152 
153 
154  /**
155  * Fit function.
156  *
157  * \param event event
158  * \param in start values
159  * \return fit results
160  */
162  {
163  using namespace std;
164  using namespace JPP;
165 
166  const JBuildL0<hit_type> buildL0;
167 
168  buffer_type dataL0;
169 
170  buildL0(event, router, true, back_inserter(dataL0));
171 
172  return (*this)(dataL0, in);
173  }
174 
175 
176  /**
177  * Fit function.
178  *
179  * \param data dataL0
180  * \param in start values
181  * \return fit results
182  */
183  JEvt operator()(const buffer_type& data, const JEvt& in)
184  {
185  using namespace std;
186  using namespace JPP;
187 
188  JEvt out;
189 
190  const JDetector& detector = router.getReference();
191 
192  const JStart start(Pmin1, Pmin2, Nmax2);
193 
194  for (JEvt::const_iterator track = in.begin(); track != in.end(); ++track) {
195 
196  const JRotation3D R (getDirection(*track));
197  const JLine1Z tz(getPosition (*track).rotate(R), track->getT());
198  const JFIT::JModel<JLine1Z> match(tz, roadWidth_m, JRegressor_t::T_ns);
199 
201 
202  for (buffer_type::const_iterator i = data.begin(); i != data.end(); ++i) {
203 
204  hit_type hit(*i);
205 
206  hit.rotate(R);
207 
208  if (match(hit)) {
209  top[hit.getModuleID()].insert(hit.getPMTAddress());
210  }
211  }
212 
213  struct JHit_t {
214 
215  double getZ() const { return z; }
216  double getP() const { return p; }
217 
218  double z;
219  double p;
220  };
221 
222  vector<JHit_t> data;
223 
224  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
225 
226  if (summary.hasSummaryFrame(module->getID())) {
227 
228  const JDAQSummaryFrame& frame = summary.getSummaryFrame(module->getID());
229 
230  JPosition3D pos(module->getPosition());
231 
232  pos.transform(R, tz.getPosition());
233 
234  if (pos.getX() <= roadWidth_m) {
235 
236  const double z = pos.getZ() - pos.getX() / getTanThetaC();
237 
238  const double p = getProbability(*module, frame, rates_Hz.getMultiplesRates(), JRegressor_t::T_ns.getLength(), top[module->getID()]);
239 
240  data.push_back({ z, p });
241  }
242  }
243  }
244 
245  double Zmin = 0.0; // relative start position [m]
246  double Zmax = 0.0; // relative end position [m]
247  double npe_total = 0.0; // npe due to mip
248  double npe_missed = 0.0; // npe due to mip not detected
249 
250  if (!data.empty()) {
251 
252  sort(data.begin(), data.end(), JLANG::make_comparator(&JHit_t::getZ));
253 
254  vector<JHit_t>::const_iterator track_start = start.find(data. begin(), data. end());
255  vector<JHit_t>::const_reverse_iterator track_end = start.find(data.rbegin(), data.rend());
256 
257  if (track_start != data. end()) { Zmin = track_start->getZ(); }
258  if (track_end != data.rend()) { Zmax = track_end ->getZ(); }
259 
260  // additional features
261 
262  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
263 
264  JPosition3D pos(module->getPosition());
265 
266  pos.transform(R, tz.getPosition());
267 
268  if (pos.getX() <= roadWidth_m) {
269 
270  const double z = pos.getZ() - pos.getX() / getTanThetaC();
271 
272  if (z >= Zmin && z <= Zmax) {
273 
274  for (size_t i = 0; i != module->size(); ++i) {
275 
276  const JDAQSummaryFrame& frame = summary.getSummaryFrame(module->getID());
277 
278  if (getDAQStatus(frame, *module, i) &&
279  getPMTStatus(frame, *module, i) &&
280  !module->getPMT(i).has(PMT_DISABLE)) {
281 
282  JPMT pmt = module->getPMT(i);
283 
284  pmt.transform(R, tz.getPosition());
285 
286  const double ya = this->getNPE(pmt, 0.0).getYA();
287 
288  npe_total += ya;
289 
290  if (top[module->getID()].count(i) == 0) {
291  npe_missed += ya;
292  }
293  }
294  }
295  }
296  }
297  }
298  }
299 
300  JFit fit = *track;
301 
302  // move track
303 
304  fit.move(Zmin, getSpeedOfLight());
305 
306  out.push_back(fit.add(JMUONSTART));
307 
308  out.rbegin()->setW(track->getW());
309  out.rbegin()->setW(JSTART_NPE_MIP_TOTAL, npe_total);
310  out.rbegin()->setW(JSTART_NPE_MIP_MISSED, npe_missed);
311  out.rbegin()->setW(JSTART_LENGTH_METRES, Zmax - Zmin);
312  }
313 
314  return out;
315  }
316 
317  private:
321  int debug;
322  };
323 }
324 
325 #endif
Auxiliary methods to evaluate Poisson probabilities and chi2.
static const int JMUONSTART
JRegressor< JEnergy > JRegressor_t
Definition: JMuonStart.hh:116
Template definition of a data regressor of given model.
Definition: JRegressor.hh:68
static const int JSTART_NPE_MIP_TOTAL
number of photo-electrons along the whole track from JStart.cc
int getModuleID() const
Get module identifier.
double getRate(const int tdc, const double factor=1.0) const
Get count rate.
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
Data structure for a composite optical module.
Definition: JModule.hh:68
Auxiliary method to locate start and end point of muon trajectory.
Regressor function object for fit of muon energy.
Detector data structure.
Definition: JDetector.hh:89
Router for direct addressing of module data in detector data structure.
Rotation matrix.
Definition: JRotation3D.hh:111
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Template specialisation of class JModel to match hit with muon trajectory along z-axis.
Definition: JFit/JModel.hh:34
T find(T __begin, T __end) const
Get start point of muon trajectory.
Definition: JStart.hh:77
JFit & add(const int type)
Add event to history.
Data structure for detector geometry and calibration.
void transform(const JRotation3D &R, const JVector3D &pos)
Transform position.
Definition: JPosition3D.hh:331
void transform(const JAxis3D &axis)
Transform axis to reference frame of given axis.
Definition: JAxis3D.hh:359
int getPMTAddress() const
Get PMT identifier.
Basic data structure for L0 hit.
Data structure for track fit results with history and optional associated values. ...
Auxiliary class to extract a subset of optical modules from a detector.
const JK40Rates rates_Hz
Definition: JMuonStart.hh:320
Data structure for fit parameters.
double TMax_ns
maximal time w.r.t. Cherenkov hypothesis [ns]
Auxiliary class to determine start and end position of muon trajectory.
Definition: JMuonStart.hh:111
JAxis3D & rotate(const JRotation3D &R)
Rotate axis.
Definition: JAxis3D.hh:225
Detector file.
Definition: JHead.hh:226
JDirection3D getDirection(const Vec &dir)
Get direction.
JMuonStart(const JMuonStartParameters_t &parameters, const JModuleRouter &router, const JSummaryRouter &summary, const std::string &pdfFile, const JK40Rates &rates_Hz, const int debug=0)
Constructor.
Definition: JMuonStart.hh:132
static const int JSTART_NPE_MIP_MISSED
number of photo-electrons missed from JStart.cc
bool has(const int bit) const
Test PMT status.
Definition: JStatus.hh:120
Auxiliary class for start or end point evaluation.
Definition: JStart.hh:21
Data storage class for rate measurements of all PMTs in one module.
Data structure for PMT geometry, calibration and status.
Definition: JPMT.hh:43
static const int PMT_DISABLE
KM3NeT Data Definitions v3.0.0-3-gef79250 https://git.km3net.de/common/km3net-dataformat.
Definition: pmt_status.hh:12
JPosition3D getPosition(const Vec &pos)
Get position.
then awk string
Physics constants.
Router for fast addressing of summary data in KM3NETDAQ::JDAQSummaryslice data structure as a functio...
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:173
JEvt operator()(const KM3NETDAQ::JDAQEvent &event, const JEvt &in)
Fit function.
Definition: JMuonStart.hh:161
double getP(const double expval, bool hit)
Get Poisson probability to observe a hit or not for given expectation value for the number of hits...
Definition: JFitToolkit.hh:41
Direct access to module in detector data structure.
const JModuleRouter & router
Definition: JMuonStart.hh:318
Reduced data structure for L1 hit.
then JCookie sh JDataQuality D $DETECTOR_ID R
Definition: JDataQuality.sh:41
bool getPMTStatus(const JStatus &status)
Test status of PMT.
JTRIGGER::JHitL0 hit_type
Definition: JMuonStart.hh:117
const double getSpeedOfLight()
Get speed of light.
static const int JSTART_LENGTH_METRES
distance between first and last hits in metres from JStart.cc
Data structure for set of track fit results.
Data structure for L0 hit.
Definition: JHitL0.hh:27
Auxiliary class to set-up Hit.
Definition: JSirene.hh:57
double getProbability(const size_t N, const size_t M, const JK40Rates &R_Hz, const double T_ns)
Get probability due to random background.
Definition: JFitToolkit.hh:248
Data structure for fit of straight line paralel to z-axis.
Definition: JLine1Z.hh:27
const JSummaryRouter & summary
Definition: JMuonStart.hh:319
Data structure for fit of energy.
Definition: JEnergy.hh:28
double getTanThetaC()
Get average tangent of Cherenkov angle of water corresponding to group velocity.
double getNPE(const Hit &hit)
Get true charge of hit.
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
double TMin_ns
minimal time w.r.t. Cherenkov hypothesis [ns]
Data regression method for JFIT::JEnergy.
void move(const double step, const double velocity)
Move vertex along this track with given velocity.
Template L0 hit builder.
Definition: JBuildL0.hh:35
bool getDAQStatus(const JDAQFrameStatus &frame, const JStatus &status)
Test status of DAQ.
JEvt operator()(const buffer_type &data, const JEvt &in)
Fit function.
Definition: JMuonStart.hh:183
std::vector< double > JRateL1_t
Type definition of count rate as a function of multiplicty [Hz] The multiples rate start counting at ...
Definition: JK40Rates.hh:27
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Definition: JPosition3D.hh:186
std::vector< hit_type > buffer_type
Definition: JMuonStart.hh:118
Maximum likelihood estimator (M-estimators).
int debug
debug level
Auxiliary class for K40 rates.
Definition: JK40Rates.hh:41