00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "RecoMET/METAlgorithms/interface/SignCaloSpecificAlgo.h"
00014 #include "RecoMET/METAlgorithms/interface/significanceAlgo.h"
00015 #include "RecoMET/METAlgorithms/interface/SignAlgoResolutions.h"
00016 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00017 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019
00020 #include <string>
00021
00022 using namespace reco;
00023 using namespace std;
00024
00025
00026 SignCaloSpecificAlgo::SignCaloSpecificAlgo():
00027 significance_(0.),
00028 matrix_(2,2)
00029 {
00030 matrix_(0,0)=matrix_(1,0)=matrix_(0,1)=matrix_(1,1)=0.;
00031 }
00032 SignCaloSpecificAlgo::~SignCaloSpecificAlgo()
00033 {
00034 }
00035
00036 void SignCaloSpecificAlgo::usePreviousSignif(const std::vector<double> &values)
00037 {
00038 if(values.size()!=4)
00039 return;
00040 matrix_(0,0)=values[0];
00041 matrix_(0,1)=values[1];
00042 matrix_(1,0)=values[2];
00043 matrix_(1,1)=values[3];
00044 return;
00045 }
00047
00048
00049
00050 std::vector<metsig::SigInputObj>
00051 SignCaloSpecificAlgo::makeVectorOutOfCaloTowers(edm::Handle<edm::View<reco::Candidate> > towers, const::metsig::SignAlgoResolutions& resolutions, bool noHF, double globalThreshold)
00052 {
00053
00054 edm::View<Candidate>::const_iterator towerCand = towers->begin();
00055 std::vector<metsig::SigInputObj> signInputVec;
00056
00057 for( ; towerCand != towers->end(); towerCand++ ) {
00058 const Candidate *candidate = &(*towerCand);
00059 if(candidate){
00060 const CaloTower * calotower = dynamic_cast<const CaloTower*> (candidate);
00061 if(calotower){
00062 double sign_tower_et = calotower->et();
00063 if(sign_tower_et<globalThreshold)
00064 continue;
00065 bool wasused=false;
00066 double sign_tower_phi = calotower->phi();
00067 double sign_tower_sigma_et = 0;
00068 double sign_tower_sigma_phi = 0;
00069 std::string sign_tower_type = "";
00070
00071 bool hadIsDone = false;
00072 bool emIsDone = false;
00073 int cell = calotower->constituentsSize();
00074
00075 while ( --cell >= 0 && (!hadIsDone || !emIsDone) )
00076 {
00077 DetId id = calotower->constituent( cell );
00078 if( !hadIsDone && id.det() == DetId::Hcal )
00079 {
00080 HcalSubdetector subdet = HcalDetId(id).subdet();
00081 if(subdet == HcalBarrel){
00082 sign_tower_type = "hadcalotower";
00083 sign_tower_et = calotower->hadEt();
00084 sign_tower_sigma_et = resolutions.eval(metsig::caloHB,metsig::ET,sign_tower_et,calotower->phi(),calotower->eta());
00085 sign_tower_sigma_phi = resolutions.eval(metsig::caloHB,metsig::PHI,sign_tower_et,calotower->phi(),calotower->eta());
00086 }
00087 else if(subdet==HcalOuter){
00088 sign_tower_type = "hadcalotower";
00089 sign_tower_et = calotower->outerEt();
00090 sign_tower_sigma_et = resolutions.eval(metsig::caloHO,metsig::ET,sign_tower_et,calotower->phi(),calotower->eta());
00091 sign_tower_sigma_phi = resolutions.eval(metsig::caloHO,metsig::PHI,sign_tower_et,calotower->phi(),calotower->eta());
00092 }
00093 else if(subdet==HcalEndcap){
00094 sign_tower_type = "hadcalotower";
00095 sign_tower_et = calotower->hadEt();
00096 sign_tower_sigma_et = resolutions.eval(metsig::caloHE,metsig::ET,sign_tower_et,calotower->phi(),calotower->eta());
00097 sign_tower_sigma_phi = resolutions.eval(metsig::caloHE,metsig::PHI,sign_tower_et,calotower->phi(),calotower->eta());
00098 }
00099 else if(subdet == HcalForward){
00100 sign_tower_type = "hadcalotower";
00101 sign_tower_et = calotower->et();
00102 sign_tower_sigma_et = resolutions.eval(metsig::caloHF,metsig::ET,sign_tower_et,calotower->phi(),calotower->eta());
00103 sign_tower_sigma_phi = resolutions.eval(metsig::caloHF,metsig::PHI,sign_tower_et,calotower->phi(),calotower->eta());
00104 }
00105 else{
00106 edm::LogWarning("SignCaloSpecificAlgo") << " HCAL tower cell not assigned to an HCAL subdetector!!!" << std::endl;
00107 }
00108
00109 metsig::SigInputObj temp(sign_tower_type,sign_tower_et,sign_tower_phi,sign_tower_sigma_et,sign_tower_sigma_phi);
00110 if(!noHF || subdet !=HcalForward)
00111 signInputVec.push_back(temp);
00112
00113 wasused=1;
00114 hadIsDone = true;
00115 }
00116 else if( !emIsDone && id.det() == DetId::Ecal )
00117 {
00118 EcalSubdetector subdet = EcalSubdetector( id.subdetId() );
00119
00120 if(subdet == EcalBarrel){
00121 sign_tower_type = "emcalotower";
00122 sign_tower_et = calotower->emEt();
00123 sign_tower_sigma_et = resolutions.eval(metsig::caloEB,metsig::ET,sign_tower_et,calotower->phi(),calotower->eta());
00124 sign_tower_sigma_phi = resolutions.eval(metsig::caloEB,metsig::PHI,sign_tower_et,calotower->phi(),calotower->eta());
00125 }
00126 else if(subdet == EcalEndcap ){
00127 sign_tower_type = "emcalotower";
00128 sign_tower_et = calotower->emEt();
00129 sign_tower_sigma_et = resolutions.eval(metsig::caloEE,metsig::ET,sign_tower_et,calotower->phi(),calotower->eta());
00130 sign_tower_sigma_phi = resolutions.eval(metsig::caloEE,metsig::PHI,sign_tower_et,calotower->phi(),calotower->eta());
00131
00132 }
00133 else{
00134 edm::LogWarning("SignCaloSpecificAlgo") << " ECAL tower cell not assigned to an ECAL subdetector!!!" << std::endl;
00135 }
00136 metsig::SigInputObj temp(sign_tower_type,sign_tower_et,sign_tower_phi,sign_tower_sigma_et,sign_tower_sigma_phi);
00137 signInputVec.push_back(temp);
00138 wasused=1;
00139 emIsDone = true;
00140 }
00141 }
00142 if(wasused==0)
00143 edm::LogWarning("SignCaloSpecificAlgo") << "found non-assigned cell, " << std::endl;
00144 }
00145 }
00146 }
00147 return signInputVec;
00148 }
00150
00151
00152 void SignCaloSpecificAlgo::calculateBaseCaloMET(edm::Handle<edm::View<reco::Candidate> > towers, CommonMETData met,const metsig::SignAlgoResolutions& resolutions, bool noHF, double globalThreshold)
00153 {
00154
00155
00156
00157
00158
00159
00160
00161
00162 std::vector<metsig::SigInputObj> signInputVec = makeVectorOutOfCaloTowers(towers, resolutions, noHF, globalThreshold);
00163
00164
00165
00166 double sign_calo_met_total=0;
00167 double sign_calo_met_phi=0;
00168 double sign_calo_met_set=0;
00169 metsig::significanceAlgo signifalgo;
00170
00171 signifalgo.addSignifMatrix(matrix_);
00172 signifalgo.addObjects(signInputVec);
00173 matrix_=signifalgo.getSignifMatrix();
00174 significance_ = signifalgo.significance( sign_calo_met_total, sign_calo_met_phi, sign_calo_met_set);
00175
00176 signInputVec.clear();
00177
00178 }
00179
00180