Universita' di GenovaINFN Sezione di Genova  
AIRWATCH / EUSO Genova

ESinglePhotonsPainter - source file

#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) {
    //

    // Constructor

    //


    for(Int_t j=0; j<6; j++) {
        fXmin[j] = fXmax[j] = 0.;
        fYmin[j] = fYmax[j] = 0.;
        fZmin[j] = fZmax[j] = 0.;
    }
    
    if (!fAtmosphere) {
        Info("BuildPoints()","EAtmosphere object is NULL. Painter made zombie.");
        MakeZombie();
        return;
    }
    
    // initialize fIndex_list

    Int_t ns = fAtmosphere->GetNumSingles();
    fIndex_list.Set(ns);
    for(Int_t i=0; i<ns; i++) fIndex_list[i] = i;

    BuildPoints();
}

//_____________________________________________________________________________

 ESinglePhotonsPainter::~ESinglePhotonsPainter() {
    //

    // Destructor

    //

    Reset();
}

//______________________________________________________________________________

 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;
    }

    // first == photon history

    // second == photon index in the list

    map < Int_t, vector<Int_t> > types;
      
    // initialization

    ESinglePhoton *ph = fAtmosphere->GetSingle(0);
    for(Int_t j=0; j<6; j++) {
        fXmin[j] = fXmax[j] = ph->GetPos().X();
        fYmin[j] = fYmax[j] = ph->GetPos().Y();
        fZmin[j] = fZmax[j] = ph->GetPos().Z();
    }
    
    // define geometries and select relevant photons (MScattCut)

    for (Int_t k = 0; k < fIndex_list.GetSize(); k++) {
        if(fIndex_list[k] < 0) break;
        ph = fAtmosphere->GetSingle(fIndex_list[k]);
        if((ph->GetPos() - ph->GetShowerPos()).Mag() < 100e6) {
	    Int_t j = ph->GetHistory();
            types[j].push_back(fIndex_list[k]);
	    fXmin[j] = Min(fXmin[j],ph->GetPos().X());
            fXmax[j] = Max(fXmax[j],ph->GetPos().X());
            fYmin[j] = Min(fYmin[j],ph->GetPos().Y());
            fYmax[j] = Max(fYmax[j],ph->GetPos().Y());
            fZmin[j] = Min(fZmin[j],ph->GetPos().Z());
            fZmax[j] = Max(fZmax[j],ph->GetPos().Z());
	    if (!ph->IsAbsorbed()) {
	        fXmin[5] = Min(fXmin[5],ph->GetPos().X());
                fXmax[5] = Max(fXmax[5],ph->GetPos().X());
                fYmin[5] = Min(fYmin[5],ph->GetPos().Y());
                fYmax[5] = Max(fYmax[5],ph->GetPos().Y());
                fZmin[5] = Min(fZmin[5],ph->GetPos().Z());
                fZmax[5] = Max(fZmax[5],ph->GetPos().Z());
	    }
	}
    }

    // fill the lists of points

    map < Int_t, vector<Int_t> >::const_iterator i;
    for (i = types.begin(); i != types.end(); i++) {
        fPoints_fluo[i->first] = new TPolyMarker3D(i->second.size()*3,fMarkerStyle,"");
        fPoints_ckov[i->first] = new TPolyMarker3D(i->second.size()*3,fMarkerStyle,"");
        fPoints_trans[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]);
	    if(ph->GetType() == 0) fPoints_fluo[i->first]->SetPoint(k,ph->GetPos().X(),ph->GetPos().Y(),ph->GetPos().Z());
	    if(ph->GetType() == 1) fPoints_ckov[i->first]->SetPoint(k,ph->GetPos().X(),ph->GetPos().Y(),ph->GetPos().Z());
            fPoints_trans[i->first]->SetPoint(k,ph->GetPos().X(),ph->GetPos().Y(),ph->GetPos().Z());
        } 
    }
}

