// draw r distributiob void genPlots03(std::string fullPath, int nOverlay = 500) { const int fVerbose(0); setTDRStyle(); gStyle->SetOptStat(112211); gStyle->SetPalette(1); // Canvas c = new TCanvas("c3","c3",1000,600); const unsigned int nPadX = 1; const unsigned int nPadY = 1; c->Divide(nPadX,nPadY); const unsigned int nPads=nPadX*nPadY; for(unsigned int i=1; i<=nPads; i++) { TPad* pad= (TPad*)c->cd(i); pad->SetTopMargin(0.10); pad->SetRightMargin(0.20); pad->SetLeftMargin(0.15); pad->SetLogy(); } // Open file TFile *f = TFile::Open(fullPath.c_str()); if (f==0) { cout << "File " << fullPath << " not found -- exiting" << endl; return; } if(fVerbose>0) cout << "Succesfully opened file " << fullPath << endl; // Get TTree TTree* t = (TTree*) f->Get("events"); if(fVerbose>0) cout << "Got TTree with " << t->GetEntries() << " entries" << endl; // Do plots c->cd(1); //doPlot2d(t,"hrzL0vtx", "vrl0:TMath::Abs(vzl0)",30,0,300,30,0,120,"Tit","|z|","r","cm","cm"); std::string histoName = "hrL0vtxreco"; doPlot1d(t,histoName.c_str(), "vrl0",30,0,30,"#Lambda vertices","r","cm"); // draw radii { TH2F *h = (TH2F*)gDirectory->GetList()->FindObject(histoName.c_str()); double r; const double min = h->GetMinimum(); const double max = h->GetMaximum(); TLine *l; r = 4.4; l = new TLine(r,min,r,max); l->Draw(); r = 7.3; l = new TLine(r,min,r,max); l->Draw(); r = 10.2; l = new TLine(r,min,r,max); l->Draw(); r = 25.5; l = new TLine(r,min,r,max); l->Draw(); } }
//------------------------------------------------------------------------------ // DrawIt //------------------------------------------------------------------------------ void DrawIt(TString filename, TString hname, TString cname, TString title) { TFile* inputfile = TFile::Open("../AuxiliaryFilesWZXS8TeV/" + filename + ".root"); TH2F* h = (TH2F*)inputfile->Get(hname)->Clone(cname); h->SetDirectory(0); inputfile->Close(); TString name = h->GetName(); TCanvas* canvas = new TCanvas(name, name, 600, 600); if (name.Contains("PR")) canvas->SetLogx(); if (name.Contains("SF")) canvas->SetLogx(); canvas->SetLeftMargin (0.9 * canvas->GetLeftMargin()); canvas->SetRightMargin(3.5 * canvas->GetRightMargin()); canvas->SetTopMargin (1.2 * canvas->GetTopMargin()); TH2FAxisFonts(h, "x", "p_{T} [GeV]"); TH2FAxisFonts(h, "y", "#eta"); h->Draw("colz"); h->SetTitle(""); DrawTLatex(42, 0.940, 0.976, _bigLabelSize, 33, title); if (!title.Contains("trigger")) { Double_t hmin = h->GetMinimum(); Double_t hmax = h->GetMaximum(); for (Int_t i=1; i<=h->GetNbinsX(); i++) { for (Int_t j=1; j<=h->GetNbinsY(); j++) { Double_t value = h->GetBinContent(i,j); Double_t ypos = h->GetYaxis()->GetBinCenter(j); Double_t xpos = h->GetXaxis()->GetBinCenter(i); if (gPad->GetLogx()) xpos = h->GetXaxis()->GetBinCenterLog(i); TLatex* latex = new TLatex(xpos, ypos, Form("%.2f", value)); latex->SetTextAlign( 22); latex->SetTextFont ( 42); latex->SetTextSize (0.027); if (value < hmin + 0.3*(hmax - hmin)) latex->SetTextColor(kWhite); latex->Draw(); } } } // Set the palette font //---------------------------------------------------------------------------- canvas->Update(); TPaletteAxis* palette = (TPaletteAxis*)h->GetListOfFunctions()->FindObject("palette"); palette->SetLabelFont(42); // Save the plot //---------------------------------------------------------------------------- canvas->Update(); canvas->Modified(); canvas->GetFrame()->DrawClone(); canvas->SaveAs("pdf/scale_factors/" + name + ".pdf"); canvas->SaveAs("png/scale_factors/" + name + ".png"); }
int main(int argc, char **argv) { // This allows you to view ROOT-based graphics in your C++ program // If you don't want view graphics (eg just read/process/write data files), // this can be ignored TApplication theApp("App", &argc, argv); TCanvas* canvas = new TCanvas(); // *************************************** // not important for this exmple // Set a bunch of parameters to make the plot look nice canvas->SetFillColor(0); canvas->UseCurrentStyle(); canvas->SetBorderMode(0); // still leaves red frame bottom and right canvas->SetFrameBorderMode(0); // need this to turn off red hist frame! gROOT->SetStyle("Plain"); canvas->UseCurrentStyle(); gROOT->ForceStyle(); canvas->Divide(2, 1); gStyle->SetOptStat(0); gStyle->SetTitleBorderSize(0); gStyle->SetTitleSize(0.04); gStyle->SetTitleFont(42, "hxy"); // for histogram and axis titles gStyle->SetLabelFont(42, "xyz"); // for axis labels (values) gROOT->ForceStyle(); // *************************************** TFile *f=new TFile("fitInputs.root"); TH2F *hist1 = (TH2F*)f->Get("hdata"); TH2F *hback = (TH2F*)f->Get("hbkg"); double xmin = 0.0; double xmax = 6.0; double ymin = 0.0; double ymax=6.0; // Initialize minuit, set initial values etc. of parameters. const int npar = 6; // the number of parameters TMinuit minuit(npar); minuit.SetFCN(fcn); // the fcn to be minized // (eg calculates chi^2 or NLL, not the // parameterization of the data! TF2* myfunc = new TF2("myfunc", gausPdf, xmin, xmax, ymin, ymax, npar); // use this to fit the data and get results double par[npar]; // the start values double stepSize[npar]; // step sizes double minVal[npar]; // minimum bound on parameter double maxVal[npar]; // maximum bound on parameter TString parName[npar]; par[0] = hback->GetMaximum(); // guesses for starting the fit par[1] = hist1->GetMaximum(); par[2] = 3.555; //use mean and rms values from histogram par[3] = 1.17; //as initial guesses for parameters par[4] = 1.879; par[5] = 1.229; stepSize[0] = TMath::Abs(par[0]*0.1); stepSize[1] = TMath::Abs(par[1]*0.1); // step size MUST be positive! stepSize[2] = TMath::Abs(par[2]*0.1); stepSize[3] = TMath::Abs(par[3]*0.1); stepSize[4] = TMath::Abs(par[4]*0.1); stepSize[5] = TMath::Abs(par[5]*0.1); minVal[0] = 0; // if min and max values = 0, parameter is unbounded. maxVal[0] = 0; minVal[1] = 0; maxVal[1] = 0; minVal[2] = 0; maxVal[2] = 6; minVal[3] = 0; maxVal[3] = 6; minVal[4] = 0; maxVal[4] = 6; minVal[5] = 0; maxVal[5] = 6; parName[0] = "Bkg"; parName[1] = "A"; parName[2] = "x0"; parName[3] = "sigma_x"; parName[4] = "y0"; parName[5] = "sigma_y"; for (int i=0; i<npar; i++){ minuit.DefineParameter(i, parName[i].Data(), par[i], stepSize[i], minVal[i], maxVal[i]); } // here we define the pointers to pass information to Minuit's fcn // not pretty, but works well hdata=hist1; hback->Scale(1.0/3600.0); //scale over total number of entries first hb=hback; fparam=myfunc; // Do the minimization! minuit.Migrad(); // Minuit's best minimization algorithm double outpar[npar], err[npar]; for (int i=0; i<npar; i++){ minuit.GetParameter(i,outpar[i],err[i]); } TH2F *residual = new TH2F("residual", "Residuals Plot: data-fit", 50, 0, 6, 50, 0, 6); myfunc->SetParameters(outpar); for (int i=1; i<=hist1->GetNbinsX(); i++){ for(int j=1; j<=hist1->GetNbinsY(); j++){ double x = hist1->GetBinCenter(i); double y = hist1->GetBinCenter(j); double f= myfunc->Eval(x, y); double r = hist1->GetBinContent(i, j) -f; residual->Fill(x, y, r); } } canvas->cd(1); residual->GetXaxis()->SetTitle("x"); residual->GetYaxis()->SetTitle("y"); residual->GetXaxis()->CenterTitle(); residual->GetYaxis()->CenterTitle(); residual->GetXaxis()->SetTitleOffset(1.25); residual->GetYaxis()->SetTitleOffset(1.25); residual->Draw("colz"); canvas->cd(2); hist1->Add(hback, -outpar[0]); hist1->SetTitle("Data Signal with Fitted Background Subtracted"); hist1->GetXaxis()->SetTitle("x"); hist1->GetYaxis()->SetTitle("y"); hist1->GetZaxis()->SetTitle("signal value"); hist1->GetXaxis()->CenterTitle(); hist1->GetYaxis()->CenterTitle(); hist1->GetXaxis()->SetTitleOffset(1.25); hist1->GetYaxis()->SetTitleOffset(1.25); hist1->Draw("lego"); cout << "To exit, quit ROOT from the File menu of the plot (or use control-C)" << endl; theApp.Run(true); canvas->Close(); return 0; }
int main(int argc, char** argv){ ///================================================== ///==== Draw Distribution with and without scale ==== ///================================================== ///=============================================================================== gROOT->Reset(); gROOT->SetStyle("Plain"); gStyle->SetPalette(1); gStyle->SetOptStat(0); gStyle->SetOptFit(0); const Int_t __NRGBs = 5; const Int_t __NCont = 76; Double_t __stops[__NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 }; Double_t __red[__NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 }; Double_t __green[__NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 }; Double_t __blue[__NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 }; TColor::CreateGradientColorTable(__NRGBs, __stops, __red, __green, __blue, __NCont); gStyle->SetNumberContours(__NCont); ///=============================================================================== if(argc != 2) { std::cerr << ">>>>> analysis.cpp::usage: " << argv[0] << " configFileName" << std::endl ; return 1; } // Parse the config file parseConfigFile (argv[1]) ; std::string treeNameDATA = gConfigParser -> readStringOption("InputDATA::treeName"); std::string inputFileDATA = gConfigParser -> readStringOption("InputDATA::inputFile"); double luminosity = gConfigParser -> readDoubleOption("InputDATA::luminosity"); std::cout << ">>>>> InputDATA::treeName " << treeNameDATA << std::endl; std::cout << ">>>>> InputDATA::inputFile " << inputFileDATA << std::endl; std::cout << ">>>>> InputDATA::luminosity " << luminosity << std::endl; std::string treeNameMC = gConfigParser -> readStringOption("InputMC::treeName"); std::vector< std::string > inputFileMC = gConfigParser -> readStringListOption("InputMC::inputFile"); std::vector< std::string > inputSampleMC = gConfigParser -> readStringListOption("InputMC::nameSample"); std::vector< double > xSecAndEfficiency = gConfigParser -> readDoubleListOption("InputMC::xsecEff"); std::cout << ">>>>> InputMC::treeName " << treeNameMC << std::endl; std::cout << ">>>>> InputMC::inputFile size " << inputFileMC.size() << std::endl; if (inputFileMC.size() != xSecAndEfficiency.size() || inputFileMC.size() != inputSampleMC.size()) { std::cerr << " >>>> Error: different number of samples and cross sections" << std::endl; return 0; } int nMC = inputFileMC.size(); for (int iMC = 0; iMC < nMC; iMC++) { std::cout << ">>>>> InputMC::inputFile[" << iMC << "] = " << inputSampleMC.at(iMC) << " => " << inputFileMC.at(iMC) << " : " << xSecAndEfficiency.at(iMC) << " : " << luminosity * xSecAndEfficiency.at(iMC) << std::endl; } int binX = gConfigParser -> readIntOption("Options::binX"); double minX = gConfigParser -> readDoubleOption("Options::minX"); double maxX = gConfigParser -> readDoubleOption("Options::maxX"); std::string variableX = gConfigParser -> readStringOption("Options::variableX"); std::cout << ">>>>> Options::binX " << binX << std::endl; std::cout << ">>>>> Options::minX " << minX << std::endl; std::cout << ">>>>> Options::maxX " << maxX << std::endl; std::cout << ">>>>> Options::variableX " << variableX.c_str() << std::endl; int binY = gConfigParser -> readIntOption("Options::binY"); double minY = gConfigParser -> readDoubleOption("Options::minY"); double maxY = gConfigParser -> readDoubleOption("Options::maxY"); std::string variableY = gConfigParser -> readStringOption("Options::variableY"); std::cout << ">>>>> Options::binY " << binY << std::endl; std::cout << ">>>>> Options::minY " << minY << std::endl; std::cout << ">>>>> Options::maxY " << maxY << std::endl; std::cout << ">>>>> Options::variableY " << variableY.c_str() << std::endl; int binRatio = gConfigParser -> readIntOption("Options::binRatio"); double minRatio = gConfigParser -> readDoubleOption("Options::minRatio"); double maxRatio = gConfigParser -> readDoubleOption("Options::maxRatio"); std::cout << ">>>>> Options::minRatio " << minRatio << std::endl; std::cout << ">>>>> Options::maxRatio " << maxRatio << std::endl; std::string outputFile = gConfigParser -> readStringOption("Output::outputFile"); std::cout << ">>>>> Output::outputFile " << outputFile << std::endl; // TString AdditionalCut = Form("eta > 1.5");// || eta < -1.5)");// && eleFBrem<0.5"); TString AdditionalCut = Form("eta < -1.5");// || eta < -1.5)");// && eleFBrem<0.5"); // TString AdditionalCut = Form("(eta > 1.5 || eta < -1.5)");// && abs(eleFBrem)<1"); EColor vColor[100] = { kBlue,(EColor)(kBlue+1),(EColor) (kBlue+2), kRed,(EColor) (kRed+1),(EColor) (kRed+2), kGreen,(EColor) (kGreen+1),(EColor) (kGreen+2), kTeal,(EColor) (kTeal+1), kOrange,(EColor) (kOrange+1), kMagenta,(EColor) (kMagenta+1),(EColor) (kViolet),(EColor) (kYellow),(EColor) (kGray)}; ///==== DATA ==== TFile* fileInDATA = new TFile(inputFileDATA.c_str(),"READ"); ///==== W ==== TFile* fileInMC[nMC]; for (int iMC = 0; iMC < nMC; iMC++) { fileInMC[iMC] = new TFile(inputFileMC.at(iMC).c_str(),"READ"); } ///==== output ==== TFile* outFile = new TFile(outputFile.c_str(),"RECREATE"); outFile->cd(); ///==== Prepare input trees ==== TLegend* leg = new TLegend(0.55,0.7,0.95,0.95); leg->SetFillColor(0); TLegend* legDown = new TLegend(0.55,0.1,0.95,0.35); legDown->SetFillColor(0); TTree* MyTreeDATA = (TTree*) fileInDATA->Get(treeNameDATA.c_str()); int initialNumber; TH2F* HistoDATA = new TH2F("DATA","DATA",binX,minX,maxX,binY,minY,maxY); TH1F* HistoRatioDATA = new TH1F("RatioDATA","RatioDATA",binRatio,minRatio,maxRatio); TString DrawDATA = Form("%s:%s >> DATA",variableY.c_str(),variableX.c_str()); MyTreeDATA->Draw(DrawDATA.Data(),AdditionalCut.Data()); HistoDATA->SetMarkerSize(1); HistoDATA->SetMarkerStyle(20); HistoDATA->GetXaxis()->SetTitle(variableX.c_str()); HistoDATA->GetYaxis()->SetTitle(variableY.c_str()); leg->AddEntry(HistoDATA,HistoDATA->GetTitle(),"p"); legDown->AddEntry(HistoDATA,HistoDATA->GetTitle(),"p"); DrawDATA = Form("(%s) / (%s) >> RatioDATA",variableY.c_str(),variableX.c_str()); MyTreeDATA->Draw(DrawDATA.Data(),AdditionalCut.Data()); HistoRatioDATA->SetMarkerSize(1); HistoRatioDATA->SetMarkerStyle(20); HistoRatioDATA->GetXaxis()->SetTitle(Form("(%s)/(%s)",variableY.c_str(),variableX.c_str())); TH2F* HistoMC[nMC]; TH1F* HistoRatioMC[nMC]; TH2F* HistoMC_SUM = new TH2F("HistoMC_SUM","HistoMC_SUM",binX,minX,maxX,binY,minY,maxY); TH1F* HistoRatioMC_SUM = new TH1F("HistoRatioMC_SUM","HistoRatioMC_SUM",binRatio,minRatio,maxRatio); SetColorAndStyleHisto(*(HistoRatioMC_SUM),kBlue); TTree* MyTreeMC[nMC]; THStack* hsMC = new THStack("hsMC","hsMC"); double MC_Expected = 0; for (int iMC = 0; iMC < nMC; iMC++) { // for (int iMC = nMC-1; iMC >= 0; iMC--) { MyTreeMC[iMC] = (TTree*) fileInMC[iMC]->Get(treeNameMC.c_str()); MyTreeMC[iMC]->SetBranchAddress("initialNumber",&initialNumber); MyTreeMC[iMC]->GetEntry(0); xSecAndEfficiency.at(iMC) = xSecAndEfficiency.at(iMC) / initialNumber; ///==== normalize to initial number of events HistoMC[iMC] = new TH2F(inputSampleMC.at(iMC).c_str(),inputSampleMC.at(iMC).c_str(),binX,minX,maxX,binY,minY,maxY); HistoRatioMC[iMC] = new TH1F(Form("%s_Ratio",inputSampleMC.at(iMC).c_str()),Form("%s_Ratio",inputSampleMC.at(iMC).c_str()),binRatio,minRatio,maxRatio); TString Draw = Form("%s:%s >> %s",variableY.c_str(),variableX.c_str(),inputSampleMC.at(iMC).c_str()); MyTreeMC[iMC]->Draw(Draw.Data(),AdditionalCut.Data()); Draw = Form("(%s) / (%s) >> %s",variableY.c_str(),variableX.c_str(),Form("%s_Ratio",inputSampleMC.at(iMC).c_str())); MyTreeMC[iMC]->Draw(Draw.Data(),AdditionalCut.Data()); HistoRatioMC[iMC]->GetXaxis()->SetTitle(Form("(%s)/(%s)",variableY.c_str(),variableX.c_str())); std::cout << ">>>>>> " << inputSampleMC.at(iMC) << " : " << xSecAndEfficiency.at(iMC) << " : " << luminosity << " : " << HistoMC[iMC]->GetEntries() << " = " << luminosity * xSecAndEfficiency.at(iMC) * HistoMC[iMC]->GetEntries() << std::endl; std::cout << " >> " << Draw.Data() << std::endl; std::cout << " >> " << HistoMC[iMC]->GetEntries() << " Entries" << std::endl; MC_Expected += luminosity * xSecAndEfficiency.at(iMC) * HistoMC[iMC]->GetEntries(); HistoMC[iMC]->Scale(luminosity * xSecAndEfficiency.at(iMC)); // / HistoMC[iMC]->GetEntries()); HistoRatioMC[iMC]->Scale(luminosity * xSecAndEfficiency.at(iMC)); // / HistoMC[iMC]->GetEntries()); SetColorAndStyleHisto(*(HistoMC[iMC]),vColor[iMC]); SetColorAndStyleHisto(*(HistoRatioMC[iMC]),vColor[iMC]); HistoMC[iMC]->GetXaxis()->SetTitle(variableX.c_str()); HistoMC[iMC]->GetYaxis()->SetTitle(variableY.c_str()); HistoMC_SUM->Add(HistoMC[iMC]); HistoMC_SUM->GetXaxis()->SetTitle(variableX.c_str()); HistoMC_SUM->GetYaxis()->SetTitle(variableY.c_str()); HistoRatioMC_SUM->Add(HistoRatioMC[iMC]); HistoRatioMC_SUM->GetXaxis()->SetTitle(Form("(%s)/(%s)",variableY.c_str(),variableX.c_str())); hsMC->Add(HistoMC[iMC]); if (iMC == 0) hsMC->Add(HistoMC[iMC]); leg->AddEntry(HistoMC[iMC],HistoMC[iMC]->GetTitle(),"f"); legDown->AddEntry(HistoMC[iMC],HistoMC[iMC]->GetTitle(),"f"); } ///==== make fit ==== TH1D* htemp_prof = smartGausProfileXSQRTN(HistoDATA,2); TGraphErrors grH = buildGEfromH_Personalized(*htemp_prof); grH.SetMarkerStyle(22); grH.SetMarkerSize(0.7); grH.SetMarkerColor(kBlue); grH.SetFillColor(kBlue); grH.SetFillStyle(3335); grH.SetLineWidth(1); grH.SetLineColor(kBlue); grH.GetXaxis()->SetTitle(variableX.c_str()); grH.GetYaxis()->SetTitle(variableY.c_str()); ///---------------------- ///---- Plot results ---- ///---------------------- std::cerr << " MC expected : DATA = " << MC_Expected << " : " << HistoDATA->GetEntries() << std::endl; std::cerr << " HistoDATA->GetMaximum() = " << HistoDATA->GetMaximum() << std::endl; std::cerr << " HistoDATA->GetEntries() = " << HistoDATA->GetEntries() << std::endl; outFile->cd(); TCanvas cResultDistro("cResultDistro","cResultDistro",900,900); cResultDistro.Divide(2,2); cResultDistro.cd(1); HistoDATA->DrawClone("colz"); gPad->SetGrid(); TString tLumiName = Form("#int L = %.4f pb^{-1}",luminosity); TLatex tLumi(1.5 * HistoDATA->GetMean(1),0.2 * HistoDATA->GetMaximum(),tLumiName.Data()); tLumi.DrawClone(); cResultDistro.cd(2); HistoRatioMC_SUM->Draw(); HistoRatioDATA->Draw("E1same"); TString tEleName = Form("%d electrons",(int) HistoDATA->GetEntries()); TLatex tEle(2.0 * HistoRatioDATA->GetMean(1),0.3 * HistoRatioDATA->GetMaximum(),tEleName.Data()); tEle.DrawClone(); gPad->SetGrid(); cResultDistro.cd(3); grH.Draw("APL"); double minFit = gConfigParser -> readDoubleOption("Options::minFit"); double maxFit = gConfigParser -> readDoubleOption("Options::maxFit"); std::cout << ">>>>> Options::minFit " << minFit << std::endl; std::cout << ">>>>> Options::maxFit " << maxFit << std::endl; TF1* funz = new TF1 ("funz","pol1",minFit,maxFit); // funz->FixParameter(0,0); funz->SetParameter(0,0); funz->SetParameter(1,1); grH.Fit("funz","RMQ"); std::cerr << " Y = [0] + [1] * X " << std::endl; std::cerr << " [0] = " << funz->GetParameter(0) << " +/- " << funz->GetParError(0) << std::endl; std::cerr << " [1] = " << funz->GetParameter(1) << " +/- " << funz->GetParError(1) << std::endl; double coeffDATA = funz->GetParameter(1); double errCoeffDATA = funz->GetParError(1); gPad->SetGrid(); cResultDistro.cd(4); HistoRatioMC_SUM->Draw(); HistoRatioDATA->Draw("E1same"); tEle.DrawClone(); gPad->SetGrid(); gPad->SetLogy(); TString nameImage = Form("%s_%s_%d.png",variableY.c_str(),variableX.c_str(),1); cResultDistro.SaveAs(nameImage.Data()); TString nameImageRoot = Form("%s_%s_%d.root",variableY.c_str(),variableX.c_str(),1); cResultDistro.SaveAs(nameImageRoot.Data()); TCanvas cResultDistroMC("cResultDistroMC","cResultDistroMC",800,800); cResultDistroMC.Divide(2,2); // cResultDistroMC.Divide(2,nMC); // for (int iMC = 0; iMC < nMC; iMC++) { // cResultDistroMC.cd(2*iMC+1); // HistoMC[iMC]->DrawClone("colz"); // HistoDATA->DrawClone("BOXsame"); // cResultDistroMC.cd(2*iMC+2); // HistoRatioMC[iMC]->DrawNormalized(""); // HistoRatioDATA->DrawNormalized("E1same"); // } cResultDistroMC.cd(1); HistoMC_SUM->DrawClone("colz"); HistoDATA->DrawClone("BOXsame"); gPad->SetGrid(); ///==== make fit ==== cResultDistroMC.cd(3); TH1D* MChtemp_prof = smartGausProfileXSQRTN(HistoMC_SUM,2); TGraphErrors MCgrH = buildGEfromH_Personalized(*MChtemp_prof); MCgrH.SetMarkerStyle(22); MCgrH.SetMarkerSize(0.7); MCgrH.SetMarkerColor(kRed); MCgrH.SetFillColor(kRed); MCgrH.SetFillStyle(3335); MCgrH.SetLineWidth(1); MCgrH.SetLineColor(kRed); MCgrH.GetXaxis()->SetTitle(variableX.c_str()); MCgrH.GetYaxis()->SetTitle(variableY.c_str()); funz->SetParameter(0,0); funz->SetParameter(1,1); MCgrH.Fit("funz","RMQ"); std::cerr << " ================= " << std::endl; std::cerr << " ======= MC ====== " << std::endl; std::cerr << " Y = [0] + [1] * X " << std::endl; std::cerr << " [0] = " << funz->GetParameter(0) << " +/- " << funz->GetParError(0) << std::endl; std::cerr << " [1] = " << funz->GetParameter(1) << " +/- " << funz->GetParError(1) << std::endl; double coeffMC = funz->GetParameter(1); double errCoeffMC = funz->GetParError(1); MCgrH.Draw("APL"); gPad->SetGrid(); cResultDistroMC.cd(4); MCgrH.Draw("APL"); grH.Draw("PLSAME"); gPad->SetGrid(); TString nameImageLog = Form("%s_%s_%d_MC.png",variableY.c_str(),variableX.c_str(),1); cResultDistroMC.SaveAs(nameImageLog.Data()); std::cerr << " 1 - alpha = " << coeffDATA / coeffMC << " +/- " << sqrt( (errCoeffDATA/coeffMC)*(errCoeffDATA/coeffMC) + (errCoeffMC*coeffDATA/coeffMC/coeffMC)*(errCoeffMC*coeffDATA/coeffMC/coeffMC) ) << std::endl; std::cerr << " alpha = " << 1-coeffDATA / coeffMC << " +/- " << sqrt( (errCoeffDATA/coeffMC)*(errCoeffDATA/coeffMC) + (errCoeffMC*coeffDATA/coeffMC/coeffMC)*(errCoeffMC*coeffDATA/coeffMC/coeffMC) ) << std::endl; // TCanvas cResultDistro_1("cResultDistro_1","cResultDistro_1",800,800); // HistoRatioMC_SUM->Draw(); // HistoRatioDATA->Draw("E1same"); // tEle.DrawClone(); // gPad->SetGrid(); // gPad->SetLogy(); }
void rulevisHists( TDirectory *rfdir, TDirectory *vardir, TDirectory *corrdir, TMVAGlob::TypeOfPlot type) { // if (rfdir==0) return; if (vardir==0) return; if (corrdir==0) return; // const TString rfName = rfdir->GetName(); const TString maintitle = rfName + " : Rule Importance"; const TString rfNameOpt = "_RF2D_"; const TString outfname[TMVAGlob::kNumOfMethods] = { "rulevisHists", "rulevisHists_decorr", "rulevisCorr_pca", "rulevisCorr_gaussdecorr" }; const TString outputName = outfname[type]+"_"+rfdir->GetName(); // TIter rfnext(rfdir->GetListOfKeys()); TKey *rfkey; Double_t rfmax; Double_t rfmin; Bool_t allEmpty=kTRUE; Bool_t first=kTRUE; while ((rfkey = (TKey*)rfnext())) { // make sure, that we only look at histograms TClass *cl = gROOT->GetClass(rfkey->GetClassName()); if (!cl->InheritsFrom("TH2F")) continue; TH2F *hrf = (TH2F*)rfkey->ReadObj(); TString hname= hrf->GetName(); if (hname.Contains("__RF_")){ // found a new RF plot Double_t valmin = hrf->GetMinimum(); Double_t valmax = hrf->GetMaximum(); if (first) { rfmin=valmin; rfmax=valmax; first = kFALSE; } else { if (valmax>rfmax) rfmax=valmax; if (valmin<rfmin) rfmin=valmin; } if (hrf->GetEntries()>0) allEmpty=kFALSE; } } if (first) { cout << "ERROR: no RF plots found..." << endl; return; } const Int_t nContours = 100; Double_t contourLevels[nContours]; Double_t dcl = (rfmax-rfmin)/Double_t(nContours-1); // for (Int_t i=0; i<nContours; i++) { contourLevels[i] = rfmin+dcl*Double_t(i); } /////////////////////////// vardir->cd(); // how many plots are in the directory? Int_t noPlots = ((vardir->GetListOfKeys())->GetEntries()) / 2; // define Canvas layout here! // default setting Int_t xPad; // no of plots in x Int_t yPad; // no of plots in y Int_t width; // size of canvas Int_t height; switch (noPlots) { case 1: xPad = 1; yPad = 1; width = 500; height = 0.7*width; break; case 2: xPad = 2; yPad = 1; width = 600; height = 0.7*width; break; case 3: xPad = 3; yPad = 1; width = 900; height = 0.4*width; break; case 4: xPad = 2; yPad = 2; width = 600; height = width; break; default: xPad = 3; yPad = 2; width = 800; height = 0.7*width; break; } Int_t noPad = xPad * yPad ; // this defines how many canvases we need const Int_t noCanvas = 1 + (Int_t)((noPlots - 0.001)/noPad); TCanvas **c = new TCanvas*[noCanvas]; for (Int_t ic=0; ic<noCanvas; ic++) c[ic] = 0; // counter variables Int_t countCanvas = 0; Int_t countPad = 1; // loop over all objects in directory TIter next(vardir->GetListOfKeys()); TKey *key; TH1F *sigCpy=0; TH1F *bgdCpy=0; // Bool_t first = kTRUE; while ((key = (TKey*)next())) { // make sure, that we only look at histograms TClass *cl = gROOT->GetClass(key->GetClassName()); if (!cl->InheritsFrom("TH1")) continue; sig = (TH1F*)key->ReadObj(); TString hname= sig->GetName(); // check for all signal histograms if (hname.Contains("__S")){ // found a new signal plot // sigCpy = new TH1F(*sig); // create new canvas if ((c[countCanvas]==NULL) || (countPad>noPad)) { char cn[20]; sprintf( cn, "rulehist%d_", countCanvas+1 ); TString cname(cn); cname += rfdir->GetName(); c[countCanvas] = new TCanvas( cname, maintitle, countCanvas*50+200, countCanvas*20, width, height ); // style c[countCanvas]->Divide(xPad,yPad); countPad = 1; } // save canvas to file TPad *cPad = (TPad *)(c[countCanvas]->GetPad(countPad)); c[countCanvas]->cd(countPad); countPad++; // find the corredponding background histo TString bgname = hname; bgname.ReplaceAll("__S","__B"); hkey = vardir->GetKey(bgname); bgd = (TH1F*)hkey->ReadObj(); if (bgd == NULL) { cout << "ERROR!!! couldn't find backgroung histo for" << hname << endl; exit; } TString rfname = hname; rfname.ReplaceAll("__S","__RF"); TKey *hrfkey = rfdir->GetKey(rfname); TH2F *hrf = (TH2F*)hrfkey->ReadObj(); Double_t wv = hrf->GetMaximum(); // if (rfmax>0.0) // hrf->Scale(1.0/rfmax); hrf->SetMinimum(rfmin); // make sure it's zero -> for palette axis hrf->SetMaximum(rfmax); // make sure max is 1.0 -> idem hrf->SetContour(nContours,&contourLevels[0]); // this is set but not stored during plot creation in MVA_Factory // TMVAGlob::SetSignalAndBackgroundStyle( sigK, bgd ); sig->SetFillStyle(3002); sig->SetFillColor(1); sig->SetLineColor(1); sig->SetLineWidth(2); bgd->SetFillStyle(3554); bgd->SetFillColor(1); bgd->SetLineColor(1); bgd->SetLineWidth(2); // chop off "signal" TString title(hrf->GetTitle()); title.ReplaceAll("signal",""); // finally plot and overlay Float_t sc = 1.1; if (countPad==2) sc = 1.3; sig->SetMaximum( TMath::Max( sig->GetMaximum(), bgd->GetMaximum() )*sc ); Double_t smax = sig->GetMaximum(); if (first) { hrf->SetTitle( maintitle ); first = kFALSE; } else { hrf->SetTitle( "" ); } hrf->Draw("colz ah"); TMVAGlob::SetFrameStyle( hrf, 1.2 ); sig->Draw("same ah"); bgd->Draw("same ah"); // draw axis using range [0,smax] hrf->GetXaxis()->SetTitle( title ); hrf->GetYaxis()->SetTitleOffset( 1.30 ); hrf->GetYaxis()->SetTitle("Events"); hrf->GetYaxis()->SetLimits(0,smax); hrf->Draw("same axis"); cPad->SetRightMargin(0.13); cPad->Update(); // Draw legend if (countPad==2){ TLegend *legend= new TLegend( cPad->GetLeftMargin(), 1-cPad->GetTopMargin()-.18, cPad->GetLeftMargin()+.4, 1-cPad->GetTopMargin() ); legend->AddEntry(sig,"Signal","F"); legend->AddEntry(bgd,"Background","F"); legend->Draw("same"); legend->SetBorderSize(1); legend->SetMargin( 0.3 ); legend->SetFillColor(19); legend->SetFillStyle(1); } // save canvas to file if (countPad > noPad) { c[countCanvas]->Update(); TString fname = Form( "plots/%s_c%i", outputName.Data(), countCanvas+1 ); TMVAGlob::imgconv( c[countCanvas], fname ); // TMVAGlob::plot_logo(); // don't understand why this doesn't work ... :-( countCanvas++; } } } if (countPad <= noPad) { c[countCanvas]->Update(); TString fname = Form( "plots/%s_c%i", outputName.Data(), countCanvas+1 ); TMVAGlob::imgconv( c[countCanvas], fname ); } }
void checkRsnPIDqa(TString filename, TString foldername, Bool_t savePng, TString plotTPCpi, TString plotTPCka, TString plotTPCpro, TString plotTTOFpi, TString plotTOFka, TString plotTOFpro) { //Open input file TFile * fin = TFile::Open(filename.Data()); if (!fin) return 0x0; //Access output of specific wagon TList * list = (TList*) fin->Get(foldername.Data()); if (!list) return 0x0; //Set range for fit Float_t RangeFitMomMin = 0.1; //range in momentum where to check the mean and pull Float_t RangeFitMomMax = 2.0; Int_t xbinFitMin = 0; Int_t xbinFitMax = -1; Float_t RangeFitNsigmaPIDmin = -2.0; //range in Nsigma where the fit is to be performed Float_t RangeFitNsigmaPIDmax = 2.0; //Set range for visualisation Float_t RangeShowTPC[2] = {0.1, 2.0}; Float_t RangeShowTOF[2] = {0.25, 2.0}; //-------------------------- // TPC PID Nsigma // fit with simple gaussian //-------------------------- //Gaussian function TF1 *fGaus = new TF1("f","gaus", -7.0, 7.0); //--- pions TH2F * hTPCsigmaPi = (TH2F*)list->FindObject(plotTPCpi.Data()); hTPCsigmaPi->RebinX(2); hTPCsigmaPi->SetTitle("TPC Pions"); MakeUpHisto(hTPCsigmaPi,"p_{TPC} (GeV/c)", "N#sigma_{TPC}", 1, kBlack, 2); hTPCsigmaPi->GetYaxis()->SetRangeUser(-5.1,5.1); hTPCsigmaPi->GetXaxis()->SetRangeUser(RangeShowTPC[0], RangeShowTPC[1]); xbinFitMin = hTPCsigmaPi->GetXaxis()->FindBin(RangeFitMomMin); xbinFitMax = hTPCsigmaPi->GetXaxis()->FindBin(RangeFitMomMax); hTPCsigmaPi->FitSlicesY(fGaus, xbinFitMin, xbinFitMax ); TH1D * hTPCsigmaPi_mean = ((TH1D*)gDirectory->FindObject(Form("%s_1", plotTPCpi.Data())))->Clone("hNsigmaTPCpi_mean"); TH1D * hTPCsigmaPi_pull = ((TH1D*)gDirectory->FindObject(Form("%s_2", plotTPCpi.Data())))->Clone("hNsigmaTPCpi_pull"); MakeUpHisto(hTPCsigmaPi_mean, "", "", 1, kBlack, 2); MakeUpHisto(hTPCsigmaPi_pull, "", "", 1, kRed+2, 2); //--- kaons TH2F * hTPCsigmaKa = (TH2F*)list->FindObject(plotTPCka.Data()); hTPCsigmaKa->RebinX(2); hTPCsigmaKa->SetTitle("TPC Kaons"); hTPCsigmaKa->GetYaxis()->SetRangeUser(-5.1,5.1); hTPCsigmaKa->GetXaxis()->SetRangeUser(RangeShowTPC[0], RangeShowTPC[1]); hTPCsigmaKa->FitSlicesY(fGaus, xbinFitMin, xbinFitMax ); MakeUpHisto(hTPCsigmaKa,"p_{TPC} (GeV/c)", "N#sigma_{TPC}", 1, kBlack, 2); TH1D * hTPCsigmaKa_mean = ((TH1D*)gDirectory->FindObject(Form("%s_1", plotTPCka.Data())))->Clone("hNsigmaTPCka_mean"); TH1D * hTPCsigmaKa_pull = ((TH1D*)gDirectory->FindObject(Form("%s_2", plotTPCka.Data())))->Clone("hNsigmaTPCka_pull"); MakeUpHisto(hTPCsigmaKa_mean, "", "", 1, kBlack, 2); MakeUpHisto(hTPCsigmaKa_pull, "", "", 1, kRed+2, 2); //--- protons TH2F * hTPCsigmaPro = (TH2F*)list->FindObject(plotTPCpro.Data()); hTPCsigmaPro->RebinX(2); hTPCsigmaPro->SetTitle("TPC Protons"); MakeUpHisto(hTPCsigmaPro,"p_{TPC} (GeV/c)", "N#sigma_{TPC}", 1, kBlack, 2); hTPCsigmaPro->GetYaxis()->SetRangeUser(-5.1,5.1); hTPCsigmaPro->GetXaxis()->SetRangeUser(RangeShowTPC[0], RangeShowTPC[1]); hTPCsigmaPro->FitSlicesY(fGaus, xbinFitMin, xbinFitMax ); TH1D * hTPCsigmaPro_mean = ((TH1D*)gDirectory->FindObject(Form("%s_1", plotTPCpro.Data())))->Clone("hNsigmaTPCpro_mean"); TH1D * hTPCsigmaPro_pull = ((TH1D*)gDirectory->FindObject(Form("%s_2", plotTPCpro.Data())))->Clone("hNsigmaTPCpro_pull"); MakeUpHisto(hTPCsigmaPro_mean, "", "", 1, kBlack, 2); MakeUpHisto(hTPCsigmaPro_pull, "", "", 1, kRed+2, 2); //--- plot TPC TLine *l11=new TLine(RangeShowTPC[0],0.,RangeShowTPC[1],0.); l11->SetLineWidth(1); l11->SetLineStyle(7); TLine *l12=new TLine(RangeShowTPC[0],1.,RangeShowTPC[1],1.); l12->SetLineWidth(1); l12->SetLineStyle(7); gStyle->SetOptStat(0); TCanvas *cPidPerformance4 = new TCanvas("cPIDperformance4","TPC PID",1200,500); cPidPerformance4->Divide(3,1); cPidPerformance4->cd(1); gPad->SetLogz(); gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy(); hTPCsigmaPi->DrawCopy("colz"); hTPCsigmaPi_mean->DrawCopy("same"); hTPCsigmaPi_pull->DrawCopy("same"); l11->Draw("same"); l12->Draw("same"); cPidPerformance4->cd(2); gPad->SetLogz(); gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy(); hTPCsigmaKa->DrawCopy("colz"); hTPCsigmaKa_mean->DrawCopy("same"); hTPCsigmaKa_pull->DrawCopy("same"); l11->Draw("same"); l12->Draw("same"); cPidPerformance4->cd(3); gPad->SetLogz(); gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy(); hTPCsigmaPro->DrawCopy("colz"); hTPCsigmaPro_mean->DrawCopy("same"); hTPCsigmaPro_pull->DrawCopy("same"); l11->Draw("same"); l12->Draw("same"); TLegend * pidLegTPC = new TLegend(0.15,0.8,0.88,0.88); pidLegTPC->SetBorderSize(0); pidLegTPC->SetFillStyle(1001); pidLegTPC->SetFillColor(kWhite); pidLegTPC->SetTextSize(0.04); pidLegTPC->SetNColumns(2); pidLegTPC->AddEntry(hTPCsigmaPro_mean,"Mean","lp"); pidLegTPC->AddEntry(hTPCsigmaPro_pull,Form("#sigma, Gaus fit (%2.1f,%2.1f)",RangeFitNsigmaPIDmin,RangeFitNsigmaPIDmax),"lp"); pidLegTPC->Draw("same"); if (savePng) cPidPerformance4->SaveAs("RsnQA_TPC_Nsigma.png"); //---------------------------------------------------- // TOF // fit with signal model = gaussian + exponential tail //---------------------------------------------------- //Signal model for TOF signal = gaus + exp tail const Int_t npars = 6; TF1 *fSignalModel = new TF1("fSignalModel", TOFsignal, -7.0, 7.0, npars); fSignalModel->SetTitle("TOF Signal"); fSignalModel->SetParameter(0, 1.); fSignalModel->SetParameter(1, 0.); fSignalModel->SetParLimits(1, -2., 1.); fSignalModel->SetParameter(2, 1.); fSignalModel->SetParLimits(2, 0.5, 2.); fSignalModel->SetParameter(3, 1.); fSignalModel->SetParLimits(3, 0.5, 1.5); fSignalModel->SetParameter(4, 1.); fSignalModel->SetParLimits(4, 0., 1.e8); fSignalModel->SetParameter(5, 0.); fSignalModel->SetParLimits(5, -10., 10.); fSignalModel->SetNpx(2000); fSignalModel->SetParNames("Norm", "Mean", "Sigma", "Tail", "Shift", "Slope"/*, "Square"*/); fSignalModel->SetLineColor(kRed+1); //results TObjArray *results[3]; for(Int_t i = 0; i < 3; i++){ results[i] = new TObjArray(10); } TH1D * par[3][npars]; //--- pions TH2F * hTOFsigmaPi = (TH2F*)list->FindObject(plotTOFpi.Data()); hTOFsigmaPi->SetTitle("TOF Pions"); hTOFsigmaPi->RebinX(2); MakeUpHisto(hTOFsigmaPi,"p (GeV/c)", "N#sigma_{TOF}", 1, kBlack, 2); hTOFsigmaPi->GetYaxis()->SetRangeUser(-5.1,5.1); hTOFsigmaPi->GetXaxis()->SetRangeUser(RangeShowTOF[0], RangeShowTOF[1]); fSignalModel->SetParLimits(4, 0., hTOFsigmaPi->GetMaximum()*0.5); fSignalModel->SetParLimits(0, 0., hTOFsigmaPi->GetMaximum()*1.2); hTOFsigmaPi->FitSlicesY(fSignalModel, xbinFitMin, xbinFitMax, 0, "QR", results[0] ); for(Int_t cc = 0; cc < npars ; cc++) { par[0][cc] = (TH1D*)gDirectory->FindObject(Form("%s_%i", plotTOFpi.Data(), cc)); } MakeUpHisto(par[0][1], "", "", 1, kBlue, 2); MakeUpHisto(par[0][2], "", "", 1, kMagenta+2, 2); //--- KAONS TH2F * hTOFsigmaKa = (TH2F*)list->FindObject(plotTOFka.Data()); hTOFsigmaKa->SetTitle("TOF Kaons"); hTOFsigmaKa->RebinX(2); MakeUpHisto(hTOFsigmaKa,"p (GeV/c)", "N#sigma_{TOF}", 1, kBlack, 2); hTOFsigmaKa->GetYaxis()->SetRangeUser(-5.1,5.1); hTOFsigmaKa->GetXaxis()->SetRangeUser(RangeShowTOF[0], RangeShowTOF[1]); fSignalModel->SetParLimits(4, 0., hTOFsigmaKa->GetMaximum()*0.5); fSignalModel->SetParLimits(0, 0., hTOFsigmaKa->GetMaximum()*1.2); hTOFsigmaKa->FitSlicesY(fSignalModel, xbinFitMin, xbinFitMax, 0, "QR", results[0] ); for(Int_t cc = 0; cc < npars ; cc++) { par[1][cc] = (TH1D*)gDirectory->FindObject(Form("%s_%i", plotTOFka.Data(), cc)); } MakeUpHisto(par[1][1], "", "", 1, kBlue, 2); MakeUpHisto(par[1][2], "", "", 1, kMagenta+2, 2); //--- protons TH2F * hTOFsigmaPro = (TH2F*)list->FindObject(plotTOFpro.Data()); hTOFsigmaPro->SetTitle("TOF Protons"); hTOFsigmaPro->RebinX(2); MakeUpHisto(hTOFsigmaPro,"p (GeV/c)", "N#sigma_{TOF}", 1, kBlack, 2); hTOFsigmaPro->GetYaxis()->SetRangeUser(-5.1,5.1); hTOFsigmaPro->GetXaxis()->SetRangeUser(RangeShowTOF[0], RangeShowTOF[1]); fSignalModel->SetParLimits(4, 0., hTOFsigmaPro->GetMaximum()*0.5); fSignalModel->SetParLimits(0, 0., hTOFsigmaPro->GetMaximum()*1.2); hTOFsigmaPro->FitSlicesY(fSignalModel, xbinFitMin, xbinFitMax, 0, "QR", results[0] ); for(Int_t cc = 0; cc < npars ; cc++) { par[2][cc] = (TH1D*)gDirectory->FindObject(Form("%s_%i", plotTOFpro.Data(), cc)); } MakeUpHisto(par[2][1], "", "", 1, kBlue, 2); MakeUpHisto(par[2][2], "", "", 1, kMagenta+2, 2); //--- plot TOF gStyle->SetOptStat(0); TCanvas *cPidPerformance3 = new TCanvas("cPidPerformance3","TOF PID performance",1200,500); cPidPerformance3->Divide(3,1); cPidPerformance3->cd(1); gPad->SetLogz(); gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy(); hTOFsigmaPi->DrawCopy("colz"); if(par[0][1]) par[0][1]->DrawCopy("same"); if(par[0][2]) par[0][2]->DrawCopy("same"); l11->Draw("same"); l12->Draw("same"); cPidPerformance3->cd(2); gPad->SetLogz(); gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy(); hTOFsigmaKa->DrawCopy("colz"); if(par[1][1]) par[1][1]->DrawCopy("same"); if(par[1][2]) par[1][2]->DrawCopy("same"); l11->Draw("same"); l12->Draw("same"); cPidPerformance3->cd(3); gPad->SetLogz(); gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy(); hTOFsigmaPro->DrawCopy("colz"); if(par[2][1]) par[2][1]->DrawCopy("same"); if(par[2][2]) par[2][2]->DrawCopy("same"); l11->Draw("same"); l12->Draw("same"); TLegend * pidLegTOF = new TLegend(0.15,0.8,0.88,0.88); pidLegTOF->SetBorderSize(0); pidLegTOF->SetFillStyle(1001); pidLegTOF->SetFillColor(kWhite); pidLegTOF->SetTextSize(0.04); pidLegTOF->SetNColumns(2); pidLegTOF->AddEntry(par[0][1],"Mean","lp"); pidLegTOF->AddEntry(par[0][2], Form("#sigma, Gaus+Tail fit (%2.1f,%2.1f)",RangeFitNsigmaPIDmin, RangeFitNsigmaPIDmax),"lp"); pidLegTOF->Draw("same"); if (savePng) cPidPerformance3->Print("RsnQA_TOF_Nsigma.png"); return; }
void DoEvolutions( const TString &sim, Int_t time, Int_t Nbins=1, const TString &options="") { #ifdef __CINT__ gSystem->Load("libptools.so"); #endif PGlobals::Initialize(); // Palettes! gROOT->Macro("PPalettes.C"); TString opt = options; // cout << "options = " << opt << endl; // Load PData PData *pData = PData::Get(sim.Data()); pData->LoadFileNames(time); if(!pData->IsInit()) return; Bool_t CYL = kFALSE; if(sim.Contains("cyl")) { CYL = kTRUE; opt += "cyl"; } Bool_t ThreeD = kFALSE; if(sim.Contains("3D")) ThreeD = kTRUE; // Some plasma constants Double_t n0 = pData->GetPlasmaDensity(); Double_t kp = pData->GetPlasmaK(); Double_t skindepth = 1.0; if(kp!=0.0) skindepth = 1/kp; Double_t E0 = pData->GetPlasmaE0(); // Some initial beam properties: Float_t Ebeam = pData->GetBeamEnergy() * PUnits::MeV; Float_t gamma = pData->GetBeamGamma(); Float_t vbeam = pData->GetBeamVelocity(); Double_t rms0 = pData->GetBeamRmsY() * kp; if(CYL) rms0 = pData->GetBeamRmsR() * kp; // Time in OU Float_t Time = pData->GetRealTime(); // z start of the plasma in normalized units. Float_t zStartPlasma = pData->GetPlasmaStart() * kp; // z start of the beam in normalized units. Float_t zStartBeam = pData->GetBeamStart() * kp; if(opt.Contains("center")) { Time -= zStartPlasma; if(opt.Contains("comov")) // Centers on the head of the beam. Time += zStartBeam; } // Beam charge 2D and 1D histogram (on-axis) // ------------------------------------------------------------------ TH2F *hDen2D = NULL; if(pData->GetChargeFileName(1)) { char hName[24]; sprintf(hName,"hDen2D"); hDen2D = (TH2F*) gROOT->FindObject(hName); if(hDen2D) { delete hDen2D; hDen2D = NULL; } if(!ThreeD) hDen2D = pData->GetCharge(1,opt); else hDen2D = pData->GetCharge2DSliceZY(1,-1,1,opt+"avg"); hDen2D->SetName(hName); hDen2D->GetXaxis()->CenterTitle(); hDen2D->GetYaxis()->CenterTitle(); hDen2D->GetZaxis()->CenterTitle(); if(opt.Contains("comov")) hDen2D->GetXaxis()->SetTitle("k_{p}#zeta"); else hDen2D->GetXaxis()->SetTitle("k_{p}z"); if(CYL) hDen2D->GetYaxis()->SetTitle("k_{p}r"); else hDen2D->GetYaxis()->SetTitle("k_{p}y"); hDen2D->GetZaxis()->SetTitle("n_{b}/n_{0}"); } // Define ranges from the charge 2D histogram: // Binning for 2D histograms: // We get this values from the 2D density histogram. Int_t x1Nbin = hDen2D->GetNbinsX(); Float_t x1Range = (hDen2D->GetXaxis()->GetXmax() - hDen2D->GetXaxis()->GetXmin()); Float_t x1Mid = (hDen2D->GetXaxis()->GetXmax() + hDen2D->GetXaxis()->GetXmin())/2.; Float_t x1Min = hDen2D->GetXaxis()->GetXmin(); Float_t x1Max = hDen2D->GetXaxis()->GetXmax(); Int_t x2Nbin = hDen2D->GetNbinsY(); Float_t x2Range = (hDen2D->GetYaxis()->GetXmax() - hDen2D->GetYaxis()->GetXmin()); Float_t x2Mid = (hDen2D->GetYaxis()->GetXmax() + hDen2D->GetYaxis()->GetXmin())/2.; Float_t x2Min = x2Mid - x2Range/2; Float_t x2Max = x2Mid + x2Range/2; if(Nbins==0) { Nbins = TMath::Nint(rms0 / hDen2D->GetYaxis()->GetBinWidth(1)) ; // cout << Form(" Rms0 = %6.2f Dx = %6.2f Nbins = %4i .", // rms0, hDen2D->GetYaxis()->GetBinWidth(1), Nbins) << endl; } // Slice width limits. Int_t FirstyBin = 0; Int_t LastyBin = 0; if(!CYL) { FirstyBin = hDen2D->GetNbinsY()/2 + 1 - Nbins; LastyBin = hDen2D->GetNbinsY()/2 + Nbins; } else { FirstyBin = 1; LastyBin = Nbins; } // OUTPUT ROOT FILE WITH THE PLOTS: TString filename = Form("./%s/Plots/Evolutions/Evolutions-%s.root",sim.Data(),sim.Data()); TFile * ifile = (TFile*) gROOT->GetListOfFiles()->FindObject(filename); // if doesn't exist the directory should be created if (!ifile) { TString f = filename; TString dir2 = f.Remove( f.Last( '/' ), f.Length() - f.Last( '/' ) ); TString dir1 = f.Remove( f.Last( '/' ), f.Length() - f.Last( '/' ) ); gSystem->mkdir( dir1 ); gSystem->mkdir( dir2 ); ifile = new TFile(filename,"UPDATE"); } // Charge 1D histogram on axis TH1F *hDen1D = NULL; if(pData->GetChargeFileName(1)) { TString opth1 = opt; opth1 += "avg"; char hName[24]; sprintf(hName,"hDen1D"); hDen1D = (TH1F*) gROOT->FindObject(hName); if(hDen1D) delete hDen1D; if(ThreeD) { hDen1D = pData->GetH1SliceZ3D(pData->GetChargeFileName(1)->c_str(),"charge",-1,Nbins,-1,Nbins,opth1.Data()); } else if(CYL) { // Cylindrical: The first bin with r>0 is actually the number 1 (not the 0). hDen1D = pData->GetH1SliceZ(pData->GetChargeFileName(1)->c_str(),"charge",1,Nbins,opth1.Data()); } else { // 2D cartesian hDen1D = pData->GetH1SliceZ(pData->GetChargeFileName(1)->c_str(),"charge",-1,Nbins,opth1.Data()); } hDen1D->SetName(hName); if(opt.Contains("comov")) hDen1D->GetXaxis()->SetTitle("k_{p}#zeta"); else hDen1D->GetXaxis()->SetTitle("k_{p}z"); hDen1D->GetYaxis()->SetTitle("n_{b}/n_{0}"); } // On-axis beam density vs \zeta vs time! _________________________________ TH2F *hDen1DvsTime = NULL; if(hDen1D) { char hName[24]; sprintf(hName,"hDen1DvsTime"); TH2F *hDen1DvsTimeOld = (TH2F*) ifile->Get(hName); Int_t nBins = 1; Float_t edge0 = Time-0.5; Float_t edge1 = Time+0.5; if(hDen1DvsTimeOld!=NULL) { nBins = hDen1DvsTimeOld->GetNbinsX()+1; Float_t binwidth = (Time - hDen1DvsTimeOld->GetXaxis()->GetBinCenter(1))/(nBins-1); edge0 = hDen1DvsTimeOld->GetXaxis()->GetBinCenter(1) - binwidth/2.; edge1 = Time + binwidth/2.; } hDen1DvsTime = new TH2F("temp","",nBins,edge0,edge1, hDen1D->GetNbinsX(), hDen1D->GetBinLowEdge(1), hDen1D->GetBinLowEdge(hDen1D->GetNbinsX()+1)); for(Int_t ix=1;ix<hDen1DvsTime->GetNbinsX();ix++) { for(Int_t iy=1;iy<hDen1DvsTime->GetNbinsY();iy++) { hDen1DvsTime->SetBinContent(ix,iy,hDen1DvsTimeOld->GetBinContent(ix,iy)); } } delete hDen1DvsTimeOld; // Fill last bin with the newest values. for(Int_t iy=1;iy<=hDen1D->GetNbinsX();iy++) { hDen1DvsTime->SetBinContent(nBins,iy,hDen1D->GetBinContent(iy)); } hDen1DvsTime->GetZaxis()->SetTitle("n_{b}/n_{0}"); hDen1DvsTime->GetYaxis()->SetTitle("k_{p}#zeta"); hDen1DvsTime->GetXaxis()->SetTitle("k_{p}z"); hDen1DvsTime->GetZaxis()->CenterTitle(); hDen1DvsTime->GetYaxis()->CenterTitle(); hDen1DvsTime->GetXaxis()->CenterTitle(); hDen1DvsTime->SetName(hName); // Change the range of z axis Float_t Denmax = hDen1DvsTime->GetMaximum(); hDen1DvsTime->GetZaxis()->SetRangeUser(0,Denmax); hDen1DvsTime->Write(hName,TObject::kOverwrite); } // RMS (vs z) of the beam's charge distribution: TProfile *hDen2Dprof = NULL; TH1F *hRms = NULL; Double_t axisPos = x2Mid; if(hDen2D) { TString pname = hDen2D->GetName(); pname += "_pfx"; hDen2Dprof = (TProfile*) gROOT->FindObject(pname.Data()); if(hDen2Dprof) { delete hDen2Dprof; hDen2Dprof = NULL; } hDen2Dprof = hDen2D->ProfileX("_pfx",1,-1,"s"); hRms = (TH1F*) gROOT->FindObject("hRms"); if(hRms) delete hRms; hRms = new TH1F("hRms","",x1Nbin,x1Min,x1Max); if(CYL) axisPos = 0.0; for(Int_t j=0;j<hRms->GetNbinsX();j++) { Double_t rms = 0; Double_t total = 0; for(Int_t k=1;k<=x2Nbin;k++) { Double_t value = hDen2D->GetBinContent(j,k); Double_t radius = hDen2D->GetYaxis()->GetBinCenter(k) - axisPos; if(CYL) { rms += radius*radius*radius*value; total += radius*value; } else { rms += radius*radius*value; total += value; } // cout << Form(" (%i,%i) -> radius = %7.4f , density = %7.4f",j,k,radius,value) << endl; } rms /= total; rms = sqrt(rms); hRms->SetBinContent(j,rms); } hRms->GetXaxis()->SetTitle("k_{p}z"); if(opt.Contains("comov")) hRms->GetXaxis()->SetTitle("k_{p}#zeta"); hRms->GetYaxis()->SetTitle("k_{p}#LTr#GT_{rms}"); } // Transverse charge RMS vs \zeta vs time! _________________________________ TH2F *hRmsvsTime = NULL; if(hRms) { char hName[24]; sprintf(hName,"hRmsvsTime"); TH2F *hRmsvsTimeOld = (TH2F*) ifile->Get(hName); Int_t nBins = 1; Float_t edge0 = Time-0.5; Float_t edge1 = Time+0.5; if(hRmsvsTimeOld!=NULL) { nBins = hRmsvsTimeOld->GetNbinsX()+1; Float_t binwidth = (Time - hRmsvsTimeOld->GetXaxis()->GetBinCenter(1))/(nBins-1); edge0 = hRmsvsTimeOld->GetXaxis()->GetBinCenter(1) - binwidth/2.; edge1 = Time + binwidth/2.; } hRmsvsTime = new TH2F("temp","",nBins,edge0,edge1, hRms->GetNbinsX(), hRms->GetBinLowEdge(1), hRms->GetBinLowEdge(hRms->GetNbinsX()+1)); for(Int_t ix=1;ix<hRmsvsTime->GetNbinsX();ix++) { for(Int_t iy=1;iy<hRmsvsTime->GetNbinsY();iy++) { hRmsvsTime->SetBinContent(ix,iy,hRmsvsTimeOld->GetBinContent(ix,iy)); } } delete hRmsvsTimeOld; // Fill last bin with the newest values. for(Int_t iy=1;iy<=hRms->GetNbinsX();iy++) { hRmsvsTime->SetBinContent(nBins,iy,hRms->GetBinContent(iy)); } hRmsvsTime->GetZaxis()->SetTitle("#LTr#GT_{rms}"); hRmsvsTime->GetYaxis()->SetTitle("k_{p}#zeta"); hRmsvsTime->GetXaxis()->SetTitle("k_{p}z"); hRmsvsTime->GetZaxis()->CenterTitle(); hRmsvsTime->GetYaxis()->CenterTitle(); hRmsvsTime->GetXaxis()->CenterTitle(); hRmsvsTime->SetName(hName); // Change the range of z axis Float_t Rmsmax = hRmsvsTime->GetMaximum(); hRmsvsTime->GetZaxis()->SetRangeUser(0,Rmsmax); hRmsvsTime->Write(hName,TObject::kOverwrite); } // INTEGRATED Beam's Charge: // Total charge vs time : TGraph *gQvsTime = NULL; if(hDen2D) { Double_t Q = 0; for(Int_t i=1;i<=x1Nbin;i++) { for(Int_t j=1;j<=x2Nbin;j++) { Double_t value = hDen2D->GetBinContent(i,j); if(CYL) { Double_t radius = hDen2D->GetYaxis()->GetBinCenter(j); Q += radius * value; // cout << Form(" (%i,%i) -> radius = %7.4f , value = %7.4f",i,j,radius,value) << endl; } else { Q += value; } } } Double_t xbinsize = hDen2D->GetXaxis()->GetBinWidth(1); Double_t ybinsize = hDen2D->GetYaxis()->GetBinWidth(1); Q *= xbinsize * ybinsize; if(!CYL && !ThreeD) { Q *= TMath::Sqrt(2*TMath::Pi()) * rms0; } else if(CYL) { Q *= 2*TMath::Pi(); } if(opt.Contains("units")) { Double_t dV = skindepth * skindepth * skindepth; Q *= n0 * dV; Q *= (PConst::ElectronCharge/PUnits::picocoulomb); cout << Form(" Integrated charge = %8i pC", TMath::Nint(Q)) << endl; } else { cout << Form(" Integrated charge = %8.4f n0 * kp^-3",Q) << endl; } Int_t nPoints = 0; char gName[32]; sprintf(gName,"gQvsTime"); gQvsTime = (TGraph*) ifile->Get(gName); if(gQvsTime==NULL) { gQvsTime = new TGraph(); gQvsTime->SetName(gName); nPoints = 0; // Some cosmetics at creation time: gQvsTime->SetLineWidth(3); gQvsTime->SetLineColor(PGlobals::fieldLine); gQvsTime->SetMarkerStyle(20); gQvsTime->SetMarkerSize(0.4); gQvsTime->SetMarkerColor(PGlobals::fieldLine); gQvsTime->GetYaxis()->SetTitle("charge [n_{0}/k_{p}^{3}]"); gQvsTime->GetXaxis()->SetTitle("k_{p}z"); } else { nPoints = gQvsTime->GetN(); } gQvsTime->Set(nPoints+1); gQvsTime->SetPoint(nPoints,Time,Q); gQvsTime->Write(gName,TObject::kOverwrite); } // ------------------------------------------------------------------------------------ // Longitudinal phasespace Int_t gNbin = 100; // Float_t gMin = 80; // Float_t gMax = 120; Float_t gMin = 43.07 - 1.2; Float_t gMax = 43.07 + 1.2; TH2F *hGvsZ = NULL; if(pData->GetRawFileName(1)) { char hName[24]; sprintf(hName,"hGvsZ"); hGvsZ = (TH2F*) gROOT->FindObject(hName); if(hGvsZ) { delete hGvsZ; hGvsZ = NULL; } hGvsZ = new TH2F(hName,"",x1Nbin,x1Min,x1Max,gNbin,gMin,gMax); pData->GetH2Raw(pData->GetRawFileName(1)->c_str(),"x1","gamma",hGvsZ,opt); hGvsZ->GetXaxis()->CenterTitle(); hGvsZ->GetYaxis()->CenterTitle(); hGvsZ->GetZaxis()->CenterTitle(); hGvsZ->GetYaxis()->SetTitle("#gamma"); if(opt.Contains("comov")) { hGvsZ->GetXaxis()->SetTitle("k_{p}#zeta"); hGvsZ->GetZaxis()->SetTitle("dN/d#zetad#gamma [a.u.]"); } else { hGvsZ->GetXaxis()->SetTitle("k_{p}z"); hGvsZ->GetZaxis()->SetTitle("dN/dzd#gamma [a.u.]"); } } else { cout << Form("--> No RAW data file is present for species 1") << endl; } TH2F *hGvsTime = NULL; TProfile *hGvsZprof = NULL; TGraphErrors *gGvsZ = NULL; if(hGvsZ) { TString pname = hGvsZ->GetName(); pname += "_pfx"; hGvsZprof = (TProfile*) gROOT->FindObject(pname.Data()); if(hGvsZprof) delete hGvsZprof; hGvsZprof = hGvsZ->ProfileX("_pfx",1,-1,"s"); gGvsZ = (TGraphErrors*) gROOT->FindObject("gGvsZ"); if(gGvsZ) delete gGvsZ; Int_t Npoints = hGvsZprof->GetNbinsX(); Double_t *x = new Double_t[Npoints]; Double_t *y = new Double_t[Npoints]; Double_t *ex = new Double_t[Npoints]; Double_t *ey = new Double_t[Npoints]; for(Int_t j=0;j<Npoints;j++) { x[j] = hGvsZprof->GetBinCenter(j); y[j] = hGvsZprof->GetBinContent(j); ex[j] = 0; ey[j] = hGvsZprof->GetBinError(j); } gGvsZ = new TGraphErrors(Npoints,x,y,ex,ey); gGvsZ->SetName("gGvsZ"); // PGlobals::SetH1Style((TH1*)gGvsZ,1); PGlobals::SetGraphStyle(gGvsZ,1); if(opt.Contains("comov")) gGvsZ->GetXaxis()->SetTitle("k_{p}#zeta"); else gGvsZ->GetXaxis()->SetTitle("k_{p}z"); gGvsZ->GetYaxis()->SetTitle("#LT#gamma#GT [MeV]"); char hName[24]; sprintf(hName,"hGvsTime"); TH2F *hGvsTimeOld = (TH2F*) ifile->Get(hName); Int_t nBins = 1; Float_t edge0 = Time-0.5; Float_t edge1 = Time+0.5; if(hGvsTimeOld!=NULL) { nBins = hGvsTimeOld->GetNbinsX()+1; Float_t binwidth = (Time - hGvsTimeOld->GetXaxis()->GetBinCenter(1))/(nBins-1); edge0 = hGvsTimeOld->GetXaxis()->GetBinCenter(1) - binwidth/2.; edge1 = Time + binwidth/2.; } hGvsTime = new TH2F("temp","",nBins,edge0,edge1, hGvsZprof->GetNbinsX(), hGvsZprof->GetBinLowEdge(1), hGvsZprof->GetBinLowEdge(hGvsZprof->GetNbinsX()+1)); for(Int_t ix=1;ix<hGvsTime->GetNbinsX();ix++) { for(Int_t iy=1;iy<hGvsTime->GetNbinsY();iy++) { hGvsTime->SetBinContent(ix,iy,hGvsTimeOld->GetBinContent(ix,iy)); } } delete hGvsTimeOld; // Fill last bin with the newest values. for(Int_t iy=1;iy<=hGvsZprof->GetNbinsX();iy++) { hGvsTime->SetBinContent(nBins,iy,hGvsZprof->GetBinContent(iy)); } hGvsTime->GetZaxis()->SetTitle("#LT#gamma#GT"); hGvsTime->GetYaxis()->SetTitle("k_{p}#zeta"); hGvsTime->GetXaxis()->SetTitle("k_{p}z"); hGvsTime->GetZaxis()->CenterTitle(); hGvsTime->GetYaxis()->CenterTitle(); hGvsTime->GetXaxis()->CenterTitle(); hGvsTime->SetName(hName); // Change the range of z axis Float_t Gmax = hGvsTime->GetMaximum(); Float_t Gmin = hGvsTime->GetMinimum(); hGvsTime->GetZaxis()->SetRangeUser(Gmin,Gmax); hGvsTime->Write(hName,TObject::kOverwrite); } // --------------------------------------------------------------------------------- // EM fields on - axis : TString opth1 = opt; opth1 += "avg"; // Get electric fields const Int_t Nfields = 2; TH1F **hE1D = new TH1F*[Nfields]; for(Int_t i=0;i<Nfields;i++) { hE1D[i] = NULL; if(!pData->GetEfieldFileName(i)) continue; char nam[3]; sprintf(nam,"e%i",i+1); if(ThreeD) { if(i==0) hE1D[i] = pData->GetH1SliceZ3D(pData->GetEfieldFileName(i)->c_str(),nam,-1,Nbins,-1,Nbins,opth1.Data()); else hE1D[i] = pData->GetH1SliceZ3D(pData->GetEfieldFileName(i)->c_str(),nam,-Nbins,Nbins,-Nbins,Nbins,opth1.Data()); } else if(CYL) { // Cylindrical: The first bin with r>0 is actually the number 1 (not the 0). if(i==0) hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,1,Nbins,opth1.Data()); else hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,1,Nbins,opth1.Data()); } else { // 2D cartesian if(i==0) hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,-1,Nbins,opth1.Data()); else hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,-Nbins,Nbins,opth1.Data()); } char hName[24]; sprintf(hName,"hE_%i_%i",i,time); hE1D[i]->SetName(hName); if(opt.Contains("comov")) hE1D[i]->GetXaxis()->SetTitle("k_{p}#zeta"); else hE1D[i]->GetXaxis()->SetTitle("k_{p}z"); if(i==0) hE1D[i]->GetYaxis()->SetTitle("E_{z}/E_{0}"); else if(i==1) hE1D[i]->GetYaxis()->SetTitle("E_{y}/E_{0}"); else if(i==2) hE1D[i]->GetYaxis()->SetTitle("E_{x}/E_{0}"); hE1D[i]->GetYaxis()->CenterTitle(); hE1D[i]->GetXaxis()->CenterTitle(); } // Calculate wave positions: // ---------------------------------------------------------------- // Calculate the crossings and the extremes of the Electric fields Float_t Ecross[Nfields][100] = {{0.0}}; Float_t Eextr[Nfields][100] = {{0.0}}; Int_t Ncross[Nfields] = {0}; for(Int_t i=0;i<Nfields;i++) { Ncross[i] = 0; if(!hE1D[i]) continue; // Only smooths the focusing if flag activated.. if(i>0 && opt.Contains("smooth")) { // cout << " Smoothing fields on axis..." << endl; hE1D[i]->Smooth(10); } Float_t maxZeta = zStartBeam; if(opt.Contains("center")) maxZeta -= zStartBeam; for(Int_t ip=hE1D[i]->GetNbinsX();ip>1;ip--) { Float_t Z2 = hE1D[i]->GetBinCenter(ip-1); if(Z2 > maxZeta) continue; Float_t E1 = hE1D[i]->GetBinContent(ip); Float_t E2 = hE1D[i]->GetBinContent(ip-1); Float_t Z1 = hE1D[i]->GetBinCenter(ip); // cout << Form("Z1 = %6.4f Z2 = %6.4f E1 = %6.4f E2 = %6.4f", Z1, Z2, E1, E2) << endl; if(E1*E2 >= 0) { // No change of sign means we are in a side of the zero axis. if(fabs(E2)>fabs(Eextr[i][Ncross[i]])) { Eextr[i][Ncross[i]] = E2; } } if(E1*E2 < 0) { // change of sign means a crossing! // The next crossing has to be far enough from the previous one: Float_t zcross = -E1 * ( (Z2-Z1)/(E2-E1) ) + Z1; if(Ncross[i]>0 && fabs(Ecross[i][Ncross[i]-1]-zcross)<TMath::PiOver2() ) continue; // cout << " CROSS! " << endl; // add the point Ecross[i][Ncross[i]] = zcross; Ncross[i]++; } } cout << " -> Number of crossings for field " << i << " : " << Ncross[i] << endl; for(Int_t ic=0;ic<Ncross[i];ic++) { // cout << Form(" %2i: zeta = %6.4f E = %6.4f", ic, Ecross[i][ic], Eextr[i][ic]) << endl; } hE1D[i]->SetLineColor(kRed); hE1D[i]->Write(hE1D[i]->GetName(),TObject::kOverwrite); } // Get the Graphs and histos from file Int_t nPoints = 0; TGraph ***gEcross = new TGraph**[Nfields]; TGraph ***gEextr = new TGraph**[Nfields]; TH2F **hEvsTime = new TH2F*[Nfields]; for(Int_t i=0;i<Nfields;i++) { char hName[24]; sprintf(hName,"hEvsTime_%i",i); TH2F *hEvsTimeOld = (TH2F*) ifile->Get(hName); Int_t nBins = 1; Float_t edge0 = Time-0.5; Float_t edge1 = Time+0.5; if(hEvsTimeOld!=NULL) { nBins = hEvsTimeOld->GetNbinsX()+1; Float_t binwidth = (Time - hEvsTimeOld->GetXaxis()->GetBinCenter(1))/(nBins-1); edge0 = hEvsTimeOld->GetXaxis()->GetBinCenter(1) - binwidth/2.; edge1 = Time + binwidth/2.; } hEvsTime[i] = new TH2F("temp","",nBins,edge0,edge1, hE1D[i]->GetNbinsX(), hE1D[i]->GetBinLowEdge(1), hE1D[i]->GetBinLowEdge(hE1D[i]->GetNbinsX()+1)); for(Int_t ix=1;ix<hEvsTime[i]->GetNbinsX();ix++) { for(Int_t iy=1;iy<hEvsTime[i]->GetNbinsY();iy++) { hEvsTime[i]->SetBinContent(ix,iy,hEvsTimeOld->GetBinContent(ix,iy)); } } delete hEvsTimeOld; // Fill last bin with the newest values. for(Int_t iy=1;iy<=hE1D[i]->GetNbinsX();iy++) { hEvsTime[i]->SetBinContent(nBins,iy,hE1D[i]->GetBinContent(iy)); } if(i==0) hEvsTime[i]->GetZaxis()->SetTitle("E_{z}/E_{0}"); else if(i==1) hEvsTime[i]->GetZaxis()->SetTitle("E_{y}/E_{0}"); else if(i==2) hEvsTime[i]->GetZaxis()->SetTitle("E_{x}/E_{0}"); hEvsTime[i]->GetYaxis()->SetTitle("k_{p}#zeta"); hEvsTime[i]->GetXaxis()->SetTitle("k_{p}z"); hEvsTime[i]->GetZaxis()->CenterTitle(); hEvsTime[i]->GetYaxis()->CenterTitle(); hEvsTime[i]->GetXaxis()->CenterTitle(); hEvsTime[i]->SetName(hName); // Change the range of z axis for the fields to be symmetric. Float_t Emax = hEvsTime[i]->GetMaximum(); Float_t Emin = hEvsTime[i]->GetMinimum(); if(Emax > TMath::Abs(Emin)) Emin = -Emax; else Emax = -Emin; hEvsTime[i]->GetZaxis()->SetRangeUser(Emin,Emax); hEvsTime[i]->Write(hName,TObject::kOverwrite); // --- gEcross[i] = new TGraph*[Ncross[i]]; gEextr[i] = new TGraph*[Ncross[i]]; char gName[24]; Int_t ifail = 0; for(Int_t ic=0;ic<Ncross[i];ic++) { sprintf(gName,"gEcross_%i_%i",i,ic); gEcross[i][ic] = (TGraph*) ifile->Get(gName); if(gEcross[i][ic]==NULL) { gEcross[i][ic] = new TGraph(); gEcross[i][ic]->SetName(gName); nPoints = 0; // Some cosmetics at creation time: if(i==1) gEcross[i][ic]->SetLineStyle(2); else gEcross[i][ic]->SetLineStyle(1); gEcross[i][ic]->SetLineWidth(1); gEcross[i][ic]->SetLineColor(kGray+1); gEcross[i][ic]->SetMarkerStyle(20); gEcross[i][ic]->SetMarkerSize(0.4); gEcross[i][ic]->SetMarkerColor(kGray+1); gEcross[i][ic]->GetYaxis()->SetTitle("k_{p}#zeta]"); gEcross[i][ic]->GetXaxis()->SetTitle("k_{p}z"); } else { nPoints = gEcross[i][ic]->GetN(); } // Check the new crossings respect the previous ones: // Double_t t,zeta; // if(nPoints>0) { // gEcross[i][ic]->GetPoint(nPoints-1,t,zeta); // if(fabs(zeta-Ecross[i][ic+ifail])>TMath::Pi()) { // ic--; // ifail++; // continue; // } // } gEcross[i][ic]->Set(nPoints+1); gEcross[i][ic]->SetPoint(nPoints,Time,Ecross[i][ic+ifail]); gEcross[i][ic]->Write(gName,TObject::kOverwrite); // if(ic==Ncross[i]-1) continue; sprintf(gName,"gEextr_%i_%i",i,ic); gEextr[i][ic] = (TGraph*) ifile->Get(gName); if(gEextr[i][ic]==NULL) { gEextr[i][ic] = new TGraph(); gEextr[i][ic]->SetName(gName); nPoints = 0; // Some cosmetics at creation time: if(i==0) { gEextr[i][ic]->SetLineWidth(3); gEextr[i][ic]->SetLineColor(PGlobals::fieldLine); gEextr[i][ic]->SetMarkerStyle(20); gEextr[i][ic]->SetMarkerSize(0.4); gEextr[i][ic]->SetMarkerColor(PGlobals::fieldLine); gEextr[i][ic]->GetYaxis()->SetTitle("E_{z}/E_{0}"); gEextr[i][ic]->GetXaxis()->SetTitle("k_{p}z"); } else if(i==1) { gEextr[i][ic]->SetLineWidth(1); gEextr[i][ic]->SetLineColor(kGray+2); gEextr[i][ic]->SetMarkerStyle(20); gEextr[i][ic]->SetMarkerSize(0.4); gEextr[i][ic]->SetMarkerColor(kGray+2); gEextr[i][ic]->GetYaxis()->SetTitle("E_{y}/E_{0}"); gEextr[i][ic]->GetXaxis()->SetTitle("k_{p}z"); } } else { nPoints = gEextr[i][ic]->GetN(); } gEextr[i][ic]->Set(nPoints+1); gEextr[i][ic]->SetPoint(nPoints,Time,Eextr[i][ic]); gEextr[i][ic]->Write(gName,TObject::kOverwrite); } } ifile->Close(); }
void SignfificanceT2tt(bool pval, int exp=0){ TFile *f = TFile::Open("Significances2DHistograms_T2tt.root"); TH2F *h; if(pval){ if(exp==0) h = (TH2F*)f->Get("hpObs"); else if(exp==1) h = (TH2F*)f->Get("hpExpPosteriori"); else if(exp==2) h = (TH2F*)f->Get("hpExpPriori"); } else { if(exp==0) h = (TH2F*)f->Get("hObs"); else if(exp==1) h = (TH2F*)f->Get("hExpPosteriori"); else if(exp==2) h = (TH2F*)f->Get("hExpPriori"); } h->GetXaxis()->SetTitle("m_{#tilde{t}} [GeV]"); h->GetXaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.035); h->GetXaxis()->SetTitleSize(0.05); h->GetXaxis()->SetTitleOffset(1.2); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitle("m_{#tilde{#chi}_{1}^{0}} [GeV]"); h->GetYaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelSize(0.035); h->GetYaxis()->SetTitleSize(0.05); h->GetYaxis()->SetTitleOffset(1.35); h->GetYaxis()->SetTitleFont(42); double maximum = h->GetMaximum(); double minimum = h->GetMinimum(); double sigmin = 99; int sigminx=-1; int sigminy=-1; if(pval) sigmin = -99; h->GetZaxis()->SetRangeUser(minimum,maximum); for(int x = 1; x<=h->GetNbinsX();++x){ for(int y = 1; y<=h->GetNbinsX();++y){ if(!pval&&h->GetBinContent(x,y)<sigmin){ sigmin =h->GetBinContent(x,y); sigminx = x; sigminy = y; } if( pval&&h->GetBinContent(x,y)>sigmin){ sigmin =h->GetBinContent(x,y); sigminx = x; sigminy = y; } if(!pval&&h->GetXaxis()->GetBinLowEdge(x)<h->GetYaxis()->GetBinLowEdge(y)+75) h->SetBinContent(x,y,-999); if(h->GetXaxis()->GetBinLowEdge(x)<374) continue; if(h->GetXaxis()->GetBinLowEdge(x)>424) continue; if(h->GetYaxis()->GetBinLowEdge(y)<199) continue; if(h->GetYaxis()->GetBinLowEdge(y)>249) continue; if(!pval&&h->GetBinContent(x,y)>0.3) h->SetBinContent(x,y,0.05); } } h->GetZaxis()->SetRangeUser(minimum,maximum); if(!pval) cout << "minimal significance " << sigmin << " at " << h->GetXaxis()->GetBinLowEdge(sigminx) << "-" << h->GetYaxis()->GetBinLowEdge(sigminy) << endl; else cout << "maximal p- value " << sigmin << " at " << h->GetXaxis()->GetBinLowEdge(sigminx) << "-" << h->GetYaxis()->GetBinLowEdge(sigminy) << endl; TCanvas *c1 = new TCanvas("c1", "c1",50,50,600,600); gStyle->SetOptFit(1); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); gStyle->SetErrorX(0.5); //c1->Range(-6.311689,-1.891383,28.75325,4.56342); c1->SetFillColor(0); c1->SetBorderMode(0); c1->SetBorderSize(2); //c1->SetLogy(); c1->SetTickx(1); c1->SetTicky(1); c1->SetLeftMargin(0.15); // c1->SetRightMargin(0.05); c1->SetRightMargin(0.15); c1->SetTopMargin(0.07); c1->SetBottomMargin(0.15); c1->SetFrameFillStyle(0); c1->SetFrameBorderMode(0); c1->SetFrameFillStyle(0); c1->SetFrameBorderMode(0); gStyle->SetHatchesLineWidth(0); TH1F *hSum = new TH1F("hSum","",10,100,900); hSum->SetMinimum(0.); hSum->SetMaximum(550); hSum->SetDirectory(0); hSum->SetStats(0); hSum->Draw(); hSum->GetYaxis()->SetRangeUser(0,500); hSum->GetXaxis()->SetRangeUser(100,900); Int_t ci; // for color index setting ci = TColor::GetColor("#000099"); hSum->SetLineColor(ci); hSum->SetLineStyle(0); hSum->SetMarkerStyle(20); hSum->GetXaxis()->SetTitle("m_{#tilde{t}} [GeV]"); //hSum->GetXaxis()->SetBit(TAxis::kLabelsVert); hSum->GetXaxis()->SetLabelFont(42); //hSum->GetXaxis()->SetLabelOffset(0.005); hSum->GetXaxis()->SetLabelSize(0.035); hSum->GetXaxis()->SetTitleSize(0.06); hSum->GetXaxis()->SetTitleOffset(1.2); hSum->GetXaxis()->SetTitleFont(42); hSum->GetYaxis()->SetTitle("m_{#tilde{#chi}}_{1}^{0} [GeV]"); hSum->GetYaxis()->SetLabelFont(42); //hSum->GetYaxis()->SetLabelOffset(0.007); hSum->GetYaxis()->SetLabelSize(0.035); hSum->GetYaxis()->SetTitleSize(0.05); hSum->GetYaxis()->SetTitleOffset(1.3); hSum->GetYaxis()->SetTitleFont(42); /* TLegend *legO = new TLegend(0.175,0.675,0.50,0.855,NULL,"brNDC"); //legO-> SetNColumns(2); legO->SetBorderSize(0); legO->SetTextSize(0.04); legO->SetTextFont(42); legO->SetLineColor(1); legO->SetLineStyle(1); legO->SetLineWidth(2); legO->SetFillColor(0); legO->SetFillStyle(1001); legO->SetHeader("Observed"); legO->AddEntry(gObs, "unpolarized","l"); legO->AddEntry(gObsR, "right-handed","l"); legO->AddEntry(gObsL, "left-handed","l"); */ TGraph* graphWhite = new TGraph(5); graphWhite->SetName("white"); graphWhite->SetTitle("white"); graphWhite->SetFillColor(kWhite); graphWhite->SetFillStyle(1001); graphWhite->SetLineColor(kBlack); graphWhite->SetLineStyle(1); graphWhite->SetLineWidth(3); graphWhite->SetPoint(0,100, 500); graphWhite->SetPoint(1,900, 500); graphWhite->SetPoint(2,900, 500*0.75); graphWhite->SetPoint(3,100, 500*0.75); graphWhite->SetPoint(4,100, 500); Float_t diagX[4] = {175.+25.,175.+25.+5000,175.-25.+5000,175.-25.}; Float_t diagY[4] = {0,5000,5000,0}; TGraph *gdiagonal = new TGraph(4, diagX, diagY); gdiagonal->SetName("MtopDiagonal"); gdiagonal->SetFillColor(kWhite); //#gdiagonal->SetFillColor(18); TLine* ldiagonal = new TLine(175,0.,650-25.,450); //TLine* ldiagonal = new TLine(175.,25,175+500,500); ldiagonal->SetLineColor(kGray); ldiagonal->SetLineStyle(2); TLatex* tdiagonal = new TLatex(400-2.5, 400-172.5,"m_{#tilde{t}} = m_{t} + m_{#tilde{#chi}_{1}^{0}}"); //tdiagonal->SetTextAngle(TMath::RadToDeg()*TMath::ATan(float(800)/float(500))); tdiagonal->SetTextAngle(56.31); tdiagonal->SetTextColor(kGray+2); tdiagonal->SetTextAlign(11); tdiagonal->SetTextSize(0.025); TLine* l2 = new TLine(150,75,585,500); l2->SetLineColor(kGray); l2->SetLineStyle(2); // if(killlowdiag){ // l2->SetX1(200); l2->SetY1(0); l2->SetX2(600); l2->SetY2(400); // } TLatex *t2 = new TLatex(300, 300-72.5,"m_{#tilde{t}} = m_{W} + m_{#tilde{#chi}_{1}^{0}}"); //t2->SetTextAngle(TMath::RadToDeg()*TMath::ATan(float(800)/float(500))); t2->SetTextAngle(56.31); t2->SetTextColor(kGray+2); t2->SetTextAlign(11); t2->SetTextSize(0.025); hSum->Draw("axis"); h->Draw("COLZsame"); gdiagonal->Draw("FSAME"); ldiagonal->Draw("LSAME"); l2->Draw(); // if(!killlowdiag) t2->Draw(); tdiagonal->Draw("SAME"); graphWhite->Draw("FSAME"); graphWhite->Draw("LSAME"); string textstring = "observed"; if(exp!=0) textstring = "expected"; TLatex* textOE= new TLatex(0.175,0.715,textstring.c_str() ); textOE->SetNDC(); textOE->SetTextAlign(13); textOE->SetTextFont(42); textOE->SetTextSize(0.042); textOE->Draw(); TLatex* textModelLabel= new TLatex(0.175,0.92,"pp #rightarrow #tilde{t} #tilde{t}*, #tilde{t} #rightarrow t #tilde{#chi}^{0}_{1}"); //TLatex* textModelLabel= new TLatex(0.175,0.92,"pp #rightarrow #tilde{t} #tilde{t}*, #tilde{t} #rightarrow t #tilde{#chi}^{0}_{1}"); //TLatex* textModelLabel= new TLatex(0.175,0.92,"#tilde{#chi} "); textModelLabel->SetNDC(); textModelLabel->SetTextAlign(13); textModelLabel->SetTextFont(42); textModelLabel->SetTextSize(0.042); textModelLabel->Draw(); TLatex* textlLabel= new TLatex(0.175,0.85,"NLO+NLL significance"); textlLabel->SetNDC(); textlLabel->SetTextAlign(13); textlLabel->SetTextFont(42); textlLabel->SetTextSize(0.042); textlLabel->Draw(); string psig = "significance [#sigma]"; if(pval) psig = "p-value"; TLatex * ztex = new TLatex(0.985,0.92,psig.c_str() ); ztex->SetNDC(); ztex->SetTextAlign(31); ztex->SetTextFont(42); ztex->SetTextSize(0.045); ztex->SetTextAngle(90); ztex->SetLineWidth(2); ztex->Draw(); //final CMS style TLatex *tLumi = new TLatex(0.81,0.944,"2.3 fb^{-1} (13 TeV)"); tLumi->SetNDC(); tLumi->SetTextAlign(31); tLumi->SetTextFont(42); tLumi->SetTextSize(0.042); tLumi->SetLineWidth(2); tLumi->Draw(); TLatex *tCMS = new TLatex(0.152,0.944,"CMS"); tCMS->SetNDC(); tCMS->SetTextAlign(11); tCMS->SetTextFont(61); tCMS->SetTextSize(0.0525); tCMS->SetLineWidth(2); tCMS->Draw(); TLatex *tPrel = new TLatex(0.265,0.944,"Preliminary"); tPrel->SetNDC(); tPrel->SetTextAlign(11); tPrel->SetTextFont(52); tPrel->SetTextSize(0.042); tPrel->SetLineWidth(2); tPrel->Draw(); c1->Modified(); c1->cd(); c1->Update(); c1->SetSelected(c1); }
int main() { Int_t nbins = 800, j; char name[20], title[100]; TStopwatch t; TFile f1("/home/marko/Desktop/H4Analysis/ntuples/analysis_3898.root"); //Run 3898 ntuple TFile f2("/home/marko/Desktop/H4Analysis/ntuples/analysis_3902.root"); //Run 3902 ntuple TFile f3("/home/marko/Desktop/H4Analysis/ntuples/analysis_3905.root"); //Run 3905 ntuple TTree* h4_3898 = (TTree*) f1.Get("h4"); TTree* h4_3902 = (TTree*) f2.Get("h4"); TTree* h4_3905 = (TTree*) f3.Get("h4"); TFile outputfile("AllPedestalEventFFTs.root", "recreate"); //individual event noise spectra Int_t nentries1 = h4_3898->GetEntries("WF_ch==APD1 && amp_max[APD3]<25 && b_rms[APD3]<5. && charge_tot[APD3]<20000 && amp_max[APD5]<25 && b_rms[APD5]<5. && amp_max[APD6]<25 && b_rms[APD6]<5. && amp_max[APD4]<25 && b_rms[APD4]<5. && amp_max[SiPM1]<20 && amp_max[SiPM2]<20 && amp_max[APD1]<40 && amp_max[APD2]<40 && b_rms[APD1]<5. && b_rms[APD2]<5. && WF_time<160"); Int_t nentries2 = h4_3902->GetEntries("WF_ch==APD1 && amp_max[APD3]<25 && b_rms[APD3]<5. && charge_tot[APD3]<20000 && amp_max[APD5]<25 && b_rms[APD5]<5. && amp_max[APD6]<25 && b_rms[APD6]<5. && amp_max[APD4]<25 && b_rms[APD4]<5. && amp_max[SiPM1]<20 && amp_max[SiPM2]<20 && amp_max[APD1]<40 && amp_max[APD2]<40 && b_rms[APD1]<5. && b_rms[APD2]<5. && WF_time<160"); Int_t nentries3 = h4_3905->GetEntries("WF_ch==APD1 && amp_max[APD3]<25 && b_rms[APD3]<5. && charge_tot[APD3]<20000 && amp_max[APD5]<25 && b_rms[APD5]<5. && amp_max[APD6]<25 && b_rms[APD6]<5. && amp_max[APD4]<25 && b_rms[APD4]<5. && amp_max[SiPM1]<20 && amp_max[SiPM2]<20 && amp_max[APD1]<40 && amp_max[APD2]<40 && b_rms[APD1]<5. && b_rms[APD2]<5. && WF_time<160"); Int_t entriestotal = nentries1 + nentries2 + nentries3; Int_t nspill = 15; //how many spills will be analyzed (not all spills necessarily have data) TH1F *HistoEvent[entriestotal]; for (Int_t z=0;z<entriestotal;z++) { sprintf(name,"HistoEvent%d",z); sprintf(title,"Event%d Histo", z); HistoEvent[z] = new TH1F(name,title,nbins, -0.1, 159.9); } TH1F *NewHistoEvent[entriestotal]; for (Int_t z=0;z<entriestotal;z++) { sprintf(name,"NewHistoEvent%d",z); sprintf(title,"Event%d Histo", z); NewHistoEvent[z] = new TH1F(name,title,nbins, -0.1, 159.9); } TH1F *NewHistoEventFFT[entriestotal]; for (Int_t z=0;z<entriestotal;z++) { sprintf(name,"NewHistoEventFFT%d",z); sprintf(title,"Event%d Histo", z); NewHistoEventFFT[z] = new TH1F(name,title,nbins, 0, 5); } TH1F* NormNoiseFFT = new TH1F ("NormNoiseFFT", "Normalized Noise FFT", nbins, 0, 5); Int_t count = 0; t.Start(); for (Int_t spill=0;spill<nspill;spill++) { cout << "Run 3898 Spill " << spill << endl; h4_3898->SetEntryList(0); TString listcut = "WF_ch==APD1 && amp_max[APD3]<25 && b_rms[APD3]<5. && charge_tot[APD3]<20000 && amp_max[APD5]<25 && b_rms[APD5]<5. && amp_max[APD6]<25 && b_rms[APD6]<5. && amp_max[APD4]<25 && b_rms[APD4]<5. && amp_max[SiPM1]<20 && amp_max[SiPM2]<20 && amp_max[APD1]<40 && amp_max[APD2]<40 && b_rms[APD1]<5. && b_rms[APD2]<5. && WF_time<160 && spill=="; listcut += spill; TString spillcut = "spill=="; spillcut += spill; h4_3898->Draw(">>myList", listcut, "entrylist"); TEntryList *myList = (TEntryList*) gDirectory->Get("myList"); h4_3898->SetEntryList(myList); Int_t entriesperspill = myList->GetN(); h4_3898->Draw("event", spillcut, "goff"); Double_t *vTemp = h4_3898->GetV1(); Double_t *vEvent = new Double_t[entriesperspill]; for (int iEntry = 0; iEntry<entriesperspill; iEntry++){ vEvent[iEntry] = vTemp[iEntry]; } Double_t mean. rms; TString plot, cut; for (j=0;j<entriesperspill;j++) { TString histoname = "Run3898TempHisto_"; histoname += spill; histoname += "_"; histoname += j; TH2F* TempHisto = new TH2F (histoname, "Temp Histo", nbins, -0.1, 159.9, 1000, -15, 15); plot = "WF_val:WF_time>>"; plot += histoname; cut = "WF_ch==APD1 && amp_max[APD3]<25 && b_rms[APD3]<5. && charge_tot[APD3]<20000 && amp_max[APD5]<25 && b_rms[APD5]<5. && amp_max[APD6]<25 && b_rms[APD6]<5. && amp_max[APD4]<25 && b_rms[APD4]<5. && amp_max[SiPM1]<20 && amp_max[SiPM2]<20 && amp_max[APD1]<40 && amp_max[APD2]<40 && b_rms[APD1]<5. && b_rms[APD2]<5. && WF_time<160 && spill=="; cut += spill; cut += " && event=="; cut += vEvent[j]; h4_3898->Draw(plot, cut, "goff"); TempHisto = (TH2F*) gDirectory->Get(histoname); if (TempHisto->GetMaximum() == 0) { continue; } HistoEvent[count] = transform2Dto1D(TempHisto); mean = TempHisto->GetMean(2); rms = TempHisto->GetRMS(2); for (Int_t q=0;q<nbins;q++) { NewHistoEvent[count]->SetBinContent(q+1, HistoEvent[count]->GetBinContent(q+1)-mean); //centering the pedestal at <y> = 0 } NewHistoEvent[count]->Scale(1/rms); //dividing by RMS of pedestal event, later undone when the filter is applied to the wave pulses NewHistoEvent[count]->FFT(NewHistoEventFFT[count], "MAG"); //noise power spectrum (frequency domain) NormNoiseFFT->Add(NormNoiseFFT, NewHistoEventFFT[count]); NewHistoEventFFT[count]->Write(); cout << "Event " << count+1 << " out of " << entriestotal << endl; count += 1; delete TempHisto; } } for (Int_t spill=0;spill<nspill;spill++) { cout << "Run 3902 Spill " << spill << endl; h4_3902->SetEntryList(0); TString listcut = "WF_ch==APD1 && amp_max[APD3]<25 && b_rms[APD3]<5. && charge_tot[APD3]<20000 && amp_max[APD5]<25 && b_rms[APD5]<5. && amp_max[APD6]<25 && b_rms[APD6]<5. && amp_max[APD4]<25 && b_rms[APD4]<5. && amp_max[SiPM1]<20 && amp_max[SiPM2]<20 && amp_max[APD1]<40 && amp_max[APD2]<40 && b_rms[APD1]<5. && b_rms[APD2]<5. && WF_time<160 && spill=="; listcut += spill; TString spillcut = "spill=="; spillcut += spill; h4_3902->Draw(">>myList", listcut, "entrylist"); TEntryList *myList = (TEntryList*) gDirectory->Get("myList"); h4_3902->SetEntryList(myList); Int_t entriesperspill = myList->GetN(); h4_3902->Draw("event", spillcut, "goff"); Double_t *vTemp = h4_3902->GetV1(); Double_t *vEvent = new Double_t[entriesperspill]; for (int iEntry = 0; iEntry<entriesperspill; iEntry++){ vEvent[iEntry] = vTemp[iEntry]; } Double_t mean, rms; TString plot, cut; for (j=0;j<entriesperspill;j++) { TString histoname = "Run3902TempHisto_"; histoname += spill; histoname += "_"; histoname += j; TH2F* TempHisto = new TH2F (histoname, "Temp Histo", nbins, -0.1, 159.9, 1000, -15, 15); plot = "WF_val:WF_time>>"; plot += histoname; cut = "WF_ch==APD1 && amp_max[APD3]<25 && b_rms[APD3]<5. && charge_tot[APD3]<20000 && amp_max[APD5]<25 && b_rms[APD5]<5. && amp_max[APD6]<25 && b_rms[APD6]<5. && amp_max[APD4]<25 && b_rms[APD4]<5. && amp_max[SiPM1]<20 && amp_max[SiPM2]<20 && amp_max[APD1]<40 && amp_max[APD2]<40 && b_rms[APD1]<5. && b_rms[APD2]<5. && WF_time<160 && spill=="; cut += spill; cut += " && event=="; cut += vEvent[j]; h4_3902->Draw(plot, cut, "goff"); TempHisto = (TH2F*) gDirectory->Get(histoname); if (TempHisto->GetMaximum() == 0) { continue; } HistoEvent[count] = transform2Dto1D(TempHisto); mean = TempHisto->GetMean(2); rms = TempHisto->GetRMS(2); for (Int_t q=0;q<nbins;q++) { NewHistoEvent[count]->SetBinContent(q+1, HistoEvent[count]->GetBinContent(q+1)-mean); } NewHistoEvent[count]->Scale(1/rms); NewHistoEvent[count]->FFT(NewHistoEventFFT[count], "MAG"); NormNoiseFFT->Add(NormNoiseFFT, NewHistoEventFFT[count]); NewHistoEventFFT[count]->Write(); cout << "Event " << count+1 << " out of " << entriestotal << endl; count += 1; delete TempHisto; } } for (Int_t spill=1;spill<2;spill++) { cout << "Run 3905 Spill " << spill << endl; h4_3905->SetEntryList(0); TString listcut = "WF_ch==APD1 && amp_max[APD3]<25 && b_rms[APD3]<5. && charge_tot[APD3]<20000 && amp_max[APD5]<25 && b_rms[APD5]<5. && amp_max[APD6]<25 && b_rms[APD6]<5. && amp_max[APD4]<25 && b_rms[APD4]<5. && amp_max[SiPM1]<20 && amp_max[SiPM2]<20 && amp_max[APD1]<40 && amp_max[APD2]<40 && b_rms[APD1]<5. && b_rms[APD2]<5. && WF_time<160 && spill=="; listcut += spill; TString spillcut = "spill=="; spillcut += spill; h4_3905->Draw(">>myList", listcut, "entrylist"); TEntryList *myList = (TEntryList*) gDirectory->Get("myList"); h4_3905->SetEntryList(myList); Int_t entriesperspill = myList->GetN(); h4_3905->Draw("event", spillcut, "goff"); Double_t *vTemp = h4_3905->GetV1(); Double_t *vEvent = new Double_t[entriesperspill]; for (int iEntry = 0; iEntry<entriesperspill; iEntry++){ vEvent[iEntry] = vTemp[iEntry]; } Double_t mean, rms; TString plot, cut; for (j=0;j<entriesperspill;j++) { TString histoname = "Run3905TempHisto_"; histoname += spill; histoname += "_"; histoname += j; TH2F* TempHisto = new TH2F (histoname, "Temp Histo", nbins, -0.1, 159.9, 1000, -15, 15); plot = "WF_val:WF_time>>"; plot += histoname; cut = "WF_ch==APD1 && amp_max[APD3]<25 && b_rms[APD3]<5. && charge_tot[APD3]<20000 && amp_max[APD5]<25 && b_rms[APD5]<5. && amp_max[APD6]<25 && b_rms[APD6]<5. && amp_max[APD4]<25 && b_rms[APD4]<5. && amp_max[SiPM1]<20 && amp_max[SiPM2]<20 && amp_max[APD1]<40 && amp_max[APD2]<40 && b_rms[APD1]<5. && b_rms[APD2]<5. && WF_time<160 && spill=="; cut += spill; cut += " && event=="; cut += vEvent[j]; h4_3905->Draw(plot, cut, "goff"); TempHisto = (TH2F*) gDirectory->Get(histoname); if (TempHisto->GetMaximum() == 0) { continue; } HistoEvent[count] = transform2Dto1D(TempHisto); mean = TempHisto->GetMean(2); rms = TempHisto->GetRMS(2); for (Int_t q=0;q<nbins;q++) { NewHistoEvent[count]->SetBinContent(q+1, HistoEvent[count]->GetBinContent(q+1)-mean); } NewHistoEvent[count]->Scale(1/rms); NewHistoEvent[count]->FFT(NewHistoEventFFT[count], "MAG"); NormNoiseFFT->Add(NormNoiseFFT, NewHistoEventFFT[count]); HistoEvent[count]->Write(); NewHistoEventFFT[count]->Write(); cout << "Event " << count+1 << " out of " << entriestotal << endl; count += 1; delete TempHisto; } } TFile out("AllNormalizedNoiseFFT.root", "recreate"); NormNoiseFFT->Scale(1./count); NormNoiseFFT->Write(); t.Stop(); t.Print(); }