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

#include <QsumEnergyTool.h>

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

List of all members.

Public Member Functions

 QsumEnergyTool (const std::string &type, const std::string &name, const IInterface *parent)
virtual ~QsumEnergyTool ()
virtual StatusCode reconstruct (const DayaBay::CalibReadout &readout, DayaBay::RecTrigger &recTrigger)
virtual StatusCode initialize ()
virtual StatusCode finalize ()

Static Public Member Functions

static const InterfaceID & interfaceID ()

Private Attributes

std::string m_cableSvcName
ICableSvcm_cableSvc
std::string m_recDataSvcName
IDetCalibSvcm_recDataSvc
bool m_useUniformityCorrection
int m_task_es
int nodb_count
std::string m_calibStatsLocation
std::string m_chargeLeaveName
std::string m_uniformityCorrFileName
std::string m_uniformityCorrFileNameMC
Correctorm_corrector
Correctorm_corrector_mc

Detailed Description

Definition at line 45 of file QsumEnergyTool.h.


Constructor & Destructor Documentation

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

Definition at line 25 of file QsumEnergyTool.cc.

  : GaudiTool(type,name,parent)
  , m_cableSvc(0)
{

  declareInterface< IReconTool >(this) ;   
    declareProperty("CableSvcName",m_cableSvcName="CableSvc",
                    "Name of service to map between detector, hardware, and electronic IDs");
    declareProperty("RecDataSvcName", m_recDataSvcName="DybDetCalibSvc",
                    "Name of calibration data service");
    declareProperty("TaskForEnergyScale",m_task_es=1,
                    "Task number for DB energy scale lookup (0 for Co60; 1 for SN)");
    declareProperty("CalibStatsLocation",m_calibStatsLocation="/Event/Data/CalibStats",
                    "Location of the CalibStats");
    declareProperty("Charge",m_chargeLeaveName="NominalCharge",
                    "Name of the leave that hold the total charge in CalibStats");

    std::string Path = getenv ("DATASVCROOT");
    declareProperty("UniformityCorrFileName", m_uniformityCorrFileName = Path+"/share/uni-corr-p14a-v1.root",
                    "File name of the charge distribution template");

    declareProperty("UniformityCorrFileNameMC", m_uniformityCorrFileNameMC = Path+"/share/uni-corr-m14a-v1.root",
                    "File name of the charge distribution template for MC");

    // This root file include the new AD-by-AD non-uniformity correction.
    // Currently, this new non-uniformity correction works only for data.
    
}
QsumEnergyTool::~QsumEnergyTool ( ) [virtual]

Definition at line 56 of file QsumEnergyTool.cc.

{}

Member Function Documentation

StatusCode QsumEnergyTool::reconstruct ( const DayaBay::CalibReadout readout,
DayaBay::RecTrigger recTrigger 
) [virtual]

Implements IReconTool.

Definition at line 87 of file QsumEnergyTool.cc.

