CMS 3D CMS Logo

HLTTrackClusterRemoverNew.cc
Go to the documentation of this file.
7 
22 
25 
29 
34 
35 //
36 // class decleration
37 //
38 
40  public:
43  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override ;
44  private:
45  struct ParamBlock {
47  ParamBlock(const edm::ParameterSet& iConfig) :
48  isSet_(true),
49  usesCharge_(iConfig.exists("maxCharge")),
50  usesSize_(iConfig.exists("maxSize")),
51  cutOnPixelCharge_(iConfig.exists("minGoodPixelCharge")),
52  cutOnStripCharge_(iConfig.exists("minGoodStripCharge")),
53  maxChi2_(iConfig.getParameter<double>("maxChi2")),
54  maxCharge_(usesCharge_ ? iConfig.getParameter<double>("maxCharge") : 0),
55  minGoodPixelCharge_(cutOnPixelCharge_ ? iConfig.getParameter<double>("minGoodPixelCharge") : 0),
56  minGoodStripCharge_(cutOnStripCharge_ ? iConfig.getParameter<double>("minGoodStripCharge") : 0),
57  maxSize_(usesSize_ ? iConfig.getParameter<uint32_t>("maxSize") : 0) { }
60  size_t maxSize_;
61  };
62  static const unsigned int NumberOfParamBlocks = 6;
63 
64  bool doTracks_;
66  bool mergeOld_;
67 
75 
76 
78  void readPSet(const edm::ParameterSet& iConfig, const std::string &name,
79  int id1=-1, int id2=-1, int id3=-1, int id4=-1, int id5=-1, int id6=-1) ;
80 
81  std::vector<uint8_t> pixels, strips; // avoid unneed alloc/dealloc of this
82  edm::ProductID pixelSourceProdID, stripSourceProdID; // ProdIDs refs must point to (for consistency tests)
83 
84  inline void process(const TrackingRecHit *hit, float chi2, const TrackerGeometry* tg);
85  inline void process(const OmniClusterRef & cluRef, uint32_t subdet);
86 
87  template<typename T>
88  std::unique_ptr<edmNew::DetSetVector<T> >
89  cleanup(const edmNew::DetSetVector<T> &oldClusters, const std::vector<uint8_t> &isGood,
91 
92  // Carries in full removal info about a given det from oldRefs
94 
97  std::vector<bool> collectedRegStrips_;
98  std::vector<bool> collectedPixels_;
99 
100 };
101 
102 
103 using namespace std;
104 using namespace edm;
105 using namespace reco;
106 
107 void
109  int id1, int id2, int id3, int id4, int id5, int id6)
110 {
111  if (iConfig.exists(name)) {
112  ParamBlock pblock(iConfig.getParameter<ParameterSet>(name));
113  if (id1 == -1) {
115  } else {
116  pblocks_[id1] = pblock;
117  if (id2 != -1) pblocks_[id2] = pblock;
118  if (id3 != -1) pblocks_[id3] = pblock;
119  if (id4 != -1) pblocks_[id4] = pblock;
120  if (id5 != -1) pblocks_[id5] = pblock;
121  if (id6 != -1) pblocks_[id6] = pblock;
122  }
123  }
124 }
125 
127  : doTracks_(iConfig.exists("trajectories"))
128  , doStrip_ (iConfig.existsAs<bool>("doStrip") ? iConfig.getParameter<bool>("doStrip") : true)
129  , doPixel_ (iConfig.existsAs<bool>("doPixel") ? iConfig.getParameter<bool>("doPixel") : true)
130  , mergeOld_(false)
132  , doStripChargeCheck_(iConfig.existsAs<bool>("doStripChargeCheck") ? iConfig.getParameter<bool>("doStripChargeCheck") : false)
133  , doPixelChargeCheck_(iConfig.existsAs<bool>("doPixelChargeCheck") ? iConfig.getParameter<bool>("doPixelChargeCheck") : false)
134 
135 {
136 
137  if (iConfig.exists("oldClusterRemovalInfo"))
138  {
139  oldPxlMaskToken_ = consumes<PixelMaskContainer>(iConfig.getParameter<InputTag>("oldClusterRemovalInfo"));
140  oldStrMaskToken_ = consumes<StripMaskContainer>(iConfig.getParameter<InputTag>("oldClusterRemovalInfo"));
141  if (not (iConfig.getParameter<InputTag>("oldClusterRemovalInfo")== edm::InputTag())) mergeOld_=true;
142  }
143 
145  throw cms::Exception("Configuration Error") << "HLTTrackClusterRemoverNew: Charge check asked without cluster collection ";
147  throw cms::Exception("Configuration Error") << "HLTTrackClusterRemoverNew: Pixel cluster charge check not yet implemented";
148 
150  readPSet(iConfig, "Common",-1);
151  if (doPixel_) {
152  readPSet(iConfig, "Pixel" , 0,1);
153  readPSet(iConfig, "PXB" , 0);
154  readPSet(iConfig, "PXE" , 1);
155  }
156  if (doStrip_) {
157  readPSet(iConfig, "Strip" , 2,3,4,5);
158  readPSet(iConfig, "StripInner" ,2,3);
159  readPSet(iConfig, "StripOuter" ,4,5);
160  readPSet(iConfig, "TIB" , 2);
161  readPSet(iConfig, "TID" , 3);
162  readPSet(iConfig, "TOB" , 4);
163  readPSet(iConfig, "TEC" , 5);
164  }
165 
166  bool usingCharge = false;
167  for (size_t i = 0; i < NumberOfParamBlocks; ++i) {
168  if (!pblocks_[i].isSet_) throw cms::Exception("Configuration Error") << "HLTTrackClusterRemoverNew: Missing configuration for detector with subDetID = " << (i+1);
169  if (pblocks_[i].usesCharge_ && !usingCharge) {
170  throw cms::Exception("Configuration Error") << "HLTTrackClusterRemoverNew: Configuration for subDetID = " << (i+1) << " uses cluster charge, which is not enabled.";
171  }
172  }
173 
174  // trajectories_ = consumes<vector<Trajectory> >(iConfig.getParameter<InputTag>("trajectories"));
175  if (doTracks_) trajectories_ = consumes<vector<Trajectory> > (iConfig.getParameter<InputTag>("trajectories") );
176  if (doPixel_) pixelClusters_ = consumes<edmNew::DetSetVector<SiPixelCluster> >(iConfig.getParameter<InputTag>("pixelClusters"));
177  if (doStrip_) stripClusters_ = consumes<edmNew::DetSetVector<SiStripCluster> > (iConfig.getParameter<InputTag>("stripClusters"));
178  if (mergeOld_) {
179  oldPxlMaskToken_ = consumes<PixelMaskContainer>(iConfig.getParameter<InputTag>("oldClusterRemovalInfo"));
180  oldStrMaskToken_ = consumes<StripMaskContainer>(iConfig.getParameter<InputTag>("oldClusterRemovalInfo"));
181  }
182 
183  //produces<edmNew::DetSetVector<SiPixelClusterRefNew> >();
184  //produces<edmNew::DetSetVector<SiStripRecHit1D::ClusterRegionalRef> >();
185 
186  produces< edm::ContainerMask<edmNew::DetSetVector<SiPixelCluster> > >();
187  produces< edm::ContainerMask<edmNew::DetSetVector<SiStripCluster> > >();
188 
189 }
190 
191 
193 {
194 }
195 
197  const ClusterRemovalInfo::Indices &oldRefs)
198 {
199  for (size_t i = 0, n = refs.size(); i < n; ++i) {
200  refs[i] = oldRefs[refs[i]];
201  }
202 }
203 
204 
205 template<typename T>
206 std::unique_ptr<edmNew::DetSetVector<T> >
207 HLTTrackClusterRemoverNew::cleanup(const edmNew::DetSetVector<T> &oldClusters, const std::vector<uint8_t> &isGood,
209  typedef typename edmNew::DetSetVector<T> DSV;
210  typedef typename edmNew::DetSetVector<T>::FastFiller DSF;
211  typedef typename edmNew::DetSet<T> DS;
212  auto output = std::make_unique<DSV>();
213  output->reserve(oldClusters.size(), oldClusters.dataSize());
214 
215  unsigned int countOld=0;
216  unsigned int countNew=0;
217 
218  // cluster removal loop
219  const T * firstOffset = & oldClusters.data().front();
220  for (typename DSV::const_iterator itdet = oldClusters.begin(), enddet = oldClusters.end(); itdet != enddet; ++itdet) {
221  DS oldDS = *itdet;
222 
223  if (oldDS.empty()) continue; // skip empty detsets
224 
225  uint32_t id = oldDS.detId();
226  DSF outds(*output, id);
227 
228  for (typename DS::const_iterator it = oldDS.begin(), ed = oldDS.end(); it != ed; ++it) {
229  uint32_t index = ((&*it) - firstOffset);
230  countOld++;
231  if (isGood[index]) {
232  outds.push_back(*it);
233  countNew++;
234  refs.push_back(index);
235  //std::cout << "HLTTrackClusterRemoverNew::cleanup " << typeid(T).name() << " reference " << index << " to " << (refs.size() - 1) << std::endl;
236  }
237 
238  }
239  if (outds.empty()) outds.abort(); // not write in an empty DSV
240  }
241  // double fraction = countNew / (double) countOld;
242  // std::cout<<"fraction: "<<fraction<<std::endl;
243  if (oldRefs != 0) mergeOld(refs, *oldRefs);
244  return output;
245 }
246 
247 void HLTTrackClusterRemoverNew::process(OmniClusterRef const & clusterReg, uint32_t subdet) {
248 
249  if (clusterReg.id() != stripSourceProdID) throw cms::Exception("Inconsistent Data") <<
250  "HLTTrackClusterRemoverNew: strip cluster ref from Product ID = " << clusterReg.id() <<
251  " does not match with source cluster collection (ID = " << stripSourceProdID << ")\n.";
252 
253  if (collectedRegStrips_.size()<=clusterReg.key()){
254  edm::LogError("BadCollectionSize")<<collectedRegStrips_.size()<<" is smaller than "<<clusterReg.key();
255 
256  assert(collectedRegStrips_.size()>clusterReg.key());
257  }
258  collectedRegStrips_[clusterReg.key()]=true;
259 }
260 
261 
262 
264  DetId detid = hit->geographicalId();
265  uint32_t subdet = detid.subdetId();
266 
267 
268  assert ((subdet > 0) && (subdet <= NumberOfParamBlocks));
269 
270  // chi2 cut
271  if (chi2 > pblocks_[subdet-1].maxChi2_) return;
272 
274  // std::cout<<"process pxl hit"<<std::endl;
275  if (!doPixel_) return;
276  // this is a pixel, and i *know* it is
277  const SiPixelRecHit *pixelHit = static_cast<const SiPixelRecHit *>(hit);
278 
279  SiPixelRecHit::ClusterRef cluster = pixelHit->cluster();
280  if (cluster.id() != pixelSourceProdID) throw cms::Exception("Inconsistent Data") <<
281  "HLTTrackClusterRemoverNew: pixel cluster ref from Product ID = " << cluster.id() <<
282  " does not match with source cluster collection (ID = " << pixelSourceProdID << ")\n.";
283 
284  assert(cluster.id() == pixelSourceProdID);
285  //DBG// cout << "HIT NEW PIXEL DETID = " << detid.rawId() << ", Cluster [ " << cluster.key().first << " / " << cluster.key().second << " ] " << endl;
286 
287  // if requested, cut on cluster size
288  if (pblocks_[subdet-1].usesSize_ && (cluster->pixels().size() > pblocks_[subdet-1].maxSize_)) return;
289 
290  // mark as used
291  //pixels[cluster.key()] = false;
292  assert(collectedPixels_.size() > cluster.key());
293  collectedPixels_[cluster.key()]=true;
294  } else { // aka Strip
295  if (!doStrip_) return;
296  const type_info &hitType = typeid(*hit);
297  if (hitType == typeid(SiStripRecHit2D)) {
298  const SiStripRecHit2D *stripHit = static_cast<const SiStripRecHit2D *>(hit);
299  //DBG// cout << "Plain RecHit 2D: " << endl;
300  process(stripHit->omniClusterRef(),subdet);
301  // int clusCharge=0;
302  // for ( auto cAmp : stripHit->omniClusterRef().stripCluster().amplitudes() ) clusCharge+=cAmp;
303  // std::cout << "[HLTTrackClusterRemoverNew::process (SiStripRecHit2D) chi2: " << chi2 << " [" << subdet << " --> charge: " << clusCharge << "]" << std::endl;
304  } else if (hitType == typeid(SiStripRecHit1D)) {
305  const SiStripRecHit1D *hit1D = static_cast<const SiStripRecHit1D *>(hit);
306  process(hit1D->omniClusterRef(),subdet);
307  // int clusCharge=0;
308  // for ( auto cAmp : hit1D->omniClusterRef().stripCluster().amplitudes() ) clusCharge+=cAmp;
309  // std::cout << "[HLTTrackClusterRemoverNew::process (SiStripRecHit1D) chi2: " << chi2 << " [" << subdet << " --> charge: " << clusCharge << "]" << std::endl;
310  } else if (hitType == typeid(SiStripMatchedRecHit2D)) {
311  const SiStripMatchedRecHit2D *matchHit = static_cast<const SiStripMatchedRecHit2D *>(hit);
312  //DBG// cout << "Matched RecHit 2D: " << endl;
313  process(matchHit->monoClusterRef(), subdet);
314  // int clusCharge=0;
315  // for ( auto cAmp : matchHit->monoClusterRef().stripCluster().amplitudes() ) clusCharge+=cAmp;
316  // std::cout << "[HLTTrackClusterRemoverNew::process (SiStripMatchedRecHit2D:mono) chi2: " << chi2 << " [" << subdet << " --> charge: " << clusCharge << "]" << std::endl;
317 
318  process(matchHit->stereoClusterRef(),subdet);
319  // clusCharge=0;
320  // for ( auto cAmp : matchHit->stereoClusterRef().stripCluster().amplitudes() ) clusCharge+=cAmp;
321  // std::cout << "[HLTTrackClusterRemoverNew::process (SiStripMatchedRecHit2D:stereo) chi2: " << chi2 << " [" << subdet << " --> charge: " << clusCharge << "]" << std::endl;
322 
323  } else if (hitType == typeid(ProjectedSiStripRecHit2D)) {
324  const ProjectedSiStripRecHit2D *projHit = static_cast<const ProjectedSiStripRecHit2D *>(hit);
325  //DBG// cout << "Projected RecHit 2D: " << endl;
326  process(projHit->originalHit().omniClusterRef(),subdet);
327  // int clusCharge=0;
328  // for ( auto cAmp : projHit->originalHit().omniClusterRef().stripCluster().amplitudes() ) clusCharge+=cAmp;
329  // std::cout << "[HLTTrackClusterRemoverNew::process (ProjectedSiStripRecHit2D) chi2: " << chi2 << " [" << subdet << " --> charge: " << clusCharge << "]" << std::endl;
330  } else throw cms::Exception("NOT IMPLEMENTED") << "Don't know how to handle " << hitType.name() << " on detid " << detid.rawId() << "\n";
331  }
332 }
333 
334 /* Schematic picture of n-th step Iterative removal
335  * (that os removing clusters after n-th step tracking)
336  * clusters: [ C1 ] -> [ C2 ] -> ... -> [ Cn ] -> [ Cn + 1 ]
337  * ^ ^ ^--- OUTPUT "new" ID
338  * |-- before any removal |----- Source clusters
339  * |-- OUTPUT "old" ID |----- Hits in Traj. point here
340  * | \----- Old ClusterRemovalInfo "new" ID
341  * \-- Old ClusterRemovalInfo "old" ID
342  */
343 
344 
345 void
347 {
348  ProductID pixelOldProdID, stripOldProdID;
349 
351  iSetup.get<TrackerDigiGeometryRecord>().get(tgh);
352 
354  if (doPixel_) {
355  iEvent.getByToken(pixelClusters_, pixelClusters);
356  pixelSourceProdID = pixelClusters.id();
357  }
358 
360  if (doStrip_) {
361  iEvent.getByToken(stripClusters_, stripClusters);
362  stripSourceProdID = stripClusters.id();
363  }
364 
365  //Handle<TrajTrackAssociationCollection> trajectories;
367  iEvent.getByToken(trajectories_, trajectories);
368 
369  if(mergeOld_) {
372  iEvent.getByToken(oldPxlMaskToken_ ,oldPxlMask);
373  iEvent.getByToken(oldStrMaskToken_ ,oldStrMask);
374  LogDebug("TrackClusterRemover")<<"to merge in, "<<oldStrMask->size()<<" strp and "<<oldPxlMask->size()<<" pxl";
375  oldStrMask->copyMaskTo(collectedRegStrips_);
376  oldPxlMask->copyMaskTo(collectedPixels_);
377  collectedRegStrips_.resize(stripClusters->dataSize(),false);
378  }else {
379  collectedRegStrips_.resize(stripClusters->dataSize(), false);
380  collectedPixels_.resize(pixelClusters->dataSize(), false);
381  }
382 
383 
384  //for (TrajTrackAssociationCollection::const_iterator it = trajectories->begin(), ed = trajectories->end(); it != ed; ++it) {
385  // const Trajectory &tj = * it->key;
386 
387  for (std::vector<Trajectory>::const_iterator it = trajectories->begin(), ed = trajectories->end(); it != ed; ++it) {
388  const Trajectory &tj = * it;
389  const std::vector<TrajectoryMeasurement> &tms = tj.measurements();
390 
391  std::vector<TrajectoryMeasurement>::const_iterator itm, endtm;
392  for (itm = tms.begin(), endtm = tms.end(); itm != endtm; ++itm) {
393 
394  const TrackingRecHit *hit = itm->recHit()->hit();
395  if (!hit->isValid()) continue;
396  // std::cout<<"process hit"<<std::endl;
397  process( hit, itm->estimate() , tgh.product());
398  }
399  }
400 
401 
402  // std::cout << " => collectedRegStrips_: " << collectedRegStrips_.size() << std::endl;
403  // std::cout << " total strip to skip (before charge check): "<<std::count(collectedRegStrips_.begin(),collectedRegStrips_.end(),true) << std::endl;
404 
405 
406  // checks only cluster already found! creates regression
407  if (doStripChargeCheck_) {
408  // std::cout << "[HLTTrackClusterRemoverNew::produce] doStripChargeCheck_: " << (doStripChargeCheck_ ? "true" : "false") << " stripClusters: " << stripClusters->size() << std::endl;
409 
410 
411  auto const & clusters = stripClusters->data();
412  for (auto const & item : stripClusters->ids()) {
413 
414  if (!item.isValid()) continue; // not umpacked
415 
416  DetId detid = item.id;
417  uint32_t subdet = detid.subdetId();
418  if (!pblocks_[subdet-1].cutOnStripCharge_) continue;
419 
420  // std::cout << " i: " << i << " --> detid: " << detid << " --> subdet: " << subdet << std::endl;
421 
422  for (int i = item.offset; i<item.offset+int(item.size); ++i) {
423  int clusCharge=0;
424  for ( auto cAmp : clusters[i].amplitudes() ) clusCharge+=cAmp;
425 
426  // if (clusCharge < pblocks_[subdet-1].minGoodStripCharge_) std::cout << " clusCharge: " << clusCharge << std::endl;
427  if(clusCharge < pblocks_[subdet-1].minGoodStripCharge_) collectedRegStrips_[i] = true; // (|= does not work!)
428  }
429 
430  }
431  }
432 
433  // std::cout << " => collectedRegStrips_: " << collectedRegStrips_.size() << std::endl;
434  // std::cout << " total strip to skip: "<<std::count(collectedRegStrips_.begin(),collectedRegStrips_.end(),true) << std::endl;
435  LogDebug("TrackClusterRemover")<<"total strip to skip: "<<std::count(collectedRegStrips_.begin(),collectedRegStrips_.end(),true);
436  // std::cout << "TrackClusterRemover" <<" total strip to skip: "<<std::count(collectedRegStrips_.begin(),collectedRegStrips_.end(),true)<<std::endl;
437  iEvent.put(std::make_unique<StripMaskContainer>(edm::RefProd<edmNew::DetSetVector<SiStripCluster> >(stripClusters),collectedRegStrips_));
438 
439  LogDebug("TrackClusterRemover")<<"total pxl to skip: "<<std::count(collectedPixels_.begin(),collectedPixels_.end(),true);
440  iEvent.put(std::make_unique<PixelMaskContainer>(edm::RefProd<edmNew::DetSetVector<SiPixelCluster> >(pixelClusters),collectedPixels_));
441 
442  collectedRegStrips_.clear();
443  collectedPixels_.clear();
444 
445 
446 }
447 
#define LogDebug(id)
T getParameter(std::string const &) const
edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > stripClusters_
const GeomDetEnumerators::SubDetector geomDetSubDetector(int subdet) const
const_iterator end(bool update=false) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
size_type dataSize() const
static const unsigned int NumberOfParamBlocks
ProductID id() const
Definition: HandleBase.cc:15
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > pixelClusters_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
OmniClusterRef const & stereoClusterRef() const
bool exists(std::string const &parameterName) const
checks if a parameter exists
key_type key() const
Accessor for product key.
Definition: Ref.h:264
void copyMaskTo(std::vector< bool > &) const
Definition: ContainerMask.h:90
ProductID id() const
Accessor for product ID.
Definition: Ref.h:258
edm::EDGetTokenT< PixelMaskContainer > oldPxlMaskToken_
HLTTrackClusterRemoverNew(const edm::ParameterSet &iConfig)
edm::ContainerMask< edmNew::DetSetVector< SiStripCluster > > StripMaskContainer
std::unique_ptr< edmNew::DetSetVector< T > > cleanup(const edmNew::DetSetVector< T > &oldClusters, const std::vector< uint8_t > &isGood, reco::ClusterRemovalInfo::Indices &refs, const reco::ClusterRemovalInfo::Indices *oldRefs)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
void readPSet(const edm::ParameterSet &iConfig, const std::string &name, int id1=-1, int id2=-1, int id3=-1, int id4=-1, int id5=-1, int id6=-1)
DataContainer const & measurements() const
Definition: Trajectory.h:196
int iEvent
Definition: GenABIO.cc:230
void process(const TrackingRecHit *hit, float chi2, const TrackerGeometry *tg)
ParamBlock pblocks_[NumberOfParamBlocks]
data_type const * data(size_t cell) const
edm::EDGetTokenT< std::vector< Trajectory > > trajectories_
size_t size() const
Definition: ContainerMask.h:54
OmniClusterRef const & monoClusterRef() const
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
std::vector< uint32_t > Indices
SiStripRecHit2D originalHit() const
Definition: DetId.h:18
OmniClusterRef const & omniClusterRef() const
ClusterRef cluster() const
Definition: SiPixelRecHit.h:49
const T & get() const
Definition: EventSetup.h:56
void mergeOld(reco::ClusterRemovalInfo::Indices &refs, const reco::ClusterRemovalInfo::Indices &oldRefs)
bool isValid() const
bool isTrackerPixel(const GeomDetEnumerators::SubDetector m)
size_type size() const
fixed size matrix
edm::ProductID id() const
HLT enums.
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
ParamBlock(const edm::ParameterSet &iConfig)
DetId geographicalId() const
edm::ContainerMask< edmNew::DetSetVector< SiPixelCluster > > PixelMaskContainer
long double T
unsigned int key() const
T const * product() const
Definition: ESHandle.h:86
const_iterator begin(bool update=false) const
edm::EDGetTokenT< StripMaskContainer > oldStrMaskToken_
Our base class.
Definition: SiPixelRecHit.h:23