95 using namespace KM3NETDAQ;
107 int numberOfOutliers;
108 double gridAngle_deg;
110 size_t numberOfPrefits;
115 JParser<> zap(
"Program to perform pre-fit of muon trajectory to data.");
120 zap[
'n'] =
make_field(numberOfEvents) = JLimit::max();
128 zap[
'N'] =
make_field(numberOfPrefits) = numeric_limits<size_t>::max();
133 catch(
const exception& error) {
134 FATAL(error.what() << endl);
141 const int FACTORY_LIMIT = 8;
142 const double STANDARD_DEVIATIONS = 3.0;
143 const double HIT_OFF = 1.0e3 * sigma_ns * sigma_ns;
144 const int NUMBER_OF_L1HITS = (useL0 ? 1 : 4);
145 const int MAXIMUM_NUMBER_OF_HITS = 50;
170 const JOmega3D omega(gridAngle_deg *
PI/180.0);
177 while (inputFile.hasNext()) {
179 STATUS(
"event: " << setw(10) << inputFile.getCounter() <<
'\r');
DEBUG(endl);
190 buildL0(
JDAQTimeslice(*tev,
true), router, back_inserter(dataL0));
191 buildL2(
JDAQTimeslice(*tev, !useL0), router, back_inserter(dataL1));
196 JDataL1_t::iterator __end = unique(dataL1.begin(), dataL1.end(), equal_to<JDAQModuleIdentifier>());
201 if (distance(dataL1.begin(), __end) >= NUMBER_OF_L1HITS) {
207 for (JOmega3D_t::const_iterator dir = omega.begin(); dir != omega.end(); ++dir) {
213 copy(dataL1.begin(), __end, back_inserter(data));
215 for (JDataR1_t::iterator i = data.begin(); i != data.end(); ++i) {
220 JDataR1_t::iterator __end1 = data.end();
225 if (distance(data.begin(), __end1) > MAXIMUM_NUMBER_OF_HITS) {
227 advance(__end1 = data.begin(), MAXIMUM_NUMBER_OF_HITS);
229 partial_sort(data.begin(), __end1, data.end(), cmz);
237 if (distance(data.begin(), __end1) < NUMBER_OF_L1HITS) {
244 data.erase(__end1, data.end());
246 data.reserve(data.size() + dataL0.size());
250 for (JDataL0_t::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
252 if (find_if(data.begin(), __end1, bind2nd(equal_to<JDAQModuleIdentifier>(), i->getModuleID())) == __end1) {
258 if (count_if(data.begin(), __end1,
JBind2nd(match1D,hit)) >= NUMBER_OF_L1HITS) {
264 __end1 =
clusterize(__end1, data.end(), match1D);
275 double chi2 = numeric_limits<double>::max();
282 if (distance(data.begin(), __end1) <= FACTORY_LIMIT) {
284 double ymin = numeric_limits<double>::max();
286 JDataR1_t::iterator __end2 = __end1;
290 sort(data.begin(), __end1, compare);
298 V.
set(fit, data.begin(), __end2, gridAngle_deg, sigma_ns);
299 Y.
set(fit, data.begin(), __end2);
306 WARNING(endl <<
"chi2(1) " << y << endl);
307 }
else if (y < ymin) {
319 ymin -= STANDARD_DEVIATIONS * STANDARD_DEVIATIONS;
330 V.
set(fit, data.begin(), __end1, gridAngle_deg, sigma_ns);
331 Y.
set(fit, data.begin(), __end1);
338 for (
int n = 0; n <= number_of_outliers && NDF > 0; ++n, --NDF) {
343 for (
unsigned int i = 0; i != Y.size(); ++i) {
348 WARNING(endl <<
"chi2(2) " << y << endl);
349 }
else if (y > ymax) {
355 if (ymax < STANDARD_DEVIATIONS * STANDARD_DEVIATIONS) {
361 fit.update(data.begin(), __end1, V);
363 Y.
set(fit, data.begin(), __end1);
384 if (numberOfPrefits > 0) {
386 JEvt::iterator __end = out.end();
388 advance(__end = out.begin(), min(numberOfPrefits, out.size()));
396 JEvt::iterator __begin = __end;
399 advance(__end = __begin, min(numberOfPrefits, (
size_t) distance(__begin, __q)));
404 out.erase(__end, out.end());
Utility class to parse command line options.
Linear fit of straight line parallel to z-axis to set of hits (objects with position and time)...
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
JBinder2nd< JHit_t > JBind2nd(const JMatch< JHit_t > &match, const JHit_t &second)
Auxiliary method to create JBinder2nd object.
void set(const JVector3D &pos, T __begin, T __end, const double alpha, const double sigma)
Set co-variance matrix.
JPosition3D & rotate_back(const JRotation3D &R)
Rotate back.
Template specialisation of L0 builder for JHitL0 data type.
double getCount(TH1D *hptr, int muon_threshold)
Router for direct addressing of module data in detector data structure.
Container for historical events.
Direction set covering (part of) solid angle.
Template definition of linear fit.
void update(const unsigned int k, const double extra)
Update inverted matrix at given diagonal element.
JHitIterator_t clusterizeWeight(JHitIterator_t __begin, JHitIterator_t __end, const JMatch< JHit_t > &match)
Partition data according given binary match operator.
JFit getFit(const JHistory &history, const JTrack3D &track, const double Q, const int NDF, const double energy=0.0, const int status=0)
Get fit.
Auxiliary class for permutations of L1 hits.
Auxiliary class for defining the range of iterations of objects.
JHitIterator_t clusterize(JHitIterator_t __begin, JHitIterator_t __end, const JMatch< JHit_t > &match, const int Nmin=1)
Partition data according given binary match operator.
Determination of the time residual vector of hits for a track along z-axis (JFIT::JLine1Z).
Determination of the co-variance matrix of hits for a track along z-axis (JFIT::JLine1Z).
Auxiliary class for recursive type list generation.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
void set(const JLine1Z &track, T __begin, T __end)
Set time residual vector.
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
double getQuality(const double chi2, const int NDF)
Get quality of fit.
Data structure for set of track fit results.
Data structure for fit of straight line paralel to z-axis.
bool qualitySorter(const JFIT::JFit &first, const JFIT::JFit &second)
Comparison of fit results.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Reduced data structure for L1 hit.
2-dimensional frame with time calibrated data from one optical module.
Object reading from a list of files.
const JLimit & getLimit() const
Get limit.
double getChi2(const double P)
Get chi2 corresponding to given probability.
void invert()
Invert matrix.
JTriggerCounter_t next()
Increment trigger counter.
3D match criterion with road width.
#define DEBUG(A)
Message macros.