Public Member Functions | Private Member Functions | Private Attributes | List of all members
caldata::CalWireDUNEDPhase Class Reference
Inheritance diagram for caldata::CalWireDUNEDPhase:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Member Functions

 CalWireDUNEDPhase (fhicl::ParameterSet const &pset)
 
virtual ~CalWireDUNEDPhase ()
 
void produce (art::Event &evt)
 
void beginJob ()
 
void endJob ()
 
void reconfigure (fhicl::ParameterSet const &p)
 
- Public Member Functions inherited from art::EDProducer
 EDProducer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDProducer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Producer
virtual ~Producer () noexcept
 
 Producer (fhicl::ParameterSet const &)
 
 Producer (Producer const &)=delete
 
 Producer (Producer &&)=delete
 
Produceroperator= (Producer const &)=delete
 
Produceroperator= (Producer &&)=delete
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Modifier
 ~Modifier () noexcept
 
 Modifier ()
 
 Modifier (Modifier const &)=delete
 
 Modifier (Modifier &&)=delete
 
Modifieroperator= (Modifier const &)=delete
 
Modifieroperator= (Modifier &&)=delete
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

void SubtractBaseline (std::vector< float > &holder)
 

Private Attributes

int fPostsample
 number of postsample bins More...
 
int fDoBaselineSub
 number of postsample bins More...
 
std::string fDigitModuleLabel
 constants More...
 
std::string fSpillName
 
unsigned short fPreROIPad
 ROI padding. More...
 
unsigned short fPostROIPad
 ROI padding. More...
 
double fSigThrFact
 Signal shreshold factor. More...
 

Additional Inherited Members

- Public Types inherited from art::EDProducer
using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
- Public Types inherited from art::detail::Producer
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 
- Public Types inherited from art::Modifier
template<typename UserConfig , typename UserKeysToIgnore = void>
using Table = ProducerTable< UserConfig, detail::ModuleConfig, UserKeysToIgnore >
 
- Static Public Member Functions inherited from art::EDProducer
static void commitEvent (EventPrincipal &ep, Event &e)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 47 of file CalWireDUNEDPhase_module.cc.

Constructor & Destructor Documentation

caldata::CalWireDUNEDPhase::CalWireDUNEDPhase ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 82 of file CalWireDUNEDPhase_module.cc.

82  : EDProducer{pset}
83  {
84  this->reconfigure(pset);
85 
86  produces< std::vector<recob::Wire> >(fSpillName);
87  produces<art::Assns<raw::RawDigit, recob::Wire>>(fSpillName);
88  }
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
void reconfigure(fhicl::ParameterSet const &p)
caldata::CalWireDUNEDPhase::~CalWireDUNEDPhase ( )
virtual

Definition at line 91 of file CalWireDUNEDPhase_module.cc.

92  {
93  }

Member Function Documentation

void caldata::CalWireDUNEDPhase::beginJob ( )
virtual

Reimplemented from art::EDProducer.

Definition at line 120 of file CalWireDUNEDPhase_module.cc.

121  {
122  }
void caldata::CalWireDUNEDPhase::endJob ( )
virtual

Reimplemented from art::EDProducer.

Definition at line 125 of file CalWireDUNEDPhase_module.cc.

126  {
127  }
void caldata::CalWireDUNEDPhase::produce ( art::Event evt)
virtual

Implements art::EDProducer.

Definition at line 130 of file CalWireDUNEDPhase_module.cc.

