Skip to content

Commit 4d6ec07

Browse files
authored
Merge pull request #46583 from TomasKello/kello-DMRaveraged
Global config added for DMR-averaged tool
2 parents 46d3a51 + d2b959c commit 4d6ec07

File tree

9 files changed

+95
-17
lines changed

9 files changed

+95
-17
lines changed

Alignment/OfflineValidation/bin/DMRmerge.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ int merge(int argc, char* argv[]) {
5656
//Read all configure variables and set default for missing keys
5757
std::string methods = validation.count("methods") ? getVecTokenized(validation, "methods", ",") : "median,rmsNorm";
5858
std::string curves = validation.count("curves") ? getVecTokenized(validation, "curves", ",") : "plain";
59+
std::string moduleFilterFile =
60+
validation.count("moduleFilterFile") ? validation.get<std::string>("moduleFilterFile") : "";
61+
float maxBadLumiPixel = validation.count("maxBadLumiPixel") ? validation.get<float>("maxBadLumiPixel") : 0.5;
62+
float maxBadLumiStrip = validation.count("maxBadLumiStrip") ? validation.get<float>("maxBadLumiStrip") : 7.0;
5963
std::string rlabel = validation.count("customrighttitle") ? validation.get<std::string>("customrighttitle") : "";
6064
rlabel = merge_style.count("Rlabel") ? merge_style.get<std::string>("Rlabel") : rlabel;
6165
std::string cmslabel = merge_style.count("CMSlabel") ? merge_style.get<std::string>("CMSlabel") : "INTERNAL";
@@ -122,7 +126,7 @@ int merge(int argc, char* argv[]) {
122126
plotter.setOutputDir(main_tree.get<std::string>("output"));
123127
plotter.useFitForDMRplots(useFit);
124128
plotter.setTreeBaseDir("TrackHitFilter");
125-
plotter.plotDMR(methods, minimum, curves);
129+
plotter.plotDMR(methods, minimum, curves, moduleFilterFile, maxBadLumiPixel, maxBadLumiStrip);
126130
plotter.plotSurfaceShapes("coarse");
127131
plotter.plotChi2((main_tree.get<std::string>("output") + "/" + "result.root").c_str());
128132

Alignment/OfflineValidation/interface/PlotAlignmentValidation.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,15 @@ class PlotAlignmentValidation {
123123
void plotDMR(const std::string& plotVar = "medianX",
124124
Int_t minHits = 50,
125125
const std::string& options = "plain",
126-
const std::string& filterName = "");
126+
const std::string& filterName = "",
127+
Float_t maxBadLumiPixel = 0.5,
128+
Float_t maxBadLumiStrip = 7.0);
127129
/**<
128130
* plotVar=mean,meanX,meanY,median,rms etc., comma-separated list can be given;
129131
* minHits=the minimum hits needed for module to appear in plot;
130132
* options="plain" for regular DMR, "split" for inwards/outwards split, "layers" for layerwise DMR, "layer=N" for Nth layer, or combination of the previous (e.g. "split layers")
131133
* filterName=rootfile containing tree with module ids to be skipped in plotting (to be used for averaged plots or in debugging)
134+
* maxBadLumiPixel and maxBadLumiStrip place cuts on maximum luminosity for which module wont be skipped if it does not satisfy condition for guaranteed number of hits
132135
*/
133136
void plotSurfaceShapes(const std::string& options = "layers", const std::string& variable = "");
134137
void plotChi2(const char* inputFile);
@@ -169,6 +172,8 @@ class PlotAlignmentValidation {
169172
TH1F* h2;
170173
bool firsthisto;
171174
std::string filterName;
175+
float maxBadLumiPixel;
176+
float maxBadLumiStrip;
172177
};
173178

174179
private:

Alignment/OfflineValidation/plugins/TrackerOfflineValidation.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ class TrackerOfflineValidation : public edm::one::EDAnalyzer<edm::one::SharedRes
128128

129129
TH1* LocalX;
130130
TH1* LocalY;
131+
132+
unsigned int EntriesInt;
131133
};
132134

133135
// container struct to organize collection of histograms during endJob
@@ -373,7 +375,7 @@ class TrackerOfflineValidation : public edm::one::EDAnalyzer<edm::one::SharedRes
373375

374376
unsigned long long nTracks_;
375377
const unsigned long long maxTracks_;
376-
378+
const unsigned int maxEntriesPerModuleForDmr_;
377379
TrackerValidationVariables avalidator_;
378380
};
379381

