source: JEM-EUSO/esaf_lal/tags/v1_r0/esaf/packages/common/eventviewer/src/EFocalSurface3DPainter.cc @ 117

Last change on this file since 117 was 117, checked in by moretto, 11 years ago

ESAF version compilable on mac OS

File size: 14.1 KB
Line 
1// $Id: EFocalSurface3DPainter.cc 2846 2010-04-18 06:09:05Z fenu $
2// Author: Alessandro Thea   2005/07/13
3
4/*****************************************************************************
5 * ESAF: Euso Simulation and Analysis Framework                              *
6 *                                                                           *
7 *  Id: EFocalSurface3DPainter                                               *
8 *  Package: <packagename>                                                   *
9 *  Coordinator: <coordinator>                                               *
10 *                                                                           *
11 *****************************************************************************/
12
13//_____________________________________________________________________________
14//
15// EFocalSurface3DPainter
16//
17// <extensive class description>
18//
19//   Config file parameters
20//   ======================
21//
22//   <parameter name>: <parameter description>
23//   -Valid options: <available options>
24//
25
26#include "EFocalSurface3DPainter.hh"
27
28#include "EEvent.hh"
29#include "EDetector.hh"
30#include "ERunParameters.hh"
31#include "EFee.hh"
32#include "EPmtData.hh"
33#include "ESystemOfUnits.hh"
34#include "Etypes.hh"
35
36#include <map>
37#include <TPolyMarker3D.h>
38#include <TPolyLine3D.h>
39#include <TMath.h>
40#include <TView.h>
41#include <TGaxis.h>
42#include <TAxis3D.h>
43#include <TLatex.h>
44#include <TPad.h>
45#include <TPave.h>
46#include <ConfigFileParser.hh>
47#include <Config.hh>
48
49ClassImp(EFocalSurface3DPainter)
50
51using namespace std;
52using namespace sou;
53using namespace TMath;
54
55//_____________________________________________________________________________
56EFocalSurface3DPainter::EFocalSurface3DPainter() {
57    //
58    // Constructor
59    //
60        ConfigFileParser* pConf = Config::Get()->GetCF("Electronics","MacroCell");
61        Double_t fGTU = pConf->GetNum("MacroCell.fGtuTimeLength");
62        fGTU/=1000.;
63
64    Constructor();
65}
66
67//_____________________________________________________________________________
68EFocalSurface3DPainter::EFocalSurface3DPainter( EEvent* ev ) {
69    //
70    // Constructor
71    //
72
73    Constructor();
74    Load(ev);
75}
76//_____________________________________________________________________________
77EFocalSurface3DPainter::EFocalSurface3DPainter( EDetector* det, ERunParameters* runpars ) {
78    //
79    // Constructor
80    //
81
82    Constructor();
83    Load(det, runpars);
84}
85//_____________________________________________________________________________
86EFocalSurface3DPainter::~EFocalSurface3DPainter() {
87    //
88    // Destructor
89    //
90
91    Clear();
92    SafeDelete(fSignals);
93    SafeDelete(fHits);
94    SafeDelete(fPixels);
95}
96
97//______________________________________________________________________________
98void EFocalSurface3DPainter::Constructor() {
99    //
100    //
101    //
102
103    fDetector = 0;
104    fRunPars = 0;
105
106    fAlpha           = 2.;
107    fMarkerStyle     = 20;
108    fMaxMarkerSize   = 2.;
109    fMinMarkerSize   = .3;
110    fMinMarkerColor  = 51;
111    fNumMarkerColors = 50;
112    fBackgroundColor = kBlack; 
113    fLabelColor      = kWhite; 
114    fPixelColor = kWhite; 
115   
116    fDrawCode = kCodeHits;
117   
118    fNumMarkers     = 0;
119    fNumPixels      = 0;
120
121    fSignals = new TObjArray;
122    fHits = new TObjArray;
123    fPixels = new TObjArray;
124
125    fXmin = fXmax = fYmin = fYmax = fTmin = fTmax = 0;
126    fCmin = fCmax = 0;
127
128    Int_t ndiv = 7;
129    fAxis3D = new TAxis3D;
130    fAxis3D->SetNdivisions(ndiv,"X");
131    fAxis3D->SetNdivisions(ndiv,"Y");
132    fAxis3D->SetXTitle("x [mm]");
133    fAxis3D->SetYTitle("y [mm]");
134    fAxis3D->SetZTitle("t [#mus]");
135    fAxis3D->GetXaxis()->SetTitleColor(fLabelColor);
136    fAxis3D->GetXaxis()->SetTitleOffset(1.5);
137    fAxis3D->GetXaxis()->SetTitleFont(42);
138    fAxis3D->GetXaxis()->SetLabelFont(52);
139    fAxis3D->GetYaxis()->SetTitleColor(fLabelColor);
140    fAxis3D->GetYaxis()->SetTitleOffset(1.5);
141    fAxis3D->GetYaxis()->SetTitleFont(42);
142    fAxis3D->GetYaxis()->SetLabelFont(52);
143    fAxis3D->GetZaxis()->SetTitleColor(fLabelColor);
144    fAxis3D->GetZaxis()->SetTitleOffset(1.5);
145    fAxis3D->GetZaxis()->SetTitleFont(42);
146    fAxis3D->GetZaxis()->SetLabelFont(52);
147
148    fLabel = new TLatex;
149    fLabel->SetNDC();
150    fLabel->SetTextColor(fLabelColor);
151    fLabel->SetTextFont(42);
152
153    fAxis = new TGaxis;
154    fAxis->SetLineColor(fLabelColor);
155    fAxis->SetLineWidth(2);
156    fAxis->SetLabelColor(fLabelColor);
157    fAxis->SetLabelFont(52);
158    fAxis->SetTitle("Counts");
159    fAxis->SetTitleOffset(0.);
160    fAxis->SetTextColor(fLabelColor);
161    fAxis->SetTextFont(52);
162
163}
164
165//______________________________________________________________________________
166void EFocalSurface3DPainter::Clear( Option_t* opt  ) {
167    //
168    // Clear
169    //
170
171    if ( fSignals ) fSignals->Clear();
172    if ( fHits ) fHits->Delete();
173    if ( fPixels ) fPixels->Delete();
174}
175
176//______________________________________________________________________________
177void EFocalSurface3DPainter::Load( EEvent* ev ) {
178
179    if ( !ev ) {
180        Info("EFocalSurface3DPainter","Event is not defined. Painter made zombie.");
181        MakeZombie();
182        return;
183    }
184   
185    Load(ev->GetDetector(), ev->GetRunPars());
186}
187
188//______________________________________________________________________________
189void EFocalSurface3DPainter::Load( EDetector* det, ERunParameters* runpars) {
190
191    if ( !det || !runpars ) {
192        Info("EFocalSurface3DPainter","Either Event or RunParameters is not defined. Painter made zombie.");
193        MakeZombie(); 
194        return;
195    }
196
197    fDetector = det;
198    fRunPars = runpars;
199
200    Int_t numPoints = 0;
201    fCmax = -kMaxInt;
202    fCmin =  kMaxInt;
203    Double_t thres = 0;
204    fMeanThres = 0;
205
206    std::map<Int_t,Int_t> pixels;
207    TPolyLine3D* px;
208
209   if ( !fDetector->GetNumFee() ) {
210        Info("Load","No EFee in EDetector object. Painter made zombie.");
211        MakeZombie();
212        return;
213    }
214
215    for(Int_t i(0); i<det->GetNumFee(); i++) {
216        EFee *dfee = det->GetFee(i);
217        Int_t uid =  dfee->GetChUId();
218        Double_t rate = runpars->GetNightGlowRateByUId(uid)/microsecond
219            *runpars->GetPmtData().GetGtuLength();
220
221        Int_t nCounts;
222        switch ( fDrawCode ) {
223            case kCodeSigs:
224                thres = 0;
225                nCounts = dfee->GetNumSignals();
226                break;
227            case kCodeHits:
228            default:
229                thres = rate+fAlpha*Sqrt(rate);
230                nCounts = dfee->GetNumHits()-Nint(Ceil(thres));
231                break;
232        }
233        fMeanThres += thres/det->GetNumFee();
234
235        if ( nCounts > 0 ) {
236
237            numPoints++;
238
239            fCmin = Min(fCmin,nCounts);
240            fCmax = Max(fCmax,nCounts);
241
242            if ( !pixels.count(uid) )
243                pixels[uid] = 0;
244
245
246
247            pixels[uid] += nCounts;
248        }
249    }
250
251    TPolyMarker3D* p;// = new TPolyMarker3D(numSig);
252
253    fXmin = fYmin = fTmin = kHuge;
254    fXmax = fYmax = fTmax = -kHuge;
255
256
257    TVector3 pos;
258    for(Int_t i(0); i<det->GetNumFee(); i++) {
259        EFee *dfee = det->GetFee(i);
260        Int_t uid =  dfee->GetChUId();
261        Double_t rate = runpars->GetNightGlowRateByUId(uid)/microsecond
262            *runpars->GetPmtData().GetGtuLength();
263
264        Int_t nCounts, nSignals;
265        switch ( fDrawCode ) {
266            case kCodeSigs:
267                thres = 0;
268                nCounts = nSignals = dfee->GetNumSignals();
269                break;
270            case kCodeHits:
271            default:
272                thres = rate+fAlpha*Sqrt(rate);
273                nCounts = dfee->GetNumHits()-Nint(Ceil(thres));
274                nSignals = dfee->GetNumSignals();
275                break;
276        }
277
278        if ( nCounts > 0 ) {
279            Double_t time =  fGTU*dfee->GetGtu();
280            pos = runpars->PixelCenter(uid);
281
282            p = new TPolyMarker3D(1,fMarkerStyle);
283            p->SetPoint(0,pos.X(),pos.Y(),time);
284            fHits->Add(p);
285            if ( nSignals )
286                fSignals->Add(p);
287
288
289
290            Float_t size = fMinMarkerSize+(fMaxMarkerSize-fMinMarkerSize)*
291                (nCounts-fCmin)/(Float_t)(fCmax-fCmin);
292            Color_t color = (Color_t)(fMinMarkerColor+((fNumMarkerColors-1)*
293                        (nCounts-fCmin)/(Float_t)(fCmax-fCmin)));
294
295            p->SetMarkerSize(size);
296            p->SetMarkerColor(color);
297
298            fXmin = Min(fXmin, pos.X());
299            fYmin = Min(fYmin, pos.Y());
300            fTmin = Min(fTmin, time);
301            fXmax = Max(fXmax, pos.X());
302            fYmax = Max(fYmax, pos.Y());
303            fTmax = Max(fTmax, time);
304        }
305    }
306
307    map<Int_t,Int_t>::iterator it;
308    for(it = pixels.begin(); it != pixels.end(); it++){
309
310        Double_t x[5], y[5], z[5];
311        for(Int_t iCorner(0); iCorner<4; iCorner++){
312            TVector3 dummy = runpars->PixelCorner(it->first,iCorner);
313            x[iCorner] = dummy.X();
314            y[iCorner] = dummy.Y();
315            z[iCorner] = fTmin;
316
317        }
318        x[4] = x[0];
319        y[4] = y[0];
320        z[4] = z[0];
321
322        px = new TPolyLine3D(5,x,y,z);
323        px->SetBit(kCanDelete);
324        px->SetLineColor(fPixelColor);
325        fPixels->Add(px);
326    }
327
328    const EPmtData& data = fRunPars->GetPmtData();
329
330    if ((fXmax-fXmin) < data.GetPadSide()) {
331        Double_t x = (fXmax-fXmin)/2.;
332        fXmax = x+data.GetPadSide();
333        fXmin = x-data.GetPadSide();
334    }
335
336    if ((fYmax-fYmin) < data.GetPadSide()) {
337        Double_t y = (fYmax-fYmin)/2.;
338        fYmax= y+data.GetPadSide();
339        fYmin = y-data.GetPadSide();
340    }
341
342    if ((fTmax-fTmin) < data.GetGtuLength()/microsecond) {
343        Double_t t = (fTmax-fTmin)/2.;
344        fTmax = t+data.GetGtuLength()/microsecond;
345        fTmin = t-data.GetGtuLength()/microsecond;
346    }
347
348}
349
350
351
352//______________________________________________________________________________
353void EFocalSurface3DPainter::Draw( Option_t* option ) {
354   
355    TString opt(option);
356
357   Bool_t has_pad = (gPad==0)?kFALSE:kTRUE;
358    if (!gPad) {
359#if ( ROOT_VERSION_CODE <= ROOT_VERSION(5,16,00) )
360        if (!gROOT->GetMakeDefCanvas()) return;
361        (gROOT->GetMakeDefCanvas());
362#else
363        if (!gROOT->MakeDefCanvas()) return;
364        (gROOT->MakeDefCanvas());
365#endif
366    }
367
368    if ( !opt.Contains("same")) gPad->Clear();
369
370    AppendPad(option);
371
372    TView *view = gPad->GetView();
373    if (!view) {
374#if ( ROOT_VERSION_CODE <= ROOT_VERSION(5,16,00) )
375        view = new TView(11);
376#else
377        view =TView::CreateView(1);
378#endif
379//        view->SetAutoRange(kTRUE);
380//        Paint("range");
381//        view->SetAutoRange(kFALSE);
382    }
383
384    view->SetRange(fXmin,fYmin,fTmin,fXmax,fYmax,fTmax);
385    gPad->SetFillColor(fBackgroundColor);
386
387    if ( has_pad) gPad->Modified();
388
389    if (!view->IsPerspective()) view->SetPerspective();
390
391//    fAxis3D->Draw();
392
393}
394//______________________________________________________________________________;
395void EFocalSurface3DPainter::Paint( Option_t* ) {
396
397    if ( IsModified() ) Update();
398   
399    TView *view = gPad->GetView();
400    if (!view) {
401#if ( ROOT_VERSION_CODE <= ROOT_VERSION(5,16,00) )
402        view = new TView(11);
403#else
404        view =TView::CreateView(1);
405#endif
406//        view->SetAutoRange(kTRUE);
407//        Paint("range");
408//        view->SetAutoRange(kFALSE);
409        view->SetRange(fXmin,fYmin,fTmin,fXmax,fYmax,fTmax);
410        if (!view->IsPerspective()) view->SetPerspective();
411
412    }
413
414    // background
415    TPave pave;
416    pave.SetBorderSize(0);
417    pave.SetFillColor(fBackgroundColor);
418    pave.PaintPave(gPad->GetUxmin(),gPad->GetUymin(),gPad->GetUxmax(),gPad->GetUymax());
419    gPad->SetFillColor(fBackgroundColor);
420
421    TIter nextPx(fPixels); 
422    TIter nextMk(fHits); 
423
424       
425    while ( TPolyLine3D* obj = (TPolyLine3D*)nextPx()) {
426        obj->SetLineColor(fPixelColor);
427        obj->Paint();
428    }
429    while ( TPolyMarker3D* obj = (TPolyMarker3D*)nextMk()) {
430        obj->SetMarkerStyle(fMarkerStyle);
431        obj->Paint();
432    }
433
434    fLabel->SetTextColor(fLabelColor);
435    fLabel->SetTextFont(42);
436    switch ( fDrawCode ) {
437        case kCodeSigs:
438            fLabel->SetText(0.05,0.05,"Signal only");
439            fLabel->Paint();
440            break;
441        case kCodeHits:
442        default:
443            fLabel->SetText(0.05,0.05,Form("Average Treshold %.3f",fMeanThres));
444            fLabel->Paint();
445            break;
446    }
447
448
449    Double_t pXmin = 0.83*(gPad->GetUxmax()-gPad->GetUxmin())+gPad->GetUxmin(); 
450    Double_t pXmax = 0.88*(gPad->GetUxmax()-gPad->GetUxmin())+gPad->GetUxmin();
451    Double_t pYmin = 0.1*(gPad->GetUymax()-gPad->GetUymin())+gPad->GetUymin(); 
452    Double_t pYmax = 0.9*(gPad->GetUymax()-gPad->GetUymin())+gPad->GetUymin();
453
454    Double_t cmin, cmax;
455    cmin = fCmin;
456    cmax = fCmax;
457    Int_t ndiv = 10;
458
459    fAxis->SetLineColor(fLabelColor);
460    fAxis->SetTitleColor(fLabelColor);
461    fAxis->SetLabelColor(fLabelColor);
462    fAxis->PaintAxis(pXmax,pYmin,pXmax,pYmax,cmin,cmax,ndiv,"+L");
463
464    Float_t w = (pXmax-pXmin);
465    Float_t h = (pYmax-pYmin)/fNumMarkerColors;
466
467    for( Int_t i(0); i < fNumMarkerColors; i++) {
468        pave.SetFillColor(i+fMinMarkerColor); 
469        pave.PaintPave(pXmax-w,pYmin+i*h,pXmax,pYmin+(i+1)*h,0);
470    }
471
472    fAxis3D->GetXaxis()->SetTitleColor(fLabelColor);
473    fAxis3D->GetXaxis()->SetTitleOffset(1.5);
474    fAxis3D->GetXaxis()->SetTitleFont(42);
475    fAxis3D->GetXaxis()->SetLabelFont(52);
476    fAxis3D->GetYaxis()->SetTitleColor(fLabelColor);
477    fAxis3D->GetYaxis()->SetTitleOffset(1.5);
478    fAxis3D->GetYaxis()->SetTitleFont(42);
479    fAxis3D->GetYaxis()->SetLabelFont(52);
480    fAxis3D->GetZaxis()->SetTitleColor(fLabelColor);
481    fAxis3D->GetZaxis()->SetTitleOffset(1.5);
482    fAxis3D->GetZaxis()->SetTitleFont(42);
483    fAxis3D->GetZaxis()->SetLabelFont(52);
484
485    fAxis3D->Paint();
486
487
488}
489
490
491//______________________________________________________________________________
492void EFocalSurface3DPainter::Update() {
493    Clear();
494    Load( fDetector, fRunPars );
495
496    Modified(kFALSE);
497}
498
499//______________________________________________________________________________
500Int_t EFocalSurface3DPainter::DistancetoPrimitive(Int_t px, Int_t py) {
501    //
502    //
503    //
504   
505    Int_t dist = 999999;
506
507    TIter nextMk(fSignals);
508    while(TObject* obj = nextMk() )
509        dist = Min(dist,obj->DistancetoPrimitive(px,py));
510
511    TIter nextPx(fPixels);
512    while(TObject* obj = nextPx() )
513        dist = Min(dist,obj->DistancetoPrimitive(px,py));
514   
515    return dist;
516}
517
Note: See TracBrowser for help on using the repository browser.