Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:34:14

0001 #include <iostream.h>
0002 #include "TFile.h"
0003 
0004 class HistoCompare {
0005 
0006  public:
0007 
0008   HistoCompare() 
0009   { 
0010     std::cout << "Initializing HistoCompare... " << std::endl; 
0011     name = "none";
0012   } ;
0013 
0014   HistoCompare(char* thisname = "none") : mypv(-9999.9)
0015   { 
0016     name = thisname;
0017     std::cout << "Initializing HistoCompare... " << std::endl; 
0018     if ( name != "none" )
0019       {
0020     cout << "... creating output file" << endl;
0021     
0022     out_file.open( thisname, ios::out);
0023     if ( out_file.fail() )
0024       {
0025         cout << "Could not open data file" << endl;
0026         exit(1);
0027       }
0028       }
0029   } ;
0030   
0031   ~HistoCompare()
0032   {
0033     if ( name != "none" )
0034       {
0035     cout << "... closing output file" << endl;
0036     out_file.close();
0037       }
0038     
0039   };
0040 
0041   void PVCompute(TH1 * oldHisto , TH1 * newHisto , TText * te );
0042   void PVCompute(TH2 * oldHisto , TH2 * newHisto , TText * te );
0043   void PVCompute(TProfile * oldHisto , TProfile * newHisto , TText * te );
0044 
0045   Double_t getPV() { return mypv; };
0046   void setName(char* s) { name = s; };
0047 
0048  private:
0049   
0050   Double_t mypv;
0051 
0052   TH1 * myoldHisto1;
0053   TH1 * mynewHisto1;
0054 
0055   TH2 * myoldHisto2;
0056   TH2 * mynewHisto2;
0057 
0058   TProfile * myoldProfile;
0059   TProfile * mynewProfile;
0060 
0061   TText * myte;
0062   
0063   char* name;
0064   
0065   fstream out_file;
0066 
0067 };
0068 
0069 HistoCompare::PVCompute(TH1 * oldHisto , TH1 * newHisto , TText * te )
0070 {
0071 
0072   myoldHisto1 = oldHisto;
0073   mynewHisto1 = newHisto;
0074   myte = te;
0075 
0076   //  Double_t mypv = myoldHisto1->Chi2Test(mynewHisto1,"OU");
0077   mypv = myoldHisto1->Chi2Test(mynewHisto1, "OU");
0078   std::strstream buf;
0079   std::string value;
0080   buf<<"PV="<<mypv<<std::endl;
0081   buf>>value;
0082   
0083   myte->DrawTextNDC(0.6,0.7, value.c_str());
0084 
0085   std::cout << "[OVAL] " << myoldHisto1->GetName() << " PV = " << mypv << std::endl;
0086   
0087   if ( name != "none" )
0088     {
0089       if ( mypv < 0.01 )
0090     out_file << myoldHisto1->GetName() << "     pv = " << mypv << "      comparison fails !!!" << endl; 
0091       else
0092     out_file << myoldHisto1->GetName() << "     pv = " << mypv << endl;
0093     }
0094   
0095   return;
0096 
0097 }
0098 
0099 HistoCompare::PVCompute(TH2 * oldHisto , TH2 * newHisto , TText * te )
0100 {
0101 
0102   myoldHisto2 = oldHisto;
0103   mynewHisto2 = newHisto;
0104   myte = te;
0105 
0106   //Double_t mypv = myoldHisto2->Chi2Test(mynewHisto2,"OU");
0107   mypv = myoldHisto2->Chi2Test(mynewHisto2,"OU");
0108   std::strstream buf;
0109   std::string value;
0110   buf<<"PV="<<mypv<<std::endl;
0111   buf>>value;
0112   
0113   myte->DrawTextNDC(0.2,0.7, value.c_str());
0114 
0115   std::cout << "[OVAL] " << myoldHisto2->GetName() << " PV = " << mypv << std::endl;
0116   
0117   if ( name != "none" )
0118     {
0119       if ( mypv < 0.01 )
0120     out_file << myoldHisto1->GetName() << "     pv = " << mypv << "      comparison fails !!!" << endl; 
0121       else
0122     out_file << myoldHisto1->GetName() << "     pv = " << mypv << endl;
0123     }
0124 
0125   return;
0126 }
0127 
0128 
0129 HistoCompare::PVCompute(TProfile * oldHisto , TProfile * newHisto , TText * te )
0130 {
0131 
0132   myoldProfile = oldHisto;
0133   mynewProfile = newHisto;
0134   myte = te;
0135 
0136   //Double_t mypv = myoldProfile->Chi2Test(mynewProfile,"OU");
0137   mypv = myoldProfile->Chi2Test(mynewProfile,"OU");
0138   std::strstream buf;
0139   std::string value;
0140   buf<<"PV="<<mypv<<std::endl;
0141   buf>>value;
0142   
0143   myte->DrawTextNDC(0.2,0.7, value.c_str());
0144 
0145   std::cout << "[OVAL] " << myoldProfile->GetName() << " PV = " << mypv << std::endl;
0146   
0147   if ( name != "none" )
0148     {
0149       if ( mypv < 0.01 )
0150     out_file << myoldHisto1->GetName() << "     pv = " << mypv << "      comparison fails !!!" << endl; 
0151       else
0152     out_file << myoldHisto1->GetName() << "     pv = " << mypv << endl;
0153     }
0154   
0155   return;
0156 
0157 }