ROOT logo
#ifndef __CINT__

#include "TSystem.h"
#include "TGeoManager.h"
#include <AliRunLoader.h>
#include <AliGeomManager.h>
#include <AliITSgeom.h>
#include <AliTracker.h>
#include "TRandom.h"
#include "TMath.h"
#include "TH2F.h"
#include "TCanvas.h"
#include "TFile.h"
#include <AliRun.h>
#include <TLegend.h>

#include <TGeoVolume.h>
#include "TGeoMaterial.h"
#include "TGeoMedium.h"
#include <TGeoTube.h>
#include <AliITSUGeomTGeo.h>
#include <TPaveText.h>
#include <TText.h>

#endif

/*
  gSystem->Load("libITSUpgradeBase");
  gSystem->Load("libITSUpgradeSim");

  .L GetMaterialBudget.C

  DrawMaterialBudget_SPLITTED(); 
  DrawMaterialBudget_FromTo();

  GetMaterialBudget_EtaVsPhi(0,0);
  GetMaterialBudget_inPhi(0,0);

*/

// Original version
// Chinorat Kobdaj (kobdaj@g.sut.ac.th)
// Revised and adapted to newer AliITSUv1 versions
// Mario Sitta <sitta@to.infn.it> - Nov 2014


enum {
    kIBModelDummy=0,
    kIBModel0=1,
    kIBModel1=2, 
    kIBModel21=3,
    kIBModel22=4,
    kIBModel3=5,
    kOBModelDummy=6,
    kOBModel0=7,
    kOBModel1=8, 
    kOBModel2=9 
};


//______________________________________________________________________
void PrintMaterialDefs(const char *geofile="geometry.root")
{
  //
  // Print material definition for all ITS materials/mediums
  // Rewritten - M.Sitta 15 Nov 2014
  //
  TGeoManager::Import(geofile);

  TGeoMedium *med;
  TGeoMaterial *mat;
  char mediaName[50], matName[50], shortName[50];

  Int_t nMedia = gGeoManager->GetListOfMedia()->GetEntries();

  printf("\n\n\n");
  printf("              ==== ITSU  Material  Properties ====\n\n");
  printf("    A      Z   d (g/cm3)  RadLen (cm)  IntLen (cm)\t Name\n");

  // Loop on media, select ITS materials, print their characteristics
  for (Int_t i = 0; i < nMedia; i++) {
    med = (TGeoMedium *)(gGeoManager->GetListOfMedia()->At(i));
    strcpy(mediaName, med->GetName());
    // The trick here: the name must begin with the string "ITS_"
    // so the pointer to the first occurrence of the substring as returned
    // by strstr() must match the beginning of the string
    if (strstr(mediaName,"ITS_") == mediaName) { // name begins with "ITS_"
      mat = med->GetMaterial();
      strcpy(matName, mat->GetName());
      strncpy(shortName, matName+4, strlen(matName)-5); // get rid of ITS_ , $
      shortName[strlen(matName)-5] = '\0';
      printf(" %5.1f %6.1f %8.3f %13.3f %11.3f\t %s\n", 
	     mat->GetA(), mat->GetZ(), mat->GetDensity(), mat->GetRadLen(),
	     mat->GetIntLen(), shortName);
    }
  }

  printf("\n");

//   printf("Values in Corrados estimate");
//   const Int_t nC=6;
//   TString medNC[nC]={"ITS_SI$","ITS_WATER$","ITS_CARBON$","ITS_KAPTON$","ITS_FLEXCABLE$","ITS_GLUE$"};
//   Double_t radl[nC]={9.36,36.1,25,28.6,13.3,44.37};
//   for (Int_t i=0; i<nC; i++) {
//     printf("%8.2lf (cm)  \t%s\n", radl[i],medNC[i].Data());
//   }
  
}


//______________________________________________________________________
Double_t ComputeMaterialBudget(Double_t rmin, Double_t rmax, Double_t etaPos,
			       Double_t phiMax,
			       TH1F* xOverX01d, TH2F* xOverX02d = 0)
{
  //
  // Ancillary function to compute material budget between rmin and rmax
  // and +/- etaPos in the 0--phiMax range, filling two histograms
  // Rewritten - M.Sitta 15 Nov 2014
  //
  Int_t n = 5e4; //testtracks

  TH1F *nParticles1d = new TH1F("", "", 300, 0, phiMax);
  TH2F *nParticles2d = new TH2F("", "", 300, -etaPos, etaPos, 300, 0, phiMax);

  Double_t mparam[7]={0.,0.,0.,0.,0.};
  Double_t point1[3],point2[3];

  for (Int_t it=0; it<n; it++) {

    // PHI VS ETA
    Double_t phi = gRandom->Rndm()*phiMax;
    Double_t eta = gRandom->Rndm()*2*etaPos - etaPos;
    Double_t theta = TMath::ATan(TMath::Exp(-eta))*2;
    point1[0] = rmin*TMath::Cos(phi);
    point1[1] = rmin*TMath::Sin(phi);
    point1[2] = rmin/TMath::Tan(theta);
    point2[0] = rmax*TMath::Cos(phi);
    point2[1] = rmax*TMath::Sin(phi);
    point2[2] = rmax/TMath::Tan(theta);
    
    AliTracker::MeanMaterialBudget(point1,point2,mparam);

    xOverX01d->Fill(phi, mparam[1]*100);
    nParticles1d->Fill(phi, 1.);

    if (xOverX02d != 0) {
      xOverX02d->Fill(eta, phi, mparam[1]*100);
      nParticles2d->Fill(eta, phi, 1.);
    }

    if (!(it%10000)) cout<<" : "<<mparam[1]*100<<"   phi:"<<phi<<endl;

  }

  // normalization to number of particles in case of phi vs eta
  Double_t theta = TMath::ATan(TMath::Exp(-etaPos/2))*2;
  printf("<eta>=%lf -> Sin(theta) %lf\n",etaPos/2,TMath::Sin(theta)); 

  for (Int_t ix = 1; ix<=nParticles1d->GetNbinsX(); ix++) {
    if (nParticles1d->GetBinContent(ix) > 0) 
      xOverX01d->SetBinContent(ix,xOverX01d->GetBinContent(ix)/nParticles1d->GetBinContent(ix)*TMath::Sin(theta));
    }

  if (xOverX02d) {
    for (Int_t ix = 1; ix<=nParticles2d->GetNbinsX(); ix++) {
      for (Int_t iy = 1; iy<=nParticles2d->GetNbinsY(); iy++) {
	if (nParticles2d->GetBinContent(ix,iy) > 0) 
	  xOverX02d->SetBinContent(ix,iy,xOverX02d->GetBinContent(ix,iy)/nParticles2d->GetBinContent(ix,iy));
      }
    }
  }

  Double_t mean = 0;
  for (Int_t ix = 1; ix<=xOverX01d->GetNbinsX(); ix++)
    mean+=xOverX01d->GetBinContent(ix);

  mean /= xOverX01d->GetNbinsX();

  return mean;
}


//______________________________________________________________________
void DrawMaterialBudget_Splitted(Int_t nLay = 0, Double_t rmin = 1.,
				 Double_t rmax = 5.)
{
  //
  // Function to factorize the percentage of each medium in the
  // total material budget between rmin and rmax for layer nLay
  // Cleaned up - M.Sitta 15 Nov 2014
  //
  TCanvas *c2 = new TCanvas("c2","c2");

  Double_t etaPos = 1.;

  Bool_t firstPlot = 1;

  // Check parameters
  if (nLay < 0 || nLay > 6) {
    printf("ERROR! Wrong layer number %d\n",nLay);
    return;
  }

  if (rmin < 0. || rmax < 0. || rmax < rmin) {
    printf("ERROR! Wrong radial values rmin = %f rmax = %f\n",rmin,rmax);
    return;
  }

  // In current version, build levels have different meaning for IB and OB
  const Int_t nScenariosIB = 6, nScenariosOB = 7;
  TString strDescripOB[nScenariosOB] = {"Copper", "Aluminum", "Glue", "Water",
				        "Kapton", "Carbon"  , "Silicon"      };
  //  Color codes
  //  Water                kBlack
  //  Kapton               kYellow
  //  Carbon               kRed
  //  Glue                 kBlue
  //  Aluminum             kCyan
  //  Si-Sensor            kGreen
  //  Copper               kGray
  Int_t colorsOB[nScenariosOB] = {kGray  , kCyan, kBlue, kBlack,
			          kYellow, kRed , kGreen       };

//   TString strDescripIB[nScenariosIB] = {"Carbon Structure", "Water",
// 				        "Cooling Pipe Walls and ColdPlate",
// 				        "Glue", "Flex Cable", "Pixel Chip"};
  TString strDescripIB[nScenariosIB] = {"Flex cable", "Glue",
				        "Carbon structure", "Water",
					"Cooling walls", "Pixel Chip"};
  //  Color codes
  //  Flex Cable           kBlack
  //  Glue                 kYellow
  //  Carbon Structure     kRed
  //  Water                kBlue
  //  Cooling Walls        kCyan 
  //  Si-Sensor            kGreen 
  Int_t colorsIB[nScenariosIB] = {kCyan, kBlue, kBlack, kYellow, kRed, kGreen};

  // Setup
  const Int_t maxNumberOfScenarios = nScenariosOB;

  Double_t meanX0[maxNumberOfScenarios];
  TH1F *l[maxNumberOfScenarios+1];

  TString strDescrip[maxNumberOfScenarios];
  Int_t colors[maxNumberOfScenarios];

  // Choose which scenario based on Layer number and Model
  Int_t nScenarios;

  TGeoManager::Import(Form("geometry_0.root"));
  AliITSUGeomTGeo* gm = new AliITSUGeomTGeo(kTRUE);
  Int_t nLad = gm->GetNStaves(nLay);

  Float_t phiMax = TMath::TwoPi()/nLad*2;

  char title[30];
  Int_t model, buildlevel;
  if (nLay < 3) { // IB has only 6 scenarios
    nScenarios = nScenariosIB;
    for (Int_t i=0; i<nScenarios; i++) {
      strDescrip[i] = strDescripIB[i];
      colors[i] = colorsIB[i];
    }
  } else {
    strcpy(title,
	   gGeoManager->GetVolume(Form("ITSULayer%d",nLay))->GetTitle());
    if (strlen(title) == 0) { // Old OB has only 6 scenarios like IB
      nScenarios = nScenariosIB;
      for (Int_t i=0; i<nScenarios; i++) {
	strDescrip[i] = strDescripOB[i+1];
	colors[i] = colorsOB[i+1];
      }
    } else { // New OB: check model
      sscanf(title, "Model %d Build level %d", &model, &buildlevel);
      if (model == kOBModel2) {
	nScenarios = nScenariosOB;
	for (Int_t i=0; i<nScenarios; i++) {
	  strDescrip[i] = strDescripOB[i];
	  colors[i] = colorsOB[i];
	}
      } else {
	nScenarios = nScenariosIB;
	for (Int_t i=0; i<nScenarios; i++) {
	  strDescrip[i] = strDescripOB[i+1];
	  colors[i] = colorsOB[i+1];
	}
      }
    }
  } // if (nLay < 3)

  delete gGeoManager;

  for (Int_t i=0; i<nScenarios; i++) {

    printf(" -> Loading geometry_%d.root .....\n",i);
    TGeoManager::Import(Form("geometry_%d.root",i)); 

    strcpy(title,
	   gGeoManager->GetVolume(Form("ITSULayer%d",nLay))->GetTitle());
    if (strlen(title) != 0) {
      sscanf(title, "Model %d Build level %d", &model, &buildlevel);
      if (i != buildlevel)
	printf("WARNING! Possible mismatch: file geometry_%d.root created with Build level %d\n",i,buildlevel);
    }

    TH1F *xOverX01d =  new TH1F("", "", 300, 0, phiMax);

    Double_t mean = ComputeMaterialBudget(rmin, rmax, etaPos, phiMax,
					  xOverX01d);
    meanX0[i] = mean;
    cout<<"Mean X/X0: " << meanX0[i] << " %" << endl;

    xOverX01d->GetXaxis()->SetTitle("#phi (rad)");
    xOverX01d->GetYaxis()->SetTitle(Form("X/X_{0} (%%) at #eta=0 "));
    xOverX01d->SetFillColor(colors[i]-7);
    if (i==0)  xOverX01d->SetFillColor(colors[i]);
    if ( (nScenarios == nScenariosIB && i==2) ||
	 (nScenarios == nScenariosOB && i==3) )
      xOverX01d->SetFillColor(colors[i]);
    xOverX01d->SetStats(0);

    l[i] = new TH1F("","",1,0,phiMax);
    l[i]->SetBinContent(1,mean);
    l[i]->SetStats(0);
    l[i]->SetLineColor(colors[i]-7);
    if (i==0) l[i]->SetLineColor(kGray);
    if ( (nScenarios == nScenariosIB && i==2) ||
	 (nScenarios == nScenariosOB && i==3) ) l[i]->SetLineColor(12);

    c2->cd();
    if (firstPlot) {
      xOverX01d->SetMinimum(0.);
      xOverX01d->DrawCopy(); 
      firstPlot=0;
    } else
      xOverX01d->DrawCopy("same"); 
     
    delete gGeoManager;
  }
  
  // Build meaningful legend
  TLegend *leg = new TLegend(0.76,0.77,0.99,0.99,"");
  leg->SetFillColor(0);

  for (Int_t i=0; i<nScenarios; i++) {
    // contribution in percent
    Double_t contr = 0;
    if (i == nScenarios-1)
      contr = (meanX0[i])/meanX0[0]*100; 
    else
      contr = (meanX0[i]-meanX0[i+1])/meanX0[0]*100; 
 
    strDescrip[i].Append(Form(" (%3.1lf%%)",contr));
    leg->AddEntry(l[i],strDescrip[i].Data(),"l");
  }

  TPaveText *pt = new TPaveText(0.76,0.70,0.99,0.77,"brNDC");
  pt->SetBorderSize(1); // no shadow
  pt->SetTextFont(12);
  pt->SetFillColor(0);
  pt->AddText(Form("Mean X/X0 = %4.3lf%%",meanX0[0]));
  pt->Draw();

  leg->Draw();

  l[nScenarios]=(TH1F*)l[0]->Clone();
  l[nScenarios]->SetLineColor(1);
  l[nScenarios]->SetLineWidth(2);
  l[nScenarios]->DrawCopy("same");
  
  c2->SaveAs("Material-details.pdf");
  
}


//______________________________________________________________________
void DrawMaterialBudget_FromTo(Int_t nLay = 0, Double_t rmin = 1.,
			       Double_t rmax = 5., Bool_t only2D = 1)
{
  //
  // Function to compute material budget between rmin and rmax
  // for layer nLay. If only2D is false a 1D histogram is also plotted
  // Cleaned up and simplified - M.Sitta 18 Nov 2014
  //

  Double_t etaPos = 0.25;

  // Check parameters
  if (nLay < 0 || nLay > 6) {
    printf("ERROR! Wrong layer number %d\n",nLay);
    return;
  }

  if (rmin < 0. || rmax < 0. || rmax < rmin) {
    printf("ERROR! Wrong radial values rmin = %f rmax = %f\n",rmin,rmax);
    return;
  }


  TGeoManager::Import("geometry.root"); 
  AliITSUGeomTGeo* gm = new AliITSUGeomTGeo(kTRUE);
  Int_t nLad = gm->GetNStaves(nLay);

  Float_t phiMax = TMath::TwoPi()/nLad*2;

  TH2F *xOverX0   =  new TH2F("", "", 300, -1, 1., 300, 0, phiMax);
  TH1F *xOverX01d =  new TH1F("", "", 300,  0, phiMax);

  Double_t mean = ComputeMaterialBudget(rmin, rmax, -1, phiMax,
					xOverX01d, xOverX0);
  cout<<"Mean X/X0: " << mean << " %" << endl;

  TH1F *l = new TH1F("", "", 1, 0, phiMax);
  l->SetBinContent(1, mean);
  l->SetLineColor(2);
  l->SetStats(0);
  l->SetLineWidth(2);

  // Draw the histograms
  xOverX0->SetTitle(0);
  xOverX0->GetXaxis()->SetTitle("pseudorapidity #eta ");
  xOverX0->GetYaxis()->SetTitle("#phi (rad)");
  xOverX0->GetZaxis()->SetTitle("X/X_{0} (%)");
  xOverX0->SetStats(0);

  xOverX01d->SetTitle(Form("X/X_{0} (%%) within r=(%2.1lf-%2.1lf)cm average over #eta=(%1.1lf,%1.1lf)", rmin, rmax, -1., 1.));
  xOverX01d->GetXaxis()->SetTitle("#phi (rad)");
  xOverX01d->GetYaxis()->SetTitle("X/X_{0} (%) average over #eta=(-1,1)");
  xOverX01d->SetStats(0);

  if (!only2D) {
    TCanvas *c1 = new TCanvas("c1","c1",800,800);
    c1->Divide(1,2);
    c1->cd(1); xOverX0->Draw("colz");
    c1->cd(2); xOverX01d->DrawCopy(); l->DrawCopy("same");
    c1->SaveAs("Material-1D.pdf");
  } else {
    TCanvas *c1 = new TCanvas("c1","c1");
    xOverX0->Draw("colz");
    c1->SaveAs("Material-2D.pdf");
  }

}


//______________________________________________________________________
void ComputeGeometricalParameters(const char *geofile, Double_t *rmin,
				  Double_t *rmax, Double_t *zPos,
				  Int_t *nlad, Bool_t fromGDML = 0)
{
  //
  // Ancillary function to retrieve various geometrical parameters
  // from a geometry file. The caller must ensure that all vectors
  // have proper dimensions: since this function is designed to be used
  // internally, no check is made on parameters!
  // Rewritten - M.Sitta 20 Nov 2014
  //

  if (fromGDML)  // from GDML
    TGeoManager::Import(geofile);
//    gGeoManager->ViewLeaves(true); 
//    gGeoManager->GetTopVolume()->Draw("ogl"); 
  else {         // from AliRoot simulation
        
//    gAlice=NULL;
//    AliRunLoader* runLoader = AliRunLoader::Open("galice.root");
//    runLoader->LoadgAlice();
    
//    gAlice = runLoader->GetAliRun();
//    AliGeomManager::LoadGeometry(geofile);
    TGeoManager::Import(geofile);
    AliITSUGeomTGeo* gm = new AliITSUGeomTGeo(kTRUE);

    TGeoVolume *pipeV = gGeoManager->GetVolume("IP_PIPE");
    if (!pipeV) {
      printf("Pipe volume %s is not in the geometry\n", "IP_PIPE");
      return;
    } else {
      printf("%s   ","IP_PIPE");
      TGeoTube *t = (TGeoTube*)(pipeV->GetShape());
      printf(" r = (%3.2lf %3.2lf) ", t->GetRmin(), t->GetRmax());
      printf(" z = %3.2lf\n", t->GetDz());

      rmin[0] = t->GetRmin();
      rmax[0] = t->GetRmax();
      nlad[0] = 0;
      zPos[0] = 0;
    }

    TGeoVolume *itsV = gGeoManager->GetVolume(gm->GetITSVolPattern());
    if (!itsV) {
      printf("ITS volume %s is not in the geometry\n", gm->GetITSVolPattern());
      return;
    }
    //
    // Loop on all ITSV nodes, count Layer volumes by checking names
    Int_t nNodes = itsV->GetNodes()->GetEntries();
    Int_t numberOfLayers = 0;
    for (Int_t j=0; j<nNodes; j++) {
      if ( strstr(itsV->GetNodes()->At(j)->GetName(),
		  gm->GetITSWrapVolPattern()) ) {

	TGeoNode *wrapN = (TGeoNode*)(itsV->GetNodes()->At(j));
	TGeoVolume *wrapV = wrapN->GetVolume();
 	Int_t nNodesWrap = wrapV->GetNodes()->GetEntries();

 	for (Int_t k=0; k<nNodesWrap; k++) {
 	  if ( strstr(wrapV->GetNodes()->At(k)->GetName(),
 		      gm->GetITSLayerPattern()) ) {

 	    Int_t l = numberOfLayers;
 	    numberOfLayers++;
	
 	    char laynam[30];
 	    snprintf(laynam, 30, "%s%d", gm->GetITSLayerPattern(), l);
 	    TGeoVolume* volLy = gGeoManager->GetVolume(laynam);
 	    printf("%s\t",volLy->GetName());

 	    // Layers are Assemblies not Tubes, so:
 	    // for rmax we assume the maximum extension of the assembly
 	    // for rmin: for OB (no Turbo) we take the stave height and
 	    // we subtract this from rmax; for IB (Turbo) we compute the
 	    // position of the most internal corner
 	    TGeoBBox *b = (TGeoBBox*)(volLy->GetShape());
 	    TGeoBBox *s = (TGeoBBox*)(gGeoManager->GetVolume(Form("%s%d",gm->GetITSStavePattern(),l))->GetShape());
 	    Double_t minr;

	    Double_t loc[3], mas[3];
 	    if (l < 3) {
 	      Double_t loc[3], mas[3];
  	      loc[0] = s->GetDX();
  	      loc[1] = s->GetDY();
 	      loc[2] = 0;
 	      volLy->GetNode(Form("%s%d_0",gm->GetITSStavePattern(),l))->GetMatrix()->LocalToMaster(loc,mas);
 	      minr = TMath::Sqrt(mas[0]*mas[0] + mas[1]*mas[1]);
	      zPos[l+1] = 0;
 	    } else {
 	      minr = b->GetDX() - 2*s->GetDX();
	      TGeoBBox *c = (TGeoBBox*)(gGeoManager->GetVolume(Form("%s%d",gm->GetITSChipPattern(),l))->GetShape());
	      zPos[l+1] = c->GetDZ();
 	    }
 	    rmin[l+1] = minr;
 	    rmax[l+1] = b->GetDX();
 	    nlad[l+1] = gm->GetNStaves(l);

 	    printf(" r = (%5.2lf , %5.2lf) ", rmin[l+1], rmax[l+1]);
 	    printf(" z = +/- %5.2lf ", b->GetDZ());
 	    printf(" #lad = %d \n", nlad[l+1]);

	  }
	}
      }
    }
  }

}


//______________________________________________________________________
void DrawMaterialBudget_inPhi(const char *geofile = "geometry.root",
			      Int_t lay = -1, Bool_t fromGDML = 0)
{
  //
  // Function to compute material budget as a function of phi
  // for layer lay (all layers and pipe if lay=-1). geofile is the
  // geometry file name. If fromGDML is true, use a GDML file, else
  // a standard geometry.root file.
  // Cleaned up and simplified - M.Sitta 18 Nov 2014
  //

  Double_t rmin[8], rmax[8], zPos[8];
  Int_t nlad[8];

  ComputeGeometricalParameters(geofile, rmin, rmax, zPos, nlad, fromGDML);

  Int_t n = 100000; //testtracks
  // Test Get material ?
  Double_t mparam[7]={0.,0.,0.,0.,0.};
  Double_t point1[3],point2[3];

  TH2F *xOvsPhi[8];
  Int_t ls = 0, le = 8;
  if (lay != -1) {
    ls = lay+1;
    le = lay+2;
  }

  for(Int_t i=ls; i<le; i++) {
    Double_t phiMax;
    if (i == 0) // PIPE doesn't have staves
      phiMax = TMath::TwoPi()/4.;
    else
      phiMax = TMath::TwoPi()/nlad[i]*5.; // show approx 5 ladders
    
//    xOvsPhi[i] = new TH2F("", "", 100, 0, phiMax, 100, 0.2, 0.8);
    if (i < 4)
      xOvsPhi[i] = new TH2F("", "", 100, 0, phiMax, 100, 0.0, 1.2);
    else
      xOvsPhi[i] = new TH2F("", "", 100, 0, phiMax, 100, 0.2, 2.2);

    for (Int_t it=0; it<n; it++) {
      Double_t phi = phiMax*gRandom->Rndm();
      Double_t z = zPos[i];
      point1[0] = rmin[i]*TMath::Cos(phi);
      point1[1] = rmin[i]*TMath::Sin(phi);
      point1[2] = z;
      point2[0] = rmax[i]*TMath::Cos(phi);
      point2[1] = rmax[i]*TMath::Sin(phi);
      point2[2] = z;
      AliTracker::MeanMaterialBudget(point1,point2,mparam);
      if (mparam[1] < 100)  // don't save fakes due to errors
	xOvsPhi[i]->Fill(phi,mparam[1]*100); //fxOverX0Layer
      if (!(it%10000)) cout << "layer" << i-1 << " : " << mparam[1]*100
			    << " r=(" <<rmin[i] << "," << rmax[i] << ")"
			    << " phi=" << phi <<endl;
    }

  }

  if (lay==-1) {
    TCanvas *c1 = new TCanvas("c1","Material Budget",700,800);
    c1->Divide(2,4);
    for(Int_t i=0; i<8; i++) {
      c1->cd(i+1);
      if (i>0) 
	xOvsPhi[i]->SetTitle(Form("Layer %d",i-1));
      else
	xOvsPhi[i]->SetTitle(Form("Beampipe"));
      xOvsPhi[i]->GetXaxis()->SetTitle("phi (rad)");
      xOvsPhi[i]->GetYaxis()->SetTitle("X/X_{0} (%)");
      xOvsPhi[i]->SetStats(0);
      xOvsPhi[i]->Draw("col");
    }
  } else {
    TCanvas *c1 = new TCanvas("c1","Material Budget");
    Int_t i = lay+1;
    xOvsPhi[i]->SetTitle(Form("Layer %d",lay));
    xOvsPhi[i]->GetXaxis()->SetTitle("phi (rad)");
    xOvsPhi[i]->GetYaxis()->SetTitle("X/X_{0} (%)");
    xOvsPhi[i]->SetStats(1111111);
    xOvsPhi[i]->Draw("col");
  }

}


//______________________________________________________________________
void DrawMaterialBudget_EtaVsPhi(const char *geofile = "geometry.root",
				 Int_t lay = -1, Bool_t fromGDML = 0)
{
  //
  // Function to compute material budget as a function of eta and phi
  // in eta +/- 1 for layer lay (all layers and pipe if lay=-1).
  // geofile is the geometry file name. If fromGDML is true, use a
  // GDML file, else a standard geometry.root file.
  // Cleaned up and simplified - M.Sitta 20 Nov 2014
  //

  Double_t rmin[10], rmax[10], zPos[10]; // zPos not used but needed for call
  Int_t nlad[10];

  ComputeGeometricalParameters(geofile, rmin, rmax, zPos, nlad, fromGDML);

  rmin[8] = rmin[1];
  rmax[8] = rmax[3];
  rmin[9] = rmin[4];
  rmax[9] = rmax[7];

  Int_t n = 100000; //testtracks
  // Test Get material ?
  Double_t mparam[7]={0.,0.,0.,0.,0.};
  Double_t point1[3],point2[3];

  TH2F *xOverX0[10];
  TH2F *nParticles[10];
  Int_t ls = 0, le = 10;
  if (lay != -1) {
    ls = lay+1;
    le = lay+2;
  }

  for(Int_t i=ls; i<le; i++) {
    Double_t phiMax;
    if (i == 0) // PIPE doesn't have staves
      phiMax = TMath::TwoPi()/4.;
    else if (i == 8) // Mean value of layer 0 to 2
      phiMax = TMath::TwoPi()/(0.5*(nlad[1]+nlad[3]))*5.;
    else if (i == 9) // Mean value of layer 3 to 6
      phiMax = TMath::TwoPi()/(0.5*(nlad[4]+nlad[7]))*5.;
    else
      phiMax = TMath::TwoPi()/nlad[i]*5.; // show approx 5 ladders

    xOverX0[i]    = new TH2F("", "", 100, -1., 1., 100, 0., phiMax);
    nParticles[i] = new TH2F("", "", 100, -1., 1., 100, 0., phiMax);

    for (Int_t it=0; it<n; it++) {
      Double_t phi = phiMax*gRandom->Rndm();
      Double_t eta = gRandom->Rndm()*2 - 1.; // +/- 1 eta
      Double_t theta = TMath::ATan(TMath::Exp(-eta))*2;
      point1[0] = rmin[i]*TMath::Cos(phi);
      point1[1] = rmin[i]*TMath::Sin(phi);
      point1[2] = rmin[i]/TMath::Tan(theta);
      point2[0] = rmax[i]*TMath::Cos(phi);
      point2[1] = rmax[i]*TMath::Sin(phi);
      point2[2] = rmax[i]/TMath::Tan(theta);

      AliTracker::MeanMaterialBudget(point1,point2,mparam);
      if (mparam[1] < 100) { // don't save fakes due to errors
	xOverX0[i]->Fill(eta,phi,mparam[1]*100); //fxOverX0Layer
	nParticles[i]->Fill(eta,phi,1.);
      }
      if (!(it%10000)) cout << "layer" << i-1 << " : " << mparam[1]*100
			    << " r=(" <<rmin[i] << "," << rmax[i] << ")"
			    << " phi=" << phi << " theta=" << theta <<endl;
    }

    // normalization to number of particles
    for (Int_t ix=1; ix<=nParticles[i]->GetNbinsX(); ix++) {
      for (Int_t iy=1; iy<=nParticles[i]->GetNbinsY(); iy++) {
	if (nParticles[i]->GetBinContent(ix,iy) > 0) 
	  xOverX0[i]->SetBinContent(ix,iy,xOverX0[i]->GetBinContent(ix,iy)/nParticles[i]->GetBinContent(ix,iy));
      }
    }
  }
  
  if (lay==-1) {
    TCanvas *c1 = new TCanvas("c1","Material Budget",750,900);
    c1->Divide(2,5);
    for(Int_t i=0; i<10; i++) {
      c1->cd(i+1);
      if (i==0) 
	xOverX0[i]->SetTitle(Form("Beampipe"));
      else if (i==8)
	xOverX0[i]->SetTitle(Form("Layer 0 to 2"));
      else if (i==9)
	xOverX0[i]->SetTitle(Form("Layer 3 to 6"));
      else
	xOverX0[i]->SetTitle(Form("Layer %d",i-1));
      
      
      xOverX0[i]->SetStats(0);
      xOverX0[i]->GetXaxis()->SetTitle("pseudorapidity #eta ");
      xOverX0[i]->GetYaxis()->SetTitle("#phi (rad)");
      xOverX0[i]->GetZaxis()->SetTitle("X/X_{0} (%)");
      xOverX0[i]->Draw("colz");
    }
  } else {
    TCanvas *c1 = new TCanvas("c1","Material Budget");
    Int_t i = lay+1;
    xOverX0[i]->SetTitle(Form("Layer %d",lay));
    xOverX0[i]->SetStats(0);
    xOverX0[i]->GetXaxis()->SetTitle("pseudorapidity #eta ");
    xOverX0[i]->GetYaxis()->SetTitle("#phi (rad)");
    xOverX0[i]->GetZaxis()->SetTitle("X/X_{0} (%)");
    xOverX0[i]->Draw("colz");
  }

}
 GetMaterialBudget.C:1
 GetMaterialBudget.C:2
 GetMaterialBudget.C:3
 GetMaterialBudget.C:4
 GetMaterialBudget.C:5
 GetMaterialBudget.C:6
 GetMaterialBudget.C:7
 GetMaterialBudget.C:8
 GetMaterialBudget.C:9
 GetMaterialBudget.C:10
 GetMaterialBudget.C:11
 GetMaterialBudget.C:12
 GetMaterialBudget.C:13
 GetMaterialBudget.C:14
 GetMaterialBudget.C:15
 GetMaterialBudget.C:16
 GetMaterialBudget.C:17
 GetMaterialBudget.C:18
 GetMaterialBudget.C:19
 GetMaterialBudget.C:20
 GetMaterialBudget.C:21
 GetMaterialBudget.C:22
 GetMaterialBudget.C:23
 GetMaterialBudget.C:24
 GetMaterialBudget.C:25
 GetMaterialBudget.C:26
 GetMaterialBudget.C:27
 GetMaterialBudget.C:28
 GetMaterialBudget.C:29
 GetMaterialBudget.C:30
 GetMaterialBudget.C:31
 GetMaterialBudget.C:32
 GetMaterialBudget.C:33
 GetMaterialBudget.C:34
 GetMaterialBudget.C:35
 GetMaterialBudget.C:36
 GetMaterialBudget.C:37
 GetMaterialBudget.C:38
 GetMaterialBudget.C:39
 GetMaterialBudget.C:40
 GetMaterialBudget.C:41
 GetMaterialBudget.C:42
 GetMaterialBudget.C:43
 GetMaterialBudget.C:44
 GetMaterialBudget.C:45
 GetMaterialBudget.C:46
 GetMaterialBudget.C:47
 GetMaterialBudget.C:48
 GetMaterialBudget.C:49
 GetMaterialBudget.C:50
 GetMaterialBudget.C:51
 GetMaterialBudget.C:52
 GetMaterialBudget.C:53
 GetMaterialBudget.C:54
 GetMaterialBudget.C:55
 GetMaterialBudget.C:56
 GetMaterialBudget.C:57
 GetMaterialBudget.C:58
 GetMaterialBudget.C:59
 GetMaterialBudget.C:60
 GetMaterialBudget.C:61
 GetMaterialBudget.C:62
 GetMaterialBudget.C:63
 GetMaterialBudget.C:64
 GetMaterialBudget.C:65
 GetMaterialBudget.C:66
 GetMaterialBudget.C:67
 GetMaterialBudget.C:68
 GetMaterialBudget.C:69
 GetMaterialBudget.C:70
 GetMaterialBudget.C:71
 GetMaterialBudget.C:72
 GetMaterialBudget.C:73
 GetMaterialBudget.C:74
 GetMaterialBudget.C:75
 GetMaterialBudget.C:76
 GetMaterialBudget.C:77
 GetMaterialBudget.C:78
 GetMaterialBudget.C:79
 GetMaterialBudget.C:80
 GetMaterialBudget.C:81
 GetMaterialBudget.C:82
 GetMaterialBudget.C:83
 GetMaterialBudget.C:84
 GetMaterialBudget.C:85
 GetMaterialBudget.C:86
 GetMaterialBudget.C:87
 GetMaterialBudget.C:88
 GetMaterialBudget.C:89
 GetMaterialBudget.C:90
 GetMaterialBudget.C:91
 GetMaterialBudget.C:92
 GetMaterialBudget.C:93
 GetMaterialBudget.C:94
 GetMaterialBudget.C:95
 GetMaterialBudget.C:96
 GetMaterialBudget.C:97
 GetMaterialBudget.C:98
 GetMaterialBudget.C:99
 GetMaterialBudget.C:100
 GetMaterialBudget.C:101
 GetMaterialBudget.C:102
 GetMaterialBudget.C:103
 GetMaterialBudget.C:104
 GetMaterialBudget.C:105
 GetMaterialBudget.C:106
 GetMaterialBudget.C:107
 GetMaterialBudget.C:108
 GetMaterialBudget.C:109
 GetMaterialBudget.C:110
 GetMaterialBudget.C:111
 GetMaterialBudget.C:112
 GetMaterialBudget.C:113
 GetMaterialBudget.C:114
 GetMaterialBudget.C:115
 GetMaterialBudget.C:116
 GetMaterialBudget.C:117
 GetMaterialBudget.C:118
 GetMaterialBudget.C:119
 GetMaterialBudget.C:120
 GetMaterialBudget.C:121
 GetMaterialBudget.C:122
 GetMaterialBudget.C:123
 GetMaterialBudget.C:124
 GetMaterialBudget.C:125
 GetMaterialBudget.C:126
 GetMaterialBudget.C:127
 GetMaterialBudget.C:128
 GetMaterialBudget.C:129
 GetMaterialBudget.C:130
 GetMaterialBudget.C:131
 GetMaterialBudget.C:132
 GetMaterialBudget.C:133
 GetMaterialBudget.C:134
 GetMaterialBudget.C:135
 GetMaterialBudget.C:136
 GetMaterialBudget.C:137
 GetMaterialBudget.C:138
 GetMaterialBudget.C:139
 GetMaterialBudget.C:140
 GetMaterialBudget.C:141
 GetMaterialBudget.C:142
 GetMaterialBudget.C:143
 GetMaterialBudget.C:144
 GetMaterialBudget.C:145
 GetMaterialBudget.C:146
 GetMaterialBudget.C:147
 GetMaterialBudget.C:148
 GetMaterialBudget.C:149
 GetMaterialBudget.C:150
 GetMaterialBudget.C:151
 GetMaterialBudget.C:152
 GetMaterialBudget.C:153
 GetMaterialBudget.C:154
 GetMaterialBudget.C:155
 GetMaterialBudget.C:156
 GetMaterialBudget.C:157
 GetMaterialBudget.C:158
 GetMaterialBudget.C:159
 GetMaterialBudget.C:160
 GetMaterialBudget.C:161
 GetMaterialBudget.C:162
 GetMaterialBudget.C:163
 GetMaterialBudget.C:164
 GetMaterialBudget.C:165
 GetMaterialBudget.C:166
 GetMaterialBudget.C:167
 GetMaterialBudget.C:168
 GetMaterialBudget.C:169
 GetMaterialBudget.C:170
 GetMaterialBudget.C:171
 GetMaterialBudget.C:172
 GetMaterialBudget.C:173
 GetMaterialBudget.C:174
 GetMaterialBudget.C:175
 GetMaterialBudget.C:176
 GetMaterialBudget.C:177
 GetMaterialBudget.C:178
 GetMaterialBudget.C:179
 GetMaterialBudget.C:180
 GetMaterialBudget.C:181
 GetMaterialBudget.C:182
 GetMaterialBudget.C:183
 GetMaterialBudget.C:184
 GetMaterialBudget.C:185
 GetMaterialBudget.C:186
 GetMaterialBudget.C:187
 GetMaterialBudget.C:188
 GetMaterialBudget.C:189
 GetMaterialBudget.C:190
 GetMaterialBudget.C:191
 GetMaterialBudget.C:192
 GetMaterialBudget.C:193
 GetMaterialBudget.C:194
 GetMaterialBudget.C:195
 GetMaterialBudget.C:196
 GetMaterialBudget.C:197
 GetMaterialBudget.C:198
 GetMaterialBudget.C:199
 GetMaterialBudget.C:200
 GetMaterialBudget.C:201
 GetMaterialBudget.C:202
 GetMaterialBudget.C:203
 GetMaterialBudget.C:204
 GetMaterialBudget.C:205
 GetMaterialBudget.C:206
 GetMaterialBudget.C:207
 GetMaterialBudget.C:208
 GetMaterialBudget.C:209
 GetMaterialBudget.C:210
 GetMaterialBudget.C:211
 GetMaterialBudget.C:212
 GetMaterialBudget.C:213
 GetMaterialBudget.C:214
 GetMaterialBudget.C:215
 GetMaterialBudget.C:216
 GetMaterialBudget.C:217
 GetMaterialBudget.C:218
 GetMaterialBudget.C:219
 GetMaterialBudget.C:220
 GetMaterialBudget.C:221
 GetMaterialBudget.C:222
 GetMaterialBudget.C:223
 GetMaterialBudget.C:224
 GetMaterialBudget.C:225
 GetMaterialBudget.C:226
 GetMaterialBudget.C:227
 GetMaterialBudget.C:228
 GetMaterialBudget.C:229
 GetMaterialBudget.C:230
 GetMaterialBudget.C:231
 GetMaterialBudget.C:232
 GetMaterialBudget.C:233
 GetMaterialBudget.C:234
 GetMaterialBudget.C:235
 GetMaterialBudget.C:236
 GetMaterialBudget.C:237
 GetMaterialBudget.C:238
 GetMaterialBudget.C:239
 GetMaterialBudget.C:240
 GetMaterialBudget.C:241
 GetMaterialBudget.C:242
 GetMaterialBudget.C:243
 GetMaterialBudget.C:244
 GetMaterialBudget.C:245
 GetMaterialBudget.C:246
 GetMaterialBudget.C:247
 GetMaterialBudget.C:248
 GetMaterialBudget.C:249
 GetMaterialBudget.C:250
 GetMaterialBudget.C:251
 GetMaterialBudget.C:252
 GetMaterialBudget.C:253
 GetMaterialBudget.C:254
 GetMaterialBudget.C:255
 GetMaterialBudget.C:256
 GetMaterialBudget.C:257
 GetMaterialBudget.C:258
 GetMaterialBudget.C:259
 GetMaterialBudget.C:260
 GetMaterialBudget.C:261
 GetMaterialBudget.C:262
 GetMaterialBudget.C:263
 GetMaterialBudget.C:264
 GetMaterialBudget.C:265
 GetMaterialBudget.C:266
 GetMaterialBudget.C:267
 GetMaterialBudget.C:268
 GetMaterialBudget.C:269
 GetMaterialBudget.C:270
 GetMaterialBudget.C:271
 GetMaterialBudget.C:272
 GetMaterialBudget.C:273
 GetMaterialBudget.C:274
 GetMaterialBudget.C:275
 GetMaterialBudget.C:276
 GetMaterialBudget.C:277
 GetMaterialBudget.C:278
 GetMaterialBudget.C:279
 GetMaterialBudget.C:280
 GetMaterialBudget.C:281
 GetMaterialBudget.C:282
 GetMaterialBudget.C:283
 GetMaterialBudget.C:284
 GetMaterialBudget.C:285
 GetMaterialBudget.C:286
 GetMaterialBudget.C:287
 GetMaterialBudget.C:288
 GetMaterialBudget.C:289
 GetMaterialBudget.C:290
 GetMaterialBudget.C:291
 GetMaterialBudget.C:292
 GetMaterialBudget.C:293
 GetMaterialBudget.C:294
 GetMaterialBudget.C:295
 GetMaterialBudget.C:296
 GetMaterialBudget.C:297
 GetMaterialBudget.C:298
 GetMaterialBudget.C:299
 GetMaterialBudget.C:300
 GetMaterialBudget.C:301
 GetMaterialBudget.C:302
 GetMaterialBudget.C:303
 GetMaterialBudget.C:304
 GetMaterialBudget.C:305
 GetMaterialBudget.C:306
 GetMaterialBudget.C:307
 GetMaterialBudget.C:308
 GetMaterialBudget.C:309
 GetMaterialBudget.C:310
 GetMaterialBudget.C:311
 GetMaterialBudget.C:312
 GetMaterialBudget.C:313
 GetMaterialBudget.C:314
 GetMaterialBudget.C:315
 GetMaterialBudget.C:316
 GetMaterialBudget.C:317
 GetMaterialBudget.C:318
 GetMaterialBudget.C:319
 GetMaterialBudget.C:320
 GetMaterialBudget.C:321
 GetMaterialBudget.C:322
 GetMaterialBudget.C:323
 GetMaterialBudget.C:324
 GetMaterialBudget.C:325
 GetMaterialBudget.C:326
 GetMaterialBudget.C:327
 GetMaterialBudget.C:328
 GetMaterialBudget.C:329
 GetMaterialBudget.C:330
 GetMaterialBudget.C:331
 GetMaterialBudget.C:332
 GetMaterialBudget.C:333
 GetMaterialBudget.C:334
 GetMaterialBudget.C:335
 GetMaterialBudget.C:336
 GetMaterialBudget.C:337
 GetMaterialBudget.C:338
 GetMaterialBudget.C:339
 GetMaterialBudget.C:340
 GetMaterialBudget.C:341
 GetMaterialBudget.C:342
 GetMaterialBudget.C:343
 GetMaterialBudget.C:344
 GetMaterialBudget.C:345
 GetMaterialBudget.C:346
 GetMaterialBudget.C:347
 GetMaterialBudget.C:348
 GetMaterialBudget.C:349
 GetMaterialBudget.C:350
 GetMaterialBudget.C:351
 GetMaterialBudget.C:352
 GetMaterialBudget.C:353
 GetMaterialBudget.C:354
 GetMaterialBudget.C:355
 GetMaterialBudget.C:356
 GetMaterialBudget.C:357
 GetMaterialBudget.C:358
 GetMaterialBudget.C:359
 GetMaterialBudget.C:360
 GetMaterialBudget.C:361
 GetMaterialBudget.C:362
 GetMaterialBudget.C:363
 GetMaterialBudget.C:364
 GetMaterialBudget.C:365
 GetMaterialBudget.C:366
 GetMaterialBudget.C:367
 GetMaterialBudget.C:368
 GetMaterialBudget.C:369
 GetMaterialBudget.C:370
 GetMaterialBudget.C:371
 GetMaterialBudget.C:372
 GetMaterialBudget.C:373
 GetMaterialBudget.C:374
 GetMaterialBudget.C:375
 GetMaterialBudget.C:376
 GetMaterialBudget.C:377
 GetMaterialBudget.C:378
 GetMaterialBudget.C:379
 GetMaterialBudget.C:380
 GetMaterialBudget.C:381
 GetMaterialBudget.C:382
 GetMaterialBudget.C:383
 GetMaterialBudget.C:384
 GetMaterialBudget.C:385
 GetMaterialBudget.C:386
 GetMaterialBudget.C:387
 GetMaterialBudget.C:388
 GetMaterialBudget.C:389
 GetMaterialBudget.C:390
 GetMaterialBudget.C:391
 GetMaterialBudget.C:392
 GetMaterialBudget.C:393
 GetMaterialBudget.C:394
 GetMaterialBudget.C:395
 GetMaterialBudget.C:396
 GetMaterialBudget.C:397
 GetMaterialBudget.C:398
 GetMaterialBudget.C:399
 GetMaterialBudget.C:400
 GetMaterialBudget.C:401
 GetMaterialBudget.C:402
 GetMaterialBudget.C:403
 GetMaterialBudget.C:404
 GetMaterialBudget.C:405
 GetMaterialBudget.C:406
 GetMaterialBudget.C:407
 GetMaterialBudget.C:408
 GetMaterialBudget.C:409
 GetMaterialBudget.C:410
 GetMaterialBudget.C:411
 GetMaterialBudget.C:412
 GetMaterialBudget.C:413
 GetMaterialBudget.C:414
 GetMaterialBudget.C:415
 GetMaterialBudget.C:416
 GetMaterialBudget.C:417
 GetMaterialBudget.C:418
 GetMaterialBudget.C:419
 GetMaterialBudget.C:420
 GetMaterialBudget.C:421
 GetMaterialBudget.C:422
 GetMaterialBudget.C:423
 GetMaterialBudget.C:424
 GetMaterialBudget.C:425
 GetMaterialBudget.C:426
 GetMaterialBudget.C:427
 GetMaterialBudget.C:428
 GetMaterialBudget.C:429
 GetMaterialBudget.C:430
 GetMaterialBudget.C:431
 GetMaterialBudget.C:432
 GetMaterialBudget.C:433
 GetMaterialBudget.C:434
 GetMaterialBudget.C:435
 GetMaterialBudget.C:436
 GetMaterialBudget.C:437
 GetMaterialBudget.C:438
 GetMaterialBudget.C:439
 GetMaterialBudget.C:440
 GetMaterialBudget.C:441
 GetMaterialBudget.C:442
 GetMaterialBudget.C:443
 GetMaterialBudget.C:444
 GetMaterialBudget.C:445
 GetMaterialBudget.C:446
 GetMaterialBudget.C:447
 GetMaterialBudget.C:448
 GetMaterialBudget.C:449
 GetMaterialBudget.C:450
 GetMaterialBudget.C:451
 GetMaterialBudget.C:452
 GetMaterialBudget.C:453
 GetMaterialBudget.C:454
 GetMaterialBudget.C:455
 GetMaterialBudget.C:456
 GetMaterialBudget.C:457
 GetMaterialBudget.C:458
 GetMaterialBudget.C:459
 GetMaterialBudget.C:460
 GetMaterialBudget.C:461
 GetMaterialBudget.C:462
 GetMaterialBudget.C:463
 GetMaterialBudget.C:464
 GetMaterialBudget.C:465
 GetMaterialBudget.C:466
 GetMaterialBudget.C:467
 GetMaterialBudget.C:468
 GetMaterialBudget.C:469
 GetMaterialBudget.C:470
 GetMaterialBudget.C:471
 GetMaterialBudget.C:472
 GetMaterialBudget.C:473
 GetMaterialBudget.C:474
 GetMaterialBudget.C:475
 GetMaterialBudget.C:476
 GetMaterialBudget.C:477
 GetMaterialBudget.C:478
 GetMaterialBudget.C:479
 GetMaterialBudget.C:480
 GetMaterialBudget.C:481
 GetMaterialBudget.C:482
 GetMaterialBudget.C:483
 GetMaterialBudget.C:484
 GetMaterialBudget.C:485
 GetMaterialBudget.C:486
 GetMaterialBudget.C:487
 GetMaterialBudget.C:488
 GetMaterialBudget.C:489
 GetMaterialBudget.C:490
 GetMaterialBudget.C:491
 GetMaterialBudget.C:492
 GetMaterialBudget.C:493
 GetMaterialBudget.C:494
 GetMaterialBudget.C:495
 GetMaterialBudget.C:496
 GetMaterialBudget.C:497
 GetMaterialBudget.C:498
 GetMaterialBudget.C:499
 GetMaterialBudget.C:500
 GetMaterialBudget.C:501
 GetMaterialBudget.C:502
 GetMaterialBudget.C:503
 GetMaterialBudget.C:504
 GetMaterialBudget.C:505
 GetMaterialBudget.C:506
 GetMaterialBudget.C:507
 GetMaterialBudget.C:508
 GetMaterialBudget.C:509
 GetMaterialBudget.C:510
 GetMaterialBudget.C:511
 GetMaterialBudget.C:512
 GetMaterialBudget.C:513
 GetMaterialBudget.C:514
 GetMaterialBudget.C:515
 GetMaterialBudget.C:516
 GetMaterialBudget.C:517
 GetMaterialBudget.C:518
 GetMaterialBudget.C:519
 GetMaterialBudget.C:520
 GetMaterialBudget.C:521
 GetMaterialBudget.C:522
 GetMaterialBudget.C:523
 GetMaterialBudget.C:524
 GetMaterialBudget.C:525
 GetMaterialBudget.C:526
 GetMaterialBudget.C:527
 GetMaterialBudget.C:528
 GetMaterialBudget.C:529
 GetMaterialBudget.C:530
 GetMaterialBudget.C:531
 GetMaterialBudget.C:532
 GetMaterialBudget.C:533
 GetMaterialBudget.C:534
 GetMaterialBudget.C:535
 GetMaterialBudget.C:536
 GetMaterialBudget.C:537
 GetMaterialBudget.C:538
 GetMaterialBudget.C:539
 GetMaterialBudget.C:540
 GetMaterialBudget.C:541
 GetMaterialBudget.C:542
 GetMaterialBudget.C:543
 GetMaterialBudget.C:544
 GetMaterialBudget.C:545
 GetMaterialBudget.C:546
 GetMaterialBudget.C:547
 GetMaterialBudget.C:548
 GetMaterialBudget.C:549
 GetMaterialBudget.C:550
 GetMaterialBudget.C:551
 GetMaterialBudget.C:552
 GetMaterialBudget.C:553
 GetMaterialBudget.C:554
 GetMaterialBudget.C:555
 GetMaterialBudget.C:556
 GetMaterialBudget.C:557
 GetMaterialBudget.C:558
 GetMaterialBudget.C:559
 GetMaterialBudget.C:560
 GetMaterialBudget.C:561
 GetMaterialBudget.C:562
 GetMaterialBudget.C:563
 GetMaterialBudget.C:564
 GetMaterialBudget.C:565
 GetMaterialBudget.C:566
 GetMaterialBudget.C:567
 GetMaterialBudget.C:568
 GetMaterialBudget.C:569
 GetMaterialBudget.C:570
 GetMaterialBudget.C:571
 GetMaterialBudget.C:572
 GetMaterialBudget.C:573
 GetMaterialBudget.C:574
 GetMaterialBudget.C:575
 GetMaterialBudget.C:576
 GetMaterialBudget.C:577
 GetMaterialBudget.C:578
 GetMaterialBudget.C:579
 GetMaterialBudget.C:580
 GetMaterialBudget.C:581
 GetMaterialBudget.C:582
 GetMaterialBudget.C:583
 GetMaterialBudget.C:584
 GetMaterialBudget.C:585
 GetMaterialBudget.C:586
 GetMaterialBudget.C:587
 GetMaterialBudget.C:588
 GetMaterialBudget.C:589
 GetMaterialBudget.C:590
 GetMaterialBudget.C:591
 GetMaterialBudget.C:592
 GetMaterialBudget.C:593
 GetMaterialBudget.C:594
 GetMaterialBudget.C:595
 GetMaterialBudget.C:596
 GetMaterialBudget.C:597
 GetMaterialBudget.C:598
 GetMaterialBudget.C:599
 GetMaterialBudget.C:600
 GetMaterialBudget.C:601
 GetMaterialBudget.C:602
 GetMaterialBudget.C:603
 GetMaterialBudget.C:604
 GetMaterialBudget.C:605
 GetMaterialBudget.C:606
 GetMaterialBudget.C:607
 GetMaterialBudget.C:608
 GetMaterialBudget.C:609
 GetMaterialBudget.C:610
 GetMaterialBudget.C:611
 GetMaterialBudget.C:612
 GetMaterialBudget.C:613
 GetMaterialBudget.C:614
 GetMaterialBudget.C:615
 GetMaterialBudget.C:616
 GetMaterialBudget.C:617
 GetMaterialBudget.C:618
 GetMaterialBudget.C:619
 GetMaterialBudget.C:620
 GetMaterialBudget.C:621
 GetMaterialBudget.C:622
 GetMaterialBudget.C:623
 GetMaterialBudget.C:624
 GetMaterialBudget.C:625
 GetMaterialBudget.C:626
 GetMaterialBudget.C:627
 GetMaterialBudget.C:628
 GetMaterialBudget.C:629
 GetMaterialBudget.C:630
 GetMaterialBudget.C:631
 GetMaterialBudget.C:632
 GetMaterialBudget.C:633
 GetMaterialBudget.C:634
 GetMaterialBudget.C:635
 GetMaterialBudget.C:636
 GetMaterialBudget.C:637
 GetMaterialBudget.C:638
 GetMaterialBudget.C:639
 GetMaterialBudget.C:640
 GetMaterialBudget.C:641
 GetMaterialBudget.C:642
 GetMaterialBudget.C:643
 GetMaterialBudget.C:644
 GetMaterialBudget.C:645
 GetMaterialBudget.C:646
 GetMaterialBudget.C:647
 GetMaterialBudget.C:648
 GetMaterialBudget.C:649
 GetMaterialBudget.C:650
 GetMaterialBudget.C:651
 GetMaterialBudget.C:652
 GetMaterialBudget.C:653
 GetMaterialBudget.C:654
 GetMaterialBudget.C:655
 GetMaterialBudget.C:656
 GetMaterialBudget.C:657
 GetMaterialBudget.C:658
 GetMaterialBudget.C:659
 GetMaterialBudget.C:660
 GetMaterialBudget.C:661
 GetMaterialBudget.C:662
 GetMaterialBudget.C:663
 GetMaterialBudget.C:664
 GetMaterialBudget.C:665
 GetMaterialBudget.C:666
 GetMaterialBudget.C:667
 GetMaterialBudget.C:668
 GetMaterialBudget.C:669
 GetMaterialBudget.C:670
 GetMaterialBudget.C:671
 GetMaterialBudget.C:672
 GetMaterialBudget.C:673
 GetMaterialBudget.C:674
 GetMaterialBudget.C:675
 GetMaterialBudget.C:676
 GetMaterialBudget.C:677
 GetMaterialBudget.C:678
 GetMaterialBudget.C:679
 GetMaterialBudget.C:680
 GetMaterialBudget.C:681
 GetMaterialBudget.C:682
 GetMaterialBudget.C:683
 GetMaterialBudget.C:684
 GetMaterialBudget.C:685
 GetMaterialBudget.C:686
 GetMaterialBudget.C:687
 GetMaterialBudget.C:688
 GetMaterialBudget.C:689
 GetMaterialBudget.C:690
 GetMaterialBudget.C:691
 GetMaterialBudget.C:692
 GetMaterialBudget.C:693
 GetMaterialBudget.C:694
 GetMaterialBudget.C:695
 GetMaterialBudget.C:696
 GetMaterialBudget.C:697
 GetMaterialBudget.C:698
 GetMaterialBudget.C:699
 GetMaterialBudget.C:700
 GetMaterialBudget.C:701
 GetMaterialBudget.C:702
 GetMaterialBudget.C:703
 GetMaterialBudget.C:704
 GetMaterialBudget.C:705
 GetMaterialBudget.C:706
 GetMaterialBudget.C:707
 GetMaterialBudget.C:708
 GetMaterialBudget.C:709
 GetMaterialBudget.C:710
 GetMaterialBudget.C:711
 GetMaterialBudget.C:712
 GetMaterialBudget.C:713
 GetMaterialBudget.C:714
 GetMaterialBudget.C:715
 GetMaterialBudget.C:716
 GetMaterialBudget.C:717
 GetMaterialBudget.C:718
 GetMaterialBudget.C:719
 GetMaterialBudget.C:720
 GetMaterialBudget.C:721
 GetMaterialBudget.C:722
 GetMaterialBudget.C:723
 GetMaterialBudget.C:724
 GetMaterialBudget.C:725
 GetMaterialBudget.C:726
 GetMaterialBudget.C:727
 GetMaterialBudget.C:728
 GetMaterialBudget.C:729
 GetMaterialBudget.C:730
 GetMaterialBudget.C:731
 GetMaterialBudget.C:732
 GetMaterialBudget.C:733
 GetMaterialBudget.C:734
 GetMaterialBudget.C:735
 GetMaterialBudget.C:736
 GetMaterialBudget.C:737
 GetMaterialBudget.C:738
 GetMaterialBudget.C:739
 GetMaterialBudget.C:740
 GetMaterialBudget.C:741
 GetMaterialBudget.C:742
 GetMaterialBudget.C:743
 GetMaterialBudget.C:744
 GetMaterialBudget.C:745
 GetMaterialBudget.C:746
 GetMaterialBudget.C:747
 GetMaterialBudget.C:748
 GetMaterialBudget.C:749
 GetMaterialBudget.C:750
 GetMaterialBudget.C:751
 GetMaterialBudget.C:752
 GetMaterialBudget.C:753
 GetMaterialBudget.C:754
 GetMaterialBudget.C:755
 GetMaterialBudget.C:756
 GetMaterialBudget.C:757
 GetMaterialBudget.C:758
 GetMaterialBudget.C:759
 GetMaterialBudget.C:760
 GetMaterialBudget.C:761