From Cesar: make selection and two-selection working with the new
[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
56 fEnergyColorScale (0.),
57
58 fGridColor(5),
59
fd31e9de 60 fJets(),
61 fTracks(),
62
4673ff03 63 fRnrJets (kTRUE),
64 fRnrTracks (kTRUE),
65
66 fOneSelection (kTRUE),
67 fTwoSelection (kFALSE),
9b6216c0 68 fSelConnected (kFALSE),
4673ff03 69
fd31e9de 70 fJet1(0), fJet2(0), fTrack1(0), fTrack2(0),
71
4673ff03 72 fSelectionFlag (1)
73{
9b6216c0 74 // Constructor.
75
4673ff03 76 SetMainColorPtr(&fGridColor);
a15e6d7d 77 InitMainTrans();
4673ff03 78}
79
9b6216c0 80AliEveJetPlane::~AliEveJetPlane()
81{
82 // Destructor.
83
84 if (fSelConnected)
85 {
86 gEve->GetSelection()->Disconnect("SelectionAdded(TEveElement*)", this);
87 }
88}
89
57ffa5fb 90/******************************************************************************/
4673ff03 91
ff3111ab 92void AliEveJetPlane::AddJet(AliAODJet* jet)
4673ff03 93{
a97abca8 94 // Add a jet for display.
ff3111ab 95
2ea57cb0 96 fJets.push_back(*jet);
4673ff03 97}
98
57ffa5fb 99/******************************************************************************/
4673ff03 100
2ea57cb0 101void AliEveJetPlane::AddTrack(AliAODTrack* track)
4673ff03 102{
a97abca8 103 // Add a track for display.
104
2ea57cb0 105 fTracks.push_back(*track);
4673ff03 106}
107
e930bdfa 108void AliEveJetPlane::CreateArrows()
109{
110 // Create arrows according to current state.
111
112 DestroyElements();
113
9b6216c0 114 // Finding the maximum energy
115 Double_t eJetMax = 0., eTrackMax = 0., eMax;
116 {
117 std::vector<AliAODTrack>::iterator k = fTracks.begin();
118 std::vector<AliAODJet>::iterator j = fJets.begin();
119
120 while (j != fJets.end())
121 {
122 if (j->E() > eJetMax) eJetMax = j->E();
123 ++j;
124 }
125
126 while (k != fTracks.end())
127 {
128 if (k->E() > eTrackMax) eTrackMax = k->E();
129 ++k;
130 }
131
132 eMax = eJetMax > eTrackMax ? eJetMax : eTrackMax;
133 }
134
135 // Colors
136 Int_t nCol = gStyle->GetNumberOfColors();
137
138 Double_t eta, phi, e, x, y, h;
e930bdfa 139
140 if (fRnrJets)
141 {
142 UInt_t jetid = 0;
143 std::vector<AliAODJet>::iterator j = fJets.begin();
144 while (j != fJets.end())
145 {
146 eta = j->Eta();
147 phi = j->Phi();
148 e = j->E();
9b6216c0 149 h = TMath::Log(e + 1.) * fEnergyScale;
ff3111ab 150
e930bdfa 151 x = eta*(fEtaScale);
152 y = phi*(fPhiScale) - 350;
ff3111ab 153
9b6216c0 154 Int_t colBin = TMath::Min((Int_t) ((nCol-2)*TMath::Log(e + 1.)*TMath::Power(10., fEnergyColorScale)/(TMath::Log(eMax + 1.))),nCol-2);
155 Int_t colIdx = gStyle->GetColorPalette(colBin);
ff3111ab 156
9b6216c0 157 TEveArrow *a = new TEveArrow(0, 0 , h, x, y, 0);
e930bdfa 158 a->SetSourceObject(&*j);
159 a->SetElementName (Form("Jet %d", jetid));
ff3111ab 160 a->SetElementTitle(Form("Jet 4-momentum: %f, %f, %f, %f \n Pt-Eta-Phi values: %f, %f, %f",
9b6216c0 161 j->Px(), j->Py(), j->Pz(), e, j->Pt(), eta, phi ));
e930bdfa 162 a->SetPickable(kTRUE);
9b6216c0 163 a->SetMainColor(colIdx);
164 a->SetTubeR(0.016);
165 a->SetConeR(0.049);
166 a->SetConeL(0.170);
e930bdfa 167 AddElement(a);
168
169 ++j; ++jetid;
170 }
171 }
172
173 if (fRnrTracks)
174 {
175 UInt_t trackid = 0;
ff3111ab 176 std::vector<AliAODTrack>::iterator k = fTracks.begin();
e930bdfa 177 while (k != fTracks.end())
178 {
179 eta = k->Eta();
180 phi = k->Phi();
181 e = k->E();
9b6216c0 182 h = TMath::Log(e + 1.) * fEnergyScale;
ff3111ab 183
9b6216c0 184 if (e < 0)
185 {
186 Warning("CreateArrows()",
187 "Track %d has negative energy - NOT DISPLAYED.", trackid);
188 ++k; ++trackid;
189 continue;
190 }
191
e930bdfa 192 x = eta*(fEtaScale);
193 y = phi*(fPhiScale) - 350;
ff3111ab 194
9b6216c0 195 Int_t colBin = TMath::Min((Int_t) ((nCol-2)*TMath::Log(e + 1.)*TMath::Power(10., fEnergyColorScale)/(TMath::Log(eMax + 1.))),nCol-2);
196 Int_t colIdx = gStyle->GetColorPalette(colBin);
ff3111ab 197
9b6216c0 198 TEveArrow *a = new TEveArrow(0, 0 , h, x, y, 0);
e930bdfa 199 a->SetSourceObject(&*k);
200 a->SetElementName (Form("Track %d", trackid));
ff3111ab 201 a->SetElementTitle(Form("Track 4-momentum: %f, %f, %f, %f \n Pt-Eta-Phi values: %f, %f, %f",
9b6216c0 202 k->Px(), k->Py(), k->Pz(), e, k->Pt(), eta, phi ));
e930bdfa 203 a->SetPickable(kTRUE);
9b6216c0 204 a->SetMainColor(colIdx);
205 a->SetTubeR(0.015);
206 a->SetConeR(0.040);
207 a->SetConeL(0.130);
e930bdfa 208 AddElement(a);
209
210 ++k; ++trackid;
211 }
212 }
9b6216c0 213
214 if ( ! fSelConnected)
215 {
216 gEve->GetSelection()->Connect("SelectionAdded(TEveElement*)",
217 "AliEveJetPlane", this, "SelectionAdded(TEveElement*)");
218 fSelConnected = kTRUE;
219 }
220}
221
222/******************************************************************************/
223
ff3111ab 224
9b6216c0 225
226
227/******************************************************************************/
228
229void AliEveJetPlane::SelectionAdded(TEveElement* el)
230{
231 // Slot called when EVE selection gets a new element.
232
ff3111ab 233
234 if (fOneSelection)
9b6216c0 235 {
ff3111ab 236 if (HasChild(el))
237 {
238 printf("\n\nNOW SELECTED: %s\n", el->GetElementName());
239
240 TObject *src = el->GetSourceObject();
9b6216c0 241
ff3111ab 242 AliAODTrack *k = dynamic_cast<AliAODTrack*>(src);
243 AliAODJet *j = dynamic_cast<AliAODJet*> (src);
9b6216c0 244
ff3111ab 245 // printf ("Track %p --- Jet %p\n", (void*)t, (void*)j);
246 if (k) printf("Track 4-momentum: %f, %f, %f, %f \nPt-Eta-Phi values: %f, %f, %f \n",
247 k->Px(), k->Py(), k->Pz(), k->E(), k->Pt(), k->Eta(), k->Phi() );
9b6216c0 248
ff3111ab 249 if (j) printf("Jet 4-momentum: %f, %f, %f, %f \nPt-Eta-Phi values: %f, %f, %f \n",
250 j->Px(), j->Py(), j->Pz(), j->E(), j->Pt(), j->Eta(), j->Phi() );
251 }
9b6216c0 252 }
253
254 TEveSelection *sel = gEve->GetSelection();
ff3111ab 255 if (fTwoSelection && sel->NumChildren() == 2)
9b6216c0 256 {
ff3111ab 257 Int_t numvps = 0;
258 AliVParticle *vpart[2] = { 0 };
259 TEveElement *elmnt[2] = { 0 };
260
261 for (List_i i = sel->BeginChildren(); i != sel->EndChildren(); ++i)
9b6216c0 262 {
ff3111ab 263 if (HasChild(*i))
264 {
265 TEveElement *chld = *i;
266 TObject *src = chld->GetSourceObject();
267 AliVParticle *p = dynamic_cast<AliVParticle*>(src);
268
269 if (p != 0)
270 {
271 vpart[numvps] = p;
272 elmnt[numvps] = chld;
273 ++numvps;
274 if (numvps >= 2)
275 break;
276 }
277 }
278 }
9b6216c0 279
ff3111ab 280 Double_t eta0, eta1, phi0, phi1, d;
9b6216c0 281
ff3111ab 282 if (numvps == 2)
283 {
284 eta0 = vpart[0]->Eta();
285 eta1 = vpart[1]->Eta();
286 phi0 = vpart[0]->Phi();
287 phi1 = vpart[1]->Phi();
288
289 d = TMath::Sqrt(TMath::Power(eta1-eta0,2) + TMath::Power(phi1-phi0,2));
290 printf("\n\nNOW SELECTED: '%s' and '%s'\n",
291 elmnt[0]->GetElementName(), elmnt[1]->GetElementName());
292 printf("Eta-Phi Distance: %f\n", d);
9b6216c0 293 }
294 }
e930bdfa 295}
4673ff03 296
57ffa5fb 297/******************************************************************************/
4673ff03 298
d810d0de 299void AliEveJetPlane::ComputeBBox()
4673ff03 300{
a97abca8 301 // Calculate bounding-box.
302
4673ff03 303 BBoxInit();
304 BBoxCheckPoint(-350, -350, -20);
2ea57cb0 305 BBoxCheckPoint( 350, 350, 20);
4673ff03 306}
307
e930bdfa 308
d810d0de 309void AliEveJetPlane::Paint(Option_t* /*option*/)
4673ff03 310{
a97abca8 311 // Paint the object.
312
4673ff03 313 TBuffer3D buff(TBuffer3DTypes::kGeneric);
314
315 // Section kCore
316 buff.fID = this;
68ca2fe7 317 buff.fColor = GetMainColor();
318 buff.fTransparency = GetMainTransparency();
a15e6d7d 319 if (HasMainTrans()) RefMainTrans().SetBuffer3D(buff);
4673ff03 320 buff.SetSectionsValid(TBuffer3D::kCore);
321
322 Int_t reqSections = gPad->GetViewer3D()->AddObject(buff);
323 if (reqSections == TBuffer3D::kNone) {
d810d0de 324 // printf("AliEveJetPlane::Paint viewer was happy with Core buff3d.\n");
4673ff03 325 return;
326 }
327}