103 std::map<int, TrackerOfflineValidationSummary::ModuleHistos>& moduleHist,
106 std::map<std::string, std::string>& substructureName,
114 std::map<std::string, std::string>& substructureName);
119 void getBinning(
const std::string& binningPSetName,
int& nBinsX,
double& lowerBoundX,
double& upperBoundX)
const;
160 topoToken_(esConsumes()),
162 moduleDirectory_(parSet_.getParameter<
std::
string>(
"moduleDirectoryInOutput")),
163 useFit_(parSet_.getParameter<
bool>(
"useFit")),
165 moduleMapsInitialized(
false),
166 lastSetup_(nullptr) {
192 std::vector<DetId>::const_iterator iDet;
193 for (iDet = detIdContainer.begin(); iDet != detIdContainer.end(); ++iDet) {
194 const DetId& detId = *iDet;
195 const uint32_t rawId = detId.
rawId();
196 const unsigned int subdetId = detId.
subdetId();
211 <<
"[TrackerOfflineValidationSummary] Error, tried to get reference for non-tracker subdet " << subdetId
212 <<
" from detector " << detId.
det();
231 TTree*
tree =
new TTree(
"TkOffVal",
"TkOffVal");
237 tree->Branch(
"TkOffTreeVariables", &treeMemPtr);
239 std::map<std::string, std::string>* substructureName =
new std::map<std::string, std::string>;
240 tree->Branch(
"SubstructureName", &substructureName, 32000, 00);
258 treeMemPtr =
nullptr;
259 delete substructureName;
260 substructureName =
nullptr;
264 std::map<int, TrackerOfflineValidationSummary::ModuleHistos>& moduleHist,
267 std::map<std::string, std::string>& substructureName,
269 for (std::map<int, TrackerOfflineValidationSummary::ModuleHistos>::iterator it = moduleHist.begin(),
270 itEnd = moduleHist.end();
276 const DetId detId = it->first;
281 unsigned int whichHalfBarrel(1), rawId(detId.
rawId());
282 if ((rawId >= 302056964 && rawId < 302059300) || (rawId >= 302123268 && rawId < 302127140) ||
283 (rawId >= 302189572 && rawId < 302194980))
286 treeMem.
half = whichHalfBarrel;
291 unsigned int whichHalfCylinder(1), rawId(detId.
rawId());
292 if ((rawId >= 352394500 && rawId < 352406032) || (rawId >= 352460036 && rawId < 352471568) ||
293 (rawId >= 344005892 && rawId < 344017424) || (rawId >= 344071428 && rawId < 344082960))
294 whichHalfCylinder = 2;
297 treeMem.
half = whichHalfCylinder;
302 unsigned int whichHalfShell(1), rawId(detId.
rawId());
303 if ((rawId >= 369120484 && rawId < 369120688) || (rawId >= 369121540 && rawId < 369121776) ||
304 (rawId >= 369136932 && rawId < 369137200) || (rawId >= 369137988 && rawId < 369138288) ||
305 (rawId >= 369153396 && rawId < 369153744) || (rawId >= 369154436 && rawId < 369154800) ||
306 (rawId >= 369169844 && rawId < 369170256) || (rawId >= 369170900 && rawId < 369171344) ||
307 (rawId >= 369124580 && rawId < 369124784) || (rawId >= 369125636 && rawId < 369125872) ||
308 (rawId >= 369141028 && rawId < 369141296) || (rawId >= 369142084 && rawId < 369142384) ||
309 (rawId >= 369157492 && rawId < 369157840) || (rawId >= 369158532 && rawId < 369158896) ||
310 (rawId >= 369173940 && rawId < 369174352) || (rawId >= 369174996 && rawId < 369175440))
314 treeMem.
half = whichHalfShell;
352 treeMem.
posX = gPModule.
x();
353 treeMem.
posY = gPModule.
y();
354 treeMem.
posZ = gPModule.
z();
359 LocalPoint lUDirection(1., 0., 0.), lVDirection(0., 1., 0.), lWDirection(0., 0., 1.);
361 gWDirection = surface.
toGlobal(lWDirection);
362 double dR(999.),
dPhi(999.), dZ(999.);
365 dR = gWDirection.perp() - gPModule.
perp();
367 dZ = gVDirection.z() - gPModule.
z();
375 dZ = gWDirection.z() - gPModule.
z();
381 dR = gVDirection.perp() - gPModule.
perp();
383 dZ = gWDirection.z() - gPModule.
z();
406 treeMem.
entries = static_cast<UInt_t>(it->second.ResXprimeHisto->GetEntries());
407 treeMem.
meanX = it->second.ResXprimeHisto->GetMean();
408 treeMem.
rmsX = it->second.ResXprimeHisto->GetRMS();
413 std::pair<float, float> fitResult1 = this->
fitResiduals(it->second.ResXprimeHisto);
414 treeMem.
fitMeanX = fitResult1.first;
417 std::pair<float, float> fitResult2 = this->
fitResiduals(it->second.NormResXprimeHisto);
425 int numberOfBins = it->second.ResXprimeHisto->GetNbinsX();
429 it->second.ResXprimeHisto->GetBinContent(0) + it->second.ResXprimeHisto->GetBinContent(
numberOfBins + 1);
431 treeMem.
meanNormX = it->second.NormResXprimeHisto->GetMean();
432 treeMem.
rmsNormX = it->second.NormResXprimeHisto->GetRMS();
435 it->second.NormResXprimeHisto->GetStats(
stats);
441 treeMem.
histNameX = it->second.ResXprimeHisto->GetName();
442 treeMem.
histNameNormX = it->second.NormResXprimeHisto->GetName();
445 if (it->second.ResHisto && it->second.NormResHisto) {
446 treeMem.
meanLocalX = it->second.ResHisto->GetMean();
447 treeMem.
rmsLocalX = it->second.ResHisto->GetRMS();
456 if (it->second.ResYprimeHisto) {
457 TH1*
h = it->second.ResYprimeHisto;
458 treeMem.
meanY =
h->GetMean();
459 treeMem.
rmsY =
h->GetRMS();
462 std::pair<float, float> fitMeanSigma = this->
fitResiduals(h);
463 treeMem.
fitMeanY = fitMeanSigma.first;
473 if (it->second.NormResYprimeHisto) {
474 TH1*
h = it->second.NormResYprimeHisto;
482 std::pair<float, float> fitMeanSigma = this->
fitResiduals(h);
496 std::map<std::string, std::string>& substructureName) {
497 std::stringstream
histDir, sSubdetName;
507 else if (treeMem.
rod > 15)
511 }
else if (layer == 2) {
514 else if (treeMem.
rod > 24)
518 }
else if (layer == 3) {
521 else if (treeMem.
rod > 33)
526 componentName =
"Pixel";
527 sSubdetName <<
"TPBBarrel_1";
528 histDir << componentName <<
"/" << sSubdetName.str() <<
"/TPBHalfBarrel_" << treeMem.
half <<
"/TPBLayer_"
531 unsigned int side(treeMem.
side), half(treeMem.
half), blade(0);
535 blade = treeMem.
blade - 6;
536 else if (treeMem.
blade > 18)
537 blade = treeMem.
blade - 12;
539 blade = treeMem.
blade;
540 componentName =
"Pixel";
541 sSubdetName <<
"TPEEndcap_" << side;
542 histDir << componentName <<
"/" << sSubdetName.str() <<
"/TPEHalfCylinder_" << treeMem.
half <<
"/TPEHalfDisk_"
543 << treeMem.
layer <<
"/TPEBlade_" << blade <<
"/TPEPanel_" << treeMem.
panel;
544 wheelOrLayer =
"_wheel_";
550 string = treeMem.
rod - 13;
551 else if (surface == 2)
552 string = treeMem.
rod - 15;
556 string = treeMem.
rod - 17;
557 else if (surface == 2)
558 string = treeMem.
rod - 19;
562 string = treeMem.
rod - 22;
563 else if (surface == 2)
564 string = treeMem.
rod - 23;
568 string = treeMem.
rod - 26;
569 else if (surface == 2)
570 string = treeMem.
rod - 28;
573 string = treeMem.
rod;
574 std::stringstream detString;
576 detString <<
"/Det_" << treeMem.
module;
579 componentName =
"Strip";
580 sSubdetName <<
"TIBBarrel_1";
581 histDir << componentName <<
"/" << sSubdetName.str() <<
"/TIBHalfBarrel_" << treeMem.
side <<
"/TIBLayer_"
582 << treeMem.
layer <<
"/TIBHalfShell_" << treeMem.
half <<
"/TIBSurface_" << treeMem.
outerInner
583 <<
"/TIBString_" <<
string << detString.str();
585 unsigned int side(treeMem.
side), outerInner(0);
592 std::stringstream detString;
594 detString <<
"/Det_" << treeMem.
module;
597 componentName =
"Strip";
598 sSubdetName <<
"TIDEndcap_" << side;
599 histDir << componentName <<
"/" << sSubdetName.str() <<
"/TIDDisk_" << treeMem.
layer <<
"/TIDRing_" << treeMem.
ring
600 <<
"/TIDSide_" << outerInner << detString.str();
601 wheelOrLayer =
"_wheel_";
603 std::stringstream detString;
605 detString <<
"/Det_" << treeMem.
module;
608 componentName =
"Strip";
609 sSubdetName <<
"TOBBarrel_4";
610 histDir << componentName <<
"/" << sSubdetName.str() <<
"/TOBHalfBarrel_" << treeMem.
side <<
"/TOBLayer_"
611 << treeMem.
layer <<
"/TOBRod_" << treeMem.
rod << detString.str();
613 unsigned int side(0), outerInner(0),
ring(0);
614 if (treeMem.
side == 1)
616 else if (treeMem.
side == 2)
624 else if (treeMem.
layer == 7 || treeMem.
layer == 8)
626 else if (treeMem.
layer == 9)
630 std::stringstream detString;
632 detString <<
"/Det_" << treeMem.
module;
635 componentName =
"Strip";
636 sSubdetName <<
"TECEndcap_" << side;
637 histDir << componentName <<
"/" << sSubdetName.str() <<
"/TECDisk_" << treeMem.
layer <<
"/TECSide_" << outerInner
638 <<
"/TECPetal_" << treeMem.
petal <<
"/TECRing_" <<
ring << detString.str();
639 wheelOrLayer =
"_wheel_";
642 substructureName[
"component"] = componentName;
643 substructureName[
"subdet"] = sSubdetName.str();
645 std::stringstream histName;
646 histName <<
"residuals_subdet_" << treeMem.
subDetId << wheelOrLayer << treeMem.
layer <<
"_module_"
655 <<
"Problem with names in input file produced in TrackerOfflineValidation ...\n"
656 <<
"This histogram should exist in every configuration, "
657 <<
"but no histogram with name " <<
fullPath <<
" is found!";
680 std::pair<float, float> fitResult(9999., 9999.);
681 if (!
hist ||
hist->GetEntries() < 20)
685 float sigma =
hist->GetRMS();
693 sigma =
func.GetParameter(2);
698 if (0 ==
hist->Fit(&
func,
"Q0LR")) {
699 if (
hist->GetFunction(
func.GetName())) {
700 hist->GetFunction(
func.GetName())->ResetBit(TF1::kNotDraw);
702 fitResult.first =
func.GetParameter(1);
703 fitResult.second =
func.GetParameter(2);
707 edm::LogWarning(
"Alignment") <<
"@SUB=TrackerOfflineValidation::fitResiduals"
708 <<
"Caught this exception during ROOT fit: " <<
e.what();
718 double*
x =
new double[
nbins];
719 double*
y =
new double[
nbins];
741 std::map<std::string, std::string>* substructureName =
nullptr;
742 tree.SetBranchAddress(
"TkOffTreeVariables", &treeMemPtr);
743 tree.SetBranchAddress(
"SubstructureName", &substructureName);
746 for (
unsigned int iSubdet = 1; iSubdet < 7; ++iSubdet) {
749 std::vector<unsigned int> treeEntries;
750 for (
unsigned int iSide = 1; iSide < 3; ++iSide) {
755 for (
int iTree = 0; iTree <
tree.GetEntries(); ++iTree) {
756 tree.GetEntry(iTree);
760 if (treeMemPtr->
subDetId == iSubdet) {
764 treeEntries.push_back(iTree);
765 if (hierarchyName.length() == 0) {
766 hierarchyName = (*substructureName)[
"subdet"];
767 componentName = (*substructureName)[
"component"];
787 edm::LogInfo(
"TrackerOfflineValidationSummary") <<
"Harvesting histograms will be booked for "
792 std::stringstream dmrXprimeHistoName, dmrYprimeHistoName, dmrXprimeHistoTitle, dmrYprimeHistoTitle;
793 dmrXprimeHistoName <<
"h_DmrXprime_" << iHier->hierarchyName;
794 dmrYprimeHistoName <<
"h_DmrYprime_" << iHier->hierarchyName;
795 dmrXprimeHistoTitle <<
"DMR for " << iHier->hierarchyName <<
";<#DeltaX> [cm];# modules";
796 dmrYprimeHistoTitle <<
"DMR for " << iHier->hierarchyName <<
";<#DeltaY> [cm];# modules";
799 if (directoryString.length() != 0)
800 directoryString +=
"/";
801 directoryString += iHier->componentName;
806 if (iHier->componentName ==
"Pixel") {
808 iHier->harvestingHistos.DmrXprime =
809 dbe_->
book1D(dmrXprimeHistoName.str(), dmrXprimeHistoTitle.str(), nBinsX,
xMin,
xMax)->getTH1();
811 iHier->harvestingHistos.DmrYprime =
812 dbe_->
book1D(dmrYprimeHistoName.str(), dmrYprimeHistoTitle.str(), nBinsX,
xMin,
xMax)->getTH1();
813 }
else if (iHier->componentName ==
"Strip") {
815 iHier->harvestingHistos.DmrXprime =
816 dbe_->
book1D(dmrXprimeHistoName.str(), dmrXprimeHistoTitle.str(), nBinsX,
xMin,
xMax)->getTH1();
820 iHier->harvestingHistos.DmrYprime =
821 dbe_->
book1D(dmrYprimeHistoName.str(), dmrYprimeHistoTitle.str(), nBinsX,
xMin,
xMax)->getTH1();
829 double& upperBoundX)
const {
838 std::map<std::string, std::string>* substructureName =
nullptr;
839 tree.SetBranchAddress(
"TkOffTreeVariables", &treeMemPtr);
840 tree.SetBranchAddress(
"SubstructureName", &substructureName);
842 const unsigned int minEntriesPerModule(
parSet_.
getParameter<
unsigned int>(
"minEntriesPerModuleForDmr"));
844 <<
"Median of a module is added to DMR plots if it contains at least " << minEntriesPerModule <<
" hits";
849 for (std::vector<unsigned int>::const_iterator iTreeEntries = iHier->treeEntries.begin();
850 iTreeEntries != iHier->treeEntries.end();
852 tree.GetEntry(*iTreeEntries);
853 if (treeMemPtr->
entries < minEntriesPerModule)
855 iHier->harvestingHistos.DmrXprime->Fill(treeMemPtr->
medianX);
856 if (iHier->harvestingHistos.DmrYprime)
857 iHier->harvestingHistos.DmrYprime->Fill(treeMemPtr->
medianY);