CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
L1TOccupancyClient Class Reference

#include <L1TOccupancyClient.h>

Inheritance diagram for L1TOccupancyClient:
DQMEDHarvester edm::one::EDAnalyzer< edm::one::WatchRuns, edm::one::WatchLuminosityBlocks, edm::one::SharedResources > edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Member Functions

 L1TOccupancyClient (const edm::ParameterSet &ps)
 Constructor. More...
 
virtual ~L1TOccupancyClient ()
 Destructor. More...
 
- Public Member Functions inherited from DQMEDHarvester
virtual void analyze (edm::Event const &, edm::EventSetup const &) final
 
virtual void beginLuminosityBlock (edm::LuminosityBlock const &, edm::EventSetup const &) final
 
virtual void beginRun (edm::Run const &, edm::EventSetup const &)
 
 DQMEDHarvester (void)
 
virtual void dqmEndLuminosityBlock (DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &)
 
virtual void endJob () final
 
virtual void endLuminosityBlock (edm::LuminosityBlock const &, edm::EventSetup const &) final
 
virtual void endRun (edm::Run const &, edm::EventSetup const &)
 
- Public Member Functions inherited from edm::one::EDAnalyzer< edm::one::WatchRuns, edm::one::WatchLuminosityBlocks, edm::one::SharedResources >
 EDAnalyzer ()=default
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDAnalyzerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Protected Member Functions

