#include #include #include #include #include #include #include #include #include namespace RAT { CAEN::CAEN() { fEventID = -1; // Init to -1 s.t. first event is event 0 fSYNC = false; fSYNC24 = false; fTrigTagTime = 0; fNWords = 0; fBit24 = 0; fIOPins = 0; fChannelInfo.resize(8); } void CAEN::BeginOfRun() { DBLinkPtr fLdaq = DB::Get()->GetLink("DAQ"); DBLinkPtr fRLDAQ = DB::Get()->GetLink("DAQ_RUN_LEVEL"); fSigDelay = fLdaq->GetD("trigSumDelay"); fChannelMask = fRLDAQ->GetI("channelMask"); fFormat = fRLDAQ->GetI("formatCAEN"); fBoardID = fRLDAQ->GetI("boardID"); fSamples = fRLDAQ->GetI("nSample"); fPreSamples = fRLDAQ->GetI("nPreSample"); fLatency = fLdaq->GetI("latency"); fNBits = fLdaq->GetI("nBits"); fScale = fLdaq->GetDArray("scaleCAEN"); fOffset = fRLDAQ->GetDArray("offsetCAEN"); } void CAEN::SetClock() { fTrigClock = new clock; fTrigClock->SetFrequency(125000000.0); // 125MHz trigger clock fTrigClock->SetNbits(31); fTrigClock->SetRolloverInterval(); } CAEN::~CAEN() { delete fTrigClock; } void CAEN::SetIO(bool isSYNC, bool isSYNC24){ // Signals on IO pins fSYNC = isSYNC; fSYNC24 = isSYNC24; } void CAEN::TriggerEvent() { // Ascertain trigger time i.e. next clock tick after GT arrival // (MC event occurred at fMCEventTime + // GT arrived at CAEN at fTrigTime after that) double trigTime = fTrigClock->GetNextTickTime(fMCEventTime + fTrigTime); // Set start time for digitising (in ref frame of this MC event) fStartTime = trigTime - (4.0*(fPreSamples-fLatency)) - fMCEventTime; // Adjust for delay of digitised TrigSums fStartTime -= fSigDelay; // Set TrigTagTime: tick count on which GT was latched fTrigTagTime = fTrigClock->GetCount(); // Set event ID IncrementEventID(); // Set IO Pins fIOPins = 0; if(fSYNC)BitManip::SetBit(fIOPins, 0); if(fSYNC24)BitManip::SetBit(fIOPins, 1); // Event size fNWords = fSamples + 4; } void CAEN::Digitise(AnalogSignal *sum, int i) { // If the channel is masked in if(BitManip::TestBit(fChannelMask,i)){ // Digitise sum on channel i fChannelInfo[i].resize(fSamples); for(int c=0;cGetHeight(fStartTime + c*4.0); double scaled = charge*fScale[i]; scaled += fOffset[i]; scaled = round(scaled); if (scaled > 4095) scaled = 4095; if (scaled < 0) scaled = 0; // DIGITISE! UShort_t val = (UShort_t) scaled; fChannelInfo[i][c] = val; } } } void CAEN::IncrementEventID() { // Increment the 24-bit event counter ++fEventID; // If we're at 2^24, rollover if(BitManip::TestBit(fEventID,24)) fEventID = 0; } } // namespace RAT