#ifndef DIGITIZER_H #define DIGITIZER_H #define nspe 200 #define ntof 200 #define ncat 50 #define ncas 50 #define ncar 100 #define ncal 1000 #define nnd 200 #define nstr 1000 #include #include #include #include #include #include "Riostream.h" #include "TFile.h" #include "TDirectory.h" #include "TTree.h" #include "TLeafI.h" #include "TH1.h" #include "TH2.h" #include "TMath.h" #include "TSQLServer.h" // #include "CRC.h" class Digitizer{ protected: // in and output data members TTree* fhBookTree; ofstream fOutputfile; static const int fPSCUbuffer = 8; static const int fTRIGGERbuffer = 152; //(bytes) static const int fTOFbuffer = 276; //(bytes) static const int fRunHeaderbuffer = 27; // ?? static const int fRunTrailerbuffer = 17; static const int fACbuffer = 128; static const int fNDbuffer = 6; static const int fS4buffer = 3; static const int fPADbuffer = 64; // changed from 32! static const int fCALObuffer = 10000; static const float fCALOGeV2MIPratio = 0.0001059994; static const int fDummybuffer = 64; // dimensions of vectors and buffer, parameter for tracker static const int fTRACKbuffer = 50000; // to be optimized static const int fNviews = 12; static const int fNstrips_view = 3072; static const int fNladder=3; static const int fNstrips_ladder = 1024; static const int fCutzop= 4; static const int fCutclu= 7; static const int fNclst = 2; static const float fAvePedex = 1200.; // to be adjusted static const float fSigmaPedex = 1.; // to be adjusted static const float fAveSigmax = 4.3; // to be adjusted static const float fSigmaSigmax =0.1; // to be adjusted static const float fAvePedey = 2800.; // to be adjusted static const float fSigmaPedey = 1.; // to be adjusted static const float fAveSigmay = 8.; // to be adjusted static const float fSigmaSigmay =0.1; // to be adjusted static const float fSigmaCommon = 25.; // to be adjusted // end dimensions of vectors and buffer, parameter for tracker UShort_t fDataPSCU[fPSCUbuffer]; UInt_t fCounter; UInt_t fCounterPhys; UInt_t fOBT; UShort_t fDataPadding[fPADbuffer]; UInt_t fPadding; UShort_t fDataRunHeader[fRunHeaderbuffer]; UShort_t fDataRunTrailer[fRunTrailerbuffer]; UChar_t fDataTrigger[fTRIGGERbuffer]; UChar_t fDataTof[fTOFbuffer]; UShort_t fDataAC[fACbuffer]; UShort_t fDataND[fNDbuffer]; UShort_t fDataS4[fS4buffer]; UShort_t fDataDummy[fDummybuffer]; UShort_t fDataCALO[fCALObuffer]; UShort_t fSecCalo[4]; UShort_t fSecCALOLength[4]; UShort_t fCALOlength; UShort_t fModCalo; Float_t fCalomip[2][22][96]; // ADC to MIP conversion values Float_t fcalped[4][11][96]; // pedestals Float_t fcalgood[4][11][96]; // used or not in the common noise calculation Float_t fcalthr[4][11][6]; // thresholds Float_t fcalrms[4][11][96]; // rms Float_t fcalbase[4][11][6]; // baselines (common noise) during calibration Float_t fcalvar[4][11][6]; // variance Float_t fcstwerr[4]; // status word Float_t fcperror[4]; // unpacking error flag UInt_t fGivenCaloCalib; char* fFilename; UInt_t fLen; // vectors, buffer, and variables for tracker UShort_t fDataTrack[fTRACKbuffer]; UInt_t fTracklength; // Actual length of buffer Float_t fPedeTrack[fNviews][fNstrips_view]; Float_t fSigmaTrack[fNviews][fNstrips_view]; // UShort_t fBadTrack[fNviews][fNstrips_view]; Float_t fMipCor[fNladder][fNviews] ; // end vectors, buffer, and variables for tracker // // db variables // TSQLServer *fDbc; // Declaration of leave types Int_t Irun; Int_t Ievnt; Int_t Ipa; Float_t X0; Float_t Y0; Float_t Z0; Float_t Theta; Float_t Phi; Float_t P0; Int_t Nthtof; UChar_t Ipltof[ntof]; UChar_t Ipaddle[ntof]; UChar_t Ipartof[ntof]; Float_t Xintof[ntof]; Float_t Yintof[ntof]; Float_t Zintof[ntof]; Float_t Xouttof[ntof]; Float_t Youttof[ntof]; Float_t Zouttof[ntof]; Float_t Ereltof[ntof]; Float_t Timetof[ntof]; Float_t Pathtof[ntof]; Float_t P0tof[ntof]; Int_t Nthcat; UChar_t Iparcat[ncat]; UChar_t Icat[ncat]; Float_t Xincat[ncat]; Float_t Yincat[ncat]; Float_t Zincat[ncat]; Float_t Xoutcat[ncat]; Float_t Youtcat[ncat]; Float_t Zoutcat[ncat]; Float_t Erelcat[ncat]; Float_t Timecat[ncat]; Float_t Pathcat[ncat]; Float_t P0cat[ncat]; Int_t Nthcas; UChar_t Iparcas[ncas]; UChar_t Icas[ncas]; Float_t Xincas[ncas]; Float_t Yincas[ncas]; Float_t Zincas[ncas]; Float_t Xoutcas[ncas]; Float_t Youtcas[ncas]; Float_t Zoutcas[ncas]; Float_t Erelcas[ncas]; Float_t Timecas[ncas]; Float_t Pathcas[ncas]; Float_t P0cas[ncas]; Int_t Nthspe; UChar_t Iparspe[nspe]; UChar_t Itrpb[nspe]; UChar_t Itrsl[nspe]; UChar_t Itspa[nspe]; Float_t Xinspe[nspe]; Float_t Yinspe[nspe]; Float_t Zinspe[nspe]; Float_t Xoutspe[nspe]; Float_t Youtspe[nspe]; Float_t Zoutspe[nspe]; Float_t Xavspe[nspe]; Float_t Yavspe[nspe]; Float_t Zavspe[nspe]; Float_t Erelspe[nspe]; Float_t Pathspe[nspe]; Float_t P0spe[nspe]; UChar_t Nxmult[nspe]; UChar_t Nymult[nspe]; Int_t Nstrpx; UChar_t Npstripx[nstr]; UChar_t Ntstripx[nstr]; UShort_t Istripx[nstr]; //UInt_t Istripx[nstr]; Float_t Qstripx[nstr]; Float_t Xstripx[nstr]; Int_t Nstrpy; UChar_t Npstripy[nstr]; UChar_t Ntstripy[nstr]; UShort_t Istripy[nstr]; //UInt_t Istripy[nstr]; Float_t Qstripy[nstr]; Float_t Ystripy[nstr]; Int_t Nthcali; UChar_t Icaplane[4224]; UChar_t Icastrip[4224]; Int_t Icamod[4224]; Float_t Enestrip[4224]; Int_t Nthcal; UChar_t Icapl[ncal]; UChar_t Icasi[ncal]; UChar_t Icast[ncal]; Float_t Xincal[ncal]; Float_t Yincal[ncal]; Float_t Zincal[ncal]; Float_t Erelcal[ncal]; Int_t Nthnd; UChar_t Itubend[nnd]; UChar_t Iparnd[nnd]; Float_t Xinnd[nnd]; Float_t Yinnd[nnd]; Float_t Zinnd[nnd]; Float_t Xoutnd[nnd]; Float_t Youtnd[nnd]; Float_t Zoutnd[nnd]; Float_t Erelnd[nnd]; Float_t Timend[nnd]; Float_t Pathnd[nnd]; Float_t P0nd[nnd]; Int_t Nthcard; UChar_t Iparcard[ncar]; UChar_t Icard[ncar]; Float_t Xincard[ncar]; Float_t Yincard[ncar]; Float_t Zincard[ncar]; Float_t Xoutcard[ncar]; Float_t Youtcard[ncar]; Float_t Zoutcard[ncar]; Float_t Erelcard[ncar]; Float_t Timecard[ncar]; Float_t Pathcard[ncar]; Float_t P0card[ncar]; // List of branches TBranch *b_Irun; //! TBranch *b_Ievnt; //! TBranch *b_Ipa; //! TBranch *b_X0; //! TBranch *b_Y0; //! TBranch *b_Z0; //! TBranch *b_Theta; //! TBranch *b_Phi; //! TBranch *b_P0; //! TBranch *b_Nthtof; //! TBranch *b_Ipltof; //! TBranch *b_Ipaddle; //! TBranch *b_Ipartof; //! TBranch *b_Xintof; //! TBranch *b_Yintof; //! TBranch *b_Zintof; //! TBranch *b_Xouttof; //! TBranch *b_Youttof; //! TBranch *b_Zouttof; //! TBranch *b_Ereltof; //! TBranch *b_Timetof; //! TBranch *b_Pathtof; //! TBranch *b_P0tof; //! TBranch *b_Nthcat; //! TBranch *b_Iparcat; //! TBranch *b_Icat; //! TBranch *b_Xincat; //! TBranch *b_Yincat; //! TBranch *b_Zincat; //! TBranch *b_Xoutcat; //! TBranch *b_Youtcat; //! TBranch *b_Zoutcat; //! TBranch *b_Erelcat; //! TBranch *b_Timecat; //! TBranch *b_Pathcat; //! TBranch *b_P0cat; //! TBranch *b_Nthcas; //! TBranch *b_Iparcas; //! TBranch *b_Icas; //! TBranch *b_Xincas; //! TBranch *b_Yincas; //! TBranch *b_Zincas; //! TBranch *b_Xoutcas; //! TBranch *b_Youtcas; //! TBranch *b_Zoutcas; //! TBranch *b_Erelcas; //! TBranch *b_Timecas; //! TBranch *b_Pathcas; //! TBranch *b_P0cas; //! TBranch *b_Nthspe; //! TBranch *b_Iparspe; //! TBranch *b_Itrpb; //! TBranch *b_Itrsl; //! TBranch *b_Itspa; //! TBranch *b_Xinspe; //! TBranch *b_Yinspe; //! TBranch *b_Zinspe; //! TBranch *b_Xoutspe; //! TBranch *b_Youtspe; //! TBranch *b_Zoutspe; //! TBranch *b_Xavspe; //! TBranch *b_Yavspe; //! TBranch *b_Zavspe; //! TBranch *b_Erelspe; //! TBranch *b_Pathspe; //! TBranch *b_P0spe; //! TBranch *b_Nxmult; //! TBranch *b_Nymult; //! TBranch *b_Nstrpx; //! TBranch *b_Npstripx; //! TBranch *b_Ntstripx; //! TBranch *b_Istripx; //! TBranch *b_Qstripx; //! TBranch *b_Xstripx; //! TBranch *b_Nstrpy; //! TBranch *b_Npstripy; //! TBranch *b_Ntstripy; //! TBranch *b_Istripy; //! TBranch *b_Qstripy; //! TBranch *b_Ystripy; //! TBranch *b_Nthcali; //! TBranch *b_Icaplane; //! TBranch *b_Icastrip; //! TBranch *b_Icamod; //! TBranch *b_Enestrip; //! TBranch *b_Nthcal; //! TBranch *b_Icapl; //! TBranch *b_Icasi; //! TBranch *b_Icast; //! TBranch *b_Xincal; //! TBranch *b_Yincal; //! TBranch *b_Zincal; //! TBranch *b_Erelcal; //! TBranch *b_Nthnd; //! TBranch *b_Itubend; //! TBranch *b_Iparnd; //! TBranch *b_Xinnd; //! TBranch *b_Yinnd; //! TBranch *b_Zinnd; //! TBranch *b_Xoutnd; //! TBranch *b_Youtnd; //! TBranch *b_Zoutnd; //! TBranch *b_Erelnd; //! TBranch *b_Timend; //! TBranch *b_Pathnd; //! TBranch *b_P0nd; //! TBranch *b_Nthcard; //! TBranch *b_Iparcard; //! TBranch *b_Icard; //! TBranch *b_Xincard; //! TBranch *b_Yincard; //! TBranch *b_Zincard; //! TBranch *b_Xoutcard; //! TBranch *b_Youtcard; //! TBranch *b_Zoutcard; //! TBranch *b_Erelcard; //! TBranch *b_Timecard; //! TBranch *b_Pathcard; //! TBranch *b_P0card; //! // public: Digitizer(TTree *tree, char* &file_raw); // constructor void Close(); void SetTree(TTree *tree) {fhBookTree = tree;}; void Loop(); // does the looping over events void DigitizePSCU(UInt_t, UChar_t, UShort_t*); // digitizes the CPU header void AddPadding(); void DigitizeRunHeader(); void DigitizeRunTrailer(); // void DigitizeTRIGGER(); // SO nov'07: included in DigitizeTOF void DigitizeTOF(int np,float *atte1,float *atte2,float *lambda1,float *lambda2); // digitizes the tof void LoadTOFCalib(int np,float *atte1,float *atte2,float *lambda1,float *lambda2); //load TOF calibration void DigitizeAC(); // digitizes the anti-counter void DigitizeND(); // digitizes the ND void DigitizeS4(); // digitizes the S4 void DigitizeCALO(); // digitizes the calorimeter void DigitizeCALOCALIB(); // digitizes the calorimeter calibration void DigitizeCALORAW(); // digitizes the calorimeter void DigitizeCALOCOMPRESS(); // digitizes the calorimeter void DigitizeCALOFULL(); // digitizes the calorimeter Float_t GetCALOen(Int_t sec, Int_t plane, Int_t strip); // retrieve calorimeter strip energy from the simulation void ClearCaloCalib(Int_t s); // clear calorimeter calibration variables for section s Int_t CaloLoadCalib(Int_t s,TString fcalname, UInt_t calibno); // load calorimeter calibration variables for section s from file fcalname entry calibno void CaloLoadCalib(); void DigitizeDummy(); // digitizes the dummy detector // ToF methods: UChar_t EvaluateCrcTof(UChar_t*); void Paddle2Pmt(Int_t, Int_t, Int_t*, Int_t*); //void Paddle2Pmt(Int_t, Int_t, Int_t &pmtleft, Int_t &pmtright); UChar_t Bin2GrayTof(UChar_t, UChar_t); void Crc8Tof(UChar_t*, UChar_t*); UChar_t EvaluateCrcTrigger(UChar_t*, Int_t); UShort_t* GetDataAC(){return(fDataAC);}; // retrieve AC data (not used right now) UShort_t* GetDataCALO(){return(fDataCALO);}; // retrieve AC data (not used right now) // methods for Tracker void DigitizeTrack(); // digitizes the Tracker data void DigitizeTrackCalib(Int_t ii); // digitizes the Tracker calibration (x view or y view) void WriteTrackCalib(); // writes Tracker calibration to file void ClearTrackCalib(); // clear tracker calibration void LoadTrackCalib(); // load in memmory tracker calibration void CompressTrackData(Float_t AdcTrack[fNviews][fNstrips_view]); // Compress and Digitize data of one Ladder in turn void LoadMipCor(); // Load the strip calibration in memory Float_t SaturationTrackx(Float_t ADC); // Saturation simulation Float_t SaturationTracky(Float_t ADC); // Saturation simulation // end methods for Tracker void WriteRunHeader(); void WriteRunTrailer(); void WriteData(); // writes data to file void ReadData(); // }; #endif /* DIGITIZER_H */