// ESAF : Euso Simulation and Analysis Framework
// $Id: ETreeShowerPainter.cc,v 1.4 2004/11/15 17:37:52 thea Exp $
// Author: Dmitry V.Naumov Aug, 1 2004
#include "ETreeShowerPainter.hh"
#include "ESystemOfUnits.hh"
#include "EShower.hh"
#include "EShowerStep.hh"
#include "EEvent.hh"
#include <TTree.h>
#include <TVirtualGeoTrack.h>
#include <TGeoVolume.h>
#include <TGeoManager.h>
#include <TGeoTube.h>
#include <TH1F.h>
#include <iostream>
ClassImp(ETreeShowerPainter)
//_____________________________________________________________________________
ETreeShowerPainter::ETreeShowerPainter(TTree *etree) {
//
// Constructor
//
fTree = etree;
fWorldBuild = kFALSE;
fCurrentTrack = 0;
fEv = NULL;
fHistos = new TList;
Build();
}
//_____________________________________________________________________________
ETreeShowerPainter::~ETreeShowerPainter() {
//
// Destructor
//
}
//_____________________________________________________________________________
void ETreeShowerPainter::Build() {
if ( !fTree ) {
Info("Build()","ETree object is NULL. Painter made zombie.");
MakeZombie();
return;
}
fEv = new EEvent();
fEv->SetBranches(fTree);
fEvTot = (Int_t)fTree->GetEntries();
BuildWorld();
for (Int_t i=0; i< fEvTot; i++) {
Printf("Entry %d: %d bytes read", i, fTree->GetEntry(i));
EShower *shower = fEv->GetShower();
AddShower(shower);
FillHistos(shower);
}
}
//_____________________________________________________________________________
void ETreeShowerPainter::BuildWorld() {
if(fWorldBuild) return;
new TGeoManager("TreeShowerViewer","Tree Shower Viewer");
TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0,0,0);
fVacuum = new TGeoMedium("Vacuum", 1, matVacuum);
fTop = gGeoManager->MakeBox("fTop", fVacuum, 120, 120, 40);
fFoVVolume = gGeoManager->MakeTube("fFoV",fVacuum, 0,230,20);
gGeoManager->SetTopVolume(fTop);
fTop->AddNode(fFoVVolume, 1, new TGeoTranslation(0,0,20));
gGeoManager->SetVisLevel(1);
fFoVVolume->SetLineColor(kBlue);
gGeoManager->CloseGeometry();
fWorldBuild = kTRUE;
}
//_____________________________________________________________________________
void ETreeShowerPainter::AddShower(EShower *fShower) {
Int_t track_index = gGeoManager->AddTrack(fCurrentTrack++,1);
TVirtualGeoTrack *current = gGeoManager->GetTrack(track_index);
Int_t n = fShower->GetNumSteps();
for (Int_t i=0; i<n; i++) {
double x = (fShower->GetStep(i)->GetPosi().X() + fShower->GetStep(i)->GetPosf().X())/2/km;
double y = (fShower->GetStep(i)->GetPosi().Y() + fShower->GetStep(i)->GetPosf().Y())/2/km;
double z = (fShower->GetStep(i)->GetPosi().Z() + fShower->GetStep(i)->GetPosf().Z())/2/km;
double t = (fShower->GetStep(i)->GetTimei() + fShower->GetStep(i)->GetTimef())/2;
current->AddPoint(x,y,z,t);
}
}
//_____________________________________________________________________________
void ETreeShowerPainter::Draw( Option_t *opt ) {
fTop->Draw();
gGeoManager->DrawTracks();
}
//_____________________________________________________________________________
void ETreeShowerPainter::DrawHistos(Option_t *opt) {
TString option(opt);
TH1F* th = 0;
if (option == "Energy")
th = BuildHistos("Energy","");
else if (option == "Theta")
th = BuildHistos("Theta","");
else if (option == "Phi")
th = BuildHistos("Phi","");
else if (option == "X1")
th = BuildHistos("X1","");
else
th = NULL;
th->Draw();
}
//_____________________________________________________________________________
void ETreeShowerPainter::FillHistos(EShower *fShower) {
TH1F *th1 = BuildHistos("Energy", "Energy Distribution");
TH1F *th2 = BuildHistos("Theta", "Theta Distribution");
TH1F *th3 = BuildHistos("Phi", "Phi Distribution");
TH1F *th4 = BuildHistos("X1", "X1 Distribution");
th1->Fill(fShower->GetEnergy()/1.e19);
th2->Fill(fShower->GetTheta()*TMath::RadToDeg());
th3->Fill(fShower->GetPhi()*TMath::RadToDeg());
th4->Fill(fShower->GetX1()/g*cm2);
}
//_____________________________________________________________________________
TH1F* ETreeShowerPainter::BuildHistos(const char *name, const char *title) {
TH1F* th = (TH1F*)fHistos->FindObject(name);
if (!th) {
if (name == "Energy") {
th = new TH1F( name, title, 100,0,100);
th->SetXTitle("Energy/1.e19 eV");
}
if (name == "Theta") {
th = new TH1F( name, title, 100,0,90);
th->SetXTitle("#Theta, deg");
}
if (name == "Phi") {
th = new TH1F( name, title, 100,0,360);
th->SetXTitle("#Phi, deg");
}
if (name == "X1") {
th = new TH1F( name, title, 100,0,100);
th->SetXTitle("X_{1}, g/cm^{2}");
}
fHistos->Add(th);
}
th->SetStats(0);
th->SetFillColor(9);
return th;
}