All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRTCalibrationAnalysis_module.cc
Go to the documentation of this file.
1 /**
2  * @file CRTCalibrationAnalysis_module.cc
3  * @brief Access CRT data and reco products and compare to MCTruth info
4  * @author Chris Hilgenberg (Chris.Hilgenberg@colostate.edu)
5  *
6  * The last revision of this code was done in October 2018 with LArSoft v07_06_01.
7  */
8 
9 // LArSoft includes
15 #include "larcore/CoreUtils/ServiceUtil.h" // lar::providerFrom()
19 
20 // Framework includes
21 #include "art/Framework/Core/EDAnalyzer.h"
22 #include "art/Framework/Principal/Event.h"
23 #include "art/Framework/Principal/Handle.h"
24 #include "art/Framework/Services/Registry/ServiceHandle.h"
25 #include "art_root_io/TFileService.h"
26 #include "art/Framework/Core/ModuleMacros.h"
27 #include "canvas/Persistency/Common/FindManyP.h"
28 #include "canvas/Utilities/Exception.h"
29 
30 // Utility libraries
31 #include "messagefacility/MessageLogger/MessageLogger.h"
32 #include "fhiclcpp/ParameterSet.h"
33 #include "fhiclcpp/types/Table.h"
34 #include "fhiclcpp/types/Atom.h"
35 #include "cetlib/pow.h" // cet::sum_of_squares()
36 
37 // ROOT includes
38 #include "TH1.h"
39 #include "TH2.h"
40 #include "TTree.h"
41 #include "TLorentzVector.h"
42 #include "TVector3.h"
43 #include "TGeoManager.h"
44 #include "TMath.h"
45 #include "TROOT.h"
46 
47 // C++ includes
48 #include <map>
49 #include <vector>
50 #include <string>
51 #include <set>
52 #include <cmath>
53 #include <iostream>
54 #include <utility>
55 #include <array>
56 
57 // CRT data products
61 
62 using std::string;
63 using std::vector;
64 using std::map;
65 using std::set;
66 using std::pair;
67 using std::to_string;
68 
69 namespace icarus {
70 namespace crt {
71 
72  class CRTCalibrationAnalysis : public art::EDAnalyzer
73  {
74  public:
75 
76  struct Config {
77 
78  // Save some typing:
79  using Name = fhicl::Name;
80  using Comment = fhicl::Comment;
81 
82  fhicl::Atom<art::InputTag> CRTDAQLabel {
83  Name("CRTDAQLabel"),
84  Comment("tag of the input data product with calibrated CRT data")
85  };
86 
87 
88  }; // Config
89 
90  using Parameters = art::EDAnalyzer::Table<Config>;
91 
92 
93  /// Constructor: configures the module (see the Config structure above)
94  explicit CRTCalibrationAnalysis(Parameters const& config);
95 
96  virtual void beginJob() override;
97  virtual void beginRun(const art::Run& run) override;
98  virtual void analyze (const art::Event& event) override;
99 
100 
101  private:
102 
103  art::ServiceHandle<art::TFileService> tfs;
104 
105  map<uint8_t,vector<TH1F*>*> macToHistos;
106 
107  // The parameters we'll read from the .fcl file.
108  art::InputTag fCRTDAQProducerLabel;
109 
110  // Other variables that will be shared between different methods.
111  geo::GeometryCore const* fGeometryService; ///< pointer to Geometry provider
112  int fTriggerOffset; ///< (units of ticks) time of expected neutrino event
114  }; // class CRTCalibrationAnalysis
115 
116 
117  //-----------------------------------------------------------------------
118 
120  : EDAnalyzer(config)
121  , fCRTDAQProducerLabel(config().CRTDAQLabel())
122  , fCrtutils(new CRTCommonUtils())
123  {
124  // Get a pointer to the geometry service provider.
125  fGeometryService = lar::providerFrom<geo::Geometry>();
126  // The same for detector TDC clock services.
127  // Access to detector properties.
128  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
129  fTriggerOffset = trigger_offset(clockData);
130 
131  for(int i=1; i<232; i++){
132 
133  macToHistos[i] = new vector<TH1F*>();
134 
135  for(int ch=0; ch<32; ch++){
136 
137  string hname = "hadc_"+to_string(i)+"_"+to_string(ch);
138  string htitle = "raw charge: mac5 "+to_string(i)+", ch. "+to_string(ch);
139  macToHistos[i]->push_back(tfs->make<TH1F>(hname.c_str(),htitle.c_str(),4100,0,4100));
140  }
141  }
142  }
143 
144  //-----------------------------------------------------------------------
146  {
147  }
148 
149  void CRTCalibrationAnalysis::beginRun(const art::Run& /*run*/)
150  {
151  }
152 
153  //-----------------------------------------------------------------------
154  void CRTCalibrationAnalysis::analyze(const art::Event& event)
155  {
156  MF_LOG_DEBUG("CRTCalibrationAnalysis") << "beginning analyis" << '\n';
157 
158 
159  art::Handle<vector<icarus::crt::CRTData>> crtDAQHandle;
160  bool isCRTDAQ = event.getByLabel(fCRTDAQProducerLabel, crtDAQHandle);
161 
162  if (isCRTDAQ) {
163  MF_LOG_DEBUG("CRTCalibrationAnalysis") << "about to loop over CRTDAQ entries" << '\n';
164 
165  for ( auto const& febdat : (*crtDAQHandle) ) {
166 
167  for(int ch=0; ch<32; ch++) {
168  macToHistos[febdat.fMac5]->at(ch)->Fill( febdat.fAdc[ch] );
169  }
170 
171  } //for CRT FEB events
172 
173  }//if crtdetsim products present
174 
175  else
176  mf::LogError("CRTCalibrationAnalysis") << "CRTDAQ products not found!" << std::endl;
177 
178  } // CRTCalibrationAnalysis::analyze()
179 
180  DEFINE_ART_MODULE(CRTCalibrationAnalysis)
181 } // namespace crt
182 } // namespace icarus
183 
art::ServiceHandle< art::TFileService > tfs
Utilities related to art service access.
Declaration of signal hit object.
CRTCalibrationAnalysis(Parameters const &config)
Constructor: configures the module (see the Config structure above)
Access the description of auxiliary detector geometry.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
Access the description of detector geometry.
object containing MC truth information necessary for making RawDigits and doing back tracking ...
virtual void analyze(const art::Event &event) override
int fTriggerOffset
(units of ticks) time of expected neutrino event
BEGIN_PROLOG vertical distance to the surface Name
Description of geometry of one entire detector.
Declaration of cluster object.
Definition of data types for geometry description.
map< uint8_t, vector< TH1F * > * > macToHistos
geo::GeometryCore const * fGeometryService
pointer to Geometry provider
std::string to_string(WindowPattern const &pattern)
int trigger_offset(DetectorClocksData const &data)
process_name crt
art framework interface to geometry description
virtual void beginRun(const art::Run &run) override
art::EDAnalyzer::Table< Config > Parameters