Fork me on GitHub

Changeset ffd01cb in git


Ignore:
Timestamp:
Oct 14, 2014, 11:26:44 PM (10 years ago)
Author:
Christophe Delaere <christophe.delaere@…>
Branches:
ImprovedOutputFile, Timing, dual_readout, llp, master
Children:
5bb66c9
Parents:
a844c07
Message:

Tentative code to automatize config parsing

As it is, the code is useless. It gets too complicated for the
interpreter and the auto dict generation fails. The new classes have to
be compiled separately. The idea is to move the code to the display
directory.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • examples/geometry.C

    ra844c07 rffd01cb  
    55#include <algorithm>
    66#include <sstream>
     7#include <exception>
    78#include "TGeoManager.h"
    89#include "TGeoVolume.h"
     
    4041#include "TClonesArray.h"
    4142#include "TGLClip.h"
     43#include "TEveArrow.h"
    4244
    4345/*
     
    5456class DelphesCaloData;
    5557class DelphesDisplay;
     58class DelphesBranchBase;
     59template<typename EveContainer> class DelphesBranchElement;
    5660void make_gui();
    5761void load_event();
    5862void delphes_read();
     63void readConfig(const char *configFile, const Delphes3DGeometry& det3D, std::vector<DelphesBranchBase*>& elements, std::vector<TClonesArray*>& arrays);
    5964
    6065// Configuration and global variables.
     
    8489TEveElementList *gJetList = 0;
    8590TEveElementList *gGenJetList = 0;
    86 TEveArrow *gMet = 0;
     91TEveElementList *gMetList = 0;
    8792TEveTrackList *gTrackList = 0;
    8893TEveTrackList *gElectronList = 0;
     
    121126     Double_t getDetectorRadius() const { return muonSystem_radius_; }
    122127     Double_t getTrackerHalfLength() const { return tk_length_; }
     128     Double_t getDetectorHalfLength() const { return muonSystem_length_; }
    123129     Double_t getBField() const { return tk_Bz_; }
    124130     std::pair<TAxis*, TAxis*> getCaloAxes() { return std::make_pair(etaAxis_,phiAxis_); }
     
    147153     Double_t muonSystem_thickn_;
    148154     Double_t muonSystem_radius_;
     155     Double_t muonSystem_length_;
    149156     Double_t tk_radius_;
    150157     Double_t tk_length_;
     
    282289
    283290   muonSystem_radius_ = tk_radius_ + contingency_ + (contingency_+calo_barrel_thickness_)*calorimeters_.size() + muonSystem_thickn_;
     291   muonSystem_length_ = tk_length_ + contingency_ + (contingency_+calo_endcap_thickness_)*calorimeters_.size() + muonSystem_thickn_;
    284292
    285293   delete confReader;
     
    490498/******************************************************************************/
    491499
    492 void delphes_event_display(const char *configFile, const char *inputFile, const Delphes3DGeometry& det3D)
     500void delphes_event_display(const char *configFile, const char *inputFile, Delphes3DGeometry& det3D)
    493501{
    494502
     
    505513   gPhiAxis = det3D.getCaloAxes().second;
    506514
    507    TGeoVolume* top = det3D.getDetector(false); //TODO: can this be set in the GUI?
     515   TGeoVolume* top = det3D.getDetector(false);
    508516   geom->SetTopVolume(top);
    509517   TEveElementList *geometry = new TEveElementList("Geometry");
     
    542550   gTreeReader = new ExRootTreeReader(&gChain);
    543551
     552   // prepare data collections
     553   std::vector<DelphesBranchBase*> elements;
     554   std::vector<TClonesArray*> arrays;
     555   //readConfig(configFile, det3D, elements, arrays);
    544556   // Get pointers to branches
    545557//TODO make it configurable, for more objects (or can we guess from the config?)
     
    571583   gEve->AddElement(gGenJetList);
    572584
    573    gMet = new TEveArrow(1., 0., 0., 0., 0., 0.);
    574    gMet->SetMainColor(kViolet);
    575    gMet->SetTubeR(0.02);
    576    gMet->SetPickable(kTRUE);
    577    gMet->SetName("Missing Et");
    578    gEve->GetCurrentEvent()->AddElement(gMet);
     585   gMetList = new TEveElementList("Missing Et");
     586   gMetList->SetMainColor(kViolet);
     587   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);
    579594
    580595   TEveTrackPropagator *trkProp;
     
    662677   if(gCaloData) gCaloData->ClearTowers();
    663678   if(gJetList) gJetList->DestroyElements();
     679   if(gMetList) gMetList->DestroyElements();
    664680   if(gGenJetList) gGenJetList->DestroyElements();
    665681   if(gTrackList) gTrackList->DestroyElements();
     
    703719  TEveJetCone *eveJetCone;
    704720  TEveTrack *eveTrack;
     721  TEveArrow *eveMet;
    705722
    706723  Int_t counter;
     
    839856  itMet.Reset();
    840857  while((MET = (MissingET*) itMet.Next())) {
    841     delete gMet;
    842     gMet = new TEveArrow((gRadius * MET->MET/maxPt)*cos(MET->Phi), (gRadius * MET->MET/maxPt)*sin(MET->Phi), 0., 0., 0., 0.);
    843     gMet->SetMainColor(kViolet);
    844     gMet->SetTubeR(0.04);
    845     gMet->SetConeR(0.08);
    846     gMet->SetConeL(0.10);
    847     gMet->SetPickable(kTRUE);
    848     gMet->SetName("Missing Et");
    849     gMet->SetTitle(Form("Missing Et (%.1f GeV)",MET->MET));
    850     gMet->ProjectAllChildren();
    851     gEve->GetCurrentEvent()->AddElement(gMet);
     858    eveMet = new TEveArrow((gRadius * MET->MET/maxPt)*cos(MET->Phi), (gRadius * MET->MET/maxPt)*sin(MET->Phi), 0., 0., 0., 0.);
     859    eveMet->SetMainColor(kViolet);
     860    eveMet->SetTubeR(0.04);
     861    eveMet->SetConeR(0.08);
     862    eveMet->SetConeL(0.10);
     863    eveMet->SetPickable(kTRUE);
     864    eveMet->SetName("Missing Et");
     865    eveMet->SetTitle(Form("Missing Et (%.1f GeV)",MET->MET));
     866    gMetList->AddElement(eveMet);
    852867  }
    853868}
     
    955970   // 0 - no clip, 1 - clip plane, 2 - clip box
    956971   TGLViewer *v = gEve->GetDefaultGLViewer();
    957    Double_t plane[4] = { 0., 1., 0., 0. };
     972   //Double_t plane[4] = { 0., 1., 0., 0. };
    958973   //v->GetClipSet()->SetClipState(1,plane);
    959974   //v->GetClipSet()->SetClipType(1);
     
    966981}
    967982
     983// virtual class to represent objects from a Delphes-tree branch
     984class 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.
     1001template<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
     1027template<> 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    }
     1037template<> void DelphesBranchElement<DelphesCaloData>::Reset() { data_->ClearTowers(); }
     1038// special case for element lists
     1039template<> 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    }
     1047template<> void DelphesBranchElement<TEveElementList>::Reset() { data_->DestroyElements(); }
     1048// special case for track lists
     1049template<> 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    }
     1066template<> void DelphesBranchElement<TEveTrackList>::Reset() { data_->DestroyElements(); }
     1067
     1068// function that parses the config to extract the branches of interest and prepare containers
     1069void 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.