/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
CoarseScaleCalibrationAlg Class Reference

#include <CoarseScaleCalibrationAlg.h>

Collaboration diagram for CoarseScaleCalibrationAlg:
Collaboration graph
[legend]

List of all members.

Public Member Functions

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

Private Attributes

string m_readout_location
string m_CableSvcName
string m_pmtGeomSvcName
ICableSvcm_CableSvc
IPmtGeomInfoSvcm_pmtGeomSvc
vector< int > vadc
vector< int > vscale
vector< int > vped
vector< int > vpmt
vector< int > vring
vector< int > vcolumn
vector< int > vboard
vector< int > vconnector
list __all__ = [ "run" ]

Detailed Description

Definition at line 22 of file CoarseScaleCalibrationAlg.h.


Constructor & Destructor Documentation

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

Definition at line 33 of file CoarseScaleCalibrationAlg.cc.

                                                                                                   :GaudiAlgorithm(name, pSvcLocator), m_CableSvc(0), m_pmtGeomSvc(0)
{
        declareProperty("ReadoutLocation", m_readout_location=DayaBay::ReadoutHeaderLocation::Default, "Location in TES of readout header");
        declareProperty("CableSvcName", m_CableSvcName = "CableSvc", "Name of Cable Service");
        declareProperty("PmtGeomSvcName", m_pmtGeomSvcName="PmtGeomInfoSvc", "Name of PMT Geometry Information Service");
}
CoarseScaleCalibrationAlg::~CoarseScaleCalibrationAlg ( ) [virtual]

Definition at line 41 of file CoarseScaleCalibrationAlg.cc.

{
}

Member Function Documentation

StatusCode CoarseScaleCalibrationAlg::initialize ( ) [virtual]

Definition at line 46 of file CoarseScaleCalibrationAlg.cc.

