CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
52  void analyze(const edm::Event &, const edm::EventSetup &) override;
53  void endJob() override;
54 
55  private:
59  std::unique_ptr<SiPixelGainCalibrationServiceBase> SiPixelGainCalibrationService_;
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()) {
84  usesResource(TFileService::kSharedResource);
85  if (conf_.getParameter<bool>("useSimRcd"))
87  std::make_unique<SiPixelGainCalibrationOfflineSimService>(conf_, consumesCollector());
88  else
90  std::make_unique<SiPixelGainCalibrationOfflineService>(conf_, consumesCollector());
91  }
92 
94  //Create Subdirectories
96  TFileDirectory subDirPed = fs->mkdir("Pedestals");
97  TFileDirectory subDirGain = fs->mkdir("Gains");
98  char name[128];
99 
100  unsigned int nmodules = 0;
101  uint32_t nchannels = 0;
102  uint32_t ndead = 0;
103  uint32_t nnoisy = 0;
104 
105  // Get the calibration data
106  SiPixelGainCalibrationService_->setESObjects(iSetup);
107  edm::LogInfo("SiPixelCondObjOfflineReader")
108  << "[SiPixelCondObjOfflineReader::beginJob] End Reading CondObjOfflineects" << std::endl;
109 
110  // Get the Geometry
111  const TrackerGeometry *tkgeom = &iSetup.getData(tkGeomToken_);
112  edm::LogInfo("SiPixelCondObjOfflineReader") << " There are " << tkgeom->dets().size() << " detectors" << std::endl;
113 
114  // Get the list of DetId's
115  std::vector<uint32_t> vdetId_ = SiPixelGainCalibrationService_->getDetIds();
116 
117  //Create histograms
118  _TH1F_Dead_sum = fs->make<TH1F>(
119  "Summary_dead", "Dead pixel fraction (0=dead, 1=alive)", vdetId_.size() + 1, 0, vdetId_.size() + 1);
120  _TH1F_Dead_all = fs->make<TH1F>("DeadAll",
121  "Dead pixel fraction (0=dead, 1=alive)",
122  50,
123  0.,
124  conf_.getUntrackedParameter<double>("maxRangeDeadPixHist", 0.001));
125  _TH1F_Noisy_sum = fs->make<TH1F>(
126  "Summary_noisy", "Noisy pixel fraction (0=noisy, 1=alive)", vdetId_.size() + 1, 0, vdetId_.size() + 1);
127  _TH1F_Noisy_all = fs->make<TH1F>("NoisyAll",
128  "Noisy pixel fraction (0=noisy, 1=alive)",
129  50,
130  0.,
131  conf_.getUntrackedParameter<double>("maxRangeDeadPixHist", 0.001));
132  _TH1F_Gains_sum = fs->make<TH1F>("Summary_Gain", "Gain Summary", vdetId_.size() + 1, 0, vdetId_.size() + 1);
134  fs->make<TH1F>("Summary_Pedestal", "Pedestal Summary", vdetId_.size() + 1, 0, vdetId_.size() + 1);
135  _TH1F_Pedestals_all = fs->make<TH1F>("PedestalsAll", "all Pedestals", 350, -100, 250);
136  _TH1F_Pedestals_bpix = fs->make<TH1F>("PedestalsBpix", "bpix Pedestals", 350, -100, 250);
137  _TH1F_Pedestals_fpix = fs->make<TH1F>("PedestalsFpix", "fpix Pedestals", 350, -100, 250);
138  _TH1F_Gains_all = fs->make<TH1F>("GainsAll", "all Gains", 100, 0, 10);
139  _TH1F_Gains_bpix = fs->make<TH1F>("GainsBpix", "bpix Gains", 100, 0, 10);
140  _TH1F_Gains_fpix = fs->make<TH1F>("GainsFpix", "fpix Gains", 100, 0, 10);
141 
142  TTree *tree = new TTree("tree", "tree");
143  uint32_t detid;
144  double gainmeanfortree, gainrmsfortree, pedmeanfortree, pedrmsfortree;
145  tree->Branch("detid", &detid, "detid/I");
146  tree->Branch("ped_mean", &pedmeanfortree, "ped_mean/D");
147  tree->Branch("ped_rms", &pedrmsfortree, "ped_rms/D");
148  tree->Branch("gain_mean", &gainmeanfortree, "gain_mean/D");
149  tree->Branch("gain_rms", &gainrmsfortree, "gain_rms/D");
150 
151  // Loop over DetId's
152  int ibin = 1;
153  for (std::vector<uint32_t>::const_iterator detid_iter = vdetId_.begin(); detid_iter != vdetId_.end();
154  detid_iter++) {
155  detid = *detid_iter;
156 
157  sprintf(name, "Pedestals_%d", detid);
158  _TH1F_Pedestals_m[detid] = subDirPed.make<TH1F>(name, name, 350, -100., 250.);
159  sprintf(name, "Gains_%d", detid);
160  _TH1F_Gains_m[detid] = subDirGain.make<TH1F>(name, name, 100, 0., 10.);
161 
162  DetId detIdObject(detid);
163  const PixelGeomDetUnit *_PixelGeomDetUnit =
164  dynamic_cast<const PixelGeomDetUnit *>(tkgeom->idToDetUnit(DetId(detid)));
165  if (_PixelGeomDetUnit == nullptr) {
166  edm::LogError("SiPixelCondObjOfflineDisplay") << "[SiPixelCondObjOfflineReader::beginJob] the detID " << detid
167  << " doesn't seem to belong to Tracker" << std::endl;
168  continue;
169  }
170 
171  _deadfrac_m[detid] = 0.;
172  _noisyfrac_m[detid] = 0.;
173 
174  nmodules++;
175 
176  const GeomDetUnit *geoUnit = tkgeom->idToDetUnit(detIdObject);
177  const PixelGeomDetUnit *pixDet = dynamic_cast<const PixelGeomDetUnit *>(geoUnit);
178  const PixelTopology &topol = pixDet->specificTopology();
179 
180  // Get the module sizes.
181  int nrows = topol.nrows(); // rows in x
182  int ncols = topol.ncolumns(); // cols in y
183  float nchannelspermod = 0;
184 
185  for (int col_iter = 0; col_iter < ncols; col_iter++) {
186  for (int row_iter = 0; row_iter < nrows; row_iter++) {
187  nchannelspermod++;
188  nchannels++;
189 
190  if (SiPixelGainCalibrationService_->isDead(detid, col_iter, row_iter)) {
191  // edm::LogPrint("SiPixelCondObjOfflineReader") << "found dead pixel " << detid << " " <<col_iter << "," << row_iter << std::endl;
192  ndead++;
193  _deadfrac_m[detid]++;
194  continue;
195  } else if (SiPixelGainCalibrationService_->isNoisy(detid, col_iter, row_iter)) {
196  // edm::LogPrint("SiPixelCondObjOfflineReader") << "found noisy pixel " << detid << " " <<col_iter << "," << row_iter << std::endl;
197  nnoisy++;
198  _noisyfrac_m[detid]++;
199  continue;
200  }
201 
202  float gain = SiPixelGainCalibrationService_->getGain(detid, col_iter, row_iter);
203  _TH1F_Gains_m[detid]->Fill(gain);
204  _TH1F_Gains_all->Fill(gain);
205 
206  if (detIdObject.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel))
207  _TH1F_Gains_bpix->Fill(gain);
208  if (detIdObject.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap))
209  _TH1F_Gains_fpix->Fill(gain);
210 
211  float ped = SiPixelGainCalibrationService_->getPedestal(detid, col_iter, row_iter);
212  _TH1F_Pedestals_m[detid]->Fill(ped);
213  _TH1F_Pedestals_all->Fill(ped);
214  // edm::LogPrint("SiPixelCondObjOfflineReader")<<"detid "<<detid<<" ped "<<ped<<std::endl;
215 
216  if (detIdObject.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel))
217  _TH1F_Pedestals_bpix->Fill(ped);
218  if (detIdObject.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap))
219  _TH1F_Pedestals_fpix->Fill(ped);
220 
221  // edm::LogPrint("SiPixelCondObjOfflineReader") <<" DetId "<<detid<<" Col "<<col_iter<<" Row "<<row_iter<<" Ped "<<ped<<" Gain "<<gain<<std::endl;
222  }
223  }
224 
225  _deadfrac_m[detid] /= nchannelspermod;
226  _noisyfrac_m[detid] /= nchannelspermod;
227  _TH1F_Dead_sum->SetBinContent(ibin, _deadfrac_m[detid]);
228  _TH1F_Dead_all->Fill(_deadfrac_m[detid]);
229  _TH1F_Noisy_sum->SetBinContent(ibin, _noisyfrac_m[detid]);
230  _TH1F_Noisy_all->Fill(_noisyfrac_m[detid]);
231  _TH1F_Gains_sum->SetBinContent(ibin, _TH1F_Gains_m[detid]->GetMean());
232  _TH1F_Gains_sum->SetBinError(ibin, _TH1F_Gains_m[detid]->GetRMS());
233  _TH1F_Pedestals_sum->SetBinContent(ibin, _TH1F_Pedestals_m[detid]->GetMean());
234  _TH1F_Pedestals_sum->SetBinError(ibin, _TH1F_Pedestals_m[detid]->GetRMS());
235 
236  gainmeanfortree = _TH1F_Gains_m[detid]->GetMean();
237  gainrmsfortree = _TH1F_Gains_m[detid]->GetRMS();
238  pedmeanfortree = _TH1F_Pedestals_m[detid]->GetMean();
239  pedrmsfortree = _TH1F_Pedestals_m[detid]->GetRMS();
240  edm::LogPrint("SiPixelCondObjOfflineReader")
241  << "DetId " << detid << " GainMean " << gainmeanfortree << " RMS " << gainrmsfortree << " PedMean "
242  << pedmeanfortree << " RMS " << pedrmsfortree << std::endl;
243  tree->Fill();
244 
245  if (pedmeanfortree == 0)
246  edm::LogPrint("SiPixelCondObjOfflineReader") << detid << std::endl;
247 
248  ibin++;
249  }
250 
251  edm::LogInfo("SiPixelCondObjOfflineReader")
252  << "[SiPixelCondObjOfflineReader::analyze] ---> PIXEL Modules " << nmodules << std::endl;
253  edm::LogInfo("SiPixelCondObjOfflineReader")
254  << "[SiPixelCondObjOfflineReader::analyze] ---> PIXEL Channels (i.e. Number of Columns)" << nchannels
255  << std::endl;
256 
257  edm::LogPrint("SiPixelCondObjOfflineReader") << " ---> SUMMARY :" << std::endl;
258  edm::LogPrint("SiPixelCondObjOfflineReader") << "Encounted " << ndead << " dead pixels" << std::endl;
259  edm::LogPrint("SiPixelCondObjOfflineReader") << "Encounted " << nnoisy << " noisy pixels" << std::endl;
260  edm::LogPrint("SiPixelCondObjOfflineReader")
261  << "The Gain Mean is " << _TH1F_Gains_all->GetMean() << " with rms " << _TH1F_Gains_all->GetRMS() << std::endl;
262  edm::LogPrint("SiPixelCondObjOfflineReader") << " in BPIX " << _TH1F_Gains_bpix->GetMean() << " with rms "
263  << _TH1F_Gains_bpix->GetRMS() << std::endl;
264  edm::LogPrint("SiPixelCondObjOfflineReader") << " in FPIX " << _TH1F_Gains_fpix->GetMean() << " with rms "
265  << _TH1F_Gains_fpix->GetRMS() << std::endl;
266  edm::LogPrint("SiPixelCondObjOfflineReader") << "The Ped Mean is " << _TH1F_Pedestals_all->GetMean() << " with rms "
267  << _TH1F_Pedestals_all->GetRMS() << std::endl;
268  edm::LogPrint("SiPixelCondObjOfflineReader") << " in BPIX " << _TH1F_Pedestals_bpix->GetMean()
269  << " with rms " << _TH1F_Pedestals_bpix->GetRMS() << std::endl;
270  edm::LogPrint("SiPixelCondObjOfflineReader") << " in FPIX " << _TH1F_Pedestals_fpix->GetMean()
271  << " with rms " << _TH1F_Pedestals_fpix->GetRMS() << std::endl;
272  }
273 
274  // ------------ method called once each job just after ending the event loop ------------
276  edm::LogPrint("SiPixelCondObjOfflineReader") << " ---> End job " << std::endl;
277  }
278 } // namespace cms
279 using namespace cms;
static const std::string kSharedResource
Definition: TFileService.h:76
T getUntrackedParameter(std::string const &, T const &) const
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
virtual int nrows() const =0
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Log< level::Error, false > LogError
bool getData(T &iHolder) const
Definition: EventSetup.h:128
std::map< uint32_t, double > _deadfrac_m
int iEvent
Definition: GenABIO.cc:224
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
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::map< uint32_t, TH1F * > _TH1F_Pedestals_m
T * make(const Args &...args) const
make new ROOT object
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
SiPixelCondObjOfflineReader(const edm::ParameterSet &iConfig)
std::unique_ptr< SiPixelGainCalibrationServiceBase > SiPixelGainCalibrationService_
Log< level::Warning, true > LogPrint
std::map< uint32_t, TH1F * > _TH1F_Gains_m
Log< level::Info, false > LogInfo
Definition: DetId.h:17
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::map< uint32_t, double > _noisyfrac_m
void analyze(const edm::Event &, const edm::EventSetup &) override