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::EDProducer< edm::one::WatchRuns, edm::one::WatchLuminosityBlocks, edm::one::SharedResources, edm::EndLuminosityBlockProducer > edm::one::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 L1TOccupancyClient (const edm::ParameterSet &ps)
 Constructor. More...
 
virtual ~L1TOccupancyClient ()
 Destructor. More...
 
- Public Member Functions inherited from DQMEDHarvester
virtual void beginLuminosityBlock (edm::LuminosityBlock const &, edm::EventSetup const &) override final
 
virtual void beginRun (edm::Run const &, edm::EventSetup const &) override
 
 DQMEDHarvester (void)
 
virtual void dqmEndLuminosityBlock (DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &)
 
virtual void endJob () override final
 
virtual void endLuminosityBlock (edm::LuminosityBlock const &, edm::EventSetup const &) override final
 
virtual void endRun (edm::Run const &, edm::EventSetup const &) override
 
virtual void produce (edm::Event &, edm::EventSetup const &) override final
 
virtual ~DQMEDHarvester ()=default
 
- Public Member Functions inherited from edm::one::EDProducer< edm::one::WatchRuns, edm::one::WatchLuminosityBlocks, edm::one::SharedResources, edm::EndLuminosityBlockProducer >
 EDProducer ()=default
 
- Public Member Functions inherited from edm::one::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, std::unordered_multimap< std::string, edm::ProductResolverIndex > const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 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 & itemsToGetFrom (BranchType iType) 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::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::one::EDProducerBase
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 30 of file L1TOccupancyClient.cc.

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

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

Destructor.

Definition at line 45 of file L1TOccupancyClient.cc.

References gather_cfg::cout.

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

Member Function Documentation

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

Definition at line 56 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.

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

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

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

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

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

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

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

References DEFINE_FWK_MODULE, and x().

832  {
833 
834  int nBinsX = iHist->GetNbinsX(); //actual number of bins x
835  int nBinsY = iHist->GetNbinsY(); //actual number of bins y
836 
837  if(iAxis==1){
838  int global = iHist->GetXaxis()->FindFixBin(iValue);
839 
840  // If parameter exceeds axis' value: set to maximum number of bins in x-axis
841  if(global > nBinsX*nBinsY) {global = iHist->GetXaxis()->GetLast();}
842 
843  // Get coordinates of bin
844  int y,z;
845  iHist->GetBinXYZ(global,oBinCoordinate,y,z);
846  }
847  else if(iAxis==2){
848  int global = iHist->GetYaxis()->FindFixBin(iValue);
849 
850  // If parameter exceeds axis' value: set to maximum number of bins in x-axis
851  if(global > nBinsX*nBinsY) {global = iHist->GetYaxis()->GetLast();}
852 
853  // Get coordinates of bin
854  int x,z;
855  iHist->GetBinXYZ(global,x,oBinCoordinate,z);
856  }
857 }
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 644 of file L1TOccupancyClient.cc.

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

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

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

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