// Author: Andrew M. Rogers and Mark Wallace, NSCL 07/01/2006
//* Copyright (C) 2006-2008 Andrew M. Rogers and Mark Wallace

#ifndef __TMCPDET_H
#define __TMCPDET_H

#include <iostream>

#ifndef  __ROOTDEFINE_H
#define  __ROOTDEFINE_H
#include "rootDefine.h"
#endif
#ifndef  __PACKETID_H
#define  __PACKETID_H
#include "packetID.h"
#endif


#include <TBranch.h>
#include <TCutG.h>
#include <TF2.h>
#include <TGraphErrors.h>
#include <TGraph2DErrors.h>
#include <TH2.h>
#include <TObject.h>
#include <TRandom3.h>
#include <TROOT.h>
#include <TSpline.h>
#include <TTree.h>
#include <TVector3.h>

using namespace std;

class TMcp;

class TMcpDet : public TObject{
 private:
  TRandom3      fRandom;                      //! The class's random number generator.
  Int_t         fNGainStages;                 //! Number of gain stages set in rootDefine.h

 public:
  TSpline3     *fRowX[13];                    //!
  TSpline3     *fRowY[13];                    //!
  TSpline3     *fBicubicX;                    //!
  TSpline3     *fBicubicY;                    //!
  Double_t     GridFX[13][13];                //!
  Double_t     GridFY[13][13];                //!
  Double_t     GridX[13];                     //!
  Double_t     GridY[13];                     //!

 protected:
  TString      fName;                         //! Object identifier
  TString      fTitle;                        //! Object title.
  Int_t        fId;                           //! MCP identifier (0 or 1, Upstream or Downstream).

 public:
  TMcp         *fCon;                         //! Conversion parent class.
  TMcpDet      *fConD;                        //! Conversion parent class.
  TMcp         *parent;                       //! Parent of this.

  Int_t        fMapOrder;                     //! Order of mapping calibration. (Number of calibration cycles)
  Bool_t       fPosSumCorr;                   //! Use position dependance on sum correction.

  Int_t        fChargeMap[9];                 //!
  Int_t        fSigMap[9];                    //!
  Int_t        fMethod;                       //! Use polynomial=0 or bicubic splines=1 for mask fitting.
  
  Double_t     fHLSlope[4];                   //! Corner slopes from high/low gain matching.
  Double_t     fHLOffset[4];                  //! Corner offsets from high/low gain matching.
  Double_t     fHLLimits[4][2];               //! Limits of region used for high/low matching. 

  Double_t     corner[12];                    //  Corner signals.
  Double_t     tSig;                          //  Time signal.

  Double_t     xScale;                        //! Obsolete.
  Double_t     yScale;                        //! Obsolete.
  Double_t     rotAlign;                      //! Rotation around MCP mask/target z-axis to compensate for alpha/beam.
  Double_t     xOffset;                       //! Offset Raw x position in order to align with alpha source mask.
  Double_t     yOffset;                       //! Offset Raw y position in order to align with alpha source mask.
  Double_t     zOffset;                       //! Offset Raw z position in order to align with alpha source mask.
  Double_t     xShift;                        //! Shift x position in order to align with other refernce frames.
  Double_t     yShift;                        //! Shift y position in order to align with other refernce frames.
  Double_t     zShift;                        //! Shift z position in order to align with other refernce frames.
  Double_t     foilAngle;                     //! Angle of the MCP foils w.r.t. the beam axis.
  Double_t     rotation;                      //! Rotation around MCP mask/target z-axis.
  Double_t     fEulerPhi;                     //! Phi Euler angle.
  Double_t     fEulerTheta;                   //! Theata Euler angle.
  Double_t     fEulerPsi;                     //! Psi Euler angle.
  Double_t     sumThresh;                     //!
  Double_t     cornerGain[8];                 //! Corner gains.
  Double_t     thresh[8];                     //! Corner thresholds.
  Double_t     ped[8];                        //! Corner pedestals.
 
