CMS 3D CMS Logo

SiPixelPhase1TrackClusters.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiPixelPhase1TrackClusters
4 // Class : SiPixelPhase1TrackClusters
5 //
6 
7 // Original Author: Marcel Schneider
8 
11 
16 
19 
28 
30 
33 
36 
37 namespace {
38 
39  class SiPixelPhase1TrackClusters final : public SiPixelPhase1Base {
40  enum {
41  ON_TRACK_CHARGE,
42  ON_TRACK_CORRECTEDCHARGE,
43  TEMPLATE_CORRECTION,
44  ON_TRACK_BIGPIXELCHARGE,
45  ON_TRACK_NOTBIGPIXELCHARGE,
46  ON_TRACK_SIZE,
47  ON_TRACK_SHAPE,
48  ON_TRACK_NCLUSTERS,
49  ON_TRACK_POSITIONB,
50  ON_TRACK_POSITIONF,
51  DIGIS_HITMAP_ON_TRACK,
52  ON_TRACK_NDIGIS,
53 
54  NTRACKS,
55  NTRACKS_INVOLUME,
56 
57  SIZE_VS_ETA_ON_TRACK_OUTER,
58  SIZE_VS_ETA_ON_TRACK_INNER,
59  ON_TRACK_CHARGE_OUTER,
60  ON_TRACK_CHARGE_INNER,
61  ON_TRACK_CORRECTEDCHARGE_OUTER,
62  ON_TRACK_CORRECTEDCHARGE_INNER,
63  TEMPLATE_CORRECTION_OUTER,
64  TEMPLATE_CORRECTION_INNER,
65 
66  ON_TRACK_SHAPE_OUTER,
67  ON_TRACK_SHAPE_INNER,
68 
69  ON_TRACK_SIZE_X_OUTER,
70  ON_TRACK_SIZE_X_INNER,
71  ON_TRACK_SIZE_X_F,
72  ON_TRACK_SIZE_Y_OUTER,
73  ON_TRACK_SIZE_Y_INNER,
74  ON_TRACK_SIZE_Y_F,
75 
76  ON_TRACK_SIZE_XY_OUTER,
77  ON_TRACK_SIZE_XY_INNER,
78  ON_TRACK_SIZE_XY_F,
79  CHARGE_VS_SIZE_ON_TRACK,
80 
81  ENUM_SIZE
82  };
83 
84  public:
85  explicit SiPixelPhase1TrackClusters(const edm::ParameterSet& conf);
86  void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
87  void analyze(const edm::Event&, const edm::EventSetup&) override;
88 
89  private:
90  const bool applyVertexCut_;
91  const SiPixelTemplateDBObject* templateDBobject_ = nullptr;
92  const std::vector<SiPixelTemplateStore>* thePixelTemp_ = nullptr;
93  const TrackerTopology* tkTpl = nullptr;
94 
96  edm::EDGetTokenT<reco::VertexCollection> offlinePrimaryVerticesToken_;
97  edm::EDGetTokenT<SiPixelClusterShapeCache> pixelClusterShapeCacheToken_;
98 
102 
105  };
106 
107  SiPixelPhase1TrackClusters::SiPixelPhase1TrackClusters(const edm::ParameterSet& iConfig)
108  : SiPixelPhase1Base(iConfig), applyVertexCut_(iConfig.getUntrackedParameter<bool>("VertexCut", true)) {
109  tracksToken_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
110 
111  offlinePrimaryVerticesToken_ =
112  applyVertexCut_ ? consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertices"))
113  : edm::EDGetTokenT<reco::VertexCollection>();
114 
115  pixelClusterShapeCacheToken_ =
116  consumes<SiPixelClusterShapeCache>(iConfig.getParameter<edm::InputTag>("clusterShapeCache"));
117 
118  trackerTopoToken_ = esConsumes<edm::Transition::BeginRun>();
119  trackerGeomToken_ = esConsumes<edm::Transition::BeginRun>();
120  clusterShapeHitFilterToken_ =
121  esConsumes<ClusterShapeHitFilter, CkfComponentsRecord>(edm::ESInputTag("", "ClusterShapeHitFilter"));
122  templateStoreToken_ = esConsumes<edm::Transition::BeginRun>();
123  templateDBobjectToken_ = esConsumes<edm::Transition::BeginRun>();
124  }
125 
126  void SiPixelPhase1TrackClusters::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
127  //get topology
128  tkTpl = &iSetup.getData(trackerTopoToken_);
129 
130  // Initialize 1D templates
131  templateDBobject_ = &iSetup.getData(templateDBobjectToken_);
132  thePixelTemp_ = &iSetup.getData(templateStoreToken_);
133  }
134 
136  if (!checktrigger(iEvent, iSetup, DCS))
137  return;
138 
139  if (histo.size() != ENUM_SIZE) {
140  edm::LogError("SiPixelPhase1TrackClusters")
141  << "incompatible configuration " << histo.size() << "!=" << ENUM_SIZE << std::endl;
142  return;
143  }
144 
145  edm::ESHandle<ClusterShapeHitFilter> shapeFilterH = iSetup.getHandle(clusterShapeHitFilterToken_);
146  auto const& shapeFilter = *shapeFilterH;
147 
149  if (applyVertexCut_) {
150  iEvent.getByToken(offlinePrimaryVerticesToken_, vertices);
151  if (!vertices.isValid() || vertices->empty())
152  return;
153  }
154 
155  //get the map
157  iEvent.getByToken(tracksToken_, tracks);
158 
159  if (!tracks.isValid()) {
160  edm::LogWarning("SiPixelPhase1TrackClusters") << "track collection is not valid";
161  return;
162  }
163 
164  SiPixelTemplate templ(*thePixelTemp_);
165 
166  edm::Handle<SiPixelClusterShapeCache> pixelClusterShapeCacheH;
167  iEvent.getByToken(pixelClusterShapeCacheToken_, pixelClusterShapeCacheH);
168  if (!pixelClusterShapeCacheH.isValid()) {
169  edm::LogWarning("SiPixelPhase1TrackClusters") << "PixelClusterShapeCache collection is not valid";
170  return;
171  }
172  auto const& pixelClusterShapeCache = *pixelClusterShapeCacheH;
173 
174  for (auto const& track : *tracks) {
175  if (applyVertexCut_ &&
176  (track.pt() < 0.75 || std::abs(track.dxy((*vertices)[0].position())) > 5 * track.dxyError()))
177  continue;
178 
179  bool isBpixtrack = false, isFpixtrack = false, crossesPixVol = false;
180 
181  // find out whether track crosses pixel fiducial volume (for cosmic tracks)
182  auto d0 = track.d0(), dz = track.dz();
183  if (std::abs(d0) < 16 && std::abs(dz) < 50)
184  crossesPixVol = true;
185 
186  auto etatk = track.eta();
187 
188  auto const& trajParams = track.extra()->trajParams();
189  assert(trajParams.size() == track.recHitsSize());
190  auto hb = track.recHitsBegin();
191 
192  for (unsigned int h = 0; h < track.recHitsSize(); h++) {
193  auto hit = *(hb + h);
194  if (!hit->isValid())
195  continue;
196  auto id = hit->geographicalId();
197 
198  // check that we are in the pixel
199  auto subdetid = (id.subdetId());
200  if (subdetid == PixelSubdetector::PixelBarrel)
201  isBpixtrack = true;
202  if (subdetid == PixelSubdetector::PixelEndcap)
203  isFpixtrack = true;
204  if (subdetid != PixelSubdetector::PixelBarrel && subdetid != PixelSubdetector::PixelEndcap)
205  continue;
206  bool iAmBarrel = subdetid == PixelSubdetector::PixelBarrel;
207 
208  // PXB_L4 IS IN THE OTHER WAY
209  // CAN BE XORed BUT LETS KEEP THINGS SIMPLE
210  bool iAmOuter = ((tkTpl->pxbLadder(id) % 2 == 1) && tkTpl->pxbLayer(id) != 4) ||
211  ((tkTpl->pxbLadder(id) % 2 != 1) && tkTpl->pxbLayer(id) == 4);
212 
213  auto pixhit = dynamic_cast<const SiPixelRecHit*>(hit->hit());
214  if (!pixhit)
215  continue;
216 
217  auto geomdetunit = dynamic_cast<const PixelGeomDetUnit*>(pixhit->detUnit());
218  auto const& topol = geomdetunit->specificTopology();
219 
220  // get the cluster
221  auto clustp = pixhit->cluster();
222  if (clustp.isNull())
223  continue;
224  auto const& cluster = *clustp;
225  const std::vector<SiPixelCluster::Pixel> pixelsVec = cluster.pixels();
226  for (unsigned int i = 0; i < pixelsVec.size(); ++i) {
227  float pixx = pixelsVec[i].x; // index as float=iteger, row index
228  float pixy = pixelsVec[i].y; // same, col index
229 
230  bool bigInX = topol.isItBigPixelInX(int(pixx));
231  bool bigInY = topol.isItBigPixelInY(int(pixy));
232  float pixel_charge = pixelsVec[i].adc;
233 
234  if (bigInX == true || bigInY == true) {
235  histo[ON_TRACK_BIGPIXELCHARGE].fill(pixel_charge, id, &iEvent);
236  } else {
237  histo[ON_TRACK_NOTBIGPIXELCHARGE].fill(pixel_charge, id, &iEvent);
238  }
239  } // End loop over pixels
240  auto const& ltp = trajParams[h];
241 
242  auto localDir = ltp.momentum() / ltp.momentum().mag();
243 
244  // correct charge for track impact angle
245  auto charge = cluster.charge() * ltp.absdz();
246  //Correct charge with Template1D
247  float cotAlpha = ltp.dxdz();
248  float cotBeta = ltp.dydz();
249  float locBx = 1.;
250  if (cotBeta < 0.)
251  locBx = -1.;
252  float locBz = locBx;
253  if (cotAlpha < 0.)
254  locBz = -locBx;
255  templ.interpolate(templateDBobject_->getTemplateID(id), cotAlpha, cotBeta, locBz, locBx);
256  auto charge_cor = (charge * templ.qscale()) / templ.r_qMeas_qTrue();
257  auto tmpl = templ.qscale() / templ.r_qMeas_qTrue();
258 
259  auto clustgp = pixhit->globalPosition(); // from rechit
260 
261  int part;
263  std::pair<float, float> pred;
264  if (shapeFilter.getSizes(*pixhit, localDir, pixelClusterShapeCache, part, meas, pred)) {
265  auto shape = shapeFilter.isCompatible(*pixhit, localDir, pixelClusterShapeCache);
266  unsigned shapeVal = (shape ? 1 : 0);
267 
268  if (iAmBarrel) {
269  if (iAmOuter) {
270  histo[ON_TRACK_SIZE_X_OUTER].fill(pred.first, cluster.sizeX(), id, &iEvent);
271  histo[ON_TRACK_SIZE_Y_OUTER].fill(pred.second, cluster.sizeY(), id, &iEvent);
272  histo[ON_TRACK_SIZE_XY_OUTER].fill(cluster.sizeY(), cluster.sizeX(), id, &iEvent);
273 
274  histo[ON_TRACK_SHAPE_OUTER].fill(shapeVal, id, &iEvent);
275  } else {
276  histo[ON_TRACK_SIZE_X_INNER].fill(pred.first, cluster.sizeX(), id, &iEvent);
277  histo[ON_TRACK_SIZE_Y_INNER].fill(pred.second, cluster.sizeY(), id, &iEvent);
278  histo[ON_TRACK_SIZE_XY_INNER].fill(cluster.sizeY(), cluster.sizeX(), id, &iEvent);
279 
280  histo[ON_TRACK_SHAPE_INNER].fill(shapeVal, id, &iEvent);
281  }
282  } else {
283  histo[ON_TRACK_SIZE_X_F].fill(pred.first, cluster.sizeX(), id, &iEvent);
284  histo[ON_TRACK_SIZE_Y_F].fill(pred.second, cluster.sizeY(), id, &iEvent);
285  histo[ON_TRACK_SIZE_XY_F].fill(cluster.sizeY(), cluster.sizeX(), id, &iEvent);
286  }
287  histo[ON_TRACK_SHAPE].fill(shapeVal, id, &iEvent);
288  }
289 
290  for (int i = 0; i < cluster.size(); i++) {
291  SiPixelCluster::Pixel const& vecipxl = cluster.pixel(i);
292  histo[DIGIS_HITMAP_ON_TRACK].fill(id, &iEvent, vecipxl.y, vecipxl.x);
293  histo[ON_TRACK_NDIGIS].fill(id, &iEvent);
294  }
295 
296  histo[ON_TRACK_NCLUSTERS].fill(id, &iEvent);
297  histo[ON_TRACK_CHARGE].fill(charge, id, &iEvent);
298  histo[ON_TRACK_CORRECTEDCHARGE].fill(charge_cor, id, &iEvent);
299  histo[TEMPLATE_CORRECTION].fill(tmpl, id, &iEvent);
300  histo[ON_TRACK_SIZE].fill(cluster.size(), id, &iEvent);
301 
302  histo[ON_TRACK_POSITIONB].fill(clustgp.z(), clustgp.phi(), id, &iEvent);
303  histo[ON_TRACK_POSITIONF].fill(clustgp.x(), clustgp.y(), id, &iEvent);
304 
305  histo[CHARGE_VS_SIZE_ON_TRACK].fill(cluster.size(), charge, id, &iEvent);
306 
307  if (iAmBarrel) // Avoid mistakes even if specification < should > handle it
308  {
309  if (iAmOuter) {
310  histo[SIZE_VS_ETA_ON_TRACK_OUTER].fill(etatk, cluster.sizeY(), id, &iEvent);
311  histo[ON_TRACK_CHARGE_OUTER].fill(charge, id, &iEvent);
312  histo[ON_TRACK_CORRECTEDCHARGE_OUTER].fill(charge_cor, id, &iEvent);
313  histo[TEMPLATE_CORRECTION_OUTER].fill(tmpl, id, &iEvent);
314  } else {
315  histo[SIZE_VS_ETA_ON_TRACK_INNER].fill(etatk, cluster.sizeY(), id, &iEvent);
316  histo[ON_TRACK_CHARGE_INNER].fill(charge, id, &iEvent);
317  histo[ON_TRACK_CORRECTEDCHARGE_INNER].fill(charge_cor, id, &iEvent);
318  histo[TEMPLATE_CORRECTION_INNER].fill(tmpl, id, &iEvent);
319  }
320  }
321  }
322 
323  // statistics on tracks
324  histo[NTRACKS].fill(1, DetId(0), &iEvent);
325  if (isBpixtrack || isFpixtrack)
326  histo[NTRACKS].fill(2, DetId(0), &iEvent);
327  if (isBpixtrack)
328  histo[NTRACKS].fill(3, DetId(0), &iEvent);
329  if (isFpixtrack)
330  histo[NTRACKS].fill(4, DetId(0), &iEvent);
331 
332  if (crossesPixVol) {
333  if (isBpixtrack || isFpixtrack)
334  histo[NTRACKS_INVOLUME].fill(1, DetId(0), &iEvent);
335  else
336  histo[NTRACKS_INVOLUME].fill(0, DetId(0), &iEvent);
337  }
338  }
339 
340  histo[ON_TRACK_NCLUSTERS].executePerEventHarvesting(&iEvent);
341  histo[ON_TRACK_NDIGIS].executePerEventHarvesting(&iEvent);
342  }
343 
344 } // namespace
345 
347 DEFINE_FWK_MODULE(SiPixelPhase1TrackClusters);
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
Log< level::Error, false > LogError
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
assert(be >=bs)
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:224
virtual bool isItBigPixelInX(int ixbin) const =0
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
virtual void dqmBeginRun(edm::Run const &, edm::EventSetup const &)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
Definition: DetId.h:17
static constexpr float d0
part
Definition: HCALResponse.h:20
void analyze(edm::Event const &e, edm::EventSetup const &) override=0
bool isValid() const
Definition: HandleBase.h:70
fixed size matrix
HLT enums.
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
Log< level::Warning, false > LogWarning
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
Definition: Run.h:45
Our base class.
Definition: SiPixelRecHit.h:23