//_________________________________________________________________________________________________ void GroupByStation(AliMergeableCollection& hc, int timeResolution) { int station(1); for ( Int_t ich = 1; ich < 10; ich += 2 ) { TH1* h = hc.Histo(Form("/CHAMBER/HITS/%ds/CHAMBER%d",timeResolution,ich)); TH1* h1 = hc.Histo(Form("/CHAMBER/HITS/%ds/CHAMBER%d",timeResolution,ich+1)); TH1* hstation = static_cast<TH1*>(h->Clone(Form("STATION%d",station))); hstation->Add(h1); hc.Adopt(Form("/STATION/HITS/%ds",timeResolution),hstation); h = hc.Histo(Form("/CHAMBER/HITS/%ds/CHAMBER%dLEFT",timeResolution,ich)); h1 = hc.Histo(Form("/CHAMBER/HITS/%ds/CHAMBER%dLEFT",timeResolution,ich+1)); hstation = static_cast<TH1*>(h->Clone(Form("STATION%dLEFT",station))); hstation->Add(h1); hc.Adopt(Form("/STATION/HITS/%ds",timeResolution),hstation); h = hc.Histo(Form("/CHAMBER/HITS/%ds/CHAMBER%dRIGHT",timeResolution,ich)); h1 = hc.Histo(Form("/CHAMBER/HITS/%ds/CHAMBER%dRIGHT",timeResolution,ich+1)); hstation = static_cast<TH1*>(h->Clone(Form("STATION%dRIGHT",station))); hstation->Add(h1); hc.Adopt(Form("/STATION/HITS/%ds",timeResolution),hstation); ++station; } }
//_________________________________________________________________________________________________ void GroupByChamber(AliMergeableCollection& hc, int timeResolution) { for ( Int_t ich = 1; ich <= 10; ++ich ) { AliMpDEIterator it; it.First(ich-1); TH1* hchamberLeft(0x0); TH1* hchamberRight(0x0); TList listLeft; TList listRight; listLeft.SetOwner(kFALSE); listRight.SetOwner(kFALSE); AliMpDCSNamer dcs("TRACKER"); while (!it.IsDone()) { Int_t detElemId = it.CurrentDEId(); AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId); TH1* h = hc.Histo(Form("/DE/HITS/%ds/DE%04d",timeResolution,detElemId)); if (dcs.DCSAliasName(detElemId).Contains("Left")) { if (!hchamberLeft) { hchamberLeft = static_cast<TH1*>(h->Clone(Form("CHAMBER%dLEFT",ich))); } else { listLeft.Add(h); } } else { if (!hchamberRight) { hchamberRight = static_cast<TH1*>(h->Clone(Form("CHAMBER%dRIGHT",ich))); } else { listRight.Add(h); } } it.Next(); } hchamberLeft->Merge(&listLeft); hchamberRight->Merge(&listRight); hc.Adopt(Form("/CHAMBER/HITS/%ds",timeResolution),hchamberLeft); hc.Adopt(Form("/CHAMBER/HITS/%ds",timeResolution),hchamberRight); TH1* hchamber = static_cast<TH1*>(hchamberLeft->Clone(Form("CHAMBER%d",ich))); hchamber->Add(hchamberRight); hc.Adopt(Form("/CHAMBER/HITS/%ds",timeResolution),hchamber); } }
// === FUNCTION ============================================================ // Name: TPlot::GetEffHist // Description: // =========================================================================== TH1* TPlot::GetEffHist(std::string Eff, std::string det, std::string algo) { TH1* hNum = GetHist1D(listEff[Eff].first, det, algo); TH1* hDem = GetHist1D(listEff[Eff].second, det, algo); TH1* temp = (TH1*)hNum->Clone(Eff.c_str()); assert(hNum->GetNbinsX() == hDem->GetNbinsX()); for (int i = 0; i < hNum->GetNbinsX(); ++i) { double val = hNum->GetBinContent(i) / hDem->GetBinContent(i); double valerr = val * sqrt( pow(hNum->GetBinError(i)/hNum->GetBinContent(i), 2) + pow(hDem->GetBinError(i)/hDem->GetBinContent(i), 2) ); if (isnan(val)) { val = 0; valerr = 0; } temp->SetBinContent(i, val); temp->SetBinError(i, valerr); std::cout << " bin " <<i <<" val " << val << std::endl; } //temp->Divide(hDem); temp->GetYaxis()->SetTitle("Efficiency"); return temp; } // ----- end of function TPlot::GetEffHist -----
void dominik() { TH1* matHistogramRoman = static_cast<TH1*>(extractObjectFromFile("lyRoman.root", "lightYieldProjectionY")->At(0)); TList* objects = extractObjectFromFile("c.root", "chargeBins"); TH1* matHistogramDominik = new TH1D("matHistogramDominik", ";channel;light yield / pixels", 512, -0.5, 512-0.5); int sipmIt = 0; for (int i = 0; i < objects->GetSize(); ++i) { TH1* h = static_cast<TH1*>(objects->At(i)); if (h->GetLineColor() == 8) { for (int bin = 1; bin <= 128; ++bin) { matHistogramDominik->SetBinContent(512 - (sipmIt * 128 + bin - 1), h->GetBinContent(bin)); if (h->GetBinError(bin) > 0) matHistogramDominik->SetBinError(512 - (sipmIt * 128 + bin - 1), h->GetBinError(bin)); } ++sipmIt; } } TCanvas* c = new TCanvas; c->Divide(1, 2); c->cd(1); matHistogramDominik->Draw(); matHistogramRoman->Draw("SAME"); c->cd(2); TH1* h = static_cast<TH1*>(matHistogramDominik->Clone()); h->Add(matHistogramRoman, -1); h->Draw(); }
//_________________________________________________________________________________________________ void GroupByDDL(AliMergeableCollection& hc, int timeResolution) { Int_t nddls = AliDAQ::NumberOfDdls("MUONTRK"); Int_t offset = AliDAQ::DdlIDOffset("MUONTRK"); for ( Int_t i = 0; i < nddls; ++i ) { Int_t ddlId = offset + i; AliMpDDL* ddl = AliMpDDLStore::Instance()->GetDDL(i); TH1* hddl(0x0); TList list; list.SetOwner(kFALSE); for ( Int_t ide = 0; ide < ddl->GetNofDEs(); ++ide ) { Int_t detElemId = ddl->GetDEId(ide); TH1* h = hc.Histo(Form("/DE/HITS/%ds/DE%04d",timeResolution,detElemId)); if (!hddl) { hddl = static_cast<TH1*>(h->Clone(Form("DDL%d",ddlId))); } else { list.Add(h); } } hddl->Merge(&list); hc.Adopt(Form("/DDL/HITS/%ds",timeResolution),hddl); } }
// Extract and merge histograms in range [from, to) (to is not included) // TH1 *merge(const string &path, TFile **input, const int &from, const int &to, const bool &do_normalize = false) { TH1 *result = 0; for(int i = from; to > i; ++i) { TH1 *hist = get(path, input[i], i); if (!hist) { cerr << "failed to extract: " << path << endl; continue; } if (!result) result = dynamic_cast<TH1 *>(hist->Clone()); else result->Add(hist); } if (do_normalize && result && result->GetEntries()) { result->Scale(1. / result->Integral()); } return result; }
// Test the global style settings for a generic histogram. void styles::testGlobalStyle(bool fixY, float scale) { readGroupStyle(); setGlobalStyle(); setDefaultStyle(); TH1* h = new TH1F("h", "h", 50, 0, 50); TH1* hc[6]; for (int i=1; i<=50; i++) { double value = scale*exp(-0.5*pow(((i-25.)/5.),2)); // Gaussian shape h->SetBinContent(i, value); } TCanvas c; if(nPads == 2) c.Divide(2); if(nPads == 3) c.Divide(3); if(nPads == 4) c.Divide(2,2); if(nPads == 6) c.Divide(3,2); c.cd(1); h->Draw(); if(fixY) moveYAxisLabel(h,100); setTitles(h, "D^{(*)0/+} channels", "xlabel^{2}_{miss} (GeV^{2})", "Events/(10 MeV^{2})"); float scales[] = {0.1, 10, 0.01}; for(int pads = 2; pads<=4; pads++){ if(nPads>=pads){ c.cd(pads); hc[pads-2] = static_cast<TH1F*>(h->Clone()); hc[pads-2]->Scale(scales[pads-2]); if(fixY) moveYAxisLabel(hc[pads-2],hc[pads-2]->GetMaximum()); hc[pads-2]->Draw(); setTitles(hc[pads-2], "D^{(*)0/+} channels", "xlabel^{2}_{miss} (GeV^{2})", "Events/(1000 MeV^{2})"); } } TString epsName = "babar_code/styles/Plot_"; epsName += nPads; epsName += "Pads.eps"; c.Print(epsName); }
TH1* GetHist(const std::string histname, const float scaleTo=1.0) { TH1 *res_hist = 0; if (! bFLATSAMPLE) { TH1 *hists[nBins]; for (int i=0; i<nBins; ++i) { hists[i] = 0; if (files[i]->IsZombie()) { cout << files[i]->GetName() << " not found!" << endl; assert (false); } else { hists[i] = dynamic_cast<TH1*> (files[i]->Get(histname.c_str())); if (hists[i] == 0 ) { cout << "hist_pass " << histname << " not found in " << files[i]->GetName() << "!" << endl; assert (false); } else { hists[i]->Sumw2(); //temp: no scaling for lumi wgted samples //const float scale = scaleTo/ ( nEvents[i] / xSec[i] ); //hists[i]->Scale(scale); if (i == 0) { res_hist = dynamic_cast<TH1*> (hists[i]->Clone("histcopy")); res_hist->SetDirectory(0); } else { res_hist->Add(hists[i]); } } } } } else { TFile f(sQCD_FLAT_FILE_NAME.c_str()); if (f.IsZombie()) { cout << __FUNCTION__ << ":" << __LINE__ << ":file " << sQCD_FLAT_FILE_NAME << " not found!"<< endl; assert(false); } TH1* hist = dynamic_cast<TH1*> (f.Get(histname.c_str())); if (hist == NULL) { cout << __FUNCTION__ << ":" << __LINE__ << ": " << histname << " not found!"<< endl; assert(false); } res_hist = dynamic_cast<TH1*> (hist->Clone()); res_hist->SetDirectory(0); } return res_hist; }
//____________________________________________________________________ void Run(const char* newName, const char* oldName, const char* newTitle="New", const char* oldTitle="Old") { TFile* newFile = TFile::Open(newName,"READ"); TFile* oldFile = TFile::Open(oldName,"READ"); if (!newFile || !oldFile) return; TH1* newCent = GetH1(newFile, "realCent"); TH1* oldCent = GetH1(oldFile, "realCent"); if (!newCent || !oldCent) return; TString t; t.Form("#it{R}=#frac{%s}{%s}", newTitle, oldTitle); TCanvas* c = new TCanvas("c", t, 1200, 800); c->SetTopMargin(0.01); c->SetRightMargin(0.20); fLegend = new TLegend(1-c->GetRightMargin(), c->GetBottomMargin(), 1, 1-c->GetTopMargin(), t); fLegend->SetFillStyle(0); fLegend->SetBorderSize(0); THStack* stack = new THStack("ratios",""); fMin = +1e6; fMax = -1e6; TH1* one = 0; for (Int_t i = newCent->GetNbinsX(); i--;) { Double_t c1 = newCent->GetXaxis()->GetBinLowEdge(i+1); Double_t c2 = newCent->GetXaxis()->GetBinUpEdge(i+1); Info("", "c1=%f c2=%f", c1, c2); TH1* r = One(newFile, oldFile, c1, c2); if (!r) continue; if (!one) { one = static_cast<TH1*>(r->Clone("one")); one->SetDirectory(0); one->Reset(); for (Int_t j = 1; j <= one->GetNbinsX(); j++) { one->SetBinContent(j,1); one->SetBinError (j,0); } } // r->Add(one, i-1); // r->Scale(TMath::Power(10,i)); stack->Add(r); } stack->Draw("nostack"); stack->SetMinimum(0.95*fMin); stack->SetMaximum(1.05*fMax); stack->GetHistogram()->SetXTitle("#eta"); stack->GetHistogram()->SetYTitle("#it{R}"); fLegend->Draw(); c->Modified(); c->Update(); c->cd(); c->SaveAs(Form("%sover%s.png", newTitle, oldTitle)); }
void fancyMerge( std::string beam, std::string target, std::string energy, std::string physlist, bool doScale=false ) { std::string output = beam + target + energy + "GeV" + physlist + ".root" ; targetFile = TFile::Open( output.c_str(), "RECREATE" ); double scale = 1./32.; // std::string input = beam + target + model + energy + "GeV-1.root"; // std::string input = "../t23-bld/harp-histo-no-res-decays/" + beam + target + energy + "GeV" + physlist +"-1.root"; // std::string input = "../t23-bld/harp-histo/" + beam + target + energy + "GeV" + physlist +"-1.root"; std::string input = "../t23-bld/na49-histo/" + beam + target + energy + "GeV" + physlist +"-1.root"; TFile* iFile1 = TFile::Open( input.c_str() ); TIter next( iFile1->GetListOfKeys() ); TKey* key = (TKey*)next(); TH1* h = 0; while ( key ) { if ( !(TClass::GetClass(key->GetClassName())->InheritsFrom(TH1::Class())) ) continue; const char* kName = key->GetName(); h = (TH1*)key->ReadObj(); const char* hName = h->GetName(); std::cout << " histoname = " << hName << std::endl; TH1F* h1 = h->Clone(); for ( int id=2; id<=32; id++ ) { // std::string input_t = "../t23-bld/harp-histo-no-res-decays/" + beam + target + energy + "GeV" + physlist + "-" ; // std::string input_t = "../t23-bld/harp-histo/" + beam + target + energy + "GeV" + physlist + "-" ; std::string input_t = "../t23-bld/na49-histo/" + beam + target + energy + "GeV" + physlist + "-" ; char buf[5]; sprintf( buf, "%i", id ); input_t.append( buf ); input_t += ".root"; TFile* iFile_t = TFile::Open( input_t.c_str() ); TH1F* h_t = (TH1F*)iFile_t->Get( h->GetName() ); h1->Add( h_t ); iFile_t->Close(); } if ( doScale ) { if (!(strcmp(key->GetClassName(),"TProfile"))) h1->Scale( scale ); } targetFile->cd(); h1->Write(); key = (TKey*)next(); } targetFile->Close(); return; }
TH1 *MillePedeTrees::CreateHist(const char *exp, const char *selection, const char *hDef, Option_t* opt) { TH1 *h = this->Draw(exp, selection, hDef, "goff"); TH1 *hResult = static_cast<TH1*>(h->Clone(Form("%sC", h->GetName()))); if (opt) hResult->SetOption(opt); return hResult; }
void Legend() { TLegend* leg = new TLegend(.6, .6, .9, .85); leg->SetFillStyle(0); TH1* dummy = new TH1F("", "", 1, 0, 1); dummy->SetMarkerStyle(kFullCircle); leg->AddEntry(dummy->Clone(), "Fake Data", "lep"); dummy->SetLineColor(kTotalMCColor); leg->AddEntry(dummy->Clone(), "Total MC", "l"); dummy->SetLineColor(kNCBackgroundColor); leg->AddEntry(dummy->Clone(), "NC", "l"); dummy->SetLineColor(kNumuBackgroundColor); leg->AddEntry(dummy->Clone(), "#nu_{#mu} CC", "l"); dummy->SetLineColor(kBeamNueBackgroundColor); leg->AddEntry(dummy->Clone(), "Beam #nu_{e} CC", "l"); leg->Draw(); }
TProfile *MillePedeTrees::CreateHistProf(const char *expX, const char *expY, const char *selection, const char *hDef, Option_t* opt) { const TString combExpr(Form("%s:%s", expY, expX)); TH1 *h = this->Draw(combExpr, selection, hDef, "goff prof"); TProfile *hResult = static_cast<TProfile*>(h->Clone(Form("%sClone", h->GetName()))); if (opt) hResult->SetOption(opt); return hResult; }
TH1* GetHist(const string histname) { //hists are already scaled to 10fb-1 TH1* h = dynamic_cast<TH1*> (files[0]->Get(histname.c_str())); if (h == NULL) { cout << "hist " << histname << " not found in " << "!" << endl; assert (false); } TH1* hist = dynamic_cast<TH1*> (h->Clone()); hist->Sumw2(); hist->SetLineWidth(2); return hist; }
TH1 * YieldMean_ReturnExtremeHisto(TH1 *hin, Float_t sign) { Double_t ptlow, pthigh; for (Int_t ibin = 0; ibin < hin->GetNbinsX(); ibin++) { if (hin->GetBinError(ibin + 1) <= 0.) continue; ptlow = hin->GetBinLowEdge(ibin + 1); break; } for (Int_t ibin = hin->GetNbinsX(); ibin >= 0; ibin--) { if (hin->GetBinError(ibin + 1) <= 0.) continue; pthigh = hin->GetBinLowEdge(ibin + 2); break; } Double_t mean = hin->GetMean(); Double_t maxdiff = 0.; TH1 *hmax = NULL; for (Int_t inode = 0; inode < hin->GetNbinsX(); inode++) { Double_t ptnode = hin->GetBinCenter(inode + 1); TH1 *hout = (TH1 *)hin->Clone(Form("%s_extremehard", hin->GetName())); for (Int_t ibin = 0; ibin < hin->GetNbinsX(); ibin++) { if (hin->GetBinError(ibin + 1) <= 0.) continue; Double_t val = hin->GetBinContent(ibin + 1); Double_t err = hin->GetBinError(ibin + 1); Double_t cen = hin->GetBinCenter(ibin + 1); if (cen < ptnode) err *= -1. + (cen - ptlow) / (ptnode - ptlow); else err *= (cen - ptnode) / (pthigh - ptnode); hout->SetBinContent(ibin + 1, val + sign * err); } Double_t diff = TMath::Abs(mean - hout->GetMean()); if (diff > maxdiff) { // printf("found max at %f\n", ptnode); if (hmax) delete hmax; hmax = (TH1 *)hout->Clone("hmax"); maxdiff = diff; } delete hout; } return hmax; }
//____________________________________________________________________ TH1* One(TDirectory* newDir, TDirectory* oldDir, Double_t c1, Double_t c2) { TString name; name.Form("cent%03dd%02d_%03dd%02d", Int_t(c1), Int_t(c1*100)%100, Int_t(c2), Int_t(c2*100)%100); TDirectory* newSubDir = GetD(newDir, name); TDirectory* oldSubDir = GetD(oldDir, name); if (!newSubDir || !oldSubDir) return 0; Int_t newDim = 0; if (TString(newDir->GetName()).Contains("etaipz")) newDim = 3; else if (TString(newDir->GetName()).Contains("eta")) newDim = 2; else if (TString(newDir->GetName()).Contains("const")) newDim = 1; Int_t oldDim = 0; if (TString(oldDir->GetName()).Contains("etaipz")) oldDim = 3; else if (TString(oldDir->GetName()).Contains("eta")) oldDim = 2; else if (TString(oldDir->GetName()).Contains("const")) oldDim = 1; TDirectory* newSubSubDir = GetD(newSubDir, Form("results%dd",newDim)); TDirectory* oldSubSubDir = GetD(oldSubDir, Form("results%dd",oldDim)); if (!newSubSubDir || !oldSubSubDir) return 0; TH1* newRes = GetH1(newSubSubDir, "result"); TH1* oldRes = GetH1(oldSubSubDir, "result"); if (!newRes || !oldRes) return 0; TH1* ratio = static_cast<TH1*>(newRes->Clone(name)); ratio->SetDirectory(0); ratio->SetTitle(Form("%5.1f - %5.1f%%", c1, c2)); ratio->SetYTitle("New / Old"); ratio->Divide(oldRes); fMin = TMath::Min(fMin, ratio->GetMinimum()); fMax = TMath::Max(fMax, ratio->GetMaximum()); Printf("Calculated %s/%s", newDir->GetName(), oldDir->GetName()); if (!fLegend) return ratio; TLegendEntry* e = fLegend->AddEntry("", Form("%3.0f - %3.0f%%", c1, c2), "f"); e->SetFillStyle(1001); e->SetFillColor(ratio->GetMarkerColor()); return ratio; }
void makefinal(TFile* fp, TFile *fm, TFile* of=0) { setTDRStyle(); TH1 *hp = (TH1*) fp->Get("MYHA"); TH1 *hm = (TH1*) fm->Get("MYHA"); TH1 *h = hp->Clone("MYNA"); for (int k=1; k<=h->GetNbinsX(); k++) { std::cout << hp->GetBinContent(k) << " " << hm->GetBinContent(k) << std::endl; h->SetBinContent(k,hp->GetBinContent(k)*.5 +hm->GetBinContent(k)*.5); std::cout << " NEW " << h->GetBinContent(k) << std::endl; //h->SetBinEntries(k,1); } if (of!=0) { of->cd(); h->Write();} }
//_________________________________________________________________________________________________ void GroupByDE(AliMergeableCollection& hc, int timeResolution) { AliMpDEIterator it; it.First(); while (!it.IsDone()) { Int_t detElemId = it.CurrentDEId(); AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId); TList list; list.SetOwner(kFALSE); TH1* hde(0x0); if ( de->GetStationType() != AliMp::kStationTrigger) { for ( Int_t i = 0; i < de->GetNofBusPatches(); ++i ) { Int_t busPatchId = de->GetBusPatchId(i); TH1* h = hc.Histo(Form("/BUSPATCH/HITS/%ds/BP%04d",timeResolution,busPatchId)); if (!hde) { hde = static_cast<TH1*>(h->Clone()); hde->SetName(Form("DE%04d",detElemId)); } else { list.Add(h); } } hde->Merge(&list); hc.Adopt(Form("/DE/HITS/%ds",timeResolution),hde); } it.Next(); } }
std::shared_ptr<TH1> getHistogram(const std::string& name, const std::vector<Input>& inputs, int type) { TH1* h = nullptr; for (const auto& input: inputs) { if (input.type != type) continue; TH1* f = static_cast<TH1*>(input.file->Get(name.c_str())); f->Scale(input.cross_section / (input.generated_events * input.top_pt_weight)); if (! h) { h = static_cast<TH1*>(f->Clone()); h->SetDirectory(NULL); } else h->Add(f); } return std::shared_ptr<TH1>(h); }
vector<TH1*> GetHist(const string histname) { //hists are already scaled to 10fb-1 vector<TH1*> hists; for (int i=0; i< nBins; ++i) { TH1* h = dynamic_cast<TH1*> (files[i]->Get(histname.c_str())); if (h == NULL) { cout << "hist " << histname << " not found in file # " << i << " !" << endl; assert (false); } TH1* hist = dynamic_cast<TH1*> (h->Clone()); hist->Sumw2(); hist->SetLineWidth(2); hists.push_back(hist); } return hists; }
// Do the loop here, so that we can use options like "errors" void Draw( const TString & xTitle = "", const TString & yTitle = "", const bool errors = false ) { // Create a new THStack so that it handle tha maximum // THStack stack(name_, title_); THStack * stack = new THStack(name_, title_); int colorIndex = 0; if( !(histoList_.empty()) ) { std::vector<TH1*>::iterator histoIter = histoList_.begin(); for( ; histoIter != histoList_.end(); ++histoIter, ++colorIndex ) { TH1 * histo = *histoIter; if(errors) histo->Sumw2(); // histo->SetNormFactor(1); if( colorIndex < 4 ) histo->SetLineColor(colors_[colorIndex]); else histo->SetLineColor(colorIndex); // Draw and get the maximum value TString normalizedHistoName(histo->GetName()); TH1 * normalizedHisto = (TH1*)histo->Clone(normalizedHistoName+"clone"); normalizedHisto->Scale(1/normalizedHisto->Integral()); stack->Add(normalizedHisto); } // Take the maximum of all the drawed histograms // First we need to draw the histogram, or getAxis() will return 0... (see root code...) canvas_->Draw(); canvas_->cd(); stack->Draw("nostack"); stack->GetYaxis()->SetTitleOffset(1.2); stack->GetYaxis()->SetTitle(yTitle); stack->GetXaxis()->SetTitle(xTitle); stack->GetXaxis()->SetTitleColor(kBlack); stack->Draw("nostack"); legend_->Draw("same"); canvas_->Update(); canvas_->Draw(); canvas_->ForceUpdate(); //canvas_->Print("test.pdf"); canvas_->Write(); } }
TH1* getHistogram(TFile* inputFile, const TString& meName, TObjArray& processes, const TString& region) { TH1* histogram_sum = 0; int numProcesses = processes.GetEntries(); for ( int iProcess = 0; iProcess < numProcesses; ++iProcess ) { TObjString* process = dynamic_cast<TObjString*>(processes.At(iProcess)); assert(process); TH1* histogram = getHistogram(inputFile, meName, process->GetString(), region); if ( !histogram_sum ) { TString histogramName_sum = histogram->GetName(); histogramName_sum = histogramName_sum.ReplaceAll(process->GetString(), "sum"); histogram_sum = (TH1*)histogram->Clone(histogramName_sum.Data()); if ( !histogram_sum->GetSumw2N() ) histogram_sum->Sumw2(); } else { histogram_sum->Add(histogram); } } return histogram_sum; }
void patBJetTracks_efficiencies() { // define proper canvas style setNiceStyle(); gStyle->SetOptStat(0); // open file TFile* file = new TFile("analyzePatBJetTracks.root"); TLegend *legend[3] = { 0, 0, 0 }; // draw canvas with efficiencies TCanvas *canv; canv = new TCanvas("canv0", "hand-crafted track counting efficiencies", 800, 300); canv->Divide(3, 1); TH1 *total = (TH1*)file->Get(Form("%s/flavours", directory)); TH1 *effVsCutB = 0; unsigned int i = 0; for(const char **flavour = flavours; *flavour; flavour++, i++) { TH1 *h = (TH1*)file->Get(Form("%s/trackIPSig_%s", directory, *flavour)); TH1 *discrShape = (TH1*)h->Clone(Form("%s_discrShape", h->GetName())); discrShape->Scale(1.0 / discrShape->Integral()); discrShape->SetMaximum(discrShape->GetMaximum() * 5); TH1 *effVsCut = computeEffVsCut(h, total->GetBinContent(4 - i)); TH1 *effVsBEff = 0; if (flavour == flavours) // b-jets effVsCutB = effVsCut; else effVsBEff = computeEffVsBEff(effVsCut, effVsCutB); discrShape->SetTitle("discriminator shape"); effVsCut->SetTitle("efficiency versus discriminator cut"); if (effVsBEff) effVsBEff->SetTitle("mistag versus b efficiency"); setHistStyle(discrShape); setHistStyle(effVsCut); setHistStyle(effVsBEff); canv->cd(1); gPad->SetLogy(1); gPad->SetGridy(1); discrShape->SetLineColor(i + 1); discrShape->SetMarkerColor(i + 1); discrShape->Draw(i > 0 ? "same" : ""); if (!legend[0]) legend[0] = new TLegend(0.5, 0.7, 0.78, 0.88); legend[0]->AddEntry(discrShape, *flavour); canv->cd(2); gPad->SetLogy(1); gPad->SetGridy(1); effVsCut->SetLineColor(i + 1); effVsCut->SetMarkerColor(i + 1); effVsCut->Draw(i > 0 ? "same" : ""); if (!legend[1]) legend[1] = new TLegend(0.12, 0.12, 0.40, 0.30); legend[1]->AddEntry(effVsCut, *flavour); if (!effVsBEff) continue; canv->cd(3); gPad->SetLogy(1); gPad->SetGridx(1); gPad->SetGridy(1); effVsBEff->SetLineColor(i + 1); effVsBEff->SetMarkerColor(i + 1); effVsBEff->Draw(i > 1 ? "same" : ""); if (!legend[2]) legend[2] = new TLegend(0.12, 0.7, 0.40, 0.88); legend[2]->AddEntry(effVsBEff, *flavour); } canv->cd(1); legend[0]->Draw(); canv->cd(2); legend[1]->Draw(); canv->cd(3); legend[2]->Draw(); //////////////////////////////////////////// // canvas to compare negative tagger with light flavour mistag TCanvas *canv; canv = new TCanvas("canv1", "comparing light flavour mistag with negative tagger", 530, 300); canv->Divide(2, 1); TH1 *h1 = (TH1*)file->Get(Form("%s/trackIPSig_udsg", directory)); TH1 *h2 = (TH1*)file->Get(Form("%s/negativeIPSig_all", directory)); h2 = invertHisto(h2); // invert x-axis TH1 *discrShape1 = (TH1*)h1->Clone("discrShape1"); TH1 *discrShape2 = (TH1*)h2->Clone("discrShape2"); discrShape1->Scale(1.0 / discrShape1->Integral()); discrShape1->SetMaximum(discrShape1->GetMaximum() * 5); discrShape2->Scale(1.0 / discrShape2->Integral()); TH1 *effVsCut1 = computeEffVsCut(h1, total->GetBinContent(2)); TH1 *effVsCut2 = computeEffVsCut(h2, total->GetBinContent(1)); discrShape1->SetTitle("discriminator shape"); effVsCut1->SetTitle("efficiency versus discriminator cut"); setHistStyle(discrShape1); setHistStyle(discrShape2); setHistStyle(effVsCut1); setHistStyle(effVsCut2); canv->cd(1); gPad->SetLogy(1); gPad->SetGridy(1); discrShape1->SetLineColor(1); discrShape1->SetMarkerColor(1); discrShape2->SetLineColor(2); discrShape2->SetMarkerColor(2); discrShape1->Draw(); discrShape2->Draw("same"); TLegend *l = new TLegend(0.5, 0.7, 0.78, 0.88); l->AddEntry(discrShape1, "udsg"); l->AddEntry(discrShape2, "inv. neg"); l->Draw(); canv->cd(2); gPad->SetLogy(1); gPad->SetGridy(1); effVsCut1->SetLineColor(1); effVsCut1->SetMarkerColor(1); effVsCut2->SetLineColor(2); effVsCut2->SetMarkerColor(2); effVsCut1->Draw(); effVsCut2->Draw("same"); l = new TLegend(0.5, 0.7, 0.78, 0.88); l->AddEntry(effVsCut1, "udsg"); l->AddEntry(effVsCut2, "inv. neg"); l->Draw(); }
void plot_MistagRate_allSamples(string sample="TTbar_", int wjets_hadtau_only=0){ // // icomp=0: only show own results // 1: show also Koushik's results // // /////////////////////////////////////////////////////////////////////////////////////////// ////Some cosmetic work for official documents. gStyle->SetOptStat(0); ///to avoid the stat. on the plots gROOT->LoadMacro("tdrstyle.C"); // setTDRStyle(); gROOT->LoadMacro("CMS_lumi_v2.C"); char tempname[200]; char tempname2[200]; int W = 800; int H = 600; int H_ref = 600; int W_ref = 800; float T = 0.08*H_ref; float B = 0.12*H_ref; float L = 0.12*W_ref; float R = 0.04*W_ref; TCanvas* c1 = new TCanvas("name","name",10,10,W,H); c1->SetFillColor(0); c1->SetBorderMode(0); c1->SetFrameFillStyle(0); c1->SetFrameBorderMode(0); c1->SetLeftMargin( L/W ); c1->SetRightMargin( R/W ); c1->SetTopMargin( T/H ); c1->SetBottomMargin( B/H ); c1->SetTickx(0); c1->SetTicky(0); Float_t legendX1 = .15; //.50; Float_t legendX2 = .50; //.70; Float_t legendY1 = .55; //.65; Float_t legendY2 = .88; TLegend* catLeg1 = new TLegend(legendX1,legendY1,legendX2,legendY2); catLeg1->SetTextSize(0.042); catLeg1->SetTextFont(42); catLeg1->SetFillColor(0); catLeg1->SetLineColor(0); catLeg1->SetBorderSize(0); TH1D * temp_tt_tauH, * temp_wj_tauH, *temp_tt_muH, * temp_wj_muH; // // From W+jets TFile file_WJet("Stack/TauBtaggedRate_WJet_stacked.root","R"); temp_wj_tauH = (TH1D*)file_WJet.Get("TauBtaggedRate")->Clone(); TH1D * wj_tauH = new TH1D("wj_tauH","WJet -- Tau mistag",temp_wj_tauH->GetNbinsX(),temp_wj_tauH->GetXaxis()->GetXmin(),temp_wj_tauH->GetXaxis()->GetXmax()); for(int ibin=0;ibin<wj_tauH->GetNbinsX()+2;ibin++){ double con = (double)temp_wj_tauH->GetBinContent(ibin); double err = (double)temp_wj_tauH->GetBinError(ibin); cout << "con: " << con << " err: " << err << endl; wj_tauH->SetBinContent(ibin,con); wj_tauH->SetBinError(ibin,err); } // // From ttbar TFile file_TTbar("Stack/TauBtaggedRate_TTbar_stacked.root","R"); temp_tt_tauH = (TH1D*)file_TTbar.Get("TauBtaggedRate")->Clone(); TH1D * tt_tauH = new TH1D("tt_tauH","WJet -- Tau mistag",temp_tt_tauH->GetNbinsX(),temp_tt_tauH->GetXaxis()->GetXmin(),temp_tt_tauH->GetXaxis()->GetXmax()); for(int ibin=0;ibin<tt_tauH->GetNbinsX()+2;ibin++){ double con = (double)temp_tt_tauH->GetBinContent(ibin); double err = (double)temp_tt_tauH->GetBinError(ibin); cout << "con: " << con << " err: " << err << endl; tt_tauH->SetBinContent(ibin,con); tt_tauH->SetBinError(ibin,err); } // // From W+jets - predictions TFile file_WJet_mu("../TauHad2/Stack/TauBtaggedRate_WJet_stacked.root","R"); temp_wj_muH = (TH1D*)file_WJet_mu.Get("TauBtaggedRate")->Clone(); TH1D * wj_muH = new TH1D("wj_muH","WJet -- Tau mistag",temp_wj_muH->GetNbinsX(),temp_wj_muH->GetXaxis()->GetXmin(),temp_wj_muH->GetXaxis()->GetXmax()); for(int ibin=0;ibin<wj_muH->GetNbinsX()+2;ibin++){ double con = (double)temp_wj_muH->GetBinContent(ibin); double err = (double)temp_wj_muH->GetBinError(ibin); cout << "con: " << con << " err: " << err << endl; wj_muH->SetBinContent(ibin,con); wj_muH->SetBinError(ibin,err); } // // From ttbar - predictions TFile file_TTbar_mu("../TauHad2/Stack/TauBtaggedRate_TTbar_stacked.root","R"); temp_tt_muH = (TH1D*)file_TTbar_mu.Get("TauBtaggedRate")->Clone(); TH1D * tt_muH = new TH1D("tt_muH","WJet -- Tau mistag",temp_tt_muH->GetNbinsX(),temp_tt_muH->GetXaxis()->GetXmin(),temp_tt_muH->GetXaxis()->GetXmax()); for(int ibin=0;ibin<tt_muH->GetNbinsX()+2;ibin++){ double con = (double)temp_tt_muH->GetBinContent(ibin); double err = (double)temp_tt_muH->GetBinError(ibin); cout << "con: " << con << " err: " << err << endl; tt_muH->SetBinContent(ibin,con); tt_muH->SetBinError(ibin,err); } // catLeg1->SetHeader("Prob. of #mu from #tau "); //...........................................................................// // TTbar ....................................................................// //...........................................................................// double XUp = 350. , maxVal=1.; wj_tauH->GetXaxis()->SetRangeUser(30.,XUp); wj_tauH->SetMaximum(maxVal); wj_tauH->SetTitle(""); wj_tauH->GetXaxis()->SetLabelFont(42); wj_tauH->GetXaxis()->SetLabelOffset(0.007); wj_tauH->GetXaxis()->SetLabelSize(0.04); wj_tauH->GetXaxis()->SetTitleSize(0.05); wj_tauH->GetXaxis()->SetTitleOffset(1.0); wj_tauH->GetXaxis()->SetTitleFont(42); wj_tauH->GetYaxis()->SetLabelFont(42); wj_tauH->GetYaxis()->SetLabelOffset(0.007); wj_tauH->GetYaxis()->SetLabelSize(0.04); wj_tauH->GetYaxis()->SetTitleSize(0.05); wj_tauH->GetYaxis()->SetTitleOffset(1.0); wj_tauH->GetYaxis()->SetTitleFont(42); wj_tauH->GetXaxis()->SetTitle("p_{T}(#tau jet)"); wj_tauH->GetYaxis()->SetTitle("b-tagging mistag rate"); wj_tauH->GetXaxis()->SetRangeUser(30.,XUp); wj_tauH->SetMaximum(maxVal); wj_tauH->SetLineColor(1); wj_tauH->Draw(); tt_tauH->SetLineColor(2); // thist.SetFillColor(0); // thist.SetLineWidth(3); if (!wjets_hadtau_only) tt_tauH->Draw("same"); wj_muH->SetLineColor(8); // wj_muH->SetMarkerStyle(20); if (!wjets_hadtau_only) { wj_muH->GetXaxis()->SetRangeUser(30.,500.); wj_muH->Draw("same"); } tt_muH->SetLineColor(4); if (!wjets_hadtau_only){ tt_muH->GetXaxis()->SetRangeUser(30.,500.); tt_muH->Draw("same"); } // sanity plot TH1 * sanityH = static_cast<TH1D*>(wj_tauH->Clone("sanity")); sanityH->Add(tt_muH); TH1 * tempH = static_cast<TH1D*>(wj_tauH->Clone("sanity")); tempH->Multiply(tt_muH); sanityH->Add(tempH,-1); sanityH->SetLineColor(34); if (!wjets_hadtau_only){ sanityH->GetXaxis()->SetRangeUser(30.,500.); sanityH->Draw("same"); } // // TLegend sprintf(tempname,"(a) #tau_{h}-jets in t#bar{t}"); if (!wjets_hadtau_only) catLeg1->AddEntry(tt_tauH,tempname,"l"); if (wjets_hadtau_only) sprintf(tempname,"#tau_{h}-jets in W+jets"); else sprintf(tempname,"(b) #tau_{h}-jets in W+jets"); catLeg1->AddEntry(wj_tauH,tempname,"l"); sprintf(tempname,"(c) #mu-jets in t#bar{t}"); if (!wjets_hadtau_only) catLeg1->AddEntry(tt_muH,tempname,"l"); sprintf(tempname,"(d) #mu-jets in W+jets"); if (!wjets_hadtau_only) catLeg1->AddEntry(wj_muH,tempname,"l"); //sprintf(tempname,"blue+(1 - blue)*red "); if (!wjets_hadtau_only){ sprintf(tempname,"(e) #mu-jets (t#bar{t}) + #tau_{h}-jets (W+jets)"); catLeg1->AddEntry(sanityH,tempname,"l"); TH1F *sanityHdummy = (TH1F*) sanityH->Clone(); sanityHdummy->SetLineColor(0); sprintf(tempname,"= (c) + [1-(c)]#times(b)"); catLeg1->AddEntry(sanityHdummy,tempname,"l"); } catLeg1->Draw(); if (wjets_hadtau_only) { sprintf(tempname,"TauBtaggedRate_allSamples_hadtau_Wjets.png"); c1->Print(tempname); sprintf(tempname,"TauBtaggedRate_allSamples_hadtau_Wjets.pdf"); c1->Print(tempname); } else { sprintf(tempname,"TauBtaggedRate_allSamples.png"); c1->Print(tempname); sprintf(tempname,"TauBtaggedRate_allSamples.pdf"); c1->Print(tempname); } }
void pidHistogramMaker::distributionReport( string pType ){ uint nBinsPt = ptBins.size() - 1; string rName = speciesName( pType, 0 ); taskProgress tp( pType + " distribution report", nBinsPt ); book->cd( "tof" ); for ( uint i = 0; i < nBinsPt; i ++ ){ tp.showProgress( i ); // momentum value used for finding nice range double p = ptBins[ i ]; double p2 = ptBins[ i + 1 ]; double avgP = 0.2; avgP = (ptBins[ i ] + ptBins[ i + 1])/2.0; string name = speciesName( pType, 0, i, 0 ); book->cd( "dedx_tof" ); TH2 * pTof = book->get2D( name ); book->cd( "scratch" ); TH2 * pDedx = (TH2*)pTof->Clone( "pDedx__" ); // start a new page on the report file pReport[ rName ]->newPage( 2, 2 ); // get information on plot ranges double tofLow, tofHigh, dedxLow, dedxHigh; autoViewport( pType, p, &tofLow, &tofHigh, &dedxLow, &dedxHigh, tofPadding, dedxPadding, tofScalePadding, dedxScalePadding ); if ( true ) { // show the tof proj string title = "#beta^{-1} : " + ts(ptBins[ i ], 4) + " < pT < " + ts(ptBins[i+1], 4); vector<string> others = otherSpecies( pType ); vector< double > tofMean = enhanceTof( pType, others, avgP ); vector< double > dedxMean = enhanceDedx( pType, others, avgP ); pReport[ rName ]->cd( 1, 1 ); //hdt->GetXaxis()->SetRangeUser( -.06, .06 ); // Make the all tof tracks histogram string hName = sTofName( pType, 0, i ); book->cd( "scratch" ); TH1* hTof = (TH1D*)pTof->ProjectionY( "_py" ); book->cd( "tof" ); book->add( hName, (TH1*)hTof->Clone( hName.c_str() ) ); book->style( hName )->set( "style.tof" ) ->set( "title", title )->draw(); TLine * l1 = new TLine( tofMean[ 0 ], hTof->GetMinimum(), tofMean[ 0 ], hTof->GetMaximum() ); l1->Draw(); TLine * l2 = new TLine( tofMean[ 1 ], hTof->GetMinimum(), tofMean[ 1 ], hTof->GetMaximum() ); l2->Draw(); pReport[ rName ]->cd( 2, 1 ); pTof->GetXaxis()->SetRangeUser( -.06, .06 ); // Make the all tof tracks histogram hName = sTofName( pType, 0, i, 0, pType ); book->cd( "scratch" ); hTof = (TH1D*)pTof->ProjectionY( "_py" ); book->cd( "tof" ); book->add( hName, (TH1*)hTof->Clone( hName.c_str() ) ); book->style( hName )->set( "style.tof" ) ->set( "title", title + " " + pType + " enhanced" )->draw(); for ( int j = 0; j < dedxMean.size(); j++ ){ pReport[ rName ]->cd( j+1, 2 ); pTof->GetXaxis()->SetRangeUser( dedxMean[j]-0.06, dedxMean[j]+0.06 ); // Make the all tof tracks histogram hName = sTofName( pType, 0, i, 0, others[ j ] ); book->cd( "scratch" ); hTof = (TH1D*)pTof->ProjectionY( "_py" ); book->cd( "tof" ); book->add( hName, (TH1*)hTof->Clone( hName.c_str() ) ); book->style( hName )->set( "style.tof" ) ->set( "title", title + " " + others[ j ] + " enhanced" )->draw(); } } pReport[ rName ]->savePage(); pReport[ rName ]->newPage( 2, 2 ); if ( true ) { // show the dedx proj string title = "dEdx : " + ts(ptBins[ i ], 4) + " < pT < " + ts(ptBins[i+1], 4); pTof->GetXaxis()->SetRange( 1, pTof->GetXaxis()->GetNbins() ); pTof->GetYaxis()->SetRange( 1, pTof->GetYaxis()->GetNbins() ); vector<string> others = otherSpecies( pType ); vector< double > tofMean = enhanceTof( pType, others, avgP ); vector< double > dedxMean = enhanceDedx( pType, others, avgP ); pReport[ rName ]->cd( 1, 1 ); // Make the all dedx tracks histogram string hName = sDedxName( pType, 0, i ); book->cd( "scratch" ); TH1* hDedx = (TH1D*)pTof->ProjectionX( "_px" ); book->cd( "dedx" ); book->add( hName, (TH1*)hDedx->Clone( hName.c_str() ) ); book->style( hName )->set( "style.dedx" ) ->set( "title", title )->draw(); TLine * l1 = new TLine( dedxMean[ 0 ], hDedx->GetMinimum(), dedxMean[ 0 ], hDedx->GetMaximum() ); l1->Draw(); TLine * l2 = new TLine( dedxMean[ 1 ], hDedx->GetMinimum(), dedxMean[ 1 ], hDedx->GetMaximum() ); l2->Draw(); pReport[ rName ]->cd( 2, 1 ); pTof->GetYaxis()->SetRangeUser( -.012, .012 ); // Make the all tof tracks histogram hName = sDedxName( pType, 0, i, 0, pType ); book->cd( "scratch" ); hDedx = (TH1D*)pTof->ProjectionX( "_px" ); book->cd( "dedx" ); book->add( hName, (TH1*)hDedx->Clone( hName.c_str() ) ); book->style( hName )->set( "style.dedx" ) ->set( "title", title + " " + pType + " enhanced" )->draw(); for ( int j = 0; j < dedxMean.size(); j++ ){ pReport[ rName ]->cd( j+1, 2 ); pTof->GetYaxis()->SetRangeUser( tofMean[j]-0.012, tofMean[j]+0.012 ); // Make the all tof tracks histogram hName = sDedxName( pType, 0, i, 0, others[ j ] ); book->cd( "scratch" ); hDedx = (TH1D*)pTof->ProjectionX( "_px" ); book->cd( "dedx" ); book->add( hName, (TH1*)hDedx->Clone( hName.c_str() ) ); book->style( hName )->set( "style.dedx" ) ->set( "title", title + " " + others[ j ] + " enhanced" )->draw(); } } pReport[ rName ]->savePage(); } }
TH1 * UnfoldMe_MB2(const Char_t *data, const Char_t *mc, const Char_t *anatag, Int_t bin, Bool_t useMBcorr , Bool_t usecorrfit , Bool_t ismc , Float_t smooth , Int_t iter , Int_t regul , Float_t weight , Bool_t bayesian , Int_t nloop ) { // MF comments: // usedMBcorr: changes the matrix used for unfonding, from effMatrix to bin matrix (I think this is just to use mult dependent v s mb correction_) // usecorrfit: if I understand correctly, fits the response matrix and uses fit to extrapolate it TFile *fdt =0; if (ismc) fdt = TFile::Open(data); else fdt = TFile::Open(data); TFile *fmc = TFile::Open(mc); TList *ldt = (TList *)fdt->Get(Form("%s", anatag)); TList *lmc = (TList *)fmc->Get(Form("%s", anatag)); TH2 *hmatdt = (TH2 *)ldt->FindObject(Form(responseMatrix, bin)); TH2 *hmatmc = 0; if (useMBcorr){ hmatmc = (TH2 *)lmc->FindObject("effMatrix"); std::cout << "USING MB" << std::endl; } else { hmatmc = (TH2 *)lmc->FindObject(Form(responseMatrix, bin)); } TH1 *hdata = hmatdt->ProjectionY("hdata"); // TH1 *hdata = hmatdt->ProjectionY("htrue"); // For truth Only Calculations hdata->Sumw2(); hdata->SetBinContent(1, 0.); hdata->SetBinError(1, 0.); // hdata->Scale(1. / hdata->Integral()); hdata->SetMarkerStyle(25); TH1 *htrue = hmatdt->ProjectionX("htrue"); htrue->Sumw2(); // htrue->Scale(1. / htrue->Integral()); htrue->SetMarkerStyle(7); htrue->SetMarkerColor(2); htrue->SetBinContent(1, 0.); htrue->SetBinError(1, 0.); TH2 *hcorr = (TH2 *)hmatmc->Clone("hcorr"); TH1 *hinit = (TH1 *)hdata->Clone("hinit"); TH1 *hresu = (TH1 *)hdata->Clone("hresu"); TH1 *hbias = (TH1 *)hdata->Clone("hbias"); hresu->SetMarkerStyle(20); hresu->SetMarkerColor(4); hresu->Reset(); TH1 *hnum = hcorr->ProjectionY("hnum"); TH1 *hden = hcorr->ProjectionY("hden"); TH1 *heff = hcorr->ProjectionY("heff"); hnum->Reset(); hnum->Sumw2(); hden->Reset(); hden->Sumw2(); heff->Reset(); for (Int_t i = 0; i < heff->GetNbinsX(); i++) { Float_t int1 = hcorr->Integral(i + 1, i + 1, 0, -1); if (int1 <= 0.) continue; Float_t int2 = hcorr->Integral(i + 1, i + 1, 2, -1); hnum->SetBinContent(i + 1, int2); hnum->SetBinError(i + 1, TMath::Sqrt(int2)); hden->SetBinContent(i + 1, int1); hden->SetBinError(i + 1, TMath::Sqrt(int1)); } TCanvas *cEfficiency = new TCanvas("cEfficiency", "cEfficiency"); cEfficiency->SetLogx(); cEfficiency->SetLogy(); heff->Divide(hnum, hden, 1., 1., "B"); heff->Draw(); #if 0 for (Int_t ii = 0; ii < heff->GetNbinsX(); ii++) { heff->SetBinContent(ii + 1, 1.); heff->SetBinError(ii + 1, 0.); } #endif for (Int_t i = 0; i < hcorr->GetNbinsX(); i++) { hcorr->SetBinContent(i + 1, 1, 0.); hcorr->SetBinError(i + 1, 1, 0.); } for (Int_t i = 0; i < hcorr->GetNbinsY(); i++) { hcorr->SetBinContent(1, i + 1, 0.); hcorr->SetBinError(1, i + 1, 0.); } TH2 *hcorrfit = ReturnCorrFromFit(hcorr); // Docs from AliUnfolding //Int_t AliUnfolding::Unfold(TH2* correlation, TH1* efficiency, TH1* measured, TH1* initialConditions, TH1* result, Bool_t check) // unfolds with unfolding method fgMethodType // // parameters: // correlation: response matrix as measured vs. generated // efficiency: (optional) efficiency that is applied on the unfolded spectrum, i.e. it has to be in unfolded variables. If 0 no efficiency is applied. // measured: the measured spectrum // initialConditions: (optional) initial conditions for the unfolding. if 0 the measured spectrum is used as initial conditions. // result: target for the unfolded result // check: depends on the unfolding method, see comments in specific functions for (Int_t iloop = 0; iloop < nloop; iloop++) { if (bayesian) { AliUnfolding::SetUnfoldingMethod(AliUnfolding::kBayesian); AliUnfolding::SetBayesianParameters(smooth, iter); } else { AliUnfolding::SetUnfoldingMethod(AliUnfolding::kChi2Minimization); AliUnfolding::SetChi2Regularization(AliUnfolding::RegularizationType(regul), weight); } AliUnfolding::SetSkip0BinInChi2(kTRUE); AliUnfolding::SetSkipBinsBegin(1); AliUnfolding::SetNbins(150, 150); AliUnfolding::Unfold(usecorrfit ? hcorrfit : hcorr, heff, hdata, hinit, hresu); hinit = (TH1 *)hresu->Clone(Form("hinit_%d", iloop)); } printf("hdata->Integral(2, -1) = %f\n", hdata->Integral(2, -1)); printf("hresu->Integral(2, -1) = %f\n", hresu->Integral(2, -1)); TCanvas *cUnfolded = new TCanvas ("cUnfolded", "cUnfolded", 400, 800); cUnfolded->Divide(1, 2); cUnfolded->cd(1)->SetLogx(); cUnfolded->cd(1)->SetLogy(); hdata->Draw(); hresu->Draw("same"); htrue->Draw("same"); cUnfolded->cd(2)->SetLogx(); cUnfolded->cd(2)->DrawFrame(1., 0, 300., 10); TH1 *hrat = (TH1 *)hresu->Clone("hrat"); hrat->Divide(htrue); hrat->Draw("same"); TH1 *htrig = (TH1 *)hresu->Clone("htrig"); htrig->Multiply(heff); Float_t dndeta_resu = 0.; Float_t integr_resu = 0.; Float_t dndeta_trig = 0.; Float_t integr_trig = 0.; for (Int_t i = 1; i < hresu->GetNbinsX(); i++) { dndeta_resu += hresu->GetBinContent(i + 1) * hresu->GetBinLowEdge(i + 1); integr_resu += hresu->GetBinContent(i + 1); dndeta_trig += htrig->GetBinContent(i + 1) * htrig->GetBinLowEdge(i + 1); integr_trig += htrig->GetBinContent(i + 1); } cUnfolded->SaveAs("unfold_efficiency.pdf"); integr_eff = integr_trig / integr_resu; integr_eff_err = TMath::Sqrt(integr_eff * (1. - integr_eff) / integr_resu); dndeta_eff = dndeta_trig / dndeta_resu; dndeta_eff_err = TMath::Sqrt(dndeta_eff * (1. - dndeta_eff) / dndeta_resu); printf("INEL > 0 efficiency: %.3f +- %.3f\n", integr_eff, integr_eff_err); printf("dN/dEta correction: %.3f +- %.3f\n", dndeta_eff, dndeta_eff_err); return hresu; }
//______________________________________________________________________________ void CBEnergy() { // Main method. Char_t tmp[256]; // load CaLib gSystem->Load("libCaLib.so"); // general configuration const Char_t* data = "Data.CB.E1"; const Char_t* hName = "CaLib_CB_IM_Neut"; // configuration (December 2007) //const Char_t calibration[] = "LD2_Dec_07"; //const Char_t filePat[] = "/usr/puma_scratch0/werthm/A2/Dec_07/AR/out/ARHistograms_CB_RUN.root"; // configuration (February 2009) const Char_t calibration[] = "LD2_Feb_09"; //const Char_t filePat[] = "/usr/puma_scratch0/werthm/A2/Feb_09/AR/out/ARHistograms_CB_RUN.root"; const Char_t filePat[] = "/usr/cheetah_scratch0/kaeser/CaLib/Feb_09/ARHistograms_CB_RUN.root"; // configuration (May 2009) //const Char_t calibration[] = "LD2_May_09"; //const Char_t filePat[] = "/usr/puma_scratch0/werthm/A2/May_09/AR/out/ARHistograms_CB_RUN.root"; // get number of sets Int_t nSets = TCMySQLManager::GetManager()->GetNsets(data, calibration); // create canvas Int_t n = TMath::Sqrt(nSets); TCanvas* cOverview = new TCanvas(); cOverview->Divide(n, nSets / n + 1); // create arrays Double_t* pos = new Double_t[nSets+1]; Double_t* fwhm = new Double_t[nSets+1]; // total sum histogram TH1* hTot = 0; // loop over sets for (Int_t i = 0; i < nSets; i++) { // create file manager TCFileManager m(data, calibration, 1, &i, filePat); // get histo TH2* h2 = (TH2*) m.GetHistogram(hName); // skip empty histo if (!h2) continue; // project histo sprintf(tmp, "Proj_%d", i); TH1* h = (TH1*) h2->ProjectionX(tmp); // add to total histogram if (!hTot) hTot = (TH1*) h->Clone(); else hTot->Add(h); // fit histo cOverview->cd(i+1); Fit(h, &pos[i], &fwhm[i]); } // show total histogram TCanvas* cTot = new TCanvas(); Fit(hTot, &pos[nSets], &fwhm[nSets]); // show results for (Int_t i = 0; i < nSets; i++) printf("Set %02d: Pos: %.2f MeV FWHM: %.2f MeV\n", i, pos[i], fwhm[i]); printf("Total : Pos: %.2f MeV FWHM: %.2f MeV\n", pos[nSets], fwhm[nSets]); }
//void MergeMetHists(const int Nfiles=0, // const std::string filenamebase="", // const std::string title="", const std::string name="", // const float LoX=-1, const float HiX=-1, const int rebin=1, // const std::string printfile="", bool debug=false) void MergeMetHists(const int Nfiles, const std::string filenamebase, const std::string title, const std::string name, const float LoX=-1, const float HiX=-1, const int rebin=1, const std::string printfile="", const int MetSig=4, bool debug=false, const bool logy=false) { assert (Nfiles>0 && "Number of files must be > 0"); assert (name.length()>0 && "Require hist name!"); assert (filenamebase.length()>0 && "Require base of the file name!"); std::cout << "MetSig=" << MetSig << std::endl; std::cout << "Searching for obj = " << name <<std::endl; std::string data_path, bg_path, def_path; std::string ue1_path, ue2_path, ue3_path, ue4_path, ue5_path, ue6_path; std::string ue7_path, ue8_path, ue9_path; std::string jer1_path, jer2_path, jer3_path, jer4_path, jer5_path; std::string jer6_path, jer7_path, jer8_path, jer9_path, jer10_path; data_path="/Ana/MyJetFilter/Hist/Ana_data/"; bg_path="/Ana/MyJetFilter/Hist/Ana_bckg/"; def_path="/Ana/MyJetFilter/Hist/Ana_def/"; ue1_path="/Ana/MyJetFilter/Hist/Ana_ue1/"; ue2_path="/Ana/MyJetFilter/Hist/Ana_ue2/"; ue3_path="/Ana/MyJetFilter/Hist/Ana_ue3/"; ue4_path="/Ana/MyJetFilter/Hist/Ana_ue4/"; ue5_path="/Ana/MyJetFilter/Hist/Ana_ue5/"; ue6_path="/Ana/MyJetFilter/Hist/Ana_ue6/"; ue7_path="/Ana/MyJetFilter/Hist/Ana_ue7/"; ue8_path="/Ana/MyJetFilter/Hist/Ana_ue8/"; ue9_path="/Ana/MyJetFilter/Hist/Ana_ue9/"; jer1_path="/Ana/MyJetFilter/Hist/Ana_jer1/"; jer2_path="/Ana/MyJetFilter/Hist/Ana_jer2/"; jer3_path="/Ana/MyJetFilter/Hist/Ana_jer3/"; jer4_path="/Ana/MyJetFilter/Hist/Ana_jer4/"; jer5_path="/Ana/MyJetFilter/Hist/Ana_jer5/"; jer6_path="/Ana/MyJetFilter/Hist/Ana_jer6/"; jer7_path="/Ana/MyJetFilter/Hist/Ana_jer7/"; jer8_path="/Ana/MyJetFilter/Hist/Ana_jer8/"; jer9_path="/Ana/MyJetFilter/Hist/Ana_jer9/"; jer10_path="/Ana/MyJetFilter/Hist/Ana_jer10/"; /* data_path="Ana_data"; bg_path="Ana_bckg"; def_path="Ana_def"; ue1_path="Ana_ue1"; ue2_path="Ana_ue2"; ue3_path="Ana_ue3"; ue4_path="Ana_ue4"; ue5_path="Ana_ue5"; ue6_path="Ana_ue6"; ue7_path="Ana_ue7"; ue8_path="Ana_ue8"; ue9_path="Ana_ue9"; jer1_path="Ana_jer1"; jer2_path="Ana_jer2"; jer3_path="Ana_jer3"; jer4_path="Ana_jer4"; jer5_path="Ana_jer5"; jer6_path="Ana_jer6"; jer7_path="Ana_jer7"; jer8_path="Ana_jer8"; jer9_path="Ana_jer9"; jer10_path="Ana_jer10"; */ std::vector<std::string> vPaths; vPaths.push_back(data_path); vPaths.push_back(bg_path); vPaths.push_back(def_path); vPaths.push_back(ue1_path); vPaths.push_back(ue2_path); vPaths.push_back(ue3_path); vPaths.push_back(ue4_path); vPaths.push_back(ue5_path); vPaths.push_back(ue6_path); vPaths.push_back(ue7_path); vPaths.push_back(ue8_path); vPaths.push_back(ue9_path); vPaths.push_back(jer1_path); vPaths.push_back(jer2_path); vPaths.push_back(jer3_path); vPaths.push_back(jer4_path); vPaths.push_back(jer5_path); vPaths.push_back(jer6_path); vPaths.push_back(jer7_path); vPaths.push_back(jer8_path); vPaths.push_back(jer9_path); vPaths.push_back(jer10_path); TFile *f = 0; TH1 *hist_data = 0, *hist_bg = 0; int iNHists = vPaths.size(); std::vector<TH1*> vHist; for (int n= 0; n < iNHists; ++n) { TH1 *temp=0; vHist.push_back(temp); } int NfilesOpened = 0; //for (int i=1; i<=1; ++i) for (int i=1; i<=Nfiles; ++i) { std::stringstream file; file << filenamebase << i; //file << "myhisto_PhoJetAna_Pyth_phojet22_1Njet15_test_040208.root"; f = new TFile (file.str().c_str()); if (f->IsZombie()) { std::cout << "ERROR::File " << file.str() << " did not open! Exiting." << std::endl; exit (1); } else { NfilesOpened++; if (debug) { std::cout << "File Added::"; f->Print(); } } gROOT->ls(); TFolder *fold = (TFolder*) gDirectory->FindObjectAny("Ana"); assert(fold != NULL && "folder null"); TFolder *dir = (TFolder*) fold->FindObjectAny("MyJetFilter"); assert(dir != NULL && "dir null"); TFolder *dir2 = (TFolder*) dir->FindObjectAny("Hist"); assert(dir2 != NULL && "Hist null"); //TH1 *h = dynamic_cast<TH1*> (dir3->FindObjectAny(name.c_str())); //assert (h!=NULL && "hist null"); //h->Draw(); //return; for (unsigned int iPath = 0; iPath < vPaths.size(); ++iPath) { //std::cout << "iPath = " << iPath << std::endl; TFolder *dir3 = (TFolder*) dir2->FindObjectAny(vPaths.at(iPath).c_str()); assert(dir3 != NULL && "data null"); //f->cd(); //gDirectory->pwd(); //f->cd(vPaths.at(iPath).c_str()); //gDirectory->pwd(); //if (iPath<2) f->ls(); //TH1 *hTemp = dynamic_cast<TH1*> (gDirectory->FindObjectAny(name.c_str())); std::stringstream histpath; histpath << vPaths.at(iPath) << name; //TFolder *ana = (TFolder*) gDirectory->FindObjectAny("Ana"); //assert(ana !=NULL && "Ana folder not found"); //std::cout << "histpath = " << histpath.str() << std::endl; TH1 *hTemp = dynamic_cast<TH1*> (dir3->FindObjectAny(name.c_str())); assert(hTemp != NULL && "object not found!"); if (hTemp->GetEntries()) // this has to be done to avoid crashes when adding hists which some how have 'sum=nan' instead of 'sum=0' when they do not have any entries. { if (! vHist.at(iPath)) { std::string name = hTemp->GetName() + std::string ("_Clone"); vHist.at(iPath) = dynamic_cast<TH1*>(hTemp->Clone (name.c_str())); assert(vHist.at(iPath) != NULL && "Data hist cast failed"); vHist.at(iPath)->SetDirectory(0); } else { vHist.at(iPath)->Add(hTemp); } } } delete f; } /* assert(vHist.size() == vPaths.size()); for (int k=0; k < vHist.size(); ++k) { vHist.at(k)->Print(); } */ DoSystematics(vHist); hist_data = vHist.at(0); hist_bg = vHist.at(1); /* std::cout << "NORMALIZING BG TO DATA " << std::endl; double data_int = hist_data->Integral(); double bg_int = hist_bg->Integral(); hist_bg->Scale(data_int/bg_int); std::cout << "SCALE = " << data_int/bg_int << std::endl; */ if (debug) { hist_data->Print("all"); hist_bg->Print("all"); } std::cout << "Total file added = " << NfilesOpened << std::endl; gStyle->SetOptStat(""); if (hist_data->GetEntries()) hist_data->Rebin(rebin); if (hist_bg->GetEntries()) hist_bg->Rebin(rebin); TH1 *hist_err_copy = NULL; std::string bgname = hist_bg->GetName() + std::string ("err_copy"); hist_err_copy = dynamic_cast<TH1*>(hist_bg->Clone (bgname.c_str())); hist_err_copy->SetDirectory(0); TH1 *hist_data_copy = NULL; std::string dataname = hist_data->GetName() + std::string ("data_copy"); hist_data_copy = dynamic_cast<TH1*>(hist_data->Clone (dataname.c_str())); hist_data_copy->SetDirectory(0); float x_loLim, x_hiLim; if (LoX >0) x_loLim = LoX; else x_loLim = hist_data->GetBinLowEdge(1); if (HiX >0) x_hiLim = HiX; else x_hiLim = max(FindUpLimit(hist_data), FindUpLimit(hist_bg)) + hist_data->GetBinWidth(1) * 2; if (debug) { std::cout << "min, max = " << x_loLim << ", " << x_hiLim << std::endl; } float y_hiLim = max(FindUpLimit(hist_data,"Y"), FindUpLimit(hist_bg,"Y")); if (logy) y_hiLim *= 10; else y_hiLim += y_hiLim * 0.1; gStyle->SetCanvasColor (10); gStyle->SetCanvasBorderSize (0); gStyle->SetCanvasBorderMode (0); gStyle->SetPadColor (10); gStyle->SetFillColor (10); gStyle->SetTitleFillColor (10); gStyle->SetTitleBorderSize (0); gStyle->SetStatColor (10); gStyle->SetStatBorderSize (1); gStyle->SetCanvasDefW(1200); gStyle->SetCanvasDefH(600); int labelfont = 10 * 4 + 2; //10 * font ID + precision (2 = scalable) int titlefont = 10 * 4 + 2; //10 * font ID + precision (2 = scalable) gStyle->SetLabelFont(labelfont,"X"); gStyle->SetLabelFont(labelfont,"Y"); gStyle->SetTitleFont(titlefont,"X"); gStyle->SetTitleFont(titlefont,"Y"); gStyle->SetLabelSize(0.04,"X"); gStyle->SetLabelSize(0.027,"Y"); //gStyle->SetLabelOffset(0.9); gStyle->SetTitleSize(0.03,"Y"); gStyle->SetTitleOffset(1.8,"Y"); //TGaxis::SetMaxDigits(3); hist_data->UseCurrentStyle(); hist_bg->UseCurrentStyle(); TCanvas *c1= new TCanvas; c1->Divide(2,1); c1->cd(1); if (logy) { if (hist_data->GetEntries() > 0 && hist_bg->GetEntries() > 0) gPad->SetLogy(); } gPad->SetTickx(); gPad->SetTicky(); gPad->SetGridx(); gPad->SetGridy(); TPaveText *tp = new TPaveText(0.02,0.92,0.98,0.99,"NDC"); tp->SetLineColor(10); tp->SetTextFont(titlefont); std::string tt(hist_data->GetTitle()); // hist_data->SetTitle(""); // hist_bg->SetTitle(""); if (title.length()>0) { //tt += " - "; tt += title; //tt = title; if (debug) { std::cout << tt << std::endl; } tp->AddText(tt.c_str()); } std::stringstream ytitle, xtitle; ytitle << "Events / " << setprecision(3) << hist_data->GetXaxis()->GetBinWidth(1) << " GeV"; if (debug) { std::cout << hist_data->GetBinWidth(1) <<std::endl; } if (name == "MetAll") xtitle << "#slash{E}_{T} (for all events) (GeV)"; else if (name == "Met") xtitle << "#slash{E}_{T} (after cuts) (GeV)"; else if (name == "MetSig") xtitle << "#slash{E}_{T} Significance (for all events)"; else if (name == "Njet15") xtitle << "Njets^{E_{T}>15GeV} (After #slash{E}_{T}-Sig cut)"; else if (name == "Njet20") xtitle << "Njets^{E_{T}>20GeV} (After #slash{E}_{T}-Sig cut)"; else if (name == "Njet25") xtitle << "Njets^{E_{T}>25GeV} (After #slash{E}_{T}-Sig cut)"; else if (name == "Njet30") xtitle << "Njets^{E_{T}>30GeV} (After #slash{E}_{T}-Sig cut)"; else if (name == "Njet35") xtitle << "Njets^{E_{T}>35GeV} (After #slash{E}_{T}-Sig cut)"; if (debug) { std::cout << "xtitle=" << xtitle.str() << std::endl; } if (debug) { hist_data->Print(); std::cout << "bin#\tLoEdge\tdata\tdata_err\tbg_cont\tbg_err"<<std::endl; for (unsigned bin = 0; bin <= (unsigned) hist_data_copy->GetNbinsX() + 1; ++ bin) { float val = hist_data->GetBinContent (bin); float err = hist_data->GetBinError(bin); float val2 = hist_bg->GetBinContent (bin); float err2 = hist_bg->GetBinError(bin); float loEdge = hist_data->GetBinLowEdge(bin); if (val>0 || err>0 || val2>0 || err2>0) std::cout << bin << "\t" << loEdge <<"\t" << val << "\t" << err << "\t\t" << val2 << "\t" << err2 << std::endl; } } hist_data->GetXaxis()->SetTitle(xtitle.str().c_str()); if (name.find("Njet") == std::string::npos) hist_data->GetYaxis()->SetTitle(ytitle.str().c_str()); hist_data->GetXaxis()->CenterTitle(true); hist_data->GetYaxis()->CenterTitle(true); hist_bg->GetXaxis()->SetTitle(xtitle.str().c_str()); if (name.find("Njet") == std::string::npos) hist_bg->GetYaxis()->SetTitle(ytitle.str().c_str()); hist_bg->GetXaxis()->CenterTitle(true); hist_bg->GetYaxis()->CenterTitle(true); //temp x_loLim = 0; x_hiLim = 200; hist_data->GetXaxis()->SetRangeUser(x_loLim, x_hiLim); hist_bg->GetXaxis()->SetRangeUser(x_loLim, x_hiLim); hist_data->SetMinimum(0.1); hist_bg->SetMinimum(0.1); hist_data->SetMaximum(y_hiLim); hist_bg->SetMaximum(y_hiLim); hist_data->SetMarkerStyle(8); hist_data->SetMarkerSize(1.0); hist_data->SetMarkerColor(kBlue); hist_data->SetLineColor(kBlue); hist_bg->SetMarkerColor(kRed); hist_bg->SetLineColor(kRed); hist_bg->SetFillColor(kRed); hist_data->SetTitleSize(0.04); hist_bg->SetTitleSize(0.04); TH1* hist_bg_copy = dynamic_cast<TH1*>(hist_bg->Clone ("hist_bg_BlkLine")); hist_bg_copy->SetLineColor(kBlack); hist_bg_copy->SetLineWidth(2); hist_bg_copy->SetFillColor(0); //hist_bg_copy->Draw("L"); //hist_bg->Draw("sameE2"); // hist_bg->SetFillColor(10); // hist_bg->SetLineColor(10); hist_bg->Draw("E2"); hist_bg_copy->Draw("SAME HIST"); hist_data->Draw("sameP"); //tp->Draw(); TLegend *leg = new TLegend (0.4,0.8,0.90,0.90); leg->SetTextFont(42); leg->SetTextSize(0.025); leg->SetBorderSize (1); leg->SetFillColor (10); //std::stringstream leg_data, leg_bg; //leg_data << "Data (E=" << hist_data->GetEntries() << " M=" << hist_data->GetMean() // << " R=" << hist_data->GetRMS() << ")"; //leg_bg << "Bkg (E=" << hist_bg->GetEntries() << " M=" << hist_bg->GetMean() // << " R=" << hist_bg->GetRMS() << ")"; //leg->AddEntry(hist_data,leg_data.str().c_str()); //leg->AddEntry(hist_bg,leg_bg.str().c_str()); //leg->AddEntry(hist_data,"Data (Measured) (DET Jets) "); //leg->AddEntry(hist_bg, "MC Prediction (HAD Jets, Norm to Data)"); leg->AddEntry(hist_data,"Data (Measured)"); leg->AddEntry(hist_bg, "MC Prediction"); leg->Draw(); // now to make the ratio plots for (unsigned bin = 0; bin <= (unsigned) hist_data_copy->GetNbinsX() + 1; ++ bin) { const float val = hist_err_copy->GetBinContent (bin); const float scale = val ? 1. / val : 0; hist_data_copy->SetBinContent (bin, (hist_data_copy->GetBinContent (bin) - val) * scale); hist_data_copy->SetBinError (bin, hist_data_copy->GetBinError (bin) * scale); }; for (unsigned bin = 0; bin <= (unsigned) hist_err_copy->GetNbinsX() + 1; ++ bin) { float value = hist_err_copy->GetBinContent (bin); float error = hist_err_copy->GetBinError (bin); hist_err_copy->SetBinError (bin, value ? error / value : 0); hist_err_copy->SetBinContent (bin, 0); }; /* TH1 *hist_ratio = NULL; std::string myname = hist_data->GetName() + std::string ("_copy"); hist_ratio = dynamic_cast<TH1*>(hist_data->Clone (myname.c_str())); hist_ratio->Divide(hist_bg); */ hist_data_copy->UseCurrentStyle(); hist_err_copy->UseCurrentStyle(); //new TCanvas(); c1->cd(2); gPad->SetTickx(); gPad->SetTicky(); gPad->SetGridx(); gPad->SetGridy(); hist_data_copy->SetTitle(""); hist_err_copy->SetTitle(""); //hist_data_copy->SetTitle(tt.c_str()); //hist_err_copy->SetTitle(tt.c_str()); hist_data_copy->GetXaxis()->SetTitle(xtitle.str().c_str()); hist_err_copy->GetXaxis()->SetTitle(xtitle.str().c_str()); hist_data_copy->GetXaxis()->SetRangeUser(x_loLim, x_hiLim); hist_err_copy->GetXaxis()->SetRangeUser(x_loLim, x_hiLim); float fRatioHist_ymax = 1.0; float fRatioHist_ymin = -1.0; hist_data_copy->SetMinimum(fRatioHist_ymin); hist_data_copy->SetMaximum(fRatioHist_ymax); hist_err_copy->SetMinimum(fRatioHist_ymin); hist_err_copy->SetMaximum(fRatioHist_ymax); std::stringstream ratio_ytitle; ratio_ytitle << "(Data Measured - MC Prediction) / MC Prediction"; hist_data_copy->GetYaxis()->SetTitle(ratio_ytitle.str().c_str()); hist_err_copy->GetYaxis()->SetTitle(ratio_ytitle.str().c_str()); //hist_data_copy->SetTitle(ratio_ytitle.str().c_str()); //hist_err_copy->SetTitle(ratio_ytitle.str().c_str()); hist_data_copy->GetXaxis()->CenterTitle(true); hist_data_copy->GetYaxis()->CenterTitle(true); hist_err_copy->GetXaxis()->CenterTitle(true); hist_err_copy->GetYaxis()->CenterTitle(true); // hist_data->GetYaxis()->SetRangeUser(; //// hist_bg->SetMinimum(0.1); hist_data_copy->SetLineColor(kBlue); hist_data_copy->SetMarkerColor(kBlue); hist_data_copy->SetMarkerStyle (8); hist_data_copy->SetMarkerSize(1.0); hist_err_copy->SetFillColor(kRed); hist_err_copy->SetFillStyle(3002); hist_data_copy->Draw("P"); hist_err_copy->Draw("same E2"); //tp->Draw(); c1->cd(); if (printfile.length()>0) { c1->Print(printfile.c_str()); } DebugSystError(hist_data,hist_bg, hist_data_copy, hist_err_copy); }
TH1 * UnfoldMe(Char_t *data, Char_t *mc, Char_t *anatag, Int_t bin, Bool_t useMBcorr = kTRUE, Bool_t usecorrfit = kFALSE, Bool_t ismc = kFALSE, Float_t smooth = 0.001, Int_t iter = 50, Int_t regul = AliUnfolding::kPowerLaw, Float_t weight = 100., Bool_t bayesian = kTRUE, Int_t nloop = 1) { if (ismc) TFile *fdt = TFile::Open(data); else TFile *fdt = TFile::Open(data); TFile *fmc = TFile::Open(mc); TList *ldt = (TList *)fdt->Get(Form("clist_%s", anatag)); TList *lmc = (TList *)fmc->Get(Form("clist_%s", anatag)); TH2 *hmatdt = (TH2 *)ldt->FindObject(Form("b%d_corrMatrix", bin)); if (useMBcorr) TH2 *hmatmc = (TH2 *)lmc->FindObject("effMatrix"); else TH2 *hmatmc = (TH2 *)lmc->FindObject(Form("b%d_corrMatrix", bin)); TH1 *hdata = hmatdt->ProjectionY("hdata"); hdata->Sumw2(); hdata->SetBinContent(1, 0.); hdata->SetBinError(1, 0.); // hdata->Scale(1. / hdata->Integral()); hdata->SetMarkerStyle(25); TH1 *htrue = hmatdt->ProjectionX("htrue"); htrue->Sumw2(); // htrue->Scale(1. / htrue->Integral()); htrue->SetMarkerStyle(7); htrue->SetMarkerColor(2); htrue->SetBinContent(1, 0.); htrue->SetBinError(1, 0.); TH2 *hcorr = (TH2 *)hmatmc->Clone("hcorr"); TH1 *hinit = (TH1 *)hdata->Clone("hinit"); TH1 *hresu = (TH1 *)hdata->Clone("hresu"); TH1 *hbias = (TH1 *)hdata->Clone("hbias"); hresu->SetMarkerStyle(20); hresu->SetMarkerColor(4); hresu->Reset(); TH1 *hnum = hcorr->ProjectionY("hnum"); TH1 *hden = hcorr->ProjectionY("hden"); TH1 *heff = hcorr->ProjectionY("heff"); hnum->Reset(); hnum->Sumw2(); hden->Reset(); hden->Sumw2(); heff->Reset(); for (Int_t i = 0; i < heff->GetNbinsX(); i++) { Float_t int1 = hcorr->Integral(i + 1, i + 1, 0, -1); if (int1 <= 0.) continue; Float_t int2 = hcorr->Integral(i + 1, i + 1, 2, -1); hnum->SetBinContent(i + 1, int2); hnum->SetBinError(i + 1, TMath::Sqrt(int2)); hden->SetBinContent(i + 1, int1); hden->SetBinError(i + 1, TMath::Sqrt(int1)); } new TCanvas("cEfficiency"); heff->Divide(hnum, hden, 1., 1., "B"); heff->Draw(); #if 0 for (Int_t ii = 0; ii < heff->GetNbinsX(); ii++) { heff->SetBinContent(ii + 1, 1.); heff->SetBinError(ii + 1, 0.); } #endif for (Int_t i = 0; i < hcorr->GetNbinsX(); i++) { hcorr->SetBinContent(i + 1, 1, 0.); hcorr->SetBinError(i + 1, 1, 0.); } for (Int_t i = 0; i < hcorr->GetNbinsY(); i++) { hcorr->SetBinContent(1, i + 1, 0.); hcorr->SetBinError(1, i + 1, 0.); } TH2 *hcorrfit = ReturnCorrFromFit(hcorr); for (Int_t iloop = 0; iloop < nloop; iloop++) { if (bayesian) { AliUnfolding::SetUnfoldingMethod(AliUnfolding::kBayesian); AliUnfolding::SetBayesianParameters(smooth, iter); } else { AliUnfolding::SetUnfoldingMethod(AliUnfolding::kChi2Minimization); AliUnfolding::SetChi2Regularization(regul, weight); } AliUnfolding::SetSkip0BinInChi2(kTRUE); AliUnfolding::SetSkipBinsBegin(1); AliUnfolding::SetNbins(150, 150); AliUnfolding::Unfold(usecorrfit ? hcorrfit : hcorr, heff, hdata, hinit, hresu); hinit = (TH1 *)hresu->Clone(Form("hinit_%d", iloop)); } printf("hdata->Integral(2, -1) = %f\n", hdata->Integral(2, -1)); printf("hresu->Integral(2, -1) = %f\n", hresu->Integral(2, -1)); TCanvas *cUnfolded = new TCanvas ("cUnfolded", "", 400, 800); cUnfolded->Divide(1, 2); cUnfolded->cd(1)->SetLogx(); cUnfolded->cd(1)->SetLogy(); hdata->Draw(); hresu->Draw("same"); htrue->Draw("same"); cUnfolded->cd(2)->SetLogx(); cUnfolded->cd(2)->DrawFrame(1., 0.75, 300., 1.25); TH1 *hrat = (TH1 *)hresu->Clone("hrat"); hrat->Divide(htrue); hrat->Draw("same"); TH1 *htrig = (TH1 *)hresu->Clone("htrig"); htrig->Multiply(heff); Float_t dndeta_resu = 0.; Float_t integr_resu = 0.; Float_t dndeta_trig = 0.; Float_t integr_trig = 0.; for (Int_t i = 1; i < hresu->GetNbinsX(); i++) { dndeta_resu += hresu->GetBinContent(i + 1) * hresu->GetBinLowEdge(i + 1); integr_resu += hresu->GetBinContent(i + 1); dndeta_trig += htrig->GetBinContent(i + 1) * htrig->GetBinLowEdge(i + 1); integr_trig += htrig->GetBinContent(i + 1); } // dndeta_resu /= integr_resu; // dndeta_trig /= integr_trig; integr_eff = integr_trig / integr_resu; integr_eff_err = TMath::Sqrt(integr_eff * (1. - integr_eff) / integr_resu); dndeta_eff = dndeta_trig / dndeta_resu; dndeta_eff_err = TMath::Sqrt(dndeta_eff * (1. - dndeta_eff) / dndeta_resu); printf("INEL > 0 efficiency: %.3f +- %.3f\n", integr_eff, integr_eff_err); printf("dN/dEta correction: %.3f +- %.3f\n", dndeta_eff, dndeta_eff_err); return hresu; }
void ttreesToHistograms() { //******************************************************************** //**** Variables ****// cout << "Loading variables into vectors..." << endl; vector<TString> fileName; fileName.push_back( "rootfiles0/PhotonJetPt15_Summer09.root" );//file0 fileName.push_back( "rootfiles0/PhotonJetPt30_Summer09.root" );//file1 fileName.push_back( "rootfiles0/PhotonJetPt80_Summer09.root" );//file2 fileName.push_back( "rootfiles0/PhotonJetPt170_Summer09.root" );//file3 fileName.push_back( "rootfiles0/PhotonJetPt300_Summer09.root" );//file4 fileName.push_back( "rootfiles0/PhotonJetPt470_Summer09.root" );//file5 fileName.push_back( "rootfiles0/PhotonJetPt800_Summer09.root" );//file6 TString treeName = "TreePhotonJet"; TString outputFileName = "PhotonJetHists-2009-09-02-matchesReco.root"; //********************************* //**** Set Scale // The following 4 number set the scale // example: // scale = (integrated luminosity (1/pb))*(cross section (pb))*(filter eff)/(events analyzed) float invLuminosityToScaleTo = 200; // in pb-1 vector<float> crossSection; crossSection.push_back( 2.887E5 -3.222E4 ); // in pb crossSection.push_back( 3.222E4 -1.010E3 ); crossSection.push_back( 1.010E3 -5.143E1 ); crossSection.push_back( 5.143E1 -4.193E0 ); crossSection.push_back( 4.193E0 -4.515E-1 ); crossSection.push_back( 4.515E-1 -2.003E-2 ); crossSection.push_back( 2.003E-2 ); vector<float> filterEffeciency; filterEffeciency.push_back( 1.0 ); filterEffeciency.push_back( 1.0 ); filterEffeciency.push_back( 1.0 ); filterEffeciency.push_back( 1.0 ); filterEffeciency.push_back( 1.0 ); filterEffeciency.push_back( 1.0 ); filterEffeciency.push_back( 1.0 ); vector<float> eventsAnalyzied; eventsAnalyzied.push_back( 1073270 ); eventsAnalyzied.push_back( 1088546 ); eventsAnalyzied.push_back( 993509 ); eventsAnalyzied.push_back( 1483940 ); eventsAnalyzied.push_back( 1024589 ); eventsAnalyzied.push_back( 1014413 ); eventsAnalyzied.push_back( 1216320 ); // END of setting scale //********************************* //********************************* //**** Set Cuts ****// // Variables will be plotted for each "location" vector<TString> locationCut; locationCut.push_back( "abs(hardGenPhoton_eta)>1.55&&abs(hardGenPhoton_eta)<2.5" ); locationCut.push_back( "abs(hardGenPhoton_eta)<1.45" ); vector<TString> locationName; locationName.push_back( "Endcap" ); locationName.push_back( "Barrel" ); // These cuts will be merged into one giant cut, applied to all plots for all files vector<TString> cuts; cuts.push_back( "hardGenPhoton_et>15.0&&photon_et>15.0&&photon_matches_hardGen>0.5" ); // These cuts will be applied only to corresponding file vector<TString> fileCuts; fileCuts.push_back( "event_genEventScale>15&&event_genEventScale<30" ); //file0 fileCuts.push_back( "event_genEventScale>30&&event_genEventScale<80" ); //file1 fileCuts.push_back( "event_genEventScale>80&&event_genEventScale<170" ); //file2 fileCuts.push_back( "event_genEventScale>170&&event_genEventScale<300" ); //file3 fileCuts.push_back( "event_genEventScale>300&&event_genEventScale<470" ); //file4 fileCuts.push_back( "event_genEventScale>470&&event_genEventScale<800" ); //file5 fileCuts.push_back( "event_genEventScale>800&&event_genEventScale<1400" ); //file6 //**** END of setting cuts //********************************* //********************************* int locationVariablesToPlot[2][2]; // [a][b], a=number of locations, b=2 (for min,max range of variables to plot) locationVariablesToPlot[0][0] = 16; // Endcap locationVariablesToPlot[0][1] = 35; locationVariablesToPlot[1][0] = 16; // Barrel locationVariablesToPlot[1][1] = 35; /*locationVariablesToPlot[2][0] = 0; locationVariablesToPlot[2][1] = 4; locationVariablesToPlot[3][0] = 0; locationVariablesToPlot[3][1] = 4; locationVariablesToPlot[4][0] = 0; locationVariablesToPlot[4][1] = 4; locationVariablesToPlot[5][0] = 0; locationVariablesToPlot[5][1] = 4; locationVariablesToPlot[6][0] = 0; locationVariablesToPlot[6][1] = 4; locationVariablesToPlot[7][0] = 0; locationVariablesToPlot[7][1] = 4;*/ // Variables you want plotted vector<TString> variableToPlot; // --- the following require gen level info variableToPlot.push_back( "hardGenPhoton_et" ); // 0 variableToPlot.push_back( "hardGenPhoton_eta" ); variableToPlot.push_back( "hardGenPhoton_phi" ); variableToPlot.push_back( "fmod(hardGenPhoton_phi+3.141592,20.0*3.141592/180.0)-10.0*3.141592/180.0" ); variableToPlot.push_back( "abs(hardGenPhoton_eta)" ); // 4 variableToPlot.push_back( "(recPhoton.energy-hardGenPhoton_energy)/hardGenPhoton_energy" ); variableToPlot.push_back( "(recPhoton.energy-hardGenPhoton_energy)/hardGenPhoton_energy:hardGenPhoton_energy" ); variableToPlot.push_back( "(recPhoton.energy-hardGenPhoton_energy)/hardGenPhoton_energy:abs(hardGenPhoton_eta)" ); variableToPlot.push_back( "(recPhoton.energy-hardGenPhoton_energy)/hardGenPhoton_energy:hardGenPhoton_phiMod" ); variableToPlot.push_back( "photon_hadronicOverEm:hardGenPhoton_et" ); variableToPlot.push_back( "photon_hadronicOverEm:abs(hardGenPhoton_eta)" ); // 10 variableToPlot.push_back( "photon_hadronicOverEm:hardGenPhoton_phiMod" ); variableToPlot.push_back( "photon_eta-hardGenPhoton_eta" ); variableToPlot.push_back( "photon_eta-hardGenPhoton_eta:hardGenPhoton_et" ); variableToPlot.push_back( "photon_eta-hardGenPhoton_eta:abs(hardGenPhoton_eta)" ); variableToPlot.push_back( "deltaPhiGenRecPhoton" ); // 15 // --- the following require only rec photons variableToPlot.push_back( "photon_et" ); // 16 variableToPlot.push_back( "photon_eta" ); variableToPlot.push_back( "photon_phi" ); variableToPlot.push_back( "fmod(photon_phi+3.141592,20.0*3.141592/180.0)-10.0*3.141592/180.0" ); variableToPlot.push_back( "abs(photon_eta)" ); // 20 variableToPlot.push_back( "photon_r9" ); variableToPlot.push_back( "photon_ecalRecHitSumEtConeDR03" ); variableToPlot.push_back( "photon_hcalTowerSumEtConeDR03" ); variableToPlot.push_back( "photon_trkSumPtSolidConeDR03" ); variableToPlot.push_back( "photon_trkSumPtHollowConeDR03" ); //25 variableToPlot.push_back( "photon_nTrkSolidConeDR03" ); variableToPlot.push_back( "photon_nTrkHollowConeDR03" ); variableToPlot.push_back( "photon_hadronicOverEm" ); variableToPlot.push_back( "photon_r2x5" ); variableToPlot.push_back( "photon_ecalRecHitSumEtConeDR03/photon_et" ); // 30 variableToPlot.push_back( "photon_hcalTowerSumEtConeDR03/photon_et" ); variableToPlot.push_back( "photon_trkSumPtSolidConeDR03/photon_et" ); variableToPlot.push_back( "photon_trkSumPtHollowConeDR03/photon_et" ); // --- the following require jets /*variableToPlot.push_back( "calcDeltaPhi(photon_phi,jet_phi)" ); variableToPlot.push_back( "calcDeltaPhi(photon_phi,jet2_phi)" ); // 35 variableToPlot.push_back( "calcDeltaPhi(jet_phi,jet2_phi)" );*/ variableToPlot.push_back( "(photon_et-jet_et)/photon_et" ); variableToPlot.push_back( "jet2_et/photon_et" ); // Histograms for the above variables vector<TH1*> histogram; // --- the following require gen level info histogram.push_back( new TH1F("photonGenEt", "Photon E_{T} ;E_{T} (GeV);entries per 15 GeV", 50, 0, 750) ); // 0 histogram.push_back( new TH1F("photonGenEta", "Photon #eta ;#eta;entries per 0.1 bin", 61, -3.05, 3.05) ); histogram.push_back( new TH1F("photonGenPhi", "Photon #phi ;#phi;entries per bin", 62, (-1.-1./30.)*TMath::Pi(), (1.+1./30.)*TMath::Pi()) ); histogram.push_back( new TH1F("photonGenPhiMod", "Photon #phi_{mod} ", 42, (-1.-1./20)*0.1745329, (1.+1./20.)*0.1745329) ); histogram.push_back( new TH1F("photonGenAbsEta", "Photon |#eta| ", 51, 0.00, 2.55) ); histogram.push_back( new TH1F("photonDeltaE", "(E(#gamma_{rec})-E(#gamma_{gen}))/E(#gamma_{gen}) ", 50, -0.8, 0.3) ); histogram.push_back( new TH2F("photonDeltaE_vs_E","(E(#gamma_{rec})-E(#gamma_{gen}))/E(#gamma_{gen}) vs E(#gamma_{gen}) ", 50, 0, 3000, 50, -0.8, 0.3) ); histogram.push_back( new TH2F("photonDeltaE_vs_AbsEta","(E(#gamma_{rec})-E(#gamma_{gen}))/E(#gamma_{gen}) vs |#eta(#gamma_{gen}|) ", 51, 0.0, 2.5, 50, -0.8, 0.3) ); histogram.push_back( new TH2F("photonDeltaE_vs_PhiMod","(E(#gamma_{rec})-E(#gamma_{gen}))/E(#gamma_{gen}) vs #phi_{mod}(#gamma_{gen}) ", 42, (-1.-1./20)*0.1745329, (1.+1./20.)*0.1745329, 50, -0.9, 0.2) ); histogram.push_back( new TH2F("photonHoverE_vs_Et", "H/E vs E_{T}(#gamma_{gen}) ", 50, 0, 1000, 50, 0.0, 0.2) ); histogram.push_back( new TH2F("photonHoverE_vs_AbsEta", "H/E vs |#eta(#gamma_{gen})| ", 51, 0.0, 2.5, 50, 0.0, 0.2) ); histogram.push_back( new TH2F("photonHoverE_vs_PhiMod", "H/E vs #phi_{mod}(#gamma_{gen}) ", 42, (-1.-1./20)*0.1745329, (1.+1./20.)*0.1745329, 50, 0.0, 0.2) ); histogram.push_back( new TH1F("photonDeltaEta", "#Delta#eta(#gamma_{rec},#gamma_{gen}) ;#Delta#eta(#gamma_{rec},#gamma_{gen});entries/bin", 41, -0.01, 0.01) ); histogram.push_back( new TH2F("photonDeltaEta_vs_Et", "#Delta#eta(#gamma_{rec},#gamma_{gen}) vs E_{T}(#gamma_{gen}) ", 50, 0, 1000, 41, -0.1, 0.1) ); histogram.push_back( new TH2F("photonDeltaEta_vs_AbsEta","#Delta#eta(#gamma_{rec},#gamma_{gen}) vs #eta(#gamma_{gen})", 51, 0.0, 2.55, 41, -0.1, 0.1) ); histogram.push_back( new TH1F("photonDeltaPhi", "#Delta#phi(#gamma_{rec},#gamma_{gen}) ;#Delta#phi(#gamma_{rec},#gamma_{gen});entries/bin", 41, 0.0, 0.01) ); // 15 // --- the following require only rec photons histogram.push_back( new TH1F("photonEt", "Photon E_{T} ;E_{T} (GeV);entries per 15 GeV", 50, 0, 750 ) ); // 16 histogram.push_back( new TH1F("photonEta", "Photon #eta ;#eta;entries per 0.1" , 61, -3.05, 3.05) ); histogram.push_back( new TH1F("photonPhi", "Photon #phi ;#phi;entries per bin" , 62, (-1.-1./30.)*TMath::Pi(), (1.+1./30.)*TMath::Pi()) ); histogram.push_back( new TH1F("photonPhiMod", "Photon #phi_{mod} " , 42, (-1.-1./20)*0.1745329, (1.+1./20.)*0.1745329) ); histogram.push_back( new TH1F("photonAbsEta", "Photon |#eta| " , 51, 0.00, 2.55) ); // 20 histogram.push_back( new TH1F("photonR9", "R9 = E(3x3) / E(SuperCluster) ;R9;entries/bin" , 50, 0.6, 1.0) ); histogram.push_back( new TH1F("photonEcalIso", "#SigmaEcal Rec Hit E_{T} in Hollow #DeltaR cone " , 50, 0 , 15) ); histogram.push_back( new TH1F("photonHcalIso", "#SigmaHcal Rec Hit E_{T} in Hollow #DeltaR cone " , 50, 0 , 15) ); histogram.push_back( new TH1F("photonTrackSolidIso", "#Sigmatrack p_{T} in Solid #DeltaR cone " , 50, 0 , 15) ); histogram.push_back( new TH1F("photonTrackHollowIso", "#Sigmatrack p{T} in Hollow #DeltaR cone " , 50, 0 , 15) ); // 25 histogram.push_back( new TH1F("photonTrackCountSolid", "Number of tracks in Solid #DeltaR cone ;Number of Tracks;entries/bin" , 25, -0.5, 24.5) ); histogram.push_back( new TH1F("photonTrackCountHollow", "Number of tracks in Hollow #DeltaR cone ;Number of Tracks;entries/bin", 25, -0.5, 24.5) ); histogram.push_back( new TH1F("photonHoverE", "Hadronic / EM ", 50, 0.0, 0.2) ); histogram.push_back( new TH1F("photonScSeedE2x5over5x5", "E2x5/E5x5 " , 50, 0.6, 1.0) ); histogram.push_back( new TH1F("photonEcalIsoOverE", "#SigmaEcal Rec Hit E_{T} in #DeltaR cone / Photon E_{T} " , 50, -0.1, 1.0) ); // 30 histogram.push_back( new TH1F("photonHcalIsoOverE", "#SigmaHcal Rec Hit E_{T} in #DeltaR cone / Photon E_{T} " , 50, -0.1, 1.0) ); histogram.push_back( new TH1F("photonTrackSolidIsoOverE" , "#SigmaTrack p_{T} in #DeltaR cone / Photon E_{T} " , 50, -0.1, 1.0) ); histogram.push_back( new TH1F("photonTrackHollowIsoOverE", "#SigmaTrack p_{T} in Hollow #DeltaR cone / Photon E_{T} " , 50, -0.1, 1.0) ); // --- the following require jets /*histogram.push_back( new TH1F("h_deltaPhi_photon_jet", "#Delta#phi between Highest E_{T} #gamma and jet;#Delta#phi(#gamma,1^{st} jet)" , 50, 0, 3.1415926) ); histogram.push_back( new TH1F("h_deltaPhi_photon_jet2","#Delta#phi between Highest E_{T} #gamma and 2^{nd} highest jet;#Delta#phi(#gamma,2^{nd} jet)", 50, 0, 3.1415926) ); histogram.push_back( new TH1F("h_deltaPhi_jet_jet2" , "#Delta#phi between Highest E_{T} jet and 2^{nd} jet;#Delta#phi(1^{st} jet,2^{nd} jet)" , 50, 0, 3.1415926) );*/ histogram.push_back( new TH1F("h_deltaEt_photon_jet" , "(E_{T}(#gamma)-E_{T}(jet))/E_{T}(#gamma) when #Delta#phi(#gamma,1^{st} jet) > 2.8;#DeltaE_{T}(#gamma,1^{st} jet)/E_{T}(#gamma)", 20, -1.0, 1.0) ); histogram.push_back( new TH1F("h_jet2_etOverPhotonEt", "E_{T}(2^{nd} highest jet) / E_{T}(#gamma);E_{T}(2^{nd} Jet)/E_{T}(#gamma)", 20, 0.0, 4.0) ); //**** END of Variables ****// //******************************************************************** //******************************************************************** //**** Main part of Program ****// // Human error checking if (variableToPlot.size() != histogram.size() ) { cout << "Should have equal entries in histogram and variableToPlot vector." << endl; return; } if (fileName.size() > crossSection.size() ) { cout << "Should have equal entries in fileName and crossSection vetor." << endl; return; } if (fileName.size() > fileCuts.size() ) { cout << "Should have equal entries in fileName and fileCuts vector." << endl; return; } // Combine all the cuts into one cout << endl << "Cuts that will be applied to everything: " << endl << " "; TCut allCuts = ""; for (int i =0; i<cuts.size(); i++) { allCuts += cuts[i]; if (i>0) cout << "&&"; cout << "(" << cuts[i] << ")"; } cout << endl << endl; // Open the files & set their scales cout << endl << "Histograms will be scaled to " << invLuminosityToScaleTo << "pb-1 " << endl; cout << "Looking for TTree named \"" << treeName << "\" in files..." << endl; vector<float> fileScale; TList *fileList = new TList(); for (int i=0; i < fileName.size(); i++) { TFile* currentFile = TFile::Open(fileName[i]); fileList->Add(currentFile); float currentScale = crossSection[i]*invLuminosityToScaleTo*filterEffeciency[i]/eventsAnalyzied[i]; fileScale.push_back( currentScale ); // Display entries in that file's TTree TTree* tree; currentFile->GetObject(treeName, tree); cout << "file" << i <<": " << fileName[i] << " contains " << tree->GetEntries(allCuts) << " entries, and will be scaled by " << currentScale << endl; } cout << endl << endl; //Create output file TFile *outputFile = TFile::Open( outputFileName, "RECREATE" ); //************************************************************ // Core of the Script // // Loop over locations for (int l=0; l<locationName.size(); l++) { TString currentLocation = locationName[l]; TCut currentCuts = allCuts; currentCuts += locationCut[l]; cout << "Creating plots for " << currentLocation << ", " << locationCut[l] << endl; // Loop over variables to plot for (int i=0; i<variableToPlot.size(); i++) { // should we plot this variable for this location? if (i<locationVariablesToPlot[l][0] || i>locationVariablesToPlot[l][1]) continue; TString currentHistType = histogram[i]->IsA()->GetName(); TString currentHistName = TString(histogram[i]->GetName()) + "_" + currentLocation; TString currentHistTitle = TString(histogram[i]->GetTitle()) + "(" + currentLocation + ")"; cout << " " << variableToPlot[i] << " >> " << currentHistName; TString currentHistDrawOpt; if (currentHistType=="TH2F") { currentHistDrawOpt="goffbox"; } else { currentHistDrawOpt="egoff"; } TH1* currentHist = (TH1*)histogram[i]->Clone(currentHistName); // Creates clone with name currentHistName currentHist->Sumw2(); // store errors currentHist->SetTitle(currentHistTitle); //cout << " from file"; // Plot from the first file int f = 0; //cout << f; TTree *tree; TFile *current_file = (TFile*)fileList->First(); current_file->cd(); current_file->GetObject(treeName, tree); tree->Draw(variableToPlot[i]+">>"+currentHistName,currentCuts+TCut(fileCuts[f]),currentHistDrawOpt); currentHist->Scale(fileScale[f]); f++; // Loop over files current_file = (TFile*)fileList->After( current_file ); while ( current_file ) { current_file->cd(); //cout << ", file" << f; current_file->GetObject(treeName, tree); TString tempHistName = currentHistName+"Temp"; TH1* tempHist = (TH1*)currentHist->Clone(tempHistName); tree->Draw(variableToPlot[i]+">>"+tempHistName,currentCuts+TCut(fileCuts[f]),currentHistDrawOpt); tempHist->Scale(fileScale[f]); currentHist->Add(tempHist); tempHist->Delete(); current_file = (TFile*)fileList->After( current_file ); f++; } // End of loop over files outputFile->cd(); currentHist->Write(); cout << endl; } // End of loop over variabls to plot } // End of loop over locations // END of Core of Script // //************************************************************ cout << endl; cout << "Wrote file " << outputFileName << endl; cout << endl; outputFile->Close(); }