Пример #1
0
void testNormalizeHistogram()
{
    printf("\nTEST NORMALIZE HISTOGRAM\n");

    Histogram h1;
    initHistogram(&h1, 5, 3);
    h1.freq[0][0] = 12;
    h1.freq[1][0] = 15;
    h1.freq[2][0] = 20;
    h1.freq[3][0] = 45;
    h1.freq[4][0] = 19;

    h1.freq[0][1] = 5;
    h1.freq[1][1] = 7;
    h1.freq[2][1] = 16;
    h1.freq[3][1] = 6;
    h1.freq[4][1] = 4;

    normalizeHistogram(&h1);
    printf("Expected: 0.11, Actual: %.2f\n", h1.freq[0][0]);
    printf("Expected: 0.14, Actual: %.2f\n", h1.freq[1][0]);
    printf("Expected: 0.18, Actual: %.2f\n", h1.freq[2][0]);
    printf("Expected: 0.41, Actual: %.2f\n", h1.freq[3][0]);
    printf("Expected: 0.17, Actual: %.2f\n", h1.freq[4][0]);

    printf("Expected: 0.13, Actual: %.2f\n", h1.freq[0][1]);
    printf("Expected: 0.18, Actual: %.2f\n", h1.freq[1][1]);
    printf("Expected: 0.42, Actual: %.2f\n", h1.freq[2][1]);
    printf("Expected: 0.16, Actual: %.2f\n", h1.freq[3][1]);
    printf("Expected: 0.11, Actual: %.2f\n", h1.freq[4][1]);
}
/**
 * Return the better threshold,
 * its is used in cvThreshold function.
 * 
 * @param histogram
 * @param imageSize
 * @return factor of limiarization
 */
