15 const char* infileA=
"links/DEV.nofield.1244036.noExB.refitOS.slice/dip5.slice.root";
16 const char* infileB=
"links/P00hk.nofield.refitOS.0917.slice/dip5.typec.slice.new.root";
17 const char* outfile=
"links/DEV.nofield.1244036.noExB.refitOS.slice/dip5.typec.DEVminusP00hk.slice.root";
20 int main(
int argc,
char** argv)
22 char* argvZ[] = {
"-b"};
24 TApplication r00t(
"r00t", &argcZ, argvZ);
27 const char* options =
"a:b:o:";
28 Int_t chr, a=0,b=0,o=0;
29 char inFileA[300],inFileB[300],outFile[300];
30 while ((chr = getopt(argc, argv, options)) >= 0){
32 case 'a': strcpy(inFileA,optarg); a=1;
break;
33 case 'b': strcpy(inFileB,optarg); b=1;
break;
34 case 'o': strcpy(outFile,optarg); o=1;
break;
38 cout <<
"-a infileA -b infileB -o outFile" << endl;
46 cout <<
"infileA=" << inFileA << endl
47 <<
"infileB=" << inFileB << endl
48 <<
"outFile=" << outFile << endl;
50 TFile inRootA(inFileA);
if(!inRootA.IsOpen())
return -1;
51 TFile inRootB(inFileB);
if(!inRootB.IsOpen())
return -1;
52 TFile outRoot(outFile,
"RECREATE");
if(!outRoot.IsOpen())
return -1;
54 TIterator* iterator = inRootA.GetListOfKeys()->MakeIterator();
57 while( (key=dynamic_cast<TKey*>(iterator->Next())) != 0){
59 TH1 *hA=0,*hB=0,*hOut=0;
60 hA = (TH1*)inRootA.Get(key->GetName());
61 if(hA->GetDimension()!=1)
continue;
63 hB = (TH1*)inRootB.Get(key->GetName());
65 cout <<
"Cannot find " << key->GetName()
66 <<
" in file " << inFileB << endl;
69 if(hA->GetNbinsX()!=hB->GetNbinsX() ||
70 hA->GetXaxis()->GetBinLowEdge(1) != hB->GetXaxis()->GetBinLowEdge(1)){
71 cout <<
"Different bins " << key->GetName() << endl;
74 if(hA->GetXaxis()->GetXbins()){
75 hOut =
new TH1D(hA->GetName(),hA->GetTitle(),
76 hA->GetNbinsX(),hA->GetXaxis()->GetXbins()->GetArray());
79 hOut =
new TH1D(hA->GetName(),hA->GetTitle(),
81 hA->GetXaxis()->GetBinLowEdge(1),
82 hA->GetXaxis()->GetBinUpEdge(hA->GetNbinsX()));
85 for(
int i=1; i<=hA->GetNbinsX(); i++){
86 double val=hA->GetBinContent(i)-hB->GetBinContent(i);
87 double err=sqrt(hA->GetBinError(i)*hA->GetBinError(i)+
88 hB->GetBinError(i)*hB->GetBinError(i));
89 hOut->SetBinContent(i,val);
90 hOut->SetBinError(i,err);
98 cout <<
"done" << endl;