Skip to content
Snippets Groups Projects
  • hallc-online's avatar
    820fbf88
    Modify THcHodoscope.cxx · 820fbf88
    hallc-online authored
    The change was in part of code which calculates the fiducial
     area of the scintillators where the drift chamber should
     have had a track. This sets fGoodScintHits=1 or 0
     Used to calculate the DC track efficiency
    
    1) Eliminate variables fScinShould and fScindid. These will
       be defined in the cuts file.
    2) Eliminate code which determined bestXpScin and bestYpScin since
       since these variables were never used.
    3) Initialized  fHitSweet1X,fHitSweet1Y,fHitSweet2X and
       fHitSweet2Y to zero.
    4) Change so that loops over number of paddles do not
        assume that X (Y) planes for Ch1 and Ch2 have same number
        of paddles.
    820fbf88
    History
    Modify THcHodoscope.cxx
    hallc-online authored
    The change was in part of code which calculates the fiducial
     area of the scintillators where the drift chamber should
     have had a track. This sets fGoodScintHits=1 or 0
     Used to calculate the DC track efficiency
    
    1) Eliminate variables fScinShould and fScindid. These will
       be defined in the cuts file.
    2) Eliminate code which determined bestXpScin and bestYpScin since
       since these variables were never used.
    3) Initialized  fHitSweet1X,fHitSweet1Y,fHitSweet2X and
       fHitSweet2Y to zero.
    4) Change so that loops over number of paddles do not
        assume that X (Y) planes for Ch1 and Ch2 have same number
        of paddles.
THcHodoscope.h 11.10 KiB
#ifndef ROOT_THcHodoscope
#define ROOT_THcHodoscope

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// THcHodoscope                                                              //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

#include <vector>

#include "TClonesArray.h"
#include "THaNonTrackingDetector.h"
#include "THcHitList.h"
#include "THcHodoHit.h"
#include "THcRawHodoHit.h"
#include "THcScintillatorPlane.h"
#include "THcShower.h"
#include "THcCherenkov.h"

#include "THaTrackingDetector.h"
#include "THcHitList.h"
#include "THcRawDCHit.h"
#include "THcSpacePoint.h"
#include "THcDriftChamberPlane.h"
#include "THcDriftChamber.h"
#include "TMath.h"

#include "THaSubDetector.h"
#include "TClonesArray.h"
#include <iostream>
#include <fstream>


class THaScCalib;

class THcHodoscope : public THaNonTrackingDetector, public THcHitList {

public:
  THcHodoscope( const char* name, const char* description = "",
		   THaApparatus* a = NULL );
  virtual ~THcHodoscope();

  virtual Int_t      Decode( const THaEvData& );
  virtual EStatus    Init( const TDatime& run_time );

  virtual Int_t      CoarseProcess( TClonesArray& tracks );
  virtual Int_t      FineProcess( TClonesArray& tracks );

