//This macro is coincidence analysis, subtracting background spectra from a gated spectrum and analyzing the remaining peaks. #include #include #include #include #include #include #include "TH2.h" #include "TH1.h" #include "TRandom.h" #include "iostream" #include #include "TObjArray.h" #include "TF1.h" #include "TSpectrum.h" #include "TVirtualFitter.h" #include "Riostream.h" TObjArray List1; TObjArray List2; TObjArray List3; void bgs(){ // func = Gate - 0.5(background_gate + background_gate_2) -> function used to subtract out the gated peak of interest (POI). // Retrieve the histogram: TFile *file = new TFile("out_gate_2270_2570_2070_2170_2670_2770.root"); // Create a new canvas: TCanvas * c0 = new TCanvas("c0", "64Ni 8.7MeV Coincidence Analysis", 10,10, 800, 800); // Create a THStack object to hold the histograms: THStack * stack = new THStack("stack", "Stacked Histograms"); // Placing multiple histograms on the same canvas: TH1D * gate_hist=new TH1D("gatehist","gatehist",4096,-2.0,16382.0); TH1D * avg_bg=new TH1D("avg_bg","avg_bg",4096,-2.0,16382.0); TH1D * gated_bgs=new TH1D("gated_bgs","gate_bgs",4096,-2.0,16382.0); TH1D * gated_cal=new TH1D("gated_cal","gate_Cal",4096,-2.0,16382.0);//calibrated spectrum // Placing in the gated spectra: c0->Divide(2,3); c0->cd(1); gPad->SetLogy(0);//Linear(0), Log(1) gate_hist->Add(gate,1); gate_hist->Draw(); // Placing the background regions into the canvas then subtract the gated_spectrum from the avg_bg (scale factor determined in hdtv). Adding the background spectra (pad2): c0->cd(2); gPad->SetLogy(0);//Linear(0), Log(1) avg_bg->Add(background_gate,0.5); avg_bg->Add(background_gate_2,0.5); avg_bg->Draw(); // Subtracting gate from avg_bg into pad3: // Scaling factors to normalize the avg_bg: // projx scaling: 1345 -> 1.693 , 2276 -> 1.7, 2610 -> 1.25, 2867 -> 1.453, 3025 -> 1.792, 3463 -> 1.406 //Log and Linear histograms: TH1D * log_cal = new TH1D("log_cal","log_cal",4096,-2.0,16382.0);//log spectrum TH1D * linear_cal = new TH1D("linear_cal","linear_cal",4096,-2.0,16382.0);//linear spectrum // Base and Transparent pad to place a log and linear graph on the same plot: TPad * Blog_pad = new TPad("log","LogHist",0,0,1,1);//log spectrum Blog_pad->SetFillColor(0); Blog_pad->SetFillStyle(0); TH1D * linear_padT = new TH1D("lin","LinHist",4096,-2.0,16382.0);//linear spectrum // Linear pad: c0->cd(3); //linear_cal->GetYaxis()->SetRangeUser(0, linear_cal->GetMaximum() * 1.1); gPad->SetLogy(0);//Linear(0), setting the y-axis scale linear_cal->Add(gate_hist,1); linear_cal->Add(avg_bg,-1); linear_cal->Add(avg_bg,-1.7); linear_cal->SetLineColor(kBlack); linear_cal->GetYaxis()->SetTitle("Hist 1 axis label"); linear_cal->GetXaxis()->SetTitle("x axis label"); linear_cal->GetYaxis()->SetTitle("Left y axis label"); linear_cal->SetMarkerStyle(kFullCircle); linear_cal->Draw(); // Log pad: c0->cd(4); //log_cal->GetYaxis()->SetRangeUser(0, linear_cal->GetMaximum() * 1.1); gPad->SetLogy(1);//Log(1) log_cal->Add(gate_hist,1); log_cal->Add(avg_bg,-1); log_cal->Add(avg_bg,-1.7); log_cal->GetYaxis()->SetTitle("Right y axis label"); log_cal->GetYaxis()->SetTitleOffset(1.3); log_cal->SetLineColor(kBlue); log_cal->SetMarkerColor(kBlue); log_cal->SetMarkerStyle(kOpenCircle); log_cal->Draw(); // Create a TMultiGraph to hold the log and linear graphs: //TMultiGraph * mg = new TMultiGraph(); //TGraph * linear_graph = new TGraph(linear_cal); //linear_graph->SetLineColor(kBlack); //mg->Add(linear_graph); //TGraph * log_graph = new TGraph(log_cal); //log_graph->SetLineColor(kBlue); //mg->Add(log_graph); // Draw the TMultiGraph on the canvas: //c0->cd(3); //gPad->SetLogy(0); //mg->Draw("a"); // Add the first histogram to the pad -linear: //c0->cd(5); linear_cal->Add(gate_hist,1); linear_cal->Add(avg_bg,-1); linear_cal->Add(avg_bg,-1.7); linear_cal->SetLineColor(kBlack); linear_cal->GetYaxis()->SetTitle("Hist 1 axis label"); linear_cal->GetXaxis()->SetTitle("x axis label"); linear_cal->GetYaxis()->SetTitle("Left y axis label"); linear_cal->GetYaxis()->SetRangeUser(1e-16, 1.4); linear_cal->SetMarkerStyle(kFullCircle); linear_cal->Draw(); //linear_padT->SetFillColor(0); //linear_padT->SetFillStyle(0); //gPad->SetLogy(0);//Linear(0) //linear_cal->Add(gate_hist,1); //linear_cal->Add(avg_bg,-1); //linear_cal->Add(avg_bg,-1.7); //linear_padT->GetYaxis()->SetTitle("Hist 1 axis label"); //linear_padT->GetXaxis()->SetTitle("x axis label"); //linear_padT->GetYaxis()->SetTitle("Left y axis label"); //linear_padT->SetLineColor(kGreen); //stack->Add(linear_cal); // Add the second histogram to the pad-log: //gPad->SetLogy(1);// Log(1) Blog_pad->Draw(); Blog_pad->cd(); Blog_pad->SetTicks(0,0); Blog_pad->SetLogy(0); log_cal->GetYaxis()->SetTitle("Right y axis label"); log_cal->GetYaxis()->SetTitleOffset(1.3); log_cal->GetYaxis()->SetRangeUser( 1e-2, 20); log_cal->SetLineColor(kBlue); log_cal->Draw("Y+"); //stack->Add(log_cal); // Draw the stacked histograms: //stack->Draw("stack"); // Add a legend: //TLegend* legend = new TLegend(0.1, 0.7, 0.3, 0.9); //legend->SetHeader("Legend Title","C");//"C" options centers the header //legend->AddEntry(log_cal, "Log", "l"); //legend->AddEntry(linear_cal, "Linear", "l"); //legend->Draw(); // Update the canvas c0->Update(); }