Jpp  18.3.0-209-g56ce19a
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JShowerEnergyPrefit.hh
Go to the documentation of this file.
1 #ifndef JSHOWERENERGYPREFIT_INCLUDE
2 #define JSHOWERENERGYPREFIT_INCLUDE
3 
4 #include <string>
5 #include <iostream>
6 #include <set>
7 #include <vector>
8 #include <algorithm>
9 #include <memory>
10 #include <math.h>
11 
14 
15 #include "JTrigger/JHit.hh"
16 #include "JTrigger/JTimeslice.hh"
17 #include "JTrigger/JHitL0.hh"
18 #include "JTrigger/JHitL1.hh"
19 #include "JTrigger/JHitR1.hh"
20 #include "JTrigger/JBuildL0.hh"
21 #include "JTrigger/JBuildL2.hh"
22 #include "JTrigger/JAlgorithm.hh"
23 #include "JTrigger/JMatch3G.hh"
24 #include "JTrigger/JBind2nd.hh"
25 
27 
29 #include "JFit/JFitToolkit.hh"
30 #include "JFit/JPoint4D.hh"
31 #include "JFit/JModel.hh"
32 #include "JFit/JSimplex.hh"
33 #include "JFit/JShowerNPEHit.hh"
34 #include "JFit/JShowerNPE.hh"
35 
36 #include "JAAnet/JAAnetToolkit.hh"
37 
39 #include "JReconstruction/JEvt.hh"
42 
43 #include "JDetector/JDetector.hh"
45 
46 #include "JGeometry3D/JVector3D.hh"
48 #include "JGeometry3D/JOmega3D.hh"
49 #include "JGeometry3D/JTrack3D.hh"
50 #include "JGeometry3D/JTrack3E.hh"
51 #include "JGeometry3D/JShower3E.hh"
52 
53 #include "JLang/JSharedPointer.hh"
54 
55 
56 /**
57  * \author adomi
58  */
59 namespace JRECONSTRUCTION {}
60 namespace JPP { using namespace JRECONSTRUCTION; }
61 
62 namespace JRECONSTRUCTION {
63 
66  using JFIT::JRegressor;
67  using JFIT::JEnergy;
68  using JFIT::JSimplex;
69 
70  /**
71  * class to handle the third step of the shower reconstruction, mainly dedicated for ORCA
72  */
75  public JRegressor<JEnergy, JSimplex>
76  {
77 
79  using JRegressor_t::operator();
80 
81  public:
82 
83  /**
84  * Parameterized constructor
85  *
86  * \param parameters struct that holds default-optimized parameters for the reconstruction, available in $JPP_DATA.
87  * \param router module router, this is built via detector file.
88  * \param summary summary router
89  * \param pdfFile PDF file
90  * \param debug debug
91  */
93  const JModuleRouter& router,
94  const JSummaryRouter& summary,
95  const std::string pdfFile,
96  const int debug = 0):
98  JRegressor_t(pdfFile),
99  router(router),
100  summary(summary)
101  {
102  using namespace JPP;
103 
105  JRegressor_t::T_ns.setRange(parameters.TMin_ns, parameters.TMax_ns);
108 
109  this->estimator.reset(getMEstimator(parameters.mestimator));
110  }
111 
112 
113  /**
114  * Auxiliary class for energy estimation.
115  */
116  struct JResult {
117  /**
118  * Constructor.
119  *
120  * \param x Energy [log(E/GeV)]
121  * \param chi2 chi2
122  */
123  JResult(const JEnergy& x = 0.0,
124  const double chi2 = std::numeric_limits<double>::max())
125  {
126  this->x = x;
127  this->chi2 = chi2;
128  }
129 
130  /**
131  * Type conversion.
132  *
133  * \return true if valid chi2; else false
134  */
135  operator bool() const
136  {
137  return chi2 != std::numeric_limits<double>::max();
138  }
139 
140  JEnergy x; //!< Energy
141  double chi2; //!< chi2
142  };
143 
144 
145  /**
146  * Declaration of the member function that actually performs the reconstruction
147  *
148  * \param event which is a JDAQEvent
149  * \param in input fits, which should contain a vertex fit
150  */
152  {
153  using namespace std;
154  using namespace JPP;
155 
156  typedef vector<JHitL0> JDataL0_t;
157  JBuildL0<JHitL0> buildL0;
158 
159  JEvt out;
160 
162 
163  JDataL0_t dataL0;
164  buildL0(JDAQTimeslice(event, true), router, back_inserter(dataL0));
165 
166  for (JEvt::const_iterator shower = in.begin(); shower != in.end(); ++shower) {
167 
168  JShower3E sh(getPosition(*shower), getDirection(*shower), shower->getT(), shower->getE());
169 
171 
173  vector<JShowerNPEHit> buffer;
174 
175  const JFIT::JModel<JPoint4D> match(JPoint4D(sh.getPosition(), sh.getT()), roadWidth_m, JRegressor_t::T_ns);
176 
177  for (JDataL0_t::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
178 
179  if (match(*i)) {
180  top.insert(i->getPMTIdentifier());
181  }
182  }
183 
184  JDetectorSubset_t subdetector(detector, sh.getPosition(), roadWidth_m);
185 
186  for (JDetector::const_iterator module = subdetector.begin(); module != subdetector.end(); ++module) {
187 
188  const JDAQSummaryFrame& frame = summary.getSummaryFrame(module->getID());
189 
190  for (size_t i = 0; i != module->size(); ++i) {
191 
192  if (getDAQStatus(frame, *module, i) &&
193  getPMTStatus(frame, *module, i) &&
194  frame[i].is_valid() &&
195  !module->getPMT(i).has(PMT_DISABLE)) {
196 
197  const JDAQPMTIdentifier id(module->getID(), i);
198 
199  const double rate_Hz = summary.getRate(id);
200  const size_t count = top.count(id);
201 
202  data.push_back(JShowerNPEHit(this->getNPE(module->getPMT(i), rate_Hz), count));
203  }
204  }
205  }
206 
207  const int NDF = data.size() - 1;
208 
209  if (NDF >= 0) {
210 
211  // 5-point search between given limits
212  const int N = 5;
213 
214  JResult result[N];
215 
216  for (int i = 0; i != N; ++i) {
217 
218  result[i].x = log10(Emin_GeV + i * (Emax_GeV - Emin_GeV) / (N-1));
219 
220  }
221 
222  do{
223 
224  int j = 0;
225 
226  for (int i = 0; i != N; ++i) {
227 
228  if (!result[i]) {
229 
230  result[i].chi2 = (*this)(result[i].x, data.begin(), data.end());
231 
232  }
233 
234  if (result[i].chi2 < result[j].chi2) {
235  j = i;
236  }
237  }
238 
239  // squeeze range
240 
241  switch (j) {
242 
243  case 0:
244  result[4] = result[1];
245  result[2] = JResult(0.5 * (result[0].x + result[4].x));
246  break;
247 
248  case 1:
249  result[4] = result[2];
250  result[2] = result[1];
251  break;
252 
253  case 2:
254  result[0] = result[1];
255  result[4] = result[3];
256  break;
257 
258  case 3:
259  result[0] = result[2];
260  result[2] = result[3];
261  break;
262 
263  case 4:
264  result[0] = result[3];
265  result[2] = JResult(0.5 * (result[0].x + result[4].x));
266  break;
267  }
268 
269  result[1] = JResult(0.5 * (result[0].x + result[2].x));
270  result[3] = JResult(0.5 * (result[2].x + result[4].x));
271 
272  } while (result[4].x - result[0].x > resolution);
273 
274 
275  if (result[1].chi2 != result[3].chi2) {
276 
277  result[2].x += 0.25 * (result[3].x - result[1].x) * (result[1].chi2 - result[3].chi2) / (result[1].chi2 + result[3].chi2 - 2*result[2].chi2);
278 
279  result[2].chi2 = (*this)(result[2].x, data.begin(), data.end());
280 
281  }
282 
283  // const double chi2 = result[2].chi2; // this is not used because fits are sorted wrt the position fit
284  const double E = result[2].x.getE();
285 
286  JShower3E sh_fit(sh.getPosition(), sh.getDirection(), sh.getT(), E);
287 
288  // the fits of this reco step are sorted wrt the previous reco step
289  // because otherwise it tends to degrade the position reco performances
290  out.push_back(getFit(JHistory(shower->getHistory()).add(JSHOWERENERGYPREFIT), sh_fit, shower->getQ(),
291  shower->getNDF(), sh_fit.getE()));
292 
293  }
294  }
295 
296  return out;
297 
298  }
299 
302  };
303 }
304 
305 #endif
306 
Auxiliary methods to evaluate Poisson probabilities and chi2.
static int debug
debug level (default is off).
Definition: JMessage.hh:45
Template definition of a data regressor of given model.
Definition: JRegressor.hh:70
double getE() const
Get energy.
Definition: JEnergy.hh:170
then usage $script< input file >[option[primary[working directory]]] nWhere option can be E
Definition: JMuonPostfit.sh:40
JRegressor< JEnergy, JSimplex > JRegressor_t
Algorithms for hit clustering and sorting.
Template specialisation of L0 builder for JHitL0 data type.
Definition: JBuildL0.hh:102
static double Vmax_npe
Maximal integral of PDF [npe].
JEvt operator()(const KM3NETDAQ::JDAQEvent &event, const JFIT::JEvt &in)
Declaration of the member function that actually performs the reconstruction.
Data structure for vertex fit.
Definition: JPoint4D.hh:22
Detector data structure.
Definition: JDetector.hh:89
Router for direct addressing of module data in detector data structure.
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
const JDAQSummaryFrame & getSummaryFrame() const
Get default summary frame.
Basic data structure for time and time over threshold information of hit.
static const int JSHOWERENERGYPREFIT
3D track with energy.
Definition: JTrack3E.hh:30
Data structure for detector geometry and calibration.
JResult(const JEnergy &x=0.0, const double chi2=std::numeric_limits< double >::max())
Constructor.
Basic data structure for L0 hit.
Auxiliary class to extract a subset of optical modules from a detector.
Auxiliary class for energy estimation.
Detector file.
Definition: JHead.hh:226
double TMin_ns
minimum time for local coincidences [ns]
class to handle the third step of the shower reconstruction, mainly dedicated for ORCA ...
JDirection3D getDirection(const Vec &dir)
Get direction.
set_variable E_E log10(E_{fit}/E_{#mu})"
Data storage class for rate measurements of all PMTs in one module.
static const int PMT_DISABLE
KM3NeT Data Definitions v3.3.0-2-g5cc95cf https://git.km3net.de/common/km3net-dataformat.
Definition: pmt_status.hh:12
double VMax_npe
maximum number of of photo-electrons
JPosition3D getPosition(const Vec &pos)
Get position.
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
then awk string
Data time slice.
JShowerEnergyPrefit(const JShowerEnergyPrefitParameters_t &parameters, const JModuleRouter &router, const JSummaryRouter &summary, const std::string pdfFile, const int debug=0)
Parameterized constructor.
static JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].
Router for fast addressing of summary data in KM3NETDAQ::JDAQSummaryslice data structure as a functio...
Detector subset without binary search functionality.
Reduced data structure for L1 hit.
bool getPMTStatus(const JStatus &status)
Test status of PMT.
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
JFIT::JHistory JHistory
Definition: JHistory.hh:354
const JClass_t & getReference() const
Get reference to object.
Definition: JReference.hh:38
Data regression method for JFIT::JShower3EZ only focused on the energy estimation from a bright point...
Data structure for set of track fit results.
double TMax_ns
maximum time for local coincidences [ns]
JFit getFit(const int id, const JMODEL::JString &string)
Get fit parameters of string.
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
Simple fit method based on Powell&#39;s algorithm, see reference: Numerical Recipes in C++...
then if[[!-f $DETECTOR]] then JDetector sh $DETECTOR fi cat $WORKDIR trigger_parameters txt<< EOFtrigger3DMuon.enabled=1;trigger3DMuon.numberOfHits=5;trigger3DMuon.gridAngle_deg=1;ctMin=0.0;TMaxLocal_ns=15.0;EOF set_variable TRIGGEREFFICIENCY_TRIGGERED_EVENTS_ONLY INPUT_FILES=() for((i=1;$i<=$NUMBER_OF_RUNS;++i));do JSirene.sh $DETECTOR $JPP_DATA/genhen.km3net_wpd_V2_0.evt.gz $WORKDIR/sirene_ ${i}.root JTriggerEfficiency.sh $DETECTOR $DETECTOR $WORKDIR/sirene_ ${i}.root $WORKDIR/trigger_efficiency_ ${i}.root $WORKDIR/trigger_parameters.txt $JPP_DATA/PMT_parameters.txt INPUT_FILES+=($WORKDIR/trigger_efficiency_ ${i}.root) done for ANGLE_DEG in $ANGLES_DEG[*];do set_variable SIGMA_NS 3.0 set_variable OUTLIERS 3 set_variable OUTPUT_FILE $WORKDIR/matrix\[${ANGLE_DEG}\deg\].root $JPP_DIR/examples/JReconstruction-f"$INPUT_FILES[*]"-o $OUTPUT_FILE-S ${SIGMA_NS}-A ${ANGLE_DEG}-O ${OUTLIERS}-d ${DEBUG}--!fiif[[$OPTION=="plot"]];then if((0));then for H1 in h0 h1;do JPlot1D-f"$WORKDIR/matrix["${^ANGLES_DEG}" deg].root:${H1}"-y"1 2e3"-Y-L TR-T""-\^"number of events [a.u.]"-> o chi2
Definition: JMatrixNZ.sh:106
Auxiliary class for simultaneously handling light yields and response of PMT.
Regressor function object for JShower3EZ fit using JSimplex minimiser.
Data structure for fit of energy.
Definition: JEnergy.hh:28
double getNPE(const Hit &hit)
Get true charge of hit.
static int MAXIMUM_ITERATIONS
maximal number of iterations
Definition: JSimplex.hh:237
int j
Definition: JPolint.hh:792
JMEstimator * getMEstimator(const int type)
Get M-Estimator.
Definition: JMEstimator.hh:203
bool getDAQStatus(const JDAQFrameStatus &frame, const JStatus &status)
Test status of DAQ.
Template specialisation of class JModel to match hit with bright point.
Definition: JFit/JModel.hh:121
Match operator for Cherenkov light from shower in any direction.
Basic data structure for L1 hit.
int debug
debug level