//////////////////////////////////////////////////////////////////// // Processor for generating constants from the ECA // // Author: Gabriel D. Orebi Gann Author and contact // Javier Caravaca - Contact // // REVISION HISTORY: // // Oct 2013 G.D. Orebi Gann Add vector of ints for // TSlope point status // + K. Kamdin Fix array indexing // & extra debug output // Sep 2014 K. Kamdin Add options for extra // diagnostic output. // Add run_status field to // .ratdb output // Add new flags for more // robust checks. // Jun 24 N Barros Change table header to // new database schema // Jun 27 J. Caravaca Added rate and pattern as // an index to ECA constants // Make compatible with SNO // EpedRecords // Added extra output for monitoring // // // This class generates ECA constants from the electronics // calibrations runs. // // //////////////////////////////////////////////////////////////////// #ifndef __RAT_ECAProc__ #define __RAT_ECAProc__ #include #include #include #include #include #include #include #include #include "dprintf.hpp" #include "fileio.hpp" #include "multiio.hpp" #include "TFile.h" #include "TMath.h" #include "TGraphErrors.h" #include "TF1.h" #include namespace RAT { class ECAProc : public Processor { public: ECAProc(); virtual ~ECAProc(); void BeginOfRun( DS::Run& run ); void EndOfRun( DS::Run& run ); virtual Processor::Result DSEvent(DS::Run& run, DS::Entry& ds); protected: // Output and status methods void Die(std::string message="", int flag_err=0, float info1=0, float info2=0, int return_code=1); void DontDie(std::string message="", int flag_err=0, float info1=0, float info2=0); void InitLogOut(std::string _logfilename); void InitECARoot(std::string _rootfilename); void CloseECARoot(); void CreateECATable(); void CreateECAMoni(); void MergeECAResults(); void Summarise(); bool MatchPrevTinj(std::string msg); int IdentifyLast(int cccc); // Kate void WriteTSlopesRoot(); void WriteECADebugHistosRoot(); void InitECADebugOut(std::string _debugfilename); void WriteECADebugHeader(); void FillECADebug(); void CloseECADebug(); void ReassignSigs(); std::vector fCellsToReassign; // Diagnostics void PedDiagnostic(); std::vector TSlopeFilter(int cccc); int TSlopeNGood(int cccc); void TSlopeDiagnostic(); std::vector TSlopeBadCombined(int cccc); // Calculations void MultiCalc(int n, std::vector arg); void TSlopeFit(int cccc); void LinearFit(int n, float* &x, float* &y, float* &p, float valid); void CubicFit(int n, float* &x, float* &y, float* &ye, float* &p, float* &pe, float& chisq); bool FileExists(std::string filename); void LoadPatterns(); // ECA control information (user-defined) DBLinkPtr fECAbank; DBLinkPtr fECAPatt; std::vector fCurrentPattern; std::vector > > fPatterns; int fECAflag; int fPassNo; int fRunRangeMax; std::string fECAIndex; UInt_t fRunMask; int fECArate; int fECAmerge; int fECAlogverb; int fECAdiff; int fRunMerge; int fDoDroop; // DQIDs DBLinkPtr fDQXXbank; std::vector fDQID; std::vector fECADQID; std::vector fECAPrevDQID; // Histograms ECAHists fHists; // Status words ECABits fECABits; // Results // NB charges and TAC in adc counts, therefore ints // However if the median falls between 2, it will be a float // and float = int = 32-bit, therefore not using any extra space this way int fOverallMask; std::vector fCellStatus; std::vector fTestChannel; int fNChanNotTested; // Pedestals and widths std::vector fCellQHS; std::vector fCellQHL; std::vector fCellQLX; std::vector fCellTAC; std::vector fCellSigQHS; // Estimate of 1 sigma spread of points std::vector fCellSigQHL; std::vector fCellSigQLX; std::vector fCellSigTAC; std::vector fCellWidthQHS; // P80-P50, used for width tests (from SNO) std::vector fCellWidthQHL; std::vector fCellWidthQLX; std::vector fCellWidthTAC; std::vector > fCellNo; // store cell# for 1st 16 ev on each chan // Tslopes // number of entries needed for TSlope-point flags per cell //(32-bits per word therefore NPoints/32 entries needed) int fNdim; // Flag bad points in a TAC slope for a single cell (32-bit word per cell) std::vector > fCellBad; // Flag suspicious points in a TAC slope for a single cell std::vector > fCellSusp; std::vector > fCellCurl; // points on TAC slope that are in the curl region // Arrays to hold median/width at each point, and fit parameters, per cell std::vector > fCellTACPoints; // 2D array of fNTotCell cells // * (31 tac points) per cell std::vector > fCellTACrms; // 2D array of fNTotCell cells // * (31 tac points) per cell std::vector > fCellTACwidth; std::vector > fCellTACFits; // 2D array of fNTotCell cells // * (4 fit pars) per cell // X values should be the same for every cell, and every event; but are floats! std::vector fEVTACX; // Last good point on slope, in ADC counts //std::vector fLastTAC; // Previous ECA numbers std::vector fPrevStatus; std::vector fPrevQHS; std::vector fPrevQHL; std::vector fPrevQLX; std::vector fPrevTAC; std::vector fPrevSigQHS; std::vector fPrevSigQHL; std::vector fPrevSigQLX; std::vector fPrevSigTAC; std::vector > fPrevBad; std::vector > fPrevTACPoints; std::vector > fPrevTACFits; std::vector fPrevEVTACX; //std::vector fPrevLast; // Number of events per cell (for pedestals) std::vector fNevCell; // Number of events per point on slope, per cell (Tslope) // i.e. fNevTACSlp[cell number][point number] = Nevents std::vector > fNevTACSlp; // Actual event values per cell (a length-fNMaxEV array per cell) // e.g. fEVQHS[cell #][event #] = qhs std::vector > fEVQHS; std::vector > fEVQHL; std::vector > fEVQLX; std::vector > fEVTAC; // per-cell array of fNSlopepoints, fNMaxEV events each // e.g. fEVTACPoints[cell #][slope point][event #] = measured T (V in adc counts) std::vector > > fEVTACPoints; int fNMaxEV; // kate int fLastPatternID; int fTimeSkipped; //extra diagnostics int fSuperDebug; std::string fTSlopesRootName; TFile* fTSlopesRootFile; std::vector fTSlopes; std::vector fLinearFits; std::vector fCubicFits; TH1F* fTrigWordHist; TH1F* fTrigWordHistSkippedEV; TH1F* fResetTimes; std::string fECAdebugdbname; omtext ecadebugrecord; oftext fECAdebugdbfile; std::string fECAdebugname; std::vector > fCellTACFitErrs; // 2D array of fNTotCell cells // * (4 fit parerrs) per cell std::string fECAdebughistosname; TFile* fdebughistosROOTfile; TH1F* fb0_NHit100Lo; TH1F* fb1_NHit100Med; TH1F* fb2_NHit100Hi; TH1F* fb3_NHit20; TH1F* fb4_NHit20LB; TH1F* fb5_ESumLo; TH1F* fb6_ESumHi; TH1F* fb7_OWLN; TH1F* fb8_OWLELo; TH1F* fb9_OWLEHi; TH1F* fb10_PulseGT; TH1F* fb11_Prescale; TH1F* fb12_Pedestal; TH1F* fb13_Pong; TH1F* fb14_Sync; TH1F* fb15_EXTASY; TH1F* fb16_Ext2; TH1F* fb17_Ext3; TH1F* fb18_Ext4; TH1F* fb19_Ext5; TH1F* fb20_Ext6; TH1F* fb21_Ext7; TH1F* fb22_Ext8PulseAsync; TH1F* fb23_SpecialRaw; TH1F* fb24_NCD; TH1F* fb25_SoftGT; TH1F* fb26_MissedTrig; int fRunNo; int fNcrate; int fNcard; int fNchannel; int fNcell; int fTotChannel; int fNTotCell; int fNDSEvents; int fNSlopePoints; int fPrevNSlopePoints; int fNTACFitPars; float fMedian; float fWidth; float fWidth2; float fSig; BitManip *fBits; bool isSNOdata; UInt_t fGTDelC; UInt_t fGTDelF; UInt_t fPattern; UInt_t fCalType; UInt_t fPattSet; UInt_t fPedWidth; UInt_t fNumSkip; UInt_t fHitSkip; float fTinj; int fArrayID; int fNSet; std::vector fNPatt; float fDAQns_offset; float fDAQns_max; float fDAQns_scale1; float fDAQns_scale2; // For output omtext ecalog; std::string fECAlogname; std::string fECAdbname; std::string fECAmoniname; std::string fECArootname; oftext fECAlogfile; oftext fECAdbfile; TFile *fECArootfile; }; extern omtext ecalog; } // namespace RAT #endif