//______________________________________________________________________________

 void ESinglePhotonsPainter::Draw( Option_t* option ) {
    //

    // Option explanations : nb 1 or 2 specifies if view must be shrunk or expanded

    // WARNING : the first option coming must be associated with 2

    //

    //


    TString opt(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);

    if(opt.Contains("direct2"))         view->SetRange(fXmin[0],fYmin[0], fZmin[0], fXmax[0], fYmax[0], fZmax[0],2 );
    if(opt.Contains("reflected2"))      view->SetRange(fXmin[1],fYmin[1], fZmin[1], fXmax[1], fYmax[1], fZmax[1],2 );
    if(opt.Contains("raylscat2"))       view->SetRange(fXmin[2],fYmin[2], fZmin[2], fXmax[2], fYmax[2], fZmax[2],2 );
    if(opt.Contains("cloudscat2"))      view->SetRange(fXmin[3],fYmin[3], fZmin[3], fXmax[3], fYmax[3], fZmax[3],2 );
    if(opt.Contains("aeroscat2"))       view->SetRange(fXmin[4],fYmin[4], fZmin[4], fXmax[4], fYmax[4], fZmax[4],2 );
    if(opt.Contains("all2"))            view->SetRange(fXmin[5],fYmin[5], fZmin[5], fXmax[5], fYmax[5], fZmax[5],2 );
    if(opt.Contains("direct1"))         view->SetRange(fXmin[0],fYmin[0], fZmin[0], fXmax[0], fYmax[0], fZmax[0],1 );
    if(opt.Contains("reflected1"))      view->SetRange(fXmin[1],fYmin[1], fZmin[1], fXmax[1], fYmax[1], fZmax[1],1 );
    if(opt.Contains("raylscat1"))       view->SetRange(fXmin[2],fYmin[2], fZmin[2], fXmax[2], fYmax[2], fZmax[2],1 );
    if(opt.Contains("cloudscat1"))      view->SetRange(fXmin[3],fYmin[3], fZmin[3], fXmax[3], fYmax[3], fZmax[3],1 );
    if(opt.Contains("aeroscat1"))       view->SetRange(fXmin[4],fYmin[4], fZmin[4], fXmax[4], fYmax[4], fZmax[4],1 );
    if(opt.Contains("all1"))            view->SetRange(fXmin[5],fYmin[5], fZmin[5], fXmax[5], fYmax[5], fZmax[5],1 );
    
    if (!view->IsPerspective()) view->SetPerspective();

    TAxis3D::ToggleRulers();
    gPad->SetFillColor(kBlack);

    gPad->Modified();

}

