CMS 3D CMS Logo

SiPixelOfflineCalibAnalysisBase.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiPixelOfflineCalibAnalysisBase
4 // Class: SiPixelOfflineCalibAnalysisBase
5 //
13 //
14 // Original Author: Evan Klose Friis
15 // additions by: Freya Blekman
16 // Created: Tue Nov 6 17:27:19 CET 2007
17 //
18 //
19 
21 
25 
30 #include "TList.h"
31 
34 // constructors and destructor
35 //
37 {
38  siPixelCalibDigiProducer_ = iConfig.getParameter<edm::InputTag>("DetSetVectorSiPixelCalibDigiTag");
39  createOutputFile_ = iConfig.getUntrackedParameter<bool>("saveFile",false);
40  outputFileName_ = iConfig.getParameter<std::string>("outputFileName");
43  tPixelCalibDigi = consumes <edm::DetSetVector<SiPixelCalibDigi> > (siPixelCalibDigiProducer_);
44 
45 }
46 
48 {
49  throw cms::Exception("") << "ERROR: Classes derived from SiPixelOfflineCalibAnalysisBase must call SiPixelOfflineCalibAnalysisBase::SiPixelOfflineCalibAnalysisBase(const edm::ParameterSet& iConfig) from their constructor." << std::endl;
50 }
51 
53 {
54 }
55 
56 
57 //
58 // member functions
59 //
60 
61 // ------------ method called to for each event ------------
62 void
64 {
65  using namespace edm;
66 
67  iSetup.get<TrackerDigiGeometryRecord>().get( geom_ );
70  if(eventCounter_==0)
71  this->calibrationSetup(iSetup);
72  eventCounter_++;
73 
74  // check first if you're analyzing the right type of calibration
76  return;
77 
78  uint32_t runnumber=iEvent.id().run();
79  if(runnumbers_.empty())
80  runnumbers_.push_back(runnumber);
81  else{
82  bool foundnumber=false;
83  for(size_t iter=0; iter<runnumbers_.size() && !foundnumber; ++ iter){
84  if(runnumbers_[iter]==runnumber){
85  foundnumber=true;
86  continue;
87  }
88  }
89  if(!foundnumber)
90  runnumbers_.push_back(runnumber);
91  }
92 
94  iEvent.getByToken( tPixelCalibDigi, thePlaquettes);
95 
97 
98  //loop over the plaquettes pulsed in this pattern
99  for(digiIter=thePlaquettes->begin(); digiIter!=thePlaquettes->end(); ++digiIter)
100  {
101  uint32_t detId = digiIter->id;
102  //check to see if this detID has not been encountered. If not, run the newDetID (pure virtual) function
103  if (detIdsEntered_.find(detId) == detIdsEntered_.end())
104  {
105  detIdsEntered_.insert(std::make_pair(detId, 0));
106  detIdNames_.insert(std::make_pair(detId, translateDetIdToString(detId)));
107  newDetID(detId);
108  }
110  //loop over pixels pulsed in the current plaquette
111  for(ipix=digiIter->data.begin(); ipix!=digiIter->end(); ++ipix)
112  {
113  //called derived function to fit this curve
114  this->doFits(detId, ipix);
115  }
116  }
117 
118 }
119 
121 {
122  //load the calibration information from the database
123  iSetup.get<SiPixelCalibConfigurationRcd>().get(calib_);
124  iSetup.get<TrackerDigiGeometryRecord>().get( geom_ );
126 
130  std::cout << "!!!! in beginRun" << std::endl;
131  edm::LogInfo("SiPixelOfflineCalibAnalysisBase") << "Calibration file loaded. Mode: " << calibrationMode_ << " nTriggers: " << nTriggers_ << " Vcal steps: " << vCalValues_.size() << std::endl;
132  //call calibrationSetup virtual function
133  this->calibrationSetup(iSetup);
135 }
136 void
138 {
139 
140 }
141 // ------------ method called once each job just before starting event loop ------------
142 
143 // ------------ method called once each job just after ending the event loop ------------
144 void
146  this->calibrationEnd();
147  edm::LogInfo("SiPixelOfflineCalibAnalysisBase") << "Running end job... output file name is: " << outputFileName_;
148  if (!outputFileName_.empty() && createOutputFile_)
149  {
150  edm::LogInfo("SiPixelOfflineCalibAnalysisBase") << "Writing ROOT file to: " << outputFileName_ << std::endl;
151  daqBE_->save(outputFileName_);
152  }
153 }
154 
155 // ------------ helper functions ---------------------------------------------------------
156 
157 const std::vector<short>*
159 {
160  return &vCalValues_;
161 }
162 
165 {
166  std::map<uint32_t, std::string>::iterator detNameIter = detIdNames_.find(detid);
167  if (detNameIter != detIdNames_.end()) {
168  return detNameIter->second;
169  }
170  std::string output = "DetID translation error";
171  DetId detId(detid);
172  uint32_t detSubId = detId.subdetId();
173  if (detSubId > 2 || detSubId < 1)
174  {
175  edm::LogError("SiPixelOfflineCalibAnalysisBase") << "ERROR: Expected a pixel detector ID (1 - barrel, 2 - forward) but got " << detSubId << std::endl;
176  return output;
177  }
178  if (detSubId == 2) //FPIX
179  {
180  PixelEndcapName nameworker(detid);
181  output = nameworker.name();
182  } else //BPIX
183  {
184  PixelBarrelName nameworker(detid);
185  output = nameworker.name();
186  }
187  detIdNames_.insert(std::make_pair(detid, output));
188  return output;
189 }
190 
192 {
193  std::string hid = theHistogramIdWorker_->setHistoId(name,detid);
194  return daqBE_->book1D(hid, title, nchX, lowX, highX);
195 }
196 
198 {
199  std::string hid = theHistogramIdWorker_->setHistoId(name,detid);
200  return daqBE_->book1D(hid, title, nchX, xbinsize);
201 }
202 
203 MonitorElement* SiPixelOfflineCalibAnalysisBase::bookDQMHistogram2D(uint32_t detid, std::string name, std::string title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
204 {
205  std::string hid = theHistogramIdWorker_->setHistoId(name,detid);
206  return daqBE_->book2D(hid, title, nchX, lowX, highX, nchY, lowY, highY);
207 }
208 
210  DetId detId(detid);
211  const TrackerGeometry &theTracker(*geom_);
212  const PixelGeomDetUnit *theGeomDet = dynamic_cast<const PixelGeomDetUnit*> ( theTracker.idToDet(detId) );
213  int maxcol = theGeomDet->specificTopology().ncolumns();
214  int maxrow = theGeomDet->specificTopology().nrows();
215 
216 
217  std::string hid = theHistogramIdWorker_->setHistoId(name,detid);
218  return daqBE_->book2D(hid,title,maxcol,0,maxcol,maxrow,0,maxrow);
219 }
220 
221 bool
223 {
224  daqBE_->setCurrentFolder(dirName);
225  return daqBE_->dirExists(dirName);
226 }
227 
228 bool
230 {
231  return folderMaker_->setModuleFolder(detID,0);
232 }
233 
234 
235 // ------------ virtual functions ------------------------------------------------
236 bool
238 {
239  return true;
240 }
241 
242 bool
243 SiPixelOfflineCalibAnalysisBase::doFits(uint32_t detid, std::vector<SiPixelCalibDigi>::const_iterator ipix)
244 {
245  short row=ipix->row();
246  short col=ipix->col();
247  std::vector<uint8_t> nentries = ipix->getnentries();
248  std::vector<uint32_t> sum = ipix->getsum();
249  std::vector<uint32_t> sumquares = ipix->getsumsquares();
250  //do nothing
251  //return false;
252  //
253  //DEBUG
254  std::cout << "Row: " << row << " Col: " << col << std::endl;
255  for (unsigned int i = 0; i < sum.size(); i++)
256  {
257  std::cout << sum[i] << " ";
258  }
259  std::cout << std::endl;
260  return false;
261 
262 }
263 
264 void
266 {
267  //do nothing
268 }
269 
271 {
272  // do nothing
273 }
274 void
276 {
277  //do nothing
278  edm::LogInfo("SiPixelOfflineCalibAnalysisBase") << "SiPixelOfflineCalibAnalysisBase - Found new DetID: " << detid << " Name: " << detIdNames_[detid];
279 }
280 
281 bool
282 SiPixelOfflineCalibAnalysisBase::checkPixel(uint32_t detid,short row, short col)
283 {
284  // finds the fed ID:
285  int thefedid = -1;
286  for(int fedid=0; fedid<=40 && thefedid==-1; ++fedid)
287  {
289  if(converter.hasDetUnit(detid))
290  {
291  thefedid=fedid;
292  }
293  }
294  if(thefedid==-1)
295  return false; // fed ID not associated with det ID. No pattern check possible
296 
297  SiPixelFrameConverter formatter(theCablingMap_.product(),thefedid);
298  sipixelobjects::DetectorIndex detector ={detid, row, col};
300 
301  formatter.toCabling(cabling,detector);
302  // cabling should now contain cabling.roc and cabling.dcol and cabling.pxid
303 
304  // however, the coordinates now need to be converted from dcl, pxid to the row,col coordinates used in the calibration info
306  loc.dcol = cabling.dcol;
307  loc.pxid = cabling.pxid;
308  sipixelobjects::LocalPixel locpixel(loc);
309  short localrow = locpixel.rocRow();
310  short localcol = locpixel.rocCol();
311 
312  // now get the patterns from the calib object:
313  std::vector<short> calibcols = calib_->getColumnPattern();
314  std::vector<short> calibrows = calib_->getRowPattern();
315  // first check rows:
316  for(size_t irow=0; irow<calibrows.size(); ++irow)
317  {
318  if(calibrows[irow]==localrow)
319  {
320  // check the columns
321  for(size_t icol=0; icol<calibcols.size(); ++icol)
322  {
323  if(calibcols[icol]==localcol)
324  return true;
325  }
326  }
327  }
328 
329  return false;
330 }
331 
332 // function to add tf1's to ME's:
334 
335  if(func){
336  ele->getTH1()->GetListOfFunctions()->Add(func);
337  }
338  return;
339 }
340 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void beginRun(const edm::Run &, const edm::EventSetup &) override
virtual int nrows() const =0
std::vector< short > getRowPattern() const
edm::ESHandle< SiPixelCalibConfiguration > calib_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
TH1 * getTH1() const
std::map< uint32_t, std::string > detIdNames_
std::string translateDetIdToString(uint32_t detid)
MonitorElement * bookDQMHistoPlaquetteSummary2D(uint32_t detid, std::string name, std::string title)
identify pixel inside single ROC
Definition: LocalPixel.h:7
std::string name() const override
from base class
edm::ESHandle< TrackerGeometry > geom_
virtual void calibrationSetup(const edm::EventSetup &iSetup)
int iEvent
Definition: GenABIO.cc:230
bool setModuleFolder(const uint32_t &rawdetid=0, int type=0, bool isUpgrade=false)
Set folder name for a module or plaquette.
MonitorElement * bookDQMHistogram1D(uint32_t detid, std::string name, std::string title, int nchX, double lowX, double highX)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
std::string name() const override
from base class
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:361
double collumn and pixel ID in double collumn representation
Definition: LocalPixel.h:22
std::string setHistoId(std::string variable, uint32_t &rawId)
Set Histogram Id.
Definition: DetId.h:18
void analyze(const edm::Event &, const edm::EventSetup &) override
std::vector< short > getColumnPattern() const
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
std::string const & label() const
Definition: InputTag.h:36
std::string getCalibrationMode() const
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
virtual int ncolumns() const =0
virtual bool doFits(uint32_t detid, std::vector< SiPixelCalibDigi >::const_iterator ipix)
T get() const
Definition: EventSetup.h:68
const std::vector< short > getVCalValues() const
col
Definition: cuy.py:1010
const TrackerGeomDet * idToDet(DetId) const override
static const std::vector< short > * getVcalValues()
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:346
bool checkPixel(uint32_t detid, short row, short column)
void addTF1ToDQMMonitoringElement(MonitorElement *ele, TF1 *func)
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:104
edm::ESHandle< SiPixelFedCablingMap > theCablingMap_
T const * product() const
Definition: ESHandle.h:84
MonitorElement * bookDQMHistogram2D(uint32_t detid, std::string name, std::string title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
edm::EDGetTokenT< edm::DetSetVector< SiPixelCalibDigi > > tPixelCalibDigi
Definition: Run.h:44