EM.cpp 4.29 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/** @ingroup ana
 *  @file EM.cpp
 *  @brief Implementation of EM.
 *
 *  Function definitions for EM are provided.
 *  This is a daughter class of Detector.
 *  Methods specific to EMs are implemented here.
 *
 *  @author Aric Tate
 *  @bug No known bugs.
 */

#include "EM.h"

#include <string>
#include <stdio.h>

/** @brief Default Constructor for EM.
 */
EM::EM( ){

}

/** @brief Constructor that takes the whole vector of channels readout and selects and stores only the EM ones
 *  @param _readOut Vector of Channels with all detector configs
 *
 *  Creates a new EM type Detector and picks the relevant Channels from the input vector.
 *
*/

EM::EM( std::vector < Channel* > _readOut, int _runNumber, std::string _name ){

    SetName ( _name );
    // Set up the row translation if run number is from 2021 test beam
    for(int i = 0; i < m_nRows; i++){
      if(false){//SPECIAL CASE IF NEEDED eg: _runNumber >=79 && _runNumber <= 413
        rowTranslation[i] = i+1; //CHECK FOR 2021!
      }else{
        rowTranslation[i] = i;
      }
    }
    for(int i = 0; i < m_nColumns; i++){
      if(false){//SPECIAL CASE IF NEEDED eg: _runNumber >=79 && _runNumber <= 413
        colTranslation[i] = 4-i; //CHECK FOR 2021!
      }else{
        colTranslation[i] = i;
      }
    }

    ResizeSortedElements();
    for(int row = 0; row < m_nRows; row++){
        for(int column = 0; column < m_nColumns; column++){
            for(int i=0; i < (int)_readOut.size(); i++){
                if(_readOut.at(i)->mapping_row == rowTranslation[row] && _readOut.at(i)->mapping_column == colTranslation[column]){
                    m_SortedElements.at(row).push_back(_readOut.at(i));
                    SetElement(_readOut.at(i));
                }
            }
        }
    }

    std::cout << "EM object created with " << m_nRows << " rows and " << m_nColumns << " columns" << std::endl;
}

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

}

/** @brief Get the properties of a detector element
 *  @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
 *
 * If m_SortedElements is populated, return the element in
 * m_SortedElements[row][column].
 * Otherwise returns a pointer to the Channel stored in m_Element
 * with the requested row and column.
 * If the requested element is not found, return a warning message and a NULL pointer.
 *
 */
Channel* EM::GetElement(int row, int column){

    if( ((int)m_SortedElements.size()) == m_nRows){
      return m_SortedElements[row][column];
    }else{
        for(int i=0; i < (int)GetChannelsVector().size(); i++){
            if(rowTranslation[row] == GetChannelsVector().at(i)->mapping_row && colTranslation[column] == GetChannelsVector().at(i)->mapping_column){
              return GetChannelsVector().at(i);
            }
        }
     }
  std::cerr << " WARNING: Element (" << row << "," << column << ") not found! " << std::endl;
  return nullptr;

}

/** @brief Prints a map of the EM to the terminal
 *
 * Prints the map of a 3x3 EM.
 * Displays a grid of elements with row,column on the top line, DRS4
 * Channel on the second line, and if the element is functioning on the
 * third line.
 *
 */
void EM::PrintMap(){
  std::cout << " ___________________________________ " << std::endl;
  //EM has 3 rows and 3 columns
  for(int row = 1; row <= m_nRows; row++){
      Channel* c[5];
      std::string status, name;
      for(int cln = 1; cln <= m_nColumns; cln++){

          c[cln] = GetElement(row,cln);
          if(c[cln]->is_on) status = "ON";
              else status = "OFF";
          if (cln == 1) std::cout << "|  " << row << "," << cln << " --> " << c[cln]->name << " , " << status;
          else std::cout << "  |  " << row << "," << cln << " --> " << c[cln]->name << " , " << status;

        }//End of the loop over columns
      }//End of the loop over rows
}

/** @brief Resizes m_SortedElements
 *
 * Uses m_nRows and m_nColumns to resize m_SortedElements
 * 2D vectors must have columns sized individually.
 *
 */
void EM::ResizeSortedElements(){
    m_SortedElements.resize(m_nRows);
    for(int row=0; row < m_nRows; row++){
        m_SortedElements.resize(m_nColumns);
    }
}