void makePlots_hlt_eventbyevent_comparison( std::string inputFile_="input.root", std::string target_label_="Target", std::string outputSuffix_="_out" ) { TFile *file = new TFile(inputFile_.c_str()); std::string dirprefix = "Images" + outputSuffix_; struct stat st; if( stat(dirprefix.c_str(),&st) != 0 ) mkdir(dirprefix.c_str(),0777); std::string label_ref = "Reference"; std::string label_tgt = target_label_; TH1D* h_ref = (TH1D*)file->Get("eventbyevent/HLT_Ref"); TH1D* h_tgt = (TH1D*)file->Get("eventbyevent/HLT_Tgt"); TH1D* h_tgt_sep = (TH1D*)file->Get("eventbyevent/HLT_Tgt_sep"); std::map<std::string, int> hlt_counts_per_path_ref_; std::map<std::string, int> hlt_counts_per_path_tgt_; std::map<double, std::string> hlt_counts_per_path_diff_; std::vector<std::string> hlt_common_paths; TAxis * axis = h_ref->GetXaxis(); // loop over target paths for( int iPath=0; iPath<h_tgt_sep->GetNbinsX(); iPath++ ){ std::string name(h_tgt_sep->GetXaxis()->GetBinLabel(iPath+1)); int bin = axis->FindBin(name.c_str()); if( bin<1 ) continue; double cnt_ref = h_ref->GetBinContent(bin); double cnt_tgt = h_tgt->GetBinContent(bin); int diff = int( cnt_ref - cnt_tgt ); double rel_diff = double(diff); if( cnt_ref>0 ) rel_diff = fabs(cnt_tgt - cnt_ref)/cnt_ref; else if( cnt_tgt>0 ) rel_diff = fabs(cnt_tgt - cnt_ref)/cnt_tgt; else rel_diff = 0.; // printf("%s\t %d\t %d\t %d\t %.3f \n", // name.c_str(), int(cnt_ref), int(cnt_tgt), diff, rel_diff ); hlt_counts_per_path_ref_[name] = int(cnt_ref); hlt_counts_per_path_tgt_[name] = int(cnt_tgt); hlt_counts_per_path_diff_[rel_diff] = name; if( rel_diff>0.15 ) hlt_common_paths.push_back(name); } std::map<double, std::string>::reverse_iterator rit; for( rit=hlt_counts_per_path_diff_.rbegin(); rit!=hlt_counts_per_path_diff_.rend(); ++rit ) std::cout << "path: " << rit->second << "\t" << rit->first << "\t" << hlt_counts_per_path_ref_[rit->second] << "\t" << hlt_counts_per_path_tgt_[rit->second] << std::endl; int numPaths = int( hlt_counts_per_path_ref_.size() ); TH1D* h_hlt_ref = new TH1D("h_hlt_ref",";HLT path", numPaths, 0, numPaths ); TH1D* h_hlt_tgt = new TH1D("h_hlt_tgt",";HLT path", numPaths, 0, numPaths ); TH1D* h_hlt_diff = new TH1D("h_hlt_diff",";HLT path", numPaths, 0, numPaths ); int iHLT=0; for( std::map<std::string, int>::iterator it=hlt_counts_per_path_ref_.begin(); it!=hlt_counts_per_path_ref_.end(); ++it ){ iHLT++; std::string name = it->first; double cnt_ref = double(hlt_counts_per_path_ref_[name]); double cnt_tgt = double(hlt_counts_per_path_tgt_[name]); double rel_diff = 1.0; if( cnt_ref>0 ) rel_diff = (cnt_tgt - cnt_ref)/cnt_ref; else if( cnt_tgt>0 ) rel_diff = (cnt_tgt - cnt_ref)/cnt_tgt; else rel_diff = 0.; h_hlt_ref->SetBinContent(iHLT,cnt_ref); h_hlt_tgt->SetBinContent(iHLT,cnt_tgt); h_hlt_diff->SetBinContent(iHLT,rel_diff); h_hlt_ref->GetXaxis()->SetBinLabel(iHLT,name.c_str()); h_hlt_diff->GetXaxis()->SetBinLabel(iHLT,name.c_str()); } h_hlt_ref->SetStats(0); h_hlt_ref->SetLineColor(kBlue); h_hlt_tgt->SetLineColor(kRed); if( true ){ // TLegend *legend = new TLegend(0.255,0.78,0.92,0.89); TLegend *legend = new TLegend(0.255,0.92,0.92,0.99); legend->SetFillColor(kWhite); legend->SetLineColor(kWhite); legend->SetShadowColor(kWhite); legend->SetTextFont(42); legend->SetTextSize(0.035); legend->SetNColumns(2); legend->AddEntry(h_hlt_ref,label_ref.c_str(),"l"); legend->AddEntry(h_hlt_tgt,label_tgt.c_str(),"l"); //// Original // double ratioMin = -1.2; // double ratioMax = 1.2; double ratioMin = -0.6; double ratioMax = 0.6; //Hack to get it plotted with ratio plot TCanvas* myC = new TCanvas("myC", "myC", 1200,700); gStyle->SetPadBorderMode(0); gStyle->SetFrameBorderMode(0); Float_t small = 1.e-5; myC->Divide(1,2,small,small); const float padding=1e-5; const float ydivide=0.3; myC->GetPad(1)->SetPad( padding, ydivide + padding , 1-padding, 1-padding); myC->GetPad(2)->SetPad( padding, padding, 1-padding, ydivide-padding); myC->GetPad(1)->SetLeftMargin(.11); myC->GetPad(2)->SetLeftMargin(.11); myC->GetPad(1)->SetRightMargin(.05); myC->GetPad(2)->SetRightMargin(.05); myC->GetPad(1)->SetBottomMargin(.3); myC->GetPad(2)->SetBottomMargin(.3); myC->GetPad(1)->Modified(); myC->GetPad(2)->Modified(); myC->cd(1); gPad->SetBottomMargin(small); gPad->Modified(); TH1D* myRatio = (TH1D*)h_hlt_diff->Clone("myRatio"); myRatio->SetStats(0); myRatio->Sumw2(); myRatio->SetLineColor(kBlack); myRatio->SetMarkerColor(kBlack); myRatio->SetMinimum(ratioMin); myRatio->SetMaximum(ratioMax); //myRatio->GetYaxis()->SetNdivisions(50000+404); myRatio->GetYaxis()->SetNdivisions(20000+505); myRatio->GetYaxis()->SetLabelSize(0.1); //make y label bigger myRatio->GetXaxis()->SetLabelSize(0.1); //make y label bigger myRatio->GetXaxis()->SetTitleOffset(1.1); myRatio->GetXaxis()->SetTitle(h_hlt_diff->GetXaxis()->GetTitle()); //make y label bigger myRatio->GetXaxis()->SetLabelSize(0.12); myRatio->GetXaxis()->SetLabelOffset(0.04); myRatio->GetXaxis()->SetTitleSize(0.12); // myRatio->GetYaxis()->SetTitle("Data/MC"); myRatio->GetYaxis()->SetTitle("New - Old / Old"); myRatio->GetYaxis()->SetTitleSize(0.1); myRatio->GetYaxis()->SetTitleOffset(.45); myC->cd(2); gPad->SetTopMargin(small); gPad->SetTickx(); gPad->Modified(); myC->cd(1); h_hlt_ref->GetYaxis()->SetTitle("Number of Events"); h_hlt_ref->GetYaxis()->SetTitleSize(0.05); h_hlt_ref->GetYaxis()->SetTitleOffset(.95); h_hlt_ref->Draw(); h_hlt_tgt->Draw("same"); legend->Draw(); double xmin = h_hlt_ref->GetBinLowEdge(1); double xmax = h_hlt_ref->GetBinLowEdge(h_hlt_ref->GetNbinsX()) + h_hlt_ref->GetBinWidth(h_hlt_ref->GetNbinsX()); myC->cd(2); myRatio->SetLineWidth(2); myRatio->Draw("hist"); TLine* myLine; myLine = new TLine(xmin, 0, xmax, 0); myLine->Draw(); std::string outputFile = dirprefix + "/hlt_path_comparison" + outputSuffix_ + ".pdf"; myC->Print(outputFile.c_str()); delete legend; delete myC; delete myLine; } if( true ){ int numCommonPaths = int(hlt_common_paths.size()); for( int iPath=0; iPath<numCommonPaths; iPath++ ){ std::cout << " ====================== " << std::endl; std::string name = hlt_common_paths[iPath]; std::string pathName_ref = "eventbyevent/h_path_ref_" + name; std::string pathName_tgt = "eventbyevent/h_path_tgt_" + name; std::string diffname = "h_path_diff_" + name; //std::cout << " path is " << pathName_ref << std::endl; if( name=="HLT_LogMonitor" ) continue; TH1D* h_hlt_filt_ref = (TH1D*)file->Get(pathName_ref.c_str()); TH1D* h_hlt_filt_tgt = (TH1D*)file->Get(pathName_tgt.c_str()); TH1D* h_hlt_filt_diff = (TH1D*)h_hlt_filt_ref->Clone(diffname.c_str()); bool printOut = true; for( int iBin=0; iBin<h_hlt_filt_tgt->GetNbinsX(); iBin++ ){ double cnt_ref = h_hlt_filt_ref->GetBinContent(iBin+1); double cnt_tgt = h_hlt_filt_tgt->GetBinContent(iBin+1); double rel_diff = 1.0; if( cnt_ref>0 ) rel_diff = (cnt_tgt - cnt_ref)/cnt_ref; else if( cnt_tgt>0 ) rel_diff = (cnt_tgt - cnt_ref)/cnt_tgt; else rel_diff = 0.; h_hlt_filt_diff->SetBinContent(iBin+1,rel_diff); //if( fabs(rel_diff)>0.0002 ) printOut = true; } if( printOut ){ double cnt_ref = double(hlt_counts_per_path_ref_[name]); double cnt_tgt = double(hlt_counts_per_path_tgt_[name]); double rel_diff = 1.0; if( cnt_ref>0 ) rel_diff = (cnt_tgt - cnt_ref)/cnt_ref; else if( cnt_tgt>0 ) rel_diff = (cnt_tgt - cnt_ref)/cnt_tgt; else rel_diff = 0.; printf("%s: relative difference = %.3f,\t reference = %d,\t target = %d \n", name.c_str(), rel_diff, hlt_counts_per_path_ref_[name], hlt_counts_per_path_tgt_[name]); for( int iBin=0; iBin<h_hlt_filt_tgt->GetNbinsX(); iBin++ ){ double my_cnt_ref = h_hlt_filt_ref->GetBinContent(iBin+1); double my_cnt_tgt = h_hlt_filt_tgt->GetBinContent(iBin+1); double my_rel_diff = 1.0; if( my_cnt_ref>0 ) my_rel_diff = (my_cnt_tgt - my_cnt_ref)/my_cnt_ref; else if( my_cnt_tgt>0 ) my_rel_diff = (my_cnt_tgt - my_cnt_ref)/my_cnt_tgt; else my_rel_diff = 0.; printf("\t %s \t %.3f \t %.0f \t %.0f \n", h_hlt_filt_ref->GetXaxis()->GetBinLabel(iBin+1), my_rel_diff, my_cnt_ref, my_cnt_tgt); } } h_hlt_filt_ref->SetStats(0); h_hlt_filt_ref->SetLineColor(kBlue); h_hlt_filt_tgt->SetLineColor(kRed); //TLegend *legend = new TLegend(0.255,0.78,0.92,0.89); TLegend *legend = new TLegend(0.255,0.92,0.92,0.99); legend->SetFillColor(kWhite); legend->SetLineColor(kWhite); legend->SetShadowColor(kWhite); legend->SetTextFont(42); legend->SetTextSize(0.035); legend->SetNColumns(2); legend->AddEntry(h_hlt_filt_ref,label_ref.c_str(),"l"); legend->AddEntry(h_hlt_filt_tgt,label_tgt.c_str(),"l"); double ratioMin = -1.2; double ratioMax = 1.2; //Hack to get it plotted with ratio plot TCanvas* myC = new TCanvas("myC", "myC", 600,700); gStyle->SetPadBorderMode(0); gStyle->SetFrameBorderMode(0); Float_t small = 1.e-5; myC->Divide(1,2,small,small); const float padding=1e-5; const float ydivide=0.3; myC->GetPad(1)->SetPad( padding, ydivide + padding , 1-padding, 1-padding); myC->GetPad(2)->SetPad( padding, padding, 1-padding, ydivide-padding); myC->GetPad(1)->SetLeftMargin(.11); myC->GetPad(2)->SetLeftMargin(.11); myC->GetPad(1)->SetRightMargin(.05); myC->GetPad(2)->SetRightMargin(.05); myC->GetPad(1)->SetBottomMargin(.3); myC->GetPad(2)->SetBottomMargin(.3); myC->GetPad(1)->Modified(); myC->GetPad(2)->Modified(); myC->cd(1); gPad->SetBottomMargin(small); gPad->Modified(); TH1D* myRatio = (TH1D*)h_hlt_filt_diff->Clone(); myRatio->SetStats(0); myRatio->Sumw2(); myRatio->SetLineColor(kBlack); myRatio->SetMarkerColor(kBlack); myRatio->SetMinimum(ratioMin); myRatio->SetMaximum(ratioMax); myRatio->GetYaxis()->SetNdivisions(50000+404); myRatio->GetYaxis()->SetLabelSize(0.1); //make y label bigger myRatio->GetXaxis()->SetLabelSize(0.1); //make y label bigger myRatio->GetXaxis()->SetTitleOffset(1.1); myRatio->GetXaxis()->SetTitle(h_hlt_diff->GetXaxis()->GetTitle()); //make y label bigger myRatio->GetXaxis()->SetLabelSize(0.12); myRatio->GetXaxis()->SetLabelOffset(0.04); myRatio->GetXaxis()->SetTitleSize(0.12); // myRatio->GetYaxis()->SetTitle("Data/MC"); myRatio->GetYaxis()->SetTitle("New - Old / Old"); myRatio->GetYaxis()->SetTitleSize(0.1); myRatio->GetYaxis()->SetTitleOffset(.45); myC->cd(2); gPad->SetTopMargin(small); gPad->SetTickx(); gPad->Modified(); myC->cd(1); h_hlt_filt_ref->GetYaxis()->SetTitle("Number of Events"); h_hlt_filt_ref->GetYaxis()->SetTitleSize(0.05); h_hlt_filt_ref->GetYaxis()->SetTitleOffset(.95); h_hlt_filt_ref->Draw(); h_hlt_filt_tgt->Draw("same"); legend->Draw(); double xmin = h_hlt_filt_ref->GetBinLowEdge(1); double xmax = h_hlt_filt_ref->GetBinLowEdge(h_hlt_filt_ref->GetNbinsX()) + h_hlt_filt_ref->GetBinWidth(h_hlt_filt_ref->GetNbinsX()); myC->cd(2); myRatio->SetLineWidth(2); myRatio->Draw("hist"); TLine* myLine; myLine = new TLine(xmin, 0, xmax, 0); myLine->Draw(); std::string outputFile = dirprefix + "/hlt_path_" + name + outputSuffix_ + ".pdf"; myC->Print(outputFile.c_str()); delete legend; delete myC; delete myLine; } std::cout << " ====================== " << std::endl; } // close file file->Close(); }
//________________________________________________________________ void KVCanvas::DynamicZoom(Int_t Sign, Int_t px, Int_t py) { // Zoom in or out of histogram with mouse wheel // Info("DynamicZoom","px=%d py=%d",px,py); if (!fSelected) return; TH2* TheHisto = (TH2*) FindHisto();//fSelected; Double_t percent = 0.15 - Sign * 0.05; Int_t dX = 0; Int_t dY = 0; Double_t ppx = AbsPixeltoX(px); Double_t ppy = AbsPixeltoY(py); TAxis* ax = TheHisto->GetXaxis(); Int_t NbinsXtmp = ax->GetNbins(); Int_t X0tmp = ax->GetFirst(); Int_t X1tmp = ax->GetLast(); Int_t step = TMath::Min(TMath::Max(1, (Int_t)(percent * (X1tmp - X0tmp))), NbinsXtmp / 2); step *= Sign; X0tmp = TMath::Min(TMath::Max(X0tmp + step, 1), X1tmp - step); X1tmp = TMath::Max(TMath::Min(X1tmp - step, NbinsXtmp), X0tmp); if (X0tmp >= X1tmp) X0tmp = X1tmp - 1; if (Sign > 0) dX = (Int_t)(X0tmp + (X1tmp - X0tmp) * 0.5 - ax->FindBin(ppx)); if ((X0tmp - dX) < 0) ax->SetRange(0, X1tmp - X0tmp); else if ((X1tmp - dX) > ax->GetNbins()) ax->SetRange(ax->GetNbins() - (X1tmp - X0tmp), ax->GetNbins()); else ax->SetRange(X0tmp - dX, X1tmp - dX); ax = TheHisto->GetYaxis(); Int_t NbinsYtmp = ax->GetNbins(); Int_t Y0tmp = ax->GetFirst(); Int_t Y1tmp = ax->GetLast(); step = TMath::Min(TMath::Max(1, (Int_t)(percent * (Y1tmp - Y0tmp))), NbinsYtmp / 2); step *= Sign; Y0tmp = TMath::Min(TMath::Max(Y0tmp + step, 1), Y1tmp - step); Y1tmp = TMath::Max(TMath::Min(Y1tmp - step, NbinsYtmp), Y0tmp); if (Y0tmp >= Y1tmp) Y0tmp = Y1tmp - 1; if (Sign > 0) dY = (Int_t)(Y0tmp + (Y1tmp - Y0tmp) * 0.5 - ax->FindBin(ppy)); if ((Y0tmp - dY) < 0) ax->SetRange(0, Y1tmp - Y0tmp); else if ((Y1tmp - dY) > ax->GetNbins()) ax->SetRange(ax->GetNbins() - (Y1tmp - Y0tmp), ax->GetNbins()); else ax->SetRange(Y0tmp - dY, Y1tmp - dY); Modified(); Update(); return; }
//________________________________________________________________ void KVCanvas::DynamicZoomTH1(Int_t Sign, Int_t px, Int_t) { // Zoom in or out of histogram with mouse wheel if (!fSelected) return; TH1* TheHisto = (TH1*) FindHisto();//fSelected; Double_t percent = 0.15 - Sign * 0.05; Int_t dX = 0; px = AbsPixeltoX(px); TAxis* ax = TheHisto->GetXaxis(); Int_t NbinsXtmp = ax->GetNbins(); Int_t X0tmp = ax->GetFirst(); Int_t X1tmp = ax->GetLast(); Int_t step = TMath::Min(TMath::Max(1, (Int_t)(percent * (X1tmp - X0tmp))), NbinsXtmp / 2); step *= Sign; X0tmp = TMath::Min(TMath::Max(X0tmp + step, 1), X1tmp - step); X1tmp = TMath::Max(TMath::Min(X1tmp - step, NbinsXtmp), X0tmp); if (X0tmp >= X1tmp) X0tmp = X1tmp - 1; if (Sign > 0) dX = (Int_t)(X0tmp + (X1tmp - X0tmp) * 0.5 - ax->FindBin(px)); if ((X0tmp - dX) < 0) ax->SetRange(0, X1tmp - X0tmp); else if ((X1tmp - dX) > ax->GetNbins()) ax->SetRange(ax->GetNbins() - (X1tmp - X0tmp), ax->GetNbins()); else ax->SetRange(X0tmp - dX, X1tmp - dX); Modified(); Update(); return; }
void GetSlices(Double_t start, Double_t end, TH3D *source, TH2D **target) { TAxis *zAxis = source->GetZaxis(); Int_t startBin = zAxis->FindBin(start); Int_t endBin = zAxis->FindBin(end); Int_t it = 0; for(Int_t iBin = startBin; iBin < endBin; iBin += 10){ zAxis->SetRange(iBin, iBin + 9); //cout << iBin << endl; TString name = Form("yx%d", it); target[it++] = (TH2D*)source->Project3D(name); } source->GetZaxis()->UnZoom(); //zAxis->UnZoom(); }
//Get background counts on NRS from Geant4 simulation template (histogram) void ResonanceSimulator::get_background(){ TAxis *xaxis = hbkg->GetXaxis(); int binx = xaxis->FindBin(e_cut); int binmax = xaxis->GetXmax(); N_background = hbkg->Integral(binx,binmax); return; }
void GetInt(TH1F *hzj,float xmin,float xmax,double& integralfull, double& integral) { TAxis *axis = hzj->GetXaxis(); int bmin = axis->FindBin(xmin); int bmax = axis->FindBin(xmax); integralfull = hzj->Integral(); integral = hzj->Integral(bmin,bmax); integral -= hzj->GetBinContent(bmin)*(xmin-axis->GetBinLowEdge(bmin))/axis->GetBinWidth(bmin); integral -= hzj->GetBinContent(bmax)*(axis->GetBinUpEdge(bmax)-xmax)/axis->GetBinWidth(bmax); fout<<"Full Integral: "<<integralfull<<endl; }
double integralInRange( TH1F * var_h, float lower, float upper ){ TAxis *axis = var_h->GetXaxis(); int bmin = axis->FindBin(lower); int bmax = axis->FindBin(upper); double integr = var_h->Integral(bmin,bmax); integr -= ( (var_h->GetBinContent(bmin)) * (lower - (axis->GetBinLowEdge(bmin))) )/ axis->GetBinWidth(bmin); integr -= ( (var_h->GetBinContent(bmax)) * ( (axis->GetBinUpEdge(bmax)) - upper) )/ axis->GetBinWidth(bmax); return integr; }
double integrate(TH1F* h, double xmin, double xmax){ TAxis *axis = h->GetXaxis(); int bmin = axis->FindBin(xmin); //in your case xmin=-1.5 int bmax = axis->FindBin(xmax); //in your case xmax=0.8 double integral = h->Integral(bmin,bmax); integral -= h->GetBinContent(bmin)*(xmin-axis->GetBinLowEdge(bmin))/axis->GetBinWidth(bmin); integral -= h->GetBinContent(bmax)*(axis->GetBinUpEdge(bmax)-xmax)/axis->GetBinWidth(bmax); return integral; }
void GetIntg(TH1F *hzj,float xmin,float xmax,double& count1, double& count2) { TAxis *axis = hzj->GetXaxis(); int bmin = axis->FindBin(xmin); int bmax = axis->FindBin(xmax); double integralfull = hzj->Integral(); double integral = hzj->Integral(bmin,bmax); integral -= hzj->GetBinContent(bmin)*(xmin-axis->GetBinLowEdge(bmin))/axis->GetBinWidth(bmin); integral -= hzj->GetBinContent(bmax)*(axis->GetBinUpEdge(bmax)-xmax)/axis->GetBinWidth(bmax); count1=count1+integralfull; count2=count2+integral; // cout<<count1<<'\t'<<count2<<endl; }
//------------------------------------------------------------------------------ // ZeroOutOfRangeBins //------------------------------------------------------------------------------ void ZeroOutOfRangeBins(TH1* h, Double_t xmin, Double_t xmax) { UInt_t nbins = h->GetNbinsX(); TAxis* axis = (TAxis*)h->GetXaxis(); Int_t firstBin = (xmin != -999) ? axis->FindBin(xmin) : 1; Int_t lastBin = (xmax != 999) ? axis->FindBin(xmax) : nbins; for (UInt_t i=0; i<=nbins+1; i++) { if (i < firstBin || i > lastBin) { h->SetBinContent(i, 0); h->SetBinError (i, 0); } } }
void Bin2DTree::constrainSplit(int axis, double& cut, bool& veto) /*****************************************************************/ { if(m_gridConstraint && !m_vetoSplitXY[axis]) { TAxis* gridAxis = NULL; if(axis==0) { gridAxis = m_gridConstraint->GetXaxis(); } else { gridAxis = m_gridConstraint->GetYaxis(); } // Find the closest grid constraint for the cut // And modify the cut according to this constraint int b = gridAxis->FindBin(cut); double low = gridAxis->GetBinLowEdge(b); double up = gridAxis->GetBinUpEdge(b); if(fabs(up-cut)<fabs(cut-low)) { cut = up; // If the constrained cut is outside the bin boundaries, try the other grid constraint if(cut>=getBinBoundaries()[axis].second) { cut = low; } } else { cut = low; // If the constrained cut is outside the bin boundaries, try the other grid constraint if(cut<=getBinBoundaries()[axis].first) { cut = up; } } // If the constrained cut is still outside the bin boundaries, veto this bin and axis if(cut<=getBinBoundaries()[axis].first || cut>=getBinBoundaries()[axis].second) { m_vetoSplitXY[axis] = true; } } veto = m_vetoSplitXY[axis]; }
//------------------------------------------------------------------------------ // MoveOverflowBins //------------------------------------------------------------------------------ void MoveOverflowBins(TH1* h, Double_t xmin, Double_t xmax) { UInt_t nbins = h->GetNbinsX(); TAxis* axis = (TAxis*)h->GetXaxis(); Int_t firstBin = (xmin != -999) ? axis->FindBin(xmin) : 1; Int_t lastBin = (xmax != 999) ? axis->FindBin(xmax) : nbins; Double_t firstVal = 0; Double_t firstErr = 0; Double_t lastVal = 0; Double_t lastErr = 0; for (UInt_t i=0; i<=nbins+1; i++) { if (i <= firstBin) { firstVal += h->GetBinContent(i); firstErr += (h->GetBinError(i)*h->GetBinError(i)); } if (i >= lastBin) { lastVal += h->GetBinContent(i); lastErr += (h->GetBinError(i)*h->GetBinError(i)); } if (i < firstBin || i > lastBin) { h->SetBinContent(i, 0); h->SetBinError (i, 0); } } firstErr = sqrt(firstErr); lastErr = sqrt(lastErr); h->SetBinContent(firstBin, firstVal); h->SetBinError (firstBin, firstErr); h->SetBinContent(lastBin, lastVal); h->SetBinError (lastBin, lastErr); }
//------------------------------------------------------------------------------ // GetMaximumIncludingErrors //------------------------------------------------------------------------------ Float_t GetMaximumIncludingErrors(TH1F* h, Double_t xmin, Double_t xmax) { UInt_t nbins = h->GetNbinsX(); TAxis* axis = (TAxis*)h->GetXaxis(); Int_t firstBin = (xmin != -999) ? axis->FindBin(xmin) : 1; Int_t lastBin = (xmax != 999) ? axis->FindBin(xmax) : nbins; Float_t maxWithErrors = 0; for (Int_t i=firstBin; i<=lastBin; i++) { Float_t binHeight = h->GetBinContent(i) + h->GetBinError(i); if (binHeight > maxWithErrors) maxWithErrors = binHeight; } return maxWithErrors; }
void fillHistograms(double mvaOutput, double pt, double eta, double Nvtx, double evtWeight) { histogramPt_denominator_->Fill(pt, evtWeight); histogramEta_denominator_->Fill(eta, evtWeight); histogramNvtx_denominator_->Fill(Nvtx, evtWeight); bool passesCuts = (mvaOutput > mvaCut_); //std::cout << "passesCuts = " << passesCuts << std::endl; if ( passesCuts ) { histogramPt_numerator_->Fill(pt, evtWeight); histogramEta_numerator_->Fill(eta, evtWeight); histogramNvtx_numerator_->Fill(Nvtx, evtWeight); } double y = mvaOutput; TAxis* yAxis = histogramMVAoutput_vs_Pt_->GetYaxis(); int binY = yAxis->FindBin(y); int numBinsY = yAxis->GetNbins(); if ( binY < 1 ) binY = 1; if ( binY > numBinsY ) binY = numBinsY; double yWithinRange = yAxis->GetBinCenter(binY); histogramMVAoutput_vs_Pt_->Fill(pt, y, evtWeight); histogramPt_->Fill(pt, evtWeight); }
void DrawEfficiencyCentralitySource(Int_t bincentrality,Int_t source,const char *testfile) { // // source: 0 (charm), 1 (beauty), 2 (gamma), 3 (others) // centrality: from 0 to 100 with 0-5, 5-10, 10-15... // // gStyle->SetPalette(1); gStyle->SetOptStat(1111); gStyle->SetPadBorderMode(0); gStyle->SetCanvasColor(10); gStyle->SetPadLeftMargin(0.13); gStyle->SetPadRightMargin(0.13); /////////////////////////////////// // Take the stuff ////////////////////////////////// TList *results = GetResults(testfile,""); if(!results){ printf("No output objects: Calculation will terminate here\n"); return; } AliHFEcontainer *containerhfe = (AliHFEcontainer *) results->FindObject("trackContainer"); if(!containerhfe) { printf("No hfe container \n"); return; } // 0: pt, 1: eta, 2: phi, 3: charge, 4: source, 5: centrality AliCFContainer *sumcontaineresdd = containerhfe->MakeMergedCFContainer("sumesd","sumesd","MCTrackCont:recTrackContReco"); AliCFContainer *sumcontainermcc = containerhfe->MakeMergedCFContainer("summc","summc","MCTrackCont:recTrackContMC"); if(!sumcontaineresdd) { printf("No container sum esd\n"); return; } if(!sumcontainermcc) { printf("No container sum mc\n"); return; } // 0: pt, 1: eta, 2: phi for a given centrality and source //AliCFContainer *sumcontaineresd = GetContainerSourceCentrality(sumcontaineresdd,bincentrality,source); //AliCFContainer *sumcontainermc = GetContainerSourceCentrality(sumcontainermcc,bincentrality,source); // 0: pt, 1: eta, 2: phi, 3: centrality for a given centrality and source AliCFContainer *sumcontaineresd = GetContainerSourceAsFunctionOfCentrality(sumcontaineresdd,source); AliCFContainer *sumcontainermc = GetContainerSourceAsFunctionOfCentrality(sumcontainermcc,source); Int_t nSteps = sumcontaineresd->GetNStep(); printf("In total %d steps\n",nSteps); AliCFDataGrid *dataGrida = (AliCFDataGrid *) GetSpectrum(sumcontaineresdd,nSteps-1); TH1D *spectrumcentrality = (TH1D *) dataGrida->Project(5); TH1D *spectrumpt = (TH1D *) dataGrida->Project(0); TH2D *spectrumptc = (TH2D *) dataGrida->Project(5,0); TAxis *xaxis = spectrumptc->GetXaxis(); Int_t bin0 = xaxis->FindBin(0.0); Int_t bin5_s = xaxis->FindBin(4.99); Int_t bin30 = xaxis->FindBin(30.0); Int_t bin40_s = xaxis->FindBin(39.9); Int_t bin70 = xaxis->FindBin(70.0); Int_t bin80_s = xaxis->FindBin(79.9); printf("Bin 0 %d\n",bin0); printf("Bin 5 %d\n",bin5_s); printf("Bin 30 %d\n",bin30); printf("Bin 40 %d\n",bin40_s); printf("Bin 70 %d\n",bin70); printf("Bin 80 %d\n",bin80_s); TH1D *spectrumcentrality_0_5 = spectrumptc->ProjectionY("centrality_0_5",bin0,bin5_s); TH1D *spectrumcentrality_30_40 = spectrumptc->ProjectionY("centrality_30_40",bin30,bin40_s); TH1D *spectrumcentrality_70_80 = spectrumptc->ProjectionY("centrality_70_80",bin70,bin80_s); Int_t numberOfEvents = (Int_t) containerhfe->GetNumberOfEvents(); printf("Number of events for a %d after Event cut\n",numberOfEvents); //////////////////////////////// // Input after ITS&TPC refit /////////////////////////////// TCanvas * canvascpt = new TCanvas("RawSpectrumCentrality","RawSpectrumCentrality",1000,700); canvascpt->Divide(2,1); canvascpt->cd(1); spectrumpt->SetTitle(""); spectrumpt->SetStats(0); spectrumpt->SetLineColor(kBlue); spectrumpt->SetMarkerColor(kBlue); spectrumpt->SetMarkerStyle(25); // spectrumcentrality_0_5->SetTitle(""); spectrumcentrality_0_5->SetStats(0); spectrumcentrality_0_5->SetLineColor(kRed); spectrumcentrality_0_5->SetMarkerColor(kRed); spectrumcentrality_0_5->SetMarkerStyle(26); // spectrumcentrality_30_40->SetTitle(""); spectrumcentrality_30_40->SetStats(0); spectrumcentrality_30_40->SetLineColor(kMagenta); spectrumcentrality_30_40->SetMarkerColor(kBlack); spectrumcentrality_30_40->SetMarkerStyle(27); // spectrumcentrality_70_80->SetTitle(""); spectrumcentrality_70_80->SetStats(0); spectrumcentrality_70_80->SetLineColor(kBlue); spectrumcentrality_70_80->SetMarkerColor(kBlue); spectrumcentrality_70_80->SetMarkerStyle(28); // spectrumpt->Draw(); spectrumcentrality_0_5->Draw("same"); spectrumcentrality_30_40->Draw("same"); spectrumcentrality_70_80->Draw("same"); TLegend *leg_different_centralities = new TLegend(0.4,0.6,0.89,0.89); leg_different_centralities->AddEntry(spectrumpt,"Minimum-bias","p"); leg_different_centralities->AddEntry(spectrumcentrality_0_5,"0_5","p"); leg_different_centralities->AddEntry(spectrumcentrality_30_40,"30_40","p"); leg_different_centralities->AddEntry(spectrumcentrality_70_80,"70_80","p"); leg_different_centralities->Draw("same"); canvascpt->cd(2); spectrumptc->Draw("colz"); ///////////////////////////////////// // Take efficiencies ///////////////////////////////////// AliCFEffGrid *efficiencystepkineITSTPC = (AliCFEffGrid*) GetEfficiency(sumcontaineresd,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecKineITSTPC,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecNoCut); AliCFEffGrid *efficiencystepPrim = (AliCFEffGrid*) GetEfficiency(sumcontaineresd,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecPrim,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecKineITSTPC); AliCFEffGrid *efficiencystepHFEcutsITS = (AliCFEffGrid*) GetEfficiency(sumcontaineresd,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsITS,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecPrim); AliCFEffGrid *efficiencystepHFEcutsTRD = (AliCFEffGrid*) GetEfficiency(sumcontaineresd,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsITS); AliCFEffGrid *efficiencystepPIDTOF = (AliCFEffGrid*) GetEfficiency(sumcontaineresd,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD+1,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD); AliCFEffGrid *efficiencystepPIDTPC = (AliCFEffGrid*) GetEfficiency(sumcontaineresd,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD+2,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD+1); AliCFEffGrid *efficiencystepPIDall = (AliCFEffGrid*) GetEfficiency(sumcontaineresd,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD+2,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD); AliCFEffGrid *efficiencystepall = (AliCFEffGrid*) GetEfficiency(sumcontaineresd,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD+2,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecNoCut); // AliCFEffGrid *efficiencystepMCkineITSTPC = (AliCFEffGrid*) GetEfficiency(sumcontainermc,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecKineITSTPC,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecNoCut); AliCFEffGrid *efficiencystepMCPrim = (AliCFEffGrid*) GetEfficiency(sumcontainermc,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecPrim,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecKineITSTPC); AliCFEffGrid *efficiencystepMCHFEcutsITS = (AliCFEffGrid*) GetEfficiency(sumcontainermc,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsITS,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecPrim); AliCFEffGrid *efficiencystepMCHFEcutsTRD = (AliCFEffGrid*) GetEfficiency(sumcontainermc,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsITS); AliCFEffGrid *efficiencystepMCPIDTOF = (AliCFEffGrid*) GetEfficiency(sumcontainermc,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD+1,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD); AliCFEffGrid *efficiencystepMCPIDTPC = (AliCFEffGrid*) GetEfficiency(sumcontainermc,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD+2,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD+1); AliCFEffGrid *efficiencystepMCPIDall = (AliCFEffGrid*) GetEfficiency(sumcontainermc,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD+2,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD); AliCFEffGrid *efficiencystepMCall = (AliCFEffGrid*) GetEfficiency(sumcontainermc,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD+2,0); /////////////////////////////////////// // Plot 1D /////////////////////////////////////// ///////////////////// // Different cuts ///////////////////// TCanvas * canvascomparison = new TCanvas("ITSTPCrefitStepESD","ITSTPCrefitStepESD",1000,700); canvascomparison->Divide(2,2); canvascomparison->cd(1); TH2D* h_effsteponlykineITSTPC1Donly = (TH2D *) efficiencystepkineITSTPC->Project(0,3); h_effsteponlykineITSTPC1Donly->SetTitle(""); h_effsteponlykineITSTPC1Donly->SetStats(0); h_effsteponlykineITSTPC1Donly->SetLineColor(kBlue); h_effsteponlykineITSTPC1Donly->SetMarkerColor(kBlue); h_effsteponlykineITSTPC1Donly->SetMarkerStyle(25); h_effsteponlykineITSTPC1Donly->Draw("colz"); canvascomparison->cd(2); TH2D* h_effsteponlyPrim1Donly =( TH2D *) efficiencystepPrim->Project(0,3); h_effsteponlyPrim1Donly->SetTitle(""); h_effsteponlyPrim1Donly->SetStats(0); h_effsteponlyPrim1Donly->SetLineColor(kBlue); h_effsteponlyPrim1Donly->SetMarkerColor(kBlue); h_effsteponlyPrim1Donly->SetMarkerStyle(25); h_effsteponlyPrim1Donly->Draw("colz"); canvascomparison->cd(3); TH2D* h_effsteponlyHFEcutsITS1Donly = (TH2D *) efficiencystepHFEcutsITS->Project(0,3); h_effsteponlyHFEcutsITS1Donly->SetTitle(""); h_effsteponlyHFEcutsITS1Donly->SetStats(0); h_effsteponlyHFEcutsITS1Donly->SetLineColor(kBlue); h_effsteponlyHFEcutsITS1Donly->SetMarkerColor(kBlue); h_effsteponlyHFEcutsITS1Donly->SetMarkerStyle(25); h_effsteponlyHFEcutsITS1Donly->Draw("colz"); canvascomparison->cd(4); TH2D* h_effsteponlyPID1Donly = (TH2D *) efficiencystepHFEcutsTRD->Project(0,3); h_effsteponlyPID1Donly->SetTitle(""); h_effsteponlyPID1Donly->SetStats(0); h_effsteponlyPID1Donly->SetLineColor(kBlue); h_effsteponlyPID1Donly->SetMarkerColor(kBlue); h_effsteponlyPID1Donly->SetMarkerStyle(25); h_effsteponlyPID1Donly->Draw("colz"); ///////////////////// // Different cuts ///////////////////// TCanvas * canvascomparisonbis = new TCanvas("ITSTPCrefitStepMC","ITSTPCrefitStepMC",1000,700); canvascomparisonbis->Divide(2,2); canvascomparisonbis->cd(1); TH2D* h_effstepMCkineITSTPC1Donly = (TH2D *)efficiencystepMCkineITSTPC->Project(0,3); h_effstepMCkineITSTPC1Donly->SetTitle(""); h_effstepMCkineITSTPC1Donly->SetStats(0); h_effstepMCkineITSTPC1Donly->SetLineColor(kBlue); h_effstepMCkineITSTPC1Donly->SetMarkerColor(kBlue); h_effstepMCkineITSTPC1Donly->SetMarkerStyle(25); h_effstepMCkineITSTPC1Donly->Draw("colz"); canvascomparisonbis->cd(2); TH2D* h_effstepMCPrim1Donly = (TH2D *) efficiencystepMCPrim->Project(0,3); h_effstepMCPrim1Donly->SetTitle(""); h_effstepMCPrim1Donly->SetStats(0); h_effstepMCPrim1Donly->SetLineColor(kBlue); h_effstepMCPrim1Donly->SetMarkerColor(kBlue); h_effstepMCPrim1Donly->SetMarkerStyle(25); h_effstepMCPrim1Donly->Draw("colz"); canvascomparisonbis->cd(3); TH2D* h_effstepMCHFEcutsITS1Donly = (TH2D *) efficiencystepMCHFEcutsITS->Project(0,3); h_effstepMCHFEcutsITS1Donly->SetTitle(""); h_effstepMCHFEcutsITS1Donly->SetStats(0); h_effstepMCHFEcutsITS1Donly->SetLineColor(kBlue); h_effstepMCHFEcutsITS1Donly->SetMarkerColor(kBlue); h_effstepMCHFEcutsITS1Donly->SetMarkerStyle(25); h_effstepMCHFEcutsITS1Donly->Draw("colz"); canvascomparisonbis->cd(4); TH2D* h_effstepMCPID1Donly = (TH2D *) efficiencystepMCHFEcutsTRD->Project(0,3); h_effstepMCPID1Donly->SetTitle(""); h_effstepMCPID1Donly->SetStats(0); h_effstepMCPID1Donly->SetLineColor(kBlue); h_effstepMCPID1Donly->SetMarkerColor(kBlue); h_effstepMCPID1Donly->SetMarkerStyle(25); h_effstepMCPID1Donly->Draw("colz"); /////////// // PID /////////// TCanvas * canvasc1Don = new TCanvas("PIDstepESD","PIDstepESD",1000,700); canvasc1Don->Divide(3,1); canvasc1Don->cd(1); TH2D* h_effstepPID1Donly = (TH2D *) efficiencystepPIDTOF->Project(0,3); h_effstepPID1Donly->SetTitle(""); h_effstepPID1Donly->SetStats(0); h_effstepPID1Donly->SetLineColor(kBlue); h_effstepPID1Donly->SetMarkerColor(kBlue); h_effstepPID1Donly->SetMarkerStyle(25); gPad->SetLogz(); h_effstepPID1Donly->Draw("colz"); canvasc1Don->cd(2); TH2D* h_effstepPID1Donlyy = (TH2D *) efficiencystepPIDTPC->Project(0,3); h_effstepPID1Donlyy->SetTitle(""); h_effstepPID1Donlyy->SetStats(0); h_effstepPID1Donlyy->SetLineColor(kBlue); h_effstepPID1Donlyy->SetMarkerColor(kBlue); h_effstepPID1Donlyy->SetMarkerStyle(25); gPad->SetLogz(); h_effstepPID1Donlyy->Draw("colz"); canvasc1Don->cd(3); TH2D* h_effstepPID1Donlyyy = (TH2D *) efficiencystepPIDall->Project(0,3); h_effstepPID1Donlyyy->SetTitle(""); h_effstepPID1Donlyyy->SetStats(0); h_effstepPID1Donlyyy->SetLineColor(kBlue); h_effstepPID1Donlyyy->SetMarkerColor(kBlue); h_effstepPID1Donlyyy->SetMarkerStyle(25); gPad->SetLogz(); h_effstepPID1Donlyyy->Draw("colz"); // TCanvas * canvasc1DonMC = new TCanvas("PIDstepMC","PIDstepMC",1000,700); canvasc1DonMC->Divide(3,1); canvasc1DonMC->cd(1); TH2D* h_effstepPID1DMConly = (TH2D *) efficiencystepMCPIDTOF->Project(0,3); h_effstepPID1DMConly->SetTitle(""); h_effstepPID1DMConly->SetStats(0); h_effstepPID1DMConly->SetLineColor(kBlue); h_effstepPID1DMConly->SetMarkerColor(kBlue); h_effstepPID1DMConly->SetMarkerStyle(25); gPad->SetLogz(); h_effstepPID1DMConly->Draw("colz"); canvasc1DonMC->cd(2); TH2D* h_effstepPID1DMConlyy = (TH2D *) efficiencystepMCPIDTPC->Project(0,3); h_effstepPID1DMConlyy->SetTitle(""); h_effstepPID1DMConlyy->SetStats(0); h_effstepPID1DMConlyy->SetLineColor(kBlue); h_effstepPID1DMConlyy->SetMarkerColor(kBlue); h_effstepPID1DMConlyy->SetMarkerStyle(25); gPad->SetLogz(); h_effstepPID1DMConlyy->Draw("colz"); canvasc1DonMC->cd(3); TH2D* h_effstepPID1DMConlyyy = (TH2D *) efficiencystepMCPIDall->Project(0,3); h_effstepPID1DMConlyyy->SetTitle(""); h_effstepPID1DMConlyyy->SetStats(0); h_effstepPID1DMConlyyy->SetLineColor(kBlue); h_effstepPID1DMConlyyy->SetMarkerColor(kBlue); h_effstepPID1DMConlyyy->SetMarkerStyle(25); gPad->SetLogz(); h_effstepPID1DMConlyyy->Draw("colz"); ////////// // all ////////// TCanvas * canvasall = new TCanvas("AllMC","AllMC",1000,700); //canvasall->Divide(2,1); canvasall->cd(1); TH2D* h_effstepPID1Dall = (TH2D *) efficiencystepMCall->Project(0,3); h_effstepPID1Dall->SetTitle(""); h_effstepPID1Dall->SetStats(0); h_effstepPID1Dall->SetLineColor(kBlue); h_effstepPID1Dall->SetMarkerColor(kBlue); h_effstepPID1Dall->SetMarkerStyle(25); gPad->SetLogz(); h_effstepPID1Dall->Draw("colz"); }
void dileptonMassFit(const char* pInFileName="PanchoSkim4JanAll.root", // "PromtRecoV2V3V3H_DiMuonPlot_TightSTACutsAll15Dec.root", // "Z0_DataMixPt50_PatDiMuonPlots_NewCutAll14Dec.root", const char* pHistNameOpCh="diMuonsGlobalInvMassVsPt",//diMuonsGlobalInvMassVsPtW", const char* pHistNameSameCh="diMuonsGlobalSameChargeInvMassVsPt", const char* pSpectra="pt", // pt, y, centr bool doMc=false, int nFitFunction = 3, int getYield = 1) { gROOT->Macro("setStyle.C+"); //gROOT->Macro("/Users/eusmartass/Software/utilities/setStyle.C+"); char szBuf[256]; //////// definitions of Switches /////////// // nFitFunction = 1 RBW + Pol2 // nFitFunction = 2 Gaus + Pol2 // nFitFunction = 3 RBWGaus + Pol2 // getYield = 1 Bin counting // getYield = 2 Integral //////////////////////////////////////////////////////////// // make some choices float MassZ0 = 91.1876; float WidthZ0 = 2.4952; float massFit_low = 60; float massFit_high = 120; // Fit ranges float massDraw_low = 30.0; // 0. float massDraw_high = 130.0; // 200/ int nrebin = 80; bool isLog = 0; bool isFit = 1; // draw ranges float massCount_low = 60.0; //78.0 float massCount_high = 120.0; //102.0 //___________________________________________________________________________________ // ------- Open input file sprintf(szBuf,"%s",pInFileName); TString inFileName(szBuf); TFile *pfInFile = new TFile(inFileName); // ------- get histograms: sprintf(szBuf,"%s",pHistNameOpCh); TH2D *phDimuMass_1 = (TH2D*)pfInFile->Get(szBuf)->Clone("phDimuMass_1"); sprintf(szBuf,"%s",pHistNameSameCh); TH2D *phDimuMass_1S = (TH2D*)pfInFile->Get(szBuf)->Clone("phDimuMass_1S"); phDimuMass_1->SetDirectory(0); phDimuMass_1S->SetDirectory(0); // Open pp data file TFile *ppFile = new TFile("Zmumu_40-200_35pb.root"); TH1F *Zmumu = (TH1F*)ppFile->Get("hdata"); //___________________________________________________________________________________ // bins definition: const char* Xname[] = {" ", "p_{T}^{Dimuon} (GeV/c)", "rapidity", "centrality"}; bool doPt = false; bool doY = false; bool doCent = false; int GenRange, nBins; double binEdge[10]; char* label; sprintf(szBuf,"%s",pSpectra); TString wichSpectra(szBuf); if ( wichSpectra.CompareTo("pt") == 0) { doPt = true; label = (char*)Xname[1]; GenRange = 20; nBins = 1; binEdge[0] = 0.0; binEdge[1]= 100.0; // double binEdge[10] = {0.0, 10., 20., 100.0}; if(doMc) { nBins = 1; binEdge[0] = 0.0; binEdge[1]= 50.0; // nBins = 7; // binEdge[0] = 0.0; binEdge[1] = 2.0; binEdge[2] = 4.0; binEdge[3] = 8.0; //binEdge[4] = 12.0; binEdge[5] = 16.0; binEdge[6] = 22.0; binEdge[7] = 50.0; } } else { if ( wichSpectra.CompareTo("y") == 0) { doY = true; label = (char*)Xname[2]; nBins = 3; GenRange = 4.8; binEdge[0] = -2.4; binEdge[1] = -0.8; binEdge[2] = 0.8; binEdge[3] = 2.4; } else { if ( wichSpectra.CompareTo("cent") == 0) { doCent = true; label = (char*)Xname[3]; nBins = 4; GenRange = 40; binEdge[0] = 0.; binEdge[1] = 4; binEdge[2] = 8.; binEdge[3] = 16; binEdge[4] = 40; } else { cout<<"Don't know what you want to do!!!!"<<endl; return; } } } double PT[10], DelPT[10], mom_err[100]; for (Int_t ih = 0; ih < nBins; ih++) { PT[ih] = (binEdge[ih] + binEdge[ih+1])/2.0; DelPT[ih] = binEdge[ih+1] - binEdge[ih]; mom_err[ih] = DelPT[ih]/2.0; } //___________________________________________________________________________________ double gen_pt[10]; double egen_pt[10]; TCanvas *pcPt_1 = new TCanvas("pcPt_1"," Z0 Yield Vs. Pt ", 40,40,600,600); if(doMc) { pcPt_1->Divide(nBins,2); //TH2D *genMass_1 = (TH2D*)pfInFile->Get("diMuonsGenInvMassVsPt"); TH2D *genMass_1 = (TH2D*)pfInFile->Get("diMuonsGenInvMassVsPtW"); TH1D *ptaxis = (TH1D*)genMass_1->ProjectionY("ptaxis"); for (Int_t ih = 0; ih < nBins; ih++) { pcPt_1->cd(ih+nBins+1); int bin1 = ptaxis->FindBin(binEdge[ih]+0.0000001); int bin2 = ptaxis->FindBin(binEdge[ih+1]+0.0000001); TH1D * genMassVsPt = (TH1D*)genMass_1->ProjectionX("genMassVsPt", bin1, bin2-1); genMassVsPt->Draw("EPL"); pcPt_1->Update(); TAxis *axs = genMassVsPt->GetXaxis(); int binlow = axs->FindBin(massCount_low); int binhi = axs->FindBin(massCount_high); double int_sig_gen; double int_sig_gen_sqr; for(Int_t bin = binlow; bin<=binhi; bin++) { // cout << " int_sig += dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin);"<<int_sigpow_gen <<"+="<< "bin" << bin << " content"<<genMassVsPt->GetBinContent(bin)<<endl; int_sig_gen += genMassVsPt->GetBinContent(bin); int_sig_gen_sqr += pow(genMassVsPt->GetBinContent(bin),2); } gen_pt[ih] = int_sig_gen;//genMassVsPt->GetEntries(); cout<<" gen entries : "<< gen_pt[ih]<<endl; egen_pt[ih] =int_sig_gen_sqr; } } else { if (nBins == 2) pcPt_1->Divide(2,1); if (nBins == 3 || nBins == 4) pcPt_1->Divide(2,2); if (nBins == 5 || nBins == 6) pcPt_1->Divide(3,2); } //___________________________________________________________________________________ // Fit Function // const char *name_fit[] = {" ", "RBWPol1", "GausPol1", "RBWGausPol2"}; int nParam[] = {0,6,6,7}; int nFitParam = nParam[nFitFunction]; TF1 *RBWPOL=0; if(nFitFunction == 1) RBWPOL = new TF1("RBWPOL", RBWPol2, 0, 200, nFitParam); if(nFitFunction == 2) RBWPOL = new TF1("RBWPOL", GausPol2, 0, 200, nFitParam); if(nFitFunction == 3) RBWPOL = new TF1("RBWPOL", RBWGausPol2, 0, 200, nFitParam); TF1 *EXP = new TF1("EXP", Exp, 0, 200, 2); RBWPOL->SetLineWidth(1); RBWPOL->SetParameter(1, MassZ0); RBWPOL->SetParameter(2, WidthZ0); RBWPOL->SetParLimits(1, 0.9*MassZ0, 1.1*MassZ0); RBWPOL->SetParLimits(2, 0.1*WidthZ0, 5.0*WidthZ0); if(nFitFunction == 1 || nFitFunction == 2) RBWPOL->FixParameter(5, 0); if(nFitFunction == 3 || nFitFunction == 4) { RBWPOL->SetParameter(3, WidthZ0); RBWPOL->SetParLimits(3, 0.1, 20); RBWPOL->FixParameter(2, WidthZ0); RBWPOL->FixParameter(4, 0); // for no bkg RBWPOL->FixParameter(5, 0); // for no bkg RBWPOL->FixParameter(6, 0); } //___________________________________________________________________________________ // Efficiency double yld_cat_1[10], cyld_cat_1[10], eyld_cat_1[10], ceyld_cat_1[10]; double Eff_cat_1[10], errEff_cat_1[10]; ///// Write the spectra sprintf(szBuf,"fileSpecta%d.root", getYield); // TFile *fileSpectra = new TFile(szBuf, "recreate"); //___________________________________________________________________________________ // Drawing // Category _1 TLegend *pLegCategory = new TLegend(.66, .74, .92, .94); // pLegCategory = new TLegend(.1, .82, .50, .93); pLegCategory->SetBorderSize(0); pLegCategory->SetFillStyle(0); pLegCategory->SetFillColor(0); pLegCategory->SetTextSize(0.03); // pLegCategory->AddEntry(RBWPOL," CMS Preliminary", " "); pLegCategory->AddEntry(RBWPOL," CMS Pb+Pb ", " "); pLegCategory->AddEntry(RBWPOL," #sqrt{s_{NN}} = 2.76 TeV ", " "); pLegCategory->AddEntry(RBWPOL," #int Ldt = 6.6 #mub^{-1} ", " "); // pLegCategory->AddEntry(RBWPOL," Global-Global ", ""); //pLegCategory->AddEntry(RBWPOL," |y| < 2.4 ", "P"); //pLegCategory->AddEntry(RBWPOL," Run# 150431-151027 ", "P"); TLegend *legend_1[12]; for(int i=0; i<12; i++) { if(isFit) legend_1[i] = new TLegend(.13, .66, .52, 0.94); if(!isFit) legend_1[i] = new TLegend(.13, .66, .52, 0.94 ); // legend_1[i] = new TLegend(.68, .62, .91, 0.93 ); legend_1[i]->SetBorderSize(0); legend_1[i]->SetFillStyle(0); legend_1[i]->SetFillColor(0); legend_1[i]->SetTextSize(0.028); } int bin_bound[100]; TH1D *dimuonsGlobalInvMassVsPt[10]; TH1D *dimuonsGlobalInvMassVsPtS[10]; TH1D *service = (TH1D*)phDimuMass_1->ProjectionY("service"); // cout << endl << label << " Yield Mass (GeV) Width (GeV) GauWidth chi2/ndf " << endl << endl; for (Int_t ih = 0; ih < nBins; ih++) { pcPt_1->cd(ih+1); gPad->SetTickx(); gPad->SetTicky(); // Project 1 D bin_bound[ih] = service->FindBin(binEdge[ih]+0.0000001); bin_bound[ih+1] = service->FindBin(binEdge[ih+1]+0.0000001); sprintf(szBuf,"Z0_1_pt_%d",ih); dimuonsGlobalInvMassVsPt[ih] = (TH1D*)phDimuMass_1->ProjectionX(szBuf, bin_bound[ih], bin_bound[ih+1]-1+1, "e"); sprintf(szBuf,"Z0_1S_pt_%d",ih); dimuonsGlobalInvMassVsPtS[ih] = (TH1D*)phDimuMass_1S->ProjectionX(szBuf, bin_bound[ih], bin_bound[ih+1]-1+1); cout << "reco entries" << dimuonsGlobalInvMassVsPt[ih]->GetEntries() <<endl; if(doPt || doY) { sprintf(szBuf," %s [%.1f, %.1f]", label, service->GetBinLowEdge(bin_bound[ih]), service->GetBinLowEdge(bin_bound[ih+1]-1) + service->GetBinWidth(bin_bound[ih+1])); } if(doCent) { sprintf(szBuf," %s [%.1f, %.1f] %s", label, 2.5*service->GetBinLowEdge(bin_bound[ih]), 2.5*(service->GetBinLowEdge(bin_bound[ih+1]-1) + service->GetBinWidth(bin_bound[ih+1])), "%"); } dimuonsGlobalInvMassVsPt[ih]->Rebin(nrebin); dimuonsGlobalInvMassVsPtS[ih]->Rebin(nrebin); // -------- Fit Function + Bkg Function double part[20]; dimuonsGlobalInvMassVsPt[ih]->Fit("EXP","LEQ", "", 34, 60); EXP->GetParameters(part); if(nFitFunction == 4) { RBWPOL->FixParameter(4, part[0]); RBWPOL->FixParameter(5, part[1]); } if(isFit) { //dimuonsGlobalInvMassVsPt[ih]->Fit("RBWPOL","LEQ", "", massFit_low, massFit_high); //TFitResultPtr r = dimuonsGlobalInvMassVsPt[ih]->Fit("RBWPOL","LEQS0","", massFit_low, massFit_high); // if(r->IsValid()) r->Print(); //else cout<<"Fit not valid!!!\n"<<endl; } //------ get fit parameters double par[20]; RBWPOL->GetParameters(par); float GGphDimuMass = RBWPOL->GetParameter(1); float GGZ0Width = RBWPOL->GetParameter(2); float GauWidth =0; if(nFitFunction == 3 || nFitFunction == 4) GauWidth = RBWPOL->GetParameter(3); double chisq = RBWPOL->GetChisquare(); int ndf = RBWPOL->GetNDF(); double chisqdf =1000; if(ndf!=0) chisqdf=chisq/ndf; // +++ set backgroudn fit sprintf(szBuf,"pt_1B_%d",ih); TF1 *bkgFit_1 = new TF1(szBuf, Pol2, massFit_low, massFit_high, 3); // if(nFitFunction == 4) bkgFit_1 = new TF1(namePt_1B, Exp, massFit_low, massFit_high, 2); bkgFit_1->SetParameters(&par[3]); if(nFitFunction == 3 || nFitFunction == 4) bkgFit_1->SetParameters(&par[4]); // ---------- Integrated Yield // float massCount_low =GGphDimuMass-(4.0*GGZ0Width); // float massCount_high =GGphDimuMass+(4.0*GGZ0Width); TAxis *axs = dimuonsGlobalInvMassVsPt[ih]->GetXaxis(); int binlow = axs->FindBin(massCount_low); int binhi = axs->FindBin(massCount_high); Double_t bin_size = (1.0*dimuonsGlobalInvMassVsPt[ih]->GetNbinsX())/(axs->GetXmax() - axs->GetXmin()); Float_t int_sig = 0.0; Float_t int_sig_sqr = 0.0; for(Int_t bin = binlow; bin<=binhi; bin++) { // cout << " int_sig += dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin);"<<int_sig <<"+="<< "bin" << bin << " content"<<dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin)<<endl; int_sig += dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin); int_sig_sqr += pow(dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin),2); } if(getYield == 2) { int_sig = RBWPOL->Integral(massCount_low, massCount_high)*bin_size; yld_cat_1[ih] = int_sig - bin_size*bkgFit_1->Integral(massCount_low, massCount_high); eyld_cat_1[ih] = TMath::Sqrt(int_sig + bin_size*bkgFit_1->Integral(massCount_low, massCount_high) ); } else { yld_cat_1[ih] = int_sig ; eyld_cat_1[ih] = int_sig_sqr; } cout << "int_sig - bin_size*bkgFit_1->Integral(massCount_low, massCount_high);" << int_sig<< " -"<< bin_size<<"*"<<bkgFit_1->Integral(massCount_low, massCount_high)<< " with low"<< massCount_low<<" high "<< massCount_high<<endl; //// Printing ///// cout << PT[ih] << " " << yld_cat_1[ih] << " +- " << eyld_cat_1[ih] <<" " << GGphDimuMass << " " << GGZ0Width << " " << GauWidth <<" "<< chisq << "/" << ndf << endl; // -------------- Draw // dimuonsGlobalInvMassVsPt[ih]->SetMinimum(-.05*dimuonsGlobalInvMassVsPt[ih]->GetMaximum()); if(isLog) gPad->SetLogy(1); TColor *pal = new TColor(); Int_t kblue = pal->GetColor(9,0,200); // Int_t korange = pal->GetColor(101, 42, 0); // +++ opposite charge dimuonsGlobalInvMassVsPt[ih]->SetMarkerStyle(21); dimuonsGlobalInvMassVsPt[ih]->SetMarkerColor(kblue); dimuonsGlobalInvMassVsPt[ih]->SetLineColor(kblue); dimuonsGlobalInvMassVsPt[ih]->SetMarkerSize(1.1); dimuonsGlobalInvMassVsPt[ih]->GetXaxis()->SetTitle("Dimuon mass (GeV/c^{2})"); dimuonsGlobalInvMassVsPt[ih]->GetYaxis()->SetTitle("dN/dM (2 GeV/c^{2})^{-1}"); dimuonsGlobalInvMassVsPt[ih]->GetXaxis()->SetRangeUser(massDraw_low,massDraw_high); // dimuonsGlobalInvMassVsPt[ih]->Add(dimuonsGlobalInvMassVsPtS[ih], -1); pcPt_1->cd(ih+1); dimuonsGlobalInvMassVsPt[ih]->DrawCopy("EPLsame"); // pp data TAxis *axs1 = Zmumu->GetXaxis(); int ll = axs1->FindBin(massCount_low); int hh = axs1->FindBin(massCount_high); double scalefactor = yld_cat_1[ih]/Zmumu->Integral(ll, hh); cout << Zmumu->Integral(ll, hh) << endl; Zmumu->Scale(scalefactor); Zmumu->SetFillColor(19); Zmumu->Draw("same"); dimuonsGlobalInvMassVsPt[ih]->DrawCopy("EPLsame"); // dimuonsGlobalInvMassVsPt[ih]->Draw("B"); // +++ same charge dimuonsGlobalInvMassVsPtS[ih]->SetMarkerStyle(8); dimuonsGlobalInvMassVsPtS[ih]->SetMarkerColor(46); dimuonsGlobalInvMassVsPtS[ih]->SetLineColor(46); dimuonsGlobalInvMassVsPtS[ih]->SetMarkerSize(1.1); dimuonsGlobalInvMassVsPtS[ih]->DrawCopy("EPsame"); // background // RBWPOL->SetLineColor(kblue); bkgFit_1->SetLineColor(46); bkgFit_1->SetLineWidth(1); // if(isFit) bkgFit_1->Draw("same"); // ++++ legend pLegCategory->Draw("same"); // legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," Global-Global", " "); legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," |#eta^{#mu}| < 2.4, p_{T}^{#mu} > 10 GeV/c ", ""); legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," Unlike Sign ", "LP"); legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPtS[ih]," Like Sign ", "LP"); legend_1[ih]->AddEntry(Zmumu," pp Data ", "L"); // legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], text, ""); sprintf(szBuf, "N=%1.0f #pm %1.1f ", yld_cat_1[ih], sqrt(yld_cat_1[ih]) ); legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], szBuf, ""); // sprintf(label_1, "N_{Z^{0}} = 27"); sprintf(szBuf, "mass = %1.2f #pm %1.2f GeV/c^{2}", RBWPOL->GetParameter(1), RBWPOL->GetParError(1)); // if(isFit) legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih],szBuf, ""); sprintf(szBuf, "#sigma_{Gauss} = %1.2f #pm %1.2f GeV/c^{2}", RBWPOL->GetParameter(2), RBWPOL->GetParError(2)); if(nFitFunction ==3 || nFitFunction == 4) sprintf(szBuf, "#sigma_{Gauss} = %1.2f #pm %1.2f GeV/c^{2}", RBWPOL->GetParameter(3), RBWPOL->GetParError(3)); // if(isFit) legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], szBuf, ""); sprintf(szBuf, "#chi^{2}/ndf = %1.2f / %d", chisq, ndf); // if(isFit) legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], label_4, ""); legend_1[ih]->Draw("same"); pcPt_1->Update(); } cout << endl << endl; TGraphErrors *Z0pt_cat_1 = new TGraphErrors(nBins, PT, yld_cat_1, mom_err, eyld_cat_1); Z0pt_cat_1->SetMarkerStyle(20); Z0pt_cat_1->SetMarkerColor(2); Z0pt_cat_1->GetXaxis()->SetTitle(label); Z0pt_cat_1->GetYaxis()->SetTitle("counts"); TCanvas *pc2 = new TCanvas("pc2","pc2"); Z0pt_cat_1->SetMinimum(0.0); Z0pt_cat_1->SetName("Z0pt_cat_1"); Z0pt_cat_1->Draw("AP"); TGraphErrors *Z0ptC_cat_1_gen = new TGraphErrors(nBins, PT, gen_pt, mom_err, egen_pt); // Z0ptC_cat_1_gen->SetMarkerStyle(23); //Z0ptC_cat_1_gen->SetMarkerColor(3); //Z0ptC_cat_1_gen->Draw("AP"); pLegCategory->Draw("same"); Z0pt_cat_1->Write(); pLegCategory->Write(); // gPad->Print("Pt_Z0YieldCat_1.png"); pcPt_1->Print("Pt_Z0YieldCat_1.png"); cout << endl << endl; ////////////////////////////////////////////////////////////////////////////// // Efficiency correction if(doMc) { ofstream fileout("correction.txt"); cout << label << " Eff_cat_1 " << endl; for (Int_t ih = 0; ih < nBins; ih++) { Eff_cat_1[ih] = yld_cat_1[ih]/gen_pt[ih]; errEff_cat_1[ih] = sqrt( (pow(Eff_cat_1[ih]/yld_cat_1[ih],2))*eyld_cat_1[ih] +(pow((1-Eff_cat_1[ih]/yld_cat_1[ih]),2))*( yld_cat_1[ih]-gen_pt[ih]/ yld_cat_1[ih])); // errEff_cat_1[ih] = sqrt( (pow(Eff_cat_1[ih]/yld_cat_1[ih],2))*eyld_cat_1[ih] // +(pow((1-Eff_cat_1[ih]/yld_cat_1[ih]),2))*event failing); // fileout << PT[ih] <<" "<< Eff_cat_1[ih] << " " << Eff_cat_2[ih] <<" " << Eff_cat_3[ih] << endl; // cout <<" " << PT[ih] <<" "<< Eff_cat_1[ih] << " " << Eff_cat_2[ih] << " " << Eff_cat_3[ih] << endl; fileout << PT[ih] <<" "<< Eff_cat_1[ih] << " " << errEff_cat_1[ih] << endl; cout <<" " << PT[ih] <<" "<< Eff_cat_1[ih] << " +- " << errEff_cat_1[ih] << endl; cyld_cat_1[ih] = Eff_cat_1[ih]; ceyld_cat_1[ih] = errEff_cat_1[ih]; } } else { ifstream filein("correction.txt"); cout << label << " yld_cat_1 " << " efficiency " << " corr. yld_cat_1 " << endl; for (Int_t ih = 0; ih < nBins; ih++) { // filein >> PT[ih] >> Eff_cat_1[ih] >> Eff_cat_2[ih] >> Eff_cat_3[ih] ; // cout << " " << PT[ih] << " "<< yld_cat_1[ih] << " " << yld_cat_2[ih] <<" " << yld_cat_3[ih] << endl; filein >> PT[ih] >> Eff_cat_1[ih] >> errEff_cat_1[ih]; cout << " " << PT[ih] << " " << yld_cat_1[ih] << " " << Eff_cat_1[ih] << " " << yld_cat_1[ih]/Eff_cat_1[ih] << endl; cyld_cat_1[ih] = yld_cat_1[ih]/Eff_cat_1[ih]; ceyld_cat_1[ih] = eyld_cat_1[ih]/Eff_cat_1[ih]; } } // TF1 *EXPA = new TF1("EXPA", Exp, 0, 100, 2); TGraphErrors *Z0ptC_cat_1 = new TGraphErrors(nBins, PT, cyld_cat_1, mom_err, ceyld_cat_1); Z0ptC_cat_1->SetMarkerStyle(20); Z0ptC_cat_1->SetMarkerColor(2); Z0ptC_cat_1->GetXaxis()->SetTitle(label); Z0ptC_cat_1->GetYaxis()->SetTitle("Acc x Eff"); // if(part == 2) Z0ptC_cat_1->Fit("EXPA","LEQ", "", 7, 16); new TCanvas; Z0ptC_cat_1->SetMinimum(0.0); Z0ptC_cat_1->SetMaximum(0.8); Z0ptC_cat_1->SetName("Z0ptC_cat_1"); Z0ptC_cat_1->Draw("AP"); pLegCategory->Draw("same"); cout << endl << endl; Z0ptC_cat_1->Write(); }
//______________________________________________________________________________ void KVCanvas::HandleInput(EEventType event, Int_t px, Int_t py) { // Handle Input Events. // // Handle input events, like button up/down in current canvas. if (fFreezed) return; TPad* pad; TPad* prevSelPad = (TPad*) fSelectedPad; TObject* prevSelObj = fSelected; fPadSave = (TPad*)gPad; cd(); // make sure this canvas is the current canvas fEvent = event; fEventX = px; fEventY = py; Int_t sign = 0; Bool_t sendOrder = true; if (fHasDisabledClasses && fSelected) { if (fDisabledClasses.Contains(fSelected->ClassName())) sendOrder = false; } if (fHasDisabledObject && fSelected) { if (fDisabledObjects.Contains(fSelected)) sendOrder = false; } switch (event) { case kMouseMotion: // highlight object tracked over pad = Pick(px, py, prevSelObj); if (!pad) return; EnterLeave(prevSelPad, prevSelObj); gPad = pad; // don't use cd() we will use the current // canvas via the GetCanvas member and not via // gPad->GetCanvas if (sendOrder) fSelected->ExecuteEvent(event, px, py); RunAutoExec(); if (fAgeOfEmpire && (fSelected->InheritsFrom("TH2"))) { TH2* TheHisto = (TH2*) FindHisto();//fSelected; Double_t size = 0.4 - 0.35 * fVenerMode; Int_t dX = 0; Int_t dY = 0; Double_t ppx = AbsPixeltoX(px); Double_t ppy = AbsPixeltoY(py); TAxis* ax = TheHisto->GetXaxis(); Int_t X0 = ax->GetFirst(); Int_t X1 = ax->GetLast(); Int_t NbinsX = ax->GetNbins(); px = ax->FindBin(ppx); Double_t ddX = (X1 + X0) * 0.5 - px; Double_t distX = TMath::Abs(ddX) / (X1 - X0); if (distX >= 0.5) return; TAxis* ay = TheHisto->GetYaxis(); Int_t Y0 = ay->GetFirst(); Int_t Y1 = ay->GetLast(); Int_t NbinsY = ay->GetNbins(); py = ay->FindBin(ppy); Double_t ddY = (Y1 + Y0) * 0.5 - py; Double_t distY = TMath::Abs(ddY) / (Y1 - Y0); if (distY >= 0.5) return; if ((distX <= size) && (distY <= size)) return; dX = TMath::Nint(ddX * (0.05 + 0.05 * fVenerMode)); dY = TMath::Nint(ddY * (0.05 + 0.05 * fVenerMode)); if (TMath::Abs(dX) < 1) dX = TMath::Sign(1., ddX); if (TMath::Abs(dY) < 1) dY = TMath::Sign(1., ddY); Bool_t up = false; if ((X0 - dX > 0) && (X1 - dX < NbinsX)) { ax->SetRange(X0 - dX, X1 - dX); up = true; } if ((Y0 - dY > 0) && (Y1 - dY < NbinsY)) { ay->SetRange(Y0 - dY, Y1 - dY); up = true; } if (up) { Modified(); Update(); } } break; case kMouseEnter: // mouse enters canvas if (!fDoubleBuffer) FeedbackMode(kTRUE); break; case kMouseLeave: // mouse leaves canvas { // force popdown of tooltips TObject* sobj = fSelected; TPad* spad = fSelectedPad; fSelected = 0; fSelectedPad = 0; EnterLeave(prevSelPad, prevSelObj); fSelected = sobj; fSelectedPad = spad; if (!fDoubleBuffer) FeedbackMode(kFALSE); } break; case kButton1Double: // triggered on the second button down within 350ms and within // 3x3 pixels of the first button down, button up finishes action case kButton1Down: // find pad in which input occured pad = Pick(px, py, prevSelObj); if (!pad) return; gPad = pad; // don't use cd() because we won't draw in pad // we will only use its coordinate system if (fSelected) { FeedbackMode(kTRUE); // to draw in rubberband mode fSelected->ExecuteEvent(event, px, py); RunAutoExec(); if (fSelected->InheritsFrom("TH2")) { oldx = GetEventX(); oldy = GetEventY(); xmin = AbsPixeltoX(oldx); ymin = AbsPixeltoY(oldy); gVirtualX->DrawBox(XtoAbsPixel(xmin), YtoAbsPixel(ymin), oldx, oldy, TVirtualX::kHollow); } } break; case kButton1Motion: if (fSelected) { if (fSelected->InheritsFrom("TH2")) { gVirtualX->DrawBox(XtoAbsPixel(xmin), YtoAbsPixel(ymin), oldx, oldy, TVirtualX::kHollow); oldx = GetEventX(); oldy = GetEventY(); gVirtualX->DrawBox(XtoAbsPixel(xmin), YtoAbsPixel(ymin), oldx, oldy, TVirtualX::kHollow); moved = true; } } case kButton1ShiftMotion: //8 == kButton1Motion + shift modifier if (fSelected) { gPad = fSelectedPad; if (sendOrder) fSelected->ExecuteEvent(event, px, py); gVirtualX->Update(); if (!fSelected->InheritsFrom(TAxis::Class())) { Bool_t resize = kFALSE; if (fSelected->InheritsFrom(TBox::Class())) resize = ((TBox*)fSelected)->IsBeingResized(); if (fSelected->InheritsFrom(TVirtualPad::Class())) resize = ((TVirtualPad*)fSelected)->IsBeingResized(); if ((!resize && TestBit(kMoveOpaque)) || (resize && TestBit(kResizeOpaque))) { gPad = fPadSave; Update(); FeedbackMode(kTRUE); } } RunAutoExec(); } break; case kButton1Up: if (fSelected) { gPad = fSelectedPad; if (sendOrder) fSelected->ExecuteEvent(event, px, py); RunAutoExec(); if (fPadSave) gPad = fPadSave; else { gPad = this; fPadSave = this; } if (fSelected->InheritsFrom("TH2") && moved && !fSelected->InheritsFrom("TH3")) { xmax = AbsPixeltoX(GetEventX()); ymax = AbsPixeltoY(GetEventY()); Double_t toto = 0; if (xmax < xmin) { toto = xmax; xmax = xmin; xmin = toto; } if (ymax < ymin) { toto = ymax; ymax = ymin; ymin = toto; } ZoomSelected((TH2*)FindHisto()); // ZoomSelected((TH2*)fSelected); moved = false; } Update(); // before calling update make sure gPad is reset } break; //*-*---------------------------------------------------------------------- case kButton2Down: // find pad in which input occured pad = Pick(px, py, prevSelObj); if (!pad) return; gPad = pad; // don't use cd() because we won't draw in pad // we will only use its coordinate system FeedbackMode(kTRUE); if (!fSelected->InheritsFrom("TH1")) fSelected->Pop(); // pop object to foreground pad->cd(); // and make its pad the current pad if (fSelected->InheritsFrom("TH2") && !fSelected->InheritsFrom("TH3")) { // implement pan & scan X0 = px; Y0 = py; // u clikd here theXaxis = ((TH2*)FindHisto())->GetXaxis(); theYaxis = ((TH2*)FindHisto())->GetYaxis(); NXbins = theXaxis->GetNbins(); // maximum bin number in X NYbins = theYaxis->GetNbins(); // maximum bin number in Y Xf1 = Xfirst0 = theXaxis->GetFirst(); // initial displayed bin range in X Xl1 = Xlast0 = theXaxis->GetLast(); Yf1 = Yfirst0 = theYaxis->GetFirst(); // initial displayed bin range in Y Yl1 = Ylast0 = theYaxis->GetLast(); // size of axes in pixels Int_t pixelWidthX = gPad->XtoAbsPixel(gPad->GetUxmax()) - gPad->XtoAbsPixel(gPad->GetUxmin()); Int_t pixelWidthY = gPad->YtoAbsPixel(gPad->GetUymax()) - gPad->YtoAbsPixel(gPad->GetUymin()); // sizes of bins in pixels NdisXbins = Xlast0 - Xfirst0 + 1; NdisYbins = Ylast0 - Yfirst0 + 1; XbinPixel = pixelWidthX / (1.0 * NdisXbins); YbinPixel = pixelWidthY / (1.0 * NdisYbins); } if (gDebug) printf("Current Pad: %s / %s\n", pad->GetName(), pad->GetTitle()); // loop over all canvases to make sure that only one pad is highlighted { TIter next(gROOT->GetListOfCanvases()); TCanvas* tc; while ((tc = (TCanvas*)next())) tc->Update(); } /*if (pad->GetGLDevice() != -1 && fSelected) fSelected->ExecuteEvent(event, px, py);*/ break; // don't want fPadSave->cd() to be executed at the end case kButton2Motion: //was empty! if (fSelected && fSelected->InheritsFrom("TH2") && !fSelected->InheritsFrom("TH3")) { // implement pan & scan Int_t dX = px - X0; // how far have i moved ? Int_t dY = py - Y0; Int_t dXbins = dX / XbinPixel; Int_t dYbins = dY / YbinPixel; Bool_t changed = kFALSE; Int_t newXfirst = Xfirst0 - dXbins; Int_t newXlast; if (newXfirst < 1) { newXfirst = 1; newXlast = NdisXbins; } else { newXlast = Xlast0 - dXbins; if (newXlast > NXbins) { newXlast = NXbins; newXfirst = newXlast - NdisXbins + 1; } } if (newXfirst != Xf1) { Xf1 = newXfirst; Xl1 = newXlast; theXaxis->SetRange(Xf1, Xl1); changed = kTRUE; } Int_t newYfirst = Yfirst0 - dYbins; Int_t newYlast; if (newYfirst < 1) { newYfirst = 1; newYlast = NdisYbins; } else { newYlast = Ylast0 - dYbins; if (newYlast > NYbins) { newYlast = NYbins; newYfirst = newYlast - NdisYbins + 1; } } if (newYfirst != Yf1) { Yf1 = newYfirst; Yl1 = newYlast; theYaxis->SetRange(Yf1, Yl1); changed = kTRUE; } if (changed) { Modified(); Update(); } } case kButton2Up: if (fSelected) { gPad = fSelectedPad; if (sendOrder) fSelected->ExecuteEvent(event, px, py); RunAutoExec(); } break; case kButton2Double: break; //*-*---------------------------------------------------------------------- case kButton3Down: // popup context menu pad = Pick(px, py, prevSelObj); if (!pad) return; if (!fDoubleBuffer) FeedbackMode(kFALSE); if (fContextMenu && !fSelected->TestBit(kNoContextMenu) && !pad->TestBit(kNoContextMenu) && !TestBit(kNoContextMenu)) { if (sendOrder) fContextMenu->Popup(px, py, fSelected, this, pad); else fSelected->ExecuteEvent(event, px, py); } break; case kButton3Motion: break; case kButton3Up: if (!fDoubleBuffer) FeedbackMode(kTRUE); break; case kButton3Double: break; case kKeyDown: // Info("HandleInput","Key down: %d %d",px,py); break; case kKeyUp: // Info("HandleInput","Key up: %d %d",px,py); break; case kKeyPress: if (!fSelectedPad || !fSelected) return; gPad = fSelectedPad; // don't use cd() because we won't draw in pad // we will only use its coordinate system fSelected->ExecuteEvent(event, px, py); HandleKey(px, py); RunAutoExec(); break; case kButton1Shift: // Try to select pad = Pick(px, py, prevSelObj); if (!pad) return; EnterLeave(prevSelPad, prevSelObj); gPad = pad; // don't use cd() we will use the current // canvas via the GetCanvas member and not via // gPad->GetCanvas fSelected->ExecuteEvent(event, px, py); RunAutoExec(); break; case kWheelUp: case kWheelDown: pad = Pick(px, py, prevSelObj); if (!pad) return; sign = (event == kWheelUp ? 1 : -1); gPad = pad; if (fSelected->InheritsFrom("TAxis")) fSelected->ExecuteEvent(event, px, py); else if (fSelected->InheritsFrom("TH2")) DynamicZoom(sign, px, py); RunAutoExec(); break; default: break; } if (fPadSave && event != kButton2Down) fPadSave->cd(); if (event != kMouseLeave) { // signal was already emitted for this event ProcessedEvent(event, px, py, fSelected); // emit signal DrawEventStatus(event, px, py, fSelected); } }
void plotMC(){//main TFile *file[6]; file[0]= TFile::Open("../data/plot_T5Wg_mGl-800to1000.root"); file[1]= TFile::Open("../data/plot_T5Wg_mGl-1050to1100.root"); file[2]= TFile::Open("../data/plot_T5Wg_mGl-1250to1300.root"); file[3]= TFile::Open("../data/plot_T5Wg_mGl-1350to1400.root"); file[4]= TFile::Open("../data/plot_T5Wg_mGl-1450to1500.root"); file[5]= TFile::Open("../data/plot_T5Wg_mGl-1550.root"); TH2F *p_SUSYMass[6]; TH1F *p_mcphotonET[6]; TH1F *p_mceleET[6]; TH1F *p_phoEBR9_true[6]; TH1F *p_phoEER9_true[6]; TH1F *p_phoEBHoverE_true[6]; TH1F *p_phoEEHoverE_true[6]; TH1F *p_phoEBsigma_true[6]; TH1F *p_phoEEsigma_true[6]; TH1F *p_phoEBChIso_true[6]; TH1F *p_phoEEChIso_true[6]; TH1F *p_phoEBNeuIso_true[6]; TH1F *p_phoEENeuIso_true[6]; TH1F *p_phoEBPhoIso_true[6]; TH1F *p_phoEEPhoIso_true[6]; TH1F *p_eleEBR9_true[6]; TH1F *p_eleEER9_true[6]; TH1F *p_eleEBR9_idselect[6]; TH1F *p_eleEER9_idselect[6]; TH1F *p_Mt[6]; TH1F *p_PhoELeDeltaR[6]; TH1F *p_PhoEleMass[6]; TH1F *p_selectPhoEleMass[6]; for(unsigned iF(0); iF < 6; iF++){ p_SUSYMass[iF] = (TH2F*)file[iF]->Get("Mass"); p_mcphotonET[iF] = (TH1F*)file[iF]->Get("photonET"); p_mceleET[iF] = (TH1F*)file[iF]->Get("eleET"); p_phoEBR9_true[iF] = (TH1F*)file[iF]->Get("p_phoEBR9"); p_phoEBR9_true[iF]->GetXaxis()->SetRangeUser(0.5,1); p_phoEER9_true[iF] = (TH1F*)file[iF]->Get("p_phoEER9"); p_phoEER9_true[iF]->GetXaxis()->SetRangeUser(0.5,1); p_phoEBHoverE_true[iF] = (TH1F*)file[iF]->Get("p_phoEBHoverE"); p_phoEEHoverE_true[iF] = (TH1F*)file[iF]->Get("p_phoEEHoverE"); p_phoEBsigma_true[iF] = (TH1F*)file[iF]->Get("p_phoEBsigma"); p_phoEEsigma_true[iF] = (TH1F*)file[iF]->Get("p_phoEEsigma"); p_phoEBChIso_true[iF] = (TH1F*)file[iF]->Get("p_phoEBChIso"); p_phoEEChIso_true[iF] = (TH1F*)file[iF]->Get("p_phoEEChIso"); p_phoEBNeuIso_true[iF] = (TH1F*)file[iF]->Get("p_phoEBNeuIso"); p_phoEENeuIso_true[iF] = (TH1F*)file[iF]->Get("p_phoEENeuIso"); p_phoEBPhoIso_true[iF] = (TH1F*)file[iF]->Get("p_phoEBPhoIso"); p_phoEEPhoIso_true[iF] = (TH1F*)file[iF]->Get("p_phoEEPhoIso"); p_eleEBR9_true[iF] = (TH1F*)file[iF]->Get("p_eleEBR9"); p_eleEBR9_true[iF]->GetXaxis()->SetRangeUser(0.5,1); p_eleEER9_true[iF] = (TH1F*)file[iF]->Get("p_eleEER9"); p_eleEER9_true[iF]->GetXaxis()->SetRangeUser(0.5,1); p_eleEBR9_idselect[iF] = (TH1F*)file[iF]->Get("p_eleEBR9_idselect"); p_eleEBR9_idselect[iF]->GetXaxis()->SetRangeUser(0.5,1); p_eleEER9_idselect[iF] = (TH1F*)file[iF]->Get("p_eleEER9_idselect"); p_eleEER9_idselect[iF]->GetXaxis()->SetRangeUser(0.5,1); p_Mt[iF] = (TH1F*)file[iF]->Get("Mt"); p_PhoELeDeltaR[iF] = (TH1F*)file[iF]->Get("p_PhoELeDeltaR"); p_PhoEleMass[iF] = (TH1F*)file[iF]->Get("p_PhoEleMass"); p_selectPhoEleMass[iF] = (TH1F*)file[iF]->Get("p_selectPhoEleMass"); } p_SUSYMass[0]->Add(p_SUSYMass[1]); p_SUSYMass[0]->Add(p_SUSYMass[2]); p_SUSYMass[0]->Add(p_SUSYMass[3]); p_SUSYMass[0]->Add(p_SUSYMass[4]); p_SUSYMass[0]->Add(p_SUSYMass[5]); setTDRStyle(); TCanvas *hist_MC[6][19]; std::ostringstream canvas; for(unsigned iF(0); iF<6; iF++){ for(unsigned iC(0); iC<19; iC++){ canvas.str(""); canvas << "energy" << iF << "_canvas" << iC; hist_MC[iF][iC] = new TCanvas(canvas.str().c_str(),canvas.str().c_str(),600,600); } } TCanvas *canMass = new TCanvas("SUSY Mass","SUSY Mass",600,600); TCanvas *canEt = new TCanvas("Photon Et","Photon Et",600,600); canEt->cd(); int norm(1); int LineColor[] = {1,2,3,4,6,41}; string FileList[] = {"M_{#tilde{g}}=800 to 1000","M_{#tilde{g}}=1050 to 1100", "M_{#tilde{g}}=1250 to 1300","M_{#tilde{g}}=1350 to 1400","M_{#tilde{g}}=1450 to 1500","M_{#tilde{g}}=1550"}; TLegend *legEt = new TLegend(0.4,0.55,0.86,0.85); std::ostringstream histname; for(unsigned ii(0); ii<6; ii++){ histname.str(""); histname << FileList[ii]; norm = p_mcphotonET[ii]->GetEntries(); p_mcphotonET[ii]->Scale(1.0/norm); p_mcphotonET[ii]->SetLineColor(LineColor[ii]); legEt->AddEntry(p_mcphotonET[ii],histname.str().c_str()); if(ii==0)p_mcphotonET[ii]->Draw(); else p_mcphotonET[ii]->Draw("same"); } legEt->Draw("same"); canMass->cd(); Int_t PaletteColors[] = {kBlue+1, kBlue, kBlue-7, kCyan,kGreen, kGreen-6}; // #colors >= #levels - 1 TLine *MassGridX[32]; TLine *MassGridY[16]; for(unsigned ix(0); ix < 32; ix++)MassGridX[ix]= new TLine(ix*50,800,ix*50,1600); for(unsigned iy(0); iy < 16; iy++)MassGridY[iy]= new TLine(0,iy*50+800,1600,iy*50+800); gStyle->SetPalette((sizeof(PaletteColors)/sizeof(Int_t)), PaletteColors); p_SUSYMass[0]->GetYaxis()->SetTitleOffset(1.7); p_SUSYMass[0]->Draw("colz"); for(unsigned ix(0); ix < 32; ix++)MassGridX[ix]->Draw("same"); for(unsigned iy(0); iy < 16; iy++)MassGridY[iy]->Draw("same"); TCanvas *canPt = new TCanvas("Electron Pt","Electron Pt",600,600); canPt->cd(); for(unsigned ii(0); ii<6; ii++){ norm = p_mceleET[ii]->GetEntries(); p_mceleET[ii]->Scale(1.0/norm); p_mceleET[ii]->SetLineColor(LineColor[ii]); if(ii==0)p_mceleET[ii]->Draw(); else p_mceleET[ii]->Draw("same"); } legEt->Draw("same"); TCanvas *canMT = new TCanvas("MT","MT",600,600); canMT->cd(); for(unsigned ii(0); ii<6; ii++){ norm = p_Mt[ii]->GetEntries(); p_Mt[ii]->Scale(1.0/norm); p_Mt[ii]->SetLineColor(LineColor[ii]); if(ii==0)p_Mt[ii]->Draw(); else p_Mt[ii]->Draw("same"); } legEt->Draw("same"); for(unsigned iF(0); iF<6; iF++){ TAxis *axis = p_selectPhoEleMass[iF]->GetXaxis(); Int_t bmin = axis->FindBin(0.0); Int_t bmax = axis->FindBin(95.0); double integral = p_selectPhoEleMass[iF]->Integral(bmin,bmax); std::cout << integral << " events less then 95GeV out of " << p_selectPhoEleMass[iF]->GetEntries() << std::endl; hist_MC[iF][0]->cd(); p_selectPhoEleMass[iF]->Draw(); TLine *masscut = new TLine(95,0,95,1000); masscut->SetLineColor(kRed); masscut->Draw("same"); hist_MC[iF][1]->cd(); p_mceleET[iF]->Draw(); hist_MC[iF][2]->cd(); p_phoEBR9_true[iF]->Draw(); hist_MC[iF][3]->cd(); p_phoEER9_true[iF]->Draw(); hist_MC[iF][4]->cd(); gPad->SetLogy(); p_phoEBHoverE_true[iF]->Draw(); hist_MC[iF][5]->cd(); gPad->SetLogy(); p_phoEEHoverE_true[iF]->Draw(); hist_MC[iF][6]->cd(); p_phoEBsigma_true[iF]->Draw(); hist_MC[iF][7]->cd(); p_phoEEsigma_true[iF]->Draw(); hist_MC[iF][8]->cd(); gPad->SetLogy(); p_phoEBChIso_true[iF]->Draw(); hist_MC[iF][9]->cd(); gPad->SetLogy(); p_phoEEChIso_true[iF]->Draw(); hist_MC[iF][10]->cd(); gPad->SetLogy(); p_phoEBNeuIso_true[iF]->Draw(); hist_MC[iF][11]->cd(); gPad->SetLogy(); p_phoEENeuIso_true[iF]->Draw(); hist_MC[iF][12]->cd(); gPad->SetLogy(); p_phoEBPhoIso_true[iF]->Draw(); hist_MC[iF][13]->cd(); gPad->SetLogy(); p_phoEEPhoIso_true[iF]->Draw(); hist_MC[iF][14]->cd(); p_eleEBR9_true[iF]->SetLineColor(kBlue); p_eleEBR9_idselect[iF]->SetLineColor(kRed); TLegend *legEBR9 = new TLegend(0.4,0.65,0.86,0.85); legEBR9->AddEntry(p_eleEBR9_true[iF],"all e#pm R9"); legEBR9->AddEntry(p_eleEBR9_idselect[iF],"pt>25GeV,medium WP e#pm,R9"); p_eleEBR9_true[iF]->Draw(); p_eleEBR9_idselect[iF]->Draw("same"); legEBR9->Draw("same"); hist_MC[iF][15]->cd(); p_eleEER9_true[iF]->SetLineColor(kBlue); p_eleEER9_idselect[iF]->SetLineColor(kRed); TLegend *legEER9 = new TLegend(0.4,0.65,0.86,0.85); legEER9->AddEntry(p_eleEER9_true[iF],"all e#pm R9"); legEER9->AddEntry(p_eleEER9_idselect[iF],"pt>25GeV,medium WP e#pm, R9"); p_eleEER9_true[iF]->Draw(); p_eleEER9_idselect[iF]->Draw("same"); legEER9->Draw("same"); hist_MC[iF][16]->cd(); p_Mt[iF]->Draw(); hist_MC[iF][17]->cd(); p_PhoELeDeltaR[iF]->Draw(); hist_MC[iF][18]->cd(); p_PhoEleMass[iF]->Draw(); } for(unsigned iF(0); iF<6; iF++){ for(unsigned iC(0); iC<19; iC++){ canvas.str(""); canvas << "energy" << iF << "_canvas" << iC << ".pdf"; hist_MC[iF][iC]->SaveAs(canvas.str().c_str()); } } canEt->SaveAs("MC_photonEt.pdf"); canMass->SaveAs("SUSY_Mass.pdf"); canPt->SaveAs("MC_elePt.pdf"); canMT->SaveAs("MC_MT.pdf"); }
void memstat(double update=0.01, const char* fname="*") { // Open the memstat data file, then call TTree::Draw to precompute // the arrays of positions and nbytes per entry. // update is the time interval in the data file in seconds after which // the display is updated. For example is the job producing the memstat.root file // took 100s to execute, an update of 0.1s will generate 1000 time views of // the memory use. // if fname=="*" (default), the most recent file memstat*.root will be taken. TString s; if (!fname || strlen(fname) <5 || strstr(fname,"*")) { //take the most recent file memstat*.root s = gSystem->GetFromPipe("ls -lrt memstat*.root"); Int_t ns = s.Length(); fname = strstr(s.Data()+ns-25,"memstat"); } printf("Analyzing file: %s\n",fname); f = TFile::Open(fname); if (!f) { printf("Cannot open file %s\n",fname); return; } T = (TTree*)f->Get("T"); if (!T) { printf("cannot find the TMemStat TTree named T in file %s\n",fname); return; } if (update <= 0) { printf("Illegal update value %g, changed to 0.01\n",update); update = 0.01; } if (update < 0.001) printf("Warning update parameter is very small, processing may be slow\n"); Long64_t nentries = T->GetEntries(); T->SetEstimate(nentries+10); Long64_t nsel = T->Draw("pos:nbytes:time:btid","","goff"); //now we compute the best binning for the histogram Int_t nbytes; Double_t pos; V1 = T->GetV1(); V2 = T->GetV2(); V3 = T->GetV3(); V4 = T->GetV4(); Long64_t imean = (Long64_t)TMath::Mean(nsel,V1); Long64_t irms = (Long64_t)TMath::RMS(nsel,V1); //Long64_t bw = 10000; Long64_t bw = 1000; imean = imean - imean%bw; irms = irms -irms%bw; Int_t nbins = Int_t(4*irms/bw); Long64_t ivmin = imean -bw*nbins/2; Long64_t ivmax = ivmin+bw*nbins; if (ivmax > 2000000000 && ivmin <2000000000) { //the data set has been likely generated on a 32 bits machine //we are mostly interested by the small allocations, so we select //only values below 2 GBytes printf("memory locations above 2GBytes will be ignored\n"); nsel = T->Draw("pos:nbytes:time:btid","pos <2e9","goff"); V1 = T->GetV1(); V2 = T->GetV2(); V3 = T->GetV3(); V4 = T->GetV4(); imean = (Long64_t)TMath::Mean(nsel,V1); irms = (Long64_t)TMath::RMS(nsel,V1); bw = 10000; imean = imean - imean%bw; irms = irms -irms%bw; nbins = Int_t(4*irms/bw); ivmin = imean -bw*nbins/2; ivmax = ivmin+bw*nbins; } update *= 0.0001*V3[nsel-1]; //convert time per cent in seconds Long64_t nvm = Long64_t(ivmax-ivmin+1); Long64_t *nbold = new Long64_t[nvm]; Int_t *ientry = new Int_t[nvm]; memset(nbold,0,nvm*8); Double_t dv = (ivmax-ivmin)/nbins; h = new TH1D("h",Form("%s;pos;per cent of pages used",fname),nbins,ivmin,ivmax); TAxis *axis = h->GetXaxis(); gStyle->SetOptStat("ie"); h->SetFillColor(kRed); h->SetMinimum(0); h->SetMaximum(100); halloc = new TH1D("halloc",Form("%s;pos;number of mallocs",fname),nbins,ivmin,ivmax); hfree = new TH1D("hfree", Form("%s;pos;number of frees",fname),nbins,ivmin,ivmax); //open a canvas and draw the empty histogram TCanvas *c1 = new TCanvas("c1","c1",1200,600); c1->SetFrameFillColor(kYellow-3); c1->SetGridx(); c1->SetGridy(); h->Draw(); //create a TPaveText to show the summary results TPaveText *pvt = new TPaveText(.5,.9,.75,.99,"brNDC"); pvt->Draw(); //create a TPaveLabel to show the time TPaveLabel *ptime = new TPaveLabel(.905,.7,.995,.76,"time","brNDC"); ptime->SetFillColor(kYellow-3); ptime->Draw(); //draw producer identifier TNamed *named = (TNamed*)T->GetUserInfo()->FindObject("SysInfo"); TText tmachine; tmachine.SetTextSize(0.02); tmachine.SetNDC(); if (named) tmachine.DrawText(0.01,0.01,named->GetTitle()); //start loop on selected rows Int_t bin,nb=0,j; Long64_t ipos; Double_t dbin,rest,time; Double_t updateLast = 0; Int_t nleaks = 0; Int_t i; for (i=0;i<nsel;i++) { pos = V1[i]; ipos = (Long64_t)(pos-ivmin); nbytes = (Int_t)V2[i]; time = 0.0001*V3[i]; bin = axis->FindBin(pos); if (bin<1 || bin>nbins) continue; dbin = axis->GetBinUpEdge(bin)-pos; if (nbytes > 0) { halloc->Fill(pos); if (dbin > nbytes) dbin = nbytes; //fill bytes in the first page h->AddBinContent(bin,100*dbin/dv); //fill bytes in full following pages nb = Int_t((nbytes-dbin)/dv); if (bin+nb >nbins) nb = nbins-bin; for (j=1;j<=nb;j++) h->AddBinContent(bin+j,100); //fill the bytes remaining in last page rest = nbytes-nb*dv-dbin; if (rest > 0) h->AddBinContent(bin+nb+1,100*rest/dv); //we save nbytes at pos. This info will be used when we free this slot if (nbold[ipos] > 0) printf("reallocating %d bytes (was %lld) at %lld, entry=%d\n",nbytes,nbold[ipos],ipos,i); if (nbold[ipos] == 0) { nleaks++; //save the Tree entry number where we made this allocation ientry[ipos] = i; } nbold[ipos] = nbytes; } else { hfree->Fill(pos); nbytes = nbold[ipos]; if (bin+nb >nbins) nb = nbins-bin; nbold[ipos] = 0; nleaks--; if (nbytes <= 0) continue; //fill bytes free in the first page if (dbin > nbytes) dbin = nbytes; h->AddBinContent(bin,-100*dbin/dv); //fill bytes free in full following pages nb = Int_t((nbytes-dbin)/dv); if (bin+nb >nbins) nb = nbins-bin; for (j=1;j<=nb;j++) h->AddBinContent(bin+j,-100); //fill the bytes free in in last page rest = nbytes-nb*dv-dbin; if (rest > 0) h->AddBinContent(bin+nb+1,-100*rest/dv); } if (time -updateLast > update) { //update canvas at regular intervals updateLast = time; h->SetEntries(i); c1->Modified(); pvt->GetListOfLines()->Delete(); Double_t mbytes = 0; Int_t nonEmpty = 0; Double_t w; for (Int_t k=1;k<nbins;k++) { w = h->GetBinContent(k); if (w > 0) { nonEmpty++; mbytes += 0.01*w*dv; } } Double_t occupancy = mbytes/(nonEmpty*0.01*dv); pvt->AddText(Form("memory used = %g Mbytes",mbytes*1e-6)); pvt->AddText(Form("page occupancy = %f per cent",occupancy)); pvt->AddText("(for non empty pages only)"); ptime->SetLabel(Form("%g sec",time)); c1->Update(); gSystem->ProcessEvents(); } } h->SetEntries(nsel); Int_t nlmax = nleaks; nleaks += 1000; Int_t *lindex = new Int_t[nleaks]; Int_t *entry = new Int_t[nleaks]; Int_t *ileaks = new Int_t[nleaks]; nleaks =0; for (Int_t ii=0;ii<nvm;ii++) { if (nbold[ii] > 0) { ileaks[nleaks] = (Int_t)nbold[ii]; entry[nleaks] = ientry[ii]; nleaks++; if (nleaks > nlmax) break; } } TMath::Sort(nleaks,ileaks,lindex); hentry = new TH1I("hentry","leak entry index",nleaks,0,nleaks); hleaks = new TH1I("hleaks","leaks;leak number;nbytes in leak",nleaks,0,nleaks); for (Int_t k=0;k<nleaks;k++) { Int_t kk = lindex[k]; i = entry[kk]; hentry->SetBinContent(k+1,i); hleaks->SetBinContent(k+1,ileaks[kk]); } hentry->SetEntries(nleaks); hleaks->SetEntries(nleaks); //open a second canvas and draw the histogram with leaks in decreasing order TCanvas *c2 = new TCanvas("c2","c2",1200,600); c2->SetFrameFillColor(kCyan-6); c2->SetGridx(); c2->SetGridy(); c2->SetLogy(); hleaks->SetFillColor(kRed-3); if (nleaks > 1000) hleaks->GetXaxis()->SetRange(1,1000); hleaks->Draw(); //draw producer identifier if (named) tmachine.DrawText(0.01,0.01,named->GetTitle()); //construct the tooltip TRootCanvas *rc = (TRootCanvas *)c2->GetCanvasImp(); TGMainFrame *frm = dynamic_cast<TGMainFrame *>(rc); // create the tooltip with a timeout of 250 ms if (!gTip) gTip = new TGToolTip(gClient->GetDefaultRoot(), frm, "", 250); c2->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)", 0, 0, "EventInfo(Int_t, Int_t, Int_t, TObject*)"); }
int main(int argc, char *argv[]) { cout.setf(ios::fixed, ios::floatfield); cout.precision(12); // Prompt for filename of run numbers int iXeRunPeriod; cout << "Enter Xenon run period: " << endl; cin >> iXeRunPeriod; cout << endl; /*bool allResponseClasses = true; int numResponseClasses = 0; vector <int> responseClasses; cout << "All Response Classes? (true=1/false=0): " << endl; cin >> allResponseClasses; cout << endl; if (!allResponseClasses) { cout << "Enter number of response classes: " << endl; cin >> numResponseClasses; cout << endl; if (numResponseClasses<1 || numResponseClasses>9) { cout << "Bad number of response classes to include!!\n"; exit(1); } responseClasses.resize(numResponseClasses,0); char quest[30]; for (int i=0; i<numResponseClasses; i++) { sprintf(quest,"Enter class #%i: ",i+1); cout << quest; cin >> responseClasses[i]; cout << endl; if (responseClasses[i]<0 || responseClasses[i]>8) { cout << "You entered a non-existent response class!\n"; exit(1); } } }*/ int nRuns = 0; int runList[500]; char temp[500]; sprintf(temp, "%s/run_lists/Xenon_Calibration_Run_Period_%i.dat", getenv("ANALYSIS_CODE"),iXeRunPeriod); ifstream fileRuns(temp); int ii = 0; while (fileRuns >> runList[ii]) { ii++; nRuns++; } cout << "... Number of runs: " << nRuns << endl; for (int i=0; i<nRuns; i++) { cout << runList[i] << endl; } double xyBinWidth = 5.; //2.5; PositionMap posmap(xyBinWidth,50.); posmap.setRCflag(false); //telling the position map to not use the RC choices Int_t nBinsXY = posmap.getNbinsXY(); // Open output ntuple string tempOutBase; string tempOut; //sprintf(tempOut, "position_map_%s.root", argv[1]); tempOutBase = "position_map_" + itos(iXeRunPeriod); /*if (!allResponseClasses) { tempOutBase+="_RC_"; for (int i=0; i< numResponseClasses; i++) { tempOutBase+=itos(responseClasses[i]); } }*/ tempOut = getenv("POSITION_MAPS")+tempOutBase+"_"+ftos(xyBinWidth)+"mm.root"; TFile *fileOut = new TFile(tempOut.c_str(),"RECREATE"); // Output histograms int nPMT = 8; int nBinHist = 4100;//1025; TH1D *hisxy[nPMT][nBinsXY][nBinsXY]; char *hisxyName = new char[10]; for (int p=0; p<nPMT; p++) { for (int i=0; i<posmap.getNbinsXY(); i++) { for (int j=0; j<posmap.getNbinsXY(); j++) { if (p == 0) sprintf(hisxyName, "e0_%0.0f_%0.0f", posmap.getBinCenter(i), posmap.getBinCenter(j)); if (p == 1) sprintf(hisxyName, "e1_%0.0f_%0.0f", posmap.getBinCenter(i), posmap.getBinCenter(j)); if (p == 2) sprintf(hisxyName, "e2_%0.0f_%0.0f", posmap.getBinCenter(i), posmap.getBinCenter(j)); if (p == 3) sprintf(hisxyName, "e3_%0.0f_%0.0f", posmap.getBinCenter(i), posmap.getBinCenter(j)); if (p == 4) sprintf(hisxyName, "w0_%0.0f_%0.0f", posmap.getBinCenter(i), posmap.getBinCenter(j)); if (p == 5) sprintf(hisxyName, "w1_%0.0f_%0.0f", posmap.getBinCenter(i), posmap.getBinCenter(j)); if (p == 6) sprintf(hisxyName, "w2_%0.0f_%0.0f", posmap.getBinCenter(i), posmap.getBinCenter(j)); if (p == 7) sprintf(hisxyName, "w3_%0.0f_%0.0f", posmap.getBinCenter(i), posmap.getBinCenter(j)); hisxy[p][i][j] = new TH1D(hisxyName, "", nBinHist,-100.,4000.0); } } } // Loop through input ntuples char tempIn[500]; for (int i=0; i<nRuns; i++) { // Open input ntuple sprintf(tempIn, "%s/replay_pass2_%i.root",getenv("REPLAY_PASS2"), runList[i]); DataTree *t = new DataTree(); t->setupInputTree(std::string(tempIn),"pass2"); if ( !t->inputTreeIsGood() ) { std::cout << "Skipping " << tempIn << "... Doesn't exist or couldn't be opened.\n"; continue; } int nEvents = t->getEntries(); cout << "Processing " << runList[i] << " ... " << endl; cout << "... nEvents = " << nEvents << endl; // Loop over events for (int i=0; i<nEvents; i++) { t->getEvent(i); // Select Type 0 events if (t->PID != 1) continue; if (t->Type != 0) continue; //Cut out clipped events if ( t->Side==0 && ( t->xE.nClipped>0 || t->yE.nClipped>0 || t->xeRC<1 || t->xeRC>4 || t->yeRC<1 || t->yeRC>4 ) ) continue; else if ( t->Side==1 && ( t->xW.nClipped>0 || t->yW.nClipped>0 || t->xwRC<1 || t->xwRC>4 || t->ywRC<1 || t->ywRC>4) ) continue; /*bool moveOnX = true, moveOnY=true; // Determining if the event is of the correct response class in x and y //Swank addition: Wire Chamber Response class. for (int j=0; j<numResponseClasses; j++) { if (t->xeRC == responseClasses[j]) {moveOnX=false;} if (t->yeRC == responseClasses[j]) {moveOnY=false;} } if (moveOnX || moveOnY) continue;*/ // Type 0 East Trigger int intBinX, intBinY; if (t->Side == 0) { intBinX = posmap.getBinNumber(t->xE.center); intBinY = posmap.getBinNumber(t->yE.center); // Fill PMT histograms if (intBinX>-1 && intBinY>-1) hisxy[0][intBinX][intBinY]->Fill(t->ScintE.q1); if (intBinX>-1 && intBinY>-1) hisxy[1][intBinX][intBinY]->Fill(t->ScintE.q2); if (intBinX>-1 && intBinY>-1) hisxy[2][intBinX][intBinY]->Fill(t->ScintE.q3); if (intBinX>-1 && intBinY>-1) hisxy[3][intBinX][intBinY]->Fill(t->ScintE.q4); } // Type 0 West Trigger //moveOnX=moveOnY=true; else if (t->Side == 1) { //Swank Only Allow triangles!!! //for (int j=0; j<numResponseClasses; j++) { // if (t->xwRC == responseClasses[j]) {moveOnX=false;} // if (t->ywRC == responseClasses[j]) {moveOnY=false;} //} //if (moveOnX || moveOnY) continue; intBinX = posmap.getBinNumber(t->xW.center); intBinY = posmap.getBinNumber(t->yW.center); // Fill PMT histograms if (intBinX>-1 && intBinY>-1) hisxy[4][intBinX][intBinY]->Fill(t->ScintW.q1); if (intBinX>-1 && intBinY>-1) hisxy[5][intBinX][intBinY]->Fill(t->ScintW.q2); if (intBinX>-1 && intBinY>-1) hisxy[6][intBinX][intBinY]->Fill(t->ScintW.q3); if (intBinX>-1 && intBinY>-1) hisxy[7][intBinX][intBinY]->Fill(t->ScintW.q4); } } // Close input ntuple delete t; } //Rebinning the histograms based on the mean value... for (int p=0; p<nPMT; p++) { for (int i=0; i<nBinsXY; i++) { for (int j=0; j<nBinsXY; j++) { hisxy[p][i][j]->GetXaxis()->SetRange(1,nBinHist); Double_t mean = hisxy[p][i][j]->GetMean(); hisxy[p][i][j]->GetXaxis()->SetRange(0,nBinHist); double nGroup = 4.*mean/200.; nGroup = nGroup>1. ? nGroup : 1.; hisxy[p][i][j]->Rebin((int)nGroup); } } } // Extracting mean from 200 keV peak // Define fit ranges double xLowBin[nPMT][nBinsXY][nBinsXY]; double xHighBin[nPMT][nBinsXY][nBinsXY]; double xLow[nPMT][nBinsXY][nBinsXY]; double xHigh[nPMT][nBinsXY][nBinsXY]; int maxBin[nPMT][nBinsXY][nBinsXY]; double maxCounts[nPMT][nBinsXY][nBinsXY]; double binCenterMax[nPMT][nBinsXY][nBinsXY]; double meanVal[nPMT][nBinsXY][nBinsXY]; // Holds the mean of the distribution as defined by first fitting the peak double fitMean[nPMT][nBinsXY][nBinsXY]; // Holds the mean of the low energy peak double fitSigma[nPMT][nBinsXY][nBinsXY]; // Holds the sigma of the low energy peak double endpoint[nPMT][nBinsXY][nBinsXY]; // Holds the endpoint /////// First determine roughly where the low energy peak is TSpectrum *spec; for (int p=0; p<nPMT; p++) { for (int i=0; i<nBinsXY; i++) { for (int j=0; j<nBinsXY; j++) { double r = sqrt(power(posmap.getBinCenter(j),2)+power(posmap.getBinCenter(i),2)); // Find bin with maximum content hisxy[p][i][j]->GetXaxis()->SetRange(2,nBinHist); maxBin[p][i][j] = hisxy[p][i][j]->GetMaximumBin(); maxCounts[p][i][j] = hisxy[p][i][j]->GetBinContent(maxBin[p][i][j]); binCenterMax[p][i][j] = hisxy[p][i][j]->GetBinCenter(maxBin[p][i][j]); if (r<=(50.+2*xyBinWidth)) { spec = new TSpectrum(20); Int_t npeaks = spec->Search(hisxy[p][i][j],1.5,"",0.5); if (npeaks==0) { cout << "No peaks identified at PMT" << p << " position " << posmap.getBinCenter(i) << ", " << posmap.getBinCenter(j) << endl; } else { Float_t *xpeaks = spec->GetPositionX(); // Note that newer versions of ROOT return a pointer to double... TAxis *xaxis = (TAxis*)(hisxy[p][i][j]->GetXaxis()); Int_t peakBin=0; Double_t BinSum=0.; Double_t BinSumHold = 0.; Int_t maxPeak=0.; for (int pk=0;pk<npeaks;pk++) { peakBin = xaxis->FindBin(xpeaks[pk]); //Sum over 3 center bins of peak and compare to previos BinSum to see which peak is higher BinSum = hisxy[p][i][j]->GetBinContent(peakBin) + hisxy[p][i][j]->GetBinContent(peakBin-1) + hisxy[p][i][j]->GetBinContent(peakBin+1); if (BinSum>BinSumHold) { BinSumHold=BinSum; maxPeak=pk; } } binCenterMax[p][i][j] = xpeaks[maxPeak]; } delete spec; } xLow[p][i][j] = binCenterMax[p][i][j]*2./3.; xHigh[p][i][j] = 1.5*binCenterMax[p][i][j]; } } } //////// Now fit the histograms for the peak for (int p=0; p<nPMT; p++) { for (int i=0; i<nBinsXY; i++) { for (int j=0; j<nBinsXY; j++) { if ( hisxy[p][i][j]->Integral() > 500.) {// && r<=(50.+2*xBinWidth)) { SinglePeakHist sing(hisxy[p][i][j], xLow[p][i][j], xHigh[p][i][j], true, 5, 0.8, 1.); if (sing.isGoodFit() && sing.ReturnMean()>xLow[p][i][j] && sing.ReturnMean()<xHigh[p][i][j]) { fitMean[p][i][j] = sing.ReturnMean(); fitSigma[p][i][j] = sing.ReturnSigma(); } else { cout << "Can't converge on peak in PMT " << p << " at (" << posmap.getBinCenter(i) << ", " << posmap.getBinCenter(j) << "). Trying one more time......" << endl; sing.SetRangeMin(xLow[p][i][j]); sing.SetRangeMax(xHigh[p][i][j]); sing.FitHist((double)maxBin[p][i][j], hisxy[p][i][j]->GetMean()/5., hisxy[p][i][j]->GetBinContent(maxBin[p][i][j])); if (sing.isGoodFit() && sing.ReturnMean()>xLow[p][i][j] && sing.ReturnMean()<xHigh[p][i][j]) { fitMean[p][i][j] = sing.ReturnMean(); fitSigma[p][i][j] = sing.ReturnSigma(); } else { fitMean[p][i][j] = hisxy[p][i][j]->GetMean()/1.8; int meanBin = hisxy[p][i][j]->GetXaxis()->FindBin(fitMean[p][i][j]); int counts_check = hisxy[p][i][j]->GetBinContent(meanBin); int counts = counts_check; int bin=0; if ( counts_check > 10 ) { while (counts>0.6*counts_check) { bin++; counts = hisxy[p][i][j]->GetBinContent(meanBin+bin); } } xHighBin[p][i][j] = (meanBin+bin) < hisxy[p][i][j]->GetNbinsX()/3 ? (meanBin+bin): meanBin; fitSigma[p][i][j] = hisxy[p][i][j]->GetBinCenter(xHighBin[p][i][j]) - fitMean[p][i][j]; cout << "Can't converge on peak in PMT " << p << " at bin (" << posmap.getBinCenter(i) << ", " << posmap.getBinCenter(j) << "). "; cout << "**** replaced fit mean with hist_mean/1.8 " << fitMean[p][i][j] << endl; } } } else { fitMean[p][i][j] = hisxy[p][i][j]->GetMean()/1.8; //if ( fitMean[p][i][j]>xLow[p][i][j] && fitMean[p][i][j]<xHigh[p][i][j] ) cout << "**** replaced fit mean with hist_mean/1.8 " << fitMean[p][i][j] << endl; //else { //fitMean[p][i][j] = binCenterMax[p][i][j]; //cout << "**** replaced fit mean with binCenterMax " << fitMean[p][i][j] << endl; //} int meanBin = hisxy[p][i][j]->GetXaxis()->FindBin(fitMean[p][i][j]); int counts_check = hisxy[p][i][j]->GetBinContent(meanBin); int counts = counts_check; int bin=0; double frac = exp(-1/2.); // This should be the fraction of events for a gaussian at 1 sigma if ( counts_check > 10 ) { while (counts>frac*counts_check) { bin++; counts = hisxy[p][i][j]->GetBinContent(meanBin+bin); } } xHighBin[p][i][j] = (meanBin+bin) < hisxy[p][i][j]->GetNbinsX()/3 ? (meanBin+bin): meanBin; fitSigma[p][i][j] = hisxy[p][i][j]->GetBinCenter(xHighBin[p][i][j]) - fitMean[p][i][j]; } } } } fileOut->Write(); // Writing the histograms with the peaks to file ////////// Now determine the mean of the Xe distribution in every position bin above the peak to avoid ////////// trigger effects double nSigmaFromMean = 1.5; // This is how far over from the peak we are starting the sum of the spectra for (int p=0; p<nPMT; p++) { for (int i=0; i<nBinsXY; i++) { for (int j=0; j<nBinsXY; j++) { hisxy[p][i][j]->GetXaxis()->SetRange(hisxy[p][i][j]->GetXaxis()->FindBin(fitMean[p][i][j]+nSigmaFromMean*fitSigma[p][i][j]), hisxy[p][i][j]->GetNbinsX()-1); meanVal[p][i][j] = hisxy[p][i][j]->GetMean(); hisxy[p][i][j]->GetXaxis()->SetRange(0, hisxy[p][i][j]->GetNbinsX()); // Set the range back to the full range } } } ////////// Now determine the endpoint of the Xe distribution in every position bin double lowerBoundMult = 1.; double upperBoundMult = 2.; TFile *epfile = new TFile(TString::Format("%s/%s_%smm_endpoints.root",getenv("POSITION_MAPS"),tempOutBase.c_str(),ftos(xyBinWidth).c_str()),"RECREATE"); TGraphErrors epgraph; KurieFitter kf; for (int p=0; p<nPMT; p++) { for (int i=0; i<nBinsXY; i++) { for (int j=0; j<nBinsXY; j++) { kf.FitSpectrum(hisxy[p][i][j], lowerBoundMult*meanVal[p][i][j], upperBoundMult*meanVal[p][i][j], 1.); endpoint[p][i][j] = kf.returnK0(); epgraph = kf.returnKuriePlot(); epgraph.SetName(TString::Format("pmt%i_x%0.1f_y%0.1f",p,posmap.getBinCenter(i), posmap.getBinCenter(j))); epgraph.Write(); } } } delete epfile; delete fileOut; ///////////////////////// Extract position maps for meanVal /////////////////////////////// double norm[nPMT]; for (int p=0; p<nPMT; p++) { norm[p] = meanVal[p][nBinsXY/2][nBinsXY/2]; cout << norm[p] << endl; } //Checking for weird outliers for (int p=0; p<nPMT; p++) { for (int i=0; i<nBinsXY; i++) { for (int j=0; j<nBinsXY; j++) { if ( meanVal[p][i][j]<(0.1*norm[p]) || meanVal[p][i][j]>(8.*norm[p]) ) meanVal[p][i][j] = (0.1*norm[p]); } } } double positionMap[nPMT][nBinsXY][nBinsXY]; for (int p=0; p<nPMT; p++) { for (int i=0; i<nBinsXY; i++) { for (int j=0; j<nBinsXY; j++) { positionMap[p][i][j] = meanVal[p][i][j] / norm[p]; } } } // Write position maps to file TString mapFile = TString::Format("%s/%s_%0.1fmm.dat", getenv("POSITION_MAPS"),tempOutBase.c_str(),xyBinWidth); ofstream outMap(mapFile.Data()); for (int i=0; i<nBinsXY; i++) { for (int j=0; j<nBinsXY; j++) { outMap << posmap.getBinCenter(i) << " " << posmap.getBinCenter(j) << " " << positionMap[0][i][j] << " " << positionMap[1][i][j] << " " << positionMap[2][i][j] << " " << positionMap[3][i][j] << " " << positionMap[4][i][j] << " " << positionMap[5][i][j] << " " << positionMap[6][i][j] << " " << positionMap[7][i][j] << endl; } } outMap.close(); // Write norms to file TString normFile = TString::Format("%s/norm_%s_%0.1fmm.dat", getenv("POSITION_MAPS"),tempOutBase.c_str(),xyBinWidth); ofstream outNorm(normFile.Data()); for (int p=0; p<nPMT; p++) { outNorm << norm[p] << endl; } outNorm.close(); ///////////////////////// Extract position maps for peaks /////////////////////////////// for (int p=0; p<nPMT; p++) { norm[p] = fitMean[p][nBinsXY/2][nBinsXY/2]; cout << norm[p] << endl; } //Checking for weird outliers for (int p=0; p<nPMT; p++) { for (int i=0; i<nBinsXY; i++) { for (int j=0; j<nBinsXY; j++) { if ( fitMean[p][i][j]<(0.1*norm[p]) || fitMean[p][i][j]>(8.*norm[p]) ) fitMean[p][i][j] = (0.1*norm[p]); } } } for (int p=0; p<nPMT; p++) { for (int i=0; i<nBinsXY; i++) { for (int j=0; j<nBinsXY; j++) { positionMap[p][i][j] = fitMean[p][i][j] / norm[p]; } } } // Write position maps to file mapFile = TString::Format("%s/%s_%0.1fmm_peakFits.dat", getenv("POSITION_MAPS"),tempOutBase.c_str(),xyBinWidth); outMap.open(mapFile.Data()); for (int i=0; i<nBinsXY; i++) { for (int j=0; j<nBinsXY; j++) { outMap << posmap.getBinCenter(i) << " " << posmap.getBinCenter(j) << " " << positionMap[0][i][j] << " " << positionMap[1][i][j] << " " << positionMap[2][i][j] << " " << positionMap[3][i][j] << " " << positionMap[4][i][j] << " " << positionMap[5][i][j] << " " << positionMap[6][i][j] << " " << positionMap[7][i][j] << endl; } } outMap.close(); ///////////////////////// Extract position maps for endpoints /////////////////////////////// for (int p=0; p<nPMT; p++) { norm[p] = endpoint[p][nBinsXY/2][nBinsXY/2]; cout << norm[p] << endl; } //Checking for weird outliers for (int p=0; p<nPMT; p++) { for (int i=0; i<nBinsXY; i++) { for (int j=0; j<nBinsXY; j++) { if ( endpoint[p][i][j]<(0.1*norm[p]) || endpoint[p][i][j]>(8.*norm[p]) ) endpoint[p][i][j] = (0.1*norm[p]); } } } for (int p=0; p<nPMT; p++) { for (int i=0; i<nBinsXY; i++) { for (int j=0; j<nBinsXY; j++) { positionMap[p][i][j] = endpoint[p][i][j] / norm[p]; } } } // Write position maps to file mapFile = TString::Format("%s/%s_%0.1fmm_endpoints.dat", getenv("POSITION_MAPS"),tempOutBase.c_str(),xyBinWidth); outMap.open(mapFile.Data()); for (int i=0; i<nBinsXY; i++) { for (int j=0; j<nBinsXY; j++) { outMap << posmap.getBinCenter(i) << " " << posmap.getBinCenter(j) << " " << positionMap[0][i][j] << " " << positionMap[1][i][j] << " " << positionMap[2][i][j] << " " << positionMap[3][i][j] << " " << positionMap[4][i][j] << " " << positionMap[5][i][j] << " " << positionMap[6][i][j] << " " << positionMap[7][i][j] << endl; } } outMap.close(); return 0; }
void Z0AccEff(int isData = 2, int yieldInt = 1, int iSpec = 3, int Weight =1) { //////// definitions of Switches /////////// // isData = 1 for Data // isData = 2 for Simulation // iSpec = 1 pT spectra // iSpec = 2 Y spectra // iSpec = 3 Centrality Spectra //Weight = 1 for weighted histo //weight = 0 for non weighted histo //////////////////////////////////////////////////////////// gStyle->SetOptStat(0); gStyle->SetOptStat(0); gStyle->SetOptFit(0000); // Fit ranges float mass_low, mass_high, mlow, mhigh; int nrebin; bool isLog, isFit; double MassZ0, WidthZ0; // High Mass range MassZ0 = 91.1876; WidthZ0 = 2.4952; mass_low = 60; mass_high = 120; // Fit ranges Glb Glb //mass_low = 40; mass_high = 140; // Fit ranges STA mlow = 0.0; mhigh = 200.0; nrebin = 80; isLog =0; isFit = 0; // draw ranges int whis = 1; // 1 for full all eta, 2 for barrel //4 for trigger matched PAT //file one is good file TFile *fil1, *fil2; if (isData == 2) fil2 = new TFile("Z0_DataMixPt50_PatDiMuonPlots_All11Dec.root"); //if (isData == 2) fil2 = new TFile("ReReco_DM_DiMuonPlot_All16Dec.root"); if (isData == 2) fil1 = new TFile("Z0HydPt50_PatDiMuonPlots_AllWOSel12Dec.root"); // Pt bin sizes int Nptbin=1; double pt_bound[100] = {0}; if(iSpec == 1) { Nptbin = 3; pt_bound[0] = 0.0; pt_bound[1] = 6.0; pt_bound[2] = 12.0; pt_bound[3] = 100.0; if(isData == 2) { Nptbin = 25; // pt_bound[100] = {0.0,100.0,12.0,100.0}; pt_bound[0] = 0; pt_bound[1] = 2; pt_bound[2] = 4; pt_bound[3] = 6; pt_bound[4] = 8; pt_bound[5] = 10; pt_bound[6] = 12; pt_bound[7] = 14; pt_bound[8] = 16; pt_bound[9] = 18; pt_bound[10] = 20; pt_bound[11] = 22; pt_bound[12] = 24; pt_bound[13] = 26; pt_bound[14] = 28; pt_bound[15] = 30; pt_bound[16] = 32; pt_bound[17] = 34; pt_bound[18] = 36; pt_bound[19] = 38; pt_bound[20] = 40; pt_bound[21] = 42; pt_bound[22] = 44; pt_bound[23] = 46; pt_bound[24] = 48; pt_bound[25] = 50; } } // Y bin sizes if(iSpec == 2) { Nptbin = 10; // pt_bound[100] = {-2.4,-1.0,-0.5,0.5,1.0,2.4}; // pt_bound[100] = {-2.4,-1.0,-0.5,0.5,1.0,2.4}; // pt_bound[100] = {-2.4,-2.1,-1.6,-1.1,-0.6,0,0.6,1.1,1.6,2.1,2.4}; pt_bound[0] = -2.4; pt_bound[1] = -2.1; pt_bound[2] = -1.6; pt_bound[3] = -1.1; pt_bound[4] = -0.6; pt_bound[5] = 0.0; pt_bound[6] = 0.6; pt_bound[7] = 1.1; pt_bound[8] = 1.6; pt_bound[9] = 2.1; pt_bound[10] = 2.4; } if(iSpec == 3) { if(isData == 2) { Nptbin = 9; pt_bound[0] = 0.0; pt_bound[1] = 4.0; pt_bound[2] = 8.0; pt_bound[3] = 12.0; pt_bound[4] = 16.0; pt_bound[5] = 20.0; pt_bound[6] = 24.0; pt_bound[7] = 28.0; pt_bound[8] = 32.0; pt_bound[9] = 40.0; } } double PT[100], DelPT[100], mom_err[100]; for (Int_t ih = 0; ih < Nptbin; ih++) { PT[ih] = (pt_bound[ih] + pt_bound[ih+1])/2.0; DelPT[ih] = pt_bound[ih+1] - pt_bound[ih]; mom_err[ih] = DelPT[ih]/2.0; } float gen_pt[100], gen_ptError[100]; float gen_ptS[100], gen_ptErrorS[100]; if(isData==2){ TH2D *genMass_1, *genMassS_1; if (iSpec == 1 && Weight==1 ) genMass_1 = (TH2D*)fil1->Get("diMuonsGenInvMassVsPtW"); if (iSpec == 2 && Weight==1) genMass_1 = (TH2D*)fil1->Get("diMuonsGenInvMassVsYW"); if (iSpec == 3 && Weight==1) genMass_1 = (TH2D*)fil1->Get("diMuonsGenInvMassVsCenW"); if (iSpec == 1 && Weight==1) genMassS_1 = (TH2D*)fil2->Get("diMuonsGenInvMassVsPtW"); if (iSpec == 2 && Weight==1) genMassS_1 = (TH2D*)fil2->Get("diMuonsGenInvMassVsYW"); if (iSpec == 3 && Weight==1) genMassS_1 = (TH2D*)fil2->Get("diMuonsGenInvMassVsCenW"); if (iSpec == 1 && Weight==0) genMass_1 = (TH2D*)fil1->Get("diMuonsGenInvMassVsPt"); if (iSpec == 2 && Weight==0) genMass_1 = (TH2D*)fil1->Get("diMuonsGenInvMassVsY"); if (iSpec == 3 && Weight==0) genMass_1 = (TH2D*)fil1->Get("diMuonsGenInvMassVsCen"); if (iSpec == 1 && Weight==0) genMassS_1 = (TH2D*)fil2->Get("diMuonsGenInvMassVsPt"); if (iSpec == 2 && Weight==0) genMassS_1 = (TH2D*)fil2->Get("diMuonsGenInvMassVsY"); if (iSpec == 3 && Weight==0) genMassS_1 = (TH2D*)fil2->Get("diMuonsGenInvMassVsCen"); TH1D *ptaxis = (TH1D*)genMass_1->ProjectionY("ptaxis"); for (Int_t ih = 0; ih < Nptbin; ih++) { cout<<pt_bound[ih]<<" "<<pt_bound[ih+1]<<endl; int pt_bin1 = ptaxis->FindBin(pt_bound[ih]+0.0000001); int pt_bin2 = ptaxis->FindBin(pt_bound[ih+1]+0.0000001); cout<< pt_bin1<<" "<< pt_bin2<<endl; TH1D * genMassVsPt = (TH1D*)genMass_1->ProjectionX("genMassVsPt", pt_bin1, pt_bin2-1); TH1D * genMassVsPtS = (TH1D*)genMassS_1->ProjectionX("genMassVsPtS", pt_bin1, pt_bin2-1); //does not work with weight //gen_pt[ih] = genMassVsPt->GetEntries(); double genError,genErrorS; gen_pt[ih] = genMassVsPt->IntegralAndError(1,8000,genError); gen_ptError[ih]= genError; gen_ptS[ih] = genMassVsPtS->IntegralAndError(1,8000,genErrorS); gen_ptErrorS[ih]= genErrorS; cout<<" gen entries : "<< gen_pt[ih]<<endl; cout<<"genErro "<<genError<<" "<< gen_ptError[ih]<<endl<<endl; } } // Efficiency float Eff_cat_1[100]; float Eff_catS_1[100]; float errEff_cat_1[100]; float errEff_catS_1[100]; float errEff_cat_S1[100], errEff_cat_S2[100]; float errEff_catS_S1[100], errEff_catS_S2[100]; char *Xname[100] = {" ", "p_{T}^{Dimuon} (GeV/c)", "rapidity", "centrality"}; double yld_cat_1[100]; double yld_catS_1[100]; double cyld_cat_1[100]; double cyld_catS_1[100]; double eyld_cat_1[100]; double eyld_catS_1[100]; double ceyld_cat_1[100], ceyld_catS_1[100]; char namePt_1[500]; char namePt_1S[500]; //char namePt_1B[500]; char text[100]; ///// Write the spectra char fspectra[500]; sprintf(fspectra,"fileSpecta%d.root", yieldInt); TFile *fileSpectra = new TFile(fspectra, "recreate"); /////////////////////////////////////////////////////////////////////// // Category _1 TLegend *lcat_1; lcat_1 = new TLegend(.1, .82, .50, .93); lcat_1->SetName("lcat_1"); lcat_1->SetBorderSize(0); lcat_1->SetFillStyle(0); lcat_1->SetFillColor(0); lcat_1->SetTextSize(0.032); //lcat_1->AddEntry(RBWPOL," CMS Preliminary", " "); //lcat_1->AddEntry(RBWPOL," PbPb #sqrt{s_{NN}} = 2.76 TeV ", " "); TLegend *legend_1[100]; for(int i=0; i<100; i++) { if(isFit) legend_1[i] = new TLegend(.62, .52, .91, 0.93 ); if(!isFit) legend_1[i] = new TLegend(.62, .68, .91, 0.93 ); legend_1[i]->SetBorderSize(0); legend_1[i]->SetFillStyle(0); legend_1[i]->SetFillColor(0); legend_1[i]->SetTextSize(0.032); } //for no cut //if(whis == 1 && iSpec == 1 ) TH2D *Z0Mass_1 = (TH2D*)fil1->Get("dimu"); //if(whis == 2 && iSpec == 1) TH2D *Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsPtBRL"); //if(whis == 4 && iSpec == 1 ) { //TH2D *Z0Mass_1 = (TH2D*)fil1->Get("diMuonsPATInvMassVsPt"); //TH2D *Z0Mass_1 = (TH2D*)fil1->Get("diMuonsPATSTAInvMassVsPt"); //} TH2D *Z0Mass_1, *Z0Mass_1S; //with weight if(iSpec == 1 && Weight==1 ) Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsPtW"); if(iSpec == 2 && Weight==1) Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsYW"); if(iSpec == 3 && Weight==1) Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsCenW"); //without weight if(iSpec == 1 && Weight==0) Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsPt"); if(iSpec == 2 && Weight==0) Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsY"); if(iSpec == 3 && Weight==0) Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsCen"); //with weight fil2 if(iSpec == 1 && Weight==1) Z0Mass_1S = (TH2D*)fil2->Get("diMuonsGlobalInvMassVsPtW"); if(iSpec == 2 && Weight==1) Z0Mass_1S = (TH2D*)fil2->Get("diMuonsGlobalInvMassVsYW"); if(iSpec == 3 && Weight==1) Z0Mass_1S = (TH2D*)fil2->Get("diMuonsGlobalInvMassVsCenW"); //without weight fil2 if(iSpec == 1 && Weight==0 ) Z0Mass_1S = (TH2D*)fil2->Get("diMuonsGlobalInvMassVsPt"); if(iSpec == 2 && Weight==0 ) Z0Mass_1S = (TH2D*)fil2->Get("diMuonsGlobalInvMassVsY"); if(iSpec == 3 && Weight==0 ) Z0Mass_1S = (TH2D*)fil2->Get("diMuonsGlobalInvMassVsCen"); TH1D *service = (TH1D*)Z0Mass_1->ProjectionY("service"); int pt_bin_bound[100]; TH1D *dimuonsGlobalInvMassVsPt[100], *dimuonsGlobalInvMassVsPtS[100]; TCanvas *CanvPt_1 = new TCanvas("CanvPt_1"," Z0 Yield Vs. Pt ", 40,40,1000,700); if (Nptbin == 2) CanvPt_1->Divide(2,1); if (Nptbin == 3 || Nptbin == 4) CanvPt_1->Divide(2,2); if (Nptbin == 5 || Nptbin == 6) CanvPt_1->Divide(3,2); if (Nptbin == 9 || Nptbin == 10) CanvPt_1->Divide(5,2); cout << endl << Xname[iSpec] << " Yield Mass (GeV) Width (GeV) GauWidth chi2/ndf " << endl << endl; //ih loop for (Int_t ih = 0; ih < Nptbin; ih++) { CanvPt_1->cd(ih+1); gPad->SetTickx(); gPad->SetTicky(); // Project 1 D pt_bin_bound[ih] = Z0Mass_1->GetYaxis()->FindBin(pt_bound[ih]+0.0000001); pt_bin_bound[ih+1] = Z0Mass_1->GetYaxis()->FindBin(pt_bound[ih+1]-0.0000001); sprintf(namePt_1,"Z0_1_pt_%d",ih); sprintf(namePt_1S,"Z0_1S_pt_%d",ih); //printf(namePt_1,"Z0_1_pt_%d",ih); //cout<<endl<<endl; //continue; dimuonsGlobalInvMassVsPt[ih] = (TH1D*)Z0Mass_1->ProjectionX(namePt_1, pt_bin_bound[ih], pt_bin_bound[ih+1]-1+1, "e"); dimuonsGlobalInvMassVsPtS[ih] = (TH1D*)Z0Mass_1S->ProjectionX(namePt_1S, pt_bin_bound[ih], pt_bin_bound[ih+1]-1+1,"e"); if(iSpec == 1 || iSpec == 2) {sprintf(text," %s [%.1f, %.1f]", Xname[iSpec], service->GetBinLowEdge(pt_bin_bound[ih]), service->GetBinLowEdge(pt_bin_bound[ih+1])+service->GetBinWidth(pt_bin_bound[ih+1]));} if(iSpec == 3) {sprintf(text," %s [%.1f, %.1f] %s", Xname[iSpec], 2.5*service->GetBinLowEdge(pt_bin_bound[ih]), 2.5*(service->GetBinLowEdge(pt_bin_bound[ih+1])+service->GetBinWidth(pt_bin_bound[ih+1])), "%");} dimuonsGlobalInvMassVsPt[ih]->Rebin(nrebin); dimuonsGlobalInvMassVsPtS[ih]->Rebin(nrebin); float m_low = 60.0; float m_high = 120.0; TAxis *axs = dimuonsGlobalInvMassVsPt[ih]->GetXaxis(); int binlow = axs->FindBin(m_low); int binhi = axs->FindBin(m_high); // Double_t bin_size = (1.0*dimuonsGlobalInvMassVsPt[ih]->GetNbinsX())/(axs->GetXmax() - axs->GetXmin()); // Float_t int_sig = 0.0; //for(Int_t bin = binlow; bin<=binhi;bin++) { //int_sig+ = dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin); //} double recerror,recerrorS; //double yld; double yld_1 = dimuonsGlobalInvMassVsPt[ih]->IntegralAndError(binlow, binhi, recerror); double yldS_1 = dimuonsGlobalInvMassVsPtS[ih]->IntegralAndError(binlow, binhi, recerrorS); eyld_cat_1[ih] =recerror; eyld_catS_1[ih] =recerrorS; cout<< "yld " << yld_1 <<" eyld_cat_1[ih] "<< eyld_cat_1[ih]<<" rec error "<<recerror<<endl; yld_cat_1[ih] = yld_1; yld_catS_1[ih] = yldS_1; if(isLog) gPad->SetLogy(1); TColor *pal = new TColor(); Int_t kblue = pal->GetColor(9,0,200); // Int_t korange = pal->GetColor(101, 42, 0); dimuonsGlobalInvMassVsPt[ih]->SetMarkerStyle(21); dimuonsGlobalInvMassVsPt[ih]->SetMarkerColor(kblue); dimuonsGlobalInvMassVsPt[ih]->SetLineColor(kblue); dimuonsGlobalInvMassVsPt[ih]->GetXaxis()->SetTitle("Dimuon mass (GeV/c^{2})"); dimuonsGlobalInvMassVsPt[ih]->GetYaxis()->SetTitle("Events/(2 GeV/c^{2})"); dimuonsGlobalInvMassVsPt[ih]->GetXaxis()->SetRangeUser(mlow,mhigh); dimuonsGlobalInvMassVsPt[ih]->DrawCopy("EPL"); // fil2 dimuonsGlobalInvMassVsPtS[ih]->SetMarkerStyle(8); dimuonsGlobalInvMassVsPtS[ih]->SetMarkerColor(46); dimuonsGlobalInvMassVsPtS[ih]->SetLineColor(46); //****** dimuonsGlobalInvMassVsPtS[ih]->DrawCopy("EPsame"); //RBWPOL->SetLineColor(kblue); //backfun_1->SetLineColor(46); //backfun_1->SetLineWidth(1); //if(isFit) backfun_1->Draw("same"); lcat_1->Draw("same"); legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih],"Global-Global", " "); legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," |y| < 2.4 ", ""); legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], text, ""); legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," Opposite Charge ", "LP"); legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPtS[ih]," Same Charge ", "LP"); char label_1[512]; // char label_2[512], label_3[512], label_4[512]; sprintf(label_1, "N=%1.2f #pm %1.2f ", yld_cat_1[ih], eyld_cat_1[ih]); // sprintf(label_1, "N_{Z^{0}} = 27"); legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], label_1, ""); }//ih loop cout << endl << endl; CanvPt_1->Print("Pt_Z0MassCat_1.png"); TGraphErrors *Z0pt_cat_1 = new TGraphErrors(Nptbin, PT, yld_cat_1, mom_err, eyld_cat_1); Z0pt_cat_1->SetMarkerStyle(20); Z0pt_cat_1->SetMarkerColor(2); Z0pt_cat_1->GetXaxis()->SetTitle(Xname[iSpec]); Z0pt_cat_1->GetYaxis()->SetTitle("counts"); new TCanvas; Z0pt_cat_1->SetMinimum(0.0); Z0pt_cat_1->SetName("Z0pt_cat_1"); Z0pt_cat_1->Draw("AP"); lcat_1->Draw("same"); gPad->Print("Pt_Z0YieldCat_1.png"); cout << endl << endl; Z0pt_cat_1->Write(); lcat_1->Write(); // Efficiency correction if(isData==2) { ofstream fileout("correction.txt"); cout << Xname[iSpec] << " Eff_cat_1 " << endl; for (Int_t ih = 0; ih < Nptbin; ih++) { //cout<<"gen_pt[ih]; "<<gen_pt[ih]<<endl; Eff_cat_1[ih] = yld_cat_1[ih]/gen_pt[ih]; Eff_catS_1[ih] = yld_catS_1[ih]/gen_ptS[ih]; //eyld_cat_1[ih]; //gen_ptError[ih]; //cout<<endl<<endl<<endl; //cout<<"Eff_cat_1[ih] "<<Eff_cat_1[ih]<<endl; //cout<<"yld_cat_1[ih] "<< yld_cat_1[ih] <<endl; //cout<<"eyld_cat_1[ih] "<<eyld_cat_1[ih] <<endl; //cout<<"gen_pt[ih] "<< gen_pt[ih] <<endl; //cout<<"gen_ptError[ih] "<< gen_ptError[ih]<<endl; //Error for first graph double errEff_cat_S1_1[100]={0},errEff_cat_S1_2[100]={0}; double errEff_cat_S2_1[100]={0},errEff_cat_S2_2[100]={0}; errEff_cat_S1_1[ih]= ( (Eff_cat_1[ih] * Eff_cat_1[ih]) /(gen_pt[ih] * gen_pt[ih]) ); errEff_cat_S1_2[ih]= (gen_ptError[ih] * gen_ptError[ih] ) - ( eyld_cat_1[ih] * eyld_cat_1[ih] ); errEff_cat_S1[ih]= (errEff_cat_S1_1[ih] * errEff_cat_S1_2[ih]); //cout<<" errEff_cat_S1_1[ih] "<< errEff_cat_S1_1[ih]<< " errEff_cat_S1_2[ih] "<<errEff_cat_S1_2[ih]<<endl; errEff_cat_S2_1[ih]= ( (1 - Eff_cat_1[ih])* (1 - Eff_cat_1[ih]) ) / ( gen_pt[ih] * gen_pt[ih]); errEff_cat_S2_2[ih]= (eyld_cat_1[ih] * eyld_cat_1[ih]); errEff_cat_S2[ih]=errEff_cat_S2_1[ih]*errEff_cat_S2_2[ih]; //cout<<" errEff_cat_S2_1[ih] "<< errEff_cat_S2_1[ih]<< " errEff_cat_S2_2[ih] "<<errEff_cat_S2_2[ih]<<endl; //cout<<"errEff_cat_S1[ih] "<<errEff_cat_S1[ih]<< " errEff_cat_S2[ih] "<< errEff_cat_S2[ih]<<endl; errEff_cat_1[ih]=sqrt(errEff_cat_S1[ih] + errEff_cat_S2[ih]); //Error for second graph double errEff_catS_S1_1[100]={0},errEff_catS_S1_2[100]={0}; double errEff_catS_S2_1[100]={0},errEff_catS_S2_2[100]={0}; errEff_catS_S1_1[ih]= ( (Eff_catS_1[ih] * Eff_catS_1[ih]) /(gen_ptS[ih] * gen_ptS[ih]) ); errEff_catS_S1_2[ih]= (gen_ptErrorS[ih] * gen_ptErrorS[ih] ) - (eyld_catS_1[ih] * eyld_catS_1[ih] ); errEff_catS_S1[ih]= (errEff_catS_S1_1[ih] * errEff_catS_S1_2[ih]); errEff_catS_S2_1[ih]= ( (1 - Eff_catS_1[ih])* (1 - Eff_catS_1[ih]) ) / ( gen_ptS[ih] * gen_ptS[ih]); errEff_catS_S2_2[ih]= (eyld_catS_1[ih] * eyld_catS_1[ih]); errEff_catS_S2[ih]= errEff_catS_S2_1[ih]*errEff_catS_S2_2[ih]; errEff_catS_1[ih]=sqrt(errEff_catS_S1[ih] + errEff_catS_S2[ih]); //Error for no weight //errEff_cat_1[ih] =((Eff_cat_1[ih]*(1- Eff_cat_1[ih]))/gen_pt[ih]); //Prashant error //errEff_cat_1[ih] = eyld_cat_1[ih]/gen_pt[ih]; fileout << PT[ih] <<" "<< Eff_cat_1[ih] << " " << errEff_cat_1[ih] << endl; cout <<" " << PT[ih] <<" "<< Eff_cat_1[ih] << " +- " << errEff_cat_1[ih] << endl; cyld_cat_1[ih] = Eff_cat_1[ih]; ceyld_cat_1[ih] = errEff_cat_1[ih]; cyld_catS_1[ih] = Eff_catS_1[ih]; ceyld_catS_1[ih] = errEff_catS_1[ih]; } } TGraphErrors *Z0ptC_cat_1 = new TGraphErrors(Nptbin, PT, cyld_cat_1, mom_err, ceyld_cat_1); Z0ptC_cat_1->SetMarkerStyle(20); Z0ptC_cat_1->SetMarkerColor(2); Z0ptC_cat_1->GetXaxis()->SetTitle(Xname[iSpec]); Z0ptC_cat_1->GetYaxis()->SetTitle("Acc #times Eff"); Z0ptC_cat_1->GetYaxis()->SetRangeUser(0,1.0); TGraphErrors *Z0ptC_catS_1 = new TGraphErrors(Nptbin, PT, cyld_catS_1, mom_err, ceyld_catS_1); Z0ptC_catS_1->SetMarkerStyle(8); Z0ptC_catS_1->SetMarkerColor(1); Z0ptC_catS_1->GetYaxis()->SetRangeUser(0,0.8); TLegend *legend_GP = new TLegend( 0.59,0.79,0.88,0.89); legend_GP->SetBorderSize(0); legend_GP->SetFillStyle(0); legend_GP->SetFillColor(0); legend_GP->SetTextSize(0.032); //legend_GP->AddEntry(Z0ptC_catS_1,"Pythia Gun in MB HI Data ", ""); legend_GP->AddEntry(Z0ptC_catS_1,"Pythia Gun in MB Hydjet ", ""); new TCanvas; Z0ptC_cat_1->SetMinimum(0.0); Z0ptC_cat_1->Draw("AP"); //Z0ptC_catS_1->Draw("sameP"); lcat_1->Draw("same"); legend_GP->Draw("same"); cout << endl << endl; Z0ptC_cat_1->Write(); }
void eta() { // TFile* f = TFile::Open("small.root"); // open the file // TFile* f = TFile::Open("Hgg_Moriond2013-Y2012_merge_200804_216432_Presel_1lepton.root"); // TFile* f = TFile::Open("Hgg_Moriond2013-Y2012_ZH900_Pythia_NoMassCut.root"); // open the file // TTree* tree = (TTree*)f->Get("tree"); float m, me; photon p1, p2; electron e1, e2; muon m1, m2; float avg_m, sigma_m; const int N = 8; TFile *files[N]; TTree *trees[N]; int count[N]; for(int k = 0; k < N; ++k) { char filename[128] = ""; sprintf(filename, "Hgg_Moriond2013-Y2012_ZH%d00_Pythia_NoMassCut.root", k+2); files[k] = TFile::Open(filename); trees[k] = (TTree *)files[k]->Get("tree"); count[k] = trees[k]->GetEntries(); bind_attributes(trees[k], p1, p2, e1, e2, m1, m2); } const int n = 12; TF1 *fa = new TF1("fa1","(cos(x/2)/sin(x/2) ) / ((cos(x/2)/sin(x/2)) *(cos(x/2)/sin(x/2)) + 1)",0,3.142); TH1F* h = new TH1F("h", "\\mbox{ erreur energie };\\Delta E_{T}/E_{T};\\mbox{count}", n, E_min, E_max); // create a histogram : 500 bins ranging from 100 to 600 GeV. TH1F* h2 = new TH1F("h2", "invariant mass gamma gamma", n, E_min, E_max); // create a histogram : 500 bins ranging from 100 to 600 GeV. //h2->SetLineColor(kRed); int totalEntries = 0; int looseEntries = 0; int keptEntries = 0; /*int n = 0, k = 0; for (unsigned int i = 0; i < tree->GetEntries(); i++) { //if(p1.true_E < 0) continue; tree->GetEntry(i); if(p1.true_mother==25 && p2.true_mother==25) { if(p1.true_E > 0) { ++n; } } } float *x = new float[n+1], *y = new float[n+1];*/ //TF1 *f1 = new TF1("f1","gaus",122, 128); double *err[n]; int elems[n], index[n]; double en[n], den[n], xerr[n], yerr[n]; for (unsigned a = 0; a < N; ++a) { TTree *tree = trees[a]; for (unsigned int i = 0; i < count[a]; i++) { //if(p1.true_E < 0) continue; tree->GetEntry(i); //if(p1.mother==25 && p2.mother==25) { //if(p1.true_E > 0) { vec imp1, imp2; imp1.pr2c(p1.true_E, p1.true_phi, p1.true_eta); imp2.pr2c(p2.true_E, p2.true_phi, p2.true_eta); imp1.add(imp2); float p = imp1.norm(); imp1.c2pr(imp1.x, imp1.y, imp1.z); /*float px = p1.true_E * TMath::Cos(p1.true_phi) + p2.true_E * TMath::Cos(p2.true_phi); float py = p1.true_E * TMath::Sin(p1.true_phi) + p2.true_E * TMath::Sin(p2.true_phi); float pz = p1.true_E * TMath::SinH(p1.true_eta) + p2.true_E * TMath::SinH(p2.true_eta) ; float p = TMath::Sqrt(px*px + py*py + pz*pz); float eta = TMath::ATanH(pz/p);*/ //y[k] = invMassTrue(p1, p2); //x[k] = eta; //++k; //printf("%.2f\n", imp1.z - eta); //float theta = 2*atan(exp(-imp1.z)); // todo: par unité d'angle solide en fct de theta ? //h->Fill(2*atan(exp(-imp1.z))/*+TMath::Pi()/2.0f*/); /*float i1 = p1.true_E * cosh(p1.true_eta); float i2 = p2.true_E * cosh(p2.true_eta);*/ /*if(p1.tight && p1.true_E > E_min && p1.true_E < E_max) { h->Fill(p1.true_E); } if(p2.tight && p2.true_E > E_min && p2.true_E < E_max) { h->Fill(p1.true_E); }*/ p1.E *= cosh(p1.true_eta); p2.E *= cosh(p2.true_eta); p1.true_E *= cosh(p1.true_eta); p2.true_E *= cosh(p2.true_eta); if(keep_photon(p1)) { h->Fill(p1.E); if(abs(p1.E-p1.true_E) > 50) printf("%.3f %.3f %.3f %.3f\n", p1.true_E, p1.E, p1.eta, p1.isolTrack); } if(keep_photon(p2)) { h->Fill(p2.E); if(abs(p2.E-p2.true_E) > 50) printf("%.3f %.3f %.3f %.3f\n", p2.true_E, p2.E, p2.eta, p2.isolTrack); } } } } } for(int k = 0; k < n; ++k) { err[k] = NULL; elems[k] = 0; } for (unsigned a = 0; a < N; ++a) { TTree *tree = trees[a]; for(unsigned int i = 0; i < count[a]; ++i) { tree->GetEntry(i); TAxis *xaxis = h->GetXaxis(); int bin1 = xaxis->FindBin(p1.true_E)-1; int bin2 = xaxis->FindBin(p2.true_E)-1; if(keep_photon(p1) && bin1 >= 0 && bin1<n) { elems[bin1]++; } if(keep_photon(p2) && bin2 >= 0 && bin2<n) { elems[bin2]++; } } } for(int k = 0; k < n; ++k) { err[k] = new double[elems[k]]; index[k] = 0; } for (unsigned a = 0; a < N; ++a) { TTree *tree = trees[a]; for(unsigned int i = 0; i < count[a]; ++i) { tree->GetEntry(i); TAxis *xaxis = h->GetXaxis(); int bin1 = xaxis->FindBin(p1.true_E)-1; int bin2 = xaxis->FindBin(p2.true_E)-1; if(keep_photon(p1) && bin1 >= 0 && bin1 < n) { err[bin1][index[bin1]++] = p1.E-p1.true_E; } if(keep_photon(p2) && bin2 >= 0 && bin2 < n) { err[bin2][index[bin2]++] = p2.E-p2.true_E; } } } for(int k = 0; k < n; ++k) { double mean = 0; for(int j = 0; j < elems[k]; ++j) { mean += err[k][j]; } mean /= double(elems[k]); double tot = 0; //mean = 0; for(int j = 0; j < elems[k]; ++j) { //if(k == 2) printf("err: %.3f \n", err[k][j]); tot += (err[k][j]-mean) * (err[k][j]-mean); } tot /= double(elems[k]); double E = float(E_min + float(k)/float(n) * (E_max-E_min)); /*printf("%.2f %.6f %.6f %.6f %% %.7f %% %.7f %d\n", E, float(mean), float(sqrt(tot)), 100 * float(sqrt(tot))/float(E), 100 * float(sqrt(tot))/float(E)/sqrt(index[k]-1), float(1)/float(n) * (E_max-E_min)/2.0, index[k]);*/ printf("%.2f %.6f %% %.7f %% %.7f %d\n", E, 100 * float(sqrt(tot))/float(E), 100 * float(sqrt(tot))/float(E)/sqrt(index[k]-1), float(1)/float(n) * (E_max-E_min)/2.0, index[k]); en[k] = E; den[k] = 100 * float(sqrt(tot))/float(E); yerr[k] = 100 * float(sqrt(tot))/float(E)/sqrt(index[k]-1); xerr[k] = float(1)/float(n) * (E_max-E_min)/2.0; } TF1 *energy = new TF1("energy", " [0]/sqrt(x) + [1]", 100, 1000); TGraphErrors *gr = new TGraphErrors(n,en,den,xerr,yerr); gr->Fit("energy"); gr->SetTitle("\\mbox{Resolution en energie};E\\mbox{ (GeV) };\\sigma_{E} / E \\mbox{ \\% }"); gr->SetLineStyle(0); gr->SetLineWidth(0); /* h->Sumw2(); h2->Sumw2(); h->Fit("f1"); TH1F *r = (TH1F *)h->Clone(); r->Divide(h, h2, 1., 1., "B"); //r->Draw(); h->Draw();*/ gr->Draw("AP"); printf("tight ratio: %.6f\n", float(keptEntries)/float(totalEntries)); /*h->Multiply(fa); h->Draw("E");*/ // h->Draw(); // plot the histogram //h2->Draw(); }