Jpp  19.1.0-rc.1
the software that should make you happy
JEventShapeVariables.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 #include <vector>
4 
7 
11 
14 
16 
17 #include "JDetector/JDetector.hh"
19 
20 #include "JSupport/JSupport.hh"
24 
25 #include "Jeep/JeepToolkit.hh"
26 #include "Jeep/JParser.hh"
27 #include "Jeep/JMessage.hh"
28 
29 #include "TFile.h"
30 #include "TH1D.h"
31 
32 
33 /**
34  * \file
35  *
36  * Auxiliary program to plot event shape variables.
37  * \author bjjung
38  */
39 int main(int argc, char **argv)
40 {
41  using namespace std;
42  using namespace JPP;
43 
44  JMultipleFileScanner_t inputFiles;
45  string outputFile;
46  string detectorFile;
47 
48  JLimit_t numberOfEvents;
49 
50  bool useBoost;
51 
52  bool useWeights;
53  string oscProbTable;
54  JOscParameters<double> oscParameters;
55  JFluxMap fluxMap{JOscProbInterpolator<>()};
56 
57  int debug;
58 
59  try {
60 
61  JParser<> zap("Auxiliary program to test event shape variables.");
62 
63  zap['f'] = make_field(inputFiles);
64  zap['o'] = make_field(outputFile);
65  zap['a'] = make_field(detectorFile) = "";
66  zap['n'] = make_field(numberOfEvents) = JLimit::max();
67  zap['B'] = make_field(useBoost);
68  zap['W'] = make_field(useWeights);
69  zap['@'] = make_field(fluxMap)
71  zap['P'] = make_field(oscProbTable)
73  zap['#'] = make_field(oscParameters)
75  zap['d'] = make_field(debug) = 3;
76 
77  zap(argc, argv);
78  }
79  catch(const exception &error) {
80  FATAL(error.what() << endl);
81  }
82 
83  if (useWeights && numberOfEvents != JLimit::max()) {
84  FATAL("Cannot apply weighting to limited number of events.");
85  }
86 
87 
88  // Load detector file
89 
91 
92  if (!detectorFile.empty()) {
93  try {
94  load(detectorFile, detector);
95  }
96  catch(const JException& error) {
97  FATAL(error);
98  }
99  }
100 
101  JCylinder3D fiducialVolume;
102 
103  if (!detector.empty()) {
104  fiducialVolume.set(detector.begin(), detector.end());
105  }
106 
107 
108  // Load oscillation probability table
109 
110  if (!oscProbTable.empty()) {
111 
112  JOscProbInterpolator<>& interpolator = static_cast<JOscProbInterpolator<>&>(fluxMap.oscProb.getOscProbInterface());
113 
114  interpolator.load(oscProbTable.c_str());
115  interpolator.set (oscParameters);
116  }
117 
118 
119  // Create file scanners
120 
121  JEvtWeightFileScannerSet<> scanners(inputFiles);
122 
123  if (scanners.setFlux(fluxMap) == 0) {
124  WARNING("No flux function set." << endl);
125  }
126 
127 
128  // Define histograms
129 
130  TFile out(outputFile.c_str(), "recreate");
131 
132  TH1D hT("hT", "thrust", 50, 0.5, 1.0);
133 
134  TH1D hA("hA", "aplanarity", 50, 0.0, 0.5);
135  TH1D hS("hS", "sphericity", 100, 0.0, 1.0);
136  TH1D hc("hc", "circularity", 100, 0.0, 1.0);
137  TH1D hp("hp", "planar flow", 100, 0.0, 1.0);
138 
139  TH1D hC("hC", "C-variable", 100, 0.0, 1.0);
140  TH1D hD("hD", "D-variable", 100, 0.0, 1.0);
141 
142  TH1D hH10("hH10", "H10", 100, 0.0, 1.0);
143  TH1D hH20("hH20", "H20", 100, 0.0, 1.0);
144  TH1D hH30("hH30", "H30", 100, 0.0, 1.0);
145  TH1D hH40("hH40", "H40", 100, 0.0, 1.0);
146 
147  TH1D hq("hq", "Logarithmic eigenvalue ratio hit inertia tensor", 200, -20.0, 0.0);
148 
149 
150  // Loop over events
151 
152  STATUS(RIGHT(15) << "header ID" << RIGHT(15) << "event" << RIGHT(15) << "weight" << endl);
153 
154  for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
155 
156  scanner->setLimit(numberOfEvents);
157 
158  const JHead& header = scanner->getHeader();
159 
160  if (detector.empty()) { // Use can volume if detector file has not been specified
161  fiducialVolume = getCylinder(header);
162  }
163 
164  while (scanner->hasNext()) {
165 
166  Evt* event = scanner->next();
167 
168  const double weight = (useWeights ? scanner->getWeight(*event) : 1.0);
169 
170  STATUS(RIGHT (15) << distance(scanners.begin(), scanner) <<
171  RIGHT (15) << scanner->getCounter() <<
172  SCIENTIFIC(15, 3) << weight << '\r'); DEBUG(endl);
173 
174  if (useBoost) { boostToCOM(*event); }
175 
176  const JVertex3D vertex = getVertex(*event);
177 
178  const JSphericityTensor S1(*event, 1.0);
179  const JSphericityTensor S2(*event, 2.0);
180 
181  const JFoxWolframMoments H(*event, fiducialVolume, 4);
182 
183  const JHitInertiaTensor Q(*event, vertex);
184 
185  const double thrust = getThrust(*event);
186 
187  const double aplanarity = S2.getAplanarity();
188  const double sphericity = S2.getSphericity();
189  const double circularity = S2.getCircularity();
190  const double planarflow = S2.getPlanarFlow();
191 
192  const double C = S1.getC();
193  const double D = S1.getD();
194 
195  const double q = Q.getEigenvalueRatio();
196 
197  hT.Fill(thrust, weight);
198 
199  hA.Fill(aplanarity, weight);
200  hS.Fill(sphericity, weight);
201  hc.Fill(circularity, weight);
202  hp.Fill(planarflow, weight);
203 
204  hC.Fill(C, weight);
205  hD.Fill(D, weight);
206 
207  hH10.Fill(H[1]/H[0], weight);
208  hH20.Fill(H[2]/H[0], weight);
209  hH30.Fill(H[3]/H[0], weight);
210  hH40.Fill(H[4]/H[0], weight);
211 
212  hq.Fill(log10(q), weight);
213  }
214  }
215 
216  STATUS(endl);
217 
218  out.Write();
219  out.Close();
220 
221  return 0;
222 }
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
string outputFile
Data structure for detector geometry and calibration.
int main(int argc, char **argv)
Event shape variables.
Auxiliary methods for calculating Lorentz boosts.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define STATUS(A)
Definition: JMessage.hh:63
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define WARNING(A)
Definition: JMessage.hh:65
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
ROOT TTree parameter settings of various packages.
Auxiliary methods for handling file names, type names and environment.
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 for a map between event categories and flux factors.
Monte Carlo run header.
Definition: JHead.hh:1236
const JHead & getHeader() const
Get header.
Definition: JHead.hh:1270
Detector data structure.
Definition: JDetector.hh:96
void set(const JVector2D &p0, const JVector2D &p1)
Set circle.
Definition: JCircle2D.hh:157
Cylinder object.
Definition: JCylinder3D.hh:41
General exception.
Definition: JException.hh:24
Data structure for single set of oscillation parameters.
Template definition of a multi-dimensional oscillation probability interpolation table.
void load(const char *const fileName)
Load oscillation probability table from file.
Utility class to parse command line options.
Definition: JParser.hh:1714
#define S1(x)
void boostToCOM(Evt &event)
Boost event to the Center of Mass (COM) frame.
JCylinder3D getCylinder(const JHead &header)
Get cylinder corresponding to the positions of generated tracks (i.e.
JVertex3D getVertex(const Trk &track)
Get vertex.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
@ RIGHT
Definition: JTwosome.hh:18
static const double H
Planck constant [eV s].
static const double C
Physics constants.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
double getThrust(const std::vector< Trk >::const_iterator __begin, const std::vector< Trk >::const_iterator __end)
Compute thrust for a given range of tracks.
Definition: JSTDTypes.hh:14
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:21
Detector file.
Definition: JHead.hh:227
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:84
Class for computing Fox-Wolfram moments.
Class for hit inertia tensor calculations.
double getEigenvalueRatio() const
Get eigenvalue ratio.
Class for sphericity tensor calculations.
double getSphericity() const
Get sphericity.
double getAplanarity() const
Get aplanarity.
double getCircularity() const
Get circularity.
double getPlanarFlow() const
Get planar flow.
Auxiliary class for organising Monte Carlo file scanners associated with event weighters.
size_t setFlux(const JEvtCategoryHelper &category, const JFluxHelper &flux)
Set flux function for all MC-files corresponding to a given event category.
std::vector< filescanner_type >::iterator iterator
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:45
Auxiliary base class for list of file names.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:488