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 
23 
24 
26  SiPixelPhase1Base(iConfig)
27 {
28  clustersToken_ = consumes<edmNew::DetSetVector<SiPixelCluster>>(iConfig.getParameter<edm::InputTag>("clusters"));
29  tracksToken_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
30 }
31 
33 
34  // get geometry
36  iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
37  assert(tracker.isValid());
38 
39  //get the map
41  iEvent.getByToken( tracksToken_, tracks);
42 
43  // get clusters
45  iEvent.getByToken( clustersToken_, clusterColl );
46 
47  // we need to store some per-cluster data. Instead of a map, we use a vector,
48  // exploiting the fact that all custers live in the DetSetVector and we can
49  // use the same indices to refer to them.
50  // corr_charge is not strictly needed but cleaner to have it.
51  std::vector<bool> ontrack (clusterColl->data().size(), false);
52  std::vector<float> corr_charge(clusterColl->data().size(), -1.0f);
53 
54  for (auto const & track : *tracks) {
55 
56  bool isBpixtrack = false, isFpixtrack = false, crossesPixVol=false;
57 
58  // find out whether track crosses pixel fiducial volume (for cosmic tracks)
59  double d0 = track.d0(), dz = track.dz();
60  if(std::abs(d0)<15 && std::abs(dz)<50) crossesPixVol = true;
61 
62  auto const & trajParams = track.extra()->trajParams();
63  assert(trajParams.size()==track.recHitsSize());
64  auto hb = track.recHitsBegin();
65  for(unsigned int h=0;h<track.recHitsSize();h++){
66  auto hit = *(hb+h);
67  if (!hit->isValid()) continue;
68  DetId id = hit->geographicalId();
69 
70  // check that we are in the pixel
71  uint32_t subdetid = (id.subdetId());
72  if (subdetid == PixelSubdetector::PixelBarrel) isBpixtrack = true;
73  if (subdetid == PixelSubdetector::PixelEndcap) isFpixtrack = true;
74  if (subdetid != PixelSubdetector::PixelBarrel && subdetid != PixelSubdetector::PixelEndcap) continue;
75  auto pixhit = dynamic_cast<const SiPixelRecHit*>(hit->hit());
76  if (!pixhit) continue;
77 
78  // get the cluster
79  auto clust = pixhit->cluster();
80  if (clust.isNull()) continue;
81  ontrack[clust.key()] = true; // mark cluster as ontrack
82 
83 
84  // correct charge for track impact angle
85  auto const & ltp = trajParams[h];
86  LocalVector localDir = ltp.momentum()/ltp.momentum().mag();
87 
88  float clust_alpha = atan2(localDir.z(), localDir.x());
89  float clust_beta = atan2(localDir.z(), localDir.y());
90  double corrCharge = clust->charge() * sqrt( 1.0 / ( 1.0/pow( tan(clust_alpha), 2 ) +
91  1.0/pow( tan(clust_beta ), 2 ) +
92  1.0 ));
93  corr_charge[clust.key()] = (float) corrCharge;
94  }
95 
96  // statistics on tracks
97  histo[NTRACKS].fill(1, DetId(0), &iEvent);
98  if (isBpixtrack || isFpixtrack)
99  histo[NTRACKS].fill(2, DetId(0), &iEvent);
100  if (isBpixtrack)
101  histo[NTRACKS].fill(3, DetId(0), &iEvent);
102  if (isFpixtrack)
103  histo[NTRACKS].fill(4, DetId(0), &iEvent);
104 
105  if (crossesPixVol) {
106  if (isBpixtrack || isFpixtrack)
107  histo[NTRACKS_VOLUME].fill(1, DetId(0), &iEvent);
108  else
109  histo[NTRACKS_VOLUME].fill(0, DetId(0), &iEvent);
110  }
111  }
112 
114  for (it = clusterColl->begin(); it != clusterColl->end(); ++it) {
115  auto id = DetId(it->detId());
116 
117  const PixelGeomDetUnit* geomdetunit = dynamic_cast<const PixelGeomDetUnit*> ( tracker->idToDet(id) );
118  const PixelTopology& topol = geomdetunit->specificTopology();
119 
120  for(auto subit = it->begin(); subit != it->end(); ++subit) {
121  // we could do subit-...->data().front() as well, but this seems cleaner.
122  auto key = edmNew::makeRefTo(clusterColl, subit).key();
123  bool is_ontrack = ontrack[key];
124  float corrected_charge = corr_charge[key];
125  SiPixelCluster const& cluster = *subit;
126 
127  LocalPoint clustlp = topol.localPosition(MeasurementPoint(cluster.x(), cluster.y()));
128  GlobalPoint clustgp = geomdetunit->surface().toGlobal(clustlp);
129 
130  if (is_ontrack) {
131  histo[ONTRACK_NCLUSTERS ].fill(id, &iEvent);
132  histo[ONTRACK_CHARGE ].fill(double(corrected_charge), id, &iEvent);
133  histo[ONTRACK_SIZE ].fill(double(cluster.size() ), id, &iEvent);
134  histo[ONTRACK_POSITION_B].fill(clustgp.z(), clustgp.phi(), id, &iEvent);
135  histo[ONTRACK_POSITION_F].fill(clustgp.x(), clustgp.y(), id, &iEvent);
136  } else {
137  histo[OFFTRACK_NCLUSTERS ].fill(id, &iEvent);
138  histo[OFFTRACK_CHARGE ].fill(double(cluster.charge()), id, &iEvent);
139  histo[OFFTRACK_SIZE ].fill(double(cluster.size() ), id, &iEvent);
140  histo[OFFTRACK_POSITION_B].fill(clustgp.z(), clustgp.phi(), id, &iEvent);
141  histo[OFFTRACK_POSITION_F].fill(clustgp.x(), clustgp.y(), id, &iEvent);
142  }
143  }
144  }
145 
146  histo[ONTRACK_NCLUSTERS].executePerEventHarvesting(&iEvent);
147  histo[OFFTRACK_NCLUSTERS].executePerEventHarvesting(&iEvent);
148 }
149 
151 
T getParameter(std::string const &) const
edm::Ref< typename HandleT::element_type, typename HandleT::element_type::value_type::value_type > makeRefTo(const HandleT &iHandle, typename HandleT::element_type::value_type::const_iterator itIter)
float charge() const
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
const_iterator end(bool update=false) const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
edm::EDGetTokenT< reco::TrackCollection > tracksToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
T y() const
Definition: PV3DBase.h:63
SiPixelPhase1TrackClusters(const edm::ParameterSet &conf)
Measurement2DPoint MeasurementPoint
Measurement points are two-dimensional by default.
int iEvent
Definition: GenABIO.cc:230
T mag() const
Definition: PV3DBase.h:67
T sqrt(T t)
Definition: SSEVec.h:18
void analyze(const edm::Event &, const edm::EventSetup &)
T z() const
Definition: PV3DBase.h:64
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Definition: DetId.h:18
ClusterRef cluster() const
Definition: SiPixelRecHit.h:49
const T & get() const
Definition: EventSetup.h:56
virtual LocalPoint localPosition(const MeasurementPoint &) const =0
std::vector< HistogramManager > histo
Pixel cluster – collection of neighboring pixels above threshold.
float y() const
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > clustersToken_
bool isValid() const
Definition: ESHandle.h:47
T x() const
Definition: PV3DBase.h:62
float x() const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
const_iterator begin(bool update=false) const
const TrackerGeomDet * idToDet(DetId) const
Our base class.
Definition: SiPixelRecHit.h:23
int size() const