CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/L1Trigger/L1GctAnalyzer/interface/compareCands.h

Go to the documentation of this file.
00001 #ifndef compareCands_h
00002 #define compareCands_h
00003 
00004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00005 #include "FWCore/Framework/interface/Frameworkfwd.h"
00006 #include "FWCore/Framework/interface/EDAnalyzer.h"
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "FWCore/Framework/interface/MakerMacros.h"
00009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00010 #include "FWCore/Utilities/interface/InputTag.h"
00011 #include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h" 
00012 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctCollections.h"
00013 #include "TH2.h"
00014 #include "TH1.h"
00015 #include "L1Trigger/L1GctAnalyzer/interface/GctErrorAnalyzerDefinitions.h"
00016 
00017 //first declare stuff about the class template 
00018 //notice that we pass our own defined struct of data with necessary mbx information (we can modify this in future without changing much)
00019 //we also avoid messing about with class hierarchy...
00020 template <class T>
00021 class compareCands {
00022  public:
00023   compareCands(const T &data, const T &emu, const GctErrorAnalyzerMBxInfo &mbxparams);
00024   ~compareCands();
00025 
00026   bool doCompare(TH1I *errorFlag_hist_, TH1I *mismatchD_Rank, TH2I *mismatchD_EtEtaPhi, TH1I *mismatchE_Rank, TH2I *mismatchE_EtEtaPhi);
00027 
00028  private:  
00029   T data_, emu_;
00030   GctErrorAnalyzerMBxInfo mbxparams_;
00031 
00032 };
00033 
00034 //now the implementation
00035 template<class T>
00036 compareCands<T>::compareCands(const T &data, const T &emu, const GctErrorAnalyzerMBxInfo &mbxparams) :
00037   data_(data),
00038   emu_(emu),
00039   mbxparams_(mbxparams)
00040 {
00041   //std::cout << "initialising..." << std::endl;
00042 }
00043 
00044 template<class T>
00045 compareCands<T>::~compareCands() {
00046   //anything need destructing?
00047 }
00048 
00049 template<class T>
00050 bool compareCands<T>::doCompare(TH1I *errorFlag_hist_, TH1I *mismatchD_Rank, TH2I *mismatchD_EtEtaPhi, TH1I *mismatchE_Rank, TH2I *mismatchE_EtEtaPhi) {
00051 
00052   //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
00053   //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
00054   //These TrigBx parameters are set in the configuration to make things more flexible if things change later
00055 
00056   //define some temporary local variables
00057   bool errorFlag=0;
00058   unsigned int i=0, j=0;
00059   std::vector<bool> matched(GCT_OBJECT_QUANTA);
00060   //this makes a vector of GCT_OBJECT_QUANTA=4 bools, all set to false
00061   //remember that pushing back will make the vector larger!
00062 
00063   for(i=0; i < data_->size(); i++) {
00064 
00065     //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)
00066     if(data_->at(i).bx() != mbxparams_.GCTTrigBx) continue;
00067     
00068     //If the data candidate has zero rank, move to the next data candidate
00069     //since all the candidates are ranked in order of rank, this implies all the remaining data candidates also have rank = 0
00070     if(data_->at(i).rank() == 0 ) continue;
00071 
00072     for(j=0; j < emu_->size(); j++) {
00073 
00074       //Again, the first thing to check in this loop is that the BX of the emulator data corresponds to the trig Bx
00075       if(emu_->at(j).bx() != mbxparams_.EmuTrigBx) continue;
00076 
00077       if(   data_->at(i).rank() == emu_->at(j).rank()
00078             && data_->at(i).regionId().ieta() == emu_->at(j).regionId().ieta()
00079             && data_->at(i).regionId().iphi() == emu_->at(j).regionId().iphi()
00080             && matched.at((j % GCT_OBJECT_QUANTA)) == 0 ) {
00081         //this means that the ith data candidate matches the jth emulator candidate
00082         errorFlag_hist_->Fill(0); //fill the errorflag histo in the matched bin
00083         matched.at((j % GCT_OBJECT_QUANTA)) = 1; //set emulator candidate to matched so it doesn't get re-used
00084         break; //matched the current data candidate, now move to the next
00085       }
00086 
00087       if( (j % GCT_OBJECT_QUANTA) + 1 == GCT_OBJECT_QUANTA) {
00088         errorFlag_hist_->Fill(1); //fill the errorflag histo in the unmatched data candidate bin
00089         mismatchD_Rank->Fill(data_->at(i).rank()); //fill the rank histogram of mismatched data candidates
00090         mismatchD_EtEtaPhi->Fill(data_->at(i).regionId().ieta(),data_->at(i).regionId().iphi(),data_->at(i).rank()); //fill the EtEtaPhi dist for mismatched candidates
00091         errorFlag=1; //set the errorFlag to true
00092       }
00093 
00094     }
00095   }
00096 
00097 //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
00098   for(i=0; i<matched.size(); i++) {
00099     //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
00100     //emulator candidates either have rank = 0 (which is good) or rank > 0 (which is bad)
00101     if(matched.at(i)) continue;
00102 
00103     //now loop over the emulator candidates
00104     for(j=0; j< emu_->size(); j++) {
00105       //check that the bx of the emulator candidates is the trigbx
00106       if(emu_->at(j).bx() != mbxparams_.EmuTrigBx) continue;
00107       
00108       //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
00109       if((j%GCT_OBJECT_QUANTA == i) && (emu_->at(j).rank()>0) ) {
00110         errorFlag_hist_->Fill(2); //increment emulator mismatched bin
00111         mismatchE_Rank->Fill(emu_->at(j).rank()); //fill the rank histogram for unmatched emulator
00112         mismatchE_EtEtaPhi->Fill(emu_->at(j).regionId().ieta(),emu_->at(j).regionId().iphi(),emu_->at(j).rank()); //fill EtEtaPhi for unmatched emu cands
00113         errorFlag=1; //set the errorFlag (if it's not already)
00114       }
00115     }
00116   }
00117 
00118   return errorFlag;
00119 }
00120 
00121 
00122 #endif