test
CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  trackAssociationToken_ = consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("trajectories"));
30 }
31 
33 
34  // get geometry
36  iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
37  assert(tracker.isValid());
38 
39  //get the map
41  iEvent.getByToken( trackAssociationToken_, ttac);
42 
43  // get clusters
45  iEvent.getByToken( clustersToken_, clusterColl );
46 
47  TrajectoryStateCombiner tsoscomb;
48 
49  // we need to store some per-cluster data. Instead of a map, we use a vector,
50  // exploiting the fact that all custers live in the DetSetVector and we can
51  // use the same indices to refer to them.
52  // corr_charge is not strictly needed but cleaner to have it.
53  std::vector<bool> ontrack (clusterColl->data().size(), false);
54  std::vector<float> corr_charge(clusterColl->data().size(), -1.0f);
55 
56  for (auto& item : *ttac) {
57  auto trajectory_ref = item.key;
58  reco::TrackRef track_ref = item.val;
59 
60  bool isBpixtrack = false, isFpixtrack = false, crossesPixVol=false;
61 
62  // find out whether track crosses pixel fiducial volume (for cosmic tracks)
63  double d0 = track_ref->d0(), dz = track_ref->dz();
64  if(std::abs(d0)<15 && std::abs(dz)<50) crossesPixVol = true;
65 
66  for (auto& measurement : trajectory_ref->measurements()) {
67  // check if things are all valid
68  if (!measurement.updatedState().isValid()) continue;
69  auto hit = measurement.recHit();
70  if (!hit->isValid()) continue;
71  DetId id = hit->geographicalId();
72 
73  // check that we are in the pixel
74  uint32_t subdetid = (id.subdetId());
75  if (subdetid == PixelSubdetector::PixelBarrel) isBpixtrack = true;
76  if (subdetid == PixelSubdetector::PixelEndcap) isFpixtrack = true;
77  if (subdetid != PixelSubdetector::PixelBarrel && subdetid != PixelSubdetector::PixelEndcap) continue;
78  auto pixhit = dynamic_cast<const SiPixelRecHit*>(hit->hit());
79  if (!pixhit) continue;
80 
81  // get the cluster
82  auto clust = pixhit->cluster();
83  if (clust.isNull()) continue;
84  ontrack[clust.key()] = true; // mark cluster as ontrack
85 
86  // compute trajectory parameters at hit
87  TrajectoryStateOnSurface tsos = tsoscomb(measurement.forwardPredictedState(),
88  measurement.backwardPredictedState());
89  if (!tsos.isValid()) continue;
90 
91  // correct charge for track impact angle
93  LocalVector localDir = ltp.momentum()/ltp.momentum().mag();
94 
95  float clust_alpha = atan2(localDir.z(), localDir.x());
96  float clust_beta = atan2(localDir.z(), localDir.y());
97  double corrCharge = clust->charge() * sqrt( 1.0 / ( 1.0/pow( tan(clust_alpha), 2 ) +
98  1.0/pow( tan(clust_beta ), 2 ) +
99  1.0 ));
100  corr_charge[clust.key()] = (float) corrCharge;
101  }
102 
103  // statistics on tracks
104  histo[NTRACKS].fill(1, DetId(0), &iEvent);
105  if (isBpixtrack || isFpixtrack)
106  histo[NTRACKS].fill(2, DetId(0), &iEvent);
107  if (isBpixtrack)
108  histo[NTRACKS].fill(3, DetId(0), &iEvent);
109  if (isFpixtrack)
110  histo[NTRACKS].fill(4, DetId(0), &iEvent);
111 
112  if (crossesPixVol) {
113  if (isBpixtrack || isFpixtrack)
114  histo[NTRACKS_VOLUME].fill(1, DetId(0), &iEvent);
115  else
116  histo[NTRACKS_VOLUME].fill(0, DetId(0), &iEvent);
117  }
118  }
119 
121  for (it = clusterColl->begin(); it != clusterColl->end(); ++it) {
122  auto id = DetId(it->detId());
123 
124  const PixelGeomDetUnit* geomdetunit = dynamic_cast<const PixelGeomDetUnit*> ( tracker->idToDet(id) );
125  const PixelTopology& topol = geomdetunit->specificTopology();
126 
127  for(auto subit = it->begin(); subit != it->end(); ++subit) {
128  // we could do subit-...->data().front() as well, but this seems cleaner.
129  auto key = edmNew::makeRefTo(clusterColl, subit).key();
130  bool is_ontrack = ontrack[key];
131  float corrected_charge = corr_charge[key];
132  SiPixelCluster const& cluster = *subit;
133 
134  LocalPoint clustlp = topol.localPosition(MeasurementPoint(cluster.x(), cluster.y()));
135  GlobalPoint clustgp = geomdetunit->surface().toGlobal(clustlp);
136 
137  if (is_ontrack) {
138  histo[ONTRACK_NCLUSTERS ].fill(id, &iEvent);
139  histo[ONTRACK_CHARGE ].fill(double(corrected_charge), id, &iEvent);
140  histo[ONTRACK_SIZE ].fill(double(cluster.size() ), id, &iEvent);
141  histo[ONTRACK_POSITION_B].fill(clustgp.z(), clustgp.phi(), id, &iEvent);
142  histo[ONTRACK_POSITION_F].fill(clustgp.x(), clustgp.y(), id, &iEvent);
143  } else {
144  histo[OFFTRACK_NCLUSTERS ].fill(id, &iEvent);
145  histo[OFFTRACK_CHARGE ].fill(double(cluster.charge()), id, &iEvent);
146  histo[OFFTRACK_SIZE ].fill(double(cluster.size() ), id, &iEvent);
147  histo[OFFTRACK_POSITION_B].fill(clustgp.z(), clustgp.phi(), id, &iEvent);
148  histo[OFFTRACK_POSITION_F].fill(clustgp.x(), clustgp.y(), id, &iEvent);
149  }
150  }
151  }
152 
153  histo[ONTRACK_NCLUSTERS].executePerEventHarvesting(&iEvent);
154  histo[OFFTRACK_NCLUSTERS].executePerEventHarvesting(&iEvent);
155 }
156 
158 
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
virtual LocalPoint localPosition(const MeasurementPoint &) const =0
const LocalTrajectoryParameters & localParameters() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
assert(m_qm.get())
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
edm::EDGetTokenT< TrajTrackAssociationCollection > trackAssociationToken_
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
LocalVector momentum() const
Momentum vector in the local frame.
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
Definition: DetId.h:18
ClusterRef cluster() const
Definition: SiPixelRecHit.h:49
const T & get() const
Definition: EventSetup.h:56
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
Our base class.
Definition: SiPixelRecHit.h:23
int size() const