/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 | Static Public Member Functions | Private Member Functions | Private Attributes
Background Class Reference

#include <Background.h>

Inheritance diagram for Background:
Inheritance graph
[legend]
Collaboration diagram for Background:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Background (const std::string &type, const std::string &name, const IInterface *parent)
virtual ~Background ()
virtual StatusCode initialize ()
virtual StatusCode finalize ()
virtual StatusCode process (const DayaBay::CalibReadoutHeader &calibReadout, int st, int acu, int zpo)
 Implementation of IEnergyCalibTool ////////////////////////////.
virtual StatusCode calibrate (float TimeInterval, int, int, int, int)
 calibrate() is called after processing many readouts.

Static Public Member Functions

static const InterfaceID & interfaceID ()
 Retrieve interface ID.

Private Member Functions

bool hasStats (const DayaBay::Detector &detector)
 Check if the statistics for this detector have been initialized.
StatusCode prepareStats (const Context &context)
 Get the current statistics for a detector, or create if needed.
std::string getPath (const DayaBay::Detector &detector)
bool GoodTdc (int Tdc)

Private Attributes

std::string m_cableSvcName
std::string m_outfilepath
std::string m_infilepath
std::string m_pmtGeomSvcName
IPmtGeomInfoSvcm_pmtGeomSvc
ICableSvcm_cableSvc
IStatisticsSvcm_statsSvc
std::string m_calibDataSvcName
ICalibDataSvcm_calibDataSvc
std::vector< DayaBay::Detectorm_processedDetectors
int m_tdclow
int m_tdchigh
TimeStamp m_vetoMuonTime
TimeStamp m_AD1MuonTime
TimeStamp m_AD2MuonTime
TimeStamp m_AD3MuonTime
TimeStamp m_AD4MuonTime
bool first

Detailed Description

Definition at line 31 of file Background.h.


Constructor & Destructor Documentation

Background::Background ( const std::string &  type,
const std::string &  name,
const IInterface *  parent 
)

Definition at line 33 of file Background.cc.

  : GaudiTool(type,name,parent)
  , m_cableSvc(0)
  , m_statsSvc(0)
{
  
  declareInterface< IEnergyCalibTool >(this) ;   
  declareProperty("CableSvcName",m_cableSvcName="CableSvc",
                  "Name of service to map between detector, hardware, and electronic IDs");
  declareProperty("outFilePath",m_outfilepath="/file1/Background",
                  "File path of registered histograms.");
  declareProperty("TDCCutLow",m_tdclow=-1650,"low tdc cut for good hits");
  declareProperty("TDCCutHigh",m_tdchigh=-1450,"high tdc cut for good hits");
  declareProperty("CalibDataSvcName", m_calibDataSvcName="StaticCalibDataSvc",
                    "Name of calibration data service");

        declareProperty("PmtGeomSvcName", m_pmtGeomSvcName = "PmtGeomInfoSvc", 
      "Name of Pmt Geometry Information Service");

}
Background::~Background ( ) [virtual]

Definition at line 56 of file Background.cc.

{}

Member Function Documentation

StatusCode Background::initialize ( ) [virtual]

Definition at line 58 of file Background.cc.

                                 {
         info() << "initialize()" << endreq;
  StatusCode sc = this->GaudiTool::initialize();
  if( sc != StatusCode::SUCCESS ) return sc;
  
  //Get PMT geometry service
  m_pmtGeomSvc = svc<IPmtGeomInfoSvc>(m_pmtGeomSvcName, true);
   if(!m_pmtGeomSvc ){
    error() << "Failed to access PMT geometry svc: " << m_pmtGeomSvcName << endreq;
    return StatusCode::FAILURE;
  }
  // Get Cable Service
  m_cableSvc = svc<ICableSvc>(m_cableSvcName,true);
  if(!m_cableSvc){
    error() << "Failed to access cable svc: " << m_cableSvcName << endreq;
    return StatusCode::FAILURE;
  }
  // Get the histogram service
  m_statsSvc = svc<IStatisticsSvc>("StatisticsSvc",true);
  if(!m_statsSvc) {
    error() << " No StatisticsSvc available." << endreq;
    return StatusCode::FAILURE;
  }
   m_calibDataSvc = svc<ICalibDataSvc>(m_calibDataSvcName,true);
  first = true;
    return StatusCode::SUCCESS;
}
StatusCode Background::finalize ( ) [virtual]