  void EstimateFocalPlaneTime(void);
  virtual Int_t      ApplyCorrections( void );
  Double_t GetStartTime() const { return fStartTime; }
  Bool_t IsStartTimeGood() const {return fGoodStartTime;};
  Int_t GetNfptimes() const {return fNfptimes;};
  Int_t GetScinIndex(Int_t nPlane, Int_t nPaddle);
  Int_t GetScinIndex(Int_t nSide, Int_t nPlane, Int_t nPaddle);
  Double_t GetPathLengthCentral();
  Int_t GetNTracks() const { return fTrackProj->GetLast()+1; }
  Double_t GetTdcMin() const {return fScinTdcMin;}
  Double_t GetTdcMax() const {return fScinTdcMax;}
  Double_t GetTofTolerance() const {return fTofTolerance;}
  Double_t GetTdcToTime() const {return fScinTdcToTime;}
  Double_t GetBetaNominal() const {return fBetaNominal;}
  Double_t GetHodoPosPhcCoeff(Int_t iii) const {return fHodoPosPhcCoeff[iii];}
  Double_t GetHodoNegPhcCoeff(Int_t iii) const {return fHodoNegPhcCoeff[iii];}
  Double_t GetHodoPosMinPh(Int_t iii) const {return fHodoPosMinPh[iii];}
  Double_t GetHodoNegMinPh(Int_t iii) const {return fHodoNegMinPh[iii];}
  Double_t GetHodoPosTimeOffset(Int_t iii) const {return fHodoPosTimeOffset[iii];}
  Double_t GetHodoNegTimeOffset(Int_t iii) const {return fHodoNegTimeOffset[iii];}
  Double_t GetHodoVelLight(Int_t iii) const {return fHodoVelLight[iii];}
  Double_t GetHodoPosInvAdcOffset(Int_t iii) const {return fHodoPosInvAdcOffset[iii];}
  Double_t GetHodoNegInvAdcOffset(Int_t iii) const {return fHodoNegInvAdcOffset[iii];}
  Double_t GetHodoPosInvAdcLinear(Int_t iii) const {return fHodoPosInvAdcLinear[iii];}
  Double_t GetHodoNegInvAdcLinear(Int_t iii) const {return fHodoNegInvAdcLinear[iii];}
  Double_t GetHodoPosInvAdcAdc(Int_t iii) const {return fHodoPosInvAdcAdc[iii];}
  Double_t GetHodoNegInvAdcAdc(Int_t iii) const {return fHodoNegInvAdcAdc[iii];}

  Double_t GetStartTimeCenter() const {return fStartTimeCenter;}
  Double_t GetStartTimeSlop() const {return fStartTimeSlop;}
  Double_t GetBetaNotrk() const {return fBetaNoTrk;}

  Int_t GetGoodRawPad(Int_t iii){return fTOFCalc[iii].good_raw_pad;}
  Int_t GetGoodRawPlane(Int_t iii){return fTOFCalc[iii].pindex;}
  Int_t GetNScinHits(Int_t iii){return fNScinHits[iii];}
  Int_t GetTotHits(){return fTOFCalc.size();}

  Int_t GetNPlanes() { return fNPlanes;}
  THcScintillatorPlane* GetPlane(Int_t ip) { return fPlanes[ip];}
  UInt_t GetNPaddles(Int_t ip) { return fNPaddle[ip];}
  Double_t GetHodoSlop(Int_t ip) { return fHodoSlop[ip];}
  Double_t GetPlaneCenter(Int_t ip) { return fPlaneCenter[ip];}
  Double_t GetPlaneSpacing(Int_t ip) { return fPlaneSpacing[ip];}
  Int_t GetTdcOffset(Int_t ip) const { return fTdcOffset[ip];}


  Double_t GetBeta() const {return fBeta;}


  Double_t GetHodoPosSigma(Int_t iii) const {return fHodoPosSigma[iii];}
  Double_t GetHodoNegSigma(Int_t iii) const {return fHodoNegSigma[iii];}

  Bool_t GetFlags(Int_t itrack, Int_t iplane, Int_t ihit,
		  Bool_t& onTrack, Bool_t& goodScinTime,
		  Bool_t& goodTdcNeg, Bool_t& goodTdcPos) const {
    onTrack = fGoodFlags[itrack][iplane][ihit].onTrack;
    goodScinTime = fGoodFlags[itrack][iplane][ihit].goodScinTime;
    goodTdcNeg = fGoodFlags[itrack][iplane][ihit].goodTdcNeg;
    goodTdcPos = fGoodFlags[itrack][iplane][ihit].goodTdcPos;
    return(kTRUE);
  }

  const TClonesArray* GetTrackHits() const { return fTrackProj; }

  friend class THaScCalib;

  THcHodoscope();  // for ROOT I/O
protected:

  Int_t fAnalyzePedestals;

  Int_t fNHits;

  // Calibration

  // Per-event data
  Bool_t fSHMS;
  Bool_t fGoodStartTime;
  Double_t fStartTime;
  Double_t fFPTimeAll;
  Int_t fNfptimes;

  Double_t     fBeta;

  Double_t     fBetaNoTrk;
  Double_t     fBetaNoTrkChiSq;
  // Per-event data

