/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Private Member Functions | Private Attributes
PulseParamGenAlg Class Reference

#include <PulseParamGenAlg.h>

List of all members.

Public Member Functions

 PulseParamGenAlg (const string &name, ISvcLocator *pSvcLocator)
virtual ~PulseParamGenAlg ()
virtual StatusCode initialize ()
virtual StatusCode execute ()
virtual StatusCode finalize ()

Private Member Functions

int readPmtIdx (ServiceMode svcMode, DetInfo *detInfo, const DaqPmtChannel *channel)
DetInfogetDetInfo (const DaqCrate *crate)
void processChannel (const DaqPmtChannel *channel, int pmtIdx, DetInfo *detInfo)
bool muonCheck (DetInfo *detInfo, const DaqCrate *crate)
void getProfileHists (DetInfo *detInfo, TProfile **profHists)
bool readCachedData (TProfile **profHists, int *&sensorFullPackedData, TString *&detName)
void computeParams (TProfile **profHists, int *sensorFullPackedData, const char *detName)

Private Attributes

string m_cableSvcName
bool m_excludeMuonEvents
string m_muonTag
double m_muonBlindTime
string m_cachedPulseFile
map< Detector, DetInfo * > m_detInfoMap
ICableSvc * m_cableSvc

Detailed Description

Definition at line 29 of file PulseParamGenAlg.h.


Constructor & Destructor Documentation

PulseParamGenAlg::PulseParamGenAlg ( const string &  name,
ISvcLocator *  pSvcLocator 
)

Definition at line 89 of file PulseParamGenAlg.cc.

  : GaudiAlgorithm(name, pSvcLocator)
{
  declareProperty("ExcludeMuonEvents", m_excludeMuonEvents=false,
                  "Exclude tagged muon events");

  declareProperty("MuonTag",
                  m_muonTag="/Event/Tag/Physics/MuonTight",
                  "Tag for muon events");

  declareProperty("MuonBlindTime", m_muonBlindTime=200,
                  "Time window (us) for ignoring post-muon events");

  declareProperty("CableSvcName", m_cableSvcName="CableSvc",
                  "Name of cable service");

  declareProperty("CachedPulseFile", m_cachedPulseFile="",
                  "ROOT file containing cached pulse profile histograms");
}
PulseParamGenAlg::~PulseParamGenAlg ( ) [virtual]

Definition at line 111 of file PulseParamGenAlg.cc.

{
}

Member Function Documentation

StatusCode PulseParamGenAlg::initialize ( ) [virtual]

Definition at line 116 of file PulseParamGenAlg.cc.

{
  m_cableSvc = svc<ICableSvc>(m_cableSvcName, true);
  if (m_cableSvc == NULL) {
    error() << "Unable to initialize cable service" << endreq;
    return StatusCode::FAILURE;
  }

  return this->GaudiAlgorithm::initialize();
}
StatusCode PulseParamGenAlg::execute ( ) [virtual]

Definition at line 187 of file PulseParamGenAlg.cc.

{
  if (!exist<ReadoutHeader>(ReadoutHeader::defaultLocation()))
    return StatusCode::SUCCESS;

  const ReadoutHeader* roHeader =
    get<ReadoutHeader>(ReadoutHeader::defaultLocation());

  const DaqCrate *crate = roHeader->daqCrate();
  DetInfo *detInfo = getDetInfo(crate);
  if (detInfo == NULL) return StatusCode::SUCCESS; // not AD

  if (m_excludeMuonEvents && muonCheck(detInfo, crate))
    return StatusCode::SUCCESS;

  const DaqPmtCrate::PmtChannelPtrList& channels =
    crate->asPmtCrate()->pmtChannelReadouts();

  for (DaqPmtCrate::PmtChannelPtrList::const_iterator iChannel =
         channels.begin(); iChannel != channels.end(); ++iChannel) {

    const DaqPmtChannel* channel = *iChannel;

    if (channel->hitCount() > 1) {
      int pmtIdx = readPmtIdx(ServiceMode(roHeader->context(), 0),
                              detInfo, channel);
      if (pmtIdx >= 0)          // ensure PMT is valid
        processChannel(channel, pmtIdx, detInfo);
    }
  }

  return StatusCode::SUCCESS;
}
StatusCode PulseParamGenAlg::finalize ( ) [virtual]

Definition at line 295 of file PulseParamGenAlg.cc.

{
  if (!m_cachedPulseFile.empty()) { // use cached pulses
    TProfile* profHists[NUM_HISTS];
    int *sensorFullPackedData;
    TString *detName;

    if (!readCachedData(profHists, sensorFullPackedData, detName)) {
      error() << "Unable to read cached pulse data" << endreq;
      return StatusCode::FAILURE;
    }

    computeParams(profHists, sensorFullPackedData, *detName);
  }

  else for (map<Detector, DetInfo*>::iterator
              i = m_detInfoMap.begin(), end = m_detInfoMap.end();
            i != end; ++i) {
    DetInfo *detInfo = i->second;

    // save raw histograms
    detInfo->histFile->cd();
    for (int i = 0; i < NUM_HISTS; ++i)
      detInfo->hists[i]->Write();

    TProfile* profHists[NUM_HISTS];
    getProfileHists(detInfo, profHists);

    detInfo->histFile->Close(); // no longer needed

    computeParams(profHists, detInfo->sensorFullPackedData,
                  detInfo->det.detName().c_str());
  }

  return this->GaudiAlgorithm::finalize();
}
int PulseParamGenAlg::readPmtIdx ( ServiceMode  svcMode,
DetInfo detInfo,
const DaqPmtChannel channel 
) [private]