Definition at line 86 of file Background.cc.

{
  StatusCode sc = this->GaudiTool::finalize();
  if( sc != StatusCode::SUCCESS ) return sc;

  return StatusCode::SUCCESS;
}
StatusCode Background::process ( const DayaBay::CalibReadoutHeader calibReadout,
int  st,
int  acu,
int  zpo 
) [virtual]

Implementation of IEnergyCalibTool ////////////////////////////.

process(const DayaBay::CalibReadoutPmtCrate&) process a single readout, extracting the information needed for calibration

Implements IEnergyCalibTool.

Definition at line 94 of file Background.cc.

                                                                                                          {
        
        CalibReadout* calibReadout = const_cast<CalibReadout*>(calibReadoutHeader.calibReadout());
        const DayaBay::Detector& det = calibReadout->detector();
        const TimeStamp TriTime = calibReadout->triggerTime();
        Context context = calibReadoutHeader.context();
        if( !hasStats(det) ){
    // New detector; initialize all the detector statistics
                StatusCode sc = prepareStats(context);
        if( sc != StatusCode::SUCCESS ) return sc;
    }
   int task=0;
   ServiceMode svcMode(context, task);

   TH1F* NoSpectrum = m_statsSvc->getTH1F( this->getPath(det) + "/BackgroundSpectrumNoVeto");
   TH1F* YesSpectrum = m_statsSvc->getTH1F( this->getPath(det) + "/BackgroundSpectrumVetoed");
   TH1F *CutSpectrum  = m_statsSvc->getTH1F( this->getPath(det) + "/BackgroundSpectrumVertexCut");

        if(first){
                m_vetoMuonTime = TriTime;
                m_AD1MuonTime = TriTime;
                m_AD2MuonTime = TriTime;
                m_AD3MuonTime = TriTime;
                m_AD4MuonTime = TriTime;
                first = false;
                return StatusCode::SUCCESS;
        }
        if(det.isWaterShield() || det.detectorId() == DetectorId::kRPC){
                m_vetoMuonTime = TriTime;
                return StatusCode::SUCCESS;
        }
        CalibReadoutPmtCrate* calibCrate = dynamic_cast<CalibReadoutPmtCrate*>(calibReadout);
        CalibReadoutPmtCrate::PmtChannelReadouts calibChannels = calibCrate->channelReadout();
        double qsum = 0, qsumx=0, qsumy=0, qsumz=0;
        CalibReadoutPmtCrate::PmtChannelReadouts::iterator it;
        for (it=calibChannels.begin(); it != calibChannels.end(); it++) {
                const CalibReadoutPmtChannel& channel = *it;
        AdPmtSensor pmtId(channel.pmtSensorId().fullPackedData());
        const PmtCalibData* pmtCalib = m_calibDataSvc->pmtCalibData(pmtId, svcMode);
        if( !pmtCalib ){ 
          error() << "No calibration data for pmt ID: " << pmtId << endreq;
         
         return StatusCode::FAILURE;
       }
       if( pmtCalib->m_status != PmtCalibData::kGood ) { continue; }
        if( pmtId.ring()<1 ){ continue; }  // Ignore calibration pmts
            //double largecharge = it->properCharge(m_tdclow,m_tdchigh);
            
                std::vector<double> charge = it->charge();
                std::vector<double> time = it->time();
                double largecharge=0,earlytime=0;
                for(int i = 0; i<time.size();i++){
                        if(time[i]<m_tdchigh&&time[i]>m_tdclow&&charge[i]>largecharge){
                                largecharge = charge[i];
                                earlytime = time[i];
                                //break;
                        }
                }
                
                //double largecharge = it->maxCharge();
                //double largecharge=0;
                //vector<double> charge = it->charge();
                //for(int i=0;i<charge.size();i++) largecharge += charge[i];
                qsum+=largecharge;
                int ring = pmtId.ring();
                int column = pmtId.column();
                double PMTx=2340*cos(((column-1)*15+7.5)/180*3.1415);
        double PMTy=2340*sin(((column-1)*15+7.5)/180*3.1415);
        double PMTz=500*(ring-4.5);
                qsumx += largecharge*PMTx;
                qsumy += largecharge*PMTy;
                qsumz += largecharge*PMTz;
                //cout<<qsum<<endl;
        }
        NoSpectrum->Fill(qsum);
        qsumx /= qsum;
        qsumy /= qsum;
        qsumz /= qsum;
        qsumx /= 0.67;
        qsumy /= 0.67;
        qsumz /= 0.4;
        double rr = sqrt(qsumx*qsumx+qsumy*qsumy);
    qsumz*=(1.3-rr*0.00023);
        double sourcex=0,sourcey=0, sourcez = 0.0;
        //if(acu==2) { sourcex = 1350*cos(112.5/180*3.1415); sourcey =  1350*sin(112.5/180*3.1415); }
        //else if(acu==3) { sourcex = 1720*cos(292.5/180*3.1415); sourcey =  1720*sin(292.5/180*3.1415);}
        //else {sourcex =0.0; sourcey=0.0;}
        double distance = sqrt( (qsumx-sourcex)*(qsumx-sourcex)+(qsumy-sourcey)*(qsumy-sourcey)+(qsumz-sourcez)*(qsumz-sourcez) );
        
        if(qsum > 5000) {
                if(det.detectorId() == 1) m_AD1MuonTime = TriTime;
                else if(det.detectorId() == 2)  m_AD2MuonTime = TriTime;
                else if(det.detectorId() == 3)  m_AD3MuonTime = TriTime;
                else if(det.detectorId() == 4)  m_AD4MuonTime = TriTime;
                else ;
                return StatusCode::SUCCESS;
        }
        if(det.detectorId() == 1&&( TriTime.GetNanoSec()-m_AD1MuonTime.GetNanoSec() + (TriTime.GetSec()-m_AD1MuonTime.GetSec())*1e9 )>1000000 ){
                YesSpectrum->Fill(qsum);
                if(distance<400) CutSpectrum->Fill(qsum);
        }
        if(det.detectorId() == 2&&( TriTime.GetNanoSec()-m_AD2MuonTime.GetNanoSec() + (TriTime.GetSec()-m_AD2MuonTime.GetSec())*1e9)>1000000 ){
                YesSpectrum->Fill(qsum);
                if(distance<400) CutSpectrum->Fill(qsum);
        }
        if(det.detectorId() == 3&&( TriTime.GetNanoSec()-m_AD3MuonTime.GetNanoSec()+ (TriTime.GetSec()-m_AD3MuonTime.GetSec())*1e9 )>1000000 ){
                YesSpectrum->Fill(qsum);
                if(distance<400) CutSpectrum->Fill(qsum);
        }
        if(det.detectorId() == 4&&( TriTime.GetNanoSec()-m_AD4MuonTime.GetNanoSec()+ (TriTime.GetSec()-m_AD4MuonTime.GetSec())*1e9 )>1000000 ){
                YesSpectrum->Fill(qsum);
                if(distance<400) CutSpectrum->Fill(qsum);
        }
        return StatusCode::SUCCESS; 
}
StatusCode Background::calibrate ( float  TimeInterval,
int  st,
int  acu,
int  zpo,
int  runN 
) [virtual]

