CMS 3D CMS Logo

FWTrackResidualDetailView.cc
Go to the documentation of this file.
1 
2 #include "TVector3.h"
3 #include "TH2.h"
4 #include "TLine.h"
5 #include "TLatex.h"
6 #include "TPaveText.h"
7 #include "TCanvas.h"
8 #include "TEveWindow.h"
9 
13 
20 
21 using reco::HitPattern;
22 using reco::Track;
23 using reco::TrackBase;
25 
26 const char* FWTrackResidualDetailView::m_det_tracker_str[6] = {"PXB", "PXF", "TIB", "TID", "TOB", "TEC"};
27 
29  : m_ndet(0),
30  m_nhits(0),
31  m_resXFill(3007),
32  m_resXCol(kGreen - 9),
33  m_resYFill(3006),
34  m_resYCol(kWhite),
35  m_stereoFill(3004),
36  m_stereoCol(kCyan - 9),
37  m_invalidFill(3001),
38  m_invalidCol(kRed) {
39  memset(m_det, 0, sizeof(m_det));
40  memset(res, 0, sizeof(res));
41  memset(hittype, 0, sizeof(hittype));
42  memset(stereo, 0, sizeof(stereo));
43  memset(substruct, 0, sizeof(substruct));
44  memset(subsubstruct, 0, sizeof(subsubstruct));
45  memset(m_detector, 0, sizeof(m_detector));
46 }
47 
49 
51  auto const& residuals = track->residuals();
52 
53  const FWGeometry* geom = id.item()->getGeom();
54  assert(geom != nullptr);
55 
56  const HitPattern& hitpat = track->hitPattern();
58  for (int i = 0; i < m_nhits; ++i) {
59  //printf("there are %d hits in the pattern, %d in the vector, this is %u\n",
60  // m_nhits, track->recHitsEnd() - track->recHitsBegin(), (*(track->recHitsBegin() + i))->geographicalId().rawId());
62  hittype[i] = HitPattern::getHitType(pattern);
63  stereo[i] = HitPattern::getSide(pattern);
64  subsubstruct[i] = HitPattern::getSubSubStructure(pattern);
65  substruct[i] = HitPattern::getSubStructure(pattern);
66  m_detector[i] = HitPattern::getSubDetector(pattern);
67  if ((*(track->recHitsBegin() + i))->isValid()) {
68  res[0][i] = getSignedResidual(geom, (*(track->recHitsBegin() + i))->geographicalId().rawId(), residuals.pullX(i));
69  } else {
70  res[0][i] = 0;
71  }
72  res[1][i] = residuals.pullY(i);
73  // printf("%s, %i\n",m_det_tracker_str[substruct[i]-1],subsubstruct[i]);
74  }
75 
76  m_det[0] = 0;
77  for (int j = 0; j < m_nhits - 1;) {
78  int k = j + 1;
79  for (; k < m_nhits; k++) {
80  if (substruct[j] == substruct[k] && subsubstruct[j] == subsubstruct[k]) {
81  if (k == (m_nhits - 1))
82  j = k;
83  } else {
84  m_ndet++;
85  j = k;
86  m_det[m_ndet] = j;
87  break;
88  }
89  }
90  }
91  m_ndet++;
92  m_det[m_ndet] = m_nhits;
93  // printDebug();
94 }
95 
97  if (!track->extra().isAvailable()) {
98  fwLog(fwlog::kError) << " no track extra information is available.\n";
99  m_viewCanvas->cd();
100  TLatex* latex = new TLatex();
101  latex->SetTextSize(0.1);
102  latex->DrawLatex(0.1, 0.5, "No track extra information");
103  return;
104  }
105  prepareData(id, track);
106 
107  // draw histogram
108  m_viewCanvas->cd();
109  m_viewCanvas->SetHighLightColor(-1);
110  TH2F* h_res = new TH2F("h_resx", "h_resx", 10, -5.5, 5.5, m_ndet, 0, m_ndet);
111  TPad* padX = new TPad("pad1", "pad1", 0.2, 0., 0.8, 0.99);
112  padX->SetBorderMode(0);
113  padX->SetLeftMargin(0.2);
114  padX->Draw();
115  padX->cd();
116  padX->SetFrameLineWidth(0);
117  padX->Modified();
118  h_res->SetDirectory(nullptr);
119  h_res->SetStats(kFALSE);
120  h_res->SetTitle("");
121  h_res->SetXTitle("residual");
122  h_res->GetXaxis()->SetTickLength(0);
123  h_res->GetYaxis()->SetTickLength(0);
124  h_res->GetXaxis()->SetNdivisions(20);
125  h_res->GetYaxis()->SetLabelSize(0.06);
126  h_res->Draw();
127  padX->SetGridy();
128 
129  float larray[9] = {0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.5, 4.5, 5.5};
130  float larray2[8];
131  for (int l = 0; l < 8; l++) {
132  float diff2 = (larray[l + 1] - larray[l]) / 2;
133  larray2[l] = larray[l] + diff2;
134  // printf("(%.1f,%.1f),",larray[i],larray[i+1]);
135  }
136 
137  int resi[2][64];
138  for (int l = 0; l < m_nhits; l++) {
139  for (int k = 0; k < 8; k++) {
140  if (fabs(res[0][l]) == larray2[k])
141  resi[0][l] = k;
142  if (fabs(res[1][l]) == larray2[k])
143  resi[1][l] = k;
144  }
145  }
146 
147  TLine* lines[17];
148  for (int l = 0; l < 17; l++) {
149  int ix = l % 9;
150  int sign = 1;
151  sign = (l > 8) ? -1 : 1;
152  lines[l] = new TLine(sign * larray[ix], 0, sign * larray[ix], m_ndet);
153  if (l != 9)
154  lines[l]->SetLineStyle(3);
155  padX->cd();
156  lines[l]->Draw();
157  }
158 
159  float width = 0.25;
160  int filltype;
161  Color_t color;
162  Double_t box[4];
163  padX->cd();
164 
165  for (int h = 0; h < 2; h++) {
166  float height1 = 0;
167  for (int j = 0; j < m_ndet; j++) {
168  // take only X res and Y pixel residals
169  if (strcmp(m_det_tracker_str[substruct[m_det[j]] - 1], "PXB") && h)
170  continue;
171 
172  char det_str2[256];
173  snprintf(det_str2, 255, "%s/%i", m_det_tracker_str[substruct[m_det[j]] - 1], subsubstruct[m_det[j]]);
174  h_res->GetYaxis()->SetBinLabel(j + 1, det_str2);
175 
176  int diff = m_det[j + 1] - m_det[j];
177  int k = 0;
178  width = 1.0 / diff;
179 
180  for (int l = m_det[j]; l < (m_det[j] + diff); l++) {
181  // g->SetPoint(l,resx[l],j+0.5);
182  // printf("%i, %f %f %f\n",l,resx[l],sign*larray[resxi[l]],sign*larray[resxi[l]+1]);
183  int sign = (res[h][l] < 0) ? -1 : 1;
184  box[0] = (hittype[l] == 0) ? sign * larray[resi[h][l]] : -5.5;
185  box[2] = (hittype[l] == 0) ? sign * larray[resi[h][l] + 1] : 5.5;
186  box[1] = height1 + width * k;
187  box[3] = height1 + width * (k + 1);
188 
189  if (stereo[l] == 1) {
190  color = m_stereoCol;
191  filltype = m_stereoFill;
192  } else if (hittype[l] != 0) {
193  color = m_invalidCol;
194  filltype = m_invalidFill;
195  } else {
196  filltype = h ? m_resYFill : m_resXFill;
197  color = h ? m_resYCol : m_resXCol;
198  }
199 
200  drawCanvasBox(box, color, filltype, h < 1);
201  k++;
202  }
203  height1 += 1;
204  }
205  }
206 
207  // title
208  const char* res_str = "residuals in Si detector local x-y coord.";
209  TPaveText* pt = new TPaveText(0.0, 0.91, 1, 0.99, "blNDC");
210  pt->SetBorderSize(0);
211  pt->SetFillColor(kWhite);
212  pt->AddText(res_str);
213  pt->Draw();
214 
215  m_viewCanvas->cd();
216  m_viewCanvas->SetEditable(kFALSE);
217 
218  setTextInfo(id, track);
219 }
220 
221 double FWTrackResidualDetailView::getSignedResidual(const FWGeometry* geom, unsigned int id, double resX) {
222  double local1[3] = {0, 0, 0};
223  double local2[3] = {resX, 0, 0};
224  double global1[3], global2[3];
225  const TGeoMatrix* m = geom->getMatrix(id);
226  assert(m != nullptr);
227  m->LocalToMaster(local1, global1);
228  m->LocalToMaster(local2, global2);
229  TVector3 g1 = global1;
230  TVector3 g2 = global2;
231  if (g2.DeltaPhi(g1) > 0)
232  return resX;
233  else
234  return -resX;
235 }
236 
238  for (int i = 0; i < m_ndet; i++) {
239  std::cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
240  std::cout << "idx " << i << " det[idx] " << m_det[i] << std::endl;
241  std::cout << "m_det idx " << m_det[i] << std::endl;
242  std::cout << "m_det_tracker_str idx " << substruct[m_det[i]] - 1 << std::endl;
243  printf("m_det[idx] %i m_det_tracker_str %s substruct %i\n",
244  m_det[i],
246  subsubstruct[m_det[i]]);
247  }
248 }
249 
250 void FWTrackResidualDetailView::setTextInfo(const FWModelId& /*id*/, const reco::Track* /*track*/) {
251  m_infoCanvas->cd();
252 
253  char mytext[256];
254  Double_t fontsize = 0.07;
255  TLatex* latex = new TLatex();
256  latex->SetTextSize(fontsize);
257  latex->Draw();
258  Double_t x0 = 0.02;
259  Double_t y = 0.95;
260 
261  // summary
262  int nvalid = 0;
263  int npix = 0;
264  int nstrip = 0;
265  for (int i = 0; i < m_nhits; i++) {
266  if (hittype[i] == 0)
267  nvalid++;
268  if (substruct[i] < 3)
269  npix++;
270  else
271  nstrip++;
272  }
273 
274  latex->SetTextSize(fontsize);
275  Double_t boxH = 0.25 * fontsize;
276 
277  double yStep = 0.04;
278 
279  latex->DrawLatex(x0, y, "Residual:");
280  y -= yStep;
281  latex->DrawLatex(
282  x0,
283  y,
284  "sgn(#hat{X}#bullet#hat{#phi}) #times #frac{X_{hit} - X_{traj}}{#sqrt{#sigma^{2}_{hit} + #sigma^{2}_{traj}}}");
285  y -= 2.5 * yStep;
286  snprintf(mytext, 255, "layers hit: %i", m_ndet);
287  latex->DrawLatex(x0, y, mytext);
288  y -= yStep;
289  snprintf(mytext, 255, "valid Si hits: %i", nvalid);
290  latex->DrawLatex(x0, y, mytext);
291  y -= yStep;
292  snprintf(mytext, 255, "total Si hits: %i", m_nhits);
293  latex->DrawLatex(x0, y, mytext);
294  y -= yStep;
295  snprintf(mytext, 255, "valid Si pixel hits: %i", npix);
296  latex->DrawLatex(x0, y, mytext);
297  y -= yStep;
298  snprintf(mytext, 255, "valid Si strip hits: %i", nstrip);
299  latex->DrawLatex(x0, y, mytext);
300 
301  Double_t pos[4];
302  pos[0] = 0.4;
303  pos[2] = 0.55;
304 
305  y -= yStep * 2;
306  latex->DrawLatex(x0, y, "X hit");
307  pos[1] = y;
308  pos[3] = pos[1] + boxH;
310 
311  y -= yStep;
312  latex->DrawLatex(x0, y, "Y hit");
313  pos[1] = y;
314  pos[3] = pos[1] + boxH;
316 
317  y -= yStep;
318  latex->DrawLatex(x0, y, "stereo hit");
319  pos[1] = y;
320  pos[3] = pos[1] + boxH;
322 
323  y -= yStep;
324  latex->DrawLatex(x0, y, "invalid hit");
325  pos[1] = y;
326  pos[3] = pos[1] + boxH;
328 }
329 
FWDetailViewCanvas< reco::Track >::m_viewCanvas
TCanvas * m_viewCanvas
Definition: FWDetailViewCanvas.h:21
FWTrackResidualDetailView::subsubstruct
int subsubstruct[64]
Definition: FWTrackResidualDetailView.h:72
change_name.diff
diff
Definition: change_name.py:13
reco::HitPattern::getHitPattern
uint16_t getHitPattern(HitCategory category, int position) const
Definition: HitPattern.h:531
DDAxes::y
ApeEstimator_cff.width
width
Definition: ApeEstimator_cff.py:24
FWTrackResidualDetailView::m_det
int m_det[64]
Definition: FWTrackResidualDetailView.h:67
fwLog
#define fwLog(_level_)
Definition: fwLog.h:45
mps_fire.i
i
Definition: mps_fire.py:428
FWTrackResidualDetailView::m_nhits
int m_nhits
Definition: FWTrackResidualDetailView.h:66
FWTrackResidualDetailView::m_detector
int m_detector[64]
Definition: FWTrackResidualDetailView.h:73
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11724
FWGeometry
Definition: FWGeometry.h:27
FWTrackResidualDetailView::m_resYFill
Int_t m_resYFill
Definition: FWTrackResidualDetailView.h:77
FWTrackResidualDetailView::hittype
int hittype[64]
Definition: FWTrackResidualDetailView.h:69
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
FWModelId
Definition: FWModelId.h:28
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pos
Definition: PixelAliasList.h:18
diffTwoXMLs.g1
g1
Definition: diffTwoXMLs.py:52
FWModelId.h
FWDetailView.h
cms::cuda::assert
assert(be >=bs)
Validation_hcalonly_cfi.sign
sign
Definition: Validation_hcalonly_cfi.py:32
FWTrackResidualDetailView::m_resYCol
Color_t m_resYCol
Definition: FWTrackResidualDetailView.h:78
REGISTER_FWDETAILVIEW
#define REGISTER_FWDETAILVIEW(_classname_, _name_,...)
Definition: FWDetailViewFactory.h:32
FWDetailViewBase::drawCanvasBox
static void drawCanvasBox(Double_t *pos, Color_t fillCol, Int_t fillType=0, bool bg=kTRUE)
Definition: FWDetailViewBase.cc:53
FWTrackResidualDetailView::prepareData
void prepareData(const FWModelId &id, const reco::Track *)
Definition: FWTrackResidualDetailView.cc:50
h
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
reco::TrackResiduals
Definition: TrackResiduals.h:8
beampixel_dqm_sourceclient-live_cfg.yStep
yStep
Definition: beampixel_dqm_sourceclient-live_cfg.py:151
FWTrackResidualDetailView::m_invalidFill
Int_t m_invalidFill
Definition: FWTrackResidualDetailView.h:81
FWTrackResidualDetailView::m_resXFill
Int_t m_resXFill
Definition: FWTrackResidualDetailView.h:75
FWTrackResidualDetailView::m_resXCol
Color_t m_resXCol
Definition: FWTrackResidualDetailView.h:76
FWTrackResidualDetailView::m_ndet
int m_ndet
Definition: FWTrackResidualDetailView.h:65
reco::HitPattern
Definition: HitPattern.h:147
TrackingRecHit.h
Track.h
FWTrackResidualDetailView::substruct
int substruct[64]
Definition: FWTrackResidualDetailView.h:71
FWTrackResidualDetailView::m_det_tracker_str
const static char * m_det_tracker_str[]
Definition: FWTrackResidualDetailView.h:84
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:78
reco::Track
Definition: Track.h:27
relativeConstraints.geom
geom
Definition: relativeConstraints.py:72
FWTrackResidualDetailView::FWTrackResidualDetailView
FWTrackResidualDetailView()
Definition: FWTrackResidualDetailView.cc:28
h
dqmdumpme.k
k
Definition: dqmdumpme.py:60
FWGeometry.h
FWTrackResidualDetailView::getSignedResidual
double getSignedResidual(const FWGeometry *geom, unsigned int id, double resX)
Definition: FWTrackResidualDetailView.cc:221
FWTrackResidualDetailView::m_stereoCol
Color_t m_stereoCol
Definition: FWTrackResidualDetailView.h:80
groupFilesInBlocks.lines
lines
Definition: groupFilesInBlocks.py:95
FWTrackResidualDetailView::stereo
int stereo[64]
Definition: FWTrackResidualDetailView.h:70
reco::TrackBase
Definition: TrackBase.h:62
topSingleLeptonDQM_PU_cfi.pattern
pattern
Definition: topSingleLeptonDQM_PU_cfi.py:39
fwLog.h
HitPattern.h
res
Definition: Electron.h:6
diffTwoXMLs.g2
g2
Definition: diffTwoXMLs.py:71
FWEventItem.h
FWTrackResidualDetailView
Definition: FWTrackResidualDetailView.h:47
FWTrackResidualDetailView::setTextInfo
void setTextInfo(const FWModelId &id, const reco::Track *) override
Definition: FWTrackResidualDetailView.cc:250
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
reco::HitPattern::TRACK_HITS
Definition: HitPattern.h:155
FWDetailViewCanvas< reco::Track >::m_infoCanvas
TCanvas * m_infoCanvas
Definition: FWDetailViewCanvas.h:19
FWTrackResidualDetailView.h
reco::HitPattern::numberOfAllHits
int numberOfAllHits(HitCategory category) const
Definition: HitPattern.h:791
FWTrackResidualDetailView::~FWTrackResidualDetailView
~FWTrackResidualDetailView() override
Definition: FWTrackResidualDetailView.cc:48
FWTrackResidualDetailView::m_stereoFill
Int_t m_stereoFill
Definition: FWTrackResidualDetailView.h:79
fwlog::kError
Definition: fwLog.h:35
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
FWTrackResidualDetailView::m_invalidCol
Color_t m_invalidCol
Definition: FWTrackResidualDetailView.h:82
FWTrackResidualDetailView::printDebug
void printDebug()
Definition: FWTrackResidualDetailView.cc:237
FWTrackResidualDetailView::build
void build(const FWModelId &id, const reco::Track *) override
Definition: FWTrackResidualDetailView.cc:96