diff --git a/DataQuality/DataQualityUtils/src/HanOutputFile.cxx b/DataQuality/DataQualityUtils/src/HanOutputFile.cxx index cc6c4bbbe024296fadcf29241e6068f485870d16..8ef2fb04bb40e3afd172fb38b0a982dc23860c8a 100644 --- a/DataQuality/DataQualityUtils/src/HanOutputFile.cxx +++ b/DataQuality/DataQualityUtils/src/HanOutputFile.cxx @@ -36,6 +36,7 @@ #include <TBufferJSON.h> #include <TString.h> #include <TEfficiency.h> +#include <TGraphAsymmErrors.h> #include "TPluginManager.h" #define BINLOEDGE(h,n) h->GetXaxis()->GetBinLowEdge(n) @@ -1008,8 +1009,10 @@ std::pair<std::string,std::string> HanOutputFile:: getHistogram( std::string nam TObject* hobj = hkey->ReadObj(); TObject* ref(0); TH1* hRef(0); + TEfficiency* eRef(0); TH2* h2Ref(0); std::vector<TH1*> hRefs; + std::vector<TEfficiency*> eRefs; bool hasPlotted(false); TH1* h = dynamic_cast<TH1*>( hobj ); TH2* h2 = dynamic_cast<TH2*>( h ); @@ -1305,7 +1308,7 @@ std::pair<std::string,std::string> HanOutputFile:: getHistogram( std::string nam while ((ref2=icolln->Next())) { hRef = dynamic_cast<TH1*>(ref2); if (hRef) { - if (hRef->GetDimension() == h->GetDimension()) { + if (hRef->GetDimension() == h->GetDimension()) { hRefs.push_back(hRef); } } @@ -1315,6 +1318,7 @@ std::pair<std::string,std::string> HanOutputFile:: getHistogram( std::string nam } groupDir->cd(); } + if( hRefs.size() > 0 ){ legend = new TLegend(0.55,0.77,0.87,0.87); legend->SetTextFont(62); @@ -1517,10 +1521,75 @@ std::pair<std::string,std::string> HanOutputFile:: getHistogram( std::string nam /*************************************************************************************************************/ if( e != 0 ) { + hasPlotted=false; auto myC = std::make_unique<TCanvas>( nameHis.c_str(), "myC", ww, wh ); - myC->cd(); formatTEfficiency( myC.get(), e ); - e->Draw((std::string("AP") + drawopt).c_str()); + if(drawRefs){ + groupDir->cd((nameHis+"_/Results").c_str()); + gDirectory->GetObject("Reference;1",ref); + eRef = dynamic_cast<TEfficiency*>(ref); + if(eRef){ + eRefs.push_back(eRef); + } else{ + TCollection* colln = dynamic_cast<TCollection*>(ref); + if (colln) { + WasCollectionReference = true; + TIterator* icolln = colln->MakeIterator(); + TObject* ref2; + while ((ref2=icolln->Next())) { + eRef = dynamic_cast<TEfficiency*>(ref2); + if (eRef) { + if (eRef->GetDimension() == e->GetDimension()) { + eRefs.push_back(eRef); + } + } + else std::cout << "eRef cast failed!!!" << std::endl; + } + } + } + groupDir->cd(); + } + if(eRefs.size() > 0 ){ + legend = new TLegend(0.55,0.77,0.87,0.87); + legend->SetTextFont(62); + legend->SetMargin(0.15); + legend->SetFillStyle(0); + legend->SetBorderSize(0); + legend->AddEntry(e,datatitle.c_str()); + int itrcolor(0); + for (auto eRef : eRefs) { + myC->cd(); + e->Draw(""); + eRef->Draw(""); + gPad->Update(); + + int local_color = root_color_choices[itrcolor]; + itrcolor++; + + formatTEfficiency( myC.get(), eRef ); + eRef->SetMarkerColor(local_color); + eRef->SetLineColor(local_color); + + if (!hasPlotted) { + e->Draw((std::string("AP") + drawopt).c_str()); + hasPlotted=true; + } + eRef->Draw("SAME"); + myC->Update(); + + if (WasCollectionReference) { + legend->AddEntry(eRef, eRef->GetName()); + } else { + std::string refInfo = getStringName(pathname + "/"+ nameHis+"_/Config/annotations/refInfo"); + legend->AddEntry(eRef, refInfo != "Undefined" ? refInfo.c_str() : "Reference"); + } + } + legend->Draw(); + } else { + myC->cd(); + e->Draw((std::string("AP") + drawopt).c_str()); + } + myC->cd(); displayExtra(myC.get(),display); TLatex t; t.SetNDC(); @@ -1550,6 +1619,7 @@ std::pair<std::string,std::string> HanOutputFile:: getHistogram( std::string nam bool HanOutputFile::saveHistogramToFileSuperimposed( std::string nameHis, std::string location, TDirectory* groupDir1, TDirectory* groupDir2, bool drawRefs,std::string run_min_LB, std::string pathName,int cnvsType){ + dqi::DisableMustClean disabled; groupDir1->cd(); gStyle->SetFrameBorderMode(0); @@ -1778,7 +1848,7 @@ bool HanOutputFile::saveHistogramToFileSuperimposed( std::string nameHis, std::s tt.SetNDC(); tt.SetTextSize(0.03); tt.DrawLatex(0.02,0.01,pathName.c_str()); - + convertToGraphics(cnvsType,myC.get(),namePNG,nameJSON); gStyle->Reset(); diff --git a/DataQuality/dqm_algorithms/src/Chi2Test.cxx b/DataQuality/dqm_algorithms/src/Chi2Test.cxx index 171360340c70e9015938ee0e490a8bb168165692..f7e314ab80ea93659137abee13c1220595e2b4ac 100644 --- a/DataQuality/dqm_algorithms/src/Chi2Test.cxx +++ b/DataQuality/dqm_algorithms/src/Chi2Test.cxx @@ -10,6 +10,7 @@ #include <dqm_algorithms/Chi2Test.h> #include <dqm_algorithms/tools/AlgorithmHelper.h> #include <TH1.h> +#include <TEfficiency.h> #include <TF1.h> #include <TClass.h> #include <ers/ers.h> @@ -42,26 +43,49 @@ dqm_algorithms::Chi2Test::execute( const std::string & name , const TObject & object, const dqm_core::AlgorithmConfig & config ) { - const TH1 * histogram; - + const TH1* histogram = 0; + const TEfficiency* efficiency = 0; + TH1* passed_histogram = 0; + TH1* total_histogram = 0; + if(object.IsA()->InheritsFrom( "TH1" )) { histogram = static_cast<const TH1*>( &object ); if (histogram->GetDimension() > 2 ){ throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 2 " ); } + } else if(object.IsA()->InheritsFrom( "TEfficiency" )) { + // get the histograms from TEfficiency object to perform Chi2Test + efficiency = static_cast<const TEfficiency*>( &object); + if (efficiency->GetDimension() > 2 ){ + throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 2 " ); + } + + passed_histogram = efficiency->GetCopyPassedHisto(); + total_histogram = efficiency->GetCopyTotalHisto(); + passed_histogram->Divide(total_histogram); + } else { - throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" ); + throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1 or TEfficiency"); } const double minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1); - - if (histogram->GetEntries() < minstat ) { + double current_stat = 0; + + if(object.IsA()->InheritsFrom( "TH1" )) { + current_stat = histogram->GetEntries(); + } else if(object.IsA()->InheritsFrom( "TEfficiency" )){ + current_stat = total_histogram->GetEntries(); + } + + if(current_stat < minstat ) { dqm_core::Result *result = new dqm_core::Result(dqm_core::Result::Undefined); - result->tags_["InsufficientEntries"] = histogram->GetEntries(); + result->tags_["InsufficientEntries"] = current_stat; return result; } - - TH1 * refhist; + + TH1 * refhist = 0; + TH1 * ref_total_hist; + TEfficiency * refeff; double gthresho; double rthresho; std::string option; @@ -90,24 +114,54 @@ dqm_algorithms::Chi2Test::execute( const std::string & name , } - try { - refhist = dynamic_cast<TH1 *>( config.getReference() ); - } - catch ( dqm_core::Exception & ex ) { - throw dqm_core::BadRefHist(ERS_HERE,name," Could not retreive reference"); - } + if(object.IsA()->InheritsFrom( "TH1" )) { + try { + refhist = dynamic_cast<TH1 *>( config.getReference() ); + } + catch ( dqm_core::Exception & ex ) { + throw dqm_core::BadRefHist(ERS_HERE,name," Could not retreive reference"); + } + } else if(object.IsA()->InheritsFrom( "TEfficiency" )){ + try { + refeff = dynamic_cast<TEfficiency *>( config.getReference() ); + } + catch ( dqm_core::Exception & ex ) { + throw dqm_core::BadRefHist(ERS_HERE,name," Could not retreive reference"); + } + + refhist = refeff->GetCopyPassedHisto(); + ref_total_hist = refeff->GetCopyTotalHisto(); + refhist->Divide(ref_total_hist); + } + if (!refhist) { throw dqm_core::BadRefHist(ERS_HERE,name,"Bad reference type"); } + + double value = 0; + if(object.IsA()->InheritsFrom( "TH1" )) { - if (histogram->GetDimension() != refhist->GetDimension() ) { - throw dqm_core::BadRefHist( ERS_HERE, "Dimension", name ); - } - - if ((histogram->GetNbinsX() != refhist->GetNbinsX()) || (histogram->GetNbinsY() != refhist->GetNbinsY())) { - throw dqm_core::BadRefHist( ERS_HERE, "number of bins", name ); - } + if (histogram->GetDimension() != refhist->GetDimension() ) { + throw dqm_core::BadRefHist( ERS_HERE, "Dimension", name ); + } + if ((histogram->GetNbinsX() != refhist->GetNbinsX()) || (histogram->GetNbinsY() != refhist->GetNbinsY())) { + throw dqm_core::BadRefHist( ERS_HERE, "number of bins", name ); + } - double value = histogram->Chi2Test( refhist, option.c_str() ); + value = histogram->Chi2Test( refhist, option.c_str() ); + + } else if(object.IsA()->InheritsFrom( "TEfficiency" )){ + + if (passed_histogram->GetDimension() != refhist->GetDimension() ) { + throw dqm_core::BadRefHist( ERS_HERE, "Dimension", name ); + } + + if ((passed_histogram->GetNbinsX() != refhist->GetNbinsX()) || (passed_histogram->GetNbinsY() != refhist->GetNbinsY())) { + throw dqm_core::BadRefHist( ERS_HERE, "number of bins", name ); + } + + value = passed_histogram->Chi2Test( refhist, option.c_str() ); + } + ERS_DEBUG(1,"Green threshold: "<< gthresho << "; Red threshold: " << rthresho ); ERS_DEBUG(1,"Chi2 Test with Option " << option << " is " << value ); @@ -132,6 +186,7 @@ dqm_algorithms::Chi2Test::execute( const std::string & name , } } + ERS_DEBUG(2,"Result: "<<*result); return result; diff --git a/DataQuality/dqm_algorithms/src/RepeatAlgorithm.cxx b/DataQuality/dqm_algorithms/src/RepeatAlgorithm.cxx index 0913db52bef955527292688e70635575498067ba..bacb12659e5ab14c0f995d8f52b78dbbcab74641 100644 --- a/DataQuality/dqm_algorithms/src/RepeatAlgorithm.cxx +++ b/DataQuality/dqm_algorithms/src/RepeatAlgorithm.cxx @@ -118,12 +118,13 @@ execute( const std::string& name, const TObject& data, const dqm_core::Algorithm } tags[ireference->GetName() + std::string("|Status")] = subResult->status_; if ( dqm_algorithms::tools::GetFirstFromMap("RepeatAlgorithm--ResultsNEntries", config.getParameters(), 0) > 0 ) { - TH1* hireference = dynamic_cast<TH1*>(ireference); - if (hireference) { - tags[ireference->GetName() + std::string("|NEntries")] = hireference->GetEntries(); - } else { - throw dqm_core::BadConfig( ERS_HERE, "RepeatAlgorithm", std::string("Reference ") + ireference->GetName() + " is not TH1, yet we want to get # entries" ); - } + + if( ireference->IsA()->InheritsFrom( "TH1" )){ + TH1* hireference = dynamic_cast<TH1*>(ireference); + if (hireference) { + tags[ireference->GetName() + std::string("|NEntries")] = hireference->GetEntries(); + } + } } if (subResult->getObject()) {