void setLogz(TCanvas *c, bool on = true) { c->Modified(); c->Update(); //gSystem->ProcessEvents(); TObject *obj; TIter next(c->GetListOfPrimitives()); while ((obj = next())) { if (obj->InheritsFrom(TVirtualPad::Class())) { TVirtualPad *pad = (TVirtualPad*)obj; pad->Modified(); pad->Update(); pad->SetLogz(on); pad->Modified(); pad->Update(); } } }
/** * * * @param o * @param useWeights * @param correct * * @ingroup pwglf_forward_scripts_tests */ void TestPoisson(Double_t o=.3, bool useWeights=false, bool correct=true) { const char* load = "$ALICE_PHYSICS/PWGLF/FORWARD/analysis2/scripts/LoadLibs.C"; if (!gROOT->GetClass("AliAODForwardMult")) { gROOT->Macro(load); gROOT->GetInterpreter()->UnloadFile(gSystem->ExpandPathName(load)); } // --- Parameters of this script ----------------------------------- Int_t nBin = 5; // Our detector matrix size Int_t nMax = TMath::Max(Int_t(nBin * nBin * o + .5)+nBin/2,nBin); Int_t nEv = 10000; // Number of events Double_t mp = o; // The 'hit' probability TH2D* base = new TH2D("base", "Basic histogram", nBin,-.5, nBin-.5, nBin, -.5, nBin-.5); base->SetXTitle("#eta"); base->SetYTitle("#varphi"); base->SetDirectory(0); base->SetOption("colz"); Int_t tN1=nMax; Double_t tMin1; Double_t tMax1; Int_t tN2=nMax*10; Double_t tMin2; Double_t tMax2=nMax; MakeIntegerAxis(tN1, tMin1, tMax1); MakeIntegerAxis(tN2, tMin2, tMax2); TH2D* corr = new TH2D("comp", "Comparison", tN1, tMin1, tMax1, tN2, tMin2, tMax2); corr->SetXTitle("Input"); corr->SetYTitle("Poisson"); corr->SetDirectory(0); corr->SetOption("colz"); corr->SetStats(0); TLine* lcorr = new TLine(0, 0, tMax2, tMax2); Int_t mm = TMath::Max(Int_t(nBin * o + .5),nBin/2); tN2=mm*10; tMax2 = mm; MakeIntegerAxis(tN2, tMin2, tMax2); Info("", "Making mean w/nbins=%d,range=[%f,%f]", tN2, tMin2, tMax2); TH2D* mean = new TH2D("mean", "Mean comparison", tN2, tMin2, tMax2, tN2, tMin2, tMax2); mean->SetXTitle("Input"); mean->SetYTitle("Poisson"); mean->SetDirectory(0); mean->SetOption("colz"); mean->SetStats(0); TLine* lmean = new TLine(tMin2, tMin2, tMax2, tMax2); TH1D* dist = new TH1D("dist", "Distribution of hits", tN1, tMin1, tMax1); dist->SetXTitle("s"); dist->SetYTitle("P(s)"); dist->SetFillColor(kRed+1); dist->SetFillStyle(3001); dist->SetDirectory(0); TH1D* diff = new TH1D("diff", "P-T", 100, -25, 25); diff->SetXTitle("Difference"); diff->SetFillColor(kRed+1); diff->SetFillStyle(3001); diff->SetYTitle("Prob"); AliPoissonCalculator* c = new AliPoissonCalculator("ignored"); c->Init(nBin ,nBin); for (Int_t i = 0; i < nEv; i++) { c->Reset(base); base->Reset(); for (Int_t iEta = 0; iEta < nBin; iEta++) { for (Int_t iPhi = 0; iPhi < nBin; iPhi++) { // Throw a die Int_t m = gRandom->Poisson(mp); dist->Fill(m); // Fill into our base histogram base->Fill(iEta, iPhi, m); // Fill into poisson calculator c->Fill(iEta, iPhi, m > 0, (useWeights ? m : 1)); } } // Calculate the result TH2D* res = c->Result(correct); // Now loop and compare Double_t mBase = 0; Double_t mPois = 0; for (Int_t iEta = 0; iEta < nBin; iEta++) { for (Int_t iPhi = 0; iPhi < nBin; iPhi++) { Double_t p = res->GetBinContent(iEta, iPhi); Double_t t = base->GetBinContent(iEta, iPhi); mBase += t; mPois += p; corr->Fill(t, p); diff->Fill(p-t); } } Int_t nn = nBin * nBin; mean->Fill(mBase / nn, mPois / nn); } TCanvas* cc = new TCanvas("c", "c", 900, 900); cc->SetFillColor(0); cc->SetFillStyle(0); cc->SetBorderMode(0); cc->SetRightMargin(0.02); cc->SetTopMargin(0.02); cc->Divide(2,2); TVirtualPad* pp = cc->cd(1); pp->SetFillColor(0); pp->SetFillStyle(0); pp->SetBorderMode(0); pp->SetRightMargin(0.15); pp->SetTopMargin(0.02); pp->SetLogz(); pp->SetGridx(); pp->SetGridy(); corr->Draw(); lcorr->Draw(); pp = cc->cd(2); pp->SetFillColor(0); pp->SetFillStyle(0); pp->SetBorderMode(0); pp->SetRightMargin(0.02); pp->SetTopMargin(0.02); #if 0 c->GetMean()->Draw(); #elif 1 pp->SetLogy(); diff->Draw(); #elif 1 c->GetOccupancy()->Draw(); #else pp->SetLogy(); dist->SetStats(0); dist->Scale(1. / dist->Integral()); dist->Draw(); TH1D* m1 = c->GetMean(); m1->Scale(1. / m1->Integral()); m1->Draw("same"); Double_t eI; Double_t ii = 100 * dist->Integral(2, 0); TLatex* ll = new TLatex(.97, .85, Form("Input #bar{m}: %5.3f", mp)); ll->SetNDC(); ll->SetTextFont(132); ll->SetTextAlign(31); ll->Draw(); ll->DrawLatex(.97, .75, Form("Result #bar{m}: %5.3f", dist->GetMean())); ll->DrawLatex(.97, .65, Form("Occupancy: #int_{1}^{#infty}P(s)ds = %6.2f%%", ii)); #endif pp = cc->cd(3); pp->SetFillColor(0); pp->SetFillStyle(0); pp->SetBorderMode(0); pp->SetRightMargin(0.15); pp->SetTopMargin(0.02); pp->SetGridx(); pp->SetGridy(); c->GetCorrection()->Draw(); pp = cc->cd(4); pp->SetFillColor(0); pp->SetFillStyle(0); pp->SetBorderMode(0); pp->SetRightMargin(0.15); pp->SetTopMargin(0.02); pp->SetLogz(); pp->SetGridx(); pp->SetGridy(); mean->Draw(); lmean->Draw(); cc->cd(); }
void TestSPD(const TString& which, Double_t nVar=2) { TFile* file = TFile::Open("forward.root", "READ"); if (!file) return; Bool_t spd = which.EqualTo("spd", TString::kIgnoreCase); TList* l = 0; if (spd) l = static_cast<TList*>(file->Get("CentralSums")); else l = static_cast<TList*>(file->Get("ForwardSums")); if (!l) { Warning("", "%sSums not found", spd ? "Central" : "Forward"); return; } TList* ei = static_cast<TList*>(l->FindObject("fmdEventInspector")); if (!l) { Warning("", "fmdEventInspector not found"); return; } TObject* run = ei->FindObject("runNo"); if (!run) Warning("", "No run number found"); ULong_t runNo = run ? run->GetUniqueID() : 0; TH2* h = 0; if (spd) h = static_cast<TH2*>(l->FindObject("nClusterVsnTracklet")); else { TList* den = static_cast<TList*>(l->FindObject("fmdDensityCalculator")); if (!den) { Error("", "fmdDensityCalculator not found"); return; } TList* rng = static_cast<TList*>(den->FindObject(which)); if (!rng) { Error("", "%s not found", which.Data()); return; } h = static_cast<TH2*>(rng->FindObject("elossVsPoisson")); } if (!h) { Warning("", "%s not found", spd ? nClusterVsnTracklet : "elossVsPoisson"); return; } gStyle->SetOptFit(1111); gStyle->SetOptStat(0); TCanvas* c = new TCanvas("c", Form("Run %u", runNo)); c->Divide(2,2); TVirtualPad* p = c->cd(1); if (spd) { p->SetLogx(); p->SetLogy(); } p->SetLogz(); h->Draw("colz"); TObjArray* fits = new TObjArray; h->FitSlicesY(0, 1, -1, 0, "QN", fits); TF1* mean = new TF1("mean", "pol1"); TF1* var = new TF1("var", "pol1"); // mean->FixParameter(0, 0); // var->FixParameter(0, 0); for (Int_t i = 0; i < 3; i++) { p = c->cd(2+i); if (spd) { p->SetLogx(); p->SetLogy(); } TH1* hh = static_cast<TH1*>(fits->At(i)); hh->Draw(); if (i == 0) continue; hh->Fit((i == 1? mean : var), "+Q"); } TGraphErrors* g1 = new TGraphErrors(h->GetNbinsX()); g1->SetFillColor(kBlue-10); g1->SetFillStyle(3001); g1->SetLineStyle(1); TGraph* u1 = new TGraph(h->GetNbinsX()); TGraph* l1 = new TGraph(h->GetNbinsX()); u1->SetLineColor(kBlue+1); l1->SetLineColor(kBlue+1); u1->SetName("u1"); l1->SetName("l1"); TGraphErrors* g2 = new TGraphErrors(h->GetNbinsX()); g2->SetFillColor(kRed-10); g2->SetFillStyle(3001); g2->SetLineStyle(2); TGraph* u2 = new TGraph(h->GetNbinsX()); TGraph* l2 = new TGraph(h->GetNbinsX()); u2->SetLineColor(kRed+1); l2->SetLineColor(kRed+1); u2->SetName("u2"); l2->SetName("l2"); for (Int_t i = 1; i <= h->GetNbinsX(); i++) { Double_t x = hh->GetXaxis()->GetBinCenter(i); Double_t y = mean->Eval(x); Double_t e = var->Eval(y); Double_t e1 = nVar * e; if (spd) e1 *= TMath::Log10(e); // Printf("%10e -> %10e +/- %10e", x, y, ee); g1->SetPoint(i-1, x, y); g1->SetPointError(i-1, 0, e1); u1->SetPoint(i-1, x, y+e1); l1->SetPoint(i-1, x, y-e1); // Printf("%3d: %f -> %f +/- %f", i, x, y, ee); Double_t e2 = nVar*0.05*x; g2->SetPoint(i-1, x, x); g2->SetPointError(i-1, 0, e2); u2->SetPoint(i-1, x, x+e2); l2->SetPoint(i-1, x, x-e2); } p = c->cd(1); c->Clear(); c->cd(); c->SetLogz(); h->Draw("colz"); g1->Draw("3 same"); u1->Draw("l same"); l1->Draw("l same"); g2->Draw("3 same"); u2->Draw("l same"); l2->Draw("l same"); Double_t ly = 0.9; Double_t dy = 0.06; TLatex* ltx = new TLatex(0.15, ly, Form("#LTy#GT = %f + %f x", mean->GetParameter(0), mean->GetParameter(1))); ltx->SetNDC(); ltx->SetTextSize(dy); ltx->SetTextAlign(13); ltx->Draw(); ly -= dy + 0.01; ltx->DrawLatex(0.15, ly, Form("#sigma_{y} = %f + %f x", var->GetParameter(0), var->GetParameter(1))); ly -= dy + 0.01; ltx->DrawLatex(0.15, ly, Form("#delta = %f #sigma %s", nVar, (spd ? "log_{10}(#sigma" : ""))); }
void Energy() { /*****************************************************************/ // Prepare the canvas gStyle->SetOptStat("ne"); TCanvas *canvas = (TCanvas *) gROOT->GetListOfCanvases()->At(0); canvas->Divide(2,1,0.001,0.001,10); /*****************************************************************/ char name[256]; const unsigned int kBL_B =1; const unsigned int kBL_C =1; const unsigned int kBR_B =1; const unsigned int kBR_C =2; const unsigned int kML_B =1; const unsigned int kML_C =3; const unsigned int kMC_B =1; const unsigned int kMC_C =4; const unsigned int kMR_B =2; const unsigned int kMR_C =1; const unsigned int kTL_B =2; const unsigned int kTL_C =2; const unsigned int kTR_B =2; const unsigned int kTR_C =3; const unsigned int kSiPM_B = kTR_B; const unsigned int kSiPM_C = kTR_C; const unsigned int kR9800_B = kMC_B; const unsigned int kR9800_C = kMC_C; // SET PARAMETERS BELOW HERE unsigned int icrate = 1; unsigned int iboard = kSiPM_B; unsigned int ichannel = kSiPM_C; int rebinParameter = 16; int binsLeftOfPeak = 4; int binsRightOfPeak = 30; int binsToShow = 150; int ipad = 1; gStyle->SetOptFit(1111); canvas->cd(ipad++); sprintf(name,"sis3350_defna/h1_defna_area_crate_%02d_board_%02d_channel_%d",icrate,iboard,ichannel); TH1D *h1 = (TH1D*)getObject(name); if ( !h1 ) { printf("***ERROR! Cannot retrieve histogram [%s]\n",name); } else { h1->Rebin(rebinParameter); // h1->GetXaxis()->SetRangeUser(4000,14000); h1->SetLineColor( kBlue ); h1->SetLineWidth( 2 ); h1->Draw(); TF1* user = new TF1("user","[0]*exp(-0.5*((x-[1])/[2])**2)+[3]",0,100000); double peak = h1->GetMaximumBin(); printf("%f\n",h1->GetMaximum()); double meanguess = h1->GetBinCenter(peak); user->SetParameters(0.025*meanguess,meanguess,0.15*meanguess,1); user->SetParNames("Amp","Mean","Sigma","Bkg"); h1->Fit("user","","",h1->GetBinCenter(peak-binsLeftOfPeak),h1->GetBinCenter(peak+binsRightOfPeak)); h1->GetXaxis()->SetRange(peak-binsToShow,peak+binsToShow); printf("Mean/Sigma = (%f/%f)=%f\n",user->GetParameter(2), user->GetParameter(1),user->GetParameter(2)/user->GetParameter(1)); } TVirtualPad *pad = canvas->cd(ipad++); sprintf(name,"sis3350_hist_raw/h2_wf_crate_%02d_board_%02d_channel_%d",icrate,iboard,ichannel); TH2D *h2 = (TH2D*)getObject(name); if ( !h2 ) { printf("***ERROR! Cannot retrieve histogram [%s]\n",name); } else { h2->Draw("ColZ"); pad->SetLogz(); } }