Skip to content

Commit

Permalink
Merge pull request cms-sw#89 from amarini/topic_finalhistos
Browse files Browse the repository at this point in the history
introducing final histos
  • Loading branch information
amarini authored Nov 17, 2016
2 parents 0da3dd8 + a38e264 commit 3d747bf
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
1 change: 1 addition & 0 deletions dat/config.dat
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Smear=NONE

Correct=NONE
#Correct=MetPhiCorrector
Final=no


#________________________________________________________________
Expand Down
2 changes: 2 additions & 0 deletions interface/AnalysisBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class AnalysisBase : public Named
void Fill2D(string name, string syst , double valueX,double valueY, double weight=1);
TH1D* GetHisto(string name, string systname);
TH2D* GetHisto2D(string name, string systname);
void AddFinalHisto(const string&name) {output_ -> AddFinalHisto(name); }
void SetOnlyFinal(bool x=true) { output_->SetOnlyFinal(x) ; }

vector<string> labels;
inline vector<string>& AllLabel(){return labels;}
Expand Down
2 changes: 2 additions & 0 deletions interface/Loop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class Looper{
int InitAnalysis() ;//{ for(auto a : analysis_ ) { a->SetOutput(output_); a->doInit() ;} return 0;}
int PrintInfo();
int InitOutput(string name){output_ -> Open(name); return 0;}
void AddFinalHisto(const string&name) {output_ -> AddFinalHisto(name); }
void SetOnlyFinal(bool x=true) { output_->SetOnlyFinal(x) ; }
//
void Loop();

Expand Down
28 changes: 25 additions & 3 deletions interface/Output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <map>
#include <memory>
#include <set>

using namespace std;

Expand Down Expand Up @@ -51,15 +52,32 @@ class Output{
TFile *file_;
map<string,TH1D*> histos_;
map<string,TH2D*> histos2D_;



inline TH1D* Get(string name){ return histos_[name];}
inline TH2D* Get2D(string name){ return histos2D_[name];}
inline TH1D* Get(string name){
if (not PassFinal(name) ) return dummy.get();
return histos_[name];
}
inline TH2D* Get2D(string name){
if (not PassFinal(name) ) return dummy2D.get();
return histos2D_[name];
}

void CreateDir(string dir); // called by Write

// this option can be used to check name against
// histo and avoid booking and filling
// use to make everything faster, don't use too many "final" objects
set<string> finalHistos_;
bool onlyFinal_{false};
inline bool PassFinal(const string&name) { return (not onlyFinal_) or finalHistos_.find(name) != finalHistos_.end() ; }
// create a fake histogram for not final return pointers
std::unique_ptr<TH1D> dummy;
std::unique_ptr<TH2D> dummy2D;

public:
Output(){file_=NULL;}
Output(){file_=NULL;dummy.reset(new TH1D("dummy","dummy",100,0,1));dummy2D.reset(new TH2D("dummy","dummy",10,0,10,10,0,10));}
~Output(){}
void Close();
void Open(string name) ;
Expand All @@ -79,6 +97,10 @@ class Output{

inline TFile * GetFile(){ return file_;} // TMVA wants the file pointer

// Final objects
void SetOnlyFinal(bool x=true) {onlyFinal_ = x;}
void AddFinalHisto(string s){ finalHistos_.insert(s) ;}

// ---- Tree Operations
private:
DataStore varValues_;
Expand Down
3 changes: 2 additions & 1 deletion python/ParseDat.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def ParseDat(name):
value = ''
if '=' in l : value = '='.join(l.split('=')[1:])
######### BOOL ###########
if key == "Dump":
if key == "Dump" or key=="Final":
config[key]=BoolKey(value)
######### SUB ######
if key == 'sub':
Expand Down Expand Up @@ -163,6 +163,7 @@ def FindEOS(name,mount=""):
if '/eos/cms/store/' in name: return [name] # likely already parsed
if 'root://eoscms//' in name: return [name] # already parsed
if 'root://eosuser//' in name: return [name] # already parsed
if 'root://' in name: return [name] # already parsed
if os.path.isfile(name): return [name] ## file exists

userInstance=""
Expand Down
10 changes: 10 additions & 0 deletions src/Output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ using namespace std;
//
void Output::Fill(string name, string syst , double value, double weight)
{
if (not PassFinal(name) ) return ;

string fullname = name + "_" + syst;
if ( syst == "" or syst == "NONE")
fullname = name;
Expand All @@ -24,6 +26,8 @@ void Output::Fill(string name, string syst , double value, double weight)

void Output::Fill2D(string name, string syst , double valueX,double valueY, double weight)
{
if (not PassFinal(name) ) return ;

string fullname = name + "_" + syst;
if ( syst == "" or syst == "NONE")
fullname = name;
Expand Down Expand Up @@ -132,6 +136,8 @@ void Output::Write(){

void Output::Book(string name, string title,int nBins, double xmin, double xmax)
{
if (not PassFinal(name) ) return ;

if ( Exists(name) )
cout <<"[Output]::[Book]::[ERROR] a TH1D/TH2D histo with the same name '"<<name<<"' already exist"<<endl;
histos_ [name] = new TH1D(name.c_str(),
Expand All @@ -142,6 +148,8 @@ void Output::Book(string name, string title,int nBins, double xmin, double xmax)

void Output::Book2D(string name, string title,int nBins, double xmin, double xmax,int nBins2, double ymin,double ymax)
{
if (not PassFinal(name) ) return ;

if ( Exists(name) )
cout <<"[Output]::[Book2D]::[ERROR] a TH1D/TH2D histo with the same name '"<<name<<"' already exist"<<endl;

Expand All @@ -155,6 +163,8 @@ void Output::Book2D(string name, string title,int nBins, double xmin, double xma

void Output::Book(string name, string title,int nBins, double *xbound)
{
if (not PassFinal(name) ) return ;

if ( Exists(name) )
cout <<"[Output]::[Book]::[ERROR] a TH1/TH2 histo with the same name '"<<name<<"' already exist"<<endl;

Expand Down

0 comments on commit 3d747bf

Please sign in to comment.