int ImageNoisesExtractor::getBetterThresholdBasedOnHistogram(int* histogram, int imageSize) {
    float* histogramNormalized = normalizeHistogram(histogram, imageSize);
    
    int pikePosition = 0;
    float pike = 0;
    for(int i = 0; i < 256; i++) { // get the max value of histogram
        if(histogramNormalized[i] > pike) {
            pike = histogramNormalized[i];
            pikePosition = i;
        }
    }
    
    int breakParameter = 0.1; // value determined empirically
    
    int indexOfThreshold = 0;
    for(indexOfThreshold = pikePosition; indexOfThreshold < 256; indexOfThreshold++) {
        if(histogramNormalized[indexOfThreshold]/histogramNormalized[pikePosition] <= breakParameter) {
            break;
        }
    }
    
//    printf("index of threshold: %d\n", indexOfThreshold);
    
    return histogramNormalized[indexOfThreshold] * imageSize; // denormalize
}
Пример #3
0
void buildExpectedPhiHistorgtam(
  cv::Mat& histogram,
  double degrees_per_bin,
  double stdev)
{
  int n_bins = (int)(360.0 / degrees_per_bin);
  histogram = cv::Mat::zeros(1, n_bins, CV_32FC1);

  double s = stdev  / degrees_per_bin;

  double mean[4];
  mean[0] =   0.0 / degrees_per_bin;
  mean[1] =  90.0 / degrees_per_bin;
  mean[2] = 180.0 / degrees_per_bin;
  mean[3] = 270.0 / degrees_per_bin;

  double a = 1.0 / (s * sqrt(2.0 * M_PI));
  double b = 2.0 * s * s; 

  for (int u = 0; u < n_bins; ++u)
  {
    float& bin = histogram.at<float>(0, u);

    // accumulate 4 gaussians
    for (int g = 0; g < 4; g++)
    {
      int x = u - mean[g];
  
      // wrap around to closer distance
      if (x < -n_bins/2) x += n_bins;
      if (x >= n_bins/2) x -= n_bins;

      float r = a * exp(-x*x / b);

      bin += r;
    }
  }

  normalizeHistogram(histogram);
}  
Пример #4
0
void buildPhiHistogram(
  const pcl::PointCloud<pcl::PointXYZRGBNormal>& cloud,
  cv::Mat& histogram,
  double degrees_per_bin)
{
  int phi_bins = (int)(360.0 / degrees_per_bin);
  histogram = cv::Mat::zeros(1, phi_bins, CV_32FC1);
  
  for (unsigned int i = 0; i < cloud.points.size(); ++i)
  {
    const pcl::PointXYZRGBNormal& p = cloud.points[i]; 

    double nx = p.normal_x;
    double ny = p.normal_y;
    double nz = p.normal_z;

    if (isnan(nx) || isnan(ny) || isnan(nz)) continue;

    double r = sqrt(nx*nx + ny*ny + nz*nz);
    double theta = acos(nz/r);
    double phi   = atan2(ny, nx);

    double phi_deg   = phi   * 180.0 / M_PI;
    double theta_deg = theta * 180.0 / M_PI; 

    // normalize phi to [0, 360)
    if (phi_deg < 0.0) phi_deg += 360.0;

    // only consider points which are close to vertical
    if (std::abs(90-theta_deg) > 3.0) continue; 

    int idx_phi = (int)(phi_deg / degrees_per_bin);

    float& bin = histogram.at<float>(0, idx_phi);
    bin = bin + 1.0; 
  }

  normalizeHistogram(histogram);
}
Пример #5
0
void compareSyncNtuples(const std::string & ref_str,
                        const std::string & test_str,
                        const std::string & sample_str)
{
  gROOT->SetBatch(true);
  gErrorIgnoreLevel = kWarning;

  const NtupleMetaData & ref = ntupleMetadataMap.at(sample_str).at(ref_str);
  const NtupleMetaData & test = ntupleMetadataMap.at(sample_str).at(test_str);

  TFile* inputFile_ref = openFile(ref.inputFilePath, ref.inputFileName);
  TTree* tree_ref = loadTree(inputFile_ref, ref.treeName, ref.dirName);
  TFile* inputFile_test = openFile(test.inputFilePath, test.inputFileName);
  TTree* tree_test = loadTree(inputFile_test, test.treeName, test.dirName);

  const std::string outputFilePath = base_dir + "plots/" +
                                     sample_str + "/" + ref.legendEntry + "_vs_" + test.legendEntry;
  struct stat st = {0};
  if(stat(outputFilePath.c_str(), &st) == -1)
    _mkdir(outputFilePath.c_str());

  std::vector<branchEntryType*> branchesToCompare;
  branchesToCompare.push_back(new branchEntryType("n_presel_mu", "I", "", 20, -0.5, 19.5));
  branchesToCompare.push_back(new branchEntryType("n_fakeablesel_mu", "I", "", 20, -0.5, 19.5));
//  branchesToCompare.push_back(new branchEntryType("n_cutsel_mu", "I", "", 20, -0.5, 19.5));
  branchesToCompare.push_back(new branchEntryType("n_mvasel_mu", "I", "", 20, -0.5, 19.5));
  branchesToCompare.push_back(new branchEntryType("n_presel_ele", "I", "", 20, -0.5, 19.5));
  branchesToCompare.push_back(new branchEntryType("n_fakeablesel_ele", "I", "", 20, -0.5, 19.5));
//  branchesToCompare.push_back(new branchEntryType("n_cutsel_ele", "I", "", 20, -0.5, 19.5));
  branchesToCompare.push_back(new branchEntryType("n_mvasel_ele", "I", "", 20, -0.5, 19.5));
  branchesToCompare.push_back(new branchEntryType("n_presel_tau", "I", "", 20, -0.5, 19.5));
  branchesToCompare.push_back(new branchEntryType("n_presel_jet", "I", "", 20, -0.5, 19.5));
  branchesToCompare.push_back(new branchEntryType("mu0_charge", "I", "n_presel_mu >= 1", 3, -1.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("mu0_jetNDauChargedMVASel", "F", "n_presel_mu >= 1", 20, -0.5, 19.5));
  branchesToCompare.push_back(new branchEntryType("mu0_jetPtRel", "F", "n_presel_mu >= 1", 100., -0.01, 10.));
  branchesToCompare.push_back(new branchEntryType("mu0_miniIsoNeutral", "F", "n_presel_mu >= 1", 100, -0.01, 100.));
  branchesToCompare.push_back(new branchEntryType("mu0_miniIsoCharged", "F", "n_presel_mu >= 1", 100, -0.01, 100.));
  branchesToCompare.push_back(new branchEntryType("mu0_E", "F", "n_presel_mu >= 1", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("mu0_conept", "F", "", 100, 0., 1000.));
  branchesToCompare.push_back(new branchEntryType("mu0_jetPtRatio", "F", "n_presel_mu >= 1", 100, -0.01, 3.));
  branchesToCompare.push_back(new branchEntryType("mu0_leptonMVA", "F", "n_presel_mu >= 1", 100, -1., +1.));
  branchesToCompare.push_back(new branchEntryType("mu0_jetCSV", "F", "n_presel_mu >= 1", 100, 0., +1.));
  branchesToCompare.push_back(new branchEntryType("mu0_dpt_div_pt", "F", "n_presel_mu >= 1", 100, 0., +0.25));
  branchesToCompare.push_back(new branchEntryType("mu0_segmentCompatibility", "F", "n_presel_mu >= 1", 100, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("mu0_phi", "F", "n_presel_mu >= 1", 36, -TMath::Pi(), +TMath::Pi()));
  branchesToCompare.push_back(new branchEntryType("mu0_sip3D", "F", "n_presel_mu >= 1", 100, 0., +10.));
  branchesToCompare.push_back(new branchEntryType("mu0_pt", "F", "n_presel_mu >= 1", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("mu0_miniRelIso", "F", "n_presel_mu >= 1", 100, -0.01, 1.));
  branchesToCompare.push_back(new branchEntryType("mu0_dxy", "F", "n_presel_mu >= 1", 100, -0.1, +0.1));
  branchesToCompare.push_back(new branchEntryType("mu0_eta", "F", "n_presel_mu >= 1", 100, -3., +3.));
  branchesToCompare.push_back(new branchEntryType("mu0_dz", "F", "n_presel_mu >= 1", 100, -0.2, +0.2));
  branchesToCompare.push_back(new branchEntryType("mu0_isfakeablesel", "I", "n_presel_mu >= 1", 2, -0.5, +1.5));
//  branchesToCompare.push_back(new branchEntryType("mu0_iscutsel", "I", "n_presel_mu >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("mu0_ismvasel", "I", "n_presel_mu >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("mu1_charge", "I", "n_presel_mu >= 2", 3, -1.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("mu1_jetNDauChargedMVASel", "F", "n_presel_mu >= 2", 20, -0.5, 19.5));
  branchesToCompare.push_back(new branchEntryType("mu1_jetPtRel", "F", "n_presel_mu >= 2", 100., -0.01, 10.));
  branchesToCompare.push_back(new branchEntryType("mu1_miniIsoNeutral", "F", "n_presel_mu >= 2", 100, -0.01, 100.));
  branchesToCompare.push_back(new branchEntryType("mu1_miniIsoCharged", "F", "n_presel_mu >= 2", 100, -0.01, 100.));
  branchesToCompare.push_back(new branchEntryType("mu1_E", "F", "n_presel_mu >= 2", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("mu1_conept", "F", "", 100, 0., 500.));
  branchesToCompare.push_back(new branchEntryType("mu1_jetPtRatio", "F", "n_presel_mu >= 2", 100, -0.01, 3.));
  branchesToCompare.push_back(new branchEntryType("mu1_leptonMVA", "F", "n_presel_mu >= 2", 100, -1., +1.));
  branchesToCompare.push_back(new branchEntryType("mu1_jetCSV", "F", "n_presel_mu >= 2", 100, 0., +1.));
  branchesToCompare.push_back(new branchEntryType("mu1_dpt_div_pt", "F", "n_presel_mu >= 2", 100, 0., +0.25));
  branchesToCompare.push_back(new branchEntryType("mu1_segmentCompatibility", "F", "n_presel_mu >= 2", 100, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("mu1_phi", "F", "n_presel_mu >= 2", 36, -TMath::Pi(), +TMath::Pi()));
  branchesToCompare.push_back(new branchEntryType("mu1_sip3D", "F", "n_presel_mu >= 2", 100, 0., +10.));
  branchesToCompare.push_back(new branchEntryType("mu1_pt", "F", "n_presel_mu >= 2", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("mu1_miniRelIso", "F", "n_presel_mu >= 2", 100, -0.01, 1.));
  branchesToCompare.push_back(new branchEntryType("mu1_dxy", "F", "n_presel_mu >= 2", 100, -0.1, +0.1));
  branchesToCompare.push_back(new branchEntryType("mu1_eta", "F", "n_presel_mu >= 2", 100, -3., +3.));
  branchesToCompare.push_back(new branchEntryType("mu1_dz", "F", "n_presel_mu >= 2", 100, -0.2, +0.2));
  branchesToCompare.push_back(new branchEntryType("mu1_isfakeablesel", "I", "n_presel_mu >= 1", 2, -0.5, +1.5));
//  branchesToCompare.push_back(new branchEntryType("mu1_iscutsel", "I", "n_presel_mu >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("mu1_ismvasel", "I", "n_presel_mu >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("ele0_ntMVAeleID", "F", "n_presel_ele >= 1", 100, -1., +1.));
  branchesToCompare.push_back(new branchEntryType("ele0_charge", "I", "n_presel_ele >= 1", 3, -1.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("ele0_jetNDauChargedMVASel", "F", "n_presel_ele >= 1", 20, -0.5, +19.5));
  branchesToCompare.push_back(new branchEntryType("ele0_jetPtRel", "F", "n_presel_ele >= 1", 100, -0.01, 10.));
  branchesToCompare.push_back(new branchEntryType("ele0_miniIsoNeutral", "F", "n_presel_ele >= 1", 100, -0.01, 100.));
  branchesToCompare.push_back(new branchEntryType("ele0_miniIsoCharged", "F", "n_presel_ele >= 1", 100, -0.01, 100.));
  branchesToCompare.push_back(new branchEntryType("ele0_E", "F", "n_presel_ele >= 1", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("ele0_conept", "F", "", 100, 0., 1000.));
  branchesToCompare.push_back(new branchEntryType("ele0_jetPtRatio", "F", "n_presel_ele >= 1", 100, -0.01, 3.));
  branchesToCompare.push_back(new branchEntryType("ele0_leptonMVA", "F", "n_presel_ele >= 1", 100, -1., +1.));
  branchesToCompare.push_back(new branchEntryType("ele0_jetCSV", "F", "n_presel_ele >= 1", 100, 0., +1.));
  branchesToCompare.push_back(new branchEntryType("ele0_phi", "F", "n_presel_ele >= 1", 36, -TMath::Pi(), +TMath::Pi()));
  branchesToCompare.push_back(new branchEntryType("ele0_sip3D", "F", "n_presel_ele >= 1", 100, 0., +10.));
  branchesToCompare.push_back(new branchEntryType("ele0_pt", "F", "n_presel_ele >= 1", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("ele0_miniRelIso", "F", "n_presel_ele >= 1", 100, -0.01, 1.));
  branchesToCompare.push_back(new branchEntryType("ele0_dxy", "F", "n_presel_ele >= 1", 100, -0.1, +0.1));
  branchesToCompare.push_back(new branchEntryType("ele0_eta", "F", "n_presel_ele >= 1", 100, -3.0, +3.0));
  branchesToCompare.push_back(new branchEntryType("ele0_dz", "F", "n_presel_ele >= 1", 100, -0.2, +0.2));
  branchesToCompare.push_back(new branchEntryType("ele0_nMissingHits", "I", "n_presel_ele >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("ele0_isChargeConsistent", "I", "n_presel_ele >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("ele0_isfakeablesel", "I", "n_presel_ele >= 1", 2, -0.5, +1.5));
//  branchesToCompare.push_back(new branchEntryType("ele0_iscutsel", "I", "n_presel_ele >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("ele0_ismvasel", "I", "n_presel_ele >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("ele1_ntMVAeleID", "F", "n_presel_ele >= 2", 100, -1., +1.));
  branchesToCompare.push_back(new branchEntryType("ele1_charge", "I", "n_presel_ele >= 2", 3, -1.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("ele1_jetNDauChargedMVASel", "F", "n_presel_ele >= 2", 20, -0.5, +19.5));
  branchesToCompare.push_back(new branchEntryType("ele1_jetPtRel", "F", "n_presel_ele >= 2", 100, -0.01, 10.));
  branchesToCompare.push_back(new branchEntryType("ele1_miniIsoNeutral", "F", "n_presel_ele >= 2", 100, -0.01, 100.));
  branchesToCompare.push_back(new branchEntryType("ele1_miniIsoCharged", "F", "n_presel_ele >= 2", 100, -0.01, 100.));
  branchesToCompare.push_back(new branchEntryType("ele1_E", "F", "n_presel_ele >= 2", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("ele1_conept", "F", "", 100, 0., 500.));
  branchesToCompare.push_back(new branchEntryType("ele1_jetPtRatio", "F", "n_presel_ele >= 2", 100, -0.01, 3.));
  branchesToCompare.push_back(new branchEntryType("ele1_leptonMVA", "F", "n_presel_ele >= 2", 100, -1., +1.));
  branchesToCompare.push_back(new branchEntryType("ele1_jetCSV", "F", "n_presel_ele >= 2", 100, 0., +1.));
  branchesToCompare.push_back(new branchEntryType("ele1_phi", "F", "n_presel_ele >= 2", 36, -TMath::Pi(), +TMath::Pi()));
  branchesToCompare.push_back(new branchEntryType("ele1_sip3D", "F", "n_presel_ele >= 2", 100, 0., +10.));
  branchesToCompare.push_back(new branchEntryType("ele1_pt", "F", "n_presel_ele >= 2", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("ele1_miniRelIso", "F", "n_presel_ele >= 2", 100, -0.01, 1.));
  branchesToCompare.push_back(new branchEntryType("ele1_dxy", "F", "n_presel_ele >= 2", 100, -0.1, +0.1));
  branchesToCompare.push_back(new branchEntryType("ele1_eta", "F", "n_presel_ele >= 2", 100, -3.0, +3.0));
  branchesToCompare.push_back(new branchEntryType("ele1_dz", "F", "n_presel_ele >= 2", 100, -0.2, +0.2));
  branchesToCompare.push_back(new branchEntryType("ele1_nMissingHits", "I", "n_presel_ele >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("ele1_isChargeConsistent", "I", "n_presel_ele >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("ele1_isfakeablesel", "I", "n_presel_ele >= 2", 2, -0.5, +1.5));
//  branchesToCompare.push_back(new branchEntryType("ele1_iscutsel", "I", "n_presel_ele >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("ele1_ismvasel", "I", "n_presel_ele >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_againstElectronVTightMVA6", "I", "n_presel_tau >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_againstElectronTightMVA6", "I", "n_presel_tau >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_againstElectronMediumMVA6", "I", "n_presel_tau >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_againstElectronLooseMVA6", "I", "n_presel_tau >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_againstElectronVLooseMVA6", "I", "n_presel_tau >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_againstMuonLoose3", "I", "n_presel_tau >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_byVTightIsolationMVArun2v1DBdR03oldDMwLT", "I", "n_presel_tau >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_byTightIsolationMVArun2v1DBdR03oldDMwLT", "I", "n_presel_tau >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_byMediumIsolationMVArun2v1DBdR03oldDMwLT", "I", "n_presel_tau >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_byLooseCombinedIsolationDeltaBetaCorr3Hits", "I", "n_presel_tau >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_decayModeFindingOldDMs", "I", "n_presel_tau >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_againstMuonTight3", "I", "n_presel_tau >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_byLooseCombinedIsolationDeltaBetaCorr3HitsdR03", "I", "n_presel_tau >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_decayModeFindingNewDMs", "I", "n_presel_tau >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_charge", "I", "n_presel_tau >= 1", 3, -1.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_byTightCombinedIsolationDeltaBetaCorr3Hits", "I", "n_presel_tau >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_byMediumCombinedIsolationDeltaBetaCorr3Hits", "I", "n_presel_tau >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_byMediumCombinedIsolationDeltaBetaCorr3HitsdR03", "I", "n_presel_tau >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_byTightCombinedIsolationDeltaBetaCorr3HitsdR03", "I", "n_presel_tau >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_byLooseIsolationMVArun2v1DBdR03oldDMwLT", "F", "n_presel_tau >= 1", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau0_byCombinedIsolationDeltaBetaCorr3Hits", "F", "n_presel_tau >= 1", 100, -0.01, 5.));
  branchesToCompare.push_back(new branchEntryType("tau0_dz", "F", "n_presel_tau >= 1", 100, -0.3, +0.3));
  branchesToCompare.push_back(new branchEntryType("tau0_dxy", "F", "n_presel_tau >= 1", 100, -0.2, +0.2));
  branchesToCompare.push_back(new branchEntryType("tau0_pt", "F", "n_presel_tau >= 1", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("tau0_eta", "F", "n_presel_tau >= 1", 100, -3., +3.));
  branchesToCompare.push_back(new branchEntryType("tau0_phi", "F", "n_presel_tau >= 1", 36, -TMath::Pi(), +TMath::Pi()));
  branchesToCompare.push_back(new branchEntryType("tau0_E", "F", "n_presel_tau >= 1", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("tau1_againstElectronVTightMVA6", "I", "n_presel_tau >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau1_againstElectronTightMVA6", "I", "n_presel_tau >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau1_againstElectronMediumMVA6", "I", "n_presel_tau >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau1_againstElectronLooseMVA6", "I", "n_presel_tau >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau1_againstElectronVLooseMVA6", "I", "n_presel_tau >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau1_againstMuonLoose3", "I", "n_presel_tau >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau1_byVTightIsolationMVArun2v1DBdR03oldDMwLT", "I", "n_presel_tau >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau1_byTightIsolationMVArun2v1DBdR03oldDMwLT", "I", "n_presel_tau >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau1_byMediumIsolationMVArun2v1DBdR03oldDMwLT", "I", "n_presel_tau >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau1_byLooseCombinedIsolationDeltaBetaCorr3Hits", "I", "n_presel_tau >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau1_decayModeFindingOldDMs", "I", "n_presel_tau >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau1_againstMuonTight3", "I", "n_presel_tau >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau1_byLooseCombinedIsolationDeltaBetaCorr3HitsdR03", "I", "n_presel_tau >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau1_decayModeFindingNewDMs", "I", "n_presel_tau >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau1_charge", "I", "n_presel_tau >= 2", 3, -1.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau1_byTightCombinedIsolationDeltaBetaCorr3Hits", "I", "n_presel_tau >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau1_byMediumCombinedIsolationDeltaBetaCorr3Hits", "I", "n_presel_tau >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau1_byMediumCombinedIsolationDeltaBetaCorr3HitsdR03", "I", "n_presel_tau >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau1_byTightCombinedIsolationDeltaBetaCorr3HitsdR03", "I", "n_presel_tau >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau1_byLooseIsolationMVArun2v1DBdR03oldDMwLT", "F", "n_presel_tau >= 2", 2, -0.5, +1.5));
  branchesToCompare.push_back(new branchEntryType("tau1_byCombinedIsolationDeltaBetaCorr3Hits", "F", "n_presel_tau >= 2", 100, -0.01, 5.));
  branchesToCompare.push_back(new branchEntryType("tau1_dz", "F", "n_presel_tau >= 2", 100, -0.3, +0.3));
  branchesToCompare.push_back(new branchEntryType("tau1_dxy", "F", "n_presel_tau >= 2", 100, -0.2, +0.2));
  branchesToCompare.push_back(new branchEntryType("tau1_pt", "F", "n_presel_tau >= 2", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("tau1_eta", "F", "n_presel_tau >= 2", 100, -3., +3.));
  branchesToCompare.push_back(new branchEntryType("tau1_phi", "F", "n_presel_tau >= 2", 36, -TMath::Pi(), +TMath::Pi()));
  branchesToCompare.push_back(new branchEntryType("tau1_E", "F", "n_presel_tau >= 2", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("jet0_CSV", "F", "n_presel_jet >= 1", 100, 0., +1.));
  branchesToCompare.push_back(new branchEntryType("jet0_pt", "F", "n_presel_jet >= 1", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("jet0_eta", "F", "n_presel_jet >= 1", 100, -3., +3.));
  branchesToCompare.push_back(new branchEntryType("jet0_phi", "F", "n_presel_jet >= 1", 36, -TMath::Pi(), +TMath::Pi()));
  branchesToCompare.push_back(new branchEntryType("jet0_E", "F", "n_presel_jet >= 1", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("jet1_CSV", "F", "n_presel_jet >= 2", 100, 0., +1.));
  branchesToCompare.push_back(new branchEntryType("jet1_pt", "F", "n_presel_jet >= 2", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("jet1_eta", "F", "n_presel_jet >= 2", 100, -3., +3.));
  branchesToCompare.push_back(new branchEntryType("jet1_phi", "F", "n_presel_jet >= 2", 36, -TMath::Pi(), +TMath::Pi()));
  branchesToCompare.push_back(new branchEntryType("jet1_E", "F", "n_presel_jet >= 2", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("jet2_CSV", "F", "n_presel_jet >= 3", 100, 0., +1.));
  branchesToCompare.push_back(new branchEntryType("jet2_pt", "F", "n_presel_jet >= 3", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("jet2_eta", "F", "n_presel_jet >= 3", 100, -3., +3.));
  branchesToCompare.push_back(new branchEntryType("jet2_phi", "F", "n_presel_jet >= 3", 36, -TMath::Pi(), +TMath::Pi()));
  branchesToCompare.push_back(new branchEntryType("jet2_E", "F", "n_presel_jet >= 3", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("jet3_CSV", "F", "n_presel_jet >= 4", 100, 0., +1.));
  branchesToCompare.push_back(new branchEntryType("jet3_pt", "F", "n_presel_jet >= 4", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("jet3_eta", "F", "n_presel_jet >= 4", 100, -3., +3.));
  branchesToCompare.push_back(new branchEntryType("jet3_phi", "F", "n_presel_jet >= 4", 36, -TMath::Pi(), +TMath::Pi()));
  branchesToCompare.push_back(new branchEntryType("jet3_E", "F", "n_presel_jet >= 4", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("PFMET", "F", "", 100, 0., 250.));
  branchesToCompare.push_back(new branchEntryType("PFMETphi", "F", "", 36, -TMath::Pi(), +TMath::Pi()));
  branchesToCompare.push_back(new branchEntryType("MHT", "F", "", 100, 0., 600.));
  branchesToCompare.push_back(new branchEntryType("metLD", "F", "", 100, 0., 2.));
  branchesToCompare.push_back(new branchEntryType("lep0_conept", "F", "", 100, 0., 1000.));
  branchesToCompare.push_back(new branchEntryType("lep1_conept", "F", "", 100, 0., 500.));
  branchesToCompare.push_back(new branchEntryType("mindr_lep0_jet", "F", "", 100, 0., 5.));
  branchesToCompare.push_back(new branchEntryType("mindr_lep1_jet", "F", "", 100, 0., 5.));
//  branchesToCompare.push_back(new branchEntryType("n_jet25_recl", "F", "", 100, 0., 50.));
  branchesToCompare.push_back(new branchEntryType("MT_met_lep0", "F", "", 100, 0., 500.));
  branchesToCompare.push_back(new branchEntryType("avg_dr_jet", "F", "", 100, 0., 6.));
  branchesToCompare.push_back(new branchEntryType("MVA_2lss_ttV", "F", "(n_fakeablesel_mu + n_fakeablesel_ele) >= 2", 100, -1., 1.));
  branchesToCompare.push_back(new branchEntryType("MVA_2lss_ttbar", "F", "(n_fakeablesel_mu + n_fakeablesel_ele) >= 2", 100, -1., 1.));

  for ( std::vector<branchEntryType*>::const_iterator branch = branchesToCompare.begin();
        branch != branchesToCompare.end(); ++branch ) {
    std::cout << "plotting " << (*branch)->branchName_ << "..." << std::endl;

    branchEntryType* branch_ref = (*branch)->Clone("ref");
    if(branch_ref->fillHistogram(tree_ref, ref.selection) < 0)
      branch_ref->histogram_ = nullptr;
    else
      normalizeHistogram(branch_ref->histogram_);
    
    branchEntryType* branch_test = (*branch)->Clone("test");
    if(branch_test->fillHistogram(tree_test, test.selection) < 0)
      branch_test->histogram_ = nullptr;
    else
      normalizeHistogram(branch_test->histogram_);

    std::string outputFileName = Form("compareSyncNtuples_%s.png", (*branch)->branchName_.data());
    showHistograms(800, 900, 
                   branch_ref->histogram_, ref.legendEntry,
                   branch_test->histogram_, test.legendEntry,
                   NULL, "",
                   NULL, "",
                   NULL, "",
                   NULL, "",
                   (*branch)->branchName_, 1.10,
                   true, 1.e-4, 1.e+1, "N", 1.30,
                   0.16, 0.80,
                   outputFilePath, outputFileName);

    delete branch_ref;
    delete branch_test;
  }
  
  for ( std::vector<branchEntryType*>::const_iterator it = branchesToCompare.end();
        it != branchesToCompare.end(); ++it ) {
    delete (*it);
  }

  delete inputFile_ref;
  delete inputFile_test;
}
void plotTauIdMVAEfficiency_and_FakeRate()
{
//--- stop ROOT from keeping references to all histograms
  TH1::AddDirectory(false);

//--- suppress the output canvas 
  gROOT->SetBatch(true);

  std::vector<mvaEntryType*> mvaEntries;
  mvaEntries.push_back(new mvaEntryType("/data1/veelken/tmp/tauIdMVATraining/tauId_v1_6/trainTauIdMVA_mvaIsolation3HitsDeltaR04opt1b.root",     "opt1b",   0.80, kLogTauPt, kTauAbsEta));
  mvaEntries.push_back(new mvaEntryType("/data1/veelken/tmp/tauIdMVATraining/tauId_v1_6/trainTauIdMVA_mvaIsolation3HitsDeltaR04opt1c.root",     "opt1c",   0.80, kTauPt, kTauAbsEta));
  mvaEntries.push_back(new mvaEntryType("/data1/veelken/tmp/tauIdMVATraining/tauId_v1_13_4/trainTauIdMVA_mvaIsolation3HitsDeltaR05opt2a.root",   "opt2a",   0.80, kLogTauPt, kTauAbsEta));
  mvaEntries.push_back(new mvaEntryType("/data1/veelken/tmp/tauIdMVATraining/tauId_v1_13_4/trainTauIdMVA_mvaIsolation3HitsDeltaR05opt2aLT.root", "opt2aLT", 0.80, kLogTauPt, kTauAbsEta));
  mvaEntries.push_back(new mvaEntryType("/data1/veelken/tmp/tauIdMVATraining/tauId_v1_13_4/trainTauIdMVA_mvaIsolation3HitsDeltaR05opt2b.root",   "opt2b",   0.80, kLogTauPt, kTauAbsEta));
  mvaEntries.push_back(new mvaEntryType("/data1/veelken/tmp/tauIdMVATraining/tauId_v1_13_4/trainTauIdMVA_mvaIsolation3HitsDeltaR05opt2bLT.root", "opt2bLT", 0.80, kLogTauPt, kTauAbsEta));

  for ( std::vector<mvaEntryType*>::iterator mvaEntry = mvaEntries.begin();
	mvaEntry != mvaEntries.end(); ++mvaEntry ) {
    std::cout << "processing " << (*mvaEntry)->legendEntry_ << std::endl;
    fillPlots((*mvaEntry)->inputFileName_, (*mvaEntry)->plots_signal_, (*mvaEntry)->plots_background_, 
	      (*mvaEntry)->mvaCut_, 
	      (*mvaEntry)->tauPtMode_, (*mvaEntry)->tauEtaMode_, 
	      (*mvaEntry)->mvaOutput_normalization_);
  }
/*  
  showEfficiency("", 800, 600,
		 mvaEntries[0]->plots_signal_->histogramPt_numerator_, mvaEntries[0]->plots_signal_->histogramPt_denominator_, mvaEntries[0]->legendEntry_,
		 mvaEntries[1]->plots_signal_->histogramPt_numerator_, mvaEntries[1]->plots_signal_->histogramPt_denominator_, mvaEntries[1]->legendEntry_,
		 mvaEntries[2]->plots_signal_->histogramPt_numerator_, mvaEntries[2]->plots_signal_->histogramPt_denominator_, mvaEntries[2]->legendEntry_,
		 mvaEntries[3]->plots_signal_->histogramPt_numerator_, mvaEntries[3]->plots_signal_->histogramPt_denominator_, mvaEntries[3]->legendEntry_,
		 mvaEntries[4]->plots_signal_->histogramPt_numerator_, mvaEntries[4]->plots_signal_->histogramPt_denominator_, mvaEntries[4]->legendEntry_,
		 mvaEntries[5]->plots_signal_->histogramPt_numerator_, mvaEntries[5]->plots_signal_->histogramPt_denominator_, mvaEntries[5]->legendEntry_,
		 "P_{T} / GeV", 1.2, 
		 false, 0.5, 1., "Efficiency", 1.2, 
		 0.61, 0.165, 
		 "plots/plotTauIdMVAEfficiency_vs_Pt.png");
  showEfficiency("", 800, 600,
		 mvaEntries[0]->plots_signal_->histogramEta_numerator_, mvaEntries[0]->plots_signal_->histogramEta_denominator_, mvaEntries[0]->legendEntry_,
		 mvaEntries[1]->plots_signal_->histogramEta_numerator_, mvaEntries[1]->plots_signal_->histogramEta_denominator_, mvaEntries[1]->legendEntry_,
		 mvaEntries[2]->plots_signal_->histogramEta_numerator_, mvaEntries[2]->plots_signal_->histogramEta_denominator_, mvaEntries[2]->legendEntry_,
		 mvaEntries[3]->plots_signal_->histogramEta_numerator_, mvaEntries[3]->plots_signal_->histogramEta_denominator_, mvaEntries[3]->legendEntry_,
		 mvaEntries[4]->plots_signal_->histogramEta_numerator_, mvaEntries[4]->plots_signal_->histogramEta_denominator_, mvaEntries[4]->legendEntry_,
		 mvaEntries[5]->plots_signal_->histogramEta_numerator_, mvaEntries[5]->plots_signal_->histogramEta_denominator_, mvaEntries[5]->legendEntry_,
		 "#eta", 1.2, 
		 false, 0.5, 1., "Efficiency", 1.2, 
		 0.61, 0.165, 
		 "plots/plotTauIdMVAEfficiency_vs_Eta.png");
  showEfficiency("", 800, 600,
		 mvaEntries[0]->plots_signal_->histogramNvtx_numerator_, mvaEntries[0]->plots_signal_->histogramNvtx_denominator_, mvaEntries[0]->legendEntry_,
		 mvaEntries[1]->plots_signal_->histogramNvtx_numerator_, mvaEntries[1]->plots_signal_->histogramNvtx_denominator_, mvaEntries[1]->legendEntry_,
		 mvaEntries[2]->plots_signal_->histogramNvtx_numerator_, mvaEntries[2]->plots_signal_->histogramNvtx_denominator_, mvaEntries[2]->legendEntry_,
		 mvaEntries[3]->plots_signal_->histogramNvtx_numerator_, mvaEntries[3]->plots_signal_->histogramNvtx_denominator_, mvaEntries[3]->legendEntry_,
		 mvaEntries[4]->plots_signal_->histogramNvtx_numerator_, mvaEntries[4]->plots_signal_->histogramNvtx_denominator_, mvaEntries[4]->legendEntry_,
		 mvaEntries[5]->plots_signal_->histogramNvtx_numerator_, mvaEntries[5]->plots_signal_->histogramNvtx_denominator_, mvaEntries[5]->legendEntry_,
		 "N_{vtx}", 1.2, 
		 false, 0.5, 1., "Efficiency", 1.2, 
		 0.61, 0.165, 
		 "plots/plotTauIdMVAEfficiency_vs_Nvtx.png");
  
  showEfficiency("", 800, 600,
		 mvaEntries[0]->plots_background_->histogramPt_numerator_, mvaEntries[0]->plots_background_->histogramPt_denominator_, mvaEntries[0]->legendEntry_,
		 mvaEntries[1]->plots_background_->histogramPt_numerator_, mvaEntries[1]->plots_background_->histogramPt_denominator_, mvaEntries[1]->legendEntry_,
		 mvaEntries[2]->plots_background_->histogramPt_numerator_, mvaEntries[2]->plots_background_->histogramPt_denominator_, mvaEntries[2]->legendEntry_,
		 mvaEntries[3]->plots_background_->histogramPt_numerator_, mvaEntries[3]->plots_background_->histogramPt_denominator_, mvaEntries[3]->legendEntry_,
		 mvaEntries[4]->plots_background_->histogramPt_numerator_, mvaEntries[4]->plots_background_->histogramPt_denominator_, mvaEntries[4]->legendEntry_,
		 mvaEntries[5]->plots_background_->histogramPt_numerator_, mvaEntries[5]->plots_background_->histogramPt_denominator_, mvaEntries[5]->legendEntry_,
		 "P_{T} / GeV", 1.2, 
		 true, 1.e-3, 1., "Fake-rate", 1.2, 
		 0.61, 0.545,
		 "plots/plotTauIdMVAFakeRate_vs_Pt.png");
  showEfficiency("", 800, 600,
		 mvaEntries[0]->plots_background_->histogramEta_numerator_, mvaEntries[0]->plots_background_->histogramEta_denominator_, mvaEntries[0]->legendEntry_,
		 mvaEntries[1]->plots_background_->histogramEta_numerator_, mvaEntries[1]->plots_background_->histogramEta_denominator_, mvaEntries[1]->legendEntry_,
		 mvaEntries[2]->plots_background_->histogramEta_numerator_, mvaEntries[2]->plots_background_->histogramEta_denominator_, mvaEntries[2]->legendEntry_,
		 mvaEntries[3]->plots_background_->histogramEta_numerator_, mvaEntries[3]->plots_background_->histogramEta_denominator_, mvaEntries[3]->legendEntry_,
		 mvaEntries[4]->plots_background_->histogramEta_numerator_, mvaEntries[4]->plots_background_->histogramEta_denominator_, mvaEntries[4]->legendEntry_,
		 mvaEntries[5]->plots_background_->histogramEta_numerator_, mvaEntries[5]->plots_background_->histogramEta_denominator_, mvaEntries[5]->legendEntry_,
		 "#eta", 1.2, 
		 true, 1.e-3, 1., "Fake-rate", 1.2, 
		 0.61, 0.545,
		 "plots/plotTauIdMVAFakeRate_vs_Eta.png");
  showEfficiency("", 800, 600,
		 mvaEntries[0]->plots_background_->histogramNvtx_numerator_, mvaEntries[0]->plots_background_->histogramNvtx_denominator_, mvaEntries[0]->legendEntry_,
		 mvaEntries[1]->plots_background_->histogramNvtx_numerator_, mvaEntries[1]->plots_background_->histogramNvtx_denominator_, mvaEntries[1]->legendEntry_,
		 mvaEntries[2]->plots_background_->histogramNvtx_numerator_, mvaEntries[2]->plots_background_->histogramNvtx_denominator_, mvaEntries[2]->legendEntry_,
		 mvaEntries[3]->plots_background_->histogramNvtx_numerator_, mvaEntries[3]->plots_background_->histogramNvtx_denominator_, mvaEntries[3]->legendEntry_,
		 mvaEntries[4]->plots_background_->histogramNvtx_numerator_, mvaEntries[4]->plots_background_->histogramNvtx_denominator_, mvaEntries[4]->legendEntry_,
		 mvaEntries[5]->plots_background_->histogramNvtx_numerator_, mvaEntries[5]->plots_background_->histogramNvtx_denominator_, mvaEntries[5]->legendEntry_,
		 "N_{vtx}", 1.2, 
		 true, 1.e-3, 1., "Fake-rate", 1.2, 
		 0.61, 0.545,
		 "plots/plotTauIdMVAFakeRate_vs_Nvtx.png");
 */

  for ( std::vector<mvaEntryType*>::iterator mvaEntry = mvaEntries.begin();
	mvaEntry != mvaEntries.end(); ++mvaEntry ) {

    normalizeHistogram((*mvaEntry)->plots_signal_->histogramPt_numerator_);
    normalizeHistogram((*mvaEntry)->plots_signal_->histogramPt_denominator_);
    normalizeHistogram((*mvaEntry)->plots_signal_->histogramEta_numerator_);
    normalizeHistogram((*mvaEntry)->plots_signal_->histogramEta_denominator_);
    normalizeHistogram((*mvaEntry)->plots_signal_->histogramNvtx_numerator_);
    normalizeHistogram((*mvaEntry)->plots_signal_->histogramNvtx_denominator_);

    normalizeHistogram((*mvaEntry)->plots_background_->histogramPt_numerator_);
    normalizeHistogram((*mvaEntry)->plots_background_->histogramPt_denominator_);
    normalizeHistogram((*mvaEntry)->plots_background_->histogramEta_numerator_);
    normalizeHistogram((*mvaEntry)->plots_background_->histogramEta_denominator_);
    normalizeHistogram((*mvaEntry)->plots_background_->histogramNvtx_numerator_);
    normalizeHistogram((*mvaEntry)->plots_background_->histogramNvtx_denominator_);

    showDistribution("", 800, 600,
		     (*mvaEntry)->plots_signal_->histogramPt_denominator_, "Signal",
		     (*mvaEntry)->plots_background_->histogramPt_denominator_, "Background",
		     0, "",
		     0, "",
		     "P_{T} / GeV", 1.2, 
		     true, 1.e-3, 1., "a.u.", 1.2, 
		     0.145, 0.745, 
		     TString(Form("plots/plotTauIdMVAEfficiency_and_FakeRate_denominatorPt_%s.png", (*mvaEntry)->legendEntry_.data())).ReplaceAll(" ", "").Data());
    showDistribution("", 800, 600,
		     (*mvaEntry)->plots_signal_->histogramEta_denominator_, "Signal",
		     (*mvaEntry)->plots_background_->histogramEta_denominator_, "Background",
		     0, "",
		     0, "",
		     "#eta", 1.2, 
		     true, 1.e-3, 1., "a.u.", 1.2, 
		     0.145, 0.745, 
		     TString(Form("plots/plotTauIdMVAEfficiency_and_FakeRate_denominatorEta_%s.png", (*mvaEntry)->legendEntry_.data())).ReplaceAll(" ", "").Data());
    showDistribution("", 800, 600,
		     (*mvaEntry)->plots_signal_->histogramNvtx_denominator_, "Signal",
		     (*mvaEntry)->plots_background_->histogramNvtx_denominator_, "Background",
		     0, "",
		     0, "",
		     "N_{vtx}", 1.2, 
		     true, 1.e-3, 1., "a.u.", 1.2, 
		     0.145, 0.745, 
		     TString(Form("plots/plotTauIdMVAEfficiency_and_FakeRate_denominatorNvtx_%s.png", (*mvaEntry)->legendEntry_.data())).ReplaceAll(" ", "").Data());

    TGraph* graphEfficiencyEq40percent = compMVAcut((*mvaEntry)->plots_signal_->histogramMVAoutput_vs_Pt_, (*mvaEntry)->plots_signal_->histogramPt_, 0.40);
    TGraph* graphEfficiencyEq50percent = compMVAcut((*mvaEntry)->plots_signal_->histogramMVAoutput_vs_Pt_, (*mvaEntry)->plots_signal_->histogramPt_, 0.50);
    TGraph* graphEfficiencyEq60percent = compMVAcut((*mvaEntry)->plots_signal_->histogramMVAoutput_vs_Pt_, (*mvaEntry)->plots_signal_->histogramPt_, 0.60);
    TGraph* graphEfficiencyEq70percent = compMVAcut((*mvaEntry)->plots_signal_->histogramMVAoutput_vs_Pt_, (*mvaEntry)->plots_signal_->histogramPt_, 0.70);
    TGraph* graphEfficiencyEq80percent = compMVAcut((*mvaEntry)->plots_signal_->histogramMVAoutput_vs_Pt_, (*mvaEntry)->plots_signal_->histogramPt_, 0.80);
    TGraph* graphEfficiencyEq90percent = compMVAcut((*mvaEntry)->plots_signal_->histogramMVAoutput_vs_Pt_, (*mvaEntry)->plots_signal_->histogramPt_, 0.90);

    showGraphs("#tau_{had} Efficiency", 800, 600,
	       graphEfficiencyEq90percent, "90%",
	       graphEfficiencyEq80percent, "80%",
	       graphEfficiencyEq70percent, "70%",
	       graphEfficiencyEq60percent, "60%",
	       graphEfficiencyEq50percent, "50%",
	       graphEfficiencyEq40percent, "40%",
	       0., 2500., 10, "P_{T} / GeV", 1.2,
	       0.0, 1.0, "MVA_{cut}", 1.35,
	       0.69, 0.145, 
	       TString(Form("plots/plotTauIdMVAEfficiency_MVAcutVsPtConstEfficiency_%s.png", (*mvaEntry)->legendEntry_.data())).ReplaceAll(" ", "").Data());

    std::string outputFileName_MVAoutput_vs_Pt = Form("plots/plotTauIdMVAEfficiency_and_FakeRate_MVAoutput_vs_Pt_%s.root", (*mvaEntry)->mvaName_.data());
    TFile* outputFile_MVAoutput_vs_Pt = new TFile(outputFileName_MVAoutput_vs_Pt.data(), "RECREATE");
    (*mvaEntry)->plots_signal_->histogramMVAoutput_vs_Pt_->Write();
    delete outputFile_MVAoutput_vs_Pt;

    std::string outputFileName_effGraphs = Form("wpDiscriminationByIsolationMVA3_%s.root", (*mvaEntry)->mvaName_.data());
    graphEfficiencyEq90percent->SetName(Form("%sEff90", (*mvaEntry)->mvaName_.data()));
    graphEfficiencyEq80percent->SetName(Form("%sEff80", (*mvaEntry)->mvaName_.data()));
    graphEfficiencyEq70percent->SetName(Form("%sEff70", (*mvaEntry)->mvaName_.data()));
    graphEfficiencyEq60percent->SetName(Form("%sEff60", (*mvaEntry)->mvaName_.data()));
    graphEfficiencyEq50percent->SetName(Form("%sEff50", (*mvaEntry)->mvaName_.data()));
    graphEfficiencyEq40percent->SetName(Form("%sEff40", (*mvaEntry)->mvaName_.data()));      
    TFile* outputFile_effGraphs = new TFile(outputFileName_effGraphs.data(), "RECREATE");
    graphEfficiencyEq90percent->Write();
    graphEfficiencyEq80percent->Write();
    graphEfficiencyEq70percent->Write();
    graphEfficiencyEq60percent->Write();
    graphEfficiencyEq50percent->Write();
    graphEfficiencyEq40percent->Write();
    (*mvaEntry)->mvaOutput_normalization_->Write();
    delete outputFile_effGraphs;

    TGraph* graphFakeRateEq001percent = compMVAcut((*mvaEntry)->plots_background_->histogramMVAoutput_vs_Pt_, (*mvaEntry)->plots_background_->histogramPt_, 0.001);
    TGraph* graphFakeRateEq002percent = compMVAcut((*mvaEntry)->plots_background_->histogramMVAoutput_vs_Pt_, (*mvaEntry)->plots_background_->histogramPt_, 0.002);
    TGraph* graphFakeRateEq005percent = compMVAcut((*mvaEntry)->plots_background_->histogramMVAoutput_vs_Pt_, (*mvaEntry)->plots_background_->histogramPt_, 0.005);
    TGraph* graphFakeRateEq010percent = compMVAcut((*mvaEntry)->plots_background_->histogramMVAoutput_vs_Pt_, (*mvaEntry)->plots_background_->histogramPt_, 0.010);
    TGraph* graphFakeRateEq020percent = compMVAcut((*mvaEntry)->plots_background_->histogramMVAoutput_vs_Pt_, (*mvaEntry)->plots_background_->histogramPt_, 0.020);
    TGraph* graphFakeRateEq050percent = compMVAcut((*mvaEntry)->plots_background_->histogramMVAoutput_vs_Pt_, (*mvaEntry)->plots_background_->histogramPt_, 0.050);
    
    showGraphs("#tau_{had} Fake-rate", 800, 600,
	       graphFakeRateEq050percent, "5%",
	       graphFakeRateEq020percent, "2%",
	       graphFakeRateEq010percent, "1%",
	       graphFakeRateEq005percent, "0.5%",
	       graphFakeRateEq002percent, "0.2%",
	       graphFakeRateEq001percent, "0.1%",
	       0., 2500., 10, "P_{T} / GeV", 1.2,
	       0.0, 1.0, "MVA_{cut}", 1.35,
	       0.69, 0.145, 
	       TString(Form("plots/plotTauIdMVAEfficiency_MVAcutVsPtConstFakeRate_%s.png", (*mvaEntry)->legendEntry_.data())).ReplaceAll(" ", "").Data());
  }    

  for ( std::vector<mvaEntryType*>::iterator it = mvaEntries.begin();
	it != mvaEntries.end(); ++it ) {
    delete (*it);
  }
}
Пример #7
0
void BackgroundSubtractorGMG::PixelModelGMG::insertFeature(double learningRate)
{

    std::list<HistogramFeatureGMG>::iterator feature;
    std::list<HistogramFeatureGMG>::iterator swap_end;
    std::list<HistogramFeatureGMG>::iterator last_feature = histogram.end();
    /*
     * If feature is in histogram already, add the weights, and move feature to front.
     * If there are too many features, remove the end feature and push new feature to beginning
     */
    if (learningRate == -1.0) // then, this is a training-mode update.
    {
        /*
         * (1) Check if feature already represented in histogram
         */
        lastObservedFeature.likelihood = 1.0;

        for (feature = histogram.begin(); feature != last_feature; ++feature)
        {
            if (lastObservedFeature == *feature)  // feature in histogram
            {
                feature->likelihood += lastObservedFeature.likelihood;
                // now, move feature to beginning of list and break the loop
                HistogramFeatureGMG tomove = *feature;
                histogram.erase(feature);
                histogram.push_front(tomove);
                return;
            }
        }
        if (numFeatures == maxFeatures)
        {
            histogram.pop_back(); // discard oldest feature
            histogram.push_front(lastObservedFeature);
        }
        else
        {
            histogram.push_front(lastObservedFeature);
            ++numFeatures;
        }
    }
    else
    {
        /*
         * (1) Scale entire histogram by scaling factor
         * (2) Scale input feature.
         * (3) Check if feature already represented. If so, simply add.
         * (4) If feature is not represented, remove old feature, distribute weight evenly among existing features, add in new feature.
         */
        *this *= float(1.0-learningRate);
        lastObservedFeature.likelihood = float(learningRate);

        for (feature = histogram.begin(); feature != last_feature; ++feature)
        {
            if (lastObservedFeature == *feature)  // feature in histogram
            {
                lastObservedFeature.likelihood += feature->likelihood;
                histogram.erase(feature);
                histogram.push_front(lastObservedFeature);
                return;  // done with the update.
            }
        }
        if (numFeatures == maxFeatures)
        {
            histogram.pop_back(); // discard oldest feature
            histogram.push_front(lastObservedFeature);
            normalizeHistogram();
        }
        else
        {
            histogram.push_front(lastObservedFeature);
            ++numFeatures;
        }
    }
}
Пример #8
0
void testAbsDiffHistograms()
{
    printf("\nTEST HISTOGRAM DIFFERENCE\n");

    // Construction d'histogrammes de test
    int channel = 0;
    Histogram h1;
    initHistogram(&h1, 5, 3);
    h1.freq[0][channel] = 12;   // 0.11
    h1.freq[1][channel] = 15;   // 0.14
    h1.freq[2][channel] = 20;   // 0.18
    h1.freq[3][channel] = 45;   // 0.41
    h1.freq[4][channel] = 19;   // 0.17
    
    Histogram h2;
    initHistogram(&h2, 5, 3);
    h2.freq[0][channel] = 3;    // 0.02
    h2.freq[1][channel] = 17;   // 0.14
    h2.freq[2][channel] = 19;   // 0.15
    h2.freq[3][channel] = 70;   // 0.56
    h2.freq[4][channel] = 16;   // 0.13

    float sum = absDiffHistograms(&h1, &h2, channel);
    printf("Expected: 40.00, Actual: %.2f\n", sum);

    // Avec histogrammes normalises
    normalizeHistogram(&h1);
    normalizeHistogram(&h2);

    sum = absDiffHistograms(&h1, &h2, channel);
    printf("Expected: 0.31, Actual: %.2f\n", sum);


    // Test 2: histogrammes identiques
    //
    h1.freq[0][channel] = 12;   // 0.11
    h1.freq[1][channel] = 15;   // 0.14
    h1.freq[2][channel] = 20;   // 0.18
    h1.freq[3][channel] = 45;   // 0.41
    h1.freq[4][channel] = 19;   // 0.17

    h2.freq[0][channel] = 12;   // 0.11
    h2.freq[1][channel] = 15;   // 0.14
    h2.freq[2][channel] = 20;   // 0.18
    h2.freq[3][channel] = 45;   // 0.41
    h2.freq[4][channel] = 19;   // 0.17

    normalizeHistogram(&h1);
    normalizeHistogram(&h2);

    sum = absDiffHistograms(&h1, &h2, channel);
    printf("Expected: 0.00, Actual: %.2f\n", sum);


    // Test 3: histogrammes disjoints completement
    //
    h1.freq[0][channel] = 0;   // 0.00
    h1.freq[1][channel] = 0;   // 0.00
    h1.freq[2][channel] = 0;   // 0.00
    h1.freq[3][channel] = 45;  // 0.70
    h1.freq[4][channel] = 19;  // 0.30

    h2.freq[0][channel] = 23;  // 0.56
    h2.freq[1][channel] = 15;  // 0.37
    h2.freq[2][channel] = 3;   // 0.07
    h2.freq[3][channel] = 0;   // 0.00
    h2.freq[4][channel] = 0;   // 0.00

    normalizeHistogram(&h1);
    normalizeHistogram(&h2);

    sum = absDiffHistograms(&h1, &h2, channel);
    printf("Expected: 2.00, Actual: %.2f\n", sum);
}