00001
00002
00003
00004
00005
00021
00022
00023
00024 #include "DQM/SiPixelMonitorRawData/interface/SiPixelRawDataErrorSource.h"
00025
00026 #include "FWCore/ServiceRegistry/interface/Service.h"
00027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00028
00029 #include "DQM/SiPixelCommon/interface/SiPixelFolderOrganizer.h"
00030 #include "DQMServices/Core/interface/DQMStore.h"
00031
00032 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00033 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00034 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00035 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
00036
00037 #include "DataFormats/DetId/interface/DetId.h"
00038 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00039 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00040 #include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h"
00041 #include "DataFormats/SiPixelDetId/interface/PixelEndcapName.h"
00042
00043 #include <string>
00044 #include <stdlib.h>
00045
00046 using namespace std;
00047 using namespace edm;
00048
00049 SiPixelRawDataErrorSource::SiPixelRawDataErrorSource(const edm::ParameterSet& iConfig) :
00050 conf_(iConfig),
00051 src_( conf_.getParameter<edm::InputTag>( "src" ) ),
00052 saveFile( conf_.getUntrackedParameter<bool>("saveFile",false) ),
00053 isPIB( conf_.getUntrackedParameter<bool>("isPIB",false) ),
00054 slowDown( conf_.getUntrackedParameter<bool>("slowDown",false) ),
00055 reducedSet( conf_.getUntrackedParameter<bool>("reducedSet",false) ),
00056 modOn( conf_.getUntrackedParameter<bool>("modOn",true) ),
00057 ladOn( conf_.getUntrackedParameter<bool>("ladOn",false) ),
00058 bladeOn( conf_.getUntrackedParameter<bool>("bladeOn",false) )
00059 {
00060 theDMBE = edm::Service<DQMStore>().operator->();
00061 LogInfo ("PixelDQM") << "SiPixelRawDataErrorSource::SiPixelRawDataErrorSource: Got DQM BackEnd interface"<<endl;
00062 }
00063
00064
00065 SiPixelRawDataErrorSource::~SiPixelRawDataErrorSource()
00066 {
00067
00068
00069 LogInfo ("PixelDQM") << "SiPixelRawDataErrorSource::~SiPixelRawDataErrorSource: Destructor"<<endl;
00070 }
00071
00072
00073 void SiPixelRawDataErrorSource::beginJob(){
00074 firstRun = true;
00075 }
00076
00077 void SiPixelRawDataErrorSource::beginRun(const edm::Run& r, const edm::EventSetup& iSetup){
00078
00079 LogInfo ("PixelDQM") << " SiPixelRawDataErrorSource::beginRun - Initialisation ... " << std::endl;
00080 LogInfo ("PixelDQM") << "Mod/Lad/Blade " << modOn << "/" << ladOn << "/" << bladeOn << std::endl;
00081
00082 if(firstRun){
00083 eventNo = 0;
00084
00085 buildStructure(iSetup);
00086
00087 bookMEs();
00088
00089 firstRun = false;
00090 }
00091 }
00092
00093
00094 void SiPixelRawDataErrorSource::endJob(void){
00095
00096 if(saveFile) {
00097 LogInfo ("PixelDQM") << " SiPixelRawDataErrorSource::endJob - Saving Root File " << std::endl;
00098 std::string outputFile = conf_.getParameter<std::string>("outputFile");
00099 theDMBE->save( outputFile.c_str() );
00100 }
00101
00102 }
00103
00104
00105
00106
00107 void SiPixelRawDataErrorSource::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00108 {
00109 eventNo++;
00110
00111
00112 edm::Handle< edm::DetSetVector<SiPixelRawDataError> > input;
00113 iEvent.getByLabel( src_, input );
00114 if (!input.isValid()) return;
00115
00116
00117 DQMStore* theDMBE = edm::Service<DQMStore>().operator->();
00118
00119
00120
00121
00122 int lumiSection = (int)iEvent.luminosityBlock();
00123
00124 int nEventBPIXModuleErrors = 0; int nEventFPIXModuleErrors = 0; int nEventBPIXFEDErrors = 0; int nEventFPIXFEDErrors = 0;
00125 int nErrors = 0;
00126
00127 std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter;
00128 std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter2;
00129 for (struct_iter = thePixelStructure.begin() ; struct_iter != thePixelStructure.end() ; struct_iter++) {
00130
00131 int numberOfModuleErrors = (*struct_iter).second->fill(*input, modOn, ladOn, bladeOn);
00132 if(DetId( (*struct_iter).first ).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) nEventBPIXModuleErrors = nEventBPIXModuleErrors + numberOfModuleErrors;
00133 if(DetId( (*struct_iter).first ).subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) nEventFPIXModuleErrors = nEventFPIXModuleErrors + numberOfModuleErrors;
00134 nErrors = nErrors + numberOfModuleErrors;
00135 }
00136 for (struct_iter2 = theFEDStructure.begin() ; struct_iter2 != theFEDStructure.end() ; struct_iter2++) {
00137
00138 int numberOfFEDErrors = (*struct_iter2).second->fillFED(*input);
00139 if((*struct_iter2).first <= 31) nEventBPIXFEDErrors = nEventBPIXFEDErrors + numberOfFEDErrors;
00140 if((*struct_iter2).first >= 32 && (*struct_iter2).first <= 39) nEventFPIXFEDErrors = nEventFPIXFEDErrors + numberOfFEDErrors;
00141 nErrors = nErrors + numberOfFEDErrors;
00142 }
00143 MonitorElement* me = theDMBE->get("Pixel/AdditionalPixelErrors/byLumiErrors");
00144 if(me){
00145 me->setBinContent(0,eventNo);
00146 if(nEventBPIXModuleErrors+nEventBPIXFEDErrors>0) me->setBinContent(1,nEventBPIXModuleErrors+nEventBPIXFEDErrors);
00147 if(nEventFPIXModuleErrors+nEventFPIXFEDErrors>0) me->setBinContent(2,nEventFPIXModuleErrors+nEventFPIXFEDErrors);
00148 }
00149
00150
00151 MonitorElement* me1 = theDMBE->get("Pixel/AdditionalPixelErrors/errorRate");
00152 if(me1){
00153 int nLumiErrors = int(me1->getBinContent(lumiSection+1)) + nErrors;
00154 me1->Fill(lumiSection, nLumiErrors);
00155 }
00156
00157
00158
00159
00160 if(slowDown) usleep(100000);
00161
00162 }
00163
00164
00165
00166
00167 void SiPixelRawDataErrorSource::buildStructure(const edm::EventSetup& iSetup){
00168
00169 LogInfo ("PixelDQM") <<" SiPixelRawDataErrorSource::buildStructure" ;
00170 edm::ESHandle<TrackerGeometry> pDD;
00171 iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
00172
00173 LogVerbatim ("PixelDQM") << " *** Geometry node for TrackerGeom is "<<&(*pDD)<<std::endl;
00174 LogVerbatim ("PixelDQM") << " *** I have " << pDD->dets().size() <<" detectors"<<std::endl;
00175 LogVerbatim ("PixelDQM") << " *** I have " << pDD->detTypes().size() <<" types"<<std::endl;
00176
00177 for(TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++){
00178
00179 if( ((*it)->subDetector()==GeomDetEnumerators::PixelBarrel) || ((*it)->subDetector()==GeomDetEnumerators::PixelEndcap) ){
00180 DetId detId = (*it)->geographicalId();
00181 const GeomDetUnit * geoUnit = pDD->idToDetUnit( detId );
00182 const PixelGeomDetUnit * pixDet = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
00183 int nrows = (pixDet->specificTopology()).nrows();
00184 int ncols = (pixDet->specificTopology()).ncolumns();
00185
00186 if(detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
00187 if(isPIB) continue;
00188 LogDebug ("PixelDQM") << " ---> Adding Barrel Module " << detId.rawId() << endl;
00189 uint32_t id = detId();
00190 SiPixelRawDataErrorModule* theModule = new SiPixelRawDataErrorModule(id, ncols, nrows);
00191 thePixelStructure.insert(pair<uint32_t,SiPixelRawDataErrorModule*> (id,theModule));
00192
00193 } else if(detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) {
00194 LogDebug ("PixelDQM") << " ---> Adding Endcap Module " << detId.rawId() << endl;
00195 uint32_t id = detId();
00196 SiPixelRawDataErrorModule* theModule = new SiPixelRawDataErrorModule(id, ncols, nrows);
00197
00198 PixelEndcapName::HalfCylinder side = PixelEndcapName(DetId(id)).halfCylinder();
00199 int disk = PixelEndcapName(DetId(id)).diskName();
00200 int blade = PixelEndcapName(DetId(id)).bladeName();
00201 int panel = PixelEndcapName(DetId(id)).pannelName();
00202 int module = PixelEndcapName(DetId(id)).plaquetteName();
00203
00204 char sside[80]; sprintf(sside, "HalfCylinder_%i",side);
00205 char sdisk[80]; sprintf(sdisk, "Disk_%i",disk);
00206 char sblade[80]; sprintf(sblade, "Blade_%02i",blade);
00207 char spanel[80]; sprintf(spanel, "Panel_%i",panel);
00208 char smodule[80];sprintf(smodule,"Module_%i",module);
00209 std::string side_str = sside;
00210 std::string disk_str = sdisk;
00211 bool mask = side_str.find("HalfCylinder_1")!=string::npos||
00212 side_str.find("HalfCylinder_2")!=string::npos||
00213 side_str.find("HalfCylinder_4")!=string::npos||
00214 disk_str.find("Disk_2")!=string::npos;
00215
00216 mask = false;
00217 if(isPIB && mask) continue;
00218
00219 thePixelStructure.insert(pair<uint32_t,SiPixelRawDataErrorModule*> (id,theModule));
00220 }
00221 }
00222 }
00223 LogDebug ("PixelDQM") << " ---> Adding Module for Additional Errors " << endl;
00224 pair<int,int> fedIds (FEDNumbering::MINSiPixelFEDID, FEDNumbering::MAXSiPixelFEDID);
00225 fedIds.first = 0;
00226 fedIds.second = 39;
00227 for (int fedId = fedIds.first; fedId <= fedIds.second; fedId++) {
00228
00229 uint32_t id = static_cast<uint32_t> (fedId);
00230 SiPixelRawDataErrorModule* theModule = new SiPixelRawDataErrorModule(id);
00231 theFEDStructure.insert(pair<uint32_t,SiPixelRawDataErrorModule*> (id,theModule));
00232 }
00233
00234 LogInfo ("PixelDQM") << " *** Pixel Structure Size " << thePixelStructure.size() << endl;
00235 }
00236
00237
00238
00239 void SiPixelRawDataErrorSource::bookMEs(){
00240
00241
00242 DQMStore* theDMBE = edm::Service<DQMStore>().operator->();
00243 theDMBE->setCurrentFolder("Pixel/AdditionalPixelErrors");
00244 char title[80]; sprintf(title, "By-LumiSection Error counters");
00245 byLumiErrors = theDMBE->book1D("byLumiErrors",title,2,0.,2.);
00246 byLumiErrors->setLumiFlag();
00247 char title1[80]; sprintf(title1, "Errors per LumiSection;LumiSection;NErrors");
00248 errorRate = theDMBE->book1D("errorRate",title1,5000,0.,5000.);
00249
00250 std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter;
00251 std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter2;
00252
00253 SiPixelFolderOrganizer theSiPixelFolder;
00254
00255 for(struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++){
00257
00258 if(modOn){
00259 if(theSiPixelFolder.setModuleFolder((*struct_iter).first)) {
00260 (*struct_iter).second->book( conf_, 0 );
00261 }
00262 else {
00263
00264 if(!isPIB) throw cms::Exception("LogicError")
00265 << "[SiPixelRawDataErrorSource::bookMEs] Creation of DQM folder failed";
00266 }
00267 }
00268
00269 if(ladOn){
00270 if(theSiPixelFolder.setModuleFolder((*struct_iter).first,1)) {
00271 (*struct_iter).second->book( conf_, 1 );
00272 }
00273 else {
00274 LogDebug ("PixelDQM") << "PROBLEM WITH LADDER-FOLDER\n";
00275 }
00276 }
00277
00278 if(bladeOn){
00279 if(theSiPixelFolder.setModuleFolder((*struct_iter).first,4)) {
00280 (*struct_iter).second->book( conf_, 4 );
00281 }
00282 else {
00283 LogDebug ("PixelDQM") << "PROBLEM WITH BLADE-FOLDER\n";
00284 }
00285 }
00286
00287 }
00288
00289 for(struct_iter2 = theFEDStructure.begin(); struct_iter2 != theFEDStructure.end(); struct_iter2++){
00291 if(theSiPixelFolder.setFedFolder((*struct_iter2).first)) {
00292 (*struct_iter2).second->bookFED( conf_ );
00293 }
00294 else {
00295 throw cms::Exception("LogicError")
00296 << "[SiPixelRawDataErrorSource::bookMEs] Creation of DQM folder failed";
00297 }
00298
00299 }
00300
00301 }