Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JCalibrateMuon.cc File Reference

Program to perform detector calibration using reconstructed muon trajectories. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <algorithm>
#include "TROOT.h"
#include "TFile.h"
#include "TProfile.h"
#include "TH2D.h"
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "JDAQ/JDAQEventIO.hh"
#include "JDAQ/JDAQTimesliceIO.hh"
#include "JDAQ/JDAQSummarysliceIO.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JDynamics/JDynamics.hh"
#include "JLang/JPredicate.hh"
#include "JTrigger/JHit.hh"
#include "JTrigger/JFrame.hh"
#include "JTrigger/JTimeslice.hh"
#include "JTrigger/JHitL0.hh"
#include "JTrigger/JBuildL0.hh"
#include "JTrigger/JTriggerParameters.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JParallelFileScanner.hh"
#include "JSupport/JSummaryFileRouter.hh"
#include "JSupport/JMeta.hh"
#include "JReconstruction/JEvt.hh"
#include "JReconstruction/JMuonGandalf.hh"
#include "JReconstruction/JMuonGandalfParameters_t.hh"
#include "JTools/JAbstractHistogram.hh"
#include "JROOT/JRootToolkit.hh"
#include "JROOT/JManager.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

Program to perform detector calibration using reconstructed muon trajectories.

It is recommended to perform the detector calibration after JMuonGandalf.cc and to accordingly set option JMuonGandalfParameters_t::numberOfPrefits = 1, so that the best track from the previous output is used. Several histograms will be produced which can subsequently be processed with JHobbit.cc for the determination of the time calibration of optical modules and JFrodo.cc for the time-slewing correction.

Author
mdejong

Definition in file JCalibrateMuon.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 65 of file JCalibrateMuon.cc.

