CMS 3D CMS Logo

SiStripApvGainInspector.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CondTools/SiStrip
4 // Class: SiStripApvGainInspector
5 //
6 /*
7  *\class SiStripApvGainInspector SiStripApvGainInspector.cc CalibTracker/SiStripChannelGain/plugins/SiStripApvGainInspector.cc
8 
9  Description: This module allows redo the per-APV gain fits with different PDFs (landau, landau + gaus convolution, etc.) starting from the Charge vs APV index plot produced in the SiStrip G2 APV gain PCL workflow. It is possible to inspect the 1D charge distributions for certain APVs after fitting by means of specifying them via the parameter selectedModules.
10 
11  Implementation: largely based off CalibTracker/SiStripChannelGain/src/SiStripGainsPCLHarvester.cc
12 
13 */
14 //
15 // Original Author: Marco Musich
16 // Created: Tue, 05 Jun 2018 15:46:15 GMT
17 //
18 //
19 
20 // system include files
21 #include <cmath> /* log */
22 #include <memory>
23 
24 // user include files
55 
56 // ROOT includes
57 #include "TStyle.h"
58 #include "TCanvas.h"
59 #include "TFile.h"
60 #include "TTree.h"
61 #include "TH1F.h"
62 #include "TH2S.h"
63 #include "TProfile.h"
64 #include "TF1.h"
65 
66 //
67 // class declaration
68 //
69 class SiStripApvGainInspector : public edm::one::EDAnalyzer<edm::one::SharedResources> {
70 public:
72  ~SiStripApvGainInspector() override;
73 
74  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
75 
76 private:
77  void beginJob() override;
78  void analyze(const edm::Event&, const edm::EventSetup&) override;
79  void endJob() override;
80  void checkBookAPVColls(const edm::EventSetup& es);
82  bool isGoodLandauFit(double* FitResults);
83  void getPeakOfLandau(TH1* InputHisto, double* FitResults, double LowRange = 50, double HighRange = 5400);
84  void getPeakOfLanGau(TH1* InputHisto, double* FitResults, double LowRange = 50, double HighRange = 5400);
85  void doFakeFit(TH1* InputHisto, double* FitResults);
86  void getPeakOfLandauAroundMax(TH1* InputHisto, double* FitResults, double LowRange = 100, double HighRange = 100);
87  static double langaufun(Double_t* x, Double_t* par);
89  void makeNicePlotStyle(TH1F* plot);
90  std::unique_ptr<SiStripApvGain> getNewObject();
91  std::map<std::string, TH1*> bookQualityMonitor(const TFileDirectory& dir);
92  void fillQualityMonitor();
93 
94  void inline fill1D(std::map<std::string, TH1*>& h, const std::string& s, double x) {
95  if (h.count(s) == 0) {
96  edm::LogWarning("SiStripApvGainInspector") << "Trying to fill non-existing Histogram named " << s << std::endl;
97  return;
98  }
99  h[s]->Fill(x);
100  }
101 
102  void inline fill2D(std::map<std::string, TH1*>& h, const std::string& s, double x, double y) {
103  if (h.count(s) == 0) {
104  edm::LogWarning("SiStripApvGainInspector") << "Trying to fill non-existing Histogram named " << s << std::endl;
105  return;
106  }
107  h[s]->Fill(x, y);
108  }
109 
110  // ----------member data ---------------------------
111  enum fitMode { landau = 1, landauAroundMax = 2, landauGauss = 3, fake = 4 };
112 
113  const std::vector<std::string> fitModeStrings = {
114  "", // Enum values start from 1, so index 0 is empty or can be used as "invalid"
115  "landau",
116  "landauAroundMax",
117  "landauGauss",
118  "fake"};
119 
120  inline bool isValidMode(int mode) const {
121  return mode == landau || mode == landauAroundMax || mode == landauGauss || mode == fake;
122  }
123 
128 
130 
131  // map the APV ids to the charge plots
132  std::map<std::pair<unsigned char, uint32_t>, TH1F*> histoMap_;
133 
135  const TrackerGeometry* bareTkGeomPtr_; // ugly hack to fill APV colls only once, but checks
137 
140 
141  unsigned int GOOD;
142  unsigned int BAD;
143  unsigned int MASKED;
144 
145  std::vector<std::shared_ptr<stAPVGain>> APVsCollOrdered;
146  std::unordered_map<unsigned int, std::shared_ptr<stAPVGain>> APVsColl;
147 
148  const TH2F* Charge_Vs_Index;
149  TFile* fin;
150  fitMode fitMode_; // Declare the enum variable
152  double minNrEntries;
153  std::vector<unsigned int> wantedmods;
154 
155  std::unique_ptr<TrackerMap> ratio_map;
156  std::unique_ptr<TrackerMap> old_payload_map;
157  std::unique_ptr<TrackerMap> new_payload_map;
158  std::unique_ptr<TrackerMap> mpv_map;
159  std::unique_ptr<TrackerMap> mpv_err_map;
160  std::unique_ptr<TrackerMap> entries_map;
161  std::unique_ptr<TrackerMap> fitChi2_map;
162 
163  std::map<std::string, TH1*> hControl;
164 };
165 
166 //
167 // constructors and destructor
168 //
170  : gainToken_(esConsumes()),
171  qualityToken_(esConsumes()),
172  tkGeomToken_(esConsumes()),
173  tTopoToken_(esConsumes()),
174  bareTkGeomPtr_(nullptr),
175  tTopo_(nullptr),
176  GOOD(0),
177  BAD(0),
178  filename_(iConfig.getUntrackedParameter<std::string>("inputFile")),
179  minNrEntries(iConfig.getUntrackedParameter<double>("minNrEntries", 20)),
180  wantedmods(iConfig.getUntrackedParameter<std::vector<unsigned int>>("selectedModules")) {
181  usesResource(TFileService::kSharedResource);
183 
184  sort(wantedmods.begin(), wantedmods.end());
185 
186  edm::LogInfo("SelectedModules") << "Selected module list";
187  for (std::vector<unsigned int>::const_iterator mod = wantedmods.begin(); mod != wantedmods.end(); mod++) {
188  edm::LogVerbatim("SelectedModules") << *mod;
189  }
190 
191  int modeValue = iConfig.getParameter<int>("fitMode");
192  if (!isValidMode(modeValue)) {
193  throw std::invalid_argument("Invalid value provided for 'fitMode'");
194  } else {
195  edm::LogPrint("SiStripApvGainInspector") << "Chosen fitting mode: " << fitModeStrings[modeValue];
196  }
197 
198  fitMode_ = static_cast<fitMode>(modeValue);
199 
200  //now do what ever initialization is needed
201  fin = TFile::Open(filename_.c_str(), "READ");
202  Charge_Vs_Index = (TH2F*)fin->Get("DQMData/Run 999999/AlCaReco/Run summary/SiStripGainsAAG/Charge_Vs_Index_AagBunch");
203 
204  ratio_map = std::make_unique<TrackerMap>("ratio");
205  ratio_map->setTitle("Average by module of the G2 Gain payload ratio (new/old)");
206  ratio_map->setPalette(1);
207 
208  new_payload_map = std::make_unique<TrackerMap>("new_payload");
209  new_payload_map->setTitle("Tracker Map of Updated G2 Gain payload averaged by module");
210  new_payload_map->setPalette(1);
211 
212  old_payload_map = std::make_unique<TrackerMap>("old_payload");
213  old_payload_map->setTitle("Tracker Map of Starting G2 Gain Payload averaged by module");
214  old_payload_map->setPalette(1);
215 
216  // fit quality maps
217 
218  mpv_map = std::make_unique<TrackerMap>("MPV");
219  mpv_map->setTitle("Landau Fit MPV average value per module [ADC counts/mm]");
220  mpv_map->setPalette(1);
221 
222  mpv_err_map = std::make_unique<TrackerMap>("MPVerr");
223  mpv_err_map->setTitle("Landau Fit MPV average error per module [ADC counts/mm]");
224  mpv_err_map->setPalette(1);
225 
226  entries_map = std::make_unique<TrackerMap>("Entries");
227  entries_map->setTitle("log_{10}(entries) average per module");
228  entries_map->setPalette(1);
229 
230  fitChi2_map = std::make_unique<TrackerMap>("FitChi2");
231  fitChi2_map->setTitle("log_{10}(Fit #chi^{2}/ndf) average per module");
232  fitChi2_map->setPalette(1);
233 }
234 
235 // do anything here that needs to be done at desctruction time
236 // (e.g. close files, deallocate resources etc.)
238  fin->Close();
239  delete fin;
240 }
241 
242 //
243 // member functions
244 //
245 
246 // ------------ method called for each event ------------
248  using namespace edm;
249  this->checkBookAPVColls(iSetup); // check whether APV colls are booked and do so if not yet done
250  this->checkAndRetrieveTopology(iSetup);
251 
252  edm::ESHandle<SiStripGain> gainHandle = iSetup.getHandle(gainToken_);
253  if (!gainHandle.isValid()) {
254  edm::LogError("SiStripApvGainInspector") << "gainHandle is not valid\n";
255  exit(0);
256  }
257 
258  edm::ESHandle<SiStripQuality> SiStripQuality_ = iSetup.getHandle(qualityToken_);
259 
260  for (unsigned int a = 0; a < APVsCollOrdered.size(); a++) {
261  std::shared_ptr<stAPVGain> APV = APVsCollOrdered[a];
262 
264  continue;
265 
266  APV->isMasked = SiStripQuality_->IsApvBad(APV->DetId, APV->APVId);
267 
268  if (gainHandle->getNumberOfTags() != 2) {
269  edm::LogError("SiStripApvGainInspector") << "NUMBER OF GAIN TAG IS EXPECTED TO BE 2\n";
270  fflush(stdout);
271  exit(0);
272  };
273  float newPreviousGain = gainHandle->getApvGain(APV->APVId, gainHandle->getRange(APV->DetId, 1), 1);
274  if (APV->PreviousGain != 1 and newPreviousGain != APV->PreviousGain)
275  edm::LogWarning("SiStripApvGainInspector") << "WARNING: ParticleGain in the global tag changed\n";
276  APV->PreviousGain = newPreviousGain;
277 
278  float newPreviousGainTick = gainHandle->getApvGain(APV->APVId, gainHandle->getRange(APV->DetId, 0), 0);
279  if (APV->PreviousGainTick != 1 and newPreviousGainTick != APV->PreviousGainTick) {
280  edm::LogWarning("SiStripApvGainInspector")
281  << "WARNING: TickMarkGain in the global tag changed\n"
282  << std::endl
283  << " APV->SubDet: " << APV->SubDet << " APV->APVId:" << APV->APVId << std::endl
284  << " APV->PreviousGainTick: " << APV->PreviousGainTick << " newPreviousGainTick: " << newPreviousGainTick
285  << std::endl;
286  }
287  APV->PreviousGainTick = newPreviousGainTick;
288  }
289 
290  unsigned int I = 0;
291  TH1F* Proj = nullptr;
292  double FitResults[6];
293  double MPVmean = 300;
294 
295  if (Charge_Vs_Index == nullptr) {
296  edm::LogError("SiStripGainsPCLHarvester") << "Harvesting: could not find input histogram " << std::endl;
297  return;
298  }
299 
300  printf("Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
301  printf("Fitting Charge Distribution :");
302  int TreeStep = APVsColl.size() / 50;
303 
304  for (auto it = APVsColl.begin(); it != APVsColl.end(); it++, I++) {
305  if (I % TreeStep == 0) {
306  printf(".");
307  fflush(stdout);
308  }
309  std::shared_ptr<stAPVGain> APV = it->second;
310  if (APV->Bin < 0)
311  APV->Bin = Charge_Vs_Index->GetXaxis()->FindBin(APV->Index);
312 
313  Proj = (TH1F*)(Charge_Vs_Index->ProjectionY(
314  "", Charge_Vs_Index->GetXaxis()->FindBin(APV->Index), Charge_Vs_Index->GetXaxis()->FindBin(APV->Index), "e"));
315  if (!Proj)
316  continue;
317 
318  switch (fitMode_) {
319  case landau:
320  getPeakOfLandau(Proj, FitResults);
321  break;
322  case landauAroundMax:
323  getPeakOfLandauAroundMax(Proj, FitResults);
324  break;
325  case landauGauss:
326  getPeakOfLanGau(Proj, FitResults);
327  break;
328  case fake:
329  doFakeFit(Proj, FitResults);
330  break;
331  default:
332  throw std::invalid_argument("Invalid value provided for 'fitMode'");
333  }
334 
335  APV->FitMPV = FitResults[0];
336  APV->FitMPVErr = FitResults[1];
337  APV->FitWidth = FitResults[2];
338  APV->FitWidthErr = FitResults[3];
339  APV->FitChi2 = FitResults[4];
340  APV->FitNorm = FitResults[5];
341  APV->NEntries = Proj->GetEntries();
342 
343  for (const auto& mod : wantedmods) {
344  if (mod == APV->DetId) {
345  edm::LogInfo("ModuleFound") << " module " << mod << " found! Storing... " << std::endl;
346  histoMap_[std::make_pair(APV->APVId, APV->DetId)] = (TH1F*)Proj->Clone(Form("hClone_%s", Proj->GetName()));
347  }
348  }
349 
350  if (isGoodLandauFit(FitResults)) {
351  APV->Gain = APV->FitMPV / MPVmean;
352  if (APV->SubDet > 2)
353  GOOD++;
354  } else {
355  APV->Gain = APV->PreviousGain;
356  if (APV->SubDet > 2)
357  BAD++;
358  }
359  if (APV->Gain <= 0)
360  APV->Gain = 1;
361 
362  delete Proj;
363  }
364  printf("\n");
365 }
366 
367 //********************************************************************************//
368 // ------------ method called once each job just before starting event loop ------------
371  const TrackerGeometry* newBareTkGeomPtr = &(*tkGeom_);
372  if (newBareTkGeomPtr == bareTkGeomPtr_)
373  return; // already filled APVColls, nothing changed
374 
375  if (!bareTkGeomPtr_) { // pointer not yet set: called the first time => fill the APVColls
376  auto const& Det = newBareTkGeomPtr->dets();
377 
378  unsigned int Index = 0;
379 
380  for (unsigned int i = 0; i < Det.size(); i++) {
381  DetId Detid = Det[i]->geographicalId();
382  int SubDet = Detid.subdetId();
383 
386  auto DetUnit = dynamic_cast<const StripGeomDetUnit*>(Det[i]);
387  if (!DetUnit)
388  continue;
389 
390  const StripTopology& Topo = DetUnit->specificTopology();
391  unsigned int NAPV = Topo.nstrips() / 128;
392 
393  for (unsigned int j = 0; j < NAPV; j++) {
394  auto APV = std::make_shared<stAPVGain>();
395  APV->Index = Index;
396  APV->Bin = -1;
397  APV->DetId = Detid.rawId();
398  APV->APVId = j;
399  APV->SubDet = SubDet;
400  APV->FitMPV = -1;
401  APV->FitMPVErr = -1;
402  APV->FitWidth = -1;
403  APV->FitWidthErr = -1;
404  APV->FitChi2 = -1;
405  APV->FitNorm = -1;
406  APV->Gain = -1;
407  APV->PreviousGain = 1;
408  APV->PreviousGainTick = 1;
409  APV->x = DetUnit->position().basicVector().x();
410  APV->y = DetUnit->position().basicVector().y();
411  APV->z = DetUnit->position().basicVector().z();
412  APV->Eta = DetUnit->position().basicVector().eta();
413  APV->Phi = DetUnit->position().basicVector().phi();
414  APV->R = DetUnit->position().basicVector().transverse();
415  APV->Thickness = DetUnit->surface().bounds().thickness();
416  APV->NEntries = 0;
417  APV->isMasked = false;
418 
419  APVsCollOrdered.push_back(APV);
420  APVsColl[(APV->DetId << 4) | APV->APVId] = APV;
421  Index++;
422  NStripAPVs++;
423  } // loop on APVs
424  } // if is Strips
425  } // loop on dets
426 
427  for (unsigned int i = 0; i < Det.size();
428  i++) { //Make two loop such that the Pixel information is added at the end --> make transition simpler
429  DetId Detid = Det[i]->geographicalId();
430  int SubDet = Detid.subdetId();
432  auto DetUnit = dynamic_cast<const PixelGeomDetUnit*>(Det[i]);
433  if (!DetUnit)
434  continue;
435 
436  const PixelTopology& Topo = DetUnit->specificTopology();
437  unsigned int NROCRow = Topo.nrows() / (80.);
438  unsigned int NROCCol = Topo.ncolumns() / (52.);
439 
440  for (unsigned int j = 0; j < NROCRow; j++) {
441  for (unsigned int i = 0; i < NROCCol; i++) {
442  auto APV = std::make_shared<stAPVGain>();
443  APV->Index = Index;
444  APV->Bin = -1;
445  APV->DetId = Detid.rawId();
446  APV->APVId = (j << 3 | i);
447  APV->SubDet = SubDet;
448  APV->FitMPV = -1;
449  APV->FitMPVErr = -1;
450  APV->FitWidth = -1;
451  APV->FitWidthErr = -1;
452  APV->FitChi2 = -1;
453  APV->Gain = -1;
454  APV->PreviousGain = 1;
455  APV->PreviousGainTick = 1;
456  APV->x = DetUnit->position().basicVector().x();
457  APV->y = DetUnit->position().basicVector().y();
458  APV->z = DetUnit->position().basicVector().z();
459  APV->Eta = DetUnit->position().basicVector().eta();
460  APV->Phi = DetUnit->position().basicVector().phi();
461  APV->R = DetUnit->position().basicVector().transverse();
462  APV->Thickness = DetUnit->surface().bounds().thickness();
463  APV->isMasked = false; //SiPixelQuality_->IsModuleBad(Detid.rawId());
464  APV->NEntries = 0;
465 
466  APVsCollOrdered.push_back(APV);
467  APVsColl[(APV->DetId << 4) | APV->APVId] = APV;
468  Index++;
469  NPixelDets++;
470 
471  } // loop on ROC cols
472  } // loop on ROC rows
473  } // if Pixel
474  } // loop on Dets
475  } //if (!bareTkGeomPtr_) ...
476  bareTkGeomPtr_ = newBareTkGeomPtr;
477 }
478 
480  unsigned int tree_Index;
481  unsigned int tree_Bin;
482  unsigned int tree_DetId;
483  unsigned char tree_APVId;
484  unsigned char tree_SubDet;
485  float tree_x;
486  float tree_y;
487  float tree_z;
488  float tree_Eta;
489  float tree_R;
490  float tree_Phi;
491  float tree_Thickness;
492  float tree_FitMPV;
493  float tree_FitMPVErr;
494  float tree_FitWidth;
495  float tree_FitWidthErr;
496  float tree_FitChi2NDF;
497  float tree_FitNorm;
498  double tree_Gain;
499  double tree_PrevGain;
500  double tree_PrevGainTick;
501  double tree_NEntries;
502  bool tree_isMasked;
503 
504  TTree* MyTree;
505  MyTree = tfs->make<TTree>("APVGain", "APVGain");
506  MyTree->Branch("Index", &tree_Index, "Index/i");
507  MyTree->Branch("Bin", &tree_Bin, "Bin/i");
508  MyTree->Branch("DetId", &tree_DetId, "DetId/i");
509  MyTree->Branch("APVId", &tree_APVId, "APVId/b");
510  MyTree->Branch("SubDet", &tree_SubDet, "SubDet/b");
511  MyTree->Branch("x", &tree_x, "x/F");
512  MyTree->Branch("y", &tree_y, "y/F");
513  MyTree->Branch("z", &tree_z, "z/F");
514  MyTree->Branch("Eta", &tree_Eta, "Eta/F");
515  MyTree->Branch("R", &tree_R, "R/F");
516  MyTree->Branch("Phi", &tree_Phi, "Phi/F");
517  MyTree->Branch("Thickness", &tree_Thickness, "Thickness/F");
518  MyTree->Branch("FitMPV", &tree_FitMPV, "FitMPV/F");
519  MyTree->Branch("FitMPVErr", &tree_FitMPVErr, "FitMPVErr/F");
520  MyTree->Branch("FitWidth", &tree_FitWidth, "FitWidth/F");
521  MyTree->Branch("FitWidthErr", &tree_FitWidthErr, "FitWidthErr/F");
522  MyTree->Branch("FitChi2NDF", &tree_FitChi2NDF, "FitChi2NDF/F");
523  MyTree->Branch("FitNorm", &tree_FitNorm, "FitNorm/F");
524  MyTree->Branch("Gain", &tree_Gain, "Gain/D");
525  MyTree->Branch("PrevGain", &tree_PrevGain, "PrevGain/D");
526  MyTree->Branch("PrevGainTick", &tree_PrevGainTick, "PrevGainTick/D");
527  MyTree->Branch("NEntries", &tree_NEntries, "NEntries/D");
528  MyTree->Branch("isMasked", &tree_isMasked, "isMasked/O");
529 
530  uint32_t cachedId(0);
531  SiStripMiscalibrate::Entry gain_ratio;
538 
539  for (unsigned int a = 0; a < APVsCollOrdered.size(); a++) {
540  std::shared_ptr<stAPVGain> APV = APVsCollOrdered[a];
541  if (APV == nullptr)
542  continue;
543  // printf( "%i | %i | PreviousGain = %7.5f NewGain = %7.5f (#clusters=%8.0f)\n", APV->DetId,APV->APVId,APV->PreviousGain,APV->Gain, APV->NEntries);
544  //fprintf(Gains,"%i | %i | PreviousGain = %7.5f(tick) x %7.5f(particle) NewGain (particle) = %7.5f (#clusters=%8.0f)\n", APV->DetId,APV->APVId,APV->PreviousGainTick, APV->PreviousGain,APV->Gain, APV->NEntries);
545 
546  // do not fill the Pixel
548  continue;
549 
550  tree_Index = APV->Index;
551  tree_Bin = Charge_Vs_Index->GetXaxis()->FindBin(APV->Index);
552  tree_DetId = APV->DetId;
553  tree_APVId = APV->APVId;
554  tree_SubDet = APV->SubDet;
555  tree_x = APV->x;
556  tree_y = APV->y;
557  tree_z = APV->z;
558  tree_Eta = APV->Eta;
559  tree_R = APV->R;
560  tree_Phi = APV->Phi;
561  tree_Thickness = APV->Thickness;
562  tree_FitMPV = APV->FitMPV;
563  tree_FitMPVErr = APV->FitMPVErr;
564  tree_FitWidth = APV->FitWidth;
565  tree_FitWidthErr = APV->FitWidthErr;
566  tree_FitChi2NDF = APV->FitChi2;
567  tree_FitNorm = APV->FitNorm;
568  tree_Gain = APV->Gain;
569  tree_PrevGain = APV->PreviousGain;
570  tree_PrevGainTick = APV->PreviousGainTick;
571  tree_NEntries = APV->NEntries;
572  tree_isMasked = APV->isMasked;
573 
574  // flush the counters
575  if (cachedId != 0 && tree_DetId != cachedId) {
576  //ratio_map->fill(cachedId,gain_ratio.mean());
577  ratio_map->fill(cachedId, o_gain.mean() / n_gain.mean());
578  old_payload_map->fill(cachedId, o_gain.mean());
579  new_payload_map->fill(cachedId, n_gain.mean());
580 
581  if (entries.mean() > 0) {
582  mpv_map->fill(cachedId, mpv.mean());
583  mpv_err_map->fill(cachedId, mpv_err.mean());
584  entries_map->fill(cachedId, log10(entries.mean()));
585  if (fitChi2.mean() > 0) {
586  fitChi2_map->fill(cachedId, log10(fitChi2.mean()));
587  } else {
588  fitChi2_map->fill(cachedId, -1);
589  }
590  }
591 
592  gain_ratio.reset();
593  o_gain.reset();
594  n_gain.reset();
595 
596  mpv.reset();
597  mpv_err.reset();
598  entries.reset();
599  fitChi2.reset();
600  }
601 
602  cachedId = tree_DetId;
603  gain_ratio.add(tree_PrevGain / tree_Gain);
604  o_gain.add(tree_PrevGain);
605  n_gain.add(tree_Gain);
606  mpv.add(tree_FitMPV);
607  mpv_err.add(tree_FitMPVErr);
608  entries.add(tree_NEntries);
609  fitChi2.add(tree_FitChi2NDF);
610 
611  if (tree_DetId == 402673324) {
612  printf("%i | %i : %f --> %f (%f)\n", tree_DetId, tree_APVId, tree_PrevGain, tree_Gain, tree_NEntries);
613  }
614 
615  MyTree->Fill();
616  }
617 }
618 
619 //********************************************************************************//
621  if (!tTopo_) {
622  edm::ESHandle<TrackerTopology> TopoHandle = setup.getHandle(tTopoToken_);
623  tTopo_ = TopoHandle.product();
624  }
625 }
626 
627 //********************************************************************************//
628 void SiStripApvGainInspector::getPeakOfLandau(TH1* InputHisto, double* FitResults, double LowRange, double HighRange) {
629  FitResults[0] = -0.5; //MPV
630  FitResults[1] = 0; //MPV error
631  FitResults[2] = -0.5; //Width
632  FitResults[3] = 0; //Width error
633  FitResults[4] = -0.5; //Fit Chi2/NDF
634  FitResults[5] = 0; //Normalization
635 
636  if (InputHisto->GetEntries() < minNrEntries)
637  return;
638 
639  // perform fit with standard landau
640  TF1 MyLandau("MyLandau", "landau", LowRange, HighRange);
641  MyLandau.SetParameter(1, 300);
642  InputHisto->Fit(&MyLandau, "QR WW");
643 
644  // MPV is parameter 1 (0=constant, 1=MPV, 2=Sigma)
645  FitResults[0] = MyLandau.GetParameter(1); //MPV
646  FitResults[1] = MyLandau.GetParError(1); //MPV error
647  FitResults[2] = MyLandau.GetParameter(2); //Width
648  FitResults[3] = MyLandau.GetParError(2); //Width error
649  FitResults[4] = MyLandau.GetChisquare() / MyLandau.GetNDF(); //Fit Chi2/NDF
650  FitResults[5] = MyLandau.GetParameter(0);
651 }
652 
653 void SiStripApvGainInspector::doFakeFit(TH1* InputHisto, double* FitResults) {
654  FitResults[0] = -0.5; //MPV
655  FitResults[1] = 0; //MPV error
656  FitResults[2] = -0.5; //Width
657  FitResults[3] = 0; //Width error
658  FitResults[4] = -0.5; //Fit Chi2/NDF
659  FitResults[5] = 0; //Normalization
660 }
661 
662 //********************************************************************************//
663 double SiStripApvGainInspector::langaufun(Double_t* x, Double_t* par)
664 //********************************************************************************//
665 {
666  //Fit parameters:
667  //par[0]=Width (scale) parameter of Landau density
668  //par[1]=Most Probable (MP, location) parameter of Landau density
669  //par[2]=Total area (integral -inf to inf, normalization constant)
670  //par[3]=Width (sigma) of convoluted Gaussian function
671  //
672  //In the Landau distribution (represented by the CERNLIB approximation),
673  //the maximum is located at x=-0.22278298 with the location parameter=0.
674  //This shift is corrected within this function, so that the actual
675  //maximum is identical to the MP parameter.
676 
677  // Numeric constants
678  Double_t invsq2pi = 0.3989422804014; // (2 pi)^(-1/2)
679  Double_t mpshift = -0.22278298; // Landau maximum location
680 
681  // Control constants
682  Double_t np = 100.0; // number of convolution steps
683  Double_t sc = 5.0; // convolution extends to +-sc Gaussian sigmas
684 
685  // Variables
686  Double_t xx;
687  Double_t mpc;
688  Double_t fland;
689  Double_t sum = 0.0;
690  Double_t xlow, xupp;
691  Double_t step;
692  Double_t i;
693 
694  // MP shift correction
695  mpc = par[1] - mpshift * par[0];
696 
697  // Range of convolution integral
698  xlow = x[0] - sc * par[3];
699  xupp = x[0] + sc * par[3];
700 
701  step = (xupp - xlow) / np;
702 
703  // Convolution integral of Landau and Gaussian by sum
704  for (i = 1.0; i <= np / 2; i++) {
705  xx = xlow + (i - .5) * step;
706  fland = TMath::Landau(xx, mpc, par[0]) / par[0];
707  sum += fland * TMath::Gaus(x[0], xx, par[3]);
708 
709  xx = xupp - (i - .5) * step;
710  fland = TMath::Landau(xx, mpc, par[0]) / par[0];
711  sum += fland * TMath::Gaus(x[0], xx, par[3]);
712  }
713 
714  return (par[2] * step * sum * invsq2pi / par[3]);
715 }
716 
717 //********************************************************************************//
718 void SiStripApvGainInspector::getPeakOfLanGau(TH1* InputHisto, double* FitResults, double LowRange, double HighRange) {
719  FitResults[0] = -0.5; //MPV
720  FitResults[1] = 0; //MPV error
721  FitResults[2] = -0.5; //Width
722  FitResults[3] = 0; //Width error
723  FitResults[4] = -0.5; //Fit Chi2/NDF
724  FitResults[5] = 0; //Normalization
725 
726  if (InputHisto->GetEntries() < minNrEntries)
727  return;
728 
729  // perform fit with standard landau
730  TF1 MyLandau("MyLandau", "landau", LowRange, HighRange);
731  MyLandau.SetParameter(1, 300);
732  InputHisto->Fit(&MyLandau, "QR WW");
733 
734  double startvalues[4] = {100, 300, 10000, 100};
735  double parlimitslo[4] = {0, 250, 10, 0};
736  double parlimitshi[4] = {200, 350, 1000000, 200};
737 
738  TF1 MyLangau("MyLanGau", langaufun, LowRange, HighRange, 4);
739 
740  MyLangau.SetParameters(startvalues);
741  MyLangau.SetParNames("Width", "MP", "Area", "GSigma");
742 
743  for (unsigned int i = 0; i < 4; i++) {
744  MyLangau.SetParLimits(i, parlimitslo[i], parlimitshi[i]);
745  }
746 
747  InputHisto->Fit("MyLanGau", "QRB0"); // fit within specified range, use ParLimits, do not plot
748 
749  // MPV is parameter 1 (0=constant, 1=MPV, 2=Sigma)
750  FitResults[0] = MyLangau.GetParameter(1); //MPV
751  FitResults[1] = MyLangau.GetParError(1); //MPV error
752  FitResults[2] = MyLangau.GetParameter(0); //Width
753  FitResults[3] = MyLangau.GetParError(0); //Width error
754  FitResults[4] = MyLangau.GetChisquare() / MyLangau.GetNDF(); //Fit Chi2/NDF
755  FitResults[5] = MyLangau.GetParameter(3);
756 }
757 
758 //********************************************************************************//
760  double* FitResults,
761  double LowRange,
762  double HighRange) {
763  FitResults[0] = -0.5; //MPV
764  FitResults[1] = 0; //MPV error
765  FitResults[2] = -0.5; //Width
766  FitResults[3] = 0; //Width error
767  FitResults[4] = -0.5; //Fit Chi2/NDF
768  FitResults[5] = 0; //Normalization
769 
770  if (InputHisto->GetEntries() < minNrEntries)
771  return;
772 
773  int maxbin = InputHisto->GetMaximumBin();
774  int maxbin2 = -9999.;
775 
776  if (InputHisto->GetBinContent(maxbin - 1) > InputHisto->GetBinContent(maxbin + 1)) {
777  maxbin2 = maxbin - 1;
778  } else {
779  maxbin2 = maxbin + 1;
780  }
781 
782  float maxbincenter = (InputHisto->GetBinCenter(maxbin) + InputHisto->GetBinCenter(maxbin2)) / 2;
783 
784  TF1 MyLandau("MyLandau", "[2]*TMath::Landau(x,[0],[1],0)", maxbincenter - LowRange, maxbincenter + HighRange);
785  // TF1 MyLandau("MyLandau", "landau", LowRange, HighRange);
786  // MyLandau.SetParameter(1, 300);
787  InputHisto->Fit(&MyLandau, "QR WW");
788 
789  MyLandau.SetParameter(0, maxbincenter);
790  MyLandau.SetParameter(1, maxbincenter / 10.);
791  MyLandau.SetParameter(2, InputHisto->GetMaximum());
792 
793  float mpv = MyLandau.GetParameter(1);
794  MyLandau.SetParameter(1, mpv);
795  //InputHisto->Rebin(3);
796  InputHisto->Fit(&MyLandau, "QOR", "", mpv - 50, mpv + 100);
797 
798  InputHisto->Fit(&MyLandau, "QOR", "", maxbincenter - LowRange, maxbincenter + HighRange);
799  InputHisto->Fit(&MyLandau, "QOR", "", maxbincenter - LowRange, maxbincenter + HighRange);
800 
801  // MPV is parameter 1 (0=constant, 1=MPV, 2=Sigma)
802  FitResults[0] = MyLandau.GetParameter(1); //MPV
803  FitResults[1] = MyLandau.GetParError(1); //MPV error
804  FitResults[2] = MyLandau.GetParameter(2); //Width
805  FitResults[3] = MyLandau.GetParError(2); //Width error
806  FitResults[4] = MyLandau.GetChisquare() / MyLandau.GetNDF(); //Fit Chi2/NDF
807  FitResults[5] = MyLandau.GetParameter(0);
808 }
809 
810 //********************************************************************************//
812  if (FitResults[0] <= 0)
813  return false;
814  // if(FitResults[1] > MaxMPVError )return false;
815  // if(FitResults[4] > MaxChi2OverNDF)return false;
816  return true;
817 }
818 
819 /*--------------------------------------------------------------------*/
821 /*--------------------------------------------------------------------*/
822 {
823  plot->GetXaxis()->CenterTitle(true);
824  plot->GetYaxis()->CenterTitle(true);
825  plot->GetXaxis()->SetTitleFont(42);
826  plot->GetYaxis()->SetTitleFont(42);
827  plot->GetXaxis()->SetTitleSize(0.05);
828  plot->GetYaxis()->SetTitleSize(0.05);
829  plot->GetXaxis()->SetTitleOffset(0.9);
830  plot->GetYaxis()->SetTitleOffset(1.3);
831  plot->GetXaxis()->SetLabelFont(42);
832  plot->GetYaxis()->SetLabelFont(42);
833  plot->GetYaxis()->SetLabelSize(.05);
834  plot->GetXaxis()->SetLabelSize(.05);
835 }
836 
837 //********************************************************************************//
838 std::unique_ptr<SiStripApvGain> SiStripApvGainInspector::getNewObject() {
839  std::unique_ptr<SiStripApvGain> obj = std::make_unique<SiStripApvGain>();
840 
841  std::vector<float> theSiStripVector;
842  unsigned int PreviousDetId = 0;
843  for (unsigned int a = 0; a < APVsCollOrdered.size(); a++) {
844  std::shared_ptr<stAPVGain> APV = APVsCollOrdered[a];
845  if (APV == nullptr) {
846  printf("Bug\n");
847  continue;
848  }
849  if (APV->SubDet <= 2)
850  continue;
851  if (APV->DetId != PreviousDetId) {
852  if (!theSiStripVector.empty()) {
853  SiStripApvGain::Range range(theSiStripVector.begin(), theSiStripVector.end());
854  if (!obj->put(PreviousDetId, range))
855  printf("Bug to put detId = %i\n", PreviousDetId);
856  }
857  theSiStripVector.clear();
858  PreviousDetId = APV->DetId;
859  }
860  theSiStripVector.push_back(APV->Gain);
861 
862  LogDebug("SiStripGainsPCLHarvester") << " DetId: " << APV->DetId << " APV: " << APV->APVId
863  << " Gain: " << APV->Gain << std::endl;
864  }
865  if (!theSiStripVector.empty()) {
866  SiStripApvGain::Range range(theSiStripVector.begin(), theSiStripVector.end());
867  if (!obj->put(PreviousDetId, range))
868  printf("Bug to put detId = %i\n", PreviousDetId);
869  }
870 
871  return obj;
872 }
873 
874 // ------------ method called once each job just before starting event loop ------------
876  TFileDirectory control_dir = tfs->mkdir("Control");
877  //DA.cd();
878  hControl = this->bookQualityMonitor(control_dir);
879 }
880 
881 // ------------ method called once each job just after ending the event loop ------------
883  edm::LogVerbatim("SelectedModules") << "Selected APVs:" << histoMap_.size() << std::endl;
884  for (const auto& plot : histoMap_) {
885  TCanvas* c1 = new TCanvas(Form("c1_%i_%i", plot.first.second, plot.first.first),
886  Form("c1_%i_%i", plot.first.second, plot.first.first),
887  800,
888  600);
889  // Define common things for the different fits
890 
891  gStyle->SetOptFit(1011);
892  c1->Clear();
893 
894  c1->SetLeftMargin(0.15);
895  c1->SetRightMargin(0.10);
896  plot.second->SetTitle(Form("Cluster Charge (%i,%i)", plot.first.second, plot.first.first));
897  plot.second->GetXaxis()->SetTitle("Normalized Cluster Charge [ADC counts/mm]");
898  plot.second->GetYaxis()->SetTitle("On-track clusters");
899  plot.second->GetXaxis()->SetRangeUser(0., 1000.);
900 
901  this->makeNicePlotStyle(plot.second);
902  plot.second->Draw();
903  edm::LogVerbatim("SelectedModules") << " DetId: " << plot.first.second << " (" << plot.first.first << ")"
904  << std::endl;
905  ;
906 
907  c1->Print(Form("c1_%i_%i.png", plot.first.second, plot.first.first));
908  c1->Print(Form("c1_%i_%i.pdf", plot.first.second, plot.first.first));
909  }
910 
912  storeOnTree(tfs);
913 
915 
916  ratio_map->save(true, range.first, range.second, "G2_gain_ratio_map.pdf");
917  ratio_map->save(true, range.first, range.second, "G2_gain_ratio_map.png");
918 
920 
921  old_payload_map->save(true, range.first, range.second, "starting_G2_gain_payload_map.pdf");
922  old_payload_map->save(true, range.first, range.second, "starting_G2_gain_payload_map.png");
923 
925 
926  new_payload_map->save(true, range.first, range.second, "new_G2_gain_payload_map.pdf");
927  new_payload_map->save(true, range.first, range.second, "new_G2_gain_payload_map.png");
928 
929  mpv_map->save(true, 250, 350., "mpv_map.pdf");
930  mpv_map->save(true, 250, 350., "mpv_map.png");
931 
932  mpv_err_map->save(true, 0., 3., "mpv_err_map.pdf");
933  mpv_err_map->save(true, 0., 3., "mpv_err_map.png");
934 
935  entries_map->save(true, 0, 0, "entries_map.pdf");
936  entries_map->save(true, 0, 0, "entries_map.png");
937 
938  fitChi2_map->save(true, 0., 0., "fitChi2_map.pdf");
939  fitChi2_map->save(true, 0., 0., "fitChi2_map.png");
940 
942 
943  std::unique_ptr<SiStripApvGain> theAPVGains = this->getNewObject();
944 
945  // write out the APVGains record
947 
948  if (poolDbService.isAvailable())
949  poolDbService->writeOneIOV(theAPVGains.get(), poolDbService->currentTime(), "SiStripApvGainRcd");
950  else
951  throw std::runtime_error("PoolDBService required.");
952 }
953 
955  int MPVbin = 300;
956  float MPVmin = 0.;
957  float MPVmax = 600.;
958 
959  TH1F::SetDefaultSumw2(kTRUE);
960  std::map<std::string, TH1*> h;
961 
962  h["MPV_Vs_EtaTIB"] = dir.make<TH2F>("MPVvsEtaTIB", "MPV vs Eta TIB", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
963  h["MPV_Vs_EtaTID"] = dir.make<TH2F>("MPVvsEtaTID", "MPV vs Eta TID", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
964  h["MPV_Vs_EtaTOB"] = dir.make<TH2F>("MPVvsEtaTOB", "MPV vs Eta TOB", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
965  h["MPV_Vs_EtaTEC"] = dir.make<TH2F>("MPVvsEtaTEC", "MPV vs Eta TEC", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
966  h["MPV_Vs_EtaTECthin"] = dir.make<TH2F>("MPVvsEtaTEC1", "MPV vs Eta TEC-thin", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
967  h["MPV_Vs_EtaTECthick"] =
968  dir.make<TH2F>("MPVvsEtaTEC2", "MPV vs Eta TEC-thick", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
969 
970  h["MPV_Vs_PhiTIB"] = dir.make<TH2F>("MPVvsPhiTIB", "MPV vs Phi TIB", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
971  h["MPV_Vs_PhiTID"] = dir.make<TH2F>("MPVvsPhiTID", "MPV vs Phi TID", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
972  h["MPV_Vs_PhiTOB"] = dir.make<TH2F>("MPVvsPhiTOB", "MPV vs Phi TOB", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
973  h["MPV_Vs_PhiTEC"] = dir.make<TH2F>("MPVvsPhiTEC", "MPV vs Phi TEC", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
974  h["MPV_Vs_PhiTECthin"] =
975  dir.make<TH2F>("MPVvsPhiTEC1", "MPV vs Phi TEC-thin ", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
976  h["MPV_Vs_PhiTECthick"] =
977  dir.make<TH2F>("MPVvsPhiTEC2", "MPV vs Phi TEC-thick", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
978 
979  h["NoMPVfit"] = dir.make<TH2F>("NoMPVfit", "Modules with bad Landau Fit", 350, -350, 350, 240, 0, 120);
980  h["NoMPVmasked"] = dir.make<TH2F>("NoMPVmasked", "Masked Modules", 350, -350, 350, 240, 0, 120);
981 
982  h["Gains"] = dir.make<TH1F>("Gains", "Gains", 300, 0, 2);
983  h["MPVs"] = dir.make<TH1F>("MPVs", "MPVs", MPVbin, MPVmin, MPVmax);
984  h["MPVs320"] = dir.make<TH1F>("MPV_320", "MPV 320 thickness", MPVbin, MPVmin, MPVmax);
985  h["MPVs500"] = dir.make<TH1F>("MPV_500", "MPV 500 thickness", MPVbin, MPVmin, MPVmax);
986  h["MPVsTIB"] = dir.make<TH1F>("MPV_TIB", "MPV TIB", MPVbin, MPVmin, MPVmax);
987  h["MPVsTID"] = dir.make<TH1F>("MPV_TID", "MPV TID", MPVbin, MPVmin, MPVmax);
988  h["MPVsTIDP"] = dir.make<TH1F>("MPV_TIDP", "MPV TIDP", MPVbin, MPVmin, MPVmax);
989  h["MPVsTIDM"] = dir.make<TH1F>("MPV_TIDM", "MPV TIDM", MPVbin, MPVmin, MPVmax);
990  h["MPVsTOB"] = dir.make<TH1F>("MPV_TOB", "MPV TOB", MPVbin, MPVmin, MPVmax);
991  h["MPVsTEC"] = dir.make<TH1F>("MPV_TEC", "MPV TEC", MPVbin, MPVmin, MPVmax);
992  h["MPVsTECP"] = dir.make<TH1F>("MPV_TECP", "MPV TECP", MPVbin, MPVmin, MPVmax);
993  h["MPVsTECM"] = dir.make<TH1F>("MPV_TECM", "MPV TECM", MPVbin, MPVmin, MPVmax);
994  h["MPVsTECthin"] = dir.make<TH1F>("MPV_TEC1", "MPV TEC thin", MPVbin, MPVmin, MPVmax);
995  h["MPVsTECthick"] = dir.make<TH1F>("MPV_TEC2", "MPV TEC thick", MPVbin, MPVmin, MPVmax);
996  h["MPVsTECP1"] = dir.make<TH1F>("MPV_TECP1", "MPV TECP thin ", MPVbin, MPVmin, MPVmax);
997  h["MPVsTECP2"] = dir.make<TH1F>("MPV_TECP2", "MPV TECP thick", MPVbin, MPVmin, MPVmax);
998  h["MPVsTECM1"] = dir.make<TH1F>("MPV_TECM1", "MPV TECM thin", MPVbin, MPVmin, MPVmax);
999  h["MPVsTECM2"] = dir.make<TH1F>("MPV_TECM2", "MPV TECM thick", MPVbin, MPVmin, MPVmax);
1000 
1001  h["MPVError"] = dir.make<TH1F>("MPVError", "MPV Error", 150, 0, 150);
1002  h["MPVErrorVsMPV"] = dir.make<TH2F>("MPVErrorVsMPV", "MPV Error vs MPV", 300, 0, 600, 150, 0, 150);
1003  h["MPVErrorVsEta"] = dir.make<TH2F>("MPVErrorVsEta", "MPV Error vs Eta", 50, -3.0, 3.0, 150, 0, 150);
1004  h["MPVErrorVsPhi"] = dir.make<TH2F>("MPVErrorVsPhi", "MPV Error vs Phi", 50, -3.4, 3.4, 150, 0, 150);
1005  h["MPVErrorVsN"] = dir.make<TH2F>("MPVErrorVsN", "MPV Error vs N", 500, 0, 1000, 150, 0, 150);
1006 
1007  h["DiffWRTPrevGainTIB"] = dir.make<TH1F>("DiffWRTPrevGainTIB", "Diff w.r.t. PrevGain TIB", 250, 0.5, 1.5);
1008  h["DiffWRTPrevGainTID"] = dir.make<TH1F>("DiffWRTPrevGainTID", "Diff w.r.t. PrevGain TID", 250, 0.5, 1.5);
1009  h["DiffWRTPrevGainTOB"] = dir.make<TH1F>("DiffWRTPrevGainTOB", "Diff w.r.t. PrevGain TOB", 250, 0.5, 1.5);
1010  h["DiffWRTPrevGainTEC"] = dir.make<TH1F>("DiffWRTPrevGainTEC", "Diff w.r.t. PrevGain TEC", 250, 0.5, 1.5);
1011 
1012  h["GainVsPrevGainTIB"] = dir.make<TH2F>("GainVsPrevGainTIB", "Gain vs PrevGain TIB", 100, 0, 2, 100, 0, 2);
1013  h["GainVsPrevGainTID"] = dir.make<TH2F>("GainVsPrevGainTID", "Gain vs PrevGain TID", 100, 0, 2, 100, 0, 2);
1014  h["GainVsPrevGainTOB"] = dir.make<TH2F>("GainVsPrevGainTOB", "Gain vs PrevGain TOB", 100, 0, 2, 100, 0, 2);
1015  h["GainVsPrevGainTEC"] = dir.make<TH2F>("GainVsPrevGainTEC", "Gain vs PrevGain TEC", 100, 0, 2, 100, 0, 2);
1016 
1017  return h;
1018 }
1019 
1021  for (unsigned int a = 0; a < APVsCollOrdered.size(); a++) {
1022  std::shared_ptr<stAPVGain> APV = APVsCollOrdered[a];
1023  if (APV == nullptr)
1024  continue;
1025 
1026  //unsigned int Index = APV->Index;
1027  //unsigned int DetId = APV->DetId;
1028  unsigned int SubDet = APV->SubDet;
1029  float z = APV->z;
1030  float Eta = APV->Eta;
1031  float R = APV->R;
1032  float Phi = APV->Phi;
1033  float Thickness = APV->Thickness;
1034  double FitMPV = APV->FitMPV;
1035  double FitMPVErr = APV->FitMPVErr;
1036  double Gain = APV->Gain;
1037  double NEntries = APV->NEntries;
1038  double PreviousGain = APV->PreviousGain;
1039 
1040  if (SubDet < 3)
1041  continue; // avoid to loop over Pixel det id
1042 
1043  if (FitMPV <= 0.) { // No fit of MPV
1044  if (APV->isMasked)
1045  fill2D(hControl, "NoMPVmasked", z, R);
1046  else
1047  fill2D(hControl, "NoMPVfit", z, R);
1048  } else { // Fit of MPV
1049  if (FitMPV > 0.)
1050  fill1D(hControl, "Gains", Gain);
1051 
1052  fill1D(hControl, "MPVs", FitMPV);
1053  if (Thickness < 0.04)
1054  fill1D(hControl, "MPVs320", FitMPV);
1055  if (Thickness > 0.04)
1056  fill1D(hControl, "MPVs500", FitMPV);
1057 
1058  fill1D(hControl, "MPVError", FitMPVErr);
1059  fill2D(hControl, "MPVErrorVsMPV", FitMPV, FitMPVErr);
1060  fill2D(hControl, "MPVErrorVsEta", Eta, FitMPVErr);
1061  fill2D(hControl, "MPVErrorVsPhi", Phi, FitMPVErr);
1062  fill2D(hControl, "MPVErrorVsN", NEntries, FitMPVErr);
1063 
1064  if (SubDet == 3) {
1065  fill2D(hControl, "MPV_Vs_EtaTIB", Eta, FitMPV);
1066  fill2D(hControl, "MPV_Vs_PhiTIB", Phi, FitMPV);
1067  fill1D(hControl, "MPVsTIB", FitMPV);
1068 
1069  } else if (SubDet == 4) {
1070  fill2D(hControl, "MPV_Vs_EtaTID", Eta, FitMPV);
1071  fill2D(hControl, "MPV_Vs_PhiTID", Phi, FitMPV);
1072  fill1D(hControl, "MPVsTID", FitMPV);
1073  if (Eta < 0.)
1074  fill1D(hControl, "MPVsTIDM", FitMPV);
1075  if (Eta > 0.)
1076  fill1D(hControl, "MPVsTIDP", FitMPV);
1077 
1078  } else if (SubDet == 5) {
1079  fill2D(hControl, "MPV_Vs_EtaTOB", Eta, FitMPV);
1080  fill2D(hControl, "MPV_Vs_PhiTOB", Phi, FitMPV);
1081  fill1D(hControl, "MPVsTOB", FitMPV);
1082 
1083  } else if (SubDet == 6) {
1084  fill2D(hControl, "MPV_Vs_EtaTEC", Eta, FitMPV);
1085  fill2D(hControl, "MPV_Vs_PhiTEC", Phi, FitMPV);
1086  fill1D(hControl, "MPVsTEC", FitMPV);
1087  if (Eta < 0.)
1088  fill1D(hControl, "MPVsTECM", FitMPV);
1089  if (Eta > 0.)
1090  fill1D(hControl, "MPVsTECP", FitMPV);
1091  if (Thickness < 0.04) {
1092  fill2D(hControl, "MPV_Vs_EtaTECthin", Eta, FitMPV);
1093  fill2D(hControl, "MPV_Vs_PhiTECthin", Phi, FitMPV);
1094  fill1D(hControl, "MPVsTECthin", FitMPV);
1095  if (Eta > 0.)
1096  fill1D(hControl, "MPVsTECP1", FitMPV);
1097  if (Eta < 0.)
1098  fill1D(hControl, "MPVsTECM1", FitMPV);
1099  }
1100  if (Thickness > 0.04) {
1101  fill2D(hControl, "MPV_Vs_EtaTECthick", Eta, FitMPV);
1102  fill2D(hControl, "MPV_Vs_PhiTECthick", Phi, FitMPV);
1103  fill1D(hControl, "MPVsTECthick", FitMPV);
1104  if (Eta > 0.)
1105  fill1D(hControl, "MPVsTECP2", FitMPV);
1106  if (Eta < 0.)
1107  fill1D(hControl, "MPVsTECM2", FitMPV);
1108  }
1109  }
1110  }
1111 
1112  if (SubDet == 3 && PreviousGain != 0.)
1113  fill1D(hControl, "DiffWRTPrevGainTIB", Gain / PreviousGain);
1114  else if (SubDet == 4 && PreviousGain != 0.)
1115  fill1D(hControl, "DiffWRTPrevGainTID", Gain / PreviousGain);
1116  else if (SubDet == 5 && PreviousGain != 0.)
1117  fill1D(hControl, "DiffWRTPrevGainTOB", Gain / PreviousGain);
1118  else if (SubDet == 6 && PreviousGain != 0.)
1119  fill1D(hControl, "DiffWRTPrevGainTEC", Gain / PreviousGain);
1120 
1121  if (SubDet == 3)
1122  fill2D(hControl, "GainVsPrevGainTIB", PreviousGain, Gain);
1123  else if (SubDet == 4)
1124  fill2D(hControl, "GainVsPrevGainTID", PreviousGain, Gain);
1125  else if (SubDet == 5)
1126  fill2D(hControl, "GainVsPrevGainTOB", PreviousGain, Gain);
1127  else if (SubDet == 6)
1128  fill2D(hControl, "GainVsPrevGainTEC", PreviousGain, Gain);
1129 
1130  } // loop on the APV collections
1131 }
1132 
1133 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
1136  desc.addUntracked<std::string>("inputFile", {});
1137  desc.addUntracked<double>("minNrEntries", 20);
1138  desc.add<int>("fitMode", 2)
1139  ->setComment("fit mode. Available options: 1: landau\n 2: landau around max\n 3:landau&gaus convo\n 4: fake");
1140  desc.addUntracked<std::vector<unsigned int>>("selectedModules", {});
1141  descriptions.addWithDefaultLabel(desc);
1142 }
1143 
1144 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
Log< level::Info, true > LogVerbatim
static constexpr auto TEC
virtual int nstrips() const =0
std::unique_ptr< TrackerMap > mpv_err_map
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
void getPeakOfLanGau(TH1 *InputHisto, double *FitResults, double LowRange=50, double HighRange=5400)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::map< std::string, TH1 * > hControl
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
static double langaufun(Double_t *x, Double_t *par)
std::map< std::string, TH1 * > bookQualityMonitor(const TFileDirectory &dir)
bool IsApvBad(uint32_t detid, short apvNb) const
bool isValidMode(int mode) const
std::unique_ptr< TrackerMap > entries_map
virtual int ncolumns() const =0
std::unique_ptr< TrackerMap > new_payload_map
virtual int nrows() const =0
std::unique_ptr< TrackerMap > mpv_map
SiStripApvGainInspector(const edm::ParameterSet &)
void storeOnTree(TFileService *tfs)
const SiStripApvGain::Range getRange(uint32_t detID) const
Definition: SiStripGain.h:75
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
void doFakeFit(TH1 *InputHisto, double *FitResults)
std::vector< unsigned int > wantedmods
Log< level::Error, false > LogError
std::unique_ptr< TrackerMap > fitChi2_map
static double fitChi2(const CachingVertex< 5 > &vtx)
void analyze(const edm::Event &, const edm::EventSetup &) override
static float getApvGain(const uint16_t &apv, const SiStripApvGain::Range &range)
Definition: SiStripGain.h:80
std::unordered_map< unsigned int, std::shared_ptr< stAPVGain > > APVsColl
void getPeakOfLandauAroundMax(TH1 *InputHisto, double *FitResults, double LowRange=100, double HighRange=100)
size_t getNumberOfTags() const
Definition: SiStripGain.h:99
int iEvent
Definition: GenABIO.cc:224
T const * product() const
Definition: ESHandle.h:86
int np
Definition: AMPTWrapper.h:43
SubDet
Definition: ModulesSoA.h:11
const std::vector< std::string > fitModeStrings
const TrackerTopology * tTopo_
std::unique_ptr< TrackerMap > old_payload_map
std::pair< ContainerIterator, ContainerIterator > Range
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
const std::complex< double > I
Definition: I.h:8
#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
std::unique_ptr< TrackerMap > ratio_map
double const GOOD
Definition: Constants.h:13
static constexpr auto TOB
Log< level::Warning, true > LogPrint
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
std::unique_ptr< SiStripApvGain > getNewObject()
const edm::ESGetToken< SiStripGain, SiStripGainRcd > gainToken_
bool isValid() const
Definition: ESHandle.h:44
std::map< std::pair< unsigned char, uint32_t >, TH1F * > histoMap_
void fill1D(std::map< std::string, TH1 *> &h, const std::string &s, double x)
Log< level::Info, false > LogInfo
Definition: DetId.h:17
double const BAD
Definition: Constants.h:15
static constexpr auto TIB
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
const TrackerGeometry * bareTkGeomPtr_
std::pair< float, float > getTruncatedRange(const TrackerMap *theMap)
bool isGoodLandauFit(double *FitResults)
std::vector< std::shared_ptr< stAPVGain > > APVsCollOrdered
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void checkBookAPVColls(const edm::EventSetup &es)
static const std::string kSharedResource
HLT enums.
double a
Definition: hdecay.h:121
edm::ESHandle< TrackerGeometry > tkGeom_
void fill2D(std::map< std::string, TH1 *> &h, const std::string &s, double x, double y)
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
bool isAvailable() const
Definition: Service.h:40
step
Definition: StallMonitor.cc:83
Log< level::Warning, false > LogWarning
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
static constexpr auto TID
void checkAndRetrieveTopology(const edm::EventSetup &setup)
const edm::ESGetToken< SiStripQuality, SiStripQualityRcd > qualityToken_
void getPeakOfLandau(TH1 *InputHisto, double *FitResults, double LowRange=50, double HighRange=5400)
#define LogDebug(id)
def exit(msg="")