Remove parenthesis around throw arguments.
[u/mrichter/AliRoot.git] / EVE / EveBase / AliEveJetPlane.cxx
CommitLineData
d810d0de 1// $Id$
2// Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
4673ff03 3
d810d0de 4/**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
51346b82 7 * full copyright notice. *
d810d0de 8 **************************************************************************/
9
10#include "AliEveJetPlane.h"
a15e6d7d 11
12#include <TEveTrans.h>
2ea57cb0 13#include <TEveArrow.h>
9b6216c0 14#include <TEveSelection.h>
15#include <TEveManager.h>
a15e6d7d 16
4673ff03 17#include <TBuffer3D.h>
18#include <TBuffer3DTypes.h>
19#include <TVirtualPad.h>
20#include <TVirtualViewer3D.h>
21
9b6216c0 22#include <TColor.h>
23#include <TStyle.h>
24#include <TROOT.h>
25
57ffa5fb 26//______________________________________________________________________________
4673ff03 27//
a97abca8 28// Show jets and tracks in eta-phi plane.
a15e6d7d 29//
ff3111ab 30//
4673ff03 31
a97abca8 32ClassImp(AliEveJetPlane)
4673ff03 33
d810d0de 34Bool_t AliEveJetPlane::fgOneMomentumXYZ = kFALSE;
35Bool_t AliEveJetPlane::fgOneMomentumPhiTheta = kFALSE;
a97abca8 36Bool_t AliEveJetPlane::fgOneEta = kFALSE;
37Bool_t AliEveJetPlane::fgOneE = kFALSE;
38Bool_t AliEveJetPlane::fgOneChgMass = kFALSE;
4673ff03 39
40
d810d0de 41AliEveJetPlane::AliEveJetPlane(Int_t iev) :
42 TEveElementList(Form("AliEveJetPlane %i",iev), Form("%i",iev)),
4673ff03 43
44 fMinEta (-1.5 ),
45 fMaxEta ( 1.5 ),
2ea57cb0 46 fMinPhi ( 0.0 ),
47 fMaxPhi ( 2.0 * TMath::Pi() ),
4673ff03 48
49 fNEtaDiv(30),
50 fNPhiDiv(30),
51
52 fEtaScale(350/1.5),
2ea57cb0 53 fPhiScale(350/(TMath::Pi())),
9b6216c0 54 fEnergyScale(50.0),
4673ff03 55
361f01a5 56 fArrowJetScale (2.0),
57 fArrowTrackScale (0.7),
4673ff03 58
59 fGridColor(5),
60
fd31e9de 61 fJets(),
62 fTracks(),
63
4673ff03 64 fRnrJets (kTRUE),
65 fRnrTracks (kTRUE),
66
67 fOneSelection (kTRUE),
68 fTwoSelection (kFALSE),
9b6216c0 69 fSelConnected (kFALSE),
4673ff03 70
fd31e9de 71 fJet1(0), fJet2(0), fTrack1(0), fTrack2(0),
72
4673ff03 73 fSelectionFlag (1)
74{
9b6216c0 75 // Constructor.
76
4673ff03 77 SetMainColorPtr(&fGridColor);
a15e6d7d 78 InitMainTrans();
4673ff03 79}
80
9b6216c0 81AliEveJetPlane::~AliEveJetPlane()
82{
83 // Destructor.
84
85 if (fSelConnected)
86 {
87 gEve->GetSelection()->Disconnect("SelectionAdded(TEveElement*)", this);
88 }
89}
90
57ffa5fb 91/******************************************************************************/
4673ff03 92
ff3111ab 93void AliEveJetPlane::AddJet(AliAODJet* jet)
4673ff03 94{
a97abca8 95 // Add a jet for display.
ff3111ab 96
2ea57cb0 97 fJets.push_back(*jet);
4673ff03 98}
99
57ffa5fb 100/******************************************************************************/
4673ff03 101
2ea57cb0 102void AliEveJetPlane::AddTrack(AliAODTrack* track)
4673ff03 103{
a97abca8 104 // Add a track for display.
105
2ea57cb0 106 fTracks.push_back(*track);
4673ff03 107}
108
e930bdfa 109void AliEveJetPlane::CreateArrows()
110{
111 // Create arrows according to current state.
112
361f01a5 113 TEveManager::TRedrawDisabler noRedraw(gEve);
114
e930bdfa 115 DestroyElements();
116
9b6216c0 117 // Finding the maximum energy
118 Double_t eJetMax = 0., eTrackMax = 0., eMax;
119 {
120 std::vector<AliAODTrack>::iterator k = fTracks.begin();
121 std::vector<AliAODJet>::iterator j = fJets.begin();
122
123 while (j != fJets.end())
124 {
125 if (j->E() > eJetMax) eJetMax = j->E();
126 ++j;
127 }
128
129 while (k != fTracks.end())
130 {
131 if (k->E() > eTrackMax) eTrackMax = k->E();
132 ++k;
133 }
134
135 eMax = eJetMax > eTrackMax ? eJetMax : eTrackMax;
136 }
137
138 // Colors
139 Int_t nCol = gStyle->GetNumberOfColors();
140
141 Double_t eta, phi, e, x, y, h;
e930bdfa 142
143 if (fRnrJets)
144 {
145 UInt_t jetid = 0;
146 std::vector<AliAODJet>::iterator j = fJets.begin();
147 while (j != fJets.end())
148 {
149 eta = j->Eta();
150 phi = j->Phi();
151 e = j->E();
9b6216c0 152 h = TMath::Log(e + 1.) * fEnergyScale;
ff3111ab 153
e930bdfa 154 x = eta*(fEtaScale);
155 y = phi*(fPhiScale) - 350;
ff3111ab 156
361f01a5 157 Int_t colBin = TMath::Min((Int_t) ((nCol-2)*TMath::Log(e + 1.)/(TMath::Log(eMax + 1.))),nCol-2);
9b6216c0 158 Int_t colIdx = gStyle->GetColorPalette(colBin);
ff3111ab 159
9b6216c0 160 TEveArrow *a = new TEveArrow(0, 0 , h, x, y, 0);
e930bdfa 161 a->SetSourceObject(&*j);
162 a->SetElementName (Form("Jet %d", jetid));
ff3111ab 163 a->SetElementTitle(Form("Jet 4-momentum: %f, %f, %f, %f \n Pt-Eta-Phi values: %f, %f, %f",
9b6216c0 164 j->Px(), j->Py(), j->Pz(), e, j->Pt(), eta, phi ));
e930bdfa 165 a->SetPickable(kTRUE);
9b6216c0 166 a->SetMainColor(colIdx);
361f01a5 167 a->SetTubeR(0.016*fArrowJetScale);
168 a->SetConeR(0.049*fArrowJetScale);
169 a->SetConeL(0.170*fArrowJetScale);
e930bdfa 170 AddElement(a);
171
172 ++j; ++jetid;
173 }
174 }
175
176 if (fRnrTracks)
177 {
178 UInt_t trackid = 0;
ff3111ab 179 std::vector<AliAODTrack>::iterator k = fTracks.begin();
e930bdfa 180 while (k != fTracks.end())
181 {
182 eta = k->Eta();
183 phi = k->Phi();
184 e = k->E();
9b6216c0 185 h = TMath::Log(e + 1.) * fEnergyScale;
ff3111ab 186
9b6216c0 187 if (e < 0)
188 {
189 Warning("CreateArrows()",
190 "Track %d has negative energy - NOT DISPLAYED.", trackid);
191 ++k; ++trackid;
192 continue;
193 }
194
e930bdfa 195 x = eta*(fEtaScale);
196 y = phi*(fPhiScale) - 350;
ff3111ab 197
361f01a5 198 Int_t colBin = TMath::Min((Int_t) ((nCol-2)*TMath::Log(e + 1.)/(TMath::Log(eMax + 1.))),nCol-2);
9b6216c0 199 Int_t colIdx = gStyle->GetColorPalette(colBin);
ff3111ab 200
9b6216c0 201 TEveArrow *a = new TEveArrow(0, 0 , h, x, y, 0);
e930bdfa 202 a->SetSourceObject(&*k);
203 a->SetElementName (Form("Track %d", trackid));
ff3111ab 204 a->SetElementTitle(Form("Track 4-momentum: %f, %f, %f, %f \n Pt-Eta-Phi values: %f, %f, %f",
9b6216c0 205 k->Px(), k->Py(), k->Pz(), e, k->Pt(), eta, phi ));
e930bdfa 206 a->SetPickable(kTRUE);
9b6216c0 207 a->SetMainColor(colIdx);
361f01a5 208 a->SetTubeR(0.015*fArrowTrackScale);
209 a->SetConeR(0.040*fArrowTrackScale);
210 a->SetConeL(0.130*fArrowTrackScale);
e930bdfa 211 AddElement(a);
212
213 ++k; ++trackid;
214 }
215 }
9b6216c0 216
217 if ( ! fSelConnected)
218 {
219 gEve->GetSelection()->Connect("SelectionAdded(TEveElement*)",
220 "AliEveJetPlane", this, "SelectionAdded(TEveElement*)");
221 fSelConnected = kTRUE;
222 }
223}
224
225/******************************************************************************/
226
9b6216c0 227void AliEveJetPlane::SelectionAdded(TEveElement* el)
228{
229 // Slot called when EVE selection gets a new element.
230
ff3111ab 231
232 if (fOneSelection)
9b6216c0 233 {
ff3111ab 234 if (HasChild(el))
235 {
236 printf("\n\nNOW SELECTED: %s\n", el->GetElementName());
237
238 TObject *src = el->GetSourceObject();
9b6216c0 239
ff3111ab 240 AliAODTrack *k = dynamic_cast<AliAODTrack*>(src);
241 AliAODJet *j = dynamic_cast<AliAODJet*> (src);
9b6216c0 242
ff3111ab 243 // printf ("Track %p --- Jet %p\n", (void*)t, (void*)j);
244 if (k) printf("Track 4-momentum: %f, %f, %f, %f \nPt-Eta-Phi values: %f, %f, %f \n",
245 k->Px(), k->Py(), k->Pz(), k->E(), k->Pt(), k->Eta(), k->Phi() );
9b6216c0 246
ff3111ab 247 if (j) printf("Jet 4-momentum: %f, %f, %f, %f \nPt-Eta-Phi values: %f, %f, %f \n",
248 j->Px(), j->Py(), j->Pz(), j->E(), j->Pt(), j->Eta(), j->Phi() );
249 }
9b6216c0 250 }
251
252 TEveSelection *sel = gEve->GetSelection();
ff3111ab 253 if (fTwoSelection && sel->NumChildren() == 2)
9b6216c0 254 {
ff3111ab 255 Int_t numvps = 0;
256 AliVParticle *vpart[2] = { 0 };
257 TEveElement *elmnt[2] = { 0 };
258
259 for (List_i i = sel->BeginChildren(); i != sel->EndChildren(); ++i)
9b6216c0 260 {
ff3111ab 261 if (HasChild(*i))
262 {
263 TEveElement *chld = *i;
264 TObject *src = chld->GetSourceObject();
265 AliVParticle *p = dynamic_cast<AliVParticle*>(src);
266
267 if (p != 0)
268 {
269 vpart[numvps] = p;
270 elmnt[numvps] = chld;
271 ++numvps;
272 if (numvps >= 2)
273 break;
274 }
275 }
276 }
9b6216c0 277
ff3111ab 278 Double_t eta0, eta1, phi0, phi1, d;
9b6216c0 279
ff3111ab 280 if (numvps == 2)
281 {
282 eta0 = vpart[0]->Eta();
283 eta1 = vpart[1]->Eta();
284 phi0 = vpart[0]->Phi();
285 phi1 = vpart[1]->Phi();
286
287 d = TMath::Sqrt(TMath::Power(eta1-eta0,2) + TMath::Power(phi1-phi0,2));
288 printf("\n\nNOW SELECTED: '%s' and '%s'\n",
289 elmnt[0]->GetElementName(), elmnt[1]->GetElementName());
290 printf("Eta-Phi Distance: %f\n", d);
9b6216c0 291 }
292 }
e930bdfa 293}
4673ff03 294
57ffa5fb 295/******************************************************************************/
4673ff03 296
d810d0de 297void AliEveJetPlane::ComputeBBox()
4673ff03 298{
a97abca8 299 // Calculate bounding-box.
300
4673ff03 301 BBoxInit();
302 BBoxCheckPoint(-350, -350, -20);
2ea57cb0 303 BBoxCheckPoint( 350, 350, 20);
4673ff03 304}
305
e930bdfa 306
d810d0de 307void AliEveJetPlane::Paint(Option_t* /*option*/)
4673ff03 308{
a97abca8 309 // Paint the object.
310
4673ff03 311 TBuffer3D buff(TBuffer3DTypes::kGeneric);
312
313 // Section kCore
314 buff.fID = this;
68ca2fe7 315 buff.fColor = GetMainColor();
316 buff.fTransparency = GetMainTransparency();
a15e6d7d 317 if (HasMainTrans()) RefMainTrans().SetBuffer3D(buff);
4673ff03 318 buff.SetSectionsValid(TBuffer3D::kCore);
319
320 Int_t reqSections = gPad->GetViewer3D()->AddObject(buff);
321 if (reqSections == TBuffer3D::kNone) {
d810d0de 322 // printf("AliEveJetPlane::Paint viewer was happy with Core buff3d.\n");
4673ff03 323 return;
324 }
325}