ROOT logo
#include "TTree.h"
#include "TH2D.h"
#include "TH1D.h"
#include "TH3D.h"
#include "TH3F.h"
#include "THnSparse.h"
#include "TProfile.h"
#include "TProfile2D.h"
#include "TF1.h"
#include "TFitResultPtr.h"
#include "TFitResult.h"
#include "TCanvas.h"
#include "TStyle.h"
#include "TVirtualFitter.h"
#include "TLinearFitter.h"
#include "TList.h"
#include "TString.h"
#include "TLegend.h"
#include "TLegendEntry.h"
#include "TFile.h"
#include "TGraphErrors.h"
#include "TGraph.h"
#include "TMath.h"
#include "TDatime.h"
#include "TSystem.h"
#include "TSpline.h"

#include "AliPID.h"

#include <iostream>
#include <iomanip>

#include "THnSparseDefinitions.h"
#include "ProgressBar.h"

enum mapType {
  kNoNormalisation = 1,
  kSmallEtaNormalisation = 2,
  kLargeEtaNormalisation = 3
};
enum type {
  kTypeDelta = 1,
  kTypeDeltaPrime = 2,
  kTypeSigmaDeltaPrime = 3
};

const Double_t binContentThreshold = 1e-4;
const TString suffixMapType[kLargeEtaNormalisation + 1] = {"", "NoNormalisation", "SmallEtaNormalisation", "LargeEtaNormalisation"};

//__________________________________________________________________________________________
Int_t getBinX(TH2D* h, Double_t tanTheta)
{
  Int_t binX = h->GetXaxis()->FindBin(tanTheta);
  
  if (binX <= 0)
    binX = 1;
  if (binX > h->GetXaxis()->GetNbins())
    binX = h->GetXaxis()->GetNbins();

    return binX;
}


//_________________________________________________________________________________________
Int_t getBinY(TH2D* h, Double_t dEdxInv)
{
  Int_t binY = h->GetYaxis()->FindBin(dEdxInv);
  
  if (binY <= 0)
    binY = 1;
  if (binY > h->GetYaxis()->GetNbins())
    binY = h->GetYaxis()->GetNbins();

  return binY;
}


//__________________________________________________________________________________________
void SetHistAxis(TH2D* h, Int_t type)
{
  h->GetXaxis()->SetTitle("tan(#Theta)");
  h->GetYaxis()->SetTitle("1/(dE/dx) (arb. unit)");
  if (type == kTypeDelta)
    h->GetZaxis()->SetTitle("#Delta (arb. unit)");
  else if (type == kTypeDeltaPrime) 
    h->GetZaxis()->SetTitle("#Delta' (arb. unit)");
  else if (type == kTypeSigmaDeltaPrime) 
    h->GetZaxis()->SetTitle("Par1(#sigma_{rel}(#Delta'))");
  else
    printf("SetHistAxis: Unknown type %d!\n", type);
  h->GetXaxis()->SetTitleSize(0.04);
  h->GetXaxis()->SetTitleOffset(2.2);
  h->GetXaxis()->SetLabelSize(0.03);
  h->GetYaxis()->SetTitleSize(0.04);
  h->GetYaxis()->SetTitleOffset(2.6);
  h->GetYaxis()->SetLabelSize(0.03);
  h->GetZaxis()->SetTitleSize(0.04);
  h->GetZaxis()->SetTitleOffset(1.3);
}

//__________________________________________________________________________________________
Double_t getMedianOfNonZeros(Double_t* input, const Int_t dim)
{
  Double_t values[dim];
  for (Int_t i = 0; i < dim; i++)
    values[i] = 0.0;
    
  Int_t numNonZero = 0;
  
  for (Int_t i = 0; i < dim; i++) {
    if (input[i] > 0) {
      values[numNonZero] = input[i];
      numNonZero++;
    }
  }

  return ((numNonZero > 0) ? TMath::Median(numNonZero, values) : 0);
}


//__________________________________________________________________________________________
void normaliseHisto(TH2D* h, Double_t lowerLimit, Double_t upperLimit, Int_t type)
{
  if (lowerLimit >= upperLimit) {
    printf("!!!Error normaliseHisto: lowerLimit >= upperLimit!\n");
    return;
  }
  
  if (lowerLimit < 0 || upperLimit < 0) {
    printf("!!!Error normaliseHisto: lowerLimit, upperLimit >= 0 required!\n");
    return;
  }
  
  Int_t binLow = h->GetXaxis()->FindBin(lowerLimit);
  if (binLow < 1)
    binLow = 1;
  
  Int_t binHigh = h->GetXaxis()->FindBin(upperLimit);
  if (binHigh > h->GetXaxis()->GetNbins())
    binHigh = h->GetXaxis()->GetNbins();
  
  Int_t binLow2 = h->GetXaxis()->FindBin(-upperLimit);
  if (binLow2 < 1)
    binLow2 = 1;
  
  Int_t binHigh2 = h->GetXaxis()->FindBin(-lowerLimit);
  if (binHigh2 > h->GetXaxis()->GetNbins())
    binHigh2 = h->GetXaxis()->GetNbins();
  
  // If 0 is included in range, it might happen that both ranges overlap -> Remove one of the double counted binsPforMap
    if (binHigh2 >= binLow) {
      binHigh2 = binLow - 1;
      if (binHigh2 < 1)   {
        printf("!!!Error: binHigh2 = binLow - 1 is < 1\n");
        return;
      }
    }
    
    if (binLow2 > binHigh2)
      binLow2 = binHigh2;
    
    // Normalise with respect to some given tan(theta)
      // To be robust against fluctuations: Take median of a few tan(theta) bins around the desired value for scaling
      const Int_t nThetaBins = (binHigh - binLow + 1) + (binHigh2 - binLow2 + 1);
      
      if (nThetaBins <= 0)  {
        printf("Cannot renormalise histo due to bad limits for reference bins: %f -> %f\n", lowerLimit, upperLimit);
        return;
      }
      
      Double_t* values;
      values = new Double_t[nThetaBins];
      
      for (Int_t i = 1; i <= h->GetYaxis()->GetNbins(); i++) {
        // Reset values
        Int_t binIndex = 0;
        for (Int_t thetaBin = 1; thetaBin <= nThetaBins; thetaBin++)
          values[thetaBin - 1] = 0;
        
        for (Int_t thetaBin = binLow; thetaBin <= binHigh; thetaBin++)  {
          Double_t temp = h->GetBinContent(thetaBin, i);
          values[binIndex] = (temp > 0 || type == kTypeDelta) ? temp : 0;
          binIndex++;
        }
        for (Int_t thetaBin = binLow2; thetaBin <= binHigh2; thetaBin++)  {
          Double_t temp = h->GetBinContent(thetaBin, i);
          values[binIndex] = (temp > 0 || type == kTypeDelta) ? temp : 0;
          binIndex++;
        }
        
        Double_t temp = 0;
        Double_t scale = 0;
        
        if (type == kTypeDeltaPrime)  {
          temp = getMedianOfNonZeros(values, nThetaBins);
          if (temp <= 0)
            continue;
          scale = 1. / temp;
        }
        else if (type == kTypeDelta)  {
          scale = TMath::Median(nThetaBins, values);
        }
        else  {
          printf("Error: Type %d not supported for normalisation!\n", type);
          return;
        }
        
        
        for (Int_t thetaBin = 1; thetaBin <= h->GetXaxis()->GetNbins(); thetaBin++)  {
          if (type == kTypeDeltaPrime)  {
            h->SetBinContent(thetaBin, i, h->GetBinContent(thetaBin, i) * scale);
            h->SetBinError(thetaBin, i, h->GetBinError(thetaBin, i) * scale);
          }
          else if (type == kTypeDelta)  {
            h->SetBinContent(thetaBin, i, h->GetBinContent(thetaBin, i) - scale);
            h->SetBinError(thetaBin, i, h->GetBinError(thetaBin, i) - scale);
          }
        }
      }  
      delete values;
}