  Double_t     xRaw;                          // Raw x position (Only on Mult=4).
  Double_t     yRaw;                          // Raw y position (Only on Mult=4).
  Double_t     xRawHG;                        // Raw high gain x position (Only on Mult=4).
  Double_t     yRawHG;                        // Raw high gain y position (Only on Mult=4).
  Double_t     xRawM;                         // Raw matched x position (Only on Mult=4).
  Double_t     yRawM;                         // Raw matched y position (Only on Mult=4).
  Double_t     x;                             // Corrected x position.
  Double_t     y;                             // Corrected y position.
  Double_t     xHG;                           // Corrected high gain x position.
  Double_t     yHG;                           // Corrected high gain y position.
  Double_t     z;                             // Corrected z position.
  Double_t     r;                             // Off center distance.
  Double_t     sum;                           // Corner sum.
  Double_t     sumHG;                         // Corner high gain sum.
  Double_t     cMult;                         // Detector corner multiplicity.
  
  TVector3     posV;                          // Calculated 3D interaction position.

  TGraphErrors       g_maskCentroids[5];      //! Graph of mask centroids.
  TGraph2DErrors     g_maskHolesX[5];         //! Graph used for fPolyX0.
  TGraph2DErrors     g_maskHolesY[5];         //! Graph used for fPolyY0.
  TF2               *fPolyX[5];               //! X position polynomial fit function.
  TF2               *fPolyY[5];               //! Y position polynomial fit function.
  TF2               *fPosSumX[5];             //! X position dependance on sum polynomial fit functions.
  TF2               *fPosSumY[5];             //! Y position dependance on sum polynomial fit functions.

  TBranch      *b_xRaw;                       //! 
  TBranch      *b_yRaw;                       //! 
  TBranch      *b_x;                          //! 
  TBranch      *b_y;                          //!
  TBranch      *b_xRawHG;                     //!
  TBranch      *b_yRawHG;                     //! 
  TBranch      *b_xHG;                        //! 
  TBranch      *b_yHG;                        //!
  TBranch      *b_xRawM;                      //!
  TBranch      *b_yRawM;                      //! 
  TBranch      *b_z;                          //!
  TBranch      *b_r;                          //!
  TBranch      *b_sum;                        //!
  TBranch      *b_sumHG;                      //!
  TBranch      *b_cMult;                      //! 
  TBranch      *b_tSig;                       //! 
  TBranch      *b_corner;                     //!
  TBranch      *b_posVX;                       //!
  TBranch      *b_posVY;                       //!
  TBranch      *b_posVZ;                       //!

  TTree        *fChain;                       //! pointer to the analyzed TTree or TChain
  Int_t        fCurrent;                      //! current Tree number in a TChain


 private:
  Bool_t     FitMask(Int_t mapOrder);                                  //

 public:
 TMcpDet(): fName(), fTitle() {fRandom.SetSeed(0);}
  ~TMcpDet();
  TMcpDet(const TMcpDet &);                                           // The copy ctor.

  const Int_t    GetId() const { return fId; }
  const Char_t  *GetName() const { return fName; }
  const Char_t  *GetTitle() const { return fTitle; }
  void           SetId(const Int_t Id);
  void           SetName(const Char_t *name);
  void           SetNameTitle(const Char_t *name, const Char_t *title);
  void           SetTitle(const Char_t *title=""); 

  Int_t      Calculate(Long64_t entry);                                // Calculate an entry.
  Int_t      Calibrate(Long64_t entry);                                // Calibrate an entry.
  void       Clear(Option_t *option="");                               // Clear data members
  void       Copy(TObject &det) const;                                 // Copy method.
  Bool_t     CreateMaskFile(TH2* histo);                               //
  Int_t      GenPrime(Long64_t entry);                                 // Generate primary data for an enrty.
  void       InitClass(TString name,Int_t ID,Int_t nStages);           //
  void       InitTree(TTree *tree);                                    //
  Bool_t     LoadCorrections(Char_t *fileName);                        //
  Bool_t     LoadMaskFile(Char_t *fileName,Int_t mapOrder,Int_t fUseErrors=0);                             // 

  ClassDef(TMcpDet,7)     // MCP Detector Class.
};


Double_t function(Double_t *x, Double_t *a);

Bool_t GetCentroid(TH2* histo,TCutG *cut,Double_t *centroid,Bool_t kPrint=kTRUE);


#endif

Last change: Sun Dec 21 12:38:50 2008
Last generated: 2008-12-21 12:38

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.