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