CMS 3D CMS Logo

SiPixelCondObjReader.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiPixelCondObjReader
4 // Class: SiPixelCondObjReader
5 //
13 //
14 // Original Author: Vincenzo CHIOCHIA
15 // Created: Tue Oct 17 17:40:56 CEST 2006
16 // $Id: SiPixelCondObjReader.h,v 1.8 2009/05/28 22:12:55 dlange Exp $
17 //
18 //
19 
20 // system includes
21 #include <memory>
22 
23 // user includes
39 
40 // ROOT includes
41 #include "TROOT.h"
42 #include "TFile.h"
43 #include "TTree.h"
44 #include "TBranch.h"
45 #include "TH1F.h"
46 
47 namespace cms {
48  class SiPixelCondObjReader : public edm::one::EDAnalyzer<edm::one::SharedResources> {
49  public:
50  explicit SiPixelCondObjReader(const edm::ParameterSet &iConfig);
51 
52  ~SiPixelCondObjReader() override = default;
53 
54  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
55  void analyze(const edm::Event &, const edm::EventSetup &) override;
56  void endJob() override;
57 
58  private:
62 
63  std::map<uint32_t, TH1F *> _TH1F_Pedestals_m;
64  std::map<uint32_t, TH1F *> _TH1F_Gains_m;
65  std::map<uint32_t, double> _deadfrac_m;
66  std::map<uint32_t, double> _noisyfrac_m;
67 
80  };
81 } // namespace cms
82 
83 namespace cms {
85  : conf_(conf), tkGeomToken_(esConsumes()), SiPixelGainCalibrationService_(conf, consumesCollector()) {
86  usesResource(TFileService::kSharedResource);
87  }
88 
90  //Create Subdirectories
92  TFileDirectory subDirPed = fs->mkdir("Pedestals");
93  TFileDirectory subDirGain = fs->mkdir("Gains");
94  char name[128];
95 
96  unsigned int nmodules = 0;
97  uint32_t nchannels = 0;
98  uint32_t ndead = 0;
99  uint32_t nnoisy = 0;
100 
101  // Get the calibration data
103  edm::LogInfo("SiPixelCondObjReader") << "[SiPixelCondObjReader::beginJob] End Reading CondObjects" << std::endl;
104 
105  // Get the Geometry
106  const TrackerGeometry *tkgeom = &iSetup.getData(tkGeomToken_);
107  edm::LogInfo("SiPixelCondObjReader") << " There are " << tkgeom->dets().size() << " detectors" << std::endl;
108 
109  // Get the list of DetId's
110  std::vector<uint32_t> vdetId_ = SiPixelGainCalibrationService_.getDetIds();
111 
112  //Create histograms
113  _TH1F_Dead_sum = fs->make<TH1F>(
114  "Summary_dead", "Dead pixel fraction (0=dead, 1=alive)", vdetId_.size() + 1, 0, vdetId_.size() + 1);
115  _TH1F_Dead_all = fs->make<TH1F>("DeadAll",
116  "Dead pixel fraction (0=dead, 1=alive)",
117  50,
118  0.,
119  conf_.getUntrackedParameter<double>("maxRangeDeadPixHist", 0.001));
120  _TH1F_Noisy_sum = fs->make<TH1F>(
121  "Summary_noisy", "Noisy pixel fraction (0=noisy, 1=alive)", vdetId_.size() + 1, 0, vdetId_.size() + 1);
122  _TH1F_Noisy_all = fs->make<TH1F>("NoisyAll",
123  "Noisy pixel fraction (0=noisy, 1=alive)",
124  50,
125  0.,
126  conf_.getUntrackedParameter<double>("maxRangeDeadPixHist", 0.001));
127  _TH1F_Gains_sum = fs->make<TH1F>("Summary_Gain", "Gain Summary", vdetId_.size() + 1, 0, vdetId_.size() + 1);
129  fs->make<TH1F>("Summary_Pedestal", "Pedestal Summary", vdetId_.size() + 1, 0, vdetId_.size() + 1);
130  _TH1F_Pedestals_all = fs->make<TH1F>("PedestalsAll", "all Pedestals", 350, -100, 250);
131  _TH1F_Pedestals_bpix = fs->make<TH1F>("PedestalsBpix", "bpix Pedestals", 350, -100, 250);
132  _TH1F_Pedestals_fpix = fs->make<TH1F>("PedestalsFpix", "fpix Pedestals", 350, -100, 250);
133  _TH1F_Gains_all = fs->make<TH1F>("GainsAll", "all Gains", 100, 0, 10);
134  _TH1F_Gains_bpix = fs->make<TH1F>("GainsBpix", "bpix Gains", 100, 0, 10);
135  _TH1F_Gains_fpix = fs->make<TH1F>("GainsFpix", "fpix Gains", 100, 0, 10);
136 
137  TTree *tree = new TTree("tree", "tree");
138  uint32_t detid;
139  double gainmeanfortree, gainrmsfortree, pedmeanfortree, pedrmsfortree;
140  tree->Branch("detid", &detid, "detid/I");
141  tree->Branch("ped_mean", &pedmeanfortree, "ped_mean/D");
142  tree->Branch("ped_rms", &pedrmsfortree, "ped_rms/D");
143  tree->Branch("gain_mean", &gainmeanfortree, "gain_mean/D");
144  tree->Branch("gain_rms", &gainrmsfortree, "gain_rms/D");
145 
146  // Loop over DetId's
147  int ibin = 1;
148  for (std::vector<uint32_t>::const_iterator detid_iter = vdetId_.begin(); detid_iter != vdetId_.end();
149  detid_iter++) {
150  detid = *detid_iter;
151 
152  sprintf(name, "Pedestals_%d", detid);
153  _TH1F_Pedestals_m[detid] = subDirPed.make<TH1F>(name, name, 350, -100., 250.);
154  sprintf(name, "Gains_%d", detid);
155  _TH1F_Gains_m[detid] = subDirGain.make<TH1F>(name, name, 100, 0., 10.);
156 
157  DetId detIdObject(detid);
158  const PixelGeomDetUnit *_PixelGeomDetUnit =
159  dynamic_cast<const PixelGeomDetUnit *>(tkgeom->idToDetUnit(DetId(detid)));
160  if (_PixelGeomDetUnit == nullptr) {
161  edm::LogError("SiPixelCondObjDisplay") << "[SiPixelCondObjReader::beginJob] the detID " << detid
162  << " doesn't seem to belong to Tracker" << std::endl;
163  continue;
164  }
165 
166  _deadfrac_m[detid] = 0.;
167  _noisyfrac_m[detid] = 0.;
168 
169  nmodules++;
170 
171  const GeomDetUnit *geoUnit = tkgeom->idToDetUnit(detIdObject);
172  const PixelGeomDetUnit *pixDet = dynamic_cast<const PixelGeomDetUnit *>(geoUnit);
173  const PixelTopology &topol = pixDet->specificTopology();
174 
175  // Get the module sizes.
176  int nrows = topol.nrows(); // rows in x
177  int ncols = topol.ncolumns(); // cols in y
178  float nchannelspermod = 0;
179 
180  for (int col_iter = 0; col_iter < ncols; col_iter++) {
181  for (int row_iter = 0; row_iter < nrows; row_iter++) {
182  nchannelspermod++;
183  nchannels++;
184 
185  if (SiPixelGainCalibrationService_.isDead(detid, col_iter, row_iter)) {
186  // edm::LogPrint("SiPixelCondObjReader") << "found dead pixel " << detid << " " <<col_iter << "," << row_iter << std::endl;
187  ndead++;
188  _deadfrac_m[detid]++;
189  continue;
190  } else if (SiPixelGainCalibrationService_.isNoisy(detid, col_iter, row_iter)) {
191  // edm::LogPrint("SiPixelCondObjReader") << "found noisy pixel " << detid << " " <<col_iter << "," << row_iter << std::endl;
192  nnoisy++;
193  _noisyfrac_m[detid]++;
194  continue;
195  }
196 
197  float gain = SiPixelGainCalibrationService_.getGain(detid, col_iter, row_iter);
198  _TH1F_Gains_m[detid]->Fill(gain);
199  _TH1F_Gains_all->Fill(gain);
200 
201  if (detIdObject.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel))
202  _TH1F_Gains_bpix->Fill(gain);
203  if (detIdObject.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap))
204  _TH1F_Gains_fpix->Fill(gain);
205 
206  float ped = SiPixelGainCalibrationService_.getPedestal(detid, col_iter, row_iter);
207  _TH1F_Pedestals_m[detid]->Fill(ped);
208  _TH1F_Pedestals_all->Fill(ped);
209  // edm::LogPrint("SiPixelCondObjReader")<<"detid "<<detid<<" ped "<<ped<<std::endl;
210 
211  if (detIdObject.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel))
212  _TH1F_Pedestals_bpix->Fill(ped);
213  if (detIdObject.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap))
214  _TH1F_Pedestals_fpix->Fill(ped);
215 
216  // edm::LogPrint("SiPixelCondObjReader") <<" DetId "<<detid<<" Col "<<col_iter<<" Row "<<row_iter<<" Ped "<<ped<<" Gain "<<gain<<std::endl;
217  }
218  }
219 
220  _deadfrac_m[detid] /= nchannelspermod;
221  _noisyfrac_m[detid] /= nchannelspermod;
222  _TH1F_Dead_sum->SetBinContent(ibin, _deadfrac_m[detid]);
223  _TH1F_Dead_all->Fill(_deadfrac_m[detid]);
224  _TH1F_Noisy_sum->SetBinContent(ibin, _noisyfrac_m[detid]);
225  _TH1F_Noisy_all->Fill(_noisyfrac_m[detid]);
226  _TH1F_Gains_sum->SetBinContent(ibin, _TH1F_Gains_m[detid]->GetMean());
227  _TH1F_Gains_sum->SetBinError(ibin, _TH1F_Gains_m[detid]->GetRMS());
228  _TH1F_Pedestals_sum->SetBinContent(ibin, _TH1F_Pedestals_m[detid]->GetMean());
229  _TH1F_Pedestals_sum->SetBinError(ibin, _TH1F_Pedestals_m[detid]->GetRMS());
230 
231  gainmeanfortree = _TH1F_Gains_m[detid]->GetMean();
232  gainrmsfortree = _TH1F_Gains_m[detid]->GetRMS();
233  pedmeanfortree = _TH1F_Pedestals_m[detid]->GetMean();
234  pedrmsfortree = _TH1F_Pedestals_m[detid]->GetRMS();
235  edm::LogPrint("SiPixelCondObjReader")
236  << "DetId " << detid << " GainMean " << gainmeanfortree << " RMS " << gainrmsfortree << " PedMean "
237  << pedmeanfortree << " RMS " << pedrmsfortree << std::endl;
238  tree->Fill();
239 
240  ibin++;
241  }
242 
243  edm::LogInfo("SiPixelCondObjReader") << "[SiPixelCondObjReader::analyze] ---> PIXEL Modules " << nmodules
244  << std::endl;
245  edm::LogInfo("SiPixelCondObjReader") << "[SiPixelCondObjReader::analyze] ---> PIXEL Channels " << nchannels
246  << std::endl;
247 
248  edm::LogPrint("SiPixelCondObjReader") << " ---> SUMMARY :" << std::endl;
249  edm::LogPrint("SiPixelCondObjReader") << "Encounted " << ndead << " dead pixels" << std::endl;
250  edm::LogPrint("SiPixelCondObjReader") << "Encounted " << nnoisy << " noisy pixels" << std::endl;
251  edm::LogPrint("SiPixelCondObjReader")
252  << "The Gain Mean is " << _TH1F_Gains_all->GetMean() << " with rms " << _TH1F_Gains_all->GetRMS() << std::endl;
253  edm::LogPrint("SiPixelCondObjReader") << " in BPIX " << _TH1F_Gains_bpix->GetMean() << " with rms "
254  << _TH1F_Gains_bpix->GetRMS() << std::endl;
255  edm::LogPrint("SiPixelCondObjReader") << " in FPIX " << _TH1F_Gains_fpix->GetMean() << " with rms "
256  << _TH1F_Gains_fpix->GetRMS() << std::endl;
257  edm::LogPrint("SiPixelCondObjReader") << "The Ped Mean is " << _TH1F_Pedestals_all->GetMean() << " with rms "
258  << _TH1F_Pedestals_all->GetRMS() << std::endl;
259  edm::LogPrint("SiPixelCondObjReader") << " in BPIX " << _TH1F_Pedestals_bpix->GetMean() << " with rms "
260  << _TH1F_Pedestals_bpix->GetRMS() << std::endl;
261  edm::LogPrint("SiPixelCondObjReader") << " in FPIX " << _TH1F_Pedestals_fpix->GetMean() << " with rms "
262  << _TH1F_Pedestals_fpix->GetRMS() << std::endl;
263  }
264 
265  // ------------ method called once each job just after ending the event loop ------------
266  void SiPixelCondObjReader::endJob() { edm::LogPrint("SiPixelCondObjReader") << " ---> End job " << std::endl; }
267 
270  desc.setComment("EDAnalyzer to read per-module SiPixelGainCalibration payloads in the EventSetup");
271  desc.addUntracked<double>("maxRangeDeadPixHist", 0.001);
272  descriptions.addWithDefaultLabel(desc);
273  }
274 
275 } // namespace cms
276 using namespace cms;
static const std::string kSharedResource
Definition: TFileService.h:76
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
virtual int ncolumns() const =0
std::map< uint32_t, double > _noisyfrac_m
virtual int nrows() const =0
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Log< level::Error, false > LogError
T getUntrackedParameter(std::string const &, T const &) const
T * make(const Args &...args) const
make new ROOT object
int iEvent
Definition: GenABIO.cc:224
float getGain(const uint32_t &detID, const int &col, const int &row) override
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
SiPixelCondObjReader(const edm::ParameterSet &iConfig)
void setESObjects(const edm::EventSetup &es) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
bool getData(T &iHolder) const
Definition: EventSetup.h:122
Log< level::Warning, true > LogPrint
std::map< uint32_t, TH1F * > _TH1F_Gains_m
Namespace of DDCMS conversion namespace.
Log< level::Info, false > LogInfo
Definition: DetId.h:17
~SiPixelCondObjReader() override=default
std::map< uint32_t, TH1F * > _TH1F_Pedestals_m
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
float getPedestal(const uint32_t &detID, const int &col, const int &row) override
std::map< uint32_t, double > _deadfrac_m
Definition: tree.py:1
bool isDead(const uint32_t &detID, const int &col, const int &row) override
void analyze(const edm::Event &, const edm::EventSetup &) override
SiPixelGainCalibrationService SiPixelGainCalibrationService_
bool isNoisy(const uint32_t &detID, const int &col, const int &row) override