Jpp
Functions
JFilter.cc File Reference
#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <iterator>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TProfile.h"
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "km3net-dataformat/offline/Hit.hh"
#include "JAAnet/JHead.hh"
#include "JAAnet/JHeadToolkit.hh"
#include "JDAQ/JDAQEventIO.hh"
#include "JDAQ/JDAQTimesliceIO.hh"
#include "km3net-dataformat/online/JDAQClock.hh"
#include "JSirene/JPulse.hh"
#include "JTools/JConstants.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JDetector/JPMTRouter.hh"
#include "JDetector/JTimeRange.hh"
#include "JTrigger/JHit.hh"
#include "JTrigger/JFrame.hh"
#include "JTrigger/JTimeslice.hh"
#include "JTrigger/JHitL0.hh"
#include "JTrigger/JHitL1.hh"
#include "JTrigger/JBuildL1.hh"
#include "JTrigger/JBuildL2.hh"
#include "JTrigger/JAlgorithm.hh"
#include "JTrigger/JMatch3B.hh"
#include "JTrigger/JMatch3D.hh"
#include "JTrigger/JMatch1D.hh"
#include "JTrigger/JBind2nd.hh"
#include "JTrigger/JTimeConverter.hh"
#include "JSupport/JTriggeredFileScanner.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "JSupport/JSupport.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to test performance of various hit filters based on JTRIGGER::clusterize method.

Author
mdejong

Definition in file JFilter.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 210 of file JFilter.cc.

