9 #include "TObjString.h"
22 std::string
ConcatPath(
const std::string&
a,
const std::string& b)
24 if(a.empty())
return b;
31 return a.GetString() == b.GetString();
36 return (a-b).Norm1() == 0;
41 if(a.GetNcells() != b.GetNcells())
return false;
43 for(
int i = 0; i <= a.GetNcells(); ++i)
44 if(a.GetBinContent(i) != b.GetBinContent(i))
51 std::ostream&
operator<<(std::ostream& os,
const TObjString&
a)
53 return os <<
"\"" << a.GetString() <<
"\"";
58 return os <<
"integral " << a.Integral(0, -1);
68 void Plots(
const TH1&
a,
const TH1& b,
const std::string& key)
70 TH1* ac = (TH1*)a.Clone();
71 TH1* bc = (TH1*)b.Clone();
73 ac->SetLineColor(kRed);
74 bc->SetLineColor(kBlue);
76 if(ac->Integral() < bc->Integral()) std::swap(ac, bc);
78 ac->SetTitle(key.c_str());
81 bc->Draw(
"hist same");
85 gPad->Print(
"diff.pdf[");
88 gPad->Print(
"diff.pdf");
93 template<
class T>
bool Compare(
const T&
a,
const T& b,
const std::string& key)
100 std::cout <<
"\n'" << key <<
"' differs: " << a <<
" vs " << b << std::endl;
102 if constexpr(std::is_same_v<T, TH1>)
112 if(a.ClassName() != std::string(b.ClassName())){
113 std::cout << key <<
" is of unlike type: "
114 << a.ClassName() <<
" vs "
115 << b.ClassName() << std::endl;
119 if(a.ClassName() == std::string(
"TObjString")){
120 return Compare((TObjString&)a, (TObjString&)b, key);
123 if(a.ClassName() == std::string(
"TVectorT<double>")){
124 return Compare((TVectorD&)a, (TVectorD&)b, key);
127 if(a.ClassName() == std::string(
"TVector3")){
128 return Compare((TVector3&)a, (TVector3&)b, key);
131 if(a.InheritsFrom(TH1::Class()) && b.InheritsFrom(TH1::Class())){
132 return Compare((TH1&)a, (TH1&)b, key);
135 std::cout <<
"Don't know how to compare '" << key <<
"' of type "
136 << a.ClassName() << std::endl;
143 if(only.empty())
return;
145 std::cout <<
"The following keys exist only in " << dir->GetFile()->GetName() << std::endl;
146 for(
const std::string&
k: only)
std::cout <<
" " <<
k << std::endl;
152 std::set<std::string> keysA, keysB;
153 TIter nextA(a->GetListOfKeys()), nextB(b->GetListOfKeys());
154 while(TObject*
x = nextA()) keysA.insert(
x->GetName());
155 while(TObject*
x = nextB()) keysB.insert(
x->GetName());
157 std::vector<std::string> onlyA, onlyB, bothAB;
158 std::set_difference (keysA.begin(), keysA.end(), keysB.begin(), keysB.end(), std::back_inserter(onlyA));
159 std::set_difference (keysB.begin(), keysB.end(), keysA.begin(), keysA.end(), std::back_inserter(onlyB));
160 std::set_intersection(keysA.begin(), keysA.end(), keysB.begin(), keysB.end(), std::back_inserter(bothAB));
165 bool ok = onlyA.empty() && onlyB.empty();
167 for(
const std::string& key: bothAB){
168 TObject* objA = a->Get(key.c_str());
169 TObject* objB = b->Get(key.c_str());
171 TDirectory* dirA =
dynamic_cast<TDirectoryFile*
>(objA);
172 TDirectory* dirB =
dynamic_cast<TDirectoryFile*
>(objB);
191 std::cout <<
"Usage: diff_spectra [-np] input1.root input2.root" << std::endl;
192 std::cout <<
" -np Disable plotting functionality" << std::endl;
198 int main(
int argc,
char** argv)
200 if(argc != 3 && argc != 4)
usage();
201 if(argc == 4 && argv[1] != std::string(
"-np"))
usage();
210 const std::string fnameA = argv[1];
211 const std::string fnameB = argv[2];
213 std::cout <<
"Comparing " << fnameA <<
" and " << fnameB << std::endl;
216 TFile::Open(fnameB.c_str()))){
217 std::cout <<
"\nFiles match!" << std::endl;
223 std::cout <<
"\nFiles do not match" << std::endl;
process_name opflash particleana ie x
bool CheckDirectory(TDirectory *a, TDirectory *b, std::string path="")
bool CompareObjects(const TObject &a, const TObject &b, const std::string &key)
bool Compare(const T &a, const T &b, const std::string &key)
BEGIN_PROLOG triggeremu_data_config_icarus settings PMTADCthresholds sequence::icarus_stage0_multiTPC_TPC physics sequence::icarus_stage0_EastHits_TPC physics sequence::icarus_stage0_WestHits_TPC physics producers purityana0 caloskimCalorimetryCryoE physics caloskimCalorimetryCryoW physics path
std::string ConcatPath(const std::string &a, const std::string &b)
void ReportUnique(const std::vector< std::string > &only, TDirectory *dir)
void Plots(const TH1 &a, const TH1 &b, const std::string &key)
int main(int argc, char **argv)
std::ostream & operator<<(std::ostream &out, lar::example::CheatTrack const &track)
bool operator==(infinite_endcount_iterator< T > const &, count_iterator< T > const &)
BEGIN_PROLOG could also be cout