ATLAS Offline Software
EDM_object.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <vector>
6 #include <string>
7 #include <iostream>
8 
9 #include "TTree.h"
10 #include "TBranch.h"
11 #include "TFile.h"
12 
13 #include "EDM_object.h"
14 
16  m_stationName = nullptr;
17  m_stationEta = nullptr;
18  m_stationPhi = nullptr;
19  m_multiplet = nullptr;
20  m_gas_gap = nullptr;
21  m_channel_type = nullptr;
22  m_channel = nullptr;
23  m_matchedchannel = nullptr;
24  m_mismatches = 0;
25  m_total = 0;
26 }
27 
29  if (m_matchedchannel) {
30  delete m_matchedchannel;
31  m_matchedchannel = nullptr;
32  }
33 }
34 
35 size_t EDM_object::size() {
36  if (!m_stationName) { return 0; }
37  checksize();
38  return m_stationName->size();
39 }
40 
42  size_t channel_type_size;
43  size_t size = m_stationName->size();
44  //skip channel_type check if MM, as MM does not have this parameter.
45  channel_type_size = (m_channel_type) ? m_channel_type->size() : size;
46  if (! (m_stationEta->size() == size ||
47  m_stationPhi->size() == size ||
48  m_multiplet->size() == size ||
49  m_gas_gap->size() == size ||
50  channel_type_size == size ||
51  m_channel->size() == size) )
52  { printf("NSWMatchingAlg: Sizes of data object %s_%s do not match!\n", m_name.Data(), m_detector.Data()); }
53 }
54 
56  // sTGC
57  if (m_channel_type) {
58  printf("%-15s %-15s %-15s %-15s %-15s %-15s %-15s %-15s\n", "stationname", "stationEta", "stationPhi", "multiplet", "gas_gap", "channel_type", "channel", "matchedchannel");
59  for (uint i = 0; i < this->size(); ++i)
60  { printf("%-15s %-15d %-15d %-15d %-15d %-15d %-15d %-15d\n", m_stationName->at(i).data(), m_stationEta->at(i), m_stationPhi->at(i), m_multiplet->at(i), m_gas_gap->at(i), m_channel_type->at(i), m_channel->at(i), m_matchedchannel->at(i));}
61  // MM
62  } else {
63  printf("%-15s %-15s %-15s %-15s %-15s %-15s %-15s\n", "stationname", "stationEta", "stationPhi", "multiplet", "gas_gap", "channel", "matchedchannel");
64  for (uint i = 0; i < this->size(); ++i)
65  { printf("%-15s %-15d %-15d %-15d %-15d %-15d %-15d\n", m_stationName->at(i).data(), m_stationEta->at(i), m_stationPhi->at(i), m_multiplet->at(i), m_gas_gap->at(i), m_channel->at(i), m_matchedchannel->at(i));}
66  }
67 }
68 
70  bool match = true;
71  match &= data0.m_channel_type ? data0.m_channel_type->at(i) == data1.m_channel_type->at(j) : true;
72  match &= data0.m_stationName->at(i).compare(data1.m_stationName->at(j)) == 0;
73  match &= data0.m_stationEta->at(i) == data1.m_stationEta->at(j);
74  match &= data0.m_stationPhi->at(i) == data1.m_stationPhi->at(j);
75  match &= data0.m_multiplet->at(i) == data1.m_multiplet->at(j);
76  match &= data0.m_gas_gap->at(i) == data1.m_gas_gap->at(j);
77  return match;
78 }
79 
80 bool EDM_object::update_match(int index, int ch_candidate) {
81  // make sure the machedchannel is set to the default value (-10)
82  if (!m_matchedchannel) { return false; }
83  // If any match found, overwarite default value
84  if ( m_matchedchannel->at(index) == -10 ) { m_matchedchannel->at(index) = ch_candidate; }
85  // Default channel value in digitization = -1
86  if ( ch_candidate == -1 ) { return false; }
87  // Check if the match is close enough
88  if (abs(ch_candidate - m_channel->at(index)) < abs(m_channel->at(index) - m_matchedchannel->at(index)) ) {
89  m_matchedchannel->at(index) = ch_candidate;
90  return true;
91  }
92  return false;
93 }
94 
96  if (empty()) { return; }
97  m_matchedchannel = new std::vector<int>(this->size());
98  for ( uint i = 0; i < this->size(); ++i) { m_matchedchannel->at(i) = -10; }
99 }
100 
102  if (!m_stationName) { return true; }
103  if (m_stationName->empty()) { return true; }
104  return false;
105 }
106 
107 void EDM_object::update_efficiency ( int maximum_difference ) {
108  uint nMatches = 0;
109  size_t n_obj = size();
110  m_total += n_obj;
111  bool isMatched;
112  for (uint i = 0; i < n_obj; ++i) {
113  // default matched channel value is -10. If not set to any other value, it is always a mismatch
114  isMatched = m_matchedchannel->at(i) < 0 || abs( m_channel->at(i) - m_matchedchannel->at(i) ) <= maximum_difference;
115  nMatches += isMatched;
116  }
117  m_mismatches += (n_obj - nMatches);
118 }
119 
120 void EDM_object::printEfficiency(std::ofstream& file) {
121  file << "\nMatching " << m_name << " to " << m_matchedwith << " for " << m_detector << std::endl;
122  file << "Total: " << m_total << ", number of mismatches: " << m_mismatches << std::endl;
123  file << "Efficiency: " << (m_total - m_mismatches) / (double)m_total * 100. << "%" << std::endl;
124 }
EDM_object::identifierMatch
bool identifierMatch(EDM_object &data0, EDM_object &data1, uint i, uint j)
Definition: EDM_object.cxx:69
EDM_object::m_stationName
std::vector< std::string > * m_stationName
Definition: EDM_object.h:46
EDM_object::checksize
void checksize()
Definition: EDM_object.cxx:41
EDM_object
Definition: EDM_object.h:14
EDM_object::m_matchedchannel
std::vector< int > * m_matchedchannel
Definition: EDM_object.h:54
index
Definition: index.py:1
EDM_object::m_detector
TString m_detector
Definition: EDM_object.h:59
EDM_object::size
size_t size()
Definition: EDM_object.cxx:35
EDM_object::m_matchedwith
TString m_matchedwith
Definition: EDM_object.h:58
EDM_object::m_stationPhi
std::vector< int > * m_stationPhi
Definition: EDM_object.h:48
InDetSecVtxTruthMatchUtils::isMatched
bool isMatched(int matchInfo)
Definition: InDetSecVtxTruthMatchTool.h:48
EDM_object::m_channel
std::vector< int > * m_channel
Definition: EDM_object.h:52
EDM_object::update_efficiency
void update_efficiency(int maximum_difference)
Definition: EDM_object.cxx:107
EDM_object::empty
bool empty()
Definition: EDM_object.cxx:101
EDM_object::m_gas_gap
std::vector< int > * m_gas_gap
Definition: EDM_object.h:50
EDM_object::m_channel_type
std::vector< int > * m_channel_type
Definition: EDM_object.h:51
uint
unsigned int uint
Definition: LArOFPhaseFill.cxx:20
lumiFormat.i
int i
Definition: lumiFormat.py:85
file
TFile * file
Definition: tile_monitor.h:29
EDM_object::init_matching
void init_matching()
Definition: EDM_object.cxx:95
EDM_object::EDM_object
EDM_object()
Definition: EDM_object.cxx:15
EDM_object::m_mismatches
int m_mismatches
Definition: EDM_object.h:60
EDM_object::update_match
bool update_match(int index, int ch_candidate)
Definition: EDM_object.cxx:80
EDM_object::m_name
TString m_name
Definition: EDM_object.h:57
RTTAlgmain.data1
data1
Definition: RTTAlgmain.py:54
EDM_object::printEfficiency
void printEfficiency(std::ofstream &file)
Definition: EDM_object.cxx:120
EDM_object.h
EDM_object::m_total
int m_total
Definition: EDM_object.h:61
EDM_object::m_multiplet
std::vector< int > * m_multiplet
Definition: EDM_object.h:49
EDM_object::clearVars
void clearVars()
Definition: EDM_object.cxx:28
EDM_object::printInfo
void printInfo()
Definition: EDM_object.cxx:55
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356
EDM_object::m_stationEta
std::vector< int > * m_stationEta
Definition: EDM_object.h:47