CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
SiStripCMMonitorPlugin Class Reference

#include <DQM/SiStripMonitorHardware/plugins/SiStripCMMonitor.cc>

Inheritance diagram for SiStripCMMonitorPlugin:
one::DQMEDAnalyzer< T > one::dqmimplementation::DQMBaseClass< T... >

Classes

struct  Statistics
 

Public Member Functions

 SiStripCMMonitorPlugin (const edm::ParameterSet &)
 
 ~SiStripCMMonitorPlugin () override
 
- Public Member Functions inherited from one::DQMEDAnalyzer< T >
 DQMEDAnalyzer ()=default
 
 DQMEDAnalyzer (DQMEDAnalyzer< T... > const &)=delete
 
 DQMEDAnalyzer (DQMEDAnalyzer< T... > &&)=delete
 
 ~DQMEDAnalyzer () override=default
 

Private Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void bookHistograms (DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
 
void dqmBeginRun (const edm::Run &, const edm::EventSetup &) override
 
void fillMaps (uint32_t aDetId, unsigned short aChInModule, std::pair< uint16_t, uint16_t > aMedians)
 
void updateCabling (const edm::EventSetup &eventSetup)
 

Private Attributes

const SiStripFedCablingcabling_
 
uint32_t cablingCacheId_
 
CMHistograms cmHists_
 
std::map< unsigned int, StatisticsCommonModes_
 
std::map< unsigned int, StatisticsCommonModesAPV0minusAPV1_
 
bool doTkHistoMap_
 
edm::EventNumber_t evt_
 
std::vector< unsigned int > fedIdVec_
 
bool fillAllDetailedHistograms_
 
bool fillWithEvtNum_
 
bool fillWithLocalEvtNum_
 
std::string folderName_
 
std::pair< uint16_t, uint16_t > prevMedians_ [FEDNumbering::MAXSiStripFEDID+1][sistrip::FEDCH_PER_FED]
 
unsigned int printDebug_
 
edm::InputTag rawDataTag_
 
edm::EDGetTokenT< FEDRawDataCollectionrawDataToken_
 

Detailed Description

Description: DQM source application to monitor common mode for SiStrip data

Definition at line 62 of file SiStripCMMonitor.cc.

Constructor & Destructor Documentation

SiStripCMMonitorPlugin::SiStripCMMonitorPlugin ( const edm::ParameterSet iConfig)
explicit

Definition at line 123 of file SiStripCMMonitor.cc.

References cmHists_, CommonModes_, CommonModesAPV0minusAPV1_, doTkHistoMap_, evt_, sistrip::FEDCH_PER_FED, l1t::stage2::layer2::fedId, fillAllDetailedHistograms_, fillWithEvtNum_, folderName_, LogTrace, FEDNumbering::MAXSiStripFEDID, FEDNumbering::MINSiStripFEDID, prevMedians_, printDebug_, rawDataTag_, and rawDataToken_.

124  : rawDataTag_(iConfig.getUntrackedParameter<edm::InputTag>("RawDataTag",edm::InputTag("source",""))),
125  folderName_(iConfig.getUntrackedParameter<std::string>("HistogramFolderName","SiStrip/ReadoutView/CMMonitoring")),
126  fedIdVec_(iConfig.getUntrackedParameter<std::vector<unsigned int> >("FedIdVec")),
127  fillAllDetailedHistograms_(iConfig.getUntrackedParameter<bool>("FillAllDetailedHistograms",false)),
128  fillWithEvtNum_(iConfig.getUntrackedParameter<bool>("FillWithEventNumber",false)),
129  fillWithLocalEvtNum_(iConfig.getUntrackedParameter<bool>("FillWithLocalEventNumber",false)),
130  printDebug_(iConfig.getUntrackedParameter<unsigned int>("PrintDebugMessages",1)),
131  cablingCacheId_(0)
132 
133 {
134  rawDataToken_ = consumes<FEDRawDataCollection>(rawDataTag_);
135  //print config to debug log
136  std::ostringstream debugStream;
137  if (printDebug_>1) {
138  debugStream << "[SiStripCMMonitorPlugin]Configuration for SiStripCMMonitorPlugin: " << std::endl
139  << "[SiStripCMMonitorPlugin]\tRawDataTag: " << rawDataTag_ << std::endl
140  << "[SiStripCMMonitorPlugin]\tHistogramFolderName: " << folderName_ << std::endl
141  << "[SiStripCMMonitorPlugin]\tFillAllDetailedHistograms? " << (fillAllDetailedHistograms_ ? "yes" : "no") << std::endl
142  << "[SiStripCMMonitorPlugin]\tFillWithEventNumber?" << (fillWithEvtNum_ ? "yes" : "no") << std::endl
143  << "[SiStripCMMonitorPlugin]\tPrintDebugMessages? " << (printDebug_ ? "yes" : "no") << std::endl;
144  }
145 
146  std::ostringstream* pDebugStream = (printDebug_>1 ? &debugStream : nullptr);
147 
148  cmHists_.initialise(iConfig,pDebugStream);
149 
150  doTkHistoMap_ = cmHists_.tkHistoMapEnabled();
151 
152  CommonModes_.clear();
154 
156  for (unsigned int iCh(0); iCh<sistrip::FEDCH_PER_FED; iCh++){
157  prevMedians_[fedId][iCh] = std::pair<uint16_t,uint16_t>(0,0);
158  }
159  }
160 
161 
162  if (printDebug_)
163  LogTrace("SiStripMonitorHardware") << debugStream.str();
164 
165  evt_ = 0;
166 
167 }
T getUntrackedParameter(std::string const &, T const &) const
std::pair< uint16_t, uint16_t > prevMedians_[FEDNumbering::MAXSiStripFEDID+1][sistrip::FEDCH_PER_FED]
std::vector< unsigned int > fedIdVec_
std::map< unsigned int, Statistics > CommonModesAPV0minusAPV1_
edm::EventNumber_t evt_
edm::EDGetTokenT< FEDRawDataCollection > rawDataToken_
#define LogTrace(id)
std::map< unsigned int, Statistics > CommonModes_
static const uint16_t FEDCH_PER_FED
SiStripCMMonitorPlugin::~SiStripCMMonitorPlugin ( )
override

