Esempio n. 1
0
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");

}
Esempio n. 2
0
// Sum of background and peak function
// peak uses par[0-2]
// background uses par[3-5]
Double_t totFit(Double_t *x, Double_t *par) {
	return gaussFit(x,par) + polFit(x,&par[3]);
}
Esempio n. 3
0
	void CreateDrawAndSaveHistogramWithFit(TH1* &histo, TString outputdir, TString outputname, bool saveoutput, bool close, bool autorange = true, double innerRange = 0.1 , double outerRange=1, bool excludeCenter=false, int fittype=2){

			/** @brief  saves Histogramm as *.root and *.png and if wanted closes the histograms at the end
			*	@details This mehtod create a histogramm and save it as root and png file. If you choose close, the canvas is closed after the histogram was saved
			*/

			setPandaStyle();

			TString name = TString(histo->GetName());
			TString title = TString(histo->GetTitle());

			TCanvas * canvas = new TCanvas("c_"+name, title, 0,0,1500,1000);


			histo->Draw();

			TF1 * fit;
			TF1 * fitinner;
			TF1 * fitouter;

			if(excludeCenter){
				fit = andi::doubleGaussFitExcludeCenter(histo, false, innerRange, outerRange);
			}
			else if (fittype==1){
				fit = gaussFit(histo, innerRange);
			}
			else if (fittype==2){
				fit = doubleGaussFit(histo, autorange, innerRange, outerRange);
				fitinner = getDoubleFit(histo, autorange, innerRange, outerRange, 1);
				fitouter = getDoubleFit(histo, autorange, innerRange, outerRange, 2);
			}
			else{
				std::cout << "Type of fit is not defined"<< std::endl;
			}
			fit->SetLineColor(kRed);
			fit->SetLineStyle(7);
			fit->SetLineWidth(3);
			fit->Draw("SAME");

			fitinner->SetLineColor(kBlue);
			fitinner->SetLineStyle(7);
			fitinner->SetLineWidth(3);
			fitinner->Draw("SAME");


			fitouter->SetLineColor(kBlack);
			fitouter->SetLineStyle(7);
			fitouter->SetLineWidth(3);
			fitouter->Draw("SAME");

			PandaSmartLabel("L");


			if (saveoutput){
				canvas->Print(outputdir + "root-files/" + outputname + ".root");
				canvas->Print(outputdir + "png-files/" + outputname + ".png");
				canvas->Print(outputdir + "pdf-files/" + outputname + ".pdf");
			}

			if (close) canvas->Close();


		}