La seguente macro per root (cern) crea un istogramma,
sum
, che รจ la sottrazione di due istogrammi,
h2
e
h2_noise
, normalizzati tramite i fattori di scala
scale1
e
scale2
rispettivamente.
h2
e
h2_noise
sono riempiti con i valori dei rami etichettati con
ch2
nelle ntuple relative allo spettro (
spectrum.root
) e al fondo (
noise.root
) rispettivamente.
#if !defined(__CINT__) || defined(__MAKECINT__)
#include <riostream.h>
#include <stdlib.h>
#include <troot.h>
#include <tarrayi.h>
#include <tbranch.h>
#include <tcanvas.h>
#include <tclasstable.h>
#include <tclonesarray.h>
#include <tfile.h>
#include <tgeomanager.h>
#include <th1.h>
#include <th2.h>
#include <tstopwatch.h>
#include <tmath.h>
#include <tsystem.h>
#include <trandom.h>
#include <tinterpreter.h>
#include <tobject.h>
#include <tobjarray.h>
#include <ttree.h>
#include <tchain.h>
#include <tcanvas.h>
#include <tview.h>
#include <tntuple.h>
#include <tpolymarker3d.h>
#include <tfile.h>
#endif
void noise(char* infile1="sp_urto_Al.root",char* infile2="sp_urto_fondo.root", float scale1=1,float scale2=1.55)
{
float ch2;
int nentries;
TH1F *h2 =new TH1F("h2","h2",2048,0,2048);
TH1F *h2_noise =new TH1F("h2_noise","h2_noise",2048,0,2048);
TFile *fin=new TFile(infile1);
pjmca->SetBranchAddress("ch2",&ch2);
nentries=pjmca->GetEntries();
for(int i=0;i<nentries;i++){
pjmca->GetEntry(i);
h2->Fill(ch2);
}
h2->Scale(scale1);
TFile *fin=new TFile(infile2);
pjmca->SetBranchAddress("ch2",&ch2);
nentries=pjmca->GetEntries();
for(int i=0;i<nentries;i++){
pjmca->GetEntry(i);
h2_noise->Fill(ch2);
}
h2_noise->Scale(scale2);
TH1F *sum =new TH1F("sum","fondo sottratto",2048,0,2048);
sum->Add(h2,h2_noise,1,-1);
//Draw spectrum, noise, spectrum without noise:
//h2->SetLineColor(kGreen);
//h2->Draw();
//h2_noise->SetLineColor(kRed);
//h2_noise->Draw("same");
//sum->Draw("same");
//Draw spectrum without noise:
sum->Draw();
}
No comments:
Post a Comment