/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 Member Functions | Private Attributes
AdReconFigs Class Reference

#include <AdReconFigs.h>

Collaboration diagram for AdReconFigs:
Collaboration graph
[legend]

List of all members.

Public Member Functions

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

Private Member Functions

TH1 * getOrMakeHist (int run, const DayaBay::Detector &detector, int histogram)
std::string getPath (int run, const char *detectorName, const char *histName)

Private Attributes

std::string m_reconLocation
IStatisticsSvcm_statsSvc
TimeStampm_firstTriggerTime
std::map< DayaBay::Detector,
TimeStamp
m_lastTriggerTime
std::map< int, TH1 ** > m_shortCuts
std::vector< TH1 * > m_normalize

Detailed Description

Definition at line 37 of file AdReconFigs.h.


Constructor & Destructor Documentation

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

Definition at line 16 of file AdReconFigs.cc.

  : GaudiAlgorithm(name,pSvcLocator),
    m_statsSvc(0),
    m_firstTriggerTime(0)
{
  declareProperty("ReconLocation", m_reconLocation="/Event/Rec/AdSimple",
                  "Generate histograms for this reconstruction TES path");
}
AdReconFigs::~AdReconFigs ( ) [virtual]

Definition at line 26 of file AdReconFigs.cc.

{
}

Member Function Documentation

StatusCode AdReconFigs::initialize ( ) [virtual]

Definition at line 30 of file AdReconFigs.cc.

{
  // Initialize the necessary services
  StatusCode sc = this->service("StatisticsSvc",m_statsSvc,true);
  if(sc.isFailure()){
    error() << "Failed to get StatisticsSvc" << endreq;
    return sc;
  }
  return sc;
}
StatusCode AdReconFigs::execute ( ) [virtual]

Definition at line 41 of file AdReconFigs.cc.

