CVNCosmicTFFilt_module.cc
Go to the documentation of this file.
1 #include<iostream>
2 
10 #include "fhiclcpp/ParameterSet.h"
12 
13 #include "RecoBase/CellHit.h"
14 #include "RecoBase/Cluster.h"
15 #include "RawData/RawDigit.h"
18 
20 #include <boost/algorithm/string.hpp>
21 
22 #include <memory>
23 #include <fstream>
24 #include <iomanip>
25 #include <iostream>
26 
27 namespace cvntf{
29  public:
30  explicit CVNCosmicTFFilt(fhicl::ParameterSet const &pset);
31  virtual ~CVNCosmicTFFilt();
32 
33  void produce(art::Event& evt);
34 
35  protected:
38 
40  /// Read CellHits from this input
42  };
43 }
44 
45 namespace cvntf{
47  fCVNCosmicFiltInput(pset.get<std::string>("CVNCosmicFiltInput")),
48  fApplyHitFilter(pset.get<bool>("ApplyHitFilter")),
50  fCellHitToken(consumes<std::vector<rb::CellHit>>(pset.get<std::string>("CellHitInput")))
51  {
52  produces<std::vector<rb::CellHit> >();
53 
54  }
55 
57  {
58  }
59 
61  {
62 
63 
65  evt.getByToken(fCellHitToken, hitcol);
66  std::vector<rb::CellHit> hitlist = *hitcol;
67  std::sort(hitlist.begin(), hitlist.end(),
68  [](const rb::CellHit& a, const rb::CellHit& b)
69  {return a.TNS() < b.TNS();});
70 
71 
73  evt.getByToken(fFiltList, filtcol);
74  std::vector<cvntf::CVNCosmicFiltList> filtlist = *filtcol;
75 
76  auto cellhitcol = std::make_unique<std::vector<rb::CellHit>>();
77 
78  cvntf::CVNCosmicFiltList cosfiltlist;
79 
80  //
81  // do hit filtering
82  //
83  float minT = -99999;
84  float maxT = -99999;
85  unsigned int cStart = 0;
86  unsigned int checksum = 0;
87  unsigned int hitCount = 0;
88  bool selected = false;
89  for(size_t iP = 0; iP < filtlist[0].ListSize(); ++iP) {
90  cvntf::CVNCosmicFilt cosfilt = filtlist[0].GetTimeSlice(iP);
91 
92  // Keep hits for selected slices or if we are keeping all hits
93  if (!cosfilt.passSel && fApplyHitFilter) continue;
94  unsigned int gapCount = 0;
95  checksum += cosfilt.nHits;
96  minT = cosfilt.timeWinMin;
97  //if we have two consectutive selected slices, count overlap
98  if (selected && (minT < maxT)){
99  for (unsigned int it = 0; it < hitlist.size(); ++it){
100  const rb::CellHit& cell = hitlist[it];
101  if (minT > cell.TNS()) continue;
102  if (cell.TNS() >= maxT) break;
103  gapCount++;
104  }
105  checksum -= gapCount;
106  }
107  if (minT < maxT) minT = maxT;
108  maxT = cosfilt.timeWinMax;
109  for (unsigned int ic = cStart; ic < hitlist.size(); ++ic){
110  const rb::CellHit& cell = hitlist[ic];
111  if (minT > cell.TNS()) continue;
112  if (cell.TNS() >= maxT){
113  cStart = ic;
114  break;
115  }
116  hitCount++;
117  cellhitcol->push_back(cell);
118  }
119  //store selection state for next time slice
120  selected = cosfilt.passSel;
121  if (!fApplyHitFilter) selected = true;
122 
123  } // pixel maps
124 
125  //abort if we are dropping hits and the checksum doesn't match
126  if (checksum != hitCount){
127  std::cout<<"CVNCosmicTFFilter: Expected number of cell hits: "<<
128  checksum<<" not equal to hits in filter list "<<hitCount<<" aborting!"
129  <<std::endl;
130  abort();
131  }
132 
133  evt.put(std::move(cellhitcol));
134 
135  } // produce
136 }
137 
float TNS() const
Definition: CellHit.h:46
set< int >::iterator it
CVNCosmicTFFilt(fhicl::ParameterSet const &pset)
const art::ProductToken< std::vector< cvntf::CVNCosmicFiltList > > fFiltList
DEFINE_ART_MODULE(TestTMapFile)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
const double a
int evt
Perform a "2 point" Hough transform on a collection of hits.
OStream cout
Definition: OStream.cxx:6
A rawdata::RawDigit with channel information decoded.
Definition: CellHit.h:27
void produce(art::Event &evt)
Result for collection of time slices evaluated by CVN for cosmic rejectionN.
const hit & b
Definition: hits.cxx:21
bool getByToken(ProductToken< PROD > const &token, Handle< PROD > &result) const
Definition: DataViewImpl.h:387
ProductToken< T > consumes(InputTag const &)
unsigned int nHits
number of hits in time window
const art::ProductToken< std::vector< rb::CellHit > > fCellHitToken
Read CellHits from this input.
enum BeamMode string