LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
CheckInteractions_module.cc
Go to the documentation of this file.
1 //
2 // __ __ __ __ __
3 // ____ ______/ /_____ _/ // / / /_/ /__
4 // / __ `/ ___/ __/ __ `/ // /_/ __/ //_/
5 // / /_/ / / / /_/ /_/ /__ __/ /_/ ,<
6 // \__,_/_/ \__/\__, / /_/ \__/_/|_|
7 // /____/
8 //
9 // artg4tk: art based Geant 4 Toolkit
10 //
11 //=============================================================================
12 // CheckInteractions_module.cc: Analyzer module that demonstrates access to hits
13 // and makes some histograms
14 //
15 // Author: Hans Wenzel (Fermilab)
16 //=============================================================================
17 
18 // C++ includes.
19 #include <iostream>
20 #include <sstream>
21 #include <string>
22 #include <vector>
23 
24 // art Framework includes.
31 #include "art_root_io/TFileService.h"
32 
33 // artg4tk includes:
34 #include "artg4tk/pluginDetectors/gdml/myInteractionArtHitData.hh"
35 
36 // Root includes.
37 #include "TH1F.h"
38 
39 using namespace std;
40 namespace artg4tk {
41  class CheckInteractions;
42 }
43 
45 public:
46  explicit CheckInteractions(fhicl::ParameterSet const& p);
47  void beginJob() override;
48  void beginRun(const art::Run& Run) override;
49  void endJob() override;
50  void analyze(const art::Event& event) override;
51 
52 private:
54  double fThetaMinFW;
55  double fDeltaThetaFW;
57  double fThetaMinLA;
58  double fDeltaThetaLA;
59  //
60  TH1F* _fHistoNSec; // number of secondaries
61  TH1F* _hEdep; // total energy deposition in CaloHits
62  TH1F* _hnDRHits; // number of DRCaloHits
63  TH1F* _hDREdep; // total energy deposition in DRCaloHits
64  TH1F* _hNCeren; // total number of Cerenkovphotons in DRCaloHits
65  std::vector<TH1D*> fHistoSecPiMinusFW;
66 };
67 
69  : art::EDAnalyzer(p)
70  , fNThetaBinsFW(p.get<int>("ThetaBinsFW", 4))
71  , fThetaMinFW(p.get<double>("ThetaMinFW", 0.05))
72  , fDeltaThetaFW(p.get<double>("DeltaThetaFW", 0.05))
73  , fNThetaBinsLA(p.get<int>("ThetaBinsLA", 9))
74  , fThetaMinLA(p.get<double>("ThetaMinLA", 0.35))
75  , fDeltaThetaLA(p.get<double>("DeltaThetaLA", 0.2))
76  , _fHistoNSec(0)
77  , _hEdep(0)
78  , _hnDRHits(0)
79  , _hDREdep(0)
80  , _hNCeren(0)
81 {}
82 
83 void
85 {
86  thisRun.beginTime();
87 }
88 
89 void
91 {
92 
94  _fHistoNSec = tfs->make<TH1F>("NSec", "proton + Ta", 100, 0., 100.);
95  _hEdep = tfs->make<TH1F>("hEdep", "total Energy deposition in CaloArtHits", 100, 0., 15.);
96  _hnDRHits = tfs->make<TH1F>("hnDRHits", "Number of DRCaloArtHits", 100, 0., 20000.);
97  _hDREdep = tfs->make<TH1F>("hDREdep", "total Energy deposition in DRCaloArtHits", 100, 0., 11.);
98  _hNCeren = tfs->make<TH1F>(
99  "hNCeren", "total number of Cerenkov Photons in DRCaloArtHits", 100, 0., 1000000.);
100 
101  string htitle;
102  string hname;
103  string ht = "proton + Ta";
104 
105  double thetaMin = 0.;
106  double thetaMax = 0.;
107  std::string theta_bin_fw;
108  std::string theta_bin_la;
109 
110  for (int i = 0; i < fNThetaBinsFW; i++) {
111  thetaMin = fThetaMinFW + fDeltaThetaFW * i;
112  thetaMax = thetaMin + fDeltaThetaFW;
113 
114  std::ostringstream osTitle1;
115  std::ostringstream osTitle2;
116  std::ostringstream osTitle3;
117 
118  osTitle1.clear();
119  osTitle1 << thetaMin;
120  theta_bin_fw = osTitle1.str() + " < theta < ";
121  osTitle2.clear();
122  osTitle2 << thetaMax;
123  theta_bin_fw += osTitle2.str();
124  theta_bin_fw += "(rad)";
125 
126  osTitle3.clear();
127  osTitle3 << i;
128 
129  htitle = ht + " -> X + pi-, " + theta_bin_fw;
130  hname = "piminus_fw_" + osTitle3.str();
131  TH1D* histo = tfs->make<TH1D>(hname.c_str(), htitle.c_str(), 80, 0., 8.0);
132  fHistoSecPiMinusFW.push_back(histo);
133  }
134 
135 } // end beginJob
136 
137 void
139 {
140  typedef std::vector<art::Handle<myInteractionArtHitDataCollection>> HandleVector;
141  auto allSims = event.getMany<myInteractionArtHitDataCollection>();
142 
143  cout << "CheckInteractions Event: " << event.event()
144  << " Nr of Interaction collections: " << allSims.size() << endl;
145 
146  for (HandleVector::const_iterator i = allSims.begin(); i != allSims.end(); ++i) {
147  const myInteractionArtHitDataCollection& sims(**i);
148  cout << "InteractionHit collection size: " << sims.size() << endl;
149  if (sims.size() > 0) {
150  _fHistoNSec->Fill(sims.size());
151  }
152  for (myInteractionArtHitDataCollection::const_iterator j = sims.begin(); j != sims.end(); ++j) {
153  const myInteractionArtHitData& hit = *j;
154  cout << "Name: " << hit.pname << " Momentum: " << hit.pmom << " Theta: " << hit.theta
155  << endl;
156 
157  if (hit.theta < fThetaMinFW)
158  continue;
159  if (hit.theta < fThetaMinFW + fDeltaThetaFW * fNThetaBinsFW) {
160  int ith = (hit.theta - fThetaMinFW) / fDeltaThetaFW;
161  if (hit.pname == "pi-") {
162  fHistoSecPiMinusFW[ith]->Fill(hit.pmom);
163  }
164  }
165  }
166  }
167 
168 } // end analyze
169 
170 void
172 {
173  cout << " ********************************CheckInteractions: now normalizing the histos " << endl;
174  double norm = _fHistoNSec->Integral();
175  double xbin = _fHistoNSec->GetBinWidth(1);
176  double scale = 1. / (xbin * norm);
177  _fHistoNSec->Scale(scale);
178 } // end endJob
179 
void beginRun(const art::Run &Run) override
STL namespace.
CheckInteractions(fhicl::ParameterSet const &p)
intermediate_table::const_iterator const_iterator
Definition: Run.h:37
Double_t scale
Definition: plot.C:24
std::vector< TH1D * > fHistoSecPiMinusFW
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
void beginJob()
Definition: Breakpoints.cc:14
void analyze(const art::Event &event) override
Detector simulation of raw signals on wires.
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
Float_t norm
Definition: MVAAlg.h:12
Timestamp const & beginTime() const
Definition: Run.cc:33
Event finding and building.