#include #include #include #include "TH2.h" #include "TCanvas.h" #include "TProfile.h" #include "TF1.h" #include "TLegend.h" #include "g_defines.h" #include "DEDXFitCreator.h" Double_t dedxfunc(Double_t *x, Double_t *par) { Double_t dedx; //dedx=par[0] + par[1]/(x[0]*x[0]) + (par[2]/(x[0]*x[0]))*log(x[0]*x[0]); //3 parameters dedx=par[0] + par[1]/(x[0]) + (par[2]/(x[0]))*log(x[0]*x[0]); //this is a good one to get the high P raising branch //dedx=par[0] + par[1]/(x[0]*x[0]) + (par[2]/(x[0]*x[0]))*log(x[0]*x[0]); return dedx; } Double_t dedxfunc_e(Double_t *, Double_t *par) { Double_t dedx; dedx=par[0]; //+ par[1]*x[0]; return dedx; } void CreateFits(vector &vFits, map &FitMap) { short int Colors[]={kRed, kGreen, kBlue, kMagenta, kYellow, kCyan, kRed, kGreen, kBlue, kMagenta, kYellow, kCyan}; assert( sizeof(Colors)/sizeof(short int) >= PDGMap.size() ); map::const_iterator cit; int nColor=0; for(cit=PDGMap.begin(); cit!=PDGMap.end(); cit++) { if( cit->first ) { // the summary histogram cannot be fitted ostringstream HistoName; HistoName << cit->second; //the histograms are named like the Particles they show printf("Creating fits for HistoName: %s\n", HistoName.str().c_str()); TH2F *pCurHisto=(TH2F*)gDirectory->Get(HistoName.str().c_str()); if(!pCurHisto) { cout << "CreateFits: Skipping " << HistoName.str().c_str() << endl; continue; } cout << "CreateFits: Creatin Fits for " << HistoName.str().c_str() << endl; TProfile *pPro=pCurHisto->ProfileX("_pfx__", -1, -1, "b"); assert(pPro); TF1 *fitFcn=NULL; string FunktionName; /*if( abs(cit->first)!=11 )*/ { //________________________________________ //Create the fit function //1. and 2. parameter: range for the fit //last parameter is number of parmaeters in fit fuction FunktionName="dedxfunc"; FunktionName=FunktionName+HistoName.str(); fitFcn = new TF1(FunktionName.c_str(),dedxfunc,0.03,3,3); //1/x + log x => exclude zero //________________________________________ //Set some Options fitFcn->SetNpx(100); fitFcn->SetLineWidth(1); fitFcn->SetLineColor(Colors[nColor++]); //________________________________________ //do the fitting //last two parameters: Range where the fitting is done? //Int_t nResult=pPro->Fit(FunktionName.c_str(), "WLLNO", "", 0.02, 1); //this is for the x[0] range, can' t be zero Int_t nResult=pPro->Fit(FunktionName.c_str(), "WLLNOR"); //this is for the x[0] range, can' t be zero if( nResult == 0) { cout << "\nFit is okay!" << endl; } //W: i ignore the errors (perhaps it would work, too if i only ignore bins with one single entry, or make the bin size bigger //LL: loglikelihood //NO: i don' t want to draw this action here //R: use Ranges } assert(fitFcn); vFits.push_back(fitFcn); ostringstream FitFcnName; FitFcnName << cit->second; FitMap[FitFcnName.str().c_str()]=fitFcn; } } } void DrawSummary(vector &vFits) { if(PDGMap.find(0)==PDGMap.end()) { return; } //________________________________________ //Draw Summary in new Canvas ostringstream CanvasName; CanvasName << "Summary_Canvas"; ostringstream CanvasTitle; CanvasTitle << "dedx"; TCanvas *pCanvas = new TCanvas(CanvasName.str().c_str(), CanvasTitle.str().c_str() , 30,30,500,350); pCanvas->cd(1); //________________________________________ //Draw the Summary Histogram and all fits stored in vFits ostringstream HistoName; HistoName << "Summary"; TH2F *pCurHisto=(TH2F*)gDirectory->Get(HistoName.str().c_str()); //the Summary histogram is filled with all Particles if(pCurHisto) { pCurHisto->Draw(); vector::const_iterator citFitFcn; //vFits is filled with all fit-functions for(citFitFcn=vFits.begin(); citFitFcn!=vFits.end(); citFitFcn++) { (*citFitFcn)->Draw("SAME"); } } } void traceDrawing(map &FitMap) { //________________________________________ //Create a new Canvas, there is a histogram and a profile Subpad for every Particle ostringstream CanvasName; CanvasName << "trace_Canvas"; TCanvas *pCanvas=new TCanvas(CanvasName.str().c_str(), "dedx and profiles"); if(PDGMap.find(0)!=PDGMap.end() ) { pCanvas->Divide(2,PDGMap.size()-1); } else { pCanvas->Divide(2,PDGMap.size()); } int nSubpad_dedx=1; //left Pads int nSubpad_profile=2; //right Pads map::const_iterator cit; for(cit=PDGMap.begin(); cit!=PDGMap.end(); cit++) { if(cit->first) { //________________________________________ //Draw the Histogram in left pad pCanvas->cd(nSubpad_dedx); ostringstream HistoName; HistoName << cit->second; printf("HistoName: %s\n", HistoName.str().c_str()); TH2F *pCurHisto=(TH2F*)gDirectory->Get(HistoName.str().c_str()); if(!pCurHisto) { continue; } pCurHisto->Draw(); //________________________________________ //Check the fit associated with the current Histogram Name //and draw the corresponding fit function ostringstream FitFcnName; FitFcnName << cit->second; if( FitMap.find(FitFcnName.str().c_str() )!=FitMap.end() ) { assert(FitMap[FitFcnName.str().c_str()]); (FitMap[FitFcnName.str().c_str()])->Draw("SAME"); } else { printf( "Tried to draw non-existing Fit for %s\n", (cit->second).c_str() ); //continue; //i want to draw the histogram even if i have no fit } //________________________________________ //Draw the profile in the right pad pCanvas->cd(nSubpad_profile); TProfile *pPro=pCurHisto->ProfileX("_pfx", -1, -1, "b"); assert(pPro); pPro->Draw(); //________________________________________ // Draw the corresponding fit function again if( FitMap.find(FitFcnName.str().c_str() )!=FitMap.end() ) { assert(FitMap[FitFcnName.str().c_str()]); (FitMap[FitFcnName.str().c_str()])->Draw("SAME"); } nSubpad_dedx+=2; nSubpad_profile+=2; } } }