当前位置: 首页>>代码示例>>C++>>正文


C++ TH2D::Fit方法代码示例

本文整理汇总了C++中TH2D::Fit方法的典型用法代码示例。如果您正苦于以下问题:C++ TH2D::Fit方法的具体用法?C++ TH2D::Fit怎么用?C++ TH2D::Fit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TH2D的用法示例。


在下文中一共展示了TH2D::Fit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: gaussFit

void gaussFit(pair<int, double> bump, vector<pair<int, double> > shower, TH1D* reso, TH2D* resoPos)
 {
       TF2* g2d = new TF2("g2D", Gaus2D, -5, 5, -5, 5, 6);
       g2d->SetParameters(IDtoX(bump.first),
			  IDtoY(bump.first), 
			  1., 1., 0., (bump.second));

       TH2D* histo = new TH2D("histo", "ShowerFit",
			      11, -5, 5,
			      11, -5, 5);


       vector<pair<int, double> >::iterator b; 
       for (b=shower.begin(); b!=shower.end(); b++)
	 {
	   histo->Fill(IDtoX(b->first), IDtoY(b->first), b->second);
	 }
       // g2d->FixParameter(4, 0.);
       histo->Fit(g2d, "Q");
       //g2d->Draw("cont1 same");
       reso->Fill(g2d->GetParameter(5)-gammaEnergy);
       resoPos->Fill(g2d->GetParameter(0), g2d->GetParameter(1));	
			  
 }
开发者ID:cesarotti,项目名称:Dark-Photons,代码行数:24,代码来源:clusterGaussReso.C

示例2: GetStartPosition


//.........这里部分代码省略.........
            hU->Fill( (*itClus)->z(),(*itClus)->position(), (*itClus)->pe()/distance );
            if ( countu < 2 ){
                zu[countu] = (*itClus)->z();
                xu[countu] = (*itClus)->position();
                countu++;
            }
        }

        if( (*itClus)->view()== Minerva::IDCluster::V ){
            debug() <<  " StartPoint V view, pe " << (*itClus)->pe() << "; z = " << (*itClus)->z()
                << "; coord " << (*itClus)->position() << endmsg;
            Dx = (*itClus)->position() -  m_mathTool->calcVfromXY(vert.x(),vert.y());
            distance = sqrt( pow(Dx,2) + pow(Dz,2) );
            if ( is_vertex ){
                hV->Fill( (*itClus)->z()-12,(*itClus)->tpos1(), (*itClus)->pe()/distance );
                hV->Fill( (*itClus)->z()+12,(*itClus)->tpos2(), (*itClus)->pe()/distance );
            }
            hV->Fill( (*itClus)->z(),(*itClus)->position(), (*itClus)->pe()/distance );
            if ( countv < 2 ){
                zv[countu] = (*itClus)->z();
                xv[countu] = (*itClus)->position();
                countv++;
            }
        }
    }

    TF1 *fU, *fV;

    double slopeu = -9999;
    double slopev = -9999;
    double bu = -9999;
    double bv = -9999;

    bool goodFit_U = false;
    bool goodFit_V = false;
    if ( hU->GetEntries() > 3 ){
        hU->Fit("pol1","Q0");
        fU = hU->GetFunction("pol1");
        bu = fU->GetParameter(0);
        slopeu = fU->GetParameter(1);
        goodFit_U = true;

        delete fU;
    }
    else if ( hU->GetEntries() == 2 ){ // to deal with 2 clusters on NCPi0
        if ( zu[0] > zu[1] ){
            slopeu = (xu[0] - xu[1]) / (zu[0] - zu[1]);
            bu = xu[1] - zu[1]*slopeu;
            goodFit_U = true;
        }
        else if (zu[0] < zu[1] ) {
            slopeu = (xu[1] - xu[0]) / (zu[1] - zu[0]);
            bu = xu[0] - zu[0]*slopeu;
            goodFit_U = true;
        }
    }

    if ( hV->GetEntries() > 3 ){
        hV->Fit("pol1","Q0");
        fV = hV->GetFunction("pol1");
        bv = fV->GetParameter(0);
        slopev = fV->GetParameter(1);
        goodFit_V = true;

        delete fV;
    }
