Jpp  19.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
13 
14 #include "JTrigger/JHitL0.hh"
15 #include "JTrigger/JBuildL0.hh"
16 
17 #include "JFit/JFitToolkit.hh"
18 #include "JFit/JLine1Z.hh"
19 #include "JFit/JLine3Z.hh"
20 #include "JFit/JModel.hh"
21 #include "JFit/JGandalf.hh"
22 #include "JFit/JLine3ZRegressor.hh"
23 
25 #include "JReconstruction/JEvt.hh"
28 
29 #include "JPhysics/JPDFTable.hh"
30 #include "JPhysics/JPDFToolkit.hh"
31 #include "JPhysics/JGeane.hh"
32 
34 
36 
38 
39 #include "JTools/JRange.hh"
40 
41 #include "Jeep/JMessage.hh"
42 
43 #include "JLang/JVectorize.hh"
44 
45 
46 /**
47  * \author mdejong, gmaggi
48  */
49 
50 namespace JRECONSTRUCTION {}
51 namespace JPP { using namespace JRECONSTRUCTION; }
52 
53 namespace JRECONSTRUCTION {
54 
57  using JFIT::JRegressor;
58  using JFIT::JLine3Z;
59  using JFIT::JGandalf;
60 
61 
62  /**
63  * Wrapper class to add features after the final fit of muon trajectory.
64  *
65  * The JMuonGandalf fit uses one or more start values (usually taken from the output of JMuonSimplex).\n
66  * All hits of which the PMT position lies within a set road width (JMuonGandalfParameters_t::roadWidth_m) and
67  * time is within a set window (JMuonGandalfParameters_t::TMin_ns, JMuonGandalfParameters_t::TMax_ns) around the Cherenkov hypothesis are taken.\n
68  * In case there are multiple hits from the same PMT is the specified window,
69  * the first hit is taken and the other hits are discarded.\n
70  * The PDF is accordingly evaluated, i.e.\ the normalised probability for a first hit at the given time of the hit is taken.
71  * The normalisation is consistently based on the specified time window.\n
72  * Note that this hit selection is unbiased with respect to the PDF of a single PMT.
73  */
74  struct JMuonFeatures :
76  public JRegressor<JLine3Z, JGandalf>
77  {
81 
82  using JRegressor_t::operator();
83 
84  /**
85  * Constructor
86  *
87  * \param parameters parameters
88  * \param router module router
89  * \param summary summary file router
90  * \param pdf_file PDF file
91  * \param debug debug
92  */
94  const JModuleRouter& router,
95  const JSummaryRouter& summary,
96  const std::string& pdf_file,
97  const int debug = 0) :
98  JMuonGandalfParameters_t(parameters),
99  JRegressor_t(pdf_file, parameters.TTS_ns),
100  router (router),
101  summary(summary)
102  {
103  using namespace JFIT;
104 
105  if (this->getRmax() < roadWidth_m) {
106  roadWidth_m = this->getRmax();
107  }
108 
113 
114  this->parameters.resize(5);
115 
116  this->parameters[0] = JLine3Z::pX();
117  this->parameters[1] = JLine3Z::pY();
118  this->parameters[2] = JLine3Z::pT();
119  this->parameters[3] = JLine3Z::pDX();
120  this->parameters[4] = JLine3Z::pDY();
121  }
122 
123 
124  /**
125  * Fit function.
126  *
127  * \param event event
128  * \param in start values
129  * \return fit results
130  */
132  {
133  using namespace std;
134  using namespace JFIT;
135  using namespace JTRIGGER;
136 
137  const JBuildL0<hit_type> buildL0;
138 
139  buffer_type dataL0;
140 
141  buildL0(event, router, true, back_inserter(dataL0));
142 
143  return (*this)(dataL0, in);
144  }
145 
146 
147  /**
148  * Fit function.
149  *
150  * \param data hit data
151  * \param in start values
152  * \return fit results
153  */
155  {
156  using namespace std;
157  using namespace JFIT;
158  using namespace JGEOMETRY3D;
159 
160  JEvt out;
161 
162  for (JEvt::const_iterator track = in.begin(); track != in.end(); ++track) {
163 
164  const JRotation3D R (getDirection(*track));
165  const JLine1Z tz(getPosition (*track).rotate(R), track->getT());
166  JRange<double> Z_m;
167 
168  if (track->hasW(JSTART_LENGTH_METRES) &&
169  track->getW(JSTART_LENGTH_METRES) > 0.0) {
170  Z_m = JZRange(ZMin_m, ZMax_m + track->getW(JSTART_LENGTH_METRES));
171  }
172 
173  const JModel<JLine1Z> match(tz, roadWidth_m, JRegressor_t::T_ns, Z_m);
174 
175  // hit selection based on start value
176 
177  vector<JHitW0> buffer;
178 
179  for (buffer_type::const_iterator i = data.begin(); i != data.end(); ++i) {
180 
181  JHitW0 hit(*i, summary.getRate(i->getPMTIdentifier()));
182 
183  hit.rotate(R);
184 
185  if (match(hit)) {
186  buffer.push_back(hit);
187  }
188  }
189 
190  // select first hit
191 
192  std::set<int> string_ids;
193  for (vector<JHitW0>::const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
194  string_ids.insert(router.getModule(((*i).getModuleID())).getString());
195  }
196 
197  const int number_of_hits = JLANG::getCount(JLANG::make_array(buffer.begin(), buffer.end(), &JHitW0::getPMTIdentifier));
198  const int number_of_doms = JLANG::getCount(JLANG::make_array(buffer.begin(), buffer.end(), &JHitW0::getModuleIdentifier));
199  const int number_of_lines = string_ids.size();
200 
201  const int NDF = number_of_hits - this->parameters.size();
202 
203  if (NDF > 0) {
204 
205  out.push_back(JFit(*track).add(JMUONFEATURES));
206 
207  // set additional values
208 
209  out.rbegin()->setW(JMUONFEATURES_NUMBER_OF_HITS , number_of_hits);
210  out.rbegin()->setW(JMUONFEATURES_NUMBER_OF_DOMS , number_of_doms);
211  out.rbegin()->setW(JMUONFEATURES_NUMBER_OF_LINES , number_of_lines);
212 
213  }
214  }
215 
216  return out;
217  }
218 
219 
222  int debug;
223  };
224 }
225 
226 #endif
227 
Auxiliary methods to evaluate Poisson probabilities and chi2.
static int debug
debug level (default is off).
Definition: JMessage.hh:45
Data regression method for JFIT::JLine3Z.
Template definition of a data regressor of given model.
Definition: JRegressor.hh:70
static const int JMUONFEATURES_NUMBER_OF_LINES
number of lines from JMuonFeatures.cc
Wrapper class to add features after the final fit of muon trajectory.
double TTS_ns
transition-time spread [ns]
const JModuleRouter & router
Auxiliary methods for PDF calculations.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
double TMin_ns
minimal time w.r.t. Cherenkov hypothesis [ns]
std::vector< hit_type > buffer_type
const JDAQPMTIdentifier & getPMTIdentifier() const
Get PMT identifier.
Energy loss of muon.
size_t getCount(const array_type< T > &buffer, const JCompare_t &compare)
Count number of unique values.
Definition: JVectorize.hh:261
Router for direct addressing of module data in detector data structure.
Rotation matrix.
Definition: JRotation3D.hh:111
double getRate() const
Get default rate.
*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
Data structure for fit of straight line in positive z-direction.
Definition: JLine3Z.hh:36
static parameter_type pT()
Definition: JLine1Z.hh:182
double VMax_npe
maximum number of of photo-electrons
JFit & add(const int type)
Add event to history.
JRegressor< JLine3Z, JGandalf > JRegressor_t
static JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].
Basic data structure for L0 hit.
JEvt operator()(const KM3NETDAQ::JDAQEvent &event, const JEvt &in)
Fit function.
static parameter_type pDX()
Definition: JLine3Z.hh:319
JAxis3D & rotate(const JRotation3D &R)
Rotate axis.
Definition: JAxis3D.hh:225
JDirection3D getDirection(const Vec &dir)
Get direction.
static const int JMUONFEATURES_NUMBER_OF_HITS
number of hits from JMuonFeatures.cc
double TMax_ns
maximal time w.r.t. Cherenkov hypothesis [ns]
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition: JVectorize.hh:54
JPosition3D getPosition(const Vec &pos)
Get position.
JMuonFeatures(const JMuonGandalfParameters_t &parameters, const JModuleRouter &router, const JSummaryRouter &summary, const std::string &pdf_file, const int debug=0)
Constructor.
Router for fast addressing of summary data in KM3NETDAQ::JDAQSummaryslice data structure as a functio...
static parameter_type pY()
Definition: JLine1Z.hh:181
Auxiliary methods to convert data members or return values of member methods of a set of objects to a...
static const int JMUONFEATURES
General purpose messaging.
static parameter_type pDY()
Definition: JLine3Z.hh:320
Direct access to module in detector data structure.
Fit method based on the Levenberg-Marquardt method.
Definition: JGandalf.hh:84
JEvt operator()(const buffer_type &data, const JEvt &in)
Fit function.
static parameter_type pX()
Definition: JLine1Z.hh:180
then JCookie sh JDataQuality D $DETECTOR_ID R
Definition: JDataQuality.sh:41
Auxiliary class for a hit with background rate value.
Definition: JHitW0.hh:21
int getString() const
Get string number.
Definition: JLocation.hh:134
static const int JMUONFEATURES_NUMBER_OF_DOMS
number of doms from JMuonFeatures.cc
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.
Regressor function object for JLine3Z fit using JGandalf minimiser.
Auxiliary class to define a range between two values.
then fatal The output file must have the wildcard in the e g root fi 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:48
static double Vmax_npe
Maximal integral of PDF [npe].
Data structure for L0 hit.
Definition: JHitL0.hh:27
Data structure for fit of straight line paralel to z-axis.
Definition: JLine1Z.hh:27
static int MAXIMUM_ITERATIONS
maximal number of iterations
Definition: JGandalf.hh:335
const JDAQModuleIdentifier & getModuleIdentifier() const
Get Module identifier.
Template L0 hit builder.
Definition: JBuildL0.hh:35
const JSummaryRouter & summary
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Definition: JPosition3D.hh:186
JTOOLS::JRange< double > JZRange
Definition: JFit/JModel.hh:21