1 const char* infileA=
"links/P01hf.nofield.refitOS.slice/dip5.typec.slice.root";
2 const char* infileB=
"links/P01hf.nofield.2230026.noExB.refitOS.slice/dip5.typec.slice.root";
3 const char* outfile=
"links/P01hf.nofield.refitOS.slice/dip5.typec.slice.ExBsubNoExB.root";
4 void subtract(
const char* inFileA=infileA,
5 const char* inFileB=infileB,
6 const char* outFile=outfile)
8 cout <<
"infileA=" << inFileA << endl
9 <<
"infileB=" << inFileB << endl
10 <<
"outFile=" << outFile << endl;
12 TFile inRootA(inFileA);
if(!inRootA.IsOpen())
return;
13 TFile inRootB(inFileB);
if(!inRootB.IsOpen())
return;
14 TFile outRoot(outFile,
"RECREATE");
if(!outRoot)
return;
16 TIterator* iterator = inRootA.GetListOfKeys()->MakeIterator();
19 while( (key=dynamic_cast<TKey*>(iterator->Next())) != 0){
21 TH1 *hA=0,*hB=0,*hOut=0;
22 hA = (TH1*)inRootA.Get(key->GetName());
23 if(hA->GetDimension()!=1)
continue;
25 hB = (TH1*)inRootB.Get(key->GetName());
27 cout <<
"Cannot find " << key->GetName()
28 <<
" in file " << inFileB << endl;
31 if(hA->GetNbinsX()!=hB->GetNbinsX() ||
32 hA->GetXaxis()->GetBinLowEdge(1) != hB->GetXaxis()->GetBinLowEdge(1)){
33 cout <<
"Different bins " << key->GetName() << endl;
36 if(hA->GetXaxis()->GetXbins()){
37 hOut =
new TH1D(hA->GetName(),hA->GetTitle(),
38 hA->GetNbinsX(),hA->GetXaxis()->GetXbins()->GetArray());
41 hOut =
new TH1D(hA->GetName(),hA->GetTitle(),
43 hA->GetXaxis()->GetBinLowEdge(1),
44 hA->GetXaxis()->GetBinUpEdge(hA->GetNbinsX()));
47 for(
int i=1; i<=hA->GetNbinsX(); i++){
48 double val=hA->GetBinContent(i)-hB->GetBinContent(i);
49 double err=sqrt(hA->GetBinError(i)*hA->GetBinError(i)+
50 hB->GetBinError(i)*hB->GetBinError(i));
51 hOut->SetBinContent(i,val);
52 hOut->SetBinError(i,err);