void fitSlices(TH2* hCorr, TF1* func){ int nBins = hCorr->GetNbinsX(); TH1D* hMean = new TH1D(Form("%s_1",hCorr->GetName()),"",nBins,hCorr->GetXaxis()->GetXmin(),hCorr->GetXaxis()->GetXmax()); TH1D* hSigma = new TH1D(Form("%s_2",hCorr->GetName()),"",nBins,hCorr->GetXaxis()->GetXmin(),hCorr->GetXaxis()->GetXmax()); for(int i = 1; i < nBins+1; ++i){ int bin = nBins - i; TH1D* h = hCorr->ProjectionY(Form("%s_bin%d",hCorr->GetName(),bin),i,i); func->SetParameter(0,h->GetMaximum()); func->SetParameter(1,h->GetMean()); func->SetParameter(2,h->GetRMS()); if(useFits) h->Fit(func); hMean->SetBinContent(i,func->GetParameter(1)); hMean->SetBinError(i,func->GetParError(1)); hSigma->SetBinContent(i,func->GetParameter(2)); hSigma->SetBinError(i,func->GetParError(2)); if(onlySaveTable){ h->Delete(); } } }
TGraphErrors* plot_point( const TString infile, double R, double R_sig ) { TTree *TData = new TTree(); TData->ReadFile(infile, "t/D:x:y:z:B1:B1Range:B2:B2Range:B3:B3Range:V:T1:T2:T3:T4:T5:T6:T7:T8"); TH1D *h = new TH1D("h", "", 10000, 0, 10000); TH1D *h2 = new TH1D("h2", "", 10000, 0, 10000); TData->Draw("TMath::Abs(B2)>>h", "", "goff"); TData->Draw("TMath::Abs(B3)>>h2", "", "goff"); vector<double> B_ext, B_in, Bratio, u, u_err, B_err; B_in.push_back(h2->GetMean(1)); B_ext.push_back(h->GetMean(1)); Bratio.push_back(B_in[0] / B_ext[0]); u.push_back( (Bratio[0]*(R**2) + Bratio[0] - 2 - 2*sqrt((Bratio[0]**2)*(R**2) - Bratio[0]*(R**2) - Bratio[0] + 1 ) ) / (Bratio[0]*(R**2) - Bratio[0]) ); B_err.push_back( 0.00 ); u_err.push_back( 0.00 ); TGraphErrors *g_uvB = new TGraphErrors(u.size(), &B_ext[0], &u[0], &B_err[0], &u_err[0]); h->Delete(); h2->Delete(); return g_uvB; }
/*=========================================================*/ Float_t AGY(Char_t *matn,Float_t peak,Float_t width=0.0) { Axis_t axmax=axmin+numchx; setcanvas(2); TH1D *hist; hist=(TH1D*)gROOT->FindObject("xtemp"); if(hist!=NULL)hist->Delete(); hist=new TH1D("xtemp","xtemp",NCHX,0,DIMX); hist->Add(histx,1.0); Float_t a=GY(matn,peak,width); histx->Add(hist,1.0); c1->cd(2); histx->SetAxisRange(axmin,axmax); histx->SetLineColor(3); histx->Draw(); return a; }
/*=========================================================*/ Float_t AGX(Char_t *matn,Float_t peak,Float_t width=0.0) { Axis_t aymax=aymin+numchy; setcanvas(2); TH1D *hist; hist=(TH1D*)gROOT->FindObject("ytemp"); if(hist!=NULL)hist->Delete(); hist=new TH1D("ytemp","ytemp",NCHY,0,DIMY); hist->Add(histy,1.0); Float_t a=GX(matn,peak,width); histy->Add(hist,1.0); c1->cd(2); histy->SetAxisRange(aymin,aymax); histy->SetLineColor(3); histy->Draw(); return a; }
double FitConfidence::choleskyUncertainty( double xx, double * fCov, TF1 * f, int nSamples ){ int nP = f->GetNpar(); INFO( FitConfidence::classname(), "Num Params : " << nP ); double *fCovSqrt = new double[ nP * nP ]; calcCholesky( nP, fCov, fCovSqrt ); double yerr = 0; TH1D *hDistributionAtX = new TH1D("hDistributionAtX","",200,f->Eval(xx) - .2,f->Eval(xx) + .2); for (int n = 0; n < nSamples; n++ ) { double val = randomSqrtCov(xx,f,nP,fCovSqrt); hDistributionAtX->Fill( val ); } yerr = hDistributionAtX->GetRMS(); hDistributionAtX->Delete(); return yerr; }
void makeCentralityTable(int nbins = 40, const string label = "hf", const char * tag = "HFhitBins", double MXS = 0.){ // This macro assumes all inefficiency is in the most peripheral bin. double EFF = 1. - MXS; // Retrieving data int nFiles = 1; vector<string> infiles; // TFile* infile = new TFile("/net/hisrv0001/home/yetkin/pstore02/ana/Hydjet_MinBias_d20100222/Hydjet_MinBias_4TeV_runs1to300.root"); // fwlite::Event event(infile); infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs1to10.root"); // infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs11to20.root"); infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs21to30.root"); infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs31to40.root"); infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs41to50.root"); infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs51to60.root"); // infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs61to70.root"); // infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs71to80.root"); // infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs81to90.root") // infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs91to100.root"); fwlite::ChainEvent event(infiles); vector<int> runnums; // Creating output table TFile* outFile = new TFile("tables.root","update"); TDirectory* dir = outFile->mkdir(tag); dir->cd(); TH1D::SetDefaultSumw2(); CentralityBins* bins = new CentralityBins("noname","Test tag", nbins); bins->table_.reserve(nbins); // Setting up variables & branches double binboundaries[nbinsMax+1]; vector<float> values; // Determining bins of cross section // loop over events unsigned int events=0; for(event.toBegin(); !event.atEnd(); ++event, ++events){ edm::EventBase const & ev = event; if( events % 100 == 0 ) cout<<"Processing event : "<<events<<endl; edm::Handle<edm::GenHIEvent> mc; ev.getByLabel(edm::InputTag("heavyIon"),mc); edm::Handle<reco::Centrality> cent; ev.getByLabel(edm::InputTag("hiCentrality"),cent); double b = mc->b(); double npart = mc->Npart(); double ncoll = mc->Ncoll(); double nhard = mc->Nhard(); double hf = cent->EtHFhitSum(); double hftp = cent->EtHFtowerSumPlus(); double hftm = cent->EtHFtowerSumMinus(); double eb = cent->EtEBSum(); double eep = cent->EtEESumPlus(); double eem = cent->EtEESumMinus(); double parameter = 0; if(label.compare("npart") == 0) parameter = npart; if(label.compare("ncoll") == 0) parameter = ncoll; if(label.compare("nhard") == 0) parameter = nhard; if(label.compare("b") == 0) parameter = b; if(label.compare("hf") == 0) parameter = hf; if(label.compare("hft") == 0) parameter = hftp + hftm; if(label.compare("eb") == 0) parameter = eb; if(label.compare("ee") == 0) parameter = eep+eem; values.push_back(parameter); int run = event.id().run(); if(runnums.size() == 0 || runnums[runnums.size()-1] != run) runnums.push_back(run); } if(label.compare("b") == 0) sort(values.begin(),values.end(),descend); else sort(values.begin(),values.end()); double max = values[events-1]; binboundaries[nbins] = max; cout<<"-------------------------------------"<<endl; cout<<label.data()<<" based cuts are : "<<endl; cout<<"("; int bin = 0; for(int i = 0; i< nbins; ++i){ // Find the boundary int offset = (int)(MXS*events); double xsec = events*(1 + MXS); // Below should be replaced with an integral // when inefficiency is better parametrized // than a step function. int entry = (int)(i*(xsec/nbins)) - offset; binboundaries[i] = values[entry]; cout<<" "<<binboundaries[i]; if(i < nbins - 1) cout<<","; else cout<<")"<<endl; } cout<<"-------------------------------------"<<endl; // Determining Glauber results in various bins TH2D* hNpart = new TH2D("hNpart","",nbins,binboundaries,500,0,500); TH2D* hNcoll = new TH2D("hNcoll","",nbins,binboundaries,2000,0,2000); TH2D* hNhard = new TH2D("hNhard","",nbins,binboundaries,250,0,250); TH2D* hb = new TH2D("hb","",nbins,binboundaries,300,0,30); for(event.toBegin(); !event.atEnd(); ++event){ edm::EventBase const & ev = event; edm::Handle<edm::GenHIEvent> mc; ev.getByLabel(edm::InputTag("heavyIon"),mc); edm::Handle<reco::Centrality> cent; ev.getByLabel(edm::InputTag("hiCentrality"),cent); double b = mc->b(); double npart = mc->Npart(); double ncoll = mc->Ncoll(); double nhard = mc->Nhard(); double hf = cent->EtHFhitSum(); double hftp = cent->EtHFtowerSumPlus(); double hftm = cent->EtHFtowerSumMinus(); double eb = cent->EtEBSum(); double eep = cent->EtEESumPlus(); double eem = cent->EtEESumMinus(); double parameter = 0; if(label.compare("npart") == 0) parameter = npart; if(label.compare("ncoll") == 0) parameter = ncoll; if(label.compare("nhard") == 0) parameter = nhard; if(label.compare("b") == 0) parameter = b; if(label.compare("hf") == 0) parameter = hf; if(label.compare("hft") == 0) parameter = hftp + hftm; if(label.compare("eb") == 0) parameter = eb; if(label.compare("ee") == 0) parameter = eep+eem; hNpart->Fill(parameter,npart); hNcoll->Fill(parameter,ncoll); hNhard->Fill(parameter,nhard); hb->Fill(parameter,b); } // Fitting Glauber distributions in bins to get mean and sigma values TF1* fGaus = new TF1("fb","gaus(0)",0,2); fGaus->SetParameter(0,1); fGaus->SetParameter(1,0.04); fGaus->SetParameter(2,0.02); fitSlices(hNpart,fGaus); fitSlices(hNcoll,fGaus); fitSlices(hNhard,fGaus); fitSlices(hb,fGaus); /* hNpart->FitSlicesY(); hNcoll->FitSlicesY(); hNhard->FitSlicesY(); hb->FitSlicesY(); */ TH1D* hNpartMean = (TH1D*)gDirectory->Get("hNpart_1"); TH1D* hNpartSigma = (TH1D*)gDirectory->Get("hNpart_2"); TH1D* hNcollMean = (TH1D*)gDirectory->Get("hNcoll_1"); TH1D* hNcollSigma = (TH1D*)gDirectory->Get("hNcoll_2"); TH1D* hNhardMean = (TH1D*)gDirectory->Get("hNhard_1"); TH1D* hNhardSigma = (TH1D*)gDirectory->Get("hNhard_2"); TH1D* hbMean = (TH1D*)gDirectory->Get("hb_1"); TH1D* hbSigma = (TH1D*)gDirectory->Get("hb_2"); cout<<"-------------------------------------"<<endl; cout<<"# Bin NpartMean NpartSigma NcollMean NcollSigma bMean bSigma BinEdge"<<endl; // Enter values in table for(int i = 0; i < nbins; ++i){ bins->table_[nbins-i-1].n_part_mean = hNpartMean->GetBinContent(i); bins->table_[nbins-i-1].n_part_var = hNpartSigma->GetBinContent(i); bins->table_[nbins-i-1].n_coll_mean = hNcollMean->GetBinContent(i); bins->table_[nbins-i-1].n_coll_var = hNcollSigma->GetBinContent(i); bins->table_[nbins-i-1].b_mean = hbMean->GetBinContent(i); bins->table_[nbins-i-1].b_var = hbSigma->GetBinContent(i); bins->table_[nbins-i-1].n_hard_mean = hNhardMean->GetBinContent(i); bins->table_[nbins-i-1].n_hard_var = hNhardSigma->GetBinContent(i); bins->table_[nbins-i-1].bin_edge = binboundaries[i]; cout<<i<<" " <<hNpartMean->GetBinContent(i)<<" " <<hNpartSigma->GetBinContent(i)<<" " <<hNcollMean->GetBinContent(i)<<" " <<hNcollSigma->GetBinContent(i)<<" " <<hbMean->GetBinContent(i)<<" " <<hbSigma->GetBinContent(i)<<" " <<binboundaries[i]<<" " <<endl; } cout<<"-------------------------------------"<<endl; // Save the table in output file if(onlySaveTable){ TH1D* hh = (TH1D*)gDirectory->Get("hNpart_0"); hh->Delete(); hh = (TH1D*)gDirectory->Get("hNcoll_0"); hh->Delete(); hh = (TH1D*)gDirectory->Get("hNhard_0"); hh->Delete(); hh = (TH1D*)gDirectory->Get("hb_0"); hh->Delete(); hNpart->Delete(); hNpartMean->Delete(); hNpartSigma->Delete(); hNcoll->Delete(); hNcollMean->Delete(); hNcollSigma->Delete(); hNhard->Delete(); hNhardMean->Delete(); hNhardSigma->Delete(); hb->Delete(); hbMean->Delete(); hbSigma->Delete(); } for(int i = 0; i < runnums.size(); ++i){ CentralityBins* binsForRun = (CentralityBins*) bins->Clone(); binsForRun->SetName(Form("run%d",runnums[i])); binsForRun->Write(); } bins->Delete(); outFile->Write(); }
TF1* GeneralCorrectionFunction( double ChannelRangeMin, double ChannelRangeMax,double ChannelPeakPos , TH2D *h2DInputForCorrection , int LineIndex, TString InputType="T10DeriMaxEnergy", TString CorrNumber="1", double XRangeMin=0, double XRangeMax=300, TString FitFuncCorr="pol2", double FitCorrRangeMin=10, double FitCorrRangeMax= 270, double TresholdForCorrection=10, TString FitFuncSlicesString="gaus(0)+[3]+gaus(4)" ) { h2DInputForCorrection->GetYaxis()->SetRangeUser(ChannelRangeMin,ChannelRangeMax); char buf[60]; sprintf(buf, "hMaxCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex); TH1D *hMaxPosManually=new TH1D(buf,"",h2DInputForCorrection->GetNbinsX(),h2DInputForCorrection->GetXaxis()->GetXmin(),h2DInputForCorrection->GetXaxis()->GetXmax()); sprintf(buf, "hMaxFitCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex); TH1D *hMaxPosManuallyFit=new TH1D(buf,"",h2DInputForCorrection->GetNbinsX(),h2DInputForCorrection->GetXaxis()->GetXmin(),h2DInputForCorrection->GetXaxis()->GetXmax()); sprintf(buf, "hGausSigmaCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex); TH1D *hGausSigmaManually=new TH1D(buf,"",h2DInputForCorrection->GetNbinsX(),h2DInputForCorrection->GetXaxis()->GetXmin(),h2DInputForCorrection->GetXaxis()->GetXmax()); for(int binX = h2DInputForCorrection->GetXaxis()->FindBin(XRangeMin);binX <= h2DInputForCorrection->GetXaxis()->FindBin(XRangeMax);binX++) //for(int binX = h2DInputForCorrection->GetXaxis()->FindBin(200);binX <= h2DInputForCorrection->GetXaxis()->FindBin(200);binX++) { TH1D *hProfileY =h2DInputForCorrection->ProjectionY("_py",binX,binX); double MaxValue=hProfileY->GetBinCenter(hProfileY->GetMaximumBin()); //hMaxPosManually->SetBinContent(binX, MaxValue); //h2DInputForCorrection //cout <<hProfileY->GetEntries()<<endl; //TF1* FitFuncSlices = new TF1("FitFuncSlices","gaus(0)+[3]",MaxValue-20,MaxValue+20); //cout << TMath::Max(MaxValue-20,double(ChannelRangeMin)) << "\t" << TMath::Min(MaxValue+20,double(ChannelRangeMax)) << "\t"<<endl; TF1* FitFuncGausSlices = new TF1("FitFuncGausSlices","gaus(0)",TMath::Max(MaxValue-20,double(ChannelRangeMin)),TMath::Min(MaxValue+20,double(ChannelRangeMax))); FitFuncGausSlices->SetParameters(hProfileY->GetBinContent(hProfileY->GetMaximumBin()),MaxValue,4); hProfileY->Fit(FitFuncGausSlices,"RNIQ"); TF1* FitFuncSlices = new TF1("FitFuncSlices",FitFuncSlicesString.Data(),TMath::Max(MaxValue-3*FitFuncGausSlices->GetParameter(2),double(ChannelRangeMin)),TMath::Min(MaxValue+3*FitFuncGausSlices->GetParameter(2),double(ChannelRangeMax))); FitFuncSlices->SetParameters(FitFuncGausSlices->GetParameter(0),FitFuncGausSlices->GetParameter(1),FitFuncGausSlices->GetParameter(2),10,10,FitFuncGausSlices->GetParameter(1)-5,5); FitFuncSlices->SetParLimits(0,FitFuncGausSlices->GetParameter(0)*0.8,FitFuncGausSlices->GetParameter(0)*1.5); FitFuncSlices->SetParLimits(1,TMath::Max(FitFuncGausSlices->GetParameter(1)-10,double(ChannelRangeMin)),TMath::Min(FitFuncGausSlices->GetParameter(1)+10,double(ChannelRangeMax))); FitFuncSlices->SetParLimits(2,0,FitFuncGausSlices->GetParameter(2)*2); FitFuncSlices->SetParLimits(3,0,500); FitFuncSlices->SetParLimits(4,0,FitFuncGausSlices->GetParameter(0)*0.3); FitFuncSlices->SetParLimits(5,TMath::Max(FitFuncGausSlices->GetParameter(1)-10,double(ChannelRangeMin)),TMath::Min(MaxValue-1,double(ChannelRangeMax))); FitFuncSlices->SetParLimits(6,0,10); hProfileY->Fit(FitFuncSlices,"RINQ"); //hProfileY->DrawCopy(); //cout <<MaxValue<<" " << FitFuncSlices->GetParameter(1) << " " << FitFuncSlices->GetParError(1) <<endl; //cout <<MaxValue<<" " << FitFuncSlices->GetParameter(1) << " " << FitFuncSlices->GetMaximumX() <<endl; hMaxPosManually->SetBinContent(binX, (FitFuncSlices->GetParameter(1))/ChannelPeakPos); hMaxPosManually->SetBinError(binX, FitFuncSlices->GetParError(1)/ChannelPeakPos); hGausSigmaManually->SetBinContent(binX, FitFuncSlices->GetParameter(2)); hGausSigmaManually->SetBinError(binX, FitFuncSlices->GetParError(2)); if(FitFuncSlices->GetParameter(2)<TresholdForCorrection && FitFuncSlices->GetParError(2)<5) { hMaxPosManuallyFit->SetBinContent(binX, (FitFuncSlices->GetParameter(1))/ChannelPeakPos); hMaxPosManuallyFit->SetBinError(binX, FitFuncSlices->GetParError(1)/ChannelPeakPos); } //hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->SetBinError(binX, FitFuncSlices->GetParameter(2)/ChannelPeakPos); hProfileY->Delete(); //cin.ignore(); } //write histos to file //sprintf(buf, "hMaxCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex); hMaxPosManually->Write(0,TObject::kOverwrite); //sprintf(buf, "hGausSigmaCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex); hGausSigmaManually->Write(0,TObject::kOverwrite); hMaxPosManuallyFit->Write(0,TObject::kOverwrite); sprintf(buf, "funcCorr%s_%sNorm_%d",CorrNumber.Data(),InputType.Data(),LineIndex); //fit corr function and write it to file TF1 *funcCorrNorm = new TF1(buf,FitFuncCorr.Data(),FitCorrRangeMin,FitCorrRangeMax); funcCorrNorm->SetParameters(1,0,-0); funcCorrNorm->SetParLimits(0,0.8,1); //funcCorrNorm->SetParLimits(2,-1E5,0); //if(LineIndex==2) // hMaxPosManuallyFit->Fit(funcCorrNorm,"RBI"); //else hMaxPosManuallyFit->Fit(funcCorrNorm,"RBQI"); sprintf(buf, "funcCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex); TF1 *funcCorr = new TF1(buf,FitFuncCorr.Data(),FitCorrRangeMin,FitCorrRangeMax); for(int i= 0; i<funcCorr->GetNpar();i++) { funcCorr->SetParameter(i,funcCorrNorm->GetParameter(i)*ChannelPeakPos); } //sprintf(buf, "funcCorr%s_%sNorm_%d",CorrNumber.Data(),InputType.Data(),LineIndex); funcCorrNorm->Write(0,TObject::kOverwrite); //sprintf(buf, "funcCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex); funcCorr->Write(0,TObject::kOverwrite); h2DInputForCorrection->GetYaxis()->UnZoom(); return funcCorr; }
TGraphErrors *FitConfidence::choleskyBands( TFitResultPtr fitResult, TF1 * f, int nSamples, int nPoints, Reporter* rp, double x1, double x2 ){ int nP = f->GetNpar(); // INFO( FitConfidence::classname(), "Num Params : " << nP ); TMatrixDSym cov = fitResult->GetCovarianceMatrix(); double *covArray = new double[ nP * nP ]; // number of parameters x number of parameters covArray = cov.GetMatrixArray(); // for ( int i = 0; i < 9; i++ ){ // INFO( FitConfidence::classname(), "[" << i << "] = " << covArray[ i ] ); // } double *fCov = new double[ nP * nP ]; fCov = cov.GetMatrixArray(); double *fCovSqrt = new double[ nP * nP ]; calcCholesky( nP, fCov, fCovSqrt ); // for ( int i = 0; i < 9; i++ ){ // INFO( FitConfidence::classname(), "[" << i << "] = " << fCovSqrt[ i ] ); // } // calculate instead if ( -1.0 == x1 && -1.0 == x2 ) f->GetRange( x1, x2 ); double step = ( x2 - x1 ) / (double) nPoints; double x[ nPoints + 1 ]; double y[ nPoints + 1 ]; // double yup[ nPoints + 1 ]; // double ydown[ nPoints + 1 ]; double yerr[ nPoints + 1 ]; vector<double> samples; int i = 0; for (double xx = x1; xx < x2; xx+= step) { x[i] = xx; TH1D *hDistributionAtX = new TH1D("hDistributionAtX","",200,f->Eval(x[i]) - .2,f->Eval(x[i]) + .2); for (int n = 0; n < nSamples; n++ ) { double val = randomSqrtCov(x[i],f,nP,fCovSqrt); hDistributionAtX->Fill( val ); samples.push_back( val ); } //hDistributionAtX->DrawCopy(); y[i] = f->Eval(x[i]); yerr[i] = hDistributionAtX->GetRMS(); // cross check - should always give the same result // but very innefficient //yerr[i] = choleskyUncertainty( xx, fitResult, f, nSamples ); // rp.savePage(); hDistributionAtX->Delete(); i++; } TGraphErrors * g = new TGraphErrors( i - 1, x, y, 0, yerr ); return g; }
void makeTable(int nbins = 40, const string label = "HFhits", const char * tag = "Preliminary_NoEffCor_AMPT_d1107", const char* dataset = "DATA"){ bool DATA = false; bool SIM = true; bool MC = false; double EFF = 1; double MXS = 1. - EFF; // Retrieving data int maxEvents = -200; vector<int> runnums; // const char* infileName = Form("/net/hisrv0001/home/yetkin/hidsk0001/analysis/prod/%s_RECO_391/test.root",dataset); const char* infileName = Form("/net/hisrv0001/home/yetkin/hidsk0001/centrality/prod/%s/test.root",dataset); // TFile* infile = new TFile(infileName,"read"); TChain* t = new TChain("HltTree"); // TChain* t = new TChain("hltanalysis/HltTree"); t->Add(infileName); // Creating output table TFile* outFile = new TFile("tables_d1108.root","update"); TDirectory* dir = outFile->mkdir(tag); dir->cd(); TNtuple* nt = new TNtuple("nt","","hf:bin:b:npart:ncoll:nhard"); CentralityBins* bins = new CentralityBins("noname","Test tag", nbins); bins->table_.reserve(nbins); TH1D::SetDefaultSumw2(); int runMC = 1; TFile * inputMCfile; CentralityBins* inputMCtable; if(DATA){ inputMCfile = new TFile("tables_d1103.root","read"); inputMCtable = (CentralityBins*)inputMCfile->Get("CentralityTable_HFhits40_AMPT2760GeV_v1_mc_MC_38Y_V12/run1"); } // Setting up variables & branches double binboundaries[nbinsMax+1]; vector<float> values; float b,npart,ncoll,nhard,hf,hfhit,eb,ee,etmr,parameter; int npix,ntrks; // TTree* t = (TTree*)infile->Get("HltTree"); int run; if(SIM){ t->SetBranchAddress("b",&b); t->SetBranchAddress("Npart",&npart); t->SetBranchAddress("Ncoll",&ncoll); t->SetBranchAddress("Nhard",&nhard); } t->SetBranchAddress("hiHFhit",&hfhit); t->SetBranchAddress("hiHF",&hf); t->SetBranchAddress("hiEB",&eb); t->SetBranchAddress("hiEE",&ee); t->SetBranchAddress("hiET",&etmr); t->SetBranchAddress("hiNpix",&npix); t->SetBranchAddress("hiNtracks",&ntrks); t->SetBranchAddress("Run",&run); bool binNpart = label.compare("Npart") == 0; bool binNcoll = label.compare("Ncoll") == 0; bool binNhard = label.compare("Nhard") == 0; bool binB = label.compare("b") == 0; bool binHF = label.compare("HFtowers") == 0; bool binHFhit = label.compare("HFhits") == 0; bool binEB = label.compare("EB") == 0; bool binEE = label.compare("EE") == 0; bool binETMR = label.compare("ETMR") == 0; bool binNpix = label.compare("PixelHits") == 0; bool binNtrks = label.compare("Ntracks") == 0; // Determining bins of cross section // loop over events unsigned int events=t->GetEntries(); for(unsigned int iev = 0; iev < events && (maxEvents < 0 || iev< maxEvents); ++iev){ if( iev % 100 == 0 ) cout<<"Processing event : "<<iev<<endl; t->GetEntry(iev); if(binNpart) parameter = npart; if(binNcoll) parameter = ncoll; if(binNhard) parameter = nhard; if(binB) parameter = b; if(binHF) parameter = hf; if(binHFhit) parameter = hfhit; if(binEB) parameter = eb; if(binEE) parameter = ee; if(binETMR) parameter = etmr; if(binNpix) parameter = npix; if(binNtrks) parameter = ntrks; values.push_back(parameter); if(runnums.size() == 0 || runnums[runnums.size()-1] != run) runnums.push_back(run); } if(label.compare("b") == 0) sort(values.begin(),values.end(),descend); else sort(values.begin(),values.end()); double max = values[events-1]; binboundaries[nbins] = max; cout<<"-------------------------------------"<<endl; cout<<label.data()<<" based cuts are : "<<endl; cout<<"("; int bin = 0; double dev = events; for(int i = 0; i< nbins; ++i){ // Find the boundary int entry = (int)(i*(dev/nbins)); binboundaries[i] = values[entry]; cout<<" "<<binboundaries[i]; if(i < nbins - 1) cout<<","; else cout<<")"<<endl; } cout<<"-------------------------------------"<<endl; if(!DATA){ // Determining Glauber results in various bins dir->cd(); TH2D* hNpart = new TH2D("hNpart","",nbins,binboundaries,500,0,500); TH2D* hNcoll = new TH2D("hNcoll","",nbins,binboundaries,2000,0,2000); TH2D* hNhard = new TH2D("hNhard","",nbins,binboundaries,250,0,250); TH2D* hb = new TH2D("hb","",nbins,binboundaries,300,0,30); for(unsigned int iev = 0; iev < events && (maxEvents < 0 || iev< maxEvents); ++iev){ if( iev % 100 == 0 ) cout<<"Processing event : "<<iev<<endl; t->GetEntry(iev); if(binNpart) parameter = npart; if(binNcoll) parameter = ncoll; if(binNhard) parameter = nhard; if(binB) parameter = b; if(binHF) parameter = hf; if(binHFhit) parameter = hfhit; if(binEB) parameter = eb; if(binEE) parameter = ee; if(binETMR) parameter = etmr; if(binNpix) parameter = npix; if(binNtrks) parameter = ntrks; hNpart->Fill(parameter,npart); hNcoll->Fill(parameter,ncoll); hNhard->Fill(parameter,nhard); hb->Fill(parameter,b); int bin = hNpart->GetXaxis()->FindBin(parameter) - 1; if(bin < 0) bin = 0; if(bin >= nbins) bin = nbins - 1; nt->Fill(hf,bin,b,npart,ncoll,nhard); } // Fitting Glauber distributions in bins to get mean and sigma values dir->cd(); TF1* fGaus = new TF1("fb","gaus(0)",0,2); fGaus->SetParameter(0,1); fGaus->SetParameter(1,0.04); fGaus->SetParameter(2,0.02); fitSlices(hNpart,fGaus); fitSlices(hNcoll,fGaus); fitSlices(hNhard,fGaus); fitSlices(hb,fGaus); TH1D* hNpartMean = (TH1D*)gDirectory->Get("hNpart_1"); TH1D* hNpartSigma = (TH1D*)gDirectory->Get("hNpart_2"); TH1D* hNcollMean = (TH1D*)gDirectory->Get("hNcoll_1"); TH1D* hNcollSigma = (TH1D*)gDirectory->Get("hNcoll_2"); TH1D* hNhardMean = (TH1D*)gDirectory->Get("hNhard_1"); TH1D* hNhardSigma = (TH1D*)gDirectory->Get("hNhard_2"); TH1D* hbMean = (TH1D*)gDirectory->Get("hb_1"); TH1D* hbSigma = (TH1D*)gDirectory->Get("hb_2"); cout<<"-------------------------------------"<<endl; cout<<"# Bin NpartMean NpartSigma NcollMean NcollSigma bMean bSigma BinEdge"<<endl; // Enter values in table for(int i = 0; i < nbins; ++i){ int ii = nbins-i; bins->table_[i].n_part_mean = hNpartMean->GetBinContent(ii); bins->table_[i].n_part_var = hNpartSigma->GetBinContent(ii); bins->table_[i].n_coll_mean = hNcollMean->GetBinContent(ii); bins->table_[i].n_coll_var = hNcollSigma->GetBinContent(ii); bins->table_[i].b_mean = hbMean->GetBinContent(ii); bins->table_[i].b_var = hbSigma->GetBinContent(ii); bins->table_[i].n_hard_mean = hNhardMean->GetBinContent(ii); bins->table_[i].n_hard_var = hNhardSigma->GetBinContent(ii); bins->table_[i].bin_edge = binboundaries[ii-1]; cout<<i<<" " <<hNpartMean->GetBinContent(ii)<<" " <<hNpartSigma->GetBinContent(ii)<<" " <<hNcollMean->GetBinContent(ii)<<" " <<hNcollSigma->GetBinContent(ii)<<" " <<hbMean->GetBinContent(ii)<<" " <<hbSigma->GetBinContent(ii)<<" " <<binboundaries[ii]<<" " <<endl; } cout<<"-------------------------------------"<<endl; // Save the table in output file if(onlySaveTable){ hNpart->Delete(); hNpartMean->Delete(); hNpartSigma->Delete(); hNcoll->Delete(); hNcollMean->Delete(); hNcollSigma->Delete(); hNhard->Delete(); hNhardMean->Delete(); hNhardSigma->Delete(); hb->Delete(); hbMean->Delete(); hbSigma->Delete(); } }else{ cout<<"-------------------------------------"<<endl; cout<<"# Bin NpartMean NpartSigma NcollMean NcollSigma bMean bSigma BinEdge"<<endl; // Enter values in table for(int i = 0; i < nbins; ++i){ int ii = nbins-i; bins->table_[i].n_part_mean = inputMCtable->NpartMeanOfBin(i); bins->table_[i].n_part_var = inputMCtable->NpartSigmaOfBin(i); bins->table_[i].n_coll_mean = inputMCtable->NcollMeanOfBin(i); bins->table_[i].n_coll_var = inputMCtable->NcollSigmaOfBin(i); bins->table_[i].b_mean = inputMCtable->bMeanOfBin(i); bins->table_[i].b_var = inputMCtable->bSigmaOfBin(i); bins->table_[i].n_hard_mean = inputMCtable->NhardMeanOfBin(i); bins->table_[i].n_hard_var = inputMCtable->NhardSigmaOfBin(i); bins->table_[i].bin_edge = binboundaries[ii-1]; cout<<i<<" " <<bins->table_[i].n_part_mean<<" " <<bins->table_[i].n_part_var<<" " <<bins->table_[i].n_coll_mean<<" " <<bins->table_[i].n_coll_var<<" " <<bins->table_[i].b_mean<<" " <<bins->table_[i].b_var<<" " <<bins->table_[i].n_hard_mean<<" " <<bins->table_[i].n_hard_var<<" " <<bins->table_[i].bin_edge<<" "<<endl; } cout<<"-------------------------------------"<<endl; } outFile->cd(); dir->cd(); bins->SetName(Form("run%d",1)); bins->Write(); nt->Write(); bins->Delete(); outFile->Write(); }
//int data_MC_Pt_Comparison_entries(int EndCaps = 0, int r9sup = 1, int log = 0) int main(int argc, char *argv[]) { for(int iarg = 0 ; iarg < argc; iarg++) { cout << "argv[" << iarg << "]= " << argv[iarg] << endl; } if( argc == 1 ) { cerr << "arguments should be passed : directoryName, eta, r9, xVariable, log" <<endl; return 1; } string directoryName = "Data_MC_Mmumugamma_Comparison_ScaleAndSmearing/smearingFactors"; string eta = "Barrel_1"; string r9 = "all"; string ptCut = "25"; // "30" "35" if( argc > 1 ) directoryName = argv[1]; if( argc > 2 ) eta = argv[2]; if( argc > 3 ) r9 = argv[3]; if( argc > 4 ) ptCut = argv[4]; int nBins = 50; //FIXME double xMin, xMax; xMin = 0.9; //FIXME xMax = 1.1; //FIXME string xVariableName, yVariableName; gROOT->Reset(); TGaxis::SetMaxDigits(3); setTDRStyle(); //setEgammaStyle(); string directoryName_2 = directoryName; string fileName = directoryName; cout<<endl<<"fileName = "<<fileName<<endl; cout<<endl<<"directoryName = "<<directoryName<<endl; directoryName += Form("/%s_%sR9/",eta.c_str(), r9.c_str()); TString cut = Form("(Photon_Et > %s && isJanLooseMMG == 1",ptCut.c_str()); if(r9 == "low" && eta == "Barrel_1") cut += " && Photon_isEB == 1 && Photon_r9 < 0.94 && abs(Photon_SC_Eta) < 1"; if(r9 == "low" && eta == "Barrel_2") cut += " && Photon_isEB == 1 && Photon_r9 < 0.94 && abs(Photon_SC_Eta) > 1"; if(r9 == "high" && eta == "Barrel_1") cut += " && Photon_isEB == 1 && Photon_r9 > 0.94 && abs(Photon_SC_Eta) < 1"; if(r9 == "high" && eta == "Barrel_2") cut += " && Photon_isEB == 1 && Photon_r9 > 0.94 && abs(Photon_SC_Eta) > 1"; if(r9 == "low" && eta == "Endcaps_1") cut += " && Photon_isEE == 1 && Photon_r9 < 0.95 && abs(Photon_SC_Eta) < 2"; if(r9 == "low" && eta == "Endcaps_2") cut += " && Photon_isEE == 1 && Photon_r9 < 0.95 && abs(Photon_SC_Eta) > 2"; if(r9 == "high" && eta == "Endcaps_1") cut += " && Photon_isEE == 1 && Photon_r9 > 0.95 && abs(Photon_SC_Eta) < 2"; if(r9 == "high" && eta == "Endcaps_2") cut += " && Photon_isEE == 1 && Photon_r9 > 0.95 && abs(Photon_SC_Eta) > 2"; if(r9 == "all" && eta == "Barrel_1") cut += " && Photon_isEB == 1 && abs(Photon_SC_Eta) < 1"; if(r9 == "all" && eta == "Barrel_2") cut += " && Photon_isEB == 1 && abs(Photon_SC_Eta) > 1"; if(r9 == "all" && eta == "Endcaps_1") cut += " && Photon_isEE == 1 && abs(Photon_SC_Eta) < 2"; if(r9 == "all" && eta == "Endcaps_2") cut += " && Photon_isEE == 1 && abs(Photon_SC_Eta) > 2"; if(r9 == "all" && eta == "all") cut += " && (Photon_isEE == 1 || Photon_isEB == 1)"; cut += ")*weight_pileUp"; cout<<endl<<"cut = "<<cut<<endl; TChain * dYToMuMuFSRChainNew = new TChain("miniTree"); TChain * dYToMuMuNonFSRChainNew = new TChain("miniTree"); TChain * ttJetsChainNew = new TChain("miniTree"); TChain * wJetsChainNew = new TChain("miniTree"); dYToMuMuFSRChainNew->Add("/sps/cms/sgandurr/CMSSW_4_2_8_patch7/src/Zmumugamma_miniTrees_rereco_2011_lastTag/miniTree_DYToMuMu_M-20_CT10_TuneZ2_7TeV-powheg-pythia_Fall11-PU_S6_START42_V14B-v1_September12_NewSelection_1_scaleAndsmearing_v4_partALL.root"); dYToMuMuNonFSRChainNew->Add("/sps/cms/sgandurr/CMSSW_4_2_8_patch7/src/Zmumugamma_miniTrees_rereco_2011_lastTag/miniTree_DYToMuMu_M-20_CT10_TuneZ2_7TeV-powheg-pythia_Fall11-PU_S6_START42_V14B-v1_September12_NewSelection_2_scaleAndsmearing_v4_partALL.root"); ttJetsChainNew->Add("/sps/cms/sgandurr/CMSSW_4_2_8_patch7/src/Zmumugamma_miniTrees_rereco_2011_lastTag/miniTree_TTJets_TuneZ2_7TeV-madgraph-tauola_NewSelection_3_scaleAndsmearing_v4_partALL.root"); wJetsChainNew->Add("/sps/cms/sgandurr/CMSSW_4_2_8_patch7/src/Zmumugamma_miniTrees_rereco_2011_lastTag/miniTree_WJetsToLNu_TuneZ2_7TeV-madgraph-tauola_NewSelection_3_scaleAndsmearing_v4_partALL.root"); TCanvas *c1 = new TCanvas("c1", "c1",0,0,600,600); TH1D *dYToMuMuFSRNew = new TH1D("dYToMuMuFSRNew","dYToMuMuFSRNew", nBins, xMin, xMax); TH1D *dYToMuMuNonFSRNew = new TH1D("dYToMuMuNonFSRNew","dYToMuMuNonFSRNew", nBins, xMin, xMax); TH1D *ttJetsNew = new TH1D("ttJetsNew","ttJetsNew", nBins, xMin, xMax); TH1D *wJetsNew = new TH1D("wJetsNew","wJetsNew", nBins, xMin, xMax); dYToMuMuFSRChainNew->Draw("shervinSmearing>>dYToMuMuFSRNew",cut); dYToMuMuNonFSRChainNew->Draw("shervinSmearing>>dYToMuMuNonFSRNew",cut); ttJetsChainNew->Draw("shervinSmearing>>ttJetsNew",cut); wJetsChainNew->Draw("shervinSmearing>>wJetsNew",cut); // --- 2012 Lumi --- // //double lumidata = 808.472 + 82.136 + 4429.0 + 495.003 + 134.242 + 6397.0 + 7274.0; //double lumiDY = 48819386.0 / 1914.894; //double lumiTtJets = 6736135.0 / 234.0; //double lumiwJets = 57709905.0 / 37509.25; // --- 2011 Lumi --- // double lumidata = (0.706370 + 0.385819 + 2.741 + 1.099) * 1000; double lumiDY = 29743564.0 / 1665.835; double lumiTtJets = 3701947.0 / 165.0; double lumiwJets = 81345381.0 / 31314.0; // --- 2011 Lumi old --- // //double lumiDY = 29743564.0 / 1626.0; //double lumiTtJets = 3701947.0 / 94.76; //double lumiwJets = 81345381.0 / 27770.0; ttJetsNew->Scale(lumiDY / lumiTtJets); wJetsNew->Scale(lumiDY / lumiwJets); dYToMuMuFSRNew->Add(dYToMuMuNonFSRNew); dYToMuMuFSRNew->Add(ttJetsNew); dYToMuMuFSRNew->Add(wJetsNew); dYToMuMuNonFSRNew->Add(ttJetsNew); dYToMuMuNonFSRNew->Add(wJetsNew); ttJetsNew->Add(wJetsNew); c1->Clear(); dYToMuMuFSRNew->GetYaxis()->SetTitle("Events / 0.004"); //FIXME dYToMuMuFSRNew->GetXaxis()->SetTitle("smearing factors"); /* dYToMuMuFSR->GetXaxis()->SetLabelFont(42); dYToMuMuFSR->GetXaxis()->SetTitleFont(42); dYToMuMuFSR->GetYaxis()->SetLabelFont(42); dYToMuMuFSR->GetYaxis()->SetTitleFont(42); dYToMuMuFSR->GetYaxis()->SetTitleOffset(1.65); */ dYToMuMuFSRNew->SetFillColor(kGreen-7); dYToMuMuNonFSRNew->SetFillColor(kAzure-5); ttJetsNew->SetFillColor(kBlue-1); wJetsNew->SetFillColor(kCyan+2); dYToMuMuFSRNew->Draw(""); // --- Fit --- // TF1 * f1 = new TF1("f1","gaus",xMin,xMax); //TF1 * f1 = new TF1("f1","gaus",0.96,1.04); //f1->FixParameter(1,1.0); //FIXME //f1->FixParameter(2,1.0); //FIXME dYToMuMuFSRNew->Fit(f1); f1->SetLineColor(kBlue); f1->SetLineWidth(2); f1->Draw("SAMES"); c1->Clear(); dYToMuMuFSRNew->Draw("E"); f1->Draw("SAMES"); dYToMuMuFSRNew->SetMarkerStyle(20); dYToMuMuFSRNew->SetMarkerSize(0.5); TLatex latexLabel; latexLabel.SetTextFont(42); latexLabel.SetTextSize(0.028); latexLabel.SetNDC(); //latexLabel.DrawLatex(0.25, 0.96, "CMS Preliminary 2011 #sqrt{s} = 7 TeV L = 4.93 fb^{-1}"); //double Ymin = 0; //double Ymax = max(dYToMuMuFSR->GetMaximum(),data->GetMaximum()) + max(dYToMuMuFSR->GetMaximum(),data->GetMaximum()) * 0.1; //cout << "Ymax = "<<Ymax<<endl; //dYToMuMuFSRNew->GetYaxis()->SetRangeUser(Ymin,Ymax); plotsRecording(directoryName, fileName, c1); c1->Clear(); f1->Delete(); f1 = 0; dYToMuMuFSRNew->Delete(); dYToMuMuFSRNew = 0; dYToMuMuNonFSRNew->Delete(); dYToMuMuNonFSRNew = 0; ttJetsNew->Delete(); ttJetsNew = 0; wJetsNew->Delete(); wJetsNew = 0; dYToMuMuFSRChainNew->Delete(); dYToMuMuFSRChainNew = 0; dYToMuMuNonFSRChainNew->Delete(); dYToMuMuNonFSRChainNew = 0; ttJetsChainNew->Delete(); ttJetsChainNew = 0; wJetsChainNew->Delete(); wJetsChainNew = 0; delete c1; c1 = 0; return 0; }