CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
compareCands.h
Go to the documentation of this file.
1 #ifndef compareCands_h
2 #define compareCands_h
3 
13 #include "TH2.h"
14 #include "TH1.h"
16 
17 //first declare stuff about the class template
18 //notice that we pass our own defined struct of data with necessary mbx information (we can modify this in future without changing much)
19 //we also avoid messing about with class hierarchy...
20 template <class T>
21 class compareCands {
22 public:
23  compareCands(const T &data, const T &emu, const GctErrorAnalyzerMBxInfo &mbxparams);
24  ~compareCands();
25 
26  bool doCompare(TH1I *errorFlag_hist_,
27  TH1I *mismatchD_Rank,
28  TH2I *mismatchD_EtEtaPhi,
29  TH1I *mismatchE_Rank,
30  TH2I *mismatchE_EtEtaPhi);
31 
32 private:
35 };
36 
37 //now the implementation
38 template <class T>
39 compareCands<T>::compareCands(const T &data, const T &emu, const GctErrorAnalyzerMBxInfo &mbxparams)
40  : data_(data), emu_(emu), mbxparams_(mbxparams) {
41  //std::cout << "initialising..." << std::endl;
42 }
43 
44 template <class T>
46  //anything need destructing?
47 }
48 
49 template <class T>
50 bool compareCands<T>::doCompare(TH1I *errorFlag_hist_,
51  TH1I *mismatchD_Rank,
52  TH2I *mismatchD_EtEtaPhi,
53  TH1I *mismatchE_Rank,
54  TH2I *mismatchE_EtEtaPhi) {
55  //this code has now been patched to be multiple_bx compliant. However, this still means that only 1 comparison will happen per event, and this has to be
56  //matched such that the RCTTrigBx(=0) data is run over the emulator and the EmuTrigBx analysis (Bx=0) corresponds to the GCTTrigBx (Bx=0) analysis
57  //These TrigBx parameters are set in the configuration to make things more flexible if things change later
58 
59  //define some temporary local variables
60  bool errorFlag = false;
61  unsigned int i = 0, j = 0;
62  std::vector<bool> matched(GCT_OBJECT_QUANTA);
63  //this makes a vector of GCT_OBJECT_QUANTA=4 bools, all set to false
64  //remember that pushing back will make the vector larger!
65 
66  for (i = 0; i < data_->size(); i++) {
67  //The first thing to check is that the BX of the data corresponds to the trig Bx (we expect these to be contiguous i.e. data sorted in Bx)
68  if (data_->at(i).bx() != mbxparams_.GCTTrigBx)
69  continue;
70 
71  //If the data candidate has zero rank, move to the next data candidate
72  //since all the candidates are ranked in order of rank, this implies all the remaining data candidates also have rank = 0
73  if (data_->at(i).rank() == 0)
74  continue;
75 
76  for (j = 0; j < emu_->size(); j++) {
77  //Again, the first thing to check in this loop is that the BX of the emulator data corresponds to the trig Bx
78  if (emu_->at(j).bx() != mbxparams_.EmuTrigBx)
79  continue;
80 
81  if (data_->at(i).rank() == emu_->at(j).rank() &&
82  data_->at(i).regionId().ieta() == emu_->at(j).regionId().ieta() &&
83  data_->at(i).regionId().iphi() == emu_->at(j).regionId().iphi() && matched.at((j % GCT_OBJECT_QUANTA)) == 0) {
84  //this means that the ith data candidate matches the jth emulator candidate
85  errorFlag_hist_->Fill(0); //fill the errorflag histo in the matched bin
86  matched.at((j % GCT_OBJECT_QUANTA)) = true; //set emulator candidate to matched so it doesn't get re-used
87  break; //matched the current data candidate, now move to the next
88  }
89 
90  if ((j % GCT_OBJECT_QUANTA) + 1 == GCT_OBJECT_QUANTA) {
91  errorFlag_hist_->Fill(1); //fill the errorflag histo in the unmatched data candidate bin
92  mismatchD_Rank->Fill(data_->at(i).rank()); //fill the rank histogram of mismatched data candidates
93  mismatchD_EtEtaPhi->Fill(data_->at(i).regionId().ieta(),
94  data_->at(i).regionId().iphi(),
95  data_->at(i).rank()); //fill the EtEtaPhi dist for mismatched candidates
96  errorFlag = true; //set the errorFlag to true
97  }
98  }
99  }
100 
101  //loop over the matched boolean vector and see if there are any rank>0 unmatched emu candidates - if there are populate the histogram in the emulator mismatched bin
102  for (i = 0; i < matched.size(); i++) {
103  //the first thing to check is that the matched flag for object i out of 0,1,2,3 (0 -> GCT_OBJECT_QUANTA-1) is not set - then we can check that the corresponding
104  //emulator candidates either have rank = 0 (which is good) or rank > 0 (which is bad)
105  if (matched.at(i))
106  continue;
107 
108  //now loop over the emulator candidates
109  for (j = 0; j < emu_->size(); j++) {
110  //check that the bx of the emulator candidates is the trigbx
111  if (emu_->at(j).bx() != mbxparams_.EmuTrigBx)
112  continue;
113 
114  //now check that the j%GCT_OBJECT_QUANTA is the same as the index of the false entry in the bool_matched vector so that we are looking at the right candidate
115  if ((j % GCT_OBJECT_QUANTA == i) && (emu_->at(j).rank() > 0)) {
116  errorFlag_hist_->Fill(2); //increment emulator mismatched bin
117  mismatchE_Rank->Fill(emu_->at(j).rank()); //fill the rank histogram for unmatched emulator
118  mismatchE_EtEtaPhi->Fill(emu_->at(j).regionId().ieta(),
119  emu_->at(j).regionId().iphi(),
120  emu_->at(j).rank()); //fill EtEtaPhi for unmatched emu cands
121  errorFlag = true; //set the errorFlag (if it's not already)
122  }
123  }
124  }
125 
126  return errorFlag;
127 }
128 
129 #endif
bool doCompare(TH1I *errorFlag_hist_, TH1I *mismatchD_Rank, TH2I *mismatchD_EtEtaPhi, TH1I *mismatchE_Rank, TH2I *mismatchE_EtEtaPhi)
Definition: compareCands.h:50
compareCands(const T &data, const T &emu, const GctErrorAnalyzerMBxInfo &mbxparams)
Definition: compareCands.h:39
const unsigned int GCT_OBJECT_QUANTA
GctErrorAnalyzerMBxInfo mbxparams_
Definition: compareCands.h:34
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
long double T