Jpp  16.0.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JReconstruction/JShowerNPE.cc File Reference

Program to evaluate hit probabilities. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include "JDAQ/JDAQEventIO.hh"
#include "JDAQ/JDAQSummarysliceIO.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JTrigger/JHitL0.hh"
#include "JTrigger/JBuildL0.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JParallelFileScanner.hh"
#include "JSupport/JSummaryFileRouter.hh"
#include "JPhysics/JNPE_t.hh"
#include "JPhysics/JPDF_t.hh"
#include "JFit/JPoint4D.hh"
#include "JFit/JModel.hh"
#include "JFit/JFitToolkit.hh"
#include "JReconstruction/JHitW0.hh"
#include "JReconstruction/JEvt.hh"
#include "JReconstruction/JEvtToolkit.hh"
#include "JReconstruction/JShowerFitParameters_t.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "JTools/JResult.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Program to evaluate hit probabilities.

Author
mdejong and adomi

Definition in file JReconstruction/JShowerNPE.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 75 of file JReconstruction/JShowerNPE.cc.

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  cout.tie(&cerr);
113 
114  if (parameters.numberOfPrefits != 1) {
115  WARNING("Number of prefits " << parameters.numberOfPrefits << " != " << 1 << endl);
116  }
117 
119 
120  try {
121  load(detectorFile, detector);
122  }
123  catch(const JException& error) {
124  FATAL(error);
125  }
126 
127  const JModuleRouter router(detector);
128 
129  JSummaryFileRouter summary(inputFile, parameters.R_Hz);
130 
131  const JShowerNPE_t npe(pdfFile);
132 
133  const JTimeRange T_ns(parameters.TMin_ns, parameters.TMax_ns);
134 
135  typedef vector<JHitL0> JDataL0_t;
136  typedef vector<JHitW0> JDataW0_t;
137 
138  const JBuildL0<JHitL0> buildL0;
139 
140  while (inputFile.hasNext()) {
141 
142  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
143 
144  multi_pointer_type ps = inputFile.next();
145 
146  JDAQEvent* tev = ps;
147  JEvt* in = ps;
148 
149  DEBUG("event: " << *tev << endl);
150 
151  summary.update(*tev);
152 
153  in->select(parameters.numberOfPrefits, qualitySorter);
154 
155  JDataL0_t dataL0;
156 
157  buildL0(*tev, router, true, back_inserter(dataL0));
158 
159  for (JEvt::const_iterator shower = in->begin(); shower != in->end(); ++shower) {
160 
161  DEBUG("shower: " << *shower << endl);
162 
163  JRotation3D R (getDirection(*shower));
164  JPoint4D vx(getPosition(*shower).rotate(R), shower->getT());
165 
166  const JModel<JPoint4D> match(vx, parameters.roadWidth_m, T_ns);
167 
168  // hit selection based on start value
169 
170  JDataW0_t data;
171 
172  for (JDataL0_t::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
173 
174  double rate_Hz = summary.getRate(*i);
175 
176  if (rate_Hz <= 0.0) {
177  rate_Hz = summary.getRate();
178  }
179 
180  JHitW0 hit(*i, rate_Hz);
181 
182  hit.rotate(R);
183 
184  if (match(hit)) {
185  data.push_back(hit);
186  }
187  }
188 
189  // select first hit in PMT
190 
191  sort(data.begin(), data.end(), compare);
192 
193  JDataW0_t::iterator __end = unique(data.begin(), data.end(), equal_to<JDAQPMTIdentifier>());
194 
195  DEBUG("point4d: "
196  << FIXED(12,3) << vx.getX() << ' '
197  << FIXED(12,3) << vx.getY() << ' '
198  << FIXED(12,3) << vx.getZ() << ' '
199  << FIXED(12,3) << vx.getT() << ' '
200  << FIXED( 8,3) << shower->getQ() << endl);
201 
202  double Q = 0.0;
203 
204  for (JDataW0_t::const_iterator hit = data.begin(); hit != __end; ++hit) {
205 
206  JPosition3D D(hit->getPosition());
207  D.sub(vx);
208 
209  const double x = hit->getX() - vx.getX();
210  const double y = hit->getY() - vx.getY();
211  const double z = hit->getZ() - vx.getZ();
212  const double cd = z/D.getLength(); // Delta = angle between shower direction and PMT position
213 
214  const double t1 = vx.getT() + (D.getLength() * getIndexOfRefraction() * getInverseSpeedOfLight());
215 
216  JDirection3D u(hit->getDX(), hit->getDY(), hit->getDZ()); // PMT orientation
217 
218  u.rotate(JRotation3Z(-atan2(y,x))); // rotate PMT axis to x-z plane
219 
220  const double theta = u.getTheta();
221  const double phi = fabs(u.getPhi()); // rotational symmetry of Cherenkov cone
222 
223  const double E = shower->getE();
224  const double dt = T_ns.constrain(hit->getT() - t1);
225 
226  double H1 = npe.calculate(E, D.getLength(), cd, theta, phi);
227  double H0 = hit->getR() * 1e-9 * T_ns.getLength();
228 
229  double Vmax_npe = 20.0;
230  if (H1 >= Vmax_npe) {
231  H1 *= Vmax_npe / H1;
232  }
233 
234  H1 += H0; // signal + background
235 
236  const double chi2 = getChi2(H1, true); // -log(lik)
237 
238  DEBUG("hit: "
239  << setw(10) << hit->getModuleID() << ':' << setw( 2) << setfill('0') << hit->getPMTAddress() << setfill(' ') << ' '
240  << FIXED(12,1) << E << ' '
241  << FIXED( 9,1) << R << ' '
242  << FIXED( 6,4) << theta << ' '
243  << FIXED( 6,4) << phi << ' '
244  << FIXED( 8,3) << dt << ' '
245  << FIXED(12,3) << chi2 << endl);
246 
247  Q += getQuality(chi2);
248  }
249 
250  DEBUG("quality: " << FIXED(8,3) << Q << ' ' << distance(data.begin(), __end) << endl);
251  }
252  }
253  STATUS(endl);
254 }
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
#define WARNING(A)
Definition: JMessage.hh:65
Q(UTCMax_s-UTCMin_s)-livetime_s
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:33
then usage E
Definition: JMuonPostfit.sh:35
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
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
Detector data structure.
Definition: JDetector.hh:89
Router for direct addressing of module data in detector data structure.
Rotation matrix.
Definition: JRotation3D.hh:111
Auxiliary data structure for shower PDF.
Definition: JNPE_t.hh:175
*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:66
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
bool qualitySorter(const JFit &first, const JFit &second)
Comparison of fit results.
Rotation around Z-axis.
Definition: JRotation3D.hh:85
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Detector file.
Definition: JHead.hh:224
JDirection3D getDirection(const Vec &dir)
Get direction.
Acoustic event fit.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
JPosition3D getPosition(const Vec &pos)
Get position.
File router for fast addressing of summary data.
int debug
debug level
Definition: JSirene.cc:63
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:43
#define FATAL(A)
Definition: JMessage.hh:67
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.
const double getInverseSpeedOfLight()
Get inverse speed of light.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
do set_variable DETECTOR_TXT $WORKDIR detector
double u[N+1]
Definition: JPolint.hh:755
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 source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:42
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Definition: JPosition3D.hh:186
do echo Generating $dir eval D
Definition: JDrawLED.sh:53