131  {
132  // get the geometry
133  // art::ServiceHandle<geo::Geometry> geom;
134 
135  // get the FFT service to have access to the FFT size
137  int transformSize = fFFT->FFTSize();
138 
139  // Get signal shaping service.
141  double DeconNorm = sss->GetDeconNorm();
142 
143  // make a collection of Wires
144  std::unique_ptr<std::vector<recob::Wire> > wirecol(new std::vector<recob::Wire>);
145  // ... and an association set
146  std::unique_ptr<art::Assns<raw::RawDigit,recob::Wire> > WireDigitAssn
148 
149  // Read in the digit List object(s).
151  auto digitVecHandle = evt.getHandle< std::vector<raw::RawDigit> >(itag1);
152 
153  // if (!digitVecHandle->size()) return;
154  if (digitVecHandle->size())
155  {
156  mf::LogInfo("CalWireDUNEDPhase") << "CalWireDUNEDPhase:: digitVecHandle size is " << digitVecHandle->size();
157 
158  // Use the handle to get a particular (0th) element of collection.
159  art::Ptr<raw::RawDigit> digitVec0(digitVecHandle, 0);
160 
161  unsigned int dataSize = digitVec0->Samples(); //size of raw data vectors
162  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
163  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt, clockData);
164  int readoutwindowsize = detProp.ReadOutWindowSize();
165  if (int(dataSize) != readoutwindowsize){
167  << "ReadOutWindowSize "<<readoutwindowsize<<" does not match data size "<<dataSize<<". Please set services.DetectorPropertiesService.NumberTimeSamples and services.DetectorPropertiesService.ReadOutWindowSize in fcl file to "<<dataSize;
168  }
169 
170  raw::ChannelID_t channel = raw::InvalidChannelID; // channel number
171  unsigned int bin(0); // time bin loop variable
172 
173  filter::ChannelFilter *chanFilt = new filter::ChannelFilter();
174 
175  std::vector<float> holder; // holds signal data
176  std::vector<short> rawadc(transformSize); // vector holding uncompressed adc values
177  std::vector<TComplex> freqHolder(transformSize+1); // temporary frequency data
178 
179  // loop over all wires
180  wirecol->reserve(digitVecHandle->size());
181  for(size_t rdIter = 0; rdIter < digitVecHandle->size(); ++rdIter){ // ++ move
182  holder.clear();
183 
184  // get the reference to the current raw::RawDigit
185  art::Ptr<raw::RawDigit> digitVec(digitVecHandle, rdIter);
186  channel = digitVec->Channel();
187 
188  // skip bad channels
189  if(!chanFilt->BadChannel(channel)) {
190  holder.resize(transformSize);
191 
192  // uncompress the data
193  raw::Uncompress(digitVec->ADCs(), rawadc, digitVec->Compression());
194 
195  // loop over all adc values and subtract the pedestal
196  for(bin = 0; bin < dataSize; ++bin)
197  holder[bin]=(rawadc[bin]-digitVec->GetPedestal());
198  //Xin fill the remaining bin with data
199  for (bin = dataSize;bin<holder.size();bin++){
200  holder[bin] = (rawadc[bin-dataSize]-digitVec->GetPedestal());
201  }
202 
203  // Do deconvolution.
204  sss->Deconvolute(clockData, channel, holder);
205  for(bin = 0; bin < holder.size(); ++bin) holder[bin]=holder[bin]/DeconNorm;
206  } // end if not a bad channel
207 
208  holder.resize(dataSize,1e-5);
209 
210  //This restores the DC component to signal removed by the deconvolution.
211  if(fPostsample) {
212  double average=0.0;
213  for(bin=0; bin < (unsigned int)fPostsample; ++bin)
214  average+=holder[holder.size()-1-bin]/(double)fPostsample;
215  for(bin = 0; bin < holder.size(); ++bin) holder[bin]-=average;
216  }
217  // adaptive baseline subtraction
218  if(fDoBaselineSub) SubtractBaseline(holder);
219 
220  // work out the ROI
222  std::vector<std::pair<unsigned int, unsigned int>> holderInfo;
223  std::vector<std::pair<unsigned int, unsigned int>> rois;
224 
225  double max = 0;
226  double deconNoise = sss->GetDeconNoise(channel);
227  // find out all ROI
228  unsigned int roiStart = 0;
229  for(bin = 0; bin < dataSize; ++bin) {
230  double SigVal = holder[bin];
231  if (SigVal > max) max = SigVal;
232  if(roiStart == 0) {
233  if (SigVal > fSigThrFact*deconNoise) roiStart = bin; // n sigma above noise
234  }else{
235  if (SigVal < deconNoise){
236  rois.push_back(std::make_pair(roiStart, bin));
237  roiStart = 0;
238  }
239  }
240  }
241  if (roiStart!=0){
242  rois.push_back(std::make_pair(roiStart, dataSize-1));
243  roiStart = 0;
244  }
245 
246  // pad them
247  // if (channel==512){
248  // for (bin = 0; bin< holder.size();++bin){
249  // if (fabs(holder[bin]) > 2)
250  // std::cout << "Xin1: " << holder[bin] << std::endl;
251  // }
252  // }
253  //std::cout << "Xin: " << max << " "<< channel << " " << deconNoise << " " << rois.size() << std::endl;
254 
255  if(rois.size() == 0) continue;
256  holderInfo.clear();
257  for(unsigned int ii = 0; ii < rois.size(); ++ii) {
258  // low ROI end
259  int low = rois[ii].first - fPreROIPad;
260  if(low < 0) low = 0;
261  rois[ii].first = low;
262  // high ROI end
263  unsigned int high = rois[ii].second + fPostROIPad;
264  if(high >= dataSize) high = dataSize-1;
265  rois[ii].second = high;
266 
267  }
268  // merge them
269  if(rois.size() >= 1) {
270  // temporary vector for merged ROIs
271 
272  for (unsigned int ii = 0; ii<rois.size();ii++){
273  unsigned int roiStart = rois[ii].first;
274  unsigned int roiEnd = rois[ii].second;
275 
276  int flag1 = 1;
277  unsigned int jj=ii+1;
278  while(flag1){
279  if (jj<rois.size()){
280  if(rois[jj].first <= roiEnd ) {
281  roiEnd = rois[jj].second;
282  ii = jj;
283  jj = ii+1;
284  }else{
285  flag1 = 0;
286  }
287  }else{
288  flag1 = 0;
289  }
290  }
291  std::vector<float> sigTemp;
292  for(unsigned int kk = roiStart; kk < roiEnd; ++kk) {
293  sigTemp.push_back(holder[kk]);
294  } // jj
295  // std::cout << "Xin: " << roiStart << std::endl;
296  ROIVec.add_range(roiStart, std::move(sigTemp));
297  //trois.push_back(std::make_pair(roiStart,roiEnd));
298  }
299  }// else{
300  // unsigned int roiStart = rois[0].first;
301  // unsigned int roiEnd = rois[0].second;
302  // std::vector<float> sigTemp;
303  // for(unsigned int kk = roiStart; kk < roiEnd; ++kk) {
304  // sigTemp.push_back(holder[kk]);
305  // } // jj
306  // // std::cout << "Xin: " << roiStart << std::endl;
307  // ROIVec.add_range(roiStart, std::move(sigTemp));
308  // }
309 
310  // save them
311  wirecol->push_back(recob::WireCreator(std::move(ROIVec),*digitVec).move());
312 
313 
314 
315 
316  // Make a single ROI that spans the entire data size
317  //wirecol->push_back(recob::WireCreator(holder,*digitVec).move());
318  // add an association between the last object in wirecol
319  // (that we just inserted) and digitVec
320  if (!util::CreateAssn(*this, evt, *wirecol, digitVec, *WireDigitAssn, fSpillName)) {
322  << "Can't associate wire #" << (wirecol->size() - 1)
323  << " with raw digit #" << digitVec.key();
324  } // if failed to add association
325  }
326 
327  if(wirecol->size() == 0)
328  mf::LogWarning("CalWireDUNEDPhase") << "No wires made for this event.";
329 
330 
331 
332  delete chanFilt;
333  }
334  evt.put(std::move(wirecol), fSpillName);
335  evt.put(std::move(WireDigitAssn), fSpillName);
336 
337  return;
338  }
double fSigThrFact
Signal shreshold factor.
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
bool BadChannel(uint32_t channel) const
const datarange_t & add_range(size_type offset, ITER first, ITER last)
Adds a sequence of elements as a range with specified offset.
uint8_t channel
Definition: CRTFragment.hh:201
Class managing the creation of a new recob::Wire object.
Definition: WireCreator.h:53
double GetDeconNoise(Channel channel) const override
int FFTSize() const
Definition: LArFFT.h:69
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
Definition: RawTypes.h:32
const double e
std::string fDigitModuleLabel
constants
def move(depos, offset)
Definition: depos.py:107
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
int fDoBaselineSub
number of postsample bins
int fPostsample
number of postsample bins
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
static int max(int a, int b)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
unsigned short fPostROIPad
ROI padding.
QTextStream & bin(QTextStream &s)
unsigned short fPreROIPad
ROI padding.
void SubtractBaseline(std::vector< float > &holder)
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:776
void Deconvolute(unsigned int channel, std::vector< T > &func) const
void caldata::CalWireDUNEDPhase::reconfigure ( fhicl::ParameterSet const &  p)