Definition at line 169 of file SiStripCMMonitor.cc.

170 {
171 }

Member Function Documentation

void SiStripCMMonitorPlugin::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 199 of file SiStripCMMonitor.cc.

References edmScanValgrind::buffer, cabling_, cmHists_, sistrip::FEDChannel::cmMedian(), gather_cfg::cout, FEDRawData::data(), FedChannelConnection::detId(), edm::EventID::event(), evt_, sistrip::FEDCH_PER_FED, SiStripFedCabling::fedConnection(), FEDRawDataCollection::FEDData(), l1t::stage2::layer2::fedId, fillMaps(), fillWithEvtNum_, fillWithLocalEvtNum_, edm::EventSetup::get(), edm::Event::getByToken(), edm::EventBase::id(), sistrip::invalid32_, FedChannelConnection::isConnected(), sistrip::FEDChannel::length(), FEDNumbering::MAXSiStripFEDID, FEDNumbering::MINSiStripFEDID, FedChannelConnection::nApvPairs(), edm::EventBase::orbitNumber(), prevMedians_, printDebug_, edm::ESHandle< T >::product(), rawDataToken_, FEDRawData::size(), updateCabling(), and MuonErrorMatrixValues_cff::values.

201 {
202  //Retrieve tracker topology from geometry
203  edm::ESHandle<TrackerTopology> tTopoHandle;
204  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
205  const TrackerTopology* const tTopo = tTopoHandle.product();
206 
207  //static bool firstEvent = true;
208  //static bool isBeingFilled = false;
209  //update cabling
210  updateCabling(iSetup);
211 
212  //get raw data
213  edm::Handle<FEDRawDataCollection> rawDataCollectionHandle;
214  iEvent.getByToken(rawDataToken_,rawDataCollectionHandle);
215  const FEDRawDataCollection& rawDataCollection = *rawDataCollectionHandle;
216 
217  //FED errors
218  FEDErrors lFedErrors;
219 
220  //loop over siStrip FED IDs
221  for (unsigned int fedId = FEDNumbering::MINSiStripFEDID;
223  fedId++) {//loop over FED IDs
224  const FEDRawData& fedData = rawDataCollection.FEDData(fedId);
225 
226  //create an object to fill all errors
227  lFedErrors.initialiseFED(fedId,cabling_,tTopo);
228 
229  //Do detailed check
230  //first check if data exists
231  bool lDataExist = lFedErrors.checkDataPresent(fedData);
232  if (!lDataExist) {
233  continue;
234  }
235 
236  std::unique_ptr<const sistrip::FEDBuffer> buffer;
237 
238  if (!lFedErrors.fillFatalFEDErrors(fedData,0)) {
239  continue;
240  }
241  else {
242  //need to construct full object to go any further
243  buffer.reset(new sistrip::FEDBuffer(fedData.data(),fedData.size(),true));
244  bool channelLengthsOK = buffer->checkChannelLengthsMatchBufferLength();
245  bool channelPacketCodesOK = buffer->checkChannelPacketCodes();
246  bool feLengthsOK = buffer->checkFEUnitLengths();
247  if ( !channelLengthsOK ||
248  !channelPacketCodesOK ||
249  !feLengthsOK ) {
250  continue;
251  }
252  }
253 
254  std::ostringstream infoStream;
255 
256 
257  if (printDebug_ > 1) {
258  infoStream << " --- Processing FED #" << fedId << std::endl;
259  }
260 
261 
262  std::vector<CMHistograms::CMvalues> values;
263 
264  for (unsigned int iCh = 0;
265  iCh < sistrip::FEDCH_PER_FED;
266  iCh++) {//loop on channels
267 
268  const FedChannelConnection & lConnection = cabling_->fedConnection(fedId,iCh);
269  bool connected = lConnection.isConnected();
270 
271  //std::cout << "FedID " << fedId << ", ch " << iCh << ", nAPVPairs " << lConnection.nApvPairs() << " apvPairNumber " << lConnection.apvPairNumber() << std::endl;
272 
273  if (!connected) {
274  continue;
275  }
276 
277  uint32_t lDetId = lConnection.detId();
278  unsigned short nChInModule = lConnection.nApvPairs();
279 
280  if (!lDetId || lDetId == sistrip::invalid32_) continue;
281 
282  bool lFailUnpackerChannelCheck = !buffer->channelGood(iCh, true) && connected;
283 
284  if (lFailUnpackerChannelCheck) {
285  continue;
286  }
287 
288 
289  //short lAPVPair = lConnection.apvPairNumber();
290  //short lSubDet = DetId(lDetId).subdetId();
291 
292 // if (firstEvent){
293 // infoStream << "Subdet " << lSubDet << ", " ;
294 // if (lSubDet == 3) {
295 //
296 // infoStream << "TIB layer " << tTopo->tibLayer(lDetId) << ", fedID " << fedId << ", channel " << iCh << std::endl;
297 // }
298 // else if (lSubDet == 4) {
299 //
300 // infoStream << "TID side " << tTopo->tibSide(lDetId) << " wheel " << tTopo->tibWheel(lDetId) << ", ring " << tTopo->tibRing(lDetId) << ", fedID " << fedId << ", channel " << iCh << std::endl;
301 // }
302 // else if (lSubDet == 5) {
303 //
304 // infoStream << "TOB side " << tTopo->tibRod(lDetId)[0] << " layer " << tTopo->tibLayer(lDetId) << ", rod " << tTopo->tibRodNumber(lDetId) << ", fedID " << fedId << ", channel " << iCh << std::endl;
305 // }
306 // else if (lSubDet == 6) {
307 //
308 // infoStream << "TEC side " << tTopo->tibSide(lDetId) << " wheel " << tTopo->tibWheel(lDetId) << ", petal " << tTopo->tibPetalNumber(lDetId) << ", ring " << tTopo->tibRing(lDetId) << ", fedID " << fedId << ", channel " << iCh << std::endl;
309 // }
310 // isBeingFilled=true;
311 // }
312 
313  std::ostringstream lMode;
314  lMode << buffer->readoutMode();
315  if (evt_ == 0 && printDebug_ > 1)
316  std::cout << "Readout mode: " << lMode.str() << std::endl;
317 
318 
319  const sistrip::FEDChannel & lChannel = buffer->channel(iCh);
320  std::pair<uint16_t,uint16_t> medians = std::pair<uint16_t,uint16_t>(0,0);
321 
322  if (lMode.str().find("Zero suppressed") != lMode.str().npos && lMode.str().find("lite") == lMode.str().npos) medians = std::pair<uint16_t,uint16_t>(lChannel.cmMedian(0),lChannel.cmMedian(1));
323 
324  CMHistograms::CMvalues lVal;
325  lVal.ChannelID = iCh;
326  lVal.Medians = std::pair<uint16_t,uint16_t>(medians.first,medians.second);
327  lVal.PreviousMedians = prevMedians_[fedId][iCh];
328 
329 // if (medians.second-medians.first > 26){
330 // std::ostringstream info;
331 // if (medians.second-medians.first > 44) info << " --- Second bump: event " << iEvent.id().event() << ", FED/Channel " << fedId << "/" << iCh << ", delta=" << medians.second-medians.first << std::endl;
332 // else info << " --- First bump: event " << iEvent.id().event() << ", FED/Channel " << fedId << "/" << iCh << ", delta=" << medians.second-medians.first << std::endl;
333 // edm::LogVerbatim("SiStripMonitorHardware") << info.str();
334 // }
335 
336  if (printDebug_ > 1) {
337  if (lChannel.length() > 7) {
338  infoStream << "Medians for channel #" << iCh << " (length " << lChannel.length() << "): " << medians.first << ", " << medians.second << std::endl;
339  }
340  }
341 
342  values.push_back(lVal);
343 
344  //if (iEvent.id().event() > 1000)
345  fillMaps(lDetId,nChInModule,medians);
346 
347  prevMedians_[fedId][iCh] = std::pair<uint16_t,uint16_t>(medians.first,medians.second);
348 
349  }//loop on channels
350 
351  float lTime = 0;
352  if (fillWithEvtNum_) {
353  // casting from unsigned long long to a float here
354  // doing it explicitely
355  lTime = static_cast<float>(iEvent.id().event());
356  } else {
357  if (fillWithLocalEvtNum_) {
358  // casting from unsigned long long to a float here
359  // doing it explicitely
360  lTime = static_cast<float>(evt_);
361  } else {
362  lTime = iEvent.orbitNumber()/11223.;
363  }
364  }
365 
366  cmHists_.fillHistograms(values,lTime,fedId);
367 
368  //if (printDebug_ > 0 && isBeingFilled && firstEvent) edm::LogVerbatim("SiStripMonitorHardware") << infoStream.str();
369 
370 
371 
372  }//loop on FEDs
373 
374 
375  //if (isBeingFilled)
376  //firstEvent = false;
377 
378  evt_++;
379 
380 }//analyze method
EventNumber_t event() const
Definition: EventID.h:41
std::pair< uint16_t, uint16_t > prevMedians_[FEDNumbering::MAXSiStripFEDID+1][sistrip::FEDCH_PER_FED]
FedChannelConnection fedConnection(uint16_t fed_id, uint16_t fed_ch) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
static const uint32_t invalid32_
Definition: Constants.h:15
void fillMaps(uint32_t aDetId, unsigned short aChInModule, std::pair< uint16_t, uint16_t > aMedians)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
uint16_t cmMedian(const uint8_t apvIndex) const
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void updateCabling(const edm::EventSetup &eventSetup)
const uint32_t & detId() const
Class containning control, module, detector and connection information, at the level of a FED channel...
edm::EventNumber_t evt_
edm::EDGetTokenT< FEDRawDataCollection > rawDataToken_
int orbitNumber() const
Definition: EventBase.h:65
const uint16_t & nApvPairs() const
const SiStripFedCabling * cabling_
edm::EventID id() const
Definition: EventBase.h:59
static const uint16_t FEDCH_PER_FED
T get() const
Definition: EventSetup.h:71
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
T const * product() const
Definition: ESHandle.h:86
void SiStripCMMonitorPlugin::bookHistograms ( DQMStore::IBooker ,
edm::Run const &  ,
edm::EventSetup const &   
)
overrideprivate

