本文整理汇总了C++中TAxis::FindBin方法的典型用法代码示例。如果您正苦于以下问题:C++ TAxis::FindBin方法的具体用法?C++ TAxis::FindBin怎么用?C++ TAxis::FindBin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TAxis
的用法示例。
在下文中一共展示了TAxis::FindBin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DynamicZoom
//________________________________________________________________
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;
}
示例2: GetSlices
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();
}
示例3: if
//________________________________________________________________
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;
}
示例4: get_background
//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;
}
示例5: GetInt
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;
}
示例6: integralInRange
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;
}
示例7: integrate
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;
}
示例8: GetIntg
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;
}
示例9: ZeroOutOfRangeBins
//------------------------------------------------------------------------------
// 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);
}
}
}
示例10:
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];
}
示例11: MoveOverflowBins
//------------------------------------------------------------------------------
// 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);
}
示例12: fillHistograms
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);
}
示例13: GetMaximumIncludingErrors
//------------------------------------------------------------------------------
// 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;
}
示例14: makePlots_hlt_eventbyevent_comparison
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);
//.........这里部分代码省略.........
开发者ID:cms-steam,项目名称:Event-by-Event_Validation,代码行数:101,代码来源:makePlots_hlt_eventbyevent_comparison.C
示例15: DrawEfficiencyCentralitySource
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);
//
//.........这里部分代码省略.........