#include "analyze.h" #include #include #include #include #include #include #include #include using namespace std; analyze::analyze(char fname[100]) { // if parameter tree is not specified (or zero), connect the file // used to generate this class and read the Tree. TFile *tf = new TFile(fname); TTree *tree = (TTree*)tf->Get("ucituple"); Init(tree); } analyze::~analyze() { if (!fChain) return; delete fChain->GetCurrentFile(); } Int_t analyze::GetEntry(Long64_t entry) { // Read contents of entry. if (!fChain) return 0; return fChain->GetEntry(entry); } Long64_t analyze::LoadTree(Long64_t entry) { // Set the environment to read one entry if (!fChain) return -5; Long64_t centry = fChain->LoadTree(entry); if (centry < 0) return centry; if (!fChain->InheritsFrom(TChain::Class())) return centry; TChain *chain = (TChain*)fChain; if (chain->GetTreeNumber() != fCurrent) { fCurrent = chain->GetTreeNumber(); Notify(); } return centry; } void analyze::Init(TTree *tree) { // The Init() function is called when the selector needs to initialize // a new tree or chain. Typically here the branch addresses and branch // pointers of the tree will be set. // It is normally not necessary to make changes to the generated // code, but the routine can be extended by the user if needed. // Init() will be called many times when running on PROOF // (once per file to be processed). // Set branch addresses and branch pointers if (!tree) return; fChain = tree; fCurrent = -1; fChain->SetMakeClass(1); fChain->SetBranchAddress("l1_pt", &l1_pt, &b_l1_pt); fChain->SetBranchAddress("l1_eta", &l1_eta, &b_l1_eta); fChain->SetBranchAddress("l1_phi", &l1_phi, &b_l1_phi); fChain->SetBranchAddress("l2_pt", &l2_pt, &b_l2_pt); fChain->SetBranchAddress("l2_eta", &l2_eta, &b_l2_eta); fChain->SetBranchAddress("l2_phi", &l2_phi, &b_l2_phi); fChain->SetBranchAddress("j1_pt", &j1_pt, &b_j1_pt); fChain->SetBranchAddress("j1_eta", &j1_eta, &b_j1_eta); fChain->SetBranchAddress("j1_phi", &j1_phi, &b_j1_phi); fChain->SetBranchAddress("j2_pt", &j2_pt, &b_j2_pt); fChain->SetBranchAddress("j2_eta", &j2_eta, &b_j2_eta); fChain->SetBranchAddress("j2_phi", &j2_phi, &b_j2_phi); fChain->SetBranchAddress("njets", &njets, &b_njets); fChain->SetBranchAddress("met_x", &met_x, &b_met_x); fChain->SetBranchAddress("met_y", &met_y, &b_met_y); fChain->SetBranchAddress("run", &run, &b_run); fChain->SetBranchAddress("event", &event, &b_event); fChain->SetBranchAddress("weight", &weight, &b_weight); Notify(); } Bool_t analyze::Notify() { // The Notify() function is called when a new file is opened. This // can be either for a new TTree in a TChain or when when a new TTree // is started when using PROOF. It is normally not necessary to make changes // to the generated code, but the routine can be extended by the // user if needed. The return value is currently not used. return kTRUE; } void analyze::Show(Long64_t entry) { // Print contents of entry. // If entry is not specified, print current entry if (!fChain) return; fChain->Show(entry); } Int_t analyze::Cut(Long64_t entry) { // This function may be called from Loop. // returns 1 if entry is accepted. // returns -1 otherwise. return 1; } void analyze::Loop(char fnameout[100],char fnamein[100]) { // In a ROOT session, you can do: // Root > .L analyze.C // Root > analyze t // Root > t.GetEntry(12); // Fill t data members with entry number 12 // Root > t.Show(); // Show values of entry 12 // Root > t.Show(16); // Read and show values of entry 16 // Root > t.Loop(); // Loop on all entries // // This is the loop skeleton where: // jentry is the global entry number in the chain // ientry is the entry number in the current Tree // Note that the argument to GetEntry must be: // jentry for TChain::GetEntry // ientry for TTree::GetEntry and TBranch::GetEntry // // To read only selected branches, Insert statements like: // METHOD1: // fChain->SetBranchStatus("*",0); // disable all branches // fChain->SetBranchStatus("branchname",1); // activate branchname // METHOD2: replace line // fChain->GetEntry(jentry); //read all branches //by b_branchname->GetEntry(ientry); //read only this branch if (fChain == 0) return; TFile *tfo = new TFile(fnameout,"recreate"); TFile *tfi = TFile::Open(fnamein); double scale; //set scale based on scalefac exist if (tfi->Get("scalefac")){ std::cout << "Scalefac found. Histograms scaled." << std::endl; TParameter *scalefac = (TParameter *) tfi->Get("scalefac"); double sf = scalefac->GetVal(); scale = sf*4200; } else { std::cout << "Scalefac not found. Histograms not scaled." << std::endl; scale = 1; } THStack hs("hs",""); TH1F *hist1 = new TH1F("M_l1l2","",200,0,200); TH1F *hist2 = new TH1F("M_j1j2","",200,0,200); TH2F *hist2D = new TH2F("ll_jj","",200,0,200,200,0,200); //TCanvas *c1 = new TCanvas("","",1200,1200); TLorentzVector l1; TLorentzVector l2; TLorentzVector j1; TLorentzVector j2; /* gStyle->SetCanvasColor(0); gStyle->SetFrameBorderMode(0); gStyle->SetStatBorderSize(1); gStyle->SetFrameFillColor(0); gStyle->SetTitleFillColor(0); gStyle->SetTitleSize(0.05593); gStyle->SetTitleXOffset(0.95); gStyle->SetTitleXSize(0.08); gStyle->SetTitleFont(132,"xyz"); gStyle->SetLabelFont(132,"xyz"); gStyle->SetTitleYOffset(1.0); gStyle->SetTitleYSize(0.06593); gStyle->SetTitleXSize(0.06593); gStyle->SetTitleBorderSize(0); gStyle->SetNdivisions(10,"xyz"); gStyle->SetLabelSize(0.035,"xyz"); gStyle->SetOptStat(000000); gStyle->SetPadBottomMargin(0.15); gStyle->SetPadLeftMargin(0.15); */ Long64_t nentries = fChain->GetEntriesFast(); Long64_t nbytes = 0, nb = 0; for (Long64_t jentry=0; jentryGetEntry(jentry); nbytes += nb; // if (Cut(ientry) < 0) continue; l1.SetPtEtaPhiM(l1_pt,l1_eta,l1_phi,0.1); l2.SetPtEtaPhiM(l2_pt,l2_eta,l2_phi,0.1); j1.SetPtEtaPhiM(j1_pt,j1_eta,j1_phi,0.1); j2.SetPtEtaPhiM(j2_pt,j2_eta,j2_phi,0.1); TLorentzVector myParticle1 = l1+l2; TLorentzVector myParticle2 = j1+j2; double M1 = myParticle1.M(); double M2 = myParticle2.M(); hist1->Fill(M1,weight); hist2->Fill(M2,weight); hist2D->Fill(M1,M2,weight); //std::cout << "M2: " << M2 << std::endl; //std::cout << "row " << jentry << std::endl << "l1_pt: " << l1_pt << " l1_eta: " << l1_eta << " l1_phi: " << l1_phi << std::endl << "l2_pt: " << l2_pt << " l2_eta: " << l2_eta //<< " l2_phi: " << l2_phi << std::endl << std:: endl; } tfo->cd(); hist1->Scale(scale); hist1->SetFillColor(kRed); //c1->cd(); hist1->Write(); //hist1->Draw(); //c1->Update(); //c1->SaveAs("stack.gif"); hs.Add(hist1); hist2->Scale(scale);; hist2->SetFillColor(kBlue); hist2->Write(); hs.Add(hist2); hist2D->Scale(scale); hist2D->Write(); hs.Write(); std::cout << "Integral M_ll: " << hist1->Integral() << std::endl; std::cout << "Integral M_jj: " << hist2->Integral() << std::endl; std::cout << "Analysis Completed." << std::endl; tfo->Close(); } int main(int argc, char *argv[]) { char infile[100]; char outfile[100]; strcpy(infile,argv[1]); strcpy(outfile,argv[2]); std::cout << "Files are " << infile << " -> " << outfile << std::endl; analyze t(infile); t.Loop(outfile,infile); }