Definition at line 179 of file SiStripCMMonitor.cc.

References cmHists_, fillAllDetailedHistograms_, folderName_, edm::EventSetup::get(), edm::ESHandle< T >::product(), and DQMStore::IBooker::setCurrentFolder().

180 {
181  ibooker.setCurrentFolder(folderName_);
182 
183  edm::ESHandle<TkDetMap> tkDetMapHandle;
184  eSetup.get<TrackerTopologyRcd>().get(tkDetMapHandle);
185  const TkDetMap* tkDetMap = tkDetMapHandle.product();
186 
187  cmHists_.bookTopLevelHistograms(ibooker, tkDetMap);
188 
189  if (fillAllDetailedHistograms_) cmHists_.bookAllFEDHistograms(ibooker);
190 }
T const * product() const
Definition: ESHandle.h:86
void SiStripCMMonitorPlugin::dqmBeginRun ( const edm::Run r,
const edm::EventSetup c 
)
overrideprivate

Definition at line 192 of file SiStripCMMonitor.cc.

193 {
194 
195 }
void SiStripCMMonitorPlugin::fillMaps ( uint32_t  aDetId,
unsigned short  aChInModule,
std::pair< uint16_t, uint16_t >  aMedians 
)
private

Definition at line 455 of file SiStripCMMonitor.cc.

