本文整理汇总了C++中TH1F::DrawClone方法的典型用法代码示例。如果您正苦于以下问题:C++ TH1F::DrawClone方法的具体用法?C++ TH1F::DrawClone怎么用?C++ TH1F::DrawClone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TH1F
的用法示例。
在下文中一共展示了TH1F::DrawClone方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ExampleMacro
/*
* From here on, the code can also be used as a macro
* Note though, that CINT may report errors where there are none
in C++. E.g. this happens here where CINT says that f1 is
out of scope ...
==>> put your code here
(remember to update the name of you Macro in the
lines above if you intend to comile the code)
*/
void ExampleMacro() {
// Create a histogram, fill it with random gaussian numbers
TH1F *h = new TH1F ("h", "example histogram", 100, -5.,5.);
h->FillRandom("gaus",1000);
// draw the histogram
h->DrawClone();
/* - Create a new ROOT file for output
- Note that this file may contain any kind of ROOT objects, histograms,
pictures, graphics objects etc.
- the new file is now becoming the current directory */
TFile *f1 = new TFile("ExampleMacro.root","RECREATE","ExampleMacro");
// write Histogram to current directory (i.e. the file just opened)
h->Write();
// Close the file.
// (You may inspect your histogram in the file using the TBrowser class)
f1->Close();
}
示例2: SPEFit
//.........这里部分代码省略.........
double minbin_location = hspe->GetBinCenter(minbin);
hspe->GetXaxis()->SetRange(1,Nbins);
TF1 *fit = new TF1("fit", FitFun, 0, 500, 5);
double mu = - log(fped->Integral(0,100)/Nev);
if(mu<0) mu=0.01;
double gain_est = max_SPE_location-1.0*fped->GetParameter(1);
if(max_SPE_bin > (minbin+1)) fit->SetParameters(mu, 20, 1, gain_est, gain_est*0.5);
else fit->SetParameters(mu, 20, 1, 2.1*fped->GetParameter(2), 10); //case of no clear minimum; start looking for SPE peak at 2sigma away from pedestal peak
fit->SetParLimits(0, 0, 10);
fit->FixParameter(1, fped->GetParameter(1));
fit->FixParameter(2, fped->GetParameter(2));
fit->SetParLimits(3, fped->GetParameter(2)*2, 350);
fit->SetParLimits(4, fped->GetParameter(2)*1.01, 250);
double maxfitrange = 500.;
double minfitrange = 0.;
hspe->Fit(fit, "MNQL", "", minfitrange, maxfitrange);
maxfitrange = fped->GetParameter(1)+4*fit->GetParameter(3)+fit->GetParameter(4);
if(500<maxfitrange) maxfitrange = 500;
hspe->Fit(fit, "MNQL", "", minfitrange, maxfitrange);
//calculate NDOF of fit excluding bins with 0 entries
int myNDOF=-3; //three free parameters
for(int j=hspe->FindBin(minfitrange); j<=hspe->FindBin(maxfitrange); j++) { //loop through fitted spe bins
if(hspe->GetBinContent(j)) myNDOF++;
} //loop through fitted spe bins
//calculate means and integrals of the fit and data
double fint, fint_error, hint, favg, havg;
int temp_lowbin, temp_highbin;
temp_lowbin = hspe->FindBin(minfitrange);
temp_highbin = hspe->FindBin(maxfitrange);
hspe_unscaled->GetXaxis()->SetRangeUser(minfitrange, maxfitrange);
havg = hspe_unscaled->GetMean();
hint = hspe->Integral(temp_lowbin,temp_highbin,"width");
double min_frange = hspe->GetBinLowEdge(temp_lowbin);
favg = fit->Mean(min_frange, maxfitrange);
fint = fit->Integral(min_frange, maxfitrange);
//fint_error = fit->IntegralError(min_frange, maxfitrange);
double PE5int = 0; //integral of events with >=5 PE
double PE5loc = fped->GetParameter(1)+ 5*fit->GetParameter(3);
if(PE5loc>500) PE5int = 0;
else {
int PE5bin = hspe_temp->FindBin(PE5loc);
temp_highbin = hspe_temp->FindBin(maxfitrange)-1;
PE5int = hspe_temp->Integral(PE5bin,temp_highbin,"width");
}
int PE5flag = 0;
if(PE5int/hint>0.05) PE5flag = 1; //set flag if more than 5% of events in the fit correspond to >=5PE
//=========================================
//for(int i1=1;i1<hspe->GetNbinsX();i1++){
//constants_file1<<HV<<"\t"<<iDepth<<"\t"<<iEta<<"\t"<<iPhi<<"\t"<<2.6*hspe->GetBinCenter(i1)<<"\t"<<hspe->GetBinContent(i1)<<"\t"<<fit->Eval(hspe->GetBinCenter(i1))<<"\n";
//}
//=========================================
//printf("%d\n",myNDOF);
//output calibrations constants
//constants_file<<endl<<"LED_amplitude HV Spigot Channel Ped_mean Ped_mean_err Ped_RMS Ped_RMS_err SPEPeak_RMS SPEPeak_RMS_err Gain Gain_err Normalized_Chi2 MeanPE_fit MeanPE_fit_err MeanPE_estimate PE5flag"<<endl;
constants_file<<LED_amp<<" "<<iDepth<<" "<<iPhi<<" "<<iEta<<" "<<scale*fped->GetParameter(1)<<" "<<scale*fped->GetParError(1)<<" "<<scale*fped->GetParameter(2)<<" "<<scale*fped->GetParError(2)<<" "<<scale*fit->GetParameter(4)<<" "<<scale*fit->GetParError(4)<<" "<<scale*fit->GetParameter(3)*fC2electrons<<" "<<scale*fit->GetParError(3)*fC2electrons<<" "<<fit->GetChisquare()/myNDOF/*fit->GetNDF()*/<<" "<<fit->GetParameter(0)<<" "<<fit->GetParError(0)<<" "<<mu<<" "<<PE5flag<<endl;
/*
if(iDepth==2 && iPhi==53 && iEta==36){
cout<<iDepth<<" "<<iPhi<<" "<<iEta<<" "<<gain_est<<" "<<fit->GetParameter(3)<<endl;
cout<<LED_amp<<" "<<iDepth<<" "<<iPhi<<" "<<iEta<<" "<<scale*fped->GetParameter(1)<<" "<<scale*fped->GetParError(1)<<" "<<scale*fped->GetParameter(2)<<" "<<scale*fped->GetParError(2)<<" "<<scale*fit->GetParameter(4)<<" "<<scale*fit->GetParError(4)<<" "<<scale*fit->GetParameter(3)*fC2electrons<<" "<<scale*fit->GetParError(3)*fC2electrons<<" "<<fit->GetChisquare()/myNDOF<<" "<<fit->GetParameter(0)<<" "<<fit->GetParError(0)<<" "<<mu<<" "<<PE5flag<<endl;
}
*/
Carray[iDepth][iPhi]->cd(iEta-MinEta+1);
gPad->SetBorderMode(0);
gPad->SetBorderSize(0);
gPad->SetRightMargin(0.01);
gPad->SetBottomMargin(0.1);
gPad->SetLogy(true);
hspe->GetXaxis()->SetRangeUser(0, 200 /*300*//*508*/);
hspe->SetLineColor(kBlue);
hspe->DrawClone("hist");
fit->SetLineWidth(2);
fit->Draw("same");
}
if(drawflag[iDepth][iPhi]) { //draw plots of fit if data for the HV is present
stringstream plot_name;
plot_name<<"Plots/SPEFits_Run_"<<run<<"_Depth"<<iDepth<<"_Phi"<<iPhi<<".pdf";
Carray[iDepth][iPhi]->SaveAs(plot_name.str().c_str());
plot_name.str( std::string() );
}
}
}
constants_file.close();
//constants_file1.close();
}
示例3: analysis
//.........这里部分代码省略.........
// if (TempHisto->GetMaximum() == 0) {
// delete HistoEvent[j+1];
// continue;
// }
// for (Int_t i=0; i<nbins; i++) {
// for (Int_t k=0; k<1000; k++) {
// if (TempHisto->GetBinContent(i+1, k) != 0) {
// HistoEvent[j+1]->SetBinContent(i+1,k*0.03-15);
// }
// }
// }
// mean = TempHisto->GetMean(2);
// rms = TempHisto->GetRMS(2);
// for (Int_t q=0;q<nbins;q++) {
// NewHistoEvent[j+1]->SetBinContent(q+1, HistoEvent[j+1]->GetBinContent(q+1)-mean);
// }
// NewHistoEvent[j+1]->Scale(1/rms);
// NewHistoEvent[j+1]->FFT(NewHistoEventFFT[j+1], "MAG");
// NormNoiseFFT->Add(NormNoiseFFT, NewHistoEventFFT[j+1]);
// TempHisto->Write();
// NewHistoEvent[j+1]->Write();
// NewHistoEventFFT[j+1]->Write();
// cout << "Event " << j << ", Mean = " << mean << ", RMS = " << rms << endl;
// count += 1;
//}
//NormNoiseFFT->Scale(1/count);
//NormNoiseFFT->Write();
//t.Stop();
//t.Print();
new TFile("/home/marko/H4Analysis/ntuples/analysis_4443.root"); // ignore this reloading of the same file, it is required or else the plots do not show up (when I tried)
TimeandFreq->cd(1);
PulseTime->GetXaxis()->SetTitle("Time (ns)");
PulseTime->GetYaxis()->SetTitle("Amplitude");
PulseTime->DrawClone(); //Wave Pulse in Time domain
TimeandFreq->cd(2);
TH1F* PulseFreq = new TH1F ("PulseFreq", "Pulse FFT", nbins, 0, 5);
TH1F* PulsePhase = new TH1F ("PulsePhase", "Pulse Phase", nbins, -0.1, 799.9);
PulseTime->FFT(PulseFreq, "MAG");
PulseTime->FFT(PulsePhase, "PH");
PulseFreq->SetLineColor(kRed);
PulseFreq->GetXaxis()->SetTitle("Frequency (GHz)");
PulseFreq->GetYaxis()->SetTitle("Amplitude");
PulseFreq->DrawClone(); //Wave Pulse in Frequency domain
gPad->SetLogy();
TimeandFreq->cd(3);
NoiseTime->GetXaxis()->SetTitle("Time (ns)");
NoiseTime->GetYaxis()->SetTitle("Amplitude");
NoiseTime->DrawClone(); // Noise from pedestal in Time domain
TimeandFreq->cd(4);
TH1F* NoiseFreq = new TH1F ("NoiseFreq", "Noise FFT", nbins, 0, 5);
NoiseTime->FFT(NoiseFreq, "MAG");
NoiseFreq->GetXaxis()->SetTitle("Frequency (GHz)");
NoiseFreq->GetYaxis()->SetTitle("Amplitude");
NoiseFreq->Draw(); // Noise from pedestal in Frequency domain
gPad->SetLogy();
Freq->Divide(1,3);
Freq->cd(1);
PulseFreq->DrawClone();
gPad->SetLogy();
Freq->cd(2);
NoiseFreq->DrawClone();
gPad->SetLogy();
Freq->cd(3);
PulseFreq->SetTitle("Pulse and Noise FFT Comparison");
PulseFreq->Draw();
NoiseFreq->Draw("same");
示例4: SPEFit
//.........这里部分代码省略.........
int myNDOF=-3; //three free parameters
for(int j=hspe->FindBin(minfitrange); j<=hspe->FindBin(maxfitrange); j++) { //loop through fitted spe bins
if(hspe->GetBinContent(j)) myNDOF++;
} //loop through fitted spe bins
// cout<<"estimate of gain "<<gain_est<<", fit "<<fit->GetParameter(3)<<endl;
// cout<<"Shape Parameter "<<fit->GetParameter(4)<<endl;
// double SPE_rms = fit->GetParameter(3)/sqrt(fit->GetParameter(4));
// cout<<"SPE width "<<SPE_rms<<endl;
//cout<<"SPE width "<<fit->GetParameter(4)<<endl;
//cout<<"Fit normalization constant: estimate "<<mu<<" fit "<<fit->GetParameter(0)<<endl;
//cout<<spename<<endl;
//calculate means and integrals of the fit and data
double fint, fint_error, hint, favg, havg;
int temp_lowbin, temp_highbin;
temp_lowbin = hspe->FindBin(minfitrange);
temp_highbin = hspe->FindBin(maxfitrange);
hspe_unscaled->GetXaxis()->SetRangeUser(minfitrange, maxfitrange);
havg = hspe_unscaled->GetMean();
hint = hspe->Integral(temp_lowbin,temp_highbin,"width");
double min_frange = hspe->GetBinLowEdge(temp_lowbin);
favg = fit->Mean(min_frange, maxfitrange);
fint = fit->Integral(min_frange, maxfitrange);
//fint_error = fit->IntegralError(min_frange, maxfitrange);
double PE5int = 0; //integral of events with >=5 PE
double PE5loc = fped->GetParameter(1)+ 5*fit->GetParameter(3);
if(PE5loc>500) PE5int = 0;
else {
int PE5bin = hspe_temp->FindBin(PE5loc);
temp_highbin = hspe_temp->FindBin(maxfitrange)-1;
PE5int = hspe_temp->Integral(PE5bin,temp_highbin,"width");
}
int PE5flag = 0;
if(PE5int/hint>0.05) PE5flag = 1; //set flag if more than 5% of events in the fit correspond to >=5PE
//=========================================
for(int i1=1;i1<hspe->GetNbinsX();i1++){
constants_file1<<HV<<"\t"<<iSpig<<"\t"<<i<<"\t"<<2.6*hspe->GetBinCenter(i1)<<"\t"<<hspe->GetBinContent(i1)<<"\t"<<fit->Eval(hspe->GetBinCenter(i1))<<"\n";
}
//=========================================
//output calibrations constants
//constants_file<<endl<<"LED_amplitude HV Spigot Channel Ped_mean Ped_mean_err Ped_RMS Ped_RMS_err SPEPeak_RMS SPEPeak_RMS_err Gain Gain_err Normalized_Chi2 MeanPE_fit MeanPE_fit_err MeanPE_estimate PE5flag Polya_shape Polya_shape_err Polya_mode"<<endl;
constants_file<<LED_amp<<" "<<HV<<" "<<iSpig<<" "<<(bb-1)*8+pmt<<" "<<scale*fped->GetParameter(1)<<" "<<scale*fped->GetParError(1)<<" "<<scale*fped->GetParameter(2)<<" "<<scale*fped->GetParError(2)<<" "<<scale*fit->GetParameter(3)/sqrt(fit->GetParameter(4))<<" "<<0<<" "<<scale*fit->GetParameter(3)*fC2electrons<<" "<<scale*fit->GetParError(3)*fC2electrons<<" "<<fit->GetChisquare()/myNDOF/*fit->GetNDF()*/<<" "<<fit->GetParameter(0)<<" "<<fit->GetParError(0)<<" "<<mu<<" "<<PE5flag<<" "<<fit->GetParameter(4)<<" "<<fit->GetParError(4)<<" "<<scale*(fit->GetParameter(4)-1.0)/fit->GetParameter(4)*fit->GetParameter(3)*fC2electrons<<endl;
// cout<<LED_amp<<" "<<HV<<" "<<iSpig<<" "<<QIECh[i]<<" "<<scale*fped->GetParameter(1)<<" "<<scale*fped->GetParError(1)<<" "<<scale*fped->GetParameter(2)<<" "<<scale*fped->GetParError(2)<<" "<<scale*fit->GetParameter(4)<<" "<<scale*fit->GetParError(4)<<" "<<scale*fit->GetParameter(3)*fC2electrons<<" "<<scale*fit->GetParError(3)*fC2electrons<<" "<<fit->GetChisquare()/fit->GetNDF()<<" "<<fit->GetChisquare()<<" "<<fit->GetNDF()<<" "<<myNDOF<<" "<<fit->GetParameter(0)<<" "<<fit->GetParError(0)<<" "<<mu<<endl;
//extra_file<<endl<<"LED_amplitude HV Spigot Channel SignalAvg_inFitRange FitAvg_inFitRange SignalInt_inFitRange FitInt_inFitRange PEge5Int Gain(fC) Gain_err Normalized_Chi2 MeanPE_fit MeanPE_fit_err MeanPE_estimate PE5flag"<<endl;
//extra_file<<LED_amp<<" "<<HV<<" "<<iSpig<<" "<<QIECh[i]<<" "<<scale*havg<<" "<<scale*favg<<" "<<hint<<" "<<fint<<" "<<PE5int<<" "<<scale*fit->GetParameter(3)<<" "<<scale*fit->GetParError(3)<<" "<<fit->GetChisquare()/myNDOF<<" "<<fit->GetParameter(0)<<" "<<fit->GetParError(0)<<" "<<mu<<" "<<PE5flag<<endl;
//cout<<"# Spigot Channel Ped_mean Ped_RMS SPE_PeakRMS Gain Normalized_Chi2 Avg_PE"<<endl;
//cout<<iSpig<<" "<<i<<" "<<scale*fped->GetParameter(1)<<" "<<scale*fped->GetParameter(2)<<" "<<scale*fit->GetParameter(4)<<" "<<scale*fit->GetParameter(3)*fC2electrons<<" "<<fit->GetChisquare()/fit->GetNDF()<<" "<<fit->GetParameter(0)<<endl<<endl;
if(iSpig==0) c1->cd(i+1);
else if(iSpig==1) c2->cd(i+1);
else if(iSpig==2) c3->cd(i+1);
gPad->SetBorderMode(0);
gPad->SetBorderSize(0);
gPad->SetRightMargin(0.01);
gPad->SetBottomMargin(0.1);
gPad->SetLogy(true);
hspe->GetXaxis()->SetRangeUser(0, /*300*/508);
hspe->SetLineColor(kBlue);
hspe->DrawClone("hist");
fit->SetLineWidth(2);
fit->Draw("same");
}
}
if(drawflag) { //draw plots of fit if data for the HV is present
stringstream plot_name;
//plot_name<<"Plots/SPEFits_Spigot0_Run_"<<run<<"_HV"<<HV<<".pdf";
plot_name<<"Plots/SPEFits_Spigot0_Run_"<<run<<"_HV"<<HV<<"_config"<<ii<<".pdf";
c1->SaveAs(plot_name.str().c_str());
plot_name.str( std::string() );
//plot_name<<"Plots/SPEFits_Spigot1_Run_"<<run<<"_HV"<<HV<<".pdf";
plot_name<<"Plots/SPEFits_Spigot1_Run_"<<run<<"_HV"<<HV<<"_config"<<ii<<".pdf";
c2->SaveAs(plot_name.str().c_str());
plot_name.str( std::string() );
//plot_name<<"Plots/SPEFits_Spigot2_Run_"<<run<<"_HV"<<HV<<".pdf";
plot_name<<"Plots/SPEFits_Spigot2_Run_"<<run<<"_HV"<<HV<<"_config"<<ii<<".pdf";
c3->SaveAs(plot_name.str().c_str());
}
} //HV loop
constants_file.close();
constants_file1.close();
}
示例5: readTree_background
void readTree_background() {
Char_t *filename = "Background.root";
// Retrieve the TTree
TFile* myFile = TFile::Open(filename);
TTree* tree = (TTree*)(myFile->Get("tree"));
Double_t Et1, eta1, phi1, Et2, eta2, phi2;
tree->SetBranchAddress("Et1" ,&Et1 );
tree->SetBranchAddress("eta1",&eta1);
tree->SetBranchAddress("phi1",&phi1);
tree->SetBranchAddress("Et2" ,&Et2 );
tree->SetBranchAddress("eta2",&eta2);
tree->SetBranchAddress("phi2",&phi2);
// Book histograms
TH1F* hmass = new TH1F("hmass","m_{#gamma#gamma}",60,100.,160.);
hmass->GetXaxis()->SetTitle("Invariant mass [GeV]");
hmass->GetYaxis()->SetTitle("Events");
// Loop over the events
Long64_t events = tree->GetEntries();
for (int i=0; i<events; i++) {
tree->GetEntry(i);
TLorentzVector g1,g2;
g1.SetPtEtaPhiM(Et1,eta1,phi1,0.);
g2.SetPtEtaPhiM(Et2,eta2,phi2,0.);
TLorentzVector gg=g1+g2;
hmass->Fill( gg.M() );
}
// Test of different background options
hmass->DrawClone("e");
TCanvas* myCanvas = new TCanvas("myCanvas","Background fits",800,800);
myCanvas->Divide(2,2);
// Linear background
TF1* myBack1 = new TF1("myBack1","[0]+[1]*x",100.,160.);
myBack1->SetParameter(0,events);
myBack1->SetParameter(1,-100.);
myCanvas->cd(1);
hmass->Fit(myBack1);
hmass->DrawClone("e");
EvaluatePvalue(myBack1);
// Quadratic background
TF1* myBack2 = new TF1("myBack2","[0]+[1]*x+[2]*x**2",100.,160.);
myBack2->SetParameter(0,events);
myBack2->SetParameter(1,-100.);
myBack2->SetParameter(1,0.);
myCanvas->cd(2);
hmass->Fit(myBack2);
hmass->DrawClone("e");
EvaluatePvalue(myBack2);
// Exponential background
TF1* myBack3 = new TF1("myBack3","[0]*exp(-x/[1])",100.,160.);
myBack3->SetParameter(0,events);
myBack3->SetParameter(1,100.);
myCanvas->cd(3);
hmass->Fit(myBack3);
hmass->DrawClone("e");
EvaluatePvalue(myBack3);
// Cubic background
TF1* myBack4 = new TF1("myBack4","[0]+[1]*x+[2]*x**2+[3]*x**3",100.,160.);
myBack4->SetParameter(0,0.);
myBack4->SetParameter(1,0.);
myBack4->SetParameter(2,0.);
myBack4->SetParameter(3,0.);
myCanvas->cd(4);
TFitResultPtr fit4 = hmass->Fit(myBack4,"S");
hmass->DrawClone("e");
EvaluatePvalue(myBack4);
}
示例6: main
//.........这里部分代码省略.........
sprintf(name, "Good Events/Event%d", vEvent[i]);
strcat(name, ".png");
h1001->SetLineColor(kRed);
h1002->SetLineColor(kBlue);
h1001->SetStats(0);
h1002->SetStats(0);
//can1->cd(1);
can1->cd();
h1001->GetXaxis()->SetTitle("Time (ns)");
h1001->GetYaxis()->SetTitle("Amplitude");
h1001->Draw();
h1002->Draw("same");
//for (Int_t i=0;i<nbins;i++) {
// h1003->SetBinContent(i+1, (h1002->GetBinContent(i+1))-(h1001->GetBinContent(i+1)));
// if (h1001->GetBinContent(i+1) != 0) h1004->SetBinContent(i+1, ((h1002->GetBinContent(i+1))-(h1001->GetBinContent(i+1)))/(h1001->GetBinContent(i+1)));
// else h1004->SetBinContent(i+1, 0);
//}
//can1->cd(2);
//h1003->Draw();
//can1->cd(3);
//h1004->Draw();
//h1004->GetYaxis()->SetRangeUser(-0.1,0.1);
//gPad->SetGrid();
can1->SaveAs(name);
//h1002->FFT(h1002fft, "MAG");
//h1002->FFT(h1002ph, "PH");
//histoavefft->Add(histoavefft, h1002fft);
//histoaveph->Add(histoaveph, h1002ph);
histoave->Add(histoave, h1002);
can2->cd(2);
h1002->Scale(1./(h1002->GetMaximum()));
h1002->Draw("same");
count++;
delete TempHisto, TempHisto2, h1001, h1002, h1003, h1004, histoname, histoname2, h1name, h1name2, h1name3, h1name4;
gDirectory->Clear();
}
can2->cd(1);
//histoavefft->Scale(1./count);
//histoaveph->Scale(1./count);
histoave->Scale(1./count);
//Double_t *re_full = new Double_t[nbins];
//Double_t *im_full = new Double_t[nbins];
//TH1 *Throwaway = 0;
//TH1F *invhistoave = new TH1F(invhistoave, "Average Pulse", nbins, -40, 120);
//TVirtualFFT *invFFT = TVirtualFFT::FFT(1, &nbins, "C2R M K");
//for (Int_t n=0; n<nbins; n++) {
// (re_full)[n]=(histoavefft->GetBinContent(n+1)*cos(histoaveph->GetBinContent(n+1)));
// (im_full)[n]=(histoavefft->GetBinContent(n+1)*sin(histoaveph->GetBinContent(n+1)));
//}
//invFFT->SetPointsComplex(re_full, im_full);
//invFFT->Transform();
//Throwaway = TH1::TransformHisto(invFFT, Throwaway, "Re");
//for (Int_t p=0; p<nbins; p++) {
// histoave->SetBinContent(p+1, Throwaway->GetBinContent(p+1)/nbins);
//}
histoave->Scale(1./(histoave->GetMaximum()));
histoave->SetLineColor(kRed);
histoave->SetLineWidth(4);
integral = templatehisto->Integral();
templatehisto->Scale(1./integral);
templatehisto->SetStats(0);
templatehisto->Draw();
integral = histoave->Integral();
histoave->Scale(1./integral);
histoave->DrawClone("same");
histoave->Scale(integral);
can2->cd(2);
histoave->GetXaxis()->SetTitle("Time (ns)");
histoave->GetYaxis()->SetTitle("Normalized Amplitude");
histoave->DrawClone("same");
can2->SaveAs("AmpSpread.png");
can2->SaveAs("AmpSpreadRoot.root");
TFile *output = new TFile("Alignment.root", "recreate");
output->cd();
originaltemplate->Write();
histoave->Write();
templatehisto->Write();
output->Close();
can3->cd(1);
histoave->Scale(1./integral);
for (int i=0;i<nbins;i++) {
difference->SetBinContent(i+1, histoave->GetBinContent(i+1) - templatehisto->GetBinContent(i+1));
if (templatehisto->GetBinContent(i+1) != 0) percentdifference->SetBinContent(i+1, (histoave->GetBinContent(i+1) - templatehisto->GetBinContent(i+1))/templatehisto->GetBinContent(i+1));
else percentdifference->SetBinContent(i+1, 0);
}
difference->GetXaxis()->SetTitle("Time (ns)");
difference->GetYaxis()->SetTitle("Average - Template");
difference->SetStats(0);
difference->Draw();
can3->cd(2);
percentdifference->GetXaxis()->SetTitle("Time (ns)");
percentdifference->GetYaxis()->SetTitle("Percent Difference Average - Template");
percentdifference->SetStats(0);
percentdifference->Draw();
percentdifference->GetYaxis()->SetRangeUser(-0.1,0.1);
gPad->SetGrid();
can3->SaveAs("Difference.png");
can3->SaveAs("Difference.root");
}