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