Jpp 20.0.0-195-g190c9e876
the software that should make you happy
Loading...
Searching...
No Matches
JMuonPDF.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/JPDF_t.hh"
23#include "JPhysics/JNPE_t.hh"
24
25#include "JFit/JLine1Z.hh"
26#include "JFit/JModel.hh"
27
32
33#include "Jeep/JPrint.hh"
34#include "Jeep/JParser.hh"
35#include "Jeep/JMessage.hh"
36
37
38namespace {
39
40 /**
41 * Auxiliary data structure for sorting of hits.
42 */
43 static const struct {
44 /**
45 * Compare hits by PMT identifier and time.
46 *
47 * \param first first hit
48 * \param second second hit
49 * \return true if first before second; else false
50 */
51 template<class T>
52 bool operator()(const T& first, const T& second) const
53 {
54 if (first.getPMTIdentifier() == second.getPMTIdentifier())
55 return first.getT() < second.getT();
56 else
57 return first.getPMTIdentifier() < second.getPMTIdentifier();
58 }
59 } compare;
60}
61
62
63/**
64 * \file
65 *
66 * Program to evaluate hit probabilities.
67 *
68 * \author mdejong
69 */
70int main(int argc, char **argv)
71{
72 using namespace std;
73 using namespace JPP;
74 using namespace KM3NETDAQ;
75
76 typedef JParallelFileScanner< JTypeList<JDAQEvent, JEvt> > JParallelFileScanner_t;
77 typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type;
78
79 JParallelFileScanner_t inputFile;
80 JLimit_t& numberOfEvents = inputFile.getLimit();
81 string detectorFile;
82 string pdfFile;
83 JMuonGandalfParameters_t parameters;
84 JPMTParametersMap pmtParameters;
85 int debug;
86
87 try {
88
89 parameters.numberOfPrefits = 1;
90
91 JParser<> zap("Program to evaluate hit probabilities.");
92
93 zap['f'] = make_field(inputFile);
94 zap['a'] = make_field(detectorFile);
95 zap['n'] = make_field(numberOfEvents) = JLimit::max();
96 zap['F'] = make_field(pdfFile);
97 zap['@'] = make_field(parameters) = JPARSER::initialised();
98 zap['P'] = make_field(pmtParameters) = JPARSER::initialised();
99 zap['d'] = make_field(debug) = 1;
100
101 zap(argc, argv);
102 }
103 catch(const exception& error) {
104 FATAL(error.what() << endl);
105 }
106
107 //setDAQLongprint(debug >= JEEP::debug_t);
108
109
110 if (parameters.numberOfPrefits != 1) {
111 WARNING("Number of prefits " << parameters.numberOfPrefits << " != " << 1 << endl);
112 }
113
115
116 try {
117 load(detectorFile, detector);
118 }
119 catch(const JException& error) {
120 FATAL(error);
121 }
122
123 const JModuleRouter router(detector);
124
125 JSummaryFileRouter summary(inputFile);
126
127 const JMuonPDF_t pdf(pdfFile, parameters.TTS_ns);
128 const JMuonNPE_t npe(pdfFile);
129
130 const JTimeRange T_ns(parameters.TMin_ns, parameters.TMax_ns);
131
132 typedef vector<JHitL0> JDataL0_t;
133 typedef vector<JHitW0> JDataW0_t;
134
135 const JBuildL0<JHitL0> buildL0;
136
137 while (inputFile.hasNext()) {
138
139 STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
140
141 multi_pointer_type ps = inputFile.next();
142
143 JDAQEvent* tev = ps;
144 JEvt* in = ps;
145
146 DEBUG("event: " << *tev << endl);
147
148 summary.update(*tev);
149
150 in->select(parameters.numberOfPrefits, qualitySorter);
151
152 JDataL0_t dataL0;
153
154 buildL0(*tev, router, true, back_inserter(dataL0));
155
156 for (JEvt::const_iterator track = in->begin(); track != in->end(); ++track) {
157
158 DEBUG("track: " << *track << endl);
159
160 JRotation3D R (getDirection(*track));
161 JLine1Z tz(getPosition (*track).rotate(R), track->getT());
162 JRange<double> Z_m;
163
164 if (track->hasW(JSTART_LENGTH_METRES)) {
165 Z_m = JRange<double>(0.0, track->getW(JSTART_LENGTH_METRES)) + JRange<double>(parameters.ZMin_m, parameters.ZMax_m);
166 }
167
168 const JModel<JLine1Z> match(tz, parameters.roadWidth_m, T_ns, Z_m);
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
200 double E_GeV = parameters.E_GeV;
201 /*
202 if (track->getE() > 0.1) {
203 E_GeV = track->getE();
204 }
205 */
206
207 DEBUG("line1z: "
208 << FIXED(12,3) << tz.getX() << ' '
209 << FIXED(12,3) << tz.getY() << ' '
210 << FIXED(12,3) << tz.getZ() << ' '
211 << FIXED(12,3) << tz.getT() << ' '
212 << FIXED(12,1) << E_GeV << ' '
213 << FIXED( 8,3) << track->getQ() << endl);
214
215 // move track to bary-center of hits
216 /*
217 int N = 0;
218 double z = 0.0;
219
220 for (JDataW0_t::const_iterator hit = data.begin(); hit != __end; ++hit) {
221 N += 1;
222 z += hit->getZ();
223 }
224
225 if (N != 0) {
226 tz.setZ(z/N, getSpeedOfLight());
227 }
228 */
229
230 double Q = 0.0;
231
232 for (JDataW0_t::const_iterator hit = data.begin(); hit != __end; ++hit) {
233
234 const double x = hit->getX() - tz.getX();
235 const double y = hit->getY() - tz.getY();
236 const double z = hit->getZ() - tz.getZ();
237 const double R = sqrt(x*x + y*y);
238
239 const double t1 = tz.getT() + (z + R * getTanThetaC()) * getInverseSpeedOfLight();
240
241 JDirection3D u(hit->getDX(), hit->getDY(), hit->getDZ()); // PMT orientation
242
243 u.rotate(JRotation3Z(-atan2(y,x))); // rotate PMT axis to x-z plane
244
245 const double theta = u.getTheta();
246 const double phi = fabs(u.getPhi()); // rotational symmetry of Cherenkov cone
247
248 //const double E = gWater.getE(E_GeV, z); // correct for energy loss
249 const double E = E_GeV;
250 const double dt = T_ns.constrain(hit->getT() - t1);
251
252 JMuonPDF_t::result_type H1 = pdf.calculate(E, R, theta, phi, dt);
253 JMuonPDF_t::result_type H0(hit->getR() * 1e-9, 0.0, T_ns);
254
255 H1 += H0; // signal + background
256
257 const double chi2 = H1.getChi2() - H0.getChi2(); // likelihood ratio
258
259 DEBUG("hit: "
260 << setw(10) << hit->getModuleID() << ':' << setw( 2) << setfill('0') << hit->getPMTAddress() << setfill(' ') << ' '
261 << FIXED(12,1) << E << ' '
262 << FIXED( 9,1) << R << ' '
263 << FIXED( 6,4) << theta << ' '
264 << FIXED( 6,4) << phi << ' '
265 << FIXED( 8,3) << dt << ' '
266 << FIXED(12,3) << chi2 << endl);
267
268 Q += getQuality(chi2);
269 }
270
271 DEBUG("quality: " << FIXED(8,3) << Q << ' ' << distance(data.begin(), __end) << endl);
272
273
274 double Y = 0.0;
275
276 for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
277
278 JPosition3D pos(i->getPosition());
279
280 pos.transform(R, tz.getPosition());
281
282 if (pos.getX() <= parameters.roadWidth_m) {
283
284 JModule module = *i;
285
286 module.transform(R, tz.getPosition());
287
288 for (JModule::iterator pmt = module.begin(); pmt != module.end(); ++pmt) {
289
290 const double R = sqrt(pmt->getX()*pmt->getX() + pmt->getY()*pmt->getY());
291 const double theta = pmt->getTheta();
292 const double phi = fabs(pmt->getPhi());
293 const double y = npe.calculate(1.0, R, theta, phi); // MIP
294
295 DEBUG("PMT: "
296 << setw(10) << module.getID() << ':' << setw( 2) << setfill('0') << distance(module.begin(),pmt) << setfill(' ') << ' '
297 << FIXED(9,1) << R << ' '
298 << FIXED(6,4) << theta << ' '
299 << FIXED(6,4) << phi << ' '
300 << SCIENTIFIC(7,2) << y << endl);
301
302 Y += y;
303 }
304 }
305 }
306
307 DEBUG("npe: " << FIXED(7,1) << Y << endl);
308 }
309 }
310 STATUS(endl);
311}
Data structure for detector geometry and calibration.
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.
int main(int argc, char **argv)
Definition JMuonPDF.cc:70
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.
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.
Data structure for a composite optical module.
Definition JModule.hh:76
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 fit of straight line paralel to z-axis.
Definition JLine1Z.hh:29
double getT(const JVector3D &pos) const
Get arrival time of Cherenkov light at given position.
Definition JLine1Z.hh:114
double getZ(const JPosition3D &pos) const
Get point of emission of Cherenkov light along muon path.
Definition JLine1Z.hh:134
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.
void transform(const JRotation3D &R, const JVector3D &pos)
Transform position.
JPosition3D & rotate(const JRotation3D &R)
Rotate.
const JPosition3D & getPosition() const
Get position.
Rotation around Z-axis.
double getY() const
Get y position.
Definition JVector3D.hh:104
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
General exception.
Definition JException.hh:24
int getID() const
Get identifier.
Definition JObjectID.hh:50
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 constrain(argument_type x) const
Constrain value to range.
Definition JRange.hh:350
Template L0 hit builder.
Definition JBuildL0.hh:38
static const int JSTART_LENGTH_METRES
distance between projected positions on the track of optical modules for which the response does not ...
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.
const double getInverseSpeedOfLight()
Get inverse speed of light.
double getTanThetaC()
Get average tangent of Cherenkov angle of water corresponding to group velocity.
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.
double calculate(const double E, const double R, const double theta, const double phi) const
Get PDF.
Definition JNPE_t.hh:110
Auxiliary data structure for muon PDF.
Definition JPDF_t.hh:135
JFunction1D_t::result_type result_type
Definition JPDF_t.hh:145
result_type calculate(const double E, const double R, const double theta, const double phi, const double t1) const
Get PDF.
Definition JPDF_t.hh:235
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
double TMin_ns
minimal time w.r.t. Cherenkov hypothesis [ns]
double TMax_ns
maximal time w.r.t. Cherenkov hypothesis [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 floating point format specification.
Definition JManip.hh:488