#include "TFile.h" #include "TCanvas.h" #include "TStyle.h" #include "TH1.h" #include "TH2.h" #include "TH3.h" #include "TGaxis.h" #include "TRandom.h" #include "TLegend.h" #include "TPaveStats.h" #include "TGraph.h" #include "TSystem.h" #include "TTree.h" #include "TTreePlayer.h" #include "TF1.h" #include "TCut.h" #include "TPaletteAxis.h" #include "TFitResult.h" #include "TMath.h" double tmin=-5000; double tpeakmin=-2500; double tpeakmax=2500; double tmax=5000; void DrawVerticalLine(Double_t x) { TLine l; l.SetLineColor(kRed); l.SetLineStyle(10); l.SetLineWidth(1.); Double_t lm = gPad->GetLeftMargin(); Double_t rm = 1.-gPad->GetRightMargin(); Double_t tm = 1.-gPad->GetTopMargin(); Double_t bm = gPad->GetBottomMargin(); Double_t xndc = (rm-lm)*((x-gPad->GetUxmin())/(gPad->GetUxmax()-gPad->GetUxmin()))+lm; l.DrawLineNDC(xndc,bm,xndc,tm); } void DrawHorizontalLine(Double_t x) { TLine l; l.SetLineColor(kRed); l.SetLineStyle(10); l.SetLineWidth(1.); Double_t lm = gPad->GetLeftMargin(); Double_t rm = 1.-gPad->GetRightMargin(); Double_t tm = 1.-gPad->GetTopMargin(); Double_t bm = gPad->GetBottomMargin(); Double_t yndc = (rm-lm)*((x-gPad->GetUymin())/(gPad->GetUymax()-gPad->GetUymin()))+lm; l.DrawLineNDC(lm,yndc,rm,yndc); } void deltatbkgest() { float fillcolor=0.35; gStyle->SetFitFormat("8.6g"); gStyle->SetOptStat(111110); ofstream results; results.open("ResultsBackgroundRun0610.txt", ios::out); TFile *fin = TFile::Open("run0610.root"); fin->ls (); TGaxis::SetMaxDigits(3); if (fin == 0) { printf("Error: cannot open the file!\n"); } else { TTree *te=0; fin->GetObject("tree",te); gStyle->SetOptFit(); gStyle->SetOptStat(111110); te->SetLineColor(kBlue); TH1::StatOverflows(true); TCanvas *c01 = new TCanvas("c01","c01",1280,1024); c01->SetLogy(); TString string = TString::Format("t1-t0 >> htemp(1000, -5000, 5000)"); TCut coincidence = TString::Format("abs(t1-t0)<5000").Data(); TCut pulser0 = TString::Format("e2==0").Data(); TCut pulser1 = TString::Format("e3==0").Data(); TCut GePD = TString::Format("e0>0").Data(); TCut GeDD = TString::Format("e1>0").Data(); //te->Draw(string,coincidence && pulser0 && pulser1); te->Draw(string,coincidence && GePD && GeDD && pulser0 && pulser1); te->GetHistogram()->SetTitle(""); // TPaveText *t=new TPaveText(0.75,0.6,0.8,0.55,"brNDC"); te->SetScanField(0); TH1F *hgraph= (TH1F*)gPad->GetPrimitive("htemp"); hgraph->GetXaxis()->SetTitle("#DeltaT (ns)"); hgraph->GetYaxis()->SetTitle("Counts"); hgraph->GetYaxis()->SetTitleSize(40); hgraph->GetYaxis()->SetTitleFont(43); hgraph->GetYaxis()->SetTitleOffset(1.1); hgraph->GetYaxis()->SetLabelFont(43); hgraph->GetYaxis()->SetLabelSize(40); hgraph->GetXaxis()->SetTitleSize(40); hgraph->GetXaxis()->SetTitleFont(43); hgraph->GetXaxis()->SetTitleOffset(1.1); hgraph->GetXaxis()->SetLabelFont(43); hgraph->GetXaxis()->SetLabelSize(40); hgraph->SetFillStyle(3005); hgraph->SetFillColorAlpha(kBlue, fillcolor); DrawVerticalLine(-2500.); DrawVerticalLine(2500.); DrawHorizontalLine(10); // float threshold = 2000; // auto lnThreshold = new TLine(0,threshold, gPad->GetUxmax(),threshold); // lnThreshold->SetLineColor(kRed); // lnThreshold->SetLineStyle(10); // lnThreshold->SetLineWidth(2.); // maybe // lnThreshold->Draw(); hgraph->SetStats(0); hgraph->Draw(); hgraph->SetName(""); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn c01->Update(); // c01->SetLogy(); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn c01->Update(); /*TLegend* leg = new TLegend(0.25, 0.7, .35, .75); leg->SetHeader("Legend"); leg->SetNColumns(1); leg->AddEntry(hgraph, "MC", "l"); leg->Draw();*/ c01->Update(); gPad->Modified(); gPad->Update(); /*TPaveStats *stats = (TPaveStats*)hgraph->GetListOfFunctions()->FindObject("stats"); stats->SetTextColor(kBlue); stats->SetX1NDC(0.80); stats->SetX2NDC(0.98); stats->SetY1NDC(0.83); stats->SetY2NDC(0.98); //stats->AddText(TString::Format("Integral = %g", integral)); stats->DrawClone();*/ gPad->Update(); gPad->Update(); c01->Print("DeltaT[-5us,5us]run0610delay_bkgestimation.png"); int BinMin = hgraph->GetXaxis()-> FindBin(tmin); int BinMax = hgraph->GetXaxis()-> FindBin(tmax); int BinPeakMin = hgraph->GetXaxis()-> FindBin(tpeakmin); int BinPeakMax = hgraph->GetXaxis()-> FindBin(tpeakmax); double TotArea= hgraph->Integral(BinMin,BinMax); double BkgAreaSx= hgraph->Integral(BinMin,BinPeakMin); double BkgAreaDx= hgraph->Integral(BinPeakMax,BinMax); double BkgArea= BkgAreaSx+BkgAreaDx; double PeakArea= hgraph->Integral(BinPeakMin,BinPeakMax); double texternal=abs(tpeakmin-tmin)+abs(tmax-tpeakmax); double tpeak=abs(tpeakmax-tpeakmin); double PeakBkgArea= (BkgArea/texternal)*tpeak; double PeakBkgPercentage= 100*PeakBkgArea/PeakArea; double TrueEventsArea= PeakArea-PeakBkgArea; results << "****************Background Estimation run0610 ****************"<< endl; results << "Time min= " << tmin << endl; results << "Time peak min= " << tpeakmin << endl; results << "Time peak max= " << tpeakmax << endl; results << "Time max= " << tmax << endl; results << "Time background external= " << texternal << endl; results << "Time peak= " << tpeak << endl; results << "Total Area= " << TotArea << endl; results << "Background Area Sx= " << BkgAreaSx << endl; results << "Background Area Dx= " << BkgAreaDx << endl; results << "Background Area= " << BkgArea << endl; results << "Peak Area= " << PeakArea << endl; results << "Peak Background Area= " << PeakBkgArea<< endl; results << "Peak Background Area (%)= 100*PeakBkgArea/PeakArea= " << PeakBkgPercentage << endl; results << "True Events area= " << TrueEventsArea << endl; delete c01; } }