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
00135 nErrors = nErrors + numberOfModuleErrors;
00136
00137 }
00138 for (struct_iter2 = theFEDStructure.begin() ; struct_iter2 != theFEDStructure.end() ; struct_iter2++) {
00139
00140 int numberOfFEDErrors = (*struct_iter2).second->fillFED(*input);
00141 if((*struct_iter2).first <= 31) nEventBPIXFEDErrors = nEventBPIXFEDErrors + numberOfFEDErrors;
00142 if((*struct_iter2).first >= 32 && (*struct_iter2).first <= 39) nEventFPIXFEDErrors = nEventFPIXFEDErrors + numberOfFEDErrors;
00143
00144 nErrors = nErrors + numberOfFEDErrors;
00145
00146 }
00147 MonitorElement* me = theDMBE->get("Pixel/AdditionalPixelErrors/byLumiErrors");
00148 if(me){
00149 me->setBinContent(0,eventNo);
00150
00151
00152
00153 if(nEventBPIXModuleErrors+nEventBPIXFEDErrors>0) me->Fill(0,1.);
00154 if(nEventFPIXModuleErrors+nEventFPIXFEDErrors>0) me->Fill(1,1.);
00155
00156 }
00157
00158
00159 MonitorElement* me1 = theDMBE->get("Pixel/AdditionalPixelErrors/errorRate");
00160 if(me1) me1->Fill(lumiSection, nErrors);
00161
00162
00163 if(slowDown) usleep(100000);
00164
00165 }
00166
00167
00168
00169
00170 void SiPixelRawDataErrorSource::buildStructure(const edm::EventSetup& iSetup){
00171
00172 LogInfo ("PixelDQM") <<" SiPixelRawDataErrorSource::buildStructure" ;
00173 edm::ESHandle<TrackerGeometry> pDD;
00174 iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
00175
00176 LogVerbatim ("PixelDQM") << " *** Geometry node for TrackerGeom is "<<&(*pDD)<<std::endl;
00177 LogVerbatim ("PixelDQM") << " *** I have " << pDD->dets().size() <<" detectors"<<std::endl;
00178 LogVerbatim ("PixelDQM") << " *** I have " << pDD->detTypes().size() <<" types"<<std::endl;
00179
00180 for(TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++){
00181
00182 if( ((*it)->subDetector()==GeomDetEnumerators::PixelBarrel) || ((*it)->subDetector()==GeomDetEnumerators::PixelEndcap) ){
00183 DetId detId = (*it)->geographicalId();
00184 const GeomDetUnit * geoUnit = pDD->idToDetUnit( detId );
00185 const PixelGeomDetUnit * pixDet = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
00186 int nrows = (pixDet->specificTopology()).nrows();
00187 int ncols = (pixDet->specificTopology()).ncolumns();
00188
00189 if(detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
00190 if(isPIB) continue;
00191 LogDebug ("PixelDQM") << " ---> Adding Barrel Module " << detId.rawId() << endl;
00192 uint32_t id = detId();
00193 SiPixelRawDataErrorModule* theModule = new SiPixelRawDataErrorModule(id, ncols, nrows);
00194 thePixelStructure.insert(pair<uint32_t,SiPixelRawDataErrorModule*> (id,theModule));
00195
00196 } else if(detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) {
00197 LogDebug ("PixelDQM") << " ---> Adding Endcap Module " << detId.rawId() << endl;
00198 uint32_t id = detId();
00199 SiPixelRawDataErrorModule* theModule = new SiPixelRawDataErrorModule(id, ncols, nrows);
00200
00201 PixelEndcapName::HalfCylinder side = PixelEndcapName(DetId(id)).halfCylinder();
00202 int disk = PixelEndcapName(DetId(id)).diskName();
00203 int blade = PixelEndcapName(DetId(id)).bladeName();
00204 int panel = PixelEndcapName(DetId(id)).pannelName();
00205 int module = PixelEndcapName(DetId(id)).plaquetteName();
00206
00207 char sside[80]; sprintf(sside, "HalfCylinder_%i",side);
00208 char sdisk[80]; sprintf(sdisk, "Disk_%i",disk);
00209 char sblade[80]; sprintf(sblade, "Blade_%02i",blade);
00210 char spanel[80]; sprintf(spanel, "Panel_%i",panel);
00211 char smodule[80];sprintf(smodule,"Module_%i",module);
00212 std::string side_str = sside;
00213 std::string disk_str = sdisk;
00214 bool mask = side_str.find("HalfCylinder_1")!=string::npos||
00215 side_str.find("HalfCylinder_2")!=string::npos||
00216 side_str.find("HalfCylinder_4")!=string::npos||
00217 disk_str.find("Disk_2")!=string::npos;
00218
00219 mask = false;
00220 if(isPIB && mask) continue;
00221
00222 thePixelStructure.insert(pair<uint32_t,SiPixelRawDataErrorModule*> (id,theModule));
00223 }
00224 }
00225 }
00226 LogDebug ("PixelDQM") << " ---> Adding Module for Additional Errors " << endl;
00227 pair<int,int> fedIds (FEDNumbering::MINSiPixelFEDID, FEDNumbering::MAXSiPixelFEDID);
00228 fedIds.first = 0;
00229 fedIds.second = 39;
00230 for (int fedId = fedIds.first; fedId <= fedIds.second; fedId++) {
00231
00232 uint32_t id = static_cast<uint32_t> (fedId);
00233 SiPixelRawDataErrorModule* theModule = new SiPixelRawDataErrorModule(id);
00234 theFEDStructure.insert(pair<uint32_t,SiPixelRawDataErrorModule*> (id,theModule));
00235 }
00236
00237 LogInfo ("PixelDQM") << " *** Pixel Structure Size " << thePixelStructure.size() << endl;
00238 }
00239
00240
00241
00242 void SiPixelRawDataErrorSource::bookMEs(){
00243
00244
00245 DQMStore* theDMBE = edm::Service<DQMStore>().operator->();
00246 theDMBE->setCurrentFolder("Pixel/AdditionalPixelErrors");
00247 char title[80]; sprintf(title, "By-LumiSection Error counters");
00248 byLumiErrors = theDMBE->book1D("byLumiErrors",title,2,0.,2.);
00249 byLumiErrors->setLumiFlag();
00250 char title1[80]; sprintf(title1, "Errors per LumiSection;LumiSection;NErrors");
00251 errorRate = theDMBE->book1D("errorRate",title1,5000,0.,5000.);
00252
00253 std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter;
00254 std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter2;
00255
00256 SiPixelFolderOrganizer theSiPixelFolder;
00257
00258 for(struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++){
00260
00261 if(modOn){
00262 if(theSiPixelFolder.setModuleFolder((*struct_iter).first)) {
00263 (*struct_iter).second->book( conf_, 0 );
00264 }
00265 else {
00266
00267 if(!isPIB) throw cms::Exception("LogicError")
00268 << "[SiPixelRawDataErrorSource::bookMEs] Creation of DQM folder failed";
00269 }
00270 }
00271
00272 if(ladOn){
00273 if(theSiPixelFolder.setModuleFolder((*struct_iter).first,1)) {
00274 (*struct_iter).second->book( conf_, 1 );
00275 }
00276 else {
00277 LogDebug ("PixelDQM") << "PROBLEM WITH LADDER-FOLDER\n";
00278 }
00279 }
00280
00281 if(bladeOn){
00282 if(theSiPixelFolder.setModuleFolder((*struct_iter).first,4)) {
00283 (*struct_iter).second->book( conf_, 4 );
00284 }
00285 else {
00286 LogDebug ("PixelDQM") << "PROBLEM WITH BLADE-FOLDER\n";
00287 }
00288 }
00289
00290 }
00291
00292 for(struct_iter2 = theFEDStructure.begin(); struct_iter2 != theFEDStructure.end(); struct_iter2++){
00294 if(theSiPixelFolder.setFedFolder((*struct_iter2).first)) {
00295 (*struct_iter2).second->bookFED( conf_ );
00296 }
00297 else {
00298 throw cms::Exception("LogicError")
00299 << "[SiPixelRawDataErrorSource::bookMEs] Creation of DQM folder failed";
00300 }
00301
00302 }
00303
00304
00305 }