CMS 3D CMS Logo

SiStripGainFromCalibTree.cc
Go to the documentation of this file.
1 // Original Author: Loic QUERTENMONT
2 // Created: Mon Nov 16 08:55:18 CET 2009
3 
4 #include <memory>
5 #include <iostream>
6 
16 
18 
24 
32 
34 
37 
50 
53 
56 
60 
63 
66 
67 #include "TFile.h"
68 #include "TObjString.h"
69 #include "TString.h"
70 #include "TH1F.h"
71 #include "TH2S.h"
72 #include "TProfile.h"
73 #include "TF1.h"
74 #include "TROOT.h"
75 #include "TTree.h"
76 #include "TChain.h"
77 
78 // user includes
81 
82 #include <unordered_map>
83 #include <array>
84 
85 using namespace edm;
86 using namespace reco;
87 using namespace std;
88 using namespace APVGain;
89 
90 class SiStripGainFromCalibTree : public ConditionDBWriter<SiStripApvGain> {
91 public:
95  ~SiStripGainFromCalibTree() override;
96 
97 private:
98  void algoBeginRun(const edm::Run& run, const edm::EventSetup& iSetup) override;
99  void algoEndRun(const edm::Run& run, const edm::EventSetup& iSetup) override;
100  void algoBeginJob(const edm::EventSetup& iSetup) override;
101  void algoEndJob() override;
102  void algoAnalyze(const edm::Event&, const edm::EventSetup&) override;
103 
104  int statCollectionFromMode(const char* tag) const;
105  void bookDQMHistos(const char* dqm_dir, const char* tag);
106 
107  bool isBFieldConsistentWithMode(const edm::EventSetup& iSetup) const;
108  void swapBFieldMode(void);
109 
110  void merge(TH2* A, TH2* B); //needed to add histograms with different number of bins
111  void algoAnalyzeTheTree();
112  void algoComputeMPVandGain();
113  void processEvent(); //what really does the job
114 
115  void getPeakOfLandau(TH1* InputHisto, double* FitResults, double LowRange = 50, double HighRange = 5400);
116  bool IsGoodLandauFit(double* FitResults);
117  void storeOnTree(TFileService* tfs);
118  void qualityMonitor();
119  void MakeCalibrationMap();
120  bool produceTagFilter();
121 
122  template <typename T>
123  inline edm::Handle<T> connect(const T*& ptr, edm::EDGetTokenT<T> token, const edm::Event& evt) {
125  evt.getByToken(token, handle);
126  ptr = handle.product();
127  return handle; //return handle to keep alive pointer (safety first)
128  }
129 
130  std::unique_ptr<SiStripApvGain> getNewObject() override;
131 
133  DQMStore* dbe;
135  double MinNrEntries;
136  double MaxMPVError;
140  double MinTrackEta;
141  double MaxTrackEta;
142  unsigned int MaxNrStrips;
143  unsigned int MinTrackHits;
151 
160  std::vector<std::string> VChargeHisto;
164 
167  vector<string> VInputFiles;
168 
169  //enum statistic_type {None=-1, StdBunch, StdBunch0T, FaABunch, FaABunch0T, IsoBunch, IsoBunch0T, Harvest};
170 
171  std::vector<string> dqm_tag_;
173 
174  std::vector<MonitorElement*> Charge_Vs_Index;
175  std::array<std::vector<APVGain::APVmon>, 7> Charge_1;
176  std::array<std::vector<APVGain::APVmon>, 7> Charge_2;
177  std::array<std::vector<APVGain::APVmon>, 7> Charge_3;
178  std::array<std::vector<APVGain::APVmon>, 7> Charge_4;
180  std::vector<MonitorElement*> Charge_Vs_PathlengthTIB;
181  std::vector<MonitorElement*> Charge_Vs_PathlengthTOB;
182  std::vector<MonitorElement*> Charge_Vs_PathlengthTIDP;
183  std::vector<MonitorElement*> Charge_Vs_PathlengthTIDM;
184  std::vector<MonitorElement*> Charge_Vs_PathlengthTECP1;
185  std::vector<MonitorElement*> Charge_Vs_PathlengthTECP2;
186  std::vector<MonitorElement*> Charge_Vs_PathlengthTECM1;
187  std::vector<MonitorElement*> Charge_Vs_PathlengthTECM2;
189  //std::vector<MonitorElement*> Charge_Vs_Index_Absolute;
190 
191  //Validation histograms
192  MonitorElement* MPV_Vs_EtaTIB;
193  MonitorElement* MPV_Vs_EtaTID;
194  MonitorElement* MPV_Vs_EtaTOB;
195  MonitorElement* MPV_Vs_EtaTEC;
196  MonitorElement* MPV_Vs_EtaTECthin;
197  MonitorElement* MPV_Vs_EtaTECthick;
199  MonitorElement* MPV_Vs_PhiTIB;
200  MonitorElement* MPV_Vs_PhiTID;
201  MonitorElement* MPV_Vs_PhiTOB;
202  MonitorElement* MPV_Vs_PhiTEC;
203  MonitorElement* MPV_Vs_PhiTECthin;
204  MonitorElement* MPV_Vs_PhiTECthick;
206  MonitorElement* NoMPVmasked;
207  MonitorElement* NoMPVfit;
209  MonitorElement* Gains;
210  MonitorElement* MPVs;
211  MonitorElement* MPVs320;
212  MonitorElement* MPVs500;
213  MonitorElement* MPVsTIB;
214  MonitorElement* MPVsTID;
215  MonitorElement* MPVsTIDP;
216  MonitorElement* MPVsTIDM;
217  MonitorElement* MPVsTOB;
218  MonitorElement* MPVsTEC;
219  MonitorElement* MPVsTECP;
220  MonitorElement* MPVsTECM;
221  MonitorElement* MPVsTECthin;
222  MonitorElement* MPVsTECthick;
223  MonitorElement* MPVsTECP1;
224  MonitorElement* MPVsTECP2;
225  MonitorElement* MPVsTECM1;
226  MonitorElement* MPVsTECM2;
228  MonitorElement* MPVError;
229  MonitorElement* MPVErrorVsMPV;
230  MonitorElement* MPVErrorVsEta;
231  MonitorElement* MPVErrorVsPhi;
232  MonitorElement* MPVErrorVsN;
234  MonitorElement* DiffWRTPrevGainTIB;
235  MonitorElement* DiffWRTPrevGainTID;
236  MonitorElement* DiffWRTPrevGainTOB;
237  MonitorElement* DiffWRTPrevGainTEC;
239  MonitorElement* GainVsPrevGainTIB;
240  MonitorElement* GainVsPrevGainTID;
241  MonitorElement* GainVsPrevGainTOB;
242  MonitorElement* GainVsPrevGainTEC;
244  std::vector<APVGain::APVmon> newCharge;
245 
246  unsigned int NEvent;
247  unsigned int NTrack;
248  unsigned int NClusterStrip;
249  unsigned int NClusterPixel;
252  unsigned int SRun;
253  unsigned int ERun;
254  unsigned int GOOD;
255  unsigned int BAD;
256  unsigned int MASKED;
257 
258  //Data members for processing
259 
260  //Event data
261  unsigned int eventnumber = 0;
262  unsigned int runnumber = 0;
263  const std::vector<bool>* TrigTech = nullptr;
265 
266  // Track data
267  const std::vector<double>* trackchi2ndof = nullptr;
269  const std::vector<float>* trackp = nullptr;
271  const std::vector<float>* trackpt = nullptr;
273  const std::vector<double>* tracketa = nullptr;
275  const std::vector<double>* trackphi = nullptr;
277  const std::vector<unsigned int>* trackhitsvalid = nullptr;
279  const std::vector<int>* trackalgo = nullptr;
281 
282  // CalibTree data
283  const std::vector<int>* trackindex = nullptr;
285  const std::vector<unsigned int>* rawid = nullptr;
287  const std::vector<double>* localdirx = nullptr;
289  const std::vector<double>* localdiry = nullptr;
291  const std::vector<double>* localdirz = nullptr;
293  const std::vector<unsigned short>* firststrip = nullptr;
295  const std::vector<unsigned short>* nstrips = nullptr;
297  const std::vector<bool>* saturation = nullptr;
299  const std::vector<bool>* overlapping = nullptr;
301  const std::vector<bool>* farfromedge = nullptr;
303  const std::vector<unsigned int>* charge = nullptr;
305  const std::vector<double>* path = nullptr;
307  const std::vector<double>* chargeoverpath = nullptr;
309  const std::vector<unsigned char>* amplitude = nullptr;
311  const std::vector<double>* gainused = nullptr;
313  const std::vector<double>* gainusedTick = nullptr;
315 
316  string EventPrefix_; //("");
317  string EventSuffix_; //("");
318  string TrackPrefix_; //("track");
319  string TrackSuffix_; //("");
320  string CalibPrefix_; //("GainCalibration");
321  string CalibSuffix_; //("");
322 
323 private:
324  std::vector<stAPVGain*> APVsCollOrdered;
325  std::unordered_map<unsigned int, stAPVGain*> APVsColl;
327 };
328 
330  std::vector<string>::const_iterator it = dqm_tag_.begin();
331  while (it != dqm_tag_.end()) {
332  if (*it == std::string(tag))
333  return it - dqm_tag_.begin();
334  it++;
335  }
336 
337  if (std::string(tag).empty())
338  return 0; // return StdBunch calibration mode for backward compatibility
339 
340  return None;
341 }
342 
344  if (A->GetNbinsX() == B->GetNbinsX()) {
345  A->Add(B);
346  } else {
347  for (int x = 0; x <= B->GetNbinsX() + 1; x++) {
348  for (int y = 0; y <= B->GetNbinsY() + 1; y++) {
349  A->SetBinContent(x, y, A->GetBinContent(x, y) + B->GetBinContent(x, y));
350  }
351  }
352  }
353 }
354 
356  : ConditionDBWriter<SiStripApvGain>(iConfig) {
357  OutputGains = iConfig.getParameter<std::string>("OutputGains");
358 
359  AlgoMode = iConfig.getUntrackedParameter<std::string>("AlgoMode", "CalibTree");
360  MagFieldCurrentTh = iConfig.getUntrackedParameter<double>("MagFieldCurrentTh", 2000.);
361  MinNrEntries = iConfig.getUntrackedParameter<double>("minNrEntries", 20);
362  MaxMPVError = iConfig.getUntrackedParameter<double>("maxMPVError", 500.0);
363  MaxChi2OverNDF = iConfig.getUntrackedParameter<double>("maxChi2OverNDF", 5.0);
364  MinTrackMomentum = iConfig.getUntrackedParameter<double>("minTrackMomentum", 3.0);
365  MaxTrackMomentum = iConfig.getUntrackedParameter<double>("maxTrackMomentum", 99999.0);
366  MinTrackEta = iConfig.getUntrackedParameter<double>("minTrackEta", -5.0);
367  MaxTrackEta = iConfig.getUntrackedParameter<double>("maxTrackEta", 5.0);
368  MaxNrStrips = iConfig.getUntrackedParameter<unsigned>("maxNrStrips", 2);
369  MinTrackHits = iConfig.getUntrackedParameter<unsigned>("MinTrackHits", 8);
370  MaxTrackChiOverNdf = iConfig.getUntrackedParameter<double>("MaxTrackChiOverNdf", 3);
371  MaxTrackingIteration = iConfig.getUntrackedParameter<int>("MaxTrackingIteration", 7);
372  AllowSaturation = iConfig.getUntrackedParameter<bool>("AllowSaturation", false);
373  FirstSetOfConstants = iConfig.getUntrackedParameter<bool>("FirstSetOfConstants", true);
374  Validation = iConfig.getUntrackedParameter<bool>("Validation", false);
375  OldGainRemoving = iConfig.getUntrackedParameter<bool>("OldGainRemoving", false);
376 
377  CalibrationLevel = iConfig.getUntrackedParameter<int>("CalibrationLevel", 0);
378  VInputFiles = iConfig.getUntrackedParameter<vector<string>>("InputFiles");
379  VChargeHisto = iConfig.getUntrackedParameter<vector<string>>("ChargeHisto");
380 
381  useCalibration = iConfig.getUntrackedParameter<bool>("UseCalibration", false);
382  m_harvestingMode = iConfig.getUntrackedParameter<bool>("harvestingMode", false);
383  m_splitDQMstat = iConfig.getUntrackedParameter<bool>("splitDQMstat", false);
384  m_calibrationMode = iConfig.getUntrackedParameter<string>("calibrationMode", "StdBunch");
385  m_calibrationPath = iConfig.getUntrackedParameter<string>("calibrationPath");
386  m_DQMdir = iConfig.getUntrackedParameter<string>("DQMdir", "AlCaReco/SiStripGains");
387 
388  tagCondition_NClusters = iConfig.getUntrackedParameter<double>("NClustersForTagProd", 2E8);
389  tagCondition_GoodFrac = iConfig.getUntrackedParameter<double>("GoodFracForTagProd", 0.95);
390 
391  saveSummary = iConfig.getUntrackedParameter<bool>("saveSummary", false);
392 
393  doChargeMonitorPerPlane = iConfig.getUntrackedParameter<bool>("doChargeMonitorPerPlane", false);
394 
395  // Gather DQM Service
397  dbe->setVerbose(10);
398 
399  //Set the monitoring element tag and store
400  dqm_tag_.reserve(7);
401  dqm_tag_.clear();
402  dqm_tag_.push_back("StdBunch"); // statistic collection from Standard Collision Bunch @ 3.8 T
403  dqm_tag_.push_back("StdBunch0T"); // statistic collection from Standard Collision Bunch @ 0 T
404  dqm_tag_.push_back("AagBunch"); // statistic collection from First Collision After Abort Gap @ 3.8 T
405  dqm_tag_.push_back("AagBunch0T"); // statistic collection from First Collision After Abort Gap @ 0 T
406  dqm_tag_.push_back("IsoMuon"); // statistic collection from Isolated Muon @ 3.8 T
407  dqm_tag_.push_back("IsoMuon0T"); // statistic collection from Isolated Muon @ 0 T
408  dqm_tag_.push_back("Harvest"); // statistic collection: Harvest
409 
410  Charge_Vs_Index.insert(Charge_Vs_Index.begin(), dqm_tag_.size(), nullptr);
411  //Charge_Vs_Index_Absolute.insert( Charge_Vs_Index_Absolute.begin(), dqm_tag_.size(), 0);
412  Charge_Vs_PathlengthTIB.insert(Charge_Vs_PathlengthTIB.begin(), dqm_tag_.size(), nullptr);
413  Charge_Vs_PathlengthTOB.insert(Charge_Vs_PathlengthTOB.begin(), dqm_tag_.size(), nullptr);
414  Charge_Vs_PathlengthTIDP.insert(Charge_Vs_PathlengthTIDP.begin(), dqm_tag_.size(), nullptr);
415  Charge_Vs_PathlengthTIDM.insert(Charge_Vs_PathlengthTIDM.begin(), dqm_tag_.size(), nullptr);
416  Charge_Vs_PathlengthTECP1.insert(Charge_Vs_PathlengthTECP1.begin(), dqm_tag_.size(), nullptr);
417  Charge_Vs_PathlengthTECP2.insert(Charge_Vs_PathlengthTECP2.begin(), dqm_tag_.size(), nullptr);
418  Charge_Vs_PathlengthTECM1.insert(Charge_Vs_PathlengthTECM1.begin(), dqm_tag_.size(), nullptr);
419  Charge_Vs_PathlengthTECM2.insert(Charge_Vs_PathlengthTECM2.begin(), dqm_tag_.size(), nullptr);
420 
421  // configure token for gathering the ntuple variables
422  edm::ParameterSet swhallowgain_pset = iConfig.getUntrackedParameter<edm::ParameterSet>("gain");
423 
424  string label = swhallowgain_pset.getUntrackedParameter<string>("label");
425  CalibPrefix_ = swhallowgain_pset.getUntrackedParameter<string>("prefix");
426  CalibSuffix_ = swhallowgain_pset.getUntrackedParameter<string>("suffix");
427 
428  trackindex_token_ = consumes<std::vector<int>>(edm::InputTag(label, CalibPrefix_ + "trackindex" + CalibSuffix_));
429  rawid_token_ = consumes<std::vector<unsigned int>>(edm::InputTag(label, CalibPrefix_ + "rawid" + CalibSuffix_));
430  localdirx_token_ = consumes<std::vector<double>>(edm::InputTag(label, CalibPrefix_ + "localdirx" + CalibSuffix_));
431  localdiry_token_ = consumes<std::vector<double>>(edm::InputTag(label, CalibPrefix_ + "localdiry" + CalibSuffix_));
432  localdirz_token_ = consumes<std::vector<double>>(edm::InputTag(label, CalibPrefix_ + "localdirz" + CalibSuffix_));
434  consumes<std::vector<unsigned short>>(edm::InputTag(label, CalibPrefix_ + "firststrip" + CalibSuffix_));
435  nstrips_token_ = consumes<std::vector<unsigned short>>(edm::InputTag(label, CalibPrefix_ + "nstrips" + CalibSuffix_));
436  saturation_token_ = consumes<std::vector<bool>>(edm::InputTag(label, CalibPrefix_ + "saturation" + CalibSuffix_));
437  overlapping_token_ = consumes<std::vector<bool>>(edm::InputTag(label, CalibPrefix_ + "overlapping" + CalibSuffix_));
438  farfromedge_token_ = consumes<std::vector<bool>>(edm::InputTag(label, CalibPrefix_ + "farfromedge" + CalibSuffix_));
439  charge_token_ = consumes<std::vector<unsigned int>>(edm::InputTag(label, CalibPrefix_ + "charge" + CalibSuffix_));
440  path_token_ = consumes<std::vector<double>>(edm::InputTag(label, CalibPrefix_ + "path" + CalibSuffix_));
442  consumes<std::vector<double>>(edm::InputTag(label, CalibPrefix_ + "chargeoverpath" + CalibSuffix_));
444  consumes<std::vector<unsigned char>>(edm::InputTag(label, CalibPrefix_ + "amplitude" + CalibSuffix_));
445  gainused_token_ = consumes<std::vector<double>>(edm::InputTag(label, CalibPrefix_ + "gainused" + CalibSuffix_));
447  consumes<std::vector<double>>(edm::InputTag(label, CalibPrefix_ + "gainusedTick" + CalibSuffix_));
448 
449  edm::ParameterSet evtinfo_pset = iConfig.getUntrackedParameter<edm::ParameterSet>("evtinfo");
450  label = evtinfo_pset.getUntrackedParameter<string>("label");
451  EventPrefix_ = evtinfo_pset.getUntrackedParameter<string>("prefix");
452  EventSuffix_ = evtinfo_pset.getUntrackedParameter<string>("suffix");
453  TrigTech_token_ = consumes<std::vector<bool>>(edm::InputTag(label, EventPrefix_ + "TrigTech" + EventSuffix_));
454 
455  edm::ParameterSet track_pset = iConfig.getUntrackedParameter<edm::ParameterSet>("tracks");
456  label = track_pset.getUntrackedParameter<string>("label");
457  TrackPrefix_ = track_pset.getUntrackedParameter<string>("prefix");
458  TrackSuffix_ = track_pset.getUntrackedParameter<string>("suffix");
459 
460  trackchi2ndof_token_ = consumes<std::vector<double>>(edm::InputTag(label, TrackPrefix_ + "chi2ndof" + TrackSuffix_));
461  trackp_token_ = consumes<std::vector<float>>(edm::InputTag(label, TrackPrefix_ + "momentum" + TrackSuffix_));
462  trackpt_token_ = consumes<std::vector<float>>(edm::InputTag(label, TrackPrefix_ + "pt" + TrackSuffix_));
463  tracketa_token_ = consumes<std::vector<double>>(edm::InputTag(label, TrackPrefix_ + "eta" + TrackSuffix_));
464  trackphi_token_ = consumes<std::vector<double>>(edm::InputTag(label, TrackPrefix_ + "phi" + TrackSuffix_));
466  consumes<std::vector<unsigned int>>(edm::InputTag(label, TrackPrefix_ + "hitsvalid" + TrackSuffix_));
467  trackalgo_token_ = consumes<std::vector<int>>(edm::InputTag(label, TrackPrefix_ + "algo" + TrackSuffix_));
468 
469  tTopo_ = nullptr;
470 }
471 
472 void SiStripGainFromCalibTree::bookDQMHistos(const char* dqm_dir, const char* tag) {
473  edm::LogInfo("SiStripGainFromCalibTree")
474  << "Setting " << dqm_dir << "in DQM and booking histograms for tag " << tag << std::endl;
475 
476  if (strcmp(booked_dir_.c_str(), dqm_dir) != 0) {
477  booked_dir_ = dqm_dir;
478  dbe->setCurrentFolder(dqm_dir);
479  }
480 
481  std::string stag(tag);
482  if (!stag.empty() && stag[0] != '_')
483  stag.insert(0, 1, '_');
484 
485  std::string cvi = std::string("Charge_Vs_Index") + stag;
486  //std::string cviA = std::string("Charge_Vs_Index_Absolute") + stag;
487  std::string cvpTIB = std::string("Charge_Vs_PathlengthTIB") + stag;
488  std::string cvpTOB = std::string("Charge_Vs_PathlengthTOB") + stag;
489  std::string cvpTIDP = std::string("Charge_Vs_PathlengthTIDP") + stag;
490  std::string cvpTIDM = std::string("Charge_Vs_PathlengthTIDM") + stag;
491  std::string cvpTECP1 = std::string("Charge_Vs_PathlengthTECP1") + stag;
492  std::string cvpTECP2 = std::string("Charge_Vs_PathlengthTECP2") + stag;
493  std::string cvpTECM1 = std::string("Charge_Vs_PathlengthTECM1") + stag;
494  std::string cvpTECM2 = std::string("Charge_Vs_PathlengthTECM2") + stag;
495 
496  int elepos = (m_harvestingMode && AlgoMode == "PCL") ? Harvest : statCollectionFromMode(tag);
497 
498  // The cluster charge is stored by exploiting a non uniform binning in order
499  // reduce the histogram memory size. The bin width is relaxed with a falling
500  // exponential function and the bin boundaries are stored in the binYarray.
501  // The binXarray is used to provide as many bins as the APVs.
502  //
503  // More details about this implementations are here:
504  // https://indico.cern.ch/event/649344/contributions/2672267/attachments/1498323/2332518/OptimizeChHisto.pdf
505 
506  std::vector<float> binXarray;
507  binXarray.reserve(NStripAPVs + 1);
508  for (int a = 0; a <= NStripAPVs; a++) {
509  binXarray.push_back((float)a);
510  }
511 
512  std::array<float, 688> binYarray;
513  double p0 = 5.445;
514  double p1 = 0.002113;
515  double p2 = 69.01576;
516  double y = 0.;
517  for (int b = 0; b < 687; b++) {
518  binYarray[b] = y;
519  if (y <= 902.)
520  y = y + 2.;
521  else
522  y = (p0 - log(exp(p0 - p1 * y) - p2 * p1)) / p1;
523  }
524  binYarray[687] = 4000.;
525 
526  Charge_Vs_Index[elepos] = dbe->book2S(cvi.c_str(), cvi.c_str(), NStripAPVs, &binXarray[0], 687, binYarray.data());
527  //Charge_Vs_Index_Absolute[elepos] = dbe->book2S(cviA.c_str() , cviA.c_str() , 88625, 0 , 88624,1000,0,4000);
528  Charge_Vs_PathlengthTIB[elepos] = dbe->book2S(cvpTIB.c_str(), cvpTIB.c_str(), 20, 0.3, 1.3, 250, 0, 2000);
529  Charge_Vs_PathlengthTOB[elepos] = dbe->book2S(cvpTOB.c_str(), cvpTOB.c_str(), 20, 0.3, 1.3, 250, 0, 2000);
530  Charge_Vs_PathlengthTIDP[elepos] = dbe->book2S(cvpTIDP.c_str(), cvpTIDP.c_str(), 20, 0.3, 1.3, 250, 0, 2000);
531  Charge_Vs_PathlengthTIDM[elepos] = dbe->book2S(cvpTIDM.c_str(), cvpTIDM.c_str(), 20, 0.3, 1.3, 250, 0, 2000);
532  Charge_Vs_PathlengthTECP1[elepos] = dbe->book2S(cvpTECP1.c_str(), cvpTECP1.c_str(), 20, 0.3, 1.3, 250, 0, 2000);
533  Charge_Vs_PathlengthTECP2[elepos] = dbe->book2S(cvpTECP2.c_str(), cvpTECP2.c_str(), 20, 0.3, 1.3, 250, 0, 2000);
534  Charge_Vs_PathlengthTECM1[elepos] = dbe->book2S(cvpTECM1.c_str(), cvpTECM1.c_str(), 20, 0.3, 1.3, 250, 0, 2000);
535  Charge_Vs_PathlengthTECM2[elepos] = dbe->book2S(cvpTECM2.c_str(), cvpTECM2.c_str(), 20, 0.3, 1.3, 250, 0, 2000);
536 
537  //Book Charge monitoring histograms
538  std::vector<std::pair<std::string, std::string>> hnames =
540  for (unsigned int i = 0; i < hnames.size(); i++) {
541  std::string htag = (hnames[i]).first + stag;
542  MonitorElement* monitor = dbe->book1DD(htag.c_str(), (hnames[i]).second.c_str(), 100, 0., 1000.);
543  int id = APVGain::subdetectorId((hnames[i]).first);
544  int side = APVGain::subdetectorSide((hnames[i]).first);
545  int plane = APVGain::subdetectorPlane((hnames[i]).first);
546  Charge_1[elepos].push_back(APVGain::APVmon(id, side, plane, monitor));
547  }
548 
550  for (unsigned int i = 0; i < hnames.size(); i++) {
551  std::string htag = (hnames[i]).first + stag;
552  MonitorElement* monitor = dbe->book1DD(htag.c_str(), (hnames[i]).second.c_str(), 100, 0., 1000.);
553  int id = APVGain::subdetectorId((hnames[i]).first);
554  int side = APVGain::subdetectorSide((hnames[i]).first);
555  int plane = APVGain::subdetectorPlane((hnames[i]).first);
556  Charge_2[elepos].push_back(APVGain::APVmon(id, side, plane, monitor));
557  }
558 
560  for (unsigned int i = 0; i < hnames.size(); i++) {
561  std::string htag = (hnames[i]).first + stag;
562  MonitorElement* monitor = dbe->book1DD(htag.c_str(), (hnames[i]).second.c_str(), 100, 0., 1000.);
563  int id = APVGain::subdetectorId((hnames[i]).first);
564  int side = APVGain::subdetectorSide((hnames[i]).first);
565  int plane = APVGain::subdetectorPlane((hnames[i]).first);
566  Charge_3[elepos].push_back(APVGain::APVmon(id, side, plane, monitor));
567  }
568 
570  for (unsigned int i = 0; i < hnames.size(); i++) {
571  std::string htag = (hnames[i]).first + stag;
572  MonitorElement* monitor = dbe->book1DD(htag.c_str(), (hnames[i]).second.c_str(), 100, 0., 1000.);
573  int id = APVGain::subdetectorId((hnames[i]).first);
574  int side = APVGain::subdetectorSide((hnames[i]).first);
575  int plane = APVGain::subdetectorPlane((hnames[i]).first);
576  Charge_4[elepos].push_back(APVGain::APVmon(id, side, plane, monitor));
577  }
578 
579  //Book validation histograms
580  if (m_harvestingMode) {
581  int MPVbin = 300;
582  float MPVmin = 0.;
583  float MPVmax = 600.;
584 
585  MPV_Vs_EtaTIB = dbe->book2DD("MPV_vs_EtaTIB", "MPV vs Eta TIB", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
586  MPV_Vs_EtaTID = dbe->book2DD("MPV_vs_EtaTID", "MPV vs Eta TID", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
587  MPV_Vs_EtaTOB = dbe->book2DD("MPV_vs_EtaTOB", "MPV vs Eta TOB", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
588  MPV_Vs_EtaTEC = dbe->book2DD("MPV_vs_EtaTEC", "MPV vs Eta TEC", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
589  MPV_Vs_EtaTECthin = dbe->book2DD("MPV_vs_EtaTEC1", "MPV vs Eta TEC-thin", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
590  MPV_Vs_EtaTECthick = dbe->book2DD("MPV_vs_EtaTEC2", "MPV vs Eta TEC-thick", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
591 
592  MPV_Vs_PhiTIB = dbe->book2DD("MPV_vs_PhiTIB", "MPV vs Phi TIB", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
593  MPV_Vs_PhiTID = dbe->book2DD("MPV_vs_PhiTID", "MPV vs Phi TID", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
594  MPV_Vs_PhiTOB = dbe->book2DD("MPV_vs_PhiTOB", "MPV vs Phi TOB", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
595  MPV_Vs_PhiTEC = dbe->book2DD("MPV_vs_PhiTEC", "MPV vs Phi TEC", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
596  MPV_Vs_PhiTECthin = dbe->book2DD("MPV_vs_PhiTEC1", "MPV vs Phi TEC-thin", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
597  MPV_Vs_PhiTECthick = dbe->book2DD("MPV_vs_PhiTEC2", "MPV vs Phi TEC-thick", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
598 
599  NoMPVfit = dbe->book2DD("NoMPVfit", "Modules with bad Landau Fit", 350, -350, 350, 240, 0, 120);
600  NoMPVmasked = dbe->book2DD("NoMPVmasked", "Masked Modules", 350, -350, 350, 240, 0, 120);
601 
602  Gains = dbe->book1DD("Gains", "Gains", 300, 0, 2);
603  MPVs = dbe->book1DD("MPVs", "MPVs", MPVbin, MPVmin, MPVmax);
604  MPVs320 = dbe->book1DD("MPV_320", "MPV 320 thickness", MPVbin, MPVmin, MPVmax);
605  MPVs500 = dbe->book1DD("MPV_500", "MPV 500 thickness", MPVbin, MPVmin, MPVmax);
606  MPVsTIB = dbe->book1DD("MPV_TIB", "MPV TIB", MPVbin, MPVmin, MPVmax);
607  MPVsTID = dbe->book1DD("MPV_TID", "MPV TID", MPVbin, MPVmin, MPVmax);
608  MPVsTIDP = dbe->book1DD("MPV_TIDP", "MPV TIDP", MPVbin, MPVmin, MPVmax);
609  MPVsTIDM = dbe->book1DD("MPV_TIDM", "MPV TIDM", MPVbin, MPVmin, MPVmax);
610  MPVsTOB = dbe->book1DD("MPV_TOB", "MPV TOB", MPVbin, MPVmin, MPVmax);
611  MPVsTEC = dbe->book1DD("MPV_TEC", "MPV TEC", MPVbin, MPVmin, MPVmax);
612  MPVsTECP = dbe->book1DD("MPV_TECP", "MPV TECP", MPVbin, MPVmin, MPVmax);
613  MPVsTECM = dbe->book1DD("MPV_TECM", "MPV TECM", MPVbin, MPVmin, MPVmax);
614  MPVsTECthin = dbe->book1DD("MPV_TEC1", "MPV TEC1", MPVbin, MPVmin, MPVmax);
615  MPVsTECthick = dbe->book1DD("MPV_TEC2", "MPV TEC2", MPVbin, MPVmin, MPVmax);
616  MPVsTECP1 = dbe->book1DD("MPV_TECP1", "MPV TECP1", MPVbin, MPVmin, MPVmax);
617  MPVsTECP2 = dbe->book1DD("MPV_TECP2", "MPV TECP2", MPVbin, MPVmin, MPVmax);
618  MPVsTECM1 = dbe->book1DD("MPV_TECM1", "MPV TECM1", MPVbin, MPVmin, MPVmax);
619  MPVsTECM2 = dbe->book1DD("MPV_TECM2", "MPV TECM2", MPVbin, MPVmin, MPVmax);
620 
621  MPVError = dbe->book1DD("MPVError", "MPV Error", 150, 0, 150);
622  MPVErrorVsMPV = dbe->book2DD("MPVErrorVsMPV", "MPV Error vs MPV", 300, 0, 600, 150, 0, 150);
623  MPVErrorVsEta = dbe->book2DD("MPVErrorVsEta", "MPV Error vs Eta", 50, -3.0, 3.0, 150, 0, 150);
624  MPVErrorVsPhi = dbe->book2DD("MPVErrorVsPhi", "MPV Error vs Phi", 50, -3.4, 3.4, 150, 0, 150);
625  MPVErrorVsN = dbe->book2DD("MPVErrorVsN", "MPV Error vs N", 500, 0, 1000, 150, 0, 150);
626 
627  DiffWRTPrevGainTIB = dbe->book1DD("DiffWRTPrevGainTIB", "Diff w.r.t. PrevGain TIB", 250, 0, 2);
628  DiffWRTPrevGainTID = dbe->book1DD("DiffWRTPrevGainTID", "Diff w.r.t. PrevGain TID", 250, 0, 2);
629  DiffWRTPrevGainTOB = dbe->book1DD("DiffWRTPrevGainTOB", "Diff w.r.t. PrevGain TOB", 250, 0, 2);
630  DiffWRTPrevGainTEC = dbe->book1DD("DiffWRTPrevGainTEC", "Diff w.r.t. PrevGain TEC", 250, 0, 2);
631 
632  GainVsPrevGainTIB = dbe->book2DD("GainVsPrevGainTIB", "Gain vs PrevGain TIB", 100, 0, 2, 100, 0, 2);
633  GainVsPrevGainTID = dbe->book2DD("GainVsPrevGainTID", "Gain vs PrevGain TID", 100, 0, 2, 100, 0, 2);
634  GainVsPrevGainTOB = dbe->book2DD("GainVsPrevGainTOB", "Gain vs PrevGain TOB", 100, 0, 2, 100, 0, 2);
635  GainVsPrevGainTEC = dbe->book2DD("GainVsPrevGainTEC", "Gain vs PrevGain TEC", 100, 0, 2, 100, 0, 2);
636 
637  std::vector<std::pair<std::string, std::string>> hnames =
639  for (unsigned int i = 0; i < hnames.size(); i++) {
640  MonitorElement* monitor = dbe->book1DD((hnames[i]).first.c_str(), (hnames[i]).second.c_str(), 100, 0., 1000.);
641  int id = APVGain::subdetectorId((hnames[i]).first);
642  int side = APVGain::subdetectorSide((hnames[i]).first);
643  int plane = APVGain::subdetectorPlane((hnames[i]).first);
644  newCharge.push_back(APVGain::APVmon(id, side, plane, monitor));
645  }
646  }
647 }
648 
650  edm::LogInfo("SiStripGainFromCalibTree") << "AlgoMode : " << AlgoMode << "\n"
651  << "CalibrationMode : " << m_calibrationMode << "\n"
652  << "HarvestingMode : " << m_harvestingMode << std::endl;
653  //Setup DQM histograms
654  if (AlgoMode != "PCL" or m_harvestingMode) {
655  const char* dqm_dir = "AlCaReco/SiStripGainsHarvesting/";
656  this->bookDQMHistos(dqm_dir, dqm_tag_[statCollectionFromMode(m_calibrationMode.c_str())].c_str());
657  } else {
658  //Check consistency of calibration Mode and BField only for the ALCAPROMPT in the PCL workflow
659  if (!isBFieldConsistentWithMode(iSetup)) {
660  string prevMode = m_calibrationMode;
661  swapBFieldMode();
662  edm::LogInfo("SiStripGainFromCalibTree") << "Switching calibration mode for endorsing BField status: " << prevMode
663  << " ==> " << m_calibrationMode << std::endl;
664  }
665  std::string dqm_dir = m_DQMdir + ((m_splitDQMstat) ? m_calibrationMode : "") + "/";
667  this->bookDQMHistos(dqm_dir.c_str(), dqm_tag_[elem].c_str());
668  }
669 
671  iSetup.get<TrackerTopologyRcd>().get(TopoHandle);
672  tTopo_ = TopoHandle.product();
673 
675  iSetup.get<TrackerDigiGeometryRecord>().get(tkGeom);
676  auto const& Det = tkGeom->dets();
677 
678  NPixelDets = 0;
679  NStripAPVs = 0;
680  unsigned int Index = 0;
681  for (unsigned int i = 0; i < Det.size(); i++) {
682  DetId Detid = Det[i]->geographicalId();
683  int SubDet = Detid.subdetId();
684 
685  if (SubDet == StripSubdetector::TIB || SubDet == StripSubdetector::TID || SubDet == StripSubdetector::TOB ||
686  SubDet == StripSubdetector::TEC) {
687  auto DetUnit = dynamic_cast<const StripGeomDetUnit*>(Det[i]);
688  if (!DetUnit)
689  continue;
690 
691  const StripTopology& Topo = DetUnit->specificTopology();
692  unsigned int NAPV = Topo.nstrips() / 128;
693 
694  for (unsigned int j = 0; j < NAPV; j++) {
695  stAPVGain* APV = new stAPVGain;
696  APV->Index = Index;
697  APV->Bin = -1;
698  APV->DetId = Detid.rawId();
699  APV->APVId = j;
700  APV->SubDet = SubDet;
701  APV->FitMPV = -1;
702  APV->FitMPVErr = -1;
703  APV->FitWidth = -1;
704  APV->FitWidthErr = -1;
705  APV->FitChi2 = -1;
706  APV->FitNorm = -1;
707  APV->Gain = -1;
708  APV->PreviousGain = 1;
709  APV->PreviousGainTick = 1;
710  APV->x = DetUnit->position().basicVector().x();
711  APV->y = DetUnit->position().basicVector().y();
712  APV->z = DetUnit->position().basicVector().z();
713  APV->Eta = DetUnit->position().basicVector().eta();
714  APV->Phi = DetUnit->position().basicVector().phi();
715  APV->R = DetUnit->position().basicVector().transverse();
716  APV->Thickness = DetUnit->surface().bounds().thickness();
717  APV->NEntries = 0;
718  APV->isMasked = false;
719 
720  APVsCollOrdered.push_back(APV);
721  APVsColl[(APV->DetId << 4) | APV->APVId] = APV;
722  Index++;
723  NStripAPVs++;
724  }
725  }
726  }
727 
728  for (unsigned int i = 0; i < Det.size();
729  i++) { //Make two loop such that the Pixel information is added at the end --> make transition simpler
730  DetId Detid = Det[i]->geographicalId();
731  int SubDet = Detid.subdetId();
733  auto DetUnit = dynamic_cast<const PixelGeomDetUnit*>(Det[i]);
734  if (!DetUnit)
735  continue;
736 
737  const PixelTopology& Topo = DetUnit->specificTopology();
738  unsigned int NROCRow = Topo.nrows() / (80.);
739  unsigned int NROCCol = Topo.ncolumns() / (52.);
740 
741  for (unsigned int j = 0; j < NROCRow; j++) {
742  for (unsigned int i = 0; i < NROCCol; i++) {
743  stAPVGain* APV = new stAPVGain;
744  APV->Index = Index;
745  APV->Bin = -1;
746  APV->DetId = Detid.rawId();
747  APV->APVId = (j << 3 | i);
748  APV->SubDet = SubDet;
749  APV->FitMPV = -1;
750  APV->FitMPVErr = -1;
751  APV->FitWidth = -1;
752  APV->FitWidthErr = -1;
753  APV->FitChi2 = -1;
754  APV->Gain = -1;
755  APV->PreviousGain = 1;
756  APV->PreviousGainTick = 1;
757  APV->x = DetUnit->position().basicVector().x();
758  APV->y = DetUnit->position().basicVector().y();
759  APV->z = DetUnit->position().basicVector().z();
760  APV->Eta = DetUnit->position().basicVector().eta();
761  APV->Phi = DetUnit->position().basicVector().phi();
762  APV->R = DetUnit->position().basicVector().transverse();
763  APV->Thickness = DetUnit->surface().bounds().thickness();
764  APV->isMasked = false; //SiPixelQuality_->IsModuleBad(Detid.rawId());
765  APV->NEntries = 0;
766 
767  APVsCollOrdered.push_back(APV);
768  APVsColl[(APV->DetId << 4) | APV->APVId] = APV;
769  Index++;
770  NPixelDets++;
771  }
772  }
773  }
774  }
775 
777 
778  NEvent = 0;
779  NTrack = 0;
780  NClusterStrip = 0;
781  NClusterPixel = 0;
782  SRun = 1 << 31;
783  ERun = 0;
784  GOOD = 0;
785  BAD = 0;
786  MASKED = 0;
787 }
788 
790  edm::ESHandle<RunInfo> runInfo;
791  iSetup.get<RunInfoRcd>().get(runInfo);
792 
793  double average_current = runInfo.product()->m_avg_current;
794  bool isOn = (average_current > MagFieldCurrentTh);
795  bool is0T = (m_calibrationMode.substr(m_calibrationMode.length() - 2) == "0T");
796 
797  return ((isOn && !is0T) || (!isOn && is0T));
798 }
799 
801  if (m_calibrationMode.substr(m_calibrationMode.length() - 2) == "0T") {
802  m_calibrationMode.erase(m_calibrationMode.length() - 2, 2);
803  } else {
804  m_calibrationMode.append("0T");
805  }
806 }
807 
809  if (!m_harvestingMode && AlgoMode == "PCL") {
810  //Check consistency of calibration Mode and BField only for the ALCAPROMPT in the PCL workflow
811  if (!isBFieldConsistentWithMode(iSetup)) {
812  string prevMode = m_calibrationMode;
813  swapBFieldMode();
814  edm::LogInfo("SiStripGainFromCalibTree") << "Switching calibration mode for endorsing BField status: " << prevMode
815  << " ==> " << m_calibrationMode << std::endl;
816  }
817  }
818 
819  edm::ESHandle<SiStripGain> gainHandle;
820  iSetup.get<SiStripGainRcd>().get(gainHandle);
821  if (!gainHandle.isValid()) {
822  edm::LogError("SiStripGainFromCalibTree") << "gainHandle is not valid\n";
823  exit(0);
824  }
825 
826  edm::ESHandle<SiStripQuality> SiStripQuality_;
827  iSetup.get<SiStripQualityRcd>().get(SiStripQuality_);
828 
829  for (unsigned int a = 0; a < APVsCollOrdered.size(); a++) {
831 
832  // MM. 03/03/2017 all of this makes sense only for SiStrip (i.e. get me out of here if I am on a pixel ROC)
834  continue;
835 
836  APV->isMasked = SiStripQuality_->IsApvBad(APV->DetId, APV->APVId);
837  // if(!FirstSetOfConstants){
838 
839  if (gainHandle->getNumberOfTags() != 2) {
840  edm::LogError("SiStripGainFromCalibTree") << "NUMBER OF GAIN TAG IS EXPECTED TO BE 2\n";
841  fflush(stdout);
842  exit(0);
843  };
844  float newPreviousGain = gainHandle->getApvGain(APV->APVId, gainHandle->getRange(APV->DetId, 1), 1);
845  if (APV->PreviousGain != 1 and newPreviousGain != APV->PreviousGain)
846  edm::LogWarning("SiStripGainFromCalibTree") << "WARNING: ParticleGain in the global tag changed\n";
847  APV->PreviousGain = newPreviousGain;
848 
849  float newPreviousGainTick = gainHandle->getApvGain(APV->APVId, gainHandle->getRange(APV->DetId, 0), 0);
850  if (APV->PreviousGainTick != 1 and newPreviousGainTick != APV->PreviousGainTick) {
851  edm::LogWarning("SiStripGainFromCalibTree")
852  << "WARNING: TickMarkGain in the global tag changed\n"
853  << std::endl
854  << " APV->SubDet: " << APV->SubDet << " APV->APVId:" << APV->APVId << std::endl
855  << " APV->PreviousGainTick: " << APV->PreviousGainTick << " newPreviousGainTick: " << newPreviousGainTick
856  << std::endl;
857  }
858  APV->PreviousGainTick = newPreviousGainTick;
859 
860  //printf("DETID = %7i APVID=%1i Previous Gain=%8.4f (G1) x %8.4f (G2)\n",APV->DetId,APV->APVId,APV->PreviousGainTick, APV->PreviousGain);
861  // }
862  }
863 }
864 
866  if (AlgoMode == "PCL" && !m_harvestingMode)
867  return; //nothing to do in that case
868 
869  if (AlgoMode == "PCL" and m_harvestingMode) {
870  // Load the 2D histograms from the DQM objects
871  // When running in AlCaHarvesting mode the histos are already booked and should be just retrieved from
872  // DQMStore so that they can be used in the fit
873 
874  edm::LogInfo("SiStripGainFromCalibTree") << "Starting harvesting statistics" << std::endl;
875 
876  // check the required tag before adding histograms
877  int elepos = statCollectionFromMode(m_calibrationMode.c_str());
878  if (elepos != Harvest) {
879  //collect statistics from DQM into the related monitored elements
881  if (!stag.empty() && stag[0] != '_')
882  stag.insert(0, 1, '_');
883 
884  if (elepos == -1) {
885  //implememt backward compatibility
886  elepos = 0;
887  stag = "";
888  }
889 
890  std::string DQM_dir = m_DQMdir + ((m_splitDQMstat) ? m_calibrationMode : "");
891 
892  std::string cvi = DQM_dir + std::string("/Charge_Vs_Index") + stag;
893  //std::string cviA = DQM_dir + std::string("/Charge_Vs_Index_Absolute") + stag;
894  std::string cvpTIB = DQM_dir + std::string("/Charge_Vs_PathlengthTIB") + stag;
895  std::string cvpTOB = DQM_dir + std::string("/Charge_Vs_PathlengthTOB") + stag;
896  std::string cvpTIDP = DQM_dir + std::string("/Charge_Vs_PathlengthTIDP") + stag;
897  std::string cvpTIDM = DQM_dir + std::string("/Charge_Vs_PathlengthTIDM") + stag;
898  std::string cvpTECP1 = DQM_dir + std::string("/Charge_Vs_PathlengthTECP1") + stag;
899  std::string cvpTECP2 = DQM_dir + std::string("/Charge_Vs_PathlengthTECP2") + stag;
900  std::string cvpTECM1 = DQM_dir + std::string("/Charge_Vs_PathlengthTECM1") + stag;
901  std::string cvpTECM2 = DQM_dir + std::string("/Charge_Vs_PathlengthTECM2") + stag;
902 
903  Charge_Vs_Index[elepos] = dbe->get(cvi);
904  //Charge_Vs_Index_Absolute[elepos] = dbe->get(cviA.c_str());
905  Charge_Vs_PathlengthTIB[elepos] = dbe->get(cvpTIB);
906  Charge_Vs_PathlengthTOB[elepos] = dbe->get(cvpTOB);
907  Charge_Vs_PathlengthTIDP[elepos] = dbe->get(cvpTIDP);
908  Charge_Vs_PathlengthTIDM[elepos] = dbe->get(cvpTIDM);
909  Charge_Vs_PathlengthTECP1[elepos] = dbe->get(cvpTECP1);
910  Charge_Vs_PathlengthTECP2[elepos] = dbe->get(cvpTECP2);
911  Charge_Vs_PathlengthTECM1[elepos] = dbe->get(cvpTECM1);
912  Charge_Vs_PathlengthTECM2[elepos] = dbe->get(cvpTECM2);
913 
914  if (Charge_Vs_Index[elepos] == nullptr) {
915  edm::LogError("SiStripGainFromCalibTree")
916  << "Harvesting: could not retrieve " << cvi.c_str() << ", statistics will not be summed!" << std::endl;
917  } else {
918  merge((Charge_Vs_Index[Harvest])->getTH2S(), (Charge_Vs_Index[elepos])->getTH2S());
919  edm::LogInfo("SiStripGainFromCalibTree")
920  << "Harvesting " << (Charge_Vs_Index[elepos])->getTH2S()->GetEntries() << " more clusters" << std::endl;
921  }
922 
923  //if (Charge_Vs_Index_Absolute[elepos]==0) {
924  // edm::LogError("SiStripGainFromCalibTree") << "Harvesting: could not retrieve " << cviA.c_str()
925  // << ", statistics will not be summed!" << std::endl;
926  //} else merge( (Charge_Vs_Index_Absolute[Harvest])->getTH2S(), (Charge_Vs_Index_Absolute[elepos])->getTH2S() );
927 
928  if (Charge_Vs_PathlengthTIB[elepos] == nullptr) {
929  edm::LogError("SiStripGainFromCalibTree")
930  << "Harvesting: could not retrieve " << cvpTIB.c_str() << ", statistics will not be summed!" << std::endl;
931  } else
932  (Charge_Vs_PathlengthTIB[Harvest])->getTH2S()->Add((Charge_Vs_PathlengthTIB[elepos])->getTH2S());
933 
934  if (Charge_Vs_PathlengthTOB[elepos] == nullptr) {
935  edm::LogError("SiStripGainFromCalibTree")
936  << "Harvesting: could not retrieve " << cvpTOB.c_str() << ", statistics will not be summed!" << std::endl;
937  } else
938  (Charge_Vs_PathlengthTOB[Harvest])->getTH2S()->Add((Charge_Vs_PathlengthTOB[elepos])->getTH2S());
939 
940  if (Charge_Vs_PathlengthTIDP[elepos] == nullptr) {
941  edm::LogError("SiStripGainFromCalibTree")
942  << "Harvesting: could not retrieve " << cvpTIDP.c_str() << ", statistics will not be summed!" << std::endl;
943  } else
944  (Charge_Vs_PathlengthTIDP[Harvest])->getTH2S()->Add((Charge_Vs_PathlengthTIDP[elepos])->getTH2S());
945 
946  if (Charge_Vs_PathlengthTIDM[elepos] == nullptr) {
947  edm::LogError("SiStripGainFromCalibTree")
948  << "Harvesting: could not retrieve " << cvpTIDM.c_str() << ", statistics will not be summed!" << std::endl;
949  } else
950  (Charge_Vs_PathlengthTIDM[Harvest])->getTH2S()->Add((Charge_Vs_PathlengthTIDM[elepos])->getTH2S());
951 
952  if (Charge_Vs_PathlengthTECP1[elepos] == nullptr) {
953  edm::LogError("SiStripGainFromCalibTree")
954  << "Harvesting: could not retrieve " << cvpTECP1.c_str() << ", statistics will not be summed!" << std::endl;
955  } else
956  (Charge_Vs_PathlengthTECP1[Harvest])->getTH2S()->Add((Charge_Vs_PathlengthTECP1[elepos])->getTH2S());
957 
958  if (Charge_Vs_PathlengthTECP2[elepos] == nullptr) {
959  edm::LogError("SiStripGainFromCalibTree")
960  << "Harvesting: could not retrieve " << cvpTECP2.c_str() << ", statistics will not be summed!" << std::endl;
961  } else
962  (Charge_Vs_PathlengthTECP2[Harvest])->getTH2S()->Add((Charge_Vs_PathlengthTECP2[elepos])->getTH2S());
963 
964  if (Charge_Vs_PathlengthTECM1[elepos] == nullptr) {
965  edm::LogError("SiStripGainFromCalibTree")
966  << "Harvesting: could not retrieve " << cvpTECM1.c_str() << ", statistics will not be summed!" << std::endl;
967  } else
968  (Charge_Vs_PathlengthTECM1[Harvest])->getTH2S()->Add((Charge_Vs_PathlengthTECM1[elepos])->getTH2S());
969 
970  if (Charge_Vs_PathlengthTECM2[elepos] == nullptr) {
971  edm::LogError("SiStripGainFromCalibTree")
972  << "Harvesting: could not retrieve " << cvpTECM2.c_str() << ", statistics will not be summed!" << std::endl;
973  } else
974  (Charge_Vs_PathlengthTECM2[Harvest])->getTH2S()->Add((Charge_Vs_PathlengthTECM2[elepos])->getTH2S());
975 
976  // Gather Charge monitoring histograms
977  std::vector<std::pair<std::string, std::string>> tags =
979  for (unsigned int i = 0; i < tags.size(); i++) {
980  std::string tag = DQM_dir + "/" + (tags[i]).first + stag;
981  Charge_1[elepos].push_back(APVGain::APVmon(0, 0, 0, dbe->get(tag)));
982  if ((Charge_1[elepos][i]).getMonitor() == nullptr) {
983  edm::LogError("SiStripGainFromCalibTree")
984  << "Harvesting: could not retrieve " << tag.c_str() << ", statistics will not be summed!" << std::endl;
985  } else
986  (Charge_1[Harvest][i]).getMonitor()->getTH1D()->Add((Charge_1[elepos][i]).getMonitor()->getTH1D());
987  }
988 
990  for (unsigned int i = 0; i < tags.size(); i++) {
991  std::string tag = DQM_dir + "/" + (tags[i]).first + stag;
992  Charge_2[elepos].push_back(APVGain::APVmon(0, 0, 0, dbe->get(tag)));
993  if ((Charge_2[elepos][i]).getMonitor() == nullptr) {
994  edm::LogError("SiStripGainFromCalibTree")
995  << "Harvesting: could not retrieve " << tag.c_str() << ", statistics will not be summed!" << std::endl;
996  } else
997  (Charge_2[Harvest][i]).getMonitor()->getTH1D()->Add((Charge_2[elepos][i]).getMonitor()->getTH1D());
998  }
999 
1001  for (unsigned int i = 0; i < tags.size(); i++) {
1002  std::string tag = DQM_dir + "/" + (tags[i]).first + stag;
1003  Charge_3[elepos].push_back(APVGain::APVmon(0, 0, 0, dbe->get(tag)));
1004  if ((Charge_3[elepos][i]).getMonitor() == nullptr) {
1005  edm::LogError("SiStripGainFromCalibTree")
1006  << "Harvesting: could not retrieve " << tag.c_str() << ", statistics will not be summed!" << std::endl;
1007  } else
1008  (Charge_3[Harvest][i]).getMonitor()->getTH1D()->Add((Charge_3[elepos][i]).getMonitor()->getTH1D());
1009  }
1010 
1012  for (unsigned int i = 0; i < tags.size(); i++) {
1013  std::string tag = DQM_dir + "/" + (tags[i]).first + stag;
1014  Charge_4[elepos].push_back(APVGain::APVmon(0, 0, 0, dbe->get(tag)));
1015  if ((Charge_4[elepos][i]).getMonitor() == nullptr) {
1016  edm::LogError("SiStripGainFromCalibTree")
1017  << "Harvesting: could not retrieve " << tag.c_str() << ", statistics will not be summed!" << std::endl;
1018  } else
1019  (Charge_4[Harvest][i]).getMonitor()->getTH1D()->Add((Charge_4[elepos][i]).getMonitor()->getTH1D());
1020  }
1021  }
1022  }
1023 }
1024 
1026  if (AlgoMode == "PCL" && !m_harvestingMode)
1027  return; //nothing to do in that case
1028 
1029  if (AlgoMode == "CalibTree") {
1030  edm::LogInfo("SiStripGainFromCalibTree") << "Analyzing calibration tree" << std::endl;
1031  // Loop on calibTrees to fill the 2D histograms
1033  } else if (m_harvestingMode) {
1034  NClusterStrip = (Charge_Vs_Index[Harvest])->getTH2S()->Integral(0, NStripAPVs + 1, 0, 99999);
1035  //NClusterPixel = (Charge_Vs_Index[Harvest])->getTH2S()->Integral(NStripAPVs+2, NStripAPVs+NPixelDets+2, 0, 99999 );
1036  }
1037 
1038  // Now that we have the full statistics we can extract the information of the 2D histograms
1040 
1041  // Result monitoring
1042  qualityMonitor();
1043 
1044  // Force the DB object writing,
1045  // thus setting the IOV as the first processed run (if timeFromEndRun is set to false)
1046  storeOnDbNow();
1047 
1048  if (AlgoMode != "PCL" or saveSummary) {
1049  edm::LogInfo("SiStripGainFromCalibTree") << "Saving summary into root file" << std::endl;
1050 
1051  //also save the 2D monitor elements to this file as TH2D tfs
1053 
1054  //save only the statistics for the calibrationTag
1055  int elepos = statCollectionFromMode(m_calibrationMode.c_str());
1056 
1057  if (Charge_Vs_Index[elepos] != nullptr)
1058  tfs->make<TH2S>(*(Charge_Vs_Index[elepos])->getTH2S());
1059  //if( Charge_Vs_Index_Absolute[elepos]!=0 ) tfs->make<TH2S> ( *(Charge_Vs_Index_Absolute[elepos])->getTH2S() );
1060  if (Charge_Vs_PathlengthTIB[elepos] != nullptr)
1061  tfs->make<TH2S>(*(Charge_Vs_PathlengthTIB[elepos])->getTH2S());
1062  if (Charge_Vs_PathlengthTOB[elepos] != nullptr)
1063  tfs->make<TH2S>(*(Charge_Vs_PathlengthTOB[elepos])->getTH2S());
1064  if (Charge_Vs_PathlengthTIDP[elepos] != nullptr)
1065  tfs->make<TH2S>(*(Charge_Vs_PathlengthTIDP[elepos])->getTH2S());
1066  if (Charge_Vs_PathlengthTIDM[elepos] != nullptr)
1067  tfs->make<TH2S>(*(Charge_Vs_PathlengthTIDM[elepos])->getTH2S());
1068  if (Charge_Vs_PathlengthTECP1[elepos] != nullptr)
1069  tfs->make<TH2S>(*(Charge_Vs_PathlengthTECP1[elepos])->getTH2S());
1070  if (Charge_Vs_PathlengthTECP2[elepos] != nullptr)
1071  tfs->make<TH2S>(*(Charge_Vs_PathlengthTECP2[elepos])->getTH2S());
1072  if (Charge_Vs_PathlengthTECM1[elepos] != nullptr)
1073  tfs->make<TH2S>(*(Charge_Vs_PathlengthTECM1[elepos])->getTH2S());
1074  if (Charge_Vs_PathlengthTECM2[elepos] != nullptr)
1075  tfs->make<TH2S>(*(Charge_Vs_PathlengthTECM2[elepos])->getTH2S());
1076 
1077  storeOnTree(tfs);
1078  }
1079 }
1080 
1081 void SiStripGainFromCalibTree::getPeakOfLandau(TH1* InputHisto, double* FitResults, double LowRange, double HighRange) {
1082  FitResults[0] = -0.5; //MPV
1083  FitResults[1] = 0; //MPV error
1084  FitResults[2] = -0.5; //Width
1085  FitResults[3] = 0; //Width error
1086  FitResults[4] = -0.5; //Fit Chi2/NDF
1087  FitResults[5] = 0; //Normalization
1088 
1089  if (InputHisto->GetEntries() < MinNrEntries)
1090  return;
1091 
1092  // perform fit with standard landau
1093  TF1* MyLandau = new TF1("MyLandau", "landau", LowRange, HighRange);
1094  MyLandau->SetParameter(1, 300);
1095  InputHisto->Fit(MyLandau, "0QR WW");
1096 
1097  // MPV is parameter 1 (0=constant, 1=MPV, 2=Sigma)
1098  FitResults[0] = MyLandau->GetParameter(1); //MPV
1099  FitResults[1] = MyLandau->GetParError(1); //MPV error
1100  FitResults[2] = MyLandau->GetParameter(2); //Width
1101  FitResults[3] = MyLandau->GetParError(2); //Width error
1102  FitResults[4] = MyLandau->GetChisquare() / MyLandau->GetNDF(); //Fit Chi2/NDF
1103  FitResults[5] = MyLandau->GetParameter(0);
1104 
1105  delete MyLandau;
1106 }
1107 
1109  if (FitResults[0] <= 0)
1110  return false;
1111  // if(FitResults[1] > MaxMPVError )return false;
1112  // if(FitResults[4] > MaxChi2OverNDF)return false;
1113  return true;
1114 }
1115 
1117  edm::LogInfo("SiStripGainFromCalibTree") << "Processing run " << runnumber << " and event " << eventnumber << " for "
1118  << m_calibrationMode << " calibration." << std::endl;
1119 
1120  if (runnumber < SRun)
1121  SRun = runnumber;
1122  if (runnumber > ERun)
1123  ERun = runnumber;
1124 
1125  NEvent++;
1126  NTrack += (*trackp).size();
1127 
1128  int elepos = statCollectionFromMode(m_calibrationMode.c_str());
1129 
1130  unsigned int FirstAmplitude = 0;
1131  for (unsigned int i = 0; i < (*chargeoverpath).size(); i++) {
1132  FirstAmplitude += (*nstrips)[i];
1133  int TI = (*trackindex)[i];
1134 
1135  //printf("%i - %i - %i %i %i\n", (int)(*rawid)[i], (int)(*firststrip)[i]/128, (int)(*farfromedge)[i], (int)(*overlapping)[i], (int)(*saturation )[i] );
1136  if ((*tracketa)[TI] < MinTrackEta)
1137  continue;
1138  if ((*tracketa)[TI] > MaxTrackEta)
1139  continue;
1140  if ((*trackp)[TI] < MinTrackMomentum)
1141  continue;
1142  if ((*trackp)[TI] > MaxTrackMomentum)
1143  continue;
1144  if ((*trackhitsvalid)[TI] < MinTrackHits)
1145  continue;
1146  if ((*trackchi2ndof)[TI] > MaxTrackChiOverNdf)
1147  continue;
1148  if ((*trackalgo)[TI] > MaxTrackingIteration)
1149  continue;
1150 
1151  stAPVGain* APV =
1152  APVsColl[((*rawid)[i] << 4) |
1153  ((*firststrip)[i] /
1154  128)]; //works for both strip and pixel thanks to firstStrip encoding for pixel in the calibTree
1155 
1156  if (APV->SubDet > 2 && (*farfromedge)[i] == false)
1157  continue;
1158  if (APV->SubDet > 2 && (*overlapping)[i] == true)
1159  continue;
1160  if (APV->SubDet > 2 && (*saturation)[i] && !AllowSaturation)
1161  continue;
1162  if (APV->SubDet > 2 && (*nstrips)[i] > MaxNrStrips)
1163  continue;
1164 
1165  //printf("detId=%7i run=%7i event=%9i charge=%5i cs=%3i\n",(*rawid)[i],runnumber,eventnumber,(*charge)[i],(*nstrips)[i]);
1166 
1167  //double trans = atan2((*localdiry)[i],(*localdirx)[i])*(180/3.14159265);
1168  //double alpha = acos ((*localdirx)[i] / sqrt( pow((*localdirx)[i],2) + pow((*localdirz)[i],2) ) ) * (180/3.14159265);
1169  //double beta = acos ((*localdiry)[i] / sqrt( pow((*localdirx)[i],2) + pow((*localdirz)[i],2) ) ) * (180/3.14159265);
1170 
1171  //printf("NStrip = %i : Charge = %i --> Path = %f --> ChargeOverPath=%f\n",(*nstrips)[i],(*charge)[i],(*path)[i],(*chargeoverpath)[i]);
1172  //printf("Amplitudes: ");
1173  //for(unsigned int a=0;a<(*nstrips)[i];a++){printf("%i ",(*amplitude)[FirstAmplitude+a]);}
1174  //printf("\n");
1175 
1176  if (APV->SubDet > 2) {
1177  NClusterStrip++;
1178  } else {
1179  NClusterPixel++;
1180  }
1181 
1182  int Charge = 0;
1183  if (APV->SubDet > 2 && (useCalibration || !FirstSetOfConstants)) {
1184  bool Saturation = false;
1185  for (unsigned int s = 0; s < (*nstrips)[i]; s++) {
1186  int StripCharge = (*amplitude)[FirstAmplitude - (*nstrips)[i] + s];
1188  StripCharge = (int)(StripCharge * (APV->PreviousGain / APV->CalibGain));
1189  } else if (useCalibration) {
1190  StripCharge = (int)(StripCharge / APV->CalibGain);
1191  } else if (!FirstSetOfConstants) {
1192  StripCharge = (int)(StripCharge * APV->PreviousGain);
1193  }
1194  if (StripCharge > 1024) {
1195  StripCharge = 255;
1196  Saturation = true;
1197  } else if (StripCharge > 254) {
1198  StripCharge = 254;
1199  Saturation = true;
1200  }
1201  Charge += StripCharge;
1202  }
1203  if (Saturation && !AllowSaturation)
1204  continue;
1205  } else if (APV->SubDet > 2) {
1206  Charge = (*charge)[i];
1207  } else {
1208  Charge = (*charge)[i] / 265.0; //expected scale factor between pixel and strip charge
1209  }
1210 
1211  //printf("ChargeDifference = %i Vs %i with Gain = %f\n",(*charge)[i],Charge,APV->CalibGain);
1212 
1213  double ClusterChargeOverPath = ((double)Charge) / (*path)[i];
1214  if (APV->SubDet > 2) {
1215  if (Validation) {
1216  ClusterChargeOverPath /= (*gainused)[i];
1217  }
1218  if (OldGainRemoving) {
1219  ClusterChargeOverPath *= (*gainused)[i];
1220  }
1221  }
1222 
1223  // keep pixel cluster charge processing until here
1224  if (APV->SubDet <= 2)
1225  continue;
1226 
1227  (Charge_Vs_Index[elepos])->Fill(APV->Index, ClusterChargeOverPath);
1228 
1229  // Compute the charge for monitoring and fill the relative histograms
1230  int mCharge1 = 0;
1231  int mCharge2 = 0;
1232  int mCharge3 = 0;
1233  int mCharge4 = 0;
1234  if (APV->SubDet > 2) {
1235  for (unsigned int s = 0; s < (*nstrips)[i]; s++) {
1236  int StripCharge = (*amplitude)[FirstAmplitude - (*nstrips)[i] + s];
1237  if (StripCharge > 1024)
1238  StripCharge = 255;
1239  else if (StripCharge > 254)
1240  StripCharge = 254;
1241  mCharge1 += StripCharge;
1242  mCharge2 += StripCharge;
1243  mCharge3 += StripCharge;
1244  mCharge4 += StripCharge;
1245  }
1246  // Revome gains for monitoring
1247  mCharge2 *= (*gainused)[i]; // remove G2
1248  mCharge3 *= (*gainusedTick)[i]; // remove G1
1249  mCharge4 *= ((*gainused)[i] * (*gainusedTick)[i]); // remove G1 and G2
1250  }
1251  std::vector<APVGain::APVmon>& v1 = Charge_1[elepos];
1252  std::vector<MonitorElement*> cmon1 = APVGain::FetchMonitor(v1, (*rawid)[i], tTopo_);
1253  for (unsigned int m = 0; m < cmon1.size(); m++)
1254  cmon1[m]->Fill(((double)mCharge1) / (*path)[i]);
1255 
1256  std::vector<APVGain::APVmon>& v2 = Charge_2[elepos];
1257  std::vector<MonitorElement*> cmon2 = APVGain::FetchMonitor(v2, (*rawid)[i], tTopo_);
1258  for (unsigned int m = 0; m < cmon2.size(); m++)
1259  cmon2[m]->Fill(((double)mCharge2) / (*path)[i]);
1260 
1261  std::vector<APVGain::APVmon>& v3 = Charge_3[elepos];
1262  std::vector<MonitorElement*> cmon3 = APVGain::FetchMonitor(v3, (*rawid)[i], tTopo_);
1263  for (unsigned int m = 0; m < cmon3.size(); m++)
1264  cmon3[m]->Fill(((double)mCharge3) / (*path)[i]);
1265 
1266  std::vector<APVGain::APVmon>& v4 = Charge_4[elepos];
1267  std::vector<MonitorElement*> cmon4 = APVGain::FetchMonitor(v4, (*rawid)[i], tTopo_);
1268  for (unsigned int m = 0; m < cmon4.size(); m++)
1269  cmon4[m]->Fill(((double)mCharge4) / (*path)[i]);
1270 
1271  // Fill Charge Vs pathLenght histograms
1272  if (APV->SubDet == StripSubdetector::TIB) {
1273  (Charge_Vs_PathlengthTIB[elepos])->Fill((*path)[i], Charge); // TIB
1274 
1275  } else if (APV->SubDet == StripSubdetector::TOB) {
1276  (Charge_Vs_PathlengthTOB[elepos])->Fill((*path)[i], Charge); // TOB
1277 
1278  } else if (APV->SubDet == StripSubdetector::TID) {
1279  if (APV->Eta < 0) {
1280  (Charge_Vs_PathlengthTIDM[elepos])->Fill((*path)[i], Charge);
1281  } // TID minus
1282  else if (APV->Eta > 0) {
1283  (Charge_Vs_PathlengthTIDP[elepos])->Fill((*path)[i], Charge);
1284  } // TID plus
1285 
1286  } else if (APV->SubDet == StripSubdetector::TEC) {
1287  if (APV->Eta < 0) {
1288  if (APV->Thickness < 0.04) {
1289  (Charge_Vs_PathlengthTECM1[elepos])->Fill((*path)[i], Charge);
1290  } // TEC minus, type 1
1291  else if (APV->Thickness > 0.04) {
1292  (Charge_Vs_PathlengthTECM2[elepos])->Fill((*path)[i], Charge);
1293  } // TEC minus, type 2
1294  } else if (APV->Eta > 0) {
1295  if (APV->Thickness < 0.04) {
1296  (Charge_Vs_PathlengthTECP1[elepos])->Fill((*path)[i], Charge);
1297  } // TEC plus, type 1
1298  else if (APV->Thickness > 0.04) {
1299  (Charge_Vs_PathlengthTECP2[elepos])->Fill((*path)[i], Charge);
1300  } // TEC plus, type 2
1301  }
1302  }
1303 
1304  } // END OF ON-CLUSTER LOOP
1305 } //END OF processEvent()
1306 
1308  for (unsigned int i = 0; i < VInputFiles.size(); i++) {
1309  printf("Openning file %3i/%3i --> %s\n", i + 1, (int)VInputFiles.size(), (char*)(VInputFiles[i].c_str()));
1310  fflush(stdout);
1311  TFile* tfile = TFile::Open(VInputFiles[i].c_str());
1312  TString tree_path = TString::Format("gainCalibrationTree%s/tree", m_calibrationMode.c_str());
1313  TTree* tree = dynamic_cast<TTree*>(tfile->Get(tree_path.Data()));
1314 
1315  tree->SetBranchAddress((EventPrefix_ + "event" + EventSuffix_).c_str(), &eventnumber, nullptr);
1316  tree->SetBranchAddress((EventPrefix_ + "run" + EventSuffix_).c_str(), &runnumber, nullptr);
1317  tree->SetBranchAddress((EventPrefix_ + "TrigTech" + EventSuffix_).c_str(), &TrigTech, nullptr);
1318 
1319  tree->SetBranchAddress((TrackPrefix_ + "chi2ndof" + TrackSuffix_).c_str(), &trackchi2ndof, nullptr);
1320  tree->SetBranchAddress((TrackPrefix_ + "momentum" + TrackSuffix_).c_str(), &trackp, nullptr);
1321  tree->SetBranchAddress((TrackPrefix_ + "pt" + TrackSuffix_).c_str(), &trackpt, nullptr);
1322  tree->SetBranchAddress((TrackPrefix_ + "eta" + TrackSuffix_).c_str(), &tracketa, nullptr);
1323  tree->SetBranchAddress((TrackPrefix_ + "phi" + TrackSuffix_).c_str(), &trackphi, nullptr);
1324  tree->SetBranchAddress((TrackPrefix_ + "hitsvalid" + TrackSuffix_).c_str(), &trackhitsvalid, nullptr);
1325  tree->SetBranchAddress((TrackPrefix_ + "algo" + TrackSuffix_).c_str(), &trackalgo, nullptr);
1326 
1327  tree->SetBranchAddress((CalibPrefix_ + "trackindex" + CalibSuffix_).c_str(), &trackindex, nullptr);
1328  tree->SetBranchAddress((CalibPrefix_ + "rawid" + CalibSuffix_).c_str(), &rawid, nullptr);
1329  tree->SetBranchAddress((CalibPrefix_ + "localdirx" + CalibSuffix_).c_str(), &localdirx, nullptr);
1330  tree->SetBranchAddress((CalibPrefix_ + "localdiry" + CalibSuffix_).c_str(), &localdiry, nullptr);
1331  tree->SetBranchAddress((CalibPrefix_ + "localdirz" + CalibSuffix_).c_str(), &localdirz, nullptr);
1332  tree->SetBranchAddress((CalibPrefix_ + "firststrip" + CalibSuffix_).c_str(), &firststrip, nullptr);
1333  tree->SetBranchAddress((CalibPrefix_ + "nstrips" + CalibSuffix_).c_str(), &nstrips, nullptr);
1334  tree->SetBranchAddress((CalibPrefix_ + "saturation" + CalibSuffix_).c_str(), &saturation, nullptr);
1335  tree->SetBranchAddress((CalibPrefix_ + "overlapping" + CalibSuffix_).c_str(), &overlapping, nullptr);
1336  tree->SetBranchAddress((CalibPrefix_ + "farfromedge" + CalibSuffix_).c_str(), &farfromedge, nullptr);
1337  tree->SetBranchAddress((CalibPrefix_ + "charge" + CalibSuffix_).c_str(), &charge, nullptr);
1338  tree->SetBranchAddress((CalibPrefix_ + "path" + CalibSuffix_).c_str(), &path, nullptr);
1339  tree->SetBranchAddress((CalibPrefix_ + "chargeoverpath" + CalibSuffix_).c_str(), &chargeoverpath, nullptr);
1340  tree->SetBranchAddress((CalibPrefix_ + "amplitude" + CalibSuffix_).c_str(), &amplitude, nullptr);
1341  tree->SetBranchAddress((CalibPrefix_ + "gainused" + CalibSuffix_).c_str(), &gainused, nullptr);
1342  tree->SetBranchAddress((CalibPrefix_ + "gainusedTick" + CalibSuffix_).c_str(), &gainusedTick, nullptr);
1343 
1344  unsigned int nentries = tree->GetEntries();
1345  printf("Number of Events = %i + %i = %i\n", NEvent, nentries, (NEvent + nentries));
1346  printf("Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
1347  printf("Looping on the Tree :");
1348  int TreeStep = nentries / 50;
1349  if (TreeStep <= 1)
1350  TreeStep = 1;
1351  for (unsigned int ientry = 0; ientry < tree->GetEntries(); ientry++) {
1352  if (ientry % TreeStep == 0) {
1353  printf(".");
1354  fflush(stdout);
1355  }
1356  tree->GetEntry(ientry);
1357  processEvent();
1358  }
1359  printf("\n"); // END OF EVENT LOOP
1360  }
1361 }
1362 
1364  unsigned int I = 0;
1365  TH1F* Proj = nullptr;
1366  double FitResults[6];
1367  double MPVmean = 300;
1368 
1369  int elepos = (AlgoMode == "PCL") ? Harvest : statCollectionFromMode(m_calibrationMode.c_str());
1370 
1371  if (Charge_Vs_Index[elepos] == nullptr) {
1372  edm::LogError("SiStripGainFromCalibTree")
1373  << "Harvesting: could not execute algoComputeMPVandGain method because " << m_calibrationMode.c_str()
1374  << " statistics cannot be retrieved.\n"
1375  << "Please check if input contains " << m_calibrationMode.c_str() << " data." << std::endl;
1376  return;
1377  }
1378 
1379  TH2S* chvsidx = (Charge_Vs_Index[elepos])->getTH2S();
1380 
1381  printf("Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
1382  printf("Fitting Charge Distribution :");
1383  int TreeStep = APVsColl.size() / 50;
1384  for (auto it = APVsColl.begin(); it != APVsColl.end(); it++, I++) {
1385  if (I % TreeStep == 0) {
1386  printf(".");
1387  fflush(stdout);
1388  }
1389  stAPVGain* APV = it->second;
1390  if (APV->Bin < 0)
1391  APV->Bin = chvsidx->GetXaxis()->FindBin(APV->Index);
1392 
1393  if (APV->isMasked) {
1394  APV->Gain = APV->PreviousGain;
1395  MASKED++;
1396  continue;
1397  }
1398 
1399  Proj = (TH1F*)(chvsidx->ProjectionY(
1400  "", chvsidx->GetXaxis()->FindBin(APV->Index), chvsidx->GetXaxis()->FindBin(APV->Index), "e"));
1401  if (!Proj)
1402  continue;
1403 
1404  if (CalibrationLevel == 0) {
1405  } else if (CalibrationLevel == 1) {
1406  int SecondAPVId = APV->APVId;
1407  if (SecondAPVId % 2 == 0) {
1408  SecondAPVId = SecondAPVId + 1;
1409  } else {
1410  SecondAPVId = SecondAPVId - 1;
1411  }
1412  stAPVGain* APV2 = APVsColl[(APV->DetId << 4) | SecondAPVId];
1413  if (APV2->Bin < 0)
1414  APV2->Bin = chvsidx->GetXaxis()->FindBin(APV2->Index);
1415  TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY("", APV2->Bin, APV2->Bin, "e"));
1416  if (Proj2) {
1417  Proj->Add(Proj2, 1);
1418  delete Proj2;
1419  }
1420  } else if (CalibrationLevel == 2) {
1421  for (unsigned int i = 0; i < 16; i++) { //loop up to 6APV for Strip and up to 16 for Pixels
1422  auto tmpit = APVsColl.find((APV->DetId << 4) | i);
1423  if (tmpit == APVsColl.end())
1424  continue;
1425  stAPVGain* APV2 = tmpit->second;
1426  if (APV2->DetId != APV->DetId || APV2->APVId == APV->APVId)
1427  continue;
1428  if (APV2->Bin < 0)
1429  APV2->Bin = chvsidx->GetXaxis()->FindBin(APV2->Index);
1430  TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY("", APV2->Bin, APV2->Bin, "e"));
1431  if (Proj2) {
1432  Proj->Add(Proj2, 1);
1433  delete Proj2;
1434  }
1435  }
1436  } else {
1437  CalibrationLevel = 0;
1438  printf("Unknown Calibration Level, will assume %i\n", CalibrationLevel);
1439  }
1440 
1441  getPeakOfLandau(Proj, FitResults);
1442  APV->FitMPV = FitResults[0];
1443  APV->FitMPVErr = FitResults[1];
1444  APV->FitWidth = FitResults[2];
1445  APV->FitWidthErr = FitResults[3];
1446  APV->FitChi2 = FitResults[4];
1447  APV->FitNorm = FitResults[5];
1448  APV->NEntries = Proj->GetEntries();
1449 
1450  if (IsGoodLandauFit(FitResults)) {
1451  APV->Gain = APV->FitMPV / MPVmean;
1452  if (APV->SubDet > 2)
1453  GOOD++;
1454  } else {
1455  APV->Gain = APV->PreviousGain;
1456  if (APV->SubDet > 2)
1457  BAD++;
1458  }
1459  if (APV->Gain <= 0)
1460  APV->Gain = 1;
1461 
1462  //printf("%5i/%5i: %6i - %1i %5E Entries --> MPV = %f +- %f\n",I,APVsColl.size(),APV->DetId, APV->APVId, Proj->GetEntries(), FitResults[0], FitResults[1]);fflush(stdout);
1463  delete Proj;
1464  }
1465  printf("\n");
1466 }
1467 
1469  int elepos = (AlgoMode == "PCL") ? Harvest : statCollectionFromMode(m_calibrationMode.c_str());
1470 
1471  for (unsigned int a = 0; a < APVsCollOrdered.size(); a++) {
1473  if (APV == nullptr)
1474  continue;
1475 
1476  unsigned int Index = APV->Index;
1477  unsigned int SubDet = APV->SubDet;
1478  unsigned int DetId = APV->DetId;
1479  float z = APV->z;
1480  float Eta = APV->Eta;
1481  float R = APV->R;
1482  float Phi = APV->Phi;
1483  float Thickness = APV->Thickness;
1484  double FitMPV = APV->FitMPV;
1485  double FitMPVErr = APV->FitMPVErr;
1486  double Gain = APV->Gain;
1487  double NEntries = APV->NEntries;
1488  double PreviousGain = APV->PreviousGain;
1489 
1490  if (SubDet < 3)
1491  continue; // avoid to loop over Pixel det id
1492 
1493  if (Gain != 1.) {
1494  std::vector<MonitorElement*> charge_histos = APVGain::FetchMonitor(newCharge, DetId, tTopo_);
1495  TH2S* chvsidx = (Charge_Vs_Index[elepos])->getTH2S();
1496  int bin = chvsidx->GetXaxis()->FindBin(Index);
1497  TH1D* Proj = chvsidx->ProjectionY("proj", bin, bin);
1498  for (int binId = 0; binId < Proj->GetXaxis()->GetNbins(); binId++) {
1499  double new_charge = Proj->GetXaxis()->GetBinCenter(binId) / Gain;
1500  if (Proj->GetBinContent(binId) != 0.) {
1501  for (unsigned int h = 0; h < charge_histos.size(); h++) {
1502  TH1D* chisto = (charge_histos[h])->getTH1D();
1503  for (int e = 0; e < Proj->GetBinContent(binId); e++)
1504  chisto->Fill(new_charge);
1505  }
1506  }
1507  }
1508  }
1509 
1510  if (FitMPV <= 0.) { // No fit of MPV
1511  if (APV->isMasked)
1512  NoMPVmasked->Fill(z, R);
1513  else
1514  NoMPVfit->Fill(z, R);
1515 
1516  } else { // Fit of MPV
1517  if (FitMPV > 0.)
1518  Gains->Fill(Gain);
1519 
1520  MPVs->Fill(FitMPV);
1521  if (Thickness < 0.04)
1522  MPVs320->Fill(FitMPV);
1523  if (Thickness > 0.04)
1524  MPVs500->Fill(FitMPV);
1525 
1526  MPVError->Fill(FitMPVErr);
1527  MPVErrorVsMPV->Fill(FitMPV, FitMPVErr);
1528  MPVErrorVsEta->Fill(Eta, FitMPVErr);
1529  MPVErrorVsPhi->Fill(Phi, FitMPVErr);
1530  MPVErrorVsN->Fill(NEntries, FitMPVErr);
1531 
1532  if (SubDet == 3) {
1533  MPV_Vs_EtaTIB->Fill(Eta, FitMPV);
1534  MPV_Vs_PhiTIB->Fill(Phi, FitMPV);
1535  MPVsTIB->Fill(FitMPV);
1536 
1537  } else if (SubDet == 4) {
1538  MPV_Vs_EtaTID->Fill(Eta, FitMPV);
1539  MPV_Vs_PhiTID->Fill(Phi, FitMPV);
1540  MPVsTID->Fill(FitMPV);
1541  if (Eta < 0.)
1542  MPVsTIDM->Fill(FitMPV);
1543  if (Eta > 0.)
1544  MPVsTIDP->Fill(FitMPV);
1545 
1546  } else if (SubDet == 5) {
1547  MPV_Vs_EtaTOB->Fill(Eta, FitMPV);
1548  MPV_Vs_PhiTOB->Fill(Phi, FitMPV);
1549  MPVsTOB->Fill(FitMPV);
1550 
1551  } else if (SubDet == 6) {
1552  MPV_Vs_EtaTEC->Fill(Eta, FitMPV);
1553  MPV_Vs_PhiTEC->Fill(Phi, FitMPV);
1554  MPVsTEC->Fill(FitMPV);
1555  if (Eta < 0.)
1556  MPVsTECM->Fill(FitMPV);
1557  if (Eta > 0.)
1558  MPVsTECP->Fill(FitMPV);
1559  if (Thickness < 0.04) {
1560  MPV_Vs_EtaTECthin->Fill(Eta, FitMPV);
1561  MPV_Vs_PhiTECthin->Fill(Phi, FitMPV);
1562  MPVsTECthin->Fill(FitMPV);
1563  if (Eta > 0.)
1564  MPVsTECP1->Fill(FitMPV);
1565  if (Eta < 0.)
1566  MPVsTECM1->Fill(FitMPV);
1567  }
1568  if (Thickness > 0.04) {
1569  MPV_Vs_EtaTECthick->Fill(Eta, FitMPV);
1570  MPV_Vs_PhiTECthick->Fill(Phi, FitMPV);
1571  MPVsTECthick->Fill(FitMPV);
1572  if (Eta > 0.)
1573  MPVsTECP2->Fill(FitMPV);
1574  if (Eta < 0.)
1575  MPVsTECM2->Fill(FitMPV);
1576  }
1577  }
1578  }
1579 
1580  if (SubDet == 3 && PreviousGain != 0.)
1581  DiffWRTPrevGainTIB->Fill(Gain / PreviousGain);
1582  else if (SubDet == 4 && PreviousGain != 0.)
1583  DiffWRTPrevGainTID->Fill(Gain / PreviousGain);
1584  else if (SubDet == 5 && PreviousGain != 0.)
1585  DiffWRTPrevGainTOB->Fill(Gain / PreviousGain);
1586  else if (SubDet == 6 && PreviousGain != 0.)
1587  DiffWRTPrevGainTEC->Fill(Gain / PreviousGain);
1588 
1589  if (SubDet == 3)
1590  GainVsPrevGainTIB->Fill(PreviousGain, Gain);
1591  else if (SubDet == 4)
1592  GainVsPrevGainTID->Fill(PreviousGain, Gain);
1593  else if (SubDet == 5)
1594  GainVsPrevGainTOB->Fill(PreviousGain, Gain);
1595  else if (SubDet == 6)
1596  GainVsPrevGainTEC->Fill(PreviousGain, Gain);
1597  }
1598 }
1599 
1601  unsigned int tree_Index;
1602  unsigned int tree_Bin;
1603  unsigned int tree_DetId;
1604  unsigned char tree_APVId;
1605  unsigned char tree_SubDet;
1606  float tree_x;
1607  float tree_y;
1608  float tree_z;
1609  float tree_Eta;
1610  float tree_R;
1611  float tree_Phi;
1612  float tree_Thickness;
1613  float tree_FitMPV;
1614  float tree_FitMPVErr;
1615  float tree_FitWidth;
1616  float tree_FitWidthErr;
1617  float tree_FitChi2NDF;
1618  float tree_FitNorm;
1619  double tree_Gain;
1620  double tree_PrevGain;
1621  double tree_PrevGainTick;
1622  double tree_NEntries;
1623  bool tree_isMasked;
1624 
1625  TTree* MyTree;
1626  MyTree = tfs->make<TTree>("APVGain", "APVGain");
1627  MyTree->Branch("Index", &tree_Index, "Index/i");
1628  MyTree->Branch("Bin", &tree_Bin, "Bin/i");
1629  MyTree->Branch("DetId", &tree_DetId, "DetId/i");
1630  MyTree->Branch("APVId", &tree_APVId, "APVId/b");
1631  MyTree->Branch("SubDet", &tree_SubDet, "SubDet/b");
1632  MyTree->Branch("x", &tree_x, "x/F");
1633  MyTree->Branch("y", &tree_y, "y/F");
1634  MyTree->Branch("z", &tree_z, "z/F");
1635  MyTree->Branch("Eta", &tree_Eta, "Eta/F");
1636  MyTree->Branch("R", &tree_R, "R/F");
1637  MyTree->Branch("Phi", &tree_Phi, "Phi/F");
1638  MyTree->Branch("Thickness", &tree_Thickness, "Thickness/F");
1639  MyTree->Branch("FitMPV", &tree_FitMPV, "FitMPV/F");
1640  MyTree->Branch("FitMPVErr", &tree_FitMPVErr, "FitMPVErr/F");
1641  MyTree->Branch("FitWidth", &tree_FitWidth, "FitWidth/F");
1642  MyTree->Branch("FitWidthErr", &tree_FitWidthErr, "FitWidthErr/F");
1643  MyTree->Branch("FitChi2NDF", &tree_FitChi2NDF, "FitChi2NDF/F");
1644  MyTree->Branch("FitNorm", &tree_FitNorm, "FitNorm/F");
1645  MyTree->Branch("Gain", &tree_Gain, "Gain/D");
1646  MyTree->Branch("PrevGain", &tree_PrevGain, "PrevGain/D");
1647  MyTree->Branch("PrevGainTick", &tree_PrevGainTick, "PrevGainTick/D");
1648  MyTree->Branch("NEntries", &tree_NEntries, "NEntries/D");
1649  MyTree->Branch("isMasked", &tree_isMasked, "isMasked/O");
1650 
1651  FILE* Gains = stdout;
1652  fprintf(Gains, "NEvents = %i\n", NEvent);
1653  fprintf(Gains, "NTracks = %i\n", NTrack);
1654  //fprintf(Gains,"NClustersPixel = %i\n",NClusterPixel);
1655  fprintf(Gains, "NClustersStrip = %i\n", NClusterStrip);
1656  //fprintf(Gains,"Number of Pixel Dets = %lu\n",static_cast<unsigned long>(NPixelDets));
1657  fprintf(Gains, "Number of Strip APVs = %lu\n", static_cast<unsigned long>(NStripAPVs));
1658  fprintf(Gains,
1659  "GoodFits = %i BadFits = %i ratio = %f%% (MASKED=%i)\n",
1660  GOOD,
1661  BAD,
1662  (100.0 * GOOD) / (GOOD + BAD),
1663  MASKED);
1664 
1665  Gains = fopen(OutputGains.c_str(), "w");
1666  fprintf(Gains, "NEvents = %i\n", NEvent);
1667  fprintf(Gains, "NTracks = %i\n", NTrack);
1668  //fprintf(Gains,"NClustersPixel = %i\n",NClusterPixel);
1669  fprintf(Gains, "NClustersStrip = %i\n", NClusterStrip);
1670  fprintf(Gains, "Number of Strip APVs = %lu\n", static_cast<unsigned long>(NStripAPVs));
1671  //fprintf(Gains,"Number of Pixel Dets = %lu\n",static_cast<unsigned long>(NPixelDets));
1672  fprintf(Gains,
1673  "GoodFits = %i BadFits = %i ratio = %f%% (MASKED=%i)\n",
1674  GOOD,
1675  BAD,
1676  (100.0 * GOOD) / (GOOD + BAD),
1677  MASKED);
1678 
1679  int elepos = statCollectionFromMode(m_calibrationMode.c_str());
1680 
1681  for (unsigned int a = 0; a < APVsCollOrdered.size(); a++) {
1683  if (APV == nullptr)
1684  continue;
1685  // printf( "%i | %i | PreviousGain = %7.5f NewGain = %7.5f (#clusters=%8.0f)\n", APV->DetId,APV->APVId,APV->PreviousGain,APV->Gain, APV->NEntries);
1686  fprintf(Gains,
1687  "%i | %i | PreviousGain = %7.5f(tick) x %7.5f(particle) NewGain (particle) = %7.5f (#clusters=%8.0f)\n",
1688  APV->DetId,
1689  APV->APVId,
1690  APV->PreviousGainTick,
1691  APV->PreviousGain,
1692  APV->Gain,
1693  APV->NEntries);
1694 
1695  tree_Index = APV->Index;
1696  tree_Bin = (Charge_Vs_Index[elepos])->getTH2S()->GetXaxis()->FindBin(APV->Index);
1697  tree_DetId = APV->DetId;
1698  tree_APVId = APV->APVId;
1699  tree_SubDet = APV->SubDet;
1700  tree_x = APV->x;
1701  tree_y = APV->y;
1702  tree_z = APV->z;
1703  tree_Eta = APV->Eta;
1704  tree_R = APV->R;
1705  tree_Phi = APV->Phi;
1706  tree_Thickness = APV->Thickness;
1707  tree_FitMPV = APV->FitMPV;
1708  tree_FitMPVErr = APV->FitMPVErr;
1709  tree_FitWidth = APV->FitWidth;
1710  tree_FitWidthErr = APV->FitWidthErr;
1711  tree_FitChi2NDF = APV->FitChi2;
1712  tree_FitNorm = APV->FitNorm;
1713  tree_Gain = APV->Gain;
1714  tree_PrevGain = APV->PreviousGain;
1715  tree_PrevGainTick = APV->PreviousGainTick;
1716  tree_NEntries = APV->NEntries;
1717  tree_isMasked = APV->isMasked;
1718 
1719  if (tree_DetId == 402673324) {
1720  printf("%i | %i : %f --> %f (%f)\n", tree_DetId, tree_APVId, tree_PrevGain, tree_Gain, tree_NEntries);
1721  }
1722 
1723  MyTree->Fill();
1724  }
1725  if (Gains)
1726  fclose(Gains);
1727 }
1728 
1730  // The goal of this function is to check wether or not there is enough statistics
1731  // to produce a meaningful tag for the DB
1732  int elepos = (AlgoMode == "PCL") ? Harvest : statCollectionFromMode(m_calibrationMode.c_str());
1733  if (Charge_Vs_Index[elepos] == nullptr) {
1734  edm::LogError("SiStripGainFromCalibTree")
1735  << "produceTagFilter -> Return false: could not retrieve the " << m_calibrationMode.c_str() << " statistics.\n"
1736  << "Please check if input contains " << m_calibrationMode.c_str() << " data." << std::endl;
1737  return false;
1738  }
1739 
1740  float integral = (Charge_Vs_Index[elepos])->getTH2S()->Integral();
1741  if ((Charge_Vs_Index[elepos])->getTH2S()->Integral(0, NStripAPVs + 1, 0, 99999) < tagCondition_NClusters) {
1742  edm::LogWarning("SiStripGainFromCalibTree")
1743  << "calibrationMode -> " << m_calibrationMode << "\n"
1744  << "produceTagFilter -> Return false: Statistics is too low : " << integral << endl;
1745  return false;
1746  }
1747  if ((1.0 * GOOD) / (GOOD + BAD) < tagCondition_GoodFrac) {
1748  edm::LogWarning("SiStripGainFromCalibTree")
1749  << "calibrationMode -> " << m_calibrationMode << "\n"
1750  << "produceTagFilter -> Return false: ratio of GOOD/TOTAL is too low: " << (1.0 * GOOD) / (GOOD + BAD) << endl;
1751  return false;
1752  }
1753  return true;
1754 }
1755 
1756 std::unique_ptr<SiStripApvGain> SiStripGainFromCalibTree::getNewObject() {
1757  auto obj = std::make_unique<SiStripApvGain>();
1758  if (!m_harvestingMode)
1759  return obj;
1760 
1761  if (!produceTagFilter()) {
1762  edm::LogWarning("SiStripGainFromCalibTree")
1763  << "getNewObject -> will not produce a paylaod because produceTagFilter returned false " << endl;
1764  setDoStore(false);
1765  return obj;
1766  }
1767 
1768  std::vector<float>* theSiStripVector = nullptr;
1769  unsigned int PreviousDetId = 0;
1770  for (unsigned int a = 0; a < APVsCollOrdered.size(); a++) {
1772  if (APV == nullptr) {
1773  printf("Bug\n");
1774  continue;
1775  }
1776  if (APV->SubDet <= 2)
1777  continue;
1778  if (APV->DetId != PreviousDetId) {
1779  if (theSiStripVector != nullptr) {
1780  SiStripApvGain::Range range(theSiStripVector->begin(), theSiStripVector->end());
1781  if (!obj->put(PreviousDetId, range))
1782  printf("Bug to put detId = %i\n", PreviousDetId);
1783  }
1784  theSiStripVector = new std::vector<float>;
1785  PreviousDetId = APV->DetId;
1786  }
1787  theSiStripVector->push_back(APV->Gain);
1788  }
1789  if (theSiStripVector != nullptr) {
1790  SiStripApvGain::Range range(theSiStripVector->begin(), theSiStripVector->end());
1791  if (!obj->put(PreviousDetId, range))
1792  printf("Bug to put detId = %i\n", PreviousDetId);
1793  }
1794 
1795  if (theSiStripVector != nullptr)
1796  delete theSiStripVector;
1797 
1798  return obj;
1799 }
1800 
1802  APVsColl.clear();
1803  for (unsigned int a = 0; a < APVsCollOrdered.size(); a++) {
1805  if (APV != nullptr)
1806  delete APV;
1807  }
1808  APVsCollOrdered.clear();
1809 }
1810 
1812  if (!useCalibration)
1813  return;
1814 
1815  TChain* t1 = new TChain("SiStripCalib/APVGain");
1816  t1->Add(m_calibrationPath.c_str());
1817 
1818  unsigned int tree_DetId;
1819  unsigned char tree_APVId;
1820  double tree_Gain;
1821 
1822  t1->SetBranchAddress("DetId", &tree_DetId);
1823  t1->SetBranchAddress("APVId", &tree_APVId);
1824  t1->SetBranchAddress("Gain", &tree_Gain);
1825 
1826  for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
1827  t1->GetEntry(ientry);
1828  stAPVGain* APV = APVsColl[(tree_DetId << 4) | (unsigned int)tree_APVId];
1829  APV->CalibGain = tree_Gain;
1830  }
1831 
1832  delete t1;
1833 }
1834 
1836  // in AlCaHarvesting mode we just need to run the logic in the endJob step
1837  if (m_harvestingMode)
1838  return;
1839 
1840  if (AlgoMode == "CalibTree")
1841  return;
1842 
1843  eventnumber = iEvent.id().event();
1844  runnumber = iEvent.id().run();
1845  auto handle01 = connect(TrigTech, TrigTech_token_, iEvent);
1846  auto handle02 = connect(trackchi2ndof, trackchi2ndof_token_, iEvent);
1847  auto handle03 = connect(trackp, trackp_token_, iEvent);
1848  auto handle04 = connect(trackpt, trackpt_token_, iEvent);
1849  auto handle05 = connect(tracketa, tracketa_token_, iEvent);
1850  auto handle06 = connect(trackphi, trackphi_token_, iEvent);
1851  auto handle07 = connect(trackhitsvalid, trackhitsvalid_token_, iEvent);
1852  auto handle08 = connect(trackindex, trackindex_token_, iEvent);
1853  auto handle09 = connect(rawid, rawid_token_, iEvent);
1854  auto handle11 = connect(localdirx, localdirx_token_, iEvent);
1855  auto handle12 = connect(localdiry, localdiry_token_, iEvent);
1856  auto handle13 = connect(localdirz, localdirz_token_, iEvent);
1857  auto handle14 = connect(firststrip, firststrip_token_, iEvent);
1858  auto handle15 = connect(nstrips, nstrips_token_, iEvent);
1859  auto handle16 = connect(saturation, saturation_token_, iEvent);
1860  auto handle17 = connect(overlapping, overlapping_token_, iEvent);
1861  auto handle18 = connect(farfromedge, farfromedge_token_, iEvent);
1862  auto handle19 = connect(charge, charge_token_, iEvent);
1863  auto handle21 = connect(path, path_token_, iEvent);
1864  auto handle22 = connect(chargeoverpath, chargeoverpath_token_, iEvent);
1865  auto handle23 = connect(amplitude, amplitude_token_, iEvent);
1866  auto handle24 = connect(gainused, gainused_token_, iEvent);
1867  auto handle25 = connect(gainusedTick, gainusedTick_token_, iEvent);
1868  auto handle26 = connect(trackalgo, trackalgo_token_, iEvent);
1869 
1870  processEvent();
1871 }
1872 
RunNumber_t run() const
Definition: EventID.h:38
bool IsApvBad(const uint32_t &detid, const short &apvNb) const
edm::EDGetTokenT< std::vector< int > > trackindex_token_
std::vector< MonitorElement * > Charge_Vs_Index
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:40
static constexpr auto TEC
T getUntrackedParameter(std::string const &, T const &) const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
virtual int nrows() const =0
const std::vector< float > * trackp
edm::EDGetTokenT< std::vector< double > > tracketa_token_
edm::EDGetTokenT< std::vector< unsigned char > > amplitude_token_
std::vector< APVGain::APVmon > newCharge
const std::vector< double > * chargeoverpath
double FitMPV
Definition: APVGainStruct.h:20
MonitorElement * book2DD(char_string const &name, char_string const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1202
edm::EDGetTokenT< std::vector< unsigned int > > rawid_token_
const std::vector< unsigned char > * amplitude
bool isBFieldConsistentWithMode(const edm::EventSetup &iSetup) const
double PreviousGainTick
Definition: APVGainStruct.h:29
const std::vector< double > * localdirz
size_t getNumberOfTags() const
Definition: SiStripGain.h:95
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
const std::vector< double > * trackchi2ndof
void algoBeginRun(const edm::Run &run, const edm::EventSetup &iSetup) override
const std::vector< double > * localdirx
const std::vector< double > * gainusedTick
dispatcher processEvent(e, inputTag, standby)
unsigned int APVId
Definition: APVGainStruct.h:11
float Thickness
Definition: APVGainStruct.h:19
void algoEndRun(const edm::Run &run, const edm::EventSetup &iSetup) override
std::vector< MonitorElement * > FetchMonitor(std::vector< APVmon >, uint32_t, const TrackerTopology *topo=0)
const std::vector< unsigned int > * rawid
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
edm::EDGetTokenT< std::vector< bool > > overlapping_token_
dqm::legacy::MonitorElement MonitorElement
SiStripGainFromCalibTree(const edm::ParameterSet &)
const TrackerTopology * tTopo_
edm::Handle< T > connect(const T *&ptr, edm::EDGetTokenT< T > token, const edm::Event &evt)
int subdetectorPlane(uint32_t, const TrackerTopology *)
const std::vector< int > * trackalgo
std::vector< MonitorElement * > Charge_Vs_PathlengthTOB
void storeOnTree(TFileService *tfs)
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
const std::vector< float > * trackpt
std::vector< MonitorElement * > Charge_Vs_PathlengthTECM1
unsigned int DetId
Definition: APVGainStruct.h:10
const std::vector< unsigned int > * trackhitsvalid
std::vector< MonitorElement * > Charge_Vs_PathlengthTECM2
bool isMasked
Definition: APVGainStruct.h:33
static float getApvGain(const uint16_t &apv, const SiStripApvGain::Range &range)
Definition: SiStripGain.h:76
edm::EDGetTokenT< std::vector< bool > > farfromedge_token_
void Fill(long long x)
U second(std::pair< T, U > const &p)
edm::EDGetTokenT< std::vector< unsigned int > > trackhitsvalid_token_
char const * label
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
std::vector< stAPVGain * > APVsCollOrdered
MonitorElement * get(std::string const &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
Definition: DQMStore.cc:1509
edm::EDGetTokenT< std::vector< double > > path_token_
double FitWidth
Definition: APVGainStruct.h:22
int iEvent
Definition: GenABIO.cc:224
double Gain
Definition: APVGainStruct.h:26
edm::EDGetTokenT< std::vector< int > > trackalgo_token_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
double PreviousGain
Definition: APVGainStruct.h:28
edm::EDGetTokenT< std::vector< float > > trackp_token_
bool IsGoodLandauFit(double *FitResults)
std::unique_ptr< SiStripApvGain > getNewObject() override
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
std::unordered_map< unsigned int, stAPVGain * > APVsColl
unsigned int Index
Definition: APVGainStruct.h:8
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
Definition: tfile.py:1
double FitNorm
Definition: APVGainStruct.h:25
double CalibGain
Definition: APVGainStruct.h:27
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
void algoBeginJob(const edm::EventSetup &iSetup) override
std::pair< ContainerIterator, ContainerIterator > Range
edm::EDGetTokenT< std::vector< bool > > TrigTech_token_
edm::EDGetTokenT< std::vector< double > > chargeoverpath_token_
const std::complex< double > I
Definition: I.h:8
edm::EDGetTokenT< std::vector< double > > gainusedTick_token_
const std::vector< double > * gainused
double FitMPVErr
Definition: APVGainStruct.h:21
std::vector< MonitorElement * > Charge_Vs_PathlengthTECP1
edm::EDGetTokenT< std::vector< double > > localdirz_token_
static const std::string B
static constexpr auto TOB
const std::vector< unsigned short > * firststrip
std::vector< MonitorElement * > Charge_Vs_PathlengthTIDM
const std::vector< double > * localdiry
edm::EDGetTokenT< std::vector< unsigned int > > charge_token_
double p2[4]
Definition: TauolaWrapper.h:90
Integral< F, X >::type integral(const F &f)
Definition: Integral.h:70
def elem(elemtype, innerHTML='', html_class='', kwargs)
Definition: HTMLExport.py:19
double FitChi2
Definition: APVGainStruct.h:24
edm::EDGetTokenT< std::vector< unsigned short > > nstrips_token_
std::vector< MonitorElement * > Charge_Vs_PathlengthTECP2
const std::vector< int > * trackindex
Definition: DetId.h:17
int statCollectionFromMode(const char *tag) const
std::vector< MonitorElement * > Charge_Vs_PathlengthTIB
edm::EDGetTokenT< std::vector< unsigned short > > firststrip_token_
void algoAnalyze(const edm::Event &, const edm::EventSetup &) override
static constexpr auto TIB
edm::EDGetTokenT< std::vector< float > > trackpt_token_
T const * product() const
Definition: Handle.h:69
MonitorElement * book2S(char_string const &name, char_string const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2S histogram.
Definition: DQMStore.cc:1190
const std::vector< bool > * overlapping
const std::vector< bool > * saturation
virtual int nstrips() const =0
bool merge(LuminosityBlockRange &lh, LuminosityBlockRange &rh)
std::array< std::vector< APVGain::APVmon >, 7 > Charge_4
void getPeakOfLandau(TH1 *InputHisto, double *FitResults, double LowRange=50, double HighRange=5400)
int subdetectorSide(uint32_t, const TrackerTopology *)
double b
Definition: hdecay.h:118
double NEntries
Definition: APVGainStruct.h:30
const std::vector< bool > * farfromedge
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:639
float m_avg_current
Definition: RunInfo.h:28
const std::vector< bool > * TrigTech
void setDoStore(const bool doStore)
When set to false the payload will not be written to the db.
edm::EventID id() const
Definition: EventBase.h:59
fixed size matrix
HLT enums.
virtual int ncolumns() const =0
double p1[4]
Definition: TauolaWrapper.h:89
double a
Definition: hdecay.h:119
T get() const
Definition: EventSetup.h:73
std::vector< std::string > VChargeHisto
edm::EDGetTokenT< std::vector< double > > localdirx_token_
edm::EDGetTokenT< std::vector< bool > > saturation_token_
edm::EDGetTokenT< std::vector< double > > trackchi2ndof_token_
std::vector< MonitorElement * > Charge_Vs_PathlengthTIDP
edm::EDGetTokenT< std::vector< double > > localdiry_token_
Definition: tree.py:1
std::array< std::vector< APVGain::APVmon >, 7 > Charge_3
const std::vector< unsigned int > * charge
std::vector< std::pair< std::string, std::string > > monHnames(std::vector< std::string >, bool, const char *tag)
bool isValid() const
Definition: ESHandle.h:44
std::array< std::vector< APVGain::APVmon >, 7 > Charge_1
const std::vector< double > * path
long double T
const std::vector< double > * trackphi
unsigned int SubDet
Definition: APVGainStruct.h:12
static constexpr auto TID
const std::vector< unsigned short > * nstrips
T const * product() const
Definition: ESHandle.h:86
edm::EDGetTokenT< std::vector< double > > gainused_token_
MonitorElement * book1DD(char_string const &name, char_string const &title, int nchX, double lowX, double highX)
Book 1S histogram.
Definition: DQMStore.cc:1133
std::array< std::vector< APVGain::APVmon >, 7 > Charge_2
int subdetectorId(uint32_t)
void bookDQMHistos(const char *dqm_dir, const char *tag)
edm::EDGetTokenT< std::vector< double > > trackphi_token_
const std::vector< double > * tracketa
Definition: Run.h:45
double FitWidthErr
Definition: APVGainStruct.h:23
const SiStripApvGain::Range getRange(uint32_t detID) const
Definition: SiStripGain.h:71
def exit(msg="")