Fork me on GitHub

Changeset 7513718 in git for examples


Ignore:
Timestamp:
Oct 8, 2014, 11:07:34 PM (10 years ago)
Author:
Christophe Delaere <christophe.delaere@…>
Branches:
ImprovedOutputFile, Timing, dual_readout, llp, master
Children:
e0c1ff0
Parents:
7f66dc0
Message:

Almost integrated geometry and event display

In terms of functionalities, we should be close. But this has to be
debugged. Then, other features will have to be developed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • examples/geometry.C

    r7f66dc0 r7513718  
    7777                                         const char* Calorimeters="Calorimeter");
    7878
     79     void loadFromFile(const char* filename, const char* name="DelphesGeometry");
     80     void save(const char* filename, const char* name="DelphesGeometry");
     81
    7982     void setContingency(Double_t contingency) { contingency_ = contingency; }
    8083     void setCaloBarrelThickness(Double_t thickness) { calo_barrel_thickness_ = thickness; }
     
    8386
    8487     TGeoVolume* getDetector(bool withTowers = true);
     88
     89     Double_t getTrackerRadius() const { return tk_radius_; }
     90     Double_t getTrackerHalfLength() const { return tk_length_; }
     91     Double_t getBField() const { return tk_Bz_; }
     92     std::pair<TAxis*, TAxis*> getCaloAxes() { return std::make_pair(etaAxis_,phiAxis_); }
    8593
    8694   private:
     
    98106     TGeoMedium *calomed_;
    99107     TGeoMedium *mudetmed_;
     108
     109     TAxis* etaAxis_;
     110     TAxis* phiAxis_;
    100111
    101112     Double_t contingency_;
     
    106117     Double_t tk_length_;
    107118     Double_t tk_etamax_;
     119     Double_t tk_Bz_;
    108120
    109121     std::vector<std::string> calorimeters_;
     
    119131   //--- the geometry manager
    120132   geom_ = geom==NULL? gGeoManager : geom;
     133   gGeoManager->DefaultColors();
    121134
    122135   //--- define some materials
     
    139152
    140153   // read these parameters from the Delphes Card (with default values)
     154   etaAxis_   = NULL;
     155   phiAxis_   = NULL;
    141156   tk_radius_ = 120.;
    142157   tk_length_ = 150.;
    143158   tk_etamax_ = 3.0;
     159   tk_Bz_     = 1.;
    144160}
    145161
     
    153169   tk_radius_ = confReader->GetDouble(Form("%s::Radius",ParticlePropagator), 1.0)*100;          // tk_radius
    154170   tk_length_ = confReader->GetDouble(Form("%s::HalfLength",ParticlePropagator), 3.0)*100;      // tk_length
     171   tk_Bz_     = confReader->GetDouble("ParticlePropagator::Bz", 0.0);                           // tk_Bz
    155172
    156173   {
     
    217234     caloBinning_[*calo] = caloBinning;
    218235   }
     236
     237   set< pair<Double_t, Int_t> > caloBinning = caloBinning_[*calorimeters_.begin()];
     238   Double_t *etaBins = new Double_t[caloBinning.size()]; // note that this is the eta binning of the first calo
     239   unsigned int i = 0;
     240   for(set< pair<Double_t, Int_t> >::const_iterator itEtaSet = caloBinning.begin(); itEtaSet != caloBinning.end(); ++itEtaSet) {
     241     etaBins[i++] = itEtaSet.first;
     242   }
     243   etaAxis_ = new TAxis(caloBinning.size() - 1, etaBins);
     244   phiAxis_ = new TAxis(72, -TMath::Pi(), TMath::Pi()); // note that this is fixed while #phibins could vary, also with eta, which doesn't seem possible in ROOT
    219245
    220246   delete confReader;
     
    427453void delphes_event_display(const char *configFile, const char *inputFile)
    428454{
    429    // to be the main function, initializes the application.
    430 
    431   gSystem->Load("libDelphesDisplay");
    432 
    433   TEveManager::Create(kTRUE, "IV");
    434 
    435 //------------------------------------ TODO: this should be moved to the geometry class
    436   ExRootConfParam param, paramEtaBins;
    437   Long_t i, j, size, sizeEtaBins;
    438   set< Double_t > etaSet;
    439   set< Double_t >::iterator itEtaSet;
    440 
    441   Double_t *etaBins;
    442 
    443   ExRootConfReader *confReader = new ExRootConfReader;
    444   confReader->ReadFile(configFile);
    445 
    446   gRadius = confReader->GetDouble("ParticlePropagator::Radius", 1.0);
    447   gHalfLength = confReader->GetDouble("ParticlePropagator::HalfLength", 3.0);
    448   gBz = confReader->GetDouble("ParticlePropagator::Bz", 0.0);
    449 
    450 
    451   // read eta and phi bins
    452   param = confReader->GetParam("Calorimeter::EtaPhiBins");
    453   size = param.GetSize();
    454   etaSet.clear();
    455   for(i = 0; i < size/2; ++i)
    456   {
    457     paramEtaBins = param[i*2];
    458     sizeEtaBins = paramEtaBins.GetSize();
    459 
    460     for(j = 0; j < sizeEtaBins; ++j)
    461     {
    462       etaSet.insert(paramEtaBins[j].GetDouble());
    463     }
    464   }
    465 
    466   delete confReader;
    467 
    468   etaBins = new Double_t[etaSet.size()];
    469   i = 0;
    470 
    471   for(itEtaSet = etaSet.begin(); itEtaSet != etaSet.end(); ++itEtaSet)
    472   {
    473     etaBins[i] = *itEtaSet;
    474     ++i;
    475   }
    476 
    477   gEtaAxis = new TAxis(etaSet.size() - 1, etaBins);
    478   gPhiAxis = new TAxis(72, -TMath::Pi(), TMath::Pi()); // note that this is fixed while #phibins could vary, also with eta, which doesn't seem possible in ROOT
    479 //-----------------------------------------------------------------------
    480 
    481   // Create chain of root trees
    482   gChain.Add(inputFile);
    483 
    484   // Create object of class ExRootTreeReader
     455   // to be the main function...
     456
     457   // initialize the application
     458   gSystem->Load("libDelphesDisplay");
     459   TEveManager::Create(kTRUE, "IV");
     460
     461   // build the detector
     462   Delphes3DGeometry det3D;
     463   det3D.readFile(filename,ParticlePropagator, TrackingEfficiency, MuonEfficiency, Calorimeters);
     464   gRadius = det3D.getTrackerRadius();
     465   gHalfLength = det3D.getTrackerHalfLength();
     466   gBz = det3D.getBField();
     467   gEtaAxis = det3D.getCaloAxes().first;
     468   gPhiAxis = det3D.getCaloAxes().second;
     469   TGeoVolume* top = gGeoManager->GetTopVolume()->FindNode("Delphes3DGeometry_1")->GetVolume();
     470   TEveElementList *geometry = new TEveElementList("Geometry");
     471   TEveGeoTopNode* trk = new TEveGeoTopNode(gGeoManager, top->FindNode("tracker_1"));
     472   trk->SetVisLevel(6);
     473   geometry->AddElement(trk);
     474   TEveGeoTopNode* calo = new TEveGeoTopNode(gGeoManager, top->FindNode("Calorimeter_barrel_1"));
     475   calo->SetVisLevel(3);
     476   geometry->AddElement(calo);
     477   calo = new TEveGeoTopNode(gGeoManager, top->FindNode("Calorimeter_endcap_1"));
     478   calo->SetVisLevel(3);
     479   calo->UseNodeTrans();
     480   geometry->AddElement(calo);
     481   calo = new TEveGeoTopNode(gGeoManager, top->FindNode("Calorimeter_endcap_2"));
     482   calo->SetVisLevel(3);
     483   calo->UseNodeTrans();
     484   geometry->AddElement(calo);
     485   TEveGeoTopNode* muon = new TEveGeoTopNode(gGeoManager, top->FindNode("muons_barrel_1"));
     486   muon->SetVisLevel(4);
     487   geometry->AddElement(muon);
     488   muon = new TEveGeoTopNode(gGeoManager, top->FindNode("muons_endcap_1"));
     489   muon->SetVisLevel(4);
     490   muon->UseNodeTrans();
     491   geometry->AddElement(muon);
     492   muon = new TEveGeoTopNode(gGeoManager, top->FindNode("muons_endcap_2"));
     493   muon->SetVisLevel(4);
     494   muon->UseNodeTrans();
     495   geometry->AddElement(muon);
     496
     497   // Create chain of root trees
     498   gChain.Add(inputFile);
     499
     500   // Create object of class ExRootTreeReader
    485501   printf("*** Opening Delphes data file ***\n");
    486   gTreeReader = new ExRootTreeReader(&gChain);
    487 
    488   // Get pointers to branches
    489   //TODO make it configurable, for more objects (or can we guess from the config?)
    490   gBranchTower = gTreeReader->UseBranch("Tower");
    491   gBranchTrack = gTreeReader->UseBranch("Track");
    492   gBranchJet   = gTreeReader->UseBranch("Jet");
    493 
     502   gTreeReader = new ExRootTreeReader(&gChain);
     503
     504   // Get pointers to branches
     505   gBranchTower = gTreeReader->UseBranch("Tower");
     506   gBranchTrack = gTreeReader->UseBranch("Track");
     507   gBranchJet   = gTreeReader->UseBranch("Jet");
     508
     509//TODO make it configurable, for more objects (or can we guess from the config?)
    494510// idea: for pf objects, we could use the TEveCompound to show track + cluster ??? (nice display but little meaning)
    495511// for MET and SHT, show an arrow (tooltip = title)
     
    514530*/
    515531
    516   // data
    517   gCaloData = new DelphesCaloData(2);
    518   gCaloData->RefSliceInfo(0).Setup("ECAL", 0.1, kRed);
    519   gCaloData->RefSliceInfo(1).Setup("HCAL", 0.1, kBlue);
    520   gCaloData->SetEtaBins(gEtaAxis);
    521   gCaloData->SetPhiBins(gPhiAxis);
    522   gCaloData->IncDenyDestroy();
    523 
    524   gJetList = new TEveElementList("Jets");
    525   gEve->AddElement(gJetList);
    526 
    527   gTrackList = new TEveTrackList("Tracks");
    528   gTrackList->SetMainColor(kBlue);
    529   gTrackList->SetMarkerColor(kRed);
    530   gTrackList->SetMarkerStyle(kCircle);
    531   gTrackList->SetMarkerSize(0.5);
    532   gEve->AddElement(gTrackList);
    533 
    534   TEveTrackPropagator *trkProp = gTrackList->GetPropagator();
    535   trkProp->SetMagField(0.0, 0.0, -gBz);
    536   trkProp->SetMaxR(gRadius*100.0);
    537   trkProp->SetMaxZ(gHalfLength*100.0);
    538 
    539   // viewers and scenes
    540 
    541   TEveCalo3D *calo = new TEveCalo3D(gCaloData);
    542   calo->SetBarrelRadius(gRadius*100.0);  //TODO get it from geometry class
    543   calo->SetEndCapPos(gHalfLength*100.0); //TODO get it from geometry class
    544 
    545   gStyle->SetPalette(1, 0);
    546   TEveCaloLego *lego = new TEveCaloLego(gCaloData);
    547   lego->InitMainTrans();
    548   lego->RefMainTrans().SetScale(TMath::TwoPi(), TMath::TwoPi(), TMath::Pi());
    549   lego->SetAutoRebin(kFALSE);
    550   lego->Set2DMode(TEveCaloLego::kValSizeOutline);
    551 
    552   gDelphesDisplay = new DelphesDisplay;
    553   gEve->AddGlobalElement(geometry);
    554   gEve->AddGlobalElement(calo);
    555   gDelphesDisplay->ImportGeomRPhi(geometry);
    556   gDelphesDisplay->ImportCaloRPhi(calo);
    557   gDelphesDisplay->ImportGeomRhoZ(geometry);
    558   gDelphesDisplay->ImportCaloRhoZ(calo);
    559   gDelphesDisplay->ImportCaloLego(lego);
    560   gEve->Redraw3D(kTRUE);
     532   // data
     533   gCaloData = new DelphesCaloData(2);
     534   gCaloData->RefSliceInfo(0).Setup("ECAL", 0.1, kRed);
     535   gCaloData->RefSliceInfo(1).Setup("HCAL", 0.1, kBlue);
     536   gCaloData->SetEtaBins(gEtaAxis);
     537   gCaloData->SetPhiBins(gPhiAxis);
     538   gCaloData->IncDenyDestroy();
     539
     540   gJetList = new TEveElementList("Jets");
     541   gEve->AddElement(gJetList);
     542
     543   gTrackList = new TEveTrackList("Tracks");
     544   gTrackList->SetMainColor(kBlue);
     545   gTrackList->SetMarkerColor(kRed);
     546   gTrackList->SetMarkerStyle(kCircle);
     547   gTrackList->SetMarkerSize(0.5);
     548   gEve->AddElement(gTrackList);
     549
     550   TEveTrackPropagator *trkProp = gTrackList->GetPropagator();
     551   trkProp->SetMagField(0.0, 0.0, -gBz);
     552   trkProp->SetMaxR(gRadius*100.0);
     553   trkProp->SetMaxZ(gHalfLength*100.0);
     554
     555   // viewers and scenes
     556
     557   TEveCalo3D *calo = new TEveCalo3D(gCaloData);
     558   calo->SetBarrelRadius(gRadius*100.0);
     559   calo->SetEndCapPos(gHalfLength*100.0);
     560
     561   gStyle->SetPalette(1, 0);
     562   TEveCaloLego *lego = new TEveCaloLego(gCaloData);
     563   lego->InitMainTrans();
     564   lego->RefMainTrans().SetScale(TMath::TwoPi(), TMath::TwoPi(), TMath::Pi());
     565   lego->SetAutoRebin(kFALSE);
     566   lego->Set2DMode(TEveCaloLego::kValSizeOutline);
     567
     568   gDelphesDisplay = new DelphesDisplay;
     569   gEve->AddGlobalElement(geometry);
     570   gEve->AddGlobalElement(calo);
     571   gDelphesDisplay->ImportGeomRPhi(geometry);
     572   gDelphesDisplay->ImportCaloRPhi(calo);
     573   gDelphesDisplay->ImportGeomRhoZ(geometry);
     574   gDelphesDisplay->ImportCaloRhoZ(calo);
     575   gDelphesDisplay->ImportCaloLego(lego);
     576   gEve->Redraw3D(kTRUE);
    561577
    562578}
Note: See TracChangeset for help on using the changeset viewer.