void quickWorldModelTest() { gSystem->Load("lib/libPropagation.so"); // BedmapTable *iceTable = new BedmapTable (RyansCons::kBathymetry); WorldModel *myWorld = new WorldModel(); TH2F *iceHist = new TH2F("iceHist","Ice Thickness",1000,-3e6,3e6,1000,-3e6,3e6); TH2F *iceHist2 = new TH2F("iceHist2","Ice Thickness (Bedmap)",1000,-3e6,3e6,1000,-3e6,3e6); TH2F *surfaceHist = new TH2F("surfaceHist","Surface",1000,-3e6,3e6,1000,-3e6,3e6); // int goodFlag; for(int binx=1;binx<=iceHist->GetNbinsX();binx++) { Double_t x=iceHist->GetXaxis()->GetBinCenter(binx); for(int biny=1;biny<=iceHist->GetNbinsY();biny++) { Double_t y=iceHist->GetYaxis()->GetBinCenter(biny); Double_t value=myWorld->getCrust2Data(x,y,RyansCons::kThicknessOfIce); iceHist->SetBinContent(binx,biny,value); value=myWorld->getIceThickness(x,y); iceHist2->SetBinContent(binx,biny,value); value=myWorld->getSurface(x,y); surfaceHist->SetBinContent(binx,biny,value/1e6); if(value>1e7 || value<1e6) cout << x << "\t" << y << "\t" << value << endl; } } TCanvas *can = new TCanvas("can","can"); can->Divide(1,2); can->cd(1); iceHist->Draw("colz"); can->cd(2); iceHist2->Draw("colz"); TCanvas *can2 = new TCanvas("can2","can2"); surfaceHist->Draw("colz"); }
TH2F *hardlimit(TH2F *limit) { TH2F *co = (TH2F*)limit->Clone("hcopy"); for(int i=1;i<=limit->GetNbinsX();i++) { for(int j=1;j<=limit->GetNbinsY();j++) { if(limit->GetBinContent(i,j)<1&&limit->GetBinContent(i,j)>0) co->SetBinContent(i,j,1); else co->SetBinContent(i,j,0); } } co->GetZaxis()->SetRangeUser(0,100);//this is to make the exclusion shape blue :-) return co; }
void makeShapeSys2DDataset() { TFile* file = new TFile("ShapeSys2D.root", "RECREATE"); TH2F* signal = new TH2F("signal", "signal", 2,0,2, 2,0,2); signal->SetBinContent(1, 1, 10); signal->SetBinContent(2, 1, 10); signal->SetBinContent(1, 2, 20); signal->SetBinContent(2, 2, 20); // Background 1 TH2F* background1 = new TH2F("background1", "background1", 2,0,2, 2,0,2); background1->SetBinContent(1, 1, 100); background1->SetBinContent(2, 1, 100); background1->SetBinContent(1, 2, 10); background1->SetBinContent(2, 2, 10); // Background 1 Error TH2F* bkg1ShapeError = new TH2F("bkg1ShapeError", "bkg1ShapeError", 2,0,2, 2,0,2); bkg1ShapeError->SetBinContent(1, 1, .10); // 10% bkg1ShapeError->SetBinContent(2, 1, .15); // 15% bkg1ShapeError->SetBinContent(1, 2, .10); // 10% bkg1ShapeError->SetBinContent(2, 2, .15); // 15% // Background 2 TH2F* background2 = new TH2F("background2", "background2", 2,0,2, 2,0,2); background2->SetBinContent(1, 1, 10); background2->SetBinContent(2, 1, 10); background2->SetBinContent(1, 2, 100); background2->SetBinContent(2, 2, 100); // Background 2 Error TH2F* bkg2ShapeError = new TH2F("bkg2ShapeError", "bkg2ShapeError", 2,0,2, 2,0,2); bkg2ShapeError->SetBinContent(1, 1, .05); // 5% bkg2ShapeError->SetBinContent(2, 1, .20); // 20% bkg2ShapeError->SetBinContent(1, 2, .05); // 5% bkg2ShapeError->SetBinContent(2, 2, .20); // 20% TH2F* data = new TH2F("data", "data", 2,0,2, 2,0,2); data->SetBinContent(1, 1, 122); data->SetBinContent(2, 1, 122); data->SetBinContent(1, 2, 132); data->SetBinContent(2, 2, 132); file->Write(); file->Close(); }
pair<TH2F*,TH2F*> Bin2DTree::fillWidths() /*****************************************************************/ { if(!m_gridConstraint) { cerr<<"ERROR: Bin2DLeaf.fillWidths(): Trying to fill histogram, but the binning is unknown. Define first the gridConstraint.\n"; exit(1); } TH2F* hWidthX = (TH2F*)m_gridConstraint->Clone("widthXFromTree"); TH2F* hWidthY = (TH2F*)m_gridConstraint->Clone("widthYFromTree"); int nbinsx = hWidthX->GetNbinsX(); int nbinsy = hWidthX->GetNbinsY(); map<Bin2DLeaf*, vector< pair<int,int> > > binsInLeaf; for(int bx=1;bx<nbinsx+1;bx++) { for(int by=1;by<nbinsy+1;by++) { double x = hWidthX->GetXaxis()->GetBinCenter(bx); double y = hWidthX->GetYaxis()->GetBinCenter(by); Bin2DLeaf* leaf = getLeaf(x, y); vector<Bin2DLeaf*> neighborLeaves = findNeighborLeaves(leaf); neighborLeaves.push_back(leaf); vector<Bin2DLeaf*>::iterator itLeaf = neighborLeaves.begin(); vector<Bin2DLeaf*>::iterator itELeaf = neighborLeaves.end(); double sumw = 0.; double sumwx = 0.; double sumwy = 0.; for(;itLeaf!=itELeaf;++itLeaf) { double xi = (*itLeaf)->getXCenter(); double yi = (*itLeaf)->getYCenter(); double dx = xi-x; double dy = yi-y; double wxi = (*itLeaf)->getXWidth(); double wyi = (*itLeaf)->getYWidth(); if(dx<0.05*wxi) dx = 0.05*wxi; if(dy<0.05*wyi) dy = 0.05*wyi; double dr2 = dx*dx+dy*dy; sumw += 1./dr2; sumwx += wxi/dr2; sumwy += wyi/dr2; } double widthx = sumwx/sumw; double widthy = sumwy/sumw; hWidthX->SetBinContent(bx,by,widthx); hWidthY->SetBinContent(bx,by,widthy); hWidthX->SetBinError(bx,by,0.); hWidthY->SetBinError(bx,by,0.); } } return make_pair(hWidthX, hWidthY); }
TH2F* make_exclusion_shape(TH2F *excl, int isprimary) { TH2F *exclusion = (TH2F*)excl->Clone("exclusion"); for(int i=1; i<(excl->GetNbinsX()+1); i++) { for(int j=1; j<(excl->GetNbinsY()+1); j++) { if(excl->GetBinContent(i,j)<1&&excl->GetBinContent(i,j)>0) exclusion->SetBinContent(i,j,0.01); else exclusion->SetBinContent(i,j,0); } } exclusion->SetLineColor(kBlue); exclusion->SetLineWidth(2); //exclusion->SetLineWidth(4); // paper style exclusion->SetLineStyle(isprimary); return exclusion; }
void testMVATrainerAnalysis() { using namespace PhysicsTools; setStyle(); MVAComputer mva("testMVAComputerEvaluate.mva"); Variable::Value values[3]; values[0].setName("x"); values[1].setName("y"); TH2F *f = new TH2F("discr", "Discriminator", 200, -10, 10, 200, -10, 10); f->SetXTitle("x"); f->SetYTitle("y"); TH2F *g = new TH2F("dx", "dD/dx", 200, -10, 10, 200, -10, 10); g->SetXTitle("x"); g->SetYTitle("y"); TH2F *h = new TH2F("dy", "dD/dy", 200, -10, 10, 200, -10, 10); h->SetXTitle("x"); h->SetYTitle("y"); for(double x = -10 + 0.05; x < 10; x += 0.1) { for(double y = -10 + 0.05; y < 10; y += 0.1) { values[0].setValue(x); values[1].setValue(y); double v = mva.deriv(values, values + 2); f->SetBinContent(f->FindBin(x, y), v); g->SetBinContent(g->FindBin(x, y), values[0].getValue()); h->SetBinContent(h->FindBin(x, y), values[1].getValue()); } } TCanvas *c1 = new TCanvas("c1"); c1->Divide(2, 2); c1->cd(1); f->SetStats(0); f->SetContour(511); f->Draw("colz"); c1->cd(3); g->SetStats(0); g->SetContour(511); g->Draw("colz"); c1->cd(4); h->SetStats(0); h->SetContour(511); h->Draw("colz"); }
RooHistPdf *nllToL(TH2F* hist){ TH2F *h = (TH2F*) hist->Clone(TString(hist->GetName())+"_L"); h->Reset(); Double_t min=1e20, max=0; for(Int_t iBinX=1; iBinX <= hist->GetNbinsX(); iBinX++){ for(Int_t iBinY=1; iBinY <= hist->GetNbinsY(); iBinY++){ Double_t binContent=hist->GetBinContent(iBinX, iBinY); if(min>binContent && binContent!=0) min=binContent; if(max<binContent) max=binContent; } } for(Int_t iBinX=1; iBinX <= hist->GetNbinsX(); iBinX++){ for(Int_t iBinY=1; iBinY <= hist->GetNbinsY(); iBinY++){ Double_t binContent=hist->GetBinContent(iBinX, iBinY); Double_t b = binContent <= 0 ? 0 : exp(-binContent+min+50); if(binContent != 0 && binContent-min<100) std::cout << iBinX << "\t" << iBinY << "\t" << binContent << "\t" << -binContent+min << "\t" << b << std::endl; //h->Fill(hist->GetXaxis()->GetBinLowEdge(iBinX), hist->GetYaxis()->GetBinLowEdge(iBinY),b); h->SetBinContent(iBinX, iBinY,b); } } RooRealVar *var1 = new RooRealVar("constTerm","",0.1); RooRealVar *var2 = new RooRealVar("alpha","",0.1); RooDataHist *dataHist = new RooDataHist(TString(hist->GetName())+"_dataHist",hist->GetTitle(), RooArgSet(*var1,*var2), h); RooHistPdf *histPdf = new RooHistPdf(TString(hist->GetName())+"_histPdf",hist->GetTitle(), RooArgSet(*var1,*var2), *dataHist); //delete dataHist; return histPdf; }
void write_func() { // create factory SmartFactory * fac = new SmartFactory("factory1"); // fill with histograms char hname[100]; for (int i = 0; i < 100; ++i) { sprintf(hname, hist_pattern, i); TH2F * h = fac->RegTH2<TH2F>(hname, "Histogram - loop", 100, -5, 5, 100, -5, 5); for (int j = 0; j < 100*100; ++j) h->SetBinContent(j+1, sqrt(j)); // sprintf(hname, can_pattern, i); // TCanvas * c = fac->RegCanvas(hname, "Canvas - loop", 800, 600); // c->cd(0); // h->Draw("colz"); bar(i); } fac->rename("renamed_factory"); fac->chdir("renamed_directory"); // list objects // fac->listRegisterdObjects(); // export factory to file fac->exportStructure("example_multi.root", true); }
void psf(){ gROOT->Reset(); int nbinx = 512; int nbiny = 512; TFile *fout = new TFile("psf.root","recreate"); TH2F *image = new TH2F("psf","psf",nbinx,-250.0,250.0,nbiny,-250.0,250.0); // FILE *fo; // if((fo=fopen("psf.dat","wb"))==NULL){ // std::cout << "error " << std::endl; // } // float xcenter = 0.05; // float ycenter =0.05; float xcenter = 0.0; float ycenter =0.0; float sum = 0.0; for(int i=1;i<=nbinx;i++){ for(int j=1;j<=nbiny;j++){ float a = image->GetXaxis()->GetBinCenter(i); float b = image->GetYaxis()->GetBinCenter(j); float r = TMath::Sqrt(TMath::Power(xcenter-a,2)+TMath::Power(ycenter-b,2)); float value = TMath::Gaus(r,0,8.0,kTRUE); // value = value * (1.+0.01*gRandom->Rndm()); sum = sum + value; image->SetBinContent(i,j,value); } } for(int i=1;i<=nbinx;i++){ for(int j=1;j<=nbiny;j++){ image->SetBinContent(i,j,image->GetBinContent(i,j)/sum); } } image->Write(); fout->Close(); // fclose(fo); }
/// /// Creates a fresh, independent copy of the input histogram. /// 2d version of TH1F* Utils::histHardCopy(). /// TH2F* Utils::histHardCopy(const TH2F* h, bool copyContent, bool uniqueName) { TString name = h->GetTitle(); if ( uniqueName ) name += getUniqueRootName(); TH2F* hNew = new TH2F(name, h->GetTitle(), h->GetNbinsX(), h->GetXaxis()->GetXmin(), h->GetXaxis()->GetXmax(), h->GetNbinsY(), h->GetYaxis()->GetXmin(), h->GetYaxis()->GetXmax()); for ( int k=1; k<=h->GetNbinsX(); k++ ) for ( int l=1; l<=h->GetNbinsY(); l++ ){ if ( copyContent ) hNew->SetBinContent(k, l, h->GetBinContent(k,l)); else hNew->SetBinContent(k, l, 0); } return hNew; }
/*=========================================================*/ Int_t putmat(Char_t *rn, Char_t *hn) { TH2F *hist; TFile *f2;; hist = (TH2F*)f1->Get(hn); for(Int_t ix=1;ix<=2048;ix++){ hist->SetBinContent(1,ix,0); hist->SetBinContent(ix,1,0); hist->SetBinContent(2,ix,0); hist->SetBinContent(ix,2,0); } f2 = new TFile(rn,"UPDATE"); hist->Write(); f2->ls(); f2->Close(); return 0; }
TH2F* cast_into_shape(TH2F *origin, TH2F *reference) { TH2F *newh = (TH2F*)reference->Clone(origin->GetName()); for(int ix=1;ix<=reference->GetNbinsX();ix++) { for(int iy=1;iy<=reference->GetNbinsY();iy++) { // reference->SetBinContent(ix,iy,origin->GetBinContent(ix,iy)); newh->SetBinContent(ix,iy,origin->GetBinContent(ix,iy)); } } return newh; }
TH2F *prof2d(TTree *tree, TString var1Name, TString var2Name, TString nllName, TString binning="(40,0,0.05,40,0,0.2)", bool delta=false){ var1Name.ReplaceAll("-","_"); var2Name.ReplaceAll("-","_"); // tree->Print(); TString histName="h"; std::cout << var1Name << "\t" << var2Name << "\t" << histName << std::endl; tree->Draw(var1Name+":"+var2Name+">>"+histName+binning); TH2F *hEntries = (TH2F*)gROOT->FindObject(histName); if(hEntries==NULL) return NULL; //std::cerr << "e qui ci sono?" << std::endl; tree->Draw(var1Name+":"+var2Name+">>shervin"+binning,nllName); TH2F *h = (TH2F*)gROOT->FindObject("shervin"); if(h==NULL) return NULL; h->Divide(hEntries); //std::cerr << "io sono qui" << std::endl; delete hEntries; Double_t min=1e20, max=0; if(delta){ for(Int_t iBinX=1; iBinX <= h->GetNbinsX(); iBinX++){ for(Int_t iBinY=1; iBinY <= h->GetNbinsY(); iBinY++){ Double_t binContent=h->GetBinContent(iBinX, iBinY); if(min>binContent && binContent!=0) min=binContent; if(max<binContent) max=binContent; } } std::cout << "min=" << min << "\tmax=" << max<<std::endl; for(Int_t iBinX=1; iBinX <= h->GetNbinsX(); iBinX++){ for(Int_t iBinY=1; iBinY <= h->GetNbinsY(); iBinY++){ Double_t binContent=h->GetBinContent(iBinX, iBinY); //std::cout << binContent << std::endl; if(binContent!=0) binContent-=min; else binContent=-1; h->SetBinContent(iBinX,iBinY,binContent); } } } h->GetZaxis()->SetRangeUser(0,500); //std::cerr << "io sono qui 3" << std::endl; return h; // Double_t variables[2]; // Double_t nll; // tree->SetBranchAddress(var1Name, &(variables[0])); // tree->SetBranchAddress(var2Name, &(variables[1])); // tree->SetBranchAddress(nllName, &(nll)); // Long64_t nEntries=tree->GetEntries(); // for(Long64_t jentry=0; jentry<nEntries; jentry++){ }
TH2F* Bin2DTree::fillHistogram() /*****************************************************************/ { if(!m_gridConstraint) { cerr<<"ERROR: Bin2DLeaf.fillHistogram(): Trying to fill histogram, but the binning is unknown. Define first the gridConstraint.\n"; exit(1); } TH2F* histo = (TH2F*)m_gridConstraint->Clone("histoFromTree"); int nbinsx = histo->GetNbinsX(); int nbinsy = histo->GetNbinsY(); map<Bin2DLeaf*, vector< pair<int,int> > > binsInLeaf; // First find the list of TH2 bins for each Bin2DLeaf bin for(int bx=1;bx<nbinsx+1;bx++) { for(int by=1;by<nbinsy+1;by++) { histo->SetBinContent(bx,by,0); histo->SetBinError(bx,by,0); double x = histo->GetXaxis()->GetBinCenter(bx); double y = histo->GetYaxis()->GetBinCenter(by); Bin2DLeaf* leaf = getLeaf(x,y); if(binsInLeaf.find(leaf)==binsInLeaf.end()) { vector< pair<int,int> > empty; binsInLeaf[leaf] = empty; } binsInLeaf[leaf].push_back(make_pair(bx,by)); } } // Then all the TH2 bins are filled according to the entries in the Bin2DLeaf bins map<Bin2DLeaf*, vector< pair<int,int> > >::iterator it = binsInLeaf.begin(); map<Bin2DLeaf*, vector< pair<int,int> > >::iterator itE = binsInLeaf.end(); for(;it!=itE;++it) { Bin2DLeaf* leaf = it->first; vector< pair<int,int> > bins = it->second; vector< vector<double> > entries = leaf->getEntries(); int nbins = bins.size(); for(int b=0;b<nbins;b++) { int bx = bins[b].first; int by = bins[b].second; double x = histo->GetXaxis()->GetBinCenter(bx); double y = histo->GetYaxis()->GetBinCenter(by); for(unsigned int e=0;e<entries.size();e++) { double value = entries[e][2]/(double)nbins; histo->Fill(x,y,value); } } } return histo; }
// make uncertainty histograms TH2F* filluncer(TH2F* h2, TH2F* h2_total) { TH2F* output = (TH2F*) h2->Clone(); for (unsigned int x = 1; x <= h2->GetXaxis()->GetNbins(); ++x) { for (unsigned int y = 1; y <= h2->GetYaxis()->GetNbins(); ++y) { output->SetBinContent(x, y, h2->GetBinError(x, y)/h2_total->GetBinContent(x, y)); } } return output; }
TH2F* compareEfficiency( TH2F *h1, TH2F *h2, bool useSigmas = false) { TH2F *result = (TH2F*)h1->Clone(); for (int i=0; i<h1->GetXaxis()->GetNbins()+2; i++) { for (int j=0; j<h1->GetYaxis()->GetNbins()+2; j++) { double ratio = 0; if (h2->GetBinContent(i,j) > 0) ratio = h1->GetBinContent(i,j) / h2->GetBinContent(i,j); double err = 0; if (h1->GetBinContent(i,j) > 0 && h2->GetBinContent(i,j)) err = ratio*sqrt( pow( h1->GetBinError(i,j)/h1->GetBinContent(i,j) , 2) + pow( h2->GetBinError(i,j)/h2->GetBinContent(i,j) , 2)); if (useSigmas) { result->SetBinContent( i,j, (ratio - 1)/err ); } else { result->SetBinContent( i,j,ratio -1 ); } } } return result; }
TH2F* shiftHist(TH2F* hin){ TH2F* hout = new TH2F(Form("%s_out",hin->GetName()),Form("%s_out",hin->GetName()), 120.0 , 0-5.0 , 1200-5.0 , 120 , 0-5.0 , 1200-5.0 ); for(int ibin = 1 ; ibin <= 120 ; ibin++ ){ for(int jbin = 1 ; jbin <= 120 ; jbin++ ){ hout->SetBinContent(ibin,jbin,hin->GetBinContent(ibin,jbin)); } } return hout; }
TH2F* adjust_histo(TH2F *oldhist, TH2F *refhisto) { TH2F *histo = new TH2F(refhisto->GetName(),refhisto->GetName(), refhisto->GetNbinsX(),refhisto->GetXaxis()->GetBinLowEdge(1),refhisto->GetXaxis()->GetBinLowEdge(refhisto->GetNbinsX())+refhisto->GetXaxis()->GetBinWidth(refhisto->GetNbinsX()), refhisto->GetNbinsY(),refhisto->GetYaxis()->GetBinLowEdge(1),refhisto->GetYaxis()->GetBinLowEdge(refhisto->GetNbinsY())+refhisto->GetYaxis()->GetBinWidth(refhisto->GetNbinsY())); for(int ix=1;ix<=refhisto->GetNbinsX();ix++) { for(int iy=1;iy<=refhisto->GetNbinsX();iy++) { int binnum=refhisto->FindBin(refhisto->GetXaxis()->GetBinCenter(ix),refhisto->GetYaxis()->GetBinCenter(iy)); histo->SetBinContent(binnum,oldhist->GetBinContent(ix,iy)); } } return histo; }
TH2F* flipth2f(TH2F *histo) { if(histo->GetNbinsX()!=histo->GetNbinsY()) { write_error(__FUNCTION__,"number of bins is not the same for x & y !!!"); return NULL; } TH2F *rethisto = (TH2F*)histo->Clone(); for(int i=1;i<histo->GetNbinsX();i++) { for(int j=1;j<histo->GetNbinsY();j++) { rethisto->SetBinContent(j,i,histo->GetBinContent(i,j)); } } return rethisto; }
/// generate TH2F from this, for example for saving to a file or doing anything that /// doesn't depend on bin edges or errors TH2F* toTH2F(const char* name_) { TH2F* h = new TH2F(name_, name_, nXBin, 0.5, nXBin+0.5, nYBin, 0.5, nYBin+0.5); for(int x=0; x<nXBin; x++) { for(int y=0; y<nYBin; y++) { h->SetBinContent(x+1, y+1, values[x][y]); h->SetBinError(x+1, y+1, getBinError(x,y)); } } return h; }
TH2F* prep_histo(TH2F *oldhist, int scantype) {///DONE string name=oldhist->GetName(); oldhist->SetName(((string)"unprepped"+oldhist->GetName()).c_str()); TH2F *histo = new TH2F(name.c_str(),name.c_str(), oldhist->GetNbinsX(),oldhist->GetXaxis()->GetBinLowEdge(1),oldhist->GetXaxis()->GetBinLowEdge(oldhist->GetNbinsX())+oldhist->GetXaxis()->GetBinWidth(oldhist->GetNbinsX()), oldhist->GetNbinsY(),oldhist->GetYaxis()->GetBinLowEdge(1),oldhist->GetYaxis()->GetBinLowEdge(oldhist->GetNbinsY())+oldhist->GetYaxis()->GetBinWidth(oldhist->GetNbinsY())); for(int ix=1;ix<=oldhist->GetNbinsX();ix++) { for(int iy=1;iy<=oldhist->GetNbinsX();iy++) { histo->SetBinContent(ix,iy,oldhist->GetBinContent(ix,iy)); } } return histo; }
TH2F* XsecThisHistogram(TH2F *hold, TH1D *hxsec){ TString name = hold->GetName() + (TString)"Xsec"; TH2F *hnew = (TH2F*)hold->Clone(name); for(int x = 1; x<=hnew->GetNbinsX(); ++x){ for(int y = 1; y<=hnew->GetNbinsY(); ++y){ float val = hnew->GetBinContent(x,y); float mstop = hnew->GetXaxis()->GetBinLowEdge(x); //cout << "check " << "bin " << x << " gets me mstop " << mstop << endl; float xsec = hxsec->GetBinContent(hxsec->FindBin(mstop)); hnew->SetBinContent(x,y,val*xsec); } } return hnew; }
TH2F* PassThisHistogram(TH2F *hold){ TString name = hold->GetName() + (TString)"Pass"; TH2F *hnew = (TH2F*)hold->Clone(name); for(int x = 1; x<=hnew->GetNbinsX(); ++x){ for(int y = 1; y<=hnew->GetNbinsY(); ++y){ float val = hnew->GetBinContent(x,y); float pass = 0; if(val>1) pass = 0.001; else if(val>0) pass = 1; hnew->SetBinContent(x,y,pass); } } return hnew; }
TH2F SantanderMatching(TH2F const& h4f, TH2F const& h5f, TH2F const* mass) { TH2F res = h4f; for (int x = 1; x <= h4f.GetNbinsX(); ++x) { for (int y = 1; y <= h4f.GetNbinsY(); ++y) { double mh = mass ? mass->GetBinContent(x, y) : h4f.GetXaxis()->GetBinCenter(x); double t = log(mh / 4.75) - 2.; double fourflav = h4f.GetBinContent(x, y); double fiveflav = h5f.GetBinContent(x, y); double sigma = (1. / (1. + t)) * (fourflav + t * fiveflav); res.SetBinContent(x, y, sigma); } } return res; }
TH2F* getMigMatrix(TH1F* htrue, TH2F* hden) { TH2F* migMatrix = (TH2F*)hden->Clone(); const int nbin = hden->GetXaxis()->GetNbins(); //this return 168 in the over/under case for( int i = 0; i < nbin+1; i++ ) { for( int j = 0; j < nbin+1; j++ ) { double den = htrue->GetBinContent(i+1); migMatrix->SetBinContent(i+1, j+1, hden->GetBinContent(i+1,j+1)/den); } } //printHisto2D(migMatrix); return migMatrix; }
void shakeErrors(TString inFileName, TString histName){ TFile inFile(inFileName); TH2F* h = (TH2F*)gROOT->FindObject(histName); if(!h){ std::cout<<"Could not access histogram!"<<std::endl; return; } TFile lowFile(TString("low_")+inFileName,"recreate"); TH2F* hLow = (TH2F*)h->Clone(histName); for(int i=0; i<h->GetSize(); i++){ hLow->SetBinContent( i, h->GetBinContent(i)-h->GetBinError(i) ); } hLow->Write(); lowFile.Close(); TFile hiFile(TString("hi_")+inFileName,"recreate"); TH2F* hHi = (TH2F*)h->Clone(histName); for(int i=0; i<h->GetSize(); i++){ hHi->SetBinContent( i, h->GetBinContent(i)+h->GetBinError(i) ); } hHi->Write(); hiFile.Close(); }
TH2F* getMigMatrix(TH1F* htrue, TH2F* hden) { TH2F* migMatrix = (TH2F*)hden->Clone(); const int nbin = hden->GetXaxis()->GetNbins(); for( int i = 0; i < nbin+1; i++ ) { for( int j = 0; j < nbin+1; j++ ) { double den = htrue->GetBinContent(i); migMatrix->SetBinContent(i, j, hden->GetBinContent(i,j)/den); } } //printHisto2D(migMatrix); return migMatrix; }
HcalElectronicsSelector::HcalElectronicsSelector(Callbacks* cb, int htrChan_lo, int htrChan_hi, int fpga_lo, int fpga_hi,int crate) { m_crate=crate; m_cb=cb; m_canvas=new TCanvas("HcalSelector"); int htrChan_bins=htrChan_hi-htrChan_lo+1; int fpga_bins=(fpga_hi-fpga_lo+1)*2; char name[10]; char title[256]; sprintf(title,"htrChan/fpga Space Crate %d",crate); sprintf(name,"Crate %d",crate); TH2F* h = new TH2F(title,name, fpga_bins, fpga_lo-0.25, fpga_hi+0.75, htrChan_bins, htrChan_lo-0.5, htrChan_hi+0.5); h->GetYaxis()->SetTitle("HTR CHANNEL"); h->GetXaxis()->SetTitle("Slot"); h->SetStats(0); // Set bins to a 'badval' in order to distinguish // between zero-mean cells and unconnected cells // for (int binx=1; binx<=h->GetNbinsX(); binx++) for (int biny=1; biny<=h->GetNbinsY(); biny++) h->SetBinContent(binx,biny,BADVAL); m_hist = h; TStyle* ms=new TStyle("hvs","hvs"); ms->SetPalette(1,0); ms->cd(); m_canvas->cd(); m_hist->Draw("COLZ"); m_canvas->Update(); m_canvas->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "HcalElectronicsSelector", this, "onEvent(Int_t,Int_t,Int_t,TObject*)");//add crate m_canvas->cd(); }
float getSMSxs(float mlsp,float mglu) { TH2F *refh = new TH2F("ReferenceHisto","ReferenceHisto",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep); refh->SetBinContent(refh->FindBin(mglu,mlsp),1);//only compute the cross section for our point TFile *xsecfile = new TFile((PlottingSetup::cbafbasedir+"/"+PlottingSetup::SMSReferenceXSFile).c_str()); if(xsecfile->IsZombie()) { write_error(__FUNCTION__,"Cross section file is invalid!!!!"); return -1; } xsecfile->Close(); delete xsecfile; TH2F *xsec = adjust_histo(get_XS(PlottingSetup::cbafbasedir+"/"+PlottingSetup::SMSReferenceXSFile,"gluino",refh),refh); int GlobalBin = xsec->FindBin(mglu,mlsp); float refxs=xsec->GetBinContent(GlobalBin); delete refh; delete xsec; return refxs; }
void Plotcolz(){ if(StopMass.size() == 0) GetAllMasses(); TCanvas *c1 = new TCanvas("c1","c1",600,400); TH2F* hist = new TH2F("hist", "nEvents for the different mass points", 40, 12.5, 1000+12.5, 24, -12.5, 600-12.5); for(int k = 0; k < StopMass.size(); k++){ hist->SetBinContent(hist->FindBin(StopMass[k], NeutralinoMass[k]), Events[k]); } hist -> SetStats(0); hist->GetXaxis()->SetTitle("Stop Mass [GeV]"); hist->GetYaxis()->SetTitle("Neutralino Mass [GeV]"); hist->GetXaxis()->SetNdivisions(40308); hist->GetYaxis()->SetNdivisions(40306); c1->SetGrid(); hist->Draw("colz"); c1 -> Print(outputdir + "MassPointsEvents.pdf", "pdf"); c1 -> Print(outputdir + "MassPointsEvents.png", "png"); }