CMS 3D CMS Logo

SiPixelStatusProducer.cc
Go to the documentation of this file.
1 // C++ standard
2 #include <string>
3 // ROOT
4 #include "TMath.h"
5 // CMSSW FW
9 // CMSSW DataFormats
17 // "FED error 25"
19 // CMSSW CondFormats
26 
27 // Header file
29 
31  /* badPixelFEDChannelCollections */
32  std::vector<edm::InputTag> badPixelFEDChannelCollectionLabels =
33  iConfig.getParameter<edm::ParameterSet>("SiPixelStatusProducerParameters")
34  .getParameter<std::vector<edm::InputTag>>("badPixelFEDChannelCollections");
36  theBadPixelFEDChannelsTokens_.push_back(consumes<PixelFEDChannelCollection>(t));
37 
38  /* pixel clusters */
39  fPixelClusterLabel_ = iConfig.getParameter<edm::ParameterSet>("SiPixelStatusProducerParameters")
40  .getUntrackedParameter<edm::InputTag>("pixelClusterLabel");
41  fSiPixelClusterToken_ = consumes<edmNew::DetSetVector<SiPixelCluster>>(fPixelClusterLabel_);
42 
43  //debug_ = iConfig.getUntrackedParameter<bool>("debug");
44 
45  /* register products */
46  produces<SiPixelDetectorStatus, edm::Transition::EndLuminosityBlock>("siPixelStatus");
47 }
48 
50 
51 //--------------------------------------------------------------------------------------------------
52 
54  /*Is it good to pass the objects stored in runCache to set class private members values *
55  or just call runCahche every time in the calss function?*/
56 
57  edm::LogInfo("SiPixelStatusProducer") << "beginRun: update the std::map for pixel geo/topo " << std::endl;
58  /* update the std::map for pixel geo/topo */
59  /* vector of all <int> detIds */
60  fDetIds_ = runCache()->getDetIds(); //getDetIds();
61  /* ROC size (number of row, number of columns for each det id) */
62  fSensors_ = runCache()->getSensors();
63  /* the roc layout on a module */
64  fSensorLayout_ = runCache()->getSensorLayout();
65  /* fedId as a function of detId */
66  fFedIds_ = runCache()->getFedIds();
67  /* map the index ROC to rocId */
68  fRocIds_ = runCache()->getRocIds();
69 }
70 
72  edm::LogInfo("SiPixelStatusProducer") << "beginlumi instance" << std::endl;
73 
74  /* initialize fDet_ with a set of modules(detIds) and clean the fFEDerror25_ */
76  for (unsigned int itDetId = 0; itDetId < fDetIds_.size(); ++itDetId) {
77  int detid = fDetIds_[itDetId];
78  int nrocs = fSensorLayout_[detid].first * fSensorLayout_[detid].second;
79 
80  fDet_.addModule(detid, nrocs);
81  }
82 
83  fFEDerror25_.clear();
84  ftotalevents_ = 0;
85 }
86 
88  edm::LogInfo("SiPixelStatusProducer") << "start cluster analyzer " << std::endl;
89 
90  /* count number of events for the current module instance in the luminosityBlock */
91  ftotalevents_++;
92 
93  /* ----------------------------------------------------------------------
94  -- Pixel cluster analysis
95  ----------------------------------------------------------------------*/
96 
98  if (!iEvent.getByToken(fSiPixelClusterToken_, hClusterColl)) {
99  edm::LogWarning("SiPixelStatusProducer")
100  << " edmNew::DetSetVector<SiPixelCluster> " << fPixelClusterLabel_ << " does not exist!" << std::endl;
101  return;
102  }
103 
104  iEvent.getByToken(fSiPixelClusterToken_, hClusterColl);
105 
106  if (hClusterColl.isValid()) {
107  for (const auto& clusters : *hClusterColl) { /*loop over different clusters in a clusters vector (module)*/
108  for (const auto& clu : clusters) { /*loop over cluster in a given detId (module)*/
109  int detid = clusters.detId();
110  int rowsperroc = fSensors_[detid].first;
111  int colsperroc = fSensors_[detid].second;
112 
113  //int nROCrows = fSensorLayout_[detid].first;
114  int nROCcolumns = fSensorLayout_[detid].second;
115 
116  int roc(-1);
117  std::map<int, int> rocIds_detid;
118  if (fRocIds_.find(detid) != fRocIds_.end()) {
119  rocIds_detid = fRocIds_[detid];
120  }
121 
122  /* A module is made with a few ROCs
123  Need to convert global row/column (on a module) to local row/column (on a ROC) */
124  const std::vector<SiPixelCluster::Pixel>& pixvector = clu.pixels();
125  for (unsigned int i = 0; i < pixvector.size(); ++i) {
126  int mr0 = pixvector[i].x; /* constant column direction is along x-axis */
127  int mc0 = pixvector[i].y; /* constant row direction is along y-axis */
128 
129  int irow = mr0 / rowsperroc;
130  int icol = mc0 / colsperroc;
131 
132  int key = indexROC(irow, icol, nROCcolumns);
133  if (rocIds_detid.find(key) != rocIds_detid.end()) {
134  roc = rocIds_detid[key];
135  }
136 
137  fDet_.fillDIGI(detid, roc);
138 
139  } /* loop over pixels in a cluster */
140 
141  } /* loop over cluster in a detId (module) */
142 
143  } /* loop over detId-grouped clusters in cluster detId-grouped clusters-vector* */
144 
145  } /* hClusterColl.isValid() */
146  else {
147  edm::LogWarning("SiPixelStatusProducer")
148  << " edmNew::DetSetVector<SiPixelCluster> " << fPixelClusterLabel_ << " is NOT Valid!" << std::endl;
149  }
150 
151  /*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
152 
153  /* FEDerror25 per-ROC per-event */
154  edm::Handle<PixelFEDChannelCollection> pixelFEDChannelCollectionHandle;
155 
156  /* look over different resouces of tokens */
158  if (!iEvent.getByToken(tk, pixelFEDChannelCollectionHandle)) {
159  edm::LogWarning("SiPixelStatusProducer")
160  << " PixelFEDChannelCollection with index " << tk.index() << " does NOT exist!" << std::endl;
161  continue;
162  }
163 
164  iEvent.getByToken(tk, pixelFEDChannelCollectionHandle);
165  if (!pixelFEDChannelCollectionHandle.isValid()) {
166  edm::LogWarning("SiPixelStatusProducer")
167  << " PixelFEDChannelCollection with index " << tk.index() << " is NOT valid!" << std::endl;
168  continue;
169  }
170 
171  /* FEDerror channels for the current events */
172  std::map<int, std::vector<PixelFEDChannel>> tmpFEDerror25;
173  for (const auto& disabledChannels : *pixelFEDChannelCollectionHandle) {
174  /* loop over different PixelFED in a PixelFED vector (module) */
175  for (const auto& ch : disabledChannels) {
176  DetId detId = disabledChannels.detId();
177  int detid = detId.rawId();
178 
179  if (ftotalevents_ == 1) {
180  /* FEDerror25 channels for the "first" event in the lumi section (first for the current instance of the module) */
181  fFEDerror25_[detid].push_back(ch);
182  } else
183  tmpFEDerror25[detid].push_back(ch);
184 
185  } /* loop over different PixelFED in a PixelFED vector (different channel for a module) */
186 
187  } /* loop over different (different DetId) PixelFED vectors in PixelFEDChannelCollection */
188 
189  /* Compare the current FEDerror list with the first event's FEDerror list
190  * and save the common channels */
191  if (!tmpFEDerror25.empty() && !fFEDerror25_.empty()) {
192  std::map<int, std::vector<PixelFEDChannel>>::iterator itFEDerror25;
193  for (itFEDerror25 = fFEDerror25_.begin(); itFEDerror25 != fFEDerror25_.end(); itFEDerror25++) {
194  int detid = itFEDerror25->first;
195  if (tmpFEDerror25.find(detid) != tmpFEDerror25.end()) {
196  std::vector<PixelFEDChannel> chs = itFEDerror25->second;
197  std::vector<PixelFEDChannel> chs_tmp = tmpFEDerror25[detid];
198 
199  std::vector<PixelFEDChannel> chs_common;
200  for (unsigned int ich = 0; ich < chs.size(); ich++) {
201  PixelFEDChannel ch = chs[ich];
202  /* loop over the current FEDerror25 channels, save the common FED channels */
203  for (unsigned int ich_tmp = 0; ich_tmp < chs_tmp.size(); ich_tmp++) {
204  PixelFEDChannel ch_tmp = chs_tmp[ich_tmp];
205  if ((ch.fed == ch_tmp.fed) && (ch.link == ch_tmp.link)) { /* the same FED channel */
206  chs_common.push_back(ch);
207  break;
208  }
209  }
210  }
211  /* remove the full module from FEDerror25 list if no common channels are left */
212  if (chs_common.empty())
213  fFEDerror25_.erase(itFEDerror25);
214  /* otherwise replace with the common channels */
215  else {
216  fFEDerror25_[detid].clear();
217  fFEDerror25_[detid] = chs_common;
218  }
219  } else { /* remove the full module from FEDerror25 list if the module doesn't appear in the current event's FEDerror25 list */
220  fFEDerror25_.erase(itFEDerror25);
221  }
222 
223  } /* loop over modules that have FEDerror25 in the first event in the lumi section */
224 
225  } /* non-empty FEDerror lists */
226 
227  } /* look over different resouces of takens */
228 
229  /* Caveat
230  no per-event collection put into iEvent
231  If use produce() function and no collection is put into iEvent, produce() will not run in unScheduled mode
232  Now since CMSSW_10_1_X, the accumulate() function will run whatsoever in the unScheduled mode
233  Accumulate() is NOT available for releases BEFORE CMSSW_10_1_X */
234 }
235 
237  /* set total number of events through ftotalevents_ */
239 
240  if (ftotalevents_ > 0) {
241  /* Add FEDerror25 information into SiPixelDetectorStatus fDet_ for FED channels stored in fFEDerror25_ */
242  if (!fFEDerror25_.empty()) { // non-empty FEDerror25
243  std::map<int, std::vector<PixelFEDChannel>>::iterator itFEDerror25;
244  for (itFEDerror25 = fFEDerror25_.begin(); itFEDerror25 != fFEDerror25_.end();
245  itFEDerror25++) { // loop over detIds
246  int detid = itFEDerror25->first;
247  std::vector<PixelFEDChannel> chs = itFEDerror25->second;
248  for (unsigned int ich = 0; ich < chs.size(); ich++) {
249  fDet_.fillFEDerror25(detid, chs[ich]);
250  }
251  } // loop over detIds
252  } // if non-empty FEDerror25
253 
254  } // only for non-zero events
255 }
256 
258  edm::LuminosityBlock const& iLumi,
259  edm::EventSetup const&,
260  std::vector<SiPixelDetectorStatus>* siPixelDetectorStatusVtr) const {
261  /*add the Stream's partial information to the full information*/
262 
263  /* only save for the lumi sections with NON-ZERO events */
264  if (ftotalevents_ > 0)
265  siPixelDetectorStatusVtr->push_back(fDet_);
266 }
267 
268 /* helper function */
269 int SiPixelStatusProducer::indexROC(int irow, int icol, int nROCcolumns) {
270  return int(icol + irow * nROCcolumns);
271 
272  /* generate the folling roc index that is going to map with ROC id as
273  8 9 10 11 12 13 14 15
274  0 1 2 3 4 5 6 7 */
275 }
276 
SiPixelStatusProducer::fFEDerror25_
std::map< int, std::vector< PixelFEDChannel > > fFEDerror25_
Definition: SiPixelStatusProducer.h:261
SiPixelStatusProducer::ftotalevents_
unsigned long int ftotalevents_
Definition: SiPixelStatusProducer.h:253
FEDNumbering.h
SiPixelTopoCache
Definition: SiPixelStatusProducer.h:53
SiPixelStatusProducer.h
mps_fire.i
i
Definition: mps_fire.py:428
PixelBarrelName.h
MessageLogger.h
RunSummaryRcd.h
PixelFEDChannel
Definition: PixelFEDChannel.h:6
SiPixelStatusProducer::theBadPixelFEDChannelsTokens_
std::vector< edm::EDGetTokenT< PixelFEDChannelCollection > > theBadPixelFEDChannelsTokens_
Definition: SiPixelStatusProducer.h:229
SiPixelStatusProducer::fSensors_
std::map< int, std::pair< int, int > > fSensors_
Definition: SiPixelStatusProducer.h:244
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
SiPixelStatusProducer
Definition: SiPixelStatusProducer.h:111
SiPixelStatusProducer::fSensorLayout_
std::map< int, std::pair< int, int > > fSensorLayout_
Definition: SiPixelStatusProducer.h:246
edm::Run
Definition: Run.h:45
edm::EDGetTokenT
Definition: EDGetToken.h:33
SiPixelCluster.h
PixelFEDChannel.h
SiPixelStatusProducer::fSiPixelClusterToken_
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > fSiPixelClusterToken_
Definition: SiPixelStatusProducer.h:228
SiPixelStatusProducer::SiPixelStatusProducer
SiPixelStatusProducer(edm::ParameterSet const &iPSet, SiPixelTopoCache const *)
Definition: SiPixelStatusProducer.cc:30
PixelDigi.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle
Definition: AssociativeIterator.h:50
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
SiPixelStatusProducer::fDetIds_
std::vector< int > fDetIds_
Definition: SiPixelStatusProducer.h:242
SiPixelStatusProducer::endLuminosityBlockSummary
void endLuminosityBlockSummary(edm::LuminosityBlock const &iLumi, edm::EventSetup const &, std::vector< SiPixelDetectorStatus > *siPixelDetectorStatusVtr) const final
Definition: SiPixelStatusProducer.cc:257
SiPixelStatusProducer::fRocIds_
std::map< int, std::map< int, int > > fRocIds_
Definition: SiPixelStatusProducer.h:250
SiPixelDetectorStatus
Definition: SiPixelDetectorStatus.h:11
SiPixelDetectorStatus::addModule
void addModule(int detid, int nrocs)
Definition: SiPixelDetectorStatus.cc:102
DetId
Definition: DetId.h:17
MakerMacros.h
SiPixelStatusProducer::endLuminosityBlock
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) final
Definition: SiPixelStatusProducer.cc:236
HLT_FULL_cff.badPixelFEDChannelCollectionLabels
badPixelFEDChannelCollectionLabels
Definition: HLT_FULL_cff.py:9507
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
SiPixelStatusProducer::fFedIds_
std::unordered_map< uint32_t, unsigned int > fFedIds_
Definition: SiPixelStatusProducer.h:248
SiPixelDetectorStatus::fillDIGI
void fillDIGI(int detid, int roc)
Definition: SiPixelDetectorStatus.cc:114
SiPixelStatusProducer::accumulate
void accumulate(edm::Event const &iEvent, edm::EventSetup const &iSetup) final
Definition: SiPixelStatusProducer.cc:87
PixelFEDChannel::link
unsigned int link
Definition: PixelFEDChannel.h:7
SiPixelStatusProducer::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) final
Definition: SiPixelStatusProducer.cc:53
PixelFEDChannel::fed
unsigned int fed
Definition: PixelFEDChannel.h:7
bsc_activity_cfg.clusters
clusters
Definition: bsc_activity_cfg.py:36
SiPixelDetectorStatus::fillFEDerror25
void fillFEDerror25(int detid, PixelFEDChannel ch)
Definition: SiPixelDetectorStatus.cc:120
TrackerDigiGeometryRecord.h
SiPixelFrameConverter.h
edm::ParameterSet
Definition: ParameterSet.h:47
SiPixelDetectorStatus::setNevents
void setNevents(unsigned long int N)
Definition: SiPixelDetectorStatus.h:47
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
SiPixelStatusProducer::~SiPixelStatusProducer
~SiPixelStatusProducer() override
Definition: SiPixelStatusProducer.cc:49
edm::EventSetup
Definition: EventSetup.h:57
DetSetVector.h
RunSummary.h
RunInfo.h
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
SiPixelStatusProducer::fPixelClusterLabel_
edm::InputTag fPixelClusterLabel_
Definition: SiPixelStatusProducer.h:227
ConditionsInEdm.h
DeadROCCounter.nrocs
nrocs
Definition: DeadROCCounter.py:57
PixelGeomDetUnit.h
SiPixelStatusProducer::indexROC
virtual int indexROC(int irow, int icol, int nROCcolumns) final
Definition: SiPixelStatusProducer.cc:269
PixelMapPlotter.roc
roc
Definition: PixelMapPlotter.py:498
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
SiPixelStatusProducer::fDet_
SiPixelDetectorStatus fDet_
Definition: SiPixelStatusProducer.h:264
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
crabWrapper.key
key
Definition: crabWrapper.py:19
SiPixelStatusProducer::beginLuminosityBlock
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) final
Definition: SiPixelStatusProducer.cc:71
PixelEndcapName.h