Index: display/DelphesBranchElement.cc
===================================================================
--- display/DelphesBranchElement.cc	(revision b3c42d35a3d208abb67a92eaa6c45ac04965722f)
+++ display/DelphesBranchElement.cc	(revision 4d999a57410bd2e0f18efb7f6965504646a43c49)
@@ -0,0 +1,64 @@
+/*
+ *  Delphes: a framework for fast simulation of a generic collider experiment
+ *  Copyright (C) 2012-2014  Universite catholique de Louvain (UCL), Belgium
+ *  
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *  
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *  
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "display/DelphesBranchElement.h"
+
+// special case for calo towers
+template<> DelphesBranchElement<DelphesCaloData>::DelphesBranchElement(const char* name, const char*type, const enum EColor color):DelphesBranchBase(name, type, color) {
+      if(TString(type)=="tower") {
+        data_ = new DelphesCaloData(2);
+        data_->RefSliceInfo(0).Setup("ECAL", 0.1, kRed);
+        data_->RefSliceInfo(1).Setup("HCAL", 0.1, kBlue);
+        data_->IncDenyDestroy();
+      } else {
+        throw std::exception();
+      }
+    }
+template<> void DelphesBranchElement<DelphesCaloData>::Reset() { data_->ClearTowers(); }
+
+// special case for element lists
+template<> DelphesBranchElement<TEveElementList>::DelphesBranchElement(const char* name, const char*type, const enum EColor color):DelphesBranchBase(name, type, color) {
+      if(TString(type)=="vector" || TString(type)=="jet") {
+        data_ = new TEveElementList(name);
+        data_->SetMainColor(color_);
+      } else {
+        throw std::exception();
+      }
+    }
+template<> void DelphesBranchElement<TEveElementList>::Reset() { data_->DestroyElements(); }
+
+// special case for track lists
+template<> DelphesBranchElement<TEveTrackList>::DelphesBranchElement(const char* name, const char*type, const enum EColor color):DelphesBranchBase(name, type, color) {
+      if(TString(type)=="track") {
+        data_ = new TEveTrackList(name);
+        data_->SetMainColor(color_);
+        data_->SetMarkerColor(color_);
+        data_->SetMarkerStyle(kCircle);
+        data_->SetMarkerSize(0.5);
+      } else if(TString(type)=="photon") {
+        data_ = new TEveTrackList(name);
+        data_->SetMainColor(color_);
+        data_->SetMarkerColor(color_);
+        data_->SetMarkerStyle(kCircle);
+        data_->SetMarkerSize(0.5);
+      } else {
+        throw std::exception();
+      }
+    }
+template<> void DelphesBranchElement<TEveTrackList>::Reset() { data_->DestroyElements(); }
+
Index: display/DelphesBranchElement.h
===================================================================
--- display/DelphesBranchElement.h	(revision b3c42d35a3d208abb67a92eaa6c45ac04965722f)
+++ display/DelphesBranchElement.h	(revision 4d999a57410bd2e0f18efb7f6965504646a43c49)
@@ -31,6 +31,5 @@
 {
   public:
-    DelphesBranchBase():color_(kBlack) {}
-    DelphesBranchBase(const char* name, const char*type, const enum EColor color):name_(name),type_(type),color_(color) {}
+    DelphesBranchBase(const char* name="", const char*type="", const enum EColor color=kBlack):name_(name),type_(type),color_(color) {}
     virtual ~DelphesBranchBase() {};
     const char* GetName() const { return (const char*)name_; }
@@ -51,6 +50,7 @@
   public:
     // constructor
-    DelphesBranchElement():DelphesBranchBase() {}
-    DelphesBranchElement(const char* name, const char*type, const enum EColor color):DelphesBranchBase(name, type, color) {}
+    DelphesBranchElement(const char* name="", const char*type="", const enum EColor color=kBlack):DelphesBranchBase(name, type, color) {
+      throw std::exception();
+    }
 
     // destructor
@@ -61,5 +61,5 @@
 
     // resets the collection (before moving to the next event)
-    virtual void Reset() = 0;
+    virtual void Reset() {};
 
     // template class name
@@ -70,113 +70,19 @@
 };
 
+#if !defined(__CINT__) && !defined(__CLING__)
+
 // special case for calo towers
-template<> class DelphesBranchElement<DelphesCaloData>: public DelphesBranchBase
-{
-  public:
-    // constructor
-    DelphesBranchElement():DelphesBranchBase() {}
-    DelphesBranchElement(const char* name, const char*type, const enum EColor color):DelphesBranchBase(name, type, color) {
-      if(TString(type)=="tower") {
-        data_ = new DelphesCaloData(2);
-        data_->RefSliceInfo(0).Setup("ECAL", 0.1, kRed);
-        data_->RefSliceInfo(1).Setup("HCAL", 0.1, kBlue);
-        data_->IncDenyDestroy();
-      } else {
-        throw std::exception();
-      }
-    }
-
-    // destructor
-    virtual ~DelphesBranchElement() { delete data_; }
-
-    // get the container (ElementList, TrackList, or CaloData)
-    DelphesCaloData* GetContainer() { return data_; }
-
-    // resets the collection (before moving to the next event)
-    virtual void Reset() { data_->ClearTowers(); }
-
-    // template class name
-    virtual const char* GetClassName() { return data_->ClassName(); }
-
-  private:
-    DelphesCaloData* data_;
-};
-//template<> DelphesBranchElement<DelphesCaloData>::DelphesBranchElement(const char* name, const char*type, const enum EColor color);
-//template<> void DelphesBranchElement<DelphesCaloData>::Reset();
+template<> DelphesBranchElement<DelphesCaloData>::DelphesBranchElement(const char* name, const char*type, const enum EColor color);
+template<> void DelphesBranchElement<DelphesCaloData>::Reset();
 
 // special case for element lists
-template<> class DelphesBranchElement<TEveElementList>: public DelphesBranchBase
-{
-  public:
-    // constructor
-    DelphesBranchElement():DelphesBranchBase() {}
-    DelphesBranchElement(const char* name, const char*type, const enum EColor color):DelphesBranchBase(name, type, color) {
-      if(TString(type)=="vector" || TString(type)=="jet") {
-        data_ = new TEveElementList(name);
-        data_->SetMainColor(color_);
-      } else {
-        throw std::exception();
-      }
-    }
-
-    // destructor
-    virtual ~DelphesBranchElement() { delete data_; }
-
-    // get the container (ElementList, TrackList, or CaloData)
-    TEveElementList* GetContainer() { return data_; }
-
-    // resets the collection (before moving to the next event)
-    virtual void Reset() { data_->DestroyElements(); }
-
-    // template class name
-    virtual const char* GetClassName() { return data_->ClassName(); }
-
-  private:
-    TEveElementList* data_;
-};
-//template<> DelphesBranchElement<TEveElementList>::DelphesBranchElement(const char* name, const char*type, const enum EColor color);
-//template<> void DelphesBranchElement<TEveElementList>::Reset();
+template<> DelphesBranchElement<TEveElementList>::DelphesBranchElement(const char* name, const char*type, const enum EColor color);
+template<> void DelphesBranchElement<TEveElementList>::Reset();
 
 // special case for track lists
-template<> class DelphesBranchElement<TEveTrackList>: public DelphesBranchBase
-{
-  public:
-    // constructor
-    DelphesBranchElement():DelphesBranchBase() {}
-    DelphesBranchElement(const char* name, const char*type, const enum EColor color):DelphesBranchBase(name, type, color) {
-      if(TString(type)=="track") {
-        data_ = new TEveTrackList(name);
-        data_->SetMainColor(color_);
-        data_->SetMarkerColor(color_);
-        data_->SetMarkerStyle(kCircle);
-        data_->SetMarkerSize(0.5);
-      } else if(TString(type)=="photon") {
-        data_ = new TEveTrackList(name);
-        data_->SetMainColor(color_);
-        data_->SetMarkerColor(color_);
-        data_->SetMarkerStyle(kCircle);
-        data_->SetMarkerSize(0.5);
-      } else {
-        throw std::exception();
-      }
-    }
+template<> DelphesBranchElement<TEveTrackList>::DelphesBranchElement(const char* name, const char*type, const enum EColor color);
+template<> void DelphesBranchElement<TEveTrackList>::Reset();
 
-    // destructor
-    virtual ~DelphesBranchElement() { delete data_; }
-
-    // get the container (ElementList, TrackList, or CaloData)
-    TEveTrackList* GetContainer() { return data_; }
-
-    // resets the collection (before moving to the next event)
-    virtual void Reset() { data_->DestroyElements(); }
-
-    // template class name
-    virtual const char* GetClassName() { return data_->ClassName(); }
-
-  private:
-    TEveTrackList* data_;
-};
-//template<> DelphesBranchElement<TEveTrackList>::DelphesBranchElement(const char* name, const char*type, const enum EColor color);
-//template<> void DelphesBranchElement<TEveTrackList>::Reset();
+#endif // CINT, CLING
 
 #endif //DelphesBranchElement_h
Index: display/DisplayLinkDef.h
===================================================================
--- display/DisplayLinkDef.h	(revision b3c42d35a3d208abb67a92eaa6c45ac04965722f)
+++ display/DisplayLinkDef.h	(revision 4d999a57410bd2e0f18efb7f6965504646a43c49)
@@ -42,7 +42,7 @@
 #pragma link C++ class DelphesDisplay+;
 #pragma link C++ class DelphesCaloData+;
-#pragma link C++ class DelphesBranchElement<DelphesCaloData>;
-#pragma link C++ class DelphesBranchElement<TEveElementList>;
-#pragma link C++ class DelphesBranchElement<TEveTrackList>;
+#pragma link C++ class DelphesBranchElement<DelphesCaloData>-!;
+#pragma link C++ class DelphesBranchElement<TEveElementList>-!;
+#pragma link C++ class DelphesBranchElement<TEveTrackList>-!;
 
 #endif
Index: examples/geometry.C
===================================================================
--- examples/geometry.C	(revision b3c42d35a3d208abb67a92eaa6c45ac04965722f)
+++ examples/geometry.C	(revision 4d999a57410bd2e0f18efb7f6965504646a43c49)
@@ -19,5 +19,5 @@
 //#include "display/DelphesCaloData.h"
 //#include "display/DelphesDisplay.h"
-//#include "display/DelphesBranchElement.h"
+#include "../display/DelphesBranchElement.h"
 //#include "classes/DelphesClasses.h"
 #include "TF2.h"
@@ -62,4 +62,8 @@
 void load_event();
 void delphes_read();
+void delphes_read_towers(TClonesArray* data, DelphesBranchBase* element);
+void delphes_read_tracks(TClonesArray* data, DelphesBranchBase* element);
+void delphes_read_jets(TClonesArray* data, DelphesBranchBase* element);
+void delphes_read_vectors(TClonesArray* data, DelphesBranchBase* element);
 void readConfig(const char *configFile, const Delphes3DGeometry& det3D, std::vector<DelphesBranchBase*>& elements, std::vector<TClonesArray*>& arrays);
 
@@ -496,5 +500,5 @@
    DelphesBranchElement<TEveTrackList>* tlist;
    DelphesBranchElement<DelphesCaloData>* clist;
-   DelphesBranchElement<TEveTrackList>* elist;
+   DelphesBranchElement<TEveElementList>* elist;
    for(Int_t b = 0; b<nBranches; ++b) {
      TString input = branches[b*3].GetString();
@@ -503,7 +507,7 @@
      if(className=="Track") {
        if(input.Contains("eflow",TString::kIgnoreCase) || name.Contains("eflow",TString::kIgnoreCase)) continue; //no eflow
-       elist = new DelphesBranchElement<TEveTrackList>(name,"track",kBlue);
-       elements.push_back(elist);
-       TEveTrackPropagator *trkProp = elist->GetContainer()->GetPropagator();
+       tlist = new DelphesBranchElement<TEveTrackList>(name,"track",kBlue);
+       elements.push_back(tlist);
+       TEveTrackPropagator *trkProp = tlist->GetContainer()->GetPropagator();
        trkProp->SetMagField(0., 0., -tk_Bz);
        trkProp->SetMaxR(tk_radius);
@@ -622,7 +626,12 @@
    gDelphesDisplay->ImportGeomRhoZ(geometry);
    // find the first calo data and use that to initialize the calo display
-   for(std::vector<DelphesBranchBase*>::iterator data=gElements.begin();data<gElements.end();++Data) {
+   for(std::vector<DelphesBranchBase*>::iterator data=gElements.begin();data<gElements.end();++data) {
      if(TString((*data)->GetType())=="tower") {
-       TEveCalo3D *calo3d = new TEveCalo3D((*data)->GetContainer());
+//TODO: why do I have to split this in two lines??? seems a cint bug?
+       DelphesBranchElement<DelphesCaloData>* data_tmp = dynamic_cast<DelphesBranchElement<DelphesCaloData>*>(*data);
+       DelphesCaloData* container =  data_tmp->GetContainer();
+//       DelphesCaloData* container = dynamic_cast<DelphesBranchElement<DelphesCaloData>*>((*data))->GetContainer();
+       assert(container);
+       TEveCalo3D *calo3d = new TEveCalo3D(container);
        calo3d->SetBarrelRadius(gRadius);
        calo3d->SetEndCapPos(gHalfLength);
@@ -630,5 +639,5 @@
        gDelphesDisplay->ImportCaloRPhi(calo3d);
        gDelphesDisplay->ImportCaloRhoZ(calo3d);
-       TEveCaloLego *lego = new TEveCaloLego((*data)->GetContainer());
+       TEveCaloLego *lego = new TEveCaloLego(container);
        lego->InitMainTrans();
        lego->RefMainTrans().SetScale(TMath::TwoPi(), TMath::TwoPi(), TMath::Pi());
@@ -653,6 +662,6 @@
    // clear the previous event
    gEve->GetViewers()->DeleteAnnotations();
-   for(std::vector<DelphesBranchBase*>::iterator data=gElements.begin();data<gElements.end();++Data) {
-     (*data)->Reset()
+   for(std::vector<DelphesBranchBase*>::iterator data=gElements.begin();data<gElements.end();++data) {
+     (*data)->Reset();
    }
 
@@ -691,5 +700,5 @@
     TString type = (*element)->GetType();
     // keep the most generic track collection for the end
-    if(type=="track" && (*element)->GetClassName()=="Track" && nTracks=0) {
+    if(type=="track" && TString((*element)->GetClassName())=="Track" && nTracks==0) {
       data_tracks = data;
       element_tracks = element;
@@ -698,5 +707,4 @@
     }
     // branch on the element type
-    // TODO : I understand that we will have to cast the elements.
     if(type=="tower") delphes_read_towers(*data,*element);
     else if(type=="track" || type=="photon") delphes_read_tracks(*data,*element);
@@ -705,9 +713,10 @@
   }
   // finish whith what we consider to be the main track collection
-  if(nTracks>0) delphes_read_tracks(*data,(*element)->GetContainer());
-}
-
-void delphes_read_towers(TClonesArray* data, DelphesBranchElement<TEveElementList>* element) {
-  DelphesCaloData* container = element->GetContainer();
+  if(nTracks>0) delphes_read_tracks(*data,*element);
+}
+
+void delphes_read_towers(TClonesArray* data, DelphesBranchBase* element) {
+  DelphesCaloData* container = dynamic_cast<DelphesBranchElement<DelphesCaloData>*>(element)->GetContainer();
+  assert(container);
   // Loop over all towers
   TIter itTower(data);
@@ -722,6 +731,7 @@
 }
 
-void delphes_read_tracks(TClonesArray* data, DelphesBranchElement<TEveTrackList>* element) {
-  TEveTrackList* container = element->GetContainer();
+void delphes_read_tracks(TClonesArray* data, DelphesBranchBase* element) {
+  TEveTrackList* container = dynamic_cast<DelphesBranchElement<TEveTrackList>*>(element)->GetContainer();
+  assert(container);
   TString className = element->GetClassName();
   TIter itTrack(data);
@@ -741,5 +751,5 @@
       eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++));
       eveTrack->SetStdTitle();
-      eveTrack->SetAttLineAttMarker(gTrackList);
+      eveTrack->SetAttLineAttMarker(container);
       container->AddElement(eveTrack);
       eveTrack->SetLineColor(element->GetColor());
@@ -749,5 +759,5 @@
     // Loop over all electrons
     Electron *electron;
-    while((electron = (Electron *) itElectron.Next())) {
+    while((electron = (Electron *) itTrack.Next())) {
       TParticle pb(electron->Charge<0?11:-11, 1, 0, 0, 0, 0,
                    electron->P4().Px(), electron->P4().Py(),
@@ -758,5 +768,5 @@
       eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++));
       eveTrack->SetStdTitle();
-      eveTrack->SetAttLineAttMarker(gElectronList);
+      eveTrack->SetAttLineAttMarker(container);
       container->AddElement(eveTrack);
       eveTrack->SetLineColor(element->GetColor());
@@ -766,5 +776,5 @@
     // Loop over all muons
     Muon *muon;
-    while((muon = (Muon *) itMuon.Next())) {
+    while((muon = (Muon *) itTrack.Next())) {
       TParticle pb(muon->Charge<0?13:-13, 1, 0, 0, 0, 0,
                    muon->P4().Px(), muon->P4().Py(),
@@ -775,5 +785,5 @@
       eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++));
       eveTrack->SetStdTitle();
-      eveTrack->SetAttLineAttMarker(gMuonList);
+      eveTrack->SetAttLineAttMarker(container);
       container->AddElement(eveTrack);
       eveTrack->SetLineColor(element->GetColor());
@@ -783,5 +793,5 @@
     // Loop over all photons
     Photon *photon;
-    while((photon = (Photon *) itPhoton.Next())) {
+    while((photon = (Photon *) itTrack.Next())) {
       TParticle pb(22, 1, 0, 0, 0, 0,
                    photon->P4().Px(), photon->P4().Py(),
@@ -792,5 +802,5 @@
       eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++));
       eveTrack->SetStdTitle();
-      eveTrack->SetAttLineAttMarker(gPhotonList);
+      eveTrack->SetAttLineAttMarker(container);
       container->AddElement(eveTrack);
       eveTrack->SetLineColor(element->GetColor());
@@ -800,6 +810,7 @@
 }
 
-void delphes_read_jets(TClonesArray* data, DelphesBranchElement<TEveElementList>* element) {
-  TEveElementList* container = element->GetContainer();
+void delphes_read_jets(TClonesArray* data, DelphesBranchBase* element) {
+  TEveElementList* container = dynamic_cast<DelphesBranchElement<TEveElementList>*>(element)->GetContainer();
+  assert(container);
   TIter itJet(data);
   Jet *jet;
@@ -822,6 +833,7 @@
 }
 
-void delphes_read_vectors(TClonesArray* data, DelphesBranchElement<TEveElementList>* element) {
-  TEveElementList* container = element->GetContainer();
+void delphes_read_vectors(TClonesArray* data, DelphesBranchBase* element) {
+  TEveElementList* container = dynamic_cast<DelphesBranchElement<TEveElementList>*>(element)->GetContainer();
+  assert(container);
   TIter itMet(data);
   MissingET *MET;
