CMS 3D CMS Logo

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