//////////////////////////////////////////////////////////////////// /// \class RAT::LivetimeCuts /// /// \brief This Proc updates the bitmask for all the livetime /// cuts, calculate their overlaps and output the final /// livetime to the LIVETIME table. /// /// \author Aobo Li /// \contact Aobo Li /// /// REVISION HISTORY:\n /// 12 November 2017 : Aobo Li - first version /// 21 December 2017 : Aobo Li - Added secondary .json reading facility /// Added prototype pedestal livetime cut /// Bugfix /// 9 January 2018 : Aobo Li - Added livetime sacrifice for each cut /// Added deadtime from Missed Muon Follower /// Cut /// 16 January 2018 : Aobo Li - Making the code two-pass /// Dealing with situations when no RUN table /// is produced. /// /// \details This processor upgrade bitmask for the following livetime /// cuts: /// *retrigger cut /// *nhit burst cut /// Calculate livetime of each run based on the given following /// cuts: /// *retrigger cut /// *nhit burst cut /// *TPMuonFollower Cut(short) /// *CAEN loss livetime burst cut /// *Pedestal Cut /// *Missed Muon Follower Cut /// and output the raw livetime, individual cut time, overlap /// among cuts and final livetime to the run table of each run /// in ratdb. /// This code is made two-pass in order to adapt grid processing need: /// Pass 1: Calculate Livetime, but do not update DC bitmask. This pass /// need to run on the run level processing macro. /// Pass 2: Apply DC bitmask, but do not calculate livetime. This pass /// Can run on the subrun level. /// //////////////////////////////////////////////////////////////////// #ifndef __RAT_LivetimeCuts__ #define __RAT_LivetimeCuts__ #include #include #include #include #include #include #include namespace RAT { class LivetimeCuts : public DataCleaningProc { public: LivetimeCuts() : DataCleaningProc("tpburstcut",1){}; virtual ~LivetimeCuts(){}; 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: virtual Processor::Result Event(DS::Entry& ds, DS::EV& ev); //This method identifies burst events cut. It takes in the array //of first event, last event and burst events, determine the livetime //of each burst, and store them for further analysis. bool BurstIdentifier(DS::EV& ev, DS::UniversalTime& fBurstWindow, int fBurstCutGTID[2], DS::UniversalTime fBurstCutTime[3], std::vector& fFirstBurstReadout, std::vector& fLastBurstReadout, std::vector& fBurstReadout); //This method identifies retrigger events, and update the first event bit //of each retrigger stream, and store its livetime for further analysis. bool RetriggerIdentifier(DS::EV& ev); //This method identifies muon follower events based on the GTID read from //TPMuonFollower Cut, and store its livetime respectively for further analysis. bool MuonIdentifier(DS::EV& ev, std::vector& muonReadout, DS::UniversalTime& muonWindow, DS::UniversalTime& muonCutTime, DS::UniversalTime& muonCut); //This method tags out forced events. Forced events(pulseGT, pedestal and Ext-Asy) //Are ignored by all livetime cuts. bool ForcedEventsTagger(DS::EV& ev); //This method check the correspondence of each start event and end event of a cut livetime period. //With this method, we can make sure the start and end pairs in fCutStart and fCutEnd are one-to-one //correspondent. bool CorrespondenceCheck(int eventSet[2], std::vector& firstArray, std::vector& secondArray); //This method calculate the livetime between start UniversalTime and end UniversalTime, then //return them as a double number. double CalculateLivetime(DS::UniversalTime &start, DS::UniversalTime &end); //This method calculate the sacrifice of each livetime cuts, the value could be used //for the uncertainty calculation of each livetime cuts. double CalculateSacrifice(int cut, double runLength); //This method read files corresponding to the input cut name, and construct arrays for //the cut. It first attempts to read files from ratdb. If ratdb does not respond, it will //attempt to read the .json file. bool ReadFile(DS::Run& run, std::string cutName, std::vector& firstReadout, std::vector& lastReadout, std::vector& burstReadout); std::vector fDCBitCollection;//This store all the Datacleaning bits we need to update in this code std::vector fCutStart;//This store the start time of each livetime cut std::vector fCutEnd;//This store the end time of each livetime cut, it is correspondent to fCutStart. //The following booleans define if we need to apply the cut, there are two situations //that the cut will not be applied: //1. The ratdb table of the listed cut is not found. //2. The ratdb table of the listed cut is found, but no event is cut by this cut. bool fFoundRetriggers; bool fFoundNhitBurst; bool fFoundMuon; bool fFoundCLBurst; bool fFoundMissedMuon; //Parameters for applying Nhit Burst cut: //The Nhit Burst Cut Window DS::UniversalTime fNhitBurstWindow; //NhitBurstCutGTID array: [1]Cut Start Event GTID, [2]Cut End EVent GTID int fNhitBurstCutGTID[2]; //Nhit Burst Cut Time array: [1]Cut Start Time, [2]Cut End Time, [3]Accumulated Cut Time DS::UniversalTime fNhitBurstCutTime[3]; //Contains all First Event of each Nhit Burst std::vector fFirstNhitBurstReadout; //Contains all Last Event of each Nhit Burst std::vector fLastNhitBurstReadout; //Contains all Nhit Burst events. std::vector fNhitBurstReadout; //Contain the Nhit Threshold for Nhit Burst Cut; UInt_t fNThreshold; //Parameters for applying CAEN Loss Burst livetime cut: DS::UniversalTime fCAENWindow; int fCLBurstCutGTID[2]; DS::UniversalTime fCLBurstCutTime[3]; std::vector fFirstCLBurstReadout; std::vector fLastCLBurstReadout; std::vector fCLBurstReadout; //Parameters for applying Retrigger livetime cut: DS::UniversalTime fRetriggerWindow; int fRetriggerCutGTID[2]; DS::UniversalTime fRetriggerCutTime[3]; std::vector fFirstRetriggerReadout; std::vector fLastRetriggerReadout; //Parameters for applying Muon livetime cut: DS::UniversalTime fMuonCut;//Current Muon Cut end time bool fFakeMuon;//Indicate whether we have a fake muon inserted in this run. DS::UniversalTime fLastMuon;//Time for the last muon in the previous run DS::UniversalTime fMuonWindow;//Muon Cut Window: TPMuonFollower Short DS::UniversalTime fMuonCutTime;//Accumulated Cut Time from Muon. std::vector fMuonReadout;//Contains GTID of all Muons. //Parameters for applying Missed Muon livetime cut, basically identical //to those for TPMuonFollower Cut DS::UniversalTime fMissedMuonCut; DS::UniversalTime fMissedMuonWindow; DS::UniversalTime fMissedMuonCutTime; std::vector fMissedMuonReadout; //Parameters for pedestal cut DS::UniversalTime fPedestalCutTime[3]; DS::UniversalTime fPedWindow; double fStart_times[3];//Start time of the run for raw livetime double fStop_times[3];//Stop time of the run for raw livetime DS::UniversalTime fValidEndTime; //This is a dual-purpose functinal variable: //1. To serve as a Null Pointer of UniversalTime //2. To define the zero time(0 days,0 scecond,0 nanosecond) to calculate // accumulated cut time. DS::UniversalTime fNullTime; //This array counts the number of events in each data set, used for //calculating the event rate for each cut. int fRateCount[3]; int fValidFirstGTID;//First valid event GTID read from run table UInt_t fRunType;//Run type word read from run table int fRunNumber;//Run number read from run table std::string fLivetimeTableName;//Name of the LIVETIME table for each run bool fInvalidTime;//If the current run's run time is invalid }; } // namespace RAT #endif