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:
48  double m_minTrackPt;
49  double m_minTrackP;
54  double m_maxDxy;
58  int m_layer;
60  bool m_doDT;
61  bool m_doCSC;
62 
64 
65  // DT [wheel][station][sector]
68 
69  // CSC [endcap*station][ring][chamber]
72 
75 };
76 
78  : AlignmentMonitorBase(cfg, "AlignmentMonitorMuonVsCurvature"),
79  m_muonCollectionTag(cfg.getParameter<edm::InputTag>("muonCollectionTag")),
80  m_minTrackPt(cfg.getParameter<double>("minTrackPt")),
81  m_minTrackP(cfg.getParameter<double>("minTrackP")),
82  m_minTrackerHits(cfg.getParameter<int>("minTrackerHits")),
83  m_maxTrackerRedChi2(cfg.getParameter<double>("maxTrackerRedChi2")),
84  m_allowTIDTEC(cfg.getParameter<bool>("allowTIDTEC")),
85  m_minNCrossedChambers(cfg.getParameter<int>("minNCrossedChambers")),
86  m_maxDxy(cfg.getParameter<double>("maxDxy")),
87  m_minDT13Hits(cfg.getParameter<int>("minDT13Hits")),
88  m_minDT2Hits(cfg.getParameter<int>("minDT2Hits")),
89  m_minCSCHits(cfg.getParameter<int>("minCSCHits")),
90  m_layer(cfg.getParameter<int>("layer")),
91  m_propagator(cfg.getParameter<std::string>("propagator")),
92  m_doDT(cfg.getParameter<bool>("doDT")),
93  m_doCSC(cfg.getParameter<bool>("doCSC")) {}
94 
96  // DT
97  std::string wheelname[5] = {"wheelm2_", "wheelm1_", "wheelz_", "wheelp1_", "wheelp2_"};
98  if (m_doDT)
99  for (int wheel = -2; wheel <= 2; wheel++)
100  for (int station = 1; station <= 4; station++)
101  for (int sector = 1; sector <= 14; sector++) {
102  if (station != 4 && sector > 12)
103  continue;
104 
105  char stationname[20];
106  sprintf(stationname, "st%d_", station);
107 
108  char sectorname[20];
109  sprintf(sectorname, "sector%02d_", sector);
110 
111  for (int component = 0; component < kNumComponents; component++) {
112  std::stringstream th2f_name, tprofile_name;
113  th2f_name << "th2f_" << wheelname[wheel + 2] << stationname << sectorname;
114  tprofile_name << "tprofile_" << wheelname[wheel + 2] << stationname << sectorname;
115 
116  double yminmax = 50., xminmax = 0.05;
117  if (m_minTrackPt > 0.)
118  xminmax = 1. / m_minTrackPt;
119  int ynbins = 50;
120  if (component == kDeltaX) {
121  th2f_name << "deltax";
122  tprofile_name << "deltax";
123  } else if (component == kDeltaDxDz) {
124  th2f_name << "deltadxdz";
125  tprofile_name << "deltadxdz";
126  }
127 
128  th2f_wheel_st_sector[wheel + 2][station - 1][sector - 1][component] =
129  book2D("/iterN/", th2f_name.str(), "", 30, -xminmax, xminmax, ynbins, -yminmax, yminmax);
130  tprofile_wheel_st_sector[wheel + 2][station - 1][sector - 1][component] =
131  bookProfile("/iterN/", tprofile_name.str(), "", 30, -xminmax, xminmax);
132  }
133  }
134 
135  // CSC
136  std::string stname[8] = {"Ep_S1_", "Ep_S2_", "Ep_S3_", "Ep_S4_", "Em_S1_", "Em_S2_", "Em_S3_", "Em_S4_"};
137  if (m_doCSC)
138  for (int station = 0; station < 8; station++)
139  for (int ring = 1; ring <= 3; ring++)
140  for (int chamber = 1; chamber <= 36; chamber++) {
141  int st = station % 4 + 1;
142  if (st > 1 && ring > 2)
143  continue; // only station 1 has more then 2 rings
144  if (st > 1 && ring == 1 && chamber > 18)
145  continue; // ring 1 stations 1,2,3 have 18 chambers
146 
147  char ringname[20];
148  sprintf(ringname, "R%d_", ring);
149 
150  char chname[20];
151  sprintf(chname, "C%02d_", chamber);
152 
153  for (int component = 0; component < kNumComponents; component++) {
154  std::stringstream componentname;
155  double yminmax = 50., xminmax = 0.05;
156  if (m_minTrackPt > 0.)
157  xminmax = 1. / m_minTrackPt;
158  if (ring == 1)
159  xminmax *= 0.5;
160  if (component == kDeltaX) {
161  componentname << "deltax";
162  } else if (component == kDeltaDxDz) {
163  componentname << "deltadxdz";
164  }
165 
166  std::stringstream th2f_name, tprofile_name;
167  th2f_name << "th2f_" << stname[station] << ringname << chname << componentname.str();
168  tprofile_name << "tprofile_" << stname[station] << ringname << chname << componentname.str();
169 
170  th2f_st_ring_chamber[station][ring - 1][chamber - 1][component] =
171  book2D("/iterN/", th2f_name.str(), "", 30, -xminmax, xminmax, 100, -yminmax, yminmax);
172  tprofile_st_ring_chamber[station][ring - 1][chamber - 1][component] =
173  bookProfile("/iterN/", tprofile_name.str(), "", 30, -xminmax, xminmax);
174  }
175  }
176 
177  th1f_trackerRedChi2 = book1D("/iterN/", "trackerRedChi2", "Refit tracker reduced chi^2", 100, 0., 30.);
179  book1D("/iterN/", "trackerRedChi2Diff", "Fit-minus-refit tracker reduced chi^2", 100, -5., 5.);
180 }
181 
183  const edm::EventSetup &iSetup,
184  const ConstTrajTrackPairCollection &trajtracks) {
186  iSetup.get<GlobalTrackingGeometryRecord>().get(globalGeometry);
187 
189  iEvent.getByLabel(m_beamSpotTag, beamSpot);
190 
191  edm::ESHandle<DetIdAssociator> muonDetIdAssociator_;
192  iSetup.get<DetIdAssociatorRecord>().get("MuonDetIdAssociator", muonDetIdAssociator_);
193 
195  iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAny", prop);
196 
199 
200  if (m_muonCollectionTag.label().empty()) // use trajectories
201  {
202  for (ConstTrajTrackPairCollection::const_iterator trajtrack = trajtracks.begin(); trajtrack != trajtracks.end();
203  ++trajtrack) {
204  const Trajectory *traj = (*trajtrack).first;
205  const reco::Track *track = (*trajtrack).second;
206 
207  if (track->pt() > m_minTrackPt && track->p() > m_minTrackP && fabs(track->dxy(beamSpot->position())) < m_maxDxy) {
208  MuonResidualsFromTrack muonResidualsFromTrack(
209  iSetup, magneticField, globalGeometry, muonDetIdAssociator_, prop, traj, track, pNavigator(), 1000.);
210  processMuonResidualsFromTrack(muonResidualsFromTrack, traj);
211  } // end if track pT is within range
212  } // end loop over tracks
213  } else {
215  iEvent.getByLabel(m_muonCollectionTag, muons);
216 
217  for (reco::MuonCollection::const_iterator muon = muons->begin(); muon != muons->end(); ++muon) {
218  if (!(muon->isTrackerMuon() && muon->innerTrack().isNonnull()))
219  continue;
220 
221  if (m_minTrackPt < muon->pt() && m_minTrackP < muon->p() &&
222  fabs(muon->innerTrack()->dxy(beamSpot->position())) < m_maxDxy) {
223  MuonResidualsFromTrack muonResidualsFromTrack(globalGeometry, &(*muon), pNavigator(), 100.);
224  processMuonResidualsFromTrack(muonResidualsFromTrack);
225  }
226  }
227  }
228 }
229 
231  const Trajectory *traj) {
232  if (mrft.trackerNumHits() < m_minTrackerHits)
233  return;
234  if (!m_allowTIDTEC && mrft.contains_TIDTEC())
235  return;
236 
237  int nMuChambers = 0;
238  std::vector<DetId> chamberIds = mrft.chamberIds();
239  for (unsigned ch = 0; ch < chamberIds.size(); ch++)
240  if (chamberIds[ch].det() == DetId::Muon)
241  nMuChambers++;
242  if (nMuChambers < m_minNCrossedChambers)
243  return;
244 
245  th1f_trackerRedChi2->Fill(mrft.trackerRedChi2());
247 
248  if (mrft.normalizedChi2() > m_maxTrackerRedChi2)
249  return;
250 
251  double qoverpt = mrft.getTrack()->charge() / mrft.getTrack()->pt();
252  double qoverpz = 0.;
253  if (fabs(mrft.getTrack()->pz()) > 0.01)
254  qoverpz = mrft.getTrack()->charge() / fabs(mrft.getTrack()->pz());
255 
256  for (std::vector<DetId>::const_iterator chamberId = chamberIds.begin(); chamberId != chamberIds.end(); ++chamberId) {
257  if (chamberId->det() != DetId::Muon)
258  continue;
259 
260  if (m_doDT && chamberId->subdetId() == MuonSubdetId::DT) {
261  DTChamberId dtid(chamberId->rawId());
263 
264  if (dt13 != nullptr && dt13->numHits() >= m_minDT13Hits) {
265  int wheel = dtid.wheel() + 2;
266  int station = dtid.station() - 1;
267  int sector = dtid.sector() - 1;
268 
269  double resid_x = 10. * dt13->global_residual();
270  double resid_dxdz = 1000. * dt13->global_resslope();
271 
272  if (fabs(resid_x) < 100. && fabs(resid_dxdz) < 100.) {
273  th2f_wheel_st_sector[wheel][station][sector][kDeltaX]->Fill(qoverpt, resid_x);
274  tprofile_wheel_st_sector[wheel][station][sector][kDeltaX]->Fill(qoverpt, resid_x);
275  th2f_wheel_st_sector[wheel][station][sector][kDeltaDxDz]->Fill(qoverpt, resid_dxdz);
276  tprofile_wheel_st_sector[wheel][station][sector][kDeltaDxDz]->Fill(qoverpt, resid_dxdz);
277  }
278  } // if it's a good segment
279  } // if DT
280 
281  if (m_doCSC && chamberId->subdetId() == MuonSubdetId::CSC) {
282  CSCDetId cscid(chamberId->rawId());
284 
285  if (csc != nullptr && csc->numHits() >= m_minCSCHits) {
286  int station = 4 * cscid.endcap() + cscid.station() - 5;
287  int ring = cscid.ring() - 1;
288  if (cscid.station() == 1 && cscid.ring() == 4)
289  ring = 0; // join ME1/a to ME1/b
290  int chamber = cscid.chamber() - 1;
291 
292  double resid_x = 10. * csc->global_residual();
293  double resid_dxdz = 1000. * csc->global_resslope();
294 
295  if (fabs(resid_x) < 100. && fabs(resid_dxdz) < 100.) {
296  th2f_st_ring_chamber[station][ring][chamber][kDeltaX]->Fill(qoverpz, resid_x);
297  tprofile_st_ring_chamber[station][ring][chamber][kDeltaX]->Fill(qoverpz, resid_x);
298  th2f_st_ring_chamber[station][ring][chamber][kDeltaDxDz]->Fill(qoverpz, resid_dxdz);
299  tprofile_st_ring_chamber[station][ring][chamber][kDeltaDxDz]->Fill(qoverpz, resid_dxdz);
300  }
301  } // if it's a good segment
302  } // if CSC
303 
304  } // end loop over chamberIds
305 }
306 
Propagator.h
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
MuonResidualsFromTrack::trackerRedChi2
double trackerRedChi2() const
Definition: MuonResidualsFromTrack.cc:722
MuonSubdetId::CSC
static constexpr int CSC
Definition: MuonSubdetId.h:12
electrons_cff.bool
bool
Definition: electrons_cff.py:393
AlignmentMonitorMuonVsCurvature::m_minDT2Hits
int m_minDT2Hits
Definition: AlignmentMonitorMuonVsCurvature.cc:56
AlignmentMonitorMuonVsCurvature::tprofile_wheel_st_sector
TProfile * tprofile_wheel_st_sector[5][4][14][kNumComponents]
Definition: AlignmentMonitorMuonVsCurvature.cc:67
pwdgSkimBPark_cfi.beamSpot
beamSpot
Definition: pwdgSkimBPark_cfi.py:5
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11779
MessageLogger.h
AlignmentMonitorMuonVsCurvature::th1f_trackerRedChi2Diff
TH1F * th1f_trackerRedChi2Diff
Definition: AlignmentMonitorMuonVsCurvature.cc:74
AlignmentMonitorMuonVsCurvature::~AlignmentMonitorMuonVsCurvature
~AlignmentMonitorMuonVsCurvature() override
Definition: AlignmentMonitorMuonVsCurvature.cc:37
AlignmentMonitorMuonVsCurvature::m_doDT
bool m_doDT
Definition: AlignmentMonitorMuonVsCurvature.cc:60
muon
Definition: MuonCocktails.h:17
AlignmentMonitorMuonVsCurvature::AlignmentMonitorMuonVsCurvature
AlignmentMonitorMuonVsCurvature(const edm::ParameterSet &cfg)
Definition: AlignmentMonitorMuonVsCurvature.cc:77
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
relativeConstraints.station
station
Definition: relativeConstraints.py:67
edm
HLT enums.
Definition: AlignableModifier.h:19
AlignmentMonitorMuonVsCurvature::m_minDT13Hits
int m_minDT13Hits
Definition: AlignmentMonitorMuonVsCurvature.cc:55
AlignmentMonitorMuonVsCurvature::th2f_st_ring_chamber
TH2F * th2f_st_ring_chamber[8][3][36][kNumComponents]
Definition: AlignmentMonitorMuonVsCurvature.cc:70
AlignmentMonitorMuonVsCurvature::m_doCSC
bool m_doCSC
Definition: AlignmentMonitorMuonVsCurvature.cc:61
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
MuonResidualsFromTrack::chamberResidual
MuonChamberResidual * chamberResidual(DetId chamberId, int type)
Definition: MuonResidualsFromTrack.cc:735
MuonResidualsFromTrack::trackerNumHits
int trackerNumHits() const
Definition: MuonResidualsFromTrack.h:78
AlignmentMonitorMuonVsCurvature::m_layer
int m_layer
Definition: AlignmentMonitorMuonVsCurvature.cc:58
GlobalTrackingGeometryRecord
Definition: GlobalTrackingGeometryRecord.h:17
AlignmentMonitorMuonVsCurvature::th2f_wheel_st_sector
TH2F * th2f_wheel_st_sector[5][4][14][kNumComponents]
Definition: AlignmentMonitorMuonVsCurvature.cc:66
AlignmentMonitorPluginFactory
AlignmentMonitorMuonVsCurvature::book
void book() override
Book or retrieve histograms; MUST be reimplemented.
Definition: AlignmentMonitorMuonVsCurvature.cc:95
HLT_FULL_cff.magneticField
magneticField
Definition: HLT_FULL_cff.py:348
edm::Handle< reco::BeamSpot >
AlignmentMonitorBase::book2D
TH2F * book2D(std::string dir, std::string name, std::string title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Definition: AlignmentMonitorBase.cc:129
AlignmentMonitorBase::pNavigator
AlignableNavigator * pNavigator()
Definition: AlignmentMonitorBase.h:114
reco::TrackBase::pt
double pt() const
track transverse momentum
Definition: TrackBase.h:637
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
edm::InputTag::label
std::string const & label() const
Definition: InputTag.h:36
csc
Definition: L1Track.h:19
AlignmentMonitorMuonVsCurvature::m_propagator
std::string m_propagator
Definition: AlignmentMonitorMuonVsCurvature.cc:59
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
HLT_FULL_cff.muon
muon
Definition: HLT_FULL_cff.py:11776
AlignmentMonitorMuonVsCurvature::event
void event(const edm::Event &iEvent, const edm::EventSetup &iSetup, const ConstTrajTrackPairCollection &iTrajTracks) override
Called for each event (by "run()"): may be reimplemented.
Definition: AlignmentMonitorMuonVsCurvature.cc:182
AlignmentMonitorMuonVsCurvature::m_maxTrackerRedChi2
double m_maxTrackerRedChi2
Definition: AlignmentMonitorMuonVsCurvature.cc:51
AlignmentMonitorMuonVsCurvature::th1f_trackerRedChi2
TH1F * th1f_trackerRedChi2
Definition: AlignmentMonitorMuonVsCurvature.cc:73
reco::Track
Definition: Track.h:27
IdealMagneticFieldRecord.h
MuonResidualsFromTrack
Definition: MuonResidualsFromTrack.h:52
edm::ESHandle< GlobalTrackingGeometry >
MuonResidualsFromTrack::getTrack
const reco::Track * getTrack()
Definition: MuonResidualsFromTrack.h:75
AlignmentMonitorMuonVsCurvature::m_muonCollectionTag
edm::InputTag m_muonCollectionTag
Definition: AlignmentMonitorMuonVsCurvature.cc:47
MuonResidualsFromTrack::chamberIds
const std::vector< DetId > chamberIds() const
Definition: MuonResidualsFromTrack.h:86
reco::TrackBase::charge
int charge() const
track electric charge
Definition: TrackBase.h:596
MuonSubdetId::DT
static constexpr int DT
Definition: MuonSubdetId.h:11
MuonResidualsFromTrack::normalizedChi2
double normalizedChi2() const
Definition: MuonResidualsFromTrack.cc:729
DEFINE_EDM_PLUGIN
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: PluginFactory.h:124
AlignmentMonitorPluginFactory.h
GlobalTrackingGeometryRecord.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
AlignmentMonitorMuonVsCurvature::processMuonResidualsFromTrack
void processMuonResidualsFromTrack(MuonResidualsFromTrack &mrft, const Trajectory *traj=nullptr)
Definition: AlignmentMonitorMuonVsCurvature.cc:230
AlignmentMonitorMuonVsCurvature
Definition: AlignmentMonitorMuonVsCurvature.cc:34
edm::ParameterSet
Definition: ParameterSet.h:47
AlignmentMonitorBase::bookProfile
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")
Definition: AlignmentMonitorBase.cc:112
AlignmentMonitorMuonVsCurvature::kDeltaX
Definition: AlignmentMonitorMuonVsCurvature.cc:63
AlignmentMonitorBase.h
CSCDetId
Definition: CSCDetId.h:26
AlignmentMonitorBase
Definition: AlignmentMonitorBase.h:42
makeMuonMisalignmentScenario.wheel
wheel
Definition: makeMuonMisalignmentScenario.py:319
createfilelist.int
int
Definition: createfilelist.py:10
MuonChamberResidual
Definition: MuonChamberResidual.h:26
iEvent
int iEvent
Definition: GenABIO.cc:224
MuonResidualsFromTrack::contains_TIDTEC
bool contains_TIDTEC() const
Definition: MuonResidualsFromTrack.h:84
AlignmentMonitorBase::m_beamSpotTag
const edm::InputTag m_beamSpotTag
Definition: AlignmentMonitorBase.h:116
DetIdAssociatorRecord.h
MagneticField.h
edm::EventSetup
Definition: EventSetup.h:57
MuonChamberResidual::kCSC
Definition: MuonChamberResidual.h:28
reco::TrackBase::normalizedChi2
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
MuonResidualsFromTrack.h
get
#define get
DetIdAssociatorRecord
Definition: DetIdAssociatorRecord.h:13
InputTag.h
looper.cfg
cfg
Definition: looper.py:297
AlignmentMonitorBase::book1D
TH1F * book1D(std::string dir, std::string name, std::string title, int nchX, double lowX, double highX)
Definition: AlignmentMonitorBase.cc:107
AlignmentMonitorMuonVsCurvature::m_minCSCHits
int m_minCSCHits
Definition: AlignmentMonitorMuonVsCurvature.cc:57
AlignmentMonitorMuonVsCurvature::m_minTrackerHits
int m_minTrackerHits
Definition: AlignmentMonitorMuonVsCurvature.cc:50
std
Definition: JetResolutionObject.h:76
AlignmentMonitorMuonVsCurvature::tprofile_st_ring_chamber
TProfile * tprofile_st_ring_chamber[8][3][36][kNumComponents]
Definition: AlignmentMonitorMuonVsCurvature.cc:71
Trajectory
Definition: Trajectory.h:38
DetIdAssociator.h
TrackingComponentsRecord.h
AlignmentMonitorMuonVsCurvature::kNumComponents
Definition: AlignmentMonitorMuonVsCurvature.cc:63
relativeConstraints.ring
ring
Definition: relativeConstraints.py:68
relativeConstraints.chamber
chamber
Definition: relativeConstraints.py:53
EventSetup.h
AlignmentMonitorMuonVsCurvature::m_allowTIDTEC
bool m_allowTIDTEC
Definition: AlignmentMonitorMuonVsCurvature.cc:52
AlignmentMonitorMuonVsCurvature::m_minTrackP
double m_minTrackP
Definition: AlignmentMonitorMuonVsCurvature.cc:49
AlignmentMonitorMuonVsCurvature::kDeltaDxDz
Definition: AlignmentMonitorMuonVsCurvature.cc:63
reco::TrackBase::pz
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:646
AlignmentMonitorBase::ConstTrajTrackPairCollection
std::vector< ConstTrajTrackPair > ConstTrajTrackPairCollection
Definition: AlignmentMonitorBase.h:45
DetId::Muon
Definition: DetId.h:26
DTChamberId
Definition: DTChamberId.h:14
ParameterSet.h
GlobalTrackingGeometry.h
MuonChamberResidual::kDT13
Definition: MuonChamberResidual.h:28
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
AlignmentMonitorMuonVsCurvature::m_maxDxy
double m_maxDxy
Definition: AlignmentMonitorMuonVsCurvature.cc:54
AlignmentMonitorMuonVsCurvature::m_minTrackPt
double m_minTrackPt
Definition: AlignmentMonitorMuonVsCurvature.cc:48
AlignmentMonitorMuonVsCurvature::m_minNCrossedChambers
bool m_minNCrossedChambers
Definition: AlignmentMonitorMuonVsCurvature.cc:53
TrackingComponentsRecord
Definition: TrackingComponentsRecord.h:12