Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
jetcone.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_eve
3 /// Demonstrates usage of TEveJetCone class.
4 ///
5 /// \image html eve_jetcone.png
6 /// \macro_code
7 ///
8 /// \author Jochen Thaeder
9 
10 const char* esd_geom_file_name =
11  "http://root.cern.ch/files/alice_ESDgeometry.root";
12 
13 TEveVector GetTEveVector(Float_t eta, Float_t phi);
14 void geomGentleTPC();
15 
16 void jetcone()
17 {
18  TEveManager::Create();
19 
20  using namespace TMath;
21 
22  TRandom r(0);
23 
24  // -- Set Constants
25  Int_t nCones = 10;
26  Int_t nTracks = 200;
27 
28  Float_t coneRadius = 0.4;
29  Float_t length = 300.;
30 
31  // -- Define palette
32  auto pal = new TEveRGBAPalette(0, 500);
33 
34  // -----------------------------------------------------------------------
35  // -- Line sets
36  // -----------------------------------------------------------------------
37 
38  // -- Define cone center
39  auto axis = new TEveStraightLineSet("Cone Axis");
40  axis->SetLineColor(kGreen);
41  axis->SetLineWidth(2);
42 
43  auto tracksXYZ = new TEveStraightLineSet("StraightLinesXYZ");
44  tracksXYZ->SetLineColor(kRed);
45  tracksXYZ->SetLineWidth(2);
46 
47  auto tracksEtaPhi = new TEveStraightLineSet("StraightLinesEtaPhi");
48  tracksEtaPhi->SetLineColor(kYellow);
49  tracksEtaPhi->SetLineWidth(2);
50 
51  auto tracksSeedEtaPhi = new TEveStraightLineSet("StraightLinesEtaPhiSeed");
52  tracksSeedEtaPhi->SetLineColor(kBlue);
53  tracksSeedEtaPhi->SetLineWidth(2);
54 
55  // -----------------------------------------------------------------------
56  // -- Draw track distribution in XYZ in TPC Volume +/-250, +/-250, +/-250
57  // -----------------------------------------------------------------------
58 
59  for ( Int_t track=0; track < nTracks ; track++ ) {
60 
61  Float_t trackX = r.Uniform(-250.0, 250.0);
62  Float_t trackY = r.Uniform(-250.0, 250.0);
63  Float_t trackZ = r.Uniform(-250.0, 250.0);
64  Float_t trackR = Sqrt(trackX*trackX + trackY*trackY + trackZ*trackZ);
65 
66  TEveVector trackDir(trackX/trackR, trackY/trackR ,trackZ/trackR);
67  TEveVector trackEnd = trackDir * length;
68  tracksXYZ->AddLine(0., 0., 0., trackEnd.fX, trackEnd.fY, trackEnd.fZ );
69  }
70 
71  // -----------------------------------------------------------------------
72  // -- Draw track distribution in eta phi in TPC Volume +/-0.9, {0, 2Pi}
73  // -----------------------------------------------------------------------
74 
75  for ( Int_t track=0; track < nTracks ; track++ ) {
76 
77  Float_t trackEta = r.Uniform(-0.9, 0.9);
78  Float_t trackPhi = r.Uniform(0.0, TwoPi());
79 
80  TEveVector trackDir( GetTEveVector(trackEta, trackPhi) );
81  TEveVector trackEnd = trackDir * length;
82 
83  if ( trackEta > coneRadius || trackEta < -coneRadius )
84  tracksEtaPhi->AddLine(0., 0., 0.,
85  trackEnd.fX, trackEnd.fY, trackEnd.fZ);
86  else
87  tracksSeedEtaPhi->AddLine(0., 0., 0.,
88  trackEnd.fX, trackEnd.fY, trackEnd.fZ);
89  }
90 
91  // -----------------------------------------------------------------------
92  // -- Draw cones
93  // -----------------------------------------------------------------------
94 
95  for ( Int_t iter = 0; iter < nCones; ++iter ) {
96 
97  // -- Get Random ( eta ,phi )
98  Float_t coneEta = r.Uniform(-0.9, 0.9);
99  Float_t conePhi = r.Uniform(0.0, TwoPi() );
100 
101  // -- Primary vertex as origin
102  TEveVector coneOrigin(0.0,0.0,0.0);
103 
104  // -- Get Cone Axis - axis line 10% longer than cone height
105  TEveVector coneAxis ( GetTEveVector( coneEta, conePhi) );
106  coneAxis *= length * 1.1;
107 
108  axis->AddLine( 0., 0., 0., coneAxis.fX, coneAxis.fY, coneAxis.fZ );
109 
110  // -- Draw jet cone
111  auto jetCone = new TEveJetCone("JetCone");
112  jetCone->SetPickable(kTRUE);
113  jetCone->SetCylinder( 250., 250. );
114  if ( (jetCone->AddCone( coneEta, conePhi, coneRadius ) ) != -1)
115  gEve->AddElement( jetCone );
116  }
117 
118  // -----------------------------------------------------------------------
119 
120  // -- Add cone axis
121  gEve->AddElement(axis);
122 
123  // -- Add lines
124  // gEve->AddElement(tracksXYZ);
125  gEve->AddElement(tracksSeedEtaPhi);
126  gEve->AddElement(tracksEtaPhi);
127 
128  // -- Load TPC geometry
129  geomGentleTPC();
130 
131  gEve->Redraw3D(kTRUE);
132 
133  return;
134 }
135 
136 //___________________________________________________________________________
137 TEveVector GetTEveVector(Float_t eta, Float_t phi)
138 {
139  using namespace TMath;
140 
141  TEveVector vec( (Float_t) Cos ( (Double_t) phi)/ CosH( (Double_t) eta ),
142  (Float_t) Sin ( (Double_t) phi)/ CosH( (Double_t) eta ),
143  (Float_t) TanH( (Double_t) eta ) );
144  return vec;
145 }
146 
147 //__________________________________________________________________________
148 void geomGentleTPC()
149 {
150  // Simple geometry
151  TFile::SetCacheFileDir(".");
152  TFile* geom = TFile::Open(esd_geom_file_name, "CACHEREAD");
153  if (!geom)
154  return;
155 
156  TEveGeoShapeExtract* gse = (TEveGeoShapeExtract*) geom->Get("Gentle");
157  TEveGeoShape* gsre = TEveGeoShape::ImportShapeExtract(gse, 0);
158  geom->Close();
159  delete geom;
160 
161  gEve->AddGlobalElement(gsre);
162 
163  TEveElement* elTRD = gsre->FindChild("TRD+TOF");
164  elTRD->SetRnrState(kFALSE);
165 
166  TEveElement* elPHOS = gsre->FindChild("PHOS");
167  elPHOS->SetRnrState(kFALSE);
168 
169  TEveElement* elHMPID = gsre->FindChild("HMPID");
170  elHMPID->SetRnrState(kFALSE);
171 }