10 #include "lbne-raw-data/Services/ChannelMap/ChannelMapService.h" 17 using std::ostringstream;
25 : m_LogLevel(1), m_nwarn(0) {
26 const string myname =
"Dune35tNoiseRemovalService::ctor: ";
38 const unsigned int nchan = m_pGeometry->Nchannels();
39 for (
unsigned int chanon=0; chanon<nchan; ++chanon ) {
40 unsigned int chanoff = m_pChannelMap->Offline(chanon);
42 unsigned int iview = gview;
47 unsigned int rop = ropid.
ROP;
48 unsigned int chan0 = m_pGeometry->FirstChannelInROP(ropid);
49 unsigned int ropchan = chanoff - chan0;
52 unsigned int ropchan = 999;
54 geo::WireID wid = m_pGeometry->ChannelToWire(chanoff).at(0);
55 unsigned int tpcoff = wid.
TPC;
56 if ( gview ==
geo::kW && tpcoff%2 ) iview = 3;
57 unsigned int apachan = chanoff%512;
58 if ( iview == 0 ) ropchan = apachan;
59 if ( iview == 1 ) ropchan = apachan - 144;
60 if ( iview == 2 ) ropchan = apachan - 288;
61 if ( iview == 3 ) ropchan = apachan - 400;
64 static string sview[4] = {
"u",
"v",
"z1",
"z2"};
65 unsigned int apa = m_pChannelMap->APAFromOnlineChannel(chanon);
67 ssrop << apa << sview[iview];
68 string srop = ssrop.str();
70 if ( ropchan < 100 ) ssrop <<
"0";
71 if ( ropchan < 10 ) ssrop <<
"0";
73 string sropchan = ssrop.str();
77 if ( m_GroupingFlag == 0 ) {
79 for (
size_t i = 0; i<3; ++i){
82 for (
unsigned int i=0; i<nchan; ++i){
83 unsigned int plane = m_pChannelMap->PlaneFromOnlineChannel(i);
84 unsigned int rce = m_pChannelMap->RCEFromOnlineChannel(i);
85 unsigned int regulator = m_pChannelMap->RegulatorFromOnlineChannel(i);
88 }
else if ( m_GroupingFlag == 1 ) {
90 for (
size_t i = 0; i<3; ++i){
94 cout << myname <<
"Online channel: plane:RCE:ASIC ROP-ropchan" <<
endl;
96 for (
unsigned int chanon=0; chanon<nchan; ++chanon ) {
97 unsigned int plane = m_pChannelMap->PlaneFromOnlineChannel(chanon);
98 unsigned int rce = m_pChannelMap->RCEFromOnlineChannel(chanon);
99 unsigned int asic = m_pChannelMap->ASICFromOnlineChannel(chanon);
101 cout << myname << chanon <<
": " << plane <<
":" << rce <<
":" << asic
108 cout << myname <<
"ERROR: Invalid GroupingFlag: " << m_GroupingFlag <<
endl;
117 const string myname =
"Dune35tNoiseRemovalService:update: ";
118 if ( datamap.size() == 0 ) {
119 cout << myname <<
"WARNING: No channels found." <<
endl;
122 unsigned int nsig = 0;
124 for (
const AdcChannelDataMap::value_type& ent : datamap ) {
126 if ( first ) nsig = data.
samples.size();
127 if ( data.
samples.size() != nsig ) {
128 cout << myname <<
"WARNING: Channels have inconsistent sample counts." <<
endl;
133 cout << myname <<
"WARNING: No ADC samples found." <<
endl;
137 cout << myname <<
"ERROR: Channel groupings have not been defined." <<
endl;
141 cout << myname <<
"Entering..." <<
endl;
142 cout << myname <<
" # Channels: " << datamap.size() <<
endl;
143 cout << myname <<
" # Ticks: " << nsig <<
endl;
146 for (
unsigned int isig=0; isig<nsig; ++isig) {
153 cout << myname <<
setw(3) << iori <<
setw(4) << igrp <<
" " << chans.size() <<
endl;
160 cout << myname <<
"Channel on/off: " << chan <<
"/" << offlineChan <<
endl;
163 if ( iacd == datamap.end() )
continue;
171 bool isSignal =
false;
173 if ( acd.
signal.size() > isig ) {
174 isSignal = acd.
signal[isig];
177 cout << myname <<
"WARNING: Signal skip requested without signal finding." <<
endl;
182 corrVals.push_back(sig);
185 unsigned int corrValSize = corrVals.
size();
186 sort(corrVals.begin(),corrVals.end());
187 double correction = 0;
188 if ( corrValSize < 2 )
190 else if ( (corrValSize % 2) == 0 )
191 correction = (corrVals[corrValSize/2] + corrVals[(corrValSize/2)-1])/2.0;
193 correction = corrVals[(corrValSize-1)/2];
198 if ( iacd == datamap.end() )
continue;
203 if ( datamap.count(offlineChan) == 0 )
continue;
216 print(ostream& out,
string prefix)
const {
217 out << prefix <<
"Dune35tNoiseRemovalService:" <<
endl;
229 out << prefix <<
setw(wori) <<
"Orient." <<
setw(wgrp) <<
"Group" <<
": " <<
" Online channels" <<
endl;
231 out << prefix <<
setw(wgrp+4) <<
"Group" <<
": ";
236 vector<vector<string>> gochans;
238 for (
unsigned int iori=0; iori<nori; ++iori ) {
240 for (
unsigned int igrp=0; igrp<gchans.size(); ++igrp ) {
242 if ( chans.size() == 0 )
continue;
243 std::vector<string> schans;
244 bool usesetw =
false;
245 bool addspace =
false;
248 schans.push_back(
".");
252 schans.push_back(sout.str());
257 schans.push_back(sout.str());
264 string::size_type
pos = schan.find(
"z1-");
265 if ( pos != string::npos ) schan.replace(pos, 2,
"z");
266 pos = schan.find(
"z2-");
267 if ( pos != string::npos ) schan.replace(pos, 2,
"Z");
268 schans.push_back(schan);
272 std::sort(schans.begin(), schans.end());
273 ostringstream sschanlist;
274 for (
string schan : schans ) {
275 if ( usesetw ) sschanlist <<
setw(wcha);
276 else if ( addspace && sschanlist.str().size() ) sschanlist <<
" ";
279 string schanlist = sschanlist.str();
281 out << prefix <<
setw(wori) << iori <<
setw(wgrp) << igrp <<
": " << schanlist <<
endl;
283 if ( gochans.size() < igrp+1 ) gochans.resize(igrp+1, std::vector<string>(nori));
284 gochans[igrp][iori] = schanlist;
289 for (
unsigned int igrp=0; igrp<gochans.size(); ++igrp ) {
290 for (
unsigned int iori=0; iori<nori; ++iori ) {
291 string schanlist = gochans[igrp][iori];
292 if ( schanlist.size() ) out << prefix <<
setw(wgrp+2) << igrp <<
"-" << iori <<
": " << schanlist <<
endl;
int update(AdcChannelDataMap &datamap) const
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Dune35tNoiseRemovalService(fhicl::ParameterSet const &pset, art::ActivityRegistry &)
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const
ROPID_t ROP
Index of the readout plane within its TPC set.
const lbne::ChannelMapService * m_pChannelMap
T get(std::string const &key) const
bool get_if_present(std::string const &key, T &value) const
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
Class identifying a set of planes sharing readout channels.
Q_EXPORT QTSManip setw(int w)
const geo::Geometry * m_pGeometry
std::vector< std::vector< AdcChannelVector > > m_GroupChannels
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
Planes which measure W (third view for Bo, MicroBooNE, etc).
TPCID_t TPC
Index of the TPC within its cryostat.
std::vector< AdcChannel > AdcChannelVector
const AdcFlag AdcStuckOff
QTextStream & endl(QTextStream &s)
std::map< unsigned int, std::string > m_sRopChannelMap