CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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::Track;
22 using reco::TrackBase;
23 using reco::HitPattern;
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 {
40  memset(m_det, 0, sizeof(m_det));
41  memset(res, 0, sizeof(res));
42  memset(hittype, 0, sizeof(hittype));
43  memset(stereo, 0, sizeof(stereo));
44  memset(substruct, 0, sizeof(substruct));
45  memset(subsubstruct, 0, sizeof(subsubstruct));
46  memset(m_detector, 0, sizeof(m_detector));
47 }
48 
50 {
51 }
52 
53 void
55 {
56  auto const & residuals = track->residuals();
57 
58  const FWGeometry *geom = id.item()->getGeom();
59  assert(geom != 0);
60 
61  const HitPattern &hitpat = track->hitPattern();
63  for (int i = 0; i < m_nhits; ++i) {
64  //printf("there are %d hits in the pattern, %d in the vector, this is %u\n",
65  // m_nhits, track->recHitsEnd() - track->recHitsBegin(), (*(track->recHitsBegin() + i))->geographicalId().rawId());
67  hittype[i] = HitPattern::getHitType(pattern);
68  stereo[i] = HitPattern::getSide(pattern);
69  subsubstruct[i] = HitPattern::getSubSubStructure(pattern);
70  substruct[i] = HitPattern::getSubStructure(pattern);
71  m_detector[i] = HitPattern::getSubDetector(pattern);
72  if ((*(track->recHitsBegin() + i))->isValid()) {
73  res[0][i] = getSignedResidual(geom,
74  (*(track->recHitsBegin() + i))->geographicalId().rawId(),
75  residuals.pullX(i));
76  } else {
77  res[0][i] = 0;
78  }
79  res[1][i] = residuals.pullY(i);
80  // printf("%s, %i\n",m_det_tracker_str[substruct[i]-1],subsubstruct[i]);
81  }
82 
83  m_det[0]=0;
84  for(int j=0; j < m_nhits-1;) {
85  int k=j+1;
86  for(; k<m_nhits ; k++) {
87  if(substruct[j]==substruct[k] && subsubstruct[j]==subsubstruct[k]) {
88  if(k==(m_nhits-1)) j=k;
89  }
90  else {
91  m_ndet++;
92  j=k;
93  m_det[m_ndet]=j;
94  break;
95  }
96  }
97  }
98  m_ndet++;
100  // printDebug();
101 }
102 
103 void
105 {
106  if (!track->extra().isAvailable()) {
107  fwLog(fwlog::kError) << " no track extra information is available.\n";
108  m_viewCanvas->cd();
109  TLatex* latex = new TLatex();
110  latex->SetTextSize(0.1);
111  latex->DrawLatex(0.1, 0.5, "No track extra information");
112  return;
113  }
114  prepareData(id, track);
115 
116  // draw histogram
117  m_viewCanvas->cd();
118  m_viewCanvas->SetHighLightColor(-1);
119  TH2F* h_res = new TH2F("h_resx","h_resx",10,-5.5,5.5,m_ndet,0,m_ndet);
120  TPad* padX = new TPad("pad1","pad1", 0.2, 0., 0.8, 0.99);
121  padX->SetBorderMode(0);
122  padX->SetLeftMargin(0.2);
123  padX->Draw();
124  padX->cd();
125  padX->SetFrameLineWidth(0);
126  padX->Modified();
127  h_res->SetDirectory(0);
128  h_res->SetStats(kFALSE);
129  h_res->SetTitle("");
130  h_res->SetXTitle("residual");
131  h_res->GetXaxis()->SetTickLength(0);
132  h_res->GetYaxis()->SetTickLength(0);
133  h_res->GetXaxis()->SetNdivisions(20);
134  h_res->GetYaxis()->SetLabelSize(0.06);
135  h_res->Draw();
136  padX->SetGridy();
137 
138  float larray[9]={0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.5, 4.5, 5.5};
139  float larray2[8];
140  for(int l=0; l<8; l++) {
141  float diff2=(larray[l+1]-larray[l])/2;
142  larray2[l]=larray[l]+diff2;
143  // printf("(%.1f,%.1f),",larray[i],larray[i+1]);
144  }
145 
146  int resi[2][64];
147  for(int l=0; l<m_nhits; l++) {
148  for(int k=0; k<8; k++) {
149  if(fabs(res[0][l])==larray2[k])
150  resi[0][l]=k;
151  if(fabs(res[1][l])==larray2[k])
152  resi[1][l]=k;
153  }
154  }
155 
156  TLine* lines[17];
157  for(int l=0; l<17; l++) {
158  int ix=l%9;
159  int sign=1;
160  sign = (l>8) ? -1 : 1;
161  lines[l] = new TLine(sign*larray[ix],0,sign*larray[ix],m_ndet);
162  if(l!=9)
163  lines[l]->SetLineStyle(3);
164  padX->cd();
165  lines[l]->Draw();
166  }
167 
168  float width=0.25;
169  int filltype;
170  Color_t color;
171  Double_t box[4];
172  padX->cd();
173 
174  for(int h=0; h<2; h++) {
175  float height1=0;
176  for(int j=0; j<m_ndet; j++) {
177  // take only X res and Y pixel residals
178  if (strcmp(m_det_tracker_str[substruct[m_det[j]]-1], "PXB") && h)
179  continue;
180 
181  char det_str2[256];
182  snprintf(det_str2, 255, "%s/%i",m_det_tracker_str[substruct[m_det[j]]-1],subsubstruct[m_det[j]]);
183  h_res->GetYaxis()->SetBinLabel(j+1, det_str2);
184 
185  int diff=m_det[j+1]-m_det[j];
186  int k=0;
187  width=1.0/diff;
188 
189  for(int l=m_det[j]; l<(m_det[j]+diff); l++) {
190  // g->SetPoint(l,resx[l],j+0.5);
191  // printf("%i, %f %f %f\n",l,resx[l],sign*larray[resxi[l]],sign*larray[resxi[l]+1]);
192  int sign = (res[h][l]<0) ? -1 : 1;
193  box[0] = (hittype[l]==0) ? sign*larray[resi[h][l]] : -5.5;
194  box[2] = (hittype[l]==0) ? sign*larray[resi[h][l]+1] : 5.5;
195  box[1] = height1+width*k;
196  box[3] = height1+width*(k+1);
197 
198  if(stereo[l]==1) {
199  color = m_stereoCol;
200  filltype = m_stereoFill;
201  }
202  else if(hittype[l]!=0) {
203  color = m_invalidCol;
204  filltype = m_invalidFill;
205  }
206  else {
207  filltype = h ? m_resYFill : m_resXFill;
208  color = h ? m_resYCol : m_resXCol;
209  }
210 
211  drawCanvasBox(box, color, filltype, h<1);
212  k++;
213  }
214  height1 +=1;
215  }
216  }
217 
218  // title
219  const char* res_str= "residuals in Si detector local x-y coord.";
220  TPaveText *pt = new TPaveText(0.0,0.91, 1,0.99,"blNDC");
221  pt->SetBorderSize(0);
222  pt->SetFillColor(kWhite);
223  pt->AddText(res_str);
224  pt->Draw();
225 
226  m_viewCanvas->cd();
227  m_viewCanvas->SetEditable(kFALSE);
228 
229  setTextInfo(id, track);
230 }
231 
232 double
233 FWTrackResidualDetailView::getSignedResidual (const FWGeometry *geom, unsigned int id, double resX)
234 {
235  double local1[3] = { 0, 0, 0 };
236  double local2[3] = { resX, 0, 0 };
237  double global1[3], global2[3];
238  const TGeoMatrix *m = geom->getMatrix(id);
239  assert(m != 0);
240  m->LocalToMaster(local1, global1);
241  m->LocalToMaster(local2, global2);
242  TVector3 g1 = global1;
243  TVector3 g2 = global2;
244  if (g2.DeltaPhi(g1) > 0)
245  return resX;
246  else return -resX;
247 }
248 
249 void
251 {
252  for(int i=0; i<m_ndet; i++)
253  {
254  std::cout <<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
255  std::cout << "idx " << i << " det[idx] " << m_det[i] << std::endl;
256  std::cout << "m_det idx " << m_det[i] << std::endl;
257  std::cout << "m_det_tracker_str idx " << substruct[m_det[i]]-1 << std::endl;
258  printf("m_det[idx] %i m_det_tracker_str %s substruct %i\n",m_det[i], m_det_tracker_str[substruct[m_det[i]]-1], subsubstruct[m_det[i]]);
259  }
260 }
261 
262 void
264 {
265  m_infoCanvas->cd();
266 
267  char mytext[256];
268  Double_t fontsize = 0.07;
269  TLatex* latex = new TLatex();
270  latex->SetTextSize(fontsize);
271  latex->Draw();
272  Double_t x0 = 0.02;
273  Double_t y = 0.95;
274 
275  // summary
276  int nvalid=0;
277  int npix=0;
278  int nstrip=0;
279  for(int i=0; i<m_nhits; i++)
280  {
281  if(hittype[i]==0) nvalid++;
282  if(substruct[i]<3) npix++;
283  else nstrip++;
284  }
285 
286  latex->SetTextSize(fontsize);
287  Double_t boxH = 0.25*fontsize;
288 
289  double yStep = 0.04;
290 
291  latex->DrawLatex(x0, y, "Residual:");
292  y-= yStep;
293  latex->DrawLatex(x0, y, "sgn(#hat{X}#bullet#hat{#phi}) #times #frac{X_{hit} - X_{traj}}{#sqrt{#sigma^{2}_{hit} + #sigma^{2}_{traj}}}" );
294  y-= 2.5*yStep;
295  snprintf(mytext, 255, "layers hit: %i", m_ndet);
296  latex->DrawLatex(x0, y, mytext);
297  y -= yStep;
298  snprintf(mytext, 255,"valid Si hits: %i", nvalid);
299  latex->DrawLatex(x0, y, mytext);
300  y -= yStep;
301  snprintf(mytext, 255,"total Si hits: %i", m_nhits);
302  latex->DrawLatex(x0, y, mytext);
303  y -= yStep;
304  snprintf(mytext, 255,"valid Si pixel hits: %i", npix);
305  latex->DrawLatex(x0, y, mytext);
306  y -= yStep;
307  snprintf(mytext, 255, "valid Si strip hits: %i", nstrip);
308  latex->DrawLatex(x0, y, mytext);
309 
310 
311  Double_t pos[4];
312  pos[0] = 0.4;
313  pos[2] = 0.55;
314 
315  y -= yStep*2;
316  latex->DrawLatex(x0, y, "X hit");
317  pos[1] = y; pos[3] = pos[1] + boxH;
319 
320  y -= yStep;
321  latex->DrawLatex(x0, y, "Y hit");
322  pos[1] = y; pos[3] = pos[1] + boxH;
324 
325  y -= yStep;
326  latex->DrawLatex(x0, y, "stereo hit");
327  pos[1] = y; pos[3] = pos[1] + boxH;
329 
330  y -= yStep;
331  latex->DrawLatex(x0, y, "invalid hit");
332  pos[1] = y; pos[3] = pos[1] + boxH;
334 }
335 
bool isAvailable() const
Definition: Ref.h:576
int i
Definition: DBlmapReader.cc:9
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
const TrackExtraRef & extra() const
reference to &quot;extra&quot; object
Definition: Track.h:189
double sign(double x)
assert(m_qm.get())
double getSignedResidual(const FWGeometry *geom, unsigned int id, double resX)
#define REGISTER_FWDETAILVIEW(_classname_, _name_,...)
const TGeoMatrix * getMatrix(unsigned int id) const
Definition: FWGeometry.cc:169
list diff
Definition: mps_update.py:85
int j
Definition: DBlmapReader.cc:9
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:104
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:445
#define fwLog(_level_)
Definition: fwLog.h:50
void prepareData(const FWModelId &id, const reco::Track *)
virtual void build(const FWModelId &id, const reco::Track *)
const TrackResiduals & residuals() const
get the residuals
Definition: Track.h:218
tuple cout
Definition: gather_cfg.py:145
static const char * m_det_tracker_str[]
uint16_t getHitPattern(HitCategory category, int position) const
Definition: HitPattern.h:515
int numberOfHits(HitCategory category) const
Definition: HitPattern.h:807
static void drawCanvasBox(Double_t *pos, Color_t fillCol, Int_t fillType=0, bool bg=kTRUE)
virtual void setTextInfo(const FWModelId &id, const reco::Track *)