#include "ESinglePhotonsPainter.hh"
#include "ESinglePhoton.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 <TCanvas.h>
#include <TPaveText.h>
#include <map>
#include <vector>
ClassImp(ESinglePhotonsPainter)
using namespace TMath;
//_____________________________________________________________________________
ESinglePhotonsPainter::ESinglePhotonsPainter( EAtmosphere *atm ) : fAtmosphere(atm),
fXmin(0), fXmax(0), fYmin(0), fYmax(0), fZmin(0), fZmax(0) {
//
// Constructor
//
BuildPoints();
}
//_____________________________________________________________________________
ESinglePhotonsPainter::~ESinglePhotonsPainter() {
//
// Destructor
//
}
//______________________________________________________________________________
void ESinglePhotonsPainter::BuildPoints() {
//
// Show photons in detector
//
if (!fAtmosphere) {
Info("BuildPoints()","EAtmosphere object is NULL. Painter made zombie.");
MakeZombie();
return;
}
if (fAtmosphere->GetNumSingles() < 2) {
Info("Draw","At least 2 photons are needed to set the view. Painter made zombie.");
MakeZombie();
return;
}
map < Int_t, vector<Int_t> > types;
ESinglePhoton *ph = fAtmosphere->GetSingle(0);
fXmin = fXmax = ph->GetPos().X();
fYmin = fYmax = ph->GetPos().Y();
fZmin = fZmax = ph->GetPos().Z();
for (Int_t k = 0; k < fAtmosphere->GetNumSingles(); k++) {
ph = fAtmosphere->GetSingle(k);
// types[ph->GetType()].push_back(k);
if (!( ph->IsAbsorbed())) types[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 = types.begin(); i != types.end(); i++){
Int_t color = 2 + ncolor++;
if ( ncolor == 2 ) color = 6;
if ( ncolor == 3 ) color = 3;
fPoints[i->first] = new TPolyMarker3D(i->second.size()*3,fMarkerStyle,"");
for ( UInt_t k(0); k < i->second.size(); k++) {
ph = fAtmosphere->GetSingle(i->second[k]);
fPoints[i->first]->SetPoint(k,ph->GetPos().X(),ph->GetPos().Y(),ph->GetPos().Z());
}
fPoints[i->first]->SetMarkerColor(color);
}
}
//______________________________________________________________________________
void ESinglePhotonsPainter::Draw( Option_t* option ) {
//
//
//
if (!gPad) {
if (!gROOT->GetMakeDefCanvas()) return;
(gROOT->GetMakeDefCanvas())();
}
// Create a 3-D view
TView *view = gPad->GetView();
if (!view) {
gPad->Clear();
view = new TView(11);
}
AppendPad(option);
view->SetRange(fXmin,fYmin, fZmin, fXmax, fYmax, fZmax );
if (!view->IsPerspective()) view->SetPerspective();
TAxis3D::ToggleRulers();
gPad->SetFillColor(kBlack);
gPad->Modified();
}
//______________________________________________________________________________
void ESinglePhotonsPainter::Paint( Option_t* option ) {
//
//
//
map < Int_t, TPolyMarker3D* >::const_iterator j;
for ( j=fPoints.begin(); j != fPoints.end(); j++ ) {
j->second->Paint( option );
}
}