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