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  void analyze(const edm::Event &, const edm::EventSetup &) override;
54  void endJob() override;
55 
56  private:
60 
61  std::map<uint32_t, TH1F *> _TH1F_Pedestals_m;
62  std::map<uint32_t, TH1F *> _TH1F_Gains_m;
63  std::map<uint32_t, double> _deadfrac_m;
64  std::map<uint32_t, double> _noisyfrac_m;
65 
78  };
79 } // namespace cms
80 
81 namespace cms {
83  : conf_(conf), tkGeomToken_(esConsumes()), SiPixelGainCalibrationService_(conf, consumesCollector()) {
84  usesResource(TFileService::kSharedResource);
85  }
86 
88  //Create Subdirectories
90  TFileDirectory subDirPed = fs->mkdir("Pedestals");
91  TFileDirectory subDirGain = fs->mkdir("Gains");
92  char name[128];
93 
94  unsigned int nmodules = 0;
95  uint32_t nchannels = 0;
96  uint32_t ndead = 0;
97  uint32_t nnoisy = 0;
98 
99  // Get the calibration data
101  edm::LogInfo("SiPixelCondObjReader") << "[SiPixelCondObjReader::beginJob] End Reading CondObjects" << std::endl;
102 
103  // Get the Geometry
104  const TrackerGeometry *tkgeom = &iSetup.getData(tkGeomToken_);
105  edm::LogInfo("SiPixelCondObjReader") << " There are " << tkgeom->dets().size() << " detectors" << std::endl;
106 
107  // Get the list of DetId's
108  std::vector<uint32_t> vdetId_ = SiPixelGainCalibrationService_.getDetIds();
109 
110  //Create histograms
111  _TH1F_Dead_sum = fs->make<TH1F>(
112  "Summary_dead", "Dead pixel fraction (0=dead, 1=alive)", vdetId_.size() + 1, 0, vdetId_.size() + 1);
113  _TH1F_Dead_all = fs->make<TH1F>("DeadAll",
114  "Dead pixel fraction (0=dead, 1=alive)",
115  50,
116  0.,
117  conf_.getUntrackedParameter<double>("maxRangeDeadPixHist", 0.001));
118  _TH1F_Noisy_sum = fs->make<TH1F>(
119  "Summary_noisy", "Noisy pixel fraction (0=noisy, 1=alive)", vdetId_.size() + 1, 0, vdetId_.size() + 1);
120  _TH1F_Noisy_all = fs->make<TH1F>("NoisyAll",
121  "Noisy pixel fraction (0=noisy, 1=alive)",
122  50,
123  0.,
124  conf_.getUntrackedParameter<double>("maxRangeDeadPixHist", 0.001));
125  _TH1F_Gains_sum = fs->make<TH1F>("Summary_Gain", "Gain Summary", vdetId_.size() + 1, 0, vdetId_.size() + 1);
127  fs->make<TH1F>("Summary_Pedestal", "Pedestal Summary", vdetId_.size() + 1, 0, vdetId_.size() + 1);
128  _TH1F_Pedestals_all = fs->make<TH1F>("PedestalsAll", "all Pedestals", 350, -100, 250);
129  _TH1F_Pedestals_bpix = fs->make<TH1F>("PedestalsBpix", "bpix Pedestals", 350, -100, 250);
130  _TH1F_Pedestals_fpix = fs->make<TH1F>("PedestalsFpix", "fpix Pedestals", 350, -100, 250);
131  _TH1F_Gains_all = fs->make<TH1F>("GainsAll", "all Gains", 100, 0, 10);
132  _TH1F_Gains_bpix = fs->make<TH1F>("GainsBpix", "bpix Gains", 100, 0, 10);
133  _TH1F_Gains_fpix = fs->make<TH1F>("GainsFpix", "fpix Gains", 100, 0, 10);
134 
135  TTree *tree = new TTree("tree", "tree");
136  uint32_t detid;
137  double gainmeanfortree, gainrmsfortree, pedmeanfortree, pedrmsfortree;
138  tree->Branch("detid", &detid, "detid/I");
139  tree->Branch("ped_mean", &pedmeanfortree, "ped_mean/D");
140  tree->Branch("ped_rms", &pedrmsfortree, "ped_rms/D");
141  tree->Branch("gain_mean", &gainmeanfortree, "gain_mean/D");
142  tree->Branch("gain_rms", &gainrmsfortree, "gain_rms/D");
143 
144  // Loop over DetId's
145  int ibin = 1;
146  for (std::vector<uint32_t>::const_iterator detid_iter = vdetId_.begin(); detid_iter != vdetId_.end();
147  detid_iter++) {
148  detid = *detid_iter;
149 
150  sprintf(name, "Pedestals_%d", detid);
151  _TH1F_Pedestals_m[detid] = subDirPed.make<TH1F>(name, name, 350, -100., 250.);
152  sprintf(name, "Gains_%d", detid);
153  _TH1F_Gains_m[detid] = subDirGain.make<TH1F>(name, name, 100, 0., 10.);
154 
155  DetId detIdObject(detid);
156  const PixelGeomDetUnit *_PixelGeomDetUnit =
157  dynamic_cast<const PixelGeomDetUnit *>(tkgeom->idToDetUnit(DetId(detid)));
158  if (_PixelGeomDetUnit == nullptr) {
159  edm::LogError("SiPixelCondObjDisplay") << "[SiPixelCondObjReader::beginJob] the detID " << detid
160  << " doesn't seem to belong to Tracker" << std::endl;
161  continue;
162  }
163 
164  _deadfrac_m[detid] = 0.;
165  _noisyfrac_m[detid] = 0.;
166 
167  nmodules++;
168 
169  const GeomDetUnit *geoUnit = tkgeom->idToDetUnit(detIdObject);
170  const PixelGeomDetUnit *pixDet = dynamic_cast<const PixelGeomDetUnit *>(geoUnit);
171  const PixelTopology &topol = pixDet->specificTopology();
172 
173  // Get the module sizes.
174  int nrows = topol.nrows(); // rows in x
175  int ncols = topol.ncolumns(); // cols in y
176  float nchannelspermod = 0;
177 
178  for (int col_iter = 0; col_iter < ncols; col_iter++) {
179  for (int row_iter = 0; row_iter < nrows; row_iter++) {
180  nchannelspermod++;
181  nchannels++;
182 
183  if (SiPixelGainCalibrationService_.isDead(detid, col_iter, row_iter)) {
184  // edm::LogPrint("SiPixelCondObjReader") << "found dead pixel " << detid << " " <<col_iter << "," << row_iter << std::endl;
185  ndead++;
186  _deadfrac_m[detid]++;
187  continue;
188  } else if (SiPixelGainCalibrationService_.isNoisy(detid, col_iter, row_iter)) {
189  // edm::LogPrint("SiPixelCondObjReader") << "found noisy pixel " << detid << " " <<col_iter << "," << row_iter << std::endl;
190  nnoisy++;
191  _noisyfrac_m[detid]++;
192  continue;
193  }
194 
195  float gain = SiPixelGainCalibrationService_.getGain(detid, col_iter, row_iter);
196  _TH1F_Gains_m[detid]->Fill(gain);
197  _TH1F_Gains_all->Fill(gain);
198 
199  if (detIdObject.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel))
200  _TH1F_Gains_bpix->Fill(gain);
201  if (detIdObject.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap))
202  _TH1F_Gains_fpix->Fill(gain);
203 
204  float ped = SiPixelGainCalibrationService_.getPedestal(detid, col_iter, row_iter);
205  _TH1F_Pedestals_m[detid]->Fill(ped);
206  _TH1F_Pedestals_all->Fill(ped);
207  // edm::LogPrint("SiPixelCondObjReader")<<"detid "<<detid<<" ped "<<ped<<std::endl;
208 
209  if (detIdObject.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel))
210  _TH1F_Pedestals_bpix->Fill(ped);
211  if (detIdObject.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap))
212  _TH1F_Pedestals_fpix->Fill(ped);
213 
214  // edm::LogPrint("SiPixelCondObjReader") <<" DetId "<<detid<<" Col "<<col_iter<<" Row "<<row_iter<<" Ped "<<ped<<" Gain "<<gain<<std::endl;
215  }
216  }
217 
218  _deadfrac_m[detid] /= nchannelspermod;
219  _noisyfrac_m[detid] /= nchannelspermod;
220  _TH1F_Dead_sum->SetBinContent(ibin, _deadfrac_m[detid]);
221  _TH1F_Dead_all->Fill(_deadfrac_m[detid]);
222  _TH1F_Noisy_sum->SetBinContent(ibin, _noisyfrac_m[detid]);
223  _TH1F_Noisy_all->Fill(_noisyfrac_m[detid]);
224  _TH1F_Gains_sum->SetBinContent(ibin, _TH1F_Gains_m[detid]->GetMean());
225  _TH1F_Gains_sum->SetBinError(ibin, _TH1F_Gains_m[detid]->GetRMS());
226  _TH1F_Pedestals_sum->SetBinContent(ibin, _TH1F_Pedestals_m[detid]->GetMean());
227  _TH1F_Pedestals_sum->SetBinError(ibin, _TH1F_Pedestals_m[detid]->GetRMS());
228 
229  gainmeanfortree = _TH1F_Gains_m[detid]->GetMean();
230  gainrmsfortree = _TH1F_Gains_m[detid]->GetRMS();
231  pedmeanfortree = _TH1F_Pedestals_m[detid]->GetMean();
232  pedrmsfortree = _TH1F_Pedestals_m[detid]->GetRMS();
233  edm::LogPrint("SiPixelCondObjReader")
234  << "DetId " << detid << " GainMean " << gainmeanfortree << " RMS " << gainrmsfortree << " PedMean "
235  << pedmeanfortree << " RMS " << pedrmsfortree << std::endl;
236  tree->Fill();
237 
238  ibin++;
239  }
240 
241  edm::LogInfo("SiPixelCondObjReader") << "[SiPixelCondObjReader::analyze] ---> PIXEL Modules " << nmodules
242  << std::endl;
243  edm::LogInfo("SiPixelCondObjReader") << "[SiPixelCondObjReader::analyze] ---> PIXEL Channels " << nchannels
244  << std::endl;
245 
246  edm::LogPrint("SiPixelCondObjReader") << " ---> SUMMARY :" << std::endl;
247  edm::LogPrint("SiPixelCondObjReader") << "Encounted " << ndead << " dead pixels" << std::endl;
248  edm::LogPrint("SiPixelCondObjReader") << "Encounted " << nnoisy << " noisy pixels" << std::endl;
249  edm::LogPrint("SiPixelCondObjReader")
250  << "The Gain Mean is " << _TH1F_Gains_all->GetMean() << " with rms " << _TH1F_Gains_all->GetRMS() << std::endl;
251  edm::LogPrint("SiPixelCondObjReader") << " in BPIX " << _TH1F_Gains_bpix->GetMean() << " with rms "
252  << _TH1F_Gains_bpix->GetRMS() << std::endl;
253  edm::LogPrint("SiPixelCondObjReader") << " in FPIX " << _TH1F_Gains_fpix->GetMean() << " with rms "
254  << _TH1F_Gains_fpix->GetRMS() << std::endl;
255  edm::LogPrint("SiPixelCondObjReader") << "The Ped Mean is " << _TH1F_Pedestals_all->GetMean() << " with rms "
256  << _TH1F_Pedestals_all->GetRMS() << std::endl;
257  edm::LogPrint("SiPixelCondObjReader") << " in BPIX " << _TH1F_Pedestals_bpix->GetMean() << " with rms "
258  << _TH1F_Pedestals_bpix->GetRMS() << std::endl;
259  edm::LogPrint("SiPixelCondObjReader") << " in FPIX " << _TH1F_Pedestals_fpix->GetMean() << " with rms "
260  << _TH1F_Pedestals_fpix->GetRMS() << std::endl;
261  }
262 
263  // ------------ method called once each job just after ending the event loop ------------
264  void SiPixelCondObjReader::endJob() { edm::LogPrint("SiPixelCondObjReader") << " ---> End job " << std::endl; }
265 } // namespace cms
266 using namespace cms;
static const std::string kSharedResource
Definition: TFileService.h:76
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
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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
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.
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