Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:09:38

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  \author C. Battilana S. Marcellini - INFN Bologna
0005  *
0006  *  threadsafe version (//-) oct/nov 2014 - WATWanAbdullah ncpp-um-my
0007  *
0008  */
0009 
0010 // This class header
0011 #include "DQM/DTMonitorClient/src/DTLocalTriggerEfficiencyTest.h"
0012 
0013 // Framework headers
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 #include "DQMServices/Core/interface/DQMStore.h"
0017 
0018 // Geometry
0019 #include "DQM/DTMonitorModule/interface/DTTrigGeomUtils.h"
0020 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0021 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0022 
0023 // Root
0024 #include "TF1.h"
0025 #include "TProfile.h"
0026 
0027 //C++ headers
0028 #include <iostream>
0029 #include <sstream>
0030 
0031 using namespace edm;
0032 using namespace std;
0033 
0034 DTLocalTriggerEfficiencyTest::DTLocalTriggerEfficiencyTest(const edm::ParameterSet& ps) : trigGeomUtils(nullptr) {
0035   setConfig(ps, "DTLocalTriggerEfficiency");
0036   baseFolderTM = "DT/03-LocalTrigger-TM/";
0037 
0038   bookingdone = false;
0039 }
0040 
0041 DTLocalTriggerEfficiencyTest::~DTLocalTriggerEfficiencyTest() {
0042   if (trigGeomUtils) {
0043     delete trigGeomUtils;
0044   }
0045 }
0046 
0047 void DTLocalTriggerEfficiencyTest::beginRun(const edm::Run& r, const edm::EventSetup& c) {
0048   DTLocalTriggerBaseTest::beginRun(r, c);
0049   trigGeomUtils = new DTTrigGeomUtils(muonGeom);
0050 }
0051 
0052 void DTLocalTriggerEfficiencyTest::Bookings(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0053   vector<string>::const_iterator iTr = trigSources.begin();
0054   vector<string>::const_iterator trEnd = trigSources.end();
0055   vector<string>::const_iterator iHw = hwSources.begin();
0056   vector<string>::const_iterator hwEnd = hwSources.end();
0057 
0058   //Booking
0059   if (parameters.getUntrackedParameter<bool>("staticBooking", true)) {
0060     for (; iTr != trEnd; ++iTr) {
0061       trigSource = (*iTr);
0062       for (; iHw != hwEnd; ++iHw) {
0063         hwSource = (*iHw);
0064         // Loop over the TriggerUnits
0065         for (int wh = -2; wh <= 2; ++wh) {
0066           for (int sect = 1; sect <= 12; ++sect) {
0067             for (int stat = 1; stat <= 4; ++stat) {
0068               DTChamberId chId(wh, stat, sect);
0069               bookChambHistos(ibooker, chId, "TrigEffPosvsAnglePhi");
0070               bookChambHistos(ibooker, chId, "TrigEffPosvsAngleHHHLPhi");
0071               bookChambHistos(ibooker, chId, "TrigEffPosPhi");
0072               bookChambHistos(ibooker, chId, "TrigEffPosHHHLPhi");
0073               bookChambHistos(ibooker, chId, "TrigEffAnglePhi");
0074               bookChambHistos(ibooker, chId, "TrigEffAngleHHHLPhi");
0075               if (stat <= 3) {
0076                 bookChambHistos(ibooker, chId, "TrigEffPosvsAngleTheta");
0077                 bookChambHistos(ibooker, chId, "TrigEffPosvsAngleHTheta");
0078                 bookChambHistos(ibooker, chId, "TrigEffPosTheta");
0079                 bookChambHistos(ibooker, chId, "TrigEffPosHTheta");
0080                 bookChambHistos(ibooker, chId, "TrigEffAngleTheta");
0081                 bookChambHistos(ibooker, chId, "TrigEffAngleHTheta");
0082               }
0083             }
0084 
0085             bookSectorHistos(ibooker, wh, sect, "TrigEffPhi");
0086             bookSectorHistos(ibooker, wh, sect, "TrigEffTheta");
0087           }
0088 
0089           bookWheelHistos(ibooker, wh, "TrigEffPhi");
0090           bookWheelHistos(ibooker, wh, "TrigEffHHHLPhi");
0091           bookWheelHistos(ibooker, wh, "TrigEffTheta");
0092           bookWheelHistos(ibooker, wh, "TrigEffHTheta");
0093         }
0094       }
0095     }
0096   }
0097 
0098   bookingdone = true;
0099 }
0100 
0101 void DTLocalTriggerEfficiencyTest::runClientDiagnostic(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0102   if (!bookingdone)
0103     Bookings(ibooker, igetter);
0104 
0105   // Loop over Trig & Hw sources
0106   for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr) {
0107     trigSource = (*iTr);
0108     for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw) {
0109       hwSource = (*iHw);
0110       // Loop over the TriggerUnits
0111       for (int stat = 1; stat <= 4; ++stat) {
0112         for (int wh = -2; wh <= 2; ++wh) {
0113           for (int sect = 1; sect <= 12; ++sect) {
0114             DTChamberId chId(wh, stat, sect);
0115             int sector_id = (wh + wheelArrayShift) + (sect - 1) * 5;
0116             uint32_t indexCh = chId.rawId();
0117 
0118             TH2F* TrackPosvsAngle = getHisto<TH2F>(igetter.get(getMEName("TrackPosvsAngle", "Segment", chId)));
0119             TH2F* TrackPosvsAngleandTrig =
0120                 getHisto<TH2F>(igetter.get(getMEName("TrackPosvsAngleandTrig", "Segment", chId)));
0121             TH2F* TrackPosvsAngleandTrigHHHL =
0122                 getHisto<TH2F>(igetter.get(getMEName("TrackPosvsAngleandTrigHHHL", "Segment", chId)));
0123 
0124             if (TrackPosvsAngle && TrackPosvsAngleandTrig && TrackPosvsAngleandTrigHHHL &&
0125                 TrackPosvsAngle->GetEntries() > 1) {
0126               if (chambME[indexCh].find(fullName("TrigEffAnglePhi")) == chambME[indexCh].end()) {
0127                 bookChambHistos(ibooker, chId, "TrigEffPosvsAnglePhi");
0128                 bookChambHistos(ibooker, chId, "TrigEffPosvsAngleHHHLPhi");
0129                 bookChambHistos(ibooker, chId, "TrigEffPosPhi");
0130                 bookChambHistos(ibooker, chId, "TrigEffPosHHHLPhi");
0131                 bookChambHistos(ibooker, chId, "TrigEffAnglePhi");
0132                 bookChambHistos(ibooker, chId, "TrigEffAngleHHHLPhi");
0133               }
0134               if (secME[sector_id].find(fullName("TrigEffPhi")) == secME[sector_id].end()) {
0135                 bookSectorHistos(ibooker, wh, sect, "TrigEffPhi");
0136               }
0137               if (whME[wh].find(fullName("TrigEffPhi")) == whME[wh].end()) {
0138                 bookWheelHistos(ibooker, wh, "TrigEffPhi");
0139                 bookWheelHistos(ibooker, wh, "TrigEffHHHLPhi");
0140               }
0141 
0142               std::map<std::string, MonitorElement*>* innerME = &(secME[sector_id]);
0143               TH1D* TrackPos = TrackPosvsAngle->ProjectionY();
0144               TH1D* TrackAngle = TrackPosvsAngle->ProjectionX();
0145               TH1D* TrackPosandTrig = TrackPosvsAngleandTrig->ProjectionY();
0146               TH1D* TrackAngleandTrig = TrackPosvsAngleandTrig->ProjectionX();
0147               TH1D* TrackPosandTrigHHHL = TrackPosvsAngleandTrigHHHL->ProjectionY();
0148               TH1D* TrackAngleandTrigHHHL = TrackPosvsAngleandTrigHHHL->ProjectionX();
0149               float binEff = float(TrackPosandTrig->GetEntries()) / TrackPos->GetEntries();
0150               float binEffHHHL = float(TrackPosandTrigHHHL->GetEntries()) / TrackPos->GetEntries();
0151               float binErr = sqrt(binEff * (1 - binEff) / TrackPos->GetEntries());
0152               float binErrHHHL = sqrt(binEffHHHL * (1 - binEffHHHL) / TrackPos->GetEntries());
0153 
0154               MonitorElement* globalEff = innerME->find(fullName("TrigEffPhi"))->second;
0155               globalEff->setBinContent(stat, binEff);
0156               globalEff->setBinError(stat, binErr);
0157 
0158               innerME = &(whME[wh]);
0159               globalEff = innerME->find(fullName("TrigEffPhi"))->second;
0160               globalEff->setBinContent(sect, stat, binEff);
0161               globalEff->setBinError(sect, stat, binErr);
0162               globalEff = innerME->find(fullName("TrigEffHHHLPhi"))->second;
0163               globalEff->setBinContent(sect, stat, binEffHHHL);
0164               globalEff->setBinError(sect, stat, binErrHHHL);
0165 
0166               innerME = &(chambME[indexCh]);
0167               makeEfficiencyME(TrackPosandTrig, TrackPos, innerME->find(fullName("TrigEffPosPhi"))->second);
0168               makeEfficiencyME(TrackPosandTrigHHHL, TrackPos, innerME->find(fullName("TrigEffPosHHHLPhi"))->second);
0169               makeEfficiencyME(TrackAngleandTrig, TrackAngle, innerME->find(fullName("TrigEffAnglePhi"))->second);
0170               makeEfficiencyME(
0171                   TrackAngleandTrigHHHL, TrackAngle, innerME->find(fullName("TrigEffAngleHHHLPhi"))->second);
0172               makeEfficiencyME2D(
0173                   TrackPosvsAngleandTrig, TrackPosvsAngle, innerME->find(fullName("TrigEffPosvsAnglePhi"))->second);
0174               makeEfficiencyME2D(TrackPosvsAngleandTrigHHHL,
0175                                  TrackPosvsAngle,
0176                                  innerME->find(fullName("TrigEffPosvsAngleHHHLPhi"))->second);
0177             }
0178 
0179             // Perform Efficiency analysis (Theta+Segments)  CB FIXME -> no TM theta qual info
0180             TH2F* TrackThetaPosvsAngle =
0181                 getHisto<TH2F>(igetter.get(getMEName("TrackThetaPosvsAngle", "Segment", chId)));
0182             TH2F* TrackThetaPosvsAngleandTrig =
0183                 getHisto<TH2F>(igetter.get(getMEName("TrackThetaPosvsAngleandTrig", "Segment", chId)));
0184             TH2F* TrackThetaPosvsAngleandTrigH =
0185                 getHisto<TH2F>(igetter.get(getMEName("TrackThetaPosvsAngleandTrigH", "Segment", chId)));
0186 
0187             if (TrackThetaPosvsAngle && TrackThetaPosvsAngleandTrig && TrackThetaPosvsAngleandTrigH &&
0188                 TrackThetaPosvsAngle->GetEntries() > 1) {
0189               if (chambME[indexCh].find(fullName("TrigEffAngleTheta")) == chambME[indexCh].end()) {
0190                 bookChambHistos(ibooker, chId, "TrigEffPosvsAngleTheta");
0191                 bookChambHistos(ibooker, chId, "TrigEffPosvsAngleHTheta");
0192                 bookChambHistos(ibooker, chId, "TrigEffPosTheta");
0193                 bookChambHistos(ibooker, chId, "TrigEffPosHTheta");
0194                 bookChambHistos(ibooker, chId, "TrigEffAngleTheta");
0195                 bookChambHistos(ibooker, chId, "TrigEffAngleHTheta");
0196               }
0197               if (secME[sector_id].find(fullName("TrigEffTheta")) == secME[sector_id].end()) {
0198                 bookSectorHistos(ibooker, wh, sect, "TrigEffTheta");
0199               }
0200               if (whME[wh].find(fullName("TrigEffTheta")) == whME[wh].end()) {
0201                 bookWheelHistos(ibooker, wh, "TrigEffTheta");
0202                 bookWheelHistos(ibooker, wh, "TrigEffHTheta");
0203               }
0204 
0205               std::map<std::string, MonitorElement*>* innerME = &(secME[sector_id]);
0206               TH1D* TrackThetaPos = TrackThetaPosvsAngle->ProjectionY();
0207               TH1D* TrackThetaAngle = TrackThetaPosvsAngle->ProjectionX();
0208               TH1D* TrackThetaPosandTrig = TrackThetaPosvsAngleandTrig->ProjectionY();
0209               TH1D* TrackThetaAngleandTrig = TrackThetaPosvsAngleandTrig->ProjectionX();
0210               TH1D* TrackThetaPosandTrigH = TrackThetaPosvsAngleandTrigH->ProjectionY();
0211               TH1D* TrackThetaAngleandTrigH = TrackThetaPosvsAngleandTrigH->ProjectionX();
0212               float binEff = float(TrackThetaPosandTrig->GetEntries()) / TrackThetaPos->GetEntries();
0213               float binErr = sqrt(binEff * (1 - binEff) / TrackThetaPos->GetEntries());
0214               float binEffH = float(TrackThetaPosandTrigH->GetEntries()) / TrackThetaPos->GetEntries();
0215               float binErrH = sqrt(binEffH * (1 - binEffH) / TrackThetaPos->GetEntries());
0216 
0217               MonitorElement* globalEff = innerME->find(fullName("TrigEffTheta"))->second;
0218               globalEff->setBinContent(stat, binEff);
0219               globalEff->setBinError(stat, binErr);
0220 
0221               innerME = &(whME[wh]);
0222               globalEff = innerME->find(fullName("TrigEffTheta"))->second;
0223               globalEff->setBinContent(sect, stat, binEff);
0224               globalEff->setBinError(sect, stat, binErr);
0225               globalEff = innerME->find(fullName("TrigEffHTheta"))->second;
0226               globalEff->setBinContent(sect, stat, binEffH);
0227               globalEff->setBinError(sect, stat, binErrH);
0228 
0229               innerME = &(chambME[indexCh]);
0230               makeEfficiencyME(TrackThetaPosandTrig, TrackThetaPos, innerME->find(fullName("TrigEffPosTheta"))->second);
0231               makeEfficiencyME(
0232                   TrackThetaPosandTrigH, TrackThetaPos, innerME->find(fullName("TrigEffPosHTheta"))->second);
0233               makeEfficiencyME(
0234                   TrackThetaAngleandTrig, TrackThetaAngle, innerME->find(fullName("TrigEffAngleTheta"))->second);
0235               makeEfficiencyME(
0236                   TrackThetaAngleandTrigH, TrackThetaAngle, innerME->find(fullName("TrigEffAngleHTheta"))->second);
0237               makeEfficiencyME2D(TrackThetaPosvsAngleandTrig,
0238                                  TrackThetaPosvsAngle,
0239                                  innerME->find(fullName("TrigEffPosvsAngleTheta"))->second);
0240               makeEfficiencyME2D(TrackThetaPosvsAngleandTrigH,
0241                                  TrackThetaPosvsAngle,
0242                                  innerME->find(fullName("TrigEffPosvsAngleHTheta"))->second);
0243             }
0244           }
0245         }
0246       }
0247     }
0248   }
0249 }
0250 
0251 void DTLocalTriggerEfficiencyTest::makeEfficiencyME(TH1D* numerator, TH1D* denominator, MonitorElement* result) {
0252   TH1F* efficiency = result->getTH1F();
0253   efficiency->Divide(numerator, denominator, 1, 1, "");
0254 
0255   int nbins = efficiency->GetNbinsX();
0256   for (int bin = 1; bin <= nbins; ++bin) {
0257     float error = 0;
0258     float bineff = efficiency->GetBinContent(bin);
0259 
0260     if (denominator->GetBinContent(bin)) {
0261       error = sqrt(bineff * (1 - bineff) / denominator->GetBinContent(bin));
0262     } else {
0263       error = 1;
0264       efficiency->SetBinContent(bin, 1.);
0265     }
0266 
0267     efficiency->SetBinError(bin, error);
0268   }
0269 }
0270 
0271 void DTLocalTriggerEfficiencyTest::makeEfficiencyME2D(TH2F* numerator, TH2F* denominator, MonitorElement* result) {
0272   TH2F* efficiency = result->getTH2F();
0273   efficiency->Divide(numerator, denominator, 1, 1, "");
0274 
0275   int nbinsx = efficiency->GetNbinsX();
0276   int nbinsy = efficiency->GetNbinsY();
0277   for (int binx = 1; binx <= nbinsx; ++binx) {
0278     for (int biny = 1; biny <= nbinsy; ++biny) {
0279       float error = 0;
0280       float bineff = efficiency->GetBinContent(binx, biny);
0281 
0282       if (denominator->GetBinContent(binx, biny)) {
0283         error = sqrt(bineff * (1 - bineff) / denominator->GetBinContent(binx, biny));
0284       } else {
0285         error = 1;
0286         efficiency->SetBinContent(binx, biny, 0.);
0287       }
0288 
0289       efficiency->SetBinError(binx, biny, error);
0290     }
0291   }
0292 }
0293 
0294 void DTLocalTriggerEfficiencyTest::bookChambHistos(DQMStore::IBooker& ibooker, DTChamberId chambId, string htype) {
0295   stringstream wheel;
0296   wheel << chambId.wheel();
0297   stringstream station;
0298   station << chambId.station();
0299   stringstream sector;
0300   sector << chambId.sector();
0301 
0302   string fullType = fullName(htype);
0303   string HistoName = fullType + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
0304 
0305   ibooker.setCurrentFolder(topFolder() + "Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str() +
0306                            "/Segment");
0307 
0308   LogTrace(category()) << "[" << testName << "Test]: booking " + topFolder() + "Wheel" << wheel.str() << "/Sector"
0309                        << sector.str() << "/Station" << station.str() << "/Segment/" << HistoName;
0310 
0311   uint32_t indexChId = chambId.rawId();
0312   if (htype.find("TrigEffAnglePhi") == 0) {
0313     chambME[indexChId][fullType] =
0314         ibooker.book1D(HistoName.c_str(), "Trigger efficiency vs angle of incidence (Phi)", 16, -40., 40.);
0315   } else if (htype.find("TrigEffAngleHHHLPhi") == 0) {
0316     chambME[indexChId][fullType] =
0317         ibooker.book1D(HistoName.c_str(), "Trigger efficiency (HH/HL) vs angle of incidence (Phi)", 16, -40., 40.);
0318   } else if (htype.find("TrigEffAngleTheta") == 0) {
0319     chambME[indexChId][fullType] =
0320         ibooker.book1D(HistoName.c_str(), "Trigger efficiency vs angle of incidence (Theta)", 16, -40., 40.);
0321   } else if (htype.find("TrigEffAngleHTheta") == 0) {
0322     chambME[indexChId][fullType] =
0323         ibooker.book1D(HistoName.c_str(), "Trigger efficiency (H) vs angle of incidence (Theta)", 16, -40., 40.);
0324   } else if (htype.find("TrigEffPosPhi") == 0) {
0325     float min, max;
0326     int nbins;
0327     trigGeomUtils->phiRange(chambId, min, max, nbins);
0328     chambME[indexChId][fullType] =
0329         ibooker.book1D(HistoName.c_str(), "Trigger efficiency vs position (Phi)", nbins, min, max);
0330   } else if (htype.find("TrigEffPosvsAnglePhi") == 0) {
0331     float min, max;
0332     int nbins;
0333     trigGeomUtils->phiRange(chambId, min, max, nbins);
0334     chambME[indexChId][fullType] =
0335         ibooker.book2D(HistoName.c_str(), "Trigger efficiency position vs angle (Phi)", 16, -40., 40., nbins, min, max);
0336   } else if (htype.find("TrigEffPosvsAngleHHHLPhi") == 0) {
0337     float min, max;
0338     int nbins;
0339     trigGeomUtils->phiRange(chambId, min, max, nbins);
0340     chambME[indexChId][fullType] = ibooker.book2D(
0341         HistoName.c_str(), "Trigger efficiency (HH/HL) pos vs angle (Phi)", 16, -40., 40., nbins, min, max);
0342   } else if (htype.find("TrigEffPosHHHLPhi") == 0) {
0343     float min, max;
0344     int nbins;
0345     trigGeomUtils->phiRange(chambId, min, max, nbins);
0346     chambME[indexChId][fullType] =
0347         ibooker.book1D(HistoName.c_str(), "Trigger efficiency (HH/HL) vs position (Phi)", nbins, min, max);
0348   } else if (htype.find("TrigEffPosTheta") == 0) {
0349     float min, max;
0350     int nbins;
0351     trigGeomUtils->thetaRange(chambId, min, max, nbins);
0352     chambME[indexChId][fullType] =
0353         ibooker.book1D(HistoName.c_str(), "Trigger efficiency vs position (Theta)", nbins, min, max);
0354   } else if (htype.find("TrigEffPosHTheta") == 0) {
0355     float min, max;
0356     int nbins;
0357     trigGeomUtils->thetaRange(chambId, min, max, nbins);
0358     chambME[indexChId][fullType] =
0359         ibooker.book1D(HistoName.c_str(), "Trigger efficiency (H) vs position (Theta)", nbins, min, max);
0360   } else if (htype.find("TrigEffPosvsAngleTheta") == 0) {
0361     float min, max;
0362     int nbins;
0363     trigGeomUtils->thetaRange(chambId, min, max, nbins);
0364     chambME[indexChId][fullType] =
0365         ibooker.book2D(HistoName.c_str(), "Trigger efficiency pos vs angle (Theta)", 16, -40., 40., nbins, min, max);
0366   } else if (htype.find("TrigEffPosvsAngleHTheta") == 0) {
0367     float min, max;
0368     int nbins;
0369     trigGeomUtils->thetaRange(chambId, min, max, nbins);
0370     chambME[indexChId][fullType] = ibooker.book2D(
0371         HistoName.c_str(), "Trigger efficiency (H) pos vs angle (Theta)", 16, -40., 40., nbins, min, max);
0372   }
0373 }