userAlg - a CAL + ntuple Example

This is an example of accessing sample CAL Digi and Recon TDS classes and creating an ntuple with selected items. Note that to create ntuples, you will need the ntupleWriterSvc package built and in your path - this should happen for you when you checkout and build userAlg.

This example will produce an ntuple with three columns - NumCalLogs, eTotal and eCorr.

CalDigi

CalRecon

StatusCode UserAlg::execute()  {


  StatusCode sc = StatusCode::SUCCESS;  
  MsgStream log( msgSvc(), name() );
  log << MSG::INFO << "executing " << ++m_count << " time" << endreq;


// An example of retrieving data from the TDS
  SmartDataPtr<Event::CalDigiCol> calDigiData(eventSvc(),"/Event/Digi/CalDigiCol");

// retrieve CAL data pointer
  if (calDigiData == 0) {
     log << MSG::INFO << "No CAL Recon Data available" << endreq;
   } else {

     int nLogs = calDigiData->size();
// Here we are adding to our ROOT ntuple

    sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "NumCalLogs", nLogs);

   double eTot = 0.;

   for (Event::CalDigiCol::const_iterator it = calDigiData->begin(); it != calDigiData->end(); it++) {
       double eLog = ((*it)->getAdc(0,idents::CalXtalId::POS) + (*it)->getAdc(0,idents::CalXtalId::NEG))/2.;
        if (eLog > 0.)     eTot += eLog;
       }
       sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "eTotal", eTot);
   }

// An example of retrieving Recon data from the TDS
  SmartDataPtr<Event::CalClusterCol> calClusData(eventSvc(),"/EventModel/CalRecon/CalClusterCol");

// retrieve CAL data pointer
  if (calClusData == 0) {
      log << MSG::INFO << "No CAL Recon Data available" << endreq;
  } else {

    int nClus = calClusData->num();

    for (int iC=0; iC < nClus; iC++) {
        Event::CalCluster* c = calClusData->getCluster(iC);
        double eCorr = c->getEnergyCorrected();
      
        sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "eCorr", eCorr); 
       }
    }
return sc;
}

You will want to be accessing the TDS - awaiting better descriptions of the classes, see the Event Model description.


R.Dubois Last Modified: 2004-08-04 15:40:37 -0700