Jpp  17.3.0-rc.1
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  for (size_t i = 0; i != module->size(); ++i) {
189 
190  const size_t count = top.count(JDAQPMTIdentifier(module->getID(), i));
191 
192  const double rate_Hz = summary.getRate(JDAQPMTIdentifier(module->getID(), i));
193 
194  data.push_back(JShowerNPEHit(this->getNPE(module->getPMT(i), rate_Hz), count));
195  }
196  }
197 
198  const int NDF = data.size() - 1;
199 
200  if (NDF >= 0) {
201 
202  // 5-point search between given limits
203  const int N = 5;
204 
205  JResult result[N];
206 
207  for (int i = 0; i != N; ++i) {
208 
209  result[i].x = log10(Emin_GeV + i * (Emax_GeV - Emin_GeV) / (N-1));
210 
211  }
212 
213  do{
214 
215  int j = 0;
216 
217  for (int i = 0; i != N; ++i) {
218 
219  if (!result[i]) {
220 
221  result[i].chi2 = (*this)(result[i].x, data.begin(), data.end());
222 
223  }
224 
225  if (result[i].chi2 < result[j].chi2) {
226  j = i;
227  }
228  }
229 
230  // squeeze range
231 
232  switch (j) {
233 
234  case 0:
235  result[4] = result[1];
236  result[2] = JResult(0.5 * (result[0].x + result[4].x));
237  break;
238 
239  case 1:
240  result[4] = result[2];
241  result[2] = result[1];
242  break;
243 
244  case 2:
245  result[0] = result[1];
246  result[4] = result[3];
247  break;
248 
249  case 3:
250  result[0] = result[2];
251  result[2] = result[3];
252  break;
253 
254  case 4:
255  result[0] = result[3];
256  result[2] = JResult(0.5 * (result[0].x + result[4].x));
257  break;
258  }
259 
260  result[1] = JResult(0.5 * (result[0].x + result[2].x));
261  result[3] = JResult(0.5 * (result[2].x + result[4].x));
262 
263  } while (result[4].x - result[0].x > resolution);
264 
265 
266  if (result[1].chi2 != result[3].chi2) {
267 
268  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);
269 
270  result[2].chi2 = (*this)(result[2].x, data.begin(), data.end());
271 
272  }
273 
274  // const double chi2 = result[2].chi2; // this is not used because fits are sorted wrt the position fit
275  const double E = result[2].x.getE();
276 
277  JShower3E sh_fit(sh.getPosition(), sh.getDirection(), sh.getT(), E);
278 
279  // the fits of this reco step are sorted wrt the previous reco step
280  // because otherwise it tends to degrade the position reco performances
281  out.push_back(getFit(JHistory(shower->getHistory()).add(JSHOWERENERGYPREFIT), sh_fit, shower->getQ(),
282  shower->getNDF(), sh_fit.getE()));
283 
284  }
285  }
286 
287  return out;
288 
289  }
290 
293  };
294 }
295 
296 #endif
297 
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:68
double getE() const
Get energy.
Definition: JEnergy.hh:170
then usage E
Definition: JMuonPostfit.sh:35
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.
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
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})"
return result
Definition: JPolint.hh:764
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.
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.
Simple fit method based on Powell&#39;s algorithm, see reference: Numerical Recipes in C++...
Definition: JSimplex.hh:42
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:703
JMEstimator * getMEstimator(const int type)
Get M-Estimator.
Definition: JMEstimator.hh:203
Template specialisation of class JModel to match hit with bright point.
Definition: JFit/JModel.hh:121
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
Match operator for Cherenkov light from shower in any direction.
Basic data structure for L1 hit.
int debug
debug level