#include #include #include using namespace std; namespace RAT { void QClusterCut::BeginOfRun(DS::Run&) { fLClean = DB::Get()->GetLink("DATACLEANING",fName); fBadCrates = fLClean->GetIArray("badcrates"); fBadCards = fLClean->GetIArray("badcards"); fBadChans = fLClean->GetIArray("badchans"); fWindowSize = fLClean->GetI("window_size"); fMaxHits = fLClean->GetI("maxhits"); fMaxBad = fLClean->GetI("maxbad"); fCutMode = fLClean->GetI("cutmode"); fUnCalQHSLow = fLClean->GetI("uncalQHS_low"); fUnCalQHSHigh = fLClean->GetI("uncalQHS_high"); fUnCalQHLLow = fLClean->GetI("uncalQHL_low"); fUnCalQHLHigh = fLClean->GetI("uncalQHL_high"); fUnCalQLXLow = fLClean->GetI("uncalQLX_low"); fUnCalQLXHigh = fLClean->GetI("uncalQLX_high"); fCalQHSLow = fLClean->GetI("calQHS_low"); fCalQHSHigh = fLClean->GetI("calQHS_high"); fCalQHLLow = fLClean->GetI("calQHL_low"); fCalQHLHigh = fLClean->GetI("calQHL_high"); fCalQLXLow = fLClean->GetI("calQLX_low"); fCalQLXHigh = fLClean->GetI("calQLX_high"); } Processor::Result QClusterCut::DSEvent(DS::Run&, DS::Entry& ds) { bool pass = true; // If any triggered event fails, they all fail for( size_t iEV = 0; iEV < ds.GetEVCount(); iEV++ ) if( Event(ds, ds.GetEV(iEV)) != OKTRUE ) pass = false; return pass ? OKTRUE : OKFALSE; } Processor::Result QClusterCut::Event(DS::Entry&, DS::EV& ev) { int nbad; int pmtid,ccc; int win_hits; vector cal_pmts; vector uncal_pmts; vector ccc_to_hit(19*16*32,0); vector win_cccs(fWindowSize); fPassFlag = true; // should pass orphans and zero hit events if (ev.GetUncalPMTs().GetCount() == 0){ // || ev.IsOrphan() UpdateMask(ev); return fPassFlag ? OKFALSE : OKTRUE; } int calibrated = 0; if (ev.GetCalPMTs().GetCount() == ev.GetUncalPMTs().GetCount()) // FIXME almost guaranteed to give the wrong answer calibrated = 1; // now loop over all hit tubes // we want to use calibrated info where available // and use raw values where its not for (size_t ipmt=0;ipmtGetID(); ccc_to_hit[pmtid] = ipmt; } for (int icrate=0;icrate<19;icrate++){ if (!fPassFlag) break; for (int icard=0;icard<16;icard++){ if (!fPassFlag) break; for (int ichan=0;ichan<32;ichan++){ if (!fPassFlag) break; ccc = icrate*16*32+icard*32+ichan; if (ccc <= (19*16*32-fWindowSize)){ win_hits = 0; // find any window of events with enough hits in it for (int iwin=0;iwin= fWindowSize) win_hits = fWindowSize-1; } } // test the window for bad charge channels if (win_hits > fMaxHits){ nbad = 0; // loop through all the hits in the window for (int iwin=0;iwinGetQHS(); int uqhl = up->GetQHL(); int uqlx = up->GetQLX(); if (calibrated){ qhs = cp->GetQHS(); qhl = cp->GetQHL(); qlx = cp->GetQLX(); }else{ qhs = -9999; qhl = -9999; qlx = -9999; } // check charges if (fCutMode == 3){ // use calibrated if available, raw adc if not if ((abs(qhs) > 8000 and uqhs < fUnCalQHSLow) or (abs(qhs) > 8000 and uqhs > fUnCalQHSHigh) or (abs(qhs) < 8000 and qhs < fCalQHSLow) or (abs(qhs) < 8000 and qhs > fCalQHSHigh) or (abs(qhl) > 8000 and uqhl < fUnCalQHLLow) or (abs(qhl) > 8000 and uqhl > fUnCalQHLHigh) or (abs(qhl) < 8000 and qhl < fCalQHLLow) or (abs(qhl) < 8000 and qhl > fCalQHLHigh) or (abs(qlx) > 8000 and uqlx < fUnCalQLXLow) or (abs(qlx) > 8000 and uqlx > fUnCalQLXHigh) or (abs(qlx) < 8000 and qlx < fCalQLXLow) or (abs(qlx) < 8000 and qlx > fCalQLXHigh)){ nbad++; } }else if (fCutMode == 2){ // only use calibrated if ((abs(qhs) < 8000 and qhs < fCalQHSLow) or (abs(qhs) < 8000 and qhs > fCalQHSHigh) or (abs(qhl) < 8000 and qhl < fCalQHLLow) or (abs(qhl) < 8000 and qhl > fCalQHLHigh) or (abs(qlx) < 8000 and qlx < fCalQLXLow) or (abs(qlx) < 8000 and qlx > fCalQLXHigh)){ nbad++; } }else{ // only use raw adc if ((uqhs < fUnCalQHSLow) or (uqhs > fUnCalQHSHigh) or (uqhl < fUnCalQHLLow) or (uqhl > fUnCalQHLHigh) or (uqlx < fUnCalQLXLow) or (uqlx > fUnCalQLXHigh)){ nbad++; } } if (nbad >= fMaxBad){ // we have failed the cut fPassFlag = false; } } // end if / else a bad channel } // end loop over hits in window } // end if enough hits in window } // end if not at the end of cccs } // end loop over chans } // end loop over cards } // end loop over crates UpdateMask(ev); return fPassFlag ? OKFALSE : OKTRUE; } } // namespace RAT