Universita' di GenovaINFN Sezione di Genova  
AIRWATCH / EUSO Genova

EORSample - source file

// $Id: EORSample.cc,v 1.5 2005/04/19 14:27:30 naumov Exp $
// Author: ale   2005/01/19

/*****************************************************************************
 * ESAF: Euso Simulation and Analysis Framework                              *
 *                                                                           *
 *  Id: EORSample                                                            *
 *  Package: <packagename>                                                   *
 *  Coordinator: <coordinator>                                               *
 *                                                                           *
 *****************************************************************************/

//_____________________________________________________________________________
//
// EORSample
//
// <extensive class description>
//
//   Config file parameters
//   ======================
//
//   <parameter name>: <parameter description>
//   -Valid options: <available options>
//

#include "EORSample.hh"
#include <TH2F.h>

ClassImp(EORSample)

//_____________________________________________________________________________
EORSample::EORSample() : fPsfHist(0) {
    //
    // Constructor
    //

    Clear();
}

//_____________________________________________________________________________
EORSample::~EORSample() {
    //
    // Destructor
    //
}


//______________________________________________________________________________
 void EORSample::Clear( Option_t* ) {
    //
    // Clear the sample
    //

    SafeDelete( fPsfHist );
    fThetaIndex    = -1;
    fLambdaIndex   = -1;
    fTheta         = -1;
    fLambda        = -1;
    fTotalEfficacy = -1;
    fTriggEfficacy = -1;
    fCentroid.SetXYZ(0.,0.,0.);
}


//______________________________________________________________________________
 void EORSample::SetPsfHist( TH2F* h ) {
    //
    // 
    //

    SafeDelete( fPsfHist );
    fPsfHist = (TH2F*)h->Clone();

}
//______________________________________________________________________________
 TH2F* EORSample::MakePsfHistRotated(Float_t phi) {
    //
    // returnes rotated for the angle phi in deg Psf distribution in XY plane
    // the user must take care to delete this histo him/her self
    if (!fPsfHist) return (TH2F*)NULL;
    
    phi = -phi;
    // get xmin, xmax, ymin, ymax of the original histo
    Float_t xmin_orig = fPsfHist->GetXaxis()->GetXmin();
    Float_t xmax_orig = fPsfHist->GetXaxis()->GetXmax();
    Float_t ymin_orig = fPsfHist->GetYaxis()->GetXmin();
    Float_t ymax_orig = fPsfHist->GetYaxis()->GetXmax();
    // compute xmin, xmax, ymin, ymax of the rotated histo (to check if this is OK)
    Float_t xmin = TMath::Min( xmin_orig*TMath::Cos(phi), xmax_orig*TMath::Cos(phi)) +            
                   TMath::Min( ymin_orig*TMath::Sin(phi), ymax_orig*TMath::Sin(phi)); 
			       
    Float_t xmax = TMath::Max( xmin_orig*TMath::Cos(phi), xmax_orig*TMath::Cos(phi)) + 
                   TMath::Max( ymin_orig*TMath::Sin(phi), ymax_orig*TMath::Sin(phi));
			       
    Float_t ymin = TMath::Min(-xmin_orig*TMath::Sin(phi), -xmax_orig*TMath::Sin(phi)) +
                   TMath::Min( ymin_orig*TMath::Cos(phi),  ymax_orig*TMath::Cos(phi));
			      
    Float_t ymax = TMath::Max(-xmin_orig*TMath::Sin(phi),-xmax_orig*TMath::Sin(phi)) + 
                   TMath::Max( ymin_orig*TMath::Cos(phi), ymax_orig*TMath::Cos(phi));
    Int_t Nx = fPsfHist->GetNbinsX();
    Int_t Ny = fPsfHist->GetNbinsY();
    // make a new histo and fill it with rotated distribution
   
    TH2F* hRotated = 
          new TH2F("hRotated",Form("Theta=%.2f deg, Phi=%.3f deg",fTheta*TMath::RadToDeg(),-phi*TMath::RadToDeg()),Nx,xmin,xmax,Ny,ymin,ymax);
//     hRotated->SetDirectory(0);
    for (Int_t ix = 0; ix < Nx; ix++) {
         Float_t x_orig = fPsfHist->GetXaxis()->GetBinCenter(ix);    
         for (Int_t iy = 0; iy < Ny; iy++) {
	 Float_t y_orig = fPsfHist->GetYaxis()->GetBinCenter(iy);  
	 Float_t x =  x_orig*TMath::Cos(phi) + y_orig*TMath::Sin(phi);
	 Float_t y = -x_orig*TMath::Sin(phi) + y_orig*TMath::Cos(phi);
	 hRotated->Fill(x,y,fPsfHist->GetBinContent(ix,iy));
         }
    }	     
    return  hRotated;
}
About Us | EUSO Official Website | Web pages created by Roberto Pesce and Alessandro Thea - Last Update 14-May-2005 21:31