#include "events.h" #include #include #include #include #include #include "TMinuit.h" #include "TRandom.h" using namespace std; void events::Loop(){ if (fChain == 0) return; Long64_t nentries = fChain->GetEntries(); Long64_t nbytes = 0, nb = 0; cout << "I have " << nentries << " events in my tree" << endl; // Hint 1: Here's a good spot to declare the histogram TLorentzVector v1; TLorentzVector v2; TLorentzVector v3; TH1F * Ztrue = new TH1F("Ztrue", "", 100, 50, 150); TH1F * Zreco = new TH1F("Zreco", "", 100, 50, 150); if (nentries>= 2000){ nentries = 2000; } for (Long64_t jentry=0; jentryGetEntry(jentry); nbytes += nb; //cout << "event: " << jentry << " Z mass " << Z_mass << endl; v1.SetPtEtaPhiM(mu1_pt, mu1_eta, mu1_phi, mu1_mass); v2.SetPtEtaPhiM(mu2_pt, mu2_eta, mu2_phi, mu2_mass); v3 = v1 + v2; Ztrue->Fill(Z_mass); Zreco->Fill(v3.M()); } // Uncomment for slide 2 // Ztrue->Draw(); // Zreco->SetLineColor(kRed); // Zreco->Draw("same"); // first part // Ztrue->Fit("gaus"); // second part // TF1 *fit = Ztrue->GetFunction("gaus"); // std::cout<<"par0 = "<GetParameter(0)<GetListOfFiles()->FindObject("mytree.root"); if (!f || !f->IsOpen()) { f = new TFile("mytree.root"); } f->GetObject("events",tree); } Init(tree); } events::~events(){ if (!fChain) return; delete fChain->GetCurrentFile(); } Int_t events::GetEntry(Long64_t entry){ // Read contents of entry. if (!fChain) return 0; return fChain->GetEntry(entry); } Long64_t events::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->GetTreeNumber() != fCurrent) { fCurrent = fChain->GetTreeNumber(); Notify(); } return centry; } void events::Init(TTree *tree){ if (!tree) return; fChain = tree; fCurrent = -1; fChain->SetMakeClass(1); fChain->SetBranchAddress("event_number", &event_number, &b_event_number); fChain->SetBranchAddress("Z_mass", &Z_mass, &b_Z_mass); fChain->SetBranchAddress("Z_pt", &Z_pt, &b_Z_pt); fChain->SetBranchAddress("Z_eta", &Z_eta, &b_Z_eta); fChain->SetBranchAddress("Z_phi", &Z_phi, &b_Z_phi); fChain->SetBranchAddress("mu1_pt", &mu1_pt, &b_mu1_pt); fChain->SetBranchAddress("mu1_eta", &mu1_eta, &b_mu1_eta); fChain->SetBranchAddress("mu1_phi", &mu1_phi, &b_mu1_phi); fChain->SetBranchAddress("mu1_mass", &mu1_mass, &b_mu1_mass); fChain->SetBranchAddress("mu1_charge", &mu1_charge, &b_mu1_charge); fChain->SetBranchAddress("mu2_pt", &mu2_pt, &b_mu2_pt); fChain->SetBranchAddress("mu2_eta", &mu2_eta, &b_mu2_eta); fChain->SetBranchAddress("mu2_phi", &mu2_phi, &b_mu2_phi); fChain->SetBranchAddress("mu2_mass", &mu2_mass, &b_mu2_mass); fChain->SetBranchAddress("mu2_charge", &mu2_charge, &b_mu2_charge); Notify(); } Bool_t events::Notify(){ return kTRUE; } void events::Show(Long64_t entry){ if (!fChain) return; fChain->Show(entry); }