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

Auxiliary program to align two detectors. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include "JMath/JMath.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JDetector/JTripod.hh"
#include "JFit/JSimplex.hh"
#include "JLang/JException.hh"
#include "JSupport/JMeta.hh"
#include "JTools/JRange.hh"
#include "Jeep/JContainer.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

Auxiliary program to align two detectors.


Author
mjongen

Definition in file JAlignDetector.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 289 of file JAlignDetector.cc.

290 {
291  using namespace std;
292  using namespace JPP;
293 
294  string detectorFile_a;
295  string detectorFile_b;
296  bool overwriteDetector;
297  string tripodFile;
298  double sigma_m;
299  bool option;
300  JRange_t range;
301  int debug;
302 
303  try {
304 
305  JParser<> zap("Auxiliary program to align two detectors.");
306 
307  zap['a'] = make_field(detectorFile_a, "detector - subject to alignment (option -A)");
308  zap['b'] = make_field(detectorFile_b, "detector - reference for alignment");
309  zap['A'] = make_field(overwriteDetector, "overwrite detector file provided through '-a' with modified positions.");
310  zap['T'] = make_field(tripodFile, "tripods") = "";
311  zap['s'] = make_field(sigma_m) = 0.2;
312  zap['O'] = make_field(option, "keep strings vertical");
313  zap['r'] = make_field(range, "range of floors used in fit") = JRange_t();
314  zap['d'] = make_field(debug) = 2;
315 
316  zap(argc, argv);
317  }
318  catch(const exception &error) {
319  FATAL(error.what() << endl);
320  }
321 
322 
323  if (overwriteDetector) {
324  if (tripodFile == "") {
325  FATAL("No tripod file.");
326  }
327  }
328 
329 
330  JDetector detector_a;
331  JDetector detector_b;
332 
333  try {
334  load(detectorFile_a, detector_a);
335  }
336  catch(const JException& error) {
337  FATAL(error);
338  }
339 
340  try {
341  load(detectorFile_b, detector_b);
342  }
343  catch(const JException& error) {
344  FATAL(error);
345  }
346 
347 
348  const JFit_t fit(detector_b, sigma_m, option, range);
349 
351 
352  for (JDetector::const_iterator module = detector_a.begin(); module != detector_a.end(); ++module) {
353  if (fit.hasModule(module->getID())) {
354  data.push_back(*module);
355  }
356  }
357 
358 
359  JSimplex<JModel_t> simplex;
360 
363 
364  simplex.value = JModel_t(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
365 
366  simplex.step.resize(6);
367 
368  simplex.step[0] = JModel_t(0.01, 0.00, 0.00, 0.0, 0.0, 0.0);
369  simplex.step[1] = JModel_t(0.00, 0.01, 0.00, 0.0, 0.0, 0.0);
370  simplex.step[2] = JModel_t(0.00, 0.00, 0.01, 0.0, 0.0, 0.0);
371  simplex.step[3] = JModel_t(0.00, 0.00, 0.00, 5.0e-4, 0.0, 0.0);
372  simplex.step[4] = JModel_t(0.00, 0.00, 0.00, 0.0, 1.0e-4, 0.0);
373  simplex.step[5] = JModel_t(0.00, 0.00, 0.00, 0.0, 0.0, 1.0e-4);
374 
375  const double chi2 = simplex(fit, data.begin(), data.end());
376 
377  cout << "Number of iterations " << simplex.numberOfIterations << endl;
378  cout << "chi2/NDF " << FIXED(7,3) << chi2 << '/' << (detector_a.size() - simplex.step.size()) << endl;
379 
380  cout << "model:" << endl;
381 
382  cout << "x " << FIXED(7,3) << simplex.value.x << endl;
383  cout << "y " << FIXED(7,3) << simplex.value.y << endl;
384  cout << "z " << FIXED(7,3) << simplex.value.z << endl;
385  cout << "phi " << FIXED(9,5) << simplex.value.phi << endl;
386  cout << "Tx " << FIXED(9,5) << simplex.value.tx << endl;
387  cout << "Ty " << FIXED(9,5) << simplex.value.ty << endl;
388 
389 
390  if (overwriteDetector) {
391 
392  NOTICE("Store alignment data on files " << detectorFile_a << " and " << tripodFile << endl);
393 
394  detector_a.comment.add(JMeta(argc,argv));
395 
396  for (JDetector::iterator module = detector_a.begin(); module != detector_a.end(); ++module) {
397 
398  const JPosition3D p1 = module->getPosition();
399  const JPosition3D p2 = fit.getPosition(simplex.value, p1);
400 
401  module->add(p2 - p1);
402  }
403 
404  try {
405  store(detectorFile_a, detector_a);
406  }
407  catch(const JException& error) {
408  FATAL(error);
409  }
410 
412 
413  tripods.load(tripodFile.c_str());
414 
415  tripods.comment.add(JMeta(argc,argv));
416 
417  for (vector<JTripod>::iterator tripod = tripods.begin(); tripod != tripods.end(); ++tripod) {
418 
419  const JPosition3D p1 = tripod->getUTMPosition() - detector_a.getUTMPosition();
420  const JPosition3D p2 = fit.getPosition(simplex.value, p1);
421 
422  tripod->add(p2 - p1);
423  }
424 
425  tripods.store(tripodFile.c_str());
426  }
427 }
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:1711
General exception.
Definition: JException.hh:24
TPaveText * p1
Detector data structure.
Definition: JDetector.hh:89
then fatal Number of tripods
Definition: JFootprint.sh:45
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
Type definition of range.
Definition: JHead.hh:41
Auxiliary wrapper for I/O of container with optional comment (see JComment).
Definition: JContainer.hh:39
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
#define NOTICE(A)
Definition: JMessage.hh:64
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
JModel_t value
Definition: JSimplex.hh:240
#define FATAL(A)
Definition: JMessage.hh:67
void load(const char *file_name)
Load from input file.
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
p2
Definition: module-Z:fit.sh:74
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Simple fit method based on Powell&#39;s algorithm, see reference: Numerical Recipes in C++...
void store(const char *file_name) const
Store to output file.
then if[[!-f $DETECTOR]] then JDetector sh $DETECTOR fi cat $WORKDIR trigger_parameters txt<< EOFtrigger3DMuon.enabled=1;trigger3DMuon.numberOfHits=5;trigger3DMuon.gridAngle_deg=1;ctMin=0.0;TMaxLocal_ns=15.0;EOF set_variable TRIGGEREFFICIENCY_TRIGGERED_EVENTS_ONLY INPUT_FILES=() for((i=1;$i<=$NUMBER_OF_RUNS;++i));do JSirene.sh $DETECTOR $JPP_DATA/genhen.km3net_wpd_V2_0.evt.gz $WORKDIR/sirene_ ${i}.root JTriggerEfficiency.sh $DETECTOR $DETECTOR $WORKDIR/sirene_ ${i}.root $WORKDIR/trigger_efficiency_ ${i}.root $WORKDIR/trigger_parameters.txt $JPP_DATA/PMT_parameters.txt INPUT_FILES+=($WORKDIR/trigger_efficiency_ ${i}.root) done for ANGLE_DEG in $ANGLES_DEG[*];do set_variable SIGMA_NS 3.0 set_variable OUTLIERS 3 set_variable OUTPUT_FILE $WORKDIR/matrix\[${ANGLE_DEG}\deg\].root $JPP_DIR/examples/JReconstruction-f"$INPUT_FILES[*]"-o $OUTPUT_FILE-S ${SIGMA_NS}-A ${ANGLE_DEG}-O ${OUTLIERS}-d ${DEBUG}--!fiif[[$OPTION=="plot"]];then if((0));then for H1 in h0 h1;do JPlot1D-f"$WORKDIR/matrix["${^ANGLES_DEG}" deg].root:${H1}"-y"1 2e3"-Y-L TR-T""-\^"number of events [a.u.]"-> o chi2
Definition: JMatrixNZ.sh:106
JComment comment
Definition: JContainer.hh:90
Fit model.
Definition: JMath/JModel.hh:29
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
JComment & add(const std::string &comment)
Add comment.
Definition: JComment.hh:100
JVector3D & add(const JVector3D &vector)
Add vector.
Definition: JVector3D.hh:142
int debug
debug level