CMS 3D CMS Logo

AlignmentMonitorMuonVsCurvature.cc
Go to the documentation of this file.
1 /*
2  * Package: CommonAlignmentProducer
3  * Class : AlignmentMonitorMuonVsCurvature
4  *
5  * Original Author: Jim Pivarski
6  * Created: Fri Feb 19 21:45:02 CET 2010
7  *
8  * $Id:$
9  */
10 
14 
21 
22 #include <sstream>
23 #include "TProfile.h"
24 #include "TH2F.h"
25 #include "TH1F.h"
26 
33 
35 public:
38 
39  void book() override;
40 
41  void event(const edm::Event &iEvent,
42  const edm::EventSetup &iSetup,
43  const ConstTrajTrackPairCollection &iTrajTracks) override;
44  void processMuonResidualsFromTrack(MuonResidualsFromTrack &mrft, const Trajectory *traj = nullptr);
45 
46 private:
47  // es token
53 
54  // parameters
56  const double m_minTrackPt;
57  const double m_minTrackP;
58  const int m_minTrackerHits;
59  const double m_maxTrackerRedChi2;
60  const bool m_allowTIDTEC;
62  const double m_maxDxy;
63  const int m_minDT13Hits;
64  const int m_minDT2Hits;
65  const int m_minCSCHits;
66  const int m_layer;
68  const bool m_doDT;
69  const bool m_doCSC;
70 
73 
75 
76  // DT [wheel][station][sector]
79 
80  // CSC [endcap*station][ring][chamber]
83 
86 };
87 
90  : AlignmentMonitorBase(cfg, iC, "AlignmentMonitorMuonVsCurvature"),
91  m_esTokenGBTGeom(iC.esConsumes()),
92  m_esTokenDetId(iC.esConsumes(edm::ESInputTag("", "MuonDetIdAssociator"))),
93  m_esTokenProp(iC.esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAny"))),
94  m_esTokenMF(iC.esConsumes()),
95  m_esTokenBuilder(iC.esConsumes(MuonResidualsFromTrack::builderESInputTag())),
96  m_muonCollectionTag(cfg.getParameter<edm::InputTag>("muonCollectionTag")),
97  m_minTrackPt(cfg.getParameter<double>("minTrackPt")),
98  m_minTrackP(cfg.getParameter<double>("minTrackP")),
99  m_minTrackerHits(cfg.getParameter<int>("minTrackerHits")),
100  m_maxTrackerRedChi2(cfg.getParameter<double>("maxTrackerRedChi2")),
101  m_allowTIDTEC(cfg.getParameter<bool>("allowTIDTEC")),
102  m_minNCrossedChambers(cfg.getParameter<int>("minNCrossedChambers")),
103  m_maxDxy(cfg.getParameter<double>("maxDxy")),
104  m_minDT13Hits(cfg.getParameter<int>("minDT13Hits")),
105  m_minDT2Hits(cfg.getParameter<int>("minDT2Hits")),
106  m_minCSCHits(cfg.getParameter<int>("minCSCHits")),
107  m_layer(cfg.getParameter<int>("layer")),
108  m_propagator(cfg.getParameter<std::string>("propagator")),
109  m_doDT(cfg.getParameter<bool>("doDT")),
110  m_doCSC(cfg.getParameter<bool>("doCSC")),
111  bsToken_(iC.consumes<reco::BeamSpot>(m_beamSpotTag)),
112  muonToken_(iC.consumes<reco::MuonCollection>(m_muonCollectionTag)) {}
113 
115  // DT
116  std::string wheelname[5] = {"wheelm2_", "wheelm1_", "wheelz_", "wheelp1_", "wheelp2_"};
117  if (m_doDT)
118  for (int wheel = -2; wheel <= 2; wheel++)
119  for (int station = 1; station <= 4; station++)
120  for (int sector = 1; sector <= 14; sector++) {
121  if (station != 4 && sector > 12)
122  continue;
123 
124  char stationname[20];
125  sprintf(stationname, "st%d_", station);
126 
127  char sectorname[20];
128  sprintf(sectorname, "sector%02d_", sector);
129 
130  for (int component = 0; component < kNumComponents; component++) {
131  std::stringstream th2f_name, tprofile_name;
132  th2f_name << "th2f_" << wheelname[wheel + 2] << stationname << sectorname;
133  tprofile_name << "tprofile_" << wheelname[wheel + 2] << stationname << sectorname;
134 
135  double yminmax = 50., xminmax = 0.05;
136  if (m_minTrackPt > 0.)
137  xminmax = 1. / m_minTrackPt;
138  int ynbins = 50;
139  if (component == kDeltaX) {
140  th2f_name << "deltax";
141  tprofile_name << "deltax";
142  } else if (component == kDeltaDxDz) {
143  th2f_name << "deltadxdz";
144  tprofile_name << "deltadxdz";
145  }
146 
147  th2f_wheel_st_sector[wheel + 2][station - 1][sector - 1][component] =
148  book2D("/iterN/", th2f_name.str(), "", 30, -xminmax, xminmax, ynbins, -yminmax, yminmax);
149  tprofile_wheel_st_sector[wheel + 2][station - 1][sector - 1][component] =
150  bookProfile("/iterN/", tprofile_name.str(), "", 30, -xminmax, xminmax);
151  }
152  }
153 
154  // CSC
155  std::string stname[8] = {"Ep_S1_", "Ep_S2_", "Ep_S3_", "Ep_S4_", "Em_S1_", "Em_S2_", "Em_S3_", "Em_S4_"};
156  if (m_doCSC)
157  for (int station = 0; station < 8; station++)
158  for (int ring = 1; ring <= 3; ring++)
159  for (int chamber = 1; chamber <= 36; chamber++) {
160  int st = station % 4 + 1;
161  if (st > 1 && ring > 2)
162  continue; // only station 1 has more then 2 rings
163  if (st > 1 && ring == 1 && chamber > 18)
164  continue; // ring 1 stations 1,2,3 have 18 chambers
165 
166  char ringname[20];
167  sprintf(ringname, "R%d_", ring);
168 
169  char chname[20];
170  sprintf(chname, "C%02d_", chamber);
171 
172  for (int component = 0; component < kNumComponents; component++) {
173  std::stringstream componentname;
174  double yminmax = 50., xminmax = 0.05;
175  if (m_minTrackPt > 0.)
176  xminmax = 1. / m_minTrackPt;
177  if (ring == 1)
178  xminmax *= 0.5;
179  if (component == kDeltaX) {
180  componentname << "deltax";
181  } else if (component == kDeltaDxDz) {
182  componentname << "deltadxdz";
183  }
184 
185  std::stringstream th2f_name, tprofile_name;
186  th2f_name << "th2f_" << stname[station] << ringname << chname << componentname.str();
187  tprofile_name << "tprofile_" << stname[station] << ringname << chname << componentname.str();
188 
189  th2f_st_ring_chamber[station][ring - 1][chamber - 1][component] =
190  book2D("/iterN/", th2f_name.str(), "", 30, -xminmax, xminmax, 100, -yminmax, yminmax);
191  tprofile_st_ring_chamber[station][ring - 1][chamber - 1][component] =
192  bookProfile("/iterN/", tprofile_name.str(), "", 30, -xminmax, xminmax);
193  }
194  }
195 
196  th1f_trackerRedChi2 = book1D("/iterN/", "trackerRedChi2", "Refit tracker reduced chi^2", 100, 0., 30.);
198  book1D("/iterN/", "trackerRedChi2Diff", "Fit-minus-refit tracker reduced chi^2", 100, -5., 5.);
199 }
200 
202  const edm::EventSetup &iSetup,
203  const ConstTrajTrackPairCollection &trajtracks) {
205 
206  const GlobalTrackingGeometry *globalGeometry = &iSetup.getData(m_esTokenGBTGeom);
207  const DetIdAssociator *muonDetIdAssociator_ = &iSetup.getData(m_esTokenDetId);
208  const Propagator *prop = &iSetup.getData(m_esTokenProp);
210  auto builder = iSetup.getHandle(m_esTokenBuilder);
211 
212  if (m_muonCollectionTag.label().empty()) // use trajectories
213  {
214  for (ConstTrajTrackPairCollection::const_iterator trajtrack = trajtracks.begin(); trajtrack != trajtracks.end();
215  ++trajtrack) {
216  const Trajectory *traj = (*trajtrack).first;
217  const reco::Track *track = (*trajtrack).second;
218 
219  if (track->pt() > m_minTrackPt && track->p() > m_minTrackP && fabs(track->dxy(beamSpot->position())) < m_maxDxy) {
220  MuonResidualsFromTrack muonResidualsFromTrack(
221  builder, magneticField, globalGeometry, muonDetIdAssociator_, prop, traj, track, pNavigator(), 1000.);
222  processMuonResidualsFromTrack(muonResidualsFromTrack, traj);
223  } // end if track pT is within range
224  } // end loop over tracks
225  } else {
227 
228  for (reco::MuonCollection::const_iterator muon = muons->begin(); muon != muons->end(); ++muon) {
229  if (!(muon->isTrackerMuon() && muon->innerTrack().isNonnull()))
230  continue;
231 
232  if (m_minTrackPt < muon->pt() && m_minTrackP < muon->p() &&
233  fabs(muon->innerTrack()->dxy(beamSpot->position())) < m_maxDxy) {
234  MuonResidualsFromTrack muonResidualsFromTrack(globalGeometry, &(*muon), pNavigator(), 100.);
235  processMuonResidualsFromTrack(muonResidualsFromTrack);
236  }
237  }
238  }
239 }
240 
242  const Trajectory *traj) {
243  if (mrft.trackerNumHits() < m_minTrackerHits)
244  return;
245  if (!m_allowTIDTEC && mrft.contains_TIDTEC())
246  return;
247 
248  int nMuChambers = 0;
249  std::vector<DetId> chamberIds = mrft.chamberIds();
250  for (unsigned ch = 0; ch < chamberIds.size(); ch++)
251  if (chamberIds[ch].det() == DetId::Muon)
252  nMuChambers++;
253  if (nMuChambers < m_minNCrossedChambers)
254  return;
255 
256  th1f_trackerRedChi2->Fill(mrft.trackerRedChi2());
258 
259  if (mrft.normalizedChi2() > m_maxTrackerRedChi2)
260  return;
261 
262  double qoverpt = mrft.getTrack()->charge() / mrft.getTrack()->pt();
263  double qoverpz = 0.;
264  if (fabs(mrft.getTrack()->pz()) > 0.01)
265  qoverpz = mrft.getTrack()->charge() / fabs(mrft.getTrack()->pz());
266 
267  for (std::vector<DetId>::const_iterator chamberId = chamberIds.begin(); chamberId != chamberIds.end(); ++chamberId) {
268  if (chamberId->det() != DetId::Muon)
269  continue;
270 
271  if (m_doDT && chamberId->subdetId() == MuonSubdetId::DT) {
272  DTChamberId dtid(chamberId->rawId());
274 
275  if (dt13 != nullptr && dt13->numHits() >= m_minDT13Hits) {
276  int wheel = dtid.wheel() + 2;
277  int station = dtid.station() - 1;
278  int sector = dtid.sector() - 1;
279 
280  double resid_x = 10. * dt13->global_residual();
281  double resid_dxdz = 1000. * dt13->global_resslope();
282 
283  if (fabs(resid_x) < 100. && fabs(resid_dxdz) < 100.) {
284  th2f_wheel_st_sector[wheel][station][sector][kDeltaX]->Fill(qoverpt, resid_x);
285  tprofile_wheel_st_sector[wheel][station][sector][kDeltaX]->Fill(qoverpt, resid_x);
286  th2f_wheel_st_sector[wheel][station][sector][kDeltaDxDz]->Fill(qoverpt, resid_dxdz);
287  tprofile_wheel_st_sector[wheel][station][sector][kDeltaDxDz]->Fill(qoverpt, resid_dxdz);
288  }
289  } // if it's a good segment
290  } // if DT
291 
292  if (m_doCSC && chamberId->subdetId() == MuonSubdetId::CSC) {
293  CSCDetId cscid(chamberId->rawId());
295 
296  if (csc != nullptr && csc->numHits() >= m_minCSCHits) {
297  int station = 4 * cscid.endcap() + cscid.station() - 5;
298  int ring = cscid.ring() - 1;
299  if (cscid.station() == 1 && cscid.ring() == 4)
300  ring = 0; // join ME1/a to ME1/b
301  int chamber = cscid.chamber() - 1;
302 
303  double resid_x = 10. * csc->global_residual();
304  double resid_dxdz = 1000. * csc->global_resslope();
305 
306  if (fabs(resid_x) < 100. && fabs(resid_dxdz) < 100.) {
307  th2f_st_ring_chamber[station][ring][chamber][kDeltaX]->Fill(qoverpz, resid_x);
308  tprofile_st_ring_chamber[station][ring][chamber][kDeltaX]->Fill(qoverpz, resid_x);
309  th2f_st_ring_chamber[station][ring][chamber][kDeltaDxDz]->Fill(qoverpz, resid_dxdz);
310  tprofile_st_ring_chamber[station][ring][chamber][kDeltaDxDz]->Fill(qoverpz, resid_dxdz);
311  }
312  } // if it's a good segment
313  } // if CSC
314 
315  } // end loop over chamberIds
316 }
317 
AlignableNavigator * pNavigator()
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::EDGetTokenT< reco::MuonCollection > muonToken_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const MuonResidualsFromTrack::BuilderToken m_esTokenBuilder
TH2F * book2D(std::string dir, std::string name, std::string title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
const edm::ESGetToken< Propagator, TrackingComponentsRecord > m_esTokenProp
TH2F * th2f_st_ring_chamber[8][3][36][kNumComponents]
const edm::EDGetTokenT< reco::BeamSpot > bsToken_
TProfile * tprofile_st_ring_chamber[8][3][36][kNumComponents]
std::string const & label() const
Definition: InputTag.h:36
AlignmentMonitorMuonVsCurvature(const edm::ParameterSet &cfg, edm::ConsumesCollector iC)
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:212
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > m_esTokenMF
TProfile * bookProfile(std::string dir, std::string name, std::string title, int nchX, double lowX, double highX, int nchY=1, double lowY=0., double highY=0., const char *option="s")
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
void event(const edm::Event &iEvent, const edm::EventSetup &iSetup, const ConstTrajTrackPairCollection &iTrajTracks) override
Called for each event (by "run()"): may be reimplemented.
double pt() const
track transverse momentum
Definition: TrackBase.h:637
void processMuonResidualsFromTrack(MuonResidualsFromTrack &mrft, const Trajectory *traj=nullptr)
int charge() const
track electric charge
Definition: TrackBase.h:596
int iEvent
Definition: GenABIO.cc:224
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > m_esTokenGBTGeom
const reco::Track * getTrack()
void book() override
Book or retrieve histograms; MUST be reimplemented.
std::vector< ConstTrajTrackPair > ConstTrajTrackPairCollection
TProfile * tprofile_wheel_st_sector[5][4][14][kNumComponents]
TH1F * book1D(std::string dir, std::string name, std::string title, int nchX, double lowX, double highX)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
Definition: L1Track.h:19
const edm::ESGetToken< DetIdAssociator, DetIdAssociatorRecord > m_esTokenDetId
const std::vector< DetId > chamberIds() const
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:646
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
Definition: TrackBase.h:593
fixed size matrix
HLT enums.
#define DEFINE_EDM_PLUGIN(factory, type, name)
static constexpr int DT
Definition: MuonSubdetId.h:11
TH2F * th2f_wheel_st_sector[5][4][14][kNumComponents]
static constexpr int CSC
Definition: MuonSubdetId.h:12
MuonChamberResidual * chamberResidual(DetId chamberId, int type)