Detector.cpp 3.69 KB
Newer Older
1
2
/** @ingroup ana
 *  @file Detector.cpp
3
4
 *  @brief Implementation of Detector.
 *
5
6
 *  Function definitions for Detector are provided.
 *  This is the mother class for detectors.
7
8
 *  Methods common to all detectors are implemented here.
 *
9
 *  @author Chad Lantz, Riccardo Longo
10
11
 *  @bug No known bugs.
 */
12

13
#include "Detector.h"
14
#include "Containers.h"
15
#include <vector>
16
17


18
19
20
21
22
23
24
25
26
27
28
29
30
/** @brief Default Constructor for Detector.
 */
Detector::Detector( ){

}

/** @brief Destructor for Detector.
 */
Detector::~Detector( ){

}

/** @brief Get the properties of a detector element
31
32
33
 *  @param row Row of element to be accessed
 *  @param column Column of element to be accessed
 *  @return Pointer to the Channel of the requested element
34
 *
35
 * Returns a pointer to the Channel stored in m_Elements with the
36
 * requested row and column.
37
 * If the requested element is not found, return a warning message and a NULL pointer.
38
 *
39
40
 */
Channel* Detector::GetElement(int row, int column){
41

42
  std::cout << "In getElement " << m_Element.size() << std::endl;
43
44
45
    for(int i=0; i < (int)m_Element.size(); i++){
            if(row == m_Element[i]->mapping_row && column == m_Element[i]->mapping_column){
            return m_Element[i];
46
47
    }
  }
48
  std::cerr << " WARNING: Element (" << row << "," << column << ") not found! " << std::endl;
49
  return nullptr;
50

51
52
}

clantz's avatar
clantz committed
53
54
55
56
57
/** @brief Get the properties of a detector element
 *
 * Returns a pointer to the Channel stored in m_Elements with the
 * requested channel name.
 * If the requested element is not found, return a warning message and a NULL pointer.
58
 *
clantz's avatar
clantz committed
59
60
 */
Channel* Detector::GetElement(std::string _name){
61

clantz's avatar
clantz committed
62
    for(int i=0; i < (int)m_Element.size(); i++){
Riccardo Longo's avatar
Riccardo Longo committed
63
            if(!_name.compare(m_Element.at(i)->name)) return m_Element[i];
clantz's avatar
clantz committed
64
65
66
  }
  std::cerr << " WARNING: Element (" << _name << ") not found! " << std::endl;
  return nullptr;
67

clantz's avatar
clantz committed
68
}
69

70
71
72
73
/**
 * @brief Set the branches of the tree to the channels of the detectors (according to their name, read from the mapping)
 * @param _dataTree : processed data tree
 */
74
75
76
void Detector::SetBranches( TTree *_dataTree ){

    for( uint ch = 0; ch < m_Element.size(); ch++ ){
77
      _dataTree->SetBranchAddress( ("Raw" + m_Element.at(ch)->name).c_str(), &m_Element.at(ch)->pWF );
78
79
80
81
    }

}

82
83
84
85
86
87
/**
 * @brief Declare histograms to be filled with the raw waveform
 */
void Detector::DeclareHistograms(){

    for( uint ch = 0; ch < m_Element.size(); ch++ ){
88
89
        m_Element.at(ch)->WF_histo        = new TH1D( m_Element.at(ch)->name.c_str(), (m_Element.at(ch)->name + ", " + m_Element.at(ch)->detector).c_str(), m_nSamp, 0, m_nSamp);
        m_Element.at(ch)->PWF_histo       = new TH1D((m_Element.at(ch)->name + " Processed").c_str(),  (m_Element.at(ch)->name + ", " + m_Element.at(ch)->detector + " Processed").c_str() , m_nSamp, 0, m_nSamp);
90
        m_Element.at(ch)->FirstDerivative = new TH1D((m_Element.at(ch)->name + " Derivative").c_str(), (m_Element.at(ch)->name + ", " + m_Element.at(ch)->detector + " Derivative").c_str(), m_nSamp, 0, m_nSamp);
91
92
93
94
95
96
97
98
99
100
    }

}

/**
 * @brief Fill histograms with the current raw waveform
 */
void Detector::FillHistograms(){
    for( uint ch = 0; ch < m_Element.size(); ch++ ){
        m_Element.at(ch)->WF_histo->Reset();
101
        m_Element.at(ch)->PWF_histo->Reset();
102
103
104
        m_Element.at(ch)->FirstDerivative->Reset();
        m_Element.at(ch)->FirstDerivativeRMS = 0;
        m_Element.at(ch)->CrossZeroPoints.clear();
105
106
107
108
109
110
        // Loop over samples in each channel
        for( uint samp = 0; samp < m_nSamp; samp++ ){
          m_Element.at(ch)->WF_histo->SetBinContent( samp + 1, m_Element.at(ch)->WF[ samp ] );
          } // End loop over samples in each channel
        }
}