CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SeedClusterRemoverPhase2.cc
Go to the documentation of this file.
7 
10 
14 
21 
24 
29 
34 
35 //
36 // class decleration
37 //
38 
40 
41  public:
44  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override ;
45  private:
47  bool mergeOld_;
56 
57  std::vector<uint8_t> pixels, OTs; // avoid unneed alloc/dealloc of this
58  edm::ProductID pixelSourceProdID, outerTrackerSourceProdID; // ProdIDs refs must point to (for consistency tests)
59 
60  inline void process(const TrackingRecHit *hit, float chi2, const TrackerGeometry* tg);
61 
62  template<typename T>
63  std::unique_ptr<edmNew::DetSetVector<T> >
64  cleanup(const edmNew::DetSetVector<T> &oldClusters, const std::vector<uint8_t> &isGood,
66 
67  // Carries in full removal info about a given det from oldRefs
69 
73  std::vector<bool> collectedOuterTrackers_;
74  std::vector<bool> collectedPixels_;
75 };
76 
77 
78 using namespace std;
79 using namespace edm;
80 using namespace reco;
81 
83  doOuterTracker_(iConfig.existsAs<bool>("doOuterTracker") ? iConfig.getParameter<bool>("doOuterTracker") : true),
84  doPixel_(iConfig.existsAs<bool>("doPixel") ? iConfig.getParameter<bool>("doPixel") : true),
85  mergeOld_(iConfig.exists("oldClusterRemovalInfo")),
86  clusterWasteSolution_(true)
87 {
88  if (iConfig.exists("clusterLessSolution"))
89  clusterWasteSolution_=!iConfig.getParameter<bool>("clusterLessSolution");
90  if (doPixel_ && clusterWasteSolution_) produces< edmNew::DetSetVector<SiPixelCluster> >();
91  if (doOuterTracker_ && clusterWasteSolution_) produces< edmNew::DetSetVector<Phase2TrackerCluster1D> >();
92  if (clusterWasteSolution_) produces< ClusterRemovalInfo >();
93 
95  produces<edm::ContainerMask<edmNew::DetSetVector<SiPixelCluster> > >();
96  produces<edm::ContainerMask<edmNew::DetSetVector<Phase2TrackerCluster1D> > >();
97  }
99  filterTracks_=false;
100  if (iConfig.exists("TrackQuality")){
101  filterTracks_=true;
103  }
104 
105  trajectories_ = consumes<TrajectorySeedCollection>(iConfig.getParameter<InputTag>("trajectories"));
106  if (doPixel_) pixelClusters_ = consumes<edmNew::DetSetVector<SiPixelCluster> >(iConfig.getParameter<InputTag>("pixelClusters"));
107  if (doOuterTracker_) phase2OTClusters_ = consumes<edmNew::DetSetVector<Phase2TrackerCluster1D> >(iConfig.getParameter<InputTag>("phase2OTClusters"));
108  if (mergeOld_) {
109  oldRemovalInfo_ = consumes<ClusterRemovalInfo>(iConfig.getParameter<InputTag>("oldClusterRemovalInfo"));
110  oldPxlMaskToken_ = consumes<PixelMaskContainer>(iConfig.getParameter<InputTag>("oldClusterRemovalInfo"));
111  oldPh2OTMaskToken_ = consumes<Phase2OTMaskContainer>(iConfig.getParameter<InputTag>("oldClusterRemovalInfo"));
112  }
113 }
114 
115 
117 {
118 }
119 
121  const ClusterRemovalInfo::Indices &oldRefs)
122 {
123  for (size_t i = 0, n = refs.size(); i < n; ++i) {
124  refs[i] = oldRefs[refs[i]];
125  }
126 }
127 
128 
129 template<typename T>
130 std::unique_ptr<edmNew::DetSetVector<T> >
131 SeedClusterRemoverPhase2::cleanup(const edmNew::DetSetVector<T> &oldClusters, const std::vector<uint8_t> &isGood,
133  typedef typename edmNew::DetSetVector<T> DSV;
134  typedef typename edmNew::DetSetVector<T>::FastFiller DSF;
135  typedef typename edmNew::DetSet<T> DS;
136  auto output = std::make_unique<DSV>();
137  output->reserve(oldClusters.size(), oldClusters.dataSize());
138 
139  unsigned int countOld=0;
140  unsigned int countNew=0;
141 
142  // cluster removal loop
143  const T * firstOffset = & oldClusters.data().front();
144  for (typename DSV::const_iterator itdet = oldClusters.begin(), enddet = oldClusters.end(); itdet != enddet; ++itdet) {
145  DS oldDS = *itdet;
146 
147  if (oldDS.empty()) continue; // skip empty detsets
148 
149  uint32_t id = oldDS.detId();
150  DSF outds(*output, id);
151 
152  for (typename DS::const_iterator it = oldDS.begin(), ed = oldDS.end(); it != ed; ++it) {
153  uint32_t index = ((&*it) - firstOffset);
154  countOld++;
155  if (isGood[index]) {
156  outds.push_back(*it);
157  countNew++;
158  refs.push_back(index);
159  LogDebug("SeedClusterRemoverPhase2") << "SeedClusterRemoverPhase2::cleanup " << typeid(T).name() << " reference " << index << " to " << (refs.size() - 1);
160  }
161 
162  }
163  if (outds.empty()) outds.abort(); // not write in an empty DSV
164  }
165 
166  if (oldRefs != 0) mergeOld(refs, *oldRefs);
167  return output;
168 }
169 
170 
171 
172 
174 
175  DetId detid = hit->geographicalId();
176  uint32_t subdet = detid.subdetId();
177 
178  assert(subdet > 0);
179 
180  const type_info &hitType = typeid(*hit);
181  if (hitType == typeid(SiPixelRecHit)) {
182 
183  if(!doPixel_) return;
184 
185  const SiPixelRecHit *pixelHit = static_cast<const SiPixelRecHit *>(hit);
186  SiPixelRecHit::ClusterRef cluster = pixelHit->cluster();
187  LogDebug("SeedClusterRemoverPhase2") << "Plain Pixel RecHit in det " << detid.rawId();
188 
189  if (cluster.id() != pixelSourceProdID) throw cms::Exception("Inconsistent Data") <<
190  "SeedClusterRemoverPhase2: pixel cluster ref from Product ID = " << cluster.id() <<
191  " does not match with source cluster collection (ID = " << pixelSourceProdID << ")\n.";
192 
193  assert(cluster.id() == pixelSourceProdID);
194 
195  // mark as used
196  pixels[cluster.key()] = false;
197 
198  assert(collectedPixels_.size() > cluster.key());
199  if(!clusterWasteSolution_) collectedPixels_[cluster.key()]=true;
200 
201  } else if (hitType == typeid(Phase2TrackerRecHit1D)) {
202 
203  if(!doOuterTracker_) return;
204 
205  const Phase2TrackerRecHit1D *ph2OThit = static_cast<const Phase2TrackerRecHit1D*>(hit);
206  LogDebug("SeedClusterRemoverPhase2") << "Plain Phase2TrackerRecHit1D in det " << detid.rawId();
207 
208  Phase2TrackerRecHit1D::CluRef cluster = ph2OThit->cluster();
209  if (cluster.id() != outerTrackerSourceProdID) throw cms::Exception("Inconsistent Data") <<
210  "SeedClusterRemoverPhase2: strip cluster ref from Product ID = " << cluster.id() <<
211  " does not match with source cluster collection (ID = " << outerTrackerSourceProdID << ")\n.";
212 
213  assert(cluster.id() == outerTrackerSourceProdID);
214 
215  OTs[cluster.key()] = false;
216  assert(collectedOuterTrackers_.size() > cluster.key());
217  if (!clusterWasteSolution_) collectedOuterTrackers_[cluster.key()]=true;
218 
219  } else throw cms::Exception("NOT IMPLEMENTED") << "I received a hit that was neither SiPixelRecHit nor Phase2TrackerRecHit1D but " << hitType.name() << " on detid " << detid.rawId() << "\n";
220 
221 
222 }
223 
224 void
226 {
227  ProductID pixelOldProdID, stripOldProdID;
228 
230  iSetup.get<TrackerDigiGeometryRecord>().get("",tgh); //is it correct to use "" ?
231 
233  if (doPixel_) {
234  iEvent.getByToken(pixelClusters_, pixelClusters);
235  pixelSourceProdID = pixelClusters.id();
236  }
237  LogDebug("SeedClusterRemoverPhase2") << "Read pixel with id " << pixelSourceProdID << std::endl;
238 
240  if (doOuterTracker_) {
241  iEvent.getByToken(phase2OTClusters_, phase2OTClusters);
242  outerTrackerSourceProdID = phase2OTClusters.id();
243  }
244  LogDebug("SeedClusterRemoverPhase2") << "Read OT cluster with id " << outerTrackerSourceProdID << std::endl;
245 
246  std::unique_ptr<ClusterRemovalInfo> cri;
248  if (doOuterTracker_ && doPixel_) cri = std::make_unique<ClusterRemovalInfo>(pixelClusters, phase2OTClusters);
249  else if (doOuterTracker_) cri = std::make_unique<ClusterRemovalInfo>(phase2OTClusters);
250  else if (doPixel_) cri = std::make_unique<ClusterRemovalInfo>(pixelClusters);
251  }
252 
253  Handle<ClusterRemovalInfo> oldRemovalInfo;
255  iEvent.getByToken(oldRemovalInfo_, oldRemovalInfo);
256  // Check ProductIDs
257  if ( (oldRemovalInfo->stripNewRefProd().id() == phase2OTClusters.id()) &&
258  (oldRemovalInfo->pixelNewRefProd().id() == pixelClusters.id()) ) {
259 
260  cri->getOldClustersFrom(*oldRemovalInfo);
261 
262  pixelOldProdID = oldRemovalInfo->pixelRefProd().id();
263  stripOldProdID = oldRemovalInfo->stripRefProd().id();
264 
265  } else {
268  throw cms::Exception("Inconsistent Data") << "SeedClusterRemoverPhase2: " <<
269  "Input collection product IDs are [pixel: " << pixelClusters.id() << ", strip: " << phase2OTClusters.id() << "] \n" <<
270  "\t but the *old* ClusterRemovalInfo " << labels.productInstance << " refers as 'new product ids' to " <<
271  "[pixel: " << oldRemovalInfo->pixelNewRefProd().id() << ", strip: " << oldRemovalInfo->stripNewRefProd().id() << "]\n" <<
272  "NOTA BENE: when running SeedClusterRemoverPhase2 with an old ClusterRemovalInfo the hits in the trajectory MUST be already re-keyed.\n";
273  }
274  } else { // then Old == Source
275  pixelOldProdID = pixelSourceProdID;
276  stripOldProdID = outerTrackerSourceProdID;
277  }
278 
279  if (doOuterTracker_) {
280  OTs.resize(phase2OTClusters->dataSize()); fill(OTs.begin(), OTs.end(), true);
281  }
282  if (doPixel_) {
283  pixels.resize(pixelClusters->dataSize()); fill(pixels.begin(), pixels.end(), true);
284  }
285  if(mergeOld_) {
288  iEvent.getByToken(oldPxlMaskToken_ ,oldPxlMask);
289  iEvent.getByToken(oldPh2OTMaskToken_ ,oldPh2OTMask);
290  LogDebug("SeedClusterRemoverPhase2") << "to merge in, "<<oldPh2OTMask->size()<<" strp and "<<oldPxlMask->size()<<" pxl";
291  oldPh2OTMask->copyMaskTo(collectedOuterTrackers_);
292  oldPxlMask->copyMaskTo(collectedPixels_);
293  assert(phase2OTClusters->dataSize()>=collectedOuterTrackers_.size());
294  collectedOuterTrackers_.resize(phase2OTClusters->dataSize(),false); // for ondemand
295  }else {
296  collectedOuterTrackers_.resize(phase2OTClusters->dataSize(), false);
297  collectedPixels_.resize(pixelClusters->dataSize(), false);
298  }
299 
300 
302  iEvent.getByToken(trajectories_,seeds);
303 
304  TrajectorySeedCollection::const_iterator seed=seeds->begin();
305 
306  for (;seed!=seeds->end();++seed){
307  TrajectorySeed::range hits=seed->recHits();
309  for (;hit!=hits.second;++hit){
310  if (!hit->isValid()) continue;
311  process( &(*hit), 0. , tgh.product());
312  }
313  }
314 
315 
318  iEvent.put(cleanup(*pixelClusters, pixels, cri->pixelIndices(), mergeOld_ ? &oldRemovalInfo->pixelIndices() : 0));
319  LogDebug("SeedClusterRemoverPhase2") << "SeedClusterRemoverPhase2: Wrote pixel " << newPixels.id() << " from " << pixelSourceProdID ;
320  cri->setNewPixelClusters(newPixels);
321  }
324  iEvent.put(cleanup(*phase2OTClusters, OTs, cri->stripIndices(), mergeOld_ ? &oldRemovalInfo->stripIndices() : 0));
325  LogDebug("SeedClusterRemoverPhase2") << "SeedClusterRemoverPhase2: Wrote strip " << newOuterTrackers.id() << " from " << outerTrackerSourceProdID;
326  cri->setNewPhase2OTClusters(newOuterTrackers);
327  }
328 
329 
330  if (clusterWasteSolution_) {
331  iEvent.put(std::move(cri));
332  }
333 
334  pixels.clear(); OTs.clear();
335 
336  if (!clusterWasteSolution_){
337 
338  LogDebug("SeedClusterRemoverPhase2")<<"total strip to skip: "<<std::count(collectedOuterTrackers_.begin(),collectedOuterTrackers_.end(),true);
339  iEvent.put(std::make_unique<Phase2OTMaskContainer>(edm::RefProd<edmNew::DetSetVector<Phase2TrackerCluster1D> >(phase2OTClusters),collectedOuterTrackers_));
340 
341  LogDebug("SeedClusterRemoverPhase2")<<"total pxl to skip: "<<std::count(collectedPixels_.begin(),collectedPixels_.end(),true);
342  iEvent.put(std::make_unique<PixelMaskContainer>(edm::RefProd<edmNew::DetSetVector<SiPixelCluster> >(pixelClusters),collectedPixels_));
343 
344  }
345  collectedOuterTrackers_.clear();
346  collectedPixels_.clear();
347 
348 }
349 
#define LogDebug(id)
std::vector< bool > collectedPixels_
std::vector< bool > collectedOuterTrackers_
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
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
string fill
Definition: lumiContext.py:319
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)
ProductID id() const
Definition: HandleBase.cc:15
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
void mergeOld(reco::ClusterRemovalInfo::Indices &refs, const reco::ClusterRemovalInfo::Indices &oldRefs)
edm::EDGetTokenT< reco::ClusterRemovalInfo > oldRemovalInfo_
TrackQuality
track quality
Definition: TrackBase.h:151
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
assert(m_qm.get())
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > pixelClusters_
bool exists(std::string const &parameterName) const
checks if a parameter exists
key_type key() const
Accessor for product key.
Definition: Ref.h:264
edm::ContainerMask< edmNew::DetSetVector< Phase2TrackerCluster1D > > Phase2OTMaskContainer
ProductID id() const
Accessor for product ID.
Definition: Ref.h:258
void process(const TrackingRecHit *hit, float chi2, const TrackerGeometry *tg)
ProductID id() const
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< TrajectorySeedCollection > trajectories_
recHitContainer::const_iterator const_iterator
edm::ContainerMask< edmNew::DetSetVector< SiPixelCluster > > PixelMaskContainer
def move
Definition: eostools.py:510
data_type const * data(size_t cell) const
std::pair< const_iterator, const_iterator > range
edm::EDGetTokenT< PixelMaskContainer > oldPxlMaskToken_
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
Definition: DetId.h:18
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:125
SeedClusterRemoverPhase2(const edm::ParameterSet &iConfig)
ClusterRef cluster() const
Definition: SiPixelRecHit.h:49
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
edm::EDGetTokenT< Phase2OTMaskContainer > oldPh2OTMaskToken_
tuple pixelClusters
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
size_type size() const
char const * productInstance
Definition: ProductLabels.h:6
reco::TrackBase::TrackQuality trackQuality_
edm::EDGetTokenT< edmNew::DetSetVector< Phase2TrackerCluster1D > > phase2OTClusters_
DetId geographicalId() const
long double T
const_iterator begin(bool update=false) const
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Our base class.
Definition: SiPixelRecHit.h:23