]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveDet/AliEveFMDLoader.cxx
Fixed a warning
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveFMDLoader.cxx
CommitLineData
274799f3 1/**************************************************************************
2 * Copyright(c) 2008, Christian Holm Christensen *
3 * *
4 * Author: Christian Holm Christensen. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation for any purposes is hereby granted without fee, *
9 * provided that the above copyright notice appears in all copies and *
10 * that both the copyright notice and this permission notice remains *
11 * intact. The authors make no claims about the suitability of this *
12 * software for any purpose. It is provided "as is" without express or *
13 * implied warranty. *
14 **************************************************************************/
15/* $Id$ */
16/** @file AliEveFMDLoader.cxx
17 @author Christian Holm Christensen <cholm@nbi.dk>
18 @date Sun Mar 26 17:59:18 2006
19 @brief Implementation of AliEveFMDLoader singleton class
20*/
21//____________________________________________________________________
22//
23// Forward Multiplicity Detector based on Silicon wafers. This class
24// is the loader for the event display.
25//
26// This class is a singleton, meaning that there's only one instance
27// of this. This is done to speed up the processing by putting all
28// things that are needed every time into the constructor.
29//
30#include "AliRunLoader.h"
31#include "EveBase/AliEveEventManager.h"
32#include "AliEveFMDLoader.h"
33#include "../FMD/AliFMDUShortMap.h"
34#include "../FMD/AliFMDBoolMap.h"
35#include "../FMD/AliFMDGeometry.h"
36#include "../FMD/AliFMDParameters.h"
37#include "../FMD/AliFMDDetector.h"
38#include "../FMD/AliFMDRing.h"
39#include "../FMD/AliFMDBaseDigit.h"
40#include "../FMD/AliFMDDigit.h"
41#include "../FMD/AliFMDRawReader.h"
42#include "../FMD/AliFMDHit.h"
43#include "AliESDEvent.h"
44#include "AliESDFMD.h"
45#include "AliLog.h"
46#include "AliRawReader.h"
47#include <TClonesArray.h>
48#include <TTree.h>
49#include <TGeoShape.h>
50#include <TGeoManager.h>
51#include <TEveGeoNode.h>
52#include <TEveBoxSet.h>
53#include <TEveQuadSet.h>
54#include <TEveManager.h>
55#include <TEveUtil.h>
56#include <TStyle.h>
57#include <TMath.h>
58#include <iostream>
59
60// Some very private variables.
61namespace
62{
63 const Char_t* kDetector = "FMD%d";
64 const Char_t* kRing = "FMD%d%c";
65 const Char_t* kModule = "FMD%d%c[%02d-%02d]";
66 const Char_t* kSector = "FMD%d%c[%02d] %s";
67
68 const Char_t* kHits = "Hits";
69 const Char_t* kDigits = "Digits";
70 const Char_t* kRaw = "Raw";
71 const Char_t* kESD = "ESD";
72
73}
74
75//____________________________________________________________________
76AliEveFMDLoader* AliEveFMDLoader::fgInstance = 0;
77
78//____________________________________________________________________
79AliEveFMDLoader* AliEveFMDLoader::Instance()
80{
81 // Get the singleton instance. If the instance has not been
82 // instantised yet, it will be after this call.
83 if (!fgInstance)
84 fgInstance = new AliEveFMDLoader();
85 return fgInstance;
86}
87
88//____________________________________________________________________
89AliEveFMDLoader::AliEveFMDLoader(const char* name, Bool_t useBoxes,
46e3ca9c 90 Bool_t /* old */)
274799f3 91 : TEveElementList(name, 0),
92 fHitPalette(0, 1000),
93 fDigitPalette(0, 1023),
94 fMultPalette(0, 20),
95 fUseBoxDigits(useBoxes),
96 fHitCache("AliFMDHit",0),
97 fDigitCache("AliFMDDigit", 0),
98 fRawCache("AliFMDDigit", 0)
99{
100 // Constructor
101 // Parameters:
102 // @param name Name of the folder.
103 // @param useBoxes Whether to use boxes or Quads for the signals
104 // @param old Whether to enable reading old RCU data format
105
106 // increase reference count
107 IncDenyDestroy();
108
109 // Increase reference counts on palettes
110 fHitPalette.IncRefCount();
111 fDigitPalette.IncRefCount();
112 fMultPalette.IncRefCount();
113
9f330d54 114
274799f3 115 // Initialize the FMD geometry manager
1c69419e 116 TGeoManager* geoMan = AliEveEventManager::AssertGeometry();
117 if (!geoMan) return;
118 geoMan->GetTopVolume()->cd(0);
119
274799f3 120 AliFMDGeometry* geom = AliFMDGeometry::Instance();
121 geom->Init();
122 geom->InitTransformations();
123
124 AliFMDParameters* pars = AliFMDParameters::Instance();
125 // pars->UseRcuTrailer(!old);
1c69419e 126 // pars->UseCompleteHeader(old);
127 // pars->SetSampleRate(4);
274799f3 128 pars->Init(kFALSE, 0);
129
130 // Get shapes
131 TGeoShape* inner = static_cast<TGeoShape*>(gGeoManager->GetListOfShapes()
d05d10dc 132 ->FindObject("FMDI_physical_sensor"));
274799f3 133 if (!inner) throw TEveException("Shape of inner type sensors not found");
134 TGeoShape* outer = static_cast<TGeoShape*>(gGeoManager->GetListOfShapes()
d05d10dc 135 ->FindObject("FMDO_physical_sensor"));
274799f3 136 if (!outer) throw TEveException("Shape of outer type sensors not found");
137
138 // Emulate reference counting
139 inner->SetUniqueID(1000);
140 outer->SetUniqueID(1000);
141
142 // Loop over detectors
143 for (UShort_t d = 1; d <= 3; d++) {
144 AliFMDDetector* detector = geom->GetDetector(d);
145 if (!detector) continue;
146 TEveElementList* ed = new TEveElementList(Form(kDetector,
147 detector->GetId()));
148 AddElement(ed);
149 ed->IncDenyDestroy();
150 ed->SetUserData(detector);
151
152 // Loop over rings
153 Char_t rings[] = { 'I', 'O', 0 };
154 Char_t* pr = &(rings[0]);
155 while (*pr) {
156 AliFMDRing* ring = detector->GetRing(*pr);
157 pr++;
158 if (!ring) continue;
159 TEveElementList* er = new TEveElementList(Form(kRing,
160 detector->GetId(),
161 ring->GetId()));
162 ed->AddElement(er);
163 er->IncDenyDestroy();
164 er->SetUserData(ring);
165
166 // UShort_t nsec = ring->GetNSectors();
167 // UShort_t nstr = ring->GetNStrips();
168 UShort_t nmod = ring->GetNModules();
169 // Loop over modules
170 for (UShort_t m = 0; m < nmod; m++) {
171 TEveGeoShape* em = new TEveGeoShape(Form(kModule,
172 detector->GetId(),
173 ring->GetId(),
174 2*m, 2*m+1));
175 er->AddElement(em);
176 em->SetTransMatrix(*(detector->FindTransform(ring->GetId(), 2*m)));
177 em->SetShape(ring->GetId() == 'I' ? inner : outer);
9f330d54 178 em->SetMainColor(Color_t(kRed));
274799f3 179 em->SetMainTransparency(32);
180 em->IncDenyDestroy();
181
182#if 0
183 for (UShort_t s = 2*m; s < 2*m+2 && s < nsec; s++) {
184 TEveDigitSet* eb = MakeDigitSet(Form(kSector,
185 detector->GetId(),
186 ring->GetId(), s), nstr);
187 em->AddElement(eb);
188 eb->SetEmitSignals(kFALSE);
189 eb->SetPickable(kTRUE);
190 // eb->SetOwnIds(kTRUE);
191 } // for (UShort_t s ...)
192#endif
193 } // for (UShort_t m ...)
194 } // while (pr)
195 } // for (UShort_t d ...)
196}
197
198//____________________________________________________________________
199AliEveFMDLoader::~AliEveFMDLoader()
200{
201 // Destructor
202 AliWarning("AliEveFMDLoader being destroyed!");
203}
204
205//____________________________________________________________________
206Int_t
207AliEveFMDLoader::RemoveFromListTrees(TEveElement* el)
208{
209 // Called when the element should be removed from the list. We
210 // overload this to allow clearing of signals.
211 // Parameters:
212 // @param el Tree to remove from.
213
214 // Since we're most likely setting up for a new event, we clear all
215 // signals here - a little tricky, but it works(tm).
216 ClearDigitSets("All");
217
218 // Do normal TEveElement::RemoveElement
219 return TEveElementList::RemoveFromListTrees(el);
220}
221//____________________________________________________________________
222void
223AliEveFMDLoader::RemoveParent(TEveElement* el)
224{
225 // Called when the element should be removed from the list. We
226 // overload this to allow clearing of signals.
227 // Parameters:
228 // @param el Parent to remove from.
229 TEveElementList::RemoveParent(el);
230}
231
232//____________________________________________________________________
233TEveDigitSet*
234AliEveFMDLoader::MakeDigitSet(const char* name, UShort_t nstr)
235{
236 // Make a digit set. The type of digit set depends on the setting
237 // of fUseBoxDigits. If this is true, we return a TEveBoxSet,
238 // otherwise a TEveQuadSet
239 // Parameters:
240 // name The name
241 // nstr The number of strips
242 // Return
243 // newly allocated digit set
244 TEveDigitSet* ret = 0;
245 if (fUseBoxDigits) {
246 TEveBoxSet* boxes = new TEveBoxSet(name);
247 // boxes->Reset(TEveBoxSet::kBT_AABox, kFALSE, nstr);
248 boxes->Reset(TEveBoxSet::kBT_FreeBox, kFALSE, nstr);
249 ret = boxes;
250 }
251 else {
252 TEveQuadSet* quads = new TEveQuadSet(name);
253 quads->Reset(TEveQuadSet::kQT_RectangleXY, kFALSE, nstr);
254 ret = quads;
255 }
256 return ret;
257}
258
259//____________________________________________________________________
260void
261AliEveFMDLoader::ClearDigitSets(const char* type)
262{
263 // Clear signals of some type.
264 // Parameters:
265 // @param type Type of signals to clear
266 // Type can be one of
267 // - All All signals
268 // - Hits Hits
269 // - Digits Digits
270 // - Raw Raw
271 // - ESD ESD
272 TString stype(type);
273
274 for (TEveElement::List_i di = BeginChildren();
275 di != EndChildren(); ++di) {
276 for (TEveElement::List_i ri = (*di)->BeginChildren();
277 ri != (*di)->EndChildren(); ++ri) {
278 for (TEveElement::List_i mi = (*ri)->BeginChildren();
279 mi != (*ri)->EndChildren(); ++mi) {
280 if (stype == "All") {
281 (*mi)->RemoveElements();
282 continue;
283 }
284 for (TEveElement::List_i si = (*mi)->BeginChildren();
285 si != (*mi)->EndChildren(); ++si) {
286 TEveDigitSet* signals = static_cast<TEveDigitSet*>((*si));
287 if (!signals) continue;
288 TString s(signals->GetName());
289 if (!s.Contains(type)) continue;
290 (*mi)->RemoveElement(signals);
291 }
292 }
293 }
294 }
295}
296
297//____________________________________________________________________
298TEveDigitSet*
299AliEveFMDLoader::FindDigitSet(const char* t, UShort_t d, Char_t r, UShort_t s)
300{
301 // Find a digit set corresponding to the passed parameters. If it
302 // is not found, one is created
303 // Parameters:
304 // @param type Type of data
305 // @param d Detector
306 // @param r Ring
307 // @param s Sector
308 // @return a digit set
309 TEveElement* detector = FindChild(Form(kDetector, d));
310 if (!detector) {
311 AliError(Form("Detector %s not found", Form(kDetector, d)));
312 return 0;
313 }
314
315 TEveElement* ring = detector->FindChild(Form(kRing, d, r));
316 if (!ring) {
317 AliError(Form("Ring %s not found", Form(kRing, d, r)));
318 return 0;
319 }
320
321 Int_t mod = 2*(s/2);
322 TEveElement* module = ring->FindChild(Form(kModule, d, r, mod, mod+1));
323 if (!module) {
324 AliError(Form("Module %s not found", Form(kModule, d, r, s, s+1)));
325 return 0;
326 }
327
328 TEveElement* sector = module->FindChild(Form(kSector, d, r, s, t));
329 TEveDigitSet* signal = static_cast<TEveDigitSet*>(sector);
330 if (!sector) {
331 AliFMDRing* rng = AliFMDGeometry::Instance()->GetRing(r);
332 signal = MakeDigitSet(Form(kSector, d, r, s, t), rng->GetNStrips());
333 module->AddElement(signal);
334 signal->SetEmitSignals(kFALSE);
335 signal->SetPickable(kTRUE);
336 TString st(t);
337 if (t == kHits) signal->SetPalette(&fHitPalette);
338 else if (t == kDigits) signal->SetPalette(&fDigitPalette);
339 else if (t == kRaw) signal->SetPalette(&fDigitPalette);
340 else if (t == kESD) {
341 signal->SetPalette(&fMultPalette);
342 signal->SetOwnIds(kTRUE);
343 }
344 }
345 return signal;
346}
347
348//____________________________________________________________________
349void
350AliEveFMDLoader::AddSignal(const char* t,
351 UShort_t det, Char_t rng, UShort_t sec,
352 UShort_t str, Float_t signal, Float_t min,
353 Float_t max, TObject* ref)
354{
355 // Add a signal to a digit set
356 // Parameters:
357 // @param type Type of data
358 // @param det Detector
359 // @param rng Ring
360 // @param sec Sector
361 // @param str Strip
362 // @param signal Signal value
363 // @param min Minimum of this kind of signal
364 // @param max Maximum of this kind of signal
365 // @param ref Reference object
366 AliFMDGeometry* geom = AliFMDGeometry::Instance();
367 Double_t x, y, z;
368 geom->Detector2XYZ(det, rng, sec, str, x, y, z);
369 AddSignal(t, det, rng, sec, str, x, y, z, signal, min, max, ref);
370}
371
372//____________________________________________________________________
373void
374AliEveFMDLoader::AddSignal(const char* t,
375 UShort_t det, Char_t rng, UShort_t sec,
376 UShort_t str, Double_t x, Double_t y, Double_t z,
377 Float_t signal, Float_t min, Float_t max,
378 TObject* ref)
379{
380 // Add a signal to a digit set, with known (x,y,z) coordinates
381 // (this is for hits)
382 // Parameters:
383 // @param type Type of data
384 // @param det Detector
385 // @param rng Ring
386 // @param sec Sector
387 // @param str Strip
388 // @param x X coordinate
389 // @param y Y coordinate
390 // @param z Z coordinate
391 // @param signal Signal value
392 // @param min Minimum of this kind of signal
393 // @param max Maximum of this kind of signal
394 // @param ref Reference object
395 AliFMDGeometry* geom = AliFMDGeometry::Instance();
396 AliFMDRing* ring = geom->GetRing(rng);
397 if (!ring) return;
398
399 TEveDigitSet* signals = FindDigitSet(t, det, rng, sec);
400 if (!signals) {
401 AliWarning(Form("No signal (%s) found for FMD%d%c[%02d,%03d]",
402 t, det, rng, sec, str));
403 return;
404 }
405
406 Float_t scaled = TMath::Min((signal - min) / (max - min) * 10., 10.);
407 Double_t w = 2*ring->GetPitch();
408 Int_t value = int(TMath::Nint(signal));
409 AliDebug(1, Form("New signal at FMD%d%c[%02d,%03d]=%f (v=%d, s=%f)",
410 det, rng, sec, str, signal, value, scaled));
411 AddDigit(signals, x, y, z, w, scaled, value, ref);
412}
413
414//____________________________________________________________________
415void
416AliEveFMDLoader::AddDigit(TEveDigitSet* signals,
417 Double_t x, Double_t y, Double_t z,
418 Double_t w, Float_t scaled, Int_t value,
419 TObject* ref)
420{
421 // Add a digit to a digit set.
422 // Parameters:
423 // @param signals Digit set.
424 // @param x X coordinate
425 // @param y Y coordinate
426 // @param z Z coordinate
427 // @param w strip pitch
428 // @param scaled Scaled value
429 // @param value Signal value
430 // @param ref Reference object
431 if (fUseBoxDigits) {
432 TEveBoxSet* boxes = static_cast<TEveBoxSet*>(signals);
433 Float_t zc = (z > 0 ? -1 : 1) * scaled + z;
434 Float_t vs[] = { -w, -5*w, zc-scaled, // Lower back left
435 +w, -5*w, zc-scaled, // Lower back right
436 +w, +5*w, zc-scaled, // Lower front right
437 -w, +5*w, zc-scaled, // Lower front left
438 -w, -5*w, zc+scaled, // Upper back left
439 +w, -5*w, zc+scaled, // Upper back right
440 +w, +5*w, zc+scaled, // Upper front right
441 -w, +5*w, zc+scaled }; // Upper front left
442 Float_t ang = TMath::ATan2(y,x);
443 for (size_t i = 0; i < 8; i++) {
444 Float_t bx = vs[3*i+0];
445 Float_t by = vs[3*i+1];
446 Float_t ca = TMath::Cos(ang);
447 Float_t sa = TMath::Sin(ang);
448 vs[3*i+0] = bx * ca - by * sa + x;
449 vs[3*i+1] = bx * sa + by * ca + y;
450 }
451 // boxes->AddBox(x, y, (z > 0 ? -scaled : 0) + z , 5*w, w, scaled);
452 boxes->AddBox(vs);
453 boxes->DigitValue(value);
454 if (ref) boxes->DigitId(ref);
455 }
456 else {
457 TEveQuadSet* quads = static_cast<TEveQuadSet*>(signals);
458 quads->AddQuad(x,y,z,w,w);
459 quads->QuadValue(value);
460 if (ref) quads->QuadId(ref);
461 }
462}
463
464
465//____________________________________________________________________
466void
467AliEveFMDLoader::CheckAdd()
468{
469 // check if we shoul re-add ourselves to the current event node
470 TEveElement* event = gEve->GetCurrentEvent();
471 if (event && event->FindChild(GetName())) return;
472 gEve->AddElement(this);
473}
474
475
476//____________________________________________________________________
477void
478AliEveFMDLoader::LoadHits()
479{
480 // Load and display hits
481 ClearDigitSets(kHits);
482
483 AliRunLoader* rl = AliEveEventManager::AssertRunLoader();
484 if (!rl) {
485 AliError("No run loader");
486 return;
487 }
488
489 rl->LoadHits("FMD");
490 TTree* ht = rl->GetTreeH("FMD", false);
491 if (!ht) {
492 AliError("No FMD tree");
493 return;
494 }
495
496 TClonesArray* hits = &fHitCache;
497 fHitCache.Clear();
498 ht->SetBranchAddress("FMD", &hits);
499
500 Float_t min = fHitPalette.GetMinVal();
501 Float_t max = fHitPalette.GetMaxVal();
502
503 Int_t nTracks = ht->GetEntriesFast();
504 for (Int_t i = 0; i < nTracks; i++) {
505 Int_t hitRead = ht->GetEntry(i);
506 if (hitRead <= 0) continue;
507
508 Int_t nHit = hits->GetEntriesFast();
509 if (nHit <= 0) continue;
510
511 for (Int_t j = 0; j < nHit; j++) {
512 AliFMDHit* hit = static_cast<AliFMDHit*>(hits->At(j));
513 if (!hit) continue;
514
515 AddSignal(kHits,
516 hit->Detector(), hit->Ring(), hit->Sector(), hit->Strip(),
517 hit->X(), hit->Y(), hit->Z(), int(hit->Edep()*1000),
518 min, max, hit);
519 }
520 }
521 CheckAdd();
522}
523
524//____________________________________________________________________
525void
526AliEveFMDLoader::DoLoadDigits(const char* t, TClonesArray* digits)
527{
528 // Do the actual display of digits
529 // Parameters:
530 // @param type What to show
531 // @param digits The digits
532 Float_t min = fDigitPalette.GetMinVal();
533 Float_t max = fDigitPalette.GetMaxVal();
534
535 Int_t n = digits->GetEntriesFast();
536 for (Int_t i = 0; i < n; i++) {
537 AliFMDDigit* digit = static_cast<AliFMDDigit*>(digits->At(i));
538 if (!digit) return;
539 AddSignal(t, digit->Detector(), digit->Ring(), digit->Sector(),
540 digit->Strip(), digit->Counts(), min, max, digit);
541 }
542 CheckAdd();
543}
544
545//____________________________________________________________________
546void
547AliEveFMDLoader::LoadDigits()
548{
549 // Load and display simulated digits
550 ClearDigitSets(kDigits);
551
552 AliRunLoader* rl = AliEveEventManager::AssertRunLoader();
553 if (!rl) {
554 AliError("No run-loader");
555 return;
556 }
557
558 rl->LoadDigits("FMD");
559 TTree* dt = rl->GetTreeD("FMD", false);
560 if (!dt) {
561 AliError("No FMD tree");
562 return;
563 }
564
565 TClonesArray* digits = &fDigitCache;
566 fDigitCache.Clear();
567 dt->SetBranchAddress("FMD", &digits);
568
569 Int_t read = dt->GetEntry(0);
570 if (read <= 0) {
571 AliWarning("Nothing read");
572 return;
573 }
574 DoLoadDigits(kDigits, digits);
575}
576
577
578//____________________________________________________________________
579void
580AliEveFMDLoader::LoadRaw()
581{
582 // Load and display raw digits
583 ClearDigitSets(kRaw);
584
585 AliRawReader* rr = AliEveEventManager::AssertRawReader();
586 if (!rr) {
587 AliError("No raw-reader");
588 return;
589 }
590 rr->Reset();
591 std::cout<<"Now in event # " << *(rr->GetEventId()) << std::endl;
592 AliFMDRawReader* fr = new AliFMDRawReader(rr, 0);
593 TClonesArray* digits = &fRawCache;
594 fRawCache.Clear();
595
596 fr->ReadAdcs(digits);
597
598 DoLoadDigits(kRaw, digits);
599}
600
601//____________________________________________________________________
602void
603AliEveFMDLoader::LoadESD()
604{
605 // Load and display ESD information
606 ClearDigitSets(kESD);
607
608 AliESDEvent* esd = AliEveEventManager::AssertESD();
609 if (!esd) {
610 AliError("No ESD");
611 return;
612 }
613
614 AliESDFMD* fmd = esd->GetFMDData();
615 if (!fmd) {
616 AliError("No FMD ESD data");
617 return;
618 }
619
620 Float_t min = fMultPalette.GetMinVal();
621 Float_t max = fMultPalette.GetMaxVal();
622
623 for (UShort_t det = 1; det <= 3; det++) {
624 Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
625 for (Char_t* rng = rings; *rng != '\0'; rng++) {
626 UShort_t nsec = (*rng == 'I' ? 20 : 40);
627 UShort_t nstr = (*rng == 'I' ? 512 : 256);
628 for (UShort_t sec = 0; sec < nsec; sec++) {
629 for (UShort_t str = 0; str < nstr; str++) {
630 Float_t mult = fmd->Multiplicity(det,*rng,sec,str);
631 if (mult == AliESDFMD::kInvalidMult) continue;
632 Float_t eta = fmd->Eta(det,*rng,sec,str);
633 AddSignal(kESD, det, *rng, sec, str, mult, min, max,
634 new TNamed(Form("FMD%d%c[%02d,%03d]", det, *rng, sec, str),
635 Form("Mch=%f, eta=%f", mult, eta)));
636 }
637 }
638 }
639 }
640 CheckAdd();
641}
642
643
644
645
646
647
648//____________________________________________________________________
649//
650// EOF
651//