CMS 3D CMS Logo

MonitorTrackResiduals.cc
Go to the documentation of this file.
13 
14 template <TrackerType pixel_or_strip>
16  : conf_(iConfig),
17  tkDetMapToken_{esConsumes<TkDetMap, TrackerTopologyRcd, edm::Transition::BeginRun>()},
18  trackerTopologyRunToken_{esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>()},
19  trackerGeometryToken_{esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>()},
20  trackerTopologyEventToken_{esConsumes<TrackerTopology, TrackerTopologyRcd>()},
21  m_cacheID_(0),
22  genTriggerEventFlag_(new GenericTriggerEventFlag(
23  iConfig.getParameter<edm::ParameterSet>("genericTriggerEventPSet"), consumesCollector(), *this)),
24  avalidator_(iConfig, consumesCollector()) {
25  ModOn = conf_.getParameter<bool>("Mod_On");
26  offlinePrimaryVerticesToken_ = consumes<reco::VertexCollection>(std::string("offlinePrimaryVertices"));
27 }
28 
29 template <TrackerType pixel_or_strip>
31  if (genTriggerEventFlag_)
32  delete genTriggerEventFlag_;
33 }
34 
35 template <TrackerType pixel_or_strip>
37  const edm::Run &run,
38  const edm::EventSetup &iSetup) {
39  unsigned long long cacheID = iSetup.get<TrackerDigiGeometryRecord>().cacheIdentifier();
40  if (m_cacheID_ != cacheID) {
41  m_cacheID_ = cacheID;
42  this->createMEs(ibooker, iSetup);
43  }
44  std::string topFolderName_ = "SiStrip";
45  SiStripFolderOrganizer folder_organizer;
46  folder_organizer.setSiStripFolderName(topFolderName_);
47  const TkDetMap *tkDetMap = &iSetup.getData(tkDetMapToken_);
48  tkhisto_ResidualsMean =
49  std::make_unique<TkHistoMap>(tkDetMap, ibooker, topFolderName_, "TkHMap_ResidualsMean", 0.0, true);
50 }
51 
52 template <TrackerType pixel_or_strip>
54  // Initialize the GenericTriggerEventFlag
55  if (genTriggerEventFlag_->on())
56  genTriggerEventFlag_->initRun(run, iSetup);
57 }
58 
59 template <TrackerType pixel_or_strip>
61  uint32_t ModuleID, const TrackerTopology *tTopo) {
62  std::string subdet = "";
63  int32_t layer = 0;
64  auto id = DetId(ModuleID);
65  switch (id.subdetId()) {
66  // Pixel Barrel, Endcap
67  case 1:
68  subdet = "BPIX";
69  layer = tTopo->pxbLayer(id);
70  break;
71  case 2:
72  subdet = "FPIX";
73  layer = tTopo->pxfDisk(id) * (tTopo->pxfSide(ModuleID) == 1 ? -1 : +1);
74  break;
75  // Strip TIB, TID, TOB, TEC
76  case 3:
77  subdet = "TIB";
78  layer = tTopo->tibLayer(id);
79  break;
80  case 4:
81  subdet = "TID";
82  layer = tTopo->tidWheel(id) * (tTopo->tidSide(ModuleID) == 1 ? -1 : +1);
83  break;
84  case 5:
85  subdet = "TOB";
86  layer = tTopo->tobLayer(id);
87  break;
88  case 6:
89  subdet = "TEC";
90  layer = tTopo->tecWheel(id) * (tTopo->tecSide(ModuleID) == 1 ? -1 : +1);
91  break;
92  default:
93  // TODO: Fail loudly.
94  subdet = "UNKNOWN";
95  layer = 0;
96  }
97  return std::make_pair(subdet, layer);
98 }
99 
100 template <TrackerType pixel_or_strip>
102  // Retrieve tracker topology and geometry
103  const TrackerTopology *const tTopo = &iSetup.getData(trackerTopologyRunToken_);
104  const TrackerGeometry *TG = &iSetup.getData(trackerGeometryToken_);
105 
106  Parameters = conf_.getParameter<edm::ParameterSet>("TH1ResModules");
107  int32_t i_residuals_Nbins = Parameters.getParameter<int32_t>("Nbinx");
108  double d_residual_xmin = Parameters.getParameter<double>("xmin");
109  double d_residual_xmax = Parameters.getParameter<double>("xmax");
110  Parameters = conf_.getParameter<edm::ParameterSet>("TH1NormResModules");
111  int32_t i_normres_Nbins = Parameters.getParameter<int32_t>("Nbinx");
112  double d_normres_xmin = Parameters.getParameter<double>("xmin");
113  double d_normres_xmax = Parameters.getParameter<double>("xmax");
114 
115  // use SistripHistoId for producing histogram id (and title)
116  SiStripHistoId hidmanager;
117 
118  SiStripFolderOrganizer strip_organizer;
119  auto pixel_organizer = SiPixelFolderOrganizer(false);
120 
121  // Collect list of modules from Tracker Geometry
122  // book histo per each detector module
123  auto ids = TG->detIds(); // or detUnitIds?
124  for (DetId id : ids) {
125  auto ModuleID = id.rawId();
126  auto isPixel = id.subdetId() == 1 || id.subdetId() == 2;
127  if (isPixel != (pixel_or_strip == TRACKERTYPE_PIXEL))
128  continue;
129 
130  // Book module histogramms?
131  if (ModOn) {
132  switch (id.subdetId()) {
133  case 1:
134  pixel_organizer.setModuleFolder(ibooker, ModuleID, 0);
135  break;
136  case 2:
137  pixel_organizer.setModuleFolder(ibooker, ModuleID, 0);
138  break;
139  default:
140  strip_organizer.setDetectorFolder(ModuleID, tTopo);
141  }
142  {
143  // this sounds strip specific but also works for pixel
144  std::string hid = hidmanager.createHistoId("HitResidualsX", "det", ModuleID);
145  std::string normhid = hidmanager.createHistoId("NormalizedHitResidualsX", "det", ModuleID);
146  auto &histos = m_ModuleResiduals[std::make_pair("", ModuleID)];
147  histos.x.base = ibooker.book1D(hid, hid, i_residuals_Nbins, d_residual_xmin, d_residual_xmax);
148  histos.x.base->setAxisTitle("(x_{pred} - x_{rec})' [cm]");
149  histos.x.normed = ibooker.book1D(normhid, normhid, i_normres_Nbins, d_normres_xmin, d_normres_xmax);
150  histos.x.normed->setAxisTitle("(x_{pred} - x_{rec})'/#sigma");
151  }
152  {
153  std::string hid = hidmanager.createHistoId("HitResidualsY", "det", ModuleID);
154  std::string normhid = hidmanager.createHistoId("NormalizedHitResidualsY", "det", ModuleID);
155  auto &histos = m_ModuleResiduals[std::make_pair("", ModuleID)];
156  histos.y.base = ibooker.book1D(hid, hid, i_residuals_Nbins, d_residual_xmin, d_residual_xmax);
157  histos.y.base->setAxisTitle("(y_{pred} - y_{rec})' [cm]");
158  histos.y.normed = ibooker.book1D(normhid, normhid, i_normres_Nbins, d_normres_xmin, d_normres_xmax);
159  histos.y.normed->setAxisTitle("(y_{pred} - y_{rec})'/#sigma");
160  }
161  }
162 
163  auto subdetandlayer = findSubdetAndLayer(ModuleID, tTopo);
164  if (m_SubdetLayerResiduals.find(subdetandlayer) == m_SubdetLayerResiduals.end()) {
165  // add new histograms
166  auto &histos = m_SubdetLayerResiduals[subdetandlayer];
167  switch (id.subdetId()) {
168  // Pixel Barrel, Endcap
169  // We can't use the folder organizer here (SiPixelActionExecutor.cc#1638
170  // does the same)
171  case 1:
172  ibooker.setCurrentFolder("Pixel/Barrel");
173  break;
174  case 2:
175  ibooker.setCurrentFolder("Pixel/Endcap");
176  break;
177  // All strip
178  default:
179  strip_organizer.setLayerFolder(ModuleID, tTopo, subdetandlayer.second);
180  }
181 
182  auto isBarrel = subdetandlayer.first.find("B") != std::string::npos;
183 
184  auto xy = std::vector<std::pair<HistoPair &, const char *>>{std::make_pair(std::ref(histos.x), "X"),
185  std::make_pair(std::ref(histos.y), "Y")};
186  for (auto &histopair : xy) {
187  // book histogramms on layer level, check for barrel/pixel only for
188  // correct labeling
189 
190  // Skip the Y plots for strips.
191  if (!isPixel && histopair.second[0] == 'Y')
192  continue;
193 
194  std::string histoname = isPixel ? ( // Pixel name
195  Form("HitResiduals%s_%s%d",
196  histopair.second,
197  isBarrel ? "L" : (subdetandlayer.second > 0 ? "Dp" : "Dm"),
198  std::abs(subdetandlayer.second)))
199  : (Form("HitResiduals_%s__%s__%d", // Strip TODO: We use a
200  // legacy name.
201  subdetandlayer.first.c_str(),
202  isBarrel ? "Layer" : "wheel",
203  std::abs(subdetandlayer.second)));
204 
205  std::string histotitle = Form("HitResiduals %s on %s%s full %s %d",
206  histopair.second,
207  subdetandlayer.first.c_str(),
208  isBarrel ? "" : (subdetandlayer.second > 0 ? "+" : "-"),
209  isBarrel ? "Layer" : (isPixel ? "Disk" : "Wheel"),
210  std::abs(subdetandlayer.second));
211 
212  std::string normhistoname = Form("Normalized%s", histoname.c_str());
213  std::string normhistotitle = Form("Normalized%s", histotitle.c_str());
214 
215  // std::cout << "##### Booking: " << ibooker.pwd() << " title " <<
216  // histoname << std::endl;
217 
218  histopair.first.base =
219  ibooker.book1D(histoname.c_str(), histotitle.c_str(), i_residuals_Nbins, d_residual_xmin, d_residual_xmax);
220  histopair.first.base->setAxisTitle("(x_{pred} - x_{rec})' [cm]");
221 
222  histopair.first.normed = ibooker.book1D(
223  normhistoname.c_str(), normhistotitle.c_str(), i_normres_Nbins, d_normres_xmin, d_normres_xmax);
224  histopair.first.normed->setAxisTitle("(x_{pred} - x_{rec})'/#sigma");
225  }
226  }
227  } // end loop over activeDets
228 }
229 
230 template <TrackerType pixel_or_strip>
232  auto vtracks = std::vector<TrackerValidationVariables::AVTrackStruct>();
233  // Filter out events if Trigger Filtering is requested
234  if (genTriggerEventFlag_->on() && !genTriggerEventFlag_->accept(iEvent, iSetup))
235  return;
236 
238  iEvent.getByToken(offlinePrimaryVerticesToken_, vertices);
239  if (!vertices.isValid() || vertices->empty())
240  return;
241  const auto primaryVertex = vertices->at(0);
242 
243  // Retrieve tracker topology from geometry
244  const TrackerTopology *const tTopo = &iSetup.getData(trackerTopologyEventToken_);
245 
246  avalidator_.fillTrackQuantities(
247  iEvent,
248  iSetup,
249  // tell the validator to only look at good tracks
250  [&](const reco::Track &track) -> bool {
251  return track.pt() > 0.75 && abs(track.dxy(primaryVertex.position())) < 5 * track.dxyError();
252  },
253  vtracks);
254 
255  for (auto &track : vtracks) {
256  for (auto &it : track.hits) {
257  uint RawId = it.rawDetId;
258 
259  auto id = DetId(RawId);
260  auto isPixel = id.subdetId() == 1 || id.subdetId() == 2;
261  if (isPixel != (pixel_or_strip == TRACKERTYPE_PIXEL))
262  continue;
263 
264  if (ModOn) {
265  auto &mod_histos = m_ModuleResiduals[std::make_pair("", RawId)];
266  mod_histos.x.base->Fill(it.resXprime);
267  mod_histos.x.normed->Fill(it.resXprime / it.resXprimeErr);
268  mod_histos.y.base->Fill(it.resYprime);
269  mod_histos.y.normed->Fill(it.resYprime / it.resYprimeErr);
270  }
271 
272  auto subdetandlayer = findSubdetAndLayer(RawId, tTopo);
273  auto histos = m_SubdetLayerResiduals[subdetandlayer];
274  // fill if its error is not zero
275  if (it.resXprimeErr != 0 && histos.x.base) {
276  histos.x.base->Fill(it.resXprime);
277  histos.x.normed->Fill(it.resXprime / it.resXprimeErr);
278  if (!isPixel)
279  tkhisto_ResidualsMean->fill(RawId, it.resXprime);
280  }
281  if (it.resYprimeErr != 0 && histos.y.base) {
282  histos.y.base->Fill(it.resYprime);
283  histos.y.normed->Fill(it.resYprime / it.resYprimeErr);
284  }
285  }
286  }
287 }
288 
MonitorTrackResidualsBase::findSubdetAndLayer
std::pair< std::string, int32_t > findSubdetAndLayer(uint32_t ModuleID, const TrackerTopology *tTopo)
Definition: MonitorTrackResiduals.cc:60
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
MonitorTrackResidualsBase::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: MonitorTrackResiduals.cc:36
SiStripFolderOrganizer.h
SiStripHistoId.h
TrackerTopology::pxfSide
unsigned int pxfSide(const DetId &id) const
Definition: TrackerTopology.h:192
edm::Run
Definition: Run.h:45
MonitorTrackResidualsBase::dqmBeginRun
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
Definition: MonitorTrackResiduals.cc:53
TrackerTopology
Definition: TrackerTopology.h:16
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
MonitorTrackResiduals
DQMStore.h
edm::Handle< reco::VertexCollection >
parallelization.uint
uint
Definition: parallelization.py:124
TrackerTopology::tidWheel
unsigned int tidWheel(const DetId &id) const
Definition: TrackerTopology.h:201
TrackerTopology::pxbLayer
unsigned int pxbLayer(const DetId &id) const
Definition: TrackerTopology.h:144
MonitorTrackResidualsBase::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: MonitorTrackResiduals.cc:231
BeamMonitor_cff.primaryVertex
primaryVertex
hltOfflineBeamSpot for HLTMON
Definition: BeamMonitor_cff.py:7
DetId
Definition: DetId.h:17
Track.h
MonitorTrackResidualsBase
Definition: MonitorTrackResiduals.h:45
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MonitorTrackResidualsBase::MonitorTrackResidualsBase
MonitorTrackResidualsBase(const edm::ParameterSet &)
Definition: MonitorTrackResiduals.cc:15
Service.h
GenericTriggerEventFlag.h
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
MonitorTrackResiduals.h
reco::Track
Definition: Track.h:27
TkDetMap
Definition: TkDetMap.h:175
Transition.h
geometryCSVtoXML.xy
xy
Definition: geometryCSVtoXML.py:19
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
PixelPluginsPhase0_cfi.isBarrel
isBarrel
Definition: PixelPluginsPhase0_cfi.py:17
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
fastTrackerRecHitType::isPixel
bool isPixel(HitType hitType)
Definition: FastTrackerRecHit.h:37
GenericTriggerEventFlag
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
Definition: GenericTriggerEventFlag.h:42
TrackerTopology::tidSide
unsigned int tidSide(const DetId &id) const
Definition: TrackerTopology.h:190
iEvent
int iEvent
Definition: GenABIO.cc:224
SiStripFolderOrganizer::setSiStripFolderName
void setSiStripFolderName(std::string name)
Definition: SiStripFolderOrganizer.cc:41
TrackerTopology::pxfDisk
unsigned int pxfDisk(const DetId &id) const
Definition: TrackerTopology.h:446
edm::EventSetup
Definition: EventSetup.h:57
SiStripFolderOrganizer::setDetectorFolder
void setDetectorFolder(uint32_t rawdetid, const TrackerTopology *tTopo)
Definition: SiStripFolderOrganizer.cc:202
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:120
combine.histos
histos
Definition: combine.py:4
SiStripHistoId
Definition: SiStripHistoId.h:25
TrackerTopology::tobLayer
unsigned int tobLayer(const DetId &id) const
Definition: TrackerTopology.h:147
writedatasetfile.run
run
Definition: writedatasetfile.py:27
MonitorTrackResidualsBase::createMEs
void createMEs(DQMStore::IBooker &, const edm::EventSetup &)
Definition: MonitorTrackResiduals.cc:101
MonitorTrackResidualsBase::~MonitorTrackResidualsBase
~MonitorTrackResidualsBase() override
Definition: MonitorTrackResiduals.cc:30
DetId.h
SiStripFolderOrganizer::setLayerFolder
void setLayerFolder(uint32_t rawdetid, const TrackerTopology *tTopo, int32_t layer=0, bool ring_flag=false)
Definition: SiStripFolderOrganizer.cc:304
SiStripFolderOrganizer
Definition: SiStripFolderOrganizer.h:27
SiPixelFolderOrganizer
Definition: SiPixelFolderOrganizer.h:26
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
TrackerGeometry::detIds
const DetIdContainer & detIds() const override
Returm a vector of all GeomDet DetIds (including those of GeomDetUnits)
Definition: TrackerGeometry.h:64
dqm::implementation::IBooker
Definition: DQMStore.h:43
TRACKERTYPE_PIXEL
Definition: MonitorTrackResiduals.h:42
SiPixelFolderOrganizer.h
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::Event
Definition: Event.h:73
Parameters
vector< ParameterSet > Parameters
Definition: HLTMuonPlotter.cc:25
TrackerTopology::tecWheel
unsigned int tecWheel(const DetId &id) const
Definition: TrackerTopology.h:198
dqm::impl::MonitorElement::setAxisTitle
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
Definition: MonitorElement.cc:800
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
pwdgSkimBPark_cfi.vertices
vertices
Definition: pwdgSkimBPark_cfi.py:7
TrackerTopology::tibLayer
unsigned int tibLayer(const DetId &id) const
Definition: TrackerTopology.h:150
TrackerGeometry
Definition: TrackerGeometry.h:14
TrackerTopology::tecSide
unsigned int tecSide(const DetId &id) const
Definition: TrackerTopology.h:184