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