/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 Attributes
DeadTime Class Reference

#include <DeadTime.h>

Collaboration diagram for DeadTime:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 DeadTime (const std::string &name, ISvcLocator *pSvcLocator)
virtual ~DeadTime ()
virtual StatusCode initialize ()
virtual StatusCode execute ()
virtual StatusCode finalize ()
void CalculateDeadTime ()
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
TH1F * h_BlockedTrigNum
TH1F * h_DeadTime
TH1F * h_TrigRates
TH1F * h_DeadTimeRatio
unsigned long m_NTrigger [10]
double m_BlockedTrigNum [10]
double m_DeadTime [10]
TimeStamp m_FirstTrigStamp_forCalcul [10]
TimeStamp m_LastTrigStamp_forCalcul [10]
TimeStamp m_PreviousTrigStamp_forCalcul [10]
double m_NTrigger_forCalcul [10]
int m_exenum [10]
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
list __all__ = [ "run" ]

Detailed Description

Definition at line 29 of file DeadTime.h.


Constructor & Destructor Documentation

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

Definition at line 17 of file DeadTime.cc.

                                                                 :
  GaudiAlgorithm(name, pSvcLocator)
{
  declareProperty("FileName", m_fileName = "AdcFit.root", "Root file name");
  declareProperty("FitPeriod", m_fitPeriod = 30*60, "Fit period in second, Default is 30 minutes");
  declareProperty("Fix", m_Fix = 0, "a temp fix for 40M noise");
}
DeadTime::~DeadTime ( ) [virtual]

Definition at line 25 of file DeadTime.cc.

{
}

Member Function Documentation

StatusCode DeadTime::initialize ( ) [virtual]

Run data service

Cable service

Definition at line 138 of file DeadTime.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;
  }

  f1 = new TF1("f1","gaus",20,250);
  //f1 = new TF1("f1",Pedestal,0,150,5);

  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 DeadTime::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

Definition at line 175 of file DeadTime.cc.

{
  debug()<<"DeadTime 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;
  }


  Detector det = pmtCrate->detector();
  ServiceMode svcMode( readoutHdr->context(),0 );
  //  cout << "run number:" << m_runDataSvc->runData(svcMode)->runNumber() << endl;
  

    if(readoutHdr->context().GetDetId()!=DetectorId::kAD1)
    {
          cout<<"The current package only used for AD#1"<<endl;
          return StatusCode::FAILURE;
    }
    int tmp_detector_id=readoutHdr->context().GetDetId();
      m_NTrigger[tmp_detector_id]++;
  // 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[tmp_detector_id]==1){
     m_FirstTrigSecond = trigTime.GetSec();
     m_FirstTrigNanoSec = trigTime.GetNanoSec();
    }
    m_NTrigger_forCalcul[tmp_detector_id]+=1;
    if(m_NTrigger_forCalcul[tmp_detector_id]==1)
    {
      m_FirstTrigStamp_forCalcul[tmp_detector_id]=trigTime;
    }
    m_LastTrigStamp_forCalcul[tmp_detector_id]=trigTime;
    int tmp_BlockedTrigNum=0;
    bool buffer_full_flag=false;
  const DaqLtb &ltb = pmtCrate->localTriggerBoard();
  //const LtbFramePtrList frames = ltb.frames();
  const vector<DayaBay::DaqLtbFrame*> &frames = ltb.frames();
  if(frames.size()>20) {
    warning() << "Two many trigger frames: " << frames.size() << endreq;
  }

  //for(unsigned int i=0; i<frames.size(); i++) {
    for(unsigned int i=0; i<1; i++) {
    //m_triggerSec[i] = frames[i]->triggerTime().GetSec();
    //m_triggerNano[i] = frames[i]->triggerTime().GetNanoSec();
    //m_triggerHSum[i] = frames[i]->hitSum();
    //m_triggerESumComp[i] = frames[i]->energySum();
    //m_triggerESumAdc[i] = frames[i]->energySum();
   buffer_full_flag= frames[i]->feeBufferFull()|frames[i]->ltbBufferFull();
    tmp_BlockedTrigNum=frames[i]->blockedTriggerCount();
  

    if(buffer_full_flag)//
    {
        m_BlockedTrigNum[tmp_detector_id]+=tmp_BlockedTrigNum; // need fill the number from LTB frame
        //cout<<"tmp_BlockedTrigNum="<<tmp_BlockedTrigNum<<"  m_BlockedTrigNum[tmp_detector_id]="<<m_BlockedTrigNum[tmp_detector_id]<<endl;
        h_BlockedTrigNum->Fill(tmp_BlockedTrigNum);
        if(m_NTrigger_forCalcul[tmp_detector_id]>1)
        {
          double deadtime_ns=(trigTime.GetSec()-m_PreviousTrigStamp_forCalcul[tmp_detector_id].GetSec())+(trigTime.GetNanoSec()-m_PreviousTrigStamp_forCalcul[tmp_detector_id].GetNanoSec())*1e-9;
          m_DeadTime[tmp_detector_id]+=deadtime_ns;
          h_DeadTime->Fill(deadtime_ns*1e6);
          m_exenum[tmp_detector_id]++;
        }
    }
    }

    m_PreviousTrigStamp_forCalcul[tmp_detector_id]=trigTime;



  //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();
    
    // 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();
    }
  } // end of channels
*/
  //-------------------------------------
  //fit the data
  if(m_currentTime - m_lastFitTime > m_fitPeriod) {
    //Fit
    CalculateDeadTime();
    //after fit
    ResetPmtProp();
    m_NStop++;
    m_lastFitTime = m_currentTime;
  }
  
  m_prevTrigTime = m_currentTime;

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

Definition at line 345 of file DeadTime.cc.

{
  //Fit
  CalculateDeadTime();
  
  m_rootfile->Write();
  m_rootfile->Close();

  delete f1;
  delete f2;
  //delete m_tree;
  delete m_rootfile;

  StatusCode sc;
  sc = this->GaudiAlgorithm::finalize();
  return sc;
}
void DeadTime::CalculateDeadTime ( )

Definition at line 29 of file DeadTime.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, "# [detId] [detName] [totalRunTime] [TotalTrigNum] [TrigRateDaq] [TrigRateAll] [RatioFromTrig] [RatioFromTime]\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;
 
  for(int i=0;i<10;i++)
  if(m_DeadTime[i]>0)
  {
    int tmp_detector_id=i;
  double  total_run_time=(m_LastTrigStamp_forCalcul[tmp_detector_id].GetSec()-m_FirstTrigStamp_forCalcul[tmp_detector_id].GetSec())+(m_LastTrigStamp_forCalcul[tmp_detector_id].GetNanoSec()-m_FirstTrigStamp_forCalcul[tmp_detector_id].GetNanoSec())*1e-9;
  double Dead_time_ratio=m_DeadTime[tmp_detector_id]/total_run_time; //all in nano sec

  double trigger_rate=(m_NTrigger_forCalcul[tmp_detector_id]+m_BlockedTrigNum[tmp_detector_id])/(total_run_time); 
  double trigger_rate_daq=m_NTrigger_forCalcul[tmp_detector_id]/total_run_time;
  double Dead_time_ratio_trig=m_BlockedTrigNum[tmp_detector_id]/(m_NTrigger_forCalcul[tmp_detector_id]+m_BlockedTrigNum[tmp_detector_id]);
  cout<<"m_NTrigger_forCalcul[tmp_detector_id]="<<m_NTrigger_forCalcul[tmp_detector_id]<<"  m_BlockedTrigNum[tmp_detector_id]="<<m_BlockedTrigNum[tmp_detector_id]<<endl;
  cout<<"total run time="<<total_run_time<<"s trigger_rate_daq="<<trigger_rate_daq<<"Hz trigger_rate_real="<<trigger_rate<<"Hz  Dead_time_ratio_time="<<Dead_time_ratio<<"  Dead_time_ratio_trig="<<Dead_time_ratio_trig<<endl;

  
   
  fprintf(outfile, "%d %s %8.3f %10d %8.3f %8.3f %8.3f %8.3f\n",tmp_detector_id, DetectorId::AsString((DetectorId_t)tmp_detector_id),total_run_time,m_NTrigger_forCalcul[tmp_detector_id]+m_BlockedTrigNum[tmp_detector_id],trigger_rate_daq,trigger_rate,Dead_time_ratio_trig,Dead_time_ratio);
  h_TrigRates->Fill(4*tmp_detector_id+1,trigger_rate_daq);
  h_TrigRates->Fill(4*tmp_detector_id+2,trigger_rate);
  h_DeadTimeRatio->Fill(4*tmp_detector_id+1,Dead_time_ratio_trig);
  h_DeadTimeRatio->Fill(4*tmp_detector_id+2,Dead_time_ratio);
  }

  h_BlockedTrigNum->Write();
  h_DeadTime->Write();
  h_TrigRates->Write();
  h_DeadTimeRatio->Write();

  ResetPmtProp();

  //m_tree->Fill();
  fclose(outfile);
}
int DeadTime::InitPmtProp ( const ServiceMode svc)

Definition at line 86 of file DeadTime.cc.

{
  string hname = "h_BlockedTrigNum";
  h_BlockedTrigNum=new  TH1F(hname.c_str(),hname.c_str(),1000,0,1000);

  hname = "h_DeadTime";
  h_DeadTime=new  TH1F(hname.c_str(),hname.c_str(),1000,0,1e6);

  hname = "h_TrigRates";
  h_TrigRates=new  TH1F(hname.c_str(),hname.c_str(),40,0,40);

  hname = "h_DeadTimeRatio";
  h_DeadTimeRatio=new  TH1F(hname.c_str(),hname.c_str(),40,0,40);

  m_NStop = 1;
  m_startrun = -1;
  m_currentrun = -1;
 
  for(int i=0;i<10;i++)
  {
    m_BlockedTrigNum[i]=0;
    m_DeadTime[i]=0;
    m_NTrigger_forCalcul[i]=0;
    m_exenum[i]=0;
  } 
  return 1;
}
int DeadTime::ResetPmtProp ( )

Definition at line 114 of file DeadTime.cc.

{
  h_BlockedTrigNum->Reset();
  h_DeadTime->Reset();
  h_TrigRates->Reset();
  h_DeadTimeRatio->Reset();
  
  for(int i=0;i<10;i++)
  {
    m_BlockedTrigNum[i]=0;
    m_DeadTime[i]=0;
    m_NTrigger_forCalcul[i]=0;
    m_exenum[i]=0;

    m_NTrigger[i] = 0;
    m_FirstTrigStamp_forCalcul[i]=0;
    m_LastTrigStamp_forCalcul[i]=0;
    m_PreviousTrigStamp_forCalcul[i]=0;
  }
  m_startrun = -1;

  return 1;
}

Member Data Documentation

Cable mapping service.

Definition at line 48 of file DeadTime.h.

Definition at line 49 of file DeadTime.h.

TF1* DeadTime::f1 [private]

Definition at line 51 of file DeadTime.h.

TF1* DeadTime::f2 [private]

Definition at line 52 of file DeadTime.h.

TFile* DeadTime::m_rootfile [private]

Definition at line 53 of file DeadTime.h.

TTree* DeadTime::m_tree [private]

Definition at line 54 of file DeadTime.h.

FILE* DeadTime::m_masterfile [private]

Definition at line 55 of file DeadTime.h.

string DeadTime::m_fileName [private]

Definition at line 56 of file DeadTime.h.

TH1F* DeadTime::h_BlockedTrigNum [private]

Definition at line 59 of file DeadTime.h.

TH1F* DeadTime::h_DeadTime [private]

Definition at line 60 of file DeadTime.h.

TH1F* DeadTime::h_TrigRates [private]

Definition at line 61 of file DeadTime.h.

TH1F* DeadTime::h_DeadTimeRatio [private]

Definition at line 62 of file DeadTime.h.

unsigned long DeadTime::m_NTrigger[10] [private]

Definition at line 65 of file DeadTime.h.

double DeadTime::m_BlockedTrigNum[10] [private]

Definition at line 67 of file DeadTime.h.

double DeadTime::m_DeadTime[10] [private]

Definition at line 68 of file DeadTime.h.

Definition at line 69 of file DeadTime.h.

Definition at line 70 of file DeadTime.h.

Definition at line 71 of file DeadTime.h.

double DeadTime::m_NTrigger_forCalcul[10] [private]

Definition at line 72 of file DeadTime.h.

int DeadTime::m_exenum[10] [private]

Definition at line 73 of file DeadTime.h.

double DeadTime::m_StartTime [private]

Definition at line 75 of file DeadTime.h.

double DeadTime::m_EndTime [private]

Definition at line 76 of file DeadTime.h.

int DeadTime::m_Fix [private]

Definition at line 78 of file DeadTime.h.

int DeadTime::m_NStop [private]

Definition at line 79 of file DeadTime.h.

Definition at line 80 of file DeadTime.h.

Definition at line 81 of file DeadTime.h.

Definition at line 82 of file DeadTime.h.

Definition at line 83 of file DeadTime.h.

int DeadTime::m_startrun [private]

Definition at line 84 of file DeadTime.h.

int DeadTime::m_currentrun [private]

Definition at line 85 of file DeadTime.h.

int DeadTime::m_site [private]

Definition at line 87 of file DeadTime.h.

int DeadTime::m_simFlag [private]

Definition at line 88 of file DeadTime.h.

double DeadTime::m_currentTime [private]

Definition at line 89 of file DeadTime.h.

double DeadTime::m_prevTrigTime [private]

Definition at line 90 of file DeadTime.h.

double DeadTime::m_lastFitTime [private]

Definition at line 91 of file DeadTime.h.

double DeadTime::m_fitPeriod [private]

Definition at line 92 of file DeadTime.h.

list DeadTime::__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:12 for DeadTime by doxygen 1.7.4