References CommonModes_, CommonModesAPV0minusAPV1_, SiStripCMMonitorPlugin::Statistics::Counter, DEFINE_FWK_MODULE, doTkHistoMap_, SiStripCMMonitorPlugin::Statistics::Mean, SiStripCMMonitorPlugin::Statistics::Rms, and edm::second().

Referenced by analyze().

456 {
457 
458  if (doTkHistoMap_){//if TkHistMap is enabled
459  std::pair<std::map<unsigned int,Statistics>::iterator,bool> alreadyThere[2];
460 
461  Statistics lStat;
462  lStat.Mean = (aMedians.first+aMedians.second)*1./(2*aChInModule);
463  lStat.Rms = (aMedians.first+aMedians.second)*(aMedians.first+aMedians.second)*1./(4*aChInModule);
464  lStat.Counter = 1./aChInModule;
465 
466  alreadyThere[0] = CommonModes_.insert(std::pair<unsigned int,Statistics>(aDetId,lStat));
467  if (!alreadyThere[0].second) {
468  ((alreadyThere[0].first)->second).Mean += (aMedians.first+aMedians.second)*1./(2*aChInModule);
469  ((alreadyThere[0].first)->second).Rms += (aMedians.first+aMedians.second)*(aMedians.first+aMedians.second)*1./(4*aChInModule);
470  ((alreadyThere[0].first)->second).Counter += 1./aChInModule;
471  }
472 
473  lStat.Mean = (aMedians.first-aMedians.second)*1./aChInModule;
474  lStat.Rms = (aMedians.first-aMedians.second)*(aMedians.first-aMedians.second)*1./aChInModule;
475  lStat.Counter = 1./aChInModule;
476 
477  alreadyThere[1] = CommonModesAPV0minusAPV1_.insert(std::pair<unsigned int,Statistics>(aDetId,lStat));
478  if (!alreadyThere[1].second) {
479  ((alreadyThere[1].first)->second).Mean += (aMedians.first-aMedians.second)*1./aChInModule;
480  ((alreadyThere[1].first)->second).Rms += (aMedians.first-aMedians.second)*(aMedians.first-aMedians.second)*1./aChInModule;
481  ((alreadyThere[1].first)->second).Counter += 1./aChInModule;
482  }
483 
484  }
485 
486 }
std::map< unsigned int, Statistics > CommonModesAPV0minusAPV1_
U second(std::pair< T, U > const &p)
std::map< unsigned int, Statistics > CommonModes_
void SiStripCMMonitorPlugin::updateCabling ( const edm::EventSetup eventSetup)
private

