CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
HeavyFlavorHarvesting Class Reference
Inheritance diagram for HeavyFlavorHarvesting:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

virtual void analyze (const edm::Event &event, const edm::EventSetup &eventSetup) override
 
virtual void endRun (const edm::Run &, const edm::EventSetup &) override
 
 HeavyFlavorHarvesting (const edm::ParameterSet &pset)
 
virtual ~HeavyFlavorHarvesting ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

void calculateEfficiency (const ParameterSet &pset)
 
void calculateEfficiency1D (TH1 *num, TH1 *den, string name)
 
void calculateEfficiency2D (TH2F *num, TH2F *den, string name)
 

Private Attributes

DQMStoredqmStore
 
const VParameterSet efficiencies
 
string myDQMrootFolder
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- 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)
 

Detailed Description

Definition at line 26 of file HeavyFlavorHarvesting.cc.

Constructor & Destructor Documentation

HeavyFlavorHarvesting::HeavyFlavorHarvesting ( const edm::ParameterSet pset)

Definition at line 44 of file HeavyFlavorHarvesting.cc.

44  :
45  myDQMrootFolder( pset.getUntrackedParameter<string>("MyDQMrootFolder") ),
46  efficiencies( pset.getUntrackedParameter<VParameterSet>("Efficiencies") )
47 {
48 }
T getUntrackedParameter(std::string const &, T const &) const
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:33
const VParameterSet efficiencies
HeavyFlavorHarvesting::~HeavyFlavorHarvesting ( )
virtual

Definition at line 188 of file HeavyFlavorHarvesting.cc.

188  {
189 }

Member Function Documentation

virtual void HeavyFlavorHarvesting::analyze ( const edm::Event event,
const edm::EventSetup eventSetup 
)
inlineoverridevirtual

Implements edm::EDAnalyzer.

Definition at line 33 of file HeavyFlavorHarvesting.cc.

33 {};
void HeavyFlavorHarvesting::calculateEfficiency ( const ParameterSet pset)
private

Definition at line 61 of file HeavyFlavorHarvesting.cc.

References calculateEfficiency1D(), calculateEfficiency2D(), dqmStore, DQMStore::get(), MonitorElement::getTH1(), edm::ParameterSet::getUntrackedParameter(), LogDebug, myDQMrootFolder, pileupDistInMC::num, and DQMStore::setCurrentFolder().

Referenced by endRun().

61  {
62 //get hold of numerator and denominator histograms
63  vector<string> numDenEffMEnames = pset.getUntrackedParameter<vector<string> >("NumDenEffMEnames");
64  if(numDenEffMEnames.size()!=3){
65  LogDebug("HLTriggerOfflineHeavyFlavor") << "NumDenEffMEnames must have three names"<<endl;
66  return;
67  }
68  string denMEname = myDQMrootFolder+"/"+numDenEffMEnames[1];
69  string numMEname = myDQMrootFolder+"/"+numDenEffMEnames[0];
70  MonitorElement *denME = dqmStore->get(denMEname);
71  MonitorElement *numME = dqmStore->get(numMEname);
72  if(denME==0 || numME==0){
73  LogDebug("HLTriggerOfflineHeavyFlavor") << "Could not find MEs: "<<denMEname<<" or "<<numMEname<<endl;
74  return;
75  }
76  TH1 *den = denME->getTH1();
77  TH1 *num = numME->getTH1();
78  //check compatibility of the histograms
79  if( den->GetNbinsX() != num->GetNbinsX() || den->GetNbinsY() != num->GetNbinsY() || den->GetNbinsZ() != num->GetNbinsZ() ){
80  LogDebug("HLTriggerOfflineHeavyFlavor") << "Monitoring elements "<<numMEname<<" and "<<denMEname<<"are incompatible"<<endl;
81  return;
82  }
83  //figure out the directory and efficiency name
84  string effName = numDenEffMEnames[2];
85  string effDir = myDQMrootFolder;
86  string::size_type slashPos = effName.rfind('/');
87  if ( string::npos != slashPos ) {
88  effDir += "/"+effName.substr(0, slashPos);
89  effName.erase(0, slashPos+1);
90  }
91  dqmStore->setCurrentFolder(effDir);
92  //calculate the efficiencies
93  int dimensions = num->GetDimension();
94  if(dimensions==1){
95  calculateEfficiency1D( num, den, effName );
96  }else if(dimensions==2){
97  calculateEfficiency2D( (TH2F*)num, (TH2F*)den, effName );
98  TH1D* numX = ((TH2F*)num)->ProjectionX();
99  TH1D* denX = ((TH2F*)den)->ProjectionX();
100  calculateEfficiency1D( numX, denX, effName+"X" );
101  delete numX;
102  delete denX;
103  TH1D* numY = ((TH2F*)num)->ProjectionY();
104  TH1D* denY = ((TH2F*)den)->ProjectionY();
105  calculateEfficiency1D( numY, denY, effName+"Y" );
106  delete numY;
107  delete denY;
108  }else{
109  return;
110  }
111 }
#define LogDebug(id)
T getUntrackedParameter(std::string const &, T const &) const
void calculateEfficiency2D(TH2F *num, TH2F *den, string name)
void calculateEfficiency1D(TH1 *num, TH1 *den, string name)
uint16_t size_type
TH1 * getTH1(void) const
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1624
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:585
void HeavyFlavorHarvesting::calculateEfficiency1D ( TH1 *  num,
TH1 *  den,
string  name 
)
private