211 {
212  using namespace std;
213  using namespace JPP;
214  using namespace KM3NETDAQ;
215 
216  JTriggeredFileScanner<> inputFile;
217  JLimit_t& numberOfEvents = inputFile.getLimit();
218  string outputFile;
219  string detectorFile;
220  double Tmax_ns;
221  double roadWidth_m;
222  double ctMin;
223  double thetaRad;
224  char cluster;
225  int histogram;
226  int debug;
227 
228  try {
229 
230  JParser<> zap("Example program to test performance of various hit filters.");
231 
232  zap['f'] = make_field(inputFile);
233  zap['o'] = make_field(outputFile) = "filter.root";
234  zap['a'] = make_field(detectorFile);
235  zap['n'] = make_field(numberOfEvents) = JLimit::max();
236  zap['T'] = make_field(Tmax_ns) = 20.0; // [ns]
237  zap['R'] = make_field(roadWidth_m) = 150.0; // [m]
238  zap['C'] = make_field(ctMin) = 0.0; //
239  zap['Q'] = make_field(thetaRad) = 0.2; //
240  zap['c'] = make_field(cluster) = 'A', 'B', 'C', 'D', 'E', 'F';
241  zap['H'] = make_field(histogram) = 1, 2;
242  zap['d'] = make_field(debug) = 1;
243 
244  zap(argc, argv);
245  }
246  catch(const exception &error) {
247  FATAL(error.what() << endl);
248  }
249 
250 
251  using namespace KM3NETDAQ;
252 
253  cout.tie(&cerr);
254 
255 
257 
258  try {
259  load(detectorFile, detector);
260  }
261  catch(const JException& error) {
262  FATAL(error);
263  }
264 
265  const JModuleRouter moduleRouter(detector);
266  const JPMTRouter pmtRouter (detector);
267 
268 
269  detector -= get<JPosition3D>(getHeader(inputFile));
270 
271 
272  TFile out(outputFile.c_str(), "recreate");
273 
274  TProfile* he;
275  TProfile* hp;
276 
277  if (histogram == 1) {
278 
279  vector<double> X;
280 
281  double x = -0.5;
282 
283  for ( ; x < 30.0; x += 1.0)
284  X.push_back(x);
285 
286  for ( ; x < 50.0; x += 2.0)
287  X.push_back(x);
288 
289  for ( ; x < 100.0; x += 5.0)
290  X.push_back(x);
291 
292  for ( ; x < 200.0; x += 10.0)
293  X.push_back(x);
294 
295  he = new TProfile("he", NULL, X.size() - 1, X.data());
296  hp = new TProfile("hp", NULL, X.size() - 1, X.data());
297 
298  } else {
299 
300  he = new TProfile("he", NULL, 28, 0.0, 7.0);
301  hp = new TProfile("hp", NULL, 28, 0.0, 7.0);
302  }
303 
304  TH1D ht1("ht1", NULL, 550, -50.0, +500.0);
305  TH1D ht2("ht2", NULL, 550, -50.0, +500.0);
306  TH1D hd1("hd1", NULL, 100, -1.0, +1.0);
307  TH1D hd2("hd2", NULL, 100, -1.0, +1.0);
308  TH1D hx1("hx1", NULL, 100, 0.0, +250.0);
309  TH1D hx2("hx2", NULL, 100, 0.0, +250.0);
310  TH1D hw1("hw1", NULL, 100, -0.5, +99.5);
311  TH1D hw2("hw2", NULL, 100, -0.5, +99.5);
312 
313 
314 
315  typedef map<int, JBuffer> JMap_t;
316  typedef vector<JHitL1> JDataL1_t;
317 
318  JMap_t zmap;
319  const JBuildL2<JHitL1> buildL2(JL2Parameters(2, Tmax_ns, ctMin));
320  const JMatch3B<JHitL1> match3B(roadWidth_m, Tmax_ns);
321  const JMatch3D<JHitL1> match3D(Tmax_ns);
322  const JMatch1D<JHitL1> match1D(roadWidth_m, Tmax_ns);
323  const JHorizon horizon(0.2, 2);
324 
325  const JVersor3D gui(getSinThetaC(), 0.0, getCosThetaC()); // photon emission direction
326 
327 
328  while (inputFile.hasNext()) {
329 
330  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
331 
333 
334  const JDAQEvent* tev = ps;
335  const Evt* event = ps;
336 
337  if (has_neutrino(*event)) {
338 
339  const Trk& neutrino = get_neutrino(*event);
340  const double E = neutrino.E; // GeV
341 
342 
343  vector<Trk>::const_iterator muon = event->mc_trks.end();
344 
345  {
346  double Emax = 0.0;
347 
348  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
349 
350  // (anti) muon
351 
352  if (is_muon(*track) && track->E > Emax) {
353  muon = track;
354  Emax = track->E;
355  }
356  }
357  }
358 
359  if (muon != event->mc_trks.end()) {
360 
361  JPosition3D pos = getPosition (*muon);
362  double t0 = muon->t;
363 
364  const JRotation3D R(getDirection(*muon));
365 
366  pos.rotate(R);
367 
368  JTimeConverter converter(*event, *tev);
369 
370  // Monte Carlo hits
371 
372  zmap.clear();
373 
374  const vector<Hit>& hitlist = event->mc_hits;
375 
376  for (vector<Hit>::const_iterator i = hitlist.begin(); i != hitlist.end(); ++i) {
377  if (!is_noise(*i)) {
378  zmap[pmtRouter.getParentModuleID(i->pmt_id)].push_back(*i);
379  }
380  }
381 
382 
383  // L1 Monte Carlo true data
384 
385  for (JMap_t::iterator i = zmap.begin(); i != zmap.end(); ) {
386 
387  i->second.compile(Tmax_ns, 2);
388 
389  if (i->second.empty())
390  zmap.erase(i++);
391  else
392  ++i;
393  }
394 
395  const int L1mc = zmap.size();
396 
397 
398  // L1 triggered data
399 
400  JDataL1_t dataL1;
401  JDataL1_t zbuf;
402 
403  JDAQTimeslice timeslice(*tev, true);
404 
405  for (JDAQTimeslice::const_iterator i = timeslice.begin(); i != timeslice.end(); ++i) {
406 
407  zbuf.clear();
408 
409  buildL2(*i, moduleRouter.getModule(i->getModuleID()), back_inserter(zbuf));
410 
411  if (!zbuf.empty()) {
412 
413  sort(zbuf.begin(), zbuf.end(), timeSorter<JHitL1>);
414 
415  dataL1.push_back(*zbuf.begin());
416  }
417  }
418 
419 
420  // cluster
421 
422  JDataL1_t::iterator __end = dataL1.begin();
423 
424  switch (cluster) {
425 
426  case 'A':
427  //__end = dataL1.end();
428  __end = clusterize(dataL1.begin(), dataL1.end(), make_match(matchAll));
429  break;
430 
431  case 'B':
432  __end = clusterize(dataL1.begin(), dataL1.end(), weightSorter<JHitL1>, match3D);
433  break;
434 
435  case 'C':
436  __end = clusterize(dataL1.begin(), dataL1.end(), match3B);
437  break;
438 
439  case 'D':
440  __end = clusterizeWeight(dataL1.begin(), dataL1.end(), match3B);
441  break;
442 
443  case 'E':
444 
445  for (JDataL1_t::iterator i = dataL1.begin(); i != dataL1.end(); ++i)
446  i->rotate(R);
447 
448  __end = clusterizeWeight(dataL1.begin(), dataL1.end(), match1D);
449 
450  for (JDataL1_t::iterator i = dataL1.begin(); i != dataL1.end(); ++i)
451  i->rotate_back(R);
452 
453  break;
454 
455  case 'F':
456 
457  __end = clusterizeWeight(dataL1.begin(), dataL1.end(), match3B);
458 
459  for (JDataL1_t::iterator i = dataL1.begin(); i != dataL1.end(); ++i)
460  i->rotate(R);
461 
462  __end = partition(dataL1.begin(), __end, horizon);
463  __end = clusterizeWeight(dataL1.begin(), __end, match1D);
464 
465  for (JDataL1_t::iterator i = dataL1.begin(); i != dataL1.end(); ++i)
466  i->rotate_back(R);
467 
468  break;
469 
470  default:
471  __end = dataL1.end();
472  break;
473  }
474 
475 
476  // L1 monitor
477 
478  JDataL1_t::iterator __q = __end;
479 
480  set<int> L1;
481  set<int> L1ok;
482 
483  for (vector<JHitL1>::iterator hit = dataL1.begin(); hit != __q; ) {
484 
485  L1.insert(hit->getModuleID());
486 
487  const double t1 = converter.getTime(*hit);
488 
489  if (zmap[hit->getModuleID()].has(JTimeRange(t1 - 0.5*Tmax_ns, t1 + 0.5*Tmax_ns))) {
490 
491  L1ok.insert(hit->getModuleID());
492 
493  ++hit;
494 
495  } else {
496 
497  iter_swap(hit, --__q);
498  }
499  }
500 
501 
502  if (L1mc != 0 && !L1.empty()) {
503 
504  Double_t x = numeric_limits<Double_t>::max();
505 
506  if (histogram == 1)
507  x = L1mc;
508  else
509  x = log10(E);
510 
511  he->Fill(x, (Double_t) L1ok.size() / (Double_t) L1mc);
512  hp->Fill(x, (Double_t) L1ok.size() / (Double_t) L1.size());
513 
514 
515  // transform hits to muon system
516 
517  for (JDataL1_t::iterator hit = dataL1.begin(); hit != __end; ++hit) {
518  hit->transform(R, pos);
519  }
520 
521 
522  for (JDataL1_t::iterator hit = dataL1.begin(); hit != __end; ++hit) {
523 
524  const double t1 = t0 + getInverseSpeedOfLight() * (hit->getZ() + hit->getX() * getTanThetaC());
525 
526  double dot = +1.0;
527 
528  for (JHitL1::const_iterator i = hit->begin(); i != hit->end(); ++i) {
529  if (i->getDot(gui) < dot)
530  dot = i->getDot(gui);
531  }
532 
533  const double w = (hit->rbegin()->getT() - hit->begin()->getT()); // / hit->size();
534 
535  if (distance(hit, __q) > 0) {
536  ht1.Fill(converter.getTime(hit->getT()) - t1);
537  hd1.Fill(dot);
538  hx1.Fill(hit->getX());
539  hw1.Fill(w);
540  } else {
541  ht2.Fill(converter.getTime(hit->getT()) - t1);
542  hd2.Fill(dot);
543  hx2.Fill(hit->getX());
544  hw2.Fill(w);
545  }
546  }
547  }
548  }
549  }
550  }
551  STATUS(endl);
552 
553  out.Write();
554  out.Close();
555 }
JTOOLS::getSinThetaC
double getSinThetaC()
Get average sine of Cherenkov angle of water.
Definition: JConstants.hh:155
KM3NETDAQ::JDAQEvent
DAQ Event.
Definition: JDAQEvent.hh:30
JTOOLS::w
data_type w[N+1][M+1]
Definition: JPolint.hh:708
JSUPPORT::JLimit
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
JTRIGGER::JL2Parameters
Data structure for L2 parameters.
Definition: JTriggerParameters.hh:33
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:476
JLANG::JMultiPointer
General purpose class for multiple pointers.
Definition: JMultiPointer.hh:22
Trk::E
double E
Energy (either MC truth or reconstructed)
Definition: Trk.hh:18
std::vector< double >
Trk
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:12
JTRIGGER::clusterize
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.
Definition: JAlgorithm.hh:45
Evt
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19
JTOOLS::getCosThetaC
double getCosThetaC()
Get average cosine of Cherenkov angle of water.
Definition: JConstants.hh:144
JTRIGGER::JTimeConverter
Auxiliary class to convert DAQ/trigger hit time to/from Monte Carlo hit time.
Definition: JTimeConverter.hh:36
JGEOMETRY3D::JVersor3D
Data structure for normalised vector in three dimensions.
Definition: JVersor3D.hh:23
KM3NETDAQ::JDAQTimeslice
Data time slice.
Definition: JDAQTimeslice.hh:30
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
distance
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Definition: PhysicsEvent.hh:434
JDETECTOR::JPMTRouter
Router for direct addressing of PMT data in detector data structure.
Definition: JPMTRouter.hh:33
JAANET::is_muon
bool is_muon(const Trk &track)
Test whether given track is a (anti-)muon.
Definition: JAAnetToolkit.hh:367
std::set< int >
JGEOMETRY3D::JPosition3D::rotate
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Definition: JPosition3D.hh:185
JTOOLS::JTimeRange
JRange< double > JTimeRange
Type definition for time range.
Definition: JTools/JTimeRange.hh:19
JSUPPORT::JTriggeredFileScanner::hasNext
virtual bool hasNext()
Check availability of next element.
Definition: JTriggeredFileScanner.hh:72
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JTRIGGER::make_match
JMatchHelper< JHit_t > make_match(bool(*match)(const JHit_t &, const JHit_t &))
Auxiliary method to make JMatch object based on pointer to match function.
Definition: JMatch.hh:92
JTRIGGER::JMatch1D
1D match criterion.
Definition: JMatch1D.hh:31
JSUPPORT::getHeader
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Definition: JMonteCarloFileSupportkit.hh:458
JSUPPORT::JMultipleFileScanner< JTypeList< JDAQEvent, JTypelist_t > >::getCounter
counter_type getCounter() const
Get counter.
Definition: JMultipleFileScanner.hh:323
JTOOLS::getInverseSpeedOfLight
const double getInverseSpeedOfLight()
Get inverse speed of light.
Definition: JConstants.hh:100
debug
int debug
debug level
Definition: JSirene.cc:59
JTRIGGER::clusterizeWeight
JHitIterator_t clusterizeWeight(JHitIterator_t __begin, JHitIterator_t __end, const JMatch< JHit_t > &match)
Partition data according given binary match operator.
Definition: JAlgorithm.hh:310
JGEOMETRY3D::JPosition3D
Data structure for position in three dimensions.
Definition: JPosition3D.hh:35
JSUPPORT::JTriggeredFileScanner::next
virtual const multi_pointer_type & next()
Get next element.
Definition: JTriggeredFileScanner.hh:92
JAANET::get_neutrino
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
Definition: JAAnetToolkit.hh:438
JTRIGGER::JMatch3D
3D match criterion.
Definition: JMatch3D.hh:29
JAANET::has_neutrino
bool has_neutrino(const Evt &evt)
Test whether given event has an incoming neutrino.
Definition: JAAnetToolkit.hh:427
JTRIGGER::JMatch3B
3D match criterion with road width.
Definition: JMatch3B.hh:34
std::map
Definition: JSTDTypes.hh:16
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JDETECTOR::JModuleRouter
Router for direct addressing of module data in detector data structure.
Definition: JModuleRouter.hh:34
JAANET::getDirection
JDirection3D getDirection(const Vec &v)
Get direction.
Definition: JAAnetToolkit.hh:221
JTOOLS::getTanThetaC
double getTanThetaC()
Get average tangent of Cherenkov angle of water.
Definition: JConstants.hh:133
JSUPPORT::JTriggeredFileScanner
Auxiliary class to synchronously read DAQ events and Monte Carlo events (and optionally other events)...
Definition: JTriggeredFileScanner.hh:39
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JDETECTOR::JDetector
Detector data structure.
Definition: JDetector.hh:80
gui
Definition: gui.cpp:136
JAANET::getPosition
JPosition3D getPosition(const Vec &v)
Get position.
Definition: JAAnetToolkit.hh:197
JAANET::detector
Detector file.
Definition: JHead.hh:130
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JLANG::JException
General exception.
Definition: JException.hh:23
JGEOMETRY3D::JRotation3D
Rotation matrix.
Definition: JRotation3D.hh:111
JTRIGGER::JBuildL2
Template L2 builder.
Definition: JBuildL2.hh:45
JAANET::is_noise
bool is_noise(const Hit &hit)
Verify hit origin.
Definition: JAAnetToolkit.hh:121