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  : runnumbers_(0), eventCounter_(0) {
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 
47  throw cms::Exception("") << "ERROR: Classes derived from SiPixelOfflineCalibAnalysisBase must call "
48  "SiPixelOfflineCalibAnalysisBase::SiPixelOfflineCalibAnalysisBase(const "
49  "edm::ParameterSet& iConfig) from their constructor."
50  << std::endl;
51 }
52 
54 
55 //
56 // member functions
57 //
58 
59 // ------------ method called to for each event ------------
61  using namespace edm;
62 
63  iSetup.get<TrackerDigiGeometryRecord>().get(geom_);
66  if (eventCounter_ == 0)
67  this->calibrationSetup(iSetup);
68  eventCounter_++;
69 
70  // check first if you're analyzing the right type of calibration
72  return;
73 
74  uint32_t runnumber = iEvent.id().run();
75  if (runnumbers_.empty())
76  runnumbers_.push_back(runnumber);
77  else {
78  bool foundnumber = false;
79  for (size_t iter = 0; iter < runnumbers_.size() && !foundnumber; ++iter) {
80  if (runnumbers_[iter] == runnumber) {
81  foundnumber = true;
82  continue;
83  }
84  }
85  if (!foundnumber)
86  runnumbers_.push_back(runnumber);
87  }
88 
90  iEvent.getByToken(tPixelCalibDigi, thePlaquettes);
91 
93 
94  //loop over the plaquettes pulsed in this pattern
95  for (digiIter = thePlaquettes->begin(); digiIter != thePlaquettes->end(); ++digiIter) {
96  uint32_t detId = digiIter->id;
97  //check to see if this detID has not been encountered. If not, run the newDetID (pure virtual) function
98  if (detIdsEntered_.find(detId) == detIdsEntered_.end()) {
99  detIdsEntered_.insert(std::make_pair(detId, 0));
100  detIdNames_.insert(std::make_pair(detId, translateDetIdToString(detId)));
101  newDetID(detId);
102  }
104  //loop over pixels pulsed in the current plaquette
105  for (ipix = digiIter->data.begin(); ipix != digiIter->end(); ++ipix) {
106  //called derived function to fit this curve
107  this->doFits(detId, ipix);
108  }
109  }
110 }
111 
113  //load the calibration information from the database
114  iSetup.get<SiPixelCalibConfigurationRcd>().get(calib_);
115  iSetup.get<TrackerDigiGeometryRecord>().get(geom_);
117 
121  std::cout << "!!!! in beginRun" << std::endl;
122  edm::LogInfo("SiPixelOfflineCalibAnalysisBase")
123  << "Calibration file loaded. Mode: " << calibrationMode_ << " nTriggers: " << nTriggers_
124  << " Vcal steps: " << vCalValues_.size() << std::endl;
125  //call calibrationSetup virtual function
126  this->calibrationSetup(iSetup);
128 }
130 // ------------ method called once each job just before starting event loop ------------
131 
132 // ------------ method called once each job just after ending the event loop ------------
134  this->calibrationEnd();
135  edm::LogInfo("SiPixelOfflineCalibAnalysisBase") << "Running end job... output file name is: " << outputFileName_;
136  if (!outputFileName_.empty() && createOutputFile_) {
137  edm::LogInfo("SiPixelOfflineCalibAnalysisBase") << "Writing ROOT file to: " << outputFileName_ << std::endl;
139  }
140 }
141 
142 // ------------ helper functions ---------------------------------------------------------
143 
144 const std::vector<short>* SiPixelOfflineCalibAnalysisBase::getVcalValues() { return &vCalValues_; }
145 
147  std::map<uint32_t, std::string>::iterator detNameIter = detIdNames_.find(detid);
148  if (detNameIter != detIdNames_.end()) {
149  return detNameIter->second;
150  }
151  std::string output = "DetID translation error";
152  DetId detId(detid);
153  uint32_t detSubId = detId.subdetId();
154  if (detSubId > 2 || detSubId < 1) {
155  edm::LogError("SiPixelOfflineCalibAnalysisBase")
156  << "ERROR: Expected a pixel detector ID (1 - barrel, 2 - forward) but got " << detSubId << std::endl;
157  return output;
158  }
159  if (detSubId == 2) //FPIX
160  {
161  PixelEndcapName nameworker(detid);
162  output = nameworker.name();
163  } else //BPIX
164  {
165  PixelBarrelName nameworker(detid);
166  output = nameworker.name();
167  }
168  detIdNames_.insert(std::make_pair(detid, output));
169  return output;
170 }
171 
173  uint32_t detid, std::string name, std::string title, int nchX, double lowX, double highX) {
174  std::string hid = theHistogramIdWorker_->setHistoId(name, detid);
175  return daqBE_->book1D(hid, title, nchX, lowX, highX);
176 }
177 
179  uint32_t detid, std::string name, std::string title, int nchX, float* xbinsize) {
180  std::string hid = theHistogramIdWorker_->setHistoId(name, detid);
181  return daqBE_->book1D(hid, title, nchX, xbinsize);
182 }
183 
187  int nchX,
188  double lowX,
189  double highX,
190  int nchY,
191  double lowY,
192  double highY) {
193  std::string hid = theHistogramIdWorker_->setHistoId(name, detid);
194  return daqBE_->book2D(hid, title, nchX, lowX, highX, nchY, lowY, highY);
195 }
196 
198  uint32_t detid, std::string name, std::string title) {
199  DetId detId(detid);
200  const TrackerGeometry& theTracker(*geom_);
201  const PixelGeomDetUnit* theGeomDet = dynamic_cast<const PixelGeomDetUnit*>(theTracker.idToDet(detId));
202  int maxcol = theGeomDet->specificTopology().ncolumns();
203  int maxrow = theGeomDet->specificTopology().nrows();
204 
205  std::string hid = theHistogramIdWorker_->setHistoId(name, detid);
206  return daqBE_->book2D(hid, title, maxcol, 0, maxcol, maxrow, 0, maxrow);
207 }
208 
210  daqBE_->setCurrentFolder(dirName);
211  return daqBE_->dirExists(dirName);
212 }
213 
215  return folderMaker_->setModuleFolder(detID, 0);
216 }
217 
218 // ------------ virtual functions ------------------------------------------------
220 
221 bool SiPixelOfflineCalibAnalysisBase::doFits(uint32_t detid, std::vector<SiPixelCalibDigi>::const_iterator ipix) {
222  short row = ipix->row();
223  short col = ipix->col();
224  std::vector<uint8_t> nentries = ipix->getnentries();
225  std::vector<uint32_t> sum = ipix->getsum();
226  std::vector<uint32_t> sumquares = ipix->getsumsquares();
227  //do nothing
228  //return false;
229  //
230  //DEBUG
231  std::cout << "Row: " << row << " Col: " << col << std::endl;
232  for (unsigned int i = 0; i < sum.size(); i++) {
233  std::cout << sum[i] << " ";
234  }
235  std::cout << std::endl;
236  return false;
237 }
238 
240  //do nothing
241 }
242 
244  // do nothing
245 }
247  //do nothing
248  edm::LogInfo("SiPixelOfflineCalibAnalysisBase")
249  << "SiPixelOfflineCalibAnalysisBase - Found new DetID: " << detid << " Name: " << detIdNames_[detid];
250 }
251 
252 bool SiPixelOfflineCalibAnalysisBase::checkPixel(uint32_t detid, short row, short col) {
253  // finds the fed ID:
254  int thefedid = -1;
255  for (int fedid = 0; fedid <= 40 && thefedid == -1; ++fedid) {
257  if (converter.hasDetUnit(detid)) {
258  thefedid = fedid;
259  }
260  }
261  if (thefedid == -1)
262  return false; // fed ID not associated with det ID. No pattern check possible
263 
264  SiPixelFrameConverter formatter(theCablingMap_.product(), thefedid);
265  sipixelobjects::DetectorIndex detector = {detid, row, col};
267 
268  formatter.toCabling(cabling, detector);
269  // cabling should now contain cabling.roc and cabling.dcol and cabling.pxid
270 
271  // however, the coordinates now need to be converted from dcl, pxid to the row,col coordinates used in the calibration info
273  loc.dcol = cabling.dcol;
274  loc.pxid = cabling.pxid;
275  sipixelobjects::LocalPixel locpixel(loc);
276  short localrow = locpixel.rocRow();
277  short localcol = locpixel.rocCol();
278 
279  // now get the patterns from the calib object:
280  std::vector<short> calibcols = calib_->getColumnPattern();
281  std::vector<short> calibrows = calib_->getRowPattern();
282  // first check rows:
283  for (size_t irow = 0; irow < calibrows.size(); ++irow) {
284  if (calibrows[irow] == localrow) {
285  // check the columns
286  for (size_t icol = 0; icol < calibcols.size(); ++icol) {
287  if (calibcols[icol] == localcol)
288  return true;
289  }
290  }
291  }
292 
293  return false;
294 }
295 
296 // function to add tf1's to ME's:
298  if (func) {
299  ele->getTH1()->GetListOfFunctions()->Add(func);
300  }
301  return;
302 }
RunNumber_t run() const
Definition: EventID.h:38
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
MonitorElement * book2D(char_string const &name, char_string const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1178
edm::ESHandle< SiPixelCalibConfiguration > calib_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
std::map< uint32_t, std::string > detIdNames_
std::string translateDetIdToString(uint32_t detid)
identify pixel inside single ROC
Definition: LocalPixel.h:7
std::string name() const override
from base class
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
bool setModuleFolder(const uint32_t &rawdetid=0, int type=0, bool isUpgrade=false)
Set folder name for a module or plaquette.
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
std::string name() const override
from base class
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:325
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.
Definition: DetId.h:17
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.
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:639
std::string const & label() const
Definition: InputTag.h:36
std::string getCalibrationMode() const
edm::EventID id() const
Definition: EventBase.h:59
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:73
const std::vector< short > getVCalValues() const
col
Definition: cuy.py:1010
const TrackerGeomDet * idToDet(DetId) const override
static const std::vector< short > * getVcalValues()
MonitorElement * book1D(char_string const &name, char_string const &title, int const nchX, double const lowX, double const highX)
Book 1D histogram.
Definition: DQMStore.cc:1121
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:314
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)
collection_type::const_iterator const_iterator
Definition: DetSet.h:32
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
edm::ESHandle< SiPixelFedCablingMap > theCablingMap_
T const * product() const
Definition: ESHandle.h:86
virtual TH1 * getTH1() const
void save(std::string const &filename, std::string const &path="", std::string const &pattern="", std::string const &rewrite="", uint32_t run=0, uint32_t lumi=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, std::string const &fileupdate="RECREATE")
Definition: DQMStore.cc:2244
edm::EDGetTokenT< edm::DetSetVector< SiPixelCalibDigi > > tPixelCalibDigi
Definition: Run.h:45
bool dirExists(std::string const &path) const
true if directory exists
Definition: DQMStore.cc:698