diff --git a/DQM/EcalMonitorClient/BuildFile.xml b/DQM/EcalMonitorClient/BuildFile.xml index 7924948a41352..1a014144d9eea 100644 --- a/DQM/EcalMonitorClient/BuildFile.xml +++ b/DQM/EcalMonitorClient/BuildFile.xml @@ -5,6 +5,8 @@ + + diff --git a/DQM/EcalMonitorClient/interface/MLClient.h b/DQM/EcalMonitorClient/interface/MLClient.h new file mode 100644 index 0000000000000..d8d8a2af92ba8 --- /dev/null +++ b/DQM/EcalMonitorClient/interface/MLClient.h @@ -0,0 +1,41 @@ +#ifndef MLClient_H +#define MLClient_H + +#include "DQWorkerClient.h" +#include +#include +#include + +namespace ecaldqm { + + class MLClient : public DQWorkerClient { + public: + MLClient(); + ~MLClient() override {} + + void producePlots(ProcessType) override; + + private: + void setParams(edm::ParameterSet const&) override; + + //Each Ecal Barrel occupancy map is plotted at the tower level + //34 towers in the eta and 72 towers in the phi directions + static const int nEtaTowers = 34; + static const int nPhiTowers = 72; + //After padding with two rows above and below to prevent the edge effect, 36 towers in eta direction + static const int nEtaTowersPad = 36; + float MLThreshold_; + float PUcorr_slope_; + float PUcorr_intercept_; + size_t nLS = 3; //No.of lumisections to add the occupancy over + size_t nLSloss = 6; //No.of lumisections to multiply the loss over + + std::deque NEventQ; //To keep the no.of events in each occupancy plot + std::deque> ebOccMap1dQ; //To keep the input occupancy plots to be summed + std::vector avgOcc_; //To keep the average occupancy to do response correction + std::deque>> lossMap2dQ; //To keep the ML losses to be multiplied + }; + +} // namespace ecaldqm + +#endif diff --git a/DQM/EcalMonitorClient/python/EcalMonitorClient_cfi.py b/DQM/EcalMonitorClient/python/EcalMonitorClient_cfi.py index a1edaffcc048e..0841ea2b5cc67 100644 --- a/DQM/EcalMonitorClient/python/EcalMonitorClient_cfi.py +++ b/DQM/EcalMonitorClient/python/EcalMonitorClient_cfi.py @@ -11,6 +11,7 @@ from DQM.EcalMonitorClient.TimingClient_cfi import ecalTimingClient from DQM.EcalMonitorClient.TrigPrimClient_cfi import ecalTrigPrimClient from DQM.EcalMonitorClient.SummaryClient_cfi import ecalSummaryClient +from DQM.EcalMonitorClient.MLClient_cfi import ecalMLClient ecalMonitorClient = DQMEDHarvester("EcalDQMonitorClient", moduleName = cms.untracked.string("Ecal Monitor Client"), @@ -22,6 +23,7 @@ "RawDataClient", "TrigPrimClient", "TimingClient", + "MLClient", "SummaryClient" ), # task parameters (included from indivitual cfis) @@ -33,7 +35,8 @@ SelectiveReadoutClient = ecalSelectiveReadoutClient, TimingClient = ecalTimingClient, TrigPrimClient = ecalTrigPrimClient, - SummaryClient = ecalSummaryClient + SummaryClient = ecalSummaryClient, + MLClient = ecalMLClient ), commonParameters = ecalCommonParams, verbosity = cms.untracked.int32(0) diff --git a/DQM/EcalMonitorClient/python/MLClient_cfi.py b/DQM/EcalMonitorClient/python/MLClient_cfi.py new file mode 100644 index 0000000000000..b5aca211b590a --- /dev/null +++ b/DQM/EcalMonitorClient/python/MLClient_cfi.py @@ -0,0 +1,411 @@ +import FWCore.ParameterSet.Config as cms + +from DQM.EcalMonitorTasks.OccupancyTask_cfi import ecalOccupancyTask + +#parameters dervied from training +MLThreshold = 0.1761 +PUcorr_slope = 8625.62354249 +PUcorr_intercept= 354776.97564344 +#Avg Occupancy of 2018 data +avgOcc = (1.4228867,1.4111477,1.4235557,1.403253 ,1.2926203,1.3110067,1.4317631, + 1.3582464,1.3350165,1.3870461,1.4315553,1.4340966,1.3463646,1.4664359, + 1.4383692,1.4883132,1.4921986,1.4414848,1.4935918,1.5053873,1.4814812, + 1.4806937,1.4688585,1.3852754,1.2133822,1.217942 ,1.2934631,1.2623638, + 1.4084297,1.2852081,1.3383209,1.3197039,1.2672714,1.2089411,1.2792134, + 1.2820784,1.2973225,1.2019042,0.0000001,1.2586329,1.424472 ,1.4129552, + 1.5303715,1.5035893,1.3739808,1.4674091,1.3101934,1.3559604,1.3654169, + 1.3723816,1.351616 ,1.3782867,1.6634412,1.6218939,1.5776167,1.5967489, + 1.4352198,1.4457697,1.5257363,1.5936497,1.2177914,1.1892394,1.2968882, + 1.2645309,1.333104 ,1.246442 ,1.2484925,1.2413881,1.3511598,1.3742812, + 1.3659753,1.3767184,1.4228867,1.4111477,1.4235557,1.403253 ,1.2926203, + 1.3110067,1.4317631,1.3582464,1.3350165,1.3870461,1.4315553,1.4340966, + 1.3463646,1.4664359,1.4383692,1.4883132,1.4921986,1.4414848,1.4935918, + 1.5053873,1.4814812,1.4806937,1.4688585,1.3852754,1.2133822,1.217942 , + 1.2934631,1.2623638,1.4084297,1.2852081,1.3383209,1.3197039,1.2672714, + 1.2089411,1.2792134,1.2820784,1.2973225,1.2019042,0.0000001,1.2586329, + 1.424472 ,1.4129552,1.5303715,1.5035893,1.3739808,1.4674091,1.3101934, + 1.3559604,1.3654169,1.3723816,1.351616 ,1.3782867,1.6634412,1.6218939, + 1.5776167,1.5967489,1.4352198,1.4457697,1.5257363,1.5936497,1.2177914, + 1.1892394,1.2968882,1.2645309,1.333104 ,1.246442 ,1.2484925,1.2413881, + 1.3511598,1.3742812,1.3659753,1.3767184,1.1556679,1.3391551,1.373256 , + 1.3540887,1.2471408,1.2453951,1.2790504,1.3212276,1.3020328,1.3587664, + 1.3487176,1.3814243,1.3593339,1.3286781,1.2952926,1.3192601,1.4060221, + 1.4540101,1.4574795,1.3729581,1.4051903,1.3568325,1.3918067,1.4169109, + 1.3129637,1.2971104,1.2642334,1.289142 ,1.3558336,1.2786664,1.296219 , + 1.298685 ,1.2628139,1.2494673,1.294434 ,1.2733648,1.2478417,1.1872551, + 1.2146964,2.0395069,1.5262315,1.4894062,1.4284101,1.4169872,1.352527 , + 1.3618537,1.3673831,1.334716 ,1.3480678,1.4098777,1.4061071,1.3918567, + 1.5523838,1.5230404,1.4913341,1.4753877,1.4160846,1.4024036,1.4175566, + 1.4888357,1.2680489,1.2883663,1.3472272,1.3023057,1.3586241,1.3383816, + 1.2996044,1.3184984,1.3418843,1.3903407,1.4139845,1.4251099,1.305113 , + 1.2633995,1.2851918,1.2743814,1.1825788,1.2547469,1.2440559,1.2770063, + 1.2717891,1.3396428,1.3710004,1.3859975,1.2798804,1.2516749,1.2677492, + 1.2683048,1.2613889,1.2783653,1.2966883,1.2827859,1.3206561,1.3148078, + 1.2636309,1.3001962,1.2161207,1.1910689,1.1688411,1.1911243,1.2880307, + 1.2225945,1.2570652,1.2086593,1.2767646,1.2320539,1.1953772,1.2159386, + 1.2037021,1.1857734,1.1674342,1.1956853,1.3138844,1.2758864,1.2300162, + 0.6665614,1.3036094,1.3088627,1.2554388,1.2967263,1.2841691,1.2875917, + 1.3089112,1.3331639,1.266067 ,1.2455457,1.2334898,1.2674097,1.276027 , + 1.1690655,1.1995609,1.199487 ,1.1338224,1.1563799,1.2194781,1.2064027, + 1.2493043,1.2673064,1.2891188,1.2735461,1.2408122,1.2415621,1.254231 , + 1.2100532,1.226575 ,1.2035872,1.2445701,1.1773577,1.1374254,1.1708428, + 1.1746327,1.1776469,1.2238355,1.2399627,1.2557915,1.2581828,1.1821021, + 1.1796409,1.2347831,1.248196 ,1.2299678,1.2151593,1.2597338,1.2399808, + 1.1583205,1.1536306,1.2159789,1.3336231,1.1655421,1.1663706,1.5020412, + 1.1574144,1.1892532,1.1677798,1.1635669,1.1543789,1.3043314,1.1876005, + 0.9521286,1.2199527,1.0653542,1.0589734,1.117103 ,1.0546287,1.2312565, + 1.1999464,1.1566527,1.1649921,1.246702 ,1.2841538,1.2533325,1.180725 , + 1.2153618,1.2312846,1.3220999,1.1518214,1.1985146,1.1956019,1.2026757, + 1.220378 ,1.2158185,1.1656332,1.1459147,1.1440367,0.0000001,1.106721 , + 1.2046571,1.1799783,1.1971282,1.2399644,1.2104925,1.1782469,1.2648659, + 1.2725782,1.2706518,1.2750179,1.1781482,1.1746165,1.1428392,1.1554896, + 1.08052 ,1.1252075,1.0796442,1.0661097,1.1994307,1.1427931,1.1547704, + 1.1450479,1.1638263,1.1558805,1.1312499,1.1190377,1.1767929,1.1355052, + 1.1739364,1.1897258,1.1543195,1.2075775,1.1802915,1.1443394,1.0686296, + 1.0484798,1.1059129,1.1041118,1.0907497,1.0863662,1.0989137,1.1160423, + 1.1354574,1.0911841,1.0848287,1.0849218,1.0303825,1.0509577,1.1060627, + 1.0906715,1.163807 ,1.1446611,1.1357274,1.1637452,1.1761752,1.1996605, + 1.1433704,1.1708797,1.0934016,1.1287714,1.1213528,0.9135892,1.1128932, + 1.1062543,1.0822164,1.1020374,1.1105623,1.0700424,1.0619079,1.1016523, + 1.0585421,1.0115267,1.031876 ,1.0759147,1.1201001,1.1058998,1.0973803, + 1.1015209,1.1435407,1.14981 ,1.1311004,1.1691828,1.1759555,1.1401734, + 1.1672325,1.1874546,1.0948305,1.0863739,1.1059391,1.0986216,1.1788837, + 1.1270268,1.1239996,1.1002039,1.1389588,1.141233 ,1.083227 ,1.0877259, + 1.1431438,1.1221772,1.1199503,1.1654431,1.1736141,1.1989235,1.1978018, + 1.167959 ,1.0133513,1.0567273,1.0395187,1.0680603,1.0610994,1.0597148, + 1.0684566,1.0339921,1.1405144,1.1203558,1.0788041,1.0960815,1.0242732, + 0.9811422,1.0137647,1.0043021,1.1159075,1.1183313,1.1035389,1.1150508, + 1.117763 ,1.1088306,1.0894555,1.1437987,1.1288823,1.1197007,1.1289188, + 1.1122833,1.1094319,1.0663022,1.0441525,1.0901659,1.1118773,1.1093612, + 1.0880778,1.0673048,1.0135869,0.9895969,1.0111624,0.994159 ,1.157239 , + 1.1461102,1.0853236,1.0694305,1.2243338,1.1992161,1.1530303,1.2302727, + 1.1132525,1.0987779,1.1112196,1.0841962,1.1152277,1.0965806,1.1059502, + 1.0867471,1.1308132,1.1056805,1.0888016,1.073627 ,1.1095271,1.0971298, + 1.0672264,1.0892332,1.1054503,1.0687332,1.0934203,1.1355063,1.24187 , + 1.2197568,1.2120614,1.1968735,1.0238991,0.9819736,0.9891209,1.0145121, + 1.0608021,1.0184129,1.0311555,1.0517814,1.1033106,1.0689223,1.0606674, + 1.0605292,1.0284557,0.971954 ,0.9526132,1.04703 ,1.128279 ,1.0795844, + 1.0738314,1.107188 ,1.1450828,1.1231935,1.0905402,1.1256251,1.1096694, + 1.0497596,1.0524868,1.0812023,1.0472693,1.0021344,1.0382787,1.0649058, + 1.0950122,1.0948782,1.0399659,1.0673079,1.0342895,1.0013512,0.9988917, + 1.0112954,1.0890151,1.042002 ,1.041176 ,1.0243192,1.1275606,1.1135633, + 1.1377431,1.1745214,1.1230987,1.0614204,1.0361215,1.1119354,1.0850902, + 1.0927483,1.1078453,1.077041 ,1.0753678,1.0642383,1.067675 ,1.1028837, + 1.0942855,1.0852079,1.0798481,1.088132 ,1.1058763,1.0810122,1.0625142, + 1.1011781,1.1856151,1.196195 ,1.1612228,1.1422418,0.9793076,0.9765419, + 0.9804395,1.0156407,1.0480926,1.0464298,1.0522102,1.0688092,1.1212629, + 1.0395747,0.9926344,1.0080917,1.0007402,0.9855192,0.9907292,0.9954209, + 1.1032989,1.0986856,1.1330308,1.1098777,1.1356755,1.1181957,1.113232 , + 1.1295322,1.1084793,1.0193369,1.0491607,1.0724577,1.0785445,1.0371226, + 0.0036721,1.0269073,1.0965271,1.0695037,1.0664477,1.087617 ,0.9891936, + 0.9989811,1.0070362,1.0190035,1.0781424,1.0664753,1.0687553,1.0421116, + 1.1388807,1.1237614,1.1355482,1.1830119,1.0553507,1.044697 ,1.0408233, + 1.0398819,1.0669746,1.0332361,1.0301825,0.9893497,1.059479 ,1.0278772, + 1.0176086,1.0205175,1.0467259,1.0548677,1.0646734,1.0527669,1.0866866, + 1.0472943,1.0426059,1.0849829,1.0999873,1.1246853,1.1031482,1.0814158, + 0.9405594,0.9336581,0.9254869,0.9352036,1.0345708,0.9965525,0.9950148, + 1.0257301,1.1129664,0.9780049,0.9502401,0.9700456,1.0284607,1.0213796, + 0.9910805,1.0367672,1.0796332,1.0587161,1.0674927,1.0761822,1.0794786, + 1.0831254,1.0830816,1.1075894,0.0126334,0.92802 ,0.9371951,0.9496164, + 1.0454251,1.0489166,1.0143294,1.0061715,1.0771358,1.0521995,1.0829998, + 1.0526272,0.9770707,0.9811446,0.9211687,0.947929 ,1.0504178,0.0000001, + 1.0035456,1.0284821,1.1091976,1.0872326,1.0880209,1.133727 ,1.014713 , + 0.9581099,0.9811009,1.0093567,1.0370228,0.989569 ,0.9988301,0.9841469, + 0.9527792,0.9855899,0.9826103,0.9610231,1.0160042,0.9992726,1.0005047, + 0.9965398,1.0511478,0.9744592,1.0089016,1.0331134,1.0977989,1.0927752, + 1.0878357,1.0548981,0.9570927,0.9533063,0.9489567,0.9408886,0.9869403, + 0.9708263,0.9788091,0.9671838,0.9488644,0.9382011,0.9179539,0.9175838, + 0.9908231,0.933664 ,0.9034764,0.929096 ,1.0545647,0.9846775,1.0010679, + 0.9964607,1.0280262,1.0288763,0.9798051,0.9853348,0.9509227,0.9410004, + 0.8996611,0.9309286,1.0092912,0.9800311,0.9862539,0.9823382,0.9956134, + 0.9848503,0.9927089,0.9988752,0.9427151,0.9123654,0.9192433,0.9211756, + 0.9682457,0.9614248,0.940841 ,2.9108264,1.0182347,1.0328737,1.0335125, + 1.0162688,0.9742591,0.9400508,0.9223933,0.9612672,0.9902653,0.9835137, + 0.9622135,0.9489338,0.9200854,0.9142317,0.9246915,0.9710323,0.9510582, + 0.986548 ,0.9715658,0.9551507,0.9795502,0.9373934,0.9590609,0.9864878, + 1.0536214,1.0606204,1.0470799,1.0450804,0.9423648,0.9130962,1.2390996, + 0.9090152,0.9728571,0.9594254,0.9378965,0.9442697,0.9128348,0.9111411, + 0.8573027,0.9057387,0.8775638,0.8585867,0.871328 ,0.8851443,1.0256898, + 0.9997756,1.0087074,0.9802992,1.0048345,0.986007 ,0.9939928,0.9924014, + 0.9393591,0.8975831,0.9569556,0.9221528,1.0005504,0.9573966,0.9446875, + 0.9525049,0.9864134,0.9616978,0.9709904,0.9688258,0.9331638,0.8939223, + 0.9041911,0.9179978,0.9570236,0.9535987,0.9462896,0.9406717,1.0385262, + 1.0471946,1.0040003,1.0764723,0.9440772,0.9303069,0.9388188,0.9624437, + 0.9522971,0.9236505,0.921064 ,0.9153899,0.9239462,0.9149684,0.9110753, + 0.9250061,0.9977021,0.9575272,0.9395442,0.9242274,0.8905004,1.215517 , + 0.9538251,0.9689807,1.0420041,1.0098691,1.0688168,0.9420413,0.9071479, + 0.9233371,0.8648853,0.9046464,0.944227 ,0.9231179,0.9260064,0.9462502, + 0.8824298,0.0000001,0.8896712,0.9343744,0.9496966,0.9062078,0.9076006, + 0.8920029,0.9911788,0.9509735,0.9620247,0.9532838,0.9553664,0.966219 , + 0.9766419,0.9830272,0.9704874,0.9066846,0.9014828,0.9114758,0.9525748, + 0.9449465,0.9234739,0.9165454,0.9440705,0.9461663,0.936758 ,0.9713703, + 0.9236538,0.9208513,0.891026 ,0.8855084,0.9444764,0.9177411,0.9162141, + 0.9445439,1.0220059,1.0118829,1.0278999,1.0203037,0.9124752,0.8955967, + 0.9001777,0.8839747,0.8924397,0.884959 ,0.9014532,0.8925565,0.7268787, + 0.8359309,0.8754961,0.8911034,0.9268813,0.9161255,0.9086187,0.853088 , + 0.9073059,0.8781778,0.9306351,0.9155804,0.9369089,0.9953336,0.9929911, + 0.9851077,0.8977557,0.8955045,0.8884436,0.8941315,0.921898 ,0.8701018, + 0.9078636,0.8981934,0.8977088,0.8691131,0.8413706,0.8976212,0.876539 , + 1.4657505,0.8280094,0.8627123,0.9547047,0.9364532,0.9272763,0.9186774, + 0.941437 ,0.9263571,0.9280555,0.9123494,0.9105576,0.9997209,0.9331673, + 0.9702676,0.911276 ,0.8823292,0.9235324,0.915177 ,0.9073598,0.8663465, + 0.8806252,0.8953832,0.8542768,0.8170022,0.8364354,0.8324253,0.9117646, + 0.8914846,0.882292 ,0.8745112,0.9651436,0.9339125,0.908168 ,0.8983836, + 1.0204283,1.014069 ,0.8514856,0.8366709,0.0000001,0.8435681,0.8716656, + 0.8663046,0.8687047,0.8607368,0.853239 ,0.8538001,0.9117879,0.8984275, + 0.9074128,0.8910619,0.9175624,0.9058829,0.9104028,0.9016951,0.9979504, + 1.0018495,0.9727136,0.9829723,0.8593063,0.8864803,0.8331164,0.8243229, + 0.8761157,0.84732 ,0.8649628,0.8924447,0.8528641,0.8461951,0.8256967, + 0.8219401,0.8493258,0.8396199,0.8288802,0.8688241,0.9221398,0.9144458, + 0.9145495,0.8767081,0.9111733,0.9246608,0.9190454,0.9145585,0.8979622, + 0.9213055,0.9043622,0.9187738,0.8733439,0.9010628,0.8879052,0.8862385, + 0.886833 ,0.8412263,0.8744929,0.8971784,0.7947825,0.7808067,0.720468 , + 0.7835823,0.8811975,0.8858461,0.8736796,0.8753381,0.9216196,0.9133907, + 0.877441 ,0.9787805,0.8858882,1.0329753,0.8817087,0.0000001,0.8540137, + 0.8454756,0.8776406,0.8772608,0.878461 ,0.817844 ,0.8320211,0.7978509, + 0.9232702,0.9232559,0.9103069,0.9115226,0.9466796,0.9346468,0.9280509, + 0.9378798,0.9828502,0.9918494,0.9742755,0.9657697,0.8602819,0.8742782, + 0.8663973,0.8632851,0.9069272,0.8904232,0.892713 ,0.9054623,0.8925498, + 0.868188 ,0.8912911,0.8767484,0.8553541,0.8425062,0.8211766,0.8539204, + 0.9321883,0.9126161,0.9168343,0.8570537,0.8895695,0.8795208,0.9255748, + 0.9180104,0.9300255,0.9378335,0.9242839,0.9336899,0.920904 ,2.8812766, + 0.9271864,0.8993225,0.8857986,0.8936499,0.8895433,0.8900022,0.8410531, + 0.8081046,0.8150144,0.8173641,0.8881866,0.8837494,0.8417418,0.8877832, + 0.9664047,0.9465755,0.8891603,1.0593798,1.0501429,1.0378563,0.9041524, + 0.9222154,0.9227488,0.8894223,1.1206282,0.8359311,1.1750071,0.8632696, + 0.0000001,0.8440654,0.9061905,0.9033526,0.9075296,0.9265232,0.9251202, + 0.9390653,0.9226105,0.935118 ,1.0248573,0.9950228,1.016836 ,1.0150337, + 0.8846998,0.8870716,0.8825005,0.8993919,0.9015642,0.917635 ,0.9108042, + 0.9158255,0.8933692,0.8818774,0.8733479,0.8590702,0.8610741,0.8412985, + 0.8419823,0.8535126,0.9552853,0.9233503,0.9074404,0.8874421,0.0000001, + 0.9037543,0.9428068,0.9528409,0.8795176,0.8777585,0.9160822,0.9397873, + 0.9309441,0.9063056,0.9192985,0.9255057,0.9270568,0.9176704,0.9140722, + 0.9111696,0.8597785,0.8489559,0.843753 ,0.8581451,0.9068368,0.8959244, + 0.9229929,0.871972 ,0.9834073,0.9476991,0.9360896,1.081524 ,0.9255442, + 0.9070221,0.9115756,0.9298295,0.9134066,0.9056591,0.9027434,0.8674105, + 0.9019305,0.8612094,0.8585056,0.854815 ,0.0000001,0.9021256,0.9177787, + 0.9240243,0.9644239,0.9404687,0.9274049,0.9379409,1.0399606,1.033352 , + 1.0249641,1.0473272,0.8932669,0.9111941,0.8852406,0.8920174,0.9242499, + 0.9056967,0.9006191,0.9015262,0.9182317,0.9183906,0.9038095,0.904799 , + 0.8838023,0.8785893,0.8584824,0.8979258,0.9706077,0.9469935,0.9398977, + 0.894461 ,0.93994 ,0.923337 ,0.9488781,0.9627277,0.9054735,0.9163985, + 0.8944787,0.9150251,1.0493075,0.9096289,0.9115776,0.9412426,0.9343278, + 0.9121064,0.9117633,0.9251044,0.8971121,0.8652557,0.8633423,0.8604623, + 0.9248523,0.9076622,0.917069 ,0.8871456,0.7269943,0.9629616,0.9667225, + 0.9250519,0.9176884,0.8880241,0.9236936,0.9247792,1.0054232,1.0092628, + 0.9994277,0.9991693,0.9058928,0.91171 ,0.9149265,0.915843 ,0.8517995, + 1.2385432,0.8757702,0.8800565,0.9347579,0.9362207,0.9103072,0.9455385, + 0.8727469,0.8400666,0.8438162,0.8415763,0.9646621,0.9707538,0.9637925, + 0.9641757,0.9592127,0.952417 ,0.943792 ,0.925786 ,0.9483845,0.9503665, + 0.9362003,0.9343288,0.9373538,0.9214206,0.9170751,0.9483343,0.9092611, + 0.9025595,0.9094557,0.8846688,0.9492338,0.9302807,0.9313844,0.9440831, + 0.9525137,0.9451442,0.9452839,0.9544351,1.036723 ,1.0263921,0.9881323, + 0.9197441,0.9673854,0.9597923,0.9846507,0.9979741,0.9559562,0.9387934, + 0.9402372,0.9639017,0.9070854,0.9081604,0.8969148,0.8985816,0.8914095, + 0.9212565,0.9167472,0.9287409,0.902436 ,0.8889644,0.8948577,0.9066438, + 0.9909534,0.9763708,0.9878008,0.9885211,0.8955337,0.8991327,0.8798093, + 0.8914046,0.8749264,0.8727064,0.8536081,0.8715125,0.8831692,0.8919016, + 0.890573 ,0.8926457,0.8800267,0.8306233,0.0000001,0.8467921,0.9303848, + 0.9340462,0.9263893,0.9474682,0.9142375,0.9178317,0.8966044,0.8933908, + 1.0630243,0.9105239,0.8925556,0.908989 ,0.9122123,0.894343 ,0.9251699, + 0.9552048,0.900656 ,0.8886392,0.9272086,0.8625895,0.9300183,0.934134 , + 0.9291555,0.9527701,0.9416874,0.9565993,0.9468805,0.9310883,0.9963626, + 0.981036 ,0.9834724,0.8948759,0.8951459,0.9467054,1.045526 ,0.9973741, + 0.9467732,0.9394466,0.9388553,0.9175566,0.8865193,0.8930401,0.8786154, + 0.8805791,0.9849347,0.8849503,0.9020472,0.9081354,0.8883678,0.8618975, + 0.8621318,0.8847593,0.9791163,0.9981784,0.9598348,0.9630426,0.8954888, + 0.9089435,0.906523 ,0.9254694,0.8724284,1.549498 ,0.854642 ,0.8899876, + 0.884106 ,0.8911538,0.8788657,0.8989016,0.8683069,0.8187966,0.8331737, + 0.8169547,0.9497713,0.9372764,0.9718387,0.9716983,0.8817951,0.9177381, + 0.9272385,0.9305192,0.9138 ,0.8917226,0.9022007,0.8728969,0.8857559, + 0.8511966,0.8776945,0.9188874,0.8799872,0.8727769,0.8972793,0.8775748, + 0.9025099,0.9059016,0.9018834,0.9358472,0.9280242,0.9306515,0.930319 , + 0.9408762,0.9894212,0.9801961,0.9481966,0.930518 ,0.9068527,0.926452 , + 0.9481174,0.9932294,0.9508854,0.9168876,0.8955552,0.9298086,0.8856096, + 0.8778232,0.8678781,0.8428098,0.8649303,0.8521905,0.8853881,0.896262 , + 0.8637611,0.8508386,0.8579808,0.8781487,0.9782724,0.9819542,0.967945 , + 0.9718521,0.8657284,0.8617702,0.8596571,0.8718904,0.815865 ,0.9508535, + 0.8448715,0.8618798,0.9203976,0.8956626,0.9108895,0.9208714,0.8267219, + 0.8333327,0.8175609,0.8405349,0.9207596,0.9302374,0.922721 ,0.9375702, + 0.8972806,0.9022034,0.9092163,0.8919818,0.9115573,0.8941678,0.9727003, + 0.8788491,0.8066372,0.8540529,0.8720537,0.9097501,0.881356 ,0.8739368, + 0.9094095,0.8718069,0.9059213,0.9068483,0.8904512,0.903352 ,0.9266117, + 0.9053527,0.8990905,0.9183056,0.9928399,0.9813229,0.9759782,0.9492933, + 0.9382915,0.9312818,0.9518742,0.9820717,0.9150143,0.8835462,0.905087 , + 0.9380701,0.8669695,0.8730215,0.8537797,0.842343 ,0.8181646,0.8662508, + 0.8914459,0.8917838,0.8953646,0.8582759,0.8843335,0.9019104,0.9775726, + 0.9695851,0.9684169,0.9945092,0.8906423,0.9011754,0.8905966,0.9067472, + 0.8615755,0.8759038,0.8511059,0.8939573,0.9214789,0.8934948,0.9003874, + 0.9254834,0.8977927,0.8781966,0.8783478,0.8897681,0.9544448,0.9752168, + 0.9538611,0.9523727,0.8953019,0.8955504,0.8835472,0.9036127,0.9425184, + 0.9428679,0.9121487,0.8942021,0.8973826,0.8607216,0.8798548,0.9563062, + 0.9242093,0.8927971,0.9064167,0.8659616,0.9165348,0.9324718,0.9197962, + 0.9270453,0.9173116,0.9100388,0.8664268,0.9012297,0.9287284,0.9629037, + 0.9950356,1.0044856,0.9998307,0.9981116,1.0173699,1.0312284,0.9523295, + 0.927979 ,0.9188983,0.9468584,0.8899338,0.8799069,0.8932109,0.8625482, + 0.8758663,0.8662992,0.8897169,0.8896759,0.9471669,0.8646078,0.9203457, + 0.9465771,1.0671935,1.0762529,1.0574509,1.0543979,0.950247 ,0.9430968, + 0.9417606,0.960602 ,0.8665491,0.8781953,0.8720518,0.8933613,0.9384555, + 0.9348907,0.9343287,0.9597977,0.9400162,0.9181851,0.9304919,0.9181332, + 0.9856796,0.989359 ,0.979789 ,0.9625634,1.0298804,0.9681855,0.926324 , + 0.9493014,0.952226 ,0.9659102,0.9622204,0.9933803,0.9975445,0.9534022, + 0.9508471,1.0023971,0.925873 ,0.9181251,0.9037386,0.9369083,0.9686341, + 0.951229 ,0.9527286,0.9704438,0.952726 ,0.9563661,0.9672213,0.9009546, + 0.891305 ,0.9141365,0.9042941,0.9908844,1.02451 ,1.0002937,1.0145459, + 1.0238333,0.9640087,0.9803975,0.9345359,0.9562771,0.9798419,0.9632123, + 0.9474075,0.9594575,0.9523167,0.9568143,0.9725029,0.9635358,0.8913772, + 0.9376766,0.9153062,0.9443082,1.0907506,1.0779955,1.0835589,1.077103 , + 0.94592 ,0.9423046,0.9353216,1.0058889,0.8812236,0.8900912,0.8739714, + 0.908954 ,0.9684916,0.9758947,0.9528789,0.9715638,0.9147444,0.9392554, + 0.9166325,0.9577266,1.0328426,1.0275623,0.9930462,1.0105317,1.0487862, + 1.0094688,0.9696991,0.9790145,0.9874703,0.9714156,1.0046459,0.9714112, + 0.9987967,0.9554723,0.9812179,1.0174359,0.9316527,0.9212265,0.9473284, + 0.9529327,0.9768106,0.9761072,0.9925398,1.0105116,0.9765943,0.9735287, + 0.9720789,0.9780715,0.8837507,0.9996244,1.0094591,0.963135 ,1.0569199, + 1.0577636,1.0485023,1.0917665,1.0001658,0.9943501,0.994733 ,0.9737829, + 0.9874289,0.9499856,0.9437758,0.9718275,0.9466712,0.9368256,0.9245117, + 0.9746943,0.9231877,0.94381 ,0.9099722,0.9743401,1.0912923,1.0798532, + 1.0705048,1.0671401,1.0020626,0.9723217,0.9538407,1.0237085,0.9082063, + 0.9232261,0.9122615,0.9056468,1.0189087,1.0061275,1.0277444,1.0416385, + 0.962988 ,0.9448321,0.9274885,0.9500597,1.0350192,1.0535637,1.0434896, + 1.0389384,1.0624195,1.0245159,1.0062119,1.0112492,0.9908073,1.0161494, + 1.0189636,1.0372617,1.0417999,0.9965699,0.98918 ,1.0221821,0.9552784, + 0.9465883,0.9436496,0.9627379,0.9957007,0.9908555,1.0349085,1.051325 , + 1.028265 ,0.9742572,0.9853188,1.0277784,1.0784379,1.0248644,1.003191 , + 1.053859 ,1.0747 ,1.0681137,1.0964813,1.1012894,1.0878161,1.0215803, + 1.0319945,1.0705597,1.0117067,1.0089118,0.9623004,0.9945062,0.9931936, + 0.9826046,0.9807656,0.9893571,0.9855912,0.9956348,1.0180117,1.0992355, + 1.1510247,1.1642762,1.1348028,1.173378 ,1.0495415,1.0537665,1.0280858, + 1.0769577,0.9539952,0.9503716,0.9480621,0.9564386,1.0447392,1.055281 , + 1.0632157,1.0446833,0.9611291,0.9580613,1.0140576,1.0192964,1.1120509, + 1.0763414,1.0876051,1.0807177,1.0965352,1.0385919,1.0403399,1.010437 , + 1.0453093,1.0263721,1.0174105,1.0635544,1.0635546,1.0340421,0.9741846, + 1.0584152,1.0422455,0.9897347,0.9849003,1.0250511,1.0373392,1.0450774, + 1.0938035,1.0942651,1.0443715,1.0503259,1.057446 ,1.0592597,1.0620625, + 1.1111387,1.1216173,1.07478 ,1.1132259,1.1209106,1.1106815,1.1423119, + 1.1024584,1.1221232,1.0857874,1.119742 ,1.0454632,1.0458753,1.0386395, + 1.0446345,1.0093486,1.031795 ,1.0488297,1.0821855,1.0077721,0.989686 , + 1.0048161,1.0512829,1.1880068,1.1788449,1.1607702,1.1446868,1.0427889, + 1.0694175,1.0607653,1.0898038,1.0094677,0.9899454,1.0312396,1.035437 , + 1.1059195,1.1086949,1.0641108,1.0961732,0.9638143,0.9419206,0.9821325, + 1.029164 ,1.1191941,1.1493175,1.1181508,1.1407369,1.1214831,1.0663868, + 1.0815727,1.1323632,1.080952 ,1.0808178,1.0681598,1.0592092,1.1199073, + 1.0957614,1.0681812,1.095979 ,1.0511014,1.0613471,1.0412358,1.0636799, + 1.1067268,1.0797632,1.0823264,1.1153238,1.1133441,1.0766457,1.0854424, + 1.0825747,1.0796758,1.077734 ,1.0952778,1.0772076,1.116454 ,1.1395183, + 1.1075819,1.1624501,1.1176701,1.0958973,1.1218029,1.1186683,1.0628506, + 1.1145004,1.082948 ,2.0175941,1.0875287,1.1025825,1.0269455,1.051285 , + 1.0476145,1.0404844,1.04963 ,1.0591438,1.1902895,1.2070227,1.070815 , + 1.1989648,1.0498666,1.0610474,1.0391423,1.1304657,1.0339167,0.9998445, + 1.0041345,1.0160474,1.0799819,1.0712526,1.0879661,1.1218227,1.009931 , + 0.9974062,1.0133066,1.0665259,1.146356 ,1.11963 ,1.1033186,1.1570126, + 1.0548068,1.0348623,1.0482756,1.0204102,1.1040101,1.0592386,0.0000001, + 1.0342314,1.103851 ,1.1129369,1.086817 ,1.1150911,1.0553069,1.1031967, + 1.0349835,1.0537988,1.057883 ,1.0326748,1.0403845,1.0982782,1.1092652, + 1.1100249,1.0888118,1.2074842,1.0731583,1.0833149,1.0942907,1.1083862, + 1.1723955,1.1690109,1.1536716,1.1711152,1.0897936,1.0986527,1.1139878, + 1.1540499,1.1051458,1.0760595,1.0817837,1.0871581,1.0496042,1.0790346, + 1.0484509,1.0936309,1.1005198,1.0929288,1.0838492,1.0982997,1.1599445, + 1.1893239,1.1655681,1.2092586,1.0883923,0.0000001,1.0871845,1.1466825, + 1.0404817,1.0230678,1.0366768,1.0639437,1.1151003,1.1272596,1.1084887, + 1.172429 ,1.0334686,1.056801 ,1.0597215,1.1326951,1.1498877,1.1962935, + 1.1868553,1.197981 ,1.1254083,1.1704431,1.1394123,1.1020141,1.1297313, + 1.0543509,1.0454857,1.0557848,1.1286277,1.1447449,1.1176616,1.1541518, + 1.0896667,1.0803887,1.0532128,1.092551 ,1.1030624,1.1308889,1.1280392, + 1.1362039,1.1384581,1.1629614,1.1217985,1.1243501,1.1104747,1.1264488, + 1.1229146,1.1263402,1.1778469,1.1807829,1.1596237,1.2130113,1.1391164, + 1.1422114,1.1164465,1.1751232,1.1258872,1.099769 ,1.0997097,1.1154337, + 1.0979413,1.1053877,1.1027399,1.1099522,1.0839096,1.0836432,1.0714954, + 1.1008861,1.2654308,1.2331656,1.2076157,1.1879531,1.0935781,1.7174256, + 1.1764588,1.1788416,1.0990402,1.0679119,1.045539 ,1.0417056,1.1428436, + 1.11865 ,1.1203463,1.1667153,1.0560808,1.059954 ,1.0763974,1.0821347, + 1.1756307,1.2023616,1.1829935,1.1883497,1.0870489,1.095404 ,1.1019858, + 1.1221294,1.0918556,1.1270142,1.1056459,1.1165003,1.1656616,1.1915104, + 0.002418 ,1.1863734,1.1364913,1.1363342,1.1130465,1.110378 ,1.1059235, + 1.1423405,1.1317402,1.1555637,1.19754 ,1.2092884,1.1779846,1.1680648, + 1.0450194,1.0761367,1.0764713,1.0921346,1.2287006,1.1786282,1.1539404, + 1.1696078,1.1572577,1.1409811,1.1399884,1.1648638,1.1468616,1.1229811, + 1.126923 ,1.1402842,1.0744516,1.1010847,1.1182138,1.129174 ,1.1766611, + 1.1814339,1.1808836,1.2256684,1.1890299,1.09418 ,1.2673656,1.2581869, + 1.1922612,1.2071455,1.1834393,1.189612 ,1.1241446,1.1361836,1.2856306, + 1.0855542,1.1677229,1.129777 ,1.1726019,1.1948112,1.177284 ,1.1930918, + 1.2184905,1.2298344,1.2539822,1.2478415,1.2095121,1.2372787,1.1454738, + 3.1246946,1.1560615,1.1634603,1.2031316,1.1657577,1.1755668,1.1764408, + 1.2373508,1.2221774,1.2183428,1.238299 ,1.1809549,1.191622 ,1.151616 , + 1.2120161,1.1659451,1.1903535,1.1537067,1.2121307,1.2561139,1.2496953, + 1.2179667,1.1991129,1.0504661,1.1208445,1.0576257,1.0786569,1.2795471, + 1.2460271,1.2595681,1.2700136,1.2370667,1.2096518,1.1916556,1.193431 , + 1.0698317,1.144996 ,1.0978631,1.1083387,1.1395663,1.1424139,1.1672275, + 1.1997005,1.2066722,1.2632322,1.2644491,1.2359862,1.30099 ,1.3310392, + 1.3187488,1.3390772,1.2772553,1.2618415,1.2443427,1.2669835,1.1606162, + 1.1572101,1.166028 ,1.1820868,1.237196 ,1.2618593,1.2292744,1.2615335, + 1.2021271,1.2560732,1.0985605,1.1192125,1.2854187,1.2854668,1.2659054, + 1.2904642,1.204288 ,1.2769686,1.22887 ,1.2694381,1.262182 ,1.2492793, + 1.2524626,1.2057602,1.285684 ,1.3115458,1.3069377,1.3391898,1.2591854, + 1.2057227,1.2264768,1.2316214,1.2125773,1.228851 ,1.2327005,1.2707509, + 1.2734746,1.3064344,1.2484472,1.2517314,1.3417968,1.3300421,1.3112333, + 1.3796477,1.2670193,1.2653888,1.3392452,1.3002052,1.2524494,1.254415 , + 1.2804451,1.2688684,1.2028832,1.1860383,1.1875746,1.1912442,0.0000001, + 1.2032371,1.2014136,1.231438 ,1.3126636,1.331844 ,1.3611454,1.4050549, + 1.4224403,1.4060786,1.3756822,1.3766484,1.3069599,1.2942712,1.2930294, + 1.3145667,1.3122438,1.2794976,1.2148988,1.3100493,1.3224905,1.3191464, + 1.3389342,1.361294 ,1.2701417,1.3292892,1.1934788,1.2651747,1.5510794, + 1.4734362,1.4419538,1.4431967,1.2666522,1.2626339,1.2941803,1.3723079, + 1.3035368,1.3176153,1.2581673,1.2753432,1.3376918,1.3208125,1.3536242, + 1.4160626,1.4042524,1.344823 ,1.2438911,1.2328366,1.3651066,1.3063282, + 1.3048015,1.4230167,1.35694 ,1.4077983,1.3601282,1.3300114,1.3991088, + 1.4520401,1.4256567,1.3559659,1.4381483,1.4401627,1.3999768,1.4125986, + 1.5223697,1.4434851,1.4603108,1.5000014,1.2174413,1.2294974,1.2586482, + 1.216323 ,1.2512149,1.2926644,1.2528789,1.2970006,1.3622391,1.3856924, + 1.4004105,1.4416406,1.4794058,1.4634441,1.4094539,1.4000301,1.3603994, + 1.3507206,1.2953093,1.3714509,1.2608073,1.2605048,1.1679753,1.2375603, + 1.301859 ,1.3278127,1.3557078,1.3832617,1.2936115,1.3297484,1.3304836, + 1.3198843,1.5357888,1.5275854,1.4613336,1.3965021,1.2506508,1.2348884, + 1.2870482,1.3202029,1.3375303,0.0000001,1.298619 ,1.3328781,1.4041303, + 1.4315721,1.3459045,1.3987832,1.4487712,1.3514799,1.3224082,1.3118832, + 0.7346643,1.4961067,1.5317262,1.5882863,1.3276595,1.3988692,1.3189229, + 1.3246715,1.4484233,1.459936 ,1.4757891,1.4265023,1.3769624,1.4194289, + 1.4359689,1.4053208,1.5716549,1.5246555,1.4746208,1.34677 ,1.2433277, + 1.2356131,1.2907763,1.2757168,1.3311623,1.3449943,1.2992672,0.0000001, + 1.3622391,1.3856924,1.4004105,1.4416406,1.4794058,1.4634441,1.4094539, + 1.4000301,1.3603994,1.3507206,1.2953093,1.3714509,1.2608073,1.2605048, + 1.1679753,1.2375603,1.301859 ,1.3278127,1.3557078,1.3832617,1.2936115, + 1.3297484,1.3304836,1.3198843,1.5357888,1.5275854,1.4613336,1.3965021, + 1.2506508,1.2348884,1.2870482,1.3202029,1.3375303,0.0000001,1.298619 , + 1.3328781,1.4041303,1.4315721,1.3459045,1.3987832,1.4487712,1.3514799, + 1.3224082,1.3118832,0.7346643,1.4961067,1.5317262,1.5882863,1.3276595, + 1.3988692,1.3189229,1.3246715,1.4484233,1.459936 ,1.4757891,1.4265023, + 1.3769624,1.4194289,1.4359689,1.4053208,1.5716549,1.5246555,1.4746208, + 1.34677 ,1.2433277,1.2356131,1.2907763,1.2757168,1.3311623,1.3449943, + 1.2992672,0.0000001) + +ecalMLClient = cms.untracked.PSet( + params = cms.untracked.PSet( + MLThreshold = cms.untracked.double(MLThreshold), + PUcorr_slope = cms.untracked.double(PUcorr_slope), + PUcorr_intercept = cms.untracked.double(PUcorr_intercept), + avgOcc = cms.untracked.vdouble(avgOcc) + ), + sources = cms.untracked.PSet( + DigiAllByLumi = ecalOccupancyTask.MEs.DigiAllByLumi, + AELoss = ecalOccupancyTask.MEs.AELoss, + PU = ecalOccupancyTask.MEs.PU, + NumEvents = ecalOccupancyTask.MEs.NEvents + ), + MEs = cms.untracked.PSet( + MLQualitySummary = cms.untracked.PSet( + path = cms.untracked.string('%(subdet)s/%(prefix)sSummaryClient/%(prefix)sOT%(suffix)s ML quality summary'), + kind = cms.untracked.string('TH2F'), + otype = cms.untracked.string('Ecal3P'), + btype = cms.untracked.string('SuperCrystal'), + description = cms.untracked.string('Quality summary from the ML inference.') + ), + EventsperMLImage = cms.untracked.PSet( + path = cms.untracked.string('Ecal/Trends/Number of Events used per ML image'), + kind = cms.untracked.string('TProfile'), + otype = cms.untracked.string('Ecal2P'), + btype = cms.untracked.string('Trend'), + description = cms.untracked.string('Trend of the number of events in an image fed into the ML model') + ) + ) +) diff --git a/DQM/EcalMonitorClient/src/MLClient.cc b/DQM/EcalMonitorClient/src/MLClient.cc new file mode 100644 index 0000000000000..7154f3859e773 --- /dev/null +++ b/DQM/EcalMonitorClient/src/MLClient.cc @@ -0,0 +1,281 @@ +#include "DQM/EcalMonitorClient/interface/MLClient.h" + +#include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h" + +#include "CondFormats/EcalObjects/interface/EcalDQMStatusHelper.h" + +#include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include "PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h" + +#include "DQM/EcalCommon/interface/MESetNonObject.h" + +using namespace cms::Ort; + +namespace ecaldqm { + MLClient::MLClient() : DQWorkerClient() { qualitySummaries_.insert("MLQualitySummary"); } + + void MLClient::setParams(edm::ParameterSet const& _params) { + MLThreshold_ = _params.getUntrackedParameter("MLThreshold"); + PUcorr_slope_ = _params.getUntrackedParameter("PUcorr_slope"); + PUcorr_intercept_ = _params.getUntrackedParameter("PUcorr_intercept"); + avgOcc_ = _params.getUntrackedParameter>("avgOcc"); + if (!onlineMode_) { + MEs_.erase(std::string("MLQualitySummary")); + MEs_.erase(std::string("EventsperMLImage")); + sources_.erase(std::string("PU")); + sources_.erase(std::string("NumEvents")); + sources_.erase(std::string("DigiAllByLumi")); + sources_.erase(std::string("AELoss")); + } + } + + void MLClient::producePlots(ProcessType) { + if (!onlineMode_) + return; + using namespace std; + MESet& meMLQualitySummary(MEs_.at("MLQualitySummary")); + MESet& meEventsperMLImage(MEs_.at("EventsperMLImage")); + + MESetNonObject const& sPU(static_cast(sources_.at("PU"))); + MESetNonObject const& sNumEvents(static_cast(sources_.at("NumEvents"))); + + //Get the no.of events and the PU per LS calculated in OccupancyTask + int nEv = sNumEvents.getFloatValue(); + double pu = sPU.getFloatValue(); + //Do not compute ML quality if PU is non existent. + if (pu < 0.) { + return; + } + uint32_t mask(1 << EcalDQMStatusHelper::PEDESTAL_ONLINE_HIGH_GAIN_RMS_ERROR | + 1 << EcalDQMStatusHelper::PHYSICS_BAD_CHANNEL_WARNING | + 1 << EcalDQMStatusHelper::PHYSICS_BAD_CHANNEL_ERROR); + + //////////////// ML Data Preprocessing ////////////////////////////////// + //Inorder to feed the data into the ML model we apply some preprocessing. + //We use the Digi Occupancy per Lumisection as the input source. + //The model was trained on each occupancy plot having 500 events. + //In apprehension of the low luminosity in the beginning of Run3, where in online DQM + //the no.of events per LS could be lower than 500, we sum the occupancies over a fixed no.of lumisections as a running sum, + //and require that the total no.of events on this summed occupancy to be atleast 200. + //(This no.of LS and the no.of events are parameters which would require tuning later) + //This summed occupancy is now the input image, which is then corrected for PileUp(PU) dependence and + //change in no.of events, which are derived from training. + //The input image is also padded by replicating the top and bottom rows so as to prevent the "edge effect" + //wherein the ML model's learning degrades near the edge of the data set it sees. + //This padding is then removed during inference on the model output. + + //Get the histogram of the input digi occupancy per lumisection. + TH2F* hEbDigiMap((sources_.at("DigiAllByLumi")).getME(1)->getTH2F()); + + size_t nTowers = nEtaTowers * nPhiTowers; //Each occupancy map is of size 34x72 towers + std::vector ebOccMap1dCumulPad; //Vector to feed into the ML network + std::valarray ebOccMap1d(nTowers); //Array to store occupancy map of size 34x72 + //Store the values from the input histogram into the array + //to do preprocessing + for (int i = 0; i < hEbDigiMap->GetNbinsY(); i++) { //NbinsY = 34, NbinsX = 72 + for (int j = 0; j < hEbDigiMap->GetNbinsX(); j++) { + int bin = hEbDigiMap->GetBin(j + 1, i + 1); + int k = (i * nPhiTowers) + j; + ebOccMap1d[k] = hEbDigiMap->GetBinContent(bin); + } + } + ebOccMap1dQ.push_back(ebOccMap1d); //Queue which stores input occupancy maps for nLS lumis + NEventQ.push_back(nEv); //Queue which stores the no.of events per LS for nLS lumis + + if (NEventQ.size() < nLS) { + return; //Should have nLS lumis to add the occupancy over. + } + if (NEventQ.size() > nLS) { + NEventQ.pop_front(); //Keep only nLS consecutive LS. Pop the first one if size greater than nLS + } + if (ebOccMap1dQ.size() > nLS) { + ebOccMap1dQ.pop_front(); //Same conditon for the input occupancy maps. + } + + int TNum = 0; + for (size_t i = 0; i < nLS; i++) { + TNum += NEventQ[i]; //Total no.of events over nLS lumis + } + if (TNum < 200) { + return; //The total no.of events should be atleast 200 over nLS for meaningful statistics + } + //Fill the ME to monitor the trend of the total no.of events in each input image to the ML model + meEventsperMLImage.fill(getEcalDQMSetupObjects(), EcalBarrel, double(timestamp_.iLumi), double(TNum)); + + //Array to hold the sum of inputs, which make atleast 200 events. + std::valarray ebOccMap1dCumul(0., nTowers); + + for (size_t i = 0; i < ebOccMap1dQ.size(); i++) { + ebOccMap1dCumul += ebOccMap1dQ[i]; //Sum the input arrays of N LS. + } + //Applying PU correction derived from training + ebOccMap1dCumul = ebOccMap1dCumul / (PUcorr_slope_ * pu + PUcorr_intercept_); + + //Scaling up to match input dimensions. 36*72 used instead of 34*72 to accommodate the additional padding + //of 2 rows to prevent the "edge effect" which is done below + ebOccMap1dCumul = ebOccMap1dCumul * (nEtaTowersPad * nPhiTowers); + + //Correction for no.of events in each input image as originally model trained with 500 events per image + ebOccMap1dCumul = ebOccMap1dCumul * (500. / TNum); + + //The pre-processed input is now fed into the input tensor vector which will go into the ML model + ebOccMap1dCumulPad.assign(std::begin(ebOccMap1dCumul), std::end(ebOccMap1dCumul)); + + //Replicate and pad with the first and last row to prevent the edge effect + for (int k = 0; k < nPhiTowers; k++) { + float val = ebOccMap1dCumulPad[nPhiTowers - 1]; + ebOccMap1dCumulPad.insert(ebOccMap1dCumulPad.begin(), + val); //padding in the beginning with the first row elements + } + + int size = ebOccMap1dCumulPad.size(); + for (int k = (size - nPhiTowers); k < size; k++) { + float val = ebOccMap1dCumulPad[k]; + ebOccMap1dCumulPad.push_back(val); //padding at the end with the last row elements + } + + ///// Model Inference ////// + //An Autoencoder (AE) network with resnet architecture is used here which is trained on + //certified good data (EB digi occupancy) from Run 2018 data. + //On giving an input occupancy map, the encoder part of the AE compresses and reduces the input data, learning its features, + //and the decoder reconstructs the data from the encoded form into a representation as close to the original input as possible. + //We then compute the Mean squared error (MSE) between the input and output image, also called the Reconstruction Loss, + //calculated at a tower by tower basis. + //Thus, given an anomalous tower the loss should be significantly higher than the loss with respect to good towers, which the model + //has already seen --> anomaly detection. + //When calculating the loss we also apply a response correction by dividing each input and output image with the average occupancy from + //all 2018 data (also to be tuned),to accommodate the difference in response of crystals in different regions of the Ecal Barrel + //Further each loss map from each input image is then multiplied by the last N loss maps, + ///so that real anomalies which persist with time are enhanced and fluctuations are suppressed. + //A quality threshold is then applied on this time multiplied loss map, to mark them as GOOD or BAD, + //after which it is stored as a quality summary ME. + + ///ONNX model running/// + std::string instanceName{"AE-DQM-inference"}; + std::string modelFilepath = edm::FileInPath("DQM/EcalMonitorClient/data/onnxModels/resnet.onnx").fullPath(); + + Ort::SessionOptions sessionOptions; + sessionOptions.SetIntraOpNumThreads(1); + Ort::Env env(OrtLoggingLevel::ORT_LOGGING_LEVEL_WARNING, instanceName.c_str()); + Ort::Session session(env, modelFilepath.c_str(), sessionOptions); + + Ort::AllocatorWithDefaultOptions allocator; + + const char* inputName = session.GetInputName(0, allocator); + + Ort::TypeInfo inputTypeInfo = session.GetInputTypeInfo(0); + auto inputTensorInfo = inputTypeInfo.GetTensorTypeAndShapeInfo(); + + std::vector inputDims = inputTensorInfo.GetShape(); + + const char* outputName = session.GetOutputName(0, allocator); + + Ort::TypeInfo outputTypeInfo = session.GetOutputTypeInfo(0); + auto outputTensorInfo = outputTypeInfo.GetTensorTypeAndShapeInfo(); + + std::vector outputDims = outputTensorInfo.GetShape(); + + size_t TensorSize = nEtaTowersPad * nPhiTowers; + std::vector ebRecoOccMap1dPad(TensorSize); //To store the output reconstructed occupancy + + std::vector inputNames{inputName}; + std::vector outputNames{outputName}; + std::vector inputTensors; + std::vector outputTensors; + + Ort::MemoryInfo memoryInfo = + Ort::MemoryInfo::CreateCpu(OrtAllocatorType::OrtArenaAllocator, OrtMemType::OrtMemTypeDefault); + inputTensors.push_back(Ort::Value::CreateTensor( + memoryInfo, ebOccMap1dCumulPad.data(), TensorSize, inputDims.data(), inputDims.size())); + + outputTensors.push_back(Ort::Value::CreateTensor( + memoryInfo, ebRecoOccMap1dPad.data(), TensorSize, outputDims.data(), outputDims.size())); + + session.Run(Ort::RunOptions{nullptr}, + inputNames.data(), + inputTensors.data(), + 1, + outputNames.data(), + outputTensors.data(), + 1); + + ///Inference on the output from the model/// + //2D Loss map to store tower by tower loss between the output (reconstructed) and input occupancies, + //Have same dimensions as the occupancy plot + std::valarray> lossMap2d(std::valarray(nPhiTowers), nEtaTowers); + + //1D val arrays to store row wise information corresponding to the reconstructed, input and average occupancies, and loss. + //and to do element wise (tower wise) operations on them to calculate the MSE loss between the reco and input occupancy. + std::valarray recoOcc1d(0., nPhiTowers); + std::valarray inputOcc1d(0., nPhiTowers); + std::valarray avgOcc1d(0., nPhiTowers); + std::valarray loss_; + + //Loss calculation + //Ignore the top and bottom replicated padded rows when doing inference + //by making index i run over (1,35) instead of (0,36) + for (int i = 1; i < 35; i++) { + for (int j = 0; j < nPhiTowers; j++) { + int k = (i * nPhiTowers) + j; + recoOcc1d[j] = ebRecoOccMap1dPad[k]; + inputOcc1d[j] = ebOccMap1dCumulPad[k]; + avgOcc1d[j] = avgOcc_[k]; + } + //Calculate the MSE loss = (output-input)^2, with avg response correction + loss_ = std::pow((recoOcc1d / avgOcc1d - inputOcc1d / avgOcc1d), 2); + lossMap2d[i - 1] = (loss_); + } + + lossMap2dQ.push_back(lossMap2d); //Store each loss map from the output in the queue + if (lossMap2dQ.size() > nLSloss) { + lossMap2dQ.pop_front(); //Keep exactly nLSloss loss maps to multiply + } + if (lossMap2dQ.size() < nLSloss) { //Exit if there are not nLSloss loss maps + return; + } + //To hold the final multiplied loss + std::valarray> lossMap2dMult(std::valarray(1., nPhiTowers), nEtaTowers); + + //Multiply together the last nLSloss loss maps + //So that real anomalies which persist with time are enhanced and fluctuations are suppressed. + for (size_t i = 0; i < lossMap2dQ.size(); i++) { + lossMap2dMult *= lossMap2dQ[i]; + } + + //Fill the AELoss ME with the values of this time multiplied loss map + MESet const& sAELoss(sources_.at("AELoss")); + TH2F* hLossMap2dMult(sAELoss.getME(1)->getTH2F()); + for (int i = 0; i < hLossMap2dMult->GetNbinsY(); i++) { + for (int j = 0; j < hLossMap2dMult->GetNbinsX(); j++) { + int bin_ = hLossMap2dMult->GetBin(j + 1, i + 1); + double content = lossMap2dMult[i][j]; + hLossMap2dMult->SetBinContent(bin_, content); + } + } + ///////////////////// ML Quality Summary ///////////////////// + //Apply the quality threshold on the time multiplied loss map stored in the ME AELoss + //If anomalous, the tower entry will have a large loss value. If good, the value will be close to zero. + + MESet::const_iterator dAEnd(sAELoss.end(GetElectronicsMap())); + for (MESet::const_iterator dItr(sAELoss.beginChannel(GetElectronicsMap())); dItr != dAEnd; + dItr.toNextChannel(GetElectronicsMap())) { + DetId id(dItr->getId()); + + bool doMaskML(meMLQualitySummary.maskMatches(id, mask, statusManager_, GetTrigTowerMap())); + + float entries(dItr->getBinContent()); + int quality(doMaskML ? kMGood : kGood); + //If a trigger tower entry is greater than the ML threshold, set it to Bad quality, otherwise Good. + if (entries > MLThreshold_) { + quality = doMaskML ? kMBad : kBad; + } + //Fill the quality summary with the quality of the given tower id. + meMLQualitySummary.setBinContent(getEcalDQMSetupObjects(), id, double(quality)); + } // ML Quality Summary + } // producePlots() + + DEFINE_ECALDQM_WORKER(MLClient); +} // namespace ecaldqm diff --git a/DQM/EcalMonitorTasks/interface/OccupancyTask.h b/DQM/EcalMonitorTasks/interface/OccupancyTask.h index d58a0f1172fcd..7a1b28a6952bd 100644 --- a/DQM/EcalMonitorTasks/interface/OccupancyTask.h +++ b/DQM/EcalMonitorTasks/interface/OccupancyTask.h @@ -11,6 +11,7 @@ #include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbService.h" #include "DataFormats/Provenance/interface/Timestamp.h" #include "FWCore/Framework/interface/ConsumesCollector.h" +#include "DataFormats/Scalers/interface/LumiScalers.h" namespace ecaldqm { class OccupancyTask : public DQWorkerTask { @@ -30,6 +31,7 @@ namespace ecaldqm { void runOnTPDigis(EcalTrigPrimDigiCollection const&); void runOnRecHits(EcalRecHitCollection const&, Collections); void setTokens(edm::ConsumesCollector&) override; + void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; private: void setParams(edm::ParameterSet const&) override; @@ -38,6 +40,12 @@ namespace ecaldqm { float recHitThreshold_; float tpThreshold_; edm::TimeValue_t m_iTime; + edm::InputTag lumiTag; + edm::EDGetTokenT lumiScalersToken_; + double scal_pu; + bool FindPUinLS = false; + int nEv; + bool lumiCheck_; }; inline bool OccupancyTask::analyze(void const* _p, Collections _collection) { diff --git a/DQM/EcalMonitorTasks/python/OccupancyTask_cfi.py b/DQM/EcalMonitorTasks/python/OccupancyTask_cfi.py index b7080fd6b94cc..f80773d936c10 100644 --- a/DQM/EcalMonitorTasks/python/OccupancyTask_cfi.py +++ b/DQM/EcalMonitorTasks/python/OccupancyTask_cfi.py @@ -2,12 +2,15 @@ tpThreshold = 4. recHitThreshold = 0.5 +lumiCheck = False ecalOccupancyTask = cms.untracked.PSet( params = cms.untracked.PSet( recHitThreshold = cms.untracked.double(recHitThreshold), - tpThreshold = cms.untracked.double(tpThreshold) - ), + tpThreshold = cms.untracked.double(tpThreshold), + scalers = cms.InputTag('hltScalersRawToDigi'), + lumiCheck = cms.untracked.bool(lumiCheck) + ), MEs = cms.untracked.PSet( TrendNTPDigi = cms.untracked.PSet( path = cms.untracked.string('Ecal/Trends/OccupancyTask %(prefix)s number of filtered TP digis'), @@ -242,8 +245,44 @@ otype = cms.untracked.string('Ecal3P'), btype = cms.untracked.string('ProjEta'), description = cms.untracked.string('Projection of average laser transparency correction from DB.') + ), + TrendEventsperLumi = cms.untracked.PSet( + path = cms.untracked.string('Ecal/Trends/Number of Events per Lumisection'), + kind = cms.untracked.string('TProfile'), + otype = cms.untracked.string('Ecal2P'), + btype = cms.untracked.string('Trend'), + description = cms.untracked.string('Trend of the number of events per lumisection') + ), + TrendPUperLumi = cms.untracked.PSet( + path = cms.untracked.string('Ecal/Trends/PU per Lumisection'), + kind = cms.untracked.string('TProfile'), + otype = cms.untracked.string('Ecal2P'), + btype = cms.untracked.string('Trend'), + description = cms.untracked.string('Trend of the pile up per lumisection') + ), + AELoss = cms.untracked.PSet( + path = cms.untracked.string('%(subdet)s/%(prefix)sOccupancyTask/%(prefix)sOT AE Loss'), + kind = cms.untracked.string('TH2F'), + otype = cms.untracked.string('Ecal3P'), + btype = cms.untracked.string('SuperCrystal'), + description = cms.untracked.string('AE Loss from inference') + ), + PU = cms.untracked.PSet( + path = cms.untracked.string('Ecal/EventInfo/PU in the lumi'), + kind = cms.untracked.string('REAL'), + otype = cms.untracked.string('None'), + btype = cms.untracked.string('User'), + description = cms.untracked.string('Pile up in this lumisection') + ), + NEvents = cms.untracked.PSet( + path = cms.untracked.string('Ecal/EventInfo/Number of events in the lumi'), + kind = cms.untracked.string('REAL'), + otype = cms.untracked.string('None'), + btype = cms.untracked.string('User'), + description = cms.untracked.string('Number of events in this lumisection') ) + # TPDigiProjPhi = cms.untracked.PSet( # path = cms.untracked.string('%(subdet)s/%(prefix)sOccupancyTask/%(prefix)sOT TP digi occupancy%(suffix)s projection phi'), # kind = cms.untracked.string('TH1F'), diff --git a/DQM/EcalMonitorTasks/src/OccupancyTask.cc b/DQM/EcalMonitorTasks/src/OccupancyTask.cc index f89cdf7016d5c..f5829246eabc0 100644 --- a/DQM/EcalMonitorTasks/src/OccupancyTask.cc +++ b/DQM/EcalMonitorTasks/src/OccupancyTask.cc @@ -4,6 +4,8 @@ #include "DataFormats/EcalRawData/interface/EcalDCCHeaderBlock.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/Framework/interface/ConsumesCollector.h" +#include "FWCore/Framework/interface/Event.h" +#include "DataFormats/Scalers/interface/LumiScalers.h" namespace ecaldqm { OccupancyTask::OccupancyTask() : DQWorkerTask(), recHitThreshold_(0.), tpThreshold_(0.), m_iTime(0.) {} @@ -11,9 +13,21 @@ namespace ecaldqm { void OccupancyTask::setParams(edm::ParameterSet const& _params) { recHitThreshold_ = _params.getUntrackedParameter("recHitThreshold"); tpThreshold_ = _params.getUntrackedParameter("tpThreshold"); + lumiTag = _params.getParameter("scalers"); + lumiCheck_ = _params.getUntrackedParameter("lumiCheck", false); + if (!onlineMode_) { + MEs_.erase(std::string("PU")); + MEs_.erase(std::string("NEvents")); + MEs_.erase(std::string("TrendEventsperLumi")); + MEs_.erase(std::string("TrendPUperLumi")); + MEs_.erase(std::string("AELoss")); + } } - void OccupancyTask::setTokens(edm::ConsumesCollector& _collector) { lasertoken_ = _collector.esConsumes(); } + void OccupancyTask::setTokens(edm::ConsumesCollector& _collector) { + lasertoken_ = _collector.esConsumes(); + lumiScalersToken_ = _collector.consumes(lumiTag); + } bool OccupancyTask::filterRunType(short const* _runType) { for (int iFED(0); iFED < 54; iFED++) { @@ -36,7 +50,14 @@ namespace ecaldqm { MEs_.at("DigiAllByLumi").reset(GetElectronicsMap()); MEs_.at("TPDigiThrAllByLumi").reset(GetElectronicsMap()); MEs_.at("RecHitThrAllByLumi").reset(GetElectronicsMap()); + nEv = 0; + if (onlineMode_) { + MEs_.at("PU").reset(GetElectronicsMap(), -1); + MEs_.at("NEvents").reset(GetElectronicsMap(), -1); + FindPUinLS = true; + } } + nEv++; MESet& meLaserCorrProjEta(MEs_.at("LaserCorrProjEta")); m_iTime = _evt.time().value(); if (FillLaser) { @@ -61,6 +82,18 @@ namespace ecaldqm { } FillLaser = false; } + if (lumiCheck_ && FindPUinLS) { + scal_pu = -1.; + MESet& mePU(static_cast(MEs_.at("PU"))); + edm::Handle lumiScalers; + _evt.getByToken(lumiScalersToken_, lumiScalers); + if (lumiScalers.isValid() and not lumiScalers->empty()) { + auto scalit = lumiScalers->begin(); + scal_pu = scalit->pileup(); + } + mePU.fill(getEcalDQMSetupObjects(), double(scal_pu)); + FindPUinLS = false; + } } void OccupancyTask::runOnRawData(EcalRawDataCollection const& _dcchs) { @@ -70,6 +103,18 @@ namespace ecaldqm { meDCC.fill(getEcalDQMSetupObjects(), dcchItr->id()); } + void OccupancyTask::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) { + if (onlineMode_) { + MESet& meNEvents(static_cast(MEs_.at("NEvents"))); + MESet& meTrendEventsperLumi(MEs_.at("TrendEventsperLumi")); + MESet& meTrendPUperLumi(MEs_.at("TrendPUperLumi")); + + meNEvents.fill(getEcalDQMSetupObjects(), double(nEv)); + meTrendEventsperLumi.fill(getEcalDQMSetupObjects(), EcalBarrel, double(timestamp_.iLumi), double(nEv)); + meTrendPUperLumi.fill(getEcalDQMSetupObjects(), EcalBarrel, double(timestamp_.iLumi), double(scal_pu)); + } + } + template void OccupancyTask::runOnDigis(DigiCollection const& _digis, Collections _collection) { MESet& meDigi(MEs_.at("Digi")); @@ -80,6 +125,9 @@ namespace ecaldqm { MESet& meDigiDCC(MEs_.at("DigiDCC")); MESet& meDigi1D(MEs_.at("Digi1D")); MESet& meTrendNDigi(MEs_.at("TrendNDigi")); + MESet* meAELoss = nullptr; + if (onlineMode_) + meAELoss = &MEs_.at("AELoss"); std::for_each(_digis.begin(), _digis.end(), [&](typename DigiCollection::Digi const& digi) { DetId id(digi.id()); @@ -89,6 +137,8 @@ namespace ecaldqm { meDigiAll.fill(getEcalDQMSetupObjects(), id); meDigiAllByLumi.fill(getEcalDQMSetupObjects(), id); meDigiDCC.fill(getEcalDQMSetupObjects(), id); + if (onlineMode_) + meAELoss->fill(getEcalDQMSetupObjects(), id); }); int iSubdet(_collection == kEBDigi ? EcalBarrel : EcalEndcap); diff --git a/DQM/Integration/python/clients/ecal_dqm_sourceclient-live_cfg.py b/DQM/Integration/python/clients/ecal_dqm_sourceclient-live_cfg.py index 5f9b35d4a5552..e79ba64ac064e 100644 --- a/DQM/Integration/python/clients/ecal_dqm_sourceclient-live_cfg.py +++ b/DQM/Integration/python/clients/ecal_dqm_sourceclient-live_cfg.py @@ -117,7 +117,7 @@ process.ecalMonitorClient.workerParameters.TimingClient.params.minChannelEntries = cms.untracked.int32(0) process.ecalMonitorClient.verbosity = 0 -process.ecalMonitorClient.workers = ['IntegrityClient', 'OccupancyClient', 'PresampleClient', 'RawDataClient', 'TimingClient', 'SelectiveReadoutClient', 'TrigPrimClient', 'SummaryClient'] +process.ecalMonitorClient.workers = ['IntegrityClient', 'OccupancyClient', 'PresampleClient', 'RawDataClient', 'TimingClient', 'SelectiveReadoutClient', 'TrigPrimClient', 'MLClient', 'SummaryClient'] process.ecalMonitorClient.workerParameters.SummaryClient.params.activeSources = ['Integrity', 'RawData', 'Presample', 'TriggerPrimitives', 'Timing', 'HotCell'] process.ecalMonitorClient.commonParameters.onlineMode = True @@ -135,7 +135,10 @@ process.tcdsDigis = tcdsRawToDigi.clone( InputLabel = "rawDataCollector" ) - +###### LumiScalars to get the PU/luminosity info ###### +process.hltScalersRawToDigi = cms.EDProducer( "ScalersRawToDigi", + scalersInputTag = cms.InputTag( "rawDataCollector" ) +) process.dqmEnv.subSystemFolder = 'Ecal' process.dqmSaver.tag = 'Ecal' @@ -158,6 +161,7 @@ process.ecalMonitorTask.workerParameters.TrigPrimTask.params.runOnEmul = True process.ecalMonitorTask.commonParameters.willConvertToEDM = False process.ecalMonitorTask.commonParameters.onlineMode = True +process.ecalMonitorTask.workerParameters.OccupancyTask.params.lumiCheck = True ### Sequences ### @@ -168,7 +172,7 @@ ### Paths ### -process.ecalMonitorPath = cms.Path(process.preScaler+process.ecalPreRecoSequence+process.ecalPhysicsFilter+process.ecalRecoSequence+process.tcdsDigis+process.ecalMonitorTask) +process.ecalMonitorPath = cms.Path(process.hltScalersRawToDigi+process.preScaler+process.ecalPreRecoSequence+process.ecalPhysicsFilter+process.ecalRecoSequence+process.tcdsDigis+process.ecalMonitorTask) process.ecalClientPath = cms.Path(process.preScaler+process.ecalPreRecoSequence+process.ecalPhysicsFilter+process.ecalMonitorClient) process.dqmEndPath = cms.EndPath(process.dqmEnv) @@ -186,7 +190,7 @@ elif (runTypeName == 'cosmic_run' or runTypeName == 'cosmic_run_stage1'): # process.dqmEndPath.remove(process.dqmQTest) process.ecalMonitorTask.workers = ['EnergyTask', 'IntegrityTask', 'OccupancyTask', 'RawDataTask', 'TimingTask', 'TrigPrimTask', 'PresampleTask', 'SelectiveReadoutTask'] - process.ecalMonitorClient.workers = ['IntegrityClient', 'OccupancyClient', 'PresampleClient', 'RawDataClient', 'TimingClient', 'SelectiveReadoutClient', 'TrigPrimClient', 'SummaryClient'] + process.ecalMonitorClient.workers = ['IntegrityClient', 'OccupancyClient', 'PresampleClient', 'RawDataClient', 'TimingClient', 'SelectiveReadoutClient', 'TrigPrimClient', 'MLClient', 'SummaryClient'] process.ecalMonitorClient.workerParameters.SummaryClient.params.activeSources = ['Integrity', 'RawData', 'Presample', 'TriggerPrimitives', 'Timing', 'HotCell'] process.ecalMonitorTask.workerParameters.PresampleTask.params.doPulseMaxCheck = False elif runTypeName == 'hi_run':