00001
00002
00003 #include <sstream>
00004 #include <DQM/RPCMonitorClient/interface/RPCOccupancyTest.h>
00005 #include "DQM/RPCMonitorDigi/interface/utils.h"
00006
00007
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009
00010 #include "Geometry/RPCGeometry/interface/RPCGeomServ.h"
00011
00012 RPCOccupancyTest::RPCOccupancyTest(const edm::ParameterSet& ps ){
00013 edm::LogVerbatim ("rpceventsummary") << "[RPCOccupancyTest]: Constructor";
00014
00015 globalFolder_ = ps.getUntrackedParameter<std::string>("RPCGlobalFolder", "RPC/RecHits/SummaryHistograms");
00016 prescaleFactor_ = ps.getUntrackedParameter<int>("DiagnosticPrescale", 1);
00017 numberOfDisks_ = ps.getUntrackedParameter<int>("NumberOfEndcapDisks", 3);
00018 numberOfRings_ = ps.getUntrackedParameter<int>("NumberOfEndcapRings", 2);
00019
00020 }
00021
00022 RPCOccupancyTest::~RPCOccupancyTest(){
00023 dbe_=0;
00024 }
00025
00026 void RPCOccupancyTest::beginJob(DQMStore * dbe){
00027 edm::LogVerbatim ("rpceventsummary") << "[RPCOccupancyTest]: Begin job ";
00028 dbe_=dbe;
00029 }
00030
00031 void RPCOccupancyTest::endRun(const edm::Run& r, const edm::EventSetup& c,std::vector<MonitorElement *> meVector, std::vector<RPCDetId> detIdVector){
00032 edm::LogVerbatim ("rpceventsummary") << "[RPCOccupancyTest]: Begin run";
00033
00034
00035 MonitorElement* me;
00036 dbe_->setCurrentFolder( globalFolder_);
00037
00038 std::stringstream histoName;
00039 rpcdqm::utils rpcUtils;
00040
00041 int limit = numberOfDisks_;
00042 if(numberOfDisks_ < 2) limit = 2;
00043
00044 histoName.str("");
00045 histoName<<"Barrel_OccupancyByStations_Normalized";
00046 me = dbe_->get( globalFolder_+"/"+ histoName.str());
00047 if ( 0!=me ) {
00048 dbe_->removeElement(me->getName());
00049 }
00050 Barrel_OccBySt = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 4, 0.5, 4.5);
00051 Barrel_OccBySt -> setBinLabel(1, "St1", 1);
00052 Barrel_OccBySt -> setBinLabel(2, "St2", 1);
00053 Barrel_OccBySt -> setBinLabel(3, "St3", 1);
00054 Barrel_OccBySt -> setBinLabel(4, "St4", 1);
00055
00056
00057 histoName.str("");
00058 histoName<<"EndCap_OccupancyByRings_Normalized";
00059 me = dbe_->get( globalFolder_+"/"+ histoName.str());
00060 if ( 0!=me ) {
00061 dbe_->removeElement(me->getName());
00062 }
00063 EndCap_OccByRng = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 4, 0.5, 4.5);
00064 EndCap_OccByRng -> setBinLabel(1, "E+/R3", 1);
00065 EndCap_OccByRng -> setBinLabel(2, "E+/R2", 1);
00066 EndCap_OccByRng -> setBinLabel(3, "E-/R2", 1);
00067 EndCap_OccByRng -> setBinLabel(4, "E-/R3", 1);
00068
00069 histoName.str("");
00070 histoName<<"EndCap_OccupancyByDisksAndRings_Normalized";
00071 me = dbe_->get( globalFolder_+"/"+ histoName.str());
00072 if ( 0!=me ) {
00073 dbe_->removeElement(me->getName());
00074 }
00075 EndCap_OccByDisk = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 12, 0, 12);
00076 EndCap_OccByDisk -> setBinLabel(1, "YE-3/R2", 1);
00077 EndCap_OccByDisk -> setBinLabel(2, "YE-2/R2", 1);
00078 EndCap_OccByDisk -> setBinLabel(3, "YE-1/R2", 1);
00079 EndCap_OccByDisk -> setBinLabel(4, "YE+1/R2", 1);
00080 EndCap_OccByDisk -> setBinLabel(5, "YE+2/R2", 1);
00081 EndCap_OccByDisk -> setBinLabel(6, "YE+3/R2", 1);
00082
00083 EndCap_OccByDisk -> setBinLabel(7, "YE-3/R3", 1);
00084 EndCap_OccByDisk -> setBinLabel(8, "YE-2/R3", 1);
00085 EndCap_OccByDisk -> setBinLabel(9, "YE-1/R3", 1);
00086 EndCap_OccByDisk -> setBinLabel(10, "YE+1/R3", 1);
00087 EndCap_OccByDisk -> setBinLabel(11, "YE+2/R3", 1);
00088 EndCap_OccByDisk -> setBinLabel(12, "YE+3/R3", 1);
00089
00090 for (int w = -1 *limit; w<=limit; w++ ){
00091 if (w>-3 && w<3){
00092 histoName.str("");
00093 histoName<<"AsymmetryLeftRight_Roll_vs_Sector_Wheel"<<w;
00094 me = 0;
00095 me = dbe_->get( globalFolder_+"/"+ histoName.str());
00096 if ( 0!=me ) {
00097 dbe_->removeElement(me->getName());
00098 }
00099
00100 AsyMeWheel[w+2] = dbe_->book2D(histoName.str().c_str(), histoName.str().c_str(), 12, 0.5, 12.5, 21, 0.5, 21.5);
00101
00102 rpcUtils.labelXAxisSector( AsyMeWheel[w+2]);
00103 rpcUtils.labelYAxisRoll( AsyMeWheel[w+2], 0, w);
00104
00105 histoName.str("");
00106 histoName<<"AsymmetryLeftRight_Distribution_Wheel"<<w;
00107 me = 0;
00108 me = dbe_->get( globalFolder_+"/"+ histoName.str());
00109 if ( 0!=me ) {
00110 dbe_->removeElement(me->getName());
00111 }
00112 AsyMeDWheel[w+2] = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 20, -0.1, 1.1);
00113
00114
00115 histoName.str("");
00116 histoName<<"OccupancyNormByEvents_Wheel"<<w;
00117 me = 0;
00118 me = dbe_->get( globalFolder_+"/"+ histoName.str());
00119 if ( 0!=me ) {
00120 dbe_->removeElement(me->getName());
00121 }
00122
00123 NormOccupWheel[w+2] = dbe_->book2D(histoName.str().c_str(), histoName.str().c_str(), 12, 0.5, 12.5, 21, 0.5, 21.5);
00124
00125 rpcUtils.labelXAxisSector( NormOccupWheel[w+2]);
00126 rpcUtils.labelYAxisRoll( NormOccupWheel[w+2], 0, w);
00127
00128 histoName.str("");
00129 histoName<<"OccupancyNormByEvents_Distribution_Wheel"<<w;
00130 me = 0;
00131 me = dbe_->get( globalFolder_+"/"+ histoName.str());
00132 if ( 0!=me ) {
00133 dbe_->removeElement(me->getName());
00134 }
00135 NormOccupDWheel[w+2] = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 100, 0.0, 0.205);
00136 }
00137
00138 if (w == 0 || w< (-1 * numberOfDisks_) || w > numberOfDisks_)continue;
00139
00140 int offset = numberOfDisks_;
00141 if (w>0) offset --;
00142
00143 histoName.str("");
00144 histoName<<"AsymmetryLeftRight_Ring_vs_Segment_Disk"<<w;
00145 me = 0;
00146 me = dbe_->get( globalFolder_+"/"+ histoName.str());
00147 if ( 0!=me ) {
00148 dbe_->removeElement(me->getName());
00149 }
00150
00151 AsyMeDisk[w+offset] = dbe_->book2D(histoName.str().c_str(), histoName.str().c_str(), 36, 0.5, 36.5, 3*numberOfRings_, 0.5,3*numberOfRings_+ 0.5);
00152
00153 rpcUtils.labelXAxisSegment(AsyMeDisk[w+offset]);
00154 rpcUtils.labelYAxisRing(AsyMeDisk[w+offset], numberOfRings_);
00155
00156 histoName.str("");
00157 histoName<<"AsymmetryLeftRight_Distribution_Disk"<<w;
00158 me = 0;
00159 me = dbe_->get( globalFolder_+"/"+ histoName.str());
00160 if ( 0!=me ) {
00161 dbe_->removeElement(me->getName());
00162 }
00163 AsyMeDDisk[w+offset] = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 20, -0.1, 1.1);
00164
00165
00166 histoName.str("");
00167 histoName<<"OccupancyNormByEvents_Disk"<<w;
00168 me = 0;
00169 me = dbe_->get( globalFolder_+"/"+ histoName.str());
00170 if ( 0!=me ) {
00171 dbe_->removeElement(me->getName());
00172 }
00173
00174 NormOccupDisk[w+offset] = dbe_->book2D(histoName.str().c_str(), histoName.str().c_str(), 36, 0.5, 36.5, 3*numberOfRings_, 0.5,3*numberOfRings_+ 0.5);
00175
00176 rpcUtils.labelXAxisSegment(NormOccupDisk[w+offset]);
00177 rpcUtils.labelYAxisRing( NormOccupDisk[w+offset],numberOfRings_);
00178
00179 histoName.str("");
00180 histoName<<"OccupancyNormByEvents_Distribution_Disk"<<w;
00181 me = 0;
00182 me = dbe_->get( globalFolder_+"/"+ histoName.str());
00183 if ( 0!=me ) {
00184 dbe_->removeElement(me->getName());
00185 }
00186 NormOccupDDisk[w+offset] = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 100, 0.0, 0.205);
00187
00188 }
00189
00190
00191 for (unsigned int i = 0 ; i<meVector.size(); i++){
00192
00193 bool flag= false;
00194
00195 DQMNet::TagList tagList;
00196 tagList = meVector[i]->getTags();
00197 DQMNet::TagList::iterator tagItr = tagList.begin();
00198
00199 while (tagItr != tagList.end() && !flag ) {
00200 if((*tagItr) == rpcdqm::OCCUPANCY)
00201 flag= true;
00202 tagItr++;
00203 }
00204
00205 if(flag){
00206 myOccupancyMe_.push_back(meVector[i]);
00207 myDetIds_.push_back(detIdVector[i]);
00208 }
00209 }
00210 }
00211
00212 void RPCOccupancyTest::beginLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& context){}
00213
00214 void RPCOccupancyTest::analyze(const edm::Event& iEvent, const edm::EventSetup& c) {}
00215
00216 void RPCOccupancyTest::endLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& iSetup) {}
00217
00218 void RPCOccupancyTest::clientOperation(edm::EventSetup const& iSetup) {
00219
00220 edm::LogVerbatim ("rpceventsummary") <<"[RPCOccupancyTest]: Client Operation";
00221
00222 MonitorElement * RPCEvents = dbe_->get(globalFolder_ +"/RPCEvents");
00223 rpcevents_ = RPCEvents -> getEntries();
00224
00225
00226
00227
00228 int limit = numberOfDisks_ * 2;
00229 if(numberOfDisks_<2) limit = 5;
00230 for(int i =0 ; i<limit; i++){
00231 if(i < numberOfDisks_ * 2){
00232 AsyMeDDisk[i]->Reset();
00233 NormOccupDDisk[i]->Reset();
00234 }
00235 if(i<5){
00236 AsyMeDWheel[i]->Reset();
00237 NormOccupDWheel[i]->Reset();
00238 }
00239 }
00240
00241
00242 for (unsigned int i = 0 ; i<myOccupancyMe_.size();i++){
00243 this->fillGlobalME(myDetIds_[i],myOccupancyMe_[i]);
00244 }
00245 }
00246
00247 void RPCOccupancyTest::endJob(void) {}
00248 void RPCOccupancyTest::beginRun(const edm:: Run& r, const edm::EventSetup& c) {}
00249
00250
00251 void RPCOccupancyTest::fillGlobalME(RPCDetId & detId, MonitorElement * myMe){
00252
00253
00254 if (!myMe) return;
00255
00256 MonitorElement * AsyMe=NULL;
00257 MonitorElement * AsyMeD=NULL;
00258 MonitorElement * NormOccup=NULL;
00259 MonitorElement * NormOccupD=NULL;
00260
00261 if(detId.region() ==0){
00262 AsyMe= AsyMeWheel[detId.ring()+2];
00263 AsyMeD= AsyMeDWheel[detId.ring()+2];
00264 NormOccup=NormOccupWheel[detId.ring()+2];
00265 NormOccupD=NormOccupDWheel[detId.ring()+2];
00266
00267 }else{
00268
00269 if( -detId.station() + numberOfDisks_ >= 0 ){
00270
00271 if(detId.region()<0){
00272 AsyMe= AsyMeDisk[-detId.station() + numberOfDisks_];
00273 AsyMeD= AsyMeDDisk[-detId.station() + numberOfDisks_];
00274 NormOccup=NormOccupDisk[-detId.station() + numberOfDisks_];
00275 NormOccupD=NormOccupDDisk[-detId.station() + numberOfDisks_];
00276 }else{
00277 AsyMe= AsyMeDisk[detId.station() + numberOfDisks_-1];
00278 AsyMeD= AsyMeDDisk[detId.station() + numberOfDisks_-1];
00279 NormOccup=NormOccupDisk[detId.station() + numberOfDisks_-1];
00280 NormOccupD=NormOccupDDisk[detId.station() + numberOfDisks_-1];
00281 }
00282 }
00283
00284
00285 }
00286
00287
00288 int xBin,yBin;
00289 if(detId.region()==0){
00290 xBin= detId.sector();
00291 rpcdqm::utils rollNumber;
00292 yBin = rollNumber.detId2RollNr(detId);
00293 }else{
00294
00295 RPCGeomServ RPCServ(detId);
00296 xBin = RPCServ.segment();
00297 (numberOfRings_ == 3 ? yBin= detId.ring()*3-detId.roll()+1 : yBin= (detId.ring()-1)*3-detId.roll()+1);
00298 }
00299
00300
00301 int stripInRoll=myMe->getNbinsX();
00302 float FOccupancy=0;
00303 float BOccupancy=0;
00304
00305 float totEnt = myMe->getEntries();
00306 for(int strip = 1 ; strip<=stripInRoll; strip++){
00307 if(strip<=stripInRoll/2) FOccupancy+=myMe->getBinContent(strip);
00308 else BOccupancy+=myMe->getBinContent(strip);
00309 }
00310
00311
00312 float asym = 0;
00313 if(totEnt != 0 ) asym = fabs((FOccupancy - BOccupancy )/totEnt);
00314
00315 if(AsyMe) AsyMe->setBinContent(xBin,yBin,asym );
00316
00317 if(AsyMeD) AsyMeD->Fill(asym);
00318
00319 float normoccup = 0;
00320 if(rpcevents_ !=0)
00321 normoccup = (totEnt/rpcevents_);
00322 if(NormOccup) NormOccup->setBinContent(xBin,yBin, normoccup);
00323 if(NormOccupD) NormOccupD->Fill(normoccup);
00324
00325
00326
00327
00328 if(detId.region()==0) {
00329 if(detId.station()==1 )Barrel_OccBySt -> Fill(1, normoccup);
00330 if(detId.station()==2 )Barrel_OccBySt -> Fill(2, normoccup);
00331 if(detId.station()==3 )Barrel_OccBySt -> Fill(3, normoccup);
00332 if(detId.station()==4 )Barrel_OccBySt -> Fill(4, normoccup);
00333
00334 }
00335 else if(detId.region()==1) {
00336
00337
00338
00339
00340
00341 if(detId.ring()==3) {
00342 EndCap_OccByRng -> Fill(1, normoccup);
00343 EndCap_OccByDisk -> Fill(detId.region()*detId.station()+8, normoccup);
00344 }
00345 else {
00346 EndCap_OccByRng -> Fill(2, normoccup);
00347 EndCap_OccByDisk -> Fill(detId.region()*detId.station()+2, normoccup);
00348 }
00349 }
00350 else {
00351
00352 if(detId.ring()==3) {
00353 EndCap_OccByRng -> Fill(4, normoccup);
00354 EndCap_OccByDisk -> Fill(detId.region()*detId.station()+9, normoccup);
00355 }
00356 else {
00357 EndCap_OccByRng -> Fill(3, normoccup);
00358 EndCap_OccByDisk -> Fill(detId.region()*detId.station()+3, normoccup);
00359 }
00360 }
00361 }
00362
00363
00364
00365
00366