calibrate() is called after processing many readouts.

This method is responsible for calculating the calibration parameters.

Implements IEnergyCalibTool.

Definition at line 219 of file Background.cc.

                                                                                     {
        std::vector<DayaBay::Detector>::iterator detIter, 
   detEnd = m_processedDetectors.end();
        for(detIter = m_processedDetectors.begin(); detIter != detEnd; detIter++){
                DayaBay::Detector detector = *detIter;
                if(detector.isAD()){
                        TObject* nTime = m_statsSvc->get(this->getPath(detector) + "/Time");
                        TParameter<float>* nTimePar= dynamic_cast<TParameter<float>*>(nTime);
                        nTimePar->SetVal(TimeInterval);
                        TObject* ACU = m_statsSvc->get(this->getPath(detector) + "/ACU");
                        TParameter<int>* nACUPar= dynamic_cast<TParameter<int>*>(ACU);
                        nACUPar->SetVal(acu);
                        TObject* nZposi = m_statsSvc->get(this->getPath(detector) + "/Zposi");
                        TParameter<int>* nZPar= dynamic_cast<TParameter<int>*>(nZposi);
                        nZPar->SetVal(zpo);
                        TObject* nRun = m_statsSvc->get(this->getPath(detector) + "/RunNum");
                        TParameter<int>* nRunPar= dynamic_cast<TParameter<int>*>(nRun);
                        nRunPar->SetVal(runN);
                }
        }
        return StatusCode::SUCCESS;
}
bool Background::hasStats ( const DayaBay::Detector detector) [private]

