Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
examples/JDynamics/JBallarat.cc File Reference

Example program to plot orientation data. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TGraph.h"
#include "JROOT/JGraph.hh"
#include "JROOT/JRootToolkit.hh"
#include "JROOT/JManager.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JDetectorAddressMapToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JCompass/JEvt.hh"
#include "JCompass/JSupport.hh"
#include "JDynamics/JDynamics.hh"
#include "Jeep/JPrint.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 plot orientation data.

Author
mdejong

Definition in file examples/JDynamics/JBallarat.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 38 of file examples/JDynamics/JBallarat.cc.

39 {
40  using namespace std;
41  using namespace JPP;
42 
44  JLimit_t& numberOfEvents = inputFile.getLimit();
45  string detectorFile;
46  string outputFile;
47  double Tmax_s;
48  int debug;
49 
50  try {
51 
52  JParser<> zap("Example program to plot orientation data.");
53 
54  zap['f'] = make_field(inputFile, "output of JBallarat[.sh]");
55  zap['n'] = make_field(numberOfEvents) = JLimit::max();
56  zap['a'] = make_field(detectorFile);
57  zap['o'] = make_field(outputFile) = "gold.root";
58  zap['T'] = make_field(Tmax_s);
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 
69 
70  try {
71  load(detectorFile, detector);
72  }
73  catch(const JException& error) {
74  FATAL(error);
75  }
76 
77  const JModuleRouter router(detector);
78 
79  if (!hasDetectorAddressMap(detector.getID())) {
80  FATAL("No detector address map for detector identier " << detector.getID() << endl);
81  }
82 
83  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
84 
85 
86  JDynamics dynamics(detector, Tmax_s);
87 
88  STATUS("loading input from file(s) " << inputFile << "... " << flush);
89 
90  dynamics.load(inputFile);
91 
92  STATUS("OK" << endl);
93 
94 
96 
97  for (JDynamics::JOrientation::const_iterator module = dynamics.orientation.begin(); module != dynamics.orientation.end(); ++module) {
98 
99  if (router.getModule(module->first).getFloor() != 0) {
100 
101  STATUS("Creating graphics for input data " << setw(10) << module->first << "... " << flush);
102 
103  JQuaternion3D Q0 = getRotation(getModule(demo.get(module->first)), router.getModule(module->first));
104 
105  Q0.conjugate();
106 
107  JGraph_t& z0 = Z0[module->first];
108 
109  for (JDynamics::JOrientation::function_type::const_iterator i = module->second.begin(); i != module->second.end(); ++i) {
110 
111  const JQuaternion3D Q1 = i->getY();
112  const JQuaternion3D Q = Q1 * Q0;
113 
115 
116  z0.put(i->getX(), (q.twist.getD() > 0.0 ? +2.0 : -2.0) * acos(q.twist.getA()));
117  }
118 
119  STATUS("OK" << endl);
120  }
121  }
122 
123  map<int, TH1D*> H0;
124 
125  for (JDynamics::JOrientation::const_iterator module = dynamics.orientation.begin(); module != dynamics.orientation.end(); ++module) {
126 
127  STATUS("Creating graphics for compiled data " << setw(10) << module->first << "... " << flush);
128 
129  if (router.getModule(module->first).getFloor() != 0 && !module->second.empty()) {
130 
131  JQuaternion3D Q0 = getRotation(getModule(demo.get(module->first)), router.getModule(module->first));
132 
133  Q0.conjugate();
134 
135  const Double_t xmin = module->second.getXmin();
136  const Double_t xmax = module->second.getXmax();
137  const Int_t nx = (Int_t) ((xmax - xmin) / Tmax_s);
138 
139  TH1D* h0 = H0[module->first] = new TH1D(MAKE_CSTRING("H[" << module->first << "].twist"), NULL, nx, xmin, xmax);
140 
141  for (Int_t i = 1; i <= h0->GetXaxis()->GetNbins(); ++i) {
142 
143  const Double_t x = h0->GetXaxis()->GetBinCenter(i);
144  const JQuaternion3D Q = module->second(x) * Q0;
145 
147 
148  h0->SetBinContent(i, (q.twist.getD() > 0.0 ? +2.0 : -2.0) * acos(q.twist.getA()));
149  }
150  }
151 
152  STATUS("OK" << endl);
153  }
154 
155 
156  const Double_t xmin = dynamics.orientation.getXmin();
157  const Double_t xmax = dynamics.orientation.getXmax();
158  const Int_t nx = (Int_t) ((xmax - xmin) / Tmax_s);
159 
160  JManager<int, TH1D> X0(new TH1D("X[%].twist", NULL, nx, xmin, xmax));
161 
162  for (Int_t i = 1; i <= X0->GetXaxis()->GetNbins(); ++i) {
163 
164  STATUS("Creating graphics for detector data " << FIXED(5,1) << (double) (i * 100) / (double) X0->GetXaxis()->GetNbins() << "%... " << flush << '\r');
165 
166  const Double_t x = X0->GetXaxis()->GetBinCenter(i);
167  const JDetector& buffer = dynamics(x);
168 
169  for (JDetector::const_iterator module = buffer.begin(); module != buffer.end(); ++module) {
170 
171  if (module->getFloor() != 0) {
172 
173  TH1D* x0 = X0[module->getID()];
174 
175  const JQuaternion3D Q = getRotation(router.getModule(module->getID()), *module);
176 
178 
179  x0->SetBinContent(i, (q.twist.getD() > 0.0 ? +2.0 : -2.0) * acos(q.twist.getA()));
180  }
181  }
182  }
183  STATUS(endl);
184 
185 
186  TFile out(outputFile.c_str(), "recreate");
187 
188  for (map<int, TH1D*>::const_iterator i = H0.begin(); i != H0.end(); ++i) {
189  out << *i->second;
190  }
191 
192  out << X0;
193 
194  for (map<int, JGraph_t>::const_iterator i = Z0.begin(); i != Z0.end(); ++i) {
195  out << JGraph(i->second, MAKE_CSTRING("G[" << i->first << "].twist"));
196  }
197 
198  out.Write();
199  out.Close();
200 }
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
void put(const Double_t x, const Double_t y)
Put data.
Definition: JGraph.hh:28
Data structure for graph data.
Definition: JGraph.hh:21
collection_type::const_iterator const_iterator
Definition: JPolfit.hh:157
#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.
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
static JRotation getRotation
Function object to get rotation matrix to go from first to second module.
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
Lookup table for PMT addresses in detector.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:445
Auxiliary data structure to build TGraph.
Definition: JGraph.hh:42
string outputFile
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
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
data_type::const_iterator const_iterator
Definition: JDynamics.hh:115
#define FATAL(A)
Definition: JMessage.hh:67
Data structure for unit quaternion in three dimensions.
Dynamic detector calibration.
Definition: JDynamics.hh:52
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
General purpose class for object reading from a list of file names.
static const JVector3D JVector3Z_t(0, 0, 1)
unit z-vector
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
do set_variable DETECTOR_TXT $WORKDIR detector
Auxiliary data structure for decomposition of quaternion in twist and swing quaternions.
const JModule & getModule(const JDetector &detector, const JModuleLocation &location)
find module with a given string and floor number
JQuaternion3D & conjugate()
Conjugate quaternion.