Jpp  18.1.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JReconstruction/JShowerNPE.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <vector>
5 #include <algorithm>
6 
7 #include "JDAQ/JDAQEventIO.hh"
9 
10 #include "JDetector/JDetector.hh"
13 
14 #include "JTrigger/JHitL0.hh"
15 #include "JTrigger/JBuildL0.hh"
16 
17 #include "JSupport/JSupport.hh"
20 
21 #include "JPhysics/JNPE_t.hh"
22 #include "JPhysics/JPDF_t.hh"
23 
24 #include "JFit/JPoint4D.hh"
25 #include "JFit/JModel.hh"
26 #include "JFit/JFitToolkit.hh"
27 
29 #include "JReconstruction/JEvt.hh"
32 
33 #include "Jeep/JPrint.hh"
34 #include "Jeep/JParser.hh"
35 #include "Jeep/JMessage.hh"
36 
37 #include "JTools/JResult.hh"
38 
39 namespace {
40 
41  /**
42  * Auxiliary data structure for sorting of hits.
43  */
44  static const struct {
45  /**
46  * Compare hits by PMT identifier and time.
47  *
48  * \param first first hit
49  * \param second second hit
50  * \return true if first before second; else false
51  */
52  template<class T>
53  bool operator()(const T& first, const T& second) const
54  {
55  using namespace std;
56  using namespace JPP;
57  using namespace KM3NETDAQ;
58 
59  if (equal_to<JDAQPMTIdentifier>()(first, second))
60  return less<JHit>()(first, second);
61  else
62  return less<JDAQPMTIdentifier>()(first, second);
63  }
64  } compare;
65 }
66 
67 
68 /**
69  * \file
70  *
71  * Program to evaluate hit probabilities.
72  *
73  * \author mdejong and adomi
74  */
75 int main(int argc, char **argv)
76 {
77  using namespace std;
78  using namespace JPP;
79  using namespace KM3NETDAQ;
80 
81  typedef JParallelFileScanner< JTypeList<JDAQEvent, JEvt> > JParallelFileScanner_t;
82  typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type;
83 
84  JParallelFileScanner_t inputFile;
85  JLimit_t& numberOfEvents = inputFile.getLimit();
86  string detectorFile;
87  string pdfFile;
89  int debug;
90 
91  try {
92 
93  parameters.numberOfPrefits = 1;
94 
95  JParser<> zap("Program to evaluate hit probabilities.");
96 
97  zap['f'] = make_field(inputFile);
98  zap['a'] = make_field(detectorFile);
99  zap['n'] = make_field(numberOfEvents) = JLimit::max();
100  zap['P'] = make_field(pdfFile);
102  zap['d'] = make_field(debug) = 1;
103 
104  zap(argc, argv);
105  }
106  catch(const exception& error) {
107  FATAL(error.what() << endl);
108  }
109 
110  //setDAQLongprint(debug >= JEEP::debug_t);
111 
112 
113  if (parameters.numberOfPrefits != 1) {
114  WARNING("Number of prefits " << parameters.numberOfPrefits << " != " << 1 << endl);
115  }
116 
118 
119  try {
120  load(detectorFile, detector);
121  }
122  catch(const JException& error) {
123  FATAL(error);
124  }
125 
126  const JModuleRouter router(detector);
127 
128  JSummaryFileRouter summary(inputFile, parameters.R_Hz);
129 
130  const JShowerNPE_t npe(pdfFile);
131 
132  const JTimeRange T_ns(parameters.TMin_ns, parameters.TMax_ns);
133 
134  typedef vector<JHitL0> JDataL0_t;
135  typedef vector<JHitW0> JDataW0_t;
136 
137  const JBuildL0<JHitL0> buildL0;
138 
139  while (inputFile.hasNext()) {
140 
141  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
142 
143  multi_pointer_type ps = inputFile.next();
144 
145  JDAQEvent* tev = ps;
146  JEvt* in = ps;
147 
148  DEBUG("event: " << *tev << endl);
149 
150  summary.update(*tev);
151 
152  in->select(parameters.numberOfPrefits, qualitySorter);
153 
154  JDataL0_t dataL0;
155 
156  buildL0(*tev, router, true, back_inserter(dataL0));
157 
158  for (JEvt::const_iterator shower = in->begin(); shower != in->end(); ++shower) {
159 
160  DEBUG("shower: " << *shower << endl);
161 
162  JRotation3D R (getDirection(*shower));
163  JPoint4D vx(getPosition(*shower).rotate(R), shower->getT());
164 
165  const JModel<JPoint4D> match(vx, parameters.roadWidth_m, T_ns);
166 
167  // hit selection based on start value
168 
169  JDataW0_t data;
170 
171  for (JDataL0_t::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
172 
173  double rate_Hz = summary.getRate(*i);
174 
175  if (rate_Hz <= 0.0) {
176  rate_Hz = summary.getRate();
177  }
178 
179  JHitW0 hit(*i, rate_Hz);
180 
181  hit.rotate(R);
182 
183  if (match(hit)) {
184  data.push_back(hit);
185  }
186  }
187 
188  // select first hit in PMT
189 
190  sort(data.begin(), data.end(), compare);
191 
192  JDataW0_t::iterator __end = unique(data.begin(), data.end(), equal_to<JDAQPMTIdentifier>());
193 
194  DEBUG("point4d: "
195  << FIXED(12,3) << vx.getX() << ' '
196  << FIXED(12,3) << vx.getY() << ' '
197  << FIXED(12,3) << vx.getZ() << ' '
198  << FIXED(12,3) << vx.getT() << ' '
199  << FIXED( 8,3) << shower->getQ() << endl);
200 
201  double Q = 0.0;
202 
203  for (JDataW0_t::const_iterator hit = data.begin(); hit != __end; ++hit) {
204 
205  JPosition3D D(hit->getPosition());
206  D.sub(vx);
207 
208  const double x = hit->getX() - vx.getX();
209  const double y = hit->getY() - vx.getY();
210  const double z = hit->getZ() - vx.getZ();
211  const double cd = z/D.getLength(); // Delta = angle between shower direction and PMT position
212 
213  const double t1 = vx.getT() + (D.getLength() * getIndexOfRefraction() * getInverseSpeedOfLight());
214 
215  JDirection3D u(hit->getDX(), hit->getDY(), hit->getDZ()); // PMT orientation
216 
217  u.rotate(JRotation3Z(-atan2(y,x))); // rotate PMT axis to x-z plane
218 
219  const double theta = u.getTheta();
220  const double phi = fabs(u.getPhi()); // rotational symmetry of Cherenkov cone
221 
222  const double E = shower->getE();
223  const double dt = T_ns.constrain(hit->getT() - t1);
224 
225  double H1 = npe.calculate(E, D.getLength(), cd, theta, phi);
226  double H0 = hit->getR() * 1e-9 * T_ns.getLength();
227 
228  double Vmax_npe = 20.0;
229  if (H1 >= Vmax_npe) {
230  H1 *= Vmax_npe / H1;
231  }
232 
233  H1 += H0; // signal + background
234 
235  const double chi2 = getChi2(H1, true); // -log(lik)
236 
237  DEBUG("hit: "
238  << setw(10) << hit->getModuleID() << ':' << setw( 2) << setfill('0') << hit->getPMTAddress() << setfill(' ') << ' '
239  << FIXED(12,1) << E << ' '
240  << FIXED( 9,1) << R << ' '
241  << FIXED( 6,4) << theta << ' '
242  << FIXED( 6,4) << phi << ' '
243  << FIXED( 8,3) << dt << ' '
244  << FIXED(12,3) << chi2 << endl);
245 
246  Q += getQuality(chi2);
247  }
248 
249  DEBUG("quality: " << FIXED(8,3) << Q << ' ' << distance(data.begin(), __end) << endl);
250  }
251  }
252  STATUS(endl);
253 }
Auxiliary methods to evaluate Poisson probabilities and chi2.
Utility class to parse command line options.
Definition: JParser.hh:1514
General exception.
Definition: JException.hh:24
Q(UTCMax_s-UTCMin_s)-livetime_s
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:33
then usage $script< input file >[option[primary[working directory]]] nWhere option can be E
Definition: JMuonPostfit.sh:40
double getQuality(const double chi2, const int NDF)
Get quality of fit.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Template specialisation of L0 builder for JHitL0 data type.
Definition: JBuildL0.hh:102
This include file containes various data structures that can be used as specific return types for the...
double getIndexOfRefraction()
Get average index of refraction of water corresponding to group velocity.
Data structure for vertex fit.
Definition: JPoint4D.hh:22
#define STATUS(A)
Definition: JMessage.hh:63
void update(const JDAQHeader &header)
Update router.
Detector data structure.
Definition: JDetector.hh:89
Router for direct addressing of module data in detector data structure.
Rotation matrix.
Definition: JRotation3D.hh:111
double getRate() const
Get default rate.
Auxiliary data structure for shower PDF.
Definition: JNPE_t.hh:175
Auxiliary data structure for muon PDF.
*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
General purpose class for parallel reading of objects from a single file or multiple files...
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
Data structure for detector geometry and calibration.
bool qualitySorter(const JFit &first, const JFit &second)
Comparison of fit results.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
Basic data structure for L0 hit.
T getLength() const
Get length (difference between upper and lower limit).
Definition: JRange.hh:289
Rotation around Z-axis.
Definition: JRotation3D.hh:85
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
I/O formatting auxiliaries.
JAxis3D & rotate(const JRotation3D &R)
Rotate axis.
Definition: JAxis3D.hh:225
Detector file.
Definition: JHead.hh:226
JDirection3D getDirection(const Vec &dir)
Get direction.
Acoustic event fit.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Parallel scanning of objects from a single file or multiple files according a format that follows fro...
JPosition3D getPosition(const Vec &pos)
Get position.
T constrain(argument_type x) const
Constrain value to range.
Definition: JRange.hh:350
File router for fast addressing of summary data.
Auxiliary data structure for muon PDF.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Direct access to module in detector data structure.
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
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Data structure for fit parameters.
Utility class to parse command line options.
const double getInverseSpeedOfLight()
Get inverse speed of light.
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
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
do set_variable DETECTOR_TXT $WORKDIR detector
double u[N+1]
Definition: JPolint.hh:776
Template specialisation of class JModel to match hit with bright point.
Definition: JFit/JModel.hh:121
double getChi2(const double P)
Get chi2 corresponding to given probability.
Definition: JFitToolkit.hh:56
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
then echo WARNING
Definition: JTuneHV.sh:91
do echo Generating $dir eval D
Definition: JDrawLED.sh:53
int debug
debug level
double calculate(const double E, const double D, const double cd, const double theta, const double phi) const
Get PDF.
Definition: JNPE_t.hh:249
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62