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 
29 
31 
34 
35 namespace {
36 
37 class SiPixelPhase1TrackClusters final : public SiPixelPhase1Base {
38 enum {
39  ON_TRACK_CHARGE,
40  ON_TRACK_BIGPIXELCHARGE,
41  ON_TRACK_NOTBIGPIXELCHARGE,
42  ON_TRACK_SIZE,
43  ON_TRACK_SHAPE,
44  ON_TRACK_NCLUSTERS,
45  ON_TRACK_POSITIONB,
46  ON_TRACK_POSITIONF,
47  DIGIS_HITMAP_ON_TRACK,
48  ON_TRACK_NDIGIS,
49 
50  NTRACKS,
51  NTRACKS_INVOLUME,
52 
53  SIZE_VS_ETA_ON_TRACK_OUTER,
54  SIZE_VS_ETA_ON_TRACK_INNER,
55  ON_TRACK_CHARGE_OUTER,
56  ON_TRACK_CHARGE_INNER,
57 
58  ON_TRACK_SHAPE_OUTER,
59  ON_TRACK_SHAPE_INNER,
60 
61  ON_TRACK_SIZE_X_OUTER,
62  ON_TRACK_SIZE_X_INNER,
63  ON_TRACK_SIZE_X_F,
64  ON_TRACK_SIZE_Y_OUTER,
65  ON_TRACK_SIZE_Y_INNER,
66  ON_TRACK_SIZE_Y_F,
67 
68  ON_TRACK_SIZE_XY_OUTER,
69  ON_TRACK_SIZE_XY_INNER,
70  ON_TRACK_SIZE_XY_F,
71  CHARGE_VS_SIZE_ON_TRACK,
72 
73  ENUM_SIZE
74 };
75 
76 public:
77  explicit SiPixelPhase1TrackClusters(const edm::ParameterSet& conf);
78  void analyze(const edm::Event&, const edm::EventSetup&) override;
79 
80 private:
81  const bool applyVertexCut_;
82 
84  edm::EDGetTokenT<reco::VertexCollection> offlinePrimaryVerticesToken_;
85  edm::EDGetTokenT<SiPixelClusterShapeCache> pixelClusterShapeCacheToken_;
86 };
87 
88 SiPixelPhase1TrackClusters::SiPixelPhase1TrackClusters(const edm::ParameterSet& iConfig) :
89  SiPixelPhase1Base(iConfig),
90  applyVertexCut_(iConfig.getUntrackedParameter<bool>("VertexCut", true))
91 {
92  tracksToken_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
93 
94  offlinePrimaryVerticesToken_ = applyVertexCut_ ?
95  consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertices")) :
96  edm::EDGetTokenT<reco::VertexCollection>();
97 
98  pixelClusterShapeCacheToken_ = consumes<SiPixelClusterShapeCache>(iConfig.getParameter<edm::InputTag>("clusterShapeCache"));
99 }
100 
102  if( !checktrigger(iEvent, iSetup, DCS) ) return;
103 
104  if (histo.size() != ENUM_SIZE) {
105  edm::LogError("SiPixelPhase1TrackClusters") << "incompatible configuration " << histo.size()
106  << "!=" << ENUM_SIZE << std::endl;
107  return;
108  }
109 
110  // get geometry
112  iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
113  assert(tracker.isValid());
114 
115  edm::ESHandle<TrackerTopology> tTopoHandle;
116  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
117  auto const & tkTpl = *tTopoHandle;
118 
120  iSetup.get<CkfComponentsRecord>().get("ClusterShapeHitFilter", shapeFilterH);
121  auto const & shapeFilter = *shapeFilterH;
122 
124  if(applyVertexCut_) {
125  iEvent.getByToken(offlinePrimaryVerticesToken_, vertices);
126  if (!vertices.isValid() || vertices->empty()) return;
127  }
128 
129  //get the map
131  iEvent.getByToken(tracksToken_, tracks);
132 
133  if ( !tracks.isValid() ) {
134  edm::LogWarning("SiPixelPhase1TrackClusters") << "track collection is not valid";
135  return;
136  }
137 
138  edm::Handle<SiPixelClusterShapeCache> pixelClusterShapeCacheH;
139  iEvent.getByToken(pixelClusterShapeCacheToken_, pixelClusterShapeCacheH);
140  if ( !pixelClusterShapeCacheH.isValid() ) {
141  edm::LogWarning("SiPixelPhase1TrackClusters") << "PixelClusterShapeCache collection is not valid";
142  return;
143  }
144  auto const & pixelClusterShapeCache = *pixelClusterShapeCacheH;
145 
146  for (auto const & track : *tracks) {
147 
148  if (applyVertexCut_ &&
149  (track.pt() < 0.75 || std::abs( track.dxy((*vertices)[0].position()) ) > 5 * track.dxyError())) continue;
150 
151  bool isBpixtrack = false, isFpixtrack = false, crossesPixVol = false;
152 
153  // find out whether track crosses pixel fiducial volume (for cosmic tracks)
154  auto d0 = track.d0(), dz = track.dz();
155  if (std::abs(d0) < 15 && std::abs(dz) < 50) crossesPixVol = true;
156 
157  auto etatk = track.eta();
158 
159  auto const & trajParams = track.extra()->trajParams();
160  assert(trajParams.size()==track.recHitsSize());
161  auto hb = track.recHitsBegin();
162 
163  for (unsigned int h = 0; h < track.recHitsSize(); h++){
164 
165  auto hit = *(hb + h);
166  if (!hit->isValid()) continue;
167  auto id = hit->geographicalId();
168 
169  // check that we are in the pixel
170  auto subdetid = (id.subdetId());
171  if (subdetid == PixelSubdetector::PixelBarrel) isBpixtrack = true;
172  if (subdetid == PixelSubdetector::PixelEndcap) isFpixtrack = true;
173  if (subdetid != PixelSubdetector::PixelBarrel && subdetid != PixelSubdetector::PixelEndcap) continue;
174  bool iAmBarrel = subdetid == PixelSubdetector::PixelBarrel;
175 
176  // PXB_L4 IS IN THE OTHER WAY
177  // CAN BE XORed BUT LETS KEEP THINGS SIMPLE
178  bool iAmOuter = ((tkTpl.pxbLadder(id) % 2 == 1) && tkTpl.pxbLayer(id) != 4) ||
179  ((tkTpl.pxbLadder(id) % 2 != 1) && tkTpl.pxbLayer(id) == 4);
180 
181  auto pixhit = dynamic_cast<const SiPixelRecHit*>(hit->hit());
182  if (!pixhit) continue;
183 
184  auto geomdetunit = dynamic_cast<const PixelGeomDetUnit*>(pixhit->detUnit());
185  auto const & topol = geomdetunit->specificTopology();
186 
187  // get the cluster
188  auto clustp = pixhit->cluster();
189  if (clustp.isNull()) continue;
190  auto const & cluster = *clustp;
191  const std::vector<SiPixelCluster::Pixel> pixelsVec = cluster.pixels();
192  for (unsigned int i = 0; i < pixelsVec.size(); ++i) {
193 
194  float pixx = pixelsVec[i].x; // index as float=iteger, row index
195  float pixy = pixelsVec[i].y; // same, col index
196 
197  bool bigInX = topol.isItBigPixelInX(int(pixx));
198  bool bigInY = topol.isItBigPixelInY(int(pixy));
199  float pixel_charge = pixelsVec[i].adc;
200 
201  if (bigInX==true || bigInY==true) {
202  histo[ON_TRACK_BIGPIXELCHARGE].fill(pixel_charge, id, &iEvent);
203  }
204  else {
205  histo[ON_TRACK_NOTBIGPIXELCHARGE].fill(pixel_charge, id, &iEvent);
206 
207  }
208  } // End loop over pixels
209  auto const & ltp = trajParams[h];
210 
211  auto localDir = ltp.momentum() / ltp.momentum().mag();
212 
213  // correct charge for track impact angle
214  auto charge = cluster.charge() * ltp.absdz();
215 
216  auto clustgp = pixhit->globalPosition(); // from rechit
217 
218  int part;
220  std::pair<float, float> pred;
221  if(shapeFilter.getSizes(*pixhit, localDir, pixelClusterShapeCache, part, meas, pred)) {
222  auto shape = shapeFilter.isCompatible(*pixhit, localDir, pixelClusterShapeCache);
223  unsigned shapeVal = (shape ? 1 : 0);
224 
225  if (iAmBarrel) {
226  if(iAmOuter) {
227  histo[ON_TRACK_SIZE_X_OUTER].fill(pred.first, cluster.sizeX(), id, &iEvent);
228  histo[ON_TRACK_SIZE_Y_OUTER].fill(pred.second, cluster.sizeY(), id, &iEvent);
229  histo[ON_TRACK_SIZE_XY_OUTER].fill(cluster.sizeY(), cluster.sizeX(), id, &iEvent);
230 
231  histo[ON_TRACK_SHAPE_OUTER].fill(shapeVal, id, &iEvent);
232  } else {
233  histo[ON_TRACK_SIZE_X_INNER].fill(pred.first, cluster.sizeX(), id, &iEvent);
234  histo[ON_TRACK_SIZE_Y_INNER].fill(pred.second, cluster.sizeY(), id, &iEvent);
235  histo[ON_TRACK_SIZE_XY_INNER].fill(cluster.sizeY(), cluster.sizeX(), id, &iEvent);
236 
237  histo[ON_TRACK_SHAPE_INNER].fill(shapeVal, id, &iEvent);
238  }
239  } else {
240  histo[ON_TRACK_SIZE_X_F].fill(pred.first, cluster.sizeX(), id, &iEvent);
241  histo[ON_TRACK_SIZE_Y_F].fill(pred.second, cluster.sizeY(), id, &iEvent);
242  histo[ON_TRACK_SIZE_XY_F].fill(cluster.sizeY(), cluster.sizeX(), id, &iEvent);
243  }
244  histo[ON_TRACK_SHAPE].fill(shapeVal, id, &iEvent);
245  }
246 
247  for (int i = 0; i < cluster.size(); i++){
248  SiPixelCluster::Pixel const & vecipxl = cluster.pixel(i);
249  histo[DIGIS_HITMAP_ON_TRACK].fill(id, &iEvent, vecipxl.y, vecipxl.x);
250  histo[ON_TRACK_NDIGIS].fill(id, &iEvent);
251  }
252 
253  histo[ON_TRACK_NCLUSTERS].fill(id, &iEvent);
254  histo[ON_TRACK_CHARGE].fill(charge, id, &iEvent);
255  histo[ON_TRACK_SIZE].fill(cluster.size(), id, &iEvent);
256 
257  histo[ON_TRACK_POSITIONB].fill(clustgp.z(), clustgp.phi(), id, &iEvent);
258  histo[ON_TRACK_POSITIONF].fill(clustgp.x(), clustgp.y(), id, &iEvent);
259 
260  histo[CHARGE_VS_SIZE_ON_TRACK].fill(cluster.size(), charge, id, &iEvent);
261 
262  if (iAmBarrel) // Avoid mistakes even if specification < should > handle it
263  {
264  if(iAmOuter) {
265  histo[SIZE_VS_ETA_ON_TRACK_OUTER].fill(etatk, cluster.sizeY(), id, &iEvent);
266  histo[ON_TRACK_CHARGE_OUTER].fill(charge, id, &iEvent);
267  } else {
268  histo[SIZE_VS_ETA_ON_TRACK_INNER].fill(etatk, cluster.sizeY(), id, &iEvent);
269  histo[ON_TRACK_CHARGE_INNER].fill(charge, id, &iEvent);
270  }
271  }
272  }
273 
274  // statistics on tracks
275  histo[NTRACKS].fill(1, DetId(0), &iEvent);
276  if (isBpixtrack || isFpixtrack)
277  histo[NTRACKS].fill(2, DetId(0), &iEvent);
278  if (isBpixtrack)
279  histo[NTRACKS].fill(3, DetId(0), &iEvent);
280  if (isFpixtrack)
281  histo[NTRACKS].fill(4, DetId(0), &iEvent);
282 
283  if (crossesPixVol) {
284  if (isBpixtrack || isFpixtrack)
285  histo[NTRACKS_INVOLUME].fill(1, DetId(0), &iEvent);
286  else
287  histo[NTRACKS_INVOLUME].fill(0, DetId(0), &iEvent);
288  }
289  }
290 
291  histo[ON_TRACK_NCLUSTERS].executePerEventHarvesting(&iEvent);
292  histo[ON_TRACK_NDIGIS].executePerEventHarvesting(&iEvent);
293 }
294 
295 } // namespace
296 
297 
299 DEFINE_FWK_MODULE(SiPixelPhase1TrackClusters);
T getParameter(std::string const &) const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
virtual example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
virtual bool isItBigPixelInX(int ixbin) const =0
int iEvent
Definition: GenABIO.cc:230
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool isValid() const
Definition: HandleBase.h:74
void analyze(edm::Event const &e, edm::EventSetup const &eSetup) override=0
Definition: DetId.h:18
part
Definition: HCALResponse.h:20
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
fixed size matrix
HLT enums.
T get() const
Definition: EventSetup.h:63
bool isValid() const
Definition: ESHandle.h:47
Our base class.
Definition: SiPixelRecHit.h:23