CMS 3D CMS Logo

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