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
42 //
43 #include <string>
44 #include <stdlib.h>
45 
46 using namespace std;
47 using namespace edm;
48 
50  conf_(iConfig),
51  src_( conf_.getParameter<edm::InputTag>( "src" ) ),
52  saveFile( conf_.getUntrackedParameter<bool>("saveFile",false) ),
53  isPIB( conf_.getUntrackedParameter<bool>("isPIB",false) ),
54  slowDown( conf_.getUntrackedParameter<bool>("slowDown",false) ),
55  reducedSet( conf_.getUntrackedParameter<bool>("reducedSet",false) ),
56  modOn( conf_.getUntrackedParameter<bool>("modOn",true) ),
57  ladOn( conf_.getUntrackedParameter<bool>("ladOn",false) ),
58  bladeOn( conf_.getUntrackedParameter<bool>("bladeOn",false) )
59 {
61  LogInfo ("PixelDQM") << "SiPixelRawDataErrorSource::SiPixelRawDataErrorSource: Got DQM BackEnd interface"<<endl;
62 }
63 
64 
66 {
67  // do anything here that needs to be done at desctruction time
68  // (e.g. close files, deallocate resources etc.)
69  LogInfo ("PixelDQM") << "SiPixelRawDataErrorSource::~SiPixelRawDataErrorSource: Destructor"<<endl;
70 }
71 
72 
74  firstRun = true;
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  // Build map
85  buildStructure(iSetup);
86  // Book Monitoring Elements
87  bookMEs();
88 
89  firstRun = false;
90  }
91 }
92 
93 
95 
96  if(saveFile) {
97  LogInfo ("PixelDQM") << " SiPixelRawDataErrorSource::endJob - Saving Root File " << std::endl;
98  std::string outputFile = conf_.getParameter<std::string>("outputFile");
99  theDMBE->save( outputFile.c_str() );
100  }
101 
102 }
103 
104 //------------------------------------------------------------------
105 // Method called for every event
106 //------------------------------------------------------------------
108 {
109  eventNo++;
110  //std::cout<<"Event number: "<<eventNo<<std::endl;
111  // get input data
113  iEvent.getByLabel( src_, input );
114  if (!input.isValid()) return;
115 
116  // Get DQM interface
118 
119  //float iOrbitSec = iEvent.orbitNumber()/11223.;
120  //int bx = iEvent.bunchCrossing();
121  //long long tbx = (long long)iEvent.orbitNumber() * 3564 + bx;
122  int lumiSection = (int)iEvent.luminosityBlock();
123 
124  int nEventBPIXModuleErrors = 0; int nEventFPIXModuleErrors = 0; int nEventBPIXFEDErrors = 0; int nEventFPIXFEDErrors = 0;
125  int nErrors = 0;
126 
127  std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter;
128  std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter2;
129  for (struct_iter = thePixelStructure.begin() ; struct_iter != thePixelStructure.end() ; struct_iter++) {
130 
131  int numberOfModuleErrors = (*struct_iter).second->fill(*input, modOn, ladOn, bladeOn);
132  if(DetId( (*struct_iter).first ).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) nEventBPIXModuleErrors = nEventBPIXModuleErrors + numberOfModuleErrors;
133  if(DetId( (*struct_iter).first ).subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) nEventFPIXModuleErrors = nEventFPIXModuleErrors + numberOfModuleErrors;
134  nErrors = nErrors + numberOfModuleErrors;
135  }
136  for (struct_iter2 = theFEDStructure.begin() ; struct_iter2 != theFEDStructure.end() ; struct_iter2++) {
137 
138  int numberOfFEDErrors = (*struct_iter2).second->fillFED(*input);
139  if((*struct_iter2).first <= 31) nEventBPIXFEDErrors = nEventBPIXFEDErrors + numberOfFEDErrors; // (*struct_iter2).first >= 0, since (*struct_iter2).first is unsigned
140  if((*struct_iter2).first >= 32 && (*struct_iter2).first <= 39) nEventFPIXFEDErrors = nEventFPIXFEDErrors + numberOfFEDErrors;
141  nErrors = nErrors + numberOfFEDErrors;
142  }
143  MonitorElement* me = theDMBE->get("Pixel/AdditionalPixelErrors/byLumiErrors");
144  if(me){
145  me->setBinContent(0,eventNo);
146  if(nEventBPIXModuleErrors+nEventBPIXFEDErrors>0) me->setBinContent(1,nEventBPIXModuleErrors+nEventBPIXFEDErrors);
147  if(nEventFPIXModuleErrors+nEventFPIXFEDErrors>0) me->setBinContent(2,nEventFPIXModuleErrors+nEventFPIXFEDErrors);
148  }
149 
150  // Rate of errors per lumi section:
151  MonitorElement* me1 = theDMBE->get("Pixel/AdditionalPixelErrors/errorRate");
152  if(me1){
153  int nLumiErrors = int(me1->getBinContent(lumiSection+1)) + nErrors;
154  me1->Fill(lumiSection, nLumiErrors);
155  }
156 
157 
158 
159  // slow down...
160  if(slowDown) usleep(100000);
161 
162 }
163 
164 //------------------------------------------------------------------
165 // Build data structure
166 //------------------------------------------------------------------
168 
169  LogInfo ("PixelDQM") <<" SiPixelRawDataErrorSource::buildStructure" ;
171  iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
172 
173  LogVerbatim ("PixelDQM") << " *** Geometry node for TrackerGeom is "<<&(*pDD)<<std::endl;
174  LogVerbatim ("PixelDQM") << " *** I have " << pDD->dets().size() <<" detectors"<<std::endl;
175  LogVerbatim ("PixelDQM") << " *** I have " << pDD->detTypes().size() <<" types"<<std::endl;
176 
177  for(TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++){
178 
179  if( ((*it)->subDetector()==GeomDetEnumerators::PixelBarrel) || ((*it)->subDetector()==GeomDetEnumerators::PixelEndcap) ){
180  DetId detId = (*it)->geographicalId();
181  const GeomDetUnit * geoUnit = pDD->idToDetUnit( detId );
182  const PixelGeomDetUnit * pixDet = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
183  int nrows = (pixDet->specificTopology()).nrows();
184  int ncols = (pixDet->specificTopology()).ncolumns();
185 
186  if(detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
187  if(isPIB) continue;
188  LogDebug ("PixelDQM") << " ---> Adding Barrel Module " << detId.rawId() << endl;
189  uint32_t id = detId();
190  SiPixelRawDataErrorModule* theModule = new SiPixelRawDataErrorModule(id, ncols, nrows);
191  thePixelStructure.insert(pair<uint32_t,SiPixelRawDataErrorModule*> (id,theModule));
192 
193  } else if(detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) {
194  LogDebug ("PixelDQM") << " ---> Adding Endcap Module " << detId.rawId() << endl;
195  uint32_t id = detId();
196  SiPixelRawDataErrorModule* theModule = new SiPixelRawDataErrorModule(id, ncols, nrows);
197 
199  int disk = PixelEndcapName(DetId(id)).diskName();
200  int blade = PixelEndcapName(DetId(id)).bladeName();
201  int panel = PixelEndcapName(DetId(id)).pannelName();
203 
204  char sside[80]; sprintf(sside, "HalfCylinder_%i",side);
205  char sdisk[80]; sprintf(sdisk, "Disk_%i",disk);
206  char sblade[80]; sprintf(sblade, "Blade_%02i",blade);
207  char spanel[80]; sprintf(spanel, "Panel_%i",panel);
208  char smodule[80];sprintf(smodule,"Module_%i",module);
209  std::string side_str = sside;
210  std::string disk_str = sdisk;
211  bool mask = side_str.find("HalfCylinder_1")!=string::npos||
212  side_str.find("HalfCylinder_2")!=string::npos||
213  side_str.find("HalfCylinder_4")!=string::npos||
214  disk_str.find("Disk_2")!=string::npos;
215  // clutch to take all of FPIX, but no BPIX:
216  mask = false;
217  if(isPIB && mask) continue;
218 
219  thePixelStructure.insert(pair<uint32_t,SiPixelRawDataErrorModule*> (id,theModule));
220  }
221  }
222  }
223  LogDebug ("PixelDQM") << " ---> Adding Module for Additional Errors " << endl;
225  fedIds.first = 0;
226  fedIds.second = 39;
227  for (int fedId = fedIds.first; fedId <= fedIds.second; fedId++) {
228  //std::cout<<"Adding FED module: "<<fedId<<std::endl;
229  uint32_t id = static_cast<uint32_t> (fedId);
231  theFEDStructure.insert(pair<uint32_t,SiPixelRawDataErrorModule*> (id,theModule));
232  }
233 
234  LogInfo ("PixelDQM") << " *** Pixel Structure Size " << thePixelStructure.size() << endl;
235 }
236 //------------------------------------------------------------------
237 // Book MEs
238 //------------------------------------------------------------------
240 
241  // Get DQM interface
243  theDMBE->setCurrentFolder("Pixel/AdditionalPixelErrors");
244  char title[80]; sprintf(title, "By-LumiSection Error counters");
245  byLumiErrors = theDMBE->book1D("byLumiErrors",title,2,0.,2.);
247  char title1[80]; sprintf(title1, "Errors per LumiSection;LumiSection;NErrors");
248  errorRate = theDMBE->book1D("errorRate",title1,5000,0.,5000.);
249 
250  std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter;
251  std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter2;
252 
253  SiPixelFolderOrganizer theSiPixelFolder;
254 
255  for(struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++){
257 
258  if(modOn){
259  if(theSiPixelFolder.setModuleFolder((*struct_iter).first)) {
260  (*struct_iter).second->book( conf_, 0 );
261  }
262  else {
263  //std::cout<<"PIB! not booking histograms for non-PIB modules!"<<std::endl;
264  if(!isPIB) throw cms::Exception("LogicError")
265  << "[SiPixelRawDataErrorSource::bookMEs] Creation of DQM folder failed";
266  }
267  }
268 
269  if(ladOn){
270  if(theSiPixelFolder.setModuleFolder((*struct_iter).first,1)) {
271  (*struct_iter).second->book( conf_, 1 );
272  }
273  else {
274  LogDebug ("PixelDQM") << "PROBLEM WITH LADDER-FOLDER\n";
275  }
276  }
277 
278  if(bladeOn){
279  if(theSiPixelFolder.setModuleFolder((*struct_iter).first,4)) {
280  (*struct_iter).second->book( conf_, 4 );
281  }
282  else {
283  LogDebug ("PixelDQM") << "PROBLEM WITH BLADE-FOLDER\n";
284  }
285  }
286 
287  }//for loop
288 
289  for(struct_iter2 = theFEDStructure.begin(); struct_iter2 != theFEDStructure.end(); struct_iter2++){
291  if(theSiPixelFolder.setFedFolder((*struct_iter2).first)) {
292  (*struct_iter2).second->bookFED( conf_ );
293  }
294  else {
295  throw cms::Exception("LogicError")
296  << "[SiPixelRawDataErrorSource::bookMEs] Creation of DQM folder failed";
297  }
298 
299  }
300 
301 }
#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:514
virtual void analyze(const edm::Event &, const edm::EventSetup &)
virtual void beginRun(const edm::Run &, edm::EventSetup const &)
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:1898
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:59
void Fill(long long x)
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
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:243
std::map< uint32_t, SiPixelRawDataErrorModule * > thePixelStructure
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1265
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:39
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
tuple input
Definition: collect_tpl.py:10
Definition: DetId.h:20
const T & get() const
Definition: EventSetup.h:55
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
double getBinContent(int binx) const
get content of bin (1-D)
virtual void buildStructure(edm::EventSetup const &)
int pannelName() const
pannel id
int diskName() const
disk id
void setLumiFlag(void)
this ME is meant to be stored for each luminosity section
HalfCylinder halfCylinder() const
Definition: vlib.h:209
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:232
Definition: Run.h:32
bool setModuleFolder(const uint32_t &rawdetid=0, int type=0)
Set folder name for a module or plaquette.