CMS 3D CMS Logo

TrackClusterRemoverPhase2.cc
Go to the documentation of this file.
6 
8 
11 
16 
18 
21 
23 
25 
26 #include<limits>
27 
28 /* This is a copy of the TrackClusterRemover
29  * for Phase2 Tk upgrade
30  * FIXME:: changing with new phase2 pixel DataFormats!
31  * FIXME:: still to be factorized
32  */
33 
34 namespace {
35 
36  class TrackClusterRemoverPhase2 final : public edm::global::EDProducer<> {
37  public:
38  TrackClusterRemoverPhase2(const edm::ParameterSet& iConfig) ;
39  ~TrackClusterRemoverPhase2() override{}
40  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
41  private:
42 
43  void produce(edm::StreamID, edm::Event& evt, const edm::EventSetup&) const override;
44 
47 
48  using QualityMaskCollection = std::vector<unsigned char>;
49 
50  const unsigned char maxChi2_;
51  const int minNumberOfLayersWithMeasBeforeFiltering_;
52  const reco::TrackBase::TrackQuality trackQuality_;
53 
54 
57 
60 
61  edm::EDGetTokenT<PixelMaskContainer> oldPxlMaskToken_;
62  edm::EDGetTokenT<Phase2OTMaskContainer> oldPh2OTMaskToken_;
63 
64  // backward compatibility during transition period
65  edm::EDGetTokenT<edm::ValueMap<int>> overrideTrkQuals_;
66 
67  };
68 
71  desc.add<edm::InputTag>("trajectories",edm::InputTag());
72  desc.add<edm::InputTag>("trackClassifier",edm::InputTag("","QualityMasks"));
73  desc.add<edm::InputTag>("phase2pixelClusters",edm::InputTag("siPixelClusters"));
74  desc.add<edm::InputTag>("phase2OTClusters",edm::InputTag("siPhase2Clusters"));
75  desc.add<edm::InputTag>("oldClusterRemovalInfo",edm::InputTag());
76 
77  desc.add<std::string>("TrackQuality","highPurity");
78  desc.add<double>("maxChi2",30.);
79  desc.add<int>("minNumberOfLayersWithMeasBeforeFiltering",0);
80  // old mode
81  desc.add<edm::InputTag>("overrideTrkQuals",edm::InputTag());
82 
83  descriptions.add("phase2trackClusterRemover", desc);
84 
85  }
86 
87  TrackClusterRemoverPhase2::TrackClusterRemoverPhase2(const edm::ParameterSet& iConfig) :
88  maxChi2_(Traj2TrackHits::toChi2x5(iConfig.getParameter<double>("maxChi2"))),
89  minNumberOfLayersWithMeasBeforeFiltering_(iConfig.getParameter<int>("minNumberOfLayersWithMeasBeforeFiltering")),
90  trackQuality_(reco::TrackBase::qualityByName(iConfig.getParameter<std::string>("TrackQuality"))),
91 
92  tracks_(iConfig.getParameter<edm::InputTag>("trajectories"),consumesCollector()),
93  pixelClusters_(consumes<edmNew::DetSetVector<SiPixelCluster> >(iConfig.getParameter<edm::InputTag>("phase2pixelClusters"))),
94  phase2OTClusters_(consumes<edmNew::DetSetVector<Phase2TrackerCluster1D> >(iConfig.getParameter<edm::InputTag>("phase2OTClusters")))
95  {
96 
97  produces<edm::ContainerMask<edmNew::DetSetVector<SiPixelCluster> > >();
98  produces<edm::ContainerMask<edmNew::DetSetVector<Phase2TrackerCluster1D> > >();
99 
100  // old mode
101  auto const & overrideTrkQuals = iConfig.getParameter<edm::InputTag>("overrideTrkQuals");
102  if ( !overrideTrkQuals.label().empty() )
103  overrideTrkQuals_ = consumes<edm::ValueMap<int> >(overrideTrkQuals);
104 
105  auto const & classifier = iConfig.getParameter<edm::InputTag>("trackClassifier");
106  if ( !classifier.label().empty())
107  srcQuals = consumes<QualityMaskCollection>(classifier);
108 
109  auto const & oldClusterRemovalInfo = iConfig.getParameter<edm::InputTag>("oldClusterRemovalInfo");
110  if (!oldClusterRemovalInfo.label().empty()) {
111  oldPxlMaskToken_ = consumes<PixelMaskContainer>(oldClusterRemovalInfo);
112  oldPh2OTMaskToken_ = consumes<Phase2OTMaskContainer>(oldClusterRemovalInfo);
113  }
114 
115  }
116 
117 
118  void
119  TrackClusterRemoverPhase2::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const
120  {
121 
122 
124  iEvent.getByToken(pixelClusters_, pixelClusters);
126  iEvent.getByToken(phase2OTClusters_, phase2OTClusters);
127 
128 
129  std::vector<bool> collectedPixels;
130  std::vector<bool> collectedPhase2OTs;
131 
132  if(!oldPxlMaskToken_.isUninitialized()) {
133 
136  iEvent.getByToken(oldPxlMaskToken_ ,oldPxlMask);
137  iEvent.getByToken(oldPh2OTMaskToken_ ,oldPh2OTMask);
138  LogDebug("TrackClusterRemoverPhase2")<<"to merge in, "<<oldPxlMask->size()<<" phase2 pixel and " << oldPh2OTMask->size() << " phase2 OT";
139  oldPxlMask->copyMaskTo(collectedPixels);
140  oldPh2OTMask->copyMaskTo(collectedPhase2OTs);
141  assert(phase2OTClusters->dataSize() >= collectedPhase2OTs.size());
142  collectedPhase2OTs.resize(phase2OTClusters->dataSize(), false);
143 
144  }else {
145 
146  collectedPixels.resize(pixelClusters->dataSize(), false);
147  collectedPhase2OTs.resize(phase2OTClusters->dataSize(), false);
148 
149  }
150 
151 
152  // loop over trajectories, filter, mask clusters../
153 
154  unsigned char qualMask = ~0;
155  if (trackQuality_!=reco::TrackBase::undefQuality) qualMask = 1<<trackQuality_;
156 
157 
158  auto const & tracks = tracks_.tracks(iEvent);
159  auto s = tracks.size();
160 
161  QualityMaskCollection oldStyle;
162  QualityMaskCollection const * pquals=nullptr;
163 
164  if (!overrideTrkQuals_.isUninitialized()) {
166  iEvent.getByToken(overrideTrkQuals_,quals);
167  assert(s==(*quals).size());
168 
169  oldStyle.resize(s,0);
170  for (auto i=0U; i<s; ++i) if ( (*quals).get(i) > 0 ) oldStyle[i] = (255)&(*quals).get(i);
171  pquals = &oldStyle;
172  }
173 
174  if (!srcQuals.isUninitialized()) {
176  iEvent.getByToken(srcQuals, hqual);
177  pquals = hqual.product();
178  }
179 
180  for (auto i=0U; i<s; ++i){
181 
182  const reco::Track & track = tracks[i];
183  bool goodTk = (pquals) ? (*pquals)[i] & qualMask : track.quality(trackQuality_);
184  if ( !goodTk) continue;
185  if(track.hitPattern().trackerLayersWithMeasurement() < minNumberOfLayersWithMeasBeforeFiltering_) continue;
186  auto const & chi2sX5 = track.extra()->chi2sX5();
187  assert(chi2sX5.size()==track.recHitsSize());
188  auto hb = track.recHitsBegin();
189  for(unsigned int h=0;h<track.recHitsSize();h++){
190  auto hit = *(hb+h);
191  if (!hit->isValid()) continue;
192  if ( chi2sX5[h] > maxChi2_ ) continue; // skip outliers
193  auto const & thit = reinterpret_cast<BaseTrackerRecHit const&>(*hit);
194  auto const & cluster = thit.firstClusterRef();
195  // FIXME when we will get also Phase2 pixel
196  if (cluster.isPixel()) collectedPixels[cluster.key()]=true;
197  else if (cluster.isPhase2()) collectedPhase2OTs[cluster.key()]=true;
198  }
199 
200  }
201 
202 
203  auto removedPixelClusterMask=
204  std::make_unique<PixelMaskContainer>(edm::RefProd<edmNew::DetSetVector<SiPixelCluster>>(pixelClusters),collectedPixels);
205  LogDebug("TrackClusterRemoverPhase2")<<"total pxl to skip: "<<std::count(collectedPixels.begin(),collectedPixels.end(),true);
206  iEvent.put(std::move(removedPixelClusterMask));
207 
208  auto removedPhase2OTClusterMask=
209  std::make_unique<Phase2OTMaskContainer>(edm::RefProd<edmNew::DetSetVector<Phase2TrackerCluster1D>>(phase2OTClusters),collectedPhase2OTs);
210  LogDebug("TrackClusterRemoverPhase2")<<"total ph2OT to skip: "<<std::count(collectedPhase2OTs.begin(),collectedPhase2OTs.end(),true);
211  iEvent.put(std::move(removedPhase2OTClusterMask));
212 
213 
214  }
215 
216 
217 }
218 
219 
222 DEFINE_FWK_MODULE(TrackClusterRemoverPhase2);
223 
#define LogDebug(id)
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
const std::vector< reco::PFCandidatePtr > & tracks_
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
const TrackExtraRef & extra() const
reference to "extra" object
Definition: Track.h:189
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
TrackQuality
track quality
Definition: TrackBase.h:151
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
Definition: Track.h:119
int trackerLayersWithMeasurement() const
Definition: HitPattern.cc:518
virtual void produce(StreamID, Event &, EventSetup const &) const =0
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:230
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:104
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillDescriptions(ConfigurationDescriptions &descriptions)
T const * product() const
Definition: Handle.h:81
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:446
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:510
Pixel cluster – collection of neighboring pixels above threshold.
fixed size matrix
HLT enums.
virtual OmniClusterRef const & firstClusterRef() const =0
def move(src, dest)
Definition: eostools.py:510