Definition at line 96 of file CalWireDUNEDPhase_module.cc.

97  {
98  std::vector<unsigned short> uin; // std::vector<unsigned short> vin;
99  // std::vector<unsigned short> zin;
100 
101  fDigitModuleLabel = p.get< std::string >("DigitModuleLabel", "daq");
102  fPostsample = p.get< int > ("PostsampleBins");
103  fDoBaselineSub = p.get< bool > ("DoBaselineSub");
104  uin = p.get< std::vector<unsigned short> > ("PlaneROIPad");
105  fSigThrFact = p.get< double> ("SigThrFact", 3.0);
106  // put the ROI pad sizes into more convenient vectors
107  fPreROIPad = uin[0];
108  fPostROIPad = uin[1];
109  fSpillName.clear();
110 
111  size_t pos = fDigitModuleLabel.find(":");
112  if( pos!=std::string::npos ) {
113  fSpillName = fDigitModuleLabel.substr( pos+1 );
114  fDigitModuleLabel = fDigitModuleLabel.substr( 0, pos );
115  }
116 
117  }
double fSigThrFact
Signal shreshold factor.
std::string string
Definition: nybbler.cc:12
std::string fDigitModuleLabel
constants
p
Definition: test.py:223
int fDoBaselineSub
number of postsample bins
int fPostsample
number of postsample bins
unsigned short fPostROIPad
ROI padding.
unsigned short fPreROIPad
ROI padding.
void caldata::CalWireDUNEDPhase::SubtractBaseline ( std::vector< float > &  holder)
private

