00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "DQM/DTMonitorClient/src/DTTriggerEfficiencyTest.h"
00012
00013
00014 #include "FWCore/Framework/interface/EventSetup.h"
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016 #include "DQMServices/Core/interface/MonitorElement.h"
00017 #include "DQMServices/Core/interface/DQMStore.h"
00018
00019
00020 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00021 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00022
00023
00024 #include "DQM/DTMonitorModule/interface/DTTrigGeomUtils.h"
00025
00026
00027 #include "TF1.h"
00028 #include "TProfile.h"
00029
00030
00031
00032 #include <iostream>
00033 #include <sstream>
00034
00035 using namespace edm;
00036 using namespace std;
00037
00038
00039 DTTriggerEfficiencyTest::DTTriggerEfficiencyTest(const edm::ParameterSet& ps){
00040
00041 setConfig(ps,"DTTriggerEfficiency");
00042 baseFolderDCC = "DT/03-LocalTrigger-DCC/";
00043 baseFolderDDU = "DT/04-LocalTrigger-DDU/";
00044 detailedPlots = ps.getUntrackedParameter<bool>("detailedAnalysis",true);
00045
00046 }
00047
00048
00049 DTTriggerEfficiencyTest::~DTTriggerEfficiencyTest(){
00050
00051 }
00052
00053
00054 void DTTriggerEfficiencyTest::beginJob(){
00055
00056 DTLocalTriggerBaseTest::beginJob();
00057
00058 }
00059
00060
00061 void DTTriggerEfficiencyTest::beginRun(const edm::Run& r,const edm::EventSetup& c){
00062
00063 DTLocalTriggerBaseTest::beginRun(r,c);
00064 trigGeomUtils = new DTTrigGeomUtils(muonGeom);
00065
00066 vector<string>::const_iterator iTr = trigSources.begin();
00067 vector<string>::const_iterator trEnd = trigSources.end();
00068 vector<string>::const_iterator iHw = hwSources.begin();
00069 vector<string>::const_iterator hwEnd = hwSources.end();
00070
00071
00072
00073 if(parameters.getUntrackedParameter<bool>("staticBooking", true)){
00074 for (; iTr != trEnd; ++iTr){
00075 trigSource = (*iTr);
00076 for (; iHw != hwEnd; ++iHw){
00077 hwSource = (*iHw);
00078
00079 for (int wh=-2; wh<=2; ++wh){
00080 if (detailedPlots) {
00081 for (int sect=1; sect<=12; ++sect){
00082 for (int stat=1; stat<=4; ++stat){
00083 DTChamberId chId(wh,stat,sect);
00084 bookChambHistos(chId,"TrigEffPosvsAnglePhi","Segment");
00085 bookChambHistos(chId,"TrigEffPosvsAngleCorrPhi","Segment");
00086 }
00087 }
00088 }
00089 bookWheelHistos(wh,"TrigEffPhi","");
00090 bookWheelHistos(wh,"TrigEffCorrPhi","");
00091 }
00092 }
00093 }
00094 }
00095
00096 }
00097
00098
00099 void DTTriggerEfficiencyTest::runClientDiagnostic() {
00100
00101
00102 for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
00103 trigSource = (*iTr);
00104 for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
00105 hwSource = (*iHw);
00106
00107 for (int wh=-2; wh<=2; ++wh){
00108
00109 TH2F * TrigEffDenum = getHisto<TH2F>(dbe->get(getMEName("TrigEffDenum","Task",wh)));
00110 TH2F * TrigEffNum = getHisto<TH2F>(dbe->get(getMEName("TrigEffNum","Task",wh)));
00111 TH2F * TrigEffCorrNum = getHisto<TH2F>(dbe->get(getMEName("TrigEffCorrNum","Task",wh)));
00112
00113 if (TrigEffDenum && TrigEffNum && TrigEffCorrNum && TrigEffDenum->GetEntries()>1) {
00114
00115 if( whME[wh].find(fullName("TrigEffPhi")) == whME[wh].end() ){
00116 bookWheelHistos(wh,"TrigEffPhi","");
00117 bookWheelHistos(wh,"TrigEffCorrPhi","");
00118 }
00119 std::map<std::string,MonitorElement*> *innerME = &(whME[wh]);
00120 makeEfficiencyME2D(TrigEffNum,TrigEffDenum,innerME->find(fullName("TrigEffPhi"))->second);
00121 makeEfficiencyME2D(TrigEffCorrNum,TrigEffDenum,innerME->find(fullName("TrigEffCorrPhi"))->second);
00122
00123 }
00124
00125 if (detailedPlots) {
00126 for (int stat=1; stat<=4; ++stat){
00127 for (int sect=1; sect<=12; ++sect){
00128 DTChamberId chId(wh,stat,sect);
00129 uint32_t indexCh = chId.rawId();
00130
00131
00132 TH2F * TrackPosvsAngle = getHisto<TH2F>(dbe->get(getMEName("TrackPosvsAngle","Segment", chId)));
00133 TH2F * TrackPosvsAngleAnyQual = getHisto<TH2F>(dbe->get(getMEName("TrackPosvsAngleAnyQual","Segment", chId)));
00134 TH2F * TrackPosvsAngleCorr = getHisto<TH2F>(dbe->get(getMEName("TrackPosvsAngleCorr","Segment", chId)));
00135
00136 if (TrackPosvsAngle && TrackPosvsAngleAnyQual && TrackPosvsAngleCorr && TrackPosvsAngle->GetEntries()>1) {
00137
00138 if( chambME[indexCh].find(fullName("TrigEffAnglePhi")) == chambME[indexCh].end()){
00139 bookChambHistos(chId,"TrigEffPosvsAnglePhi","Segment");
00140 bookChambHistos(chId,"TrigEffPosvsAngleCorrPhi","Segment");
00141 }
00142
00143 std::map<std::string,MonitorElement*> *innerME = &(chambME[indexCh]);
00144 makeEfficiencyME2D(TrackPosvsAngleAnyQual,TrackPosvsAngle,innerME->find(fullName("TrigEffPosvsAnglePhi"))->second);
00145 makeEfficiencyME2D(TrackPosvsAngleCorr,TrackPosvsAngle,innerME->find(fullName("TrigEffPosvsAngleCorrPhi"))->second);
00146
00147 }
00148 }
00149 }
00150 }
00151 }
00152
00153 }
00154 }
00155
00156 }
00157
00158 void DTTriggerEfficiencyTest::makeEfficiencyME2D(TH2F* numerator, TH2F* denominator, MonitorElement* result){
00159
00160 TH2F* efficiency = result->getTH2F();
00161 efficiency->Divide(numerator,denominator,1,1,"");
00162
00163 int nbinsx = efficiency->GetNbinsX();
00164 int nbinsy = efficiency->GetNbinsY();
00165 for (int binx=1; binx<=nbinsx; ++binx){
00166 for (int biny=1; biny<=nbinsy; ++biny){
00167 float error = 0;
00168 float bineff = efficiency->GetBinContent(binx,biny);
00169
00170 if (denominator->GetBinContent(binx,biny)){
00171 error = sqrt(bineff*(1-bineff)/denominator->GetBinContent(binx,biny));
00172 }
00173 else {
00174 error = 1;
00175 efficiency->SetBinContent(binx,biny,0.);
00176 }
00177
00178 efficiency->SetBinError(binx,biny,error);
00179 }
00180 }
00181
00182 }
00183
00184 string DTTriggerEfficiencyTest::getMEName(string histoTag, string folder, int wh) {
00185
00186 stringstream wheel; wheel << wh;
00187
00188 string folderName = topFolder(hwSource=="DCC") + folder + "/";
00189
00190 string histoname = sourceFolder + folderName
00191 + fullName(histoTag) + "_W" + wheel.str();
00192
00193 return histoname;
00194
00195 }
00196
00197 void DTTriggerEfficiencyTest::bookWheelHistos(int wheel,string hTag,string folder) {
00198
00199 stringstream wh; wh << wheel;
00200 string basedir;
00201 bool isDCC = hwSource=="DCC" ;
00202 basedir = topFolder(isDCC);
00203
00204 if (folder != "") {
00205 basedir += folder +"/" ;
00206 }
00207 dbe->setCurrentFolder(basedir);
00208
00209 string fullTag = fullName(hTag);
00210 string hname = fullTag+ "_W" + wh.str();
00211
00212 LogTrace(category()) << "[" << testName << "Test]: booking "<< basedir << hname;
00213
00214 if (hTag.find("Phi")!= string::npos ||
00215 hTag.find("Summary") != string::npos ){
00216 MonitorElement* me = dbe->book2D(hname.c_str(),hname.c_str(),12,1,13,4,1,5);
00217
00218
00219 me->setBinLabel(1,"MB1",2);
00220 me->setBinLabel(2,"MB2",2);
00221 me->setBinLabel(3,"MB3",2);
00222 me->setBinLabel(4,"MB4",2);
00223 me->setAxisTitle("Sector",1);
00224
00225 whME[wheel][fullTag] = me;
00226 return;
00227 }
00228
00229 if (hTag.find("Theta") != string::npos){
00230 MonitorElement* me =dbe->book2D(hname.c_str(),hname.c_str(),12,1,13,3,1,4);
00231
00232
00233 me->setBinLabel(1,"MB1",2);
00234 me->setBinLabel(2,"MB2",2);
00235 me->setBinLabel(3,"MB3",2);
00236 me->setAxisTitle("Sector",1);
00237
00238 whME[wheel][fullTag] = me;
00239 return;
00240 }
00241
00242 }
00243
00244 void DTTriggerEfficiencyTest::bookChambHistos(DTChamberId chambId, string htype, string folder) {
00245
00246 stringstream wheel; wheel << chambId.wheel();
00247 stringstream station; station << chambId.station();
00248 stringstream sector; sector << chambId.sector();
00249
00250 string fullType = fullName(htype);
00251 bool isDCC = hwSource=="DCC" ;
00252 string HistoName = fullType + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
00253
00254 dbe->setCurrentFolder(topFolder(isDCC) +
00255 "Wheel" + wheel.str() +
00256 "/Sector" + sector.str() +
00257 "/Station" + station.str() +
00258 "/" + folder + "/");
00259
00260 LogTrace(category()) << "[" << testName << "Test]: booking " + topFolder(isDCC) + "Wheel" << wheel.str()
00261 <<"/Sector" << sector.str() << "/Station" << station.str() << "/" + folder + "/" << HistoName;
00262
00263
00264 uint32_t indexChId = chambId.rawId();
00265 float min, max;
00266 int nbins;
00267 trigGeomUtils->phiRange(chambId,min,max,nbins,20);
00268 if (htype.find("TrigEffPosvsAnglePhi") == 0 ){
00269 chambME[indexChId][fullType] = dbe->book2D(HistoName.c_str(),"Trigger efficiency (any qual.) position vs angle (Phi)",12,-30.,30.,nbins,min,max);
00270 return;
00271 }
00272 if (htype.find("TrigEffPosvsAngleCorrPhi") == 0 ){
00273 chambME[indexChId][fullType] = dbe->book2D(HistoName.c_str(),"Trigger efficiency (correlated) pos vs angle (Phi)",12,-30.,30.,nbins,min,max);
00274 return;
00275 }
00276
00277 }