Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding class to return FR weights in ZHtautau analysis #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions interface/FRWeights.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef FRWEIGHTS_H
#define FRWEIGHTS_H

#include <string>
#include "TFile.h"
#include "TGraphErrors.h"

class FRWeights
{
public:
FRWeights();
~FRWeights();

bool init(const std::string& WeightsFileName);
double getWeight(const std::string& cat ,const std::string& bin, const std::string& var,const std::string& wrt ,const double& pT);

private:
TFile* WeightsFile;

};

#endif

49 changes: 49 additions & 0 deletions src/FRWeights.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "UserCode/llvv_fwk/interface/FRWeights.h"
#include <TFile.h>
#include <TSystem.h>
#include <math.h>
#include <vector>
#include <iostream>

using namespace std;

/*****************************************************************/
FRWeights::FRWeights()
/*****************************************************************/
{
}

/*****************************************************************/
FRWeights::~FRWeights()
/*****************************************************************/
{
}

/*****************************************************************/
bool FRWeights::init(const string& WeightsFileName)
/*****************************************************************/
{
WeightsFile = TFile::Open(WeightsFileName.c_str());
if(!WeightsFile) {
cout<<"ERROR: Cannot open weights file "<<WeightsFileName<<"\n";
return false;
} else {
return true;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cache everything and close the file when done
otherwise we will have huge trouble with file access

}

/*****************************************************************/
//double FRWeights::getWeight(string cat,string bin,string var,string wrt,double pT)
double FRWeights::getWeight(const std::string& cat ,const std::string& bin, const std::string& var,const std::string& wrt ,const double& pT)
/*****************************************************************/
{
TGraphErrors* graph = (TGraphErrors*)WeightsFile->Get((cat+"FRWeights"+var+bin+wrt).c_str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be move to the constructor and cached
We can't reload the histogram each time we want to compute the weight

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Loic yes, just testing...
also the branch is not the correct one at the moment.

double result=-1.;
if(graph){
result=(1 - graph->Eval(pT));
} else {
result = 1;
}

return result;
}