Definition at line 129 of file PulseParamGenAlg.cc.

{
  AdPmtSensor sensor = m_cableSvc->adPmtSensor
    (channel->channelId(), svcMode);

  // ignore 2" pmts and non-pmt channels
  if (sensor.ring() < 1 || sensor.bogus())
    return -1;

  int pmtIdx = 24*(sensor.ring()-1) + sensor.column()-1;

  detInfo->sensorFullPackedData[pmtIdx] = sensor.fullPackedData();

  return pmtIdx;
}
DetInfo * PulseParamGenAlg::getDetInfo ( const DaqCrate crate) [private]

Definition at line 147 of file PulseParamGenAlg.cc.

{
  const Detector& det = crate->detector();
  DetInfo* &pd = m_detInfoMap[det];

  if (pd) return pd;

  else if (det.isAD()) {
    info() << "Initializing detector " << det.detName() << endreq;
    pd = new DetInfo(det);
    return pd;
  }

  else return NULL;
}
void PulseParamGenAlg::processChannel ( const DaqPmtChannel channel,
int  pmtIdx,
DetInfo detInfo 
) [private]

Definition at line 223 of file PulseParamGenAlg.cc.

{
  int adc = int(channel->adc(0) - channel->preAdcAvg(0));
  if (adc < ADC_MIN || adc > ADC_MAX) return;

  double dt = NS_PER_TDC * (channel->tdc(0) - channel->tdc(1));
  if (dt > DT_MAX) return;

  TH2F *hist = detInfo->hists[HIST_IDX(pmtIdx, adc)];
  hist->Fill(dt, channel->preAdcAvg(1) - channel->preAdcAvg(0));
}
bool PulseParamGenAlg::muonCheck ( DetInfo detInfo,
const DaqCrate crate 
) [inline, private]

Definition at line 165 of file PulseParamGenAlg.cc.

{
  TimeStamp trig = crate->triggerTime();

  // is this a muon event?
  if (exist<DayaBay::HeaderObject>(evtSvc(), m_muonTag)) {
    // alternative:
    //     UserDataHeader *calibStats = get<UserDataHeader>
    //       ("/Event/Data/CalibStats");
    //     if (calibStats->getFloat("nPESum") > 4000) {
    detInfo->lastMuonTrig = trig; // save trigger time
    return true;
  }

  else {
    double dt = 1e6*(trig.GetSec() - detInfo->lastMuonTrig.GetSec())
      + 1e-3*(trig.GetNanoSec() - detInfo->lastMuonTrig.GetNanoSec());

    return dt < m_muonBlindTime; // recent muon event?
  }
}
void PulseParamGenAlg::getProfileHists ( DetInfo detInfo,
TProfile **  profHists 
) [private]

Definition at line 236 of file PulseParamGenAlg.cc.

{
  string fname = string("profs_") + detInfo->det.detName() + ".root";
  TFile *f = new TFile(fname.c_str(), "recreate");

  for (int i = 0; i < NUM_HISTS; ++i) {
    TProfile *pfx = detInfo->hists[i]->ProfileX();
    initAxes(pfx);
    profHists[i] = pfx;
    pfx->Write();
  }

  // cache these
  TArrayI sensors(NUM_PMTS, detInfo->sensorFullPackedData);
  f->WriteObject(&sensors, "sensors");

  TString s(detInfo->det.detName());
  f->WriteObject(&s, "detName");
}
bool PulseParamGenAlg::readCachedData ( TProfile **  profHists,
int *&  sensorFullPackedData,
TString *&  detName 
) [private]

Definition at line 257 of file PulseParamGenAlg.cc.

{
  TFile *f = new TFile(m_cachedPulseFile.c_str(), "read");
  if (!f->IsOpen()) {
    error() << "Unable to open cached data file" << endreq;
    return false;
  }

  for (int pmtIdx = 0; pmtIdx < NUM_PMTS; ++pmtIdx)
    for (int adc = ADC_MIN; adc <= ADC_MAX; adc += ADC_INC) {
      string name = histName(pmtIdx, adc).append("_pfx");
      TProfile *p = (TProfile*) f->Get(name.c_str());
      profHists[HIST_IDX(pmtIdx, adc)] = p;
    }

  TArrayI *sensors = (TArrayI*) f->Get("sensors");
  sensorFullPackedData = sensors->GetArray();

  detName = (TString*) f->Get("detName");

  return true;
}
void PulseParamGenAlg::computeParams ( TProfile **  profHists,
int *  sensorFullPackedData,
const char *  detName 
) [private]

Definition at line 283 of file PulseParamGenAlg.cc.

{
  cout << "Got detector name: " << detName << endl;
  PulseFitter pf(profHists, sensorFullPackedData, detName);
  TTree* pulses = pf.Fit();
  PMTParamSaver pps(pulses, sensorFullPackedData, detName);
  pps.GetParamTree();
}

Member Data Documentation

Definition at line 41 of file PulseParamGenAlg.h.

Definition at line 42 of file PulseParamGenAlg.h.

string PulseParamGenAlg::m_muonTag [private]

Definition at line 43 of file PulseParamGenAlg.h.

Definition at line 44 of file PulseParamGenAlg.h.

Definition at line 45 of file PulseParamGenAlg.h.

Definition at line 47 of file PulseParamGenAlg.h.

ICableSvc* PulseParamGenAlg::m_cableSvc [private]

Definition at line 49 of file PulseParamGenAlg.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:03:47 for PulseParamGen by doxygen 1.7.4