Definition at line 113 of file HeavyFlavorHarvesting.cc.

References DQMStore::bookProfile(), dqmStore, alignCSCRings::e, i, and mathSSE::sqrt().

Referenced by calculateEfficiency().

113  {
114  TProfile* eff;
115  if(num->GetXaxis()->GetXbins()->GetSize()==0){
116  eff = new TProfile(effName.c_str(),effName.c_str(),num->GetXaxis()->GetNbins(),num->GetXaxis()->GetXmin(),num->GetXaxis()->GetXmax());
117  }else{
118  eff = new TProfile(effName.c_str(),effName.c_str(),num->GetXaxis()->GetNbins(),num->GetXaxis()->GetXbins()->GetArray());
119  }
120  eff->SetTitle(effName.c_str());
121  eff->SetXTitle( num->GetXaxis()->GetTitle() );
122  eff->SetYTitle("Efficiency");
123  eff->SetOption("PE");
124  eff->SetLineColor(2);
125  eff->SetLineWidth(2);
126  eff->SetMarkerStyle(20);
127  eff->SetMarkerSize(0.8);
128  eff->GetYaxis()->SetRangeUser(-0.001,1.001);
129  eff->SetStats(kFALSE);
130  for(int i=1;i<=num->GetNbinsX();i++){
131  double e, low, high;
132 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,27,0)
133  if (int(den->GetBinContent(i))>0.) e= double(num->GetBinContent(i))/double(den->GetBinContent(i));
134  else e=0.;
135  low=TEfficiency::Wilson((double)den->GetBinContent(i),(double)num->GetBinContent(i),0.683,false);
136  high=TEfficiency::Wilson((double)den->GetBinContent(i),(double)num->GetBinContent(i),0.683,true);
137 #else
138  Efficiency( (double)num->GetBinContent(i), (double)den->GetBinContent(i), 0.683, e, low, high );
139 #endif
140  double err = e-low>high-e ? e-low : high-e;
141  //here is the trick to store info in TProfile:
142  eff->SetBinContent( i, e );
143  eff->SetBinEntries( i, 1 );
144  eff->SetBinError( i, sqrt(e*e+err*err) );
145  }
146  dqmStore->bookProfile(effName,eff);
147  delete eff;
148 }
int i
Definition: DBlmapReader.cc:9
T sqrt(T t)
Definition: SSEVec.h:48
MonitorElement * bookProfile(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option="s")
Definition: DQMStore.cc:1187
void HeavyFlavorHarvesting::calculateEfficiency2D ( TH2F *  num,
TH2F *  den,
string  name 
)
private

Definition at line 150 of file HeavyFlavorHarvesting.cc.

References DQMStore::bookProfile2D(), dqmStore, alignCSCRings::e, i, and mathSSE::sqrt().

Referenced by calculateEfficiency().