  // Potential Hall C parameters.  Mostly here for demonstration
  Int_t fNPlanes;		// Number of planes
  UInt_t fMaxScinPerPlane,fMaxHodoScin; // max number of scin/plane; product of the first two
  Double_t fStartTimeCenter, fStartTimeSlop, fScinTdcToTime;
  Double_t fTofTolerance;
  Int_t fCosmicFlag; //
  Double_t fPathLengthCentral;
  Double_t fScinTdcMin, fScinTdcMax; // min and max TDC values
  char** fPlaneNames;
  UInt_t* fNPaddle;		// Number of paddles per plane

  Double_t* fHodoVelLight;
  Double_t* fHodoPosSigma;
  Double_t* fHodoNegSigma;

  Double_t* fHodoPosMinPh;
  Double_t* fHodoNegMinPh;
  Double_t* fHodoPosPhcCoeff;
  Double_t* fHodoNegPhcCoeff;
  Double_t* fHodoPosTimeOffset;
  Double_t* fHodoNegTimeOffset;
  Int_t* fHodoPosPedLimit;
  Int_t* fHodoNegPedLimit;
  Int_t fTofUsingInvAdc;
  Double_t* fHodoPosInvAdcOffset;
  Double_t* fHodoNegInvAdcOffset;
  Double_t* fHodoPosInvAdcLinear;
  Double_t* fHodoNegInvAdcLinear;
  Double_t* fHodoPosInvAdcAdc;
  Double_t* fHodoNegInvAdcAdc;

  Double_t fPartMass;		// Nominal particle mass
  Double_t fBetaNominal;	// Beta for central ray of nominal particle type

  THcScintillatorPlane** fPlanes; // List of plane objects

  TClonesArray*  fTrackProj;  // projection of track onto scintillator plane
                              // and estimated match to TOF paddle

  //--------------------------   Ahmed   -----------------------------

  THcShower* fShower;
  THcCherenkov* fChern;


  Int_t        fCheckEvent;
  Int_t        fEventType;

  Int_t        fGoodTrack;
  Double_t     fScin2XZpos;
  Double_t     fScin2XdZpos;
  Double_t     fScin2YZpos;
  Double_t     fScin2YdZpos;

  Double_t     fChi2Min;
  Double_t*    fPlaneCenter;
  Double_t*    fPlaneSpacing;

  Double_t     fNormETot;
  Double_t     fNCerNPE;
  Double_t*    fHodoSlop;
  Int_t        *fTdcOffset;
  Int_t        fdebugprintscinraw;
  Int_t        fTestSum;
  Int_t        fTrackEffTestNScinPlanes;
  Int_t        fGoodScinHits;
  Int_t*       fxLoScin;
  Int_t*       fxHiScin;
  Int_t*       fyLoScin;
  Int_t*       fyHiScin;
  Int_t        fNHodoscopes;

  Int_t        fDumpTOF;
  ofstream    fDumpOut;
  string       fTOFDumpFile;
  Bool_t      fGoodEventTOFCalib;


  Int_t fHitSweet1X;
  Int_t fHitSweet1Y;
  Int_t fHitSweet2X;
  Int_t fHitSweet2Y;

  Int_t fSweet1XScin;
  Int_t fSweet1YScin;
  Int_t fSweet2XScin;
  Int_t fSweet2YScin;

  //  Double_t**   fScinHit;                // [fNPlanes] Array

  Double_t*    fFPTime;               // [fNPlanes] Array


  Double_t* fSumPlaneTime; // [fNPlanes]

  Int_t* fNScinHits;  // [fNPlanes]
  Int_t* fNPlaneTime; // [fNPlanes]

  Bool_t* fGoodPlaneTime;  // [fNPlanes]

  //----------------------------------------------------------------

  // Useful derived quantities
  // double tan_angle, sin_angle, cos_angle;