@@ -489,6 +491,7 @@ TrackerOfflineValidation::TrackerOfflineValidation(const edm::ParameterSet& iCon
489491
chargeCut_(parSet_.getParameter<int>("chargeCut")),
490492
nTracks_(0),
491493
maxTracks_(parSet_.getParameter<unsigned long long>("maxTracks")),
494+
maxEntriesPerModuleForDmr_(parSet_.getParameter<unsigned int>("maxEntriesPerModuleForDmr")),
492495
avalidator_(iConfig, consumesCollector()) {
493496
usesResource(TFileService::kSharedResource);
494497
}
@@ -509,6 +512,7 @@ void TrackerOfflineValidation::fillDescriptions(edm::ConfigurationDescriptions&
509512
desc.add<std::string>("moduleDirectoryInOutput", {});
510513
desc.add<int>("chargeCut", 0);
511514
desc.add<unsigned long long>("maxTracks", 0);
515+
desc.add<unsigned int>("maxEntriesPerModuleForDmr", 0);
512516

513517
// fill in the residuals details
514518
std::vector<std::string> listOfResidualsPSets = {"TH1XResPixelModules",
@@ -1325,6 +1329,9 @@ void TrackerOfflineValidation::analyze(const edm::Event& iEvent, const edm::Even
13251329

13261330
if (moduleLevelProfiles_ && itH->inside) {
13271331
float tgalpha = tan(itH->localAlpha);
1332+
histStruct.EntriesInt = histStruct.LocalX->GetEntries();
1333+
if (maxEntriesPerModuleForDmr_ > 0 && histStruct.EntriesInt >= maxEntriesPerModuleForDmr_)
1334+
continue;
13281335
if (fabs(tgalpha) != 0) {
13291336
histStruct.LocalX->Fill(itH->localXnorm, tgalpha * tgalpha);
13301337
histStruct.LocalY->Fill(itH->localYnorm, tgalpha * tgalpha);

Alignment/OfflineValidation/python/TkAlAllInOneTool/DMR.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,17 @@ def DMR(config, validationDir):
245245
elif isDataMerged[mergeName] == 1:
246246
mergesDATA.append(mergeName)
247247
else:
248-
mergesMC.append(mergeName)
248+
mergesMC.append(mergeName)
249+
if "moduleFilterFile" not in config["validations"]["DMR"]["merge"][mergeName]:
250+
raise Exception("Value for 'moduleFilterFile' is required for the 'merge' step if the 'averaged' step is requested.")
251+
if "maxBadLumiPixel" not in config["validations"]["DMR"]["merge"][mergeName]:
252+
print("WARNING: Default value for the 'maxBadLumiPixel' is used.")
253+
if "maxBadLumiStrip" not in config["validations"]["DMR"]["merge"][mergeName]:
254+
print("WARNING: Default value for the 'maxBadLumiStrip' is used.")
255+
#Validate single step within merge step
256+
for singleName in config["validations"]["DMR"]["merge"][mergeName]['singles']:
257+
if "maxEntriesPerModuleForDmr" not in config["validations"]["DMR"]["single"][singleName]:
258+
raise Exception("Value for 'maxEntriesPerModuleForDmr' is required for the 'single' step if the 'averaged' step is requested.")
249259

250260
lumiPerRun = []
251261
lumiPerIoV = []

Alignment/OfflineValidation/python/TkAlAllInOneTool/DMR_cfg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
useFit = False,
157157
useOverflowForRMS = False,
158158
maxTracks = config["validation"].get("maxtracks", 1),
159+
maxEntriesPerModuleForDmr = config["validation"].get("maxEntriesPerModuleForDmr", 0),
159160
chargeCut = config["validation"].get("chargecut", 0),
160161

161162
# Normalized X Residuals, normal local coordinates (Strip)

Alignment/OfflineValidation/python/TkAlAllInOneTool/DMRplotter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,9 @@ def __setTHStyle__(self,objects):
607607
elif obj['type'] == "DATA":
608608
obj['hist'].SetMarkerColor(self.args['colors'][self.args['objects'].index(objName)])
609609
obj['hist'].SetLineColor(self.args['colors'][self.args['objects'].index(objName)])
610+
obj['hist'].SetLineWidth(3)
610611
obj['hist'].SetMarkerStyle(self.args['styles'][self.args['objects'].index(objName)])
611-
obj['hist'].SetMarkerSize(1.5)
612+
obj['hist'].SetMarkerSize(1.5)
612613

613614
#set general style for DMRs
614615
tStyle = ROOT.TStyle("StyleCMS","Style CMS")

Alignment/OfflineValidation/src/PlotAlignmentValidation.cc

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,9 @@ void PlotAlignmentValidation::plotSS(const std::string& options, const std::stri
687687
void PlotAlignmentValidation::plotDMR(const std::string& variable,
688688
Int_t minHits,
689689
const std::string& options,
690-
const std::string& filterName) {
690+
const std::string& filterName,
691+
Float_t maxBadLumiPixel,
692+
Float_t maxBadLumiStrip) {
691693
// If several, comma-separated values are given in 'variable',
692694
// call plotDMR with each value separately.
693695
// If a comma is found, the string is divided to two.
@@ -696,17 +698,17 @@ void PlotAlignmentValidation::plotDMR(const std::string& variable,
696698
if (findres != std::string::npos) {
697699
std::string substring1 = variable.substr(0, findres);
698700
std::string substring2 = variable.substr(findres + 1, std::string::npos);
699-
plotDMR(substring1, minHits, options, filterName);
700-
plotDMR(substring2, minHits, options, filterName);
701+
plotDMR(substring1, minHits, options, filterName, maxBadLumiPixel, maxBadLumiStrip);
702+
plotDMR(substring2, minHits, options, filterName, maxBadLumiPixel, maxBadLumiStrip);
701703
return;
702704
}
703705

704706
// Variable name should end with X or Y. If it doesn't, recursively calls plotDMR twice with
705707
// X and Y added, respectively
706708
if (variable == "mean" || variable == "median" || variable == "meanNorm" || variable == "rms" ||
707709
variable == "rmsNorm") {
708-
plotDMR(variable + "X", minHits, options, filterName);
709-
plotDMR(variable + "Y", minHits, options, filterName);
710+
plotDMR(variable + "X", minHits, options, filterName, maxBadLumiPixel, maxBadLumiStrip);
711+
plotDMR(variable + "Y", minHits, options, filterName, maxBadLumiPixel, maxBadLumiStrip);
710712
return;
711713
}
712714

@@ -761,6 +763,8 @@ void PlotAlignmentValidation::plotDMR(const std::string& variable,
761763
plotinfo.plotPlain = plotPlain;
762764
plotinfo.plotLayers = plotLayers;
763765
plotinfo.filterName = filterName;
766+
plotinfo.maxBadLumiPixel = maxBadLumiPixel;
767+
plotinfo.maxBadLumiStrip = maxBadLumiStrip;
764768

765769
// width in cm
766770
// for DMRS, use 100 bins in range +-10 um, bin width 0.2um
@@ -825,6 +829,33 @@ void PlotAlignmentValidation::plotDMR(const std::string& variable,
825829
}
826830
//Begin loop on structures
827831
for (int i = 1; i <= 6; ++i) {
832+
// Preferred binning in case of averaged DMR disributions
833+
if (!plotinfo.filterName.empty()) {
834+
if (i == 1 || i == 2) {
835+
if (variable == "medianX") {
836+
if (plotSplits) {
837+
plotinfo.nbins = 50;
838+
} else {
839+
plotinfo.nbins = 50;
840+
}
841+
} else if (variable == "medianY") {
842+
if (plotSplits) {
843+
plotinfo.nbins = 50;
844+
} else {
845+
plotinfo.nbins = 25;
846+
}
847+
}
848+
} else if (i == 3 || i == 4 || i == 5 || i == 6) {
849+
if (variable == "medianX" || variable == "medianY") {
850+
if (plotSplits) {
851+
plotinfo.nbins = 50;
852+
} else {
853+
plotinfo.nbins = 25;
854+
}
855+
}
856+
}
857+
}
858+
828859
// Skip strip detectors if plotting any "Y" variable
829860
if (i != 1 && i != 2 && variable.length() > 0 && variable[variable.length() - 1] == 'Y') {
830861
continue;
@@ -2068,6 +2099,12 @@ void PlotAlignmentValidation::plotDMRHistogram(PlotAlignmentValidation::DMRPlotI
20682099
}
20692100
}
20702101
} else {
2102+
plotinfo.vars->getTree()->Draw(
2103+
plotVariable.c_str(), selection.c_str(), "goff"); //dummy to get the histogram structure
2104+
if (gDirectory)
2105+
gDirectory->GetObject(histoname.Data(), h);
2106+
h->Reset();
2107+
std::cout << "Module filter enabled." << std::endl;
20712108
TTreeReader reader(plotinfo.vars->getTree());
20722109
TTreeReaderValue<Float_t> varToPlot(reader, plotinfo.variable.c_str());
20732110
TTreeReaderValue<unsigned int> _entries(reader, "entries");
@@ -2084,9 +2121,11 @@ void PlotAlignmentValidation::plotDMRHistogram(PlotAlignmentValidation::DMRPlotI
20842121
TTreeReaderValue<int> _bad_id(readerBad, "id");
20852122
TTreeReaderValue<double> _bad_lumi(readerBad, "lumi");
20862123

2087-
//Record which modules were used
2124+
//Record which modules were or were not used
20882125
std::ofstream fUsedModules;
2126+
std::ofstream fNotUsedModules;
20892127
fUsedModules.open("usedModules.txt", std::ios::out | std::ios::app);
2128+
fNotUsedModules.open("notUsedModules.txt", std::ios::out | std::ios::app);
20902129

20912130
//Filter on modules by hand together with base selection
20922131
for (uint i = 0; i < plotinfo.vars->getTree()->GetEntries(); i++) {
@@ -2113,19 +2152,21 @@ void PlotAlignmentValidation::plotDMRHistogram(PlotAlignmentValidation::DMRPlotI
21132152
readerBad.SetEntry(ibad);
21142153
//if (*_valid == 0) {continue;} //only modules that failed 0 times are OK = very strict
21152154
if (subdet == "BPIX" || subdet == "FPIX") {
2116-
if (*_bad_lumi <= 2.0)
2155+
if (*_bad_lumi <= plotinfo.maxBadLumiPixel)
21172156
continue;
21182157
} else {
2119-
if (*_bad_lumi <= 7.0)
2158+
if (*_bad_lumi <= plotinfo.maxBadLumiStrip)
21202159
continue;
21212160
}
2122-
//modules that misbehave for less than 2/fb are OK = mild strict
2161+
//modules that misbehave for less than XYZ are OK = mild strict
21232162
if (*_moduleId == uint(*_bad_id))
21242163
isBadModule = true;
21252164
}
21262165

2127-
if (isBadModule)
2166+
if (isBadModule) {
2167+
fNotUsedModules << *_moduleId << "\n";
21282168
continue;
2169+
}
21292170
fUsedModules << *_moduleId << "\n";
21302171
if (h) {
21312172
h->Fill(*varToPlot);
@@ -2134,6 +2175,7 @@ void PlotAlignmentValidation::plotDMRHistogram(PlotAlignmentValidation::DMRPlotI
21342175

21352176
//Finalize
21362177
fUsedModules.close();
2178+
fNotUsedModules.close();
21372179
fBadModules->Close();
21382180
if (h) {
21392181
h->SetName(histoname.Data());

Alignment/OfflineValidation/test/unit_test.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@
106106
"vertexcollection": "offlinePrimaryVertices",
107107
"magneticfield": "true",
108108
"maxevents": "1",
109-
"maxtracks": "1"
109+
"maxtracks": "1",
110+
"maxEntriesPerModuleForDmr":100
110111
}
111112
},
112113
"merge": {
@@ -117,7 +118,10 @@
117118
"singles": ["TestSingleMC"],
118119
"usefit": "true",
119120
"minimum": "15",
120-
"customrighttitle": "IOV"
121+
"customrighttitle": "IOV",
122+
"moduleFilterFile": "",
123+
"maxBadLumiPixel": 0.5,
124+
"maxBadLumiStrip": 7.0
121125
}
122126
},
123127
"trends": {

Alignment/OfflineValidation/test/unit_test.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ validations:
9696
magneticfield: true
9797
maxevents: 1
9898
maxtracks: 1
99+
maxEntriesPerModuleForDmr: 100
99100

100101
merge:
101102
TestMergeMC:
@@ -106,6 +107,9 @@ validations:
106107
- plain
107108
- split
108109
customrighttitle: IOV
110+
moduleFilterFile: ""
111+
maxBadLumiPixel: 0.5
112+
maxBadLumiStrip: 7.0
109113
legendoptions:
110114
- mean
111115
- rms

0 commit comments

Comments
 (0)