{
  if( !readout.detector().isAD() ){
    debug() << "Not an AD readout; ignoring detector " 
            << readout.detector().detName() << endreq;
    recTrigger.setEnergyStatus( ReconStatus::kNotProcessed );
    return StatusCode::SUCCESS;
  }

  const CalibReadoutPmtCrate* pmtReadout 
    = dynamic_cast<const CalibReadoutPmtCrate*>(&readout);
  if(!pmtReadout){
    error() << "Incorrect type of readout crate for detector "
            << readout.detector().detName() << endreq;
    recTrigger.setEnergyStatus( ReconStatus::kBadReadout );
    return StatusCode::FAILURE;
  }


  // Context for this data
  // Note: when looking up pmt status (right below) need task of zero. When looking up energy scale the task may change, according to the value of m_task_es (jpochoa)
  ServiceMode svcMode(readout.header()->context(), 0);
  ServiceMode svcMode_es(readout.header()->context(), m_task_es);


  // Loop over hits and add up charge
  double qSum = 0;
  double qSquareSum = 0;
  int nHits = 0;

  
  DayaBay::UserDataHeader* calibStatsHdr = 0;
  if(exist<UserDataHeader>(m_calibStatsLocation)){
    calibStatsHdr = get<UserDataHeader>(m_calibStatsLocation);
  }else{
    error() << "Cannot get CalibStats information" << endreq;
    error() << "QsumEnergyTool now require to run CalibStats before this!!!!" << endreq;
    return StatusCode::FAILURE;

    // followings are obsolete code
    
    CalibReadoutPmtCrate::PmtChannelReadouts::const_iterator chanIter, 
      chanEnd = pmtReadout->channelReadout().end();
    for(chanIter=pmtReadout->channelReadout().begin(); chanIter != chanEnd; 
        chanIter++){
      const CalibReadoutPmtChannel& channel = *chanIter;
      AdPmtSensor pmtId(channel.pmtSensorId().fullPackedData());
      //AdPmtSensor pmtId = m_cableSvc->adPmtSensor(channel.channelId(), svcMode);
      if( pmtId.bogus() || pmtId.ring() < 1 ){ continue; }  // Ignore 2" pmts and non-pmt channels  (timing reference, noise... etc)
         
      //if(pmtId.ring()==1&&pmtId.column()==1) cout<<readout.detector().detName()<<' '<<pmtCalib->m_speHigh<<endl;
      //    if( pmtCalib->m_status != PmtCalibData::kGood ) { continue; } // this is obsolete
      
      double peakAdc = channel.earliestCharge(-1650,-1250);
      qSum += peakAdc;
      qSquareSum += peakAdc*peakAdc;
      if(peakAdc>0){
        nHits++;
      }
    }

  }

  
  qSum = calibStatsHdr->getFloat(m_chargeLeaveName);
  nHits = (int)calibStatsHdr->getInt("nHit");
  float nActivePMTs = calibStatsHdr->getFloat("nActivePMTs");
  
  
  if(nHits<1){
    recTrigger.setEnergyStatus( ReconStatus::kNoHits );
    return StatusCode::SUCCESS;
  }

  if(recTrigger.positionStatus()==ReconStatus::kNotConverged){
    return StatusCode::SUCCESS;
  }

  
  //Get position-dependent correction
  double posDepCorr=1.;
  if(recTrigger.positionStatus()==ReconStatus::kGood){
    const CLHEP::Hep3Vector pos = recTrigger.position();
    double position_unit = CLHEP::meter;
    double posx = pos.x()/position_unit;
    double posy = pos.y()/position_unit;
    double posz = pos.z()/position_unit;
    if ((readout.header()->context()).GetSimFlag()== SimFlag::kMC){
      int site = (readout.header()->context()).GetSite();
      int detid = (readout.header()->context()).GetDetId();
      posDepCorr = m_corrector_mc->get_corr(site,detid,posx,posy,posz);
    }else{
      // posDepCorr = uniformCorr(posx,posy,posz);//<-- uniformCorr takes reco pos in meters
      int site = (readout.header()->context()).GetSite();
      int detid = (readout.header()->context()).GetDetId();
      posDepCorr = m_corrector->get_corr(site,detid,posx,posy,posz);

    }
  }  

  // Perform scaling 
  //-->Get number from database
  double scaleConstant=170.; //default value to use for now (PEtoEvis)
  // Note: change task number when looking-up energy scale number 
  const DayaBay::DetEnergyReconData* srcEn = m_recDataSvc->detEnergyReconData(svcMode_es);
  if(!srcEn){
    nodb_count+=1;
    if(nodb_count < NODB_ERRORS){
      warning() << "No energy scale found in DB for context " << readout.header()->context().AsString() << " and task " << m_task_es << ". Will use a default value of " << scaleConstant << endreq;
    }
    if(nodb_count == NODB_ERRORS){
      warning() << "No more errors about not finding energy scale in DB will be reported. A summary count of these errors will appear at the end." << endreq;
    }
  } else {
    scaleConstant = srcEn->m_PeEvis;
  }

  // Apply scale constant based on the number of live PMTs. Aug. 2012, Yasu.
  if (nActivePMTs > 0)
    scaleConstant = scaleConstant * nActivePMTs/192.;
  
  //-->do the math
  double energy = 0;
  double rawEvis = 0;
  if(scaleConstant>0) {
    rawEvis = (qSum *1./ scaleConstant);
    energy = rawEvis*posDepCorr;
  }else {
    error() << "scaleConstant found to be negative or zero! Something is seriously wrong, so will abort" << endreq;
    return StatusCode::FAILURE;
  }
  //--> storage
  recTrigger.setRawEvis( rawEvis );
  recTrigger.setEnergy( energy );  
  // (set quality to standard deviation of hits)
  recTrigger.setEnergyQuality(sqrt((qSquareSum - qSum*qSum/nHits)/(nHits-1)));
  recTrigger.setEnergyStatus( ReconStatus::kGood );

  return StatusCode::SUCCESS;
}
StatusCode QsumEnergyTool::initialize ( ) [virtual]

Definition at line 58 of file QsumEnergyTool.cc.

{
  // Get Cable Service
  m_cableSvc = svc<ICableSvc>(m_cableSvcName,true);
  m_recDataSvc = svc<IDetCalibSvc>(m_recDataSvcName,true);

  // Initialize error counter
  nodb_count=0;
  
  info() << "Setting up non-uniformity correction using " << m_uniformityCorrFileName << endreq;
  m_corrector = new Corrector(m_uniformityCorrFileName.c_str());
  
  info() << "Setting up non-uniformity correction for MC using " << m_uniformityCorrFileNameMC << endreq;
  m_corrector_mc = new Corrector(m_uniformityCorrFileNameMC.c_str());
  
  return StatusCode::SUCCESS;

}
StatusCode QsumEnergyTool::finalize ( ) [virtual]

Definition at line 77 of file QsumEnergyTool.cc.

{

  if(nodb_count>0){
    warning() << "There were " << nodb_count << " warnings about not being able to find the energy scale constant in the database" << endreq;
  }

  return StatusCode::SUCCESS;
}

Member Data Documentation

std::string QsumEnergyTool::m_cableSvcName [private]

Definition at line 63 of file QsumEnergyTool.h.

Definition at line 66 of file QsumEnergyTool.h.

std::string QsumEnergyTool::m_recDataSvcName [private]

Definition at line 69 of file QsumEnergyTool.h.

Definition at line 72 of file QsumEnergyTool.h.

Definition at line 81 of file QsumEnergyTool.h.

Definition at line 84 of file QsumEnergyTool.h.

Definition at line 87 of file QsumEnergyTool.h.

std::string QsumEnergyTool::m_calibStatsLocation [private]

Definition at line 89 of file QsumEnergyTool.h.

std::string QsumEnergyTool::m_chargeLeaveName [private]

Definition at line 91 of file QsumEnergyTool.h.

Definition at line 93 of file QsumEnergyTool.h.

Definition at line 95 of file QsumEnergyTool.h.

Definition at line 97 of file QsumEnergyTool.h.

Definition at line 99 of file QsumEnergyTool.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:13:18 for QsumEnergy by doxygen 1.7.4