{
  // Add the current event into histograms
  DayaBay::RecHeader* recHeader = 
    get<DayaBay::RecHeader>(m_reconLocation);
  if(!recHeader){
    error() << "Failed to get reconstructed header: " << m_reconLocation
            << endreq;
    return StatusCode::FAILURE;
  }

  const DayaBay::RecTrigger* recTrigger = &(recHeader->recTrigger());
  if(!recTrigger){
    error() << "Failed to get reconstructed trigger: " << m_reconLocation
            << endreq;
    return StatusCode::FAILURE;
  }
  
  if(!recTrigger->detector().isAD()){
    // Not an AD, continue
    return StatusCode::SUCCESS;
  }

  // Add access to CalibStats
  if(!exist<DayaBay::UserDataHeader>("/Event/Data/CalibStats")){
    // No calibstats data this cycle
    return StatusCode::SUCCESS;
  }

  DayaBay::UserDataHeader* calibStats = 
    get<DayaBay::UserDataHeader>("/Event/Data/CalibStats");
  if(!calibStats){
    error() << "Failed to get CalibStats data" << endreq;
    return StatusCode::FAILURE;
  }

  // Wow... Look at the trouble we have to go through to get the run number
  int runNumber = 0;
  {
    // Add the current event into histograms
    DayaBay::ReadoutHeader* readoutHeader = 
      get<DayaBay::ReadoutHeader>("/Event/Readout/ReadoutHeader");
    if(!readoutHeader){
      error() << "Failed to get readout header." << endreq;
      return StatusCode::FAILURE;
    }
    
    const DayaBay::DaqCrate* ro = readoutHeader->daqCrate();
    if(!ro){
      error() << "Failed to get readout from header" << endreq;
      return StatusCode::FAILURE;
    }
    
    runNumber = ro->runNumber();
  }

  if(!m_firstTriggerTime){
    m_firstTriggerTime = new TimeStamp(recTrigger->triggerTime());
  }

  // Find histograms
  const DayaBay::Detector& detector = recTrigger->detector();
  TH1F* adEnergy = dynamic_cast<TH1F*>(this->getOrMakeHist(runNumber,
                                                           detector,
                                                           ADENERGY));
  TH2F* adZVsRho = dynamic_cast<TH2F*>(this->getOrMakeHist(runNumber,
                                                           detector,
                                                           ADZVSRHO));
  TH2F* adYVsX = dynamic_cast<TH2F*>(this->getOrMakeHist(runNumber,
                                                         detector,
                                                         ADYVSX));
  TH2F* adZVsXcal = dynamic_cast<TH2F*>(this->getOrMakeHist(runNumber,
                                                            detector,
                                                            ADZVSXCAL));
  TH1F* triggerBitsFlasherCut = dynamic_cast<TH1F*>(this->getOrMakeHist(runNumber,
                                                                        detector,
                                                                        TRIGGERBITSFLASHERCUT));
  TH1F* adEnergyFlasherCut = dynamic_cast<TH1F*>(this->getOrMakeHist(runNumber,
                                                                     detector,
                                                                     ADENERGYFLASHERCUT));

  // get ellipse variable from CalibStats
  float maxQ = calibStats->getFloat("MaxQ"); 
  float quadrant = calibStats->getFloat("Quadrant"); 
  float midTimeRMS = calibStats->getFloat("MiddleTimeRMS");
  float maxQ_2inch = calibStats->getFloat("MaxQ_2inchPMT");
  float ellipse = quadrant*quadrant + (maxQ/0.45)*(maxQ/0.45);

  if(recTrigger->energyStatus()==ReconStatus::kGood){
    adEnergy->Fill(recTrigger->energy());
    if(ellipse<1 && maxQ_2inch<100)
        adEnergyFlasherCut->Fill(recTrigger->energy());
    if( recTrigger->energy()>0.7 && ellipse<1 && midTimeRMS<80 ){
      unsigned int trigType = recTrigger->triggerType();
      for(unsigned i=0; i<16; i++) {
        if(trigType & 1<<i) {
          triggerBitsFlasherCut->Fill(i);
        }
      }
    }
  }
  if(recTrigger->positionStatus()==ReconStatus::kGood){
    // FIXME: Use CLHEP units
    double x = recTrigger->position().x() / 1000.;
    double y = recTrigger->position().y() / 1000.;
    double z = recTrigger->position().z() / 1000.;
    double rhoSq = x*x+y*y;
    double xCal = x*TMath::Cos(DayaBay::Calibration::AD_AxisB_phi)
      + y*TMath::Sin(DayaBay::Calibration::AD_AxisB_phi);
    adZVsRho->Fill( rhoSq/4., z );
    adYVsX->Fill(x, y);
    adZVsXcal->Fill(xCal, z);
  }

  m_lastTriggerTime[recTrigger->detector()] = recTrigger->triggerTime();

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

Definition at line 160 of file AdReconFigs.cc.

{
  // Handle Normalized histograms
  for(unsigned int normIdx=0; normIdx<m_normalize.size(); normIdx++){
    TH1* hist = m_normalize[normIdx];
    hist->Sumw2();
    if(hist->GetNormFactor()>0){
      double scale = 1./hist->GetNormFactor();
      hist->SetNormFactor(1);
      hist->Scale( scale );
    }
    hist->SetBit(TH1::kIsAverage);
  }
  m_normalize.clear();
  // Clean-up histogram shortcuts
  std::map<int,TH1**>::iterator histIter, histEnd = m_shortCuts.end();
  for(histIter = m_shortCuts.begin(); histIter!=histEnd; histIter++){
    delete [] (histIter->second);
    histIter->second = 0;
  }
  if( m_statsSvc ) m_statsSvc->release();
  if(m_firstTriggerTime){
    delete m_firstTriggerTime;
    m_firstTriggerTime = 0;
  }
  return StatusCode::SUCCESS;
}
TH1 * AdReconFigs::getOrMakeHist ( int  run,
const DayaBay::Detector detector,
int  histogram 
) [private]

Definition at line 190 of file AdReconFigs.cc.

{
  int siteInt = 0;
  switch(detector.site()){
  case Site::kUnknown:
    siteInt = 0; break;
  case Site::kDayaBay:
    siteInt = 1; break;
  case Site::kLingAo:
    siteInt = 2; break;
  case Site::kFar:
    siteInt = 3; break;
  case Site::kSAB:
    siteInt = 4; break;
  default:
    error() << "Unknown site: " << detector.detName() << endreq;
    return 0;
  }
  int detectorInt = int(detector.detectorId());
  std::map<int,TH1**>::iterator histIter = m_shortCuts.find(run);
  TH1** histograms = 0;
  if( histIter == m_shortCuts.end() ){
    // Initialize histogram shortcuts
    histograms = new TH1*[MAXRECHISTS];
    for(int i=0; i<MAXRECHISTS; i++) histograms[i] = 0;
    m_shortCuts[run] = histograms;
  }else{
    // Found run
    histograms = histIter->second;
  }
  
  TH1* hist = 
    histograms[siteInt * NDETECTORS * NRECHISTOGRAMS
               + detectorInt * NRECHISTOGRAMS
               + histogram];
  if(!hist){
    // Make this histogram
    std::string histName;
    std::string histTitle;
    if(detector.detectorId()){
      // Make detector histogram
      std::string reconStyle = "Unknown"; 
      for(int strIdx=m_reconLocation.size()-1; strIdx>=0; strIdx--){
        if(m_reconLocation[strIdx]=='/'){
          reconStyle=std::string(m_reconLocation,strIdx+1);
          break;
        }
      }
      switch(histogram){
      case ADENERGY:
        // AD Energy 
        histName = std::string("adEnergy_") + reconStyle;
        histTitle = std::string("AD Energy (") + reconStyle
          + std::string(")");
        hist = new TH1F(histName.c_str(),histTitle.c_str(),
                        1100,-1,10);
        hist->GetXaxis()->SetTitle("Energy [MeV]");
        hist->GetYaxis()->SetTitle("Events / keV");
        break;
      case ADZVSRHO:
        // AD Z vs Rho 
        histName = std::string("adZVsRho_") + reconStyle;
        histTitle = std::string("AD Reconstructed Position (") + reconStyle
          + std::string(")");
        hist = new TH2F(histName.c_str(),histTitle.c_str(),
                        400,0,1.6,400,-2,2);
        hist->GetXaxis()->SetTitle("( #rho / 2 m )^{2}");
        hist->GetYaxis()->SetTitle("z [m]");
        break;
      case ADYVSX:
        // AD Y vs X 
        histName = std::string("adYVsX_") + reconStyle;
        histTitle = std::string("AD Reconstructed Position (") + reconStyle
          + std::string(")");
        hist = new TH2F(histName.c_str(),histTitle.c_str(),
                        400,-3,3,400,-3,3);
        hist->GetXaxis()->SetTitle("x [m]");
        hist->GetYaxis()->SetTitle("y [m]");
        break;
      case ADZVSXCAL:
        // AD Z vs X_calibration  
        histName = std::string("adZVsXcal_") + reconStyle;
        histTitle = std::string("AD Reconstructed Position (") + reconStyle
          + std::string(")");
        hist = new TH2F(histName.c_str(),histTitle.c_str(),
                        400,-3,3,400,-2,2);
        hist->GetXaxis()->SetTitle("x_{calib} [m]");
        hist->GetYaxis()->SetTitle("z [m]");
        break;
      case TRIGGERBITSFLASHERCUT:
        // trigger bit
        histName = "triggerBitsFlasherCut";
        hist = new TH1F(histName.c_str(),"Trigger bits of E_adSimple>0.7MeV Events after flasher cut",
                  16,-0.5,15.5);
        hist->GetXaxis()->SetTitle("Trigger bits");
        hist->GetYaxis()->SetTitle("Events");
        break;
      case ADENERGYFLASHERCUT:
        // AD Energy After Flasher Cut
        histName = std::string("adEnergy_FlasherCut_") + reconStyle;
        histTitle = std::string("AD Energy after Flasher Cut(") + reconStyle
          + std::string(")");
        hist = new TH1F(histName.c_str(),histTitle.c_str(),
                        1300,-1,12);
        hist->GetXaxis()->SetTitle("Energy [MeV]");
        hist->GetYaxis()->SetTitle("Events / keV");
        break;
      default:
        error() << "Unknown Histogram: " << histogram << endreq;
        return 0;
      }
    }
    debug() << "Making histogram: " << histName << endreq;
    m_statsSvc->put( this->getPath(run, detector.detName().c_str(), 
                                   histName.c_str()), 
                     hist );
    histograms[siteInt * NDETECTORS * NRECHISTOGRAMS
               + detectorInt * NRECHISTOGRAMS
               + histogram] = hist;
  }

  return hist;
}
std::string AdReconFigs::getPath ( int  run,
const char *  detectorName,
const char *  histName 
) [private]

Definition at line 315 of file AdReconFigs.cc.

{
  // Construct histogram path in statistics service
  std::stringstream path;
  path << "/file1/diagnostics/run_" << std::setfill('0') << std::setw(7) 
       << run;
  if(detectorName){
    path << "/detector_" << detectorName;
  }
  path << "/" << histName;
  return path.str();
}

Member Data Documentation

std::string AdReconFigs::m_reconLocation [private]

Definition at line 56 of file AdReconFigs.h.

Definition at line 59 of file AdReconFigs.h.

Definition at line 61 of file AdReconFigs.h.

Definition at line 62 of file AdReconFigs.h.

std::map<int,TH1**> AdReconFigs::m_shortCuts [private]

Definition at line 63 of file AdReconFigs.h.

std::vector<TH1*> AdReconFigs::m_normalize [private]

Definition at line 64 of file AdReconFigs.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:04:10 for AdBasicFigs by doxygen 1.7.4