All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ISCalcAna_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: ISCalcAna
3 // Plugin Type: analyzer (art v2_05_00)
4 // File: ISCalcAna_module.cc
5 //
6 // Generated at Tue Mar 7 14:59:03 2017 by Wesley Ketchum using cetskelgen
7 // from cetlib version v1_21_00.
8 // modified at Sept 30, 2019, by muve
9 ////////////////////////////////////////////////////////////////////////
10 
11 #include "art/Framework/Core/EDAnalyzer.h"
12 #include "art/Framework/Core/ModuleMacros.h"
13 #include "art/Framework/Principal/Event.h"
14 #include "art/Framework/Principal/Handle.h"
15 #include "art/Framework/Principal/Run.h"
16 #include "art/Framework/Principal/SubRun.h"
17 #include "canvas/Utilities/InputTag.h"
18 #include "fhiclcpp/ParameterSet.h"
19 #include "messagefacility/MessageLogger/MessageLogger.h"
20 #include "nurandom/RandomUtils/NuRandomService.h"
21 
22 #include "TNtuple.h"
23 #include "art_root_io/TFileService.h"
24 
29 
35 
36 namespace larg4 {
37  class ISCalcAna : public art::EDAnalyzer {
38  public:
39  explicit ISCalcAna(fhicl::ParameterSet const& p);
40  ISCalcAna(ISCalcAna const&) = delete;
41  ISCalcAna(ISCalcAna&&) = delete;
42  ISCalcAna& operator=(ISCalcAna const&) = delete;
43  ISCalcAna& operator=(ISCalcAna&&) = delete;
44 
45  void analyze(art::Event const& event) override;
46  void beginJob() override;
47  void endJob() override;
48 
49  private:
50  std::unique_ptr<ISCalc> fISAlg;
51  art::InputTag fEDepTag;
52  art::InputTag calcTag; // name of calculator to use, NEST or Separate
53  CLHEP::HepRandomEngine& fEngine;
54  TNtuple* fNtuple;
55  };
56 
57  ISCalcAna::ISCalcAna(fhicl::ParameterSet const& pset)
58  : EDAnalyzer(pset)
59  , fEDepTag{pset.get<art::InputTag>("SimulationLabel")}
60  , calcTag{pset.get<art::InputTag>("ISCalcAlg")}
61  , fEngine(art::ServiceHandle<rndm::NuRandomService>()
62  ->createEngine(*this, "HepJamesRandom", "NEST", pset, "SeedNEST"))
63  {
64  std::cout << "ISCalcAna constructor." << std::endl;
65  }
66 
67  void
69  {
70  std::cout << "ISCalcAna beginJob." << std::endl;
71  std::cout << "Using " << calcTag.label() << " algorithm to calculate IS." << std::endl;
72 
73  if (calcTag.label() == "Separate")
74  fISAlg = std::make_unique<larg4::ISCalcSeparate>();
75  else if (calcTag.label() == "Correlated") {
76  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService>()->DataForJob();
77  fISAlg = std::make_unique<larg4::ISCalcCorrelated>(detProp, fEngine);
78  }
79  else if (calcTag.label() == "NEST")
80  fISAlg = std::make_unique<larg4::ISCalcNESTLAr>(fEngine);
81  else
82  mf::LogWarning("IonAndScint") << "No ISCalculation set, this can't be good.";
83 
84  art::ServiceHandle<art::TFileService const> tfs;
85  fNtuple = tfs->make<TNtuple>(
86  "nt_is",
87  "EDep IS Calc Ntuple",
88  "run:event:t:x:y:z:ds:e:trackid:pdg:e_deposit:n_electron:n_photon:scintyield");
89  }
90  void
92  {
93  std::cout << "ISCalcAna endJob." << std::endl;
94  }
95 
96  void
97  ISCalcAna::analyze(art::Event const& event)
98  {
99  art::Handle<std::vector<sim::SimEnergyDeposit>> edep_handle;
100  if (!event.getByLabel(fEDepTag, edep_handle)) {
101  std::cout << "PDFastSimPAR Module Cannot getByLabel: " << fEDepTag << std::endl;
102  return;
103  }
104 
105  auto const detProp =
106  art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(event);
107  for (auto const& edepi : *edep_handle) {
108  auto const [energyDeposit, nElectrons, nPhotons, scintYieldRatio] =
109  fISAlg->CalcIonAndScint(detProp, edepi);
110  fNtuple->Fill(event.run(),
111  event.event(),
112  edepi.T(),
113  edepi.X(),
114  edepi.Y(),
115  edepi.Z(),
116  edepi.StepLength(),
117  edepi.Energy(),
118  edepi.TrackID(),
119  edepi.PdgCode(),
120  energyDeposit,
121  nElectrons,
122  nPhotons,
123  scintYieldRatio);
124  }
125 
126  std::cout << "ISCalcAna analyze completed." << std::endl;
127  }
128 }
129 DEFINE_ART_MODULE(larg4::ISCalcAna)
Store parameters for running LArG4.
void beginJob() override
pdgs p
Definition: selectors.fcl:22
void analyze(art::Event const &event) override
ISCalcAna & operator=(ISCalcAna const &)=delete
ISCalcAna(fhicl::ParameterSet const &p)
art::InputTag fEDepTag
art::InputTag calcTag
std::unique_ptr< ISCalc > fISAlg
CLHEP::HepRandomEngine & fEngine
contains information for a single step in the detector simulation
art::ServiceHandle< art::TFileService > tfs
BEGIN_PROLOG could also be cout
auto const detProp
void endJob() override