#include "EDetectorPhotonsPainter.hh"
#include "EDetPhoton.hh"
#include "Etypes.hh"
#include "TMath.h"
#include "TPad.h"
#include "TView.h"
#include "TPolyMarker3D.h"
#include "TAxis3D.h"
#include "TStyle.h"
#include "Riostream.h"
#include <TBuffer3D.h>
#include <TCanvas.h>
#include <TPaveText.h>
#include <map>
#include <vector>
using namespace TMath;
ClassImp(EDetectorPhotonsPainter)
//_____________________________________________________________________________
EDetectorPhotonsPainter::EDetectorPhotonsPainter( EDetector *detector ) : fDetector(detector),fXmin(0),fXmax(0),fYmin(0),fYmax(0),fZmin(0),fZmax(0) {
//
// Constructor
//
BuildPoints();
}
//_____________________________________________________________________________
EDetectorPhotonsPainter::~EDetectorPhotonsPainter() {
//
// Destructor
//
}
//______________________________________________________________________________
void EDetectorPhotonsPainter::BuildPoints() {
//
// Show photons in detector
//
if (fDetector->GetNumPhotons() < 1) {
Info("DrawOptics()","No photons loaded.");
return;
}
map < Int_t, vector<Int_t> > histories;
EPhoton *ph = fDetector->GetPhoton(0);
fXmin = fXmax = ph->GetPos().X();
fYmin = fYmax = ph->GetPos().Y();
fZmin = fZmax = ph->GetPos().Z();
for (Int_t k = 0; k < fDetector->GetNumPhotons(); k++) {
EDetPhoton *ph = fDetector->GetPhoton(k);
histories[ph->GetHistory()].push_back(k);
fXmin = Min(fXmin,ph->GetPos().X());
fXmax = Max(fXmax,ph->GetPos().X());
fYmin = Min(fYmin,ph->GetPos().Y());
fYmax = Max(fYmax,ph->GetPos().Y());
fZmin = Min(fZmin,ph->GetPos().Z());
fZmax = Max(fZmax,ph->GetPos().Z());
}
Int_t ncolor = 0;
map < Int_t, vector<Int_t> >::const_iterator i;
for (i = histories.begin(); i != histories.end(); i++){
Int_t color = 51+(Int_t)(ncolor++*49/(histories.size()-1));
fPoints[i->first] = new TPolyMarker3D(i->second.size()*3,fMarkerStyle,"");
for ( UInt_t k(0); k < i->second.size(); k++) {
EPhoton *ph = fDetector->GetPhoton(i->second[k]);
fPoints[i->first]->SetPoint(k,ph->GetPos().X(),ph->GetPos().Y(),ph->GetPos().Z());
}
fPoints[i->first]->SetMarkerColor(color);
}
}
//______________________________________________________________________________
void EDetectorPhotonsPainter::Draw( Option_t* option ) {
//
//
//
Bool_t has_pad = (gPad==0)?kFALSE:kTRUE;
if (!gPad) {
if (!gROOT->GetMakeDefCanvas()) return;
(gROOT->GetMakeDefCanvas())();
}
AppendPad(option);
// Create a 3-D view
TView *view = gPad->GetView();
if (!view) {
view = new TView(11);
#if ( ROOT_VERSION_CODE <= ROOT_VERSION(4,03,02) )
view->SetAutoRange(kTRUE);
TBuffer3D *buff = gPad->GetBuffer3D();
buff->fOption = TBuffer3D::kRANGE;
Paint("range");
buff->fOption = TBuffer3D::kPAD;
view->SetAutoRange(kFALSE);
#endif // ROOT_VERSION_CODE <= ROOT_VERSION(4,03,02)
if (has_pad) gPad->Update();
}
if (!view->IsPerspective()) view->SetPerspective();
TAxis3D::ToggleRulers();
}
//______________________________________________________________________________
void EDetectorPhotonsPainter::Paint( Option_t* option ) {
//
//
//
map < Int_t, TPolyMarker3D* >::const_iterator j;
for ( j=fPoints.begin(); j != fPoints.end(); j++ ) {
j->second->Paint( option );
}
}