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  countLumi_++;
156 
157 }
158 
159 //--------------------------------------------------------------------------------------------------
161 
162  ftotalevents++;
163 
164  edm::LogInfo("SiPixelStatusProducer")
165  << "start cluster analyzer "<<endl;
166 
167  // ----------------------------------------------------------------------
168  // -- Pixel cluster analysis
169  // ----------------------------------------------------------------------
170 
172  if(!iEvent.getByToken(fSiPixelClusterToken_, hClusterColl)){
173  edm::LogWarning("SiPixelStatusProducer") << " edmNew::DetSetVector<SiPixelCluster> "<<fPixelClusterLabel_<<" does not exist!"<<endl;
174  return;
175  }
176 
177  iEvent.getByToken(fSiPixelClusterToken_, hClusterColl);
178 
179  if (hClusterColl.isValid()){
180 
181  for (const auto& clusters: *hClusterColl) { //loop over different clusters in a clusters vector (module)
182  for(const auto& clu: clusters) { // loop over cluster in a given detId (module)
183  int detid = clusters.detId();
184  int rowsperroc = fSensors[detid].first;
185  int colsperroc = fSensors[detid].second;
186 
187  int nROCcolumns = fSensorLayout[detid].second;
188 
189  int roc(-1);
190  std::map<int,int> fRocIds_detid;
191  if(fRocIds.find(detid)!=fRocIds.end()){
192  fRocIds_detid = fRocIds[detid];
193  }
194 
195  const vector<SiPixelCluster::Pixel>& pixvector = clu.pixels();
196  for (unsigned int i = 0; i < pixvector.size(); ++i) {
197 
198  int mr0 = pixvector[i].x; // constant column direction is along x-axis,
199  int mc0 = pixvector[i].y; // constant row direction is along y-axis
200 
201  int irow = mr0/rowsperroc;
202  int icol = mc0/colsperroc;
203 
204  int key = indexROC(irow,icol,nROCcolumns);
205  if(fRocIds_detid.find(key)!=fRocIds_detid.end()){
206  roc = fRocIds_detid[key];
207  }
208 
209  fDet.fillDIGI(detid, roc);
210 
211  }// loop over pixels in a given cluster
212 
213  }// loop over cluster in a given detId (module)
214 
215  }// loop over detId-grouped clusters in cluster detId-grouped clusters-vector
216 
217  } // hClusterColl.isValid()
218  else{
219  edm::LogWarning("SiPixelStatusProducer") << " edmNew::DetSetVector<SiPixelCluster> "<<fPixelClusterLabel_<<" is NOT Valid!"<<endl;
220  }
222 
223  // FEDerror25 per-ROC per-event
224  edm::Handle<PixelFEDChannelCollection> pixelFEDChannelCollectionHandle;
225 
226  // look over different resouces of takens
227  for (const edm::EDGetTokenT<PixelFEDChannelCollection>& tk: theBadPixelFEDChannelsTokens_) {
228 
229  // collection has to exist
230  if (!iEvent.getByToken(tk, pixelFEDChannelCollectionHandle)) {
231  edm::LogWarning("SiPixelStatusProducer") << " PixelFEDChannelCollection with index "<<tk.index()<<" does NOT exist!"<<endl;
232  continue;
233  }
234  iEvent.getByToken(tk, pixelFEDChannelCollectionHandle);
235  // collection has to be valid
236  if(!pixelFEDChannelCollectionHandle.isValid()) {
237  edm::LogWarning("SiPixelStatusProducer") << " PixelFEDChannelCollection with index "<<tk.index()<<" is NOT valid!"<<endl;
238  continue;
239  }
240  for (const auto& disabledChannels: *pixelFEDChannelCollectionHandle) {
241  //loop over different PixelFED in a PixelFED vector (module)
242  for(const auto& ch: disabledChannels) {
243 
244  DetId detId = disabledChannels.detId();
245  int detid = detId.rawId();
246  fDet.fillFEDerror25(detid,ch);
247 
248  } // loop over different PixelFED in a PixelFED vector (different channel for a given module)
249 
250  }// loop over different (different DetId) PixelFED vectors in PixelFEDChannelCollection
251 
252  } // look over different resouces of takens
253 
254  // no per-event collection put into iEvent
255  // If use produce() function and no collection is put into iEvent, produce() will not run in unScheduled mode
256  // Now since CMSSW_10_1_X, the accumulate() function will run whatsoever in the unScheduled mode
257  // But accumulate() is NOT available and will NOT be available for releases before CMSSW_10_1_X
258 
259 }
260 
261 //--------------------------------------------------------------------------------------------------
263 
264 }
265 
266 //--------------------------------------------------------------------------------------------------
268 
269  edm::LogInfo("SiPixelStatusProducer")
270  << "endlumi producer "<<endl;
271 
272  endLumi_ = lumiSeg.luminosityBlock();
273  endRun_ = lumiSeg.run();
274 
275  // check if countLumi_ is large enough to read out/save data and reset for the next round
276  if ( resetNLumi_ == -1 ) return;
277  if ( countLumi_ < resetNLumi_ ) return;
278 
279  fDet.setRunRange(beginRun_,endRun_);
280  fDet.setLSRange(beginLumi_,endLumi_);
281  fDet.setNevents(ftotalevents);
282 
283  // save result
284  auto result = std::make_unique<SiPixelDetectorStatus>();
285  *result = fDet;
286 
287  // only save for the lumi sections with NON-ZERO events
288  lumiSeg.put(std::move(result), std::string("siPixelStatus"));
289  edm::LogInfo("SiPixelStatusProducer")
290  << "new lumi-based data stored for run "<<beginRun_<<" lumi from "<<beginLumi_<<" to "<<endLumi_<<std::endl;
291 
292  // reset detector status and lumi-counter
293  fDet.resetDetectorStatus();
294  countLumi_=0;
295  ftotalevents=0;
296 
297 }
298 
299 //--------------------------------------------------------------------------------------------------
300 void SiPixelStatusProducer::onlineRocColRow(const DetId &detId, int offlineRow, int offlineCol, int &roc, int &row, int &col) {
301 
302  int fedId = fFedIds[detId.rawId()];
303 
304  // from detector to cabling
306  sipixelobjects::DetectorIndex detector; //{detId.rawId(), offlineRow, offlineCol};
307  detector.rawId = detId.rawId(); detector.row = offlineRow; detector.col = offlineCol;
308 
309  SiPixelFrameConverter converter(fCablingMap_, fedId);
310  converter.toCabling(cabling, detector);
311 
312  // then one can construct local pixel
314  loc.dcol = cabling.dcol;
315  loc.pxid = cabling.pxid;
316  // and get local(online) row/column
317  sipixelobjects::LocalPixel locpixel(loc);
318  col = locpixel.rocCol();
319  row = locpixel.rocRow();
320  //sipixelobjects::CablingPathToDetUnit path = {(unsigned int) fedId, (unsigned int)cabling.link, (unsigned int)cabling.roc};
321  //const sipixelobjects::PixelROC *theRoc = fCablingMap->findItem(path);
322  const sipixelobjects::PixelROC *theRoc = converter.toRoc(cabling.link, cabling.roc);
323  roc = theRoc->idInDetUnit();
324 
325  // has to be BPIX; has to be minus side; has to be half module
326  // for phase-I, there is no half module
327  if (detId.subdetId() == PixelSubdetector::PixelBarrel && coord_.side(detId)==1 && coord_.half(detId))
328  {
329  roc += 8;
330  }
331 
332 }
333 
334 //--------------------------------------------------------------------------------------------------
335 int SiPixelStatusProducer::indexROC(int irow, int icol, int nROCcolumns){
336 
337  return int(icol+irow*nROCcolumns);
338 
339  // generate the folling roc index that is going to map with ROC id as
340  // 8 9 10 11 12 13 14 15
341  // 0 1 2 3 4 5 6 7
342 
343 }
344 
T getParameter(std::string const &) const
virtual int nrows() const =0
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 &)
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