00001
00002 #include <sstream>
00003
00004 #include <DQM/RPCMonitorClient/interface/RPCEventSummary.h>
00005
00006 #include "CondFormats/RunInfo/interface/RunInfo.h"
00007 #include "CondFormats/DataRecord/interface/RunSummaryRcd.h"
00008
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include "FWCore/Framework/interface/LuminosityBlock.h"
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "FWCore/Framework/interface/EventSetup.h"
00013
00014
00015
00016 RPCEventSummary::RPCEventSummary(const edm::ParameterSet& ps ){
00017 edm::LogVerbatim ("rpceventsummary") << "[RPCEventSummary]: Constructor";
00018
00019 enableReportSummary_ = ps.getUntrackedParameter<bool>("EnableSummaryReport",true);
00020 prescaleFactor_ = ps.getUntrackedParameter<int>("PrescaleFactor", 1);
00021 eventInfoPath_ = ps.getUntrackedParameter<std::string>("EventInfoPath", "RPC/EventInfo");
00022
00023
00024 std::string subsystemFolder = ps.getUntrackedParameter<std::string>("RPCFolder", "RPC");
00025 std::string recHitTypeFolder = ps.getUntrackedParameter<std::string>("RecHitTypeFolder", "AllHits");
00026 std::string summaryFolder = ps.getUntrackedParameter<std::string>("SummaryFolder", "SummaryHistograms");
00027
00028 globalFolder_ = subsystemFolder +"/"+ recHitTypeFolder +"/"+ summaryFolder ;
00029 prefixFolder_ = subsystemFolder +"/"+ recHitTypeFolder ;
00030
00031 minimumEvents_= ps.getUntrackedParameter<int>("MinimumRPCEvents", 10000);
00032 numberDisk_ = ps.getUntrackedParameter<int>("NumberOfEndcapDisks", 3);
00033 doEndcapCertification_ = ps.getUntrackedParameter<bool>("EnableEndcapSummary", false);
00034
00035 FEDRange_.first = ps.getUntrackedParameter<unsigned int>("MinimumRPCFEDId", 790);
00036 FEDRange_.second = ps.getUntrackedParameter<unsigned int>("MaximumRPCFEDId", 792);
00037
00038 NumberOfFeds_ =FEDRange_.second - FEDRange_.first +1;
00039
00040 offlineDQM_ = ps.getUntrackedParameter<bool> ("OfflineDQM",true);
00041
00042
00043 }
00044
00045 RPCEventSummary::~RPCEventSummary(){
00046 edm::LogVerbatim ("rpceventsummary") << "[RPCEventSummary]: Destructor ";
00047 dbe_=0;
00048 }
00049
00050 void RPCEventSummary::beginJob(){
00051 edm::LogVerbatim ("rpceventsummary") << "[RPCEventSummary]: Begin job ";
00052 dbe_ = edm::Service<DQMStore>().operator->();
00053 }
00054
00055 void RPCEventSummary::beginRun(const edm::Run& r, const edm::EventSetup& setup){
00056 edm::LogVerbatim ("rpceventsummary") << "[RPCEventSummary]: Begin run";
00057
00058 init_ = false;
00059 lumiCounter_ = prescaleFactor_ ;
00060
00061 edm::eventsetup::EventSetupRecordKey recordKey(edm::eventsetup::EventSetupRecordKey::TypeTag::findType("RunInfoRcd"));
00062
00063 int defaultValue = 1;
00064
00065 if(0 != setup.find( recordKey ) ) {
00066 defaultValue = -1;
00067
00068 edm::ESHandle<RunInfo> sumFED;
00069 setup.get<RunInfoRcd>().get(sumFED);
00070 std::vector<int> FedsInIds= sumFED->m_fed_in;
00071 unsigned int f = 0;
00072 bool flag = false;
00073 while(!flag && f < FedsInIds.size()) {
00074 int fedID=FedsInIds[f];
00075
00076 if(fedID>=FEDRange_.first && fedID<=FEDRange_.second) {
00077 defaultValue = 1;
00078 flag = true;
00079 }
00080 f++;
00081 }
00082 }
00083
00084
00085 MonitorElement* me;
00086 dbe_->setCurrentFolder(eventInfoPath_);
00087
00088
00089
00090 std::string histoName="reportSummary";
00091 me =0;
00092 me = dbe_->get(eventInfoPath_ +"/"+ histoName);
00093 if ( 0!=me) {
00094 dbe_->removeElement(me->getName());
00095 }
00096
00097 me = dbe_->bookFloat(histoName);
00098 me->Fill(defaultValue);
00099
00100
00101 me =0;
00102 me = dbe_->get(eventInfoPath_ +"/reportSummaryMap");
00103 if ( 0!=me) {
00104 dbe_->removeElement(me->getName());
00105 }
00106
00107 me = dbe_->book2D("reportSummaryMap", "RPC Report Summary Map", 15, -7.5, 7.5, 12, 0.5 ,12.5);
00108
00109
00110 std::stringstream BinLabel;
00111 for (int i= 1 ; i<=15; i++){
00112 BinLabel.str("");
00113 if(i<13){
00114 BinLabel<<"Sec"<<i;
00115 me->setBinLabel(i,BinLabel.str(),2);
00116 }
00117
00118 BinLabel.str("");
00119 if(i<5)
00120 BinLabel<<"Disk"<<i-5;
00121 else if(i>11)
00122 BinLabel<<"Disk"<<i-11;
00123 else if(i==11 || i==5)
00124 BinLabel.str("");
00125 else
00126 BinLabel<<"Wheel"<<i-8;
00127
00128 me->setBinLabel(i,BinLabel.str(),1);
00129 }
00130
00131
00132 for(int i=1; i<=15; i++){
00133 for (int j=1; j<=12; j++ ){
00134 if(i==5 || i==11 || (j>6 && (i<6 || i>10)))
00135 me->setBinContent(i,j,-1);
00136 else
00137 me->setBinContent(i,j,defaultValue);
00138 }
00139 }
00140
00141 if(numberDisk_ < 4)
00142 for (int j=1; j<=12; j++ ){
00143 me->setBinContent(1,j,-1);
00144 me->setBinContent(15,j,-1);
00145 }
00146
00147
00148
00149 dbe_->setCurrentFolder(eventInfoPath_+ "/reportSummaryContents");
00150
00151 std::stringstream segName;
00152 std::vector<std::string> segmentNames;
00153 for(int i=-4; i<=4; i++){
00154 if(i>-3 && i<3) {
00155 segName.str("");
00156 segName<<"RPC_Wheel"<<i;
00157 segmentNames.push_back(segName.str());
00158 }
00159 if(i==0) continue;
00160 segName.str("");
00161 segName<<"RPC_Disk"<<i;
00162 segmentNames.push_back(segName.str());
00163 }
00164
00165
00166 for(unsigned int i=0; i<segmentNames.size(); i++){
00167 me =0;
00168 me = dbe_->get(eventInfoPath_ + "/reportSummaryContents/" +segmentNames[i]);
00169 if ( 0!=me) {
00170 dbe_->removeElement(me->getName());
00171 }
00172 me = dbe_->bookFloat(segmentNames[i]);
00173 me->Fill(defaultValue);
00174 }
00175
00176
00177 if(numberDisk_ < 4){
00178 me=dbe_->get(eventInfoPath_ + "/reportSummaryContents/RPC_Disk4");
00179 if(me) me->Fill(-1);
00180 me=dbe_->get(eventInfoPath_ + "/reportSummaryContents/RPC_Disk-4");
00181 if(me) me->Fill(-1);
00182 }
00183 }
00184
00185 void RPCEventSummary::beginLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& context){}
00186
00187 void RPCEventSummary::analyze(const edm::Event& iEvent, const edm::EventSetup& c) {}
00188
00189 void RPCEventSummary::endLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& iSetup) {
00190 edm::LogVerbatim ("rpceventsummary") <<"[RPCEventSummary]: End of LS transition, performing DQM client operation";
00191
00192 if(offlineDQM_) return;
00193
00194 if(!init_){
00195 this->clientOperation();
00196 return;
00197 }
00198
00199 lumiCounter_++;
00200 if(lumiCounter_%prescaleFactor_ != 0) return;
00201
00202 this->clientOperation();
00203
00204 }
00205
00206 void RPCEventSummary::endRun(const edm::Run& r, const edm::EventSetup& c){
00207
00208 this->clientOperation();
00209 }
00210
00211 void RPCEventSummary::clientOperation(){
00212
00213 float rpcevents = minimumEvents_;
00214 RPCEvents = dbe_->get( prefixFolder_ +"/RPCEvents");
00215
00216 if(RPCEvents) {
00217 rpcevents = RPCEvents ->getBinContent(1);
00218 }
00219
00220
00221 if(rpcevents < minimumEvents_) return;
00222 init_ = true;
00223 std::stringstream meName;
00224 MonitorElement * myMe;
00225
00226 meName.str("");
00227 meName<<eventInfoPath_ + "/reportSummaryMap";
00228 MonitorElement * reportMe = dbe_->get(meName.str());
00229
00230 MonitorElement * globalMe;
00231
00232
00233 float barrelFactor = 0;
00234
00235 for(int w = -2 ; w<3; w++){
00236
00237 meName.str("");
00238 meName<<globalFolder_<<"/RPCChamberQuality_Roll_vs_Sector_Wheel"<<w;
00239 myMe = dbe_->get(meName.str());
00240
00241 if(myMe){
00242 float wheelFactor = 0;
00243
00244 for(int s = 1; s<=myMe->getNbinsX() ; s++){
00245 float sectorFactor = 0;
00246 int rollInSector = 0;
00247
00248
00249 for(int r = 1;r<=myMe->getNbinsY(); r++){
00250 if((s!=4 && r > 17 ) || ((s ==9 ||s ==10) && r >15 ) ) continue;
00251 rollInSector++;
00252
00253
00254 if(myMe->getBinContent(s,r) == PARTIALLY_DEAD) sectorFactor+=0.8;
00255 else if(myMe->getBinContent(s,r) == DEAD )sectorFactor+=0;
00256 else sectorFactor+=1;
00257
00258 }
00259 if(rollInSector!=0)
00260 sectorFactor = sectorFactor/rollInSector;
00261
00262 if(reportMe) reportMe->setBinContent(w+8, s, sectorFactor);
00263 wheelFactor += sectorFactor;
00264
00265 }
00266
00267 wheelFactor = wheelFactor/myMe->getNbinsX();
00268
00269 meName.str("");
00270 meName<<eventInfoPath_ + "/reportSummaryContents/RPC_Wheel"<<w;
00271 globalMe=dbe_->get(meName.str());
00272 if(globalMe) globalMe->Fill(wheelFactor);
00273
00274 barrelFactor += wheelFactor;
00275 }
00276 }
00277
00278 barrelFactor = barrelFactor/5;
00279
00280
00281 float endcapFactor = 0;
00282
00283 if(doEndcapCertification_){
00284
00285
00286 for(int d = -numberDisk_ ; d<= numberDisk_; d++){
00287 if (d==0) continue;
00288
00289 meName.str("");
00290 meName<<globalFolder_<<"/RPCChamberQuality_Ring_vs_Segment_Disk"<<d;
00291 myMe = dbe_->get(meName.str());
00292
00293 if(myMe){
00294 float diskFactor = 0;
00295
00296 float sectorFactor[6]= {0,0,0,0,0,0};
00297
00298 for (int i = 0 ;i <6;i++){
00299 int firstSeg = (i *6 )+1;
00300 int lastSeg = firstSeg +6;
00301 int rollInSector = 0;
00302 for(int seg = firstSeg; seg< lastSeg ; seg++){
00303
00304 for(int y = 1;y<=myMe->getNbinsY(); y++){
00305 rollInSector++;
00306 if(myMe->getBinContent(seg,y) == PARTIALLY_DEAD) sectorFactor[i]+=0.8;
00307 else if(myMe->getBinContent(seg,y) == DEAD )sectorFactor[i]+=0;
00308 else sectorFactor[i]+=1;
00309
00310 }
00311 }
00312 sectorFactor[i] = sectorFactor[i]/rollInSector;
00313 }
00314
00315
00316 for (int sec = 0 ; sec<6; sec++){
00317 diskFactor += sectorFactor[sec];
00318 if(reportMe) {
00319 if (d<0) reportMe->setBinContent(d+5, sec+1 , sectorFactor[sec]);
00320 else reportMe->setBinContent(d+11, sec+1 , sectorFactor[sec]);
00321 }
00322 }
00323
00324 diskFactor = diskFactor/6;
00325
00326 meName.str("");
00327 meName<<eventInfoPath_ + "/reportSummaryContents/RPC_Disk"<<d;
00328 globalMe=dbe_->get(meName.str());
00329 if(globalMe) globalMe->Fill(diskFactor);
00330
00331 endcapFactor += diskFactor;
00332 }
00333
00334 }
00335
00336 endcapFactor=endcapFactor/ (numberDisk_ * 2);
00337
00338 }
00339
00340
00341 float rpcFactor = barrelFactor;
00342 if(doEndcapCertification_){ rpcFactor = ( barrelFactor + endcapFactor)/2; }
00343
00344 globalMe = dbe_->get(eventInfoPath_ +"/reportSummary");
00345 if(globalMe) globalMe->Fill(rpcFactor);
00346
00347
00348 }