CMS 3D CMS Logo

TrackingRecoMaterialAnalyser.cc
Go to the documentation of this file.
10 
16 
26 
27 #include <cassert>
28 #include <unordered_map>
29 #include <string>
30 
31 // Values are not ordered randomly, but the order is taken from
32 // http://cmslxr.fnal.gov/dxr/CMSSW/source/Geometry/CommonDetUnit/interface/GeomDetEnumerators.h#15
33 static const std::vector<std::string> sDETS{"", "PXB", "PXF", "TIB", "TID", "TOB", "TEC"};
34 
36 public:
38  void bookHistograms(DQMStore::IBooker &i, edm::Run const &, edm::EventSetup const &) override;
39  void analyze(const edm::Event &, const edm::EventSetup &) override;
41 
42 private:
43  inline bool isDoubleSided(SiStripDetId strip_id) {
44  return ((strip_id.subDetector() != SiStripDetId::UNKNOWN) && strip_id.glued());
45  }
50  bool usePV_;
52  std::unordered_map<std::string, MonitorElement *> histosOriEta_;
53  std::unordered_map<std::string, MonitorElement *> histosEta_;
67 };
68 
69 //-------------------------------------------------------------------------
71  : refitter_(iPSet),
72  tracksToken_(consumes<reco::TrackCollection>(iPSet.getParameter<edm::InputTag>("tracks"))),
73  beamspotToken_(consumes<reco::BeamSpot>(iPSet.getParameter<edm::InputTag>("beamspot"))),
74  verticesToken_(mayConsume<reco::VertexCollection>(iPSet.getParameter<edm::InputTag>("vertices"))),
75  usePV_(iPSet.getParameter<bool>("usePV")),
76  folder_(iPSet.getParameter<std::string>("folder")),
90 
91 //-------------------------------------------------------------------------
93 
94 //-------------------------------------------------------------------------
96  edm::Run const &,
97  edm::EventSetup const &setup) {
98  using namespace std;
99  edm::ESHandle<TrackerGeometry> trackerGeometry;
100  setup.get<TrackerDigiGeometryRecord>().get(trackerGeometry);
101 
102  ibook.setCurrentFolder(folder_);
103 
104  // Histogram to store the radiation length map, in the R-Z plane,
105  // gathering numbers directly from the trackerRecoMaterial.xml
106  // file. The numbers are not corrected for the track angle.
107  histo_RZ_Ori_ = ibook.bookProfile2D("OriRadLen", "Original_RadLen", 600, -300., 300, 120, 0., 120., 0., 1.);
108 
109  // Histogram to store the radiation length map, as before, but
110  // correcting the numbers with the track angle. This represents the
111  // real material seen by the track.
112  histo_RZ_ = ibook.bookProfile2D("RadLen", "RadLen", 600, -300., 300, 120, 0., 120., 0., 1.);
113 
114  // Histogram to show the deltaP Out-In in the eta-phi plane.
116  "DeltaP_in_out_vs_eta_vs_phi_2d", "DeltaP_in_out_vs_eta_vs_phi_2d", 100, -3.0, 3.0, 100, -3.15, 3.15, 0., 100.);
117 
118  // Histogram to show the deltaP Out-In vs eta.
120  ibook.book2D("DeltaP_in_out_vs_eta_2d", "DeltaP_in_out_vs_eta_2d", 100, -3.0, 3.0, 100, 0., 1);
121 
122  // Histogram to show the deltaP Out-In vs Z. The Z coordinate is the
123  // one computed at the outermost hit.
124  deltaP_in_out_vs_z_2d_ = ibook.book2D("DeltaP_in_out_vs_z_2d", "DeltaP_in_out_vs_z_2d", 600, -300, 300, 200., -1, 1.);
125 
126  // Histogram to show the deltaP Out-In vs eta. The eta is the one
127  // computed at the innermost hit.
129  ibook.bookProfile("DeltaP_in_out_vs_eta", "DeltaP_in_out_vs_eta", 100, -3.0, 3.0, -100., 100.);
130  deltaP_in_out_vs_z_ = ibook.bookProfile("DeltaP_in_out_vs_z", "DeltaP_in_out_vs_z", 600, -300, 300, -100., 100.);
131 
132  // Histogram to show the delta_Pt Out-In vs eta. The eta is the one
133  // computed at the innermost hit.
135  ibook.bookProfile("DeltaPt_in_out_vs_eta", "DeltaPt_in_out_vs_eta", 100, -3.0, 3.0, -100., 100.);
136 
137  // Histogram to show the delta_Pt Out-In vs Z. The Z is the one
138  // computed at the outermost hit.
139  deltaPt_in_out_vs_z_ = ibook.bookProfile("DeltaPt_in_out_vs_z", "DeltaPt_in_out_vs_z", 600, -300, 300, -100., 100);
140 
141  // Histogram to show the delta_Pl Out-In vs eta. The eta is the one
142  // computed at the innermost hit.
144  ibook.bookProfile("DeltaPz_in_out_vs_eta", "DeltaPz_in_out_vs_eta", 100, -3.0, 3.0, -100., 100.);
145 
146  // Histogram to show the delta_Pl Out-In vs Z. The Z is the one
147  // computed at the outermost hit.
148  deltaPl_in_out_vs_z_ = ibook.bookProfile("DeltaPz_in_out_vs_z", "DeltaPz_in_out_vs_z", 600, -300, 300, -100., 100.);
149 
150  // Histogram to show the delta_Pt Out-In in the Z-R plane. Z and R
151  // are related to the outermost hit.
152  deltaPt_in_out_2d_ = ibook.bookProfile2D("DeltaPt 2D", "DeltaPt 2D", 600, -300., 300, 120, 0., 120., -100., 100.);
153 
154  // Histogram to show the distribution of p vs eta for all tracks.
155  P_vs_eta_2d_ = ibook.book2D("P_vs_eta_2d", "P_vs_eta_2d", 100, -3.0, 3.0, 100., 0., 5.);
156  char title[50];
157  char key[20];
158  for (unsigned int det = 1; det < sDETS.size(); ++det) {
159  for (unsigned int sub_det = 1; sub_det <= trackerGeometry->numberOfLayers(det); ++sub_det) {
160  memset(title, 0, sizeof(title));
161  snprintf(title, sizeof(title), "Original_RadLen_vs_Eta_%s%d", sDETS[det].data(), sub_det);
162  snprintf(key, sizeof(key), "%s%d", sDETS[det].data(), sub_det);
163  histosOriEta_.insert(
164  make_pair<string, MonitorElement *>(key, ibook.bookProfile(title, title, 250, -5.0, 5.0, 0., 1.)));
165  snprintf(title, sizeof(title), "RadLen_vs_Eta_%s%d", sDETS[det].data(), sub_det);
166  histosEta_.insert(
167  make_pair<string, MonitorElement *>(key, ibook.bookProfile(title, title, 250, -5.0, 5.0, 0., 1.)));
168  }
169  }
170 }
171 
172 //-------------------------------------------------------------------------
174  using namespace edm;
175  using namespace reco;
176  using namespace std;
177 
178  refitter_.setServices(setup);
179 
182  ESHandle<TrackerTopology> trk_topology;
183 
184  // Get the TrackerTopology
185  setup.get<TrackerTopologyRcd>().get(trk_topology);
186 
187  // Get Tracks
188  event.getByToken(tracksToken_, tracks);
189  if (!tracks.isValid() || tracks->empty()) {
190  LogInfo("TrackingRecoMaterialAnalyser") << "Invalid or empty track collection" << endl;
191  return;
192  }
193 
194  // Track Selector
195  auto selector = [](const Track &track, const reco::Vertex::Point &pv) -> bool {
196  return (track.quality(track.qualityByName("highPurity")) && track.dxy(pv) < 0.01 &&
197  track.hitPattern().numberOfLostTrackerHits(HitPattern::MISSING_OUTER_HITS) == 0);
198  };
199 
200  // Get BeamSpot
202  event.getByToken(beamspotToken_, beamSpot);
203  // Bail out if missing
204  if (!beamSpot.isValid())
205  return;
206 
207  reco::Vertex::Point pv(beamSpot->position());
208  if (usePV_) {
209  event.getByToken(verticesToken_, vertices);
210  if (vertices.isValid() && !vertices->empty()) {
211  // Since we need to use eta and Z information from the tracks, in
212  // order not to have the reco material distribution washed out due
213  // to geometrical effects, we need to confine the PV to some small
214  // region.
215  const Vertex &v = (*vertices)[0];
216  if (!v.isFake() && v.ndof() > 4 && std::fabs(v.z()) < 24 && std::fabs(v.position().rho()) < 2)
217  pv = v.position();
218  }
219  }
220 
221  // Main idea:
222  // * select first good tracks in input, according to reasonable criteria
223  // * refit the tracks so that we have access to the TrajectoryMeasurements
224  // that internally have all the information about the TSOS on all
225  // crossed layers. We need the refit track and not the original one so
226  // that we are able to correctly compute the path travelled by the track
227  // within the detector, using its updated TSOS. The material description
228  // can in principle be derived also directly from the rechits, via the
229  // det()[(->)GeomDet *]->mediumProperties chain, but that would simply give the
230  // face values, not the "real" ones used while propagating the track.
231  // * Loop on all measurements, extract the information about the TSOS,
232  // its surface and its mediumProperties
233  // * Make plots for the untouched material properties, but also for the
234  // ones corrected by the track direction, since the material properties,
235  // according to the documentation, should refer to normal incidence of
236  // the track, which is seldom the case, according to the current direction
237  TrajectoryStateOnSurface current_tsos;
238  DetId current_det;
239  for (auto const track : *tracks) {
240  if (!selector(track, pv))
241  continue;
242  auto const &inner = track.innerMomentum();
243  auto const &outer = track.outerMomentum();
244  deltaP_in_out_vs_eta_->Fill(inner.eta(), inner.R() - outer.R());
245  deltaP_in_out_vs_z_->Fill(track.outerZ(), inner.R() - outer.R());
246  deltaP_in_out_vs_eta_2d_->Fill(inner.eta(), inner.R() - outer.R());
247  deltaP_in_out_vs_eta_vs_phi_2d_->Fill(inner.eta(), inner.phi(), inner.R() - outer.R());
248  deltaP_in_out_vs_z_2d_->Fill(track.outerZ(), inner.R() - outer.R());
249  deltaPt_in_out_vs_eta_->Fill(inner.eta(), inner.rho() - outer.rho());
250  deltaPt_in_out_vs_z_->Fill(track.outerZ(), inner.rho() - outer.rho());
251  deltaPl_in_out_vs_eta_->Fill(inner.eta(), inner.z() - outer.z());
252  deltaPl_in_out_vs_z_->Fill(track.outerZ(), inner.z() - outer.z());
253  deltaPt_in_out_2d_->Fill(track.outerZ(), track.outerPosition().rho(), inner.rho() - outer.rho());
254  P_vs_eta_2d_->Fill(track.eta(), track.p());
255  vector<Trajectory> traj = refitter_.transform(track);
256  if (traj.size() > 1 || traj.empty())
257  continue;
258  for (auto const &tm : traj.front().measurements()) {
259  if (tm.recHit().get() &&
260  (tm.recHitR().type() == TrackingRecHit::valid || tm.recHitR().type() == TrackingRecHit::missing)) {
261  current_tsos = tm.updatedState().isValid() ? tm.updatedState() : tm.forwardPredictedState();
262  auto const &localP = current_tsos.localMomentum();
263  current_det = tm.recHit()->geographicalId();
264  const Surface &surface = current_tsos.surface();
265  assert(tm.recHit()->surface() == &surface);
266  if (!surface.mediumProperties().isValid()) {
267  LogError("TrackingRecoMaterialAnalyser")
268  << "Medium properties for material linked to detector"
269  << " are invalid at: " << current_tsos.globalPosition() << " " << (SiStripDetId)current_det << endl;
270  assert(0);
271  continue;
272  }
273  float p2 = localP.mag2();
274  float xf = std::abs(std::sqrt(p2) / localP.z());
275  float ori_xi = surface.mediumProperties().xi();
276  float ori_radLen = surface.mediumProperties().radLen();
277  float xi = ori_xi * xf;
278  float radLen = ori_radLen * xf;
279 
280  // NOTA BENE: THIS ASSUMES THAT THE TRACKS HAVE BEEN PRODUCED
281  // WITH SPLITTING, AS IS THE CASE FOR THE generalTracks
282  // collection.
283 
284  // Since there are double-sided (glued) modules all over the
285  // tracker, the material budget has been internally
286  // partitioned in two equal components, so that each single
287  // layer will receive half of the correct radLen. For this
288  // reason, only for the double-sided components, we rescale
289  // the obtained radLen by 2.
290 
291  // In particular see code here:
292  // http://cmslxr.fnal.gov/dxr/CMSSW_8_0_5/source/Geometry/TrackerGeometryBuilder/src/TrackerGeomBuilderFromGeometricDet.cc#213
293  // where, in the SiStrip Tracker, if the module has a partner
294  // (i.e. it's a glued detector) the plane is built with a
295  // scaling of 0.5. The actual plane is built few lines below:
296  // http://cmslxr.fnal.gov/dxr/CMSSW_8_0_5/source/Geometry/TrackerGeometryBuilder/src/TrackerGeomBuilderFromGeometricDet.cc#287
297 
298  if (isDoubleSided(current_det)) {
299  LogTrace("TrackingRecoMaterialAnalyser")
300  << "Eta: " << track.eta() << " " << sDETS[current_det.subdetId()] << trk_topology->layer(current_det)
301  << " has ori_radLen: " << ori_radLen << " and ori_xi: " << xi << " and has radLen: " << radLen
302  << " and xi: " << xi << endl;
303  ori_radLen *= 2.;
304  radLen *= 2.;
305  }
306 
307  histosOriEta_[sDETS[current_det.subdetId()] + to_string(trk_topology->layer(current_det))]->Fill(
308  current_tsos.globalPosition().eta(), ori_radLen);
309  histosEta_[sDETS[current_det.subdetId()] + to_string(trk_topology->layer(current_det))]->Fill(
310  current_tsos.globalPosition().eta(), radLen);
311  histo_RZ_Ori_->Fill(current_tsos.globalPosition().z(), current_tsos.globalPosition().perp(), ori_radLen);
312  histo_RZ_->Fill(current_tsos.globalPosition().z(), current_tsos.globalPosition().perp(), radLen);
313  LogInfo("TrackingRecoMaterialAnalyser")
314  << "Eta: " << track.eta() << " " << sDETS[current_det.subdetId()] << trk_topology->layer(current_det)
315  << " has ori_radLen: " << ori_radLen << " and ori_xi: " << xi << " and has radLen: " << radLen
316  << " and xi: " << xi << endl;
317  }
318  }
319  }
320 }
321 
322 //-------------------------------------------------------------------------
323 // define as a plugin
double p() const
momentum vector magnitude
Definition: TrackBase.h:599
void bookHistograms(DQMStore::IBooker &i, edm::Run const &, edm::EventSetup const &) override
const edm::EDGetTokenT< reco::VertexCollection > verticesToken_
float radLen() const
T perp() const
Definition: PV3DBase.h:69
void setServices(const edm::EventSetup &) override
set the services needed by the TrackTransformer
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
#define nullptr
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
GlobalPoint globalPosition() const
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
std::unordered_map< std::string, MonitorElement * > histosEta_
const edm::EDGetTokenT< reco::TrackCollection > tracksToken_
const edm::EDGetTokenT< reco::BeamSpot > beamspotToken_
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:62
const Point & position() const
position
Definition: Vertex.h:113
static const std::vector< std::string > sDETS
unsigned int numberOfLayers(int subdet) const
double outerZ() const
z coordinate of the outermost hit position
Definition: Track.h:115
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int numberOfLostTrackerHits(HitCategory category) const
Definition: HitPattern.h:863
std::unordered_map< std::string, MonitorElement * > histosOriEta_
LocalVector localMomentum() const
void Fill(long long x)
const SurfaceType & surface() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:617
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
T sqrt(T t)
Definition: SSEVec.h:19
T z() const
Definition: PV3DBase.h:61
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, char const *option="s")
Definition: DQMStore.cc:333
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
static constexpr auto UNKNOWN
Definition: SiStripDetId.h:36
def pv(vc)
Definition: MetAnalyzer.py:7
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double z() const
z coordinate
Definition: Vertex.h:119
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
MonitorElement * bookProfile2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, double lowZ, double highZ, char const *option="s")
Definition: DQMStore.cc:381
std::vector< Trajectory > transform(const reco::Track &) const override
Convert a reco::Track into Trajectory.
TrackingRecoMaterialAnalyser(const edm::ParameterSet &)
bool isValid() const
Definition: HandleBase.h:70
double p2[4]
Definition: TauolaWrapper.h:90
#define LogTrace(id)
double ndof() const
Definition: Vertex.h:109
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:18
SubDetector subDetector() const
Definition: SiStripDetId.h:105
Definition: DetId.h:17
uint32_t glued() const
Definition: SiStripDetId.h:163
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
Definition: Track.h:65
bool isFake() const
Definition: Vertex.h:75
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:483
float xi() const
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:531
unsigned int layer(const DetId &id) const
T eta() const
Definition: PV3DBase.h:73
fixed size matrix
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Definition: DQMStore.cc:266
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:59
T get() const
Definition: EventSetup.h:73
bool isDoubleSided(SiStripDetId strip_id)
const Point & position() const
position
Definition: BeamSpot.h:59
void analyze(const edm::Event &, const edm::EventSetup &) override
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:587
bool isValid() const
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
const MediumProperties & mediumProperties() const
Definition: Surface.h:85
Definition: event.py:1
Definition: Run.h:45