Definition at line 340 of file CalWireDUNEDPhase_module.cc.

341  {
342 
343  float min = 0,max=0;
344  for (unsigned int bin = 0; bin < holder.size(); bin++){
345  if (holder[bin] > max) max = holder[bin];
346  if (holder[bin] < min) min = holder[bin];
347  }
348  int nbin = max - min;
349  if (nbin!=0){
350  TH1F *h1 = new TH1F("h1","h1",nbin,min,max);
351  for (unsigned int bin = 0; bin < holder.size(); bin++){
352  h1->Fill(holder[bin]);
353  }
354  float ped = h1->GetMaximum();
355  float ave=0,ncount = 0;
356  for (unsigned int bin = 0; bin < holder.size(); bin++){
357  if (fabs(holder[bin]-ped)<2){
358  ave +=holder[bin];
359  ncount ++;
360  }
361  }
362  if (ncount==0) ncount=1;
363  ave = ave/ncount;
364  for (unsigned int bin = 0; bin < holder.size(); bin++){
365  holder[bin] -= ave;
366  }
367  h1->Delete();
368  }
369  }
static int max(int a, int b)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
QTextStream & bin(QTextStream &s)

Member Data Documentation

std::string caldata::CalWireDUNEDPhase::fDigitModuleLabel
private

constants

module that made digits

Definition at line 66 of file CalWireDUNEDPhase_module.cc.

int caldata::CalWireDUNEDPhase::fDoBaselineSub
private

number of postsample bins

Definition at line 65 of file CalWireDUNEDPhase_module.cc.

unsigned short caldata::CalWireDUNEDPhase::fPostROIPad
private

ROI padding.

Definition at line 72 of file CalWireDUNEDPhase_module.cc.

int caldata::CalWireDUNEDPhase::fPostsample
private

number of postsample bins

Definition at line 64 of file CalWireDUNEDPhase_module.cc.

unsigned short caldata::CalWireDUNEDPhase::fPreROIPad
private

ROI padding.

Definition at line 71 of file CalWireDUNEDPhase_module.cc.

double caldata::CalWireDUNEDPhase::fSigThrFact
private

Signal shreshold factor.

Definition at line 73 of file CalWireDUNEDPhase_module.cc.

std::string caldata::CalWireDUNEDPhase::fSpillName
private

nominal spill is an empty string it is set by the DigitModuleLabel ex.: "daq:preSpill" for prespill data

Definition at line 68 of file CalWireDUNEDPhase_module.cc.


The documentation for this class was generated from the following file: