Index: examples/geometry.C
===================================================================
--- examples/geometry.C	(revision bf6ed573730dd56617b9e9b3f445fba10695b4c3)
+++ examples/geometry.C	(revision a0b6d15250596bd8a32e2dce51b0c9d8f2bf212c)
@@ -27,5 +27,8 @@
      ~Delphes3DGeometry() {}
 
-     void readFile(const char* filename);
+     void readFile(const char* filename, const char* ParticlePropagator="ParticlePropagator",
+                                         const char* TrackingEfficiency="ChargedHadronTrackingEfficiency",
+                                         const char* MuonEfficiency="MuonEfficiency",
+                                         const char* Calorimeters="Calorimeter");
 
      void setContingency(Double_t contingency) { contingency_ = contingency; }
@@ -57,4 +60,5 @@
      Double_t tk_radius_;
      Double_t tk_length_;
+     Double_t tk_etamax_;
      Double_t calo_endcap_etamax_;
      Double_t muonSystem_etamax_;
@@ -98,22 +102,47 @@
    tk_radius_ = 120.;
    tk_length_ = 150.;
+   tk_etamax_ = 3.0;
    calo_endcap_etamax_ = 2.6;
    muonSystem_etamax_  = 2.4;
 }
 
-void Delphes3DGeometry::readFile(const char *configFile) {
+void Delphes3DGeometry::readFile(const char *configFile,
+                                 const char* ParticlePropagator, const char* TrackingEfficiency,
+                                 const char* MuonEfficiency, const char* Calorimeters) {
 
    ExRootConfReader *confReader = new ExRootConfReader;
    confReader->ReadFile(configFile);
 
-   tk_radius_ = confReader->GetDouble("ParticlePropagator::Radius", 1.0)*100;		// tk_radius
-   tk_length_ = confReader->GetDouble("ParticlePropagator::HalfLength", 3.0)*100; 	// tk_length
-
-   TString muonEffFormula = confReader->GetString("MuonEfficiency::EfficiencyFormula","abs(eta)<2.0");
+   tk_radius_ = confReader->GetDouble(Form("%s::Radius",ParticlePropagator), 1.0)*100;		// tk_radius
+   tk_length_ = confReader->GetDouble(Form("%s::HalfLength",ParticlePropagator), 3.0)*100; 	// tk_length
+
+   {
+   TString tkEffFormula = confReader->GetString(Form("%s::EfficiencyFormula",TrackingEfficiency),"abs(eta)<3.0");
+   tkEffFormula.ReplaceAll("pt","x");
+   tkEffFormula.ReplaceAll("eta","y");
+   tkEffFormula.ReplaceAll("phi","0.");
+   TF2* tkEffFunction = new TF2("tkEff",tkEffFormula,0,1000,-10,10);
+   TH1F etaHisto("eta","eta",100,5.,-5.);
+   Double_t pt,eta;
+   for(int i=0;i<1000;++i) {
+     tkEffFunction->GetRandom2(pt,eta);
+     etaHisto.Fill(eta);
+   }
+   Int_t bin = -1;
+   bin = etaHisto.FindFirstBinAbove(0.5);
+   Double_t etamin = (bin>-1) ? etaHisto.GetBinLowEdge(bin) : -10.;
+   bin = etaHisto.FindLastBinAbove(0.5);
+   Double_t etamax = (bin>-1) ? etaHisto.GetBinLowEdge(bin+1) : -10.;
+   tk_etamax_ = TMath::Max(fabs(etamin),fabs(etamax)); 						// tk_etamax
+   delete tkEffFunction;
+   }
+
+   {
+   TString muonEffFormula = confReader->GetString(Form("%s::EfficiencyFormula",MuonEfficiency),"abs(eta)<2.0");
    muonEffFormula.ReplaceAll("pt","x");
    muonEffFormula.ReplaceAll("eta","y");
    muonEffFormula.ReplaceAll("phi","0.");
    TF2* muEffFunction = new TF2("muEff",muonEffFormula,0,1000,-10,10);
-   TH1F etaHisto("eta","eta",100,5.,-5.);
+   TH1F etaHisto("eta2","eta2",100,5.,-5.);
    Double_t pt,eta;
    for(int i=0;i<1000;++i) {
@@ -128,8 +157,9 @@
    muonSystem_etamax_ = TMath::Max(fabs(etamin),fabs(etamax));				// muonSystem_etamax
    delete muEffFunction;
+   }
        
    caloBinning_.clear();								// calo binning
    ExRootConfParam paramEtaBins, paramPhiBins;
-   ExRootConfParam param = confReader->GetParam("Calorimeter::EtaPhiBins");
+   ExRootConfParam param = confReader->GetParam(Form("%s::EtaPhiBins",Calorimeters));
    Int_t size = param.GetSize();
    for(int i = 0; i < size/2; ++i) {
@@ -140,6 +170,6 @@
    }
 
-   calo_endcap_etamax_ = TMath::Max(fabs(caloBinning_.begin()->first),fabs(caloBinning_.rbegin()->first)); // calo_endcap_etamax_
- 
+   if (size>0) calo_endcap_etamax_ = TMath::Max(fabs(caloBinning_.begin()->first),fabs(caloBinning_.rbegin()->first)); // calo_endcap_etamax_
+
    delete confReader;
 
@@ -157,5 +187,5 @@
    TGeoVolume *top = geom_->MakeBox("Delphes3DGeometry", vacuum_, 1500, 1500, 2300); // determine the size from what we know about the detector TODO
    addTracker(top);
-   addCalorimeters(top);
+   addCalorimeters(top); // TODO: allow for more than one calo
    addMuonDets(top);
    if (withTowers) {
@@ -165,4 +195,6 @@
 }
 
+//TODO: there should be a cut by two cones to limit the acceptance in eta
+//typically from ChargedHadronTrackingEfficiency 
 void Delphes3DGeometry::addTracker(TGeoVolume *top) {
    // tracker: a cylinder
@@ -311,5 +343,8 @@
 }
 
-void geometry(const char* filename = "delphes_card_CMS.tcl")
+void geometry(const char* filename = "delphes_card_CMS.tcl", const char* ParticlePropagator="ParticlePropagator",
+                                                             const char* TrackingEfficiency="ChargedHadronTrackingEfficiency",
+                                                             const char* MuonEfficiency="MuonEfficiency",
+                                                             const char* Calorimeters="Calorimeter") 
 {
    gSystem->Load("libGeom");
@@ -323,5 +358,5 @@
    // build the detector
    Delphes3DGeometry det3D;
-   det3D.readFile(filename);
+   det3D.readFile(filename,ParticlePropagator, TrackingEfficiency, MuonEfficiency, Calorimeters);
    top->AddNode(det3D.getDetector(true),1);
 
