00001
00002
00003
00004 #include <TRandom.h>
00005 #include <string>
00006 #include <sstream>
00007 #include "DQM/RPCMonitorDigi/interface/RPCMonitorDigi.h"
00008 #include "DQM/RPCMonitorDigi/interface/utils.h"
00010 #include "DataFormats/RPCDigi/interface/RPCDigi.h"
00011 #include "DataFormats/RPCDigi/interface/RPCDigiCollection.h"
00012 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00013 #include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"
00014 #include "DataFormats/GeometrySurface/interface/LocalError.h"
00015 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
00016 #include "DataFormats/Scalers/interface/DcsStatus.h"
00018 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00019 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00020 #include "Geometry/RPCGeometry/interface/RPCGeomServ.h"
00022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00023
00024 RPCMonitorDigi::RPCMonitorDigi( const edm::ParameterSet& pset ):counter(0){
00025
00026 nameInLog = pset.getUntrackedParameter<std::string>("moduleLogName", "rpcmonitordigi");
00027
00028 saveRootFile = pset.getUntrackedParameter<bool>("DigiDQMSaveRootFile", false);
00029 mergeRuns_ = pset.getUntrackedParameter<bool>("MergeDifferentRuns", false);
00030
00031 RootFileName = pset.getUntrackedParameter<std::string>("RootFileNameDigi", "RPCMonitor.root");
00032
00033 globalFolder_ = pset.getUntrackedParameter<std::string>("RPCGlobalFolder", "RPC/RecHits/SummaryHistograms");
00034 muonNoise_ = pset.getUntrackedParameter<std::string>("DataType", "Noise");
00035
00036 dqmshifter = pset.getUntrackedParameter<bool>("dqmshifter", false);
00037 dqmexpert = pset.getUntrackedParameter<bool>("dqmexpert", false);
00038 dqmsuperexpert = pset.getUntrackedParameter<bool>("dqmsuperexpert", false);
00039
00040 RPCRecHitLabel_ = pset.getParameter<edm::InputTag>("RecHitLabel");
00041 RPCDigiLabel_ =pset.getParameter<edm::InputTag>("DigiLabel");
00042 }
00043
00044 RPCMonitorDigi::~RPCMonitorDigi(){}
00045
00046
00047 void RPCMonitorDigi::beginJob(){
00048 edm::LogInfo (nameInLog) <<"[RPCMonitorDigi]: Begin job" ;
00049
00051 dbe = edm::Service<DQMStore>().operator->();
00052
00053 dbe->setCurrentFolder(globalFolder_);
00054
00055 ClusterSize_for_Barrel = dbe->book1D("ClusterSize_for_Barrel", "ClusterSize for Barrel", 20, 0.5, 20.5);
00056 ClusterSize_for_EndcapPositive = dbe->book1D("ClusterSize_for_EndcapPositive", "ClusterSize for PositiveEndcap", 20, 0.5, 20.5);
00057 ClusterSize_for_EndcapNegative = dbe->book1D("ClusterSize_for_EndcapNegative", "ClusterSize for NegativeEndcap", 20, 0.5, 20.5);
00058
00059 ClusterSize_for_BarrelandEndcaps = dbe->book1D("ClusterSize_for_BarrelandEndcap", "ClusterSize for Barrel&Endcaps", 20, 0.5, 20.5);
00060
00061 NumberOfClusters_for_Barrel = dbe -> book1D("NumberOfClusters_for_Barrel", "NumberOfClusters for Barrel", 20, 0.5, 20.5);
00062 NumberOfClusters_for_EndcapPositive = dbe -> book1D("NumberOfClusters_for_EndcapPositive", "NumberOfClusters for Endcap Positive", 20, 0.5, 20.5);
00063 NumberOfClusters_for_EndcapNegative = dbe -> book1D("NumberOfClusters_for_EndcapNegative", "NumberOfClusters for Endcap Negative", 20, 0.5, 20.5);
00064
00065 NumberOfDigis_for_Barrel = dbe -> book1D("NumberOfDigi_for_Barrel", "Number Of Digis in Barrel", 50, 0.5, 50.5);
00066 NumberOfDigis_for_EndcapPositive = dbe -> book1D("NumberOfDigi_for_EndcapPositive", "Number Of Digis in EndCapPositive", 50, 0.5, 50.5);
00067 NumberOfDigis_for_EndcapNegative= dbe -> book1D("NumberOfDigi_for_EndcapNegative", "Number Of Digis in EndCapNegative", 50, 0.5, 50.5);
00068
00069 SameBxDigisMeBarrel_ = dbe->book1D("SameBXDigis_Barrel", "Digis with same bx", 20, 0.5, 20.5);
00070 SameBxDigisMeEndcapPositive_ = dbe->book1D("SameBXDigis_EndcapPositive", "Digis with same bx", 20, 0.5, 20.5);
00071 SameBxDigisMeEndcapNegative_ = dbe->book1D("SameBXDigis_EndcapNegative", "Digis with same bx", 20, 0.5, 20.5);
00072
00073 BarrelOccupancy = dbe -> book2D("Occupancy_for_Barrel", "Barrel Occupancy Wheel vs Sector", 12, 0.5, 12.5, 5, -2.5, 2.5);
00074 EndcapPositiveOccupancy = dbe -> book2D("Occupancy_for_EndcapPositive", "Endcap Positive Occupancy Disk vs Sector", 6, 0.5, 6.5, 4, 0.5, 4.5);
00075 EndcapNegativeOccupancy = dbe -> book2D("Occupancy_for_EndcapNegative", "Endcap Negative Occupancy Disk vs Sector", 6, 0.5, 6.5, 4, 0.5, 4.5);
00076
00077 dbe->setCurrentFolder(globalFolder_);
00078 RPCEvents = dbe -> book1D("RPCEvents", "RPC Events Barrel+EndCap", 1, 0.5, 1.5);
00079
00080 std::stringstream binLabel;
00081 for (int i = 1; i<13; i++){
00082 binLabel.str("");
00083 binLabel<<"Sec"<<i;
00084 BarrelOccupancy -> setBinLabel(i, binLabel.str(), 1);
00085 if(i<6){
00086 binLabel.str("");
00087 binLabel<<"Wheel"<<i-3;
00088 BarrelOccupancy -> setBinLabel(i, binLabel.str(), 2);
00089 }
00090 if(i<7) {
00091 binLabel.str("");
00092 binLabel<<"Sec"<<i;
00093 EndcapPositiveOccupancy -> setBinLabel(i, binLabel.str(), 1);
00094 EndcapNegativeOccupancy -> setBinLabel(i, binLabel.str(), 1);
00095 }
00096 if(i<5){
00097 binLabel.str("");
00098 binLabel<<"Disk+"<<i ; ;
00099 EndcapPositiveOccupancy -> setBinLabel(i, binLabel.str(), 2);
00100 binLabel.str("");
00101 binLabel<<"Disk-"<<i ;
00102 EndcapNegativeOccupancy -> setBinLabel(i, binLabel.str(), 2);
00103 }
00104 }
00105 dcs_ = true;
00106
00107 }
00108
00109 void RPCMonitorDigi::beginRun(const edm::Run& r, const edm::EventSetup& iSetup){
00110
00111 edm::LogInfo (nameInLog) <<"Begin Run " ;
00112
00113 iSetup.get<MuonGeometryRecord>().get(rpcGeo);
00114
00115
00116 for (TrackingGeometry::DetContainer::const_iterator it=rpcGeo->dets().begin();it<rpcGeo->dets().end();it++){
00117 if(dynamic_cast< RPCChamber* >( *it ) != 0 ){
00118 RPCChamber* ch = dynamic_cast< RPCChamber* >( *it );
00119 std::vector< const RPCRoll*> roles = (ch->rolls());
00120 for(std::vector<const RPCRoll*>::const_iterator r = roles.begin();r != roles.end(); ++r){
00121 RPCDetId rpcId = (*r)->id();
00122 int region=rpcId.region();
00123
00124
00125 RPCGeomServ rpcsrv(rpcId);
00126 std::string nameRoll = rpcsrv.name();
00127
00128 meCollection[(uint32_t)rpcId]=bookDetUnitME(rpcId,iSetup );
00129
00130 int ring;
00131 if(rpcId.region() == 0)
00132 ring = rpcId.ring();
00133 else
00134 ring = rpcId.region()*rpcId.station();
00135
00136
00137 std::pair<int,int> regionRing(region,ring);
00138 std::map<std::pair<int,int>, std::map<std::string,MonitorElement*> >::iterator meRingItr = meWheelDisk.find(regionRing);
00139 if (meRingItr == meWheelDisk.end() || (meWheelDisk.size()==0)) meWheelDisk[regionRing]=bookRegionRing(region,ring);
00140 }
00141 }
00142 }
00143 }
00144
00145 void RPCMonitorDigi::endJob(void){
00146 if(saveRootFile) dbe->save(RootFileName);
00147 dbe = 0;
00148 }
00149
00150
00151
00152 void RPCMonitorDigi::analyze(const edm::Event& iEvent,const edm::EventSetup& iSetup ){
00153
00154 this->makeDcsInfo(iEvent);
00155 if( !dcs_) return;
00156
00157 counter++;
00158
00159 edm::LogInfo (nameInLog) <<"[RPCMonitorDigi]: Beginning analyzing event " << counter;
00160
00162 edm::Handle<RPCDigiCollection> rpcdigis;
00163 iEvent.getByLabel(RPCDigiLabel_, rpcdigis);
00164
00165
00166 edm::Handle<RPCRecHitCollection> rpcHits;
00167 iEvent.getByLabel(RPCRecHitLabel_,rpcHits);
00168
00169 std::map<int,int> bxMap;
00170
00171 if(rpcdigis->begin()!=rpcdigis->end()) RPCEvents -> Fill(1);
00172
00173
00174 for( RPCDigiCollection::DigiRangeIterator collectionItr=rpcdigis->begin(); collectionItr!=rpcdigis->end(); ++collectionItr){
00175
00176 RPCDetId detId=(*collectionItr).first;
00177 uint32_t id=detId();
00178
00179 const GeomDet* gdet=rpcGeo->idToDet(detId);
00180 const BoundPlane & surface = gdet->surface();
00181
00182
00183 RPCGeomServ RPCname(detId);
00184 std::string nameRoll = RPCname.name();
00185
00186 std::stringstream os;
00187
00188
00189 rpcdqm::utils prova;
00190 int nr = prova.detId2RollNr(detId);
00191
00192
00193 std::map<std::string, MonitorElement*> meMap=meCollection[id];
00194 if(meMap.size()==0) continue;
00195
00196 int region=detId.region();
00197 int ring;
00198 std::string ringType;
00199 if(region == 0) {
00200 ringType = "Wheel";
00201 ring = detId.ring();
00202 }else{
00203 ringType = "Disk";
00204 ring = region*detId.station();
00205 }
00206
00207
00208 std::pair<int,int> regionRing(region,ring);
00209 std::map<std::string, MonitorElement*> meRingMap=meWheelDisk[regionRing];
00210 if(meRingMap.size()==0) continue;
00211
00212 std::vector<std::pair <int,int> > duplicatedDigi;
00213 std::vector<int> bxs;
00214
00215
00216 typedef std::pair<RPCRecHitCollection::const_iterator, RPCRecHitCollection::const_iterator> rangeRecHits;
00217 rangeRecHits recHitCollection = rpcHits->get(detId);
00218
00219 int numberOfDigi= 0;
00220
00221 RPCDigiCollection::const_iterator digiItr;
00222
00223 for (digiItr =(*collectionItr ).second.first;digiItr != (*collectionItr ).second.second; ++digiItr){
00224 int strip= (*digiItr).strip();
00225 int bx=(*digiItr).bx();
00226
00227
00228 std::vector<std::pair <int,int> >::const_iterator itrDuplDigi = find(duplicatedDigi.begin(),duplicatedDigi.end(),std::make_pair(strip, bx));
00229 if(itrDuplDigi!=duplicatedDigi.end() && duplicatedDigi.size()!=0) continue;
00230
00231 duplicatedDigi.push_back(std::make_pair(strip, bx));
00232 ++numberOfDigi;
00233
00234
00235 std::vector<int>::const_iterator existingBX = find(bxs.begin(),bxs.end(),bx);
00236 if(existingBX==bxs.end())bxs.push_back(bx);
00237
00238
00239 std::map<int,int>::const_iterator bxItr = bxMap.find((*digiItr).bx());
00240 if (bxItr == bxMap.end()|| bxMap.size()==0 )bxMap[(*digiItr).bx()]=1;
00241 else bxMap[(*digiItr).bx()]++;
00242
00243
00244 os.str("");
00245 os<<"1DOccupancy_"<<ringType<<"_"<<ring;
00246 std::string meId = os.str();
00247 if( meRingMap[meId]){
00248 meRingMap[meId]->Fill(detId.sector());
00249
00250 }
00251
00252 os.str("");
00253 os<<"BxDistribution_"<<ringType<<"_"<<ring<<"_Sector_"<<detId.sector();
00254 if(meMap[os.str()])
00255 meMap[os.str()]->Fill(bx);
00256
00257 os.str("");
00258 os<<"BxDistribution_"<<ringType<<"_"<<ring;
00259 if(meRingMap[os.str()])
00260 meRingMap[os.str()]->Fill(bx);
00261
00262 if(detId.region()==0)
00263 BarrelOccupancy -> Fill(detId.sector(), ring);
00264 else if(detId.region()==1)
00265 EndcapPositiveOccupancy -> Fill(detId.sector(), ring);
00266 else if(detId.region()==-1)
00267 EndcapNegativeOccupancy -> Fill(detId.sector(),( -1 * ring) );
00268
00269 os.str("");
00270 os<<"Occupancy_"<<ringType<<"_"<<ring<<"_Sector_"<<detId.sector();
00271 if(meMap[os.str()]){
00272 if(detId.region() ==0) meMap[os.str()]->Fill(strip, nr);
00273 else meMap[os.str()]->Fill(strip + 32*(detId.roll()-1), RPCname.segment()+ ((detId.ring() -2)*6));
00274 }
00275
00276 os.str("");
00277 os<<"Occupancy_"<<nameRoll;
00278 if(meMap[os.str()]) meMap[os.str()]->Fill(strip);
00279
00280 os.str("");
00281 os<<"Occupancy_Roll_vs_Sector_"<<ringType<<"_"<<ring;
00282 if (meRingMap[os.str()]) {
00283 meRingMap[os.str()]->Fill(detId.sector(), nr, 1);
00284 }
00285
00286 os.str("");
00287 os<<"Occupancy_Ring_vs_Segment_"<<ringType<<"_"<<ring;
00288 if (meRingMap[os.str()]) {
00289 meRingMap[os.str()]->Fill( RPCname.segment(), (detId.ring()-1)*3-detId.roll()+1, 1);
00290 }
00291
00292 if(dqmexpert){
00293 os.str("");
00294 os<<"BXN_"<<nameRoll;
00295 if(meMap[os.str()]) meMap[os.str()]->Fill(bx);
00296 }
00297
00298 if (dqmsuperexpert) {
00299 os.str("");
00300 os<<"BXN_vs_strip_"<<nameRoll;
00301 if(meMap[os.str()]) meMap[os.str()]->Fill(strip,bx);
00302 }
00303 }
00304
00305 if (dqmexpert){
00306 os.str("");
00307 os<<"BXWithData_"<<nameRoll;
00308 if(meMap[os.str()]) meMap[os.str()]->Fill(bxs.size());
00309 }
00310
00311 os.str("");
00312 os<<"BXWithData_"<<ringType<<"_"<<ring<<"_Sector_"<<detId.sector();
00313 if(meMap[os.str()])
00314 meMap[os.str()]->Fill(bxs.size());
00315
00316 if(numberOfDigi>50) numberOfDigi=50;
00317
00318 os.str("");
00319 os<<"Multiplicity_"<<nameRoll;
00320 if(meMap[os.str()]) meMap[os.str()]->Fill(numberOfDigi);
00321
00322 if(detId.region()==0) NumberOfDigis_for_Barrel -> Fill(numberOfDigi);
00323 else if(detId.region()==1) NumberOfDigis_for_EndcapPositive -> Fill(numberOfDigi);
00324 else if(detId.region()==-1) NumberOfDigis_for_EndcapNegative -> Fill(numberOfDigi);
00325
00326
00327 if(recHitCollection.first!=recHitCollection.second ){
00328
00329 RPCRecHitCollection::const_iterator it;
00330 int numberOfHits=0;
00331 int numbOfClusters=0;
00332
00333 for (it = recHitCollection.first; it != recHitCollection.second ; it++) {
00334 numbOfClusters++;
00335 RPCDetId detIdRecHits=it->rpcId();
00336 LocalError error=it->localPositionError();
00337 LocalPoint point=it->localPosition();
00338 GlobalPoint globalHitPoint=surface.toGlobal(point);
00339
00340 int mult=it->clusterSize();
00341 int firstStrip=it->firstClusterStrip();
00342
00343 ClusterSize_for_BarrelandEndcaps -> Fill(mult);
00344
00345 if(detId.region() == 0) {
00346 ClusterSize_for_Barrel -> Fill(mult);
00347 } else if (detId.region() == -1) {
00348 if(mult<=10) ClusterSize_for_EndcapNegative -> Fill(mult);
00349 else ClusterSize_for_EndcapNegative -> Fill(11);
00350 } else if (detId.region() == 1) {
00351 if(mult<=10) ClusterSize_for_EndcapPositive -> Fill(mult);
00352 else ClusterSize_for_EndcapPositive -> Fill(11);
00353 }
00354
00355
00356 os.str("");
00357 os<<"ClusterSize_"<<ringType<<"_"<<ring;
00358 if(meRingMap[os.str()])
00359 meRingMap[os.str()] -> Fill(mult);
00360
00361 if (dqmsuperexpert) {
00362 int centralStrip=firstStrip;
00363 if(mult%2) {
00364 centralStrip+= mult/2;
00365 }else{
00366 float x = gRandom->Uniform(2);
00367 centralStrip+=(x<1)? (mult/2)-1 : (mult/2);
00368 }
00369
00370 os.str("");
00371 os<<"ClusterSize_vs_Strip_"<<nameRoll;
00372 if(meMap[os.str()])
00373 for(int index=0; index<mult; ++index)
00374 meMap[os.str()]->Fill(firstStrip+index,mult);
00375 }
00376
00377 if(dqmexpert) {
00378 os.str("");
00379 os<<"ClusterSize_"<<nameRoll;
00380 if(meMap[os.str()])
00381 meMap[os.str()]->Fill(mult);
00382 }
00383 numberOfHits++;
00384 }
00385
00386 if(dqmexpert) {
00387 if(numberOfHits>20) numberOfHits=20;
00388 os.str("");
00389 os<<"NumberOfClusters_"<<nameRoll;
00390 if(meMap[os.str()])
00391 meMap[os.str()]->Fill(numbOfClusters);
00392
00393
00394 os.str("");
00395 os<<"RecHitCounter_"<<nameRoll;
00396 if(meMap[os.str()])
00397 meMap[os.str()]->Fill(numberOfHits);
00398 }
00399
00400 if(detId.region()==0)
00401 NumberOfClusters_for_Barrel -> Fill(numbOfClusters);
00402 else if (detId.region()==1)
00403 NumberOfClusters_for_EndcapPositive -> Fill(numbOfClusters);
00404 else if(detId.region()==-1)
00405 NumberOfClusters_for_EndcapNegative -> Fill(numbOfClusters);
00406
00407 }
00408 }
00409
00410
00411 for (std::map<int, int>::const_iterator myItr= bxMap.begin();
00412 myItr!=bxMap.end(); myItr++){
00413 SameBxDigisMeBarrel_ ->Fill((*myItr).second);
00414 }
00415 }
00416
00417
00418 void RPCMonitorDigi::makeDcsInfo(const edm::Event& e) {
00419
00420 edm::Handle<DcsStatusCollection> dcsStatus;
00421
00422 if ( ! e.getByLabel("scalersRawToDigi", dcsStatus) ){
00423 dcs_ = true;
00424 return;
00425 }
00426
00427 if ( ! dcsStatus.isValid() )
00428 {
00429 edm::LogWarning("RPCDcsInfo") << "scalersRawToDigi not found" ;
00430 dcs_ = true;
00431 return;
00432 }
00433
00434
00435 for (DcsStatusCollection::const_iterator dcsStatusItr = dcsStatus->begin();
00436 dcsStatusItr != dcsStatus->end(); ++dcsStatusItr) {
00437
00438 if (!dcsStatusItr->ready(DcsStatus::RPC)) dcs_=false;
00439
00440 }
00441
00442 return ;
00443 }