Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:30:07

0001 void compareHistos( char *Current, char *Reference=0 ){
0002 
0003  TText* te = new TText();
0004  te->SetTextSize(0.1);
0005  
0006  TFile * curfile = new TFile( TString(Current)+".root" );
0007  TFile * reffile = curfile;
0008  if (Reference) reffile = new TFile(TString(Reference)+".root");
0009 
0010 
0011  //1-Dimension Histogram
0012  TList* list = reffile->GetListOfKeys();  
0013  TObject*  object = list->First();
0014  
0015  int iHisto = 0; char title[50];
0016  while (object) {
0017    // find histo objects
0018    std::cout << " Histo " << object->GetName() << std::endl;
0019    TH1I * h1 = dynamic_cast<TH1I*>( reffile->Get(object->GetName()));
0020    TH1I * h2 = dynamic_cast<TH1I*>( curfile->Get(object->GetName()));
0021    bool isHisto = (reffile->Get(object->GetName()))->InheritsFrom("TH1I");
0022    
0023    if (isHisto && h1 && h2 && *h1->GetName()== *h2->GetName()) {
0024      iHisto++;
0025      char title[50];
0026      // draw and  compare
0027      std::cout << " Start draw and compare" << std::endl;
0028      TCanvas c1;
0029      TH1I htemp2;
0030      h2->Copy(htemp2);// to keep 2 distinct histos
0031 
0032      h1->SetLineColor(2);
0033      htemp2.SetLineColor(3);
0034      h1->SetLineStyle(3);
0035      h1->SetMarkerColor(3);
0036      htemp2.SetLineStyle(5);
0037      htemp2.SetMarkerColor(5);
0038      TLegend leg(0.1, 0.15, 0.2, 0.25);
0039      leg.AddEntry(h1, "Reference", "l");
0040      leg.AddEntry(&htemp2, "New ", "l");
0041    
0042      h1->Draw();
0043      htemp2.Draw("same");
0044     
0045      leg.Draw();
0046      sprintf(title,"%s%s", object->GetName(),".gif");
0047      c1.Print(title);
0048    }
0049    
0050    // go to next object
0051    object = list->After(object);
0052    }
0053 }