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  EDProducer(pset),
48  fCVNCosmicFiltInput(pset.get<std::string>("CVNCosmicFiltInput")),
49  fApplyHitFilter(pset.get<bool>("ApplyHitFilter")),
51  fCellHitToken(consumes<std::vector<rb::CellHit>>(pset.get<std::string>("CellHitInput")))
52  {
53  produces<std::vector<rb::CellHit> >();
54 
55  }
56 
58  {
59  }
60 
62  {
63 
64 
66  evt.getByToken(fCellHitToken, hitcol);
67  std::vector<rb::CellHit> hitlist = *hitcol;
68  std::sort(hitlist.begin(), hitlist.end(),
69  [](const rb::CellHit& a, const rb::CellHit& b)
70  {return a.TNS() < b.TNS();});
71 
72 
74  evt.getByToken(fFiltList, filtcol);
75  std::vector<cvntf::CVNCosmicFiltList> filtlist = *filtcol;
76 
77  auto cellhitcol = std::make_unique<std::vector<rb::CellHit>>();
78 
79  cvntf::CVNCosmicFiltList cosfiltlist;
80 
81  //
82  // do hit filtering
83  //
84  float minT = -99999;
85  float maxT = -99999;
86  unsigned int cStart = 0;
87  unsigned int checksum = 0;
88  unsigned int hitCount = 0;
89  bool selected = false;
90  for(size_t iP = 0; iP < filtlist[0].ListSize(); ++iP) {
91  cvntf::CVNCosmicFilt cosfilt = filtlist[0].GetTimeSlice(iP);
92 
93  // Keep hits for selected slices or if we are keeping all hits
94  if (!cosfilt.passSel && fApplyHitFilter) continue;
95  unsigned int gapCount = 0;
96  checksum += cosfilt.nHits;
97  minT = cosfilt.timeWinMin;
98  //if we have two consectutive selected slices, count overlap
99  if (selected && (minT < maxT)){
100  for (unsigned int it = 0; it < hitlist.size(); ++it){
101  const rb::CellHit& cell = hitlist[it];
102  if (minT > cell.TNS()) continue;
103  if (cell.TNS() >= maxT) break;
104  gapCount++;
105  }
106  checksum -= gapCount;
107  }
108  if (minT < maxT) minT = maxT;
109  maxT = cosfilt.timeWinMax;
110  for (unsigned int ic = cStart; ic < hitlist.size(); ++ic){
111  const rb::CellHit& cell = hitlist[ic];
112  if (minT > cell.TNS()) continue;
113  if (cell.TNS() >= maxT){
114  cStart = ic;
115  break;
116  }
117  hitCount++;
118  cellhitcol->push_back(cell);
119  }
120  //store selection state for next time slice
121  selected = cosfilt.passSel;
122  if (!fApplyHitFilter) selected = true;
123 
124  } // pixel maps
125 
126  //abort if we are dropping hits and the checksum doesn't match
127  if (checksum != hitCount){
128  std::cout<<"CVNCosmicTFFilter: Expected number of cell hits: "<<
129  checksum<<" not equal to hits in filter list "<<hitCount<<" aborting!"
130  <<std::endl;
131  abort();
132  }
133 
134  evt.put(std::move(cellhitcol));
135 
136  } // produce
137 }
138 
float TNS() const
Definition: CellHit.h:46
bool getByToken(ProductToken< PROD > const &, Handle< PROD > &result) const
Definition: DataViewImpl.h:462
set< int >::iterator it
CVNCosmicTFFilt(fhicl::ParameterSet const &pset)
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
const art::ProductToken< std::vector< cvntf::CVNCosmicFiltList > > fFiltList
DEFINE_ART_MODULE(TestTMapFile)
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
ProductToken< T > consumes(InputTag const &)
Definition: ModuleBase.h:55
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
Definition: DataViewImpl.h:730
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