CMS 3D CMS Logo

SiPixelPhase1RecHits.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiPixelPhase1RecHits
4 // Class: SiPixelPhase1RecHits
5 //
6 
7 // Original Author: Marcel Schneider
8 
24 
25 namespace {
26 
27 class SiPixelPhase1RecHits final : public SiPixelPhase1Base {
28  enum {
29  NRECHITS,
30  CLUST_X,
31  CLUST_Y,
32  ERROR_X,
33  ERROR_Y,
34  POS,
35  CLUSTER_PROB
36  };
37 
38  public:
39  explicit SiPixelPhase1RecHits(const edm::ParameterSet& conf);
40  void analyze(const edm::Event&, const edm::EventSetup&) override;
41 
42  private:
44  edm::EDGetTokenT<reco::VertexCollection> offlinePrimaryVerticesToken_;
45 
46  bool onlyValid_;
47  bool applyVertexCut_;
48 };
49 
50 SiPixelPhase1RecHits::SiPixelPhase1RecHits(const edm::ParameterSet& iConfig) :
51  SiPixelPhase1Base(iConfig)
52 {
53  srcToken_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("src"));
54 
55  offlinePrimaryVerticesToken_ = consumes<reco::VertexCollection>(std::string("offlinePrimaryVertices"));
56 
57  onlyValid_=iConfig.getParameter<bool>("onlyValidHits");
58 
59  applyVertexCut_=iConfig.getUntrackedParameter<bool>("VertexCut",true);
60 
61 }
62 
64  if( !checktrigger(iEvent,iSetup,DCS) ) return;
65 
67  iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
68  assert(tracker.isValid());
69 
71  iEvent.getByToken( srcToken_, tracks);
72  if (!tracks.isValid()) return;
73 
75  iEvent.getByToken(offlinePrimaryVerticesToken_, vertices);
76 
77  if (applyVertexCut_ && (!vertices.isValid() || vertices->empty())) return;
78 
79 
80  for (auto const & track : *tracks) {
81 
82  if (applyVertexCut_ && (track.pt() < 0.75 || std::abs( track.dxy(vertices->at(0).position()) ) > 5*track.dxyError())) continue;
83 
84  bool isBpixtrack = false, isFpixtrack = false;
85 
86  auto const & trajParams = track.extra()->trajParams();
87  auto hb = track.recHitsBegin();
88  for(unsigned int h=0;h<track.recHitsSize();h++){
89 
90  auto hit = *(hb+h);
91  if(!hit->isValid()) continue;
92 
93  DetId id = hit->geographicalId();
94  uint32_t subdetid = (id.subdetId());
95 
96  if (subdetid == PixelSubdetector::PixelBarrel) isBpixtrack = true;
97  if (subdetid == PixelSubdetector::PixelEndcap) isFpixtrack = true;
98  }
99 
100  if (!isBpixtrack && !isFpixtrack) continue;
101 
102  // then, look at each hit
103  for(unsigned int h=0;h<track.recHitsSize();h++){
104  auto rechit = *(hb+h);
105 
106  if(!rechit->isValid()) continue;
107 
108  //continue if not a Pixel recHit
109  DetId id = rechit->geographicalId();
110  uint32_t subdetid = (id.subdetId());
111 
112  if ( subdetid != PixelSubdetector::PixelBarrel
113  && subdetid != PixelSubdetector::PixelEndcap) continue;
114 
115  bool isHitValid = rechit->getType()==TrackingRecHit::valid;
116  if (onlyValid_ && !isHitValid) continue; //useful to run on cosmics where the TrackEfficiency plugin is not used
117 
118  const SiPixelRecHit* prechit = dynamic_cast<const SiPixelRecHit*>(rechit);//to be used to get the associated cluster and the cluster probability
119 
120  int sizeX=0, sizeY=0;
121 
122  if (isHitValid){
123  SiPixelRecHit::ClusterRef const& clust = prechit->cluster();
124  sizeX = (*clust).sizeX();
125  sizeY = (*clust).sizeY();
126  }
127 
128  const PixelGeomDetUnit* geomdetunit = dynamic_cast<const PixelGeomDetUnit*> ( tracker->idToDet(id) );
129  const PixelTopology& topol = geomdetunit->specificTopology();
130 
131  LocalPoint lp = trajParams[h].position();
132  MeasurementPoint mp = topol.measurementPosition(lp);
133 
134  int row = (int) mp.x();
135  int col = (int) mp.y();
136 
137  float rechit_x = lp.x();
138  float rechit_y = lp.y();
139 
140  LocalError lerr = rechit->localPositionError();
141  float lerr_x = sqrt(lerr.xx());
142  float lerr_y = sqrt(lerr.yy());
143 
144  histo[NRECHITS].fill(id, &iEvent, col, row); //in general a inclusive counter of missing/valid/inactive hits
145 
146  if (isHitValid){
147  histo[CLUST_X].fill(sizeX, id, &iEvent, col, row);
148  histo[CLUST_Y].fill(sizeY, id, &iEvent, col, row);
149  }
150 
151  histo[ERROR_X].fill(lerr_x, id, &iEvent);
152  histo[ERROR_Y].fill(lerr_y, id, &iEvent);
153 
154  histo[POS].fill(rechit_x, rechit_y, id, &iEvent);
155 
156  if (isHitValid){
157  double clusterProbability= prechit->clusterProbability(0);
158  if (clusterProbability > 0)
159  histo[CLUSTER_PROB].fill(log10(clusterProbability), id, &iEvent);
160  }
161  }
162  }
163 
164  histo[NRECHITS].executePerEventHarvesting(&iEvent);
165 }
166 
167 } //namespace
168 
169 DEFINE_FWK_MODULE(SiPixelPhase1RecHits);
170 
T getParameter(std::string const &) const
float xx() const
Definition: LocalError.h:24
float clusterProbability(unsigned int flags=0) const
T y() const
Definition: PV2DBase.h:46
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:519
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
T y() const
Definition: PV3DBase.h:63
int iEvent
Definition: GenABIO.cc:230
float yy() const
Definition: LocalError.h:26
T sqrt(T t)
Definition: SSEVec.h:18
virtual MeasurementPoint measurementPosition(const LocalPoint &) const =0
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
ClusterRef cluster() const
Definition: SiPixelRecHit.h:49
const T & get() const
Definition: EventSetup.h:59
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
col
Definition: cuy.py:1008
const TrackerGeomDet * idToDet(DetId) const override
bool isValid() const
Definition: ESHandle.h:47
T x() const
Definition: PV2DBase.h:45
T x() const
Definition: PV3DBase.h:62
Our base class.
Definition: SiPixelRecHit.h:23