ImportSingle311Event_module.cc
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////
2 // Class: ImportSingle311Event
3 // Module Type: producer
4 // File: test_code.cc
5 //
6 // Generated at Fri Mar 17 13:56:31 2017 by Kevin Fusshoeller
7 //////////////////////////////////////////////////////////////////////////
8 
9 #include <vector>
10 #include <string>
11 #include <sstream>
12 #include <iostream>
13 
17 
18 #include "fhiclcpp/ParameterSet.h"
20 
21 #include "lardataobj/RawData/raw.h"
24 
25 using std::ostringstream;
26 using std::string;
27 
28 using namespace dlardaq;
29 
30 namespace EventGen{
31 
33  public:
34  explicit ImportSingle311Event(fhicl::ParameterSet const & p);
35 
36  void produce(art::Event &evt);
37  void beginJob();
38  void endJob();
39 
40  private:
41 
42  void SplitAdc(const std::vector<adc16_t> adc, size_t channel, uint32_t num_samples, std::vector<short> &adclist, size_t LArchan);
43  size_t Get311Chan(size_t LAr_chan);
44 
45  double GetPedMean(size_t RawChan, std::vector< std::pair<double, double> > *fPedMap){ return fPedMap->at(RawChan).first; }
46  double GetPedRMS(size_t RawChan, std::vector< std::pair<double, double> > *fPedMap){ return fPedMap->at(RawChan).second; }
47 
48  EventDecoder DataDecode{1280, 1};
49 
50  // fcl parameters
52  size_t fEvt_num;
54 
55  std::vector< std::pair<double, double> > fPedMap;
56  }; // Class ImportSingle311Event
57 
58 
59  //////////////////////////////////////////////////////////////////////////
60  // function to read in pedestals from file
61  /////////////////////////////////////////////////////////////////////////
62  void ReadPedestalFile(std::string PedestalFileName, std::vector < std::pair<double, double> > &PedMap)
63  {
64  //initialize the channel-ped value map
65  std::ifstream file;
66  file.open(PedestalFileName);
67  if( !file.is_open() )
68  {
70  << "failed to open input file " << PedestalFileName << "\n";
71  }
72 
73  while(!file.eof())
74  {
75  size_t ch, cryo, crate, rawch;
76  double mean, rms;
77  file >> rawch >> cryo >> crate >> ch >> mean >> rms;
78  PedMap.emplace_back(mean, rms);
79  }
80 
81  file.close();
82  return;
83  } // ReadPedestalFile()
84 
85 
86  /////////////////////////////////////////////////////////////////////////////////////////////////////
87  //
88  /////////////////////////////////////////////////////////////////////////////////////////////////////
89 
91 
93  : EDProducer(p)
94  {
95  fFilename = p.get<std::string>("Filename");
96  fEvt_num = p.get<size_t>("Evt_num");
97  fPedestalFile = p.get<std::string>("PedestalFile");
98  produces< std::vector<raw::RawDigit> >();
99  }
100 
101 
103  DataDecode.Open(fFilename);
104  }
105 
106 
107  void ImportSingle311Event::produce(art::Event &evt){
108  ReadPedestalFile(fPedestalFile, fPedMap);
109 
110  //ImportSingle311Event(fhicl::ParameterSet const & p);
111  //beginJob();
112 
113  uint32_t nsample;
114  size_t nch = DataDecode.GetNCh();
115  dlardaq::evheader_t EveHead;
116  std::vector<adc16_t> adcvec;
117 
118  ssize_t blabla = DataDecode.GetEvent(fEvt_num, EveHead, adcvec);
119  std::cout << "Fetching event " << blabla << "\n";
120  nsample = (uint32_t) EveHead.ev_size/(nch*1.5);
121  std::cout << "The size of the event is " << nsample << "\n";
122  auto max_adcvec = std::max_element(std::begin(adcvec), std::end(adcvec));
123  std::cout << "Maximum element of adcvec is: " << *max_adcvec << "\n";
124  std::cout << "The size of adcvec is: " << adcvec.size() << "\n";
125  // std::cout << "The size in bytes of adcvec is: " << sizeof(adcvec) << "\n";
126 
127  std::vector<short> adclist;
128  std::unique_ptr<std::vector<raw::RawDigit>> digcol(new std::vector<raw::RawDigit>);
129  for(size_t LAr_chan = 0; LAr_chan < nch; LAr_chan++){
130  adclist.clear();
131  size_t Chan311 = Get311Chan(LAr_chan);
132  SplitAdc(adcvec, Chan311, nsample, adclist, LAr_chan);
133 
134  short unsigned int nTickReadout = nsample;
135  raw::ChannelID_t channel = LAr_chan;
137 
138  raw::RawDigit rd(channel, nTickReadout, adclist, comp);
139  double pedval = ImportSingle311Event::GetPedMean(Chan311, &fPedMap);
140  double pedrms = ImportSingle311Event::GetPedRMS(Chan311, &fPedMap);
141  rd.SetPedestal(pedval, pedrms);
142 
143  digcol->push_back(rd);
144  }
145 
146  evt.put(std::move(digcol));
147  //endJob();
148  }
149 
150 
151  void ImportSingle311Event::SplitAdc(const std::vector<adc16_t> adc, size_t channel, uint32_t num_samples, std::vector<short> &adclist, size_t LArchan){
152  adclist.resize(num_samples);
153  for (uint32_t i = 0; i<num_samples; i++){
154  adclist[i] = static_cast<short>(adc[channel*num_samples + i]);
155  }
156  }
157 
158  //-------------------------------
159  size_t ImportSingle311Event::Get311Chan(size_t LAr_chan){
160 
161  size_t crate = LAr_chan / 320;
162  size_t Chan311;
163 
164  LAr_chan = 8*(LAr_chan/8+1)-LAr_chan%8 -1;
165 
166  if(crate == 0)
167  {
168  LAr_chan = 32*(LAr_chan/32+1)-LAr_chan%32 -1;
169  size_t card = 4 - ((LAr_chan / 32) % 5);
170  if(LAr_chan > 159)
171  {
172  size_t shift = 31 - (LAr_chan % 32);
173  Chan311 = (2*card)*32 + shift;
174  }
175  else
176  {
177  size_t shift = 31 - (LAr_chan % 32);
178  Chan311 = (2*card + 1)*32 + shift;
179  }
180  }
181  else
182  {
183  size_t new_LAr_chan = LAr_chan - crate*320;
184  size_t card = ((new_LAr_chan / 32) % 5);
185  if(new_LAr_chan > 159)
186  {
187  size_t shift = new_LAr_chan % 32;
188  Chan311 = (2*card)*32 + shift;
189  }
190  else
191  {
192  size_t shift = new_LAr_chan % 32;
193  Chan311 = (2*card + 1)*32 + shift;
194  }
195  Chan311 = Chan311 + crate*320;
196  } // end of if/else statementi
197 
198  return Chan311;
199  } // Get311Chan
200 
201  void ImportSingle311Event::endJob(){
202  DataDecode.Close();
203  }
204 } // EventGen namespace
205 
206 
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
enum raw::_compress Compress_t
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:40
double GetPedMean(size_t RawChan, std::vector< std::pair< double, double > > *fPedMap)
std::string string
Definition: nybbler.cc:12
struct vector vector
void ReadPedestalFile(std::string PedestalFileName, std::vector< std::pair< double, double > > &PedMap)
int16_t adc
Definition: CRTFragment.hh:202
uint8_t channel
Definition: CRTFragment.hh:201
no compression
Definition: RawTypes.h:9
art framework interface to geometry description
double GetPedRMS(size_t RawChan, std::vector< std::pair< double, double > > *fPedMap)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
void beginJob()
Definition: Breakpoints.cc:14
struct dune::tde::crate crate
def move(depos, offset)
Definition: depos.py:107
uint32_t ev_size
Definition: dlardaq.h:86
p
Definition: test.py:223
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
size_t Get311Chan(size_t LAr_chan)
std::vector< std::pair< double, double > > fPedMap
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void SetPedestal(float ped, float sigma=1.)
Set pedestal and its RMS (the latter is 0 by default)
Definition: RawDigit.cxx:68
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
TCEvent evt
Definition: DataStructs.cxx:7
void SplitAdc(const std::vector< dlardaq::adc16_t > *adc, size_t channel, uint32_t num_samples, std::vector< short > &adclist)
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:16