void analysis() { Int_t nbins = 800; Int_t j; char name[20]; char title[100]; TH1F *HistoEvent[2214]; for (Int_t z=0;z<2214;z++) { sprintf(name,"HistoEvent%d",z-1); sprintf(title,"Event%d Histo", z-1); HistoEvent[z] = new TH1F(name,title,nbins, -0.1, 159.9); } TH1F *NewHistoEvent[2214]; for (Int_t z=0;z<2214;z++) { sprintf(name,"NewHistoEvent%d",z-1); sprintf(title,"Event%d Histo", z-1); NewHistoEvent[z] = new TH1F(name,title,nbins, -0.1, 159.9); } TH1F *NewHistoEventFFT[2214]; for (Int_t z=0;z<2214;z++) { sprintf(name,"NewHistoEventFFT%d",z-1); sprintf(title,"Event%d Histo", z-1); NewHistoEventFFT[z] = new TH1F(name,title,nbins, 0, 5); } Double_t mean; Double_t rms; Double_t meansum = 0; Double_t count = 0; Double_t meanrms = 0; TFile f("/home/marko/H4Analysis/ntuples/analysis_4443.root"); //ntuple generated by H4Analysis tool TFile f1("/home/marko/H4Analysis/ntuples/analysis_3905.root"); TFile f2("/home/marko/Desktop/TB Timing Res/NormalizedSignalNoise.root", "read"); TH1F* BestSignal = (TH1F*) f2.Get("BetterSignal"); TFile outputfile("myoutput.root", "recreate"); TCanvas* TimeandFreq = new TCanvas("TimeandFreq","Time and Frequency",1500,900); TCanvas* Freq = new TCanvas("Freq","Frequency",800,1200); TCanvas* TimeSignal = new TCanvas("TimeSignal","Pure Signal",800,1200); TimeandFreq->Divide(2,2); TTree* h4 = (TTree*) f.Get("h4"); TTree* h4_2 = (TTree*) f1.Get("h4"); TString plot; TString cut; TH2F* WavePulse = new TH2F ("WavePulse", "Wave Pulse", nbins, -0.1, 159.9, 850, -50, 800); TH2F* NoisePulse = new TH2F ("NoisePulse", "Noise", nbins, -0.1, 159.9, 100, -50, 50); TH1F* PulseTime = new TH1F ("PulseTime", "Original Wave Pulse", nbins, -0.1, 159.9); //nanoseconds TH2F* TempHisto = new TH2F ("TempHisto", "Temp Histo", nbins, -0.1, 159.9, 1000, -15, 15); //nanoseconds h4->Draw("WF_val:WF_time>>WavePulse", "WF_ch==2 && event==1 && spill==1"); h4_2->Draw("WF_val:WF_time>>NoisePulse","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"); for (Int_t i=0; i<nbins; i++) { for (Int_t k=0; k<4096; k++) { if (WavePulse->GetBinContent(i+1, k) != 0) { PulseTime->SetBinContent(i+1,k-50); } } } TH1F *NoiseTime = new TH1F ("NoiseTime", "Noise", nbins, -0.1, 159.9); for (Int_t i=0; i<nbins; i++) { for (Int_t k=0; k<4096; k++) { if (NoisePulse->GetBinContent(i+1, k) != 0) { NoiseTime->SetBinContent(i+1,k-62.9087); } } } //TH1F* NormNoiseFFT = new TH1F ("NormNoiseFFT", "Normalized Noise FFT", nbins, 0, 5); //TStopwatch t; //t.Start(); //1 hour runtime //for (j=10;j<20;j++) { // plot = "WF_val:WF_time>>TempHisto"; // 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 && event=="; // cut += j; // h4_2->Draw(plot, cut, "goff"); // 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"); gPad->SetLogy(); TH1F* UnscaledSignalFreq = new TH1F ("UnscaledSignalFreq", "Unscaled Signal Frequency", nbins, -0.1, 799.9); for (Int_t l=0; l<nbins; l++) { UnscaledSignalFreq->SetBinContent(l+1, (PulseFreq->GetBinContent(l+1)-NoiseFreq->GetBinContent(l+1))/PulseFreq->GetBinContent(l+1)); } TH1F* SignalFreq = new TH1F ("SignalFreq", "Signal Frequency", nbins, 0, 799.9); for (Int_t m=0; m<nbins; m++) { SignalFreq->SetBinContent(m+1, UnscaledSignalFreq->GetBinContent(m+1)*PulseFreq->GetBinContent(m+1)); } Double_t *re_full = new Double_t[nbins]; Double_t *im_full = new Double_t[nbins]; for (Int_t n=0; n<nbins; n++) { (re_full)[n]=(SignalFreq->GetBinContent(n+1)*cos(PulsePhase->GetBinContent(n+1))); (im_full)[n]=(SignalFreq->GetBinContent(n+1)*sin(PulsePhase->GetBinContent(n+1))); } TVirtualFFT *invFFT = TVirtualFFT::FFT(1, &nbins, "C2R M K"); invFFT->SetPointsComplex(re_full, im_full); invFFT->Transform(); TH1 *Signal = 0; Signal = TH1::TransformHisto(invFFT,Signal,"Re"); Signal->SetTitle("Recovered Signal 'S'"); TH1F* BetterSignal = new TH1F ("BetterSignal", "Recovered Signal", nbins, -0.1, 159.9); for (Int_t p=0; p<nbins; p++) { BetterSignal->SetBinContent(p+1, Signal->GetBinContent(p+1)/nbins); } TimeSignal->Divide(1,2); TimeSignal->cd(1); PulseTime->DrawClone(); //Original Wave Pulse TimeSignal->cd(2); BetterSignal->GetXaxis()->SetTitle("Time (ns)"); BetterSignal->GetYaxis()->SetTitle("Amplitude"); BetterSignal->SetLineColor(kRed); //BetterSignal->Draw(); // Recovered Wave Pulse with decreased contribution from background noise BestSignal->SetLineColor(kGreen); BestSignal->DrawClone("same"); PulseTime->DrawClone("same"); }
void decon_ind(Int_t chan = 221){ TFile *file = new TFile("Run_00009188.root"); TH2* h1 = (TH2*)file->Get(Form("Ind_%d",chan)); TH2* h3 = (TH2*)h1->Clone("h3"); TH2* h4 = (TH2*)h1->Clone("h4"); h3->Reset(); h4->Reset(); gStyle->SetOptStat(0); TCanvas *c1 = new TCanvas("c1","c1",800,800); c1->Divide(2,2); c1->cd(1); h1->Draw("COLZ"); h1->GetZaxis()->SetRangeUser(-80,80); h1->GetXaxis()->SetRangeUser(0,3000); h1->SetTitle("Original Induction"); h3->SetTitle("Noise Removed Induction"); Int_t max_bin = h1->GetMaximumBin(); Float_t max = h1->GetBinContent(max_bin); Int_t min_bin = h1->GetMinimumBin(); Float_t min = h1->GetBinContent(min_bin); TH1F *h2 = new TH1F("h2","h2",Int_t(max - min+2), min-1, max+1); //cout << h1->GetXaxis()->GetNbins() << " " << h1->GetYaxis()->GetNbins() << endl; for (Int_t i=0;i!=h1->GetXaxis()->GetNbins();i++){ h2->Reset(); for (Int_t j=0;j!=h1->GetYaxis()->GetNbins();j++){ h2->Fill(h1->GetBinContent(i,j)); } Double_t xq = 0.5; Double_t par[10]; h2->GetQuantiles(1,&par[0],&xq); for (Int_t j=0;j!=h1->GetYaxis()->GetNbins();j++){ h3->SetBinContent(i,j,h1->GetBinContent(i,j)-par[0]); } //cout << par[0] << endl; } c1->cd(2); h3->Draw("COLZ"); h3->GetXaxis()->SetRangeUser(0,3000); // do deconvolution for every channel ... c1->cd(3); TFile *file1 = new TFile("ave_res.root"); TH1F *hva = (TH1F*)file1->Get("hu"); TGraph *gva = new TGraph(); for (Int_t i=0;i!=hva->GetNbinsX();i++){ Double_t x = hva->GetBinCenter(i+1); Double_t y = hva->GetBinContent(i+1) * (-1); gva->SetPoint(i,x,y); } TH1F *h2t = new TH1F("h2t","h2t",h1->GetXaxis()->GetNbins(),0,h1->GetXaxis()->GetNbins()); TH1F *h2r = (TH1F*)h2t->Clone("h2r"); h2r->Reset(); for (Int_t i=0;i!=h2r->GetNbinsX();i++){ Double_t x = h2r->GetBinCenter(i+1)/2.-50; h2r->SetBinContent(i+1,gva->Eval(x)); } TF1 *filter_v = new TF1("filter_v","(x>0.0)*gaus*exp(-0.5*pow(x/[3],[4]))"); double par1[5]={1.74/0.941034, 1.46, 1.33, 0.23, 4.89}; filter_v->SetParameters(par1); TVirtualFFT::SetTransform(0); TH1 *hmr = 0; TH1 *hpr = 0; Int_t n = 8192; TVirtualFFT *ifft = TVirtualFFT::FFT(1,&n,"C2R M K"); Double_t value_re[8192]; Double_t value_im[8192]; TH1 *fb = 0; TH1 *hmv = 0; TH1 *hpv = 0; for (Int_t k=0;k!=h1->GetYaxis()->GetNbins();k++){ // for (Int_t k=33;k!=33+1;k++){ h2t->Reset(); for (Int_t i=0;i!=8192;i++){ float content = h3->GetBinContent(i+1,k+1); h2t->SetBinContent(i+1,content); } h2t->Draw(); cout << h2t->Integral(500,1500) << endl; //cout << max << " " << min << endl; hmr = 0; hpr = 0; hmr = h2r->FFT(hmr,"MAG"); hpr = h2r->FFT(hpr,"PH"); hmv = 0; hpv = 0; hmv = h2t->FFT(hmv,"MAG"); hpv = h2t->FFT(hpv,"PH"); for (Int_t j=0;j!=8192;j++){ Double_t freq; if ( j < 8192/2.){ freq = j/8192.*2.; }else{ freq = (8192-j)/8192.*2.; } Double_t rho; if (hmr->GetBinContent(j+1)!=0){ rho = hmv->GetBinContent(j+1) / hmr->GetBinContent(j+1)*filter_v->Eval(freq); }else{ rho = 0; } Double_t phi = hpv->GetBinContent(j+1) - hpr->GetBinContent(j+1); value_re[j] = rho*cos(phi)/8192.; value_im[j] = rho*sin(phi)/8192.; } ifft->SetPointsComplex(value_re,value_im); ifft->Transform(); fb = 0; fb = TH1::TransformHisto(ifft,fb,"Re"); Double_t sum = 0; Double_t sum1 = 0; for (Int_t i=5000;i!=8000;i++){ sum += fb->GetBinContent(i+1); sum1 += 1; } for (Int_t i=0;i!=8192;i++){ Int_t binnum = i+1+104; if (binnum > 8192) binnum -=8192; h4->SetBinContent(binnum,k+1,fb->GetBinContent(i+1)-sum/sum1); } } h3->GetZaxis()->SetRangeUser(0,100); c1->cd(3); h4->RebinX(4); for (Int_t i=0;i!=h4->GetXaxis()->GetNbins();i++){ for (Int_t j=0;j!=h4->GetYaxis()->GetNbins();j++){ Double_t content1 = h4->GetBinContent(i+1,j+1); // if (content1 <1) // h4->SetBinContent(i+1,j+1,1); } } h4->Draw("COLZ"); h4->GetZaxis()->SetRangeUser(0,30); h4->GetXaxis()->SetRangeUser(0,3000); c1->cd(4); TH2 *h5 = (TH2*)file->Get(Form("Col_%d",chan)); h5->Draw("COLZ"); h5->GetZaxis()->SetRangeUser(0,300); h5->GetXaxis()->SetRangeUser(0,3000); c1->cd(2); for (Int_t i=0;i!=h3->GetXaxis()->GetNbins();i++){ for (Int_t j=0;j!=h3->GetYaxis()->GetNbins();j++){ Double_t content1 = h3->GetBinContent(i+1,j+1); content1 = fabs(content1); h3->SetBinContent(i+1,j+1,content1); } } h3->Draw("COLZ"); h4->SetTitle("Deconvoluted Induction"); h5->SetTitle("Collection Raw"); // c1->cd(1); // h2r->Draw(); // c1->cd(4); // Double_t sum = 0; // Double_t sum1 = 0; // for (Int_t i=4000;i!=7000;i++){ // sum += fb->GetBinContent(i+1); // sum1 += 1; // } // TH1F *h2k = (TH1F*)h2t->Clone("h2k"); // for (Int_t j=0;j!=8192;j++){ // h2k->SetBinContent(j+1,fb->GetBinContent(j+1)-sum/sum1); // } // h2k->Rebin(4); // h2k->Draw(); }