150  {
151  TProfile2D* eff;
152  if(num->GetXaxis()->GetXbins()->GetSize()==0 && num->GetYaxis()->GetXbins()->GetSize()==0){
153  eff = new TProfile2D(effName.c_str(),effName.c_str(),num->GetXaxis()->GetNbins(),num->GetXaxis()->GetXmin(),num->GetXaxis()->GetXmax(),num->GetYaxis()->GetNbins(),num->GetYaxis()->GetXmin(),num->GetYaxis()->GetXmax());
154  }else if(num->GetXaxis()->GetXbins()->GetSize()!=0 && num->GetYaxis()->GetXbins()->GetSize()==0){
155  eff = new TProfile2D(effName.c_str(),effName.c_str(),num->GetXaxis()->GetNbins(),num->GetXaxis()->GetXbins()->GetArray(),num->GetYaxis()->GetNbins(),num->GetYaxis()->GetXmin(),num->GetYaxis()->GetXmax());
156  }else if(num->GetXaxis()->GetXbins()->GetSize()==0 && num->GetYaxis()->GetXbins()->GetSize()!=0){
157  eff = new TProfile2D(effName.c_str(),effName.c_str(),num->GetXaxis()->GetNbins(),num->GetXaxis()->GetXmin(),num->GetXaxis()->GetXmax(),num->GetYaxis()->GetNbins(),num->GetYaxis()->GetXbins()->GetArray());
158  }else{
159  eff = new TProfile2D(effName.c_str(),effName.c_str(),num->GetXaxis()->GetNbins(),num->GetXaxis()->GetXbins()->GetArray(),num->GetYaxis()->GetNbins(),num->GetYaxis()->GetXbins()->GetArray());
160  }
161  eff->SetTitle(effName.c_str());
162  eff->SetXTitle( num->GetXaxis()->GetTitle() );
163  eff->SetYTitle( num->GetYaxis()->GetTitle() );
164  eff->SetZTitle("Efficiency");
165  eff->SetOption("colztexte");
166  eff->GetZaxis()->SetRangeUser(-0.001,1.001);
167  eff->SetStats(kFALSE);
168  for(int i=0;i<num->GetSize();i++){
169  double e, low, high;
170 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,27,0)
171  if (int(den->GetBinContent(i))>0.) e= double(num->GetBinContent(i))/double(den->GetBinContent(i));
172  else e=0.;
173  low=TEfficiency::Wilson((double)den->GetBinContent(i),(double)num->GetBinContent(i),0.683,false);
174  high=TEfficiency::Wilson((double)den->GetBinContent(i),(double)num->GetBinContent(i),0.683,true);
175 #else
176  Efficiency( (double)num->GetBinContent(i), (double)den->GetBinContent(i), 0.683, e, low, high );
177 #endif
178  double err = e-low>high-e ? e-low : high-e;
179  //here is the trick to store info in TProfile:
180  eff->SetBinContent( i, e );
181  eff->SetBinEntries( i, 1 );
182  eff->SetBinError( i, sqrt(e*e+err*err) );
183  }
184  dqmStore->bookProfile2D(effName,eff);
185  delete eff;
186 }
int i
Definition: DBlmapReader.cc:9
T sqrt(T t)
Definition: SSEVec.h:48
MonitorElement * bookProfile2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ, const char *option="s")
Definition: DQMStore.cc:1331
void HeavyFlavorHarvesting::endRun ( const edm::Run ,
const edm::EventSetup  
)
overridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 50 of file HeavyFlavorHarvesting.cc.

References calculateEfficiency(), dqmStore, efficiencies, and cppFunctionSkipper::operator.

50  {
52  if( !dqmStore ){
53  LogError("HLTriggerOfflineHeavyFlavor") << "Could not find DQMStore service\n";
54  return;
55  }
56  for(VParameterSet::const_iterator pset = efficiencies.begin(); pset!=efficiencies.end(); pset++){
57  calculateEfficiency(*pset);
58  }
59 }
void calculateEfficiency(const ParameterSet &pset)
const VParameterSet efficiencies

Member Data Documentation

DQMStore* HeavyFlavorHarvesting::dqmStore
private
const VParameterSet HeavyFlavorHarvesting::efficiencies
private

Definition at line 41 of file HeavyFlavorHarvesting.cc.

Referenced by endRun().

string HeavyFlavorHarvesting::myDQMrootFolder
private

Definition at line 40 of file HeavyFlavorHarvesting.cc.

Referenced by calculateEfficiency().