{
        StatusCode sc;
        sc = this->GaudiAlgorithm::initialize();

        m_CableSvc = svc<ICableSvc>(m_CableSvcName, true);
        m_pmtGeomSvc = svc<IPmtGeomInfoSvc>(m_pmtGeomSvcName, true);

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

Definition at line 58 of file CoarseScaleCalibrationAlg.cc.

{
  
  debug()<<"CoarseScaleCalibrationAlg executing ... "<<endreq;
  
  ReadoutHeader* readoutHeader;
  if (exist<ReadoutHeader>(m_readout_location)) {
    readoutHeader = get<DayaBay::ReadoutHeader>(m_readout_location);
  }
  else {
    return StatusCode::FAILURE;
  }
  
  // Extract the DaqCrate
  const DayaBay::DaqCrate* daqCrate = readoutHeader->daqCrate();
  if(!daqCrate){
    error() << "Failed to get DAQ crate from header" << endreq;
    return StatusCode::FAILURE;
  }
  //const DayaBay::Detector& detector = daqCrate->detector();

  // Convert to PMT crate readout
  const DayaBay::DaqPmtCrate* pmtCrate
      = daqCrate->asPmtCrate();
  /*if(!pmtCrate){
    // Not an AD, continue
    debug() << "process(): Do not process detector: " << detector.detName() 
            << endreq;
    return StatusCode::SUCCESS;
    }*/
  Context context = readoutHeader->context();
  
  ServiceMode svcMode(context, 0);
  
  // Store data in memory
  int adc, scale, pmt, ring, col, board, connector, ped;
  const DayaBay::DaqPmtCrate::PmtChannelPtrList& channels
    = pmtCrate->channelReadouts(); 
  const DayaBay::DaqPmtCrate::PmtChannelPtrList::const_iterator channelIter, 
    channelEnd = channels.end();
  for(DayaBay::DaqPmtCrate::PmtChannelPtrList::const_iterator channelIter = channels.begin(); channelEnd!=channelIter; ++channelIter){
    const DayaBay::DaqPmtChannel& channel = *(*channelIter);
    const DayaBay::FeeChannelId& channelID = channel.channelId();

    for (unsigned int i=0; i<channel.hitCount(); i++) { // Loop over peaks in this readout window
      adc = channel.adc(i);
      ped = channel.preAdcAvg(i);
      scale = 1;
      if(!channel.isHighGainAdc(i)) scale=2;
      
      AdPmtSensor pmtSens = m_CableSvc->adPmtSensor(channelID,svcMode);
      pmt = pmtSens.sensorId();
      ring = pmtSens.ring();
      col = pmtSens.column();
      
      //FeeChannelId feeID = m_CableSvc->feeChannelId(pmtSens,svcMode);
      board = channelID.board();
      connector = channelID.connector();
       
      vadc.push_back(adc-ped);
      vscale.push_back(scale);
      vped.push_back(ped);
      vpmt.push_back(pmt);
      vring.push_back(ring);
      vcolumn.push_back(col);
      vboard.push_back(board);
      vconnector.push_back(connector);
    }
  }
  
  return StatusCode::SUCCESS;
}
StatusCode CoarseScaleCalibrationAlg::finalize ( ) [virtual]

Definition at line 132 of file CoarseScaleCalibrationAlg.cc.

{
        StatusCode sc;
        sc = this->GaudiAlgorithm::initialize();

        CoarseScaleCalib* myCalib;
        ofstream outfile("output.txt");

        // Get the list of fired PMTs
        vector<int>::iterator it;
        vector<int> allpmts(vpmt);
        sort(allpmts.begin(),allpmts.end());
        vector<int> pmtlist(500,0);
        it = unique_copy(allpmts.begin(),allpmts.end(),pmtlist.begin());
        pmtlist.erase(it,pmtlist.end());
        allpmts.clear();

        // Get the list of rings, columns, and boards associated with each PMT
        vector<int> ring, column, board, connector;
        for (unsigned int i=0; i<pmtlist.size(); i++) {
                int thispmt = pmtlist.at(i);
                // find the first instance of this pmt in vpmt vector
                int k=0;
                while (vpmt.at(k)!=thispmt) k++;
                // get the associated ring and column for thispmt
                ring.push_back(vring.at(k));
                column.push_back(vcolumn.at(k));
                board.push_back(vboard.at(k));
                connector.push_back(vconnector.at(k));
        }

        // Loop over the list of PMTs
        vector<double> adc;
        vector<double> scale;
        vector<double> errors;
        vector<double> pedestal;
        for (unsigned int i=0; i<pmtlist.size(); i++) {
                int thispmt = pmtlist.at(i);
        
                // Get the subset of vadc and vscale that correspond to this PMT
                for (unsigned int j=0; j<vpmt.size(); j++) {
                        if (thispmt == vpmt.at(j)) {
                                adc.push_back(vadc.at(j));
                                scale.push_back(vscale.at(j));
                                pedestal.push_back(vped.at(j));
                        }
                }

                // Calculate the std. dev. of the pedestals
                int n1=0, n2=0;
                double thisped, ped1=0, ped1sq=0, ped1sd=0, ped2=0, ped2sq=0, ped2sd=0;
                for (unsigned int j=0; j<pedestal.size(); j++) {
                        if (scale.at(j)==1) {
                                thisped = pedestal.at(j);
                                if (thisped>40 && thisped<200) { // ad hoc method of cutting out low values of pre-adc
                                        ++n1;
                                        ped1 += thisped;
                                        ped1sq += thisped*thisped;
                                }
                        }
                        if (scale.at(j)==2) {
                                thisped = pedestal.at(j);
                                if (thisped>40 && thisped<200) { // ad hoc method of cutting out low values of pre-adc
                                        ++n2;
                                        ped2 += thisped;
                                        ped2sq += thisped*thisped;
                                }
                        }
                }
                ped1 /= n1; ped2 /= n2;
                ped1sd = sqrt(ped1sq/n1 - ped1*ped1); ped2sd = sqrt(ped2sq/n2 - ped2*ped2);

                // Do the calibration on this PMT
                myCalib = new CoarseScaleCalib(adc,scale,ped1,ped2,ped1sd,ped2sd);
                //if(thispmt==1283) {
                try {
                        myCalib->Fit();

                        double q1,q2;
                        myCalib->Get_quality(q1,q2);

                        // Output the results to data file (can print associated errors, but this slows the code down a lot)
                        outfile << thispmt << '\t' << ring.at(i) << '\t' << column.at(i) << '\t' << board.at(i) << '\t' << connector.at(i) << '\t'
                                << myCalib->Get_mu()    << '\t' 
                                << myCalib->Get_sigma() << '\t' 
                                << myCalib->Get_rho2()  << '\t' 
                                << myCalib->Get_M()     << '\t'
                                << myCalib->Get_ADC2_Smearing()     << '\t'
                                << q1                   << '\t' << q2 << '\t' 
                                << endl;

                        //
                        // Print the ADC1 spectrum
                        /*for (int x=2000; x<=3500; x+=1) {
                                outfile << x << '\t' << myCalib->GetEmpiricalDist(1,x) << endl; ///myCalib->Get_N1() << '\t' << myCalib->prob(x,1) << endl;
                                }*/

                        // Print the ADC2 spectrum
                        /*for (int x=0; x<=1000; x+=1) {
                        /       outfile << x << '\t' << myCalib->GetEmpiricalDist(2,x) << endl; ///myCalib->Get_N2() << '\t' << myCalib->prob(x,2) << endl;
                        }*/

                        outfile << "\n==================================================================\n";
                        //
                }
                catch(char const* e) {
                        cerr << "Cannot calibrate PMT " << thispmt << ": " << e << endl;
                }
                //}

                adc.clear();
                scale.clear();
                pedestal.clear();
                delete myCalib;
        }

        outfile.close();

        return sc;
}

Member Data Documentation

Definition at line 37 of file CoarseScaleCalibrationAlg.h.

Definition at line 38 of file CoarseScaleCalibrationAlg.h.

Definition at line 39 of file CoarseScaleCalibrationAlg.h.

Definition at line 42 of file CoarseScaleCalibrationAlg.h.

Definition at line 43 of file CoarseScaleCalibrationAlg.h.

vector<int> CoarseScaleCalibrationAlg::vadc [private]

Definition at line 46 of file CoarseScaleCalibrationAlg.h.

vector<int> CoarseScaleCalibrationAlg::vscale [private]

Definition at line 47 of file CoarseScaleCalibrationAlg.h.

vector<int> CoarseScaleCalibrationAlg::vped [private]

Definition at line 48 of file CoarseScaleCalibrationAlg.h.

vector<int> CoarseScaleCalibrationAlg::vpmt [private]

Definition at line 49 of file CoarseScaleCalibrationAlg.h.

vector<int> CoarseScaleCalibrationAlg::vring [private]

Definition at line 50 of file CoarseScaleCalibrationAlg.h.

vector<int> CoarseScaleCalibrationAlg::vcolumn [private]

Definition at line 51 of file CoarseScaleCalibrationAlg.h.

vector<int> CoarseScaleCalibrationAlg::vboard [private]

Definition at line 52 of file CoarseScaleCalibrationAlg.h.

Definition at line 53 of file CoarseScaleCalibrationAlg.h.

list CoarseScaleCalibrationAlg::__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:14:01 for CoarseScaleCalibrationAlg by doxygen 1.7.4