Jpp  16.0.2
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 288 of file JAlignDetector.cc.

289 {
290  using namespace std;
291  using namespace JPP;
292 
293  string detectorFile_a;
294  string detectorFile_b;
295  bool overwriteDetector;
296  string tripodFile;
297  double sigma_m;
298  bool option;
299  JRange_t range;
300  int debug;
301 
302  try {
303 
304  JParser<> zap("Auxiliary program to align two detectors.");
305 
306  zap['a'] = make_field(detectorFile_a, "detector - subject to alignment (option -A)");
307  zap['b'] = make_field(detectorFile_b, "detector - reference for alignment");
308  zap['A'] = make_field(overwriteDetector, "overwrite detector file provided through '-a' with modified positions.");
309  zap['T'] = make_field(tripodFile, "tripods") = "";
310  zap['s'] = make_field(sigma_m) = 0.2;
311  zap['O'] = make_field(option, "keep strings vertical");
312  zap['r'] = make_field(range, "range of floors used in fit") = JRange_t();
313  zap['d'] = make_field(debug) = 2;
314 
315  zap(argc, argv);
316  }
317  catch(const exception &error) {
318  FATAL(error.what() << endl);
319  }
320 
321 
322  if (overwriteDetector) {
323  if (tripodFile == "") {
324  FATAL("No tripod file.");
325  }
326  }
327 
328 
329  JDetector detector_a;
330  JDetector detector_b;
331 
332  try {
333  load(detectorFile_a, detector_a);
334  }
335  catch(const JException& error) {
336  FATAL(error);
337  }
338 
339  try {
340  load(detectorFile_b, detector_b);
341  }
342  catch(const JException& error) {
343  FATAL(error);
344  }
345 
346 
347  const JFit_t fit(detector_b, sigma_m, option, range);
348 
349  vector<JModule> data;
350 
351  for (JDetector::const_iterator module = detector_a.begin(); module != detector_a.end(); ++module) {
352  if (fit.hasModule(module->getID()) && module->getFloor() != 0) {
353  data.push_back(*module);
354  }
355  }
356 
357 
358  JSimplex<JModel_t> simplex;
359 
362 
363  simplex.value = JModel_t(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
364 
365  simplex.step.resize(6);
366 
367  simplex.step[0] = JModel_t(0.01, 0.00, 0.00, 0.0, 0.0, 0.0);
368  simplex.step[1] = JModel_t(0.00, 0.01, 0.00, 0.0, 0.0, 0.0);
369  simplex.step[2] = JModel_t(0.00, 0.00, 0.01, 0.0, 0.0, 0.0);
370  simplex.step[3] = JModel_t(0.00, 0.00, 0.00, 5.0e-4, 0.0, 0.0);
371  simplex.step[4] = JModel_t(0.00, 0.00, 0.00, 0.0, 1.0e-4, 0.0);
372  simplex.step[5] = JModel_t(0.00, 0.00, 0.00, 0.0, 0.0, 1.0e-4);
373 
374  const double chi2 = simplex(fit, data.begin(), data.end());
375 
376  cout << "Number of iterations " << simplex.numberOfIterations << endl;
377  cout << "chi2/NDF " << FIXED(7,3) << chi2 << '/' << (detector_a.size() - simplex.step.size()) << endl;
378 
379  cout << "model:" << endl;
380 
381  cout << "x " << FIXED(7,3) << simplex.value.x << endl;
382  cout << "y " << FIXED(7,3) << simplex.value.y << endl;
383  cout << "z " << FIXED(7,3) << simplex.value.z << endl;
384  cout << "phi " << FIXED(9,5) << simplex.value.phi << endl;
385  cout << "Tx " << FIXED(9,5) << simplex.value.tx << endl;
386  cout << "Ty " << FIXED(9,5) << simplex.value.ty << endl;
387 
388 
389  if (overwriteDetector) {
390 
391  NOTICE("Store alignment data on files " << detectorFile_a << " and " << tripodFile << endl);
392 
393  detector_a.comment.add(JMeta(argc,argv));
394 
395  for (JDetector::iterator module = detector_a.begin(); module != detector_a.end(); ++module) {
396 
397  const JPosition3D p1 = module->getPosition();
398  const JPosition3D p2 = fit.getPosition(simplex.value, p1);
399 
400  module->add(p2 - p1);
401  }
402 
403  try {
404  store(detectorFile_a, detector_a);
405  }
406  catch(const JException& error) {
407  FATAL(error);
408  }
409 
411 
412  tripods.load(tripodFile.c_str());
413 
414  tripods.comment.add(JMeta(argc,argv));
415 
416  for (vector<JTripod>::iterator tripod = tripods.begin(); tripod != tripods.end(); ++tripod) {
417 
418  const JPosition3D p1 = tripod->getUTMPosition() - detector_a.getUTMPosition();
419  const JPosition3D p2 = fit.getPosition(simplex.value, p1);
420 
421  tripod->add(p2 - p1);
422  }
423 
424  tripods.store(tripodFile.c_str());
425  }
426 }
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
JFit_t
Enumeration for fit algorithms.
Definition: JKatoomba.hh:44
General exception.
Definition: JException.hh:23
TPaveText * p1
Detector data structure.
Definition: JDetector.hh:89
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
Type definition of range.
Definition: JHead.hh:39
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:1961
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
#define NOTICE(A)
Definition: JMessage.hh:64
int debug
debug level
Definition: JSirene.cc:63
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++...
Definition: JSimplex.hh:42
void store(const char *file_name) const
Store to output file.
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
then fatal Not enough tripods
JVector3D & add(const JVector3D &vector)
Add vector.
Definition: JVector3D.hh:142