23 TGaxis::SetMaxDigits(4);
29 TH1::StatOverflows(kTRUE);
87 std::cout <<
"Can't load a root file after opening the summary file!" << std::endl;
169 options.ReplaceAll(
" ",
"").ToLower();
192 std::cout <<
"Can't set the output dir after opening the summary file!" << std::endl;
204 gStyle->SetOptStat(11111);
205 gStyle->SetOptFit(0000);
207 TCanvas*
c =
new TCanvas(
"c",
"c");
208 c->SetTopMargin(0.15);
244 TH1* sumHisto =
nullptr;
246 if (tmpcounter == 0) {
247 TFile*
f = (*it)->getFile();
248 sumHisto = (TH1*)
f->FindKeyAny(
histoName)->ReadObj();
249 sumHisto->SetLineColor(tmpcounter + 1);
250 sumHisto->SetLineStyle(tmpcounter + 1);
251 sumHisto->GetFunction(
"tmp")->SetBit(TF1::kNotDraw);
262 sumHisto = (TH1*)(*it)->getFile()->FindObjectAny(
histoName);
263 sumHisto->SetLineColor(tmpcounter + 1);
264 sumHisto->SetLineStyle(tmpcounter + 1);
265 sumHisto->GetFunction(
"tmp")->SetBit(TF1::kNotDraw);
271 TObject* statObj = sumHisto->GetListOfFunctions()->FindObject(
"stats");
273 TPaveStats*
stats =
static_cast<TPaveStats*
>(statObj);
274 stats->SetLineColor(tmpcounter + 1);
275 stats->SetTextColor(tmpcounter + 1);
276 stats->SetFillColor(10);
277 stats->SetX1NDC(0.91 - tmpcounter * 0.1);
278 stats->SetX2NDC(0.15);
280 stats->SetY2NDC(0.10);
281 sumHisto->Draw(
"sames");
302 TCanvas*
c =
new TCanvas(
"c",
"c", 1200, 400);
312 tree->Draw(
"entries:posR:posZ",
"",
"COLZ2Prof");
314 tree->Draw(
"entries:posY:posX",
"",
"COLZ2Prof");
316 tree->Draw(
"entries:posR:posPhi",
"",
"COLZ2Prof");
319 sprintf(PlotName,
"%s/%s.png",
outputDir.c_str(), histName_.c_str());
321 sprintf(PlotName,
"%s/%s.eps",
outputDir.c_str(), histName_.c_str());
323 sprintf(PlotName,
"%s/%s.pdf",
outputDir.c_str(), histName_.c_str());
325 sprintf(PlotName,
"%s/%s.root",
outputDir.c_str(), histName_.c_str());
335 float plotVariable_cut,
339 gStyle->SetOptStat(111111);
340 gStyle->SetStatY(0.9);
343 TCanvas*
c1 =
new TCanvas(
"canv",
"canv", 800, 500);
351 tree->SetBranchAddress(
"TkOffTreeVariables", &treeMem);
353 Long64_t nentries =
tree->GetEntriesFast();
355 for (Long64_t
i = 0;
i < nentries;
i++) {
381 if (
f->FindKeyAny(treeMem->
histNameX.c_str()) !=
nullptr) {
383 (TH1*)
f->FindKeyAny(treeMem->
histNameX.c_str())->ReadObj();
384 gStyle->SetOptFit(0111);
385 std::cout <<
"hist name " <<
h->GetName() << std::endl;
387 TString
path = (
char*)strstr(gDirectory->GetPath(),
"TrackerOfflineValidation");
395 TPaveText*
text =
new TPaveText(0, 0.95, 0.99, 0.99);
397 text->SetFillColor(0);
398 text->SetShadowColor(0);
399 text->SetBorderSize(0);
404 TPad* subpad = (TPad*)
c1->GetPad(1);
405 subpad->SetPad(0, 0, 0.5, 0.94);
413 TPad* subpad2 = (TPad*)
c1->GetPad(2);
414 subpad2->SetPad(0.5, 0, 0.99, 0.94);
420 std::cout <<
"There are no residual histograms on module level stored!" << std::endl;
421 std::cout <<
"Please make sure that moduleLevelHistsTransient = cms.bool(False) in the validation job!" 429 std::cout <<
"no bad modules found" << std::endl;
444 TFile* first_source = (TFile*)
sourcelist->First();
445 std::cout << first_source->GetName() << std::endl;
446 TDirectoryFile*
d = (TDirectoryFile*)first_source->Get(
treeBaseDir.c_str());
447 treeList->Add((TTree*)(*d).Get(
"TkOffVal"));
450 TFile* nextsource = (TFile*)
sourcelist->After(first_source);
452 std::cout << nextsource->GetName() << std::endl;
453 d = (TDirectoryFile*)nextsource->Get(
"TrackerOfflineValidation");
455 treeList->Add((TTree*)(*d).Get(
"TkOffVal"));
457 nextsource = (TFile*)
sourcelist->After(nextsource);
468 std::cout <<
"-------- plotSurfaceShapes called with " <<
options << std::endl;
471 else if (
options ==
"coarse") {
488 if (residType.empty()) {
494 int bkperrorx = gStyle->GetErrorX();
495 gStyle->SetErrorX(1);
500 bool plotLayers =
false;
504 TRegexp layer_re(
"layer=[0-9]+");
506 if (
options.find(
"layers") != std::string::npos) {
511 std::cerr <<
"Warning: option 'layers' overrides 'layer=N'" << std::endl;
514 plotLayerN = atoi(substr.c_str());
518 TRegexp subdet_re(
"subdet=[1-6]+");
521 plotSubDetN = atoi(substr.c_str());
524 gStyle->SetOptStat(0);
526 TCanvas
c(
"canv",
"canv");
531 for (
int iSubDet = 1; iSubDet <= 6; ++iSubDet) {
533 bool isTEC = (iSubDet == 6);
536 if (plotSubDetN != 0 && iSubDet != plotSubDetN)
546 int minlayer = plotLayers ? 1 : plotLayerN;
549 int maxlayerphase0 = plotLayers ?
numberOfLayers(0, iSubDet) : plotLayerN;
553 for (
int iTEC = 0; iTEC < 2; iTEC++) {
554 if (!isTEC && iTEC == 0)
560 sprintf(
selection,
"subDetId==%d", iSubDet);
562 sprintf(
selection,
"subDetId==%d && layer == %d", iSubDet,
layer);
565 sprintf(
selection,
"subDetId==%d && ring <= 4", iSubDet);
567 sprintf(
selection,
"subDetId==%d && ring > 4", iSubDet);
594 TString secondline =
"";
597 if (iSubDet == 4 || iSubDet == 6)
598 secondline =
"disc ";
600 secondline =
"layer ";
602 secondline += Form(
"%d",
layer);
605 if (isTEC && iTEC == 0)
606 secondline += TString(
"R1-4");
607 if (isTEC && iTEC > 0)
608 secondline += TString(
"R5-7");
611 TLegend*
legend =
nullptr;
614 if (!hs || hs->GetHists() ==
nullptr || hs->GetHists()->GetSize() == 0) {
615 std::cout <<
"No histogram for " << subDetName <<
", perhaps not enough data? Creating default histogram." 618 hs =
new THStack(
"hstack",
"");
620 TProfile* defhist =
new TProfile(
"defhist",
"Empty default histogram", 100, -1, 1, -1, 1);
624 hs->Draw(
"nostack PE");
630 TH1* firstHisto = (TH1*)hs->GetHists()->First();
631 TString xName = firstHisto->GetXaxis()->GetTitle();
632 TString yName = firstHisto->GetYaxis()->GetTitle();
633 hs->GetHistogram()->GetXaxis()->SetTitleColor(kBlack);
634 hs->GetHistogram()->GetXaxis()->SetTitle(xName);
635 hs->GetHistogram()->GetYaxis()->SetTitleColor(kBlack);
637 yName.ReplaceAll(
"cm",
"#mum");
638 hs->GetHistogram()->GetYaxis()->SetTitle(yName);
648 if (iSubDet == 4 || iSubDet == 6)
655 if (isTEC && iTEC == 0)
658 if (isTEC && iTEC > 0)
664 c.Print((
plotName.str() +
".png").c_str());
665 c.Print((
plotName.str() +
".eps").c_str());
666 c.Print((
plotName.str() +
".pdf").c_str());
669 TFile
f((
plotName.str() +
".root").c_str(),
"recreate");
678 gStyle->SetErrorX(bkperrorx);
695 std::size_t findres =
variable.find(
',');
696 if (findres != std::string::npos) {
721 TRegexp layer_re(
"layer=[0-9]+");
722 bool plotPlain =
false, plotSplits =
false, plotLayers =
false;
725 if (
options.find(
"plain") != std::string::npos) {
728 if (
options.find(
"split") != std::string::npos) {
731 if (
options.find(
"layers") != std::string::npos) {
736 std::cerr <<
"Warning: option 'layers' overrides 'layer=N'" << std::endl;
739 plotLayerN = atoi(substr.c_str());
745 if (!plotPlain && !plotSplits) {
751 static bool plotSplitsFor[6] = {
true,
true,
true,
false,
true,
false};
755 gStyle->SetOptStat(0);
757 TCanvas
c(
"canv",
"canv");
770 plotinfo.
min = -0.001;
771 plotinfo.
max = 0.001;
774 plotinfo.
min = -0.005;
775 plotinfo.
max = 0.005;
779 plotinfo.
min = -0.0005;
780 plotinfo.
max = 0.0005;
782 plotinfo.
nbins = 100;
783 plotinfo.
min = -0.001;
784 plotinfo.
max = 0.001;
789 plotinfo.
min = -0.0005;
790 plotinfo.
max = 0.0005;
792 plotinfo.
nbins = 100;
793 plotinfo.
min = -0.001;
794 plotinfo.
max = 0.001;
797 plotinfo.
nbins = 100;
800 }
else if (
variable ==
"meanNormY") {
801 plotinfo.
nbins = 100;
805 plotinfo.
nbins = 100;
809 plotinfo.
nbins = 100;
812 }
else if (
variable ==
"rmsNormX") {
813 plotinfo.
nbins = 100;
816 }
else if (
variable ==
"rmsNormY") {
817 plotinfo.
nbins = 100;
822 plotinfo.
nbins = 100;
827 for (
int i = 1;
i <= 6; ++
i) {
838 plotinfo.
plotSplits = plotSplits && plotSplitsFor[
i - 1];
862 double legendY = 0.80;
864 legendY -= 0.01 * (nPlots - 3);
870 std::cerr <<
"Warning: Huge legend!" << std::endl;
874 THStack hstack(
"hstack",
"hstack");
877 plotinfo.
legend =
new TLegend(0.17, legendY, 0.85, 0.88);
878 plotinfo.
legend->SetNColumns(2);
883 plotinfo.
legend->SetFillStyle(0);
884 plotinfo.
hstack = &hstack;
885 plotinfo.
h = plotinfo.
h1 = plotinfo.
h2 =
nullptr;
900 stringsubdet =
"BPIX";
903 stringsubdet =
"FPIX";
906 stringsubdet =
"TIB";
909 stringsubdet =
"TID";
912 stringsubdet =
"TOB";
915 stringsubdet =
"TEC";
921 plotinfo.
h1 = plotinfo.
h2 = plotinfo.
h =
nullptr;
923 int minlayer = plotLayers ? 1 : plotLayerN;
961 if (plotinfo.
h1 !=
nullptr && plotinfo.
h2 !=
nullptr && !plotinfo.
plotPlain) {
962 std::ostringstream
legend;
972 float deltamu =
factor * (plotinfo.
h2->GetMean(1) - plotinfo.
h1->GetMean(1));
976 if (
i == 4 ||
i == 6)
982 plotinfo.
legend->AddEntry(static_cast<TObject*>(
nullptr),
legend.str().c_str(),
"");
985 plotinfo.
legend->AddEntry(static_cast<TObject*>(
nullptr),
legend.str().c_str(),
"");
987 if ((plotinfo.
variable ==
"medianX" || plotinfo.
variable ==
"medianY") && !plotLayers &&
layer == 0) {
1001 if (hstack.GetHists() !=
nullptr && hstack.GetHists()->GetSize() != 0) {
1002 hstack.Draw(
"nostack");
1003 hstack.SetMaximum(plotinfo.
maxY * 1.3);
1010 plotinfo.
h =
new TH1F(
"defhist",
"Empty default histogram", plotinfo.
nbins, plotinfo.
min, plotinfo.
max);
1011 plotinfo.
h->SetMaximum(10);
1012 if (plotinfo.
variable.find(
"Norm") == std::string::npos)
1067 if (plotPlain && !plotSplits) {
1069 }
else if (!plotPlain && plotSplits) {
1074 if (
i == 4 ||
i == 6)
1079 if (plotLayerN > 0) {
1081 if (
i == 4 ||
i == 6)
1090 c.Print((
plotName.str() +
".png").c_str());
1091 c.Print((
plotName.str() +
".eps").c_str());
1092 c.Print((
plotName.str() +
".pdf").c_str());
1095 TFile
f((
plotName.str() +
".root").c_str(),
"recreate");
1104 if (!
vmean.empty()) {
1106 if (plotinfo.
variable ==
"medianY")
1109 <<
"latexname=$\\mu_\\text{" << subdet <<
"}";
1110 if (plotinfo.
variable ==
"medianY")
1113 <<
"format={:.3g}\t" 1114 <<
"latexformat=${:.3g}$";
1119 if (!
vrms.empty()) {
1121 if (plotinfo.
variable ==
"medianY")
1124 <<
"latexname=$\\sigma_\\text{" << subdet <<
"}";
1125 if (plotinfo.
variable ==
"medianY")
1128 <<
"format={:.3g}\t" 1129 <<
"latexformat=${:.3g}$";
1130 for (
auto sigma :
vrms)
1136 if (plotinfo.
variable ==
"medianY")
1139 <<
"latexname=$\\Delta\\mu_\\text{" << subdet <<
"}";
1140 if (plotinfo.
variable ==
"medianY")
1143 <<
"format={:.3g}\t" 1144 <<
"latexformat=${:.3g}$";
1151 if (plotinfo.
variable ==
"medianY")
1154 <<
"latexname=$\\sigma\\mu_\\text{" << subdet <<
"}";
1155 if (plotinfo.
variable ==
"medianY")
1158 <<
"format={:.3g}\t" 1159 <<
"latexformat=${:.3g}$";
1165 summaryfile <<
" p_delta_mu_equal_zero_" << subdet;
1166 if (plotinfo.
variable ==
"medianY")
1169 <<
"latexname=$P(\\delta\\mu_\\text{" << subdet <<
"}=0)";
1170 if (plotinfo.
variable ==
"medianY")
1173 <<
"format={:.3g}\t" 1174 <<
"latexformat=${:.3g}$";
1180 summaryfile <<
" alignment_uncertainty_" << subdet;
1181 if (plotinfo.
variable ==
"medianY")
1184 <<
"latexname=$\\sigma_\\text{align}_\\text{" << subdet <<
"}";
1185 if (plotinfo.
variable ==
"medianY")
1188 <<
"format={:.3g}\t" 1189 <<
"latexformat=${:.3g}$";
1196 if (plotinfo.
variable ==
"medianY")
1199 <<
"latexname=$P(\\mu_\\text{" << subdet <<
"}=\\mu_\\text{ideal})";
1200 if (plotinfo.
variable ==
"medianY")
1203 <<
"format={:.3g}\t" 1204 <<
"latexformat=${:.3g}$";
1211 if (plotinfo.
variable ==
"medianY")
1214 <<
"latexname=$P(\\sigma_\\text{" << subdet <<
"}=\\sigma_\\text{ideal})";
1215 if (plotinfo.
variable ==
"medianY")
1218 <<
"format={:.3g}\t" 1219 <<
"latexformat=${:.3g}$";
1232 Bool_t errorflag = kFALSE;
1233 TFile* fi1 = TFile::Open(
inputFile,
"read");
1234 if (fi1 !=
nullptr) {
1235 if (fi1->GetDirectory(
"TrackerOfflineValidation/GlobalTrackVariables") ==
nullptr) {
1242 std::cout <<
"PlotAlignmentValidation::plotChi2: Can't find GlobalTrackVariables given file," 1243 <<
" no chi^2-plots produced" << std::endl;
1247 auto normchi = fi1->Get<TCanvas>(
"TrackerOfflineValidation/GlobalTrackVariables/h_normchi2");
1249 normchi->GetFrame()->ResetBit(kCanDelete);
1251 auto chiprob = fi1->Get<TCanvas>(
"TrackerOfflineValidation/GlobalTrackVariables/h_chi2Prob");
1253 chiprob->GetFrame()->ResetBit(kCanDelete);
1255 if (normchi ==
nullptr || chiprob ==
nullptr) {
1259 std::cout <<
"PlotAlignmentValidation::plotChi2: Can't find data from given file," 1260 <<
" no chi^2-plots produced" << std::endl;
1264 TLegend*
legend =
nullptr;
1265 for (
auto primitive : *normchi->GetListOfPrimitives()) {
1278 bool foundit =
false;
1279 for (
auto entry : *
legend->GetListOfPrimitives()) {
1280 TLegendEntry* legendentry =
dynamic_cast<TLegendEntry*
>(
entry);
1282 TH1*
h =
dynamic_cast<TH1*
>(legendentry->GetObject());
1285 if (legendentry->GetLabel() ==
title &&
h->GetLineColor() == color &&
h->GetLineStyle() ==
style) {
1302 normchi->Print((
outputDir +
"/h_normchi2.png").c_str());
1303 chiprob->Print((
outputDir +
"/h_chi2Prob.png").c_str());
1304 normchi->Print((
outputDir +
"/h_normchi2.eps").c_str());
1305 chiprob->Print((
outputDir +
"/h_chi2Prob.eps").c_str());
1306 normchi->Print((
outputDir +
"/h_normchi2.pdf").c_str());
1307 chiprob->Print((
outputDir +
"/h_chi2Prob.pdf").c_str());
1310 TFile fi2((
outputDir +
"/h_normchi2.root").c_str(),
"recreate");
1314 TFile fi3((
outputDir +
"/h_chi2Prob.root").c_str(),
"recreate");
1324 const TString&
selection,
const TString& residType, TLegend** myLegend,
bool printModuleIds,
bool validforphase0) {
1338 ResidType rType = xPrimeRes;
1339 if (residType ==
"xPrime")
1341 else if (residType ==
"yPrime")
1343 else if (residType ==
"xPrimeNorm")
1344 rType = xPrimeNormRes;
1345 else if (residType ==
"yPrimeNorm")
1346 rType = yPrimeNormRes;
1347 else if (residType ==
"x")
1349 else if (residType ==
"y")
1351 else if (residType ==
"xNorm")
1354 else if (residType ==
"ResXvsXProfile")
1355 rType = ResXvsXProfile;
1356 else if (residType ==
"ResYvsXProfile")
1357 rType = ResYvsXProfile;
1358 else if (residType ==
"ResXvsYProfile")
1359 rType = ResXvsYProfile;
1360 else if (residType ==
"ResYvsYProfile")
1361 rType = ResYvsYProfile;
1363 std::cout <<
"PlotAlignmentValidation::addHists: Unknown residual type " << residType << std::endl;
1367 std::cout <<
"PlotAlignmentValidation::addHists: using selection " <<
selection << std::endl;
1368 THStack* retHistoStack =
new THStack(
"hstack",
"");
1369 if (myLegend !=
nullptr)
1370 if (*myLegend ==
nullptr) {
1371 *myLegend =
new TLegend(0.17, 0.80, 0.85, 0.88);
1374 for (std::vector<TkOfflineVariables*>::iterator itSourceFile =
sourceList.begin(); itSourceFile !=
sourceList.end();
1376 std::vector<TString> histnames;
1378 TFile*
f = (*itSourceFile)->getFile();
1379 TTree*
tree = (*itSourceFile)->getTree();
1380 int myLineColor = (*itSourceFile)->getLineColor();
1381 int myLineStyle = (*itSourceFile)->getLineStyle();
1382 TString myLegendName = (*itSourceFile)->getName();
1385 Long64_t nentries =
tree->GetEntriesFast();
1387 std::cout <<
"PlotAlignmentValidation::addHists: no tree or no file" << std::endl;
1391 bool histnamesfilled =
false;
1392 int phase = (
bool)(
f->Get(
"TrackerOfflineValidation/Pixel/P1PXBBarrel_1"));
1393 if (residType.Contains(
"Res") && residType.Contains(
"Profile")) {
1394 TString basename = TString(residType)
1395 .ReplaceAll(
"Res",
"p_res")
1396 .ReplaceAll(
"vs",
"")
1397 .ReplaceAll(
"Profile",
"_");
1400 histnames.push_back(TString(basename) +=
"P1PXBBarrel_1");
1402 histnames.push_back(TString(basename) +=
"TPBBarrel_1");
1403 histnamesfilled =
true;
1404 }
else if (
selection ==
"subDetId==2") {
1406 histnames.push_back(TString(basename) +=
"P1PXECEndcap_2");
1407 histnames.push_back(TString(basename) +=
"P1PXECEndcap_3");
1409 histnames.push_back(TString(basename) +=
"TPEEndcap_2");
1410 histnames.push_back(TString(basename) +=
"TPEEndcap_3");
1412 histnamesfilled =
true;
1413 }
else if (
selection ==
"subDetId==3") {
1414 histnames.push_back(TString(basename) +=
"TIBBarrel_1");
1415 histnamesfilled =
true;
1416 }
else if (
selection ==
"subDetId==4") {
1417 histnames.push_back(TString(basename) +=
"TIDEndcap_2");
1418 histnames.push_back(TString(basename) +=
"TIDEndcap_3");
1419 histnamesfilled =
true;
1420 }
else if (
selection ==
"subDetId==5") {
1421 histnames.push_back(TString(basename) +=
"TOBBarrel_4");
1422 histnamesfilled =
true;
1423 }
else if (
selection ==
"subDetId==6") {
1424 histnames.push_back(TString(basename) +=
"TECEndcap_5");
1425 histnames.push_back(TString(basename) +=
"TECEndcap_6");
1426 histnamesfilled =
true;
1427 }
else if (
selection ==
"subDetId==6 && ring <= 4") {
1429 for (
int iEndcap = 5; iEndcap <= 6; iEndcap++)
1430 for (
int iDisk = 1; iDisk <= 9; iDisk++)
1431 for (
int iSide = 1; iSide <= 2; iSide++)
1432 for (
int iPetal = 1; iPetal <= 8; iPetal++)
1433 for (
int iRing = 1; iRing <= 4 - (iDisk >= 4) - (iDisk >= 7) - (iDisk >= 9); iRing++)
1437 std::stringstream
s;
1438 s <<
"TrackerOfflineValidation/Strip/TECEndcap_" << iEndcap <<
"/TECDisk_" << iDisk <<
"/TECSide_" 1439 << iSide <<
"/TECPetal_" << iPetal <<
"/" << basename <<
"TECRing_" << iRing;
1440 histnames.push_back(TString(
s.str()));
1442 histnamesfilled =
true;
1443 }
else if (
selection ==
"subDetId==6 && ring > 4") {
1445 for (
int iEndcap = 5; iEndcap <= 6; iEndcap++)
1446 for (
int iDisk = 1; iDisk <= 9; iDisk++)
1447 for (
int iSide = 1; iSide <= 2; iSide++)
1448 for (
int iPetal = 1; iPetal <= 8; iPetal++)
1449 for (
int iRing = 5 - (iDisk >= 4) - (iDisk >= 7) - (iDisk >= 9);
1450 iRing <= 7 - (iDisk >= 4) - (iDisk >= 7) - (iDisk >= 9);
1455 std::stringstream
s;
1456 s <<
"TrackerOfflineValidation/Strip/TECEndcap_" << iEndcap <<
"/TECDisk_" << iDisk <<
"/TECSide_" 1457 << iSide <<
"/TECPetal_" << iPetal <<
"/" << basename <<
"TECRing_" << iRing;
1458 histnames.push_back(TString(
s.str()));
1460 histnamesfilled =
true;
1465 if (histnamesfilled && !histnames.empty()) {
1466 nSel = (Long64_t)histnames.size();
1468 if (!histnamesfilled) {
1475 std::cout <<
"PlotAlignmentValidation::addHists: no selected module." << std::endl;
1479 const std::vector<double> selected(
tree->GetV1(),
tree->GetV1() + nSel);
1481 std::vector<double>::const_iterator iterEnt = selected.begin();
1486 tree->SetBranchAddress(
"TkOffTreeVariables", &treeMem);
1487 for (Long64_t
i = 0;
i < nentries;
i++) {
1488 if (
i < *iterEnt - 0.1
1489 || iterEnt == selected.end()) {
1491 }
else if (TMath::Abs(
i - *iterEnt) < 0.11) {
1494 std::cout <<
"Must not happen: " <<
i <<
" " << *iterEnt << std::endl;
1497 if (printModuleIds) {
1528 case ResXvsXProfile:
1531 case ResXvsYProfile:
1534 case ResYvsXProfile:
1537 case ResYvsYProfile:
1541 histnames.push_back(hName);
1545 for (std::vector<TString>::iterator ithistname = histnames.begin(); ithistname != histnames.end(); ++ithistname) {
1546 if (
phase == 0 && !validforphase0)
1549 if (ithistname->Contains(
"/")) {
1550 newHist = (TH1*)
f->Get(*ithistname);
1552 TKey* histKey =
f->FindKeyAny(*ithistname);
1553 newHist = (histKey ?
static_cast<TH1*
>(histKey->ReadObj()) :
nullptr);
1556 std::cout <<
"Hist " << *ithistname <<
" not found in file, break loop." << std::endl;
1559 if (newHist->GetEntries() == 0) {
1563 newHist->SetLineColor(myLineColor);
1564 newHist->SetLineStyle(myLineStyle);
1566 TString
name(newHist->GetName());
1568 for (UInt_t
i2 = 0;
i2 < 3; ++
i2)
1569 pos_ =
name.Index(
"_", pos_ + 1);
1571 h =
static_cast<TH1*
>(newHist->Clone(
"summed_" +
name));
1580 std::cout <<
"PlotAlignmentValidation::addHists" 1581 <<
"Result is merged from " << nSel - nEmpty <<
" hists, " << nEmpty <<
" hists were empty." << std::endl;
1583 if (nSel - nEmpty == 0)
1586 if (myLegend !=
nullptr)
1587 (*myLegend)->AddEntry(
h, myLegendName,
"L");
1589 retHistoStack->Add(
h);
1592 return retHistoStack;
1603 if (!
hist ||
hist->GetEntries() < 20)
1607 float sigma =
hist->GetRMS();
1609 functionname +=
hist->GetName();
1610 TF1*
func =
new TF1(functionname.c_str(),
"gaus",
mean - 2. * sigma,
mean + 2. * sigma);
1612 func->SetLineColor(color);
1613 func->SetLineStyle(2);
1616 sigma =
func->GetParameter(2);
1621 if (0 ==
hist->Fit(
func,
"Q0ILR")) {
1622 if (
hist->GetFunction(
func->GetName())) {
1642 Double_t
xmin =
hist->GetXaxis()->GetXmin();
1643 Double_t
xmax =
hist->GetXaxis()->GetXmax();
1650 TIter
next(canv->GetListOfPrimitives());
1651 TObject*
obj =
nullptr;
1665 TNamed&
hist,
const char* titleX,
const char* titleY,
int subDetId,
bool isSurfaceDeformation, TString secondline) {
1666 std::stringstream title_Xaxis;
1667 std::stringstream title_Yaxis;
1668 TString titleXAxis = titleX;
1669 TString titleYAxis = titleY;
1670 if (titleXAxis !=
"" && titleYAxis !=
"")
1671 std::cout <<
"plot " << titleXAxis <<
" vs " << titleYAxis << std::endl;
1700 if (!isSurfaceDeformation) {
1701 text2 =
new TPaveText(0.7, 0.3, 0.9, 0.6,
"brNDC");
1703 std::cout <<
"Surface Deformation" << std::endl;
1704 text2 =
new TPaveText(0.8, 0.75, 0.9, 0.9,
"brNDC");
1706 text2->SetTextSize(0.06);
1707 text2->SetTextFont(42);
1708 text2->SetFillStyle(0);
1709 text2->SetBorderSize(0);
1710 text2->SetMargin(0.01);
1711 text2->SetTextAlign(12);
1712 text2->AddText(0.01, 0.75, subD);
1713 if (secondline !=
"") {
1714 text2->AddText(0.01, 0.25, secondline);
1724 std::stringstream title_Xaxis;
1725 std::stringstream title_Yaxis;
1726 TString titleXAxis = titleX;
1727 TString titleYAxis = titleY;
1729 if (titleXAxis.Contains(
"Phi"))
1730 title_Xaxis << titleX <<
"[rad]";
1731 else if (titleXAxis.Contains(
"meanX"))
1732 title_Xaxis <<
"#LTx'_{pred}-x'_{hit}#GT[#mum]";
1733 else if (titleXAxis.Contains(
"meanY"))
1734 title_Xaxis <<
"#LTy'_{pred}-y'_{hit}#GT[#mum]";
1735 else if (titleXAxis.Contains(
"rmsX"))
1736 title_Xaxis <<
"RMS(x'_{pred}-x'_{hit})[#mum]";
1737 else if (titleXAxis.Contains(
"rmsY"))
1738 title_Xaxis <<
"RMS(y'_{pred}-y'_{hit})[#mum]";
1739 else if (titleXAxis.Contains(
"meanNormX"))
1740 title_Xaxis <<
"#LTx'_{pred}-x'_{hit}/#sigma#GT";
1741 else if (titleXAxis.Contains(
"meanNormY"))
1742 title_Xaxis <<
"#LTy'_{pred}-y'_{hit}/#sigma#GT";
1743 else if (titleXAxis.Contains(
"rmsNormX"))
1744 title_Xaxis <<
"RMS(x'_{pred}-x'_{hit}/#sigma)";
1745 else if (titleXAxis.Contains(
"rmsNormY"))
1746 title_Xaxis <<
"RMS(y'_{pred}-y'_{hit}/#sigma)";
1747 else if (titleXAxis.Contains(
"meanLocalX"))
1748 title_Xaxis <<
"#LTx_{pred}-x_{hit}#GT[#mum]";
1749 else if (titleXAxis.Contains(
"rmsLocalX"))
1750 title_Xaxis <<
"RMS(x_{pred}-x_{hit})[#mum]";
1751 else if (titleXAxis.Contains(
"meanNormLocalX"))
1752 title_Xaxis <<
"#LTx_{pred}-x_{hit}/#sigma#GT[#mum]";
1753 else if (titleXAxis.Contains(
"rmsNormLocalX"))
1754 title_Xaxis <<
"RMS(x_{pred}-x_{hit}/#sigma)[#mum]";
1755 else if (titleXAxis.Contains(
"medianX"))
1756 title_Xaxis <<
"median(x'_{pred}-x'_{hit})[#mum]";
1757 else if (titleXAxis.Contains(
"medianY"))
1758 title_Xaxis <<
"median(y'_{pred}-y'_{hit})[#mum]";
1760 title_Xaxis << titleX <<
"[cm]";
1763 hist.SetLineColor(color);
1765 hist.SetMarkerStyle(20);
1766 hist.SetMarkerSize(0.8);
1767 hist.SetMarkerColor(color);
1770 hist.GetXaxis()->SetTitle((title_Xaxis.str()).c_str());
1772 double binning = (
hist.GetXaxis()->GetXmax() -
hist.GetXaxis()->GetXmin()) /
hist.GetNbinsX();
1773 title_Yaxis.precision(2);
1775 if (((titleYAxis.Contains(
"layer") || titleYAxis.Contains(
"ring")) && titleYAxis.Contains(
"subDetId")) ||
1776 titleYAxis.Contains(
"#modules")) {
1777 title_Yaxis <<
"number of modules";
1778 if (TString(title_Xaxis.str()).Contains(
"[#mum]"))
1779 title_Yaxis <<
" / " <<
binning <<
" #mum";
1780 else if (TString(title_Xaxis.str()).Contains(
"[cm]"))
1781 title_Yaxis <<
" / " <<
binning <<
" cm";
1783 title_Yaxis <<
" / " <<
binning;
1785 title_Yaxis << titleY <<
"[cm]";
1787 hist.GetYaxis()->SetTitle((title_Yaxis.str()).c_str());
1789 hist.GetXaxis()->SetTitleFont(42);
1790 hist.GetYaxis()->SetTitleFont(42);
1795 std::ostringstream builder;
1796 builder <<
"entries >= " <<
minHits;
1797 builder <<
" && subDetId == " <<
subDetId;
1798 if (direction != 0) {
1800 builder <<
" && zDirection == " << direction;
1802 builder <<
" && rDirection == " << direction;
1806 builder <<
" && layer == " <<
layer;
1808 return builder.str();
1813 std::ostringstream builder;
1814 builder <<
variable <<
">>" << histoname <<
"(" <<
nbins <<
"," <<
min <<
"," <<
max <<
")";
1815 return builder.str();
1823 TF1* fitResults =
nullptr;
1825 h->SetDirectory(
nullptr);
1836 if (direction == 1) {
1839 if (direction == -1) {
1845 linestyle = (linestyle + linestyleplus) % 4 + 1;
1849 linecolor +=
layer - 1;
1857 h->SetLineColor(linecolor);
1858 h->SetLineStyle(linestyle);
1860 if (plotinfo.
maxY <
h->GetMaximum()) {
1861 plotinfo.
maxY =
h->GetMaximum();
1872 std::ostringstream
legend;
1877 if (direction == -1 && plotinfo.
subDetId != 2) {
1878 legend <<
"rDirection < 0";
1879 }
else if (direction == 1 && plotinfo.
subDetId != 2) {
1880 legend <<
"rDirection > 0";
1881 }
else if (direction == -1 && plotinfo.
subDetId == 2) {
1882 legend <<
"zDirection < 0";
1883 }
else if (direction == 1 && plotinfo.
subDetId == 2) {
1884 legend <<
"zDirection > 0";
1901 double mean = 0.0, meanerror = 0.0,
rms = 0.0, rmserror = 0.0;
1902 TString rmsname,
units;
1904 (plotinfo.
h1 !=
nullptr && plotinfo.
h2 !=
nullptr && plotinfo.
plotSplits && plotinfo.
plotPlain && direction == 0);
1908 mean = fitResults->GetParameter(1) * 10000;
1909 meanerror = fitResults->GetParError(1) * 10000;
1910 rms = fitResults->GetParameter(2) * 10000;
1911 rmserror = fitResults->GetParError(2) * 10000;
1915 mean =
h->GetMean(1) * 10000;
1916 meanerror =
h->GetMeanError(1) * 10000;
1917 rms =
h->GetRMS(1) * 10000;
1918 rmserror =
h->GetRMSError(1) * 10000;
1922 }
else if (plotinfo.
variable ==
"meanNormX" || plotinfo.
variable ==
"meanNormY" || plotinfo.
variable ==
"rmsNormX" ||
1924 mean =
h->GetMean(1);
1925 meanerror =
h->GetMeanError(1);
1927 rmserror =
h->GetRMSError(1);
1934 legend <<
" #pm " << meanerror;
1940 legend <<
" " << rmsname <<
" = " <<
rms;
1942 legend <<
" #pm " << rmserror;
1953 TH1F* ideal = (TH1F*)plotinfo.
hstack->GetHists()->At(0);
1954 TH1F*
h = plotinfo.
h;
1955 if (
h->GetRMS() >= ideal->GetRMS()) {
1973 float deltamu =
factor * (plotinfo.
h2->GetMean(1) - plotinfo.
h1->GetMean(1));
1981 if (plotinfo.
h1->GetEntries() && plotinfo.
h2->GetEntries()) {
1989 plotinfo.
legend->AddEntry((TObject*)
nullptr,
legend.str().c_str(),
"");
1990 plotinfo.
legend->AddEntry((TObject*)
nullptr,
"",
"");
1995 legend << (
int)
h->GetEntries() <<
" modules";
1999 legend << (
int)
h->GetEntries() <<
" modules (" 2000 << (
int)
h->GetBinContent(0) + (
int)
h->GetBinContent(
h->GetNbinsX() + 1) <<
" outside range)";
2002 legend << (
int)
h->GetBinContent(0) + (
int)
h->GetBinContent(
h->GetNbinsX() + 1) <<
" modules outside range";
2005 plotinfo.
legend->AddEntry((TObject*)
nullptr,
legend.str().c_str(),
"");
2008 if (plotinfo.
variable.find(
"Norm") == std::string::npos)
2024 TString histoname =
"";
2026 histoname =
"median";
2027 else if (plotinfo.
variable ==
"rmsNormX" || plotinfo.
variable ==
"rmsNormY")
2028 histoname =
"DrmsNR";
2031 histoname.ReplaceAll(
" ",
"_");
2033 histoname += subdet.c_str();
2037 if (subdet ==
"TID" || subdet ==
"TEC")
2038 histoname +=
"_disc";
2040 histoname +=
"_layer";
2043 if (direction == -1) {
2044 histoname +=
"_minus";
2045 }
else if (direction == 1) {
2046 histoname +=
"_plus";
2060 gDirectory->GetObject(histoname.Data(),
h);
2061 if (
h &&
h->GetEntries() > 0) {
2062 if (direction == -1) {
2064 }
else if (direction == 1) {
2072 TTreeReaderValue<Float_t> varToPlot(
reader, plotinfo.
variable.c_str());
2073 TTreeReaderValue<unsigned int> _entries(
reader,
"entries");
2074 TTreeReaderValue<unsigned int> _subDetId(
reader,
"subDetId");
2075 TTreeReaderValue<unsigned int> _moduleId(
reader,
"moduleId");
2076 TTreeReaderValue<Float_t> _zDirection(
reader,
"zDirection");
2077 TTreeReaderValue<Float_t> _rDirection(
reader,
"rDirection");
2078 TTreeReaderValue<unsigned int> _layer(
reader,
"layer");
2080 TFile* fBadModules =
new TFile(badModulesFile_.c_str(),
"READ");
2081 TTree* tBadModules = (TTree*)fBadModules->Get(
"alignTree");
2082 TTreeReader readerBad(tBadModules);
2083 TTreeReaderValue<int> _valid(readerBad,
"valid");
2084 TTreeReaderValue<int> _bad_id(readerBad,
"id");
2085 TTreeReaderValue<double> _bad_lumi(readerBad,
"lumi");
2088 std::ofstream fUsedModules;
2089 fUsedModules.open(
"usedModules.txt",
std::ios::out | std::ios::app);
2098 if (direction != 0) {
2100 if (*_zDirection != direction)
2103 if (*_rDirection != direction)
2111 bool isBadModule =
false;
2112 for (
int ibad = 0; ibad < tBadModules->GetEntries(); ibad++) {
2113 readerBad.SetEntry(ibad);
2115 if (subdet ==
"BPIX" || subdet ==
"FPIX") {
2116 if (*_bad_lumi <= 2.0)
2119 if (*_bad_lumi <= 7.0)
2123 if (*_moduleId ==
uint(*_bad_id))
2129 fUsedModules << *_moduleId <<
"\n";
2131 h->Fill(*varToPlot);
2136 fUsedModules.close();
2137 fBadModules->Close();
2139 h->SetName(histoname.Data());
2144 if (
h &&
h->GetEntries() > 0) {
2145 if (direction == -1) {
2147 }
else if (direction == 1) {
2162 Double_t legendY = 0.80;
2167 int legendsize = hs->GetHists()->GetSize() + hasheader;
2170 legendY -= 0.01 * (legendsize - 3);
2174 if (legendY < 0.6) {
2175 std::cerr <<
"Warning: Huge legend!" << std::endl;
2183 TProfile* prof =
nullptr;
2184 TIter
next(hs->GetHists());
2185 Int_t
index = hasheader;
2186 while ((prof = (TProfile*)
next())) {
2188 Double_t
scale = 10000;
2191 Double_t
stats[6] = {0};
2192 prof->GetStats(
stats);
2194 std::ostringstream legendtext;
2195 legendtext.precision(3);
2197 legendtext <<
": y mean = " <<
stats[4] /
stats[0] *
scale <<
" #mum";
2199 TLegendEntry*
entry = (TLegendEntry*)
legend->GetListOfPrimitives()->At(
index);
2200 if (
entry ==
nullptr)
2201 std::cout <<
"PlotAlignmentValidation::PlotAlignmentValidation::modifySSLegend: Bad legend!" << std::endl;
2203 entry->SetLabel((
entry->GetLabel() + legendtext.str()).c_str());
2208 hs->SetMaximum(hs->GetMaximum(
"nostack PE") * 1.3);
2219 std::vector<double>
diff;
2222 double rmsdiff =
abs(h1->GetRMS() - h2->GetRMS());
2224 double m1 = h1->GetMean();
2225 double m2 = h2->GetMean();
2230 double test_mean = 0;
2231 for (
int i = 0;
i < numSamples;
i++) {
2234 for (
int i = 0;
i < h1->GetEntries();
i++) {
2235 d1 += h1->GetRandom() - m1;
2237 for (
int i = 0;
i < h2->GetEntries();
i++) {
2238 d2 += h2->GetRandom() +
m2;
2240 d1 /= h1->GetEntries();
2241 d2 /= h2->GetEntries();
2243 test_mean +=
abs(
d1 - d2 - rmsdiff);
2245 test_mean /= numSamples;
2249 for (
double d :
diff) {
2267 std::vector<double>
diff;
2270 double meandiff =
abs(h1->GetMean() - h2->GetMean());
2275 double test_mean = 0;
2276 for (
int i = 0;
i < numSamples;
i++) {
2279 for (
int i = 0;
i < h1->GetEntries();
i++) {
2280 d1 += h1->GetRandom();
2282 for (
int i = 0;
i < h2->GetEntries();
i++) {
2283 d2 += h2->GetRandom();
2285 d1 /= h1->GetEntries();
2286 d2 /= h2->GetEntries();
2287 diff.push_back(
abs(
d1 - d2 - meandiff));
2288 test_mean +=
abs(
d1 - d2 - meandiff);
2290 test_mean /= numSamples;
2294 for (
double d :
diff) {
2305 return 2 * (1 - ROOT::Math::tdistribution_cdf(
abs(
t),
v));
2315 auto t = (TTree*)
f->Get(
"TrackerOfflineValidation/TkOffVal");
2318 t->SetBranchAddress(
"TkOffTreeVariables", &
variables);
2319 unsigned int number_of_entries =
t->GetEntries();
2320 for (
unsigned int i = 0;
i < number_of_entries;
i++) {
2329 std::vector<TH1*>
h;
2331 auto h1 = (TH1*)
f->FindObjectAny(histnamex);
2332 auto h2 = (TH1*)
f->FindObjectAny(histnamey);
2334 h1->SetDirectory(
nullptr);
2335 h2->SetDirectory(
nullptr);
2344 TCanvas* cx =
new TCanvas(
"x_residual");
2345 TCanvas* cy =
new TCanvas(
"y_residual");
2346 TLegend* legendx =
new TLegend(0.55, 0.7, 1, 0.9);
2347 TLegend* legendy =
new TLegend(0.55, 0.7, 1, 0.9);
2349 legendx->SetTextSize(0.016);
2350 legendx->SetTextAlign(12);
2351 legendy->SetTextSize(0.016);
2352 legendy->SetTextAlign(12);
2355 TFile*
file =
it->getFile();
2356 int color =
it->getLineColor();
2357 int linestyle =
it->getLineStyle();
2358 TString legendname =
it->getName();
2361 TString histnamex = legendname +
" NEntries: " +
std::to_string(
int(
hist[0]->GetEntries()));
2362 hist[0]->SetTitle(histnamex);
2363 hist[0]->SetStats(
false);
2365 hist[0]->SetBit(TH1::kNoTitle);
2366 hist[0]->SetLineColor(color);
2367 hist[0]->SetLineStyle(linestyle);
2369 hist[0]->Draw(
"Same");
2370 legendx->AddEntry(
hist[0], histnamex,
"l");
2372 TString histnamey = legendname +
" NEntries: " +
std::to_string(
int(
hist[1]->GetEntries()));
2373 hist[1]->SetTitle(histnamey);
2374 hist[1]->SetStats(
false);
2376 hist[1]->SetBit(TH1::kNoTitle);
2377 hist[1]->SetLineColor(color);
2378 hist[1]->SetLineStyle(linestyle);
2380 hist[1]->Draw(
"Same");
2381 legendy->AddEntry(
hist[1], histnamey,
"l");
2388 cx->SaveAs(
outputDir +
"/" + filenamex +
".root");
2389 cx->SaveAs(
outputDir +
"/" + filenamex +
".pdf");
2390 cx->SaveAs(
outputDir +
"/" + filenamex +
".png");
2391 cx->SaveAs(
outputDir +
"/" + filenamex +
".eps");
2395 cy->SaveAs(
outputDir +
"/" + filenamey +
".root");
2396 cy->SaveAs(
outputDir +
"/" + filenamey +
".pdf");
2397 cy->SaveAs(
outputDir +
"/" + filenamey +
".png");
2398 cy->SaveAs(
outputDir +
"/" + filenamey +
".eps");
std::vector< double > vAlignmentUncertainty
void plotSurfaceShapes(const std::string &options="layers", const std::string &variable="")
std::vector< double > vmeanerror
void scaleXaxis(TH1 *hist, Int_t scale)
void setHistStyle(TH1 &hist, const char *titleX, const char *titleY, int color)
std::vector< double > vPValueMeanEqualIdeal
std::vector< double > vrms
void residual_by_moduleID(unsigned int moduleid)
container to hold data to be written into TTree
std::string profileNameResXvsX
TkOfflineVariables * vars
constexpr unsigned int subDetId[21]
void legendOptions(TString options)
void plotSS(const std::string &options="layers", const std::string &variable="")
std::vector< double > vPValueRMSEqualIdeal
std::string getSelectionForDMRPlot(int minHits, int subDetId, int direction=0, int layer=0)
std::ofstream summaryfile
void loadFileList(const char *inputFile, std::string fileName="", int lineColor=2, int lineStyle=1)
float twotailedStudentTTestEqualMean(float t, float v)
void plotOutlierModules(const char *outputFileName="OutlierModules.ps", std::string plotVariable="chi2PerDofX", float chi2_cut=10, unsigned int minHits=50)
std::vector< TH1 * > findmodule(TFile *f, unsigned int moduleid)
int maxNumberOfLayers(int subdetector)
void setTitleStyle(TNamed &h, const char *titleX, const char *titleY, int subDetId, bool isSurfaceDeformation=false, TString secondline="")
static std::string to_string(const XMLCh *ch)
Primitive< F, X >::type primitive(const F &f)
TF1 * fitGauss(TH1 *hist, int color)
void plotChi2(const char *inputFile)
std::string profileNameResYvsX
static void drawStandardTitle()
static const TString summaryfilename
void plotSubDetResiduals(bool plotNormHisto=false, unsigned int subDetId=7)
std::string getVariableForDMRPlot(const std::string &histoname, const std::string &variable, int nbins, double min, double max)
THStack * addHists(const TString &selection, const TString &residType="xPrime", TLegend **myLegend=nullptr, bool printModuleIds=false, bool validforphase0=false)
static TString legendheader
std::string histNameNormX
void modifySSHistAndLegend(THStack *hs, TLegend *legend)
void storeHistogramInRootfile(TH1 *hist)
void useFitForDMRplots(bool usefit=false)
void plotDMR(const std::string &plotVar="medianX", Int_t minHits=50, const std::string &options="plain", const std::string &filterName="")
double resampleTestOfEqualMeans(TH1F *h1, TH1F *h2, int numSamples)
Abs< T >::type abs(const T &t)
~PlotAlignmentValidation()
std::string histNameLocalY
void setDMRHistStyleAndLegend(TH1F *h, DMRPlotInfo &plotinfo, int direction=0, int layer=0)
Log< level::Warning, true > LogPrint
Basic3DVector unit() const
std::string histNameNormLocalX
static TString legendoptions
std::vector< double > vPValueEqualSplitMeans
Class PlotAlignmentValidation Class used as the last step for Offline Track Validation tool...
std::vector< double > vmean
TObject * findObjectFromCanvas(TCanvas *canv, const char *className, Int_t n=1)
std::string histNameLocalX
std::vector< TkOfflineVariables * > sourceList
std::string profileNameResXvsY
TString units(TString variable, Char_t axis)
void setOutputDir(std::string dir)
PlotAlignmentValidation(bool bigtext=false)
std::string histNameNormY
int numberOfLayers(int phase, int subdetector)
static constexpr float d1
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
void plotDMRHistogram(DMRPlotInfo &plotinfo, int direction=0, int layer=0, std::string subdet="")
std::vector< double > vdeltamean
double resampleTestOfEqualRMS(TH1F *h1, TH1F *h2, int numSamples)
void setTreeBaseDir(std::string dir="TrackerOfflineValidation")
Power< A, B >::type pow(const A &a, const B &b)
std::string profileNameResYvsY
std::string className(const T &t)