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 
29 
30 namespace {
31 
32 class SiPixelPhase1TrackClusters final : public SiPixelPhase1Base {
33 enum { // copy paste from cfy: the only safe way to doit....
34  SiPixelPhase1TrackClustersOnTrackCharge,
35  SiPixelPhase1TrackClustersOnTrackSize,
36  SiPixelPhase1TrackClustersOnTrackShape,
37  SiPixelPhase1TrackClustersOnTrackNClusters,
38  SiPixelPhase1TrackClustersOnTrackPositionB,
39  SiPixelPhase1TrackClustersOnTrackPositionF,
40 
41  SiPixelPhase1TrackClustersNTracks,
42  SiPixelPhase1TrackClustersNTracksInVolume,
43 
44  SiPixelPhase1ClustersSizeVsEtaOnTrackOuter,
45  SiPixelPhase1ClustersSizeVsEtaOnTrackInner,
46  SiPixelPhase1TrackClustersOnTrackChargeOuter,
47  SiPixelPhase1TrackClustersOnTrackChargeInner,
48 
49  SiPixelPhase1TrackClustersOnTrackShapeOuter,
50  SiPixelPhase1TrackClustersOnTrackShapeInner,
51 
52  SiPixelPhase1TrackClustersOnTrackSizeXOuter,
53  SiPixelPhase1TrackClustersOnTrackSizeXInner,
54  SiPixelPhase1TrackClustersOnTrackSizeYOuter,
55  SiPixelPhase1TrackClustersOnTrackSizeYInner,
56 
57  SiPixelPhase1TrackClustersOnTrackSizeXYOuter,
58  SiPixelPhase1TrackClustersOnTrackSizeXYInner,
59 
60  SiPixelPhase1ClustersSizeVsEtaOnTrack,
61 
62 
63  SiPixelPhase1TrackClustersEnumSize
64 };
65 
66 public:
67  explicit SiPixelPhase1TrackClusters(const edm::ParameterSet& conf);
68  void analyze(const edm::Event&, const edm::EventSetup&) override;
69 
70 private:
71  const bool applyVertexCut_;
72 
73  const edm::EDGetTokenT<reco::TrackCollection> tracksToken_;
74  const edm::EDGetTokenT<reco::VertexCollection> offlinePrimaryVerticesToken_;
75  const edm::EDGetTokenT<SiPixelClusterShapeCache> pixelClusterShapeCacheToken_;
76 };
77 
78 
79 
80 SiPixelPhase1TrackClusters::SiPixelPhase1TrackClusters(const edm::ParameterSet& iConfig) :
81  SiPixelPhase1Base(iConfig),
82  applyVertexCut_(iConfig.getUntrackedParameter<bool>("VertexCut",true)),
83  tracksToken_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"))),
84  offlinePrimaryVerticesToken_(applyVertexCut_ ?
85  consumes<reco::VertexCollection>(iConfig.getUntrackedParameter<edm::InputTag>("vertices",edm::InputTag("offlinePrimaryVertices"))) :
86  edm::EDGetTokenT<reco::VertexCollection>()),
87  pixelClusterShapeCacheToken_(consumes<SiPixelClusterShapeCache>( edm::InputTag("siPixelClusterShapeCache")))
88 {}
89 
91 
92  if (histo.size() != SiPixelPhase1TrackClustersEnumSize) {
93  edm::LogError("SiPixelPhase1TrackClusters") << "incompatible configuration " << histo.size()
94  << "!=" << SiPixelPhase1TrackClustersEnumSize << std::endl;
95  return;
96  }
97 
98  // get geometry
100  iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
101  assert(tracker.isValid());
102 
103  edm::ESHandle<TrackerTopology> tTopoHandle;
104  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
105  auto const & tkTpl = *tTopoHandle;
106 
108  iSetup.get<CkfComponentsRecord>().get("ClusterShapeHitFilter", shapeFilterH);
109  auto const & shapeFilter = *shapeFilterH;
110 
111 
113  if(applyVertexCut_) {
114  iEvent.getByToken(offlinePrimaryVerticesToken_, vertices);
115  if (!vertices.isValid() || vertices->empty()) return;
116  }
117 
118  //get the map
120  iEvent.getByToken( tracksToken_, tracks);
121 
122  if ( !tracks.isValid() ) {
123  edm::LogWarning("SiPixelPhase1TrackClusters") << "track collection is not valid";
124  return;
125  }
126 
127 
128  edm::Handle<SiPixelClusterShapeCache> pixelClusterShapeCacheH;
129  iEvent.getByToken(pixelClusterShapeCacheToken_, pixelClusterShapeCacheH);
130  auto const & pixelClusterShapeCache = *pixelClusterShapeCacheH;
131 
132  for (auto const & track : *tracks) {
133 
134  if (applyVertexCut_ && (track.pt() < 0.75 || std::abs( track.dxy((*vertices)[0].position()) ) > 5*track.dxyError())) continue;
135 
136  bool isBpixtrack = false, isFpixtrack = false, crossesPixVol=false;
137 
138  // find out whether track crosses pixel fiducial volume (for cosmic tracks)
139  auto d0 = track.d0(), dz = track.dz();
140  if(std::abs(d0)<15 && std::abs(dz)<50) crossesPixVol = true;
141 
142  auto etatk = track.eta();
143 
144  auto const & trajParams = track.extra()->trajParams();
145  assert(trajParams.size()==track.recHitsSize());
146  auto hb = track.recHitsBegin();
147  for(unsigned int h=0;h<track.recHitsSize();h++){
148  auto hit = *(hb+h);
149  if (!hit->isValid()) continue;
150  auto id = hit->geographicalId();
151 
152  // check that we are in the pixel
153  auto subdetid = (id.subdetId());
154  if (subdetid == PixelSubdetector::PixelBarrel) isBpixtrack = true;
155  if (subdetid == PixelSubdetector::PixelEndcap) isFpixtrack = true;
156  if (subdetid != PixelSubdetector::PixelBarrel && subdetid != PixelSubdetector::PixelEndcap) continue;
157  auto pixhit = dynamic_cast<const SiPixelRecHit*>(hit->hit());
158  if (!pixhit) continue;
159 
160  // auto geomdetunit = dynamic_cast<const PixelGeomDetUnit*> (pixhit->detUnit());
161  // auto const & topol = geomdetunit->specificTopology();
162 
163  // get the cluster
164  auto clustp = pixhit->cluster();
165  if (clustp.isNull()) continue;
166  auto const & cluster = *clustp;
167 
168  auto const & ltp = trajParams[h];
169 
170  auto localDir = ltp.momentum()/ltp.momentum().mag();
171 
172  // correct charge for track impact angle
173 
174  auto charge = cluster.charge()*ltp.absdz();
175 
176  auto clustgp = pixhit->globalPosition(); // from rechit
177 
178 
179  int part;
181  std::pair<float,float> pred;
182  if(shapeFilter.getSizes(*pixhit,localDir,pixelClusterShapeCache, part,meas, pred)) {
183  auto shape = shapeFilter.isCompatible(*pixhit,localDir,pixelClusterShapeCache);
184  if(tkTpl.pxbLadder(id)%2==1) {
185  histo[SiPixelPhase1TrackClustersOnTrackSizeXOuter].fill(pred.first, cluster.sizeX(), id, &iEvent);
186  histo[SiPixelPhase1TrackClustersOnTrackSizeYOuter].fill(pred.second,cluster.sizeY(), id, &iEvent);
187  histo[SiPixelPhase1TrackClustersOnTrackSizeXYOuter].fill(pred.second-cluster.sizeY(),pred.first-cluster.sizeX(), id, &iEvent);
188 
189  histo[SiPixelPhase1TrackClustersOnTrackShapeOuter].fill(shape?1:0,id, &iEvent);
190  } else {
191  histo[SiPixelPhase1TrackClustersOnTrackSizeXInner].fill(pred.first, cluster.sizeX(), id, &iEvent);
192  histo[SiPixelPhase1TrackClustersOnTrackSizeYInner].fill(pred.second,cluster.sizeY(), id, &iEvent);
193  histo[SiPixelPhase1TrackClustersOnTrackSizeXYInner].fill(pred.second-cluster.sizeY(),pred.first-cluster.sizeX(), id, &iEvent);
194 
195  histo[SiPixelPhase1TrackClustersOnTrackShapeInner].fill(shape?1:0,id, &iEvent);
196  }
197  histo[SiPixelPhase1TrackClustersOnTrackShape].fill(shape?1:0,id, &iEvent);
198  }
199 
200  histo[SiPixelPhase1TrackClustersOnTrackNClusters].fill(id, &iEvent);
201  histo[SiPixelPhase1TrackClustersOnTrackCharge].fill(charge, id, &iEvent);
202  histo[SiPixelPhase1TrackClustersOnTrackSize].fill(cluster.size(), id, &iEvent);
203 
204  histo[SiPixelPhase1TrackClustersOnTrackPositionB].fill(clustgp.z(), clustgp.phi(), id, &iEvent);
205  histo[SiPixelPhase1TrackClustersOnTrackPositionF].fill(clustgp.x(), clustgp.y(), id, &iEvent);
206 
207  histo[SiPixelPhase1ClustersSizeVsEtaOnTrack].fill(etatk, cluster.sizeY(), id, &iEvent);
208 
209  if(tkTpl.pxbLadder(id)%2==1) {
210  histo[SiPixelPhase1ClustersSizeVsEtaOnTrackOuter].fill(etatk, cluster.sizeY(), id, &iEvent);
211  histo[SiPixelPhase1TrackClustersOnTrackChargeOuter].fill(charge, id, &iEvent);
212  } else {
213  histo[SiPixelPhase1ClustersSizeVsEtaOnTrackInner].fill(etatk, cluster.sizeY(), id, &iEvent);
214  histo[SiPixelPhase1TrackClustersOnTrackChargeInner].fill(charge, id, &iEvent);
215  }
216 
217  }
218 
219  // statistics on tracks
220  histo[SiPixelPhase1TrackClustersNTracks].fill(1, DetId(0), &iEvent);
221  if (isBpixtrack || isFpixtrack)
222  histo[SiPixelPhase1TrackClustersNTracks].fill(2, DetId(0), &iEvent);
223  if (isBpixtrack)
224  histo[SiPixelPhase1TrackClustersNTracks].fill(3, DetId(0), &iEvent);
225  if (isFpixtrack)
226  histo[SiPixelPhase1TrackClustersNTracks].fill(4, DetId(0), &iEvent);
227 
228  if (crossesPixVol) {
229  if (isBpixtrack || isFpixtrack)
230  histo[SiPixelPhase1TrackClustersNTracksInVolume].fill(1, DetId(0), &iEvent);
231  else
232  histo[SiPixelPhase1TrackClustersNTracksInVolume].fill(0, DetId(0), &iEvent);
233  }
234  }
235 
236  histo[SiPixelPhase1TrackClustersOnTrackNClusters].executePerEventHarvesting(&iEvent);
237 }
238 
239 }// namespace
240 
242 DEFINE_FWK_MODULE(SiPixelPhase1TrackClusters);
243 
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
def analyze(function, filename, filter=None)
Definition: Profiling.py:11
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
int iEvent
Definition: GenABIO.cc:230
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool isValid() const
Definition: HandleBase.h:74
Definition: DetId.h:18
part
Definition: HCALResponse.h:20
ClusterRef cluster() const
Definition: SiPixelRecHit.h:49
const T & get() const
Definition: EventSetup.h:56
fixed size matrix
HLT enums.
void analyze(edm::Event const &e, edm::EventSetup const &eSetup)=0
bool isValid() const
Definition: ESHandle.h:47
Our base class.
Definition: SiPixelRecHit.h:23