void KVCanvas::ProjectionX(TH2* hh) { TString pname = Form("%s_px", hh->GetName()); Int_t ip = 1; while (gROOT->FindObject(pname.Data())) { pname = Form("%s_px%d", hh->GetName(), ip); ip++; } TH1* px = hh->ProjectionX(pname.Data()); if (!px) return; Double_t minY = (hh->GetYaxis()->GetXmin()); Double_t maxY = (hh->GetYaxis()->GetXmax()); Double_t dY = (maxY - minY) * 0.8; Double_t maxH = px->GetBinContent(px->GetMaximumBin()); TGraph* gg = 0; if ((gg = (TGraph*)gROOT->FindObject(Form("%s_gjx", hh->GetName())))) gg->Delete(); gg = new TGraph; for (int i = 0; i < px->GetNbinsX(); i++) { gg->SetPoint(i, px->GetBinCenter(i), minY + px->GetBinContent(i)*dY / maxH); } gg->SetName(Form("%s_gjx", hh->GetName())); gg->SetTitle(Form("%s_gjx", hh->GetName())); gg->SetLineColor(kBlack); gg->SetMarkerColor(kBlack); gg->SetMarkerStyle(8); gg->Draw("PL"); Modified(); Update(); }
//=============================================================================== void Calibration(){ //=============================================================================== gStyle->SetOptTitle(0); //The root files with the individual plots const int numberoffiles = 4; const int numberofchambers = 6; TString filename[numberoffiles]; //mu- filename[0]="testcalo_mu-_50.root"; filename[1]="testcalo_mu-_100.root"; filename[2]="testcalo_mu-_150.root"; filename[3]="testcalo_mu-_200.root"; //Energy distributions we want to fit TString energy[numberofchambers]; //nosmear // energy[0] = "histo/6"; // energy[1] = "histo/7"; // energy[2] = "histo/8"; // energy[3] = "histo/9"; // energy[4] = "histo/10"; // energy[5] = "histo/11"; //smeared energy[0] = "histo/18"; energy[1] = "histo/19"; energy[2] = "histo/20"; energy[3] = "histo/21"; energy[4] = "histo/22"; energy[5] = "histo/23"; double mpshift = 0;//-0.22278298; TGraphErrors *grMPV[numberoffiles]; TString mpvname[numberoffiles]; TGraphErrors *grSigma[numberoffiles]; TString sigmaname[numberoffiles]; //For the mpv and sigma plot const Int_t nch = 6; char *chamb[nch] = {"Std1","Star","Mirror","Snake","Spider","Std2"}; std::vector<double> chambb; chambb.push_back(1.);chambb.push_back(2.);chambb.push_back(3.);chambb.push_back(4.);chambb.push_back(5.);chambb.push_back(6.); std::vector<double> mpv; std::vector<double> thesigma; std::vector<double> chamr; std::vector<double> mpvr; std::vector<double> thesigmaerr; //The TH2F to save the histos with mpv and sigma for the different energies TH2F * mpvhistos[numberoffiles]; TH2F * sigmahistos[numberoffiles]; //====================================================================================== //Canvas TCanvas *can[numberoffiles][numberofchambers]; TString canname; TCanvas *canmpv[numberoffiles]; //====================================================================================== //Read the files and histograms here TFile* files[numberoffiles]; for (int k=0; k<numberoffiles; k++){ files[k]= new TFile(filename[k]); } TH1F * histo[numberoffiles][numberofchambers]; for (int i=0; i<numberoffiles; i++){ gROOT->Reset(); mpvname[i] = "MPV_" + filename[i]; sigmaname[i] = "Sigma" + filename[i]; mpvhistos[i] = new TH2F(mpvname[i],mpvname[i],nch,0,nch,300,0.7,1.0); sigmahistos[i] = new TH2F(sigmaname[i],sigmaname[i],nch,0,nch,300,0.7,1.0); //mpvhistos[i]->SetStats(0); sigmahistos[i]->SetStats(0); for (int k=0; k<numberofchambers; k++){ histo[i][k]= (TH1F*) files[i]->Get(energy[k]); if (!histo[i][k]){std::cerr << "Could not get histogram " << energy[k] << "in file " << files[i]->GetName() << std::endl;} std::cout << "=========================================================================" << std::endl; std::cout << files[i]->GetName() << std::endl; canname = filename[i] + histo[i][k]->GetName(); can[i][k] = new TCanvas(canname, canname,800,600); can[i][k]->cd(); histo[i][k]->Draw(); TF1 *fit = 0; double mpc = 0; double minfit = 0.; double maxfit = 0.05; histo[i][k]->Fit("landau","R+","same",minfit,maxfit); fit = (TF1*) histo[i][k]->GetFunction("landau"); mpc = fit->GetParameter(1) - mpshift * fit->GetParameter(2); mpvhistos[i]->GetXaxis()->SetBinLabel( (k+1) , chamb[k]); sigmahistos[i]->GetXaxis()->SetBinLabel( (k+1) , chamb[k]); mpvhistos[i]->Fill(k , mpc * 1000. ); // mpvhistos[i]->SetBinError( (k+1) , fit->GetParError(1) ); sigmahistos[i]->Fill( k , fit->GetParameter(2) * 1000.); // sigmahistos[i]->SetBinError( (k+1) , fit->GetParError(2) ); mpv.push_back(mpc); mpvr.push_back(fit->GetParError(1)); chamr.push_back(0.); thesigma.push_back(fit->GetParameter(2)); thesigmaerr.push_back(fit->GetParError(2)); // if(i==0) {mpvname = "grMPV_50GeV"; sigmaname = "grSigma_50GeV";} // if(i==1) {mpvname = "grMPV_100GeV";sigmaname = "grSigma_100GeV";} // if(i==2) {mpvname = "grMPV_150GeV";sigmaname = "grSigma_150GeV";} // if(i==3) {mpvname = "grMPV_200GeV";sigmaname = "grSigma_200GeV";} std::cout << "Chamber " << k << " MPV "<< mpc << std::endl; can[i][k]->Print(canname + ".root",".root"); can[i][k]->Close(); }// end of loop over histos TCanvas *c1 = new TCanvas("c1","mpv",200,10,700,500); mpvhistos[i]->GetXaxis()->SetTitle("Chamber"); mpvhistos[i]->GetYaxis()->SetTitle("Landau MPV (MIPs) (keV) "); // mpvhistos[i]->GetXaxis()->SetTitleOffset(1.2); // mpvhistos[i]->GetYaxis()->SetTitleOffset(1.3); mpvhistos[i]->GetXaxis()->SetTitleSize(0.045); mpvhistos[i]->GetYaxis()->SetTitleSize(0.045); mpvhistos[i]->GetXaxis()->SetTitleFont(42); mpvhistos[i]->GetYaxis()->SetTitleFont(42); mpvhistos[i]->SetMarkerStyle(20); mpvhistos[i]->SetMarkerSize(1.2); mpvhistos[i]->SetLineColor(2); mpvhistos[i]->Draw(); c1->Update(); // TGraphErrors *gr = new TGraphErrors(mpv.size(),&chamb[0],&mpv[0],&mpvr[0],&chamr[0]); TGraph *gr = new TGraph(mpv.size(),&chambb[0],&mpv[0]); gr->Draw("CPS"); c1->Update(); c1->Print(mpvname[i]+".png",".png"); gr->Delete(); c1->Close(); // // c1->Print("mpv.png",".png"); // c1->Close(); thesigma.clear(); thesigmaerr.clear(); chamr.clear(); mpv.clear(); mpvr.clear(); // TCanvas *c1 = new TCanvas("c1","mpv",200,10,700,500); // TGraphErrors *gr = new TGraphErrors(mpv.size(),&chamb[0],&mpv[0],&mpvr[0],&chamr[0]); // gr->SetMarkerStyle(20); // gr->SetMarkerSize(1.0); // // gr->GetYaxis()->SetRangeUser(0.,100.); // //gr->GetXaxis()->SetRangeUser(0.,300.); // gr->SetTitle(mpvname[i]); // gr->GetHistogram()->SetXTitle(" Chamber "); // gr->GetHistogram()->SetYTitle(" Landau MPV (MIPs) "); // gr->GetYaxis()->SetTitleOffset(1.6); // TCanvas *c1 = new TCanvas("c1","mpv",200,10,700,500); // gr->Draw("APL"); // c1->Update(); // c1->Print(mpvname[i]+".png",".png"); // c1->Close(); // mpv.clear(); // mpvr.clear(); // TGraphErrors *grs = new TGraphErrors(thesigma.size(),&chamb[0],&thesigma[0],&thesigmaerr[0],&chamr[0]); // grs->SetMarkerStyle(20); // grs->SetMarkerSize(1.0); // // grs->GetYaxis()->SetRangeUser(0.,100.); // //grs->GetXaxis()->SetRangeUser(0.,300.); // grs->SetTitle(sigmaname[i]); // grs->GetHistogram()->SetXTitle(" Chamber "); // grs->GetHistogram()->SetYTitle(" Sigma "); // grs->GetYaxis()->SetTitleOffset(1.6); // TCanvas *c2 = new TCanvas("c2","sigma",200,10,700,500); // grs->Draw("APL"); // c2->Update(); // c2->Print(sigmaname[i]+".png",".png"); // c2->Close(); // thesigma.clear(); // thesigmaerr.clear(); // chamr.clear(); // gr->Delete(); // c1->Close(); // c1->Close(); }// end of loop over files // for (int i=0; i<numberoffiles; i++){ // // mpvhistos[i]->Draw(i==0?"":"same"); // mpvhistos[i]->GetXaxis()->SetTitle("Chamber"); // mpvhistos[i]->GetYaxis()->SetTitle("Landau MPV (MIPs) (keV) "); // // mpvhistos[i]->GetXaxis()->SetTitleOffset(1.2); // // mpvhistos[i]->GetYaxis()->SetTitleOffset(1.3); // mpvhistos[i]->GetXaxis()->SetTitleSize(0.045); // mpvhistos[i]->GetYaxis()->SetTitleSize(0.045); // mpvhistos[i]->GetXaxis()->SetTitleFont(42); // mpvhistos[i]->GetYaxis()->SetTitleFont(42); // mpvhistos[i]->SetMarkerStyle(20); // mpvhistos[i]->SetMarkerSize(1.2); // mpvhistos[i]->SetLineColor(2); // mpvhistos[i]->Draw(); // TGraph *gr = new TGraph(n,x,y); // c1->Update(); // c1->Print(mpvname[i]+".png",".png"); // gr->Delete(); // } // // c1->Print("mpv.png",".png"); // c1->Close(); }