Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:12

0001 #ifndef compareCands_h
0002 #define compareCands_h
0003 
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/Utilities/interface/InputTag.h"
0010 #include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h"
0011 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctCollections.h"
0012 #include "TH2.h"
0013 #include "TH1.h"
0014 #include "L1Trigger/L1GctAnalyzer/interface/GctErrorAnalyzerDefinitions.h"
0015 
0016 //first declare stuff about the class template
0017 //notice that we pass our own defined struct of data with necessary mbx information (we can modify this in future without changing much)
0018 //we also avoid messing about with class hierarchy...
0019 template <class T>
0020 class compareCands {
0021 public:
0022   compareCands(const T &data, const T &emu, const GctErrorAnalyzerMBxInfo &mbxparams);
0023   ~compareCands();
0024 
0025   bool doCompare(TH1I *errorFlag_hist_,
0026                  TH1I *mismatchD_Rank,
0027                  TH2I *mismatchD_EtEtaPhi,
0028                  TH1I *mismatchE_Rank,
0029                  TH2I *mismatchE_EtEtaPhi);
0030 
0031 private:
0032   T data_, emu_;
0033   GctErrorAnalyzerMBxInfo mbxparams_;
0034 };
0035 
0036 //now the implementation
0037 template <class T>
0038 compareCands<T>::compareCands(const T &data, const T &emu, const GctErrorAnalyzerMBxInfo &mbxparams)
0039     : data_(data), emu_(emu), mbxparams_(mbxparams) {
0040   //std::cout << "initialising..." << std::endl;
0041 }
0042 
0043 template <class T>
0044 compareCands<T>::~compareCands() {
0045   //anything need destructing?
0046 }
0047 
0048 template <class T>
0049 bool compareCands<T>::doCompare(TH1I *errorFlag_hist_,
0050                                 TH1I *mismatchD_Rank,
0051                                 TH2I *mismatchD_EtEtaPhi,
0052                                 TH1I *mismatchE_Rank,
0053                                 TH2I *mismatchE_EtEtaPhi) {
0054   //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
0055   //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
0056   //These TrigBx parameters are set in the configuration to make things more flexible if things change later
0057 
0058   //define some temporary local variables
0059   bool errorFlag = false;
0060   unsigned int i = 0, j = 0;
0061   std::vector<bool> matched(GCT_OBJECT_QUANTA);
0062   //this makes a vector of GCT_OBJECT_QUANTA=4 bools, all set to false
0063   //remember that pushing back will make the vector larger!
0064 
0065   for (i = 0; i < data_->size(); i++) {
0066     //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)
0067     if (data_->at(i).bx() != mbxparams_.GCTTrigBx)
0068       continue;
0069 
0070     //If the data candidate has zero rank, move to the next data candidate
0071     //since all the candidates are ranked in order of rank, this implies all the remaining data candidates also have rank = 0
0072     if (data_->at(i).rank() == 0)
0073       continue;
0074 
0075     for (j = 0; j < emu_->size(); j++) {
0076       //Again, the first thing to check in this loop is that the BX of the emulator data corresponds to the trig Bx
0077       if (emu_->at(j).bx() != mbxparams_.EmuTrigBx)
0078         continue;
0079 
0080       if (data_->at(i).rank() == emu_->at(j).rank() &&
0081           data_->at(i).regionId().ieta() == emu_->at(j).regionId().ieta() &&
0082           data_->at(i).regionId().iphi() == emu_->at(j).regionId().iphi() && matched.at((j % GCT_OBJECT_QUANTA)) == 0) {
0083         //this means that the ith data candidate matches the jth emulator candidate
0084         errorFlag_hist_->Fill(0);                    //fill the errorflag histo in the matched bin
0085         matched.at((j % GCT_OBJECT_QUANTA)) = true;  //set emulator candidate to matched so it doesn't get re-used
0086         break;                                       //matched the current data candidate, now move to the next
0087       }
0088 
0089       if ((j % GCT_OBJECT_QUANTA) + 1 == GCT_OBJECT_QUANTA) {
0090         errorFlag_hist_->Fill(1);                   //fill the errorflag histo in the unmatched data candidate bin
0091         mismatchD_Rank->Fill(data_->at(i).rank());  //fill the rank histogram of mismatched data candidates
0092         mismatchD_EtEtaPhi->Fill(data_->at(i).regionId().ieta(),
0093                                  data_->at(i).regionId().iphi(),
0094                                  data_->at(i).rank());  //fill the EtEtaPhi dist for mismatched candidates
0095         errorFlag = true;                               //set the errorFlag to true
0096       }
0097     }
0098   }
0099 
0100   //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
0101   for (i = 0; i < matched.size(); i++) {
0102     //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
0103     //emulator candidates either have rank = 0 (which is good) or rank > 0 (which is bad)
0104     if (matched.at(i))
0105       continue;
0106 
0107     //now loop over the emulator candidates
0108     for (j = 0; j < emu_->size(); j++) {
0109       //check that the bx of the emulator candidates is the trigbx
0110       if (emu_->at(j).bx() != mbxparams_.EmuTrigBx)
0111         continue;
0112 
0113       //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
0114       if ((j % GCT_OBJECT_QUANTA == i) && (emu_->at(j).rank() > 0)) {
0115         errorFlag_hist_->Fill(2);                  //increment emulator mismatched bin
0116         mismatchE_Rank->Fill(emu_->at(j).rank());  //fill the rank histogram for unmatched emulator
0117         mismatchE_EtEtaPhi->Fill(emu_->at(j).regionId().ieta(),
0118                                  emu_->at(j).regionId().iphi(),
0119                                  emu_->at(j).rank());  //fill EtEtaPhi for unmatched emu cands
0120         errorFlag = true;                              //set the errorFlag (if it's not already)
0121       }
0122     }
0123   }
0124 
0125   return errorFlag;
0126 }
0127 
0128 #endif