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

In This Package:

Classes | Public Member Functions | Private Attributes
DarkRates Class Reference

#include <DarkRates.h>

Collaboration diagram for DarkRates:
Collaboration graph
[legend]

List of all members.

Classes

struct  PmtProp

Public Member Functions

 DarkRates (const std::string &name, ISvcLocator *pSvcLocator)
virtual ~DarkRates ()
virtual StatusCode initialize ()
virtual StatusCode execute ()
virtual StatusCode finalize ()
void calibDarkRates ()
int InitPmtProp (const ServiceMode &svc)
int ResetPmtProp ()

Private Attributes

ICableSvcm_cableSvc
 Cable mapping service.
IRunDataSvcm_runDataSvc
TF1 * f1
TF1 * f2
TFile * m_rootfile
TTree * m_tree
FILE * m_masterfile
string m_fileName
unsigned long m_NTrigger
TH1F * h_DarkRates
TH1F * h_DarkRatesErr
map< int, PmtPropm_PmtPropMap
double m_StartTime
double m_EndTime
int m_Fix
int m_NStop
int m_FirstTrigSecond
int m_FirstTrigNanoSec
int m_LastTrigSecond
int m_LastTrigNanoSec
int m_startrun
int m_currentrun
int m_site
int m_simFlag
double m_currentTime
double m_prevTrigTime
double m_lastFitTime
double m_fitPeriod
int m_TDCCutLow
int m_TDCCutHigh
list __all__ = [ "run" ]

Detailed Description

Definition at line 30 of file DarkRates.h.


Constructor & Destructor Documentation

DarkRates::DarkRates ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

Definition at line 14 of file DarkRates.cc.

                                                                   :
  GaudiAlgorithm(name, pSvcLocator)
{
  declareProperty("FileName", m_fileName = "DarkRates_calib.root", "Root file name");
  declareProperty("FitPeriod", m_fitPeriod = 30*60, "Fit period in second, Default is 30 minutes, 1.5%@20kHz");
  declareProperty("Fix", m_Fix = 0, "a temp fix for 40M noise");
  declareProperty("TDCCutLow", m_TDCCutLow = 1070, "data cut in TDC low, normal hit TDC ~1000");
  declareProperty("TDCCutHigh", m_TDCCutHigh = 1170, "data cut in TDC high, normal hit TDC ~1000");

    string hname4 = "h_DarkRates";
  h_DarkRates= new TH1F (hname4.c_str(),hname4.c_str(),20000,0,20000);

      string hname5 = "h_DarkRatesErr";
  h_DarkRatesErr= new TH1F (hname5.c_str(),hname5.c_str(),2000,0,2000);
}
DarkRates::~DarkRates ( ) [virtual]

Definition at line 30 of file DarkRates.cc.

{
}

Member Function Documentation

StatusCode DarkRates::initialize ( ) [virtual]

Run data service

Cable service

Definition at line 171 of file DarkRates.cc.

{
  StatusCode sc;
  sc = this->GaudiAlgorithm::initialize();
  if( sc.isFailure() ) {
    error() << "Base class initialization error" << endreq;
    return sc;
  }

  sc = service("RunDataSvc",m_runDataSvc);
  if( sc.isFailure() ) {
    error() << "Can't get RunDataSvc" << endreq;
    return sc;
  }

  sc = service("CableSvc",m_cableSvc);
  if( sc.isFailure() ) {
    error() << "Can't get CableSvc" << endreq;
    return sc;
  }

  m_rootfile = new TFile(m_fileName.c_str(),"recreate");
  //m_tree = new TTree("t", "My Tree");
  //m_tree->SetMaxTreeSize(200000000);  // 200M

  m_masterfile = fopen("Master.pmtCalibMap.txt", "a");
  fprintf(m_masterfile, "# [StartRun] [EndRun] [Sites] [SimFlag] [StartTimeSec] [StartTimeNanoSec] [EndTimeSec] [EndTimeNanoSec] [map file]\n");
  fclose(m_masterfile);

  return sc;
}
StatusCode DarkRates::execute ( ) [virtual]

Get run, event

}

Get ReadoutHeader

Get all information at that period.

check AD or water pool

a temporary workaround for problematic all_esum trigger 7

Loop over channel data

Definition at line 205 of file DarkRates.cc.

{
  debug()<<"DarkRates executing ... "<<endreq;

  StatusCode sc;
  
//  RawEventHeader* reh = get<RawEventHeader>(RawEventHeader::defaultLocation());
//  if(!reh) {
//    warning()<<"Failed to get raw event header"<<endreq;
//  else{
//    if(m_startrun==-1) m_startrun = reh->runNum();
//    m_currentrun = reh->runNum();
//  }

  ReadoutHeader* readoutHdr = get<ReadoutHeader>( ReadoutHeader::defaultLocation() );
  if(!readoutHdr) {
    error()<<"Failed to get readout header"<<endreq;
    return StatusCode::FAILURE;
  }

  const DaqCrate* daqCrate = readoutHdr->daqCrate();
  if(!daqCrate) {
    error()<<"Failed to get daqCrate from header"<<endreq;
    return StatusCode::FAILURE;
  }

  TimeStamp trigTime = daqCrate->triggerTime();
  m_currentTime = trigTime.GetSeconds();

  static bool first = true;
  if( first ) {
    first = false;
    Context ctx = readoutHdr->context();
    m_site=ctx.GetSite();
    m_simFlag=ctx.GetSimFlag();
    ctx.SetSite(Site::kAll);
    ctx.SetDetId(DetectorId::kAll);
    ServiceMode svc(ctx,0);
    //
    InitPmtProp(svc);
    //
    m_prevTrigTime = trigTime.GetSeconds();
    m_lastFitTime = trigTime.GetSeconds();
  }

  if( !(daqCrate->detector().isAD() ||
        daqCrate->detector().isWaterShield()) ) {
    return StatusCode::SUCCESS;
  }

  const DaqPmtCrate* pmtCrate = daqCrate->asPmtCrate();
  if (!pmtCrate) {
    error()<<"Failed to get DaqPmtCrate"<<endreq;
    return StatusCode::FAILURE;
  }
  m_NTrigger++;

  // Keep tracking the first trigger time and 
  // the laster trigger for this group of fit
  m_LastTrigSecond = trigTime.GetSec();
  m_LastTrigNanoSec = trigTime.GetNanoSec();
  if(m_NTrigger==1){
    m_FirstTrigSecond = trigTime.GetSec();
    m_FirstTrigNanoSec = trigTime.GetNanoSec();
  }

  Detector det = pmtCrate->detector();
  ServiceMode svcMode( readoutHdr->context(),0 );
  //  cout << "run number:" << m_runDataSvc->runData(svcMode)->runNumber() << endl;
  
  //int TrigType = pmtCrate->triggerType();
  //if( TrigType != 7 ) {

  const DaqPmtCrate::PmtChannelPtrList& channels = pmtCrate->pmtChannelReadouts();
  DaqPmtCrate::PmtChannelPtrList::const_iterator ci, ci_end = channels.end();

  for(ci = channels.begin(); ci!=ci_end; ci++) {
    const DaqPmtChannel* channel = *ci;
    FeeChannelId channelId = channel->channelId();
    if(channelId.board()==17&&channelId.connector()>=7) continue;
    
    // number of hits in this readout
    unsigned int multi = channel->hitCount();
    int id = 0;
    if(det.isAD()){
      AdPmtSensor pmtId = m_cableSvc->adPmtSensor( channelId, svcMode );
      id = pmtId.fullPackedData();
    }
    else{
      PoolPmtSensor pmtId = m_cableSvc->poolPmtSensor( channelId, svcMode );
      id = pmtId.fullPackedData();
    }
    map<int, PmtProp>::iterator mapit = m_PmtPropMap.find(id);
    if(mapit==m_PmtPropMap.end()) continue;//skip the one not in map
    PmtProp& curPmt = mapit->second;

 
    for(unsigned int nr = 0; nr<multi; ++nr) {
      int tdc = channel->tdc(nr);

      curPmt.h_Tdc->Fill(tdc);
      
      if(tdc>=1070 && tdc<=1170){//select dark noise before trigger
              curPmt.DarkRate++;
      }

    } // end of hits per channel
  } // end of channels

  //-------------------------------------
  //fit the data
  if(m_currentTime - m_lastFitTime > m_fitPeriod) {
    //Fit
    calibDarkRates();//
    //after fit
    ResetPmtProp();
    m_NStop++;
    m_lastFitTime = m_currentTime;
  }
  
  m_prevTrigTime = m_currentTime;

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

Definition at line 337 of file DarkRates.cc.

{
  //Fit
  calibDarkRates();
  
  map<int/*PmtId*/,PmtProp>::iterator it,idend=m_PmtPropMap.end();
  for(it=m_PmtPropMap.begin(); it!=idend; it++) {
    PmtProp& curr = it->second;
    delete curr.h_Tdc;
  }

  delete h_DarkRates;
  delete h_DarkRatesErr; 
 
  m_rootfile->Write();
  m_rootfile->Close();

  //delete m_tree;
  delete m_rootfile;

  StatusCode sc;
  sc = this->GaudiAlgorithm::finalize();
  return sc;
}
void DarkRates::calibDarkRates ( )

Definition at line 36 of file DarkRates.cc.

                              {
  ostringstream tmp;
  tmp <<setw(2) <<setfill('0') << m_NStop;
  string filename = "pmtDataTable_"+tmp.str()+".txt";
  FILE* outfile = fopen(filename.c_str(), "w+");
  
  fprintf(outfile, "# First Trigger time: (TrigSecond, TrigNanoSec) = (%d,%d).\n", m_FirstTrigSecond, m_FirstTrigNanoSec);
  fprintf(outfile, "# Last Trigger time: (TrigSecond, TrigNanoSec) = (%d,%d).\n", m_LastTrigSecond, m_LastTrigNanoSec);
  fprintf(outfile, "# [pmtID] [description] [darkRate] [darkRateErr]\n");

  m_rootfile->cd();
  string newdir = tmp.str();
  m_rootfile->mkdir(newdir.c_str());
  m_rootfile->cd(newdir.c_str());

  m_masterfile = fopen("Master.pmtCalibMap.txt", "a");
  TimeStamp lastT1(m_LastTrigSecond,m_LastTrigNanoSec+1);
  fprintf(m_masterfile, "0000000 0000000 %4.0d %4.0d %10.0d %10.0d %10.0d %10.0d %s\n",
          m_site, m_simFlag, m_FirstTrigSecond,m_FirstTrigNanoSec,(int)lastT1.GetSec(),lastT1.GetNanoSec(),filename.c_str());
  fclose(m_masterfile);

  m_StartTime = m_FirstTrigSecond + m_FirstTrigNanoSec*1e-9;
  m_EndTime = m_LastTrigSecond + m_LastTrigNanoSec*1e-9;
  
  map<int/*PmtId*/,PmtProp>::iterator it,idend=m_PmtPropMap.end();
  for(it=m_PmtPropMap.begin(); it!=idend; it++) {
    PmtProp& curr = it->second;

    //calculate dark rate
    double tlength = m_NTrigger*(m_TDCCutHigh-m_TDCCutLow+1)*1.5625*1e-9;//1 tdc corresponding 1.5625ns
    curr.DarkRateErr = sqrt(curr.DarkRate)/tlength;
    curr.DarkRate = curr.DarkRate/tlength;


      fprintf(outfile, "%d %s %9.1f %9.3f\n",
        curr.PmtId, curr.PmtLabel.c_str(), curr.DarkRate, curr.DarkRateErr);
       
      h_DarkRates->Fill(curr.DarkRate);
      h_DarkRatesErr->Fill(curr.DarkRateErr);
      curr.h_Tdc->Write();
  }

        h_DarkRates->Write();
      h_DarkRatesErr->Write();
  //m_tree->Fill();
  fclose(outfile);
}
int DarkRates::InitPmtProp ( const ServiceMode svc)

Definition at line 84 of file DarkRates.cc.

{

  const vector<AdPmtSensor>& adPmts = m_cableSvc->adPmtSensors(svc);
  const vector<PoolPmtSensor>& poolPmts = m_cableSvc->poolPmtSensors(svc);
  
  PmtProp defPmtProp;
  defPmtProp.h_Tdc=0;
  defPmtProp.DarkRate=0;
  defPmtProp.DarkRateErr=0;
  defPmtProp.PmtLabel="";
  defPmtProp.PmtId=0;
  defPmtProp.Ring=0;
  defPmtProp.Column=0;
  //define histograms
  m_PmtPropMap.clear();


  //  AD PMTs 
  for( unsigned int ct=0; ct<adPmts.size(); ct++ ) {
    AdPmtSensor sensor = adPmts[ct];
    int id = sensor.fullPackedData();
    m_PmtPropMap[id] = defPmtProp;
    // get label
    ostringstream sring, scolumn;
    sring<<setw(2)<<setfill('0')<<sensor.ring();
    scolumn<<setw(2)<<setfill('0')<<sensor.column();
    string label = sensor.detName()+"_R"+sring.str()+"_C"+scolumn.str();
    m_PmtPropMap[id].Ring=sensor.ring();
    m_PmtPropMap[id].Column=sensor.column();
    //
    string hname3 = "h_Tdc_"+label;
    m_PmtPropMap[id].h_Tdc = new TH1F(hname3.c_str(),hname3.c_str(),400,400,1200);
    m_PmtPropMap[id].PmtLabel=label;
    m_PmtPropMap[id].PmtId=id;
    //
  }
  //  Water Poll PMTs
  for( unsigned int ct=0; ct<poolPmts.size(); ct++ ) {
    PoolPmtSensor sensor = poolPmts[ct];
    int id = sensor.fullPackedData();
    m_PmtPropMap[id] = defPmtProp;
    // get label
    ostringstream swall, sspot,sfacing;
    swall<<setw(2)<<setfill('0')<<sensor.wallNumber();
    sspot<<setw(2)<<setfill('0')<<sensor.wallSpot();
    sfacing<<setw(2)<<setfill('0')<<sensor.inwardFacing();
    string label = sensor.detName()+"_W"+swall.str()+"_S"+sspot.str()+"_F"+sfacing.str();
    // 
    string hname3 = "h_Tdc_"+label;
    m_PmtPropMap[id].h_Tdc = new TH1F(hname3.c_str(),hname3.c_str(),400,400,1200);
    m_PmtPropMap[id].PmtLabel=label;
    m_PmtPropMap[id].PmtId=id;

  }

  //map<int/*PmtId*/,PmtProp>::iterator it,idend=m_PmtPropMap.end();
  //for(it=m_PmtPropMap.begin(); it!=idend; it++) {
  //  PmtProp& curr = it->second;
  //}
  
  ResetPmtProp();//reset

  m_NStop = 1;
  m_startrun = -1;
  m_currentrun = -1;
  
  return 1;
}
int DarkRates::ResetPmtProp ( )

Definition at line 154 of file DarkRates.cc.

{
  map<int/*PmtId*/,PmtProp>::iterator it,idend=m_PmtPropMap.end();
  for(it=m_PmtPropMap.begin(); it!=idend; it++) {
    PmtProp& curr = it->second;    
    curr.h_Tdc->Reset();
    curr.DarkRate=0;
    curr.DarkRateErr=0;
  }
    h_DarkRates->Reset();
    h_DarkRatesErr->Reset();
  m_NTrigger = 0;
  m_startrun = -1;

  return 1;
}

Member Data Documentation

Cable mapping service.

Definition at line 49 of file DarkRates.h.

Definition at line 50 of file DarkRates.h.

TF1* DarkRates::f1 [private]

Definition at line 52 of file DarkRates.h.

TF1* DarkRates::f2 [private]

Definition at line 53 of file DarkRates.h.

TFile* DarkRates::m_rootfile [private]

Definition at line 54 of file DarkRates.h.

TTree* DarkRates::m_tree [private]

Definition at line 55 of file DarkRates.h.

FILE* DarkRates::m_masterfile [private]

Definition at line 56 of file DarkRates.h.

string DarkRates::m_fileName [private]

Definition at line 57 of file DarkRates.h.

unsigned long DarkRates::m_NTrigger [private]

Definition at line 59 of file DarkRates.h.

TH1F* DarkRates::h_DarkRates [private]

Definition at line 71 of file DarkRates.h.

TH1F* DarkRates::h_DarkRatesErr [private]

Definition at line 72 of file DarkRates.h.

map<int,PmtProp> DarkRates::m_PmtPropMap [private]

Definition at line 74 of file DarkRates.h.

double DarkRates::m_StartTime [private]

Definition at line 76 of file DarkRates.h.

double DarkRates::m_EndTime [private]

Definition at line 77 of file DarkRates.h.

int DarkRates::m_Fix [private]

Definition at line 79 of file DarkRates.h.

int DarkRates::m_NStop [private]

Definition at line 80 of file DarkRates.h.

Definition at line 81 of file DarkRates.h.

Definition at line 82 of file DarkRates.h.

Definition at line 83 of file DarkRates.h.

Definition at line 84 of file DarkRates.h.

int DarkRates::m_startrun [private]

Definition at line 85 of file DarkRates.h.

int DarkRates::m_currentrun [private]

Definition at line 86 of file DarkRates.h.

int DarkRates::m_site [private]

Definition at line 88 of file DarkRates.h.

int DarkRates::m_simFlag [private]

Definition at line 89 of file DarkRates.h.

double DarkRates::m_currentTime [private]

Definition at line 90 of file DarkRates.h.

double DarkRates::m_prevTrigTime [private]

Definition at line 91 of file DarkRates.h.

double DarkRates::m_lastFitTime [private]

Definition at line 92 of file DarkRates.h.

double DarkRates::m_fitPeriod [private]

Definition at line 93 of file DarkRates.h.

int DarkRates::m_TDCCutLow [private]

Definition at line 94 of file DarkRates.h.

int DarkRates::m_TDCCutHigh [private]

Definition at line 95 of file DarkRates.h.

list DarkRates::__all__ = [ "run" ] [private]

Definition at line 3 of file __init__.py.


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:31 for DarkRates by doxygen 1.7.4