Definition at line 443 of file SiStripCMMonitor.cc.

References cabling_, cablingCacheId_, edm::EventSetup::get(), and edm::ESHandle< T >::product().

Referenced by analyze().

444 {
445  uint32_t currentCacheId = eventSetup.get<SiStripFedCablingRcd>().cacheIdentifier();
446  if (cablingCacheId_ != currentCacheId) {
447  edm::ESHandle<SiStripFedCabling> cablingHandle;
448  eventSetup.get<SiStripFedCablingRcd>().get(cablingHandle);
449  cabling_ = cablingHandle.product();
450  cablingCacheId_ = currentCacheId;
451  }
452 }
const SiStripFedCabling * cabling_
T get() const
Definition: EventSetup.h:71
T const * product() const
Definition: ESHandle.h:86

Member Data Documentation

const SiStripFedCabling* SiStripCMMonitorPlugin::cabling_
private

Definition at line 102 of file SiStripCMMonitor.cc.

Referenced by analyze(), and updateCabling().

uint32_t SiStripCMMonitorPlugin::cablingCacheId_
private

Definition at line 101 of file SiStripCMMonitor.cc.

Referenced by updateCabling().

CMHistograms SiStripCMMonitorPlugin::cmHists_
private

Definition at line 107 of file SiStripCMMonitor.cc.