开发者ID:oaltinok,项目名称:Minerva_Neutrino,代码行数:67,代码来源:HTBlob.cpp

示例3: clusterGaussReso

void clusterGaussReso() {

  TFile* file = new TFile("complete.root");

  TTree* tree = (TTree *)file->Get("Signal");

  int nEvents = tree->GetEntries();

  double addresses[121] = {};
  for (int k=0; k<121; k++){
    std::stringstream ss2;
    ss2 << k; 
    string str = "Crystal_"+ss2.str();
    const char* charstr = str.c_str(); 
    tree->SetBranchAddress(charstr, &addresses[k]);
  }

  TH1D* energyResoG = new TH1D("energyResoG", "Gauss_Energy_Resolution",
			      100, -10, 10);

  TH2D* posResoG = new TH2D("posResoG", "Gauss_Pos_Resolution", 
			    11, -5, 5, 11, -5, 5);

  double energyThresHi = 50.; //set energy threshold to start looking for bumps
  double energyThresLo = .5; //energy lower bound


  //Going through each scan of the calorimeter
  for (int k=0; k<nEvents; k++)
    {
      tree->GetEntry(k);

      pair<int, double> bump(0, 0.); 
      vector<pair<int, double> > geant;
      vector<pair<int, double> > hitMap;

      for(int i=0; i<121; i++)
	{
	  pair<int, double> hit(i, addresses[i]);
	  geant.push_back(hit);
	  if (addresses[i] > energyThresHi)
	    { hitMap.push_back(hit);}
	  if (hit.second>bump.second)
	    { bump = hit;}
	}

      gaussFit(bump, geant, energyResoG, posResoG);


    } //end of event

 TCanvas* canvas = new TCanvas("canvas", "canvas", 700,700);
 canvas->Divide(2, 1);
 TF1* g1d = new TF1("g1d", "gaus", -10, 10);
 TF2* g2d2 = new TF2("g2d2", Gaus2D, -10, 10, -10, 10, 6);
 g2d2->SetParameters(0., 0., 1., 1., 0., 100000);
 g2d2->FixParameter(4, 0.);
 energyResoG->Fit(g1d);
canvas->cd(1); energyResoG->Draw();
 posResoG->Fit(g2d2);
canvas->cd(2); posResoG->Draw("BOX");

}
开发者ID:cesarotti,项目名称:Dark-Photons,代码行数:63,代码来源:clusterGaussReso.C

示例4: Eloss

