CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: SiPixelOfflineCalibAnalysisBase.cc,v 1.16 2008/08/29 14:56:27 fblekman Exp $
18 //
19 //
20 
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 
44 }
45 
47 {
48  throw cms::Exception("") << "ERROR: Classes derived from SiPixelOfflineCalibAnalysisBase must call SiPixelOfflineCalibAnalysisBase::SiPixelOfflineCalibAnalysisBase(const edm::ParameterSet& iConfig) from their constructor." << std::endl;
49 }
50 
52 {
53 }
54 
55 
56 //
57 // member functions
58 //
59 
60 // ------------ method called to for each event ------------
61 void
63 {
64  using namespace edm;
65 
66  iSetup.get<TrackerDigiGeometryRecord>().get( geom_ );
69  if(eventCounter_==0)
70  this->calibrationSetup(iSetup);
71  eventCounter_++;
72 
73  // check first if you're analyzing the right type of calibration
75  return;
76 
77  uint32_t runnumber=iEvent.id().run();
78  if(runnumbers_.size()==0)
79  runnumbers_.push_back(runnumber);
80  else{
81  bool foundnumber=false;
82  for(size_t iter=0; iter<runnumbers_.size() && !foundnumber; ++ iter){
83  if(runnumbers_[iter]==runnumber){
84  foundnumber=true;
85  continue;
86  }
87  }
88  if(!foundnumber)
89  runnumbers_.push_back(runnumber);
90  }
91 
93  iEvent.getByLabel(siPixelCalibDigiProducer_, thePlaquettes);
94 
96 
97  //loop over the plaquettes pulsed in this pattern
98  for(digiIter=thePlaquettes->begin(); digiIter!=thePlaquettes->end(); ++digiIter)
99  {
100  uint32_t detId = digiIter->id;
101  //check to see if this detID has not been encountered. If not, run the newDetID (pure virtual) function
102  if (detIdsEntered_.find(detId) == detIdsEntered_.end())
103  {
104  detIdsEntered_.insert(std::make_pair(detId, 0));
105  detIdNames_.insert(std::make_pair(detId, translateDetIdToString(detId)));
106  newDetID(detId);
107  }
109  //loop over pixels pulsed in the current plaquette
110  for(ipix=digiIter->data.begin(); ipix!=digiIter->end(); ++ipix)
111  {
112  //called derived function to fit this curve
113  this->doFits(detId, ipix);
114  }
115  }
116 
117 }
118 
120 {
121  //load the calibration information from the database
122  iSetup.get<SiPixelCalibConfigurationRcd>().get(calib_);
123  iSetup.get<TrackerDigiGeometryRecord>().get( geom_ );
125 
126  calibrationMode_ = calib_->getCalibrationMode();
127  nTriggers_ = calib_->getNTriggers();
128  vCalValues_ = calib_->getVCalValues();
129  std::cout << "!!!! in beginRun" << std::endl;
130  edm::LogInfo("SiPixelOfflineCalibAnalysisBase") << "Calibration file loaded. Mode: " << calibrationMode_ << " nTriggers: " << nTriggers_ << " Vcal steps: " << vCalValues_.size() << std::endl;
131  //call calibrationSetup virtual function
132  this->calibrationSetup(iSetup);
134 }
135 void
137 {
138 
139 }
140 // ------------ method called once each job just before starting event loop ------------
141 
142 // ------------ method called once each job just after ending the event loop ------------
143 void
145  this->calibrationEnd();
146  edm::LogInfo("SiPixelOfflineCalibAnalysisBase") << "Running end job... output file name is: " << outputFileName_;
147  if (!outputFileName_.empty() && createOutputFile_)
148  {
149  edm::LogInfo("SiPixelOfflineCalibAnalysisBase") << "Writing ROOT file to: " << outputFileName_ << std::endl;
151  }
152 }
153 
154 // ------------ helper functions ---------------------------------------------------------
155 
156 const std::vector<short>*
158 {
159  return &vCalValues_;
160 }
161 
162 std::string
164 {
165  std::map<uint32_t, std::string>::iterator detNameIter = detIdNames_.find(detid);
166  if (detNameIter != detIdNames_.end()) {
167  return detNameIter->second;
168  }
169  std::string output = "DetID translation error";
170  DetId detId(detid);
171  uint32_t detSubId = detId.subdetId();
172  if (detSubId > 2 || detSubId < 1)
173  {
174  edm::LogError("SiPixelOfflineCalibAnalysisBase") << "ERROR: Expected a pixel detector ID (1 - barrel, 2 - forward) but got " << detSubId << std::endl;
175  return output;
176  }
177  if (detSubId == 2) //FPIX
178  {
179  PixelEndcapName nameworker(detid);
180  output = nameworker.name();
181  } else //BPIX
182  {
183  PixelBarrelName nameworker(detid);
184  output = nameworker.name();
185  }
186  detIdNames_.insert(std::make_pair(detid, output));
187  return output;
188 }
189 
190 MonitorElement* SiPixelOfflineCalibAnalysisBase::bookDQMHistogram1D(uint32_t detid, std::string name, std::string title, int nchX, double lowX, double highX)
191 {
192  std::string hid = theHistogramIdWorker_->setHistoId(name,detid);
193  return daqBE_->book1D(hid, title, nchX, lowX, highX);
194 }
195 
196 MonitorElement* SiPixelOfflineCalibAnalysisBase::bookDQMHistogram1D(uint32_t detid, std::string name, std::string title, int nchX, float *xbinsize)
197 {
198  std::string hid = theHistogramIdWorker_->setHistoId(name,detid);
199  return daqBE_->book1D(hid, title, nchX, xbinsize);
200 }
201 
202 MonitorElement* SiPixelOfflineCalibAnalysisBase::bookDQMHistogram2D(uint32_t detid, std::string name, std::string title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
203 {
204  std::string hid = theHistogramIdWorker_->setHistoId(name,detid);
205  return daqBE_->book2D(hid, title, nchX, lowX, highX, nchY, lowY, highY);
206 }
207 
209  DetId detId(detid);
210  const TrackerGeometry &theTracker(*geom_);
211  const PixelGeomDetUnit *theGeomDet = dynamic_cast<const PixelGeomDetUnit*> ( theTracker.idToDet(detId) );
212  int maxcol = theGeomDet->specificTopology().ncolumns();
213  int maxrow = theGeomDet->specificTopology().nrows();
214 
215 
216  std::string hid = theHistogramIdWorker_->setHistoId(name,detid);
217  return daqBE_->book2D(hid,title,maxcol,0,maxcol,maxrow,0,maxrow);
218 }
219 
220 bool
222 {
223  daqBE_->setCurrentFolder(dirName);
224  return daqBE_->dirExists(dirName);
225 }
226 
227 bool
229 {
230  return folderMaker_->setModuleFolder(detID,0);
231 }
232 
233 
234 // ------------ virtual functions ------------------------------------------------
235 bool
237 {
238  return true;
239 }
240 
241 bool
242 SiPixelOfflineCalibAnalysisBase::doFits(uint32_t detid, std::vector<SiPixelCalibDigi>::const_iterator ipix)
243 {
244  short row=ipix->row();
245  short col=ipix->col();
246  std::vector<uint8_t> nentries = ipix->getnentries();
247  std::vector<uint32_t> sum = ipix->getsum();
248  std::vector<uint32_t> sumquares = ipix->getsumsquares();
249  //do nothing
250  //return false;
251  //
252  //DEBUG
253  std::cout << "Row: " << row << " Col: " << col << std::endl;
254  for (unsigned int i = 0; i < sum.size(); i++)
255  {
256  std::cout << sum[i] << " ";
257  }
258  std::cout << std::endl;
259  return false;
260 
261 }
262 
263 void
265 {
266  //do nothing
267 }
268 
270 {
271  // do nothing
272 }
273 void
275 {
276  //do nothing
277  edm::LogInfo("SiPixelOfflineCalibAnalysisBase") << "SiPixelOfflineCalibAnalysisBase - Found new DetID: " << detid << " Name: " << detIdNames_[detid];
278 }
279 
280 bool
282 {
283  // finds the fed ID:
284  int thefedid = -1;
285  for(int fedid=0; fedid<=40 && thefedid==-1; ++fedid)
286  {
287  SiPixelFrameConverter converter(theCablingMap_.product(),fedid);
288  if(converter.hasDetUnit(detid))
289  {
290  thefedid=fedid;
291  }
292  }
293  if(thefedid==-1)
294  return false; // fed ID not associated with det ID. No pattern check possible
295 
296  SiPixelFrameConverter formatter(theCablingMap_.product(),thefedid);
297  sipixelobjects::DetectorIndex detector ={detid, row, col};
299 
300  formatter.toCabling(cabling,detector);
301  // cabling should now contain cabling.roc and cabling.dcol and cabling.pxid
302 
303  // however, the coordinates now need to be converted from dcl, pxid to the row,col coordinates used in the calibration info
305  loc.dcol = cabling.dcol;
306  loc.pxid = cabling.pxid;
307  sipixelobjects::LocalPixel locpixel(loc);
308  short localrow = locpixel.rocRow();
309  short localcol = locpixel.rocCol();
310 
311  // now get the patterns from the calib object:
312  std::vector<short> calibcols = calib_->getColumnPattern();
313  std::vector<short> calibrows = calib_->getRowPattern();
314  // first check rows:
315  for(size_t irow=0; irow<calibrows.size(); ++irow)
316  {
317  if(calibrows[irow]==localrow)
318  {
319  // check the columns
320  for(size_t icol=0; icol<calibcols.size(); ++icol)
321  {
322  if(calibcols[icol]==localcol)
323  return true;
324  }
325  }
326  }
327 
328  return false;
329 }
330 
331 // function to add tf1's to ME's:
333 
334  if(func){
335  ele->getTH1()->GetListOfFunctions()->Add(func);
336  }
337  return;
338 }
339 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:42
iterator end()
Definition: DetSet.h:59
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:514
edm::ESHandle< SiPixelCalibConfiguration > calib_
virtual int ncolumns() const =0
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:1898
virtual int nrows() const =0
std::map< uint32_t, std::string > detIdNames_
#define NULL
Definition: scimark2.h:8
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
edm::ESHandle< TrackerGeometry > geom_
virtual void calibrationSetup(const edm::EventSetup &iSetup)
int iEvent
Definition: GenABIO.cc:243
MonitorElement * bookDQMHistogram1D(uint32_t detid, std::string name, std::string title, int nchX, double lowX, double highX)
TH1 * getTH1(void) const
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
virtual const GeomDet * idToDet(DetId) const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
double collumn and pixel ID in double collumn representation
Definition: LocalPixel.h:22
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:296
std::string setHistoId(std::string variable, uint32_t &rawId)
Set Histogram Id.
Definition: DetId.h:20
virtual std::string name() const
from base class
const T & get() const
Definition: EventSetup.h:55
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
T const * product() const
Definition: ESHandle.h:62
std::string const & label() const
Definition: InputTag.h:25
virtual std::string name() const
from base class
edm::EventID id() const
Definition: EventBase.h:56
collection_type data
Definition: DetSet.h:77
virtual bool doFits(uint32_t detid, std::vector< SiPixelCalibDigi >::const_iterator ipix)
void analyze(const edm::Event &, const edm::EventSetup &)
static const std::vector< short > * getVcalValues()
tuple cout
Definition: gather_cfg.py:41
bool checkPixel(uint32_t detid, short row, short column)
void addTF1ToDQMMonitoringElement(MonitorElement *ele, TF1 *func)
collection_type::const_iterator const_iterator
Definition: DetSet.h:32
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:642
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:106
edm::ESHandle< SiPixelFedCablingMap > theCablingMap_
MonitorElement * bookDQMHistogram2D(uint32_t detid, std::string name, std::string title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:232
Definition: Run.h:32
bool setModuleFolder(const uint32_t &rawdetid=0, int type=0)
Set folder name for a module or plaquette.