Referenced by analyze(), bookHistograms(), and SiStripCMMonitorPlugin().

std::map<unsigned int,Statistics> SiStripCMMonitorPlugin::CommonModes_
private

Definition at line 109 of file SiStripCMMonitor.cc.

Referenced by fillMaps(), and SiStripCMMonitorPlugin().

std::map<unsigned int,Statistics> SiStripCMMonitorPlugin::CommonModesAPV0minusAPV1_
private

Definition at line 110 of file SiStripCMMonitor.cc.

Referenced by fillMaps(), and SiStripCMMonitorPlugin().

bool SiStripCMMonitorPlugin::doTkHistoMap_
private

Definition at line 105 of file SiStripCMMonitor.cc.

Referenced by fillMaps(), and SiStripCMMonitorPlugin().

edm::EventNumber_t SiStripCMMonitorPlugin::evt_
private

Definition at line 114 of file SiStripCMMonitor.cc.

Referenced by analyze(), and SiStripCMMonitorPlugin().

std::vector<unsigned int> SiStripCMMonitorPlugin::fedIdVec_
private

Definition at line 92 of file SiStripCMMonitor.cc.

bool SiStripCMMonitorPlugin::fillAllDetailedHistograms_
private

Definition at line 94 of file SiStripCMMonitor.cc.

Referenced by bookHistograms(), and SiStripCMMonitorPlugin().

bool SiStripCMMonitorPlugin::fillWithEvtNum_
private

Definition at line 96 of file SiStripCMMonitor.cc.

Referenced by analyze(), and SiStripCMMonitorPlugin().

bool SiStripCMMonitorPlugin::fillWithLocalEvtNum_
private

Definition at line 97 of file SiStripCMMonitor.cc.

Referenced by analyze().

std::string SiStripCMMonitorPlugin::folderName_
private

Definition at line 90 of file SiStripCMMonitor.cc.

Referenced by bookHistograms(), and SiStripCMMonitorPlugin().

std::pair<uint16_t,uint16_t> SiStripCMMonitorPlugin::prevMedians_[FEDNumbering::MAXSiStripFEDID+1][sistrip::FEDCH_PER_FED]
private

Definition at line 112 of file SiStripCMMonitor.cc.

Referenced by analyze(), and SiStripCMMonitorPlugin().

unsigned int SiStripCMMonitorPlugin::printDebug_
private

Definition at line 99 of file SiStripCMMonitor.cc.

Referenced by analyze(), and SiStripCMMonitorPlugin().

edm::InputTag SiStripCMMonitorPlugin::rawDataTag_
private

Definition at line 87 of file SiStripCMMonitor.cc.

Referenced by SiStripCMMonitorPlugin().

edm::EDGetTokenT<FEDRawDataCollection> SiStripCMMonitorPlugin::rawDataToken_
private

Definition at line 88 of file SiStripCMMonitor.cc.

Referenced by analyze(), and SiStripCMMonitorPlugin().