00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "DQM/DTMonitorClient/src/DTLocalTriggerEfficiencyTest.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 "DQM/DTMonitorModule/interface/DTTrigGeomUtils.h"
00021 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00022 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00023
00024
00025 #include "TF1.h"
00026 #include "TProfile.h"
00027
00028
00029
00030 #include <iostream>
00031 #include <sstream>
00032
00033 using namespace edm;
00034 using namespace std;
00035
00036
00037 DTLocalTriggerEfficiencyTest::DTLocalTriggerEfficiencyTest(const edm::ParameterSet& ps) : trigGeomUtils(0) {
00038
00039 setConfig(ps,"DTLocalTriggerEfficiency");
00040 baseFolderDCC = "DT/03-LocalTrigger-DCC/";
00041 baseFolderDDU = "DT/04-LocalTrigger-DDU/";
00042
00043 }
00044
00045
00046 DTLocalTriggerEfficiencyTest::~DTLocalTriggerEfficiencyTest(){
00047
00048 if (trigGeomUtils) {
00049 delete trigGeomUtils;
00050 }
00051
00052 }
00053
00054
00055 void DTLocalTriggerEfficiencyTest::beginRun(const edm::Run& r, const edm::EventSetup& c){
00056
00057 DTLocalTriggerBaseTest::beginRun(r,c);
00058 trigGeomUtils = new DTTrigGeomUtils(muonGeom);
00059
00060 vector<string>::const_iterator iTr = trigSources.begin();
00061 vector<string>::const_iterator trEnd = trigSources.end();
00062 vector<string>::const_iterator iHw = hwSources.begin();
00063 vector<string>::const_iterator hwEnd = hwSources.end();
00064
00065
00066
00067 if(parameters.getUntrackedParameter<bool>("staticBooking", true)){
00068 for (; iTr != trEnd; ++iTr){
00069 trigSource = (*iTr);
00070 for (; iHw != hwEnd; ++iHw){
00071 hwSource = (*iHw);
00072
00073 for (int wh=-2; wh<=2; ++wh){
00074 for (int sect=1; sect<=12; ++sect){
00075 for (int stat=1; stat<=4; ++stat){
00076 DTChamberId chId(wh,stat,sect);
00077 bookChambHistos(chId,"TrigEffPosvsAnglePhi");
00078 bookChambHistos(chId,"TrigEffPosvsAngleHHHLPhi");
00079 bookChambHistos(chId,"TrigEffPosPhi");
00080 bookChambHistos(chId,"TrigEffPosHHHLPhi");
00081 bookChambHistos(chId,"TrigEffAnglePhi");
00082 bookChambHistos(chId,"TrigEffAngleHHHLPhi");
00083 if (stat<=3) {
00084 bookChambHistos(chId,"TrigEffPosvsAngleTheta");
00085 bookChambHistos(chId,"TrigEffPosvsAngleHTheta");
00086 bookChambHistos(chId,"TrigEffPosTheta");
00087 bookChambHistos(chId,"TrigEffPosHTheta");
00088 bookChambHistos(chId,"TrigEffAngleTheta");
00089 bookChambHistos(chId,"TrigEffAngleHTheta");
00090 }
00091 }
00092 bookSectorHistos(wh,sect,"TrigEffPhi");
00093 bookSectorHistos(wh,sect,"TrigEffTheta");
00094 }
00095 bookWheelHistos(wh,"TrigEffPhi");
00096 bookWheelHistos(wh,"TrigEffHHHLPhi");
00097 bookWheelHistos(wh,"TrigEffTheta");
00098 bookWheelHistos(wh,"TrigEffHTheta");
00099 }
00100 }
00101 }
00102 }
00103
00104 }
00105
00106
00107 void DTLocalTriggerEfficiencyTest::runClientDiagnostic() {
00108
00109
00110 for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
00111 trigSource = (*iTr);
00112 for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
00113 hwSource = (*iHw);
00114
00115 for (int stat=1; stat<=4; ++stat){
00116 for (int wh=-2; wh<=2; ++wh){
00117 for (int sect=1; sect<=12; ++sect){
00118 DTChamberId chId(wh,stat,sect);
00119 int sector_id = (wh+3)+(sect-1)*5;
00120 uint32_t indexCh = chId.rawId();
00121
00122
00123 TH2F * TrackPosvsAngle = getHisto<TH2F>(dbe->get(getMEName("TrackPosvsAngle","Segment", chId)));
00124 TH2F * TrackPosvsAngleandTrig = getHisto<TH2F>(dbe->get(getMEName("TrackPosvsAngleandTrig","Segment", chId)));
00125 TH2F * TrackPosvsAngleandTrigHHHL = getHisto<TH2F>(dbe->get(getMEName("TrackPosvsAngleandTrigHHHL","Segment", chId)));
00126
00127 if (TrackPosvsAngle && TrackPosvsAngleandTrig && TrackPosvsAngleandTrigHHHL && TrackPosvsAngle->GetEntries()>1) {
00128
00129 if( chambME[indexCh].find(fullName("TrigEffAnglePhi")) == chambME[indexCh].end()){
00130 bookChambHistos(chId,"TrigEffPosvsAnglePhi");
00131 bookChambHistos(chId,"TrigEffPosvsAngleHHHLPhi");
00132 bookChambHistos(chId,"TrigEffPosPhi");
00133 bookChambHistos(chId,"TrigEffPosHHHLPhi");
00134 bookChambHistos(chId,"TrigEffAnglePhi");
00135 bookChambHistos(chId,"TrigEffAngleHHHLPhi");
00136 }
00137 if( secME[sector_id].find(fullName("TrigEffPhi")) == secME[sector_id].end() ){
00138 bookSectorHistos(wh,sect,"TrigEffPhi");
00139 }
00140 if( whME[wh].find(fullName("TrigEffPhi")) == whME[wh].end() ){
00141 bookWheelHistos(wh,"TrigEffPhi");
00142 bookWheelHistos(wh,"TrigEffHHHLPhi");
00143 }
00144
00145 std::map<std::string,MonitorElement*> *innerME = &(secME[sector_id]);
00146 TH1D* TrackPos = TrackPosvsAngle->ProjectionY();
00147 TH1D* TrackAngle = TrackPosvsAngle->ProjectionX();
00148 TH1D* TrackPosandTrig = TrackPosvsAngleandTrig->ProjectionY();
00149 TH1D* TrackAngleandTrig = TrackPosvsAngleandTrig->ProjectionX();
00150 TH1D* TrackPosandTrigHHHL = TrackPosvsAngleandTrigHHHL->ProjectionY();
00151 TH1D* TrackAngleandTrigHHHL = TrackPosvsAngleandTrigHHHL->ProjectionX();
00152 float binEff = float(TrackPosandTrig->GetEntries())/TrackPos->GetEntries();
00153 float binEffHHHL = float(TrackPosandTrigHHHL->GetEntries())/TrackPos->GetEntries();
00154 float binErr = sqrt(binEff*(1-binEff)/TrackPos->GetEntries());
00155 float binErrHHHL = sqrt(binEffHHHL*(1-binEffHHHL)/TrackPos->GetEntries());
00156
00157 MonitorElement* globalEff = innerME->find(fullName("TrigEffPhi"))->second;
00158 globalEff->setBinContent(stat,binEff);
00159 globalEff->setBinError(stat,binErr);
00160
00161 innerME = &(whME[wh]);
00162 globalEff = innerME->find(fullName("TrigEffPhi"))->second;
00163 globalEff->setBinContent(sect,stat,binEff);
00164 globalEff->setBinError(sect,stat,binErr);
00165 globalEff = innerME->find(fullName("TrigEffHHHLPhi"))->second;
00166 globalEff->setBinContent(sect,stat,binEffHHHL);
00167 globalEff->setBinError(sect,stat,binErrHHHL);
00168
00169
00170 innerME = &(chambME[indexCh]);
00171 makeEfficiencyME(TrackPosandTrig,TrackPos,innerME->find(fullName("TrigEffPosPhi"))->second);
00172 makeEfficiencyME(TrackPosandTrigHHHL,TrackPos,innerME->find(fullName("TrigEffPosHHHLPhi"))->second);
00173 makeEfficiencyME(TrackAngleandTrig,TrackAngle,innerME->find(fullName("TrigEffAnglePhi"))->second);
00174 makeEfficiencyME(TrackAngleandTrigHHHL,TrackAngle,innerME->find(fullName("TrigEffAngleHHHLPhi"))->second);
00175 makeEfficiencyME2D(TrackPosvsAngleandTrig,TrackPosvsAngle,innerME->find(fullName("TrigEffPosvsAnglePhi"))->second);
00176 makeEfficiencyME2D(TrackPosvsAngleandTrigHHHL,TrackPosvsAngle,innerME->find(fullName("TrigEffPosvsAngleHHHLPhi"))->second);
00177
00178 }
00179
00180
00181 TH2F * TrackThetaPosvsAngle = getHisto<TH2F>(dbe->get(getMEName("TrackThetaPosvsAngle","Segment", chId)));
00182 TH2F * TrackThetaPosvsAngleandTrig = getHisto<TH2F>(dbe->get(getMEName("TrackThetaPosvsAngleandTrig","Segment", chId)));
00183 TH2F * TrackThetaPosvsAngleandTrigH = getHisto<TH2F>(dbe->get(getMEName("TrackThetaPosvsAngleandTrigH","Segment", chId)));
00184
00185 if (TrackThetaPosvsAngle && TrackThetaPosvsAngleandTrig && TrackThetaPosvsAngleandTrigH && TrackThetaPosvsAngle->GetEntries()>1) {
00186
00187 if( chambME[indexCh].find(fullName("TrigEffAngleTheta")) == chambME[indexCh].end()){
00188 bookChambHistos(chId,"TrigEffPosvsAngleTheta");
00189 bookChambHistos(chId,"TrigEffPosvsAngleHTheta");
00190 bookChambHistos(chId,"TrigEffPosTheta");
00191 bookChambHistos(chId,"TrigEffPosHTheta");
00192 bookChambHistos(chId,"TrigEffAngleTheta");
00193 bookChambHistos(chId,"TrigEffAngleHTheta");
00194 }
00195 if( secME[sector_id].find(fullName("TrigEffTheta")) == secME[sector_id].end() ){
00196 bookSectorHistos(wh,sect,"TrigEffTheta");
00197 }
00198 if( whME[wh].find(fullName("TrigEffTheta")) == whME[wh].end() ){
00199 bookWheelHistos(wh,"TrigEffTheta");
00200 bookWheelHistos(wh,"TrigEffHTheta");
00201 }
00202
00203 std::map<std::string,MonitorElement*> *innerME = &(secME[sector_id]);
00204 TH1D* TrackThetaPos = TrackThetaPosvsAngle->ProjectionY();
00205 TH1D* TrackThetaAngle = TrackThetaPosvsAngle->ProjectionX();
00206 TH1D* TrackThetaPosandTrig = TrackThetaPosvsAngleandTrig->ProjectionY();
00207 TH1D* TrackThetaAngleandTrig = TrackThetaPosvsAngleandTrig->ProjectionX();
00208 TH1D* TrackThetaPosandTrigH = TrackThetaPosvsAngleandTrigH->ProjectionY();
00209 TH1D* TrackThetaAngleandTrigH = TrackThetaPosvsAngleandTrigH->ProjectionX();
00210 float binEff = float(TrackThetaPosandTrig->GetEntries())/TrackThetaPos->GetEntries();
00211 float binErr = sqrt(binEff*(1-binEff)/TrackThetaPos->GetEntries());
00212 float binEffH = float(TrackThetaPosandTrigH->GetEntries())/TrackThetaPos->GetEntries();
00213 float binErrH = sqrt(binEffH*(1-binEffH)/TrackThetaPos->GetEntries());
00214
00215 MonitorElement* globalEff = innerME->find(fullName("TrigEffTheta"))->second;
00216 globalEff->setBinContent(stat,binEff);
00217 globalEff->setBinError(stat,binErr);
00218
00219 innerME = &(whME[wh]);
00220 globalEff = innerME->find(fullName("TrigEffTheta"))->second;
00221 globalEff->setBinContent(sect,stat,binEff);
00222 globalEff->setBinError(sect,stat,binErr);
00223 globalEff = innerME->find(fullName("TrigEffHTheta"))->second;
00224 globalEff->setBinContent(sect,stat,binEffH);
00225 globalEff->setBinError(sect,stat,binErrH);
00226
00227 innerME = &(chambME[indexCh]);
00228 makeEfficiencyME(TrackThetaPosandTrig,TrackThetaPos,innerME->find(fullName("TrigEffPosTheta"))->second);
00229 makeEfficiencyME(TrackThetaPosandTrigH,TrackThetaPos,innerME->find(fullName("TrigEffPosHTheta"))->second);
00230 makeEfficiencyME(TrackThetaAngleandTrig,TrackThetaAngle,innerME->find(fullName("TrigEffAngleTheta"))->second);
00231 makeEfficiencyME(TrackThetaAngleandTrigH,TrackThetaAngle,innerME->find(fullName("TrigEffAngleHTheta"))->second);
00232 makeEfficiencyME2D(TrackThetaPosvsAngleandTrig,TrackThetaPosvsAngle,innerME->find(fullName("TrigEffPosvsAngleTheta"))->second);
00233 makeEfficiencyME2D(TrackThetaPosvsAngleandTrigH,TrackThetaPosvsAngle,innerME->find(fullName("TrigEffPosvsAngleHTheta"))->second);
00234 }
00235
00236 }
00237 }
00238 }
00239 }
00240 }
00241
00242 }
00243
00244
00245 void DTLocalTriggerEfficiencyTest::makeEfficiencyME(TH1D* numerator, TH1D* denominator, MonitorElement* result){
00246
00247 TH1F* efficiency = result->getTH1F();
00248 efficiency->Divide(numerator,denominator,1,1,"");
00249
00250 int nbins = efficiency->GetNbinsX();
00251 for (int bin=1; bin<=nbins; ++bin){
00252 float error = 0;
00253 float bineff = efficiency->GetBinContent(bin);
00254
00255 if (denominator->GetBinContent(bin)){
00256 error = sqrt(bineff*(1-bineff)/denominator->GetBinContent(bin));
00257 }
00258 else {
00259 error = 1;
00260 efficiency->SetBinContent(bin,1.);
00261 }
00262
00263 efficiency->SetBinError(bin,error);
00264 }
00265
00266 }
00267
00268
00269 void DTLocalTriggerEfficiencyTest::makeEfficiencyME2D(TH2F* numerator, TH2F* denominator, MonitorElement* result){
00270
00271 TH2F* efficiency = result->getTH2F();
00272 efficiency->Divide(numerator,denominator,1,1,"");
00273
00274 int nbinsx = efficiency->GetNbinsX();
00275 int nbinsy = efficiency->GetNbinsY();
00276 for (int binx=1; binx<=nbinsx; ++binx){
00277 for (int biny=1; biny<=nbinsy; ++biny){
00278 float error = 0;
00279 float bineff = efficiency->GetBinContent(binx,biny);
00280
00281 if (denominator->GetBinContent(binx,biny)){
00282 error = sqrt(bineff*(1-bineff)/denominator->GetBinContent(binx,biny));
00283 }
00284 else {
00285 error = 1;
00286 efficiency->SetBinContent(binx,biny,0.);
00287 }
00288
00289 efficiency->SetBinError(binx,biny,error);
00290 }
00291 }
00292
00293 }
00294
00295
00296 void DTLocalTriggerEfficiencyTest::bookChambHistos(DTChamberId chambId, string htype) {
00297
00298 stringstream wheel; wheel << chambId.wheel();
00299 stringstream station; station << chambId.station();
00300 stringstream sector; sector << chambId.sector();
00301
00302 string fullType = fullName(htype);
00303 bool isDCC = hwSource=="DCC" ;
00304 string HistoName = fullType + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
00305
00306 dbe->setCurrentFolder(topFolder(isDCC) + "Wheel" + wheel.str() +
00307 "/Sector" + sector.str() +
00308 "/Station" + station.str() + "/Segment");
00309
00310 LogTrace(category()) << "[" << testName << "Test]: booking " + topFolder(isDCC) + "Wheel" << wheel.str()
00311 <<"/Sector" << sector.str() << "/Station" << station.str() << "/Segment/" << HistoName;
00312
00313
00314 uint32_t indexChId = chambId.rawId();
00315 if (htype.find("TrigEffAnglePhi") == 0){
00316 chambME[indexChId][fullType] = dbe->book1D(HistoName.c_str(),"Trigger efficiency vs angle of incidence (Phi)",16,-40.,40.);
00317 }
00318 else if (htype.find("TrigEffAngleHHHLPhi") == 0){
00319 chambME[indexChId][fullType] = dbe->book1D(HistoName.c_str(),"Trigger efficiency (HH/HL) vs angle of incidence (Phi)",16,-40.,40.);
00320 }
00321 else if (htype.find("TrigEffAngleTheta") == 0){
00322 chambME[indexChId][fullType] = dbe->book1D(HistoName.c_str(),"Trigger efficiency vs angle of incidence (Theta)",16,-40.,40.);
00323 }
00324 else if (htype.find("TrigEffAngleHTheta") == 0){
00325 chambME[indexChId][fullType] = dbe->book1D(HistoName.c_str(),"Trigger efficiency (H) vs angle of incidence (Theta)",16,-40.,40.);
00326 }
00327 else if (htype.find("TrigEffPosPhi") == 0 ){
00328 float min,max;
00329 int nbins;
00330 trigGeomUtils->phiRange(chambId,min,max,nbins);
00331 chambME[indexChId][fullType] = dbe->book1D(HistoName.c_str(),"Trigger efficiency vs position (Phi)",nbins,min,max);
00332 }
00333 else if (htype.find("TrigEffPosvsAnglePhi") == 0 ){
00334 float min,max;
00335 int nbins;
00336 trigGeomUtils->phiRange(chambId,min,max,nbins);
00337 chambME[indexChId][fullType] = dbe->book2D(HistoName.c_str(),"Trigger efficiency position vs angle (Phi)",16,-40.,40.,nbins,min,max);
00338 }
00339 else if (htype.find("TrigEffPosvsAngleHHHLPhi") == 0 ){
00340 float min,max;
00341 int nbins;
00342 trigGeomUtils->phiRange(chambId,min,max,nbins);
00343 chambME[indexChId][fullType] = dbe->book2D(HistoName.c_str(),"Trigger efficiency (HH/HL) pos vs angle (Phi)",16,-40.,40.,nbins,min,max);
00344 }
00345 else if (htype.find("TrigEffPosHHHLPhi") == 0 ){
00346 float min,max;
00347 int nbins;
00348 trigGeomUtils->phiRange(chambId,min,max,nbins);
00349 chambME[indexChId][fullType] = dbe->book1D(HistoName.c_str(),"Trigger efficiency (HH/HL) vs position (Phi)",nbins,min,max);
00350 }
00351 else if (htype.find("TrigEffPosTheta") == 0){
00352 float min,max;
00353 int nbins;
00354 trigGeomUtils->thetaRange(chambId,min,max,nbins);
00355 chambME[indexChId][fullType] = dbe->book1D(HistoName.c_str(),"Trigger efficiency vs position (Theta)",nbins,min,max);
00356 }
00357 else if (htype.find("TrigEffPosHTheta") == 0){
00358 float min,max;
00359 int nbins;
00360 trigGeomUtils->thetaRange(chambId,min,max,nbins);
00361 chambME[indexChId][fullType] = dbe->book1D(HistoName.c_str(),"Trigger efficiency (H) vs position (Theta)",nbins,min,max);
00362 }
00363 else if (htype.find("TrigEffPosvsAngleTheta") == 0 ){
00364 float min,max;
00365 int nbins;
00366 trigGeomUtils->thetaRange(chambId,min,max,nbins);
00367 chambME[indexChId][fullType] = dbe->book2D(HistoName.c_str(),"Trigger efficiency pos vs angle (Theta)",16,-40.,40.,nbins,min,max);
00368 }
00369 else if (htype.find("TrigEffPosvsAngleHTheta") == 0 ){
00370 float min,max;
00371 int nbins;
00372 trigGeomUtils->thetaRange(chambId,min,max,nbins);
00373 chambME[indexChId][fullType] = dbe->book2D(HistoName.c_str(),"Trigger efficiency (H) pos vs angle (Theta)",16,-40.,40.,nbins,min,max);
00374 }
00375
00376 }