#include #include #include "TString.h" #include "TFile.h" #include "TTree.h" class TWeight { public: TString str; Double_t variable; TWeight(TString str, Double_t variable):str(str),variable(variable){}; virtual ~TWeight(){}; }; /** Normalization is done with respect to the first element. fileCross should contain the names of files and cross section times branching ratio. The print out of the function is: first line -- # of selected events, # generated, efficiency second line -- file name, weight with respect to the first entry of fileCross. */ vector * Weight(vector fileCross) { Double_t norm=1.; Double_t luminosity=1.; vector * weights = new vector; Double_t weight=1.; for(Int_t i=0;iGetEntries(); Int_t nmax; t->SetBranchAddress("nmax",&nmax); t->GetEntry(1); Double_t efficiency = nEntries*1./nmax; weight=luminosity*fileCross[i].variable*efficiency; if(i==0){ norm=luminosity*fileCross[i].variable*efficiency; } weights->push_back(TWeight(fileCross[i].str,weight/norm)); cout << nEntries << " " << nmax << " " << efficiency << endl; cout << fileCross[i].str << " " << weight/norm << endl; } return weights; } /** To run this function you need to compile it ".L efficiency.C+" and then to execute efficiency(). */ void efficiency() { vector fileCross; vector * weights; /** The first parameter is the filename and the second is cross section times the branching ratio(s). */ fileCross.push_back(TWeight("schannel.root",20.)); fileCross.push_back(TWeight("tchannel.root",800.)); /** weights can be used in the further calculations. */ weights=Weight(fileCross); }