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
31 // Geometry
36 // DataFormats
44 //
45 #include <string>
46 #include <stdlib.h>
47 
48 using namespace std;
49 using namespace edm;
50 
52  conf_(iConfig),
53  src_( consumes<DetSetVector<SiPixelRawDataError> >( conf_.getParameter<edm::InputTag>( "src" ) ) ),
54  saveFile( conf_.getUntrackedParameter<bool>("saveFile",false) ),
55  isPIB( conf_.getUntrackedParameter<bool>("isPIB",false) ),
56  slowDown( conf_.getUntrackedParameter<bool>("slowDown",false) ),
57  reducedSet( conf_.getUntrackedParameter<bool>("reducedSet",false) ),
58  modOn( conf_.getUntrackedParameter<bool>("modOn",true) ),
59  ladOn( conf_.getUntrackedParameter<bool>("ladOn",false) ),
60  bladeOn( conf_.getUntrackedParameter<bool>("bladeOn",false) ),
61  isUpgrade( conf_.getUntrackedParameter<bool>("isUpgrade",false) )
62 {
64  LogInfo ("PixelDQM") << "SiPixelRawDataErrorSource::SiPixelRawDataErrorSource: Got DQM BackEnd interface"<<endl;
65 }
66 
67 
69 {
70  // do anything here that needs to be done at desctruction time
71  // (e.g. close files, deallocate resources etc.)
72  LogInfo ("PixelDQM") << "SiPixelRawDataErrorSource::~SiPixelRawDataErrorSource: Destructor"<<endl;
73 }
74 
75 
77  firstRun = true;
78 }
79 
81 
82  LogInfo ("PixelDQM") << " SiPixelRawDataErrorSource::beginRun - Initialisation ... " << std::endl;
83  LogInfo ("PixelDQM") << "Mod/Lad/Blade " << modOn << "/" << ladOn << "/" << bladeOn << std::endl;
84 
85  if(firstRun){
86  eventNo = 0;
87  // Build map
88  buildStructure(iSetup);
89  // Book Monitoring Elements
90  bookMEs();
91 
92  firstRun = false;
93  }
94 }
95 
96 
98 
99  if(saveFile) {
100  LogInfo ("PixelDQM") << " SiPixelRawDataErrorSource::endJob - Saving Root File " << std::endl;
102  theDMBE->save( outputFile.c_str() );
103  }
104 
105 }
106 
107 //------------------------------------------------------------------
108 // Method called for every event
109 //------------------------------------------------------------------
111 {
112  eventNo++;
113  //std::cout<<"Event number: "<<eventNo<<std::endl;
114  // get input data
116  iEvent.getByToken( src_, input );
117  if (!input.isValid()) return;
118 
119  // Get DQM interface
121 
122  //float iOrbitSec = iEvent.orbitNumber()/11223.;
123  //int bx = iEvent.bunchCrossing();
124  //long long tbx = (long long)iEvent.orbitNumber() * 3564 + bx;
125  int lumiSection = (int)iEvent.luminosityBlock();
126 
127  int nEventBPIXModuleErrors = 0; int nEventFPIXModuleErrors = 0; int nEventBPIXFEDErrors = 0; int nEventFPIXFEDErrors = 0;
128  int nErrors = 0;
129 
130  std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter;
131  std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter2;
132  for (struct_iter = thePixelStructure.begin() ; struct_iter != thePixelStructure.end() ; struct_iter++) {
133 
134  int numberOfModuleErrors = (*struct_iter).second->fill(*input, modOn, ladOn, bladeOn);
135  if(DetId( (*struct_iter).first ).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) nEventBPIXModuleErrors = nEventBPIXModuleErrors + numberOfModuleErrors;
136  if(DetId( (*struct_iter).first ).subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) nEventFPIXModuleErrors = nEventFPIXModuleErrors + numberOfModuleErrors;
137  //cout<<"NErrors: "<<nEventBPIXModuleErrors<<" "<<nEventFPIXModuleErrors<<endl;
138  nErrors = nErrors + numberOfModuleErrors;
139  //if(nErrors>0) cout<<"MODULES: nErrors: "<<nErrors<<endl;
140  }
141  for (struct_iter2 = theFEDStructure.begin() ; struct_iter2 != theFEDStructure.end() ; struct_iter2++) {
142 
143  int numberOfFEDErrors = (*struct_iter2).second->fillFED(*input);
144  if((*struct_iter2).first <= 31) nEventBPIXFEDErrors = nEventBPIXFEDErrors + numberOfFEDErrors; // (*struct_iter2).first >= 0, since (*struct_iter2).first is unsigned
145  if((*struct_iter2).first >= 32 && (*struct_iter2).first <= 39) nEventFPIXFEDErrors = nEventFPIXFEDErrors + numberOfFEDErrors;
146  //cout<<"NFEDErrors: "<<nEventBPIXFEDErrors<<" "<<nEventFPIXFEDErrors<<endl;
147  nErrors = nErrors + numberOfFEDErrors;
148  //if(nErrors>0) cout<<"FEDS: nErrors: "<<nErrors<<endl;
149  }
150  MonitorElement* me = theDMBE->get("Pixel/AdditionalPixelErrors/byLumiErrors");
151  if(me){
152  me->setBinContent(0,eventNo);
153  //cout<<"NErrors: "<<nEventBPIXModuleErrors<<" "<<nEventFPIXModuleErrors<<" "<<nEventBPIXFEDErrors<<" "<<nEventFPIXFEDErrors<<endl;
154  //if(nEventBPIXModuleErrors+nEventBPIXFEDErrors>0) me->setBinContent(1,me->getBinContent(1)+nEventBPIXModuleErrors+nEventBPIXFEDErrors);
155  //if(nEventFPIXModuleErrors+nEventFPIXFEDErrors>0) me->setBinContent(2,me->getBinContent(2)+nEventFPIXModuleErrors+nEventFPIXFEDErrors);
156  if(nEventBPIXModuleErrors+nEventBPIXFEDErrors>0) me->Fill(0,1.);
157  if(nEventFPIXModuleErrors+nEventFPIXFEDErrors>0) me->Fill(1,1.);
158  //cout<<"histo: "<<me->getBinContent(0)<<" "<<me->getBinContent(1)<<" "<<me->getBinContent(2)<<endl;
159  }
160 
161  // Rate of errors per lumi section:
162  MonitorElement* me1 = theDMBE->get("Pixel/AdditionalPixelErrors/errorRate");
163  if(me1) me1->Fill(lumiSection, nErrors);
164 
165  // slow down...
166  if(slowDown) usleep(100000);
167 
168 }
169 
170 //------------------------------------------------------------------
171 // Build data structure
172 //------------------------------------------------------------------
174 
175  LogInfo ("PixelDQM") <<" SiPixelRawDataErrorSource::buildStructure" ;
177  iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
178 
179  LogVerbatim ("PixelDQM") << " *** Geometry node for TrackerGeom is "<<&(*pDD)<<std::endl;
180  LogVerbatim ("PixelDQM") << " *** I have " << pDD->dets().size() <<" detectors"<<std::endl;
181  LogVerbatim ("PixelDQM") << " *** I have " << pDD->detTypes().size() <<" types"<<std::endl;
182 
183  for(TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++){
184 
185  if( ((*it)->subDetector()==GeomDetEnumerators::PixelBarrel) || ((*it)->subDetector()==GeomDetEnumerators::PixelEndcap) ){
186  DetId detId = (*it)->geographicalId();
187  const GeomDetUnit * geoUnit = pDD->idToDetUnit( detId );
188  const PixelGeomDetUnit * pixDet = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
189  int nrows = (pixDet->specificTopology()).nrows();
190  int ncols = (pixDet->specificTopology()).ncolumns();
191 
192  if(detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
193  if(isPIB) continue;
194  LogDebug ("PixelDQM") << " ---> Adding Barrel Module " << detId.rawId() << endl;
195  uint32_t id = detId();
196  SiPixelRawDataErrorModule* theModule = new SiPixelRawDataErrorModule(id, ncols, nrows);
197  thePixelStructure.insert(pair<uint32_t,SiPixelRawDataErrorModule*> (id,theModule));
198 
199  } else if( (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) && (!isUpgrade)) {
200  LogDebug ("PixelDQM") << " ---> Adding Endcap Module " << detId.rawId() << endl;
201  uint32_t id = detId();
202  SiPixelRawDataErrorModule* theModule = new SiPixelRawDataErrorModule(id, ncols, nrows);
203 
205  int disk = PixelEndcapName(DetId(id)).diskName();
206  int blade = PixelEndcapName(DetId(id)).bladeName();
207  int panel = PixelEndcapName(DetId(id)).pannelName();
209 
210  char sside[80]; sprintf(sside, "HalfCylinder_%i",side);
211  char sdisk[80]; sprintf(sdisk, "Disk_%i",disk);
212  char sblade[80]; sprintf(sblade, "Blade_%02i",blade);
213  char spanel[80]; sprintf(spanel, "Panel_%i",panel);
214  char smodule[80];sprintf(smodule,"Module_%i",module);
215  std::string side_str = sside;
216  std::string disk_str = sdisk;
217  bool mask = side_str.find("HalfCylinder_1")!=string::npos||
218  side_str.find("HalfCylinder_2")!=string::npos||
219  side_str.find("HalfCylinder_4")!=string::npos||
220  disk_str.find("Disk_2")!=string::npos;
221  // clutch to take all of FPIX, but no BPIX:
222  mask = false;
223  if(isPIB && mask) continue;
224 
225  thePixelStructure.insert(pair<uint32_t,SiPixelRawDataErrorModule*> (id,theModule));
226  } else if( (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) && (isUpgrade)) {
227  LogDebug ("PixelDQM") << " ---> Adding Endcap Module " << detId.rawId() << endl;
228  uint32_t id = detId();
229  SiPixelRawDataErrorModule* theModule = new SiPixelRawDataErrorModule(id, ncols, nrows);
230 
232  int disk = PixelEndcapNameUpgrade(DetId(id)).diskName();
233  int blade = PixelEndcapNameUpgrade(DetId(id)).bladeName();
234  int panel = PixelEndcapNameUpgrade(DetId(id)).pannelName();
236 
237  char sside[80]; sprintf(sside, "HalfCylinder_%i",side);
238  char sdisk[80]; sprintf(sdisk, "Disk_%i",disk);
239  char sblade[80]; sprintf(sblade, "Blade_%02i",blade);
240  char spanel[80]; sprintf(spanel, "Panel_%i",panel);
241  char smodule[80];sprintf(smodule,"Module_%i",module);
242  std::string side_str = sside;
243  std::string disk_str = sdisk;
244  bool mask = side_str.find("HalfCylinder_1")!=string::npos||
245  side_str.find("HalfCylinder_2")!=string::npos||
246  side_str.find("HalfCylinder_4")!=string::npos||
247  disk_str.find("Disk_2")!=string::npos;
248  // clutch to take all of FPIX, but no BPIX:
249  mask = false;
250  if(isPIB && mask) continue;
251 
252  thePixelStructure.insert(pair<uint32_t,SiPixelRawDataErrorModule*> (id,theModule));
253  }//endif(isUpgrade)
254  }
255  }
256  LogDebug ("PixelDQM") << " ---> Adding Module for Additional Errors " << endl;
258  fedIds.first = 0;
259  fedIds.second = 39;
260  for (int fedId = fedIds.first; fedId <= fedIds.second; fedId++) {
261  //std::cout<<"Adding FED module: "<<fedId<<std::endl;
262  uint32_t id = static_cast<uint32_t> (fedId);
264  theFEDStructure.insert(pair<uint32_t,SiPixelRawDataErrorModule*> (id,theModule));
265  }
266 
267  LogInfo ("PixelDQM") << " *** Pixel Structure Size " << thePixelStructure.size() << endl;
268 }
269 //------------------------------------------------------------------
270 // Book MEs
271 //------------------------------------------------------------------
273  //cout<<"Entering SiPixelRawDataErrorSource::bookMEs now: "<<endl;
274  // Get DQM interface
276  theDMBE->setCurrentFolder("Pixel/AdditionalPixelErrors");
277  char title[80]; sprintf(title, "By-LumiSection Error counters");
278  byLumiErrors = theDMBE->book1D("byLumiErrors",title,2,0.,2.);
280  char title1[80]; sprintf(title1, "Errors per LumiSection;LumiSection;NErrors");
281  errorRate = theDMBE->book1D("errorRate",title1,5000,0.,5000.);
282 
283  std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter;
284  std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter2;
285 
286  SiPixelFolderOrganizer theSiPixelFolder;
287 
288  for(struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++){
290 
291  if(modOn){
292  if(theSiPixelFolder.setModuleFolder((*struct_iter).first,0,isUpgrade)) {
293  (*struct_iter).second->book( conf_, 0 ,isUpgrade );
294  }
295  else {
296  //std::cout<<"PIB! not booking histograms for non-PIB modules!"<<std::endl;
297  if(!isPIB) throw cms::Exception("LogicError")
298  << "[SiPixelRawDataErrorSource::bookMEs] Creation of DQM folder failed";
299  }
300  }
301 
302  if(ladOn){
303  if(theSiPixelFolder.setModuleFolder((*struct_iter).first,1,isUpgrade)) {
304  (*struct_iter).second->book( conf_, 1 , isUpgrade );
305  }
306  else {
307  LogDebug ("PixelDQM") << "PROBLEM WITH LADDER-FOLDER\n";
308  }
309  }
310 
311  if(bladeOn){
312  if(theSiPixelFolder.setModuleFolder((*struct_iter).first,4,isUpgrade)) {
313  (*struct_iter).second->book( conf_, 4 ,isUpgrade );
314  }
315  else {
316  LogDebug ("PixelDQM") << "PROBLEM WITH BLADE-FOLDER\n";
317  }
318  }
319 
320  }//for loop
321 
322  for(struct_iter2 = theFEDStructure.begin(); struct_iter2 != theFEDStructure.end(); struct_iter2++){
324  if(theSiPixelFolder.setFedFolder((*struct_iter2).first)) {
325  (*struct_iter2).second->bookFED( conf_ );
326  }
327  else {
328  throw cms::Exception("LogicError")
329  << "[SiPixelRawDataErrorSource::bookMEs] Creation of DQM folder failed";
330  }
331 
332  }
333  //cout<<"...leaving SiPixelRawDataErrorSource::bookMEs now! "<<endl;
334 
335 }
336 
#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)
std::map< uint32_t, SiPixelRawDataErrorModule * > theFEDStructure
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:928
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 &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void beginRun(const edm::Run &, edm::EventSetup const &)
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:59
int plaquetteName() const
plaquetteId (in pannel)
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
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2424
int bladeName() const
blade id
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1679
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
const T & get() const
Definition: EventSetup.h:55
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
virtual void buildStructure(edm::EventSetup const &)
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
Definition: vlib.h:208
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:639
Pixel error – collection of errors and error information.
Definition: Run.h:41