//__________________________________________________________________________________________
void eliminateNonPositivePointsInHisto(TH2D* h)
{
  const Int_t nNeighbours = 24;
  Double_t* values;
  values = new Double_t[nNeighbours];

  // Search for bins with content <= 0 (bins with fit errors). Then take all surrounding points in +-2 rows and columns
  // and take their median (only those bins without fit errors!) as the new bin content of the considered bin.
  
  for (Int_t binX = 1; binX <= h->GetXaxis()->GetNbins(); binX++) {
    Int_t firstBinLeft = TMath::Max(1, binX - 2);
    Int_t lastBinRight = TMath::Min(h->GetXaxis()->GetNbins(), binX + 2);
    
    for (Int_t binY = 1; binY <= h->GetYaxis()->GetNbins(); binY++) {
      if (h->GetBinContent(binX, binY) <= 0) {
        Int_t firstBinBelow = TMath::Max(1, binY - 2);
        Int_t lastBinAbove = TMath::Min(h->GetYaxis()->GetNbins(), binY + 2);
        
        // Reset values
        Int_t binIndex = 0;
        for (Int_t i = 0; i < nNeighbours; i++)
          values[i] = 0;
        
        for (Int_t binX2 = firstBinLeft; binX2 <= lastBinRight; binX2++) {
          for (Int_t binY2 = firstBinBelow; binY2 <= lastBinAbove; binY2++) {
            if (binX2 == binX && binY2 == binY)
              continue; // skip bin that is currently under consideration
              
            values[binIndex] = h->GetBinContent(binX2, binY2);
            binIndex++;
          }
        }
        
        Double_t temp = getMedianOfNonZeros(values, nNeighbours);
        if (temp <= 0) {
          printf("Error: Could no eliminate values <= 0 for bin at (%f, %f)!\n",
                 h->GetXaxis()->GetBinCenter(binX), h->GetYaxis()->GetBinCenter(binY));
          temp = -1;
        }
        
        h->SetBinContent(binX, binY, temp);
      }
    }
  }
  
  delete values;
}
    
    
//__________________________________________________________________________________________
void addPointToHyperplane(TH2D* h, TLinearFitter* linExtrapolation, Int_t binX, Int_t binY)
{
  if (h->GetBinContent(binX, binY) <= binContentThreshold)
    return; // Reject bins without content (within some numerical precision) or with strange content
    
  Double_t coord[2] = {0, 0};
  coord[0] = h->GetXaxis()->GetBinCenter(binX);
  coord[1] = h->GetYaxis()->GetBinCenter(binY);
  Double_t binError = h->GetBinError(binX, binY);
  if (binError <= 0) {
    binError = 1000; // Should not happen because bins without content are rejected
    printf("ERROR: This should never happen: Trying to add bin in addPointToHyperplane with error not set....\n");
  }
  linExtrapolation->AddPoint(coord, h->GetBinContent(binX, binY, binError));
}

//__________________________________________________________________________________________
TH2D* refineHistoViaLinearExtrapolation(TH2D* h, Double_t refineFactorX, Double_t refineFactorY, Int_t mapType, 
                                        TFile* fSave, Bool_t skipBinsAtBoundaries = kFALSE)
{
  if (!h)
    return 0x0;
  
  Int_t nBinsX = h->GetXaxis()->GetNbins();
  Int_t nBinsY = h->GetYaxis()->GetNbins();

  Int_t firstYbin = 1;
  
  if (skipBinsAtBoundaries) {
    // Remove the two first and the last bin on y-axis
    nBinsY -= 3;
    firstYbin = 3; 
  }
    
  // Normalise map on demand
  
  // Use kNoNormalisation for final QA
  if (mapType == kSmallEtaNormalisation) {
    normaliseHisto(h, 0., 0.11, kTypeDeltaPrime);
  }
  else if (mapType == kLargeEtaNormalisation) {
    normaliseHisto(h, 0.81, 0.99, kTypeDeltaPrime);
  }
  
  // Interpolate to finer map
  TLinearFitter* linExtrapolation = new TLinearFitter(2, "hyp2", "");

  Int_t nBinsXrefined = nBinsX * refineFactorX;
  Int_t nBinsYrefined = nBinsY * refineFactorY; 
  
  TH2D* hRefined = new TH2D(Form("%s_%s_refined", h->GetName(), suffixMapType[mapType].Data()),  Form("%s (refined)",h->GetTitle()),
                            nBinsXrefined, h->GetXaxis()->GetBinLowEdge(1), h->GetXaxis()->GetBinUpEdge(nBinsX),
                            nBinsYrefined, h->GetYaxis()->GetBinLowEdge(firstYbin), h->GetYaxis()->GetBinUpEdge(nBinsY));
  
  for (Int_t binX = 1; binX <= nBinsXrefined; binX++)  {
    for (Int_t binY = 1; binY <= nBinsYrefined; binY++)  {
      
      linExtrapolation->ClearPoints();
      
      hRefined->SetBinContent(binX, binY, 1); // Default value is 1
      
      Double_t centerX = hRefined->GetXaxis()->GetBinCenter(binX);
      Double_t centerY = hRefined->GetYaxis()->GetBinCenter(binY);
      
      // For interpolation: Just take the corresponding bin from the old histo.
      // For extrapolation: take the last available bin from the old histo.
      // If the boundaries are to be skipped, also skip the corresponding bins
      Int_t oldBinX = h->GetXaxis()->FindBin(centerX);
      if (oldBinX < 1)  
        oldBinX = 1;
      if (oldBinX > nBinsX)
        oldBinX = nBinsX;
      
      Int_t oldBinY = h->GetYaxis()->FindBin(centerY);
      if (oldBinY < firstYbin)  
        oldBinY = firstYbin;
      if (oldBinY > nBinsY)
        oldBinY = nBinsY;
      
      // Neighbours left column
      if (oldBinX >= 2) {
        if (oldBinY >= 2) {
          addPointToHyperplane(h, linExtrapolation, oldBinX - 1, oldBinY - 1);
        }
        
        addPointToHyperplane(h, linExtrapolation, oldBinX - 1, oldBinY);
        
        if (oldBinY < nBinsY) {
          addPointToHyperplane(h, linExtrapolation, oldBinX - 1, oldBinY + 1);
        }
      }
      
      // Neighbours (and point itself) same column
      if (oldBinY >= 2) {
        addPointToHyperplane(h, linExtrapolation, oldBinX, oldBinY - 1);
      }
        
      addPointToHyperplane(h, linExtrapolation, oldBinX, oldBinY);
        
      if (oldBinY < nBinsY) {
        addPointToHyperplane(h, linExtrapolation, oldBinX, oldBinY + 1);
      }
      
      // Neighbours right column
      if (oldBinX < nBinsX) {
        if (oldBinY >= 2) {
          addPointToHyperplane(h, linExtrapolation, oldBinX + 1, oldBinY - 1);
        }
        
        addPointToHyperplane(h, linExtrapolation, oldBinX + 1, oldBinY);
        
        if (oldBinY < nBinsY) {
          addPointToHyperplane(h, linExtrapolation, oldBinX + 1, oldBinY + 1);
        }
      }
      
      
      // Fit 2D-hyperplane
      if (linExtrapolation->GetNpoints() <= 0)
        continue;
        
      if (linExtrapolation->Eval() != 0)// EvalRobust -> Takes much, much, [...], much more time (~hours instead of seconds)
        continue;
      
      // Fill the bin of the refined histogram with the extrapolated value
      Double_t extrapolatedValue = linExtrapolation->GetParameter(0) + linExtrapolation->GetParameter(1) * centerX
                                 + linExtrapolation->GetParameter(2) * centerY;
                                 
      hRefined->SetBinContent(binX, binY, extrapolatedValue);      
    }
  } 
  
  delete linExtrapolation;
  
  return hRefined;
}


//__________________________________________________________________________________________
TFitResult*  doubleGaussFit(TH1D* h, Double_t currentMeanMomentum, TSpline3* splPr, TSpline3* splPi, TString fitOption = "QNS") 
{
  TFitResultPtr result = h->Fit("gaus", fitOption.Data());
  
  Double_t contaminationPeakMean = splPi->Eval(currentMeanMomentum / AliPID::ParticleMass(AliPID::kPion)) 
                                 / splPr->Eval(currentMeanMomentum / AliPID::ParticleMass(AliPID::kProton));

  if (contaminationPeakMean < h->GetXaxis()->GetBinLowEdge(1) ||
      contaminationPeakMean > h->GetXaxis()->GetBinUpEdge(h->GetNbinsX())) {
    return ((Int_t)result == 0) ? result.Get() : 0x0;
  }
  
  // Estimate parameters for doubleGauss fit
  Double_t estimatedMean = 0;
  Double_t estimatedSigma = 0;
  Double_t estimatedYield = 0;
  
  if ((Int_t) result == 0) {
    estimatedMean = result->GetParams()[1];
    estimatedSigma = result->GetParams()[2];
    estimatedYield = result->GetParams()[0];
  }
  else {
    estimatedMean = h->GetMean();
    estimatedSigma = h->GetRMS();
    estimatedYield = (estimatedSigma > 0) ? (h->Integral("width") / estimatedSigma) : h->GetEntries();
  }
  
  TF1* doubleGaus = new TF1("doubleGaus", "[0]*TMath::Gaus(x,[1],[2],0)+[3]*TMath::Gaus(x,[4],[2],0)", 0.6, 1.6);

  Double_t newPars[5] = { estimatedYield, estimatedMean, estimatedSigma, estimatedYield / 10., contaminationPeakMean };
  doubleGaus->SetParameters(newPars);
  doubleGaus->SetParLimits(0, 0., 100. * estimatedYield);
  doubleGaus->SetParLimits(1, 0.6, 1.6);
  doubleGaus->SetParLimits(2, 0, 100. * estimatedSigma);
  doubleGaus->SetParLimits(3, 0, 0.8 * estimatedYield);
  doubleGaus->SetParLimits(4, contaminationPeakMean - 0.1, contaminationPeakMean + 0.1);//TODO doubleGaus->SetParLimits(4, 0.6, 1.6);
  TFitResultPtr result2 = h->Fit(doubleGaus, fitOption.Data());

  // If fit failed, return results of standard fit instead
  if ((Int_t)result2 == 0) {
    return result2.Get();
  }
  
  return ((Int_t)result == 0) ? result.Get() : 0x0;
}