  //  static const char NDEST = 2;
  //  struct DataDest {
  //    Int_t*    nthit;
  //    Int_t*    nahit;
  //    Double_t*  tdc;
  //    Double_t*  tdc_c;
  //    Double_t*  adc;
  //    Double_t*  adc_p;
  //    Double_t*  adc_c;
  //    Double_t*  offset;
  //    Double_t*  ped;
  //    Double_t*  gain;
  //  } fDataDest[NDEST];     // Lookup table for decoder

  // Inforamtion for each plane
  //  struct NoTrkPlaneInfo {
  //    Bool_t goodplanetime;
  //    NoTrkPlaneInfo () : goodplanetime(kFALSE) {}
  //  };
  //  std::vector<NoTrkPlaneInfo> fNoTrkPlaneInfo;

  // Inforamtion for each plane
  //  struct NoTrkHitInfo {
  //    Bool_t goodtwotimes;
  //    Bool_t goodscintime;
  //    NoTrkHitInfo () : goodtwotimes(kFALSE) {}
  //  };
  //  std::vector<NoTrkHitInfo> fNoTrkHitInfo;


  // Used in TOF calculation (FineProcess) to hold information about hits
  // within a given plane
  struct TOFPInfo {
    Bool_t onTrack;
    Bool_t keep_pos;
    Bool_t keep_neg;
    Double_t time_pos; // Times also corrected for particle
    Double_t time_neg; // flight time
    Double_t scin_pos_time; // Times corrected for position on
    Double_t scin_neg_time; // the bar
    Double_t pathp;
    Double_t pathn;
    Double_t zcor;
    Double_t scinTrnsCoord;
    Double_t scinLongCoord;
    Int_t planeIndex;
    Int_t hitNumInPlane;
    THcHodoHit *hit;
    TOFPInfo () : onTrack(kFALSE), keep_pos(kFALSE), keep_neg(kFALSE),
      time_pos(-99.0), time_neg(-99.0),

scin_pos_time(0.0), scin_neg_time(0.0) {}
  };
  std::vector<TOFPInfo> fTOFPInfo;

  // Used to hold information about all hits within the hodoscope for the TOF
  struct TOFCalc {
    Int_t hit_paddle;
    Int_t pindex;		// Plane index
    Int_t good_raw_pad;
    Bool_t good_scin_time;
    Bool_t good_tdc_pos;
    Bool_t good_tdc_neg;
    Double_t scin_time;
    Double_t scin_time_fp;
    Double_t scin_sigma;
    Double_t dedx;
    TOFCalc() : good_scin_time(kFALSE), good_tdc_pos(kFALSE),
		good_tdc_neg(kFALSE) {}
  };
  std::vector<TOFCalc> fTOFCalc;
    // This doesn't work because we clear this structure each track
    // Do we need an vector of vectors of structures?
    // Start with a separate vector of vectors for now.
  std::vector<std::vector<Double_t> > fdEdX;	        // Vector over track #
  std::vector<Int_t > fNScinHit;		        // # scins hit for the track
  std::vector<std::vector<Int_t> > fScinHitPaddle;	// Vector over hits in a plane #
  std::vector<Int_t > fNClust;		                // # scins clusters for the plane
  std::vector<Int_t > fThreeScin;	                // # scins three clusters for the plane
  std::vector<Int_t > fGoodScinHitsX;                   // # hits in fid x range
  // Could combine the above into a structure

  struct GoodFlags {
    Bool_t onTrack;
    Bool_t goodScinTime;
    Bool_t goodTdcNeg;
    Bool_t goodTdcPos;
  };
  std::vector<std::vector<std::vector<GoodFlags> > > fGoodFlags;
  //

  void           ClearEvent();
  void           DeleteArrays();
  virtual Int_t  ReadDatabase( const TDatime& date );
  virtual Int_t  DefineVariables( EMode mode = kDefine );
  enum ESide { kLeft = 0, kRight = 1 };

  virtual  Double_t TimeWalkCorrection(const Int_t& paddle,
					   const ESide side);
  void Setup(const char* name, const char* description);

  ClassDef(THcHodoscope,0)   // Hodoscope detector
};

////////////////////////////////////////////////////////////////////////////////

#endif