CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTPixelClusterShapeFilter.cc
Go to the documentation of this file.
2 
6 
8 
9 //
10 // class declaration
11 //
12 
14 public:
17  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
18 
19 private:
20 
22  edm::InputTag inputTag_; // input tag identifying product containing pixel clusters
23  double minZ_; // beginning z-vertex position
24  double maxZ_; // end z-vertex position
25  double zStep_; // size of steps in z-vertex test
26 
27  std::vector<double> clusterPars_; //pixel cluster polynomial pars for vertex compatibility cut
28  int nhitsTrunc_; //maximum pixel clusters to apply compatibility check
29  double clusterTrunc_; //maximum vertex compatibility value for event rejection
30 
31  struct VertexHit
32  {
33  float z;
34  float r;
35  float w;
36  };
37 
38  virtual bool hltFilter(edm::Event&, const edm::EventSetup&, trigger::TriggerFilterObjectWithRefs & filterproduct) const override;
39  int getContainedHits(const std::vector<VertexHit> &hits, double z0, double &chi) const;
40 
41 };
42 
49 
59 
60 //
61 // constructors and destructor
62 //
63 
65  inputTag_ (config.getParameter<edm::InputTag>("inputTag")),
66  minZ_ (config.getParameter<double>("minZ")),
67  maxZ_ (config.getParameter<double>("maxZ")),
68  zStep_ (config.getParameter<double>("zStep")),
69  clusterPars_ (config.getParameter< std::vector<double> >("clusterPars")),
70  nhitsTrunc_ (config.getParameter<int>("nhitsTrunc")),
71  clusterTrunc_ (config.getParameter<double>("clusterTrunc"))
72 {
73  inputToken_ = consumes<SiPixelRecHitCollection>(inputTag_);
74  LogDebug("") << "Using the " << inputTag_ << " input collection";
75 }
76 
78 {
79 }
80 
81 void
85  desc.add<edm::InputTag>("inputTag",edm::InputTag("hltSiPixelRecHits"));
86  desc.add<double>("minZ",-20.0);
87  desc.add<double>("maxZ",20.05);
88  desc.add<double>("zStep",0.2);
89  std::vector<double> temp; temp.push_back(0.0); temp.push_back(0.0045);
90  desc.add<std::vector<double> >("clusterPars",temp);
91  desc.add<int>("nhitsTrunc",150.);
92  desc.add<double>("clusterTrunc",2.0);
93  descriptions.add("hltPixelClusterShapeFilter",desc);
94 }
95 
96 //
97 // member functions
98 //
99 
100 // ------------ method called to produce the data ------------
102 {
103  // All HLT filters must create and fill an HLT filter object,
104  // recording any reconstructed physics objects satisfying (or not)
105  // this HLT filter, and place it in the Event.
106 
107  // The filter object
108  if (saveTags()) filterproduct.addCollectionTag(inputTag_);
109  bool accept = true;
110 
111  // get hold of products from Event
113  event.getByToken(inputToken_, hRecHits);
114 
115  // get tracker geometry
116  if (hRecHits.isValid()) {
117  edm::ESHandle<TrackerGeometry> trackerHandle;
118  iSetup.get<TrackerDigiGeometryRecord>().get(trackerHandle);
119  const TrackerGeometry *tgeo = trackerHandle.product();
120  const SiPixelRecHitCollection *hits = hRecHits.product();
121 
122  // loop over pixel rechits
123  int nPxlHits=0;
124  std::vector<VertexHit> vhits;
126  end = hits->data().end(); hit != end; ++hit) {
127  if (!hit->isValid())
128  continue;
129  ++nPxlHits;
130  DetId id(hit->geographicalId());
131  if(id.subdetId() != int(PixelSubdetector::PixelBarrel))
132  continue;
133  const PixelGeomDetUnit *pgdu = static_cast<const PixelGeomDetUnit*>(tgeo->idToDet(id));
134  if (1) {
135  const PixelTopology *pixTopo = &(pgdu->specificTopology());
136  std::vector<SiPixelCluster::Pixel> pixels(hit->cluster()->pixels());
137  bool pixelOnEdge = false;
138  for(std::vector<SiPixelCluster::Pixel>::const_iterator pixel = pixels.begin();
139  pixel != pixels.end(); ++pixel) {
140  int pixelX = pixel->x;
141  int pixelY = pixel->y;
142  if(pixTopo->isItEdgePixelInX(pixelX) || pixTopo->isItEdgePixelInY(pixelY)) {
143  pixelOnEdge = true;
144  break;
145  }
146  }
147  if (pixelOnEdge)
148  continue;
149  }
150 
151  LocalPoint lpos = LocalPoint(hit->localPosition().x(),
152  hit->localPosition().y(),
153  hit->localPosition().z());
154  GlobalPoint gpos = pgdu->toGlobal(lpos);
155  VertexHit vh;
156  vh.z = gpos.z();
157  vh.r = gpos.perp();
158  vh.w = hit->cluster()->sizeY();
159  vhits.push_back(vh);
160  }
161 
162  // estimate z-position from cluster lengths
163  double zest = 0.0;
164  int nhits = 0, nhits_max = 0;
165  double chi = 0, chi_max = 1e+9;
166  for(double z0 = minZ_; z0 <= maxZ_; z0 += zStep_) {
167  nhits = getContainedHits(vhits, z0, chi);
168  if(nhits == 0)
169  continue;
170  if(nhits > nhits_max) {
171  chi_max = 1e+9;
172  nhits_max = nhits;
173  }
174  if(nhits >= nhits_max && chi < chi_max) {
175  chi_max = chi;
176  zest = z0;
177  }
178  }
179 
180  chi = 0;
181  int nbest=0, nminus=0, nplus=0;
182  nbest = getContainedHits(vhits,zest,chi);
183  nminus = getContainedHits(vhits,zest-10.,chi);
184  nplus = getContainedHits(vhits,zest+10.,chi);
185 
186  double clusVtxQual=0.0;
187  if ((nminus+nplus)> 0)
188  clusVtxQual = (2.0*nbest)/(nminus+nplus); // A/B
189  else if (nbest>0)
190  clusVtxQual = 1000.0; // A/0 (set to arbitrarily large number)
191  else
192  clusVtxQual = 0; // 0/0 (already the default)
193 
194  // construct polynomial cut on cluster vertex quality vs. npixelhits
195  double polyCut=0;
196  for(unsigned int i=0; i < clusterPars_.size(); i++) {
197  polyCut += clusterPars_[i]*std::pow((double)nPxlHits,(int)i);
198  }
199  if(nPxlHits < nhitsTrunc_)
200  polyCut=0; // don't use cut below nhitsTrunc_ pixel hits
201  if(polyCut > clusterTrunc_ && clusterTrunc_ > 0)
202  polyCut=clusterTrunc_; // no cut above clusterTrunc_
203 
204  if (clusVtxQual < polyCut) accept = false;
205  }
206 
207  // return with final filter decision
208  return accept;
209 }
210 
211 int HLTPixelClusterShapeFilter::getContainedHits(const std::vector<VertexHit> &hits, double z0, double &chi) const
212 {
213  // Calculate number of hits contained in v-shaped window in cluster y-width vs. z-position.
214  int n = 0;
215  chi = 0.;
216 
217  for(std::vector<VertexHit>::const_iterator hit = hits.begin(); hit!= hits.end(); hit++) {
218  double p = 2 * fabs(hit->z - z0)/hit->r + 0.5; // FIXME
219  if(fabs(p - hit->w) <= 1.) {
220  chi += fabs(p - hit->w);
221  n++;
222  }
223  }
224  return n;
225 }
226 
227 
228 // define as a framework module
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:52
int getContainedHits(const std::vector< VertexHit > &hits, double z0, double &chi) const
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:24
edm::EDGetTokenT< SiPixelRecHitCollection > inputToken_
virtual bool isItEdgePixelInX(int ixbin) const =0
virtual bool hltFilter(edm::Event &, const edm::EventSetup &, trigger::TriggerFilterObjectWithRefs &filterproduct) const override
data_type const * data(size_t cell) const
#define end
Definition: vmac.h:37
ParameterDescriptionBase * add(U const &iLabel, T const &value)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:75
Definition: DetId.h:18
static void makeHLTFilterDescription(edm::ParameterSetDescription &desc)
Definition: HLTFilter.cc:29
T const * product() const
Definition: Handle.h:81
const T & get() const
Definition: EventSetup.h:56
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
T const * product() const
Definition: ESHandle.h:86
void addCollectionTag(const edm::InputTag &collectionTag)
collectionTags
void add(std::string const &label, ParameterSetDescription const &psetDescription)
virtual bool isItEdgePixelInY(int iybin) const =0
bool saveTags() const
Definition: HLTFilter.h:45
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
HLTPixelClusterShapeFilter(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
virtual const TrackerGeomDet * idToDet(DetId) const