WireChgAna_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: WireChgAna
3 // Plugin Type: analyzer (art v3_05_01)
4 // File: WireChgAna_module.cc
5 //
6 // Generated at Tue Jul 21 14:37:27 2020 by Tingjun Yang using cetskelgen
7 // from cetlib version v3_10_00.
8 ////////////////////////////////////////////////////////////////////////
9 
17 #include "fhiclcpp/ParameterSet.h"
19 #include "art_root_io/TFileService.h"
23 #include "lardataobj/RawData/raw.h"
26 
27 #include "TTree.h"
28 #include "TH1D.h"
29 
30 namespace pdsp {
31  class WireChgAna;
32 }
33 
34 
36 public:
37  explicit WireChgAna(fhicl::ParameterSet const& p);
38  // The compiler-generated destructor is fine for non-base
39  // classes without bare pointers or other resource use.
40 
41  // Plugins should not be copied or assigned.
42  WireChgAna(WireChgAna const&) = delete;
43  WireChgAna(WireChgAna&&) = delete;
44  WireChgAna& operator=(WireChgAna const&) = delete;
45  WireChgAna& operator=(WireChgAna&&) = delete;
46 
47  // Required functions.
48  void analyze(art::Event const& e) override;
49 
50  // Selected optional functions.
51  void beginJob() override;
52  void endJob() override;
53 
54 private:
55 
56  // Declare member data here.
57  TTree *ftree;
58  TH1D *rawwf[3][800];
59  TH1D *deconwf[3][800];
60  double charge[3][800];
61  double deconchg[3][800];
62  double hitchg[3][800];
63  double hitsumadc[3][800];
64  double nelec[3][800];
65 
66 };
67 
68 
70  : EDAnalyzer{p} // ,
71  // More initializers here.
72 {
73  // Call appropriate consumes<>() for any products to be retrieved by this module.
74 }
75 
77 {
78 
79  for (int i = 0; i<3; ++i){
80  for (int j = 0; j<800; ++j){
81  charge[i][j] = 0;
82  nelec[i][j] = 0;
83  deconchg[i][j] = 0;
84  hitchg[i][j] = 0;
85  hitsumadc[i][j] = 0;
86  }
87  }
88 
89  // Implementation of required member function here.
90  std::vector<art::Ptr<raw::RawDigit> > rawlist;
91  art::InputTag itag("tpcrawdecoder","daq");
92  auto rawListHandle = e.getHandle< std::vector<raw::RawDigit> >(itag);
93  if (rawListHandle) art::fill_ptr_vector(rawlist, rawListHandle);
94 
95  std::vector < art::Ptr < recob::Wire > > wires;
96  art::InputTag itag2("wclsdatanfsp","gauss");
97  auto wireListHandle = e.getHandle< std::vector < recob::Wire > >(itag2);
98  if (wireListHandle) {
99  art::fill_ptr_vector(wires, wireListHandle);
100  }
101 
102  std::vector <art::Ptr<recob::Hit> > hits;
103  auto hitListHandle = e.getHandle<std::vector<recob::Hit> >("gaushit");
104  if (hitListHandle) {
105  art::fill_ptr_vector(hits, hitListHandle);
106  }
107 
108  auto const* geo = lar::providerFrom<geo::Geometry>();
109 
110  auto simChannelHandle = e.getValidHandle<std::vector<sim::SimChannel>>("tpcrawdecoder:simpleSC");
111 
112  for (unsigned int ich = 0; ich < rawlist.size(); ++ich){
113  const auto & digitVec = rawlist[ich];
114  const auto & wireid = geo->ChannelToWire(digitVec->Channel());
115  if (wireid[0].TPC != 1) continue;
116  //if (wireid[0].Plane != 2) continue;
117  int wire = wireid[0].Wire;
118  int plane = wireid[0].Plane;
119  double this_charge = 0;
120  std::vector<short> rawadc(6000);
121  raw::Uncompress(digitVec->ADCs(), rawadc, digitVec->GetPedestal(), digitVec->Compression());
122  for (size_t itck = 0; itck < rawadc.size(); ++itck){
123  this_charge += rawadc[itck] - digitVec->GetPedestal();
124  rawwf[plane][wire]->SetBinContent(itck, rawadc[itck] - digitVec->GetPedestal());
125  }
126  charge[plane][wire] = this_charge;
127  }
128 
129  for ( auto const& channel : (*simChannelHandle) ){
130  const auto & wireid = geo->ChannelToWire(channel.Channel());
131  if (wireid[0].TPC != 1) continue;
132  //if (wireid[0].Plane != 2) continue;
133  int wire = wireid[0].Wire;
134  int plane = wireid[0].Plane;
135  double this_nelec = 0;
136  auto const& timeSlices = channel.TDCIDEMap();
137  for ( auto const& timeSlice : timeSlices ){
138  auto const& energyDeposits = timeSlice.second;
139  for ( auto const& energyDeposit : energyDeposits ){
140  this_nelec += energyDeposit.numElectrons;
141  }
142  }
143  nelec[plane][wire] = this_nelec;
144  }
145 
146  for (unsigned int ich = 0; ich < wires.size(); ++ich){
147  const auto & wireid = geo->ChannelToWire(wires[ich]->Channel());
148  if (wireid[0].TPC != 1) continue;
149  //if (wireid[0].Plane != 2) continue;
150  int wire = wireid[0].Wire;
151  int plane = wireid[0].Plane;
152  double this_charge = 0;
153  const auto & signal = wires[ich]->Signal();
154 
155  for (size_t itck = 0; itck < signal.size(); ++itck){
156  this_charge += signal[itck];
157  deconwf[plane][wire]->SetBinContent(itck, signal[itck]);
158  }
159  deconchg[plane][wire] = this_charge;
160  }
161 
162  for (auto const & hit : hits){
163  if (hit->WireID().TPC != 1) continue;
164  int wire = hit->WireID().Wire;
165  int plane = hit->WireID().Plane;
166  hitchg[plane][wire] += hit->Integral();
167  hitsumadc[plane][wire] += hit->SummedADC();
168  }
169 
170  ftree->Fill();
171 }
172 
174 {
175  art::ServiceHandle<art::TFileService> fileServiceHandle;
176  ftree = fileServiceHandle->make<TTree>("ftree", "raw digit info");
177  ftree->Branch("charge", charge, "charge[3][800]/D");
178  ftree->Branch("nelec", nelec, "nelec[3][800]/D");
179  ftree->Branch("deconchg", deconchg, "deconchg[3][800]/D");
180  ftree->Branch("hitchg", hitchg, "hitchg[3][800]/D");
181  ftree->Branch("hitsumadc", hitsumadc, "hitsumadc[3][800]/D");
182 
183  for (int i = 0; i<3; ++i){
184  for (int j = 0; j<800; ++j){
185  rawwf[i][j] = fileServiceHandle->make<TH1D>(Form("rawwf_%d_%d",i,j),Form("Plane %d Wire %d",i,j),6000,0,6000);
186  deconwf[i][j] = fileServiceHandle->make<TH1D>(Form("deconwf_%d_%d",i,j),Form("Plane %d Wire %d",i,j),6000,0,6000);
187  }
188  }
189 
190 }
191 
193 {
194  // Implementation of optional member function here.
195 }
196 
WireChgAna & operator=(WireChgAna const &)=delete
TH1D * rawwf[3][800]
double nelec[3][800]
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
void beginJob() override
double charge[3][800]
WireChgAna(fhicl::ParameterSet const &p)
double hitchg[3][800]
uint8_t channel
Definition: CRTFragment.hh:201
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
art framework interface to geometry description
void analyze(art::Event const &e) override
double hitsumadc[3][800]
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
p
Definition: test.py:223
double deconchg[3][800]
Detector simulation of raw signals on wires.
Declaration of signal hit object.
void endJob() override
Declaration of basic channel signal object.
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:776
LArSoft geometry interface.
Definition: ChannelGeo.h:16
TH1D * deconwf[3][800]