// ESAF : Euso Simulation and Analysis Framework
// $Id: PixelMapBuilder.hh,v 1.17 2005/10/31 16:36:32 thea Exp $
// A.Thea created Apr, 15 2004
#ifndef __PIXELMAPBUILDER_HH__
#define __PIXELMAPBUILDER_HH__
#include "euso.hh"
#include "DiffusePhotonsOnPupil.hh"
#include "EsafConfigurable.hh"
#include "EsafMsgSource.hh"
#include "TString.h"
#include "TFile.h"
#include "TH2F.h"
#include <vector>
class EusoDetector;
class DetectorTransportManager;
class EusoElectronics;
class TTree;
class TChain;
class TCanvas;
class EGViewer;
////////////////////////////////////////////////////////////////////////////////
// //
// PixelMapBuilder //
// //
////////////////////////////////////////////////////////////////////////////////
class PixelMapBuilder: public EsafMsgSource {
public:
// ctor
PixelMapBuilder();
// dtor
virtual ~PixelMapBuilder();
void SetNphotons( Int_t n) { fNphotons = n; }
Int_t GetNphotons() { return fNphotons; }
Bool_t OpenRoot( const char* name, Bool_t write = kFALSE );
Bool_t AddToChain( const char* name);
Bool_t OpenChain( const char* name);
Bool_t OpenChain( const char** name, Int_t n );
Bool_t CloseRoot();
enum { kBufEmpty = -1};
struct Hit {
Int_t fUID;
Float_t fTheta;
Float_t fPhi;
Float_t fLambda;
};
class Header : public TObject {
public:
Header() : fNpixels(0), fNtracked(0), fNhits(0), fFoV(0), fFullFoV(0) {}
Int_t fNpixels;
Int_t fNtracked;
Int_t fNhits;
Float_t fFoV;
Float_t fFullFoV;
ClassDef(Header,1)
};
Bool_t MakePhotonsFile( const char* name, Long_t n );
Bool_t MakeMap( const char* hits, const char* mapfile);
size_t BufferEntries() { return fThetaFOVBuffer.size(); }
size_t BufEntrySize(Int_t i) {return fThetaFOVBuffer[i].size(); }
Float_t GetNsigma() const { return fNsigma; }
Int_t GetBufIndex() const { return fBufIndex; }
Int_t GetHitsThreshold() const { return fHitsThreshold; }
Long_t GetMaxBufSize() { return fMaxBufSize; }
Long_t GetBufferSize() { return fBufferSize; }
Float_t GetFoV() { return fFoV; }
Float_t GetFullFoV() { return fFullFoV; }
Int_t MapSize() { return fMapTheta.GetSize(); }
//setters
void SetNsigma(Float_t t) { fNsigma = t; }
void SetHitsThreshold( Int_t t ) { fHitsThreshold = t; }
void SetFoV( Float_t fov) { fFoV = fov <= fFullFoV ? fov : fFullFoV; }
void SetFullFoV( Float_t fov ) { fFullFoV = fov; }
void SetMaxBufSize( Long_t size ) { fMaxBufSize = size; }
void SetDisplay( EGViewer* display ) { fDisplay = display; }
Bool_t Fit(Int_t uid, Option_t *option);
TCanvas *DrawHistPad() const;
void DumpHit() const;
void SetSaveHistograms( const char* name =0 ) { fFitHistsFileName = name ? name : ""; }
void WriteMap(const char* name) ;
//private:
// objects for the map creation
DiffusePhotonsOnPupil fPupil; // photons generator
EusoDetector *fDetector; // detector
DetectorTransportManager *fTransporter; // photons transporter
EusoElectronics *fElectronics; // electronics
// common part
TString fHitsRootFileName;
TFile *fHitsRootFile; // output file
TTree *fHitsTree; // ttree containing the hits on the pixels
TChain *fHitsChain; // Chain for multiple file processing
Long64_t fNphotons; // total number of photons
TString fFitHistsFileName;
TFile* fFitHistsFile;
TTree* fFitHistsTree;
// build the map
void TrackPhotons();
Hit fHit;
Header *fHeader;
Int_t UidToIndex( Int_t uid ) { return uid-1-fBufIndex; }
Bool_t FillPixelsBuffer(Int_t first);
Bool_t CheckPixelInBuffer(Int_t first);
Bool_t ClearPixelsBuffers();
Bool_t InitFit();
Bool_t ClearFit();
void ComputeMap(Int_t first, Int_t last, const char* opt);
void OptimizeBuffer();
Long_t fBufIndex; // index
Long_t fBufferSize; // size of the buffers
Long_t fMaxBufSize; // max buffer size
vector< vector<Float_t> > fThetaFOVBuffer; //
vector< vector<Float_t> > fPhiFOVBuffer; //
// fitting
Int_t fHitsThreshold; // min number of hits per channel
Int_t fNbins; // bins of th and ph histos
Int_t fNbinsFit; // bins in fDetail
Float_t fNsigma; // number of sigma to limit fit at
Float_t fFoV; // fov used for the input photons
Float_t fFullFoV; // detector's field of view
Int_t fFitUID; // uid of the last fitted pixel
TArrayF fMapTheta;
TArrayF fMapThetaRMS;
TArrayF fMapPhi;
TArrayF fMapPhiRMS;
TArrayI fMapIndex; // pixel content. size = Npixles+1 (status)
TH1F *fH1FitTheta; // histograms for fitting theta
TH1F *fH1FitPhi; // histograms for fitting phi
TH2F *fH2FitThetaPhi; //
TH2F *fH2ThetaPhi; // full fov histogram for peak location
EGViewer* fDisplay; //
ClassDef(PixelMapBuilder,0)
};
#endif /* __PIXELMAPBUILDER_HH__ */