/////////////////////////////////////////////////////////////////////////////// /// \class RAT::TPBurstCut /// /// \brief Tagging Retrigger events, Nhit Burst Events and CAEN Loss Burst Events, /// then store their GTID in ratdb. /// /// \contact Aobo Li /// /// REVISION HISTORY:\n /// 28 Sept. 2017 Aobo Li-First Version /// 7 Dec. 2017 Aobo Li-Adding 3rd pass: CAEN Loss Burst Cut /// set pass parameters in ratdb file to always be -1 /// Adding a new field in ratdb file: cut applied /// (1 if any event is cut, 0 otherwise) /// 10 June 2018 Aobo Li-Fixing a bug that large-size cut will make the buffer /// Full and cause a Segmentation Fault(Core Dump), also fix /// any possible case of uncaught clock jump. /// 17 June 2018 AObo Li-Adding Depletion pass for Nhit Burst Cut and CAEN Loss Livetime /// Cut (see detail for depletion pass in the DepletionProcessor Method) /// /// \details This is a Preliminary three pass porcessor for burst events. /// It should only be called by the nearline processing python code. /// It will tag all the retrigger events, nhit burst events and CAEN Loss /// Burst Events Burst Events, and store their GTID in ratdb for further usage. /// Forced trigger and orphans are ignored. /// /// First Pass: tagging all the retrigger events. If one or more event(s) /// happened inside 3 microsecond of its precedent event, they will be /// tagged as retriggers, while the first event will be tagged seperately /// as "first event". /// /// Second Pass: tagging all the nhit burst events. First ignore all retrigger /// events, then if 6 events happened inside 4 second timewindow, all the 6 /// events will be tagged as nhit burst. /// /// Third Pass: tagging all CAEN Loss burst events. First ignore all retrigger /// events, then if 2 CAEN loss events or more happened inside 2ms timewindow, /// the 2 events will be tagged as CAEN loss burst. /// /// Fourth Pass: Depletion pass of Nhit Burst Cut /// /// Fifth Pass: Depletion pass for CAEN Loss Livetime Cut /// //////////////////////////////////////////////////////////////////////////////////// #ifndef __RAT_TPBurstCut__ #define __RAT_TPBurstCut__ #include #include #include #include namespace RAT { class TPBurstCut : public DataCleaningProc { public: TPBurstCut() : DataCleaningProc("tpburstcut",1){}; virtual ~TPBurstCut(){}; virtual Processor::Result DSEvent(DS::Run& /*run*/, DS::Entry& ds); void SetI(const std::string& param, const int value); void BeginOfRun(DS::Run& run); void EndOfRun(DS::Run& run); protected: //The recuesive processor for retrigger and burst cut. virtual Processor::Result BurstProcessor(int currentGTID, double currentTimeIndex); //Filter out the events that we don't consider in burst cuts, on first pass //PulseGT, Pedestal and extasy(forced trigger), second pass additionally //retrigger events. If needed we can filter out more events other than those. bool EntryFilter(DS::EV& ev); //Push the info of event to buffer. The buffer stores the GTID and Universal Time //for the events. void PushToBuffer(int GTID, double timeIndex); //Check whether the given events is within the time window comparing with the event //at the beginning of the buffer. If true, it means this is a burst events. bool WithinTimeWindow(double timeIndex); //Extract the time index of given events, returning it as a double time index with respect //to the beginning of the run. double ExtractTimeIndex(DS::UniversalTime& inputTime); //Push the Last event of a burst series into fFirstEvent and fLastEvent Array. This Method //also does two sanity check: //1.One-to-one correspondance check: Make sure the event in fFirstEvent and fLastEvent are // paired, in other word, after iteration the two array should have the same size //2.GTID Reset check. If a GTID reset occured during a burst, split the burst into two burst // series. void PushLastEvent(); //This is a depletion processor called only if fDepletionPass is set to true. It scan through //the entire data set and depelete all events in the cutting window instead of skipping non-target //events during the original pass of the cut. //Example: for Nhit Burst Cut, the target events contains all non-forced-trigger event with Nhit >40, //The original cut will only cut Nhit > 40 event, but the depletion pass will cut all events regardless //of Nhit as long as it's inside the cutting time window. void DepletionProcessor(int currentGTID, double currentTimeIndex); //Reading ratdb tables for the use of later run. The priority from highest to lowest is: //Reading the local .ratdb file //Reading the ratdb table stored inside ratdb //Reading backup .json file void readTables(std::string index, DS::Run& run); //Processing Pass(1,2,3): Buffer of each individual burst series. //Depletion Pass(4,5): Retracing buffer containing all GTID and time one-time-window // prior to the current event. std::vector fBufferTime; std::vector fBufferGTID; //Pass1: store the first events(event that triggers retrigger cut) //Pass2: store the first events of each Nhit burst //Pass3: store the first events of each CAEN loss burst //Pass4: store the first events of each Nhit burst //Pass5: store the first events of each CAEN loss burst std::vector fFirstEvents; //Pass1: store the last events(event that triggers retrigger cut) //Pass2: store the last events of each Nhit burst //Pass3: store the last events of each CAEN loss burst //Pass2: store the last events of each Nhit burst //Pass3: store the last events of each CAEN loss burst std::vector fLastEvents; //Pass1: not in use. //Pass2: store the nhitburst event series. //Pass3: store the CAEN loss event series. //Pass4: store the nhitburst event series. //Pass5: store the CAEN loss event series. std::vector fBurstEvents; //Store all the Retrigger events GTID, used to filter out retriggers for //second pass or later. std::vector fRetriggerReadout; //Burst Window ULong64_t fTwinBurst; //Minimum number of events inside burst window to be characterized as a burst unsigned int fNeventsBurst; //Used to filter out events with nhit lower than certain value. unsigned int fNhitThreshold; //The start time of this run read from RUN table, serve as a reference to all other time stamps. DS::UniversalTime fStartTime; //The total duration of this run read from RUN table double fLength; //The end of current burst, only used for depletion runs. double fCurrentBurstEnd; //Indicating whether the given pass is used to process or deplete. //Processing Pass(1,2,3): Using BurstProcessor to create burst sequences of data //Depleting Pass(4,5): Process through the entire data set again to deplete the event // not being cut by Processing Pass. bool fDepletionPass; //This flag determines whetehr the current event should be pushed to fBurstEvents, //The determination rule is constructed based on the first events and last events //To avoid repetitive push. bool fPushFlag; }; } // namespace RAT #endif