CMS 3D CMS Logo

SeedClusterRemover.cc
Go to the documentation of this file.
7 
23 
26 
31 
32 //
33 // class decleration
34 //
35 
37  public:
38  SeedClusterRemover(const edm::ParameterSet& iConfig) ;
39  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override ;
40  private:
41  struct ParamBlock {
43  ParamBlock(const edm::ParameterSet& iConfig) :
44  isSet_(true),
45  usesCharge_(iConfig.exists("maxCharge")),
46  usesSize_(iConfig.exists("maxSize")),
47  maxChi2_(iConfig.getParameter<double>("maxChi2")),
48  maxCharge_(usesCharge_ ? iConfig.getParameter<double>("maxCharge") : 0),
49  maxSize_(usesSize_ ? iConfig.getParameter<uint32_t>("maxSize") : 0) { }
52  size_t maxSize_;
53  };
54  static const unsigned int NumberOfParamBlocks = 6;
55 
57  bool mergeOld_;
58 
66 
67 
69  void readPSet(const edm::ParameterSet& iConfig, const std::string &name,
70  int id1=-1, int id2=-1, int id3=-1, int id4=-1, int id5=-1, int id6=-1) ;
71 
72  std::vector<uint8_t> pixels, strips; // avoid unneed alloc/dealloc of this
73  edm::ProductID pixelSourceProdID, stripSourceProdID; // ProdIDs refs must point to (for consistency tests)
74 
75  inline void process(const TrackingRecHit *hit, float chi2, const TrackerGeometry* tg);
76  inline void process(const OmniClusterRef & cluRef, uint32_t subdet);
77 
78 
79  std::vector<bool> collectedStrips_;
80  std::vector<bool> collectedPixels_;
81 };
82 
83 
84 using namespace std;
85 using namespace edm;
86 
87 void
89  int id1, int id2, int id3, int id4, int id5, int id6)
90 {
91  if (iConfig.exists(name)) {
92  ParamBlock pblock(iConfig.getParameter<ParameterSet>(name));
93  if (id1 == -1) {
95  } else {
96  pblocks_[id1] = pblock;
97  if (id2 != -1) pblocks_[id2] = pblock;
98  if (id3 != -1) pblocks_[id3] = pblock;
99  if (id4 != -1) pblocks_[id4] = pblock;
100  if (id5 != -1) pblocks_[id5] = pblock;
101  if (id6 != -1) pblocks_[id6] = pblock;
102  }
103  }
104 }
105 
107  doStrip_(iConfig.existsAs<bool>("doStrip") ? iConfig.getParameter<bool>("doStrip") : true),
108  doPixel_(iConfig.existsAs<bool>("doPixel") ? iConfig.getParameter<bool>("doPixel") : true),
109  mergeOld_(iConfig.exists("oldClusterRemovalInfo"))
110 {
111 
113  readPSet(iConfig, "Common",-1);
114  if (doPixel_) {
115  readPSet(iConfig, "Pixel" ,0,1);
116  readPSet(iConfig, "PXB" ,0);
117  readPSet(iConfig, "PXE" ,1);
118  }
119  if (doStrip_) {
120  readPSet(iConfig, "Strip" ,2,3,4,5);
121  readPSet(iConfig, "StripInner" ,2,3);
122  readPSet(iConfig, "StripOuter" ,4,5);
123  readPSet(iConfig, "TIB" ,2);
124  readPSet(iConfig, "TID" ,3);
125  readPSet(iConfig, "TOB" ,4);
126  readPSet(iConfig, "TEC" ,5);
127  }
128 
129  bool usingCharge = false;
130  for (size_t i = 0; i < NumberOfParamBlocks; ++i) {
131  if (!pblocks_[i].isSet_) throw cms::Exception("Configuration Error") << "SeedClusterRemover: Missing configuration for detector with subDetID = " << (i+1);
132  if (pblocks_[i].usesCharge_ && !usingCharge) {
133  throw cms::Exception("Configuration Error") << "SeedClusterRemover: Configuration for subDetID = " << (i+1) << " uses cluster charge, which is not enabled.";
134  }
135  }
136 
137 
138  trajectories_ = consumes<TrajectorySeedCollection>(iConfig.getParameter<InputTag>("trajectories"));
139  if (doPixel_) pixelClusters_ = consumes<edmNew::DetSetVector<SiPixelCluster> >(iConfig.getParameter<InputTag>("pixelClusters"));
140  if (doStrip_) stripClusters_ = consumes<edmNew::DetSetVector<SiStripCluster> >(iConfig.getParameter<InputTag>("stripClusters"));
141  if (mergeOld_) {
142  oldPxlMaskToken_ = consumes<PixelMaskContainer>(iConfig.getParameter<InputTag>("oldClusterRemovalInfo"));
143  oldStrMaskToken_ = consumes<StripMaskContainer>(iConfig.getParameter<InputTag>("oldClusterRemovalInfo"));
144  }
145 
146  produces<edm::ContainerMask<edmNew::DetSetVector<SiPixelCluster> > >();
147  produces<edm::ContainerMask<edmNew::DetSetVector<SiStripCluster> > >();
148 }
149 
150 
151 void SeedClusterRemover::process(OmniClusterRef const & ocluster, uint32_t subdet) {
152  SiStripRecHit2D::ClusterRef cluster = ocluster.cluster_strip();
153  if (cluster.id() != stripSourceProdID) throw cms::Exception("Inconsistent Data") <<
154  "SeedClusterRemover: strip cluster ref from Product ID = " << cluster.id() <<
155  " does not match with source cluster collection (ID = " << stripSourceProdID << ")\n.";
156 
157  assert(cluster.id() == stripSourceProdID);
158  if (pblocks_[subdet-1].usesSize_ && (cluster->amplitudes().size() > pblocks_[subdet-1].maxSize_)) return;
159 
160  strips[cluster.key()] = false;
161  assert(collectedStrips_.size() > cluster.key());
162  collectedStrips_[cluster.key()]=true;
163 }
164 
165 
167  DetId detid = hit->geographicalId();
168  uint32_t subdet = detid.subdetId();
169 
170  assert ((subdet > 0) && (subdet <= NumberOfParamBlocks));
171 
172  // chi2 cut
173  if (chi2 > pblocks_[subdet-1].maxChi2_) return;
174 
176  if (!doPixel_) return;
177  // this is a pixel, and i *know* it is
178  const SiPixelRecHit *pixelHit = static_cast<const SiPixelRecHit *>(hit);
179 
180  SiPixelRecHit::ClusterRef cluster = pixelHit->cluster();
181 
182  if (cluster.id() != pixelSourceProdID) throw cms::Exception("Inconsistent Data") <<
183  "SeedClusterRemover: pixel cluster ref from Product ID = " << cluster.id() <<
184  " does not match with source cluster collection (ID = " << pixelSourceProdID << ")\n.";
185 
186  assert(cluster.id() == pixelSourceProdID);
187 //DBG// cout << "HIT NEW PIXEL DETID = " << detid.rawId() << ", Cluster [ " << cluster.key().first << " / " << cluster.key().second << " ] " << endl;
188 
189  // if requested, cut on cluster size
190  if (pblocks_[subdet-1].usesSize_ && (cluster->pixels().size() > pblocks_[subdet-1].maxSize_)) return;
191 
192  // mark as used
193  pixels[cluster.key()] = false;
194 
195  assert(collectedPixels_.size() > cluster.key());
196  collectedPixels_[cluster.key()]=true;
197 
198  } else { // aka Strip
199  if (!doStrip_) return;
200  const type_info &hitType = typeid(*hit);
201  if (hitType == typeid(SiStripRecHit2D)) {
202  const SiStripRecHit2D *stripHit = static_cast<const SiStripRecHit2D *>(hit);
203 //DBG// cout << "Plain RecHit 2D: " << endl;
204  process(stripHit->omniClusterRef(),subdet);}
205  else if (hitType == typeid(SiStripRecHit1D)) {
206  const SiStripRecHit1D *hit1D = static_cast<const SiStripRecHit1D *>(hit);
207  process(hit1D->omniClusterRef(),subdet);
208  } else if (hitType == typeid(SiStripMatchedRecHit2D)) {
209  const SiStripMatchedRecHit2D *matchHit = static_cast<const SiStripMatchedRecHit2D *>(hit);
210 //DBG// cout << "Matched RecHit 2D: " << endl;
211  process(matchHit->monoClusterRef(),subdet);
212  process(matchHit->stereoClusterRef(),subdet);
213  } else if (hitType == typeid(ProjectedSiStripRecHit2D)) {
214  const ProjectedSiStripRecHit2D *projHit = static_cast<const ProjectedSiStripRecHit2D *>(hit);
215 //DBG// cout << "Projected RecHit 2D: " << endl;
216  process(projHit->originalHit().omniClusterRef(),subdet);
217  } else throw cms::Exception("NOT IMPLEMENTED") << "Don't know how to handle " << hitType.name() << " on detid " << detid.rawId() << "\n";
218  }
219 }
220 
221 
222 void
224 {
225 
227  iSetup.get<TrackerDigiGeometryRecord>().get("",tgh); //is it correct to use "" ?
228 
230  if (doPixel_) {
231  iEvent.getByToken(pixelClusters_, pixelClusters);
232  pixelSourceProdID = pixelClusters.id();
233  }
234  //DBG// std::cout << "SeedClusterRemover: Read pixel " << pixelClusters_.encode() << " = ID " << pixelSourceProdID << std::endl;
235 
237  if (doStrip_) {
238  iEvent.getByToken(stripClusters_, stripClusters);
239  stripSourceProdID = stripClusters.id();
240  }
241  //DBG// std::cout << "SeedClusterRemover: Read strip " << stripClusters_.encode() << " = ID " << stripSourceProdID << std::endl;
242 
243 
244  if (doStrip_) {
245  strips.resize(stripClusters->dataSize()); fill(strips.begin(), strips.end(), true);
246  }
247  if (doPixel_) {
248  pixels.resize(pixelClusters->dataSize()); fill(pixels.begin(), pixels.end(), true);
249  }
250  if(mergeOld_) {
253  iEvent.getByToken(oldPxlMaskToken_ ,oldPxlMask);
254  iEvent.getByToken(oldStrMaskToken_ ,oldStrMask);
255  LogDebug("SeedClusterRemover")<<"to merge in, "<<oldStrMask->size()<<" strp and "<<oldPxlMask->size()<<" pxl";
256  oldStrMask->copyMaskTo(collectedStrips_);
257  oldPxlMask->copyMaskTo(collectedPixels_);
258  assert(stripClusters->dataSize()>=collectedStrips_.size());
259  collectedStrips_.resize(stripClusters->dataSize(),false); // for ondemand
260  }else {
261  collectedStrips_.resize(stripClusters->dataSize(), false);
262  collectedPixels_.resize(pixelClusters->dataSize(), false);
263  }
264 
265 
267  iEvent.getByToken(trajectories_,seeds);
268 
269  for (auto const & seed : (*seeds) ){
270  auto hits=seed.recHits();
271  auto hit=hits.first;
272  for (;hit!=hits.second;++hit){
273  if (!hit->isValid()) continue;
274  process( &(*hit), 0. , tgh.product());
275  }
276  }
277 
278 
279  pixels.clear(); strips.clear();
280 
281 
282  LogDebug("SeedClusterRemover")<<"total strip to skip: "<<std::count(collectedStrips_.begin(),collectedStrips_.end(),true);
283  iEvent.put(std::make_unique<StripMaskContainer>(edm::RefProd<edmNew::DetSetVector<SiStripCluster> >(stripClusters),collectedStrips_));
284 
285  LogDebug("SeedClusterRemover")<<"total pxl to skip: "<<std::count(collectedPixels_.begin(),collectedPixels_.end(),true);
286  iEvent.put(std::make_unique<PixelMaskContainer>(edm::RefProd<edmNew::DetSetVector<SiPixelCluster> >(pixelClusters),collectedPixels_));
287 
288  collectedStrips_.clear();
289  collectedPixels_.clear();
290 
291 }
292 
#define LogDebug(id)
T getParameter(std::string const &) const
const GeomDetEnumerators::SubDetector geomDetSubDetector(int subdet) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
ProductID id() const
Definition: HandleBase.cc:15
static const unsigned int NumberOfParamBlocks
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
OmniClusterRef const & stereoClusterRef() const
SeedClusterRemover(const edm::ParameterSet &iConfig)
bool exists(std::string const &parameterName) const
checks if a parameter exists
key_type key() const
Accessor for product key.
Definition: Ref.h:265
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
void copyMaskTo(std::vector< bool > &) const
Definition: ContainerMask.h:91
ProductID id() const
Accessor for product ID.
Definition: Ref.h:259
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
int iEvent
Definition: GenABIO.cc:230
std::vector< bool > collectedStrips_
edm::ProductID pixelSourceProdID
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)
ClusterStripRef cluster_strip() const
ParamBlock pblocks_[NumberOfParamBlocks]
edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > stripClusters_
edm::ContainerMask< edmNew::DetSetVector< SiStripCluster > > StripMaskContainer
edm::ContainerMask< edmNew::DetSetVector< SiPixelCluster > > PixelMaskContainer
size_t size() const
Definition: ContainerMask.h:55
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
edm::EDGetTokenT< TrajectorySeedCollection > trajectories_
edm::ProductID stripSourceProdID
SiStripRecHit2D originalHit() const
Definition: DetId.h:18
OmniClusterRef const & omniClusterRef() const
ParamBlock(const edm::ParameterSet &iConfig)
ClusterRef cluster() const
Definition: SiPixelRecHit.h:49
const T & get() const
Definition: EventSetup.h:58
void process(const TrackingRecHit *hit, float chi2, const TrackerGeometry *tg)
HLT enums.
std::vector< uint8_t > strips
edm::EDGetTokenT< StripMaskContainer > oldStrMaskToken_
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > pixelClusters_
edm::EDGetTokenT< PixelMaskContainer > oldPxlMaskToken_
std::vector< bool > collectedPixels_
std::vector< uint8_t > pixels
DetId geographicalId() const
T const * product() const
Definition: ESHandle.h:86
bool isTrackerPixel(GeomDetEnumerators::SubDetector m)
Our base class.
Definition: SiPixelRecHit.h:23