void count_entries(const char* listname="list.txt", const char* treename="analyze/Analysis") { TFile *f; TTree *tree; Int_t count=0; Int_t filecount=0; ifstream list; list.open(listname); char filename[300]; while (true) { list >> filename; if (!list.good()) break; cout << filename << endl; TString base("dcap://t3se01.psi.ch:22125/"); base.Append(filename); f=TFile::Open(base.Data(),"read"); filecount++; f->GetObject(treename,tree); count+=tree->GetEntries(); f->Close(); } list.close(); cout << "Total entries: " << count << " from " << filecount << " files" << endl; }
TGraph2DErrors* GetGraph(std::string fname) { TGraph2DErrors* gr = 0; std::string fGrName = "mygraph"; TFile *f = new TFile(fname.data()); if (!f->IsOpen()) { std::cerr << "Failed to open " << fname << std::endl; return gr; } f->ls(); std::cout << "Enter name of graph : "; if (std::cin.peek()=='\n') std::cin.get(); std::getline(std::cin, fGrName); f->GetObject(fGrName.data(), gr); if (gr!=NULL) { TGraph2DErrors* tgr = (TGraph2DErrors*) gr->Clone("mygraph_0"); gr=tgr; gr->SetDirectory(0); } return gr; }
int testSimpleFile(const char *filename, Long64_t entries, Int_t compSetting, Long64_t fileSize, UInt_t tolerance = 0) { fprintf(stdout,"Checking %s\n",filename); TFile *file = TFile::Open(filename); if (file == nullptr || file->IsZombie()) { Error("testSimpleFile", "Could not open %s.",filename); return 1; } //file->ls(); if (file->GetCompressionSettings() != compSetting) { Error("testSimpleFile","Compression level of %s should have been %d but is %d\n",file->GetName(), 206, file->GetCompressionSettings() ); return 3; } if (abs(file->GetSize()-fileSize) > tolerance) { Error("testSimpleFile","Disk size of %s should have been %lld but is %lld (tolerance %u bytes)\n",file->GetName(), fileSize, file->GetSize(), tolerance); return 4; } TTree *ntuple; file->GetObject("ntuple",ntuple); if (ntuple == 0) { Error("testSimpleFile", "Could not retrieve ntuple from %s.",file->GetName()); return 2; } if (ntuple->GetEntries() != entries) { Error("testSimpleFile","Number of entries in ntuple in %s should have been %lld but is %lld\n",file->GetName(), entries, ntuple->GetEntries()); return 4; } delete file; return 0; }
void ViewData() { TFile *file = new TFile("result.root", "READ"); TTree *tree; file->GetObject("run", tree); Double_t qtotal; tree->SetBranchAddress("Q_total", &qtotal); for (Int_t i = 0; i < tree->GetEntries(); i++) { tree->GetEntry(i); cout << "Q_total = " << qtotal << endl; } /* vector<double> arrivalTimes; tree->SetBranchAddress("ArrivalTime", &arrivalTimes); cout << "Arrival Times from Measurement.root" << endl; for (unsigned int i = 0; i < 10; i++) { cout << "arrival time number " << i << ": " << arrivalTimes.at(i) << endl; } */ //TCanvas *c1 = new TCanvas("c1", "Test", 800, 600); //c1->cd(); }
float Yield(Int_t ip_chan, Int_t ip_level){ TH1F* hist; TFile* inputfile = TFile::Open(path + sampleName); inputfile->GetObject("H_Yields_" + chan[ip_chan],hist); float yield = hist->GetBinContent(ip_level+1); delete inputfile; return yield*lumi; }
int addDQMFiles_MC(){ TH2F* Charge_Vs_Index=0; TH2F* together=0; int i=0; int run; TFile *f; TString strFile; ifstream inputFile("runlistMC.txt"); while(inputFile>>run){ cout<<"run = "<<run<<endl; strFile.Form("MC2012/%i/DQM_V0001_R000000001__Express__PCLTest__ALCAPROMPT.root",run); cout<<"Open "<<strFile<<endl; f = TFile::Open(strFile); if(!f){ cout<<"continue"<<endl; continue; } TString strHisto; strHisto = "DQMData/Run 1/AlCaReco/Run summary/SiStripGains/Charge_Vs_Index;1"; cout<<"Get "<<strHisto<<endl; if(i==0){ f->GetObject(strHisto,together); together->SetDirectory(0); if(!together){ cout<<"No histogram available"<<endl; continue; } } else{ f->GetObject(strHisto,Charge_Vs_Index); together->Add(Charge_Vs_Index,1); } delete f; i++; } TFile fSave("DQM_MC.root","recreate"); together->Write(); fSave.Close(); return 0; }
int printSizes() { TFile *f = TFile::Open("hsimple.root"); if (!f) return 1; TTree *t; f->GetObject("ntuple",t); if (!t) return 1; printTreeSummary(t); return 0; }
float GetWeight(TString chan, TString lev, Int_t index){ // index from 1 to 249 TH1F* hist; TFile* inputfile = TFile::Open(path + sampleName); inputfile->GetObject("H_LHEweights"+ chan + "_" + lev,hist); float weight = hist->GetBinContent(index)*lumi; inputfile -> Close(); delete inputfile; return weight/GetWeightSum(index)*fac; }
void MECompare( TString currentfile = "new.root", TString referencefile = "ref.root", TString theDir = "DQMData/Run 1/Generator/Run summary/MBUEandQCD" ) { std::vector<TString> theList = histoList(currentfile, theDir); gROOT ->Reset(); const char* rfilename = referencefile.Data(); const char* sfilename = currentfile.Data(); delete gROOT->GetListOfFiles()->FindObject(rfilename); delete gROOT->GetListOfFiles()->FindObject(sfilename); TFile * rfile = new TFile(rfilename); TFile * sfile = new TFile(sfilename); const char* baseDir=theDir.Data(); rfile->cd(baseDir); gDirectory->ls(); sfile->cd(baseDir); gDirectory->ls(); for ( unsigned int index = 0; index < theList.size() ; index++ ) { std::cout << index << std::endl; TString theName = theDir+"/"+theList[index]; std::cout << theName << std::endl; TH1* href_; rfile->GetObject(theName,href_); TH1* hnew_; sfile->GetObject(theName,hnew_); MEComparePlot(href_, hnew_, currentfile, referencefile, theDir, theList[index]); } }
void nu_spect(const std::string& filename) { TFile* file = new TFile(filename.c_str(), "read"); TTree* tree = NULL; file->GetObject("MARLEY_event_tree", tree); if (!tree) { std::cout << "MARLEY event tree not found" << '\n'; return; } marley::Event* ev = new marley::Event; tree->SetBranchAddress("event", &ev); size_t num_events = tree->GetEntries(); std::vector<double> E_vec; for (size_t i = 0; i < num_events; ++i) { tree->GetEntry(i); E_vec.push_back(ev->projectile().total_energy()); if (i % 1000 == 0) std::cout << "Event " << i << '\n'; } double E_max = -1e30; double E_min = 1e30; for (size_t k = 0; k < E_vec.size(); ++k) { double e = E_vec.at(k); if (e > E_max) E_max = e; else if (e < E_min) E_min = e; } TString title_str; TH1D* Es = new TH1D("nu_Es", "reacting neutrino spectrum", 100, E_max, E_min); for (size_t j = 0; j < E_vec.size(); ++j) { Es->Fill(E_vec.at(j)); } TCanvas* c = new TCanvas; c->cd(); gStyle->SetOptStat(); Es->SetStats(true); Es->SetLineColor(kBlue); Es->SetLineWidth(2); Es->Draw(); //c->SaveAs("nu_Es.pdf"); }
DrawPlot::DrawPlot(const unsigned int iterationNumber, const bool summaryFile): outpath_(nullptr), file_(nullptr), fileZeroApe_(nullptr), designFile_(nullptr), baselineTreeX_(nullptr), baselineTreeY_(nullptr), delta0_(nullptr), legendEntry_("data (final APE)"), legendEntryZeroApe_("data (APE=0)"), designLegendEntry_("MCideal"), legendXmin_(0.41), legendYmin_(0.27), legendXmax_(0.71), legendYmax_(0.42), thesisMode_(false) { std::stringstream ss_inpath, ss_inpathZeroApe; ss_inpath<<"$CMSSW_BASE/src/Alignment/APEEstimation/hists/workingArea/iter"; ss_inpathZeroApe<<ss_inpath.str()<<"0/"; ss_inpath<<iterationNumber<<"/"; const TString* inpath = new TString(ss_inpath.str().c_str()); const TString* inpathZeroApe = new TString(ss_inpathZeroApe.str().c_str()); outpath_ = new TString(inpath->Copy().Append("plots/")); const TString rootFileName(summaryFile ? "allData_resultsFile.root" : "allData.root"); const TString* fileName = new TString(inpath->Copy().Append(rootFileName)); const TString* fileNameZeroApe = new TString(inpathZeroApe->Copy().Append(rootFileName)); const TString* designFileName = new TString("$CMSSW_BASE/src/Alignment/APEEstimation/hists/Design/baseline/" + rootFileName); const TString* baselineFileName = new TString("$CMSSW_BASE/src/Alignment/APEEstimation/hists/Design/baseline/allData_baselineApe.root"); std::cout<<"\n"; std::cout<<"Outpath: "<<*outpath_<<"\n"; std::cout<<"File name (final APE): "<<*fileName<<"\n"; std::cout<<"File name (zero APE): "<<*fileNameZeroApe<<"\n"; std::cout<<"Design file name: "<<*designFileName<<"\n"; std::cout<<"Baseline file name: "<<*baselineFileName<<"\n"; std::cout<<"\n"; if(iterationNumber!=0)file_ = new TFile(*fileName, "READ"); fileZeroApe_ = new TFile(*fileNameZeroApe, "READ"); designFile_ = new TFile(*designFileName, "READ"); TFile* baselineFile = new TFile(*baselineFileName, "READ"); //if(!file_ || !fileZeroApe_ || !designFile_ || !baselineFile){ // Not needed: root gives error by default when file is not found //std::cout<<"\n\tInput file not found, please check file name: "<<*fileName<<"\n"; //} if(baselineFile){ baselineFile->GetObject("iterTreeX", baselineTreeX_); baselineFile->GetObject("iterTreeY", baselineTreeY_); } if(!baselineTreeX_)std::cout<<"Baseline tree for x coordinate not found, cannot draw baselines!\n"; if(!baselineTreeY_)std::cout<<"Baseline tree for y coordinate not found, cannot draw baselines!\n"; baseLineTreeX_->SetDirectory(nullptr); baselineTreeY_->SetDirectory(nullptr); delete inpath; delete fileName; delete fileNameZeroApe; delete designFileName; delete baselineFileName; }
float stat(TString mass){ TString samplename = "TTbar_Powheg"; if (mass == "1725") samplename += ".root"; else samplename += "_mtop" + mass + ".root"; TFile *f = TFile::Open(path + samplename); TH1F* h; f->GetObject("H_Yields_ElMu", h); float y = h->GetBinError(5); delete f; return y*Lumi; }
void runreadvararypolyp() { C* c = 0; TFile* f = new TFile(testfilename); f->GetObject("C", c); c->print(); c->clear(); TTree* t = 0; f->GetObject("t", t); t->SetBranchAddress("br1.", &c); t->GetEntry(1); cout << endl; c->print(); delete t; t = 0; f->Close(); delete f; f = 0; delete c; c = 0; }
int makeGraphData(){ TGraphErrors* histoJet, *histoPhoton; TCanvas* canvas[13]; TFile *file; TString fileName; for(int i=4; i<13; i++){ fileName.Form("c%i",i); canvas[i] = new TCanvas(fileName,fileName,0,0,500,500); canvas[i] ->cd(); fileName.Form("root_files_JetHemisphere/jet_energy_resolution_for_1_eta_bin_%i_pTGamma_bin_PFCHS_mc.root",i); file = TFile::Open(fileName); file->GetObject("Graph",histoJet); histoJet -> SetMarkerColor(2); histoJet -> SetLineColor(2); histoJet -> GetFunction("fResolutionAlpha")->SetLineColor(2); histoJet ->Draw("AP"); delete file; fileName.Form("root_files/jet_energy_resolution_for_1_eta_bin_%i_pTGamma_bin_PFCHS_mc.root",i); file = TFile::Open(fileName); file->GetObject("Graph",histoPhoton); histoPhoton -> SetMarkerColor(3); histoPhoton -> SetLineColor(3); histoPhoton -> GetFunction("fResolutionAlpha")->SetLineColor(3); histoPhoton ->Draw("Psame"); delete file; } return 0; }
void eurica_treeinfo::GetTree(TString infile, TTree *tree) { // if parameter tree is not specified (or zero), connect the file // used to generate this class and read the Tree. if (tree == 0) { TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(infile); if (!f || !f->IsOpen()) { f = new TFile(infile); } f->GetObject("tree",tree); } Init(tree); }
int runprova() { TChain *chain_null = new TChain("Eventi"); chain_null->Add("prova1.root"); chain_null->Add("prova2.root"); chain_null->Draw("br.n_run"); chain_null->Merge("merge.root"); TFile *f = new TFile("merge.root"); TTree *t; f->GetObject("Eventi",t); t->Scan("br.n_ev"); return 0; }
void efficiency( TString denfile="60-120.root", TString numfile="orig.root", TString outfile="res.root" ) { gROOT ->Reset(); TFile * nume = new TFile(numfile); TFile * deno = new TFile(denfile); nume->cd("/"); deno->cd("/"); TString theName = "d02-x01-y01"; const TH1F *myNume; nume->GetObject(theName,myNume); myNume->Sumw2(); myNume->Print("all"); const TH1F *myDeno; deno->GetObject(theName,myDeno); myDeno->Sumw2(); myDeno->Print("all"); TH1F *Acce = (TH1F*)myNume->Clone("efficiency"); Acce->Reset(); Double_t f1(1.),f2(1.); Option_t* opt("b"); Acce->Divide(myNume,myDeno,f1,f2,opt); Acce->Print("all"); TFile * out = new TFile(outfile,"NEW"); Acce->Write(); out->Close(); }
// This will generate the following PDFs: // -- hDQ_TDCCheck_muSc_rate.png // -- hDQ_TDCCheck_Unknown.png // -- hDQ_TDCCheck_TDiff.png void GenerateTDCPlots(std::string filename) { std::cout << "Generating TDC plots..." << std::endl; gROOT->Reset(); gROOT->SetStyle("Plain"); gStyle->SetCanvasBorderMode(0); // turn off canvas borders TFile* file = new TFile(filename.c_str(), "READ"); // The histograms TH1F *hDQ_TDCCheck_muSc_rate; TH1F *hDQ_TDCCheck_Unknown; TH1F *hDQ_TDCCheck_TDiff; // The names of these histograms in the ROOT file should be the same regardless of the run file->GetObject("DataQuality_LowLevel/hDQ_TDCCheck_muSc_rate",hDQ_TDCCheck_muSc_rate); file->GetObject("DataQuality_LowLevel/hDQ_TDCCheck_Unknown",hDQ_TDCCheck_Unknown); file->GetObject("DataQuality_LowLevel/hDQ_TDCCheck_TDiff",hDQ_TDCCheck_TDiff); hDQ_TDCCheck_muSc_rate->GetYaxis()->SetTitleOffset(1.3); hDQ_TDCCheck_Unknown->GetYaxis()->SetTitleOffset(1.3); hDQ_TDCCheck_TDiff->GetYaxis()->SetTitleOffset(1.3); TCanvas *c1 = new TCanvas(); hDQ_TDCCheck_muSc_rate->Draw(); c1->Print("data_quality_figs/hDQ_TDCCheck_muSc_rate.png"); hDQ_TDCCheck_Unknown->Draw(); c1->Print("data_quality_figs/hDQ_TDCCheck_Unknown.png"); hDQ_TDCCheck_TDiff->Draw(); c1->Print("data_quality_figs/hDQ_TDCCheck_TDiff.png"); }
TTree* MillePedeTrees::CreateTree(const char *fileName, const TString &treeNameAdd) { TFile *file = TFile::Open(fileName); if (!file) return NULL; TString *allTreeNames[] = {&fOrgPos, &fPos, &fMisPos, &fMisPar, &fPar, &fMp}; const unsigned int nTree = sizeof(allTreeNames) / sizeof(allTreeNames[0]); unsigned int iTree = 0; TTree *mainTree = NULL; do { file->GetObject(allTreeNames[iTree]->Data(), mainTree); if (!mainTree) { ::Error("MillePedeTrees::CreateTree", "no tree %s in %s", allTreeNames[iTree]->Data(), fileName); } *(allTreeNames[iTree]) += treeNameAdd; // Yes, we really change the data members! if (mainTree && !treeNameAdd.IsNull()) { mainTree->SetName(*(allTreeNames[iTree])); } ++iTree; } while (!mainTree && iTree < nTree); if (mainTree) { for (unsigned int jTree = iTree; jTree < nTree; ++jTree) { const TString newName(*(allTreeNames[jTree]) + treeNameAdd); // either by really renaming trees: // TTree *tree = NULL; // file->GetObject(allTreeNames[jTree]->Data(), tree); // if (!tree) { // ::Error("MillePedeTrees::CreateTree", // "no tree %s in %s", allTreeNames[jTree]->Data(), fileName); // } else { // tree->SetName(newName); // mainTree->AddFriend(tree, "", true); // no alias, but warn if different lengths // } // or by setting an alias: TFriendElement *fEle = mainTree->AddFriend(newName + " = " + *(allTreeNames[jTree])); if (!fEle || !fEle->GetTree()) { ::Error("MillePedeTrees::CreateTree","no %s as friend tree",allTreeNames[jTree]->Data()); } *(allTreeNames[jTree]) = newName; // Yes, we really change the data members! } mainTree->SetEstimate(mainTree->GetEntries()); // for secure use of GetV1() etc. } return mainTree; }
int makeTriggerEffGraph(){ char title[100]; TH1D* hTriggerBefore[8]; TH1D* hTriggerAfter[8]; TH1D* hTrigger[8]; TCanvas* canv[8]; TFile *file; TFile *file1; for(int i=0; i<8;i++){ sprintf(title,"TriggerEffBefore%i_PF_mc.root",i); file = TFile::Open(title); sprintf(title,"hTriggerEffPtBinnedBefore%i",i); file->GetObject(title,hTriggerBefore[i]); sprintf(title,"TriggerEffAfter%i_PF_mc.root",i); file1 = TFile::Open(title); sprintf(title,"hTriggerEffPtBinnedAfter%i",i); file1->GetObject(title,hTriggerAfter[i]); hTrigger[i] = new TH1D("ratio","ratio",60,0,60); hTrigger[i]->Divide(hTriggerAfter[i],hTriggerBefore[i]); canv[i] = new TCanvas("ratio","ratio",500,500); canv[i] -> cd(); hTrigger[i]->SetTitle("Trigger efficiency in MC"); hTrigger[i]->SetXTitle("#Vtx"); hTrigger[i]->SetYTitle("#events pass Trigger / # all events"); hTrigger[i]->Draw(); sprintf(title,"TriggerEff%i.pdf",i); canv[i]->Print(title); delete file; delete file1; } return 0; }
/** * Get a top collection from a file * * @param fileName Name of file * @param results Wheter it's the results collection or not * * @return Collection or null */ static TCollection* GetTop(const TString& fileName, Bool_t results=false) { TFile* file = TFile::Open(fileName, "READ"); if (!file) { Error("GetTop", "Failed to open %s", fileName.Data()); return 0; } TCollection* ret = 0; TString cName(Form("ForwardMult%s", results ? "Results" : "Sums")); file->GetObject(cName, ret); if (!ret) Error("GetTop", "Failed to get collection %s from %s", cName.Data(), fileName.Data()); file->Close(); return ret; }
void backgroundFit() { TFile *file = TFile::Open("treeDYJetsToLL_all.root"); TTree *t0; file->GetObject("treeDumper/EDBRCandidates",t0); RooRealVar candMass("candMass","M_{ZZ}", 500.,3000., "GeV"); RooRealVar lumiWeight("lumiWeight", "pure weight", 0., 10.); // Weighted dataset RooDataSet wds("wds","wds",RooArgSet(candMass,lumiWeight),RooFit::WeightVar(lumiWeight),RooFit::Import(*t0)); wds.Print(); // Build exponential p.d.f. RooRealVar p0("p0","parameter 0",500., 1. , 1.e3); RooRealVar p1("p1","parameter 1", 0.,-1. , 1.); RooGenericPdf expo("expo","leveled exponential PDF","exp(-candMass/(p0+p1*candMass))",RooArgSet(candMass,p0,p1)); expo.fitTo(wds); // Plot data and fit function in the same frame RooPlot* frame1 = candMass.frame(RooFit::Title("CMS Preliminary #sqrt{s} = 13 TeV #int L dt = 3 fb^{-1}") ); wds.plotOn(frame1); expo.plotOn(frame1,RooFit::LineColor(kRed)); expo.paramOn(frame1,RooFit::Layout(0.45,0.9,0.6)); TCanvas *c1 = new TCanvas("c1","c1", 700, 700); c1->cd(); gPad->SetLogy(); gPad->SetGridx(); frame1->Draw(); frame1->getAttText()->SetTextFont(42); frame1->getAttText()->SetTextSize(0.035); frame1->GetYaxis()->SetTitleOffset(1.1); TLegend *leg = new TLegend(0.45,0.6,0.9,0.9); leg->AddEntry("h_wds","MC background","ep"); leg->AddEntry("expo_Norm[candMass]","Fit function","l"); leg->AddEntry((TObject*)0,"exp#left[#minus x / (p_{0} #plus p_{1}x)#right]",""); leg->SetTextFont(42); leg->SetTextSize(0.04); leg->Draw(); c1->Print("backgroundFit.pdf"); }
void CreateFriendTree() { // Open the file created by CreateParentTree // Copy a subset of the TTree into a new TTree // (see also tutorials copytree.C, copytree2.C and copytree3.C) // Create an index on the new TTree ("Run","Event") // Write the new TTree (including its index) TFile *f = new TFile("treeparent.root"); TTree *T; f->GetObject("T",T); TFile *ff = new TFile("treefriend.root","recreate"); TTree *TF = T->CopyTree("z<10"); TF->SetName("TF"); TF->BuildIndex("Run","Event"); TF->Write(); //TF->Print(); delete ff; }
void GetValues(TString sample){ TFile* inputfile = TFile::Open(inputpath + "Tree_" + sample + ".root"); inputfile->GetObject("CountSMS", Counts); float val = 0; for(int i = 0; i < Counts->GetNbinsX(); i++){ for(int j = 0; j< Counts->GetNbinsY(); j++){ val = Counts->GetBinContent(i,j,1); if(val!=0){ mstop = Counts->GetXaxis()->GetBinCenter(i); mchi = Counts->GetYaxis()->GetBinCenter(j); nEvents = Counts->GetBinContent(Counts->FindBin(mstop, mchi, 0)); if(mchi == 0) mchi = 1; NeutralinoMass.push_back(mchi); StopMass.push_back(mstop); Events.push_back(nEvents); } } } inputfile->Close(); delete inputfile; }
// This will generate the following PDFs: // -- hDQ_muScTDiff_[DetName]_[BankName].png void GenerateTDiffPlots(std::string filename) { std::cout << "Generating pulse shape plots..." << std::endl; gROOT->Reset(); gROOT->SetStyle("Plain"); gStyle->SetCanvasBorderMode(0); // turn off canvas borders TFile* file = new TFile(filename.c_str(), "READ"); // The histograms TH1F *hDQ_muScTDiff; // Loop through the histograms in the file and get the island histograms (bank and channel names may differ between runs) TDirectoryFile* dir = (TDirectoryFile*) file->Get("DataQuality_LowLevel"); TIter nextDirKey(dir->GetListOfKeys()); // get the list of keys in the directory (all histograms should be in this folder) TKey *dirKey; while ( (dirKey = (TKey*)nextDirKey()) ) { // Get the names of all the histograms and count them up if (strcmp(dirKey->ReadObj()->ClassName(), "TH1F") == 0) { TCanvas *c1 = new TCanvas(); std::string histogram_name = dirKey->ReadObj()->GetName(); std::string histogram_location = "DataQuality_LowLevel/" + histogram_name; std::string pngname = "data_quality_figs/" + histogram_name + ".png"; if (histogram_name.find("muScTDiff") != std::string::npos) { file->GetObject(histogram_location.c_str(),hDQ_muScTDiff); hDQ_muScTDiff->GetYaxis()->SetTitleOffset(1.3); hDQ_muScTDiff->Draw(); c1->Print(pngname.c_str()); } } } }
void testJan() { { B_Parameters *b = new B_Parameters; //TObject *o = b; //CandidateParameters *c = b; //std::cout << (void*)b << " : " << (void*)c << " and " << (void*)o << endl; std::cout << b->gamma.minTrackDTheta << std::endl; std::cout << b->gamma.uid << std::endl; std::cout << b->gamma.GetName() << std::endl; } TFile* f = new TFile("janbug.root"); TTree* t; f->GetObject("evtTree2",t); JansEvent* j = new JansEvent(); t->SetBranchAddress("event", &j); t->GetEvent(0); std::cout << j->bList.GetEntries() << std::endl; B_Parameters *b = dynamic_cast<B_Parameters*>(j->bList[0]); //std::cout << (void*)j->bList[0] << " vs " << (void*)b << endl; std::cout << b->gamma.minTrackDTheta << std::endl; std::cout << b->gamma.uid << std::endl; std::cout << b->gamma.GetName() << std::endl; }
int makeOtherRhoGraph(){ char title[100]; TH1D* hRhoD[40]; TH1D* hRhoM[40]; TCanvas* canv[40]; TFile *file; TFile *file1; for(int i=1; i<40;i++){ sprintf(title,"RhoVtxBinned/RhoVtxBinned%i_PF_data.root",i); file = TFile::Open(title); sprintf(title,"hRhoVtxBinned%i",i); file->GetObject(title,hRhoD[i]); sprintf(title,"RhoVtxBinned/RhoVtxBinned%i_PF_mc.root",i); file1 = TFile::Open(title); sprintf(title,"hRhoVtxBinned%i",i); file1->GetObject(title,hRhoM[i]); hRhoM[i]->Scale(hRhoD[i]->Integral()/hRhoM[i]->Integral()); sprintf(title,"Rho (data and MC) for #Vtx = %i ",i); canv[i] = DrawComparison(hRhoD[i], hRhoM[i],title,"","Rho", 1); sprintf(title,"RhoVtxBinned/RhoComparisonVtxBinned%i.pdf",i); canv[i]->Print(title); delete file; delete file1; } return 0; }
void print_events(const char* filename) { TFile* file = new TFile(filename, "read"); TTree* tree = NULL; file->GetObject("MARLEY_event_tree", tree); if (!tree) { std::cout << "MARLEY event tree not found" << '\n'; return; } marley::Event* ev = new marley::Event; tree->SetBranchAddress("event", &ev); marley::Particle* fp = NULL; size_t num_entries = tree->GetEntries(); for (size_t i = 0; i < num_entries; ++i) { tree->GetEntry(i); print_event_info(*ev, i); } }
Zprime_Py8::Zprime_Py8(TChain *chain) : fChain(0) , _evtCtr(0) , _evtFreq(100) , h_nsigparts(0) , h_etasigparts(0) , h_ptsigparts(0) , h_nallparts(0) , h_etaallparts(0) , h_ptallparts(0) , h_npupparts(0) , h_etapupparts(0) , h_ptpupparts(0) { if (chain == 0) { TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject("signal_Zprime.root"); if (!f || !f->IsOpen()) { f = new TFile("signal_Zprime.root"); } f->GetObject("Zprime_Py8",chain); } Init(chain); }
void draw_MA(int selection = 1, int choice = 0, bool poster = false, double normalised = false) { // choice = 0 Track Range // choice = 1 CosTheta // choice = 2 Phi // selection = 1 Christoph selection // selection = 2 Xiao selection const double BASELINE_POT = 2.300468e+20; double MA_POT = 2.000320e+20; // Ma selection I if (selection == 2) MA_POT = 2.252332e+20; // Ma selection II const double NOMINAL_POT = 2.2e20; // changed to 2.2e20 from 6.6e20 // Define colours...but I am not using them... const Color_t kTotalMCColor = kRed; const Color_t kTotalMCErrorBandColor = kRed-10; const Color_t kNueSignalColor = kViolet-6; const Color_t kNCBackgroundColor = kBlue; const Color_t kBeamNueBackgroundColor = kMagenta; const Color_t kNumuBackgroundColor = kGreen+2; const Color_t kNormalHierarchyColor = kBlue; const Color_t kInvertedHierarchyColor = kRed; const Style_t k90PercentConfidenceStyle = kSolid; const Style_t k68PercentConfidenceStyle = 7; ///< Dashed // for Selection I TFile* file = new TFile("./histograms_MA_trkrange_costheta_phi.root"); // for Selection II TFile* fileOriginal = new TFile("./MCOriginalnew.root"); TFile* fileM_A = new TFile("./MCM_Anew.root"); TH1F *histoPmu, *histoPmu_MA; if (selection == 1) { if (choice == 0) { file->GetObject("Track RangeMC Prodgenie BNB Nu Cosmic", histoPmu); file->GetObject("Track RangeMC Prodgenie BNB Nu Cosmic M_A", histoPmu_MA); } else if (choice == 1) { file->GetObject("cos#theta-AngleMC Prodgenie BNB Nu Cosmic", histoPmu); file->GetObject("cos#theta-AngleMC Prodgenie BNB Nu Cosmic M_A", histoPmu_MA); } else if (choice == 2) { file->GetObject("#phi-AngleMC Prodgenie BNB Nu Cosmic", histoPmu); file->GetObject("#phi-AngleMC Prodgenie BNB Nu Cosmic M_A", histoPmu_MA); } else cout << "Not a valid choice." << endl; } else if (selection == 2) { if (choice == 0) { fileOriginal->GetObject("SelectedFinalTrackLengthAll", histoPmu); fileM_A->GetObject("SelectedFinalTrackLengthAllWeighted", histoPmu_MA); } else if (choice == 1) { fileOriginal->GetObject("SelectedFinalTrackCorrectedCosZAll", histoPmu); fileM_A->GetObject("SelectedFinalTrackCorrectedCosZAllWeighted", histoPmu_MA); } else if (choice == 2) { fileOriginal->GetObject("SelectedFinalTrackCorrectedPhiAll", histoPmu); fileM_A->GetObject("SelectedFinalTrackCorrectedPhiAllWeighted", histoPmu_MA); } else cout << "Not a valid choice." << endl; } else cout << "Not a valid choice." << endl; cout << "histoPmu integral: " << histoPmu->Integral() << endl; cout << "histoPmu_MA integral: " << histoPmu_MA->Integral() << endl; histoPmu->Sumw2(); // just to be sure histoPmu_MA->Sumw2(); // just to be sure // POt scaling histoPmu->Scale(NOMINAL_POT/BASELINE_POT); histoPmu_MA->Scale(NOMINAL_POT/MA_POT); double histoPmu_Int = histoPmu->Integral(); double histoPmu_MA_Int = histoPmu_MA->Integral(); if (normalised) { histoPmu->Scale(1./histoPmu_Int); histoPmu_MA->Scale(1./histoPmu_MA_Int); } // Calculate integrals and print differences cout << "Integral histoPmu: " << histoPmu->Integral() << endl; cout << "Integral histoPmu_MA: " << histoPmu_MA->Integral() << endl; cout << "Difference w.r.t. histoPmu (%):" << endl; cout << "histoPmu_MA: " << (histoPmu_MA->Integral()-histoPmu->Integral())/(histoPmu->Integral())*100. << endl; cout << endl << endl << "Difference w.r.t. histoPmu (%) -- bin by bin -- MA" << endl; for (int i = 0; i < histoPmu->GetNbinsX(); i++) { cout << "Bin: " << i << " " << (histoPmu_MA->GetBinContent(i)-histoPmu->GetBinContent(i))/(histoPmu->GetBinContent(i))*100. << endl; } // Define the Canvas TCanvas *c; if (!poster) c = new TCanvas("c", "canvas", 800, 800); if (poster && choice == 0) c = new TCanvas("c", "canvas", 0,45,1164,907); if (poster && choice == 1) c = new TCanvas("c", "canvas", 0,45,800,907); //c->SetFillStyle(4000); // Transparent //c->SetFrameFillStyle(4000); // Transparent // Upper plot will be in pad1 TPad *pad1 = new TPad("pad1", "pad1", 0, 0.25, 1, 1.0); //pad1->SetFillStyle(4000); // Transparent //pad1->SetFrameFillStyle(4000); // Transparent pad1->SetBottomMargin(0); // Upper and lower plot are joined pad1->SetRightMargin(0.05); pad1->SetGridx(); // Vertical grid pad1->Draw(); // Draw the upper pad: pad1 pad1->cd(); // pad1 becomes the current pad histoPmu_MA->SetMinimum(0.0001); // Otherwise 0 label overlaps histoPmu->SetMinimum(0.0001); // Otherwise 0 label overlaps histoPmu_MA->SetStats(0); // No statistics on upper plot histoPmu->SetStats(0); // No statistics on upper plot // Define plots range based on the quantity plotted if (choice == 0) histoPmu_MA->GetXaxis()->SetRangeUser(0., 700.); if (choice == 1 && selection == 1) histoPmu_MA->GetXaxis()->SetRangeUser(0., 1.); if (choice == 1 && selection == 2) histoPmu_MA->GetXaxis()->SetRangeUser(0., 1.); if (choice == 2 && selection == 1) histoPmu_MA->GetXaxis()->SetRangeUser(-TMath::Pi(), TMath::Pi()); if (choice == 2 && selection == 2) histoPmu_MA->GetXaxis()->SetRangeUser(-3., 3.); if (choice == 1 && selection == 1) histoPmu_MA->GetYaxis()->SetRangeUser(0.0001, 4500.); if (choice == 1 && selection == 2) histoPmu_MA->GetYaxis()->SetRangeUser(0.0001, 5000.); if (choice == 2 && selection == 1) histoPmu_MA->GetYaxis()->SetRangeUser(240, 650.); if (choice == 2 && selection == 2) histoPmu_MA->GetYaxis()->SetRangeUser(300, 1500.); // Draw! histoPmu_MA->Draw("E2"); // Draw error bars only TH1F * test2 = (TH1F*)histoPmu_MA->Clone("test2"); test2->SetLineColor(kGreen+2); test2->Draw("same histo"); // Draw the histo line now histoPmu->Draw("same E2"); // Draw error bars only TH1F * test = (TH1F*)histoPmu->Clone("test"); test->Draw("same histo"); test->SetLineColor(kTotalMCColor); // Draw the histo line now // Change titles histoPmu_MA->GetYaxis()->SetTitle("Selected Events"); histoPmu_MA->SetTitle(""); if (choice == 1 && selection == 1) histoPmu_MA->GetXaxis()->SetTitle("cos#theta"); if (choice == 2 && selection == 1) histoPmu_MA->GetXaxis()->SetTitle("#phi angle [rad]"); if (choice == 0 && selection == 2) histoPmu_MA->GetXaxis()->SetTitle("Track Length [cm]"); if (choice == 1 && selection == 2) histoPmu_MA->GetXaxis()->SetTitle("cos#theta"); if (choice == 2 && selection == 2) histoPmu_MA->GetXaxis()->SetTitle("#phi angle [rad]"); uBooNESimulation_2(); // Simulation tag, this is defined in /nashome/m/mdeltutt/rootlogon.C // TLatex double x = 0.84;//0.839599,0.52 double y = 0.52; double size = 25; int color = 1; int font = 43; int align = 32; TLatex *latex; if(selection == 1) latex = new TLatex(x, y, "#splitline{All events passing}{Selection I}"); if(selection == 2) latex = new TLatex(x, y, "#splitline{All events passing}{Selection II}"); latex->SetNDC(); latex->SetTextSize(size); latex->SetTextColor(color); latex->SetTextFont(font); latex->SetTextAlign(align); latex->Draw(); // Do not draw the Y axis label on the upper plot and redraw a small // axis instead, in order to avoid the first label (0) to be clipped. (THIS SHOULDN'T BE NECESSARY NOW) //histoPmu->GetYaxis()->SetLabelSize(0.); //TGaxis *axis = new TGaxis( -5, 20, -5, 220, 20,220,510,""); //axis->SetLabelFont(43); // Absolute font size in pixel (precision 3) //axis->SetLabelSize(15); //axis->Draw(); // Legend for the upper plot leg = new TLegend(0.5964912,0.6266667,0.8922306,0.8348387,NULL,"brNDC");//0.65,0.6,.85,0.87); leg->SetTextFont(42); leg->SetBorderSize(0); //leg->SetFillStyle(0); // Transparent //leg->SetHeader(""); leg->AddEntry(histoPmu, "M_{A}^{CCQE} = 0.99 GeV"); leg->AddEntry(histoPmu_MA, "M_{A}^{CCQE} = 1.35 GeV"); leg->Draw(); // LOWER plot will be in pad c->cd(); // Go back to the main canvas before defining pad2 TPad *pad2 = new TPad("pad2", "pad2", 0, 0.005, 1, 0.25); //pad2->SetFrameFillStyle(4000); // Transparent //pad2->SetFillStyle(4000); // Transparent pad2->SetTopMargin(0); pad2->SetBottomMargin(0.3); // Leave some space for the X axis title if (poster) pad2->SetBottomMargin(0.4); // Leave some space for the X axis title pad2->SetRightMargin(0.05); pad2->SetGridx(); // vertical grid pad2->Draw(); pad2->cd(); // pad2 becomes the current pad // Define the first ratio plot TH1F *ratio_MA = (TH1F*)histoPmu_MA->Clone("ratio_MA"); ratio_MA->SetMinimum(0.4); // Define Y .. ratio_MA->SetMaximum(2.1); // .. range ratio_MA->Sumw2(); ratio_MA->SetStats(0); // No statistics on lower plot ratio_MA->Divide(histoPmu); ratio_MA->SetLineWidth(2); ratio_MA->SetLineColor(kGreen+2); if (choice == 0) ratio_MA->GetXaxis()->SetRangeUser(0., 700.); if (choice == 1) ratio_MA->GetXaxis()->SetRangeUser(0., 1.); if (choice == 2 && selection == 1) ratio_MA->GetXaxis()->SetRangeUser(-TMath::Pi(), TMath::Pi()); if (choice == 2 && selection == 2) ratio_MA->GetXaxis()->SetRangeUser(-3., 3.); // Draw! ratio_MA->Draw("E2"); // Draw error bars only TH1F * test4 = (TH1F*)ratio_MA->Clone("test4"); test4->SetLineColor(kGreen+2); test4->Draw("same histo"); // Draw the histo line now //********************** // // Settings // //********************** // h1 settings histoPmu->SetLineColor(kRed); histoPmu->SetLineWidth(2); histoPmu->SetFillColor(kTotalMCErrorBandColor); // h2 settings histoPmu_MA->SetLineColor(kGreen+2); histoPmu_MA->SetLineWidth(2); histoPmu_MA->SetFillColor(29); histoPmu_MA->GetYaxis()->CenterTitle(); histoPmu_MA->GetYaxis()->SetTitleSize(35); histoPmu_MA->GetYaxis()->SetTitleFont(43); histoPmu_MA->GetYaxis()->SetTitleOffset(1.14); // Ratio plot (ratio_MA) settings ratio_MA->SetTitle(""); // Remove the ratio title ratio_MA->SetFillColor(29); // Y axis ratio plot settings ratio_MA->GetYaxis()->SetTitle("Ratio"); ratio_MA->GetYaxis()->CenterTitle(); ratio_MA->GetYaxis()->SetNdivisions(505); ratio_MA->GetYaxis()->SetTitleSize(35); ratio_MA->GetYaxis()->SetTitleFont(43); ratio_MA->GetYaxis()->SetTitleOffset(.75); ratio_MA->GetYaxis()->SetLabelFont(43); // Absolute font size in pixel (precision 3) ratio_MA->GetYaxis()->SetLabelSize(15); // X axis ratio plot settings ratio_MA->GetXaxis()->CenterTitle(); ratio_MA->GetXaxis()->SetTitleSize(35); ratio_MA->GetXaxis()->SetTitleFont(43); ratio_MA->GetXaxis()->SetTitleOffset(3.0); ratio_MA->GetXaxis()->SetLabelFont(43); // Absolute font size in pixel (precision 3) ratio_MA->GetXaxis()->SetLabelSize(20); // Draw line at 1 in ratio plot TLine *line; if (choice == 0 && selection == 1) line = new TLine(0,1,726,1); if (choice == 0 && selection == 2) line = new TLine(0,1,700,1); if (choice == 1) line = new TLine(0,1,1,1); if (choice == 2) line = new TLine(-TMath::Pi(),1,TMath::Pi(),1); if (choice == 2 && selection == 2) line = new TLine(-TMath::Pi(),1,TMath::Pi(),1); line->SetLineColor(kBlack); line->SetLineStyle(9); // dashed line->Draw(); }