00001 #include <set>
00002 #include <sstream>
00003 #include "DQM/RPCMonitorDigi/interface/RPCMonitorDigi.h"
00004 #include "DQM/RPCMonitorDigi/interface/utils.h"
00006 #include "DataFormats/Scalers/interface/DcsStatus.h"
00007 #include "DataFormats/MuonReco/interface/Muon.h"
00009 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00010 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00011 #include "Geometry/RPCGeometry/interface/RPCGeomServ.h"
00012 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
00013
00014 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00015
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017
00018 #include "RecoMuon/TransientTrackingRecHit/interface/MuonTransientTrackingRecHit.h"
00019
00020 const std::string RPCMonitorDigi::regionNames_[3] = {"Endcap-", "Barrel", "Endcap+"};
00021
00022 RPCMonitorDigi::RPCMonitorDigi( const edm::ParameterSet& pset ):counter(0){
00023
00024 saveRootFile = pset.getUntrackedParameter<bool>("SaveRootFile", false);
00025 RootFileName = pset.getUntrackedParameter<std::string>("RootFileName", "RPCMonitorDigiDQM.root");
00026
00027 useMuonDigis_= pset.getUntrackedParameter<bool>("UseMuon", true);
00028 useRollInfo_= pset.getUntrackedParameter<bool>("UseRollInfo", false);
00029 muonLabel_ = pset.getParameter<edm::InputTag>("MuonLabel");
00030 muPtCut_ = pset.getUntrackedParameter<double>("MuonPtCut", 3.0);
00031 muEtaCut_ = pset.getUntrackedParameter<double>("MuonEtaCut", 1.9);
00032
00033 subsystemFolder_ = pset.getUntrackedParameter<std::string>("RPCFolder", "RPC");
00034 globalFolder_ = pset.getUntrackedParameter<std::string>("GlobalFolder", "SummaryHistograms");
00035
00036 rpcRecHitLabel_ = pset.getParameter<edm::InputTag>("RecHitLabel");
00037
00038 numberOfDisks_ = pset.getUntrackedParameter<int>("NumberOfEndcapDisks", 3);
00039 numberOfInnerRings_ = pset.getUntrackedParameter<int>("NumberOfInnermostEndcapRings", 2);
00040
00041 noiseFolder_ = pset.getUntrackedParameter<std::string>("NoiseFolder", "AllHits");
00042 muonFolder_ = pset.getUntrackedParameter<std::string>("MuonFolder", "Muon");
00043
00044 }
00045
00046 RPCMonitorDigi::~RPCMonitorDigi(){}
00047 void RPCMonitorDigi::beginJob(){}
00048
00049 void RPCMonitorDigi::beginRun(const edm::Run& r, const edm::EventSetup& iSetup){
00050
00051 edm::LogInfo ("rpcmonitordigi") <<"[RPCMonitorDigi]: Begin Run " ;
00052
00054 dbe = edm::Service<DQMStore>().operator->();
00055
00056
00057 this->bookRegionME(noiseFolder_, regionNoiseCollection);
00058 this->bookSectorRingME(noiseFolder_, sectorRingNoiseCollection);
00059 this->bookWheelDiskME(noiseFolder_, wheelDiskNoiseCollection);
00060
00061
00062
00063 std::string currentFolder = subsystemFolder_ +"/"+noiseFolder_;
00064 dbe->setCurrentFolder(currentFolder);
00065
00066 noiseRPCEvents_= dbe->get(currentFolder +"/RPCEvents");
00067 if(noiseRPCEvents_) dbe->removeElement(noiseRPCEvents_->getName());
00068 noiseRPCEvents_ = dbe->book1D("RPCEvents","RPCEvents", 1, 0.5, 1.5);
00069
00070
00071 if(useMuonDigis_ ){
00072 this->bookRegionME(muonFolder_, regionMuonCollection);
00073 this->bookSectorRingME(muonFolder_, sectorRingMuonCollection);
00074 this->bookWheelDiskME(muonFolder_, wheelDiskMuonCollection);
00075
00076 currentFolder = subsystemFolder_ +"/"+muonFolder_;
00077 dbe->setCurrentFolder(currentFolder);
00078
00079 muonRPCEvents_= dbe->get(currentFolder +"/RPCEvents");
00080 if(muonRPCEvents_) dbe->removeElement(muonRPCEvents_->getName());
00081 muonRPCEvents_ = dbe->book1D("RPCEvents", "RPCEvents", 1, 0.5, 1.5);
00082
00083 NumberOfMuon_ = dbe->get(currentFolder+"/NumberOfMuons");
00084 if(NumberOfMuon_) dbe->removeElement(NumberOfMuon_->getName());
00085 NumberOfMuon_ = dbe->book1D("NumberOfMuons", "Number of Muons", 11, -0.5, 10.5);
00086
00087
00088 NumberOfRecHitMuon_ = dbe->get(currentFolder+"/NumberOfRPCRecHitsMuons");
00089 if(NumberOfRecHitMuon_) dbe->removeElement(NumberOfRecHitMuon_->getName());
00090 NumberOfRecHitMuon_ = dbe->book1D("NumberOfRecHitMuons", "Number of RPC RecHits per Muon", 8, -0.5, 7.5);
00091 }
00092
00093
00094 edm::ESHandle<RPCGeometry> rpcGeo;
00095 iSetup.get<MuonGeometryRecord>().get(rpcGeo);
00096
00097 edm::LogInfo ("rpcmonitordigi") <<"[RPCMonitorDigi]: Booking histograms per roll. " ;
00098 for (TrackingGeometry::DetContainer::const_iterator it=rpcGeo->dets().begin();it<rpcGeo->dets().end();it++){
00099 if(dynamic_cast< RPCChamber* >( *it ) != 0 ){
00100 RPCChamber* ch = dynamic_cast< RPCChamber* >( *it );
00101 std::vector< const RPCRoll*> roles = (ch->rolls());
00102 if(useRollInfo_){
00103 for(std::vector<const RPCRoll*>::const_iterator r = roles.begin();r != roles.end(); ++r){
00104 RPCDetId rpcId = (*r)->id();
00105
00106 RPCGeomServ rpcsrv(rpcId);
00107 std::string nameID = rpcsrv.name();
00108 if(useMuonDigis_) bookRollME(rpcId ,iSetup, muonFolder_, meMuonCollection[nameID]);
00109 bookRollME(rpcId, iSetup, noiseFolder_, meNoiseCollection[nameID]);
00110 }
00111 }else{
00112 RPCDetId rpcId = roles[0]->id();
00113 RPCGeomServ rpcsrv(rpcId);
00114 std::string nameID = rpcsrv.chambername();
00115 if(useMuonDigis_) bookRollME(rpcId,iSetup, muonFolder_, meMuonCollection[nameID]);
00116 bookRollME(rpcId, iSetup, noiseFolder_, meNoiseCollection[nameID]);
00117
00118 }
00119 }
00120 }
00121
00122
00123
00124 dcs_ = true;
00125 }
00126
00127 void RPCMonitorDigi::endJob(void){
00128 if(saveRootFile) dbe->save(RootFileName);
00129 dbe = 0;
00130 }
00131
00132 void RPCMonitorDigi::endLuminosityBlock(edm::LuminosityBlock const& L, edm::EventSetup const& E){}
00133
00134
00135 void RPCMonitorDigi::analyze(const edm::Event& event,const edm::EventSetup& setup ){
00136 dcs_ = true;
00137
00138 this->makeDcsInfo(event);
00139 if( !dcs_){
00140 edm::LogWarning ("rpcmonitordigi") <<"[RPCMonitorDigi]: DCS bit OFF" ;
00141 return;
00142 }
00143
00144 counter++;
00145 edm::LogInfo ("rpcmonitordigi") <<"[RPCMonitorDigi]: Beginning analyzing event " << counter;
00146
00147
00148 edm::Handle<reco::CandidateView> muonCands;
00149 event.getByLabel(muonLabel_, muonCands);
00150 std::map<RPCDetId , std::vector<RPCRecHit> > rechitMuon;
00151
00152 int numMuons = 0;
00153 int numRPCRecHit = 0 ;
00154
00155 if(muonCands.isValid()){
00156
00157 int nStaMuons = muonCands->size();
00158
00159 for( int i = 0; i < nStaMuons; i++ ) {
00160
00161 const reco::Candidate & goodMuon = (*muonCands)[i];
00162 const reco::Muon * muCand = dynamic_cast<const reco::Muon*>(&goodMuon);
00163
00164 if(!muCand->isGlobalMuon())continue;
00165 if(muCand->pt() < muPtCut_ || fabs(muCand->eta())>muEtaCut_) continue;
00166 numMuons++;
00167 reco::Track muTrack = (*(muCand->outerTrack()));
00168 std::vector<TrackingRecHitRef > rpcTrackRecHits;
00169
00170 for ( trackingRecHit_iterator it= muTrack.recHitsBegin(); it != muTrack.recHitsEnd() ; it++) {
00171 if (!(*it)->isValid ())continue;
00172 int muSubDetId = (*it)->geographicalId().subdetId();
00173 if(muSubDetId == MuonSubdetId::RPC) {
00174 numRPCRecHit ++;
00175 TrackingRecHit * tkRecHit = (*it)->clone();
00176 RPCRecHit* rpcRecHit = dynamic_cast<RPCRecHit*>(tkRecHit);
00177 int detId = (int)rpcRecHit->rpcId();
00178 if(rechitMuon.find(detId) == rechitMuon.end() || rechitMuon[detId].size() == 0){
00179 std::vector<RPCRecHit> myVect(1,*rpcRecHit );
00180 rechitMuon[detId]= myVect;
00181 }else {
00182 rechitMuon[detId].push_back(*rpcRecHit);
00183 }
00184 }
00185 }
00186
00187 }
00188
00189 if( NumberOfMuon_) NumberOfMuon_->Fill(numMuons);
00190 if( NumberOfRecHitMuon_) NumberOfRecHitMuon_->Fill( numRPCRecHit);
00191
00192 }else{
00193 edm::LogError ("rpcmonitordigi") <<"[RPCMonitorDigi]: Muons - Product not valid for event" << counter;
00194 }
00195
00196
00197 edm::Handle<RPCRecHitCollection> rpcHits;
00198 event.getByLabel( rpcRecHitLabel_ , rpcHits);
00199 std::map<RPCDetId , std::vector<RPCRecHit> > rechitNoise;
00200
00201
00202 if(rpcHits.isValid()){
00203
00204
00205 RPCRecHitCollection::const_iterator rpcRecHitIter;
00206 std::vector<RPCRecHit>::const_iterator muonRecHitIter;
00207
00208 for (rpcRecHitIter = rpcHits->begin(); rpcRecHitIter != rpcHits->end() ; rpcRecHitIter++) {
00209 RPCRecHit rpcRecHit = (*rpcRecHitIter);
00210 int detId = (int)rpcRecHit.rpcId();
00211 if(rechitNoise.find(detId) == rechitNoise.end() || rechitNoise[detId].size() == 0){
00212 std::vector<RPCRecHit> myVect(1,rpcRecHit );
00213 rechitNoise[detId]= myVect;
00214 }else {
00215 rechitNoise[detId].push_back(rpcRecHit);
00216 }
00217 }
00218 }else{
00219 edm::LogError ("rpcmonitordigi") <<"[RPCMonitorDigi]: RPCRecHits - Product not valid for event" << counter;
00220 }
00221
00222
00223 if( useMuonDigis_ && muonRPCEvents_ != 0 ) muonRPCEvents_->Fill(1);
00224 if( noiseRPCEvents_ != 0) noiseRPCEvents_->Fill(1);
00225
00226 if(useMuonDigis_ ) this->performSourceOperation(rechitMuon, muonFolder_);
00227 this->performSourceOperation(rechitNoise, noiseFolder_);
00228 }
00229
00230
00231 void RPCMonitorDigi::performSourceOperation( std::map<RPCDetId , std::vector<RPCRecHit> > & recHitMap, std::string recHittype){
00232
00233 edm::LogInfo ("rpcmonitordigi") <<"[RPCMonitorDigi]: Performing DQM source operations for ";
00234
00235 if(recHitMap.size()==0) return;
00236
00237 std::map<std::string, std::map<std::string, MonitorElement*> > meRollCollection ;
00238 std::map<std::string, MonitorElement*> meWheelDisk ;
00239 std::map<std::string, MonitorElement*> meRegion ;
00240 std::map<std::string, MonitorElement*> meSectorRing;
00241
00242 if(recHittype == muonFolder_ ) {
00243 meRollCollection = meMuonCollection;
00244 meWheelDisk = wheelDiskMuonCollection;
00245 meRegion = regionMuonCollection;
00246 meSectorRing = sectorRingMuonCollection;
00247 }else if(recHittype == noiseFolder_ ){
00248 meRollCollection = meNoiseCollection;
00249 meWheelDisk = wheelDiskNoiseCollection;
00250 meRegion = regionNoiseCollection;
00251 meSectorRing = sectorRingNoiseCollection;
00252 }else{
00253 edm::LogWarning("rpcmonitordigi")<<"[RPCMonitorDigi]: RecHit type not valid.";
00254 return;
00255 }
00256
00257
00258 int totalNumberOfRecHits[3] ={ 0, 0, 0};
00259 std::stringstream os;
00260
00261
00262 for ( std::map<RPCDetId , std::vector<RPCRecHit> >::const_iterator detIdIter = recHitMap.begin(); detIdIter != recHitMap.end() ; detIdIter++){
00263
00264 RPCDetId detId = (*detIdIter).first;
00265
00266
00267
00268 rpcdqm::utils rpcUtils;
00269 int nr = rpcUtils.detId2RollNr(detId);
00270
00271
00272 RPCGeomServ geoServ(detId);
00273 std::string nameRoll = "";
00274
00275
00276 if(useRollInfo_) nameRoll = geoServ.name();
00277 else nameRoll = geoServ.chambername();
00278
00279 int region=(int)detId.region();
00280 int wheelOrDiskNumber;
00281 std::string wheelOrDiskType;
00282 int ring = 0 ;
00283 int sector = detId.sector();
00284 int layer = 0;
00285 int totalRolls = 3;
00286 int roll = detId.roll();
00287 if(region == 0) {
00288 wheelOrDiskType = "Wheel";
00289 wheelOrDiskNumber = (int)detId.ring();
00290 int station = detId.station();
00291
00292 if(station == 1){
00293 if(detId.layer() == 1){
00294 layer = 1;
00295 totalRolls = 2;
00296 }else{
00297 layer = 2;
00298 totalRolls = 2;
00299 }
00300 if(roll == 3) roll =2;
00301 }else if(station == 2){
00302 if(detId.layer() == 1){
00303 layer = 3;
00304 if( abs(wheelOrDiskNumber) ==2 && roll == 3) {
00305 roll = 2;
00306 totalRolls = 2;
00307 }
00308 }else{
00309 layer = 4;
00310 if( abs(wheelOrDiskNumber) !=2 && roll == 3){
00311 roll = 2;
00312 totalRolls = 2;
00313 }
00314 }
00315 }else if (station == 3){
00316 layer = 5;
00317 totalRolls = 2;
00318 if(roll == 3) roll =2;
00319 }else{
00320 layer = 6;
00321 totalRolls = 2;
00322 if(roll == 3) roll =2;
00323 }
00324
00325 }else {
00326 wheelOrDiskType = "Disk";
00327 wheelOrDiskNumber = region*(int)detId.station();
00328 ring = detId.ring();
00329 }
00330
00331 std::vector<RPCRecHit> recHits = (*detIdIter).second;
00332 int numberOfRecHits = recHits.size();
00333 totalNumberOfRecHits[region + 1 ] += numberOfRecHits;
00334
00335 std::set<int> bxSet ;
00336 int numDigi = 0;
00337
00338 std::map<std::string, MonitorElement*> meMap = meRollCollection[nameRoll];
00339
00340
00341 for(std::vector<RPCRecHit>::const_iterator recHitIter = recHits.begin(); recHitIter != recHits.end(); recHitIter++){
00342 RPCRecHit recHit = (*recHitIter);
00343
00344 int bx = recHit.BunchX();
00345 bxSet.insert(bx);
00346 int clusterSize = (int)recHit.clusterSize();
00347 numDigi += clusterSize ;
00348 int firstStrip = recHit.firstClusterStrip();
00349 int lastStrip = clusterSize + firstStrip - 1;
00350
00351
00352
00353 os.str("");
00354 os<<"Occupancy_"<<nameRoll;
00355 if(meMap[os.str()]) {
00356 for(int s=firstStrip; s<= lastStrip; s++){
00357 if(useRollInfo_) { meMap[os.str()]->Fill(s);}
00358 else{
00359 int nstrips = meMap[os.str()]->getNbinsX()/totalRolls;
00360 meMap[os.str()]->Fill(s + nstrips*(roll-1)); }
00361 }
00362 }
00363
00364 os.str("");
00365 os<<"BXDistribution_"<<nameRoll;
00366 if(meMap[os.str()]) meMap[os.str()]->Fill(bx);
00367
00368
00369 os.str("");
00370 os<<"ClusterSize_"<<nameRoll;
00371 if(meMap[os.str()]) meMap[os.str()]->Fill(clusterSize);
00372
00373
00374
00375
00376
00377
00378 os.str("");
00379 os<<"Occupancy_"<<wheelOrDiskType<<"_"<<wheelOrDiskNumber<<"_Sector_"<<sector;
00380 if( meSectorRing[os.str()]){
00381 for(int s=firstStrip; s<= lastStrip; s++){
00382 meSectorRing[os.str()]->Fill(s, nr);
00383 }
00384 }
00385
00386
00387
00388
00389
00390 os.str("");
00391 if(geoServ.segment() > 0 && geoServ.segment() < 19 ){
00392 os<<"Occupancy_"<<wheelOrDiskType<<"_"<<wheelOrDiskNumber<<"_Ring_"<<ring<<"_CH01-CH18";
00393 }else if (geoServ.segment() > 18 ){
00394 os<<"Occupancy_"<<wheelOrDiskType<<"_"<<wheelOrDiskNumber<<"_Ring_"<<ring<<"_CH19-CH36";
00395 }
00396
00397 if( meSectorRing[os.str()]){
00398 for(int s=firstStrip; s<= lastStrip; s++){
00399 meSectorRing[os.str()]->Fill(s + 32*(detId.roll()-1), geoServ.segment());
00400 }
00401 }
00402
00403
00404
00405
00406
00407
00408
00409 if(region ==0){
00410 os.str("");
00411 os<<"1DOccupancy_Wheel_"<<wheelOrDiskNumber;
00412 if( meWheelDisk[os.str()]) meWheelDisk[os.str()]->Fill(sector, clusterSize);
00413
00414 os.str("");
00415 os<<"Occupancy_Roll_vs_Sector_"<<wheelOrDiskType<<"_"<<wheelOrDiskNumber;
00416 if (meWheelDisk[os.str()]) meWheelDisk[os.str()]->Fill(sector, nr, clusterSize);
00417
00418 }else{
00419 os.str("");
00420 os<<"1DOccupancy_Ring_"<<ring;
00421 if ((meWheelDisk[os.str()])){
00422 if (wheelOrDiskNumber > 0 ) meWheelDisk[os.str()]->Fill(wheelOrDiskNumber +3, clusterSize);
00423 else meWheelDisk[os.str()]->Fill(wheelOrDiskNumber + 4, clusterSize);
00424 }
00425
00426 os.str("");
00427 os<<"Occupancy_Ring_vs_Segment_"<<wheelOrDiskType<<"_"<<wheelOrDiskNumber;
00428 if (meWheelDisk[os.str()]) meWheelDisk[os.str()]->Fill( geoServ.segment(), (ring-1)*3-detId.roll()+1,clusterSize );
00429 }
00430
00431 os.str("");
00432 os<<"BxDistribution_"<<wheelOrDiskType<<"_"<<wheelOrDiskNumber;
00433 if(meWheelDisk[os.str()]) meWheelDisk[os.str()]->Fill(bx);
00434
00435
00436 os.str("");
00437 os<<"ClusterSize_"<<wheelOrDiskType<<"_"<<wheelOrDiskNumber<<"_Layer"<<layer;
00438 if(meWheelDisk[os.str()]) meWheelDisk[os.str()] -> Fill(clusterSize);
00439
00440
00441 os.str("");
00442 os<<"ClusterSize_"<<wheelOrDiskType<<"_"<<wheelOrDiskNumber<<"_Ring"<<ring;
00443 if(meWheelDisk[os.str()]) meWheelDisk[os.str()] -> Fill(clusterSize);
00444
00445
00446
00447
00448
00449 os.str("");
00450 os<<"ClusterSize_"<<RPCMonitorDigi::regionNames_[region +1];
00451 if(meRegion[os.str()]) meRegion[os.str()] -> Fill(clusterSize);
00452
00453 os.str("");
00454 os<<"ClusterSize_";
00455 if(region == 0){
00456 os<<"Layer"<<layer;
00457 }else{
00458 os<<"Ring"<<ring;
00459 }
00460 if(meRegion[os.str()]) meRegion[os.str()] -> Fill(clusterSize);
00461
00462
00463 }
00464
00465 os.str("");
00466 os<<"BXWithData_"<<nameRoll;
00467 if(meMap[os.str()]) meMap[os.str()]->Fill(bxSet.size());
00468
00469 os.str("");
00470 os<<"NumberOfClusters_"<<nameRoll;
00471 if(meMap[os.str()]) meMap[os.str()]->Fill( numberOfRecHits);
00472
00473 os.str("");
00474 os<<"Multiplicity_"<<RPCMonitorDigi::regionNames_[region +1];
00475 if(meRegion[os.str()]) meRegion[os.str()]->Fill(numDigi);
00476
00477 os.str("");
00478 if(region==0) {
00479 os<<"Occupancy_for_Barrel";
00480 if(meRegion[os.str()]) meRegion[os.str()]->Fill(sector, wheelOrDiskNumber, numDigi);
00481 }else {
00482 os<<"Occupancy_for_Endcap";
00483 int xbin = wheelOrDiskNumber+3;
00484 if (region==-1) xbin = wheelOrDiskNumber+4;
00485 if(meRegion[os.str()]) meRegion[os.str()]->Fill(xbin,ring,numDigi);
00486 }
00487
00488 os.str("");
00489 os<<"Multiplicity_"<<nameRoll;
00490 if(meMap[os.str()]) meMap[os.str()]->Fill(numDigi);
00491
00492 }
00493
00494 for(int i = 0; i< 3; i++ ){
00495 os.str("");
00496 os<<"NumberOfClusters_"<<RPCMonitorDigi::regionNames_[i];
00497 if(meRegion[os.str()]) meRegion[os.str()]->Fill( totalNumberOfRecHits[i]);
00498 }
00499
00500 }
00501
00502
00503 void RPCMonitorDigi::makeDcsInfo(const edm::Event& e) {
00504
00505 edm::Handle<DcsStatusCollection> dcsStatus;
00506
00507 if ( ! e.getByLabel("scalersRawToDigi", dcsStatus) ){
00508 dcs_ = true;
00509 return;
00510 }
00511
00512 if ( ! dcsStatus.isValid() )
00513 {
00514 edm::LogWarning("RPCDcsInfo") << "scalersRawToDigi not found" ;
00515 dcs_ = true;
00516 return;
00517 }
00518
00519 for (DcsStatusCollection::const_iterator dcsStatusItr = dcsStatus->begin();
00520 dcsStatusItr != dcsStatus->end(); ++dcsStatusItr){
00521
00522 if (!dcsStatusItr->ready(DcsStatus::RPC)) dcs_=false;
00523 }
00524
00525 return ;
00526 }
00527
00528