CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTTrackClusterRemover.cc
Go to the documentation of this file.
6 
22 
25 
29 //
30 // class decleration
31 //
32 
34  public:
37  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) ;
38  private:
39  struct ParamBlock {
41  ParamBlock(const edm::ParameterSet& iConfig) :
42  isSet_(true),
43  usesCharge_(iConfig.exists("maxCharge")),
44  usesSize_(iConfig.exists("maxSize")),
45  maxChi2_(iConfig.getParameter<double>("maxChi2")),
46  maxCharge_(usesCharge_ ? iConfig.getParameter<double>("maxCharge") : 0),
47  maxSize_(usesSize_ ? iConfig.getParameter<uint32_t>("maxSize") : 0) { }
50  size_t maxSize_;
51  };
52  static const unsigned int NumberOfParamBlocks = 6;
53 
57  bool mergeOld_;
59 
61  void readPSet(const edm::ParameterSet& iConfig, const std::string &name,
62  int id1=-1, int id2=-1, int id3=-1, int id4=-1, int id5=-1, int id6=-1) ;
63 
64  std::vector<uint8_t> pixels, strips; // avoid unneed alloc/dealloc of this
65  edm::ProductID pixelSourceProdID, stripSourceProdID; // ProdIDs refs must point to (for consistency tests)
66 
67  inline void process(const TrackingRecHit *hit, float chi2);
68  inline void process(const SiStripRecHit2D *hit2D, uint32_t subdet);
69  inline void process(const SiStripRecHit1D *hit1D, uint32_t subdet);
70 
71  template<typename T>
72  std::auto_ptr<edmNew::DetSetVector<T> >
73  cleanup(const edmNew::DetSetVector<T> &oldClusters, const std::vector<uint8_t> &isGood,
75 
76  // Carries in full removal info about a given det from oldRefs
78 
80  std::map<uint32_t, std::set< SiStripRecHit1D::ClusterRegionalRef > > collectedRegStrip;
81  std::map<uint32_t, std::set< SiPixelRecHit::ClusterRef > > collectedPixel;
82 };
83 
84 
85 using namespace std;
86 using namespace edm;
87 using namespace reco;
88 
89 void
90 HLTTrackClusterRemover::readPSet(const edm::ParameterSet& iConfig, const std::string &name,
91  int id1, int id2, int id3, int id4, int id5, int id6)
92 {
93  if (iConfig.exists(name)) {
94  ParamBlock pblock(iConfig.getParameter<ParameterSet>(name));
95  if (id1 == -1) {
96  fill(pblocks_, pblocks_+NumberOfParamBlocks, pblock);
97  } else {
98  pblocks_[id1] = pblock;
99  if (id2 != -1) pblocks_[id2] = pblock;
100  if (id3 != -1) pblocks_[id3] = pblock;
101  if (id4 != -1) pblocks_[id4] = pblock;
102  if (id5 != -1) pblocks_[id5] = pblock;
103  if (id6 != -1) pblocks_[id6] = pblock;
104  }
105  }
106 }
107 
109  trajectories_(iConfig.getParameter<InputTag>("trajectories")),
110  doStrip_(iConfig.existsAs<bool>("doStrip") ? iConfig.getParameter<bool>("doStrip") : true),
111  doPixel_(iConfig.existsAs<bool>("doPixel") ? iConfig.getParameter<bool>("doPixel") : true),
112  stripClusters_(doStrip_ ? iConfig.getParameter<InputTag>("stripClusters") : InputTag("NONE")),
113  pixelClusters_(doPixel_ ? iConfig.getParameter<InputTag>("pixelClusters") : InputTag("NONE")),
114  mergeOld_(false),
115  oldRemovalInfo_(edm::InputTag()),
116  makeProducts_(true)
117 {
118 
119  if (iConfig.exists("oldClusterRemovalInfo"))
120  {
121  oldRemovalInfo_=iConfig.getParameter<InputTag>("oldClusterRemovalInfo");
122  if (not (oldRemovalInfo_== edm::InputTag())) mergeOld_=true;
123  }
124 
126  readPSet(iConfig, "Common",-1);
127  if (doPixel_) {
128  readPSet(iConfig, "Pixel" ,0,1);
129  readPSet(iConfig, "PXB" ,0);
130  readPSet(iConfig, "PXE" ,1);
131  }
132  if (doStrip_) {
133  readPSet(iConfig, "Strip" ,2,3,4,5);
134  readPSet(iConfig, "StripInner" ,2,3);
135  readPSet(iConfig, "StripOuter" ,4,5);
136  readPSet(iConfig, "TIB" ,2);
137  readPSet(iConfig, "TID" ,3);
138  readPSet(iConfig, "TOB" ,4);
139  readPSet(iConfig, "TEC" ,5);
140  }
141 
142  bool usingCharge = false;
143  for (size_t i = 0; i < NumberOfParamBlocks; ++i) {
144  if (!pblocks_[i].isSet_) throw cms::Exception("Configuration Error") << "HLTTrackClusterRemover: Missing configuration for detector with subDetID = " << (i+1);
145  if (pblocks_[i].usesCharge_ && !usingCharge) {
146  throw cms::Exception("Configuration Error") << "HLTTrackClusterRemover: Configuration for subDetID = " << (i+1) << " uses cluster charge, which is not enabled.";
147  }
148  }
149 
150  produces<edmNew::DetSetVector<SiPixelClusterRefNew> >();
151  produces<edmNew::DetSetVector<SiStripRecHit1D::ClusterRegionalRef> >();
152 
153 }
154 
155 
157 {
158 }
159 
161  const ClusterRemovalInfo::Indices &oldRefs)
162 {
163  for (size_t i = 0, n = refs.size(); i < n; ++i) {
164  refs[i] = oldRefs[refs[i]];
165  }
166 }
167 
168 
169 template<typename T>
170 auto_ptr<edmNew::DetSetVector<T> >
171 HLTTrackClusterRemover::cleanup(const edmNew::DetSetVector<T> &oldClusters, const std::vector<uint8_t> &isGood,
173  typedef typename edmNew::DetSetVector<T> DSV;
174  typedef typename edmNew::DetSetVector<T>::FastFiller DSF;
175  typedef typename edmNew::DetSet<T> DS;
176  auto_ptr<DSV> output(new DSV());
177  output->reserve(oldClusters.size(), oldClusters.dataSize());
178 
179  unsigned int countOld=0;
180  unsigned int countNew=0;
181 
182  // cluster removal loop
183  const T * firstOffset = & oldClusters.data().front();
184  for (typename DSV::const_iterator itdet = oldClusters.begin(), enddet = oldClusters.end(); itdet != enddet; ++itdet) {
185  DS oldDS = *itdet;
186 
187  if (oldDS.empty()) continue; // skip empty detsets
188 
189  uint32_t id = oldDS.detId();
190  DSF outds(*output, id);
191 
192  for (typename DS::const_iterator it = oldDS.begin(), ed = oldDS.end(); it != ed; ++it) {
193  uint32_t index = ((&*it) - firstOffset);
194  countOld++;
195  if (isGood[index]) {
196  outds.push_back(*it);
197  countNew++;
198  refs.push_back(index);
199  //std::cout << "HLTTrackClusterRemover::cleanup " << typeid(T).name() << " reference " << index << " to " << (refs.size() - 1) << std::endl;
200  }
201 
202  }
203  if (outds.empty()) outds.abort(); // not write in an empty DSV
204  }
205  // double fraction = countNew / (double) countOld;
206  // std::cout<<"fraction: "<<fraction<<std::endl;
207  if (oldRefs != 0) mergeOld(refs, *oldRefs);
208  return output;
209 }
210 
211 
212 void HLTTrackClusterRemover::process(const SiStripRecHit2D *hit, uint32_t subdet) {
214  if (clusterReg.id() != stripSourceProdID) throw cms::Exception("Inconsistent Data") <<
215  "HLTTrackClusterRemover: strip cluster ref from Product ID = " << clusterReg.id() <<
216  " does not match with source cluster collection (ID = " << stripSourceProdID << ")\n.";
217  collectedRegStrip[hit->geographicalId()].insert(clusterReg);
218 }
219 
220 void HLTTrackClusterRemover::process(const SiStripRecHit1D *hit, uint32_t subdet) {
222  if (clusterReg.id() != stripSourceProdID) throw cms::Exception("Inconsistent Data") <<
223  "HLTTrackClusterRemover: strip cluster ref from Product ID = " << clusterReg.id() <<
224  " does not match with source cluster collection (ID = " << stripSourceProdID << ")\n.";
225  collectedRegStrip[hit->geographicalId()].insert(clusterReg);
226 }
227 
228 
229 
231  DetId detid = hit->geographicalId();
232  uint32_t subdet = detid.subdetId();
233 
234  assert ((subdet > 0) && (subdet <= NumberOfParamBlocks));
235 
236  // chi2 cut
237  if (chi2 > pblocks_[subdet-1].maxChi2_) return;
238 
239  if ((subdet == PixelSubdetector::PixelBarrel) || (subdet == PixelSubdetector::PixelEndcap)) {
240  // std::cout<<"process pxl hit"<<std::endl;
241  if (!doPixel_) return;
242  // this is a pixel, and i *know* it is
243  const SiPixelRecHit *pixelHit = static_cast<const SiPixelRecHit *>(hit);
244 
245  SiPixelRecHit::ClusterRef cluster = pixelHit->cluster();
246 
247  if (cluster.id() != pixelSourceProdID) throw cms::Exception("Inconsistent Data") <<
248  "HLTTrackClusterRemover: pixel cluster ref from Product ID = " << cluster.id() <<
249  " does not match with source cluster collection (ID = " << pixelSourceProdID << ")\n.";
250 
251  assert(cluster.id() == pixelSourceProdID);
252 //DBG// cout << "HIT NEW PIXEL DETID = " << detid.rawId() << ", Cluster [ " << cluster.key().first << " / " << cluster.key().second << " ] " << endl;
253 
254  // if requested, cut on cluster size
255  if (pblocks_[subdet-1].usesSize_ && (cluster->pixels().size() > pblocks_[subdet-1].maxSize_)) return;
256 
257  // mark as used
258  // pixels[cluster.key()] = false;
259 
260  collectedPixel[detid.rawId()].insert(cluster);
261  } else { // aka Strip
262  if (!doStrip_) return;
263  const type_info &hitType = typeid(*hit);
264  if (hitType == typeid(SiStripRecHit2D)) {
265  const SiStripRecHit2D *stripHit = static_cast<const SiStripRecHit2D *>(hit);
266 //DBG// cout << "Plain RecHit 2D: " << endl;
267  process(stripHit,subdet);}
268  else if (hitType == typeid(SiStripRecHit1D)) {
269  const SiStripRecHit1D *hit1D = static_cast<const SiStripRecHit1D *>(hit);
270  process(hit1D,subdet);
271  } else if (hitType == typeid(SiStripMatchedRecHit2D)) {
272  const SiStripMatchedRecHit2D *matchHit = static_cast<const SiStripMatchedRecHit2D *>(hit);
273 //DBG// cout << "Matched RecHit 2D: " << endl;
274  process(matchHit->monoHit(),subdet);
275  process(matchHit->stereoHit(),subdet);
276  } else if (hitType == typeid(ProjectedSiStripRecHit2D)) {
277  const ProjectedSiStripRecHit2D *projHit = static_cast<const ProjectedSiStripRecHit2D *>(hit);
278 //DBG// cout << "Projected RecHit 2D: " << endl;
279  process(&projHit->originalHit(),subdet);
280  } else throw cms::Exception("NOT IMPLEMENTED") << "Don't know how to handle " << hitType.name() << " on detid " << detid.rawId() << "\n";
281  }
282 }
283 
284 /* Schematic picture of n-th step Iterative removal
285  * (that os removing clusters after n-th step tracking)
286  * clusters: [ C1 ] -> [ C2 ] -> ... -> [ Cn ] -> [ Cn + 1 ]
287  * ^ ^ ^--- OUTPUT "new" ID
288  * |-- before any removal |----- Source clusters
289  * |-- OUTPUT "old" ID |----- Hits in Traj. point here
290  * | \----- Old ClusterRemovalInfo "new" ID
291  * \-- Old ClusterRemovalInfo "old" ID
292  */
293 
294 
295 void
297 {
298  ProductID pixelOldProdID, stripOldProdID;
299 
301  if (doPixel_) {
302  iEvent.getByLabel(pixelClusters_, pixelClusters);
303  pixelSourceProdID = pixelClusters.id();
304  }
305 
307  if (doStrip_) {
308  iEvent.getByLabel(stripClusters_, stripClusters);
309  stripSourceProdID = stripClusters.id();
310  }
311 
312  //Handle<TrajTrackAssociationCollection> trajectories;
313  Handle<vector<Trajectory> > trajectories;
314  iEvent.getByLabel(trajectories_, trajectories);
315 
316 
317  //for (TrajTrackAssociationCollection::const_iterator it = trajectories->begin(), ed = trajectories->end(); it != ed; ++it) {
318  // const Trajectory &tj = * it->key;
319  for (vector<Trajectory>::const_iterator it = trajectories->begin(), ed = trajectories->end(); it != ed; ++it) {
320  const Trajectory &tj = * it;
321  const vector<TrajectoryMeasurement> &tms = tj.measurements();
322  vector<TrajectoryMeasurement>::const_iterator itm, endtm;
323  for (itm = tms.begin(), endtm = tms.end(); itm != endtm; ++itm) {
324  const TrackingRecHit *hit = itm->recHit()->hit();
325  if (!hit->isValid()) continue;
326  // std::cout<<"process hit"<<std::endl;
327  process( hit, itm->estimate() );
328  }
329  }
330 
331 
332 
333  auto_ptr<edmNew::DetSetVector<SiPixelClusterRefNew> > removedPixelClsuterRefs(new edmNew::DetSetVector<SiPixelClusterRefNew>());
334  auto_ptr<edmNew::DetSetVector<SiStripRecHit1D::ClusterRegionalRef> > removedStripClsuterRegRefs(new edmNew::DetSetVector<SiStripRecHit1D::ClusterRegionalRef>());
335 
338 
339  if (mergeOld_){
340  iEvent.getByLabel(oldRemovalInfo_,oldPxlRef);
341  iEvent.getByLabel(oldRemovalInfo_,oldStrRegRef);
342  LogDebug("TrackClusterRemover")<<"to merge in, "<<oldStrRegRef->size()<<" strp and "<<oldPxlRef->size()<<" pxl";
343  }
344 
345  if (mergeOld_){
346  for (edmNew::DetSetVector<SiStripRecHit1D::ClusterRegionalRef>::const_iterator itOld=oldStrRegRef->begin();itOld!=oldStrRegRef->end();++itOld){
347  uint32_t id = itOld->detId();
348  collectedRegStrip[id].insert(itOld->begin(),itOld->end());
349  }
350  }
351  for (std::map<uint32_t, std::set< SiStripRecHit1D::ClusterRegionalRef > >::iterator itskiped= collectedRegStrip.begin();
352  itskiped!=collectedRegStrip.end();++itskiped){
353  edmNew::DetSetVector<SiStripRecHit1D::ClusterRegionalRef>::FastFiller fill(*removedStripClsuterRegRefs, itskiped->first);
354  for (std::set< SiStripRecHit1D::ClusterRegionalRef >::iterator topush = itskiped->second.begin();
355  topush!=itskiped->second.end();++topush){
356  fill.push_back(*topush);
357  }
358  if (fill.empty()) fill.abort();
359  itskiped->second.clear();
360  }
361  iEvent.put( removedStripClsuterRegRefs );
362 
363  if (mergeOld_){
364  for (edmNew::DetSetVector<SiPixelClusterRefNew>::const_iterator itOld=oldPxlRef->begin();itOld!=oldPxlRef->end();++itOld){
365  uint32_t id = itOld->detId();
366  collectedPixel[id].insert(itOld->begin(),itOld->end());
367  }
368  }
369 
370  for (std::map<uint32_t, std::set< SiPixelRecHit::ClusterRef > >::iterator itskiped= collectedPixel.begin();
371  itskiped!=collectedPixel.end();++itskiped){
372  edmNew::DetSetVector<SiPixelClusterRefNew>::FastFiller fill(*removedPixelClsuterRefs, itskiped->first);
373  for (std::set< SiPixelRecHit::ClusterRef >::iterator topush = itskiped->second.begin();
374  topush!=itskiped->second.end();++topush){
375  fill.push_back(*topush);
376  }
377  if (fill.empty()) fill.abort();
378  itskiped->second.clear();
379  }
380  iEvent.put( removedPixelClsuterRefs );
381 
382 }
383 
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
void push_back(data_type const &d)
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
const_iterator begin() const
size_type dataSize() const
ProductID id() const
Definition: HandleBase.cc:15
const SiStripRecHit2D * stereoHit() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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)
std::vector< uint8_t > strips
bool exists(std::string const &parameterName) const
checks if a parameter exists
ClusterRegionalRef const & cluster_regional() const
std::vector< uint8_t > pixels
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
DataContainer const & measurements() const
Definition: Trajectory.h:169
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
std::map< uint32_t, std::set< SiStripRecHit1D::ClusterRegionalRef > > collectedRegStrip
static const unsigned int NumberOfParamBlocks
data_type const * data(size_t cell) const
std::map< uint32_t, std::set< SiPixelRecHit::ClusterRef > > collectedPixel
const_iterator end() const
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
std::vector< uint32_t > Indices
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
ParamBlock pblocks_[NumberOfParamBlocks]
void mergeOld(reco::ClusterRemovalInfo::Indices &refs, const reco::ClusterRemovalInfo::Indices &oldRefs)
Definition: DetId.h:20
ParamBlock(const edm::ParameterSet &iConfig)
bool isValid() const
ClusterRegionalRef const & cluster_regional() const
size_type size() const
HLTTrackClusterRemover(const edm::ParameterSet &iConfig)
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
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
Accessor for product ID.
Definition: Ref.h:255
void process(const TrackingRecHit *hit, float chi2)
DetId geographicalId() const
const SiStripRecHit2D * monoHit() const
long double T
ClusterRef const & cluster() const
Definition: SiPixelRecHit.h:42
const SiStripRecHit2D & originalHit() const
Our base class.
Definition: SiPixelRecHit.h:27