#include "TH1.h" #include "TFile.h" #include "TChain.h" #include "TTree.h" #include #include #include //Need to declare as global the variables that will be used for the branches. //Otherwise it will not compile std::vector *T_Muon_Px; void analisis(TString signal){ cout << ">> Creating the chain..." << endl; TChain *suma = new TChain("Tree"); //Signal if (signal=="TTbar7"){suma->Add("/hadoop/JF/TTreeWithPfLeptons/TTreeWithPfLeptons_TTbar_7TeV_Skim2MuPt2010/*");} //Find the number of entries in this dataset cout << ">> Calculating the number of events..." << endl; int nEvents = suma->GetEntries(); cout << endl; cout << "------------------------------------------" << endl; cout << nEvents << " raw Events (no weighted)" << endl; cout << "------------------------------------------" << endl; //Read Branches from the MiniTree cout << ">> Setting the branches... " << endl; suma->SetBranchAddress("T_Muon_Px", &T_Muon_Px); //Create the root file cout << ">> Creating the output file ..." << endl; TString histoFileName("histo"); histoFileName+=signal; histoFileName+=".root"; TFile histoAnalisis(histoFileName, "RECREATE"); if (histoAnalisis.IsOpen()) cout << " ... \"" << histoFileName << "\" created" << endl; else { cout << " ... ERROR: \""<< histoFileName << "\" already exists. Remove it." << endl; return; } //Define histograms cout << ">> Creating histograms..." << endl; TH1F *histoPxmuon=new TH1F("histoPxmuon", "Px muon", 100, 0, 300); ///////////////////////////////////////////////////////////////////////// // // Event loop // // cout << ">> Looping over the events..." << endl; // Small trick for the output unsigned int ndigits=log10(abs(nEvents))+1; char* strdelete= new char[ndigits+1]; for (unsigned int i=0; iGetEntry(event); //Loop over muons storing the Px for (unsigned int i=0; i < T_Muon_Px->size(); i++){ histoPxmuon->Fill(T_Muon_Px->at(i)); } } //Final loop output cout << strdelete << setw(ndigits) << setfill('-') << event << flush; cout << endl << ">> Writting and closing output file..." << endl; histoAnalisis.Write(); histoAnalisis.Close(); cout << "------------------------------------------" << endl; cout << endl; }