Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-25 10:58:18

0001 
0002 #include "L1Trigger/L1TNtuples/interface/L1AnalysisL1UpgradeDataFormat.h"
0003 
0004 void bitwise_compare(const char* tag,
0005                      TTree* tree1,
0006                      TTree* tree2,
0007                      const char* var,
0008                      const char* var2,
0009                      const char* cut,
0010                      int nbins,
0011                      double max,
0012                      double min) {
0013   char command[1000];
0014   static int countDiscrep = 0;
0015   static int countAgree = 0;
0016 
0017   TH1F h1("h1", "", nbins, max, min);
0018   TH1F h2("h2", "", nbins, max, min);
0019   sprintf(command, "%s>>h1", var);
0020   tree1->Draw(command, cut);
0021   sprintf(command, "%s>>h2", var2);
0022   tree2->Draw(command, cut);
0023   //cout << "count 1:  " << h1.GetEntries() << "\n";
0024   //cout << "count 2:  " << h2.GetEntries() << "\n";
0025 
0026   if (!TString(var).CompareTo("sumEt[0]")) {
0027     var = "ETT";
0028   } else if (!TString(var).CompareTo("sumEt[2]")) {
0029     var = "HTT";
0030   } else if (!TString(var).CompareTo("sumEt[4]")) {
0031     var = "ETM";
0032   } else if (!TString(var).CompareTo("sumEt[6]")) {
0033     var = "HTM";
0034   }
0035 
0036   int fail = 0;
0037   for (int i = 0; i < nbins + 2; i++) {
0038     if (h1.GetBinContent(i) != h2.GetBinContent(i)) {
0039       fail = 1;
0040       cout << "discrepancy in " << var << " bin:  " << i << " " << h1.GetBinContent(i) << " vs " << h2.GetBinContent(i)
0041            << "\n";
0042     }
0043   }
0044   if (fail) {
0045     cout << "FAILURE:  variable " << var << " shows a disagreement\n";
0046     char name[1000];
0047     sprintf(name, "discrep_%s_%s_%d.pdf", tag, var, countDiscrep);
0048     TCanvas c1;
0049     h1.GetXaxis()->SetTitle(var);
0050     h1.Draw("L");
0051     h2.Draw("epSAME");
0052     c1.SaveAs(name);
0053     countDiscrep++;
0054   } else {
0055     cout << "SUCCESS:  bitwise equality for variable " << var << "\n";
0056     char name[1000];
0057     sprintf(name, "agree_%s_%s_%d.pdf", tag, var, countAgree);
0058     TCanvas c1;
0059     h1.GetXaxis()->SetTitle(var);
0060     h1.Draw("L");
0061     h2.Draw("epSAME");
0062     c1.SaveAs(name);
0063     countAgree++;
0064   }
0065 }
0066 
0067 void bitwise_compare(
0068     const char* tag, TTree* tree1, TTree* tree2, const char* var, const char* cut, int nbins, double max, double min) {
0069   bitwise_compare(tag, tree1, tree2, var, var, cut, nbins, max, min);
0070 }
0071 
0072 void NtupleDiff(const char* tag,
0073                 const char* file1,
0074                 const char* file2,
0075                 const char* treepath1 = "l1UpgradeEmuTree/L1UpgradeTree",
0076                 const char* treepath2 = "l1UpgradeEmuTree/L1UpgradeTree") {
0077   cout << "INFO: comparing contents of tree " << treepath1 << " in file " << file1 << "\n";
0078   cout << "INFO: comparing contents of tree " << treepath2 << " in file " << file2 << "\n";
0079 
0080   TFile input1(file1);
0081   TTree* tree1 = (TTree*)input1.Get(treepath1);
0082   if (!tree1) {
0083     cout << "ERROR: could not open tree 1.\n";
0084     input1.ls();
0085     return;
0086   }
0087 
0088   TFile input2(file2);
0089   TTree* tree2 = (TTree*)input2.Get(treepath2);
0090   if (!tree2) {
0091     cout << "ERROR: could not open tree 2.\n";
0092     input2.ls();
0093     return;
0094   }
0095 
0096   tree1->Print();
0097   tree2->Print();
0098 
0099   cout << "Very Central Jets:\n";
0100   bitwise_compare(tag, tree1, tree2, "jetEt", "(jetEt > 10.0) && (abs(jetEta) < 1.5)", 20.0, 0.0, 200.0);
0101   bitwise_compare(tag, tree1, tree2, "jetEta", "(jetEt > 10.0) && (abs(jetEta) < 1.5)", 20.0, -5.0, 5.0);
0102   bitwise_compare(tag, tree1, tree2, "jetPhi", "(jetEt > 10.0) && (abs(jetEta) < 1.5)", 20.0, -6.2, 6.2);
0103 
0104   cout << "All Jets:\n";
0105   bitwise_compare(tag, tree1, tree2, "jetEt", "(jetEt > 10.0)", 20.0, 0.0, 200.0);
0106   bitwise_compare(tag, tree1, tree2, "jetEta", "(jetEt > 10.0)", 20.0, -5.0, 5.0);
0107   bitwise_compare(tag, tree1, tree2, "jetPhi", "(jetEt > 10.0)", 20.0, -6.2, 6.2);
0108 
0109   bitwise_compare(tag, tree1, tree2, "tauEt", "tauEt > 10.0", 20.0, 0.0, 200.0);
0110   bitwise_compare(tag, tree1, tree2, "tauEta", "tauEt > 10.0", 20.0, -5.0, 5.0);
0111   bitwise_compare(tag, tree1, tree2, "tauPhi", "tauEt > 10.0", 20.0, -6.2, 6.2);
0112 
0113   bitwise_compare(tag, tree1, tree2, "egEt", "egEt > 10.0", 20.0, 0.0, 200.0);
0114   bitwise_compare(tag, tree1, tree2, "egEta", "egEt > 10.0", 20.0, -5.0, 5.0);
0115   bitwise_compare(tag, tree1, tree2, "egPhi", "egEt > 10.0", 20.0, -6.2, 6.2);
0116 
0117   bitwise_compare(tag, tree1, tree2, "muonEt", "muonEt > 3.0", 20.0, 0.0, 200.0);
0118   bitwise_compare(tag, tree1, tree2, "muonEta", "muonEt > 3.0", 20.0, -5.0, 5.0);
0119   bitwise_compare(tag, tree1, tree2, "muonPhi", "muonEt > 3.0", 20.0, -6.2, 6.2);
0120 
0121   bitwise_compare(tag, tree1, tree2, "sumEt[0]", "", 20.0, 0.0, 500.0);
0122   bitwise_compare(tag, tree1, tree2, "sumEt[2]", "", 20.0, 0.0, 500.0);
0123   bitwise_compare(tag, tree1, tree2, "sumEt[4]", "", 20.0, 0.0, 500.0);
0124   bitwise_compare(tag, tree1, tree2, "sumEt[6]", "", 20.0, 0.0, 500.0);
0125 
0126   // for hack, use this version when comparing to old order sums:
0127   //bitwise_compare(tag, tree1, tree2, "sumEt[0]", "sumEt[0]", "", 20.0, 0.0, 500.0);
0128   //bitwise_compare(tag, tree1, tree2, "sumEt[2]", "sumEt[1]", "", 20.0, 0.0, 500.0);
0129   //bitwise_compare(tag, tree1, tree2, "sumEt[4]", "sumEt[2]", "", 20.0, 0.0, 500.0);
0130   //bitwise_compare(tag, tree1, tree2, "sumEt[6]", "sumEt[3]", "", 20.0, 0.0, 500.0);
0131 
0132   //TH1F * jetEt = new TH1F("jetEt","", 20, 0.0, 200.0);
0133   //tree->Draw("jetEt>>jetEt","jetEt > 10.0");
0134   //cout << "jet count:  " << jetEt->GetEntries() << "\n";
0135 
0136   //TH1F * egEt = new TH1F("egEt","", 20, 0.0, 200.0);
0137   //tree->Draw("egEt>>egEt","egEt > 10.0");
0138   //cout << "eg count:  " << egEt->GetEntries() << "\n";
0139 
0140   //TH1F * tauEt = new TH1F("tauEt","", 20, 0.0, 200.0);
0141   //tree->Draw("tauEt>>tauEt","tauEt > 10.0");
0142   //cout << "tau count:  " << tauEt->GetEntries() << "\n";
0143 
0144   //TH1F * muonEt = new TH1F("muonEt","", 20, 0.0, 200.0);
0145   //tree->Draw("muonEt>>muonEt","muonEt > 1.0");
0146   //cout << "muon count:  " << muonEt->GetEntries() << "\n";
0147 }