//__________________________________________________________________________________________
// NOTE: Use smoothing only for creation of sigma map. For normal eta map this pulls down the edges too much <-> trade-off between
// (normally very small) jumps in the map and good description at the edges.
// For the sigma map, there are not that sharp edges, but the fluctuations are by far stronger. Here it makes sense to use the smoothing.
TH2* checkShapeEtaTreePions(TTree* tree = 0x0, Double_t lowResolutionFactorX = 1/*2 or 2.1*/, Double_t lowResolutionFactorY = 1/*2 or 2.1*/, 
                       Bool_t doSmoothing = kFALSE, TString path = ".", TString suffixForFileName = "", Bool_t useDoubleGaussFit = kFALSE, 
                       TString pathNameThetaMap = "finalCuts/uncorrected/0.6GeVcut/pp/7TeV/LHC10d.pass2/outputCheckShapeEtaTree_2012_07_18__14_04.root", 
                       TString mapSuffix = "NoNormalisation",
                       TString pathNameSplinesFile = "DefaultSplines.root", TString prSplinesName = "TSPLINE3_DATA_PION_LHC10D_PASS2_PP_MEAN", 
                       Int_t returnMapType = kNoNormalisation, TString treeName = "fTreePions") 
{ 
  TString fileName = Form("bhess_PIDetaTreePions%s.root", suffixForFileName.Data());
  
  if (lowResolutionFactorX <= 0 || lowResolutionFactorY <= 0)  {
	  printf("Factor for lower resolution <= 0 is not allowed!\n");
	  return 0x0;
  }
  		       
	TFile* f = 0x0;
	
	Bool_t saveResults = kFALSE;
	
	if (!tree)  {
	  f = TFile::Open(Form("%s/%s", path.Data(), fileName.Data()));
    if (!f)  {
      std::cout << "Failed to open file \"" << Form("%s/%s", path.Data(), fileName.Data()) << "\"!" << std::endl;


      return 0x0;
    }
      
    // Extract the data Tree
    tree = dynamic_cast<TTree*>(f->Get(treeName.Data()));
    if (!tree) {
      std::cout << "Failed to load data tree!" << std::endl;
      return 0x0;
    }
    
    saveResults = kTRUE;
  }
  
  TSpline3* splPr = 0x0;
  TSpline3* splPi = 0x0;
  
  // Extract the correction maps
  TFile* fPrMap = TFile::Open(pathNameThetaMap.Data());
  if (!fPrMap)  {
    std::cout << "Failed to open proton map file \"" << pathNameThetaMap.Data() << "\"!" << std::endl;
    return 0x0;
  }

  TH2D* hPrMap = 0x0;
  
  if (fPrMap) {
    hPrMap = dynamic_cast<TH2D*>(fPrMap->Get(Form("hRefined%s", mapSuffix.Data())));
    if (!hPrMap) {
      std::cout << "Failed to load proton theta map!" << std::endl;
      return 0x0;
    }
  }
  
  
  //TString pathNameMomentumMap = "pionTree_11b2/outputCheckShapeEtaTreePions_2012_10_16__11_38.root";
  //TString pathNameMomentumMap = "pionTree_10d1/outputCheckShapeEtaTreePions_2012_10_17__07_38.root";
  TString pathNameMomentumMap = "finalCuts/uncorrected/0.6GeVcut/pp/7TeV/LHC10d.pass2/correctedV0splines_newV0tree/outputCheckShapeEtaTreePions_2012_10_23__16_02_correctedWith_10_38.root";
  TFile* fPiMap = TFile::Open(pathNameMomentumMap.Data());
  if (!fPiMap)  {
    std::cout << "Failed to open pion momentum map file \"" << pathNameMomentumMap.Data() << "\"!" << std::endl;
    return 0x0;
  }

  TH2D* hPiMap = 0x0;
  
  if (fPiMap) {
    hPiMap = dynamic_cast<TH2D*>(fPiMap->Get("hRefinedSmallEtaNormalisation")); //TODO NOW NOW NOWForm("hRefined%s", mapSuffix.Data())));
    if (!hPiMap) {
      std::cout << "Failed to load pion momentum map!" << std::endl;
      return 0x0;
    }
  }
  
  // Output file
  
  TFile* fSave = 0x0;
  TString saveFileName = "";
  if (saveResults)  {
    TDatime daTime;
    
    TString saveSuffix = "";
    if (suffixForFileName.Length() > 0)
      saveSuffix = Form("_%s", suffixForFileName.Data());
    
    saveFileName = Form("outputCheckShapeEtaTreePions_%04d_%02d_%02d__%02d_%02d%s.root", daTime.GetYear(), daTime.GetMonth(),
                        daTime.GetDay(), daTime.GetHour(), daTime.GetMinute(), saveSuffix.Data());
    
    fSave = TFile::Open(Form("%s/%s", path.Data(), saveFileName.Data()), "recreate");
    if (!fSave) {
      std::cout << "Failed to open save file \"" << Form("%s/%s", path.Data(), saveFileName.Data()) << "\"!" << std::endl;
      return 0x0;
    }
  }
  
  printf("\nProcessing file %s\n", f->GetName());
  
  
  // Only activate the branches of interest to save processing time
  tree->SetBranchStatus("*", 0); // Disable all branches
  tree->SetBranchStatus("pTPC", 1);
  //tree->SetBranchStatus("pT", 1);
  tree->SetBranchStatus("dEdx", 1);
  tree->SetBranchStatus("dEdxExpected", 1);
  tree->SetBranchStatus("tanTheta", 1);
  //if (isPbPb)
  //  tree->SetBranchStatus("fMultiplicity", 1);
  tree->SetBranchStatus("tpcSignalN", 1);
  
  TString multiplicitySelectionString = "";
// if (isPbPb)// Usually 20 bins from 0 to 4000 => bin width ~ 200
//    multiplicitySelectionString = "&& fMultiplicity > 3000 && fMultiplicity <= 3200";
  
  
  Int_t binsX = 30 / lowResolutionFactorX;
  Int_t binsY = 40 / lowResolutionFactorY;
  const Double_t pBoundLow = 0.15;// 1. / 0.6;
  const Double_t pBoundUp = 0.6;// 1. / 0.15;
  const Double_t lowerTanTheta = -1.0;
  const Double_t upperTanTheta = 1.0;
  
  progressbar(0.);
  
  TH2D* hMap = new TH2D("hMap", "#Delta' map for pTPC vs. tan(#theta) via Gauss fit;tan(#theta);p_{TPC} (GeV/c);#Delta'",
                        binsX, lowerTanTheta, upperTanTheta, binsY, pBoundLow, pBoundUp);
  
  const Int_t nDim = 3;
  
  Int_t thnBins[nDim] = {  binsX, binsY, 200  };
  Double_t xmin[nDim] = {  lowerTanTheta, pBoundLow, 0.6  };
  Double_t xmax[nDim] = {  upperTanTheta, pBoundUp, 1.6  };
  THnSparseD* hDummy = new THnSparseD("hDummy", "", nDim, thnBins, xmin, xmax);
  TH3D* hPreMap = hDummy->Projection(0, 1, 2);
  hPreMap->SetName("hPreMap");
  hPreMap->SetTitle("#Delta' map for p_{TPC_Inner} vs. tan(#theta)");   
  hPreMap->GetXaxis()->SetTitle("tan(#theta)");
  hPreMap->GetYaxis()->SetTitle("p_{TPC_inner} (GeV/c)");
  hPreMap->GetZaxis()->SetTitle("#Delta'");
  
  delete hDummy;
  
  Long64_t nTreeEntries = tree->GetEntriesFast();
  
  Double_t dEdx = 0.; // Measured dE/dx
  Double_t dEdxExpected = 0.; // Expected dE/dx according to parametrisation
  Double_t tanTheta = 0.; // Tangens of (local) theta at TPC inner wall
  Double_t pTPC = 0.; // Momentum at TPC inner wall
  Double_t pT = 0;
  UShort_t tpcSignalN = 0; // Number of clusters used for dEdx
  //Int_t fMultiplicity = 0;
  
  
  tree->SetBranchAddress("dEdx", &dEdx);
  tree->SetBranchAddress("dEdxExpected", &dEdxExpected);
  tree->SetBranchAddress("tanTheta", &tanTheta);
  tree->SetBranchAddress("tpcSignalN", &tpcSignalN);
  tree->SetBranchAddress("pTPC", &pTPC);
  //tree->SetBranchAddress("pT", &pT);
  //if (isPbPb)
  //  tree->SetBranchAddress("fMultiplicity", &fMultiplicity);
  
  Double_t correctionFactor = 1.0;
  Double_t dEdxOrig = 0;
  
  for (Long64_t i = 0; i < nTreeEntries; i++) {
    tree->GetEntry(i);
    
    if (dEdx <= 0 || dEdxExpected <= 0 || tpcSignalN <= 60) 
      continue;
    
    dEdxOrig = dEdx;
    
    // Correct for pure momentum dependence (azimuthal dependence comes into play)
    correctionFactor = hPiMap->GetBinContent(getBinX(hPiMap, tanTheta), getBinY(hPiMap, pTPC));
    correctionFactor -= 1.;
    correctionFactor *= 0.5*(TMath::Erf((0.5 - pTPC) / 0.05) + 1.); // Only correct up to 0.5 GeV/c and switch off within about 2*0.05 GeV/c
    correctionFactor += 1.;
    //TODO NOW dEdx /= correctionFactor;
    
  
    // Correct eta dependence
    correctionFactor = hPrMap->GetBinContent(getBinX(hPrMap, tanTheta), getBinY(hPrMap, 1./dEdxOrig));
    dEdx /= correctionFactor; 
  
    hPreMap->Fill(tanTheta, pTPC, dEdx / dEdxExpected);
    
    if (i % 1000 == 0)
    progressbar(100. * (((Double_t)i) / nTreeEntries));
  }
  
  progressbar(100.);

  

  printf("\n\nStarted map creation....\n");
  
  
  const Int_t numTotalBins = hPreMap->GetXaxis()->GetNbins() * hPreMap->GetYaxis()->GetNbins();
 
  for (Int_t binY = 1; binY <= hPreMap->GetYaxis()->GetNbins(); binY++) {
    for (Int_t binX = 1; binX <= hPreMap->GetXaxis()->GetNbins(); binX++) {  
      TH1D* hTempProjectionZ = 0x0;
      
      hTempProjectionZ = hPreMap->ProjectionZ("hTempProjectionZ", binX, binX, binY, binY);
      
      if (hTempProjectionZ->GetEntries() < 10) {
        printf("\nWarning: Too few entries for (%f, %f - %f): skipped\n",
               hPreMap->GetXaxis()->GetBinCenter(binX), hPreMap->GetYaxis()->GetBinLowEdge(binY),
               hPreMap->GetYaxis()->GetBinUpEdge(binY)); 
        printedSomething = kTRUE;

        delete hTempProjectionZ;
        continue;
      }  
      
      Double_t meanWithoutFit = hTempProjectionZ->GetMean();

      // Do not overwrite with data from lower statistics (larger momentum) -> Most of the cases should be caught by the merging!
      TFitResult* fitRes = 0x0;
      TFitResultPtr fitResPtr = hTempProjectionZ->Fit("gaus", "QSN", "");//TODO removed option L
      fitRes = ((Int_t)fitResPtr == 0) ? fitResPtr.Get() : 0x0;
      
      Double_t mean = 0;
      Double_t meanError = 0;
                
      // If the fit failed, use the mean of the histogram as an approximation instead
      if (!fitRes) {
        mean = meanWithoutFit;
        meanError = 1000;
        
        printf("\nWarning: Fit failed for (%f, %f), entries: %.0f -> Using mean instead (%f +- %f)\n",
               hPreMap->GetXaxis()->GetBinCenter(binX), hPreMap->GetYaxis()->GetBinCenter(binY), 
               hTempProjectionZ->GetEntries(), mean, meanError); 
        printedSomething = kTRUE;
      }
      else {
        mean = fitRes->GetParams()[1];
        meanError = fitRes->GetErrors()[1];
      }

      hMap->SetBinContent(binX, binY, mean);
      hMap->SetBinError(binX, binY, meanError);
      
      delete hTempProjectionZ;

      progressbar(100. * (((Double_t)(((binY - 1.) * hPreMap->GetXaxis()->GetNbins()) + binX)) / numTotalBins)); 
    }
  }
  
  progressbar(100);
  
  
  
  TH2D* hPureResults = (TH2D*)hMap->Clone("hPureResults");  
  TH2D* hRes3DprimeDiffSmooth = 0x0;
  
  if (doSmoothing) {
    // --------------------------------------------------
    // Determine difference between smoothed and pure map (gauss fit)    
    hRes3DprimeDiffSmooth = (TH2D*)hMap->Clone("hRes3DprimeDiffSmooth");
    hRes3DprimeDiffSmooth->SetTitle("tan(#theta) and pTPC dependence of #Delta': Smooth(Gauss) - Gauss");
    
    // Smooth the histos
    
    // If the smoothing is to be applied, the bins with fit errors (content <= 0) must be eliminated in order not to bias the smoothing.
    // In case of no smoothing, the refinement will take care of such bins....
    eliminateNonPositivePointsInHisto(hMap);
    
    
    hMap->Smooth();
        
    
    hRes3DprimeDiffSmooth->Add(hMap, -1);
    //hRes3DprimeDiffSmooth->GetZaxis()->SetRangeUser(-0.05, 0.05);
    SetHistAxis(hRes3DprimeDiffSmooth, kTypeDeltaPrime);
  }
  
  //hMap->GetZaxis()->SetRangeUser(0.95, 1.15);
  SetHistAxis(hMap, kTypeDeltaPrime);
    
  
  if (saveResults)  {
    fSave->cd();
    hPreMap->Write();
  }
  
  delete hPreMap;
  
  
  // --------------------------------------------------
  // Refine the map
  printf("\n\nMap created. Started to refine....\n\n");
  
  Double_t factorX = 6;
  Double_t factorY = 6;
  
  if (lowResolutionFactorX != 1)
    factorX *= lowResolutionFactorX;
  if (lowResolutionFactorY != 1)
    factorY *= lowResolutionFactorY;
  
  
  
  Bool_t skipBinsAtBoundaries = kFALSE; // TODO NOW Diese Bins vielleicht doch nicht rausnehmen. Der Anstieg in Sigma bei extrem kleinen Impulsen ist insofern richtig, da hier die Splines abweichen und somit eine große Streuung auftritt. Und bei großen Impulsen sollten im Moment die V0s Abhilfe von fehlerhaftenAbweichungen schaffen. Beim Mean gilt dasselbe.
  TH2D* hRefinedNoNorm = refineHistoViaLinearExtrapolation(hMap, factorX, factorY, kNoNormalisation, fSave, skipBinsAtBoundaries);
  hRefinedNoNorm->SetName(Form("hRefined%s", suffixMapType[kNoNormalisation].Data()));
  SetHistAxis(hRefinedNoNorm, kTypeDeltaPrime);
  
  TH2D* hRefinedSmallEtaNorm = refineHistoViaLinearExtrapolation(hMap, factorX, factorY, kSmallEtaNormalisation, fSave, skipBinsAtBoundaries);
  hRefinedSmallEtaNorm->SetName(Form("hRefined%s", suffixMapType[kSmallEtaNormalisation].Data()));
  SetHistAxis(hRefinedSmallEtaNorm, kTypeDeltaPrime);
  
  TH2D* hRefinedLargeEtaNorm = refineHistoViaLinearExtrapolation(hMap, factorX, factorY, kLargeEtaNormalisation, fSave, skipBinsAtBoundaries);
  hRefinedLargeEtaNorm->SetName(Form("hRefined%s", suffixMapType[kLargeEtaNormalisation].Data()));
  SetHistAxis(hRefinedLargeEtaNorm, kTypeDeltaPrime);
  
  printf("\nDone!\n\n");
  
  if (lowResolutionFactorX != 1 || lowResolutionFactorY != 1) {
    printf("\n***WARNING***: Low resolution used for map creation! Resolution scaled down by factor (%f, %f)\n\n", 
           lowResolutionFactorX, lowResolutionFactorY);
  }
  
  
  
  TH2D* hPureResultsSmallEtaNorm = (TH2D*)hPureResults->Clone("hPureResultsSmallEtaNorm");  
  normaliseHisto(hPureResultsSmallEtaNorm, 0., 0.11, kTypeDeltaPrime);
  
  if (saveResults)  {    
    fSave->cd();
    hPureResults->Write();
    hPureResultsSmallEtaNorm->Write();
    hMap->Write();
    if (doSmoothing)
      hRes3DprimeDiffSmooth->Write();
    
    hRefinedNoNorm->Write();
    hRefinedSmallEtaNorm->Write();
    hRefinedLargeEtaNorm->Write();
    
    TNamed* settings = new TNamed(
      Form("Settings for map: lowResolutionFactor (%f, %f), doSmoothing %d", lowResolutionFactorX, lowResolutionFactorY, doSmoothing), "");
    settings->Write();
    
    f->Close();
    fSave->Close();
        
    gSystem->Exec(Form("echo \"%s\" >> %s/settingsForMapCreation.txt",
                       TString(settings->GetName()).ReplaceAll("Settings for map",
                                                               Form("Settings for map %s", saveFileName.Data())).Data(), path.Data()));
    return 0x0;
  }
  
  if (returnMapType == kSmallEtaNormalisation)
    return hRefinedSmallEtaNorm;
  else if (returnMapType == kLargeEtaNormalisation)
    return hRefinedLargeEtaNorm;
  else if (returnMapType == kNoNormalisation)
    return hRefinedNoNorm;
  
  printf("Map type %d is not supported. Returning 0x0...\n", returnMapType);
  return 0x0;
}
 checkShapeEtaTreePions.C:1
 checkShapeEtaTreePions.C:2
 checkShapeEtaTreePions.C:3
 checkShapeEtaTreePions.C:4
 checkShapeEtaTreePions.C:5
 checkShapeEtaTreePions.C:6
 checkShapeEtaTreePions.C:7
 checkShapeEtaTreePions.C:8
 checkShapeEtaTreePions.C:9
 checkShapeEtaTreePions.C:10
 checkShapeEtaTreePions.C:11
 checkShapeEtaTreePions.C:12
 checkShapeEtaTreePions.C:13
 checkShapeEtaTreePions.C:14
 checkShapeEtaTreePions.C:15
 checkShapeEtaTreePions.C:16
 checkShapeEtaTreePions.C:17
 checkShapeEtaTreePions.C:18
 checkShapeEtaTreePions.C:19
 checkShapeEtaTreePions.C:20
 checkShapeEtaTreePions.C:21
 checkShapeEtaTreePions.C:22
 checkShapeEtaTreePions.C:23
 checkShapeEtaTreePions.C:24
 checkShapeEtaTreePions.C:25
 checkShapeEtaTreePions.C:26
 checkShapeEtaTreePions.C:27
 checkShapeEtaTreePions.C:28
 checkShapeEtaTreePions.C:29
 checkShapeEtaTreePions.C:30
 checkShapeEtaTreePions.C:31
 checkShapeEtaTreePions.C:32
 checkShapeEtaTreePions.C:33
 checkShapeEtaTreePions.C:34
 checkShapeEtaTreePions.C:35
 checkShapeEtaTreePions.C:36
 checkShapeEtaTreePions.C:37
 checkShapeEtaTreePions.C:38
 checkShapeEtaTreePions.C:39
 checkShapeEtaTreePions.C:40
 checkShapeEtaTreePions.C:41
 checkShapeEtaTreePions.C:42
 checkShapeEtaTreePions.C:43
 checkShapeEtaTreePions.C:44
 checkShapeEtaTreePions.C:45
 checkShapeEtaTreePions.C:46
 checkShapeEtaTreePions.C:47
 checkShapeEtaTreePions.C:48
 checkShapeEtaTreePions.C:49
 checkShapeEtaTreePions.C:50
 checkShapeEtaTreePions.C:51
 checkShapeEtaTreePions.C:52
 checkShapeEtaTreePions.C:53
 checkShapeEtaTreePions.C:54
 checkShapeEtaTreePions.C:55
 checkShapeEtaTreePions.C:56
 checkShapeEtaTreePions.C:57
 checkShapeEtaTreePions.C:58
 checkShapeEtaTreePions.C:59
 checkShapeEtaTreePions.C:60
 checkShapeEtaTreePions.C:61
 checkShapeEtaTreePions.C:62
 checkShapeEtaTreePions.C:63
 checkShapeEtaTreePions.C:64
 checkShapeEtaTreePions.C:65
 checkShapeEtaTreePions.C:66
 checkShapeEtaTreePions.C:67
 checkShapeEtaTreePions.C:68
 checkShapeEtaTreePions.C:69
 checkShapeEtaTreePions.C:70
 checkShapeEtaTreePions.C:71
 checkShapeEtaTreePions.C:72
 checkShapeEtaTreePions.C:73
 checkShapeEtaTreePions.C:74
 checkShapeEtaTreePions.C:75
 checkShapeEtaTreePions.C:76
 checkShapeEtaTreePions.C:77
 checkShapeEtaTreePions.C:78
 checkShapeEtaTreePions.C:79
 checkShapeEtaTreePions.C:80
 checkShapeEtaTreePions.C:81
 checkShapeEtaTreePions.C:82
 checkShapeEtaTreePions.C:83
 checkShapeEtaTreePions.C:84
 checkShapeEtaTreePions.C:85
 checkShapeEtaTreePions.C:86
 checkShapeEtaTreePions.C:87
 checkShapeEtaTreePions.C:88
 checkShapeEtaTreePions.C:89
 checkShapeEtaTreePions.C:90
 checkShapeEtaTreePions.C:91
 checkShapeEtaTreePions.C:92
 checkShapeEtaTreePions.C:93
 checkShapeEtaTreePions.C:94
 checkShapeEtaTreePions.C:95
 checkShapeEtaTreePions.C:96
 checkShapeEtaTreePions.C:97
 checkShapeEtaTreePions.C:98
 checkShapeEtaTreePions.C:99
 checkShapeEtaTreePions.C:100
 checkShapeEtaTreePions.C:101
 checkShapeEtaTreePions.C:102
 checkShapeEtaTreePions.C:103
 checkShapeEtaTreePions.C:104
 checkShapeEtaTreePions.C:105
 checkShapeEtaTreePions.C:106
 checkShapeEtaTreePions.C:107
 checkShapeEtaTreePions.C:108
 checkShapeEtaTreePions.C:109
 checkShapeEtaTreePions.C:110
 checkShapeEtaTreePions.C:111
 checkShapeEtaTreePions.C:112
 checkShapeEtaTreePions.C:113
 checkShapeEtaTreePions.C:114
 checkShapeEtaTreePions.C:115
 checkShapeEtaTreePions.C:116
 checkShapeEtaTreePions.C:117
 checkShapeEtaTreePions.C:118
 checkShapeEtaTreePions.C:119
 checkShapeEtaTreePions.C:120
 checkShapeEtaTreePions.C:121
 checkShapeEtaTreePions.C:122
 checkShapeEtaTreePions.C:123
 checkShapeEtaTreePions.C:124
 checkShapeEtaTreePions.C:125
 checkShapeEtaTreePions.C:126
 checkShapeEtaTreePions.C:127
 checkShapeEtaTreePions.C:128
 checkShapeEtaTreePions.C:129
 checkShapeEtaTreePions.C:130
 checkShapeEtaTreePions.C:131
 checkShapeEtaTreePions.C:132
 checkShapeEtaTreePions.C:133
 checkShapeEtaTreePions.C:134
 checkShapeEtaTreePions.C:135
 checkShapeEtaTreePions.C:136
 checkShapeEtaTreePions.C:137
 checkShapeEtaTreePions.C:138
 checkShapeEtaTreePions.C:139
 checkShapeEtaTreePions.C:140
 checkShapeEtaTreePions.C:141
 checkShapeEtaTreePions.C:142
 checkShapeEtaTreePions.C:143
 checkShapeEtaTreePions.C:144
 checkShapeEtaTreePions.C:145
 checkShapeEtaTreePions.C:146
 checkShapeEtaTreePions.C:147
 checkShapeEtaTreePions.C:148
 checkShapeEtaTreePions.C:149
 checkShapeEtaTreePions.C:150
 checkShapeEtaTreePions.C:151
 checkShapeEtaTreePions.C:152
 checkShapeEtaTreePions.C:153
 checkShapeEtaTreePions.C:154
 checkShapeEtaTreePions.C:155
 checkShapeEtaTreePions.C:156
 checkShapeEtaTreePions.C:157
 checkShapeEtaTreePions.C:158
 checkShapeEtaTreePions.C:159
 checkShapeEtaTreePions.C:160
 checkShapeEtaTreePions.C:161
 checkShapeEtaTreePions.C:162
 checkShapeEtaTreePions.C:163
 checkShapeEtaTreePions.C:164
 checkShapeEtaTreePions.C:165
 checkShapeEtaTreePions.C:166
 checkShapeEtaTreePions.C:167
 checkShapeEtaTreePions.C:168
 checkShapeEtaTreePions.C:169
 checkShapeEtaTreePions.C:170
 checkShapeEtaTreePions.C:171
 checkShapeEtaTreePions.C:172
 checkShapeEtaTreePions.C:173
 checkShapeEtaTreePions.C:174
 checkShapeEtaTreePions.C:175
 checkShapeEtaTreePions.C:176
 checkShapeEtaTreePions.C:177
 checkShapeEtaTreePions.C:178
 checkShapeEtaTreePions.C:179
 checkShapeEtaTreePions.C:180
 checkShapeEtaTreePions.C:181
 checkShapeEtaTreePions.C:182
 checkShapeEtaTreePions.C:183
 checkShapeEtaTreePions.C:184
 checkShapeEtaTreePions.C:185
 checkShapeEtaTreePions.C:186
 checkShapeEtaTreePions.C:187
 checkShapeEtaTreePions.C:188
 checkShapeEtaTreePions.C:189
 checkShapeEtaTreePions.C:190
 checkShapeEtaTreePions.C:191
 checkShapeEtaTreePions.C:192
 checkShapeEtaTreePions.C:193
 checkShapeEtaTreePions.C:194
 checkShapeEtaTreePions.C:195
 checkShapeEtaTreePions.C:196
 checkShapeEtaTreePions.C:197
 checkShapeEtaTreePions.C:198
 checkShapeEtaTreePions.C:199
 checkShapeEtaTreePions.C:200
 checkShapeEtaTreePions.C:201
 checkShapeEtaTreePions.C:202
 checkShapeEtaTreePions.C:203
 checkShapeEtaTreePions.C:204
 checkShapeEtaTreePions.C:205
 checkShapeEtaTreePions.C:206
 checkShapeEtaTreePions.C:207
 checkShapeEtaTreePions.C:208
 checkShapeEtaTreePions.C:209
 checkShapeEtaTreePions.C:210
 checkShapeEtaTreePions.C:211
 checkShapeEtaTreePions.C:212
 checkShapeEtaTreePions.C:213
 checkShapeEtaTreePions.C:214
 checkShapeEtaTreePions.C:215
 checkShapeEtaTreePions.C:216
 checkShapeEtaTreePions.C:217
 checkShapeEtaTreePions.C:218
 checkShapeEtaTreePions.C:219
 checkShapeEtaTreePions.C:220
 checkShapeEtaTreePions.C:221
 checkShapeEtaTreePions.C:222
 checkShapeEtaTreePions.C:223
 checkShapeEtaTreePions.C:224
 checkShapeEtaTreePions.C:225
 checkShapeEtaTreePions.C:226
 checkShapeEtaTreePions.C:227
 checkShapeEtaTreePions.C:228
 checkShapeEtaTreePions.C:229
 checkShapeEtaTreePions.C:230
 checkShapeEtaTreePions.C:231
 checkShapeEtaTreePions.C:232
 checkShapeEtaTreePions.C:233
 checkShapeEtaTreePions.C:234
 checkShapeEtaTreePions.C:235
 checkShapeEtaTreePions.C:236
 checkShapeEtaTreePions.C:237
 checkShapeEtaTreePions.C:238
 checkShapeEtaTreePions.C:239
 checkShapeEtaTreePions.C:240
 checkShapeEtaTreePions.C:241
 checkShapeEtaTreePions.C:242
 checkShapeEtaTreePions.C:243
 checkShapeEtaTreePions.C:244
 checkShapeEtaTreePions.C:245
 checkShapeEtaTreePions.C:246
 checkShapeEtaTreePions.C:247
 checkShapeEtaTreePions.C:248
 checkShapeEtaTreePions.C:249
 checkShapeEtaTreePions.C:250
 checkShapeEtaTreePions.C:251
 checkShapeEtaTreePions.C:252
 checkShapeEtaTreePions.C:253
 checkShapeEtaTreePions.C:254
 checkShapeEtaTreePions.C:255
 checkShapeEtaTreePions.C:256
 checkShapeEtaTreePions.C:257
 checkShapeEtaTreePions.C:258
 checkShapeEtaTreePions.C:259
 checkShapeEtaTreePions.C:260
 checkShapeEtaTreePions.C:261
 checkShapeEtaTreePions.C:262
 checkShapeEtaTreePions.C:263
 checkShapeEtaTreePions.C:264
 checkShapeEtaTreePions.C:265
 checkShapeEtaTreePions.C:266
 checkShapeEtaTreePions.C:267
 checkShapeEtaTreePions.C:268
 checkShapeEtaTreePions.C:269
 checkShapeEtaTreePions.C:270
 checkShapeEtaTreePions.C:271
 checkShapeEtaTreePions.C:272
 checkShapeEtaTreePions.C:273
 checkShapeEtaTreePions.C:274
 checkShapeEtaTreePions.C:275
 checkShapeEtaTreePions.C:276
 checkShapeEtaTreePions.C:277
 checkShapeEtaTreePions.C:278
 checkShapeEtaTreePions.C:279
 checkShapeEtaTreePions.C:280
 checkShapeEtaTreePions.C:281
 checkShapeEtaTreePions.C:282
 checkShapeEtaTreePions.C:283
 checkShapeEtaTreePions.C:284
 checkShapeEtaTreePions.C:285
 checkShapeEtaTreePions.C:286
 checkShapeEtaTreePions.C:287
 checkShapeEtaTreePions.C:288
 checkShapeEtaTreePions.C:289
 checkShapeEtaTreePions.C:290
 checkShapeEtaTreePions.C:291
 checkShapeEtaTreePions.C:292
 checkShapeEtaTreePions.C:293
 checkShapeEtaTreePions.C:294
 checkShapeEtaTreePions.C:295
 checkShapeEtaTreePions.C:296
 checkShapeEtaTreePions.C:297
 checkShapeEtaTreePions.C:298
 checkShapeEtaTreePions.C:299
 checkShapeEtaTreePions.C:300
 checkShapeEtaTreePions.C:301
 checkShapeEtaTreePions.C:302
 checkShapeEtaTreePions.C:303
 checkShapeEtaTreePions.C:304
 checkShapeEtaTreePions.C:305
 checkShapeEtaTreePions.C:306
 checkShapeEtaTreePions.C:307
 checkShapeEtaTreePions.C:308
 checkShapeEtaTreePions.C:309
 checkShapeEtaTreePions.C:310
 checkShapeEtaTreePions.C:311
 checkShapeEtaTreePions.C:312
 checkShapeEtaTreePions.C:313
 checkShapeEtaTreePions.C:314
 checkShapeEtaTreePions.C:315
 checkShapeEtaTreePions.C:316
 checkShapeEtaTreePions.C:317
 checkShapeEtaTreePions.C:318
 checkShapeEtaTreePions.C:319
 checkShapeEtaTreePions.C:320
 checkShapeEtaTreePions.C:321
 checkShapeEtaTreePions.C:322
 checkShapeEtaTreePions.C:323
 checkShapeEtaTreePions.C:324
 checkShapeEtaTreePions.C:325
 checkShapeEtaTreePions.C:326
 checkShapeEtaTreePions.C:327
 checkShapeEtaTreePions.C:328
 checkShapeEtaTreePions.C:329
 checkShapeEtaTreePions.C:330
 checkShapeEtaTreePions.C:331
 checkShapeEtaTreePions.C:332
 checkShapeEtaTreePions.C:333
 checkShapeEtaTreePions.C:334
 checkShapeEtaTreePions.C:335
 checkShapeEtaTreePions.C:336
 checkShapeEtaTreePions.C:337
 checkShapeEtaTreePions.C:338
 checkShapeEtaTreePions.C:339
 checkShapeEtaTreePions.C:340
 checkShapeEtaTreePions.C:341
 checkShapeEtaTreePions.C:342
 checkShapeEtaTreePions.C:343
 checkShapeEtaTreePions.C:344
 checkShapeEtaTreePions.C:345
 checkShapeEtaTreePions.C:346
 checkShapeEtaTreePions.C:347
 checkShapeEtaTreePions.C:348
 checkShapeEtaTreePions.C:349
 checkShapeEtaTreePions.C:350
 checkShapeEtaTreePions.C:351
 checkShapeEtaTreePions.C:352
 checkShapeEtaTreePions.C:353
 checkShapeEtaTreePions.C:354
 checkShapeEtaTreePions.C:355
 checkShapeEtaTreePions.C:356
 checkShapeEtaTreePions.C:357
 checkShapeEtaTreePions.C:358
 checkShapeEtaTreePions.C:359
 checkShapeEtaTreePions.C:360
 checkShapeEtaTreePions.C:361
 checkShapeEtaTreePions.C:362
 checkShapeEtaTreePions.C:363
 checkShapeEtaTreePions.C:364
 checkShapeEtaTreePions.C:365
 checkShapeEtaTreePions.C:366
 checkShapeEtaTreePions.C:367
 checkShapeEtaTreePions.C:368
 checkShapeEtaTreePions.C:369
 checkShapeEtaTreePions.C:370
 checkShapeEtaTreePions.C:371
 checkShapeEtaTreePions.C:372
 checkShapeEtaTreePions.C:373
 checkShapeEtaTreePions.C:374
 checkShapeEtaTreePions.C:375
 checkShapeEtaTreePions.C:376
 checkShapeEtaTreePions.C:377
 checkShapeEtaTreePions.C:378
 checkShapeEtaTreePions.C:379
 checkShapeEtaTreePions.C:380
 checkShapeEtaTreePions.C:381
 checkShapeEtaTreePions.C:382
 checkShapeEtaTreePions.C:383
 checkShapeEtaTreePions.C:384
 checkShapeEtaTreePions.C:385
 checkShapeEtaTreePions.C:386
 checkShapeEtaTreePions.C:387
 checkShapeEtaTreePions.C:388
 checkShapeEtaTreePions.C:389
 checkShapeEtaTreePions.C:390
 checkShapeEtaTreePions.C:391
 checkShapeEtaTreePions.C:392
 checkShapeEtaTreePions.C:393
 checkShapeEtaTreePions.C:394
 checkShapeEtaTreePions.C:395
 checkShapeEtaTreePions.C:396
 checkShapeEtaTreePions.C:397
 checkShapeEtaTreePions.C:398
 checkShapeEtaTreePions.C:399
 checkShapeEtaTreePions.C:400
 checkShapeEtaTreePions.C:401
 checkShapeEtaTreePions.C:402
 checkShapeEtaTreePions.C:403
 checkShapeEtaTreePions.C:404
 checkShapeEtaTreePions.C:405
 checkShapeEtaTreePions.C:406
 checkShapeEtaTreePions.C:407
 checkShapeEtaTreePions.C:408
 checkShapeEtaTreePions.C:409
 checkShapeEtaTreePions.C:410
 checkShapeEtaTreePions.C:411
 checkShapeEtaTreePions.C:412
 checkShapeEtaTreePions.C:413
 checkShapeEtaTreePions.C:414
 checkShapeEtaTreePions.C:415
 checkShapeEtaTreePions.C:416
 checkShapeEtaTreePions.C:417
 checkShapeEtaTreePions.C:418
 checkShapeEtaTreePions.C:419
 checkShapeEtaTreePions.C:420
 checkShapeEtaTreePions.C:421
 checkShapeEtaTreePions.C:422
 checkShapeEtaTreePions.C:423
 checkShapeEtaTreePions.C:424
 checkShapeEtaTreePions.C:425
 checkShapeEtaTreePions.C:426
 checkShapeEtaTreePions.C:427
 checkShapeEtaTreePions.C:428
 checkShapeEtaTreePions.C:429
 checkShapeEtaTreePions.C:430
 checkShapeEtaTreePions.C:431
 checkShapeEtaTreePions.C:432
 checkShapeEtaTreePions.C:433
 checkShapeEtaTreePions.C:434
 checkShapeEtaTreePions.C:435
 checkShapeEtaTreePions.C:436
 checkShapeEtaTreePions.C:437
 checkShapeEtaTreePions.C:438
 checkShapeEtaTreePions.C:439
 checkShapeEtaTreePions.C:440
 checkShapeEtaTreePions.C:441
 checkShapeEtaTreePions.C:442
 checkShapeEtaTreePions.C:443
 checkShapeEtaTreePions.C:444
 checkShapeEtaTreePions.C:445
 checkShapeEtaTreePions.C:446
 checkShapeEtaTreePions.C:447
 checkShapeEtaTreePions.C:448
 checkShapeEtaTreePions.C:449
 checkShapeEtaTreePions.C:450
 checkShapeEtaTreePions.C:451
 checkShapeEtaTreePions.C:452
 checkShapeEtaTreePions.C:453
 checkShapeEtaTreePions.C:454
 checkShapeEtaTreePions.C:455
 checkShapeEtaTreePions.C:456
 checkShapeEtaTreePions.C:457
 checkShapeEtaTreePions.C:458
 checkShapeEtaTreePions.C:459
 checkShapeEtaTreePions.C:460
 checkShapeEtaTreePions.C:461
 checkShapeEtaTreePions.C:462
 checkShapeEtaTreePions.C:463
 checkShapeEtaTreePions.C:464
 checkShapeEtaTreePions.C:465
 checkShapeEtaTreePions.C:466
 checkShapeEtaTreePions.C:467
 checkShapeEtaTreePions.C:468
 checkShapeEtaTreePions.C:469
 checkShapeEtaTreePions.C:470
 checkShapeEtaTreePions.C:471
 checkShapeEtaTreePions.C:472
 checkShapeEtaTreePions.C:473
 checkShapeEtaTreePions.C:474
 checkShapeEtaTreePions.C:475
 checkShapeEtaTreePions.C:476
 checkShapeEtaTreePions.C:477
 checkShapeEtaTreePions.C:478
 checkShapeEtaTreePions.C:479
 checkShapeEtaTreePions.C:480
 checkShapeEtaTreePions.C:481
 checkShapeEtaTreePions.C:482
 checkShapeEtaTreePions.C:483
 checkShapeEtaTreePions.C:484
 checkShapeEtaTreePions.C:485
 checkShapeEtaTreePions.C:486
 checkShapeEtaTreePions.C:487
 checkShapeEtaTreePions.C:488
 checkShapeEtaTreePions.C:489
 checkShapeEtaTreePions.C:490
 checkShapeEtaTreePions.C:491
 checkShapeEtaTreePions.C:492
 checkShapeEtaTreePions.C:493
 checkShapeEtaTreePions.C:494
 checkShapeEtaTreePions.C:495
 checkShapeEtaTreePions.C:496
 checkShapeEtaTreePions.C:497
 checkShapeEtaTreePions.C:498
 checkShapeEtaTreePions.C:499
 checkShapeEtaTreePions.C:500
 checkShapeEtaTreePions.C:501
 checkShapeEtaTreePions.C:502
 checkShapeEtaTreePions.C:503
 checkShapeEtaTreePions.C:504
 checkShapeEtaTreePions.C:505
 checkShapeEtaTreePions.C:506
 checkShapeEtaTreePions.C:507
 checkShapeEtaTreePions.C:508
 checkShapeEtaTreePions.C:509
 checkShapeEtaTreePions.C:510
 checkShapeEtaTreePions.C:511
 checkShapeEtaTreePions.C:512
 checkShapeEtaTreePions.C:513
 checkShapeEtaTreePions.C:514
 checkShapeEtaTreePions.C:515
 checkShapeEtaTreePions.C:516
 checkShapeEtaTreePions.C:517
 checkShapeEtaTreePions.C:518
 checkShapeEtaTreePions.C:519
 checkShapeEtaTreePions.C:520
 checkShapeEtaTreePions.C:521
 checkShapeEtaTreePions.C:522
 checkShapeEtaTreePions.C:523
 checkShapeEtaTreePions.C:524
 checkShapeEtaTreePions.C:525
 checkShapeEtaTreePions.C:526
 checkShapeEtaTreePions.C:527
 checkShapeEtaTreePions.C:528
 checkShapeEtaTreePions.C:529
 checkShapeEtaTreePions.C:530
 checkShapeEtaTreePions.C:531
 checkShapeEtaTreePions.C:532
 checkShapeEtaTreePions.C:533
 checkShapeEtaTreePions.C:534
 checkShapeEtaTreePions.C:535
 checkShapeEtaTreePions.C:536
 checkShapeEtaTreePions.C:537
 checkShapeEtaTreePions.C:538
 checkShapeEtaTreePions.C:539
 checkShapeEtaTreePions.C:540
 checkShapeEtaTreePions.C:541
 checkShapeEtaTreePions.C:542
 checkShapeEtaTreePions.C:543
 checkShapeEtaTreePions.C:544
 checkShapeEtaTreePions.C:545
 checkShapeEtaTreePions.C:546
 checkShapeEtaTreePions.C:547
 checkShapeEtaTreePions.C:548
 checkShapeEtaTreePions.C:549
 checkShapeEtaTreePions.C:550
 checkShapeEtaTreePions.C:551
 checkShapeEtaTreePions.C:552
 checkShapeEtaTreePions.C:553
 checkShapeEtaTreePions.C:554
 checkShapeEtaTreePions.C:555
 checkShapeEtaTreePions.C:556
 checkShapeEtaTreePions.C:557
 checkShapeEtaTreePions.C:558
 checkShapeEtaTreePions.C:559
 checkShapeEtaTreePions.C:560
 checkShapeEtaTreePions.C:561
 checkShapeEtaTreePions.C:562
 checkShapeEtaTreePions.C:563
 checkShapeEtaTreePions.C:564
 checkShapeEtaTreePions.C:565
 checkShapeEtaTreePions.C:566
 checkShapeEtaTreePions.C:567
 checkShapeEtaTreePions.C:568
 checkShapeEtaTreePions.C:569
 checkShapeEtaTreePions.C:570
 checkShapeEtaTreePions.C:571
 checkShapeEtaTreePions.C:572
 checkShapeEtaTreePions.C:573
 checkShapeEtaTreePions.C:574
 checkShapeEtaTreePions.C:575
 checkShapeEtaTreePions.C:576
 checkShapeEtaTreePions.C:577
 checkShapeEtaTreePions.C:578
 checkShapeEtaTreePions.C:579
 checkShapeEtaTreePions.C:580
 checkShapeEtaTreePions.C:581
 checkShapeEtaTreePions.C:582
 checkShapeEtaTreePions.C:583
 checkShapeEtaTreePions.C:584
 checkShapeEtaTreePions.C:585
 checkShapeEtaTreePions.C:586
 checkShapeEtaTreePions.C:587
 checkShapeEtaTreePions.C:588
 checkShapeEtaTreePions.C:589
 checkShapeEtaTreePions.C:590
 checkShapeEtaTreePions.C:591
 checkShapeEtaTreePions.C:592
 checkShapeEtaTreePions.C:593
 checkShapeEtaTreePions.C:594
 checkShapeEtaTreePions.C:595
 checkShapeEtaTreePions.C:596
 checkShapeEtaTreePions.C:597
 checkShapeEtaTreePions.C:598
 checkShapeEtaTreePions.C:599
 checkShapeEtaTreePions.C:600
 checkShapeEtaTreePions.C:601
 checkShapeEtaTreePions.C:602
 checkShapeEtaTreePions.C:603
 checkShapeEtaTreePions.C:604
 checkShapeEtaTreePions.C:605
 checkShapeEtaTreePions.C:606
 checkShapeEtaTreePions.C:607
 checkShapeEtaTreePions.C:608
 checkShapeEtaTreePions.C:609
 checkShapeEtaTreePions.C:610
 checkShapeEtaTreePions.C:611
 checkShapeEtaTreePions.C:612
 checkShapeEtaTreePions.C:613
 checkShapeEtaTreePions.C:614
 checkShapeEtaTreePions.C:615
 checkShapeEtaTreePions.C:616
 checkShapeEtaTreePions.C:617
 checkShapeEtaTreePions.C:618
 checkShapeEtaTreePions.C:619
 checkShapeEtaTreePions.C:620
 checkShapeEtaTreePions.C:621
 checkShapeEtaTreePions.C:622
 checkShapeEtaTreePions.C:623
 checkShapeEtaTreePions.C:624
 checkShapeEtaTreePions.C:625
 checkShapeEtaTreePions.C:626
 checkShapeEtaTreePions.C:627
 checkShapeEtaTreePions.C:628
 checkShapeEtaTreePions.C:629
 checkShapeEtaTreePions.C:630
 checkShapeEtaTreePions.C:631
 checkShapeEtaTreePions.C:632
 checkShapeEtaTreePions.C:633
 checkShapeEtaTreePions.C:634
 checkShapeEtaTreePions.C:635
 checkShapeEtaTreePions.C:636
 checkShapeEtaTreePions.C:637
 checkShapeEtaTreePions.C:638
 checkShapeEtaTreePions.C:639
 checkShapeEtaTreePions.C:640
 checkShapeEtaTreePions.C:641
 checkShapeEtaTreePions.C:642
 checkShapeEtaTreePions.C:643
 checkShapeEtaTreePions.C:644
 checkShapeEtaTreePions.C:645
 checkShapeEtaTreePions.C:646
 checkShapeEtaTreePions.C:647
 checkShapeEtaTreePions.C:648
 checkShapeEtaTreePions.C:649
 checkShapeEtaTreePions.C:650
 checkShapeEtaTreePions.C:651
 checkShapeEtaTreePions.C:652
 checkShapeEtaTreePions.C:653
 checkShapeEtaTreePions.C:654
 checkShapeEtaTreePions.C:655
 checkShapeEtaTreePions.C:656
 checkShapeEtaTreePions.C:657
 checkShapeEtaTreePions.C:658
 checkShapeEtaTreePions.C:659
 checkShapeEtaTreePions.C:660
 checkShapeEtaTreePions.C:661
 checkShapeEtaTreePions.C:662
 checkShapeEtaTreePions.C:663
 checkShapeEtaTreePions.C:664
 checkShapeEtaTreePions.C:665
 checkShapeEtaTreePions.C:666
 checkShapeEtaTreePions.C:667
 checkShapeEtaTreePions.C:668
 checkShapeEtaTreePions.C:669
 checkShapeEtaTreePions.C:670
 checkShapeEtaTreePions.C:671
 checkShapeEtaTreePions.C:672
 checkShapeEtaTreePions.C:673
 checkShapeEtaTreePions.C:674
 checkShapeEtaTreePions.C:675
 checkShapeEtaTreePions.C:676
 checkShapeEtaTreePions.C:677
 checkShapeEtaTreePions.C:678
 checkShapeEtaTreePions.C:679
 checkShapeEtaTreePions.C:680
 checkShapeEtaTreePions.C:681
 checkShapeEtaTreePions.C:682
 checkShapeEtaTreePions.C:683
 checkShapeEtaTreePions.C:684
 checkShapeEtaTreePions.C:685
 checkShapeEtaTreePions.C:686
 checkShapeEtaTreePions.C:687
 checkShapeEtaTreePions.C:688
 checkShapeEtaTreePions.C:689
 checkShapeEtaTreePions.C:690
 checkShapeEtaTreePions.C:691
 checkShapeEtaTreePions.C:692
 checkShapeEtaTreePions.C:693
 checkShapeEtaTreePions.C:694
 checkShapeEtaTreePions.C:695
 checkShapeEtaTreePions.C:696
 checkShapeEtaTreePions.C:697
 checkShapeEtaTreePions.C:698
 checkShapeEtaTreePions.C:699
 checkShapeEtaTreePions.C:700
 checkShapeEtaTreePions.C:701
 checkShapeEtaTreePions.C:702
 checkShapeEtaTreePions.C:703
 checkShapeEtaTreePions.C:704
 checkShapeEtaTreePions.C:705
 checkShapeEtaTreePions.C:706
 checkShapeEtaTreePions.C:707
 checkShapeEtaTreePions.C:708
 checkShapeEtaTreePions.C:709
 checkShapeEtaTreePions.C:710
 checkShapeEtaTreePions.C:711
 checkShapeEtaTreePions.C:712
 checkShapeEtaTreePions.C:713
 checkShapeEtaTreePions.C:714
 checkShapeEtaTreePions.C:715
 checkShapeEtaTreePions.C:716
 checkShapeEtaTreePions.C:717
 checkShapeEtaTreePions.C:718
 checkShapeEtaTreePions.C:719
 checkShapeEtaTreePions.C:720
 checkShapeEtaTreePions.C:721
 checkShapeEtaTreePions.C:722
 checkShapeEtaTreePions.C:723
 checkShapeEtaTreePions.C:724
 checkShapeEtaTreePions.C:725
 checkShapeEtaTreePions.C:726
 checkShapeEtaTreePions.C:727
 checkShapeEtaTreePions.C:728
 checkShapeEtaTreePions.C:729
 checkShapeEtaTreePions.C:730
 checkShapeEtaTreePions.C:731
 checkShapeEtaTreePions.C:732
 checkShapeEtaTreePions.C:733
 checkShapeEtaTreePions.C:734
 checkShapeEtaTreePions.C:735
 checkShapeEtaTreePions.C:736
 checkShapeEtaTreePions.C:737
 checkShapeEtaTreePions.C:738
 checkShapeEtaTreePions.C:739
 checkShapeEtaTreePions.C:740
 checkShapeEtaTreePions.C:741
 checkShapeEtaTreePions.C:742
 checkShapeEtaTreePions.C:743
 checkShapeEtaTreePions.C:744
 checkShapeEtaTreePions.C:745
 checkShapeEtaTreePions.C:746
 checkShapeEtaTreePions.C:747
 checkShapeEtaTreePions.C:748
 checkShapeEtaTreePions.C:749
 checkShapeEtaTreePions.C:750
 checkShapeEtaTreePions.C:751
 checkShapeEtaTreePions.C:752
 checkShapeEtaTreePions.C:753
 checkShapeEtaTreePions.C:754
 checkShapeEtaTreePions.C:755
 checkShapeEtaTreePions.C:756
 checkShapeEtaTreePions.C:757
 checkShapeEtaTreePions.C:758
 checkShapeEtaTreePions.C:759
 checkShapeEtaTreePions.C:760
 checkShapeEtaTreePions.C:761
 checkShapeEtaTreePions.C:762
 checkShapeEtaTreePions.C:763
 checkShapeEtaTreePions.C:764
 checkShapeEtaTreePions.C:765
 checkShapeEtaTreePions.C:766
 checkShapeEtaTreePions.C:767
 checkShapeEtaTreePions.C:768
 checkShapeEtaTreePions.C:769
 checkShapeEtaTreePions.C:770
 checkShapeEtaTreePions.C:771
 checkShapeEtaTreePions.C:772
 checkShapeEtaTreePions.C:773
 checkShapeEtaTreePions.C:774
 checkShapeEtaTreePions.C:775
 checkShapeEtaTreePions.C:776
 checkShapeEtaTreePions.C:777
 checkShapeEtaTreePions.C:778
 checkShapeEtaTreePions.C:779
 checkShapeEtaTreePions.C:780
 checkShapeEtaTreePions.C:781
 checkShapeEtaTreePions.C:782
 checkShapeEtaTreePions.C:783
 checkShapeEtaTreePions.C:784
 checkShapeEtaTreePions.C:785
 checkShapeEtaTreePions.C:786
 checkShapeEtaTreePions.C:787
 checkShapeEtaTreePions.C:788
 checkShapeEtaTreePions.C:789
 checkShapeEtaTreePions.C:790
 checkShapeEtaTreePions.C:791
 checkShapeEtaTreePions.C:792
 checkShapeEtaTreePions.C:793
 checkShapeEtaTreePions.C:794
 checkShapeEtaTreePions.C:795
 checkShapeEtaTreePions.C:796
 checkShapeEtaTreePions.C:797
 checkShapeEtaTreePions.C:798
 checkShapeEtaTreePions.C:799
 checkShapeEtaTreePions.C:800
 checkShapeEtaTreePions.C:801
 checkShapeEtaTreePions.C:802
 checkShapeEtaTreePions.C:803
 checkShapeEtaTreePions.C:804
 checkShapeEtaTreePions.C:805
 checkShapeEtaTreePions.C:806
 checkShapeEtaTreePions.C:807
 checkShapeEtaTreePions.C:808
 checkShapeEtaTreePions.C:809
 checkShapeEtaTreePions.C:810
 checkShapeEtaTreePions.C:811
 checkShapeEtaTreePions.C:812
 checkShapeEtaTreePions.C:813
 checkShapeEtaTreePions.C:814
 checkShapeEtaTreePions.C:815
 checkShapeEtaTreePions.C:816
 checkShapeEtaTreePions.C:817
 checkShapeEtaTreePions.C:818
 checkShapeEtaTreePions.C:819
 checkShapeEtaTreePions.C:820
 checkShapeEtaTreePions.C:821
 checkShapeEtaTreePions.C:822
 checkShapeEtaTreePions.C:823
 checkShapeEtaTreePions.C:824
 checkShapeEtaTreePions.C:825
 checkShapeEtaTreePions.C:826
 checkShapeEtaTreePions.C:827
 checkShapeEtaTreePions.C:828
 checkShapeEtaTreePions.C:829
 checkShapeEtaTreePions.C:830
 checkShapeEtaTreePions.C:831
 checkShapeEtaTreePions.C:832