FindSwappedChannels_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: FindSwappedChannels
3 // Module Type: filter
4 // File: FindSwappedChannels_module.cc
5 //
6 // Generated at Thu Apr 6 14:28:04 2017 by Enhao Song using artmod
7 // from cetpkgsupport v1_10_02.
8 ////////////////////////////////////////////////////////////////////////
9 
19 #include "fhiclcpp/ParameterSet.h"
21 #include "Calibrator/Calibrator.h"
24 #include "Geometry/Geometry.h"
26 #include "RecoBase/Track.h"
27 #include "RecoBase/CellHit.h"
28 #include "RecoBase/HitMap.h"
29 #include "NovaDAQConventions/DAQConventions.h"
30 #include "DAQChannelMap/DAQChannelMap.h"
31 #include "DAQChannelMap/FarDetDAQChannelMap.h"
32 
33 #include <memory>
34 #include <sstream>
35 #include <cstdio>
36 #include <stdlib.h>
37 #include <assert.h>
38 
39 // ROOT includes
40 #include "TH2.h"
41 #include "TNtuple.h"
42 
43 namespace chaninfo {
44  class FindSwappedChannels;
45 }
47  public:
48  explicit FindSwappedChannels(fhicl::ParameterSet const & p);
49  FindSwappedChannels(FindSwappedChannels const &) = delete;
53  // Required functions.
54  bool filter(art::Event & e) override;
55  // Selected optional functions.
56  void reconfigure(fhicl::ParameterSet const & p);
57  virtual void beginJob() override;
58  virtual bool beginSubRun(art::SubRun & sr);
59  private:
60  std::string fTrackLabel; //< Label for Slice
61  std::vector<std::string> fKnownSwappedChannelsString;
63  int fVerbose;
64  int fFillTree;
66  std::vector<geo::OfflineChan> fKnownSwappedChannels;
71  bool fill_hist_and_tree( std::vector<geo::OfflineChan> & hits, rb::HitMap & hmap, TH2F * missing_hits_plane_and_cell, TH2F * missing_hits_with_neighbor_hits_plane_and_cell, TNtuple * missing_hits_DiBlock_DCM_and_FEB, TNtuple * missing_hits_with_neighbor_hits_DiBlock_DCM_and_FEB,daqchannelmap::DAQChannelMap * daqcmap, int verbose, int idet, int fFillTree);
73 };
75  :
76  fTrackLabel( p.get< std::string >("TrackLabel")),
77  fKnownSwappedChannelsString( p.get<std::vector<std::string> >("KnownSwappedChannels")),
78  fDetId( p.get< std::string >("DetId")),
79  fVerbose( p.get< int >("Verbose")),
80  fFillTree( p.get< int >("FillTree")),
81  fMaxPlane( p.get< int >("MaxPlane")),
82  fMaxCell( p.get< int >("MaxCell"))
83 {
84  // Call appropriate produces<>() functions here.
85 }
87 {
89  missing_hits_plane_and_cell_XZ = tfs->make<TH2F>("missing_hits_plane_and_cell_XZ", "XZ;Plane;Cell", fMaxPlane, 0, fMaxPlane, fMaxCell, 0, fMaxCell);
90  missing_hits_with_neighbor_hits_plane_and_cell_XZ = tfs->make<TH2F>("missing_hits_with_neighbor_hits_plane_and_cell_XZ", "XZ;Plane;Cell", fMaxPlane, 0, fMaxPlane, fMaxCell, 0, fMaxCell);
91  missing_hits_plane_and_cell_YZ = tfs->make<TH2F>("missing_hits_plane_and_cell_YZ", "YZ;Plane;Cell", fMaxPlane, 0, fMaxPlane, fMaxCell, 0, fMaxCell);
92  missing_hits_with_neighbor_hits_plane_and_cell_YZ = tfs->make<TH2F>("missing_hits_with_neighbor_hits_plane_and_cell_YZ", "YZ;Plane;Cell", fMaxPlane, 0, fMaxPlane, fMaxCell, 0, fMaxCell);
93  //missing_hits_DiBlock_DCM_and_FEB = tfs->make<TNtuple>("missing_hits_DiBlock_DCM_and_FEB", "missing_hits_DiBlock_DCM_and_FEB","DiBlock:DCM:FEB");
94  //missing_hits_with_neighbor_hits_DiBlock_DCM_and_FEB = tfs->make<TNtuple>("missing_hits_with_neighbor_hits_DiBlock_DCM_and_FEB", "missing_hits_with_neighbor_hits_DiBlock_DCM_and_FEB","DiBlock:DCM:FEB");
95 }
97  int db, dcm, feb, detId;
98 // std::cout<<"before cmap" <<std::endl;
99 // int idet = novadaq::cnv::DetInfo::GetId(fDetId);
100 // daqchannelmap::DAQChannelMap* daqcmap = daqchannelmap::DAQChannelMap::getInstance(idet);
102 // std::cout<<"after cmap" <<std::endl;
103 // for (auto k : fKnownSwappedChannelsString) {
104 // std::cout<< k<<std::endl;
105 // }
106  for (auto k : fKnownSwappedChannelsString) {
107  sscanf(k.c_str(),"%d-%02d-%02d-%02d",&detId,&db,&dcm,&feb);
108  for (int ipix=0; ipix<32; ++ipix) {
110  //daqchannelmap::dchan daqChan = far_det_cmap.encodeDChan(detId,db,dcm,feb,ipix);
111  daqchannelmap::dchan daqChan = cmap->Map()->encodeDChan(detId,db,dcm,feb,ipix);
112  //std::cout<<"Sanity check: "<<std::endl;
113 // std::cout<<cmap->Map()->getDetector(daqChan)<<" "<<cmap->Map()->getDiBlock(daqChan)<<" "<<cmap->Map()->getDCM(daqChan)<<" "<<cmap->Map()->getFEB(daqChan)<<" "<<cmap->Map()->getPixel(daqChan)<<" "<<std::endl;
114  //daqchannelmap::dchan logChan = far_det_cmap.encodeLChan(daqChan);
115  daqchannelmap::dchan logChan = cmap->Map()->encodeLChan(daqChan);
116  int plane = far_det_cmap.getPlane(logChan);
117  int cell = far_det_cmap.getCell(logChan);
118  //std::cout<<"p:"<<plane<<" c:"<<cell<<std::endl;
119  //int plane = cmap->Map()->getPlane(logChan);
120  //int cell = cmap->Map()->getCell(logChan);
121  fKnownSwappedChannels.push_back(geo::OfflineChan(plane,cell));
122  }
123  }
124  return true;
125 }
126 
128 {
130  bool result = false;
131  run = e.run();
132  subrun = e.subRun();
133  event = e.event();
135  if (idet != novadaq::cnv::kFARDET && idet != novadaq::cnv::kNEARDET) {
136  std::cout << "No information available for " << fDetId << " at this time" << std::endl;
137  exit(0);
138  }
140  // Implementation of required member function here.
142  e.getByLabel(fTrackLabel, trackHandle);
143  if(trackHandle.failedToGet()){
144  std::cout<<"No tracks found, skipping event" << std::endl;
145  return false;
146  }
148  if(fVerbose == 1)
149  std::cout<<"Number of tracks in event: "<< trackHandle->size()<<std::endl;
150  for(unsigned int k=0; k<trackHandle->size(); ++k){
151  tracks.push_back(art::Ptr<rb::Track>(trackHandle, k));
152  }
153  for(unsigned int i = 0; i < tracks.size(); ++i){//loop over tracks
154  //Look at trajectory_points;
155  //First check if all trajectory points(convert to plane and cell) have hits
156  //if missing hits, check if the plane and cell's DCM other ports have hits.
157  unsigned int track = i+1;
158  if(fVerbose == 1)
159  std::cout<<"track: "<<run<<" "<<subrun<<" "<<event<<" "<<track<<std::endl;
160  rb::HitMap hmap(tracks[i].get());
161  std::vector<geo::OfflineChan> xhits, yhits;
162  geo->CountCellsOnLineFast(tracks[i]->Start(), tracks[i]->Stop(), xhits, yhits);
163  if(tracks[i]->NXCell() > 2){
165  result = true;
166  std::cout<<"track: "<<run<<" "<<subrun<<" "<<event<<" "<<track<<std::endl;
167  }
168  }
169  if(tracks[i]->NYCell() > 2){
171  result = true;
172  std::cout<<"track: "<<run<<" "<<subrun<<" "<<event<<" "<<track<<std::endl;
173  }
174  }
175  }
176  return result;
177 }
178 
180 {
181  fTrackLabel = p.get< std::string >("TrackLabel");
182 }
183 
184 bool chaninfo::FindSwappedChannels::fill_hist_and_tree( std::vector<geo::OfflineChan> & hits, rb::HitMap & hmap, TH2F * missing_hits_plane_and_cell, TH2F * missing_hits_with_neighbor_hits_plane_and_cell, TNtuple * missing_hits_DiBlock_DCM_and_FEB, TNtuple * missing_hits_with_neighbor_hits_DiBlock_DCM_and_FEB,daqchannelmap::DAQChannelMap * daqcmap, int verbose, int idet, int fillTree){
185  bool result = false;
186  for (auto hit : hits) {
187  if (IsBad(hit)) {
188  result = true;
189  const unsigned int plane = hit.Plane();
190  const unsigned int cell = hit.Cell();
191  std::cout<<"hit at p:"<<plane<<" c:"<<cell<<" z:"<<plane*1.0/fMaxPlane*5962<<" w:"<<cell*1.0/fMaxCell*(765+758)-758<<std::endl;
192  continue;
193  }
194  }
195  for(unsigned int n = 0; n < hits.size(); ++n){
196  const unsigned int plane = hits[n].Plane();
197  const unsigned int cell = hits[n].Cell();
198  if(verbose == 1)
199  std::cout<<"cellhit at plane: "<<plane <<" cell: "<<cell<<std::endl;
200  if(hmap.CellExists(plane, cell)){
201  if(verbose == 1)
202  std::cout<<"left hit"<<std::endl;
203  }
204  else{
205  if(verbose == 1)
206  std::cout<<"didn't left hit"<<std::endl;
207  missing_hits_plane_and_cell->Fill(plane,cell);
208  //int plane, cell;
209  int db, dcm, feb, pixel;
210  daqchannelmap::lchan logChan = daqcmap->encodeLChan(idet,plane,cell);
211  daqchannelmap::dchan daqChan = daqcmap->encodeDChan(logChan);
212  db = daqcmap->getDiBlock(daqChan);
213  dcm = daqcmap->getDCM(daqChan);
214  feb = daqcmap->getFEB(daqChan);
215  if(fillTree != 0)
216  missing_hits_DiBlock_DCM_and_FEB->Fill(db, dcm, feb);
217  //same db, dcm , neighbor feb, same pixel?
218  pixel = daqcmap->getPixel(daqChan);
219  unsigned int nbplane, nbcell;
220  if(feb>0){
221  daqChan = daqcmap->encodeDChan(idet,db,dcm,feb-1,pixel);
222  logChan = daqcmap->encodeLChan(daqChan);
223  nbplane = daqcmap->getPlane(logChan);
224  nbcell = daqcmap->getCell(logChan);
225  if( hmap.CellExists(nbplane, nbcell)){
226  if(verbose == 1)
227  std::cout<<"neighbor hit exist at plane: "<<nbplane <<" cell: "<<nbcell<<std::endl;
228  missing_hits_with_neighbor_hits_plane_and_cell->Fill(plane,cell);
229  if(fillTree != 0)
230  missing_hits_with_neighbor_hits_DiBlock_DCM_and_FEB->Fill(db, dcm, feb);
231  }
232  //count the number of times this happened for this idet,db,dcm,feb, then count the frequency for this. pick out high frequency idet,db,dcm,feb
233  //or the percentage that missing hits and have neighbor hit
234  }
235  if(feb<63){
236  daqChan = daqcmap->encodeDChan(idet,db,dcm,feb+1,pixel);
237  logChan = daqcmap->encodeLChan(daqChan);
238  nbplane = daqcmap->getPlane(logChan);
239  nbcell = daqcmap->getCell(logChan);
240  if(hmap.CellExists(nbplane, nbcell)){
241  if(verbose == 1)
242  std::cout<<"neighbor hit exist at plane: "<<nbplane <<" cell: "<<nbcell<<std::endl;
243  missing_hits_with_neighbor_hits_plane_and_cell->Fill(plane,cell);
244  if(fillTree != 0)
245  missing_hits_with_neighbor_hits_DiBlock_DCM_and_FEB->Fill(db, dcm, feb);
246  }
247  }
248  }
249  }
250  return result;
251 }
252 
254  for (auto ksc : fKnownSwappedChannels){
255  if (ksc == chan)
256  return true;
257  }
258  return false;
259 }
SubRunNumber_t subRun() const
Definition: Event.h:72
FindSwappedChannels(fhicl::ParameterSet const &p)
const char * p
Definition: xmltok.h:285
Definition: event.h:19
const daqchannelmap::DAQChannelMap * Map() const
Definition: CMap.h:57
FindSwappedChannels & operator=(FindSwappedChannels const &)=delete
DEFINE_ART_MODULE(TestTMapFile)
cell_t getCell(lchan logicalchan) const
Decode the cell number from an lchan.
lchan encodeLChan(int detId, plane_t plane, cell_t cell) const
void CountCellsOnLineFast(double x1, double y1, double z1, double x2, double y2, double z2, std::vector< OfflineChan > &Xhitsonline, std::vector< OfflineChan > &Yhitsonline)
Make list of cells in each view traversed by a line segment.
void reconfigure(fhicl::ParameterSet const &p)
Provides efficient lookup of CellHits by plane and cell number.
Definition: HitMap.h:22
bool filter(art::Event &e) override
std::vector< std::string > fKnownSwappedChannelsString
Far Detector at Ash River, MN.
void hits()
Definition: readHits.C:15
static DAQChannelMap * getInstance(int detID)
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
T get(std::string const &key) const
Definition: ParameterSet.h:231
std::vector< geo::OfflineChan > fKnownSwappedChannels
Near Detector in the NuMI cavern.
caf::StandardRecord * sr
EventNumber_t event() const
Definition: Event.h:67
virtual bool beginSubRun(art::SubRun &sr)
Definition: run.py:1
size_type size() const
Definition: PtrVector.h:308
OStream cout
Definition: OStream.cxx:6
static int GetId(std::string name)
pixel_t getPixel(dchan daqchan) const
Decode the pixel id from a dchan.
T * make(ARGS...args) const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
Definition: structs.h:12
A (plane, cell) pair.
Definition: OfflineChan.h:17
exit(0)
plane_t getPlane(lchan logicalchan) const
Decode the plane number from an lchan.
Interface to the run-by-run list of bad channels.
Definition: BadChanList.h:31
dcm_id_t getDCM(dchan daqchan) const
Decode the dcm ID from a dchan.
dchan encodeDChan(int detID, diblock_t diblock, dcm_id_t dcm, feb_t feb, pixel_t pixel) const
bool CellExists(unsigned int planeIdx, unsigned int cellIdx) const
Does the map contain any cell at this position?
Definition: HitMap.cxx:81
Float_t e
Definition: plot.C:35
uint32_t dchan
< DAQ Channel Map Package
RunNumber_t run() const
Definition: Event.h:77
Helper for AttenCurve.
Definition: Path.h:10
Simple object representing a (plane, cell) pair.
diblock_t getDiBlock(dchan daqchan) const
Decode the diblock ID from a dchan.
Encapsulate the geometry of one entire detector (near, far, ndos)
bool failedToGet() const
Definition: Handle.h:196
bool fill_hist_and_tree(std::vector< geo::OfflineChan > &hits, rb::HitMap &hmap, TH2F *missing_hits_plane_and_cell, TH2F *missing_hits_with_neighbor_hits_plane_and_cell, TNtuple *missing_hits_DiBlock_DCM_and_FEB, TNtuple *missing_hits_with_neighbor_hits_DiBlock_DCM_and_FEB, daqchannelmap::DAQChannelMap *daqcmap, int verbose, int idet, int fFillTree)
feb_t getFEB(dchan daqchan) const
Decode the feb id from a dchan.
enum BeamMode string