CMS 3D CMS Logo

SiPixelStatusProducer.cc
Go to the documentation of this file.
1 
8 // C++ standard
9 #include <string>
10 // ROOT
11 #include "TMath.h"
12 // CMSSW FW
21 // CMSSW DataFormats
29 // "FED error 25"
31 // CMSSW CondFormats
40 // EDProducer related dataformat
43 // header file
45 
46 using namespace std;
47 
48 //--------------------------------------------------------------------------------------------------
50  // get parameter
51 
52  // badPixelFEDChannelCollections
53  std::vector<edm::InputTag> badPixelFEDChannelCollectionLabels_ = iConfig.getParameter<edm::ParameterSet>("SiPixelStatusProducerParameters").getParameter<std::vector<edm::InputTag> >("badPixelFEDChannelCollections");
54  for (auto &t : badPixelFEDChannelCollectionLabels_)
55  theBadPixelFEDChannelsTokens_.push_back(consumes<PixelFEDChannelCollection>(t));
56  // badPixelFEDChannelCollections = cms.VInputTag(cms.InputTag('siPixelDigis'))
57 
58  fPixelClusterLabel_ = iConfig.getParameter<edm::ParameterSet>("SiPixelStatusProducerParameters").getUntrackedParameter<edm::InputTag>("pixelClusterLabel");
59  fSiPixelClusterToken_ = consumes<edmNew::DetSetVector<SiPixelCluster>>(fPixelClusterLabel_);
60  resetNLumi_ = iConfig.getParameter<edm::ParameterSet>("SiPixelStatusProducerParameters").getUntrackedParameter<int>("resetEveryNLumi",1);
61 
62  ftotalevents = 0;
63  countLumi_ = 0;
64 
65  beginLumi_ = endLumi_ = -1;
66  endLumi_ = endRun_ = -1;
67 
68  produces<SiPixelDetectorStatus, edm::Transition::EndLuminosityBlock>("siPixelStatus");
69 }
70 
71 //--------------------------------------------------------------------------------------------------
73 
74 }
75 
76 //--------------------------------------------------------------------------------------------------
78 
79  edm::LogInfo("SiPixelStatusProducer")
80  << "beginlumi setup "<<endl;
81 
82  if ( countLumi_ == 0 && resetNLumi_ > 0 ) {
83 
84  beginLumi_ = lumiSeg.luminosityBlock();
85  beginRun_ = lumiSeg.run();
86  ftotalevents = 0;
87 
88  }
89 
90  // The es watcher is acutally not needed if run parallel jobs for each lumi section
91  if(siPixelFedCablingMapWatcher_.check(iSetup)||trackerDIGIGeoWatcher_.check(iSetup)||trackerTopoWatcher_.check(iSetup)){
92 
93  coord_.init(iSetup);
94  iSetup.get<SiPixelFedCablingMapRcd>().get(fCablingMap);
95  fCablingMap_ = fCablingMap.product();
96  iSetup.get<TrackerDigiGeometryRecord>().get(fTG);
97 
98  fFedIds = fCablingMap_->det2fedMap();
99 
100  } // if conditionWatcher_.check(iSetup)
101 
102  // init the SiPixelDetectorStatus fDet and sensor size fSensors in the begining (when countLumi is zero)
103  if(countLumi_ == 0){
104 
105  for (TrackerGeometry::DetContainer::const_iterator it = fTG->dets().begin(); it != fTG->dets().end(); it++){
106 
107  const PixelGeomDetUnit *pgdu = dynamic_cast<const PixelGeomDetUnit*>((*it));
108  if (pgdu == nullptr) continue;
109  DetId detId = (*it)->geographicalId();
110  int detid = detId.rawId();
111 
112  // don't want to use magic number row 80 column 52
113  const PixelTopology* topo = static_cast<const PixelTopology*>(&pgdu->specificTopology());
114  int rowsperroc = topo->rowsperroc();
115  int colsperroc = topo->colsperroc();
116 
117  int nROCrows = pgdu->specificTopology().nrows()/rowsperroc;
118  int nROCcolumns = pgdu->specificTopology().ncolumns()/colsperroc;
119  int nrocs = nROCrows*nROCcolumns;
120 
121  fDet.addModule(detid, nrocs);
122 
123  fSensors[detid] = std::make_pair(rowsperroc,colsperroc);
124  fSensorLayout[detid] = std::make_pair(nROCrows,nROCcolumns);
125 
126  std::map<int, int> rocIdMap;
127  for(int irow = 0; irow<nROCrows; irow++){
128 
129  for(int icol = 0; icol<nROCcolumns; icol++){
130 
131  int dummyOfflineRow = (rowsperroc/2-1) + irow*rowsperroc;
132  int dummeOfflineColumn = (colsperroc/2-1) + icol*colsperroc;
133  // encode irow, icol
134  int key = indexROC(irow,icol,nROCcolumns);
135 
136  int roc(-1), rocR(-1), rocC(-1);
137  onlineRocColRow(detId, dummyOfflineRow, dummeOfflineColumn, roc, rocR, rocC);
138 
139  int value = roc;
140  rocIdMap[key] = value;
141  }
142 
143  }
144 
145  fRocIds[detid] = rocIdMap;
146  }
147 
148  } // init when countLumi = 0
149 
150  FEDerror25_.clear();
151  countLumi_++;
152 
153 }
154 
155 //--------------------------------------------------------------------------------------------------
157 
158  ftotalevents++;
159 
160  edm::LogInfo("SiPixelStatusProducer")
161  << "start cluster analyzer "<<endl;
162 
163  // ----------------------------------------------------------------------
164  // -- Pixel cluster analysis
165  // ----------------------------------------------------------------------
166 
168  if(!iEvent.getByToken(fSiPixelClusterToken_, hClusterColl)){
169  edm::LogWarning("SiPixelStatusProducer") << " edmNew::DetSetVector<SiPixelCluster> "<<fPixelClusterLabel_<<" does not exist!"<<endl;
170  return;
171  }
172 
173  iEvent.getByToken(fSiPixelClusterToken_, hClusterColl);
174 
175  if (hClusterColl.isValid()){
176 
177  for (const auto& clusters: *hClusterColl) { //loop over different clusters in a clusters vector (module)
178  for(const auto& clu: clusters) { // loop over cluster in a given detId (module)
179  int detid = clusters.detId();
180  int rowsperroc = fSensors[detid].first;
181  int colsperroc = fSensors[detid].second;
182 
183  int nROCcolumns = fSensorLayout[detid].second;
184 
185  int roc(-1);
186  std::map<int,int> fRocIds_detid;
187  if(fRocIds.find(detid)!=fRocIds.end()){
188  fRocIds_detid = fRocIds[detid];
189  }
190 
191  const vector<SiPixelCluster::Pixel>& pixvector = clu.pixels();
192  for (unsigned int i = 0; i < pixvector.size(); ++i) {
193 
194  int mr0 = pixvector[i].x; // constant column direction is along x-axis,
195  int mc0 = pixvector[i].y; // constant row direction is along y-axis
196 
197  int irow = mr0/rowsperroc;
198  int icol = mc0/colsperroc;
199 
200  int key = indexROC(irow,icol,nROCcolumns);
201  if(fRocIds_detid.find(key)!=fRocIds_detid.end()){
202  roc = fRocIds_detid[key];
203  }
204 
205  fDet.fillDIGI(detid, roc);
206 
207  }// loop over pixels in a given cluster
208 
209  }// loop over cluster in a given detId (module)
210 
211  }// loop over detId-grouped clusters in cluster detId-grouped clusters-vector
212 
213  } // hClusterColl.isValid()
214  else{
215  edm::LogWarning("SiPixelStatusProducer") << " edmNew::DetSetVector<SiPixelCluster> "<<fPixelClusterLabel_<<" is NOT Valid!"<<endl;
216  }
218 
219  // FEDerror25 per-ROC per-event
220  edm::Handle<PixelFEDChannelCollection> pixelFEDChannelCollectionHandle;
221 
222  // look over different resouces of takens
223  for (const edm::EDGetTokenT<PixelFEDChannelCollection>& tk: theBadPixelFEDChannelsTokens_) {
224 
225  // collection has to exist
226  if (!iEvent.getByToken(tk, pixelFEDChannelCollectionHandle)) {
227  edm::LogWarning("SiPixelStatusProducer") << " PixelFEDChannelCollection with index "<<tk.index()<<" does NOT exist!"<<std::endl;
228  continue;
229  }
230  iEvent.getByToken(tk, pixelFEDChannelCollectionHandle);
231  // collection has to be valid
232  if(!pixelFEDChannelCollectionHandle.isValid()) {
233  edm::LogWarning("SiPixelStatusProducer") << " PixelFEDChannelCollection with index "<<tk.index()<<" is NOT valid!"<<endl;
234  continue;
235  }
236  // FEDerror channels for the current events
237  std::map<int, std::vector<PixelFEDChannel> > tmpFEDerror25;
238  for (const auto& disabledChannels: *pixelFEDChannelCollectionHandle) {
239  //loop over different PixelFED in a PixelFED vector (module)
240  for(const auto& ch: disabledChannels) {
241 
242  DetId detId = disabledChannels.detId();
243  int detid = detId.rawId();
244 
245  if(ftotalevents==1){
246  // FEDerror25 channels for the first event in the lumi section
247  FEDerror25_[detid].push_back(ch);
248  }
249  else tmpFEDerror25[detid].push_back(ch);
250 
251  } // loop over different PixelFED in a PixelFED vector (different channel for a given module)
252 
253  }// loop over different (different DetId) PixelFED vectors in PixelFEDChannelCollection
254 
255  // Compare the current FEDerror list with the first event's FEDerror list
256  // and save the common channels
257  if(!tmpFEDerror25.empty() && !FEDerror25_.empty()){ // non-empty FEDerror lists
258 
259  std::map<int, std::vector<PixelFEDChannel> >::iterator itFEDerror25;
260  for (itFEDerror25 = FEDerror25_.begin(); itFEDerror25 != FEDerror25_.end(); itFEDerror25++) {
261 
262  int detid = itFEDerror25->first;
263  if(tmpFEDerror25.find(detid)!=tmpFEDerror25.end()){
264 
265  std::vector<PixelFEDChannel> chs = itFEDerror25->second;
266  std::vector<PixelFEDChannel> chs_tmp = tmpFEDerror25[detid];
267 
268  std::vector<PixelFEDChannel> chs_common;
269  for(unsigned int ich = 0; ich<chs.size(); ich++){
270 
271  PixelFEDChannel ch = chs[ich];
272  // look over the current FEDerror25 channels, save the common FED channels
273  for(unsigned int ich_tmp = 0; ich_tmp<chs_tmp.size(); ich_tmp++){
274 
275  PixelFEDChannel ch_tmp = chs_tmp[ich_tmp];
276  if((ch.fed == ch_tmp.fed)&&(ch.link==ch_tmp.link)) {// the same FED channel
277  chs_common.push_back(ch); break;
278  }
279  }
280 
281  }
282  // remove the full module from FEDerror25 list if no common channels are left
283  if(chs_common.empty()) FEDerror25_.erase(itFEDerror25);
284  // otherwise replace with the common channels
285  else { FEDerror25_[detid].clear();
286  FEDerror25_[detid] = chs_common;
287  }
288  }
289  else{ // remove the full module from FEDerror25 list if the module doesn't appear in the current event's FEDerror25 list
290  FEDerror25_.erase(itFEDerror25);
291  }
292 
293  }// loop over modules that have FEDerror25 in the first event in the lumi section
294 
295  }// non-empty FEDerror lists
296 
297  } // look over different resouces of takens
298 
299  // no per-event collection put into iEvent
300  // If use produce() function and no collection is put into iEvent, produce() will not run in unScheduled mode
301  // Now since CMSSW_10_1_X, the accumulate() function will run whatsoever in the unScheduled mode
302  // But accumulate() is NOT available and will NOT be available for releases before CMSSW_10_1_X
303 
304 }
305 
306 //--------------------------------------------------------------------------------------------------
308 
309 }
310 
311 //--------------------------------------------------------------------------------------------------
313 
314  edm::LogInfo("SiPixelStatusProducer")
315  << "endlumi producer "<<endl;
316 
317  endLumi_ = lumiSeg.luminosityBlock();
318  endRun_ = lumiSeg.run();
319 
320  // check if countLumi_ is large enough to read out/save data and reset for the next round
321  if ( resetNLumi_ == -1 ) return;
322  if ( countLumi_ < resetNLumi_ ) return;
323 
324  // set the FEDerror25 flag to be true for ROCs send out FEDerror25 for all events in the lumi section
325  if(!FEDerror25_.empty()){
326  std::map<int, std::vector<PixelFEDChannel> >::iterator itFEDerror25;
327  for (itFEDerror25 = FEDerror25_.begin(); itFEDerror25 != FEDerror25_.end(); itFEDerror25++) {
328  int detid = itFEDerror25->first;
329  std::vector<PixelFEDChannel> chs = itFEDerror25->second;
330  for(unsigned int ich = 0; ich<chs.size(); ich++){
331  fDet.fillFEDerror25(detid,chs[ich]);
332  }
333  }
334  }
335 
336  fDet.setRunRange(beginRun_,endRun_);
337  fDet.setLSRange(beginLumi_,endLumi_);
338  fDet.setNevents(ftotalevents);
339 
340  // save result
341  auto result = std::make_unique<SiPixelDetectorStatus>();
342  *result = fDet;
343 
344  // only save for the lumi sections with NON-ZERO events
345  lumiSeg.put(std::move(result), std::string("siPixelStatus"));
346  edm::LogInfo("SiPixelStatusProducer")
347  << "new lumi-based data stored for run "<<beginRun_<<" lumi from "<<beginLumi_<<" to "<<endLumi_<<std::endl;
348 
349  // reset detector status and lumi-counter
350  fDet.resetDetectorStatus();
351  countLumi_=0;
352  ftotalevents=0;
353  FEDerror25_.clear();
354 }
355 
356 //--------------------------------------------------------------------------------------------------
357 void SiPixelStatusProducer::onlineRocColRow(const DetId &detId, int offlineRow, int offlineCol, int &roc, int &row, int &col) {
358 
359  int fedId = fFedIds[detId.rawId()];
360 
361  // from detector to cabling
363  sipixelobjects::DetectorIndex detector; //{detId.rawId(), offlineRow, offlineCol};
364  detector.rawId = detId.rawId(); detector.row = offlineRow; detector.col = offlineCol;
365 
366  SiPixelFrameConverter converter(fCablingMap_, fedId);
367  converter.toCabling(cabling, detector);
368 
369  // then one can construct local pixel
371  loc.dcol = cabling.dcol;
372  loc.pxid = cabling.pxid;
373  // and get local(online) row/column
374  sipixelobjects::LocalPixel locpixel(loc);
375  col = locpixel.rocCol();
376  row = locpixel.rocRow();
377  //sipixelobjects::CablingPathToDetUnit path = {(unsigned int) fedId, (unsigned int)cabling.link, (unsigned int)cabling.roc};
378  //const sipixelobjects::PixelROC *theRoc = fCablingMap->findItem(path);
379  const sipixelobjects::PixelROC *theRoc = converter.toRoc(cabling.link, cabling.roc);
380  roc = theRoc->idInDetUnit();
381 
382  // has to be BPIX; has to be minus side; has to be half module
383  // for phase-I, there is no half module
384  if (detId.subdetId() == PixelSubdetector::PixelBarrel && coord_.side(detId)==1 && coord_.half(detId))
385  {
386  roc += 8;
387  }
388 
389 }
390 
391 //--------------------------------------------------------------------------------------------------
392 int SiPixelStatusProducer::indexROC(int irow, int icol, int nROCcolumns){
393 
394  return int(icol+irow*nROCcolumns);
395 
396  // generate the folling roc index that is going to map with ROC id as
397  // 8 9 10 11 12 13 14 15
398  // 0 1 2 3 4 5 6 7
399 
400 }
401 
402 //--------------------------------------------------------------------------------------------------
403 //edmPythonConfigToCppValidation CalibTracker/SiPixelQuality/python/SiPixelStatusProducer_cfi.py
405  // siPixelStatusProducer
407  {
409  psd0.addUntracked<int>("resetEveryNLumi", 1);
410  psd0.addUntracked<edm::InputTag>("pixelClusterLabel", edm::InputTag("siPixelClusters","","RECO"));
411  psd0.add<std::vector<edm::InputTag>>("badPixelFEDChannelCollections", {
412  edm::InputTag("siPixelDigis"),
413  });
414  desc.add<edm::ParameterSetDescription>("SiPixelStatusProducerParameters", psd0);
415  }
416  descriptions.add("siPixelStatusProducer", desc);
417 
418 }
419 
420 
T getParameter(std::string const &) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual int nrows() const =0
unsigned int fed
virtual int rowsperroc() const =0
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
void accumulate(edm::Event const &, const edm::EventSetup &iSetup) final
SiPixelStatusProducer(const edm::ParameterSet &)
unsigned int link
identify pixel inside single ROC
Definition: LocalPixel.h:7
LuminosityBlockNumber_t luminosityBlock() const
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
virtual int colsperroc() const =0
void put(std::unique_ptr< PROD > product)
Put a new product.
virtual void onlineRocColRow(const DetId &detId, int offlineRow, int offlineCol, int &roc, int &row, int &col) final
unsigned int idInDetUnit() const
id of this ROC in DetUnit etermined by token path
Definition: PixelROC.h:40
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
RunNumber_t run() const
Definition: value.py:1
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
double collumn and pixel ID in double collumn representation
Definition: LocalPixel.h:22
Definition: DetId.h:18
int toCabling(sipixelobjects::ElectronicIndex &cabling, const sipixelobjects::DetectorIndex &detector) const
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, const edm::EventSetup &iSetup) final
virtual int ncolumns() const =0
sipixelobjects::PixelROC const * toRoc(int link, int roc) const
T get() const
Definition: EventSetup.h:71
col
Definition: cuy.py:1010
virtual int indexROC(int irow, int icol, int nROCcolumns) final
void endLuminosityBlockProduce(edm::LuminosityBlock &lumiSeg, const edm::EventSetup &iSetup) final
def move(src, dest)
Definition: eostools.py:511
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, const edm::EventSetup &iSetup) final