void Eloss()
{
TString dir = getenv("VMCWORKDIR");
TString fFileNamebase;
std::ifstream*  ElossData;
fFileNamebase = dir+"/macro/Simulation/data/109Pd_Eloss.txt";
ElossData = new std::ifstream(fFileNamebase.Data());
  if(ElossData->fail()){
    std::cout<<cRED<<" =  No file found! Please, check the path. Current :"<<fFileNamebase.Data()<<cNORMAL<<std::endl;

  }

  TCanvas *c1 = new TCanvas();
  c1->Draw();
  c1->Divide(1,2);

TH2D *Bragg = new TH2D("Bragg", "Bragg", 1000, 0,500, 1000, 0, 1);
TH2D *Interpolate = new TH2D("Interpolate","Interpolate", 1000, 0,200000, 100, 0, 1);

Double_t Eloss_elec, Eloss_nuc,SRIM_energy;
Double_t x = 0; //microns
Double_t x1 = 0;
Double_t x0 = 0;
Double_t Z = 46;
Double_t A = 109;
Double_t step = 1; //microns
Double_t energy = 190000; //keV
Double_t e1, e2, e3, dE1, dE2, dE3;
Double_t param0, param1, param2,param3,param4,param5,param6;
std::vector<std::tuple<Double_t,Double_t,Double_t>> SRIM_table;

std::cout<<cGREEN<<"Extracting data. Please wait...."<<cNORMAL<<std::endl;
while (!ElossData->eof()){   //Fill vector with datafile
  *ElossData>>SRIM_energy>>Eloss_elec>>Eloss_nuc; //keV >> keV/micron >> keV/micron
  SRIM_table.push_back(std::make_tuple(SRIM_energy, Eloss_elec, Eloss_nuc));
  Interpolate->Fill(SRIM_energy, Eloss_elec);
}//EndWhile

/*for (Int_t n = 0; n < SRIM_table.size(); n++){
    std::cout <<' '<< std::get<0> (SRIM_table.at(n))<<' '<<std::get<1> (SRIM_table.at(n))<<' '<<std::get<2> (SRIM_table.at(n))<<std::endl;

}//EndFor
*/

/*Int_t counter = SRIM_table.size()-3;
Double_t nuc_Loss, elec_Loss, total_Loss;
e1 = std::get<0> (SRIM_table.at(counter));
e2 = std::get<0> (SRIM_table.at(counter-1));
e3 = std::get<0> (SRIM_table.at(counter-2));
dE1 = std::get<1> (SRIM_table.at(counter));
dE2 = std::get<1> (SRIM_table.at(counter-1));
dE3 = std::get<1> (SRIM_table.at(counter-2));
Interpolate->Fill(e1, dE1);
Interpolate->Fill(e2, dE2);
Interpolate->Fill(e3, dE3);
Interpolate->Fit("enFit");
param0 = enFit->GetParameter(0);
param1 = enFit->GetParameter(1);

  while (energy>20){
    if(energy>std::get<0> (SRIM_table.at(counter))){
      elec_Loss = param0*energy+param1;
      x+=step;
      //nuc_Loss = (std::get<2> (SRIM_table.at(counter+1)))*step;
      //elec_Loss = (std::get<1> (SRIM_table.at(counter+1)))*step;
      total_Loss = elec_Loss; //+nuc_Loss;
      energy -= total_Loss;
      Bragg->Fill(x/1000, total_Loss*10);
      std::cout<<energy<<" "<<total_Loss<<" "<<x<<std::endl;
    }
    else{
      counter-=1;
      Interpolate->Reset();
      e1 = std::get<0> (SRIM_table.at(counter));
      e2 = std::get<0> (SRIM_table.at(counter-1));
      e3 = std::get<0> (SRIM_table.at(counter-2));
      dE1 = std::get<1> (SRIM_table.at(counter));
      dE2 = std::get<1> (SRIM_table.at(counter-1));
      dE3 = std::get<1> (SRIM_table.at(counter-2));
      Interpolate->Fill(e1, dE1);
      Interpolate->Fill(e2, dE2);
      Interpolate->Fill(e3, dE3);
      Interpolate->Fit("enFit");
      param0 = enFit->GetParameter(0);
      param1 = enFit->GetParameter(1);
    }
}//EndWhile
*/
TF1 *enFit = new TF1("enFit", "[0]+[1]*x+[2]*pow(x,2)+[3]*pow(x,3)+[4]*pow(x,4)+[5]*pow(x,5)+[6]*pow(x,6)", 0 , 200000);
enFit->SetParameters(1,1,1,1,1,1);
Interpolate->Fit("enFit");

param0 = enFit->GetParameter(0);
param1 = enFit->GetParameter(1);
param2 = enFit->GetParameter(2);
param3 = enFit->GetParameter(3);
param4 = enFit->GetParameter(4);
param5 = enFit->GetParameter(5);
param6 = enFit->GetParameter(6);

//.........这里部分代码省略.........
开发者ID:ATTPC,项目名称:ATTPCROOTv2,代码行数:101,代码来源:Eloss.C


注:本文中的TH2D::Fit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。