75 inline bool cmz(
const JHitR1& first,
const JHitR1& second)
96 int main(
int argc,
char **argv)
100 using namespace KM3NETDAQ;
104 string outputFileName;
109 int numberOfOutliers;
110 double gridAngle_deg;
111 size_t numberOfPrefits;
120 JParser<> zap(
"Program to monitor hit time residuals from reconstructed tracks using JPrefit+JSimplex");
123 zap[
'o'] =
make_field(outputFileName) =
"HTR_monitor.root";
125 zap[
'n'] =
make_field(numberOfEvents) = JLimit::max();
134 zap[
'N'] =
make_field(numberOfPrefits) = numeric_limits<size_t>::max();
141 catch(
const exception& error) {
142 FATAL(error.what() << endl);
149 const int FACTORY_LIMIT = 8;
150 const double STANDARD_DEVIATIONS = 3.0;
151 const double HIT_OFF = 1.0e3 * sigma_ns * sigma_ns;
153 const int MAXIMUM_NUMBER_OF_HITS = 50;
154 const double TMAX_NS = 50.0;
182 const double thetaMin = 0.75*
PI ;
183 const double thetaMax =
PI ;
184 const double rad = thetaMax - thetaMin;
185 const double bin = rad / floor(rad/(gridAngle_deg*
PI/180.0) + 0.5);
187 for (
double theta = thetaMin; theta < thetaMax + 0.5*bin; theta += bin) {
188 omega.push_back(
JAngle3D(theta,0.0));
197 NOTICE(
"Scanning over " << omega.size() <<
"JPrefit directions" <<endl ) ;
201 JRegressor_t fit(sigma_ns);
206 JRegressor_t::MAXIMUM_ITERATIONS = 10000;
208 TFile
outputFile(outputFileName.c_str(),
"recreate");
216 TTree htr_tree(Form(
"%d.htr",excl_mod->getID()),Form(
"%d.htr",excl_mod->getID())) ;
217 htr_tree.Branch(
"dt",&htr_dt) ;
218 htr_tree.Branch(
"bestfit",&bestfit) ;
220 STATUS(
"Excluding DOM "<<excl_mod->getID()<<endl ) ;
222 while (inputFile.hasNext()) {
224 STATUS(
"event: " << setw(10) << inputFile.getCounter() <<
'\r');
DEBUG(endl);
235 JDataL1_t dataL1_excluded;
240 for (JDAQTimeslice::const_iterator i = timeslice.begin(); i != timeslice.end(); ++i) {
245 if (module.
getID() != excl_mod->getID()) {
247 if (!noInterDU || module.
getString() == excl_mod->getString()) {
249 buildL0(buffer, back_inserter(dataL0));
250 buildL2(buffer, back_inserter(dataL1));
256 buildL2(buffer, back_inserter(dataL1_excluded));
264 JDataL1_t::iterator __end = unique(dataL1.begin(), dataL1.end(), equal_to<JDAQModuleIdentifier>());
269 if (distance(dataL1.begin(), __end) >= minHits && dataL1_excluded.size() > 0) {
271 for (JOmega3D_t::const_iterator dir = omega.begin(); dir != omega.end(); ++dir) {
277 copy(dataL1.begin(), __end, back_inserter(data));
279 for (JDataR1_t::iterator i = data.begin(); i != data.end(); ++i) {
284 JDataR1_t::iterator __end1 = data.end();
289 if (distance(data.begin(), __end1) > MAXIMUM_NUMBER_OF_HITS) {
291 advance(__end1 = data.begin(), MAXIMUM_NUMBER_OF_HITS);
293 partial_sort(data.begin(), __end1, data.end(), cmz);
301 if (distance(data.begin(), __end1) < minHits) {
308 data.erase(__end1, data.end());
310 data.reserve(data.size() + dataL0.size());
314 for (JDataL0_t::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
316 if (find_if(data.begin(), __end1, bind2nd(equal_to<JDAQModuleIdentifier>(), i->getModuleID())) == __end1) {
322 if (count_if(data.begin(), __end1,
JBind2nd(match1D,hit)) >= minHits) {
328 __end1 =
clusterize(__end1, data.end(), match1D);
339 double chi2 = numeric_limits<double>::max();
346 if (distance(data.begin(), __end1) <= FACTORY_LIMIT) {
348 double ymin = numeric_limits<double>::max();
350 JDataR1_t::iterator __end2 = __end1;
354 sort(data.begin(), __end1, compare);
362 V.
set(fit, data.begin(), __end2, gridAngle_deg, sigma_ns);
363 Y.
set(fit, data.begin(), __end2);
370 WARNING(endl <<
"chi2(1) " << y << endl);
371 }
else if (y < ymin) {
383 ymin -= STANDARD_DEVIATIONS * STANDARD_DEVIATIONS;
394 V.
set(fit, data.begin(), __end1, gridAngle_deg, sigma_ns);
395 Y.
set(fit, data.begin(), __end1);
402 for (
int n = 0; n <= number_of_outliers && NDF > 0; ++n, --NDF) {
407 for (
unsigned int i = 0; i != Y.size(); ++i) {
412 WARNING(endl <<
"chi2(2) " << y << endl);
413 }
else if (y > ymax) {
419 if (ymax < STANDARD_DEVIATIONS * STANDARD_DEVIATIONS) {
425 fit.update(data.begin(), __end1, V);
427 Y.
set(fit, data.begin(), __end1);
448 if (numberOfPrefits > 0) {
450 JEvt::iterator __end = out.end();
452 advance(__end = out.begin(), min(numberOfPrefits, out.size()));
456 out.erase(__end, out.end());
467 JEvt::iterator __end = out.end();
469 if (numberOfPrefits > 0) {
470 advance(__end = out.begin(), min(numberOfPrefits, out.size()));
473 for (JEvt::const_iterator track = out.begin(); track != __end; ++track) {
481 for (JDataL1_t::const_iterator i = dataL1.begin(); i != dataL1.end(); ++i) {
494 data.reserve(data.size() + dataL0.size());
496 JDataR1_t::iterator __end1 = data.end();
498 for (JDataL0_t::iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
500 if (find_if(data.begin(), __end1, bind2nd(equal_to<JDAQModuleIdentifier>(), i->getModuleID())) == __end1) {
522 const int NDF =
getCount(data.begin(), data.end()) - fit.step.size();
526 const double chi2 = fit(
JLine3Z(tz), data.begin(), data.end());
546 bestfit = *out2.begin() ;
548 const double t_exp =
getTrack(bestfit).
getT(excl_mod->getPosition()) ;
550 sort(dataL1_excluded.begin(), dataL1_excluded.end()) ;
552 htr_dt = dataL1_excluded.begin()->getT()-t_exp ;
Data regression method for JFIT::JLine3Z.
Data structure for angles in three dimensions.
double getT() const
Get calibrated time of hit.
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)...
Match operator for Cherenkov light from muon with given direction.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for a composite optical module.
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.
JTrack3E getTrack(const Trk &track)
Get track.
Algorithms for hit clustering and sorting.
Template specialisation of L0 builder for JHitL0 data type.
double getCount(TH1D *hptr, int muon_threshold)
Recording of objects on file according a format that follows from the file name extension.
Router for direct addressing of module data in detector data structure.
Template specialisation of class JModel to match hit with muon trajectory along z-axis.
Data structure for fit of straight line in positive z-direction.
Direction set covering (part of) solid angle.
Linear fit of JFIT::JLine1Z.
Template definition of linear fit.
Data structure for detector geometry and calibration.
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.
Basic data structure for L0 hit.
Data structure for track fit results.
Auxiliary class for permutations of L1 hits.
Definition of fit parameters from various applications.
Basic data structure for time and time over threshold information of hit.
JDetector::const_iterator const_iterator
Auxiliary class for defining the range of iterations of objects.
int getString() const
Get string number.
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).
Match operator for Cherenkov light from muon in any direction.
Data structure for vector in three dimensions.
Determination of the co-variance matrix of hits for a track along z-axis (JFIT::JLine1Z).
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
int getID() const
Get identifier.
Parallel scanning of objects from a single file or multiple files according a format that follows fro...
Regressor function object for JLine3Z fit using JSimplex minimiser.
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.
double getT(const JVector3D &pos) const
Get arrival time of Cherenkov light at given position.
General purpose messaging.
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Direct access to module in detector data structure.
Reduced data structure for L1 hit.
double getQuality(const double chi2, const int NDF)
Get quality of fit.
Data structure for set of track fit results.
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
ROOT TTree parameter settings.
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.
2-dimensional frame with time calibrated data from one optical module.
Reduced data structure for L1 hit.
JDirection3D getDirection(const Vec &v)
Get direction.
const JLimit & getLimit() const
Get limit.
double getChi2(const double P)
Get chi2 corresponding to given probability.
Data structure for normalised vector in positive z-direction.
Base class for direction set.
JPosition3D & rotate(const JRotation3D &R)
Rotate.
double getZ() const
Get z position.
void invert()
Invert matrix.
Basic data structure for L1 hit.
JTriggerCounter_t next()
Increment trigger counter.
3D match criterion with road width.
#define DEBUG(A)
Message macros.
JPosition3D getPosition(const Vec &v)
Get position.
int main(int argc, char *argv[])