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_;
92  std::vector<SiPixelTemplateStore> thePixelTemp_;
93  const TrackerTopology* tkTpl = nullptr;
94 
96  edm::EDGetTokenT<reco::VertexCollection> offlinePrimaryVerticesToken_;
97  edm::EDGetTokenT<SiPixelClusterShapeCache> pixelClusterShapeCacheToken_;
98 
102 
104  };
105 
106  SiPixelPhase1TrackClusters::SiPixelPhase1TrackClusters(const edm::ParameterSet& iConfig)
107  : SiPixelPhase1Base(iConfig), applyVertexCut_(iConfig.getUntrackedParameter<bool>("VertexCut", true)) {
108  tracksToken_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
109 
110  offlinePrimaryVerticesToken_ =
111  applyVertexCut_ ? consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertices"))
112  : edm::EDGetTokenT<reco::VertexCollection>();
113 
114  pixelClusterShapeCacheToken_ =
115  consumes<SiPixelClusterShapeCache>(iConfig.getParameter<edm::InputTag>("clusterShapeCache"));
116 
117  trackerTopoToken_ = esConsumes<edm::Transition::BeginRun>();
118  trackerGeomToken_ = esConsumes<edm::Transition::BeginRun>();
119  clusterShapeHitFilterToken_ =
120  esConsumes<ClusterShapeHitFilter, CkfComponentsRecord>(edm::ESInputTag("", "ClusterShapeHitFilter"));
121  templateDBobjectToken_ = esConsumes<edm::Transition::BeginRun>();
122  }
123 
124  void SiPixelPhase1TrackClusters::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
125  //get topology
126  tkTpl = &iSetup.getData(trackerTopoToken_);
127 
128  // Initialize 1D templates
129  templateDBobject_ = &iSetup.getData(templateDBobjectToken_);
130  if (!SiPixelTemplate::pushfile(*templateDBobject_, thePixelTemp_))
131  edm::LogError("SiPixelPhase1TrackClusters")
132  << "Templates not filled correctly. Check the sqlite file. Using SiPixelTemplateDBObject version "
133  << (*templateDBobject_).version() << std::endl;
134  }
135 
137  if (!checktrigger(iEvent, iSetup, DCS))
138  return;
139 
140  if (histo.size() != ENUM_SIZE) {
141  edm::LogError("SiPixelPhase1TrackClusters")
142  << "incompatible configuration " << histo.size() << "!=" << ENUM_SIZE << std::endl;
143  return;
144  }
145 
146  edm::ESHandle<ClusterShapeHitFilter> shapeFilterH = iSetup.getHandle(clusterShapeHitFilterToken_);
147  auto const& shapeFilter = *shapeFilterH;
148 
150  if (applyVertexCut_) {
151  iEvent.getByToken(offlinePrimaryVerticesToken_, vertices);
152  if (!vertices.isValid() || vertices->empty())
153  return;
154  }
155 
156  //get the map
158  iEvent.getByToken(tracksToken_, tracks);
159 
160  if (!tracks.isValid()) {
161  edm::LogWarning("SiPixelPhase1TrackClusters") << "track collection is not valid";
162  return;
163  }
164 
165  SiPixelTemplate templ(thePixelTemp_);
166 
167  edm::Handle<SiPixelClusterShapeCache> pixelClusterShapeCacheH;
168  iEvent.getByToken(pixelClusterShapeCacheToken_, pixelClusterShapeCacheH);
169  if (!pixelClusterShapeCacheH.isValid()) {
170  edm::LogWarning("SiPixelPhase1TrackClusters") << "PixelClusterShapeCache collection is not valid";
171  return;
172  }
173  auto const& pixelClusterShapeCache = *pixelClusterShapeCacheH;
174 
175  for (auto const& track : *tracks) {
176  if (applyVertexCut_ &&
177  (track.pt() < 0.75 || std::abs(track.dxy((*vertices)[0].position())) > 5 * track.dxyError()))
178  continue;
179 
180  bool isBpixtrack = false, isFpixtrack = false, crossesPixVol = false;
181 
182  // find out whether track crosses pixel fiducial volume (for cosmic tracks)
183  auto d0 = track.d0(), dz = track.dz();
184  if (std::abs(d0) < 16 && std::abs(dz) < 50)
185  crossesPixVol = true;
186 
187  auto etatk = track.eta();
188 
189  auto const& trajParams = track.extra()->trajParams();
190  assert(trajParams.size() == track.recHitsSize());
191  auto hb = track.recHitsBegin();
192 
193  for (unsigned int h = 0; h < track.recHitsSize(); h++) {
194  auto hit = *(hb + h);
195  if (!hit->isValid())
196  continue;
197  auto id = hit->geographicalId();
198 
199  // check that we are in the pixel
200  auto subdetid = (id.subdetId());
201  if (subdetid == PixelSubdetector::PixelBarrel)
202  isBpixtrack = true;
203  if (subdetid == PixelSubdetector::PixelEndcap)
204  isFpixtrack = true;
205  if (subdetid != PixelSubdetector::PixelBarrel && subdetid != PixelSubdetector::PixelEndcap)
206  continue;
207  bool iAmBarrel = subdetid == PixelSubdetector::PixelBarrel;
208 
209  // PXB_L4 IS IN THE OTHER WAY
210  // CAN BE XORed BUT LETS KEEP THINGS SIMPLE
211  bool iAmOuter = ((tkTpl->pxbLadder(id) % 2 == 1) && tkTpl->pxbLayer(id) != 4) ||
212  ((tkTpl->pxbLadder(id) % 2 != 1) && tkTpl->pxbLayer(id) == 4);
213 
214  auto pixhit = dynamic_cast<const SiPixelRecHit*>(hit->hit());
215  if (!pixhit)
216  continue;
217 
218  auto geomdetunit = dynamic_cast<const PixelGeomDetUnit*>(pixhit->detUnit());
219  auto const& topol = geomdetunit->specificTopology();
220 
221  // get the cluster
222  auto clustp = pixhit->cluster();
223  if (clustp.isNull())
224  continue;
225  auto const& cluster = *clustp;
226  const std::vector<SiPixelCluster::Pixel> pixelsVec = cluster.pixels();
227  for (unsigned int i = 0; i < pixelsVec.size(); ++i) {
228  float pixx = pixelsVec[i].x; // index as float=iteger, row index
229  float pixy = pixelsVec[i].y; // same, col index
230 
231  bool bigInX = topol.isItBigPixelInX(int(pixx));
232  bool bigInY = topol.isItBigPixelInY(int(pixy));
233  float pixel_charge = pixelsVec[i].adc;
234 
235  if (bigInX == true || bigInY == true) {
236  histo[ON_TRACK_BIGPIXELCHARGE].fill(pixel_charge, id, &iEvent);
237  } else {
238  histo[ON_TRACK_NOTBIGPIXELCHARGE].fill(pixel_charge, id, &iEvent);
239  }
240  } // End loop over pixels
241  auto const& ltp = trajParams[h];
242 
243  auto localDir = ltp.momentum() / ltp.momentum().mag();
244 
245  // correct charge for track impact angle
246  auto charge = cluster.charge() * ltp.absdz();
247  //Correct charge with Template1D
248  float cotAlpha = ltp.dxdz();
249  float cotBeta = ltp.dydz();
250  float locBx = 1.;
251  if (cotBeta < 0.)
252  locBx = -1.;
253  float locBz = locBx;
254  if (cotAlpha < 0.)
255  locBz = -locBx;
256  templ.interpolate(templateDBobject_->getTemplateID(id), cotAlpha, cotBeta, locBz, locBx);
257  auto charge_cor = (charge * templ.qscale()) / templ.r_qMeas_qTrue();
258  auto tmpl = templ.qscale() / templ.r_qMeas_qTrue();
259 
260  auto clustgp = pixhit->globalPosition(); // from rechit
261 
262  int part;
264  std::pair<float, float> pred;
265  if (shapeFilter.getSizes(*pixhit, localDir, pixelClusterShapeCache, part, meas, pred)) {
266  auto shape = shapeFilter.isCompatible(*pixhit, localDir, pixelClusterShapeCache);
267  unsigned shapeVal = (shape ? 1 : 0);
268 
269  if (iAmBarrel) {
270  if (iAmOuter) {
271  histo[ON_TRACK_SIZE_X_OUTER].fill(pred.first, cluster.sizeX(), id, &iEvent);
272  histo[ON_TRACK_SIZE_Y_OUTER].fill(pred.second, cluster.sizeY(), id, &iEvent);
273  histo[ON_TRACK_SIZE_XY_OUTER].fill(cluster.sizeY(), cluster.sizeX(), id, &iEvent);
274 
275  histo[ON_TRACK_SHAPE_OUTER].fill(shapeVal, id, &iEvent);
276  } else {
277  histo[ON_TRACK_SIZE_X_INNER].fill(pred.first, cluster.sizeX(), id, &iEvent);
278  histo[ON_TRACK_SIZE_Y_INNER].fill(pred.second, cluster.sizeY(), id, &iEvent);
279  histo[ON_TRACK_SIZE_XY_INNER].fill(cluster.sizeY(), cluster.sizeX(), id, &iEvent);
280 
281  histo[ON_TRACK_SHAPE_INNER].fill(shapeVal, id, &iEvent);
282  }
283  } else {
284  histo[ON_TRACK_SIZE_X_F].fill(pred.first, cluster.sizeX(), id, &iEvent);
285  histo[ON_TRACK_SIZE_Y_F].fill(pred.second, cluster.sizeY(), id, &iEvent);
286  histo[ON_TRACK_SIZE_XY_F].fill(cluster.sizeY(), cluster.sizeX(), id, &iEvent);
287  }
288  histo[ON_TRACK_SHAPE].fill(shapeVal, id, &iEvent);
289  }
290 
291  for (int i = 0; i < cluster.size(); i++) {
292  SiPixelCluster::Pixel const& vecipxl = cluster.pixel(i);
293  histo[DIGIS_HITMAP_ON_TRACK].fill(id, &iEvent, vecipxl.y, vecipxl.x);
294  histo[ON_TRACK_NDIGIS].fill(id, &iEvent);
295  }
296 
297  histo[ON_TRACK_NCLUSTERS].fill(id, &iEvent);
298  histo[ON_TRACK_CHARGE].fill(charge, id, &iEvent);
299  histo[ON_TRACK_CORRECTEDCHARGE].fill(charge_cor, id, &iEvent);
300  histo[TEMPLATE_CORRECTION].fill(tmpl, id, &iEvent);
301  histo[ON_TRACK_SIZE].fill(cluster.size(), id, &iEvent);
302 
303  histo[ON_TRACK_POSITIONB].fill(clustgp.z(), clustgp.phi(), id, &iEvent);
304  histo[ON_TRACK_POSITIONF].fill(clustgp.x(), clustgp.y(), id, &iEvent);
305 
306  histo[CHARGE_VS_SIZE_ON_TRACK].fill(cluster.size(), charge, id, &iEvent);
307 
308  if (iAmBarrel) // Avoid mistakes even if specification < should > handle it
309  {
310  if (iAmOuter) {
311  histo[SIZE_VS_ETA_ON_TRACK_OUTER].fill(etatk, cluster.sizeY(), id, &iEvent);
312  histo[ON_TRACK_CHARGE_OUTER].fill(charge, id, &iEvent);
313  histo[ON_TRACK_CORRECTEDCHARGE_OUTER].fill(charge_cor, id, &iEvent);
314  histo[TEMPLATE_CORRECTION_OUTER].fill(tmpl, id, &iEvent);
315  } else {
316  histo[SIZE_VS_ETA_ON_TRACK_INNER].fill(etatk, cluster.sizeY(), id, &iEvent);
317  histo[ON_TRACK_CHARGE_INNER].fill(charge, id, &iEvent);
318  histo[ON_TRACK_CORRECTEDCHARGE_INNER].fill(charge_cor, id, &iEvent);
319  histo[TEMPLATE_CORRECTION_INNER].fill(tmpl, id, &iEvent);
320  }
321  }
322  }
323 
324  // statistics on tracks
325  histo[NTRACKS].fill(1, DetId(0), &iEvent);
326  if (isBpixtrack || isFpixtrack)
327  histo[NTRACKS].fill(2, DetId(0), &iEvent);
328  if (isBpixtrack)
329  histo[NTRACKS].fill(3, DetId(0), &iEvent);
330  if (isFpixtrack)
331  histo[NTRACKS].fill(4, DetId(0), &iEvent);
332 
333  if (crossesPixVol) {
334  if (isBpixtrack || isFpixtrack)
335  histo[NTRACKS_INVOLUME].fill(1, DetId(0), &iEvent);
336  else
337  histo[NTRACKS_INVOLUME].fill(0, DetId(0), &iEvent);
338  }
339  }
340 
341  histo[ON_TRACK_NCLUSTERS].executePerEventHarvesting(&iEvent);
342  histo[ON_TRACK_NDIGIS].executePerEventHarvesting(&iEvent);
343  }
344 
345 } // namespace
346 
348 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
static bool pushfile(int filenum, std::vector< SiPixelTemplateStore > &pixelTemp, std::string dir="CalibTracker/SiPixelESProducers/data/")
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