CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiPixelRawDataErrorSource.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiPixelMonitorRawData
4 // Class: SiPixelRawDataErrorSource
5 //
21 //
22 // Original Author: Andrew York
23 //
25 // Framework
28 // DQM Framework
32 
33 // Geometry
38 // DataFormats
46 //
47 #include <string>
48 #include <stdlib.h>
49 
50 using namespace std;
51 using namespace edm;
52 
54  conf_(iConfig),
55  src_( consumes<DetSetVector<SiPixelRawDataError> >( conf_.getParameter<edm::InputTag>( "src" ) ) ),
56  saveFile( conf_.getUntrackedParameter<bool>("saveFile",false) ),
57  isPIB( conf_.getUntrackedParameter<bool>("isPIB",false) ),
58  slowDown( conf_.getUntrackedParameter<bool>("slowDown",false) ),
59  reducedSet( conf_.getUntrackedParameter<bool>("reducedSet",false) ),
60  modOn( conf_.getUntrackedParameter<bool>("modOn",true) ),
61  ladOn( conf_.getUntrackedParameter<bool>("ladOn",false) ),
62  bladeOn( conf_.getUntrackedParameter<bool>("bladeOn",false) ),
63  isUpgrade( conf_.getUntrackedParameter<bool>("isUpgrade",false) )
64 {
65  firstRun = true;
66  LogInfo ("PixelDQM") << "SiPixelRawDataErrorSource::SiPixelRawDataErrorSource: Got DQM BackEnd interface"<<endl;
67 }
68 
69 
71 {
72  // do anything here that needs to be done at desctruction time
73  // (e.g. close files, deallocate resources etc.)
74  LogInfo ("PixelDQM") << "SiPixelRawDataErrorSource::~SiPixelRawDataErrorSource: Destructor"<<endl;
75 }
76 
78 
79  LogInfo ("PixelDQM") << " SiPixelRawDataErrorSource::beginRun - Initialisation ... " << std::endl;
80  LogInfo ("PixelDQM") << "Mod/Lad/Blade " << modOn << "/" << ladOn << "/" << bladeOn << std::endl;
81 
82  if(firstRun){
83  eventNo = 0;
84 
85  firstRun = false;
86  }
87 
88  // Build map
89  buildStructure(iSetup);
90 }
91 
93  // Book Monitoring Elements
94  bookMEs(iBooker);
95 }
96 
97 //------------------------------------------------------------------
98 // Method called for every event
99 //------------------------------------------------------------------
101 {
102  eventNo++;
103 
104  // get input data
106  iEvent.getByToken( src_, input );
107  if (!input.isValid()) return;
108 
109  int lumiSection = (int)iEvent.luminosityBlock();
110 
111  int nEventBPIXModuleErrors = 0; int nEventFPIXModuleErrors = 0; int nEventBPIXFEDErrors = 0; int nEventFPIXFEDErrors = 0;
112  int nErrors = 0;
113 
114  std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter;
115  std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter2;
116  for (struct_iter = thePixelStructure.begin() ; struct_iter != thePixelStructure.end() ; struct_iter++) {
117 
118  int numberOfModuleErrors = (*struct_iter).second->fill(*input, &meMapFEDs_, modOn, ladOn, bladeOn);
119  if(DetId( (*struct_iter).first ).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) nEventBPIXModuleErrors = nEventBPIXModuleErrors + numberOfModuleErrors;
120  if(DetId( (*struct_iter).first ).subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) nEventFPIXModuleErrors = nEventFPIXModuleErrors + numberOfModuleErrors;
121  //cout<<"NErrors: "<<nEventBPIXModuleErrors<<" "<<nEventFPIXModuleErrors<<endl;
122  nErrors = nErrors + numberOfModuleErrors;
123  //if(nErrors>0) cout<<"MODULES: nErrors: "<<nErrors<<endl;
124  }
125  for (struct_iter2 = theFEDStructure.begin() ; struct_iter2 != theFEDStructure.end() ; struct_iter2++) {
126 
127  int numberOfFEDErrors = (*struct_iter2).second->fillFED(*input, &meMapFEDs_);
128  if((*struct_iter2).first <= 31) nEventBPIXFEDErrors = nEventBPIXFEDErrors + numberOfFEDErrors; // (*struct_iter2).first >= 0, since (*struct_iter2).first is unsigned
129  if((*struct_iter2).first >= 32 && (*struct_iter2).first <= 39) nEventFPIXFEDErrors = nEventFPIXFEDErrors + numberOfFEDErrors;
130  //cout<<"NFEDErrors: "<<nEventBPIXFEDErrors<<" "<<nEventFPIXFEDErrors<<endl;
131  nErrors = nErrors + numberOfFEDErrors;
132  //if(nErrors>0) cout<<"FEDS: nErrors: "<<nErrors<<endl;
133  }
134  if(byLumiErrors){
136  //cout<<"NErrors: "<<nEventBPIXModuleErrors<<" "<<nEventFPIXModuleErrors<<" "<<nEventBPIXFEDErrors<<" "<<nEventFPIXFEDErrors<<endl;
137  if(nEventBPIXModuleErrors+nEventBPIXFEDErrors>0) byLumiErrors->Fill(0,1.);
138  if(nEventFPIXModuleErrors+nEventFPIXFEDErrors>0) byLumiErrors->Fill(1,1.);
139  //cout<<"histo: "<<byLumiErrors->getBinContent(0)<<" "<<byLumiErrors->getBinContent(1)<<" "<<byLumiErrors->getBinContent(2)<<endl;
140  }
141 
142  // Rate of errors per lumi section:
143  if(errorRate) errorRate->Fill(lumiSection, nErrors);
144 
145  // slow down...
146  if(slowDown) usleep(100000);
147 
148 }
149 
150 //------------------------------------------------------------------
151 // Build data structure
152 //------------------------------------------------------------------
154 
155  LogInfo ("PixelDQM") <<" SiPixelRawDataErrorSource::buildStructure" ;
157  iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
158 
159  LogVerbatim ("PixelDQM") << " *** Geometry node for TrackerGeom is "<<&(*pDD)<<std::endl;
160  LogVerbatim ("PixelDQM") << " *** I have " << pDD->dets().size() <<" detectors"<<std::endl;
161  LogVerbatim ("PixelDQM") << " *** I have " << pDD->detTypes().size() <<" types"<<std::endl;
162 
163  for(TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++){
164 
165  if( ((*it)->subDetector()==GeomDetEnumerators::PixelBarrel) || ((*it)->subDetector()==GeomDetEnumerators::PixelEndcap) ){
166  DetId detId = (*it)->geographicalId();
167  const GeomDetUnit * geoUnit = pDD->idToDetUnit( detId );
168  const PixelGeomDetUnit * pixDet = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
169  int nrows = (pixDet->specificTopology()).nrows();
170  int ncols = (pixDet->specificTopology()).ncolumns();
171 
172  if(detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
173  if(isPIB) continue;
174  LogDebug ("PixelDQM") << " ---> Adding Barrel Module " << detId.rawId() << endl;
175  uint32_t id = detId();
176  SiPixelRawDataErrorModule* theModule = new SiPixelRawDataErrorModule(id, ncols, nrows);
177  thePixelStructure.insert(pair<uint32_t,SiPixelRawDataErrorModule*> (id,theModule));
178 
179  } else if( (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) && (!isUpgrade)) {
180  LogDebug ("PixelDQM") << " ---> Adding Endcap Module " << detId.rawId() << endl;
181  uint32_t id = detId();
182  SiPixelRawDataErrorModule* theModule = new SiPixelRawDataErrorModule(id, ncols, nrows);
183 
185  int disk = PixelEndcapName(DetId(id)).diskName();
186  int blade = PixelEndcapName(DetId(id)).bladeName();
187  int panel = PixelEndcapName(DetId(id)).pannelName();
189 
190  char sside[80]; sprintf(sside, "HalfCylinder_%i",side);
191  char sdisk[80]; sprintf(sdisk, "Disk_%i",disk);
192  char sblade[80]; sprintf(sblade, "Blade_%02i",blade);
193  char spanel[80]; sprintf(spanel, "Panel_%i",panel);
194  char smodule[80];sprintf(smodule,"Module_%i",module);
195  std::string side_str = sside;
196  std::string disk_str = sdisk;
197  bool mask = side_str.find("HalfCylinder_1")!=string::npos||
198  side_str.find("HalfCylinder_2")!=string::npos||
199  side_str.find("HalfCylinder_4")!=string::npos||
200  disk_str.find("Disk_2")!=string::npos;
201  // clutch to take all of FPIX, but no BPIX:
202  mask = false;
203  if(isPIB && mask) continue;
204 
205  thePixelStructure.insert(pair<uint32_t,SiPixelRawDataErrorModule*> (id,theModule));
206  } else if( (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) && (isUpgrade)) {
207  LogDebug ("PixelDQM") << " ---> Adding Endcap Module " << detId.rawId() << endl;
208  uint32_t id = detId();
209  SiPixelRawDataErrorModule* theModule = new SiPixelRawDataErrorModule(id, ncols, nrows);
210 
212  int disk = PixelEndcapNameUpgrade(DetId(id)).diskName();
213  int blade = PixelEndcapNameUpgrade(DetId(id)).bladeName();
214  int panel = PixelEndcapNameUpgrade(DetId(id)).pannelName();
216 
217  char sside[80]; sprintf(sside, "HalfCylinder_%i",side);
218  char sdisk[80]; sprintf(sdisk, "Disk_%i",disk);
219  char sblade[80]; sprintf(sblade, "Blade_%02i",blade);
220  char spanel[80]; sprintf(spanel, "Panel_%i",panel);
221  char smodule[80];sprintf(smodule,"Module_%i",module);
222  std::string side_str = sside;
223  std::string disk_str = sdisk;
224  bool mask = side_str.find("HalfCylinder_1")!=string::npos||
225  side_str.find("HalfCylinder_2")!=string::npos||
226  side_str.find("HalfCylinder_4")!=string::npos||
227  disk_str.find("Disk_2")!=string::npos;
228  // clutch to take all of FPIX, but no BPIX:
229  mask = false;
230  if(isPIB && mask) continue;
231 
232  thePixelStructure.insert(pair<uint32_t,SiPixelRawDataErrorModule*> (id,theModule));
233  }//endif(isUpgrade)
234  }
235  }
236  LogDebug ("PixelDQM") << " ---> Adding Module for Additional Errors " << endl;
238  fedIds.first = 0;
239  fedIds.second = 39;
240  for (int fedId = fedIds.first; fedId <= fedIds.second; fedId++) {
241  //std::cout<<"Adding FED module: "<<fedId<<std::endl;
242  uint32_t id = static_cast<uint32_t> (fedId);
244  theFEDStructure.insert(pair<uint32_t,SiPixelRawDataErrorModule*> (id,theModule));
245  }
246 
247  LogInfo ("PixelDQM") << " *** Pixel Structure Size " << thePixelStructure.size() << endl;
248 }
249 //------------------------------------------------------------------
250 // Book MEs
251 //------------------------------------------------------------------
253  //cout<<"Entering SiPixelRawDataErrorSource::bookMEs now: "<<endl;
254  iBooker.setCurrentFolder("Pixel/AdditionalPixelErrors");
255  char title[80]; sprintf(title, "By-LumiSection Error counters");
256  byLumiErrors = iBooker.book1D("byLumiErrors",title,2,0.,2.);
258  char title1[80]; sprintf(title1, "Errors per LumiSection;LumiSection;NErrors");
259  errorRate = iBooker.book1D("errorRate",title1,5000,0.,5000.);
260 
261  std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter;
262  std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter2;
263 
264  SiPixelFolderOrganizer theSiPixelFolder;
265 
266  for(struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++){
268 
269  if(modOn){
270  if(!theSiPixelFolder.setModuleFolder((*struct_iter).first,0,isUpgrade)) {
271  //std::cout<<"PIB! not booking histograms for non-PIB modules!"<<std::endl;
272  if(!isPIB) throw cms::Exception("LogicError")
273  << "[SiPixelRawDataErrorSource::bookMEs] Creation of DQM folder failed";
274  }
275  }
276 
277  if(ladOn){
278  if(!theSiPixelFolder.setModuleFolder((*struct_iter).first,1,isUpgrade)) {
279  LogDebug ("PixelDQM") << "PROBLEM WITH LADDER-FOLDER\n";
280  }
281  }
282 
283  if(bladeOn){
284  if(!theSiPixelFolder.setModuleFolder((*struct_iter).first,4,isUpgrade)) {
285  LogDebug ("PixelDQM") << "PROBLEM WITH BLADE-FOLDER\n";
286  }
287  }
288 
289  }//for loop
290 
291  for(struct_iter2 = theFEDStructure.begin(); struct_iter2 != theFEDStructure.end(); struct_iter2++){
293  if(!theSiPixelFolder.setFedFolder((*struct_iter2).first)) {
294  throw cms::Exception("LogicError")
295  << "[SiPixelRawDataErrorSource::bookMEs] Creation of DQM folder failed";
296  }
297 
298  }
299 
300  //Booking FED histograms
301  std::string hid;
302  // Get collection name and instantiate Histo Id builder
304  SiPixelHistogramId* theHistogramId = new SiPixelHistogramId( src.label() );
305 
306  for (uint32_t id = 0; id < 40; id++){
307  char temp [50];
308  sprintf( temp, "Pixel/AdditionalPixelErrors/FED_%d",id);
309  iBooker.cd(temp);
310  // Types of errors
311  hid = theHistogramId->setHistoId("errorType",id);
312  meErrorType_[id] = iBooker.book1D(hid,"Type of errors",15,24.5,39.5);
313  meErrorType_[id]->setAxisTitle("Type of errors",1);
314  // Number of errors
315  hid = theHistogramId->setHistoId("NErrors",id);
316  meNErrors_[id] = iBooker.book1D(hid,"Number of errors",36,0.,36.);
317  meNErrors_[id]->setAxisTitle("Number of errors",1);
318  // Type of FIFO full (errorType = 28). FIFO 1 is 1-5 (where fullType = channel of FIFO 1),
319  // fullType = 6 signifies FIFO 2 nearly full, 7 signifies trigger FIFO nearly full, 8
320  // indicates an unexpected result
321  hid = theHistogramId->setHistoId("fullType",id);
322  meFullType_[id] = iBooker.book1D(hid,"Type of FIFO full",7,0.5,7.5);
323  meFullType_[id]->setAxisTitle("FIFO type",1);
324  // For error type 30, the type of problem encoded in the TBM trailer
325  // 0 = stack full, 1 = Pre-cal issued, 2 = clear trigger counter, 3 = sync trigger,
326  // 4 = sync trigger error, 5 = reset ROC, 6 = reset TBM, 7 = no token bit pass
327  hid = theHistogramId->setHistoId("TBMMessage",id);
328  meTBMMessage_[id] = iBooker.book1D(hid,"TBM trailer message",8,-0.5,7.5);
329  meTBMMessage_[id]->setAxisTitle("TBM message",1);
330  // For error type 30, the type of problem encoded in the TBM error trailer 0 = none
331  // 1 = data stream too long, 2 = FSM errors, 3 = invalid # of ROCs, 4 = multiple
332  hid = theHistogramId->setHistoId("TBMType",id);
333  meTBMType_[id] = iBooker.book1D(hid,"Type of TBM trailer",5,-0.5,4.5);
334  meTBMType_[id]->setAxisTitle("TBM Type",1);
335  // For error type 31, the event number of the TBM header with the error
336  hid = theHistogramId->setHistoId("EvtNbr",id);
337  meEvtNbr_[id] = iBooker.bookInt(hid);
338  // For errorType = 34, datastream size according to error word
339  hid = theHistogramId->setHistoId("evtSize",id);
340  meEvtSize_[id] = iBooker.bookInt(hid);
341  for(int j=0; j!=37; j++){
342  std::stringstream temp; temp << j;
343  hid = "FedChNErrArray_" + temp.str();
344  meFedChNErrArray_[id*37 + j] = iBooker.bookInt(hid);
345  hid = "FedChLErrArray_" + temp.str();
346  meFedChLErrArray_[id*37 + j] = iBooker.bookInt(hid);
347  hid = "FedETypeNErrArray_" + temp.str();
348  if(j<21) meFedETypeNErrArray_[id*21 + j] = iBooker.bookInt(hid);
349  }
350 
351 
352  }
353  //Add the booked histograms to the histogram map for booking
354  meMapFEDs_["meErrorType_"] = meErrorType_;
355  meMapFEDs_["meNErrors_"] = meNErrors_;
356  meMapFEDs_["meFullType_"] = meFullType_;
357  meMapFEDs_["meTBMMessage_"] = meTBMMessage_;
358  meMapFEDs_["meTBMType_"] = meTBMType_;
359  meMapFEDs_["meEvtNbr_"] = meEvtNbr_;
360  meMapFEDs_["meEvtSize_"] = meEvtSize_;
361  meMapFEDs_["meFedChNErrArray_"] = meFedChNErrArray_;
362  meMapFEDs_["meFedChLErrArray_"] = meFedChLErrArray_;
363  meMapFEDs_["meFedETypeNErrArray_"] = meFedETypeNErrArray_;
364 
365  //cout<<"...leaving SiPixelRawDataErrorSource::bookMEs now! "<<endl;
366 }
367 
#define LogDebug(id)
int plaquetteName() const
plaquetteId (in pannel)
T getParameter(std::string const &) const
void setBinContent(int binx, double content)
set content of bin (1-D)
virtual void bookMEs(DQMStore::IBooker &)
std::map< uint32_t, SiPixelRawDataErrorModule * > theFEDStructure
edm::EDGetTokenT< edm::DetSetVector< SiPixelRawDataError > > src_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
virtual void analyze(const edm::Event &, const edm::EventSetup &)
void cd(void)
Definition: DQMStore.cc:266
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
MonitorElement * bookInt(Args &&...args)
Definition: DQMStore.h:101
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:59
int plaquetteName() const
plaquetteId (in pannel)
virtual void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
static std::string const input
Definition: EdmProvDump.cc:44
void Fill(long long x)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
int bladeName() const
blade id
bool setFedFolder(const uint32_t FedId)
Set folder name for a FED (used in the case of errors without detId)
int iEvent
Definition: GenABIO.cc:230
bool setModuleFolder(const uint32_t &rawdetid=0, int type=0, bool isUpgrade=false)
Set folder name for a module or plaquette.
std::map< uint32_t, SiPixelRawDataErrorModule * > thePixelStructure
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:113
int j
Definition: DBlmapReader.cc:9
int bladeName() const
blade id
bool isValid() const
Definition: HandleBase.h:76
SiPixelRawDataErrorSource(const edm::ParameterSet &conf)
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
int diskName() const
disk id
Definition: DetId.h:18
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
const T & get() const
Definition: EventSetup.h:55
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
std::string const & label() const
Definition: InputTag.h:42
std::map< std::string, MonitorElement ** > meMapFEDs_
virtual void buildStructure(edm::EventSetup const &)
MonitorElement * meFedETypeNErrArray_[840]
MonitorElement * meFedChNErrArray_[1480]
int pannelName() const
pannel id
int diskName() const
disk id
volatile std::atomic< bool > shutdown_flag false
void setLumiFlag(void)
this ME is meant to be stored for each luminosity section
HalfCylinder halfCylinder() const
HalfCylinder halfCylinder() const
int pannelName() const
pannel id
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
Definition: vlib.h:208
Pixel error – collection of errors and error information.
Definition: Run.h:41
virtual void dqmBeginRun(const edm::Run &, edm::EventSetup const &)
MonitorElement * meFedChLErrArray_[1480]