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