CMS 3D CMS Logo

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