All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LArPropTest_module.cc
Go to the documentation of this file.
1 //
2 // Name: LArPropTest_module.cc
3 //
4 // Purpose: LArPropTest module. Test some features of LArProperties
5 // service.
6 //
7 // Created: 5-Apr-2012 H. Greenlee
8 
9 #include <iomanip>
10 #include <iostream>
11 
12 #include "art/Framework/Core/EDAnalyzer.h"
13 #include "art/Framework/Core/ModuleMacros.h"
14 #include "art/Framework/Principal/Event.h"
15 
16 #include "larcore/CoreUtils/ServiceUtil.h" // lar::providerFrom<>()
21 
22 namespace util {
23  class LArPropTest : public art::EDAnalyzer {
24  public:
25  explicit LArPropTest(fhicl::ParameterSet const& pset);
26 
27  private:
28  void beginJob() override;
29  void analyze(const art::Event& evt) override;
30  };
31 
32  DEFINE_ART_MODULE(LArPropTest)
33 
34  LArPropTest::LArPropTest(const fhicl::ParameterSet& pset) : EDAnalyzer(pset) {}
35 
36  void
38  {
39  // Make sure assert is enabled.
40 
41  bool assert_flag = false;
42  assert((assert_flag = true, assert_flag));
43  if (!assert_flag) {
44  std::cerr << "Assert is disabled" << std::endl;
45  abort();
46  }
47 
48  // Get services.
49 
50  detinfo::LArProperties const* larprop = lar::providerFrom<detinfo::LArPropertiesService>();
51  auto const detprop =
52  art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob();
53 
54  // Test (default) accessors.
55 
56  std::cout << "Density = " << detprop.Density() << " g/cm^3" << std::endl;
57  std::cout << "Drift velocity = " << detprop.DriftVelocity() << " cm/usec" << std::endl;
58  std::cout << "Efield = " << detprop.Efield() << " kV/cm" << std::endl;
59  std::cout << "Temperature = " << detprop.Temperature() << " Kelvin" << std::endl;
60  std::cout << "Electron lifetime = " << detprop.ElectronLifetime() << " usec" << std::endl;
61  std::cout << "Radiation Length = " << larprop->RadiationLength() << " g/cm^2" << std::endl;
62  std::cout << "Radiation Length = " << larprop->RadiationLength() / detprop.Density() << " cm"
63  << std::endl;
64 
65  // Make sure default values are acting correctly.
66 
67  assert(detprop.Density() == detprop.Density(detprop.Temperature()));
68  assert(detprop.Density() != detprop.Density(detprop.Temperature() + 0.1));
69  assert(detprop.DriftVelocity() == detprop.DriftVelocity(detprop.Efield()));
70  assert(detprop.DriftVelocity() ==
71  detprop.DriftVelocity(detprop.Efield(), detprop.Temperature()));
72 
73  // Drift velocity vs. electric field.
74 
75  std::cout << "\nDrift Velocity vs. Electric Field.\n"
76  << " E (kV/cm) v (cm/us)" << std::fixed << std::endl;
77  for (int i = 0; i < 3; ++i) {
78  double e = 0.5;
79  if (i == 1)
80  e = 0.666667;
81  else if (i == 2)
82  e = 0.8;
83  double v = detprop.DriftVelocity(e);
84  std::cout << std::setprecision(3) << std::setw(15) << e << std::setprecision(4)
85  << std::setw(15) << v << std::endl;
86  }
87 
88  // dE/dx.
89 
90  std::cout
91  << "\nCompare "
92  "http://pdg.lbl.gov/2011/AtomicNuclearProperties/MUON_ELOSS_TABLES/muonloss_289.dat\n"
93  << std::endl;
94 
95  double mass = 0.10565839; // Muon.
96  double fact[16] = {
97  1.0, 1.2, 1.4, 1.7, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 7.0, 8.0, 9.0};
98 
99  std::ios_base::fmtflags flags = std::cout.flags();
100  std::cout << " T p Ionization dE/dx|_R\n"
101  << " [MeV] [MeV/c] ---[MeV cm^2/g]----\n"
102  << std::scientific << std::setprecision(3);
103 
104  // Loop over kinetic energy.
105 
106  for (double tbase = 1.; tbase <= 1.e9; tbase *= 10.) {
107  for (int i = 0; i < 16; ++i) {
108 
109  // T in MeV.
110 
111  double t = tbase * fact[i];
112  if (t > 1.e9) break;
113 
114  // Calculate momentum in GeV/C
115 
116  double p = std::sqrt(1.e-6 * t * t + 2.e-3 * t * mass);
117 
118  // Calculate restricted and unrestricted dE/dx.
119 
120  double dedxr = detprop.Eloss(p, mass, 0.05) / detprop.Density(); // Restricted.
121  double dedx = detprop.Eloss(p, mass, 0.) / detprop.Density(); // Unrestricted.
122  std::cout << std::setw(10) << t << std::setw(10) << 1000. * p << std::setw(10) << dedx
123  << std::setw(10) << dedxr << std::endl;
124  }
125  }
126  std::cout.flags(flags);
127  }
128 
129  void
130  LArPropTest::analyze(const art::Event& /* evt */)
131  {}
132 }
Utilities related to art service access.
void beginJob() override
BEGIN_PROLOG could also be cerr
void analyze(const art::Event &evt) override
LArPropTest(fhicl::ParameterSet const &pset)
pdgs p
Definition: selectors.fcl:22
float mass
Definition: dedx.py:47
do i e
virtual double RadiationLength() const =0
TCEvent evt
Definition: DataStructs.cxx:8
BEGIN_PROLOG could also be cout