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 
23 
26 
31 #include "TList.h"
32 
35 // constructors and destructor
36 //
38  : runnumbers_(0), eventCounter_(0) {
39  siPixelCalibDigiProducer_ = iConfig.getParameter<edm::InputTag>("DetSetVectorSiPixelCalibDigiTag");
40  createOutputFile_ = iConfig.getUntrackedParameter<bool>("saveFile", false);
41  outputFileName_ = iConfig.getParameter<std::string>("outputFileName");
44  tPixelCalibDigi = consumes<edm::DetSetVector<SiPixelCalibDigi> >(siPixelCalibDigiProducer_);
45 
47  esConsumes<SiPixelCalibConfiguration, SiPixelCalibConfigurationRcd, edm::Transition::BeginRun>();
48  calibToken_ = esConsumes<SiPixelCalibConfiguration, SiPixelCalibConfigurationRcd>();
49  trackerGeomToken_ = esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>();
50  cablingMapToken_ = esConsumes<SiPixelFedCablingMap, SiPixelFedCablingMapRcd>();
51 }
52 
54  throw cms::Exception("") << "ERROR: Classes derived from SiPixelOfflineCalibAnalysisBase must call "
55  "SiPixelOfflineCalibAnalysisBase::SiPixelOfflineCalibAnalysisBase(const "
56  "edm::ParameterSet& iConfig) from their constructor."
57  << std::endl;
58 }
59 
61 
62 //
63 // member functions
64 //
65 
66 // ------------ method called to for each event ------------
68  using namespace edm;
69 
70  calib_ = iSetup.getHandle(calibToken_);
73  if (eventCounter_ == 0)
74  this->calibrationSetup(iSetup);
75  eventCounter_++;
76 
77  // check first if you're analyzing the right type of calibration
79  return;
80 
81  uint32_t runnumber = iEvent.id().run();
82  if (runnumbers_.empty())
83  runnumbers_.push_back(runnumber);
84  else {
85  bool foundnumber = false;
86  for (size_t iter = 0; iter < runnumbers_.size() && !foundnumber; ++iter) {
87  if (runnumbers_[iter] == runnumber) {
88  foundnumber = true;
89  continue;
90  }
91  }
92  if (!foundnumber)
93  runnumbers_.push_back(runnumber);
94  }
95 
97  iEvent.getByToken(tPixelCalibDigi, thePlaquettes);
98 
100 
101  //loop over the plaquettes pulsed in this pattern
102  for (digiIter = thePlaquettes->begin(); digiIter != thePlaquettes->end(); ++digiIter) {
103  uint32_t detId = digiIter->id;
104  //check to see if this detID has not been encountered. If not, run the newDetID (pure virtual) function
105  if (detIdsEntered_.find(detId) == detIdsEntered_.end()) {
106  detIdsEntered_.insert(std::make_pair(detId, 0));
107  detIdNames_.insert(std::make_pair(detId, translateDetIdToString(detId)));
108  newDetID(detId);
109  }
111  //loop over pixels pulsed in the current plaquette
112  for (ipix = digiIter->data.begin(); ipix != digiIter->end(); ++ipix) {
113  //called derived function to fit this curve
114  this->doFits(detId, ipix);
115  }
116  }
117 }
118 
120  //load the calibration information from the database
122 
123  calibrationMode_ = calib->getCalibrationMode();
124  nTriggers_ = calib->getNTriggers();
125  vCalValues_ = calib->getVCalValues();
126  std::cout << "!!!! in beginRun" << std::endl;
127  edm::LogInfo("SiPixelOfflineCalibAnalysisBase")
128  << "Calibration file loaded. Mode: " << calibrationMode_ << " nTriggers: " << nTriggers_
129  << " Vcal steps: " << vCalValues_.size() << std::endl;
130  //call calibrationSetup virtual function
131  this->calibrationSetup(iSetup);
133 }
134 
136 
138 // ------------ method called once each job just before starting event loop ------------
139 
140 // ------------ method called once each job just after ending the event loop ------------
142  this->calibrationEnd();
143  edm::LogInfo("SiPixelOfflineCalibAnalysisBase") << "Running end job... output file name is: " << outputFileName_;
144  if (!outputFileName_.empty() && createOutputFile_) {
145  edm::LogInfo("SiPixelOfflineCalibAnalysisBase") << "Writing ROOT file to: " << outputFileName_ << std::endl;
147  }
148 }
149 
150 // ------------ helper functions ---------------------------------------------------------
151 
152 const std::vector<short>* SiPixelOfflineCalibAnalysisBase::getVcalValues() { return &vCalValues_; }
153 
155  std::map<uint32_t, std::string>::iterator detNameIter = detIdNames_.find(detid);
156  if (detNameIter != detIdNames_.end()) {
157  return detNameIter->second;
158  }
159  std::string output = "DetID translation error";
160  DetId detId(detid);
161  uint32_t detSubId = detId.subdetId();
162  if (detSubId > 2 || detSubId < 1) {
163  edm::LogError("SiPixelOfflineCalibAnalysisBase")
164  << "ERROR: Expected a pixel detector ID (1 - barrel, 2 - forward) but got " << detSubId << std::endl;
165  return output;
166  }
167  if (detSubId == 2) //FPIX
168  {
169  PixelEndcapName nameworker(detid);
170  output = nameworker.name();
171  } else //BPIX
172  {
173  PixelBarrelName nameworker(detid);
174  output = nameworker.name();
175  }
176  detIdNames_.insert(std::make_pair(detid, output));
177  return output;
178 }
179 
181  uint32_t detid, std::string name, std::string title, int nchX, double lowX, double highX) {
183  return daqBE_->book1D(hid, title, nchX, lowX, highX);
184 }
185 
187  uint32_t detid, std::string name, std::string title, int nchX, float* xbinsize) {
189  return daqBE_->book1D(hid, title, nchX, xbinsize);
190 }
191 
195  int nchX,
196  double lowX,
197  double highX,
198  int nchY,
199  double lowY,
200  double highY) {
202  return daqBE_->book2D(hid, title, nchX, lowX, highX, nchY, lowY, highY);
203 }
204 
206  uint32_t detid, std::string name, std::string title) {
207  DetId detId(detid);
208  const TrackerGeometry& theTracker(*geom_);
209  const PixelGeomDetUnit* theGeomDet = dynamic_cast<const PixelGeomDetUnit*>(theTracker.idToDet(detId));
210  int maxcol = theGeomDet->specificTopology().ncolumns();
211  int maxrow = theGeomDet->specificTopology().nrows();
212 
214  return daqBE_->book2D(hid, title, maxcol, 0, maxcol, maxrow, 0, maxrow);
215 }
216 
219  return daqBE_->dirExists(dirName);
220 }
221 
223  return folderMaker_->setModuleFolder(detID, 0);
224 }
225 
226 // ------------ virtual functions ------------------------------------------------
228 
229 bool SiPixelOfflineCalibAnalysisBase::doFits(uint32_t detid, std::vector<SiPixelCalibDigi>::const_iterator ipix) {
230  short row = ipix->row();
231  short col = ipix->col();
232  std::vector<uint8_t> nentries = ipix->getnentries();
233  std::vector<uint32_t> sum = ipix->getsum();
234  std::vector<uint32_t> sumquares = ipix->getsumsquares();
235  //do nothing
236  //return false;
237  //
238  //DEBUG
239  std::cout << "Row: " << row << " Col: " << col << std::endl;
240  for (unsigned int i = 0; i < sum.size(); i++) {
241  std::cout << sum[i] << " ";
242  }
243  std::cout << std::endl;
244  return false;
245 }
246 
248  //do nothing
249 }
250 
252  // do nothing
253 }
255  //do nothing
256  edm::LogInfo("SiPixelOfflineCalibAnalysisBase")
257  << "SiPixelOfflineCalibAnalysisBase - Found new DetID: " << detid << " Name: " << detIdNames_[detid];
258 }
259 
260 bool SiPixelOfflineCalibAnalysisBase::checkPixel(uint32_t detid, short row, short col) {
261  // finds the fed ID:
262  int thefedid = -1;
263  for (int fedid = 0; fedid <= 40 && thefedid == -1; ++fedid) {
265  if (converter.hasDetUnit(detid)) {
266  thefedid = fedid;
267  }
268  }
269  if (thefedid == -1)
270  return false; // fed ID not associated with det ID. No pattern check possible
271 
272  SiPixelFrameConverter formatter(theCablingMap_.product(), thefedid);
275 
276  formatter.toCabling(cabling, detector);
277  // cabling should now contain cabling.roc and cabling.dcol and cabling.pxid
278 
279  // however, the coordinates now need to be converted from dcl, pxid to the row,col coordinates used in the calibration info
281  loc.dcol = cabling.dcol;
282  loc.pxid = cabling.pxid;
283  sipixelobjects::LocalPixel locpixel(loc);
284  short localrow = locpixel.rocRow();
285  short localcol = locpixel.rocCol();
286 
287  // now get the patterns from the calib object:
288  std::vector<short> calibcols = calib_->getColumnPattern();
289  std::vector<short> calibrows = calib_->getRowPattern();
290  // first check rows:
291  for (size_t irow = 0; irow < calibrows.size(); ++irow) {
292  if (calibrows[irow] == localrow) {
293  // check the columns
294  for (size_t icol = 0; icol < calibcols.size(); ++icol) {
295  if (calibcols[icol] == localcol)
296  return true;
297  }
298  }
299  }
300 
301  return false;
302 }
303 
304 // function to add tf1's to ME's:
306  if (func) {
307  ele->getTH1()->GetListOfFunctions()->Add(func);
308  }
309  return;
310 }
void beginRun(const edm::Run &, const edm::EventSetup &) override
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void endRun(const edm::Run &, const edm::EventSetup &) override
edm::ESHandle< SiPixelCalibConfiguration > calib_
virtual int ncolumns() const =0
std::vector< short > getColumnPattern() const
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:646
virtual bool dirExists(std::string const &path) const
Definition: DQMStore.cc:769
virtual int nrows() const =0
std::vector< short > getRowPattern() const
std::map< uint32_t, std::string > detIdNames_
std::string const & label() const
Definition: InputTag.h:36
std::string translateDetIdToString(uint32_t detid)
Log< level::Error, false > LogError
identify pixel inside single ROC
Definition: LocalPixel.h:7
edm::ESGetToken< SiPixelCalibConfiguration, SiPixelCalibConfigurationRcd > calibToken_
T getUntrackedParameter(std::string const &, T const &) const
MonitorElement * bookDQMHistogram1D(uint32_t detid, std::string name, std::string title, int nchX, double lowX, double highX)
edm::ESHandle< TrackerGeometry > geom_
virtual void calibrationSetup(const edm::EventSetup &iSetup)
int iEvent
Definition: GenABIO.cc:224
T const * product() const
Definition: ESHandle.h:86
std::string name() const override
from base class
bool setModuleFolder(const uint32_t &rawdetid=0, int type=0, bool isUpgrade=false)
Set folder name for a module or plaquette.
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerGeomToken_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
const TrackerGeomDet * idToDet(DetId) const override
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:316
double collumn and pixel ID in double collumn representation
Definition: LocalPixel.h:19
MonitorElement * bookDQMHistoPlaquetteSummary2D(uint32_t detid, std::string name, std::string title)
std::string setHistoId(std::string variable, uint32_t &rawId)
Set Histogram Id.
Log< level::Info, false > LogInfo
Definition: DetId.h:17
void analyze(const edm::Event &, const edm::EventSetup &) override
std::string name() const override
from base class
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
edm::ESGetToken< SiPixelFedCablingMap, SiPixelFedCablingMapRcd > cablingMapToken_
edm::ESGetToken< SiPixelCalibConfiguration, SiPixelCalibConfigurationRcd > calibTokenBeginRun_
virtual TH1 * getTH1() const
DQM_DEPRECATED void save(std::string const &filename, std::string const &path="")
Definition: DQMStore.cc:824
HLT enums.
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
virtual bool doFits(uint32_t detid, std::vector< SiPixelCalibDigi >::const_iterator ipix)
col
Definition: cuy.py:1009
static const std::vector< short > * getVcalValues()
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:305
Definition: output.py:1
bool checkPixel(uint32_t detid, short row, short column)
MonitorElement * bookDQMHistogram2D(uint32_t detid, std::string name, std::string title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
void addTF1ToDQMMonitoringElement(MonitorElement *ele, TF1 *func)
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
collection_type::const_iterator const_iterator
Definition: DetSet.h:31
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
edm::ESHandle< SiPixelFedCablingMap > theCablingMap_
edm::EDGetTokenT< edm::DetSetVector< SiPixelCalibDigi > > tPixelCalibDigi
Definition: Run.h:45