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

Example program to histogram radiation cross sections, shower energy, range and b(E) as a function of the muon energy. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "JTools/JQuantile.hh"
#include "JPhysics/JRadiation.hh"
#include "JPhysics/JRadiationSource.hh"
#include "JPhysics/JGeane.hh"
#include "JPhysics/JConstants.hh"
#include "JSirene/JSeaWater.hh"
#include "JLang/JSharedPointer.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 histogram radiation cross sections, shower energy, range and b(E) as a function of the muon energy.

Author
mdejong

Definition in file JRadiation.cc.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 55 of file JRadiation.cc.

56 {
57  using namespace std;
58 
59  string outputFile;
60  int numberOfPoints;
61  string option;
62  int debug;
63 
64  try {
65 
66  JParser<> zap("Example program to histogram radiation cross sections, shower energy, range and b(E).");
67 
68  zap['o'] = make_field(outputFile) = "radiation.root";
69  zap['n'] = make_field(numberOfPoints) = 0;
70  zap['O'] = make_field(option) = LENGTH, ENERGY, RANGE, ELOSS;
71  zap['d'] = make_field(debug) = 0;
72 
73  zap(argc, argv);
74  }
75  catch(const exception &error) {
76  FATAL(error.what() << endl);
77  }
78 
79 
80  using namespace JPP;
81 
82 
83  TFile out(outputFile.c_str(), "recreate");
84 
85  TH1* h0 = NULL; // master histogram
86 
87  if (option == LENGTH) {
88  h0 = new TH1D("total", NULL, 160, 2.0, 10.0); // interaction length [m]
89  }
90 
91  if (option == ENERGY) {
92  h0 = new TH1D("total", NULL, 24, 2.0, 10.0); // <E> [GeV]
93  }
94 
95  NOTICE("Setting up radiation tables... " << flush);
96 
97  typedef pair<JSharedPointer<JRadiationInterface>, TH1*> tuple;
98  typedef vector<tuple> ntuple;
99 
100  ntuple radiation;
101 
102  const JRadiation hydrogen( 1.0, 1.0, 40, 0.01, 0.1, 0.1);
103  const JRadiation oxygen ( 8.0, 16.0, 40, 0.01, 0.1, 0.1);
104  const JRadiation chlorine(17.0, 35.0, 40, 0.01, 0.1, 0.1);
105 
106  JSharedPointer<JRadiation> Hydrogen(new JRadiationFunction(hydrogen, 300, 0.2, 1.0e11));
107  JSharedPointer<JRadiation> Oxygen (new JRadiationFunction(oxygen, 300, 0.2, 1.0e11));
108  JSharedPointer<JRadiation> Chlorine(new JRadiationFunction(chlorine, 300, 0.2, 1.0e11));
109 
110  JRadiationSource::source_type EErad(&JRadiation::TotalCrossSectionEErad, &JRadiation::EfromEErad);
111  JRadiationSource::source_type Brems(&JRadiation::TotalCrossSectionBrems, &JRadiation::EfromBrems);
112  JRadiationSource::source_type GNrad(&JRadiation::TotalCrossSectionGNrad, &JRadiation::EfromGNrad);
113 
114  radiation.push_back(tuple(new JRadiationSource(Oxygen, DENSITY_SEA_WATER * JSeaWater::O(), EErad), clone(h0, "[eerad O]" )));
115  radiation.push_back(tuple(new JRadiationSource(Chlorine, DENSITY_SEA_WATER * JSeaWater::Cl(), EErad), clone(h0, "[eerad Cl]")));
116  radiation.push_back(tuple(new JRadiationSource(Hydrogen, DENSITY_SEA_WATER * JSeaWater::H(), EErad), clone(h0, "[eerad H]" )));
117 
118  radiation.push_back(tuple(new JRadiationSource(Oxygen, DENSITY_SEA_WATER * JSeaWater::O(), Brems), clone(h0, "[Brems O]" )));
119  radiation.push_back(tuple(new JRadiationSource(Chlorine, DENSITY_SEA_WATER * JSeaWater::Cl(), Brems), clone(h0, "[Brems Cl]")));
120  radiation.push_back(tuple(new JRadiationSource(Hydrogen, DENSITY_SEA_WATER * JSeaWater::H(), Brems), clone(h0, "[Brems H]" )));
121 
122  radiation.push_back(tuple(new JRadiationSource(Oxygen, DENSITY_SEA_WATER * JSeaWater::O(), GNrad), clone(h0, "[gnrad O]" )));
123  radiation.push_back(tuple(new JRadiationSource(Chlorine, DENSITY_SEA_WATER * JSeaWater::Cl(), GNrad), clone(h0, "[gnrad Cl]")));
124  radiation.push_back(tuple(new JRadiationSource(Hydrogen, DENSITY_SEA_WATER * JSeaWater::H(), GNrad), clone(h0, "[gnrad H]" )));
125 
126  NOTICE("OK" << endl);
127 
128 
129  if (option == LENGTH) {
130 
131  for (int i = 1; i <= h0->GetNbinsX(); ++i) {
132 
133  const double x = h0->GetBinCenter(i);
134  const double E = pow(10.0, x);
135 
136  STATUS("Energy: " << SCIENTIFIC(8,1) << E << '\r'); DEBUG(endl);
137 
138  for (ntuple::iterator p = radiation.begin(); p != radiation.end(); ++p) {
139 
140  const double li = p->first->getInverseInteractionLength(E);
141 
142  p->second->Fill(x, 1.0/li);
143  }
144  }
145  STATUS(endl);
146  }
147 
148 
149  if (option == ENERGY) {
150 
151  for (int i = 1; i <= h0->GetNbinsX(); ++i) {
152 
153  const double x = h0->GetBinCenter(i);
154  const double E = pow(10.0, x);
155 
156  STATUS("Energy: " << SCIENTIFIC(8,1) << E << '\r'); DEBUG(endl);
157 
158  for (ntuple::iterator p = radiation.begin(); p != radiation.end(); ++p) {
159 
160  JQuantile Q;
161 
162  for (int n = 0; n != numberOfPoints; ++n) {
163  Q.put(p->first->getEnergyOfShower(E));
164  }
165 
166  p->second->SetBinContent(i, Q.getMean());
167  //p->second->SetBinError (i, Q.getSTDev());
168  }
169  }
170  STATUS(endl);
171  }
172 
173 
174  if (option == RANGE) {
175 
176  TH1D* Ra = new TH1D("R[analytical]", NULL, 12, 2.0, 8.0); // Range [m]
177  TH1D* Rb = new TH1D("R[numerical]", NULL, 12, 2.0, 8.0); // Range [m]
178 
179  for (int i = 1; i <= Ra->GetNbinsX(); ++i) {
180 
181  const double x = Ra->GetBinCenter(i);
182  const double E0 = pow(10.0, x);
183  const double Z = gWater(E0);
184 
185  Ra->SetBinContent(i, Z*1e-3);
186  }
187 
188  for (int j = 1; j <= Rb->GetNbinsX(); ++j) {
189 
190  const double x = Rb->GetBinCenter(j);
191  const double E0 = pow(10.0, x);
192 
193  STATUS("Energy: " << SCIENTIFIC(8,1) << E0 << '\r'); DEBUG(endl);
194 
195  JQuantile Q;
196 
197  for (int n = 0; n != numberOfPoints; ++n) {
198 
199  double E = E0;
200  double z = 0.0;
201 
202  while (E >= 0.5) {
203 
204  const int N = radiation.size();
205 
206  double li[N]; // inverse interaction lengths
207  double ls = 1.0e-5; // minimal total inverse interaction length (100 km)^-1
208 
209  for (int i = 0; i != N; ++i) {
210  ls += li[i] = radiation[i].first->getInverseInteractionLength(E);
211  }
212 
213  double dz = min(gRandom->Exp(1.0) / ls, gWater(E));
214 
215  E -= gWater.getA() * dz;
216 
217  double Es = 0.0; // shower energy [GeV]
218  double y = gRandom->Uniform(ls);
219 
220  for (int i = 0; i != N; ++i) {
221 
222  y -= li[i];
223 
224  if (y < 0.0) {
225  Es = radiation[i].first->getEnergyOfShower(E); // shower energy [GeV]
226  break;
227  }
228  }
229 
230  z += dz;
231  E -= Es;
232  }
233 
234  Q.put(z);
235  }
236 
237  Rb->SetBinContent(j, Q.getMean() * 1e-3);
238  //Rb->SetBinError (j, Q.getSTDev() * 1e-3);
239  }
240  STATUS(endl);
241  }
242 
243 
244  if (option == ELOSS) {
245 
246  TH1D* hb = new TH1D("hb", NULL, 12, 2.0, 8.0); // b(E)
247 
248  for (int j = 1; j <= hb->GetNbinsX(); ++j) {
249 
250  const double x = hb->GetBinCenter(j);
251  const double E = pow(10.0, x);
252 
253  STATUS("Energy: " << SCIENTIFIC(8,1) << E << '\r'); DEBUG(endl);
254 
255  JQuantile Q;
256 
257  const int N = radiation.size();
258 
259  double li[N]; // inverse interaction lengths
260  double ls = 1.0e-5; // minimal total inverse interaction length (100 km)^-1
261 
262  for (int i = 0; i != N; ++i) {
263  ls += li[i] = radiation[i].first->getInverseInteractionLength(E);
264  }
265 
266  for (int i = 0; i != numberOfPoints; ++i) {
267 
268  double Es = 0.0; // shower energy [GeV]
269  double y = gRandom->Uniform(ls);
270 
271  for (int i = 0; i != N; ++i) {
272 
273  y -= li[i];
274 
275  if (y < 0.0) {
276  Es = radiation[i].first->getEnergyOfShower(E); // shower energy [GeV]
277  break;
278  }
279  }
280 
281  Q.put(1e3*ls*Es/E);
282  }
283 
284  hb->SetBinContent(j, Q.getMean());
285  //hb->SetBinError (j, Q.getSTDev());
286  }
287  STATUS(endl);
288  }
289 
290  delete h0;
291 
292  out.Write();
293  out.Close();
294 }
Utility class to parse command line options.
Definition: JParser.hh:1500
Q(UTCMax_s-UTCMin_s)-livetime_s
#define STATUS(A)
Definition: JMessage.hh:63
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
static const double H
Planck constant [eV s].
static const JGeaneWater gWater
Function object for energy loss of muon in sea water.
Definition: JGeane.hh:323
static const double DENSITY_SEA_WATER
Fixed environment values.
string outputFile
then usage E
Definition: JMuonPostfit.sh:35
const int n
Definition: JPolint.hh:660
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
#define NOTICE(A)
Definition: JMessage.hh:64
T pow(const T &x, const double y)
Power .
Definition: JMath.hh:98
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
int numberOfPoints
Definition: JResultPDF.cc:22
do set_variable MODULE getModule a $WORKDIR detector_a datx L $STRING JEditDetector a $WORKDIR detector_a datx M $MODULE setz o $WORKDIR detector_a datx JEditDetector a $WORKDIR detector_b datx M $MODULE setz o $WORKDIR detector_b datx done echo Output stored at $WORKDIR detector_a datx and $WORKDIR tripod_a txt JDrawDetector2D a $WORKDIR detector_a datx a $WORKDIR detector_b datx L BL o detector $FORMAT $BATCH JDrawDetector2D T $WORKDIR tripod_a txt T $WORKDIR tripod_b txt L BL o tripod $FORMAT $BATCH JCompareDetector a $WORKDIR detector_a datx b $WORKDIR detector_b datx o $WORKDIR abc root &dev null for KEY in X Y Z
int j
Definition: JPolint.hh:666
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:484
virtual double getA() const override
Get energy loss constant.
Definition: JGeane.hh:229