Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JRadiation.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "TROOT.h"
6 #include "TFile.h"
7 #include "TH1D.h"
8 
9 #include "JTools/JQuantile.hh"
10 
11 #include "JPhysics/JRadiation.hh"
13 #include "JPhysics/JGeane.hh"
14 #include "JPhysics/JConstants.hh"
15 
16 #include "JSirene/JSeaWater.hh"
17 #include "JLang/JSharedPointer.hh"
18 
19 #include "Jeep/JPrint.hh"
20 #include "Jeep/JParser.hh"
21 #include "Jeep/JMessage.hh"
22 
23 
24 namespace {
25 
26  static const std::string LENGTH = "length"; //!< calculation of interaction length
27  static const std::string ENERGY = "energy"; //!< calculation of shower energy
28  static const std::string RANGE = "range"; //!< calculation of muon range
29  static const std::string ELOSS = "eloss"; //!< calculation of b parameter in dE/dx formula
30 
31  /**
32  * Clone master histogram.
33  *
34  * \param h1 pointer to master histogram
35  * \param buffer name of clone
36  * \return pointer to cloned histogram
37  */
38  inline TH1* clone(TH1* h1, const char* buffer)
39  {
40  if (h1 != NULL)
41  return (TH1*) h1->Clone(buffer);
42  else
43  return NULL;
44  }
45 }
46 
47 
48 /**
49  * \file
50  *
51  * Example program to histogram radiation cross sections, shower energy, range and b(E)
52  * as a function of the muon energy.
53  * \author mdejong
54  */
55 int main(int argc, char* argv[])
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
Energy loss of muon.
#define STATUS(A)
Definition: JMessage.hh:63
static const double H
Planck constant [eV s].
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
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.
Muon radiative cross sections.
string outputFile
I/O formatting auxiliaries.
#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
Physics constants.
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
alias put_queue eval echo n
Definition: qlib.csh:19
int numberOfPoints
Definition: JResultPDF.cc:22
int j
Definition: JPolint.hh:666
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:483
then usage $script[input file[working directory[option]]] nWhere option can be N
Definition: JMuonPostfit.sh:37
then usage $script[input file[working directory[option]]] nWhere option can be E
Definition: JMuonPostfit.sh:37
virtual double getA() const override
Get energy loss constant.
Definition: JGeane.hh:229
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
int main(int argc, char *argv[])
Definition: Main.cpp:15