RawDigitAna_module.cc
Go to the documentation of this file.
1 //
2 // RawDigitAna_module.cc
3 //
4 // Created by Brian Rebel on 3/2/17.
5 //
6 
7 #ifndef GAR_ROSIM_RAWDIGITANA
8 #define GAR_ROSIM_RAWDIGITANA
9 
10 /// Framework includes
14 #include "fhiclcpp/ParameterSet.h"
17 #include "art_root_io/TFileService.h"
18 #include "art_root_io/TFileDirectory.h"
21 #include "canvas/Persistency/Common/FindMany.h"
23 #include "cetlib_except/exception.h"
24 
25 // GArSoft Includes
26 #include "MCCheater/BackTracker.h"
27 #include "nug4/ParticleNavigation/ParticleList.h"
29 #include "Geometry/GeometryGAr.h"
31 #include "CoreUtils/ServiceUtil.h"
32 
33 // ROOT includes
34 #include <TTree.h>
35 
36 // C++ Includes
37 #include <iostream>
38 #include <cstring>
39 #include <sys/stat.h>
40 
41 typedef struct{
42  int run;
43  int subrun;
44  int event;
45 } EventInfo;
46 
47 typedef struct{
48  int trackID;
49  int pdg;
50  float x;
51  float y;
52  float z;
53  float e;
54  float dX;
55  float t;
56 } EnergyDep;
57 
58 typedef struct{
59  int channel;
60  float x;
61  float y;
62  float z;
63 } ChannelInfo;
64 
65 namespace simb{
66  class MCTruth;
67 }
68 
69 namespace sim{
70  class ParticleList;
71 }
72 
73 namespace gar {
74  namespace rosim {
75 
77  public:
78 
79  /// Standard constructor and destructor for an FMWK module.
80  explicit RawDigitAna(fhicl::ParameterSet const& pset);
81  virtual ~RawDigitAna();
82 
84  void beginJob();
85  void reconfigure(fhicl::ParameterSet const& pset);
86 
87  private:
88 
89  std::string fReadoutModuleLabel; ///< module label for the Geant
90  TTree* fChannelTree; ///< Tree to keep track of sanity check info
91  EventInfo fEvt; ///< Struct containing event identification
92  EnergyDep fEDep; ///< Struct containing energy deposition info
93  ChannelInfo fChannelInfo; ///< Struct containing channel info
94  };
95 
96  } // namespace rosim
97 
98  namespace rosim {
99 
100  //-----------------------------------------------------------------------
101  // Constructor
102  RawDigitAna::RawDigitAna(fhicl::ParameterSet const& pset)
103  : EDAnalyzer(pset)
104  {
105  this->reconfigure(pset);
106  }
107 
108  //-----------------------------------------------------------------------
109  // Destructor
111  {
112  }
113 
114  //-----------------------------------------------------------------------
116  {
118 
119  fChannelTree = tfs->make<TTree>("ChannelTree", "ChannelTree");
120 
121  std::string description("run/I:subrun/I:event/I");
122 
123  fChannelTree->Branch("info", &fEvt, description.c_str());
124 
125  description = "trackID/I:pdg/I:x/F:y/F:z/F:e/F:dX/F:t/F";
126 
127  fChannelTree->Branch("edep", &fEDep, description.c_str());
128 
129  description = "channel/I:x/F:y/F:z/F";
130 
131  fChannelTree->Branch("chan", &fChannelInfo, description.c_str());
132 
133  }
134 
135  //-----------------------------------------------------------------------
137  {
138  fReadoutModuleLabel = p.get< std::string >("ReadoutModuleLabel");
139 
140  return;
141  }
142 
143  //-----------------------------------------------------------------------
145  {
146  // set the event id info
147  fEvt.run = evt.run();
148  fEvt.subrun = evt.subRun();
149  fEvt.event = evt.id().event();
150 
151  // get the list of particles from this event
152  auto bt = gar::providerFrom<cheat::BackTracker>();
153 
154  // get the raw digits for this event
155  auto digCol = evt.getValidHandle<std::vector<gar::raw::RawDigit> >(fReadoutModuleLabel);
156 
157  if( digCol.failedToGet() ){
158  MF_LOG_VERBATIM("RawDigitAna")
159  << "failed to get raw digits, bail";
160  return;
161  }
162 
163  // get the find many for the energy depositions
164  ::art::FindMany<gar::sdp::EnergyDeposit> fmEnergyDep(digCol, evt, fReadoutModuleLabel);
165 
166  if( !fmEnergyDep.isValid() ){
167  MF_LOG_WARNING("RawDigitAna")
168  << "Unable to find valid association between RawDigits and "
169  << "energy deposits, no analysis in this module is possible";
170 
171  return;
172  }
173 
174  auto geo = gar::providerFrom<geo::GeometryGAr>();
175 
176  float xyz[3] = {0.};
177  float xyzChan[3] = {0.};
178  unsigned int chan = 0;
179 
180  for(size_t d = 0; d < digCol->size(); ++d){
181  std::vector<const gar::sdp::EnergyDeposit*> edepsCol;
182  fmEnergyDep.get(d, edepsCol);
183  if(edepsCol.size() < 1) continue;
184 
185  MF_LOG_DEBUG("RawDigitAna")
186  << "There are "
187  << edepsCol.size()
188  << " energy depositions for channel "
189  << (*digCol)[d].Channel();
190 
191  geo->ChannelToPosition((*digCol)[d].Channel(), xyz);
192 
193  // fill the channel information
194  fChannelInfo.channel = (int)(*digCol)[d].Channel();
195  fChannelInfo.x = xyz[0];
196  fChannelInfo.y = xyz[1];
197  fChannelInfo.z = xyz[2];
198 
199  // loop over the energy deposition collections to fill the tree
200  for(auto edep : edepsCol){
201 
202  // get the MCParticle for this track ID
203  auto part = bt->TrackIDToParticle(edep->TrackID());
204 
205  fEDep.trackID = edep->TrackID();
206  fEDep.pdg = part->PdgCode();
207  fEDep.x = edep->X();
208  fEDep.y = edep->Y();
209  fEDep.z = edep->Z();
210  fEDep.dX = edep->dX();
211  fEDep.t = edep->Time();
212  fEDep.e = edep->Energy();
213 
214  MF_LOG_DEBUG("RawDigitAna")
215  << "pos: ("
216  << fEDep.x
217  << ", "
218  << fEDep.y
219  << ", "
220  << fEDep.z
221  << ") e: "
222  << fEDep.e
223  << " t: "
224  << fEDep.t
225  << " dX: "
226  << fEDep.dX;
227 
228  // closure test for the channel map
229  xyz[0] = fEDep.x;
230  xyz[1] = fEDep.y;
231  xyz[2] = fEDep.z;
232 
233  chan = geo->NearestChannel(xyz);
234  if (chan != geo->GapChannelNumber())
235  {
236  geo->ChannelToPosition(chan, xyzChan);
237 
238 // if(std::abs(xyz[1] - fChannelInfo.y) > 0.33)
239 // MF_LOG_VERBATIM("RawDigitAna")
240 // << "Channel "
241 // << fChannelInfo.channel
242 // << " / "
243 // << chan
244 // << " is off from the energy deposit in y: ("
245 // << fChannelInfo.y
246 // << ", "
247 // << fChannelInfo.z
248 // << ") vs ("
249 // << xyz[1]
250 // << ", "
251 // << xyz[2]
252 // << ") "
253 // << std::abs(xyz[1] - fChannelInfo.y);
254 //
255 // if(std::abs(xyz[2] - fChannelInfo.z) > 10.33)
256 // MF_LOG_VERBATIM("RawDigitAna")
257 // << "Channel "
258 // << fChannelInfo.channel
259 // << " / "
260 // << chan
261 // << " is off from the energy deposit in z: ("
262 // << fChannelInfo.y
263 // << ", "
264 // << fChannelInfo.z
265 // << ") vs ("
266 // << xyz[1]
267 // << ", "
268 // << xyz[2]
269 // << ") "
270 // << std::abs(xyz[2] - fChannelInfo.z);
271 
272  }
273 
274  // make the tree flat in terms of the energy depositions
275  fChannelTree->Fill();
276 
277  } // end loop over collection of EnergyDeposits
278  } // end loop over RawDigit collection
279 
280  return;
281  } // analyze
282 
283  } // namespace rosim
284 
285  namespace rosim {
286 
288 
289  } // namespace rosim
290 
291 } // gar
292 
293 #endif // GAR_ROSIM_RAWDIGITANA
294 
def analyze(root, level, gtrees, gbranches, doprint)
Definition: rootstat.py:69
std::string string
Definition: nybbler.cc:12
void reconfigure(fhicl::ParameterSet const &pset)
std::string fReadoutModuleLabel
module label for the Geant
EventInfo fEvt
Struct containing event identification.
ChannelInfo fChannelInfo
Struct containing channel info.
EnergyDep fEDep
Struct containing energy deposition info.
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
bt
Definition: tracks.py:83
void beginJob()
Definition: Breakpoints.cc:14
virtual void reconfigure(fhicl::ParameterSet const &pset)
T get(std::string const &key) const
Definition: ParameterSet.h:271
Framework includes.
p
Definition: test.py:223
Code to link reconstructed objects back to the MC truth information.
Base utilities and modules for event generation and detector simulation.
General GArSoft Utilities.
#define MF_LOG_VERBATIM(category)
Definition: types.h:32
#define MF_LOG_DEBUG(id)
list x
Definition: train.py:276
TCEvent evt
Definition: DataStructs.cxx:7
#define MF_LOG_WARNING(category)
LArSoft geometry interface.
Definition: ChannelGeo.h:16
art framework interface to geometry description
void analyze(const ::art::Event &evt)
TTree * fChannelTree
Tree to keep track of sanity check info.