66 {
67  using namespace std;
68  using namespace JPP;
69  using namespace KM3NETDAQ;
70 
71  typedef JParallelFileScanner< JTypeList<JDAQEvent, JFIT::JEvt> > JParallelFileScanner_t;
72  typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type;
74  JACOUSTICS::JEvt>::typelist calibration_types;
75  typedef JMultipleFileScanner<calibration_types> JCalibration_t;
76  typedef JAbstractHistogram<double> histogram_type;
77 
78  JParallelFileScanner_t inputFile;
79  string outputFile;
80  JLimit_t& numberOfEvents = inputFile.getLimit();
81  string detectorFile;
82  JCalibration_t calibrationFile;
83  double Tmax_s;
84  string pdfFile;
86  histogram_type calibrate;
87  int debug;
88 
89  try {
90 
91  parameters.numberOfPrefits = 1;
92 
93  JParser<> zap("Program to perform detector calibration using reconstructed muon trajectories.");
94 
95  zap['f'] = make_field(inputFile);
96  zap['o'] = make_field(outputFile) = "gandalf.root";
97  zap['a'] = make_field(detectorFile);
98  zap['+'] = make_field(calibrationFile) = JPARSER::initialised();
99  zap['T'] = make_field(Tmax_s) = 100.0;
100  zap['n'] = make_field(numberOfEvents) = JLimit::max();
101  zap['P'] = make_field(pdfFile);
102  zap['c'] = make_field(calibrate, "Histogram for time calibration per optical module.");
104  zap['d'] = make_field(debug) = 1;
105 
106  zap(argc, argv);
107  }
108  catch(const exception& error) {
109  FATAL(error.what() << endl);
110  }
111 
112  cout.tie(&cerr);
113 
114  if (!calibrate.is_valid()) {
115  FATAL("Invalid calibration data " << calibrate << endl);
116  }
117 
118  if (parameters.numberOfPrefits != 1) {
119  WARNING("Number of prefits " << parameters.numberOfPrefits << " != " << 1 << endl);
120  }
121 
123 
124  try {
125  load(detectorFile, detector);
126  }
127  catch(const JException& error) {
128  FATAL(error);
129  }
130 
131 
132  getMechanics.load(detector.getID());
133 
134  JDynamics dynamics(detector, Tmax_s);
135 
136  dynamics.load(calibrationFile);
137 
138 
139  const JModuleRouter router(dynamics);
140 
141  JSummaryFileRouter summary(inputFile, parameters.R_Hz);
142 
143  JMuonGandalf fit(parameters, router, summary, pdfFile, debug);
144 
145  typedef vector<JHitL0> JDataL0_t;
146  typedef vector<JHitW0> JDataW0_t;
147 
148  const JBuildL0<JHitL0> buildL0;
149 
150 
151  typedef JManager<string, TProfile> JManager_t;
152 
153  TH2D ha("ha", NULL, 256, -0.5, 255.5,
154  calibrate.getNumberOfBins(), calibrate.getLowerLimit(), calibrate.getUpperLimit());
155 
156  TProfile hb("hb", NULL, 256, -0.5, 255.5);
157 
158  TProfile hr("hr", NULL, 60, 0.0, 150.0);
159 
160  TH2D h2("h2", NULL, detector.size(), -0.5, detector.size() - 0.5,
161  calibrate.getNumberOfBins(), calibrate.getLowerLimit(), calibrate.getUpperLimit());
162 
163  JManager_t g1(new TProfile("%", NULL, detector.size(), -0.5, detector.size() - 0.5, -1.0, +1.0));
164 
165 
166  while (inputFile.hasNext()) {
167 
168  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
169 
170  multi_pointer_type ps = inputFile.next();
171 
172  JDAQEvent* tev = ps;
173  JFIT::JEvt* in = ps;
174 
175  summary.update(*tev);
176 
177  in->select(parameters.numberOfPrefits, qualitySorter);
178 
179  JDataL0_t dataL0;
180 
181  buildL0(*tev, router, true, back_inserter(dataL0));
182 
183  for (JFIT::JEvt::const_iterator track = in->begin(); track != in->end(); ++track) {
184 
185  const JRotation3D R (getDirection(*track));
186  const JLine1Z tz(getPosition (*track).rotate(R), track->getT());
187  JRange<double> Z_m;
188 
189  if (track->hasW(JSTART_LENGTH_METRES)) {
190  Z_m = JZRange(0.0, track->getW(JSTART_LENGTH_METRES)) + JRange<double>(parameters.ZMin_m, parameters.ZMax_m);
191  }
192 
193  const JFIT::JModel<JLine1Z> match(tz, parameters.roadWidth_m, JRange<double>(parameters.TMin_ns, parameters.TMax_ns), Z_m);
194 
195  // hit selection based on start value
196 
197  JDataW0_t data;
198 
199  for (JDataL0_t::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
200 
201  double rate_Hz = summary.getRate(*i);
202 
203  if (rate_Hz <= 0.0) {
204  rate_Hz = summary.getRate();
205  }
206 
207  JHitW0 hit(*i, rate_Hz);
208 
209  hit.rotate(R);
210 
211  if (match(hit)) {
212  data.push_back(hit);
213  }
214  }
215 
216  // select first hit
217 
218  sort(data.begin(), data.end(), JMuonGandalf::compare);
219 
220  JDataW0_t::iterator __end = unique(data.begin(), data.end(), equal_to<JDAQPMTIdentifier>());
221 
222 
223  // set fit parameters
224 
225  if (track->getE() > 0.1)
226  fit.JRegressor_t::E_GeV = track->getE();
227  else
228  fit.JRegressor_t::E_GeV = parameters.E_GeV;
229 
230  set<int> buffer;
231 
232  for (JDataW0_t::const_iterator hit = data.begin(); hit != __end; ++hit) {
233  buffer.insert(hit->getModuleID());
234  }
235 
236  const JLine3Z ta(tz);
237 
238  for (set<int>::const_iterator id = buffer.begin(); id != buffer.end(); ++id) {
239 
240  JDataW0_t::iterator q = partition(data.begin(), __end, make_predicate(&JHitW0::getModuleID, *id, JComparison::ne()));
241 
242  if (distance(data.begin(), q) - fit.parameters.size() > 0) {
243 
244  fit(ta, data.begin(), q); // re-fit
245 
246  for (JDataW0_t::const_iterator hit = q; hit != __end; ++hit) {
247 
248  const int index = router.getIndex(*id);
249  const double t1 = fit.value.getT(hit->getPosition());
250  JTrack3D gradient = fit(fit.value, *hit).gradient;
251 
252  gradient.rotate_back(R);
253 
254  ha.Fill(hit->getToT(), hit->getT1() - t1);
255  hb.Fill(hit->getToT(), gradient.getT());
256 
257  hr.Fill(fit.value.getDistance(*hit), gradient.getT());
258 
259  h2.Fill(index, hit->getT() - t1);
260 
261  g1["T"]->Fill(index, gradient.getT());
262  g1["X"]->Fill(index, gradient.getX());
263  g1["Y"]->Fill(index, gradient.getY());
264  g1["Z"]->Fill(index, gradient.getZ());
265  }
266  }
267  }
268  }
269  }
270  STATUS(endl);
271 
272  TFile out(outputFile.c_str(), "recreate");
273 
274  putObject(&out, JMeta(argc, argv));
275 
276  out << ha;
277  out << hb;
278  out << hr;
279  out << h2;
280  out << g1;
281 
282  out.Write();
283  out.Close();
284 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
#define WARNING(A)
Definition: JMessage.hh:65
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
static JDetectorMechanics getMechanics
Function object to get string mechanics.
Definition: JMechanics.hh:243
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Template specialisation of L0 builder for JHitL0 data type.
Definition: JBuildL0.hh:102
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:80
Router for direct addressing of module data in detector data structure.
Rotation matrix.
Definition: JRotation3D.hh:111
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
General purpose class for parallel reading of objects from a single file or multiple files...
Template specialisation of class JModel to match hit with muon trajectory along z-axis.
Definition: JFit/JModel.hh:34
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
Data structure for fit of straight line in positive z-direction.
Definition: JLine3Z.hh:36
Simple data structure for histogram binning.
string outputFile
Wrapper class to make final fit of muon trajectory.
Definition: JMuonGandalf.hh:72
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
Detector file.
Definition: JHead.hh:196
JDirection3D getDirection(const Vec &dir)
Get direction.
Acoustic event fit.
Auxiliary class for recursive type list generation.
Definition: JTypeList.hh:351
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
JPosition3D getPosition(const Vec &pos)
Get position.
JAxis3D & rotate_back(const JRotation3D &R)
Rotate back axis.
Definition: JAxis3D.hh:240
File router for fast addressing of summary data.
double getY() const
Get y position.
Definition: JVector3D.hh:104
void load(const std::string &file_name)
Load mechanical model parameters from file.
Definition: JMechanics.hh:142
int debug
debug level
Definition: JSirene.cc:63
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:40
double getT(const JVector3D &pos) const
Get arrival time of Cherenkov light at given position.
Definition: JTrack3D.hh:126
#define FATAL(A)
Definition: JMessage.hh:67
Dynamic detector calibration.
Definition: JDynamics.hh:59
Auxiliary class for a hit with background rate value.
Definition: JHitW0.hh:21
static const int JSTART_LENGTH_METRES
distance between first and last hits in metres from JStart.cc
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Data structure for set of track fit results.
General purpose class for object reading from a list of file names.
Data structure for fit of straight line paralel to z-axis.
Definition: JLine1Z.hh:27
double getX() const
Get x position.
Definition: JVector3D.hh:94
Orientation of module.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
do set_variable DETECTOR_TXT $WORKDIR detector
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:38
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Definition: JPosition3D.hh:186
void select(const JSelector_t &selector)
Select fits.
double getZ() const
Get z position.
Definition: JVector3D.hh:115
JTOOLS::JRange< double > JZRange
Definition: JFit/JModel.hh:21
bool qualitySorter(const JRECONSTRUCTION::JFit &first, const JRECONSTRUCTION::JFit &second)
Comparison of fit results.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
bool putObject(TDirectory *dir, const T &object)
Write object to ROOT directory.
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25