36 LogVerbatim (
"DTDQM|DTMonitorClient|DTOccupancyTestML") <<
"[DTOccupancyTestML]: Constructor";
44 rootFile =
new TFile(
"MLDTOccupancyTest.root",
"RECREATE");
45 ntuple =
new TNtuple(
"OccupancyNtuple",
"OccupancyNtuple",
"ls:wh:st:se:lay1MeanCell:lay1RMS:lay2MeanCell:lay2RMS:lay3MeanCell:lay3RMS:lay4MeanCell:lay4RMS:lay5MeanCell:lay5RMS:lay6MeanCell:lay6RMS:lay7MeanCell:lay7RMS:lay8MeanCell:lay8RMS:lay9MeanCell:lay9RMS:lay10MeanCell:lay10RMS:lay11MeanCell:lay11RMS:lay12MeanCell:lay12RMS");
66 LogVerbatim (
"DTDQM|DTMonitorClient|MLDTOccupancyTest") <<
" destructor called" << endl;
72 LogVerbatim (
"DTDQM|DTMonitorClient|DTOccupancyTestML") <<
"[DTOccupancyTestML]: BeginRun";
85 for(
int wh = -2; wh <= 2; ++wh) {
86 bookHistos(ibooker,wh,
string(
"MLDTOccupancies"),
"MLOccupancySummary");
90 string title =
"Occupancy Summary";
92 title =
"Test Pulse Occupancy Summary";
95 summaryHisto = ibooker.
book2D(
"MLOccupancySummary",title.c_str(),12,1,13,5,-2,3);
97 summaryHisto->setAxisTitle(
"wheel",2);
100 glbSummaryHisto = ibooker.
book2D(
"MLOccupancyGlbSummary",title.c_str(),12,1,13,5,-2,3);
102 glbSummaryHisto->setAxisTitle(
"wheel",2);
106 if(runOnAllHitsOccupancies) {
107 nameMonitoredHisto =
"OccupancyAllHits_perCh";
108 }
else if(runOnNoiseOccupancies) {
109 nameMonitoredHisto =
"OccupancyNoise_perCh";
110 }
else if(runOnInTimeOccupancies) {
111 nameMonitoredHisto =
"OccupancyInTimeHits_perCh";
113 nameMonitoredHisto =
"OccupancyAllHits_perCh";
120 LogVerbatim (
"DTDQM|DTMonitorClient|DTOccupancyTestML")
121 <<
"[DTOccupancyTestML]: End of LS transition, performing the DQM client operation";
127 summaryHisto->Reset();
128 glbSummaryHisto->Reset();
134 vector<const DTChamber*>
chambers = muonGeom->chambers();
138 edm::FileInPath modelFilePath(
"DQM/DTMonitorClient/data/occupancy_cnn_v1.pb");
144 for(vector<const DTChamber*>::const_iterator
chamber = chambers.begin();
148 MonitorElement * chamberOccupancyHisto = igetter.
get(getMEName(nameMonitoredHisto, chId));
151 if(chamberOccupancyHisto !=
nullptr) {
155 float chamberPercentage = 1.;
156 int result = runOccupancyTest(histo, chId, chamberPercentage, graphDef, session);
157 int sector = chId.
sector();
161 float resultSect4 = wheelHistos[chId.
wheel()]->getBinContent(sector, chId.
station());
162 if(resultSect4 > result) {
163 result = (
int)resultSect4;
165 }
else if(sector == 14) {
167 float resultSect10 = wheelHistos[chId.
wheel()]->getBinContent(sector, chId.
station());
168 if(resultSect10 > result) {
169 result = (
int)resultSect10;
174 if((sector == 4 || sector == 10) && chId.
station() == 4)
175 chamberPercentage = chamberPercentage/2.;
178 if(result > summaryHisto->getBinContent(sector, chId.
wheel()+3)) {
179 summaryHisto->setBinContent(sector, chId.
wheel()+3,
result);
181 glbSummaryHisto->Fill(sector, chId.
wheel(), chamberPercentage*1./4.);
183 LogVerbatim (
"DTDQM|DTMonitorClient|DTOccupancyTestML") <<
"[DTOccupancyTestML] ME: " 184 << getMEName(nameMonitoredHisto, chId) <<
" not found!" << endl;
193 string nEvtsName =
"DT/EventInfo/Counters/nProcessedEventsDigi";
199 glbSummaryHisto->setEntries(nProcEvts < nMinEvts ? 10. : nProcEvts);
200 summaryHisto->setEntries(nProcEvts < nMinEvts ? 10. : nProcEvts);
202 glbSummaryHisto->setEntries(nMinEvts +1);
203 summaryHisto->setEntries(nMinEvts + 1);
204 LogVerbatim (
"DTDQM|DTMonitorClient|DTOccupancyTestML") <<
"[DTOccupancyTestML] ME: " 205 << nEvtsName <<
" not found!" << endl;
212 if(writeRootFile)
ntuple->AutoSave(
"SaveSelf");
218 LogVerbatim (
"DTDQM|DTMonitorClient|DTOccupancyTestML") <<
"[DTOccupancyTestML] endjob called!";
231 string folder,
string histoTag) {
233 stringstream
wheel; wheel << wheelId;
238 string histoName = histoTag +
"_W" + wheel.str();
241 LogVerbatim (
"DTDQM|DTMonitorClient|DTOccupancyTestML") <<
"[DTOccupancyTestML]: booking wheel histo:" 246 << topFolder(
true) +
"Wheel"+ wheel.str() +
"/" + folder << endl;
248 string histoTitle =
"Occupancy summary WHEEL: "+wheel.str();
250 histoTitle =
"TP Occupancy summary WHEEL: "+wheel.str();
253 wheelHistos[wheelId] = ibooker.
book2D(histoName,histoTitle,12,1,13,4,1,5);
255 wheelHistos[wheelId]->setBinLabel(2,
"MB2",2);
256 wheelHistos[wheelId]->setBinLabel(3,
"MB3",2);
257 wheelHistos[wheelId]->setBinLabel(4,
"MB4",2);
258 wheelHistos[wheelId]->setAxisTitle(
"sector",1);
267 stringstream sector; sector << chId.
sector();
270 string folderRoot = topFolder(
false) +
"Wheel" + wheel.str() +
271 "/Sector" + sector.str() +
272 "/Station" + station.str() +
"/";
275 string histoName = histoTag
277 +
"_St" + station.str()
278 +
"_Sec" + sector.str();
280 string histoname = folderRoot + histoName;
289 for (Int_t
i = firstBinX;
i < lastBinX+1;
i++) {
290 for (Int_t j = firstBinY; j < lastBinY+1; j++) {
292 if (histo->GetBinContent(
i,j) >0){
293 if (!doall)
return 1;
294 sum += histo->GetBinContent(
i,j);
303 float& chamberPercentage,
304 tensorflow::GraphDef *graphDef,
305 tensorflow::Session *
session) {
307 LogTrace(
"DTDQM|DTMonitorClient|DTOccupancyTestML")
308 <<
"--- Occupancy test for chamber: " << chId << endl;
315 for (
int superLayer = 1; superLayer <= 3; superLayer++) {
316 int binYlow = ((superLayer-1)*4)+1;
319 if (chId.
station() == 4 && superLayer == 2)
continue;
322 for (
int layer = 1; layer <= 4; layer++) {
323 DTLayerId layID(chId, superLayer, layer);
324 int firstWire = muonGeom->layer(layID)->
325 specificTopology().firstChannel();
326 int nWires = muonGeom->layer(layID)->specificTopology().channels();
327 int binY = binYlow+(layer-1);
328 std::vector<float> layerOccupancy(nWires);
332 for (
int cell = firstWire; cell != (nWires + firstWire); cell++) {
333 double cellOccupancy = histo->GetBinContent(cell, binY);
334 layerOccupancy.at(channelId) = cellOccupancy;
339 std::vector<float> reshapedLayerOccupancy = interpolateLayers(layerOccupancy,
344 float maxOccupancyInLayer =
345 *std::max_element(reshapedLayerOccupancy.begin(),
346 reshapedLayerOccupancy.end());
348 if (maxOccupancyInLayer != 0) {
349 for (
auto &
val : reshapedLayerOccupancy)
350 val /= maxOccupancyInLayer;
354 tensorflow::Tensor
input(tensorflow::DT_FLOAT, {1, targetSize});
355 for (
int i = 0;
i < targetSize;
i++)
356 input.matrix<
float>()(0,
i) = reshapedLayerOccupancy[
i];
358 std::vector<tensorflow::Tensor>
outputs;
360 {
"output_cnn/Softmax" }, &
outputs);
363 bool isBad = outputs[0].matrix<
float>()(0, 1) > 0.95;
364 if (isBad) badLayers++;
369 chamberPercentage = 1.0 -
static_cast<float>(badLayers)/totalLayers;
371 if (badLayers > 8)
return 3;
372 if (badLayers > 4)
return 2;
373 if (badLayers > 0)
return 1;
379 int interpolationFloor = 0;
380 float interpolationPoint = 0.;
381 float step =
static_cast<float>(
size) / targetSize;
382 std::vector<float> reshapedInput(targetSize);
384 for (
int i = 0;
i < targetSize;
i++) {
385 interpolationFloor =
static_cast<int>(std::floor(interpolationPoint));
387 reshapedInput.at(
i) = (interpolationPoint - interpolationFloor) *
388 (inputs[interpolationFloor + 1] - inputs[interpolationFloor]) +
389 inputs[interpolationFloor];
390 interpolationPoint = step + interpolationPoint;
392 return reshapedInput;
396 if(tpMode)
return string(
"DT/10-TestPulses/");
397 if(isBooking)
return string(
"DT/01-Digi/ML");
398 return string(
"DT/01-Digi/");
Session * createSession(SessionOptions &sessionOptions)
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
Endjob.
T getUntrackedParameter(std::string const &, T const &) const
int getIntegral(TH2F *histo, int, int, int, int, bool)
double getFloatValue() const
MonitorElement * get(const std::string &path)
GraphDef * loadGraphDef(const std::string &pbFile)
void bookHistos(DQMStore::IBooker &, const int wheelId, std::string folder, std::string histoTag)
book the summary histograms
std::vector< float > interpolateLayers(std::vector< float > const &inputs, int size, int targetSize)
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
static std::string const input
void dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &) override
DQM Client Diagnostic.
std::string getMEName(std::string histoTag, const DTChamberId &chId)
Get the ME name.
bool closeSession(Session *&session)
void beginRun(edm::Run const &run, edm::EventSetup const &context) override
BeginRun.
std::string topFolder(bool isBooking) const
int runOccupancyTest(TH2F *histo, const DTChamberId &chId, float &chamberPercentage, tensorflow::GraphDef *graphDef, tensorflow::Session *session)
void setLogging(const std::string &level="3")
void setCurrentFolder(const std::string &fullpath)
MonitorElement * book2D(Args &&...args)
~DTOccupancyTestML() override
Destructor.
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, const std::vector< std::string > &targetNodes, std::vector< Tensor > *outputs)
std::string fullPath() const
int station() const
Return the station number.
static char chambers[264][20]
int wheel() const
Return the wheel number.
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
DTOccupancyTestML(const edm::ParameterSet &ps)
Constructor.