CMS 3D CMS Logo

SiPixelPhase1Analyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DQM/TrackerRemapper
4 // Class: SiPixelPhase1Analyzer
5 //
6 
8 
9 using namespace std;
10 using namespace edm;
11 
13  : geomToken_(esConsumes()),
14  topoToken_(esConsumes()),
15  opMode(static_cast<OperationMode>(iConfig.getUntrackedParameter<unsigned int>("opMode"))),
16  debugFileName(iConfig.getUntrackedParameter<string>("debugFileName")),
18  rootFileHandle(nullptr),
19  isBarrelSource(iConfig.getUntrackedParameter<vector<unsigned>>("isBarrelSource")),
20  analazedRootFileName(iConfig.getUntrackedParameter<vector<string>>("remapRootFileName")),
21  pathToHistograms(iConfig.getUntrackedParameter<vector<string>>("pathToHistograms")),
22  baseHistogramName(iConfig.getUntrackedParameter<vector<string>>("baseHistogramName")) {
23 #ifdef DEBUG_MODE
24  debugFile = std::ofstream(debugFileName.c_str(), std::ofstream::out);
25 #endif
26  usesResource("TFileService");
27 
28  orthoProjectionMatrix.BuildOrthographicMatrix(1.0f, -1.0f, 1.0f, -1.0f, -10.0f, 10.0f);
29 
30  switch (opMode) {
31  case MODE_ANALYZE:
32 
33  tracksToken = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("src"));
34 
35  analazedRootFileName.clear();
36 
37  pathToHistograms.clear();
38  pathToHistograms.push_back("RecHits/");
39 
40  baseHistogramName.clear();
41  baseHistogramName.push_back("RecHits");
42 
43  break;
44  case MODE_REMAP:
45  break;
46  default:
47  break;
48  }
49 }
50 
52  for (auto& i : bins) {
53  delete i.second;
54  }
55 
56  for (auto& i : binsSummary) {
57  delete i.second;
58  }
59 
60 #ifdef DEBUG_MODE
61  debugFile.close();
62 #endif
63 }
64 
65 // ------------ method called for each event ------------
67  const auto& theTrackerGeometry = iSetup.getData(geomToken_);
68  const auto& tt = &iSetup.getData(topoToken_);
69 
70  if (firstEvent) {
74  BookBins(theTrackerGeometry, tt);
76  if (opMode == MODE_REMAP) {
77  FillBins(nullptr, theTrackerGeometry, tt);
78  }
80  firstEvent = false;
81  }
82  if (opMode == MODE_ANALYZE) {
84  iEvent.getByToken(tracksToken, tracks);
85  if (!tracks.isValid()) {
86  LogInfo("Analyzer") << "reco::TrackCollection not found... Aborting...\n";
87  return;
88  }
89  FillBins(&tracks, theTrackerGeometry, tt);
90  }
91  // debugFile << "SiPixelPhase1Analyzer::analyze() - Event " << iEvent.run() << "/" << iEvent.id().event() << endl;
92 }
93 
95  // ghost object <initializes> FileService (without it, it crashes and creation of directories would not be possible)
96  TObject* ghostObj = fs->make<TH2Poly>("ghost", "ghost", -1, 1, -1, 1);
97 
98  TDirectory* topDir = fs->getBareDirectory();
99  topDir->cd();
100 
101 #ifdef DEBUG_MODE
102  debugFile << "Full path: " << fs->fullPath() << endl << endl;
103 #endif
104  string histName;
105  for (unsigned j = 0; j < baseHistogramName.size(); ++j) {
106  string currentHistoName = baseHistogramName[j];
107 
108  TDirectory* currentDir = topDir->mkdir(currentHistoName.c_str());
109  currentDir->cd();
110 
111  if (opMode == MODE_REMAP) {
112  if (isBarrelSource[j]) {
113  BookBarrelHistograms(currentDir, currentHistoName);
114  } else {
115  BookForwardHistograms(currentDir, currentHistoName);
116  }
117  } else {
118  BookBarrelHistograms(currentDir, currentHistoName);
119  BookForwardHistograms(currentDir, currentHistoName);
120  }
121 
122  topDir->cd();
123  }
124 
125  ghostObj->Delete(); //not needed any more
126 }
127 
128 void SiPixelPhase1Analyzer::BookBarrelHistograms(TDirectory* currentDir, const string& currentHistoName) {
129  string histName;
130  TH2Poly* th2p;
131 
132 #ifdef DEBUG_MODE
133  TH2* th2;
134 #endif
135 
136  for (unsigned i = 0; i < 4; ++i) {
137  histName = "barrel_layer_";
138 
139  th2p = new TH2Poly((histName + std::to_string(i + 1)).c_str(), "PXBMap", -15.0, 15.0, 0.0, 5.0);
140 
141  th2p->SetFloat();
142 
143  th2p->GetXaxis()->SetTitle("z [cm]");
144  th2p->GetYaxis()->SetTitle("ladder");
145 
146 #ifdef DEBUG_MODE
147  th2p->SetOption("COLZ 0 TEXT");
148 #else
149  th2p->SetOption("COLZ L");
150 #endif
151 
152  currentDir->Add(th2p);
153  th2PolyBarrel[currentHistoName].push_back(th2p);
154 
155 #ifdef DEBUG_MODE
156  if (opMode == MODE_ANALYZE) {
157  th2 = new TH2I((histName + std::to_string(i + 1) + "_DEBUG").c_str(),
158  "position",
159  3000,
160  -30.0f,
161  30.0f,
162  1000,
163  -4.5f * (i + 1),
164  4.5f * (i + 1));
165 
166  th2->GetXaxis()->SetTitle("z [cm]");
167  th2->GetYaxis()->SetTitle("-x [?]");
168 
169  th2->SetOption("COLZ 0 TEXT");
170 
171  currentDir->Add(th2);
172  th2PolyBarrelDebug[currentHistoName].push_back(th2);
173  }
174 #endif
175  }
176 
177  th2p = new TH2Poly("barrel_summary", "PXBMap", -5.0, 5.0, 0.0, 5.0);
178  th2p->SetFloat();
179 
180  th2p->GetXaxis()->SetTitle("");
181  th2p->GetYaxis()->SetTitle("~ladder");
182 
183  th2p->SetOption("COLZ L");
184 
185  currentDir->Add(th2p);
186  th2PolyBarrelSummary[currentHistoName] = th2p;
187 }
188 
189 void SiPixelPhase1Analyzer::BookForwardHistograms(TDirectory* currentDir, const string& currentHistoName) {
190  string histName;
191  TH2Poly* th2p;
192 #ifdef DEBUG_MODE
193  TH2* th2;
194 #endif
195 
196  for (unsigned side = 1; side <= 2; ++side) {
197  for (unsigned disk = 1; disk <= 3; ++disk) {
198  histName = "forward_disk_";
199 
200  th2p = new TH2Poly((histName + std::to_string((side == 1 ? -(int(disk)) : (int)disk))).c_str(),
201  "PXFMap",
202  -15.0,
203  15.0,
204  -15.0,
205  15.0);
206 
207  th2p->SetFloat();
208 
209  th2p->GetXaxis()->SetTitle("x [cm]");
210  th2p->GetYaxis()->SetTitle("y [cm]");
211 
212 #ifdef DEBUG_MODE
213  th2p->SetOption("COLZ 0 TEXT");
214 #else
215  th2p->SetOption("COLZ L");
216 #endif
217  currentDir->Add(th2p);
218  pxfTh2PolyForward[currentHistoName].push_back(th2p);
219 
220 #ifdef DEBUG_MODE
221  if (opMode == MODE_ANALYZE) {
222  th2 = new TH2I((histName + std::to_string((side == 1 ? -(int(disk)) : (int)disk)) + "_DEBUG").c_str(),
223  "position",
224  1000,
225  -15.0f,
226  15.0f,
227  1000,
228  -15.0f,
229  15.0f);
230 
231  th2->GetXaxis()->SetTitle("x [cm]");
232  th2->GetYaxis()->SetTitle("y [cm]");
233 
234  th2->SetOption("COLZ 0 TEXT");
235 
236  currentDir->Add(th2);
237  pxfTh2PolyForwardDebug[currentHistoName].push_back(th2);
238  }
239 #endif
240  }
241  }
242 
243  th2p = new TH2Poly("forward_summary", "PXFMap", -40.0, 50.0, -20.0, 90.0);
244  th2p->SetFloat();
245 
246  th2p->GetXaxis()->SetTitle("");
247  th2p->GetYaxis()->SetTitle("");
248 
249 #ifdef DEBUG_MODE
250  th2p->SetOption("COLZ 0 TEXT");
251 #else
252  th2p->SetOption("COLZ L");
253 #endif
254 
255  currentDir->Add(th2p);
256  pxfTh2PolyForwardSummary[currentHistoName] = th2p;
257 }
258 
259 void SiPixelPhase1Analyzer::BookBins(const TrackerGeometry& theTrackerGeometry, const TrackerTopology* tt) {
260  BookBarrelBins(theTrackerGeometry, tt);
261  BookForwardBins(theTrackerGeometry, tt);
262 
263 #ifdef DEBUG_MODE
265 #endif
266 }
267 
269  TrackingGeometry::DetContainer pxb = theTrackerGeometry.detsPXB();
270 #ifdef DEBUG_MODE
271  debugFile << "There are " << pxb.size() << " detector elements in the PXB." << endl;
272 #endif
273  for (auto& i : pxb) {
274  const GeomDet* det = i;
275 
276  PXBDetId id = det->geographicalId();
277 
278  Local2DPoint origin;
279  GlobalPoint p = det->surface().toGlobal(origin);
280 
281  int layer = tt->pxbLayer(id);
282  int ladder = tt->pxbLadder(id);
283 
284 #ifdef DEBUG_MODE
285  int module = tt->pxbModule(id);
286  PixelBarrelName pixelBarrelName(id, tt, true);
288  true, id.rawId(), pixelBarrelName.shell(), pixelBarrelName.layerName(), pixelBarrelName.ladderName());
289 #endif
290 
291 #ifdef DEBUG_MODE
292  float r = sqrt(p.x() * p.x() + p.y() * p.y());
293 
294  debugFile << "Layer: " << layer << "\tLadder: " << ladder << "\tModule: " << module << "\t(x, y, z, r2): (" << p.x()
295  << ", " << p.y() << ", " << p.z() << ", " << r << ")" << endl;
296 #endif
297 
298  const Bounds& b = (det->surface().bounds());
299  float bl = b.length();
300 
301 #ifdef DEBUG_MODE
302  float bw = b.width();
303  float bt = b.thickness();
304 
305  debugFile << "Length: " << bl << "\tWidth: " << bw << "\tThickness: " << bt << endl;
306 #endif
307 
308  float vertX[] = {p.z() - bl * 0.5f, p.z() + bl * 0.5f, p.z() + bl * 0.5f, p.z() - bl * 0.5f, p.z() - bl * 0.5f};
309  float vertY[] = {(ladder - 1.0f), (ladder - 1.0f), (float)ladder, (float)ladder, (ladder - 1.0f)};
310 
311  bins[id.rawId()] = new TGraph(5, vertX, vertY);
312  bins[id.rawId()]->SetName(TString::Format("%u", id.rawId()));
313 
314  // Summary plot
315  for (unsigned k = 0; k < 5; ++k) {
316  vertX[k] += ((layer == 2 || layer == 3) ? 0.0f : -60.0f);
317  vertY[k] += ((layer > 2) ? 30.0f : 0.0f);
318  }
319 
320  binsSummary[id.rawId()] = new TGraph(5, vertX, vertY);
321  binsSummary[id.rawId()]->SetName(TString::Format("%u", id.rawId()));
322 
323  for (unsigned nameNum = 0; nameNum < baseHistogramName.size(); ++nameNum) {
324  if (isBarrelSource[nameNum] || opMode == MODE_ANALYZE) {
325  const string& strName = baseHistogramName[nameNum];
326  th2PolyBarrel[strName][layer - 1]->AddBin(bins[id.rawId()]->Clone());
327  th2PolyBarrelSummary[strName]->AddBin(binsSummary[id.rawId()]->Clone());
328  }
329  }
330  }
331 }
332 
334  TrackingGeometry::DetContainer pxf = theTrackerGeometry.detsPXF();
335 #ifdef DEBUG_MODE
336  debugFile << "There are " << pxf.size() << " detector elements in the PXF." << endl;
337 #endif
338  bool firstForwardElem = true;
339 
340  float elemWidth = 1.0f;
341  float elemLength = 1.0f;
342 
343  // FIRST PASS -> MAKE MAP OF CORRESPONDING ELEMENTS (BLADES ON BOTH PANELS)
344  for (auto& i : pxf) {
345  const GeomDet* det = i;
346 
347  PXFDetId id = det->geographicalId();
348 
349  Local2DPoint origin;
350  GlobalPoint p = det->surface().toGlobal(origin);
351 
352  int panel = tt->pxfPanel(id);
353  int side = tt->side(id); //tt->pxfSide(id);
354  int disk = tt->layer(id); //tt->pxfDisk(id);
355  int blade = tt->pxfBlade(id);
356 
357 #ifdef DEBUG_MODE
358  int module = tt->module(id); //tt->pxfModule(id);
359  PixelEndcapName pixelEndcapName(id, tt, true);
361  false, id.rawId(), pixelEndcapName.halfCylinder(), pixelEndcapName.diskName(), pixelEndcapName.bladeName());
362 #endif
363 
364 #ifdef DEBUG_MODE
365  float r = sqrt(p.x() * p.x() + p.y() * p.y());
366 
367  debugFile << "Panel: " << panel << "\tSide: " << side << "\tDisk: " << disk << "\tBlade: " << blade
368  << "\tModule: " << module << "\t(x, y, z, r): (" << p.x() << ", " << p.y() << ", " << p.z() << ", " << r
369  << ")" << endl;
370 #endif
371  if (firstForwardElem) {
372  const Bounds& b = det->surface().bounds(); //const RectangularPlaneBounds& b
373 
374  elemLength = b.length();
375  elemWidth = b.width();
376 
377  firstForwardElem = false;
378  }
379 
380  const auto& rot = det->rotation();
381 
382  mat4 transMat(
383  rot.xx(), rot.xy(), rot.xz(), rot.yx(), rot.yy(), rot.yz(), rot.zx(), rot.zy(), rot.zz(), p.x(), p.y(), p.z());
384 
385  mapOfComplementaryElements[CODE_FORWARD(side, disk, blade)].mat[panel - 1] = transMat;
386  mapOfComplementaryElements[CODE_FORWARD(side, disk, blade)].rawId[panel - 1] = id.rawId();
387  }
388 
389  // SECOND PASS -> USE INFORMATION FROM MAP TO MAKE GEOMETRIC OBJECTS (BINS)
390  for (auto& i : mapOfComplementaryElements) {
391  // decode side&disk from the map key
392  unsigned side = i.first & 0xF;
393  unsigned disk = (i.first & 0xF0) >> 4;
394  // unsigned blade = (i.first & 0xFF00) >> 8;
395 
396  unsigned mapIdx = disk + (side - 1) * 3 - 1;
397 
398  // normal vectors of elements point to the (almost) opposite direction, so correction is needed before interploation (probably not 100% correct but fast)
399  i.second.mat[1].data[0] = -i.second.mat[1].data[0];
400  i.second.mat[1].data[1] = -i.second.mat[1].data[1];
401  i.second.mat[1].data[2] = -i.second.mat[1].data[2];
402 
403  i.second.mat[1].data[6] = -i.second.mat[1].data[6];
404  i.second.mat[1].data[7] = -i.second.mat[1].data[7];
405  i.second.mat[1].data[8] = -i.second.mat[1].data[8];
406 
407  mat4 meanTransform = (i.second.mat[0] + i.second.mat[1]) * 0.5f;
408  // mat4 meanTransform = i.second.mat[0];
409 
410  static const float baseVertX[4] = {-elemWidth * 0.8f, -elemWidth * 0.5f, elemWidth * 0.8f, elemWidth * 0.5f};
411  static const float baseVertY[4] = {
412  elemLength * 0.38f, -elemLength * 0.38f, elemLength * 0.38f, -elemLength * 0.38f};
413 
414  float vertXPanel[2][4], vertYPanel[2][4];
415  float vertIn[3], vertOut[3];
416 
417  /*
418  (1) __________________ (3)
419  \ /
420  \ /
421  \ /
422  \ /
423  (2)\_________/(4)
424 
425  - division line: (2) - (3)
426 
427  - panel 1: triangle of lower area (2, 3, 4)
428  - panel 2: triangle of bigger area (1, 2, 3)
429  */
430 
431  // obtain transformed vertices
432  for (unsigned j = 0; j < 4; ++j) {
433  vertIn[0] = baseVertX[j];
434  vertIn[1] = baseVertY[j];
435  vertIn[2] = 0.0f;
436 
437  meanTransform.MulVec(vertIn, vertOut);
438  std::swap(vertIn, vertOut);
439  orthoProjectionMatrix.MulVec(vertIn, vertOut);
440 
441  // vertical flip
442  vertOut[0] = -vertOut[0]; // so that inner elements have positive x-coordinate
443 
444  if (j > 0) {
445  vertXPanel[0][j - 1] = vertOut[0];
446  vertYPanel[0][j - 1] = vertOut[1]; // for panel 2
447  }
448  if (j < 3) {
449  vertXPanel[1][j] = vertOut[0];
450  vertYPanel[1][j] = vertOut[1]; // for panel 1
451  }
452  }
453 
454  for (unsigned j = 0; j < 2; ++j) {
455  vertXPanel[j][3] = vertXPanel[j][0];
456  vertYPanel[j][3] = vertYPanel[j][0];
457 
458  bins[i.second.rawId[j]] = new TGraph(4, vertXPanel[j], vertYPanel[j]);
459  bins[i.second.rawId[j]]->SetName(TString::Format("%u", i.second.rawId[j]));
460 
461  // for (auto strName: baseHistogramName)
462  // {
463  // pxfTh2PolyForward[strName][mapIdx]->AddBin(bins[i.second.rawId[j]]->Clone());
464  // }
465 
466  // Summary plot
467  for (unsigned k = 0; k < 4; ++k) {
468  vertXPanel[j][k] += (float(side) - 1.5f) * 40.0f;
469  vertYPanel[j][k] += (disk - 1) * 35.0f;
470  }
471 
472  binsSummary[i.second.rawId[j]] = new TGraph(4, vertXPanel[j], vertYPanel[j]);
473  binsSummary[i.second.rawId[j]]->SetName(TString::Format("%u", i.second.rawId[j]));
474 
475  for (unsigned nameNum = 0; nameNum < baseHistogramName.size(); ++nameNum) {
476  if (!isBarrelSource[nameNum] || opMode == MODE_ANALYZE) {
477  const string& strName = baseHistogramName[nameNum];
478  pxfTh2PolyForward[strName][mapIdx]->AddBin(bins[i.second.rawId[j]]->Clone());
479  pxfTh2PolyForwardSummary[strName]->AddBin(binsSummary[i.second.rawId[j]]->Clone());
480  }
481  }
482  }
483  }
484 }
485 
487  vector<std::ofstream*> verticesFiles[2];
488  for (unsigned i = 0; i < 4; ++i) {
489  std::ofstream* f = new std::ofstream(("vertices_barrel_" + std::to_string(i + 1)).c_str(), std::ofstream::out);
490 
491  verticesFiles[0].push_back(f);
492  }
493 
494  for (unsigned side = 1; side <= 2; ++side) {
495  for (unsigned disk = 1; disk <= 3; ++disk) {
496  std::ofstream* f = new std::ofstream(
497  ("vertices_forward_" + std::to_string((side == 1 ? -(int(disk)) : (int)disk))).c_str(), std::ofstream::out);
498 
499  verticesFiles[1].push_back(f);
500  }
501  }
502 
503  for (auto& bin : bins) {
504  unsigned rawId = bin.first;
505  DetId id(rawId);
506  unsigned subdetId = id.subdetId();
507 
508  if (subdetId != PixelSubdetector::PixelBarrel && subdetId != PixelSubdetector::PixelEndcap)
509  continue;
510 
511  double* vertX = bin.second->GetX();
512  double* vertY = bin.second->GetY();
513 
514  if (subdetId == PixelSubdetector::PixelBarrel) {
515  PXBDetId pxbId(rawId);
516  unsigned layer = tt->pxbLayer(pxbId);
517  string onlineName = PixelBarrelName(pxbId, tt, true).name();
518 
519  *(verticesFiles[0][layer - 1]) << rawId << " " << onlineName << " \"";
520  for (unsigned i = 0; i < 4; ++i) {
521  *(verticesFiles[0][layer - 1]) << vertX[i] << "," << vertY[i];
522  if (i == 3)
523  *(verticesFiles[0][layer - 1]) << "\"\n";
524  else
525  *(verticesFiles[0][layer - 1]) << " ";
526  }
527  } else {
528  PXFDetId pxfId(rawId);
529  unsigned side = tt->pxfSide(pxfId);
530  unsigned disk = tt->pxfDisk(pxfId);
531  string onlineName = PixelEndcapName(pxfId, tt, true).name();
532  unsigned mapIdx = disk + (side - 1) * 3 - 1;
533 
534  *(verticesFiles[1][mapIdx]) << rawId << " " << onlineName << " \"";
535  for (unsigned i = 0; i < 3; ++i) {
536  *(verticesFiles[1][mapIdx]) << vertX[i] << "," << vertY[i];
537 
538  if (i == 2)
539  *(verticesFiles[1][mapIdx]) << "\"\n";
540  else
541  *(verticesFiles[1][mapIdx]) << " ";
542  }
543  }
544  }
545 
546  for (unsigned i = 0; i < 2; ++i) {
547  for (auto& j : verticesFiles[i]) {
548  j->close();
549  delete j;
550  }
551  }
552 }
553 
555  const TrackerGeometry& theTrackerGeometry,
556  const TrackerTopology* tt) {
557  switch (opMode) {
558  case MODE_ANALYZE:
559  for (auto const& track : *(*tracks)) {
560  auto recHitsBegin = track.recHitsBegin();
561  for (unsigned i = 0; i < track.recHitsSize(); ++i) {
562  auto recHit = *(recHitsBegin + i);
563  if (!recHit->isValid())
564  continue;
565 
566  DetId id = recHit->geographicalId();
567  unsigned subdetId = id.subdetId();
568 
569  if (subdetId != PixelSubdetector::PixelBarrel && subdetId != PixelSubdetector::PixelEndcap)
570  continue;
571 
572  const PixelGeomDetUnit* geomdetunit =
573  dynamic_cast<const PixelGeomDetUnit*>(theTrackerGeometry.idToDet(id)); // theTrackerGeometry ?????
574  //const PixelTopology& topol = geomdetunit->specificTopology();
575 
576  LocalPoint localPoint = recHit->localPosition();
577  GlobalPoint globalPoint = geomdetunit->surface().toGlobal(localPoint);
578 
579  if (subdetId == PixelSubdetector::PixelBarrel)
580  FillBarrelBinsAnalyze(theTrackerGeometry, tt, id.rawId(), globalPoint);
581  else
582  FillForwardBinsAnalyze(theTrackerGeometry, tt, id.rawId(), globalPoint);
583  }
584  }
585  break;
586  case MODE_REMAP:
587  FillBarrelBinsRemap(theTrackerGeometry, tt);
588  FillForwardBinsRemap(theTrackerGeometry, tt);
589  break;
590  default:
591  break;
592  }
593 }
594 
596  const TrackerTopology* tt,
597  unsigned rawId,
598  const GlobalPoint& globalPoint) {
599  for (unsigned nameNum = 0; nameNum < baseHistogramName.size(); ++nameNum) {
600  string strName = baseHistogramName[nameNum];
601 
602  PXBDetId id(rawId);
603 
604  int layer = tt->pxbLayer(id);
605 
606  th2PolyBarrel[strName][layer - 1]->Fill(TString::Format("%u", rawId), 1);
607  th2PolyBarrelSummary[strName]->Fill(TString::Format("%u", rawId), 1);
608 #ifdef DEBUG_MODE
609  th2PolyBarrelDebug[strName][layer - 1]->Fill((globalPoint.y() < 0 ? globalPoint.z() + 0.5f : globalPoint.z()),
610  -globalPoint.x(),
611  (globalPoint.y() < 0 ? -1 : 1));
612 #endif
613  }
614 }
615 
617  const TrackerTopology* tt,
618  unsigned rawId,
619  const GlobalPoint& globalPoint) {
620  for (unsigned nameNum = 0; nameNum < baseHistogramName.size(); ++nameNum) {
621  string strName = baseHistogramName[nameNum];
622 
623  PXFDetId id(rawId);
624 
625  int side = tt->side(id); //tt->pxfSide(id);
626  int disk = tt->layer(id); //tt->pxfDisk(id);
627  // int blade = tt->pxfBlade(id);
628  unsigned mapIdx = disk + (side - 1) * 3 - 1;
629 
630  pxfTh2PolyForward[strName][mapIdx]->Fill(TString::Format("%u", rawId), 1);
631  pxfTh2PolyForwardSummary[strName]->Fill(TString::Format("%u", rawId), 1);
632 
633 #ifdef DEBUG_MODE
634  pxfTh2PolyForwardDebug[strName][mapIdx]->Fill(globalPoint.x(), globalPoint.y(), 1);
635 #endif
636  }
637 }
638 
640  rootFileHandle = new TFile(analazedRootFileName[0].c_str());
641 
642  if (!rootFileHandle) {
643  LogInfo("Analyzer") << "Could not open file: " << analazedRootFileName[0] << "..." << endl;
644  return;
645  }
646 
647 #ifdef DEBUG_MODE
648  rootFileHandle->ls();
649  LogInfo("Analyzer") << "\n\n";
650  rootFileHandle->pwd();
651  LogInfo("Analyzer") << "\n\n";
652 #endif
653 
654  for (unsigned nameNum = 0; nameNum < baseHistogramName.size(); ++nameNum) {
655  if (!isBarrelSource[nameNum])
656  continue;
657 
658  // if (pathToHistograms[nameNum][pathToHistograms.size() - 1] != '/') pathToHistograms[nameNum] += "/";
659  string baseHistogramNameWithPath = pathToHistograms[nameNum] + baseHistogramName[nameNum] + "_";
660 
661  const TProfile2D* handles[4];
662 #ifndef DEBUG_MODE
663  const TProfile2D* h;
664 #endif
665  bool problemWithHandles = false;
666 
667  for (unsigned i = 0; i < 4; ++i) {
668  string fullFileName = (baseHistogramNameWithPath + std::to_string(i + 1) + ";1 ");
669  handles[i] = (TProfile2D*)rootFileHandle->Get(fullFileName.c_str());
670  if (!handles[i]) {
671  problemWithHandles = true;
672  LogInfo("Analyzer") << "Histogram: " << fullFileName << " does not exist!\n";
673 
674  break;
675  }
676  }
677 
678  if (!problemWithHandles) {
679  LogInfo("Analyzer") << "\nInput histograms: " << baseHistogramNameWithPath << " opened successfully\n";
680 
681  //Add original histograms to this file
682 
683  TDirectory* currDir = fs->getBareDirectory()->GetDirectory(baseHistogramName[nameNum].c_str());
684  currDir->cd();
685 
686  for (unsigned i = 0; i < 4; ++i) {
687  currDir->Add(handles[i]->Clone());
688  }
689 
690  TrackingGeometry::DetContainer pxb = theTrackerGeometry.detsPXB();
691 #ifdef DEBUG_MODE
692  debugFile << "There are " << pxb.size() << " detector elements in the PXB." << endl;
693 #endif
694  for (auto& i : pxb) {
695  const GeomDet* det = i;
696 
697  PXBDetId id = det->geographicalId();
698  unsigned rawId = id.rawId();
699 
700  int module = tt->pxbModule(id);
701  //int ladder = tt->pxbLadder(id);
702  int layer = tt->pxbLayer(id);
703 
704  int signedOnlineModule = module - 4;
705  if (signedOnlineModule <= 0)
706  --signedOnlineModule;
707 
708  PixelBarrelName pixelBarrelName = PixelBarrelName(id, tt, true);
709  int onlineShell = pixelBarrelName.shell();
710 
711  int signedOnlineLadder = ((onlineShell & 1) ? -pixelBarrelName.ladderName() : pixelBarrelName.ladderName());
712  string strName = baseHistogramName[nameNum];
713 
714 #ifdef DEBUG_MODE
715  th2PolyBarrel[strName][layer - 1]->Fill(TString::Format("%u", rawId), signedOnlineLadder);
716  th2PolyBarrelSummary[strName]->Fill(TString::Format("%u", rawId), signedOnlineLadder);
717 #else
718  h = handles[layer - 1];
719  unsigned nx = h->GetNbinsX();
720  unsigned ny = h->GetNbinsY();
721  unsigned binX = signedOnlineModule + ((nx + 1) >> 1);
722  unsigned binY = (signedOnlineLadder) + ((ny + 1) >> 1);
723  double val = h->GetBinContent(binX, binY);
724  th2PolyBarrel[strName][layer - 1]->Fill(TString::Format("%u", rawId), val);
725  th2PolyBarrelSummary[strName]->Fill(TString::Format("%u", rawId), val);
726 #endif
727  }
728  }
729  }
730 
731  rootFileHandle->Close();
732  delete rootFileHandle;
733 }
734 
736  rootFileHandle = new TFile(analazedRootFileName[0].c_str());
737 
738  if (!rootFileHandle) {
739  return;
740  }
741 
742  TrackingGeometry::DetContainer pxf = theTrackerGeometry.detsPXF();
743 
744 #ifdef DEBUG_MODE
745  rootFileHandle->ls();
746  LogInfo("Analyzer") << "\n\n";
747  rootFileHandle->pwd();
748  LogInfo("Analyzer") << "\n\n";
749 #endif
750 
751  for (unsigned nameNum = 0; nameNum < baseHistogramName.size(); ++nameNum) {
752  if (isBarrelSource[nameNum])
753  continue;
754 
755  string baseHistogramNameWithPath = pathToHistograms[nameNum] + baseHistogramName[nameNum] + "_";
756 
757  const TProfile2D* h_1 = (TProfile2D*)rootFileHandle->Get((baseHistogramNameWithPath + "1;1 ").c_str());
758  const TProfile2D* h_2 = (TProfile2D*)rootFileHandle->Get((baseHistogramNameWithPath + "2;1 ").c_str());
759 #ifndef DEBUG_MODE
760  const TProfile2D* h;
761 #endif
762  if (h_2 && h_1) {
763  LogInfo("Analyzer") << "\nInput histograms: " << baseHistogramNameWithPath << " opened successfully\n";
764 
765  //Add original histograms to this file
766  TDirectory* currDir = fs->getBareDirectory()->GetDirectory(baseHistogramName[nameNum].c_str());
767  currDir->cd();
768  currDir->Add(h_1->Clone());
769  currDir->Add(h_2->Clone());
770 
771  for (auto& i : pxf) {
772  const GeomDet* det = i;
773 
774  PXFDetId id = det->geographicalId();
775 
776  int side = tt->side(id); //tt->pxfSide(id);
777  int disk = tt->layer(id); //tt->pxfDisk(id);
778 
779  unsigned rawId = id.rawId();
780  PixelEndcapName pixelEndcapName = PixelEndcapName(PXFDetId(rawId), tt, true);
781 
782 #ifdef DEBUG_MODE
783  int blade = tt->pxfBlade(id);
784 #else
785  int onlineBlade = pixelEndcapName.bladeName();
786  bool isInnerOnlineBlade = !(pixelEndcapName.halfCylinder() & 1); // inner -> blade > 0 (?)
787 
788  int signedOnlineBlade = (isInnerOnlineBlade) ? onlineBlade : -onlineBlade;
789  int signedDisk = (side == 2) ? disk : -disk;
790 
791  int pannel = pixelEndcapName.pannelName() - 1;
792 
793 #endif
794  unsigned mapIdx = disk + (side - 1) * 3 - 1;
795  string strName = baseHistogramName[nameNum];
796 
797 #ifdef DEBUG_MODE
798  pxfTh2PolyForward[strName][mapIdx]->Fill(TString::Format("%u", rawId), blade);
799  pxfTh2PolyForwardSummary[strName]->Fill(TString::Format("%u", rawId), blade);
800 #else
801  if (pixelEndcapName.ringName() == 1)
802  h = h_1;
803  else
804  h = h_2;
805  // ---- REMAP (Online -> Offline)
806  unsigned nx = h->GetNbinsX();
807  unsigned ny = h->GetNbinsY();
808  unsigned binX = signedDisk + ((nx + 1) >> 1);
809  unsigned binY = (signedOnlineBlade * 2) + (ny >> 1);
810  double val = h->GetBinContent(binX, binY + pannel);
811  pxfTh2PolyForward[strName][mapIdx]->Fill(TString::Format("%u", rawId), val);
812  pxfTh2PolyForwardSummary[strName]->Fill(TString::Format("%u", rawId), val);
813 #endif
814  }
815  }
816  }
817 
818  rootFileHandle->Close();
819  delete rootFileHandle;
820 }
821 
822 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
824  //The following says we do not know what parameters are allowed so do no validation
825  // Please change this to state exactly what you do use, even if it is no parameters
827  desc.setComment(
828  "Creates TH2Poly Pixel Tracker maps by either analyzing the event or remapping exising DQM historams");
829  desc.add<edm::InputTag>("src", edm::InputTag("generalTracks"));
830  desc.addUntracked<unsigned int>("opMode", 1);
831  desc.addUntracked<std::string>("debugFileName", "debug.txt");
832  desc.addUntracked<std::vector<unsigned int>>("isBarrelSource", {0, 0, 1});
833  desc.addUntracked<std::vector<std::string>>("remapRootFileName", {"dqmFile.root"});
834  desc.addUntracked<std::vector<std::string>>(
835  "pathToHistograms",
836  {"DQMData/Run 1/PixelPhase1/Run summary/Phase1_MechanicalView/PXForward/",
837  "DQMData/Run 1/PixelPhase1/Run summary/Phase1_MechanicalView/PXForward/",
838  "DQMData/Run 1/PixelPhase1/Run summary/Phase1_MechanicalView/PXBarrel/"});
839  desc.addUntracked<std::vector<std::string>>("baseHistogramName",
840  {"num_clusters_per_PXDisk_per_SignedBladePanel_PXRing",
841  "num_digis_per_PXDisk_per_SignedBladePanel_PXRing",
842  "num_digis_per_SignedModule_per_SignedLadder_PXLayer"});
843  descriptions.addWithDefaultLabel(desc);
844 }
845 
846 //define this as a plug-in
Definition: mat4.h:9
void BookForwardBins(const TrackerGeometry &theTrackerGeometry, const TrackerTopology *tt)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
void FillBins(edm::Handle< reco::TrackCollection > *tracks, const TrackerGeometry &theTrackerGeometry, const TrackerTopology *tt)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< std::string > pathToHistograms
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
int ringName() const
ring Id
std::map< std::string, std::vector< TH2Poly * > > th2PolyBarrel
const DetContainer & detsPXB() const
std::map< uint32_t, TGraph * > binsSummary
T z() const
Definition: PV3DBase.h:61
int bladeName() const
blade id
std::vector< unsigned > isBarrelSource
const DetContainer & detsPXF() const
void BookBarrelBins(const TrackerGeometry &theTrackerGeometry, const TrackerTopology *tt)
void BuildOrthographicMatrix(float left, float right, float top, float bottom, float near, float far)
Definition: mat4.h:86
std::string to_string(const V &value)
Definition: OMSAccess.h:71
std::map< std::string, std::vector< TH2Poly * > > pxfTh2PolyForward
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
std::map< unsigned short, complementaryElements > mapOfComplementaryElements
const Surface::RotationType & rotation() const
The rotation defining the local R.F.
Definition: GeomDet.h:46
std::vector< const GeomDet * > DetContainer
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
int iEvent
Definition: GenABIO.cc:224
Definition: TTTypes.h:54
std::map< std::string, TH2Poly * > pxfTh2PolyForwardSummary
edm::EDGetTokenT< reco::TrackCollection > tracksToken
std::vector< BaseVolumeHandle * > handles
int diskName() const
disk id
SiPixelPhase1Analyzer(const edm::ParameterSet &)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
std::string name() const override
from base class
T sqrt(T t)
Definition: SSEVec.h:19
#define CODE_FORWARD(s, d, b)
HalfCylinder halfCylinder() const
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
double f[11][100]
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void SaveDetectorData(bool isBarrel, unsigned rawId, int shell_hc, int layer_disk, int ladder_blade)
void FillBarrelBinsAnalyze(const TrackerGeometry &theTrackerGeometry, const TrackerTopology *tt, unsigned rawId, const GlobalPoint &globalPoint)
TDirectory * getBareDirectory(const std::string &subdir="") const
Definition: TFileService.h:52
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
std::vector< std::string > analazedRootFileName
const TrackerGeomDet * idToDet(DetId) const override
void MulVec(const float *vecIn, float *vecOut)
Definition: mat4.h:77
std::map< uint32_t, TGraph * > bins
void analyze(const edm::Event &, const edm::EventSetup &) override
void BookBarrelHistograms(TDirectory *currentDir, const std::string &currentHistoName)
Shell shell() const
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
Log< level::Info, false > LogInfo
Definition: DetId.h:17
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
void SaveDetectorVertices(const TrackerTopology *tt)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::string name() const override
from base class
void BookBins(const TrackerGeometry &theTrackerGeometry, const TrackerTopology *tt)
int layerName() const
layer id
double b
Definition: hdecay.h:118
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::Service< TFileService > fs
void FillForwardBinsRemap(const TrackerGeometry &theTrackerGeometry, const TrackerTopology *tt)
std::string fullPath() const
return the full path of the stored histograms
Definition: TFileService.h:74
HLT enums.
void FillForwardBinsAnalyze(const TrackerGeometry &theTrackerGeometry, const TrackerTopology *tt, unsigned rawId, const GlobalPoint &globalPoint)
int ladderName() const
ladder id (index in phi)
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
std::vector< std::string > baseHistogramName
void FillBarrelBinsRemap(const TrackerGeometry &theTrackerGeometry, const TrackerTopology *tt)
Definition: Bounds.h:18
std::map< std::string, TH2Poly * > th2PolyBarrelSummary
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
int pannelName() const
pannel id
const Bounds & bounds() const
Definition: Surface.h:87
void BookForwardHistograms(TDirectory *currentDir, const std::string &currentHistoName)