Jpp
JAAnet.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <cmath>
6 
7 #include "TROOT.h"
8 #include "TFile.h"
9 #include "TH1D.h"
10 
11 #include "evt/Head.hh"
12 #include "evt/Evt.hh"
13 
14 #include "JTools/JRange.hh"
15 #include "JTools/JConstants.hh"
16 #include "JDAQ/JDAQClock.hh"
17 #include "JAAnet/JAAnetToolkit.hh"
18 #include "JMath/JMathToolkit.hh"
19 #include "JDetector/JDetector.hh"
21 
23 #include "JSupport/JSupport.hh"
24 
25 #include "Jeep/JParser.hh"
26 #include "Jeep/JMessage.hh"
27 
28 
29 /**
30  * \file
31  *
32  * Example program to analyse track fit results from AAnet formatted data.
33  * \author mdejong
34  */
35 int main(int argc, char **argv)
36 {
37  using namespace std;
38  using namespace JPP;
39  using namespace KM3NETDAQ;
40 
41  typedef JTOOLS::JRange<double> JRange_t;
42 
43  JMultipleFileScanner<Evt> inputFile;
44  JLimit_t& numberOfEvents = inputFile.getLimit();
45  string detectorFile;
46  string outputFile;
47  JRange_t E;
48  int debug;
49 
50  try {
51 
52  JParser<> zap("Example program to analyse track fit results from AAnet formatted data.");
53 
54  zap['f'] = make_field(inputFile);
55  zap['n'] = make_field(numberOfEvents) = JLimit::max();
56  zap['a'] = make_field(detectorFile) = "";
57  zap['o'] = make_field(outputFile) = "histogram.root";
58  zap['E'] = make_field(E) = JRange_t();
59  zap['d'] = make_field(debug) = 2;
60 
61  zap(argc, argv);
62  }
63  catch(const exception& error) {
64  FATAL(error.what() << endl);
65  }
66 
67 
68  JDetector detector;
69 
70  if (detectorFile != "") {
71  try {
72  load(detectorFile, detector);
73  }
74  catch(const JException& error) {
75  FATAL(error);
76  }
77  }
78 
79  const JModuleRouter router(detector);
80 
81  TFile out(outputFile.c_str(), "recreate");
82 
83  TH1D hx("hx", NULL, 100, -3.0, +2.3); // [log(deg)]
84  TH1D hd("hd", NULL, 100, 0.0, 10.0); // [m]
85  TH1D ht("ht", NULL, 100, -100.0, 100.0); // [ns]
86  TH1D he("he", NULL, 100, -5.0, +5.0); // [log10(E)]
87  TH1D h1("h1", NULL, 100, -50.0, +50.0); // [ns]
88 
89 
90  while (inputFile.hasNext()) {
91 
92  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
93 
94  const Evt* evt = inputFile.next();
95 
96  //if (has_muon(*evt) && has_reconstructed_muon(*evt)) {
97  if (has_muon(*evt) && has_reconstructed_track<JPP_RECONSTRUCTION_TYPE>(*evt, JRange<int>(JFIT::JMUONBEGIN, JFIT::JMUONEND))) {
98 
99  DEBUG(get_best_reconstructed_muon(*evt).comment << endl);
100 
101  JTrack3E ta = getTrack(get_muon(*evt));
102  //JTrack3E tb = getTrack(get_best_reconstructed_muon(*evt));
103  JTrack3E tb = getTrack(get_best_reconstructed_track<JPP_RECONSTRUCTION_TYPE>(*evt, JRange<int>(JFIT::JMUONBEGIN, JFIT::JMUONEND)));
104 
105  ta.add(getTimeSinceRTS(evt->mc_t));
106 
107  ta.move(ta.getIntersection(tb), getSpeedOfLight(), gWater);
108  tb.move(tb.getIntersection(ta), getSpeedOfLight(), gWater);
109 
110  if (E(ta.getE())) {
111 
112  hx.Fill(log10(getAngle(ta.getDirection(), tb.getDirection())));
113  hd.Fill((ta.getPosition() - tb.getPosition()).getLength());
114  ht.Fill( ta.getT() - tb.getT());
115  he.Fill(log10(tb.getE()/ta.getE()));
116  }
117 
118  for (vector<Hit>::const_iterator i = evt->hits.begin(); i != evt->hits.end(); ++i) {
119 
120  if (router.hasModule(i->dom_id)) {
121 
122  const JHitL0 hit = getHit(*i, router);
123 
124  h1.Fill(hit.getT() - tb.getT(hit.getPosition()));
125  }
126  }
127  }
128  }
129  STATUS(endl);
130 
131  out.Write();
132  out.Close();
133 }
JTOOLS::getSpeedOfLight
const double getSpeedOfLight()
Number of bytes in a gigabyte.
Definition: JConstants.hh:89
JMessage.hh
JAANET::getHit
JHitL0 getHit(const Hit &hit)
Get transformation.
Definition: JAAnetToolkit.hh:292
JPHYSICS::gWater
static const JGeaneWater gWater
Function object for energy loss of muon in sea water.
Definition: JGeane.hh:328
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:456
std::vector
Definition: JSTDTypes.hh:12
JTOOLS::JRange< double >
JSUPPORT::JLimit_t
JLimit JLimit_t
Type definition of limit.
Definition: JLimit.hh:215
JAANET::getTrack
JTrack3E getTrack(const Trk &track)
Get track.
Definition: JAAnetToolkit.hh:256
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JDAQClock.hh
main
int main(int argc, char **argv)
Definition: JAAnet.cc:35
JSupport.hh
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JMathToolkit.hh
JRange.hh
JSUPPORT::JMultipleFileScanner::getCounter
counter_type getCounter() const
Get counter.
Definition: JMultipleFileScanner.hh:323
debug
int debug
debug level
Definition: JSirene.cc:59
JSUPPORT::JMultipleFileScanner::next
virtual const pointer_type & next()
Get next element.
Definition: JMultipleFileScanner.hh:398
JConstants.hh
JAAnetToolkit.hh
JAANET::get_best_reconstructed_muon
const Trk & get_best_reconstructed_muon(const Evt &evt)
Get best reconstructed muon.
Definition: JAAnetToolkit.hh:951
JMultipleFileScanner.hh
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JSUPPORT::JMultipleFileScanner::hasNext
virtual bool hasNext()
Check availability of next element.
Definition: JMultipleFileScanner.hh:350
JParser.hh
JDetectorToolkit.hh
JFIT::JMUONEND
End of muon fit applications.
Definition: JFitApplications.hh:29
KM3NETDAQ::getTimeSinceRTS
double getTimeSinceRTS(const int frame_index)
Get time in ns since last RTS for a given frame index.
Definition: JDAQClock.hh:263
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JSUPPORT::JMultipleFileScanner
General purpose class for object reading from a list of file names.
Definition: JMultipleFileScanner.hh:167
JAANET::get_muon
const Trk & get_muon(const Evt &evt)
Get first muon from the event tracklist.
Definition: JAAnetToolkit.hh:524
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
JFIT::JMUONBEGIN
Start of muon fit applications.
Definition: JFitApplications.hh:22
JDetector.hh
JMATH::getAngle
double getAngle(const JFirst_t &first, const JSecond_t &second)
Get space angle between objects.
Definition: JMathToolkit.hh:146
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JAANET::has_muon
bool has_muon(const Evt &evt)
Test whether given event has a muon.
Definition: JAAnetToolkit.hh:513