void book (DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
 
void dqmEndJob (DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter) override
 
void dqmEndLuminosityBlock (DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
 
double xySymmetry (const edm::ParameterSet &ps, std::string test_name, std::vector< std::pair< int, double > > &deadChannels, std::vector< std::pair< int, double > > &statDev, bool &enoughStats)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Private Member Functions

int compareWithStrip (TH2F *histo, std::string test, int binStrip, int nBins, int axis, double avg, const edm::ParameterSet &ps, std::vector< std::pair< int, double > > &deadChannels)
 
double getAvrg (TH2F *h2f, std::string test, int axis, int nBins, int binStrip, int avrgMode)
 
void getBinCoordinateOnAxisWithValue (TH2F *h2f, double content, int &coord, int axis)
 
void printDeadChannels (const std::vector< std::pair< int, double > > &deadChannels, TH2F *h2f, const std::vector< std::pair< int, double > > &statDev, std::string test_name)
 

Private Attributes

TFile * file_
 
L1TOccupancyClientHistogramServicehservice_
 
std::map< std::string, MonitorElement * > meCertification
 
std::map< std::string, MonitorElement * > meDifferential
 
std::map< std::string, MonitorElement * > meResults
 
std::vector< edm::ParameterSet * > mValidTests
 
edm::ParameterSet parameters_
 
std::vector< edm::ParameterSettests_
 
bool verbose_
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Detailed Description

Definition at line 30 of file L1TOccupancyClient.h.

Constructor & Destructor Documentation

L1TOccupancyClient::L1TOccupancyClient ( const edm::ParameterSet ps)

Constructor.

Definition at line 31 of file L1TOccupancyClient.cc.

References gather_cfg::cout, and edm::ParameterSet::getParameter().

31  {
32 
33 
34  // Get parameters
35  parameters_ = ps;
36  verbose_ = ps.getParameter<bool> ("verbose");
37  tests_ = ps.getParameter<std::vector<ParameterSet> >("testParams");
38 
39  if(verbose_){cout << "[L1TOccupancyClient:] Called constructor" << endl;}
40 }
T getParameter(std::string const &) const
edm::ParameterSet parameters_
std::vector< edm::ParameterSet > tests_
L1TOccupancyClient::~L1TOccupancyClient ( )
virtual

Destructor.

Definition at line 46 of file L1TOccupancyClient.cc.

References gather_cfg::cout.

46  {
47  if(verbose_){cout << "[L1TOccupancyClient:] Called destructor" << endl;}
48 }

Member Function Documentation

void L1TOccupancyClient::book ( DQMStore::IBooker ibooker,
DQMStore::IGetter igetter 
)
protected

Definition at line 57 of file L1TOccupancyClient.cc.

References DQMStore::IBooker::book1D(), DQMStore::IBooker::book2D(), gather_cfg::cout, edm::ParameterSet::getParameter(), funct::m, MonitorElement::Reset(), DQMStore::IBooker::setCurrentFolder(), MonitorElement::setTitle(), and fftjetcommon_cfi::title.

57  {
58 
60 
61  if(verbose_){
62  cout << "[L1TOccupancyClient:] Called beginRun" << endl;
63 
64  // In verbose mode we will produce an extra output file with several tests
65  file_ = TFile::Open("DQM_L1TOccupancyClient_Snapshots_LS.root","RECREATE");
66  }
67 
68  ibooker.setCurrentFolder("L1T/L1TOccupancy/");
69  //dbe_->setCurrentFolder("L1T/L1TOccupancy/Results");
70  //dbe_->setCurrentFolder("L1T/L1TOccupancy/BadCellValues");
71  //dbe_->setCurrentFolder("L1T/L1TOccupancy/Certification");
72 
73  // Loop over all tests in defined
74  for (vector<ParameterSet>::iterator it = tests_.begin(); it != tests_.end(); it++) {
75 
76  // If the test algorithm is XYSymmetry we create the necessary histograms
77  if((*it).getUntrackedParameter<string>("algoName","XYSymmetry")=="XYSymmetry") {
78 
79  // Getting Parameters for the test
80  string testName = (*it).getParameter<string> ("testName");
81  ParameterSet algoParameters = (*it).getParameter<ParameterSet> ("algoParams");
82  string histPath = algoParameters.getParameter<string>("histPath");
83 
84  if(verbose_){
85  cout << "[L1TOccupancyClient:] Monitored histogram path: " << histPath << endl;
86 
87  // Creating verbose file directory structure
88  // test_name/test_name_Results,
89  // test_name/test_name_Histos
90  // TDirectory *td = file_->mkdir(testName.c_str() ,testName.c_str());
91  //FIXME: sub never used gcc361 warning
92  //TDirectory *sub = td ->mkdir((testName+"_Results").c_str(),string("_Results").c_str());
93 
94  //sub = td->mkdir((testName+"_Histos").c_str() ,(testName+"_Histos").c_str());
95  //sub = td->mkdir((testName+"_Histos_AllLS").c_str(),(testName+"_Histos_AllLS").c_str());
96  }
97 
98  // Load histograms in service instance
99  if(hservice_->loadHisto(igetter, testName,histPath)){
100 
101 
102 
103  // Mask channels specified in python file
104  hservice_->setMaskedBins(testName,algoParameters.getParameter<vector<ParameterSet> >("maskedAreas"));
105 
106  // Book MonitorElements
107  // * Test results
108  ibooker.setCurrentFolder("L1T/L1TOccupancy/Results");
109  string title = testName;
110  MonitorElement* m = ibooker.book2D(title.c_str(),hservice_->getDifferentialHistogram(testName));
111  m->setTitle(title.c_str());
112  m->Reset();
113  meResults[title] = m;
114 
115  // * Which cells are masked as bad
116  ibooker.setCurrentFolder("L1T/L1TOccupancy/HistogramDiff");
117  title = testName;
118  m = ibooker.book2D(title.c_str(),hservice_->getDifferentialHistogram(testName));
119  m->Reset();
120  m->setTitle(title.c_str());
122 
123  // * Fraction of bad cells
124  ibooker.setCurrentFolder("L1T/L1TOccupancy/Certification");
125  title = testName;
126  m = ibooker.book1D(title.c_str(),title.c_str(),2500,-.5,2500.-.5);
127  m->setTitle(title.c_str());
129 
130  mValidTests.push_back(&(*it));
131 
132  }
133 
134  }
135  }
136 }
std::map< std::string, MonitorElement * > meResults
T getParameter(std::string const &) const
TH2F * loadHisto(DQMStore::IGetter &igetter, std::string test, std::string histo)
std::map< std::string, MonitorElement * > meCertification
void setMaskedBins(std::string test, const std::vector< edm::ParameterSet > &mask)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
void setTitle(const std::string &title)
set (ie. change) histogram/profile title
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
std::map< std::string, MonitorElement * > meDifferential
edm::ParameterSet parameters_
std::vector< edm::ParameterSet * > mValidTests
void Reset(void)
reset ME (ie. contents, errors, etc)
std::vector< edm::ParameterSet > tests_
L1TOccupancyClientHistogramService * hservice_
int L1TOccupancyClient::compareWithStrip ( TH2F *  histo,
std::string  test,
int  binStrip,
int  nBins,
int  axis,
double  avg,
const edm::ParameterSet ps,
std::vector< std::pair< int, double > > &  deadChannels 
)
private

Definition at line 697 of file L1TOccupancyClient.cc.

References funct::abs(), gather_cfg::cout, MillePedeFileConverter_cfg::e, edm::ParameterSet::getUntrackedParameter(), mps_fire::i, and infinity.

697  {
698 
699  int dead = 0;
700 
701  //
702  if(iAxis==1) {
703 
704  // Get and set parameters for working curves
705  TF1* fmuup = new TF1("fmuup" ,"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))",-10000.,10000.);
706  TF1* fmulow = new TF1("fmulow","TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))",-10000.,10000.);
707  fmuup ->SetParameter(0,iAvg*iPS.getUntrackedParameter<double>("factorup",2.0));
708  fmuup ->SetParameter(1,iAvg);
709  fmulow->SetParameter(0,iAvg*iPS.getUntrackedParameter<double>("factorlow",0.1));
710  fmulow->SetParameter(1,iAvg);
711 
712  TF1* fchi = new TF1("fchi","[0]*x**2+[1]*x+[2]",0.,1500.);
713 
714  // Evaluate sigma up
715  vector<double> defaultChi2up;
716  defaultChi2up.push_back(5.45058e-05);
717  defaultChi2up.push_back(0.268756);
718  defaultChi2up.push_back(-11.7515);
719 
720  vector<double> params = iPS.getUntrackedParameter< vector<double> >("params_chi2_up",defaultChi2up);
721  for(unsigned int i=0; i<params.size(); i++){fchi->SetParameter(i,params[i]);}
722  double sigma_up = fchi->Eval(iAvg);
723 
724  // Evaluate sigma low
725  vector<double> defaultChi2low;
726  defaultChi2low.push_back(4.11095e-05);
727  defaultChi2low.push_back(0.577451);
728  defaultChi2low.push_back(-10.378);
729 
730  params = iPS.getUntrackedParameter< vector<double> >("params_chi2_low",defaultChi2low);
731  for(unsigned int i=0; i<params.size(); i++){fchi->SetParameter(i,params[i]);}
732  double sigma_low = fchi->Eval(iAvg);
733 
734  if(verbose_){cout << "binstrip= " << iBinStrip << ", sigmaup= " << sigma_up << ", sigmalow= " << sigma_low << endl;}
735 
736  for(int i=1;i<=iNBins;i++) {
737  if(verbose_) {
738  cout << " " << i << " binContent: up:" << fmuup ->Eval(iHist->GetBinContent(iBinStrip,i))
739  << " low: " << fmulow->Eval(iHist->GetBinContent(iBinStrip,i)) << endl;
740  }
741 
742  // Evaluate chi2 for cells
743  double muup = fmuup ->Eval(iHist->GetBinContent(iBinStrip,i));
744  double mulow = fmulow->Eval(iHist->GetBinContent(iBinStrip,i));
745 
746  // If channel is masked -> set it to value -1
747  if(hservice_->isMasked(iTestName,iBinStrip,i)) {
748  oChannels.push_back(pair<int,double>(iHist->GetBin(iBinStrip,i),-1.0));
749  }
750  //else perform test
751  else if(muup > sigma_up ||
752  mulow > sigma_low ||
753  ((fabs(muup) == std::numeric_limits<double>::infinity()) && (
754  fabs(mulow) == std::numeric_limits<double>::infinity()))) {
755  dead++;
756  oChannels.push_back(pair<int,double>(iHist->GetBin(iBinStrip,i),abs(iHist->GetBinContent(iBinStrip,i)-iAvg)/iAvg));
757  }
758  }
759  }
760  //
761  else if(iAxis==2){
762 
763  //get and set parameters for working curves
764  TF1* fmuup = new TF1("fmuup" ,"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))",-10000.,10000.);
765  TF1* fmulow = new TF1("fmulow","TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))",-10000.,10000.);
766  fmuup ->SetParameter(0,iAvg*iPS.getUntrackedParameter<double>("factorup",2.0));
767  fmuup ->SetParameter(1,iAvg);
768  fmulow->SetParameter(0,iAvg*iPS.getUntrackedParameter<double>("factorlow",0.1));
769  fmulow->SetParameter(1,iAvg);
770 
771  TF1* fchi = new TF1("fchi","[0]*x**2+[1]*x+[2]",0.,1500.);
772 
773  // Evaluate sigma up
774  vector<double> defaultChi2up;
775  defaultChi2up.push_back(5.45058e-05);
776  defaultChi2up.push_back(0.268756);
777  defaultChi2up.push_back(-11.7515);
778 
779  vector<double> params = iPS.getUntrackedParameter<vector<double> >("params_chi2_up",defaultChi2up);
780  for(unsigned int i=0;i<params.size();i++){fchi->SetParameter(i,params[i]);}
781  double sigma_up = fchi->Eval(iAvg);
782 
783  // Evaluate sigma low
784  vector<double> defaultChi2low;
785  defaultChi2low.push_back(4.11095e-05);
786  defaultChi2low.push_back(0.577451);
787  defaultChi2low.push_back(-10.378);
788 
789  params = iPS.getUntrackedParameter<vector<double> >("params_chi2_low",defaultChi2low);
790  for(unsigned int i=0;i<params.size();i++){fchi->SetParameter(i,params[i]);}
791  double sigma_low = fchi->Eval(iAvg);
792 
793  if(verbose_) {cout << "binstrip= " << iBinStrip << ", sigmaup= " << sigma_up << ", sigmalow= " << sigma_low << endl;}
794 
795  for(int i=1;i<=iNBins;i++) {
796  if(verbose_) {
797  cout << " " << i << " binContent: up:" << fmuup ->Eval(iHist->GetBinContent(i,iBinStrip))
798  << " low: " << fmulow->Eval(iHist->GetBinContent(i,iBinStrip)) << endl;
799  }
800 
801  //evaluate chi2 for cells
802  double muup = fmuup ->Eval(iHist->GetBinContent(i,iBinStrip));
803  double mulow = fmulow->Eval(iHist->GetBinContent(i,iBinStrip));
804 
805  //if channel is masked -> set it to value -1
806  if(hservice_->isMasked(iTestName,i,iBinStrip)) {
807  oChannels.push_back(pair<int,double>(iHist->GetBin(iBinStrip,i),-1.0));
808  }
809  //else perform test
810  else if(muup > sigma_up ||
811  mulow > sigma_low ||
812  ((fabs(muup) == std::numeric_limits<double>::infinity()) &&
813  (fabs(mulow) == std::numeric_limits<double>::infinity()))) {
814  dead++;
815  oChannels.push_back(pair<int,double>(iHist->GetBin(i,iBinStrip),abs(iHist->GetBinContent(i,iBinStrip)-iAvg)/iAvg));
816  }
817  }
818  }
819  else {if(verbose_) {cout << "invalid axis" << endl;}}
820 
821  return dead;
822 }
const double infinity
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool isMasked(std::string test, int x, int y)
L1TOccupancyClientHistogramService * hservice_
void L1TOccupancyClient::dqmEndJob ( DQMStore::IBooker ibooker,
DQMStore::IGetter igetter 
)
overrideprotectedvirtual

Implements DQMEDHarvester.

Definition at line 145 of file L1TOccupancyClient.cc.

References CSCSegmentAlgorithmDF_cfi::algo_name, stringResolutionProvider_cfi::bin, gather_cfg::cout, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), mps_fire::i, and harvestTrackValidationPlots::str.

145  {
146 
147  book(ibooker, igetter);
148 
149  if(verbose_){cout << "[L1TOccupancyClient:] Called endRun()" << endl;}
150 
151  // Loop over every test in python
152  for (std::vector<ParameterSet*>::iterator it = mValidTests.begin(); it != mValidTests.end(); it++) {
153 
154  ParameterSet &test = (**it);
155  string algo_name = test.getUntrackedParameter<string>("algoName","XYSymmetry");
156  string test_name = test.getParameter <string>("testName");
157 
158  if(verbose_) {cout << "[L1TOccupancyClient:] Starting calculations for: " << algo_name << " on: " << test_name << endl;}
159 
160  if(algo_name == "XYSymmetry") {
161 
162  ParameterSet ps = (**it).getParameter<ParameterSet>("algoParams");
163  string histPath = ps.getParameter<string>("histPath");
164 
165  vector<pair<int,double> > deadChannels;
166  vector<pair<int,double> > statDev;
167  bool enoughStats = false;
168 
169  // Make final block
170  hservice_->updateHistogramEndRun(test_name);
171 
172  // Perform the test
173  double dead = xySymmetry(ps,test_name,deadChannels,statDev,enoughStats);
174  stringstream str;
175  str << test_name << "_cumu_LS_EndRun";
176 
177  if(verbose_) {
178  TH2F* cumulative_save = (TH2F*) hservice_->getDifferentialHistogram(test_name)->Clone(str.str().c_str());
179 
180  cumulative_save->SetTitle(str.str().c_str());
181 
182  TDirectory* td = file_->GetDirectory(test_name.c_str());
183 
184  td->cd(string(test_name+"_Histos_AllLS").c_str());
185 
186  cumulative_save->Write();
187  }
188  // If we have enough statistics, we can write test result
189  if(enoughStats) {
190 
191  // Make the result histogram
192  printDeadChannels(deadChannels,meResults[test_name]->getTH2F(),statDev,test_name);
193 
194  if(verbose_) {
195  TH2F* cumulative_save = (TH2F*) hservice_->getDifferentialHistogram(test_name)->Clone(str.str().c_str());
196  cumulative_save->SetTitle(str.str().c_str());
197  TDirectory* td = file_->GetDirectory(("DQM_L1TOccupancyClient_Snapshots_LS.root:/"+test_name).c_str());
198  td->cd(string(test_name+"_Histos").c_str());
199  cumulative_save->Write();
200 
201  // save the result histo
202  TH2F* h2f = meResults[test_name]->getTH2F();
203  stringstream str2;
204  str2 << test_name << "_result_LS_EndRun";
205  TH2F* dead_save = (TH2F*) h2f->Clone(str2.str().c_str());
206 
207  td->cd(string(test_name+"_Results").c_str());
208  dead_save->SetTitle(str2.str().c_str());
209  dead_save->Write();
210  }
211 
212  // Updating test results
213  meDifferential[test_name]->Reset();
214  meDifferential[test_name]->getTH2F()->Add(hservice_->getDifferentialHistogram(test_name));
215 
216  vector<int> lsCertification = hservice_->getLSCertification(test_name);
217 
218  // Fill fraction of dead channels
219  for(unsigned int i=0;i<lsCertification.size();i++){
220  int bin = meCertification[test_name]->getTH1()->FindBin(lsCertification[i]);
221  meCertification[test_name]->getTH1()->SetBinContent(bin,1-dead);
222  }
223 
224  // Reset differential histo
225  hservice_->resetHisto(test_name);
226 
227  if(verbose_) {cout << "Now we have enough statstics for " << test_name << endl;}
228 
229  }else{
230  if(verbose_){cout << "we don't have enough statstics for " << test_name << endl;}
231 
232  // Getting LS which this test monitored
233  vector<int> lsCertification = hservice_->getLSCertification(test_name);
234 
235  // Fill fraction of dead channels
236  for(unsigned int i=0;i<lsCertification.size();i++){
237  int bin = meCertification[test_name]->getTH1()->FindBin(lsCertification[i]);
238  meCertification[test_name]->getTH1()->SetBinContent(bin,-1);
239  }
240  }
241  }else {if(verbose_){cout << "No valid algorithm" << std::endl;}}
242  }
243 
244  if(verbose_){file_->Close();}
245 
246  delete hservice_;
247 
248 }
std::map< std::string, MonitorElement * > meResults
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< int > getLSCertification(std::string iHistName)
void printDeadChannels(const std::vector< std::pair< int, double > > &deadChannels, TH2F *h2f, const std::vector< std::pair< int, double > > &statDev, std::string test_name)
std::map< std::string, MonitorElement * > meCertification
double xySymmetry(const edm::ParameterSet &ps, std::string test_name, std::vector< std::pair< int, double > > &deadChannels, std::vector< std::pair< int, double > > &statDev, bool &enoughStats)
void book(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
bin
set the eta bin as selection string.
std::map< std::string, MonitorElement * > meDifferential
std::vector< edm::ParameterSet * > mValidTests
L1TOccupancyClientHistogramService * hservice_
void L1TOccupancyClient::dqmEndLuminosityBlock ( DQMStore::IBooker ibooker,
DQMStore::IGetter igetter,
const edm::LuminosityBlock lumiSeg,
const edm::EventSetup c 
)
overrideprotected

Definition at line 265 of file L1TOccupancyClient.cc.

References CSCSegmentAlgorithmDF_cfi::algo_name, stringResolutionProvider_cfi::bin, gather_cfg::cout, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), mps_fire::i, edm::LuminosityBlockBase::id(), edm::LuminosityBlockID::luminosityBlock(), and harvestTrackValidationPlots::str.

265  {
266 
267  book(ibooker, igetter);
268 
269  int eventLS = lumiSeg.id().luminosityBlock();
270 
271  if(verbose_) {
272  cout << "[L1TOccupancyClient:] Called endLuminosityBlock()" << endl;
273  cout << "[L1TOccupancyClient:] Lumisection: " << eventLS << endl;
274  }
275 
276  // Loop over every test in python
277  for (std::vector<ParameterSet*>::const_iterator it = mValidTests.begin(); it != mValidTests.end(); it++) {
278 
279  ParameterSet &test = (**it);
280  string algo_name = test.getUntrackedParameter<string>("algoName","XYSymmetry");
281  string test_name = test.getParameter <string>("testName");
282 
283  if(verbose_) {cout << "[L1TOccupancyClient:] Starting calculations for " << algo_name << " on:" << test_name << endl;}
284 
285  if(algo_name == "XYSymmetry") {
286 
287  ParameterSet ps = (**it).getParameter<ParameterSet>("algoParams");
288  string histPath = ps.getParameter<string>("histPath");
289 
290  vector<pair<int,double> > deadChannels;
291  vector<pair<int,double> > statDev;
292  bool enoughStats = false;
293 
294  // Update histo's data with data of this LS
295  hservice_->updateHistogramEndLS(igetter, test_name,histPath,eventLS);
296 
297  // Perform the test
298  double dead = xySymmetry(ps,test_name,deadChannels,statDev,enoughStats);
299  stringstream str;
300  str << test_name << "_cumu_LS_" << eventLS;
301 
302  if(verbose_) {
303  TH2F* cumulative_save = (TH2F*) hservice_->getDifferentialHistogram(test_name)->Clone(str.str().c_str());
304  cumulative_save->SetTitle(str.str().c_str());
305  TDirectory* td = file_->GetDirectory(test_name.c_str());
306  td->cd(string(test_name+"_Histos_AllLS").c_str());
307  cumulative_save->Write();
308  }
309 
310  // If we have enough statistics, we can write test result
311  if(enoughStats) {
312 
313  // Make the result histogram
314  printDeadChannels(deadChannels,meResults[test_name]->getTH2F(),statDev,test_name);
315 
316  if(verbose_) {
317  TH2F* cumulative_save = (TH2F*) hservice_->getDifferentialHistogram(test_name)->Clone(str.str().c_str());
318  cumulative_save->SetTitle(str.str().c_str());
319  TDirectory* td = file_->GetDirectory(("DQM_L1TOccupancyClient_Snapshots_LS.root:/"+test_name).c_str());
320  td->cd(string(test_name+"_Histos").c_str());
321  cumulative_save->Write();
322 
323  // save the result histo
324  TH2F* h2f = meResults[test_name]->getTH2F();
325  stringstream str2;
326  str2 << test_name << "_result_LS_" << eventLS;
327  TH2F* dead_save = (TH2F*) h2f->Clone(str2.str().c_str());
328 
329  td->cd(string(test_name+"_Results").c_str());
330  dead_save->SetTitle(str2.str().c_str());
331  dead_save->Write();
332  }
333 
334  // Updating test results
335  meDifferential[test_name]->Reset();
336  meDifferential[test_name]->getTH2F()->Add(hservice_->getDifferentialHistogram(test_name));
337 
338  vector<int> lsCertification = hservice_->getLSCertification(test_name);
339 
340  // Fill fraction of dead channels
341  for(unsigned int i=0;i<lsCertification.size();i++){
342  int bin = meCertification[test_name]->getTH1()->FindBin(lsCertification[i]);
343  meCertification[test_name]->getTH1()->SetBinContent(bin,1-dead);
344  }
345 
346  // Reset differential histo
347  hservice_->resetHisto(test_name);
348 
349  if(verbose_) {cout << "Now we have enough statstics for " << test_name << endl;}
350 
351  }else{if(verbose_){cout << "we don't have enough statstics for " << test_name << endl;}}
352  }else {if(verbose_){cout << "No valid algorithm" << std::endl;}}
353  }
354 }
LuminosityBlockID id() const
std::map< std::string, MonitorElement * > meResults
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< int > getLSCertification(std::string iHistName)
void printDeadChannels(const std::vector< std::pair< int, double > > &deadChannels, TH2F *h2f, const std::vector< std::pair< int, double > > &statDev, std::string test_name)
std::map< std::string, MonitorElement * > meCertification
double xySymmetry(const edm::ParameterSet &ps, std::string test_name, std::vector< std::pair< int, double > > &deadChannels, std::vector< std::pair< int, double > > &statDev, bool &enoughStats)
void book(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
bin
set the eta bin as selection string.
LuminosityBlockNumber_t luminosityBlock() const
std::map< std::string, MonitorElement * > meDifferential
void updateHistogramEndLS(DQMStore::IGetter &igetter, std::string test, std::string histo, int iLS)
std::vector< edm::ParameterSet * > mValidTests
L1TOccupancyClientHistogramService * hservice_
double L1TOccupancyClient::getAvrg ( TH2F *  h2f,
std::string  test,
int  axis,
int  nBins,
int  binStrip,
int  avrgMode 
)
private

Definition at line 570 of file L1TOccupancyClient.cc.

References gather_cfg::cout, trackerHits::histo, mps_fire::i, NULL, and MuonErrorMatrixValues_cff::values.

570  {
571 
572  double avg = 0.0;
573  TH1D* proj = NULL;
574  TH2F* histo = new TH2F(*iHist);
575 
576  std::vector<double> values;
577  int marked;
578 
579  if(iAxis==1) {
580 
581  switch(iAvgMode) {
582 
583  // arithmetic average
584  case 1:
585  marked = hservice_->maskBins(iTestName,histo,iBinStrip,iAxis);
586  proj = histo->ProjectionX();
587  avg = proj->GetBinContent(iBinStrip)/(iNBins-marked);
588  break;
589 
590  // median
591  case 2:
592  marked = hservice_->maskBins(iTestName,histo,iBinStrip,iAxis);
593  proj = histo->ProjectionY("_py",iBinStrip,iBinStrip);
594  for(int i=0;i<iNBins;i++) {
595  values.push_back(proj->GetBinContent(i+1));
596  }
597  avg = TMath::Median(iNBins,&values[0]);
598  break;
599  default:
600  if(verbose_){cout << "Invalid averaging mode!" << endl;}
601  break;
602  }
603  }
604  else if(iAxis==2) {
605 
606  switch(iAvgMode) {
607  // arithmetic average
608  case 1:
609  marked = hservice_->maskBins(iTestName,histo,iBinStrip,iAxis);
610  proj = histo->ProjectionY();
611  avg = proj->GetBinContent(iBinStrip)/(iNBins-marked);
612  break;
613  // median
614  case 2:
615  marked = hservice_->maskBins(iTestName,histo,iBinStrip,iAxis);
616  proj = histo->ProjectionX("_px",iBinStrip,iBinStrip);
617  for(int i=0;i<iNBins;i++) {
618  values.push_back(proj->GetBinContent(i+1));
619  }
620 
621  avg = TMath::Median(iNBins,&values[0]);
622  break;
623  default:
624  if(verbose_) { cout << "invalid averaging mode!" << endl;}
625  break;
626  }
627  }
628  else {
629  if(verbose_) {cout << "invalid axis" << endl;}
630  }
631  delete proj;
632  delete histo;
633  return avg;
634 }
#define NULL
Definition: scimark2.h:8
int maskBins(std::string test, TH2F *histo, int strip, int axis)
L1TOccupancyClientHistogramService * hservice_
void L1TOccupancyClient::getBinCoordinateOnAxisWithValue ( TH2F *  h2f,
double  content,
int &  coord,
int  axis 
)
private

Definition at line 833 of file L1TOccupancyClient.cc.

References DEFINE_FWK_MODULE, and x().

833  {
834 
835  int nBinsX = iHist->GetNbinsX(); //actual number of bins x
836  int nBinsY = iHist->GetNbinsY(); //actual number of bins y
837 
838  if(iAxis==1){
839  int global = iHist->GetXaxis()->FindFixBin(iValue);
840 
841  // If parameter exceeds axis' value: set to maximum number of bins in x-axis
842  if(global > nBinsX*nBinsY) {global = iHist->GetXaxis()->GetLast();}
843 
844  // Get coordinates of bin
845  int y,z;
846  iHist->GetBinXYZ(global,oBinCoordinate,y,z);
847  }
848  else if(iAxis==2){
849  int global = iHist->GetYaxis()->FindFixBin(iValue);
850 
851  // If parameter exceeds axis' value: set to maximum number of bins in x-axis
852  if(global > nBinsX*nBinsY) {global = iHist->GetYaxis()->GetLast();}
853 
854  // Get coordinates of bin
855  int x,z;
856  iHist->GetBinXYZ(global,x,oBinCoordinate,z);
857  }
858 }
void L1TOccupancyClient::printDeadChannels ( const std::vector< std::pair< int, double > > &  deadChannels,
TH2F *  h2f,
const std::vector< std::pair< int, double > > &  statDev,
std::string  test_name 
)
private

Definition at line 645 of file L1TOccupancyClient.cc.

References stringResolutionProvider_cfi::bin, HiEvtPlane_cfi::chi2, gather_cfg::cout, and x().

645  {
646 
647  // Reset the dead channels histogram
648  oHistDeadChannels->Reset();
649  if(verbose_) {cout << "suspect or masked channels of " << iTestName << ": ";}
650 
651  int x,y,z;
652  float chi2 = 0.0;
653 
654  // put all bad (value=1) and masked (value=-1) cells in histo
655  for (std::vector<pair<int,double> >::const_iterator it = iDeadChannels.begin(); it != iDeadChannels.end(); it++) {
656 
657  int bin = (*it).first;
658  oHistDeadChannels->GetBinXYZ(bin,x,y,z);
659 
660  if(hservice_->isMasked(iTestName,x,y)){
661  oHistDeadChannels->SetBinContent(bin,-1);
662  if(verbose_){printf("(%4i,%4i) Masked\n",x,y);}
663  }
664  else{
665  oHistDeadChannels->SetBinContent(bin, 1);
666  if(verbose_){printf("(%4i,%4i) Failed test\n",x,y);}
667  }
668  }
669 
670  // FIXME: Is this needed?
671  for (std::vector<pair<int,double> >::const_iterator it = statDev.begin(); it != statDev.end(); it++) {
672  double dev = (*it).second;
673  chi2 += dev;
674  }
675  //put total chi2 in float
676 
677  if(verbose_) {
678  cout << "total number of suspect channels: " << (iDeadChannels.size()-(hservice_->getNBinsMasked(iTestName))) << endl;
679  }
680 }
bin
set the eta bin as selection string.
bool isMasked(std::string test, int x, int y)
L1TOccupancyClientHistogramService * hservice_
double L1TOccupancyClient::xySymmetry ( const edm::ParameterSet ps,
std::string  test_name,
std::vector< std::pair< int, double > > &  deadChannels,
std::vector< std::pair< int, double > > &  statDev,
bool &  enoughStats 
)
protected

Definition at line 377 of file L1TOccupancyClient.cc.

References gather_cfg::cout, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), mps_fire::i, createfilelist::int, gen::k, and Max().

381  {
382 
383  // Getting differential histogram for this this thes
384  TH2F* diffHist = hservice_->getDifferentialHistogram(iTestName);
385 
386  int pAxis = ps.getUntrackedParameter<int> ("axis",1);
387  int pAverageMode = ps.getUntrackedParameter<int> ("averageMode",2); // 1=arith. mean, 2=median
388  int nBinsX = diffHist->GetNbinsX(); // actual number of bins x
389  int nBinsY = diffHist->GetNbinsY(); // actual number of bins y
390 
391  // Axis==1 : Means symmetry axis is vertical
392  if(pAxis==1){
393 
394  int maxBinStrip, centralBinStrip; // x-coordinate of strips
395 
396  maxBinStrip = nBinsX;
397 
398  // If takeCenter=true determine central bin of the pAxis
399  // If takeCenter=false determine the bin to use based user input
400  if(ps.getUntrackedParameter<bool>("takeCenter",true)){centralBinStrip = nBinsX / 2 + 1;}
401  else {
402  double pAxisSymmetryValue = ps.getParameter <double>("axisSymmetryValue");
403  getBinCoordinateOnAxisWithValue(diffHist, pAxisSymmetryValue, centralBinStrip, 1);
404  }
405 
406  // Assuming odd number of strips --> first comparison is middle strip to itself
407  int upBinStrip = centralBinStrip;
408  int lowBinStrip = centralBinStrip;
409 
410  // If even number decrease lowBinstrip by one
411  if(nBinsX%2==0){lowBinStrip--;}
412 
413  // Do we have enough statistics? Min(Max(strip_i,strip_j))>threshold
414  std::unique_ptr<double[]> maxAvgs(new double[maxBinStrip-upBinStrip+1]);
415 
416  int nActualStrips=0; //number of strips that are not fully masked
417  for(int i=0, j=upBinStrip, k=lowBinStrip;j<=maxBinStrip;i++,j++,k--) {
418  double avg1 = getAvrg(diffHist,iTestName,pAxis,nBinsY,j,pAverageMode);
419  double avg2 = getAvrg(diffHist,iTestName,pAxis,nBinsY,k,pAverageMode);
420 
421  // Protection for when both strips are masked
422  if(!hservice_->isStripMasked(iTestName,j,pAxis) && !hservice_->isStripMasked(iTestName,k,pAxis)) {
423  maxAvgs[i] = TMath::Max(avg1,avg2);
424  nActualStrips++;
425  }
426  }
427 
428  vector<double> defaultMu0up;
429  defaultMu0up.push_back(13.7655);
430  defaultMu0up.push_back(184.742);
431  defaultMu0up.push_back(50735.3);
432  defaultMu0up.push_back(-97.6793);
433 
434  TF1 tf("myFunc","[0]*(TMath::Log(x*[1]+[2]))+[3]",10.,11000.);
435  vector<double> params = ps.getUntrackedParameter< vector<double> >("params_mu0_up",defaultMu0up);
436  for(unsigned int i=0;i<params.size();i++) {tf.SetParameter(i,params[i]);}
437  int statsup = (int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
438 
439  vector<double> defaultMu0low;
440  defaultMu0low.push_back(2.19664);
441  defaultMu0low.push_back(1.94546);
442  defaultMu0low.push_back(-99.3263);
443  defaultMu0low.push_back(19.388);
444 
445  params = ps.getUntrackedParameter<vector<double> >("params_mu0_low",defaultMu0low);
446  for(unsigned int i=0;i<params.size();i++) {tf.SetParameter(i,params[i]);}
447  int statslow = (int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
448 
449  if(verbose_) {
450  cout << "nbins: " << hservice_->getNBinsHistogram(iTestName) << endl;
451  cout << "statsup= " << statsup << ", statslow= " << statslow << endl;
452  }
453 
454  enoughStats = TMath::MinElement(nActualStrips,maxAvgs.get())>TMath::Max(statsup,statslow);
455  if(verbose_) {
456  cout << "stats: " << TMath::MinElement(nActualStrips,maxAvgs.get()) << ", statsAvg: " << diffHist->GetEntries()/hservice_->getNBinsHistogram(iTestName) << ", threshold: " << TMath::Max(statsup,statslow) << endl;
457  }
458 
459  //if enough statistics
460  //make the test
461  if(enoughStats) {
462  for(;upBinStrip<=maxBinStrip;upBinStrip++,lowBinStrip--) {
463  double avg = getAvrg(diffHist, iTestName, pAxis, nBinsY, upBinStrip, pAverageMode);
464  compareWithStrip(diffHist,iTestName,lowBinStrip,nBinsY,pAxis,avg,ps,deadChannels); //compare with lower side
465 
466  avg = getAvrg(diffHist, iTestName, pAxis, nBinsY, lowBinStrip, pAverageMode);
467  compareWithStrip(diffHist,iTestName,upBinStrip,nBinsY,pAxis,avg,ps,deadChannels); //compare with upper side
468  }
469  }
470  }
471 
472  // pAxis==2 : Means symetry pAxis is horizontal
473  else if(pAxis==2) {
474  int maxBinStrip, centralBinStrip; //x-coordinate of strips
475 
476  maxBinStrip = nBinsY;
477 
478  // Determine center of diagram: either with set pAxis or middle of diagram
479  if(ps.getUntrackedParameter<bool>("takeCenter",true)){centralBinStrip = nBinsY / 2 + 1;}
480  else {
481  double pAxisSymmetryValue = ps.getParameter<double>("axisSymmetryValue");
482  getBinCoordinateOnAxisWithValue(diffHist, pAxisSymmetryValue, centralBinStrip, 2);
483 
484  }
485 
486  //assuming odd number of strips --> first comparison is middle strip to itself
487  int lowBinStrip = centralBinStrip, upBinStrip = centralBinStrip;
488 
489  //if even number
490  if(nBinsX%2==0) {
491  //decrease lowBinstrip by one
492  lowBinStrip--;
493  }
494 
495  //do we have enough statistics? Min(Max(strip_i,strip_j))>threshold
496  std::unique_ptr<double[]> maxAvgs(new double[maxBinStrip-upBinStrip+1]);
497  int nActualStrips = 0;
498  for(int i=0, j=upBinStrip, k=lowBinStrip;j<=maxBinStrip;i++,j++,k--) {
499  double avg1 = getAvrg(diffHist, iTestName, pAxis, nBinsX, j, pAverageMode);
500  double avg2 = getAvrg(diffHist, iTestName, pAxis, nBinsX, k, pAverageMode);
501  if(!hservice_->isStripMasked(iTestName,j,pAxis) && !hservice_->isStripMasked(iTestName,k,pAxis)) {
502  maxAvgs[i] = TMath::Max(avg1,avg2);
503  nActualStrips++;
504  }
505  }
506 
507  vector<double> defaultMu0up;
508  defaultMu0up.push_back(13.7655);
509  defaultMu0up.push_back(184.742);
510  defaultMu0up.push_back(50735.3);
511  defaultMu0up.push_back(-97.6793);
512 
513  vector<double> params = ps.getUntrackedParameter<std::vector<double> >("params_mu0_up",defaultMu0up);
514  TF1 tf("myFunc","[0]*(TMath::Log(x*[1]+[2]))+[3]",10.,11000.);
515  for(unsigned int i=0;i<params.size();i++) {
516  tf.SetParameter(i,params[i]);
517  }
518  int statsup = (int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
519 
520  vector<double> defaultMu0low;
521  defaultMu0low.push_back(2.19664);
522  defaultMu0low.push_back(1.94546);
523  defaultMu0low.push_back(-99.3263);
524  defaultMu0low.push_back(19.388);
525 
526  params = ps.getUntrackedParameter<std::vector<double> >("params_mu0_low",defaultMu0low);
527  for(unsigned int i=0;i<params.size();i++) {
528  tf.SetParameter(i,params[i]);
529  }
530  int statslow = (int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
531  if(verbose_) {
532  cout << "statsup= " << statsup << ", statslow= " << statslow << endl;
533  }
534  enoughStats = TMath::MinElement(nActualStrips,maxAvgs.get())>TMath::Max(statsup,statslow);
535  if(verbose_) {
536  cout << "stats: " << TMath::MinElement(nActualStrips,maxAvgs.get()) << ", statsAvg: " << diffHist->GetEntries()/hservice_->getNBinsHistogram(iTestName) << ", threshold: " << TMath::Max(statsup,statslow) << endl;
537  }
538 
539  //if we have enough statistics
540  //make the test
541  if(enoughStats) {
542  for(;upBinStrip<=maxBinStrip;upBinStrip++,lowBinStrip--) {
543  double avg = getAvrg(diffHist, iTestName, pAxis, nBinsX, upBinStrip, pAverageMode);
544  compareWithStrip(diffHist,iTestName, lowBinStrip,nBinsX,pAxis,avg,ps,deadChannels); //compare with lower side
545 
546  avg = getAvrg(diffHist, iTestName, pAxis, nBinsX, lowBinStrip, pAverageMode);
547  compareWithStrip(diffHist,iTestName, upBinStrip,nBinsX,pAxis,avg,ps,deadChannels); //compare with upper side
548  }
549  }
550  }
551  else {if(verbose_){cout << "Invalid axis" << endl;}}
552 
553  return (deadChannels.size()-hservice_->getNBinsMasked(iTestName))*1.0/hservice_->getNBinsHistogram(iTestName);
554 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void getBinCoordinateOnAxisWithValue(TH2F *h2f, double content, int &coord, int axis)
double getAvrg(TH2F *h2f, std::string test, int axis, int nBins, int binStrip, int avrgMode)
bool isStripMasked(std::string test, int binStrip, int axis)
int k[5][pyjets_maxn]
T Max(T a, T b)
Definition: MathUtil.h:44
int compareWithStrip(TH2F *histo, std::string test, int binStrip, int nBins, int axis, double avg, const edm::ParameterSet &ps, std::vector< std::pair< int, double > > &deadChannels)
L1TOccupancyClientHistogramService * hservice_

Member Data Documentation

TFile* L1TOccupancyClient::file_
private

Definition at line 57 of file L1TOccupancyClient.h.

L1TOccupancyClientHistogramService* L1TOccupancyClient::hservice_
private

Definition at line 56 of file L1TOccupancyClient.h.

std::map<std::string,MonitorElement*> L1TOccupancyClient::meCertification
private

Definition at line 68 of file L1TOccupancyClient.h.

std::map<std::string,MonitorElement*> L1TOccupancyClient::meDifferential
private

Definition at line 67 of file L1TOccupancyClient.h.

std::map<std::string,MonitorElement*> L1TOccupancyClient::meResults
private

Definition at line 66 of file L1TOccupancyClient.h.

std::vector<edm::ParameterSet*> L1TOccupancyClient::mValidTests
private

Definition at line 64 of file L1TOccupancyClient.h.

edm::ParameterSet L1TOccupancyClient::parameters_
private
std::vector<edm::ParameterSet> L1TOccupancyClient::tests_
private

Definition at line 63 of file L1TOccupancyClient.h.

bool L1TOccupancyClient::verbose_
private

Definition at line 60 of file L1TOccupancyClient.h.