Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JMuonPath.cc File Reference

Program to perform JFIT::JRegressor<JLine3Z,JGandalf> fit with I/O of JFIT::JEvt data. More...

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Program to perform JFIT::JRegressor<JLine3Z,JGandalf> fit with I/O of JFIT::JEvt data.

Author
mdejong

Definition in file JMuonPath.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 62 of file JMuonPath.cc.

63{
64 using namespace std;
65 using namespace JPP;
66 using namespace KM3NETDAQ;
67
68 typedef JParallelFileScanner< JTypeList<JDAQEvent, JEvt> > JParallelFileScanner_t;
69 typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type;
71
72 JParallelFileScanner_t inputFile;
74 JLimit_t& numberOfEvents = inputFile.getLimit();
75 string detectorFile;
76 string pdfFile;
77 double roadWidth_m;
78 double R_Hz;
79 size_t numberOfPrefits;
80 double TTS_ns;
81 double E_GeV;
82 int debug;
83
84 try {
85
86 JParser<> zap("Program to perform fit of muon path to data.");
87
88 zap['f'] = make_field(inputFile);
89 zap['o'] = make_field(outputFile) = "path.root";
90 zap['a'] = make_field(detectorFile);
91 zap['n'] = make_field(numberOfEvents) = JLimit::max();
92 zap['P'] = make_field(pdfFile);
93 zap['R'] = make_field(roadWidth_m) = numeric_limits<double>::max();
94 zap['B'] = make_field(R_Hz) = 6.0e3;
95 zap['N'] = make_field(numberOfPrefits) = 1;
96 zap['T'] = make_field(TTS_ns);
97 zap['E'] = make_field(E_GeV) = 1.0e3;
98 zap['d'] = make_field(debug) = 1;
99
100 zap(argc, argv);
101 }
102 catch(const exception& error) {
103 FATAL(error.what() << endl);
104 }
105
106
108
109 try {
110 load(detectorFile, detector);
111 }
112 catch(const JException& error) {
113 FATAL(error);
114 }
115
116 const JModuleRouter router(detector);
117
118
119 typedef vector<JHitL0> JDataL0_t;
120 const JBuildL0<JHitL0> buildL0;
121
122
124
125 const JTimeRange T_ns(-50.0, +50.0);
126
127 JRegressor_t::debug = debug;
128 JRegressor_t::Vmax_npe = 10.0; // npe
129 JRegressor_t::MAXIMUM_ITERATIONS = 10000;
130
131 JRegressor_t fit(pdfFile, T_ns, TTS_ns);
132
133 fit.transform(JRegressor_t::transformer_type::getDefaultTransformer()); // get rid of R-dependent weight function
134
135 fit.estimator.reset(new JMEstimatorLorentzian());
136
137 fit.parameters.resize(4);
138
139 fit.parameters[0] = JLine3Z::pX();
140 fit.parameters[1] = JLine3Z::pY();
141 fit.parameters[2] = JLine3Z::pDX();
142 fit.parameters[3] = JLine3Z::pDY();
143
144 if (fit.getRmax() < roadWidth_m) {
145
146 roadWidth_m = fit.getRmax();
147
148 WARNING("Set road width to [m] " << roadWidth_m << endl);
149 }
150
151 const double Rmax_m = 100.0; // hit selection [m]
152 const double Tmax_ns = 10.0; // hit selection [ns]
153
154
155 outputFile.open();
156
157 outputFile.put(JMeta(argc, argv));
158
159 while (inputFile.hasNext()) {
160
161 STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
162
163 multi_pointer_type ps = inputFile.next();
164
165 const JDAQEvent* tev = ps;
166 const JEvt* in = ps;
167
168 JEvt cp = *in;
169 JEvt out;
170
171 cp.select(numberOfPrefits, qualitySorter);
172
173
174 JDataL0_t dataL0;
175
176 buildL0(*tev, router, true, back_inserter(dataL0));
177
178
179 for (JEvt::const_iterator track = cp.begin(); track != cp.end(); ++track) {
180
181 const JRotation3D R (getDirection(*track));
182 const JLine1Z tz(getPosition (*track).rotate(R), track->getT());
183 const JModel<JLine1Z> match(tz, roadWidth_m, T_ns);
184
185 // hit selection based on start value
186
188
190
191 for (JDataL0_t::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
192
193 JHitW0 hit(*i, R_Hz);
194
195 hit.rotate(R);
196
197 if (match(hit)) {
198
199 top.insert(hit.getPMTIdentifier());
200
201 const double t1 = hit.getT() - tz.getT(hit);
202
203 if (tz.getDistance(hit) <= Rmax_m && t1 >= -Tmax_ns && t1 <= +Tmax_ns) {
204 Z.include(hit.getZ() - tz.getDistance(hit) / getTanThetaC());
205 }
206 }
207 }
208
209
210 vector<JPMTW0> buffer;
211
212 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
213
214 JPosition3D pos(module->getPosition());
215
216 pos.rotate(R);
217
218 if (tz.getDistance(pos) <= roadWidth_m && Z(pos.getZ() - tz.getDistance(pos) / getTanThetaC())) {
219
220 for (unsigned int i = 0; i != module->size(); ++i) {
221
222 const JDAQPMTIdentifier id(module->getID(), i);
223
224 JPMT pmt(module->getPMT(i));
225
226 pmt.rotate(R);
227
228 buffer.push_back(JPMTW0(pmt, R_Hz, top.count(id)));
229 }
230 }
231 }
232
233
234 const int NDF = buffer.size() - fit.parameters.size();
235
236 if (NDF >= 0) {
237
238 // set fit parameters
239
240 if (track->getE() > 0.1)
241 fit.E_GeV = track->getE();
242 else
243 fit.E_GeV = E_GeV;
244
245 const double chi2 = fit(JLine3Z(tz), buffer.begin(), buffer.end());
246
247 JTrack3D tb(fit.value);
248
249 tb.rotate_back(R);
250
251 out.push_back(getFit(JMUONPATH, tb, getQuality(chi2), NDF));
252
253 out.rbegin()->setW(track->getW());
254 }
255 }
256
257 // apply default sorter
258
259 sort(out.begin(), out.end(), qualitySorter);
260
261 outputFile.put(out);
262 }
263 STATUS(endl);
264
266
267 io >> outputFile;
268
269 outputFile.close();
270}
string outputFile
#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:72
#define WARNING(A)
Definition JMessage.hh:65
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Detector data structure.
Definition JDetector.hh:96
Router for direct addressing of module data in detector data structure.
Data structure for PMT geometry, calibration and status.
Definition JPMT.hh:49
Data structure for fit of straight line paralel to z-axis.
Definition JLine1Z.hh:29
static parameter_type pY()
Definition JLine1Z.hh:181
static parameter_type pX()
Definition JLine1Z.hh:180
Data structure for fit of straight line in positive z-direction.
Definition JLine3Z.hh:40
static parameter_type pDY()
Definition JLine3Z.hh:320
static parameter_type pDX()
Definition JLine3Z.hh:319
Data structure for position in three dimensions.
JPosition3D & rotate(const JRotation3D &R)
Rotate.
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:23
Object writing to file.
General purpose class for parallel reading of objects from a single file or multiple files.
Object reading from a list of files.
static JRange< T, JComparator_t > DEFAULT_RANGE()
Default range.
Definition JRange.hh:555
range_type & include(argument_type x)
Include given value to range.
Definition JRange.hh:397
Template L0 hit builder.
Definition JBuildL0.hh:38
static const int JMUONPATH
JDirection3D getDirection(const Vec &dir)
Get direction.
JPosition3D getPosition(const Vec &pos)
Get position.
double getQuality(const JEvent &evt)
Get average quality.
JFit getFit(const int id, const JMODEL::JString &string)
Get fit parameters of string.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
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.
JFIT::JRegressor< JFIT::JLine3Z, JFIT::JGandalf > JRegressor_t
Definition JPerth.cc:132
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
Detector file.
Definition JHead.hh:227
Acoustic event fit.
Model for fit to acoustics data.
Lorentzian M-estimator.
Auxiliary class for handling PMT geometry, rate and response.
Definition JPMTW0.hh:24
Template definition of a data regressor of given model.
Definition JRegressor.hh:70
Type list.
Definition JTypeList.hh:23
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 class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72