Fork me on GitHub

source: svn/trunk/examples/EventDisplay.C@ 1174

Last change on this file since 1174 was 1098, checked in by Pavel Demin, 12 years ago

replace libDelphes with libDelphesDisplay

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision Date
File size: 6.7 KB
RevLine 
[899]1/*
[958]2root -l examples/EventDisplay.C\(\"examples/delphes_card_CMS.tcl\",\"delphes_output.root\"\)
[904]3ShowEvent(1);
4ShowEvent(2);
[899]5*/
6
7//------------------------------------------------------------------------------
8
[958]9// radius of the barrel, in m
10Double_t gRadius = 1.29;
[899]11
[958]12// half-length of the barrel, in m
13Double_t gHalfLength = 3.0;
14
[899]15// magnetic field
[958]16Double_t gBz = 3.8;
[899]17
[958]18TAxis *gEtaAxis = 0;
19TAxis *gPhiAxis = 0;
[899]20
21//------------------------------------------------------------------------------
22
[958]23#include <set>
24#include <vector>
[901]25
[958]26using namespace std;
27
[942]28class ExRootTreeReader;
29class DelphesCaloData;
30class DelphesDisplay;
31
[958]32TChain gChain("Delphes");
33
[901]34ExRootTreeReader *gTreeReader = 0;
[942]35
[901]36TClonesArray *gBranchTower = 0;
37TClonesArray *gBranchTrack = 0;
38TClonesArray *gBranchJet = 0;
39
40DelphesCaloData *gCaloData = 0;
41TEveElementList *gJetList = 0;
42TEveTrackList *gTrackList = 0;
43
44DelphesDisplay *gDelphesDisplay = 0;
45
46//------------------------------------------------------------------------------
47
[958]48void EventDisplay(const char *configFile, const char *inputFile)
[899]49{
[1098]50 gSystem->Load("libDelphesDisplay");
[942]51
[904]52 TEveManager::Create(kTRUE, "IV");
[901]53
[958]54 ExRootConfParam param, paramEtaBins;
55 Long_t i, j, size, sizeEtaBins;
56 set< Double_t > etaSet;
57 set< Double_t >::iterator itEtaSet;
58
59 Double_t *etaBins;
60
61 ExRootConfReader *confReader = new ExRootConfReader;
62 confReader->ReadFile(configFile);
63
64 gRadius = confReader->GetDouble("ParticlePropagator::Radius", 1.0);
65 gHalfLength = confReader->GetDouble("ParticlePropagator::HalfLength", 3.0);
66 gBz = confReader->GetDouble("ParticlePropagator::Bz", 0.0);
67
68 // read eta and phi bins
69 param = confReader->GetParam("Calorimeter::EtaPhiBins");
70 size = param.GetSize();
71 etaSet.clear();
72 for(i = 0; i < size/2; ++i)
73 {
74 paramEtaBins = param[i*2];
75 sizeEtaBins = paramEtaBins.GetSize();
76
77 for(j = 0; j < sizeEtaBins; ++j)
78 {
79 etaSet.insert(paramEtaBins[j].GetDouble());
80 }
81 }
82
83 delete confReader;
84
85 etaBins = new Double_t[etaSet.size()];
86 i = 0;
87
88 for(itEtaSet = etaSet.begin(); itEtaSet != etaSet.end(); ++itEtaSet)
89 {
90 etaBins[i] = *itEtaSet;
91 ++i;
92 }
93
94 gEtaAxis = new TAxis(etaSet.size() - 1, etaBins);
95 gPhiAxis = new TAxis(72, -TMath::Pi(), TMath::Pi());
96
[899]97 // Create chain of root trees
[901]98 gChain.Add(inputFile);
[958]99
[899]100 // Create object of class ExRootTreeReader
[901]101 gTreeReader = new ExRootTreeReader(&gChain);
[899]102
[901]103 // Get pointers to branches
104 gBranchTower = gTreeReader->UseBranch("Tower");
105 gBranchTrack = gTreeReader->UseBranch("Track");
106 gBranchJet = gTreeReader->UseBranch("Jet");
[958]107
[899]108 // data
[901]109 gCaloData = new DelphesCaloData(2);
[904]110 gCaloData->RefSliceInfo(0).Setup("ECAL", 0.1, kRed);
[901]111 gCaloData->RefSliceInfo(1).Setup("HCAL", 0.1, kBlue);
[958]112 gCaloData->SetEtaBins(gEtaAxis);
113 gCaloData->SetPhiBins(gPhiAxis);
[901]114 gCaloData->IncDenyDestroy();
[958]115
[901]116 gJetList = new TEveElementList("Jets");
117 gEve->AddElement(gJetList);
[958]118
119 gTrackList = new TEveTrackList("Tracks");
[901]120 gTrackList->SetMainColor(kBlue);
121 gTrackList->SetMarkerColor(kRed);
[904]122 gTrackList->SetMarkerStyle(kCircle);
[901]123 gTrackList->SetMarkerSize(0.5);
124 gEve->AddElement(gTrackList);
[899]125
[901]126 TEveTrackPropagator *trkProp = gTrackList->GetPropagator();
[958]127 trkProp->SetMagField(0.0, 0.0, -gBz);
128 trkProp->SetMaxR(gRadius*100.0);
129 trkProp->SetMaxZ(gHalfLength*100.0);
[899]130
[901]131 // viewers and scenes
[899]132
[901]133 TEveElementList *geometry = new TEveElementList("Geometry");
[899]134
[901]135 TEveGeoShape *barell = new TEveGeoShape("Barell");
[958]136 barell->SetShape(new TGeoTube(gRadius*100.0 - 1, gRadius*100.0, gHalfLength*100.0));
[901]137 barell->SetMainColor(kCyan);
138 barell->SetMainTransparency(80);
139 geometry->AddElement(barell);
[899]140
[901]141 TEveCalo3D *calo = new TEveCalo3D(gCaloData);
[958]142 calo->SetBarrelRadius(gRadius*100.0);
143 calo->SetEndCapPos(gHalfLength*100.0);
[899]144
[901]145 gStyle->SetPalette(1, 0);
146 TEveCaloLego *lego = new TEveCaloLego(gCaloData);
147 lego->InitMainTrans();
148 lego->RefMainTrans().SetScale(TMath::TwoPi(), TMath::TwoPi(), TMath::Pi());
[899]149 lego->SetAutoRebin(kFALSE);
150 lego->Set2DMode(TEveCaloLego::kValSizeOutline);
151
[901]152 gDelphesDisplay = new DelphesDisplay;
[899]153
[901]154 gEve->AddGlobalElement(geometry);
155 gEve->AddGlobalElement(calo);
[899]156
[901]157 gDelphesDisplay->ImportGeomRPhi(geometry);
158 gDelphesDisplay->ImportCaloRPhi(calo);
[899]159
[901]160 gDelphesDisplay->ImportGeomRhoZ(geometry);
161 gDelphesDisplay->ImportCaloRhoZ(calo);
[899]162
[901]163 gDelphesDisplay->ImportCaloLego(lego);
[899]164
[901]165 gEve->Redraw3D(kTRUE);
[899]166}
167
168//------------------------------------------------------------------------------
169
[904]170void ShowEvent(Long64_t event)
[899]171{
[901]172 TIter itTower(gBranchTower);
173 TIter itTrack(gBranchTrack);
174 TIter itJet(gBranchJet);
[899]175
[901]176 Tower *tower;
177 Track *track;
178 Jet *jet;
[958]179
[901]180 TEveJetCone *eveJetCone;
181 TEveTrack *eveTrack;
[899]182
[901]183 Int_t counter;
[899]184
[904]185 TEveElement *currentEvent = gEve->GetCurrentEvent();
[899]186
[901]187 TEveTrackPropagator *trkProp = gTrackList->GetPropagator();
[958]188
[901]189 if(event >= gTreeReader->GetEntries()) return;
[899]190
[901]191 // Load selected branches with data from specified event
192 gTreeReader->ReadEntry(event);
[899]193
[901]194 gCaloData->ClearTowers();
195 gJetList->DestroyElements();
196 gTrackList->DestroyElements();
[899]197
[901]198 // Loop over all towers
199 itTower.Reset();
200 while((tower = (Tower *) itTower.Next()))
201 {
202 gCaloData->AddTower(tower->Edges[0], tower->Edges[1], tower->Edges[2], tower->Edges[3]);
203 gCaloData->FillSlice(0, tower->Eem);
204 gCaloData->FillSlice(1, tower->Ehad);
205 }
206 gCaloData->DataChanged();
[899]207
[901]208 // Loop over all tracks
209 itTrack.Reset();
210 counter = 0;
211 while((track = (Track *) itTrack.Next()))
212 {
213 TParticle pb(track->PID, 1, 0, 0, 0, 0,
214 track->P4().Px(), track->P4().Py(),
215 track->P4().Pz(), track->P4().E(),
216 track->X, track->Y, track->Z, 0.0);
[899]217
[901]218 eveTrack = new TEveTrack(&pb, counter, trkProp);
219 eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++));
220 eveTrack->SetStdTitle();
221 eveTrack->SetAttLineAttMarker(gTrackList);
[899]222
[901]223 switch(TMath::Abs(track->PID))
224 {
225 case 11:
226 eveTrack->SetLineColor(kRed);
227 break;
228 case 13:
229 eveTrack->SetLineColor(kGreen);
230 break;
231 default:
232 eveTrack->SetLineColor(kBlue);
233 }
[903]234 gTrackList->AddElement(eveTrack);
235 eveTrack->MakeTrack();
[901]236 }
[899]237
[901]238 // Loop over all jets
239 itJet.Reset();
240 counter = 0;
241 while((jet = (Jet *) itJet.Next()))
242 {
243 eveJetCone = new TEveJetCone();
244 eveJetCone->SetName(Form("jet [%d]", counter++));
245 eveJetCone->SetMainTransparency(60);
246 eveJetCone->SetLineColor(kYellow);
[958]247 eveJetCone->SetCylinder(gRadius*100.0 - 10, gHalfLength*100.0 - 10);
[901]248 eveJetCone->SetPickable(kTRUE);
249 eveJetCone->AddEllipticCone(jet->Eta, jet->Phi, jet->DeltaEta, jet->DeltaPhi);
250 gJetList->AddElement(eveJetCone);
251 }
[899]252
[901]253 gDelphesDisplay->DestroyEventRPhi();
[904]254 gDelphesDisplay->ImportEventRPhi(currentEvent);
[899]255
[901]256 gDelphesDisplay->DestroyEventRhoZ();
[904]257 gDelphesDisplay->ImportEventRhoZ(currentEvent);
[899]258
[901]259 gEve->Redraw3D(kTRUE);
[899]260}
Note: See TracBrowser for help on using the repository browser.