//______________________________________________________________________________

 void ESinglePhotonsPainter::Paint( Option_t* option ) {
    //

    // Option explanations : photon type AND history can be specified

    // Some examples :

    //    - fluodirect            <=> direct photons, but only fluo

    //    - direct                <=> direct photons, both fluo and cerenkov

    //    - directckovreflected   <=> direct (both) and reflected (only ckov)

    //

    
    TString finalopt(option);
    TString opt("same");
    finalopt += opt;
    
    map < Int_t, TPolyMarker3D* >::const_iterator j;
    
    // direct

    if(finalopt.Contains("direct")) {
	if(!finalopt.Contains("ckovdirect")) {
	    for ( j=fPoints_fluo.begin(); j != fPoints_fluo.end(); j++ ) {
                if(j->first == 0) {
	    	    j->second->SetMarkerColor(3);
		    j->second->Paint( finalopt.Data() );
	        }
	    }
	}

	if(!finalopt.Contains("fluodirect")) {
	    for ( j=fPoints_ckov.begin(); j != fPoints_ckov.end(); j++ ) {
                if(j->first == 0) {
		    j->second->SetMarkerColor(6);
		    j->second->Paint(  finalopt.Data() );
	        }
	    }
	}
    }
    
    // reflected

    if(finalopt.Contains("reflected")) {
	if(!finalopt.Contains("ckovreflected")) {
	    for ( j=fPoints_fluo.begin(); j != fPoints_fluo.end(); j++ ) {
                if(j->first == 1) {
		    j->second->SetMarkerColor(3);
		    j->second->Paint(  finalopt.Data() );
	        }
	    }
	}

	if(!finalopt.Contains("fluoreflected")) {
	    for ( j=fPoints_ckov.begin(); j != fPoints_ckov.end(); j++ ) {
                if(j->first == 1) {
		    j->second->SetMarkerColor(6);
	  	    j->second->Paint(  finalopt.Data() );
	        }
	    }
	}
    }
    
    // rayleigh scattered

    if(finalopt.Contains("raylscat")) {
	if(!finalopt.Contains("ckovraylscat")) {
	    for ( j=fPoints_fluo.begin(); j != fPoints_fluo.end(); j++ ) {
                if(j->first == 2) {
		    j->second->SetMarkerColor(3);
		    j->second->Paint(  finalopt.Data() );
	        }
	    }
	}

	if(!finalopt.Contains("fluoraylscat")) {
	    for ( j=fPoints_ckov.begin(); j != fPoints_ckov.end(); j++ ) {
                if(j->first == 2) {
		    j->second->SetMarkerColor(6);
		    j->second->Paint(  finalopt.Data() );
	        }
	    }
	}
    }
    
    // clouds scattered

    if(finalopt.Contains("cloudscat")) {
	if(!finalopt.Contains("ckovcloudscat")) {
	    for ( j=fPoints_fluo.begin(); j != fPoints_fluo.end(); j++ ) {
                if(j->first == 3) {
		    j->second->SetMarkerColor(3);
		    j->second->Paint(  finalopt.Data() );
	        }
	    }
	}

	if(!finalopt.Contains("fluocloudscat")) {
	    for ( j=fPoints_ckov.begin(); j != fPoints_ckov.end(); j++ ) {
                if(j->first == 3) {
		    j->second->SetMarkerColor(6);
	    	    j->second->Paint(  finalopt.Data() );
	        }
	    }
	}
    }
    
    // aerosols scattered

    if(finalopt.Contains("aeroscat")) {
	if(!finalopt.Contains("ckovaeroscat")) {
	    for ( j=fPoints_fluo.begin(); j != fPoints_fluo.end(); j++ ) {
                if(j->first == 4) {
		    j->second->SetMarkerColor(3);
		    j->second->Paint(  finalopt.Data() );
	        }
	    }
	}

	if(!finalopt.Contains("fluoaeroscat")) {
	    for ( j=fPoints_ckov.begin(); j != fPoints_ckov.end(); j++ ) {
                if(j->first == 4) {
		    j->second->SetMarkerColor(6);
		    j->second->Paint(  finalopt.Data() );
	        }
	    }
	}
    }
    
    // all the photons

    if(finalopt.Contains("all")) {
	if(!finalopt.Contains("ckovall")) {
	    for ( j=fPoints_fluo.begin(); j != fPoints_fluo.end(); j++ ) {
                j->second->SetMarkerColor(3);
	        j->second->Paint(  finalopt.Data() );
	    }
	}

	if(!finalopt.Contains("fluoall")) {
	    for ( j=fPoints_ckov.begin(); j != fPoints_ckov.end(); j++ ) {
	        j->second->SetMarkerColor(6);
	        j->second->Paint(  finalopt.Data() );
	    }
	}
    }
}

//______________________________________________________________________________

 void ESinglePhotonsPainter::DefineMScattCut(const TArrayI& array) {
    //

    // define MScatt cut - copy of EAtmospherePainter

    //

    
    Reset();
    fIndex_list.Set(array.GetSize());
    for(Int_t i=0; i<array.GetSize(); i++) fIndex_list[i] = array[i];
    BuildPoints();
    
}

//______________________________________________________________________________

 void ESinglePhotonsPainter::Reset() {
    //

    // reset internal maps

    //

    
    map < Int_t, TPolyMarker3D* >::const_iterator j;
    for ( j=fPoints_fluo.begin(); j != fPoints_fluo.end(); j++ ) {
        delete j->second;
	fPoints_fluo[j->first] = 0;
	fPoints_fluo.clear();
    }
    for ( j=fPoints_ckov.begin(); j != fPoints_ckov.end(); j++ ) {
        delete j->second;
	fPoints_ckov[j->first] = 0;
	fPoints_ckov.clear();
    }
    for ( j=fPoints_trans.begin(); j != fPoints_trans.end(); j++ ) {
        delete j->second;
	fPoints_trans[j->first] = 0;
	fPoints_trans.clear();
    }
}



About Us | EUSO Official Website | Web pages created by Roberto Pesce and Alessandro Thea - Last Update Wed Nov 16 16:57:39 2005 Wed Nov 16 16:29:22 2005