Fork me on GitHub

Changeset 115298d in git for examples


Ignore:
Timestamp:
Oct 15, 2014, 2:09:13 AM (10 years ago)
Author:
Christophe Delaere <christophe.delaere@…>
Branches:
ImprovedOutputFile, Timing, dual_readout, llp, master
Children:
b3c42d3
Parents:
5bb66c9
Message:

Working classes for automatic parsing of branches

Slightly less elegant, but it works.
The code in geometry.C is able to call the new methods and classes but
doesn't use it yet.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • examples/geometry.C

    r5bb66c9 r115298d  
    1919//#include "display/DelphesCaloData.h"
    2020//#include "display/DelphesDisplay.h"
     21//#include "display/DelphesBranchElement.h"
    2122//#include "classes/DelphesClasses.h"
    2223#include "TF2.h"
     
    498499/******************************************************************************/
    499500
     501// function that parses the config to extract the branches of interest and prepare containers
     502void readConfig(const char *configFile, Delphes3DGeometry& det3D, std::vector<DelphesBranchBase*>& elements, std::vector<TClonesArray*>& arrays) {
     503   ExRootConfReader *confReader = new ExRootConfReader;
     504   confReader->ReadFile(configFile);
     505   Double_t tk_radius = det3D.getTrackerRadius();
     506   Double_t tk_length = det3D.getTrackerHalfLength();
     507   Double_t tk_Bz     = det3D.getBField();
     508   Double_t mu_radius = det3D.getDetectorRadius();
     509   Double_t mu_length = det3D.getDetectorHalfLength();
     510   TAxis*   etaAxis   = det3D.getCaloAxes().first;
     511   TAxis*   phiAxis   = det3D.getCaloAxes().second;
     512   ExRootConfParam branches = confReader->GetParam("TreeWriter::Branch");
     513   Int_t nBranches = branches.GetSize()/3;
     514   DelphesBranchElement<TEveTrackList>* tlist;
     515   DelphesBranchElement<DelphesCaloData>* clist;
     516   DelphesBranchElement<TEveTrackList>* elist;
     517   for(Int_t b = 0; b<nBranches; ++b) {
     518     TString input = branches[b*3].GetString();
     519     TString name = branches[b*3+1].GetString();
     520     TString className = branches[b*3+2].GetString();
     521     if(className=="Track") {
     522       if(input.Contains("eflow",TString::kIgnoreCase) || name.Contains("eflow",TString::kIgnoreCase)) continue; //no eflow
     523       elist = new DelphesBranchElement<TEveTrackList>(name,"track",kBlue);
     524       elements.push_back(elist);
     525       TEveTrackPropagator *trkProp = elist->GetContainer()->GetPropagator();
     526       trkProp->SetMagField(0., 0., -tk_Bz);
     527       trkProp->SetMaxR(tk_radius);
     528       trkProp->SetMaxZ(tk_length);
     529     } else if(className=="Tower") {
     530       if(input.Contains("eflow",TString::kIgnoreCase) || name.Contains("eflow",TString::kIgnoreCase)) continue; //no eflow
     531       clist = new DelphesBranchElement<DelphesCaloData>(name,"tower",kBlack);
     532       clist->GetContainer()->SetEtaBins(etaAxis);
     533       clist->GetContainer()->SetPhiBins(phiAxis);
     534       elements.push_back(clist);
     535     } else if(className=="Jet") {
     536       if(input.Contains("GenJetFinder")) {
     537         elist = new DelphesBranchElement<TEveElementList>(name,"jet",kCyan);
     538         elist->GetContainer()->SetRnrSelf(false);
     539         elist->GetContainer()->SetRnrChildren(false);
     540         elements.push_back(elist);
     541       } else {
     542         elements.push_back(new DelphesBranchElement<TEveElementList>(name,"jet",kYellow));
     543       }
     544     } else if(className=="Electron") {
     545       tlist = new DelphesBranchElement<TEveTrackList>(name,"track",kRed);
     546       elements.push_back(tlist);
     547       TEveTrackPropagator *trkProp = tlist->GetContainer()->GetPropagator();
     548       trkProp->SetMagField(0., 0., -tk_Bz);
     549       trkProp->SetMaxR(tk_radius);
     550       trkProp->SetMaxZ(tk_length);
     551     } else if(className=="Photon") {
     552       tlist = new DelphesBranchElement<TEveTrackList>(name,"photon",kYellow);
     553       elements.push_back(tlist);
     554       TEveTrackPropagator *trkProp = tlist->GetContainer()->GetPropagator();
     555       trkProp->SetMagField(0., 0., 0.);
     556       trkProp->SetMaxR(tk_radius);
     557       trkProp->SetMaxZ(tk_length);
     558     } else if(className=="Muon") {
     559       tlist = new DelphesBranchElement<TEveTrackList>(name,"track",kGreen);
     560       elements.push_back(tlist);
     561       TEveTrackPropagator *trkProp = tlist->GetContainer()->GetPropagator();
     562       trkProp->SetMagField(0., 0., -tk_Bz);
     563       trkProp->SetMaxR(mu_radius);
     564       trkProp->SetMaxZ(mu_length);
     565     } else if(className=="MissingET") {
     566       elements.push_back(new DelphesBranchElement<TEveElementList>(name,"vector",kViolet));
     567     } else if(className=="GenParticle") {
     568       tlist = new DelphesBranchElement<TEveTrackList>(name,"track",kCyan);
     569       elements.push_back(tlist);
     570       tlist->GetContainer()->SetRnrSelf(false);
     571       tlist->GetContainer()->SetRnrChildren(false);
     572       TEveTrackPropagator *trkProp = tlist->GetContainer()->GetPropagator();
     573       trkProp->SetMagField(0., 0., -tk_Bz);
     574       trkProp->SetMaxR(tk_radius);
     575       trkProp->SetMaxZ(tk_length);
     576     }
     577     arrays.push_back(gTreeReader->UseBranch(name));
     578   }
     579}
     580
    500581void delphes_event_display(const char *configFile, const char *inputFile, Delphes3DGeometry& det3D)
    501582{
     
    513594   gPhiAxis = det3D.getCaloAxes().second;
    514595
     596   //TODO specific to some classical detector... could use better the det3D
    515597   TGeoVolume* top = det3D.getDetector(false);
    516598   geom->SetTopVolume(top);
     
    553635   std::vector<DelphesBranchBase*> elements;
    554636   std::vector<TClonesArray*> arrays;
    555    //readConfig(configFile, det3D, elements, arrays);
     637   readConfig(configFile, det3D, elements, arrays);
    556638   // Get pointers to branches
    557 //TODO make it configurable, for more objects (or can we guess from the config?)
     639   // TODO not needed. use arrays above.
    558640   gBranchTower  = gTreeReader->UseBranch("Tower");
    559641   gBranchTrack  = gTreeReader->UseBranch("Track");
     
    566648
    567649   // data
     650   // TODO not needed. use elements above
    568651   gCaloData = new DelphesCaloData(2);
    569652   gCaloData->RefSliceInfo(0).Setup("ECAL", 0.1, kRed);
     
    586669   gMetList->SetMainColor(kViolet);
    587670   gEve->AddElement(gMetList);
    588 //   gMet = new TEveArrow(1., 0., 0., 0., 0., 0.);
    589 //   gMet->SetMainColor(kViolet);
    590 //   gMet->SetTubeR(0.02);
    591 //   gMet->SetPickable(kTRUE);
    592 //   gMet->SetName("Missing Et");
    593 //   gEve->GetCurrentEvent()->AddElement(gMet);
    594671
    595672   TEveTrackPropagator *trkProp;
     
    675752   gEve->GetViewers()->DeleteAnnotations();
    676753
     754   //TODO use the elements vector and call Reset for all
    677755   if(gCaloData) gCaloData->ClearTowers();
    678756   if(gJetList) gJetList->DestroyElements();
     
    700778{
    701779
     780  //TODO use the existing arrays in std loop.
    702781  TIter itTower(gBranchTower);
    703782  TIter itTrack(gBranchTrack);
     
    730809  // Load selected branches with data from specified event
    731810  gTreeReader->ReadEntry(event_id);
     811
     812
     813  //TODO the code below should go in small methods.
     814  //it's maybe time to convert that in a class.
    732815
    733816  // Loop over all towers
     
    9621045
    9631046   // create the application items
    964    delphes_event_display("delphes_card_CMS.tcl", "../delphes_output.root", det3D);
     1047   delphes_event_display("delphes_card_CMS.tcl", "../delphes_output.root", det3D); //TODO root file as input cfg
    9651048   make_gui();
    9661049   load_event();
     
    9811064}
    9821065
    983 // virtual class to represent objects from a Delphes-tree branch
    984 class DelphesBranchBase
    985 {
    986   public:
    987     DelphesBranchBase(const char* name, const char*type, const enum EColor color):name_(name),type_(type),color_(color) {}
    988     virtual ~DelphesBranchBase() {};
    989     const char* GetName() const { return (const char*)name_; }
    990     const char* GetType() const { return (const char*)type_; }
    991     enum EColor GetColor() const { return color_; }
    992     virtual const char* GetClassName() = 0;
    993     virtual void Reset() = 0;
    994 
    995   private:
    996     TString name_;
    997     TString type_; // needed for parsing the branch later on
    998     const enum EColor color_;
    999 };
    1000 // concrete implementations. EveContainer can be a TrackList, ElementList or CaloData.
    1001 template<typename EveContainer> class DelphesBranchElement: public DelphesBranchBase
    1002 {
    1003   public:
    1004     DelphesBranchElement(const char* name, const char*type, const enum EColor color):DelphesBranchBase(name, type, color) {
    1005       throw std::exception();
    1006     }
    1007 
    1008     // destructor
    1009     virtual ~DelphesBranchElement() {
    1010       delete data_;
    1011     }
    1012  
    1013     // get the container (ElementList, TrackList, or CaloData)
    1014     EveContainer* GetContainer() { return data_; }
    1015 
    1016     // resets the collection (before moving to the next event)
    1017     // making it pure virtual implies that only the specializations below will compile
    1018     virtual void Reset() {};
    1019 
    1020     // template class name
    1021     virtual const char* GetClassName() { return data_->ClassName(); }
    1022 
    1023   private:
    1024     EveContainer* data_;
    1025 };
    1026 // special case for calo towers
    1027 template<> DelphesBranchElement<DelphesCaloData>::DelphesBranchElement(const char* name, const char*type, const enum EColor color):DelphesBranchBase(name, type, color) {
    1028       if(TString(type)=="tower") {
    1029         data_ = new DelphesCaloData(2);
    1030         data_->RefSliceInfo(0).Setup("ECAL", 0.1, kRed);
    1031         data_->RefSliceInfo(1).Setup("HCAL", 0.1, kBlue);
    1032         data_->IncDenyDestroy();
    1033       } else {
    1034         throw std::exception();
    1035       }
    1036     }
    1037 template<> void DelphesBranchElement<DelphesCaloData>::Reset() { data_->ClearTowers(); }
    1038 // special case for element lists
    1039 template<> DelphesBranchElement<TEveElementList>::DelphesBranchElement(const char* name, const char*type, const enum EColor color):DelphesBranchBase(name, type, color) {
    1040       if(TString(type)=="vector" || TString(type)=="jet") {
    1041         data_ = new TEveElementList(name);
    1042         data_->SetMainColor(color_);
    1043       } else {
    1044         throw std::exception();
    1045       }
    1046     }
    1047 template<> void DelphesBranchElement<TEveElementList>::Reset() { data_->DestroyElements(); }
    1048 // special case for track lists
    1049 template<> DelphesBranchElement<TEveTrackList>::DelphesBranchElement(const char* name, const char*type, const enum EColor color):DelphesBranchBase(name, type, color) {
    1050       if(TString(type)=="track") {
    1051         data_ = new TEveTrackList(name);
    1052         data_->SetMainColor(color_);
    1053         data_->SetMarkerColor(color_);
    1054         data_->SetMarkerStyle(kCircle);
    1055         data_->SetMarkerSize(0.5);
    1056       } else if(TString(type)=="photon") {
    1057         data_ = new TEveTrackList(name);
    1058         data_->SetMainColor(color_);
    1059         data_->SetMarkerColor(color_);
    1060         data_->SetMarkerStyle(kCircle);
    1061         data_->SetMarkerSize(0.5);
    1062       } else {
    1063         throw std::exception();
    1064       }
    1065     }
    1066 template<> void DelphesBranchElement<TEveTrackList>::Reset() { data_->DestroyElements(); }
    1067 
    1068 // function that parses the config to extract the branches of interest and prepare containers
    1069 void readConfig(const char *configFile, Delphes3DGeometry& det3D, std::vector<DelphesBranchBase*>& elements, std::vector<TClonesArray*>& arrays) {
    1070    ExRootConfReader *confReader = new ExRootConfReader;
    1071    confReader->ReadFile(configFile);
    1072    Double_t tk_radius = det3D.getTrackerRadius();
    1073    Double_t tk_length = det3D.getTrackerHalfLength();
    1074    Double_t tk_Bz     = det3D.getBField();
    1075    Double_t mu_radius = det3D.getDetectorRadius();
    1076    Double_t mu_length = det3D.getDetectorHalfLength();
    1077    TAxis*   etaAxis   = det3D.getCaloAxes().first;
    1078    TAxis*   phiAxis   = det3D.getCaloAxes().second;
    1079    ExRootConfParam branches = confReader->GetParam("TreeWriter::Branch");
    1080    Int_t nBranches = branches.GetSize()/3;
    1081    for(Int_t b = 0; b<nBranches; ++b) {
    1082      TString input = branches[b*3].GetString();
    1083      TString name = branches[b*3+1].GetString();
    1084      TString className = branches[b*3+2].GetString();
    1085      if(className=="Track") {
    1086        if(input.Contains("eflow",TString::kIgnoreCase) || name.Contains("eflow",TString::kIgnoreCase)) continue; //no eflow
    1087        DelphesBranchElement<TEveTrackList>* list = new DelphesBranchElement<TEveTrackList>(name,"track",kBlue);
    1088        elements.push_back(list);
    1089        TEveTrackPropagator *trkProp = list->GetContainer()->GetPropagator();
    1090        trkProp->SetMagField(0., 0., -tk_Bz);
    1091        trkProp->SetMaxR(tk_radius);
    1092        trkProp->SetMaxZ(tk_length);
    1093      } else if(className=="Tower") {
    1094        if(input.Contains("eflow",TString::kIgnoreCase) || name.Contains("eflow",TString::kIgnoreCase)) continue; //no eflow
    1095        DelphesBranchElement<DelphesCaloData>* list = new DelphesBranchElement<DelphesCaloData>(name,"tower",kBlack);
    1096        list->GetContainer()->SetEtaBins(etaAxis);
    1097        list->GetContainer()->SetPhiBins(phiAxis);
    1098        elements.push_back(list);
    1099      } else if(className=="Jet") {
    1100        if(input.Contains("GenJetFinder")) {
    1101          DelphesBranchElement<TEveElementList>* list = new DelphesBranchElement<TEveElementList>(name,"jet",kCyan);
    1102          list->GetContainer()->SetRnrSelf(false);
    1103          list->GetContainer()->SetRnrChildren(false);
    1104          elements.push_back(list);
    1105        } else {
    1106          elements.push_back(new DelphesBranchElement<TEveElementList>(name,"jet",kYellow));
    1107        }
    1108      } else if(className=="Electron") {
    1109        DelphesBranchElement<TEveTrackList>* list = new DelphesBranchElement<TEveTrackList>(name,"track",kRed);
    1110        elements.push_back(list);
    1111        TEveTrackPropagator *trkProp = list->GetContainer()->GetPropagator();
    1112        trkProp->SetMagField(0., 0., -tk_Bz);
    1113        trkProp->SetMaxR(tk_radius);
    1114        trkProp->SetMaxZ(tk_length);
    1115      } else if(className=="Photon") {
    1116        DelphesBranchElement<TEveTrackList>* list = new DelphesBranchElement<TEveTrackList>(name,"photon",kYellow);
    1117        elements.push_back(list);
    1118        TEveTrackPropagator *trkProp = list->GetContainer()->GetPropagator();
    1119        trkProp->SetMagField(0., 0., 0.);
    1120        trkProp->SetMaxR(tk_radius);
    1121        trkProp->SetMaxZ(tk_length);
    1122      } else if(className=="Muon") {
    1123        DelphesBranchElement<TEveTrackList>* list = new DelphesBranchElement<TEveTrackList>(name,"track",kGreen);
    1124        elements.push_back(list);
    1125        TEveTrackPropagator *trkProp = list->GetContainer()->GetPropagator();
    1126        trkProp->SetMagField(0., 0., -tk_Bz);
    1127        trkProp->SetMaxR(mu_radius);
    1128        trkProp->SetMaxZ(mu_length);
    1129      } else if(className=="MissingET") {
    1130        elements.push_back(new DelphesBranchElement<TEveElementList>(name,"vector",kViolet));
    1131      } else if(className=="GenParticle") {
    1132        DelphesBranchElement<TEveTrackList>* list = new DelphesBranchElement<TEveTrackList>(name,"track",kCyan);
    1133        elements.push_back(list);
    1134        list->GetContainer()->SetRnrSelf(false);
    1135        list->GetContainer()->SetRnrChildren(false);
    1136        TEveTrackPropagator *trkProp = list->GetContainer()->GetPropagator();
    1137        trkProp->SetMagField(0., 0., -tk_Bz);
    1138        trkProp->SetMaxR(tk_radius);
    1139        trkProp->SetMaxZ(tk_length);
    1140      }
    1141      arrays.push_back(gTreeReader->UseBranch(name));
    1142    }
    1143 }
Note: See TracChangeset for help on using the changeset viewer.