CMS 3D CMS Logo

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