//////////////////////////////////////////////////////////////////// /// \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. /// 17 October 2018 : Aobo Li - Livetime 2.0: /// * Moving Retrigger Cut and Nhit Burst Cut out of LivetimeCuts, now /// there are two seperate datacleaning cut (RetriggerCut.cc & NhitBurstCut.cc), /// LivetimeCuts.cc is only used for calculating livetime. /// * Adding "livetime_mask" option to accept customized datacleaning mask for livetime calculation /// * Now using Time Index instead of UniversalTime to calculate livetime /// * Adding MissedCountBurst cut, rewritting Muon cut and Atmospheric Neutrino Cut /// * Livetime Table Version 2, tracking Muon Cut and Atmospheric Neutrino Cut separately. /// /// \details This processor tracks livetime of each run based on the given /// cuts: /// *retrigger cut /// *nhit burst cut /// *TPMuonFollower Cut(short) /// *CAEN loss livetime burst cut /// *Pedestal Cut /// *Missed Muon Follower Cut /// *Atmospheric Neutrino /// *Missed Muon Follower Cut /// *Missed Channel Counts Cut /// and output the raw livetime, individual cut time, overlap /// among cuts and final livetime to the run table of each run /// in ratdb. /// //////////////////////////////////////////////////////////////////// #ifndef __RAT_LivetimeCuts__ #define __RAT_LivetimeCuts__ #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); // virtual 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, double fBurstWindow, int fBurstCutGTID[2], double fBurstCutTime[3], std::vector& fFirstBurstReadout, std::vector& fLastBurstReadout, std::vector& fBurstReadout, int fBurstBit); //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 any follower type datacleaning cut based on the GTID read from //corresponding ratdb table, and store its livetime respectively for further analysis. bool FollowerIdentifier(DS::EV& ev, std::vector& muonReadout, double muonWindow, double& muonCutTime, double& muonCut, int followerBit); //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 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); //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, double offset = 0.0); //Pushing the current cut to the cutting pool with given begin and end time. //Soft Push: Allow the begin or end of the cut to exceed the run start and run end. double PushToCuttingRecord(double begin, double end, int dcbit, bool softPush = false); 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 integer defines the datacleaning bit of dc cuts that has a livetime effect. A user can pass in //a different dc mask to disable some of them for specific analysis. int fFoundRetriggers; int fFoundNhitBurst; int fFoundMuon; int fFoundCLBurst; int fFoundMC; int fFoundAtmospheric; int fFoundPedestal; int fFoundMissedMuon; //Parameters for applying Nhit Burst cut: //The Nhit Burst Cut Window double 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 double 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: double fCAENWindow; int fCLBurstCutGTID[2]; double fCLBurstCutTime[3]; std::vector fFirstCLBurstReadout; std::vector fLastCLBurstReadout; std::vector fCLBurstReadout; //Parameters for applying Retrigger livetime cut: double fRetriggerWindow; int fRetriggerCutGTID[2]; double fRetriggerCutTime[3]; std::vector fFirstRetriggerReadout; std::vector fLastRetriggerReadout; double fMuonWindow;//Cutting window of TPMuonFollower cut double fMuonCutTime;//Accumulated Cut Time from Muon. double fAtmWindow;////Cutting window of Atmospheric Neutrino cut double fAtmCutTime;//Accumulated Cut Time from Atmospheric Neutrino. //Parameters for applying Missed Muon livetime cut, basically identical //to those for TPMuonFollower Cut double fMissedMuonCut; double fMissedMuonWindow; double fMissedMuonCutTime; std::vector fMissedMuonReadout; //Parameters for pedestal cut double fPedestalCutTime[3]; double fPedWindow; //Parameters for Missed Count Burst(follower) Cut double fMCCut; double fMCTimeCut; // Time to cut after the burst std::vector fMCGTIDs; // GTIDs at the start of a burst double fMCCutTime;//Accumulated Cut Time for MC Cut double fStart_times[3];//Start time of the run for raw livetime double fStop_times;//Stop time of the current events double fLength;//Length of the run from RUN table //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