#include #include #include #include #include #include #include #include "TMath.h" #include "TChain.h" #include "TFile.h" #include "TTree.h" #include "TLatex.h" #include "TString.h" #include "TObjString.h" #include #include #include #include #include "TSystem.h" #include "TROOT.h" #include "TMVA/Factory.h" #include "TMVA/DataLoader.h" #include "TMVA/Reader.h" #include "TMVA/Tools.h" #include "TMVA/MethodCuts.h" #include "TMVA/TMVAGui.h" using namespace std; using namespace TMVA; /*--------------------------------------------------------------------------* * Function to Get TTrees from File * *--------------------------------------------------------------------------*/ TTree* getTree(TString filename, TString TupleName) { // Get the TTree objects from files TFile* inputfile = new TFile(filename); TTree* Tree = (TTree*)inputfile->Get(TupleName); return Tree; delete inputfile; } /*--------------------------------------------------------------------------* * Significance Equation * *--------------------------------------------------------------------------*/ double ZA_fcn(double s, double b) { double Z = sqrt( 2. * ( (s+b)*TMath::Log(1 + (s/b)) - s ) ); if ( Z > 100. ) { Z = 0.; } return Z; } /*--------------------------------------------------------------------------* * Significance Function for Minuit Analysis * *--------------------------------------------------------------------------*/ // fcn passes back f = chi, the function to be minimized. void fcn(int& nvars, double* deriv, double& f, double par[], int flag) { TString sigFilename = "hhttbb.root"; TString bckFilename[] = {"ttbar_new.root", "Ztautau.root", "ZtautauB.root", "ZtautauC.root", "ZtautauL.root"}; TString TupleName = "CxAODTuple_Nominal"; const int nBackgrounds = 5; // Get the TTree objects from files TFile* siginputfile = new TFile(sigFilename); TTree* sigTree = (TTree*)siginputfile->Get(TupleName); // Get the TTree objects from files TFile* bckinputfile[nBackgrounds]; TTree* bckTree[nBackgrounds]; for ( int i=0 ; iGet(TupleName); } TString varsName[] = {"mBB", "mMMC","mHH", "drBB", "drLepTau", "mtLepMet"}; double sf[] = {1e-3, 1., 1e-3, 1., 1., 1e-3}; const int nSig = sigTree->GetEntries(); int nBck[nBackgrounds]; for ( int i=0 ; iGetEntries(); } // set address of variable to cut over TString SVN = "SelVars_Nominal_"; float var[nvars], weight; sigTree->SetBranchAddress("EventWeight_Nominal_TotalWeight", &weight); for ( int i=0 ; iSetBranchAddress(SVN + varsName[i], &var[i]); } for ( int i=0 ; iSetBranchAddress("EventWeight_Nominal_TotalWeight", &weight); for ( int j=0 ; jSetBranchAddress(SVN + varsName[j], &var[j]); } } double cutVals[nvars][2]; for ( int i=0 ; iGetEvent(i); bool pass = true; for ( int k=0 ; k cutVals[k][1]/sf[k] ) { pass = false;} } if ( pass == true ) { sigCount += weight; } sigTotalWeight += weight; } // get the background events for each cut double bckCount[nBackgrounds]; for( int i=0 ; iGetEvent(j); bool pass = true; for ( int l=0 ; l cutVals[l][1]/sf[l] ) { pass = false; } } if ( pass == true ) { bckCount[i] += weight; } bckTotalWeight[i] += weight; } } // find the significance value double s = sigCount/sigTotalWeight; double b = 0.; for ( int j=0 ; jmncomd(Form("scan %i 1000 %lg %lg", varsIndex+1, xLimits[0], xLimits[1]), icondn); TCanvas *cScan = new TCanvas(); TGraph *gScan = (TGraph*)gMinuit->GetPlot(); gScan->SetTitle("Scan " + varsLabel + "; " + varsLabel + "; Significance, Z"); //gScan->GetYaxis()->SetRangeUser(30, 40); gScan->Draw("al"); // Print the scan as a png TImage *img; img = TImage::Create(); img->FromPad(cScan); if ( varsIndexWriteImage(Form("./Cuts/Multiple Variable Cuts/%i. ", varsIndex+1) + varsName + "_Scan_t>tcut.png"); } else { img->WriteImage(Form("./Cuts/Multiple Variable Cuts/%i. ", varsIndex+1-nvars) + varsName + "_Scan_ttcut", cutVals[0][0], 0.1, 30., 100.); // mBB minuit.DefineParameter(1, varsName[1]+"_t>tcut", cutVals[1][0], 0.5, 70., 110.); // mMMC minuit.DefineParameter(2, varsName[2]+"_t>tcut", cutVals[2][0], 0.5, 250., 700.); // mHH minuit.DefineParameter(3, varsName[3]+"_t>tcut", cutVals[3][0], 0.001, 0.4, 2.); // drBB minuit.DefineParameter(4, varsName[4]+"_t>tcut", cutVals[4][0], 0.001, 0.4, 2.); minuit.DefineParameter(5, varsName[5]+"_t>tcut", cutVals[5][0], 0.5, 0., 200.); minuit.DefineParameter(6, varsName[0]+"_ttcut", cutVals[0][0], 0.1, 30., 100.); // mBB minuit.DefineParameter(1, varsName[1]+"_t>tcut", cutVals[1][0], 0.1, 70., 110.); // mMMC minuit.DefineParameter(2, varsName[0]+"_tmncomd(Form("FIX %i", i+1), icondn);} // set i!= the variable you } // Do the minimization! gMinuit->mncomd("SIMplex 1000 0.1", icondn); gMinuit->mncomd("MIGrad 20000 0.1", icondn); /* FMIN: the best function value found so far FEDM: the estimated vertical distance remaining to minimum ERRDEF: the value of UP defining parameter uncertainties NPARI: the number of currently variable parameters PARX: the highest (external) parameter number defined by user ISTAT: a status integer indicating how good is the covariance matrix: 0= not calculated at all 1= approximation only, not accurate 2= full matrix, but forced positive-definite 3= full accurate covariance matrix */ double fmin, fedm, errdef; int npari, nparx, istat; minuit.mnstat(fmin, fedm, errdef, npari, nparx, istat); cout << "fmin = " << fmin << " fedm = " << fedm << " errdef = " << errdef << endl; cout << "npari = " << npari << " nparx = " << nparx << " istat = " << istat << endl; double outpar[nvars][2], err[nvars][2]; for (int i = 0; iGetParameter(i, outpar[i][0], err[i][0]); gMinuit->GetParameter(i+nvars, outpar[i][1], err[i][1]); } cout << "minimisation of variable " << varsName[cutVarIndex] << " complete" << endl << endl; double minResults[25]; //4*nvars +1 minResults[0] = fmin; for (int i = 0; i