Check if the statistics for this detector have been initialized.

Definition at line 243 of file Background.cc.

                                                        {
  // Check if statistics have been initialized for this detector
        return (std::find(m_processedDetectors.begin(), m_processedDetectors.end(), detector) != m_processedDetectors.end());
}
StatusCode Background::prepareStats ( const Context context) [private]

Get the current statistics for a detector, or create if needed.

position z is record//

Definition at line 252 of file Background.cc.

                                                         {
        DayaBay::Detector detector(context.GetSite(), context.GetDetId());
  {
    std::ostringstream title, path;
    std::string name = "BackgroundSpectrumNoVeto";
    title << "Raw Background Spectrum in " << detector.detName()<<" . No muon veto.";
    path << this->getPath(detector) << "/" << name;
    TH1F* RawSpectrum = new TH1F(name.c_str(),title.str().c_str(),100000,0,1000000);  
    RawSpectrum->GetXaxis()->SetTitle("P.E number after calibration");
    RawSpectrum->GetYaxis()->SetTitle("Entries");
    if( m_statsSvc->put(path.str(),RawSpectrum).isFailure() ) {
      error() << "prepareStats(): Could not register " << path << endreq;
       delete RawSpectrum;
       return StatusCode::FAILURE;
    }
    }
  {
    std::ostringstream title, path;
    std::string name = "BackgroundSpectrumVetoed";
    title << "Raw Background Spectrum in " << detector.detName()<<" . Muon veto applied.";
    path << this->getPath(detector) << "/" << name;
    TH1F* RawSpectrum1 = new TH1F(name.c_str(),title.str().c_str(),2000,0,10000);  
    RawSpectrum1->GetXaxis()->SetTitle("P.E number after calibration");
    RawSpectrum1->GetYaxis()->SetTitle("Entries");
    if( m_statsSvc->put(path.str(),RawSpectrum1).isFailure() ) {
      error() << "prepareStats(): Could not register " << path << endreq;
       delete RawSpectrum1;
       return StatusCode::FAILURE;
    }
    }
  {
    std::ostringstream title, path;
    std::string name = "BackgroundSpectrumVertexCut";
    title << "Raw Background Spectrum in " << detector.detName()<<" . Vertex cut.";
    path << this->getPath(detector) << "/" << name;
    TH1F* RawSpectrum1 = new TH1F(name.c_str(),title.str().c_str(),2000,0,10000);  
    RawSpectrum1->GetXaxis()->SetTitle("P.E number after calibration");
    RawSpectrum1->GetYaxis()->SetTitle("Entries");
    if( m_statsSvc->put(path.str(),RawSpectrum1).isFailure() ) {
      error() << "prepareStats(): Could not register " << path << endreq;
       delete RawSpectrum1;
       return StatusCode::FAILURE;
    }
    }
        {
        std::string name = "Time";
    std::ostringstream path;
    path << this->getPath(detector) << "/" << name;
    TParameter<float>* par = new TParameter<float>(name.c_str(), 
                                               0);
    if( m_statsSvc->put(path.str(),par).isFailure() ) {
      error() << "prepareStats(): Could not register " << name 
              << " at " << path << endreq;
      delete par;
      par = 0;
      return StatusCode::FAILURE;
    }
  } 
        {
        std::string name = "RunNum";
    std::ostringstream path;
    path << this->getPath(detector) << "/" << name;
    TParameter<int>* par = new TParameter<int>(name.c_str(), 
                                               0);
    if( m_statsSvc->put(path.str(),par).isFailure() ) {
      error() << "prepareStats(): Could not register " << name 
              << " at " << path << endreq;
      delete par;
      par = 0;
      return StatusCode::FAILURE;
    }
  }
   {
        std::string name = "ACU";
    std::ostringstream path;
    path << this->getPath(detector) << "/" << name;
    TParameter<int>* par = new TParameter<int>(name.c_str(), 
                                               0);
    if( m_statsSvc->put(path.str(),par).isFailure() ) {
      error() << "prepareStats(): Could not register " << name 
              << " at " << path << endreq;
      delete par;
      par = 0;
      return StatusCode::FAILURE;
    }
  } 
  {
        std::string name = "Zposi";
    std::ostringstream path;
    path << this->getPath(detector) << "/" << name;
    TParameter<int>* par = new TParameter<int>(name.c_str(), 
                                               0);
    if( m_statsSvc->put(path.str(),par).isFailure() ) {
      error() << "prepareStats(): Could not register " << name 
              << " at " << path << endreq;
      delete par;
      par = 0;
      return StatusCode::FAILURE;
    }
  } 
  m_processedDetectors.push_back(detector);
  return StatusCode::SUCCESS;
}
std::string Background::getPath ( const DayaBay::Detector detector) [private]

Definition at line 248 of file Background.cc.

                                                              {
        return m_outfilepath + "/" + detector.detName();
}
bool Background::GoodTdc ( int  Tdc) [inline, private]

Definition at line 66 of file Background.h.

    {
      if(Tdc>m_tdclow&&Tdc<m_tdchigh) return true;
      else return false;
    };
const InterfaceID & IEnergyCalibTool::interfaceID ( ) [static, inherited]

Retrieve interface ID.

Definition at line 8 of file IEnergyCalibTool.cc.

{ 
    return IID_IEnergyCalibTool; 
}

Member Data Documentation

std::string Background::m_cableSvcName [private]

Definition at line 70 of file Background.h.

std::string Background::m_outfilepath [private]

Definition at line 78 of file Background.h.

std::string Background::m_infilepath [private]

Definition at line 80 of file Background.h.

std::string Background::m_pmtGeomSvcName [private]

Definition at line 82 of file Background.h.

Definition at line 85 of file Background.h.

Definition at line 88 of file Background.h.

Definition at line 91 of file Background.h.

std::string Background::m_calibDataSvcName [private]

Definition at line 93 of file Background.h.

Definition at line 96 of file Background.h.

Definition at line 99 of file Background.h.

int Background::m_tdclow [private]

Definition at line 105 of file Background.h.

int Background::m_tdchigh [private]

Definition at line 106 of file Background.h.

Definition at line 107 of file Background.h.

Definition at line 108 of file Background.h.

Definition at line 109 of file Background.h.

Definition at line 110 of file Background.h.

Definition at line 111 of file Background.h.

bool Background::first [private]

Definition at line 112 of file Background.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:20 for CalibEnergy by doxygen 1.7.4