CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoMET/METAlgorithms/src/SignCaloSpecificAlgo.cc

Go to the documentation of this file.
00001 #include "DataFormats/Math/interface/LorentzVector.h"
00002 #include "RecoMET/METAlgorithms/interface/SignCaloSpecificAlgo.h"
00003 #include "DataFormats/CaloTowers/interface/CaloTowerDetId.h"
00004 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00005 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00006 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00007 #include "RecoMET/METAlgorithms/interface/SigInputObj.h"
00008 #include "RecoMET/METAlgorithms/interface/significanceAlgo.h"
00009 #include "RecoMET/METAlgorithms/interface/SignAlgoResolutions.h"
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 #include "DataFormats/CaloTowers/interface/CaloTowerFwd.h"
00012 
00013 #include <string>
00014 using namespace reco;
00015 using namespace std;
00016 // -*- C++ -*-
00017 //
00018 // Package:    METAlgorithms
00019 // Class:      SigInputObj
00020 // 
00035 //
00036 // Original Author:  Kyle Story, Freya Blekman (Cornell University)
00037 //         Created:  Fri Apr 18 11:58:33 CEST 2008
00038 // $Id: SignCaloSpecificAlgo.cc,v 1.9 2010/02/22 23:43:47 dlange Exp $
00039 //
00040 //
00041 
00042 SignCaloSpecificAlgo::SignCaloSpecificAlgo():
00043   significance_(0.),
00044   matrix_(2,2)
00045 {
00046   matrix_(0,0)=matrix_(1,0)=matrix_(0,1)=matrix_(1,1)=0.;
00047 }
00048 SignCaloSpecificAlgo::~SignCaloSpecificAlgo()
00049 {
00050 }
00051 
00052 void SignCaloSpecificAlgo::usePreviousSignif(const std::vector<double> &values)
00053 {
00054   if(values.size()!=4)
00055     return;
00056   matrix_(0,0)=values[0];
00057   matrix_(0,1)=values[1];
00058   matrix_(1,0)=values[2];
00059   matrix_(1,1)=values[3];
00060   return;
00061 }
00063 //
00064 // Convert a list of calo towers to objects that can be passed to the significance algo:
00065 
00066 std::vector<metsig::SigInputObj> 
00067 SignCaloSpecificAlgo::makeVectorOutOfCaloTowers(edm::Handle<edm::View<reco::Candidate> > towers, const::metsig::SignAlgoResolutions& resolutions, bool noHF, double globalThreshold)
00068 {
00069 
00070   edm::View<Candidate>::const_iterator towerCand = towers->begin();
00071   std::vector<metsig::SigInputObj> signInputVec;
00072   //iterate over all CaloTowers and record information
00073   for( ; towerCand != towers->end(); towerCand++ ) {
00074     const Candidate *candidate = &(*towerCand);
00075     if(candidate){
00076       const CaloTower * calotower = dynamic_cast<const CaloTower*> (candidate);
00077       if(calotower){
00078         double sign_tower_et = calotower->et();
00079         if(sign_tower_et<globalThreshold)
00080           continue;
00081         bool wasused=false;
00082         double sign_tower_phi = calotower->phi();
00083         double sign_tower_sigma_et = 0;
00084         double sign_tower_sigma_phi = 0;
00085         std::string sign_tower_type = "";
00086         
00087         bool hadIsDone = false;
00088         bool emIsDone = false;
00089         int cell = calotower->constituentsSize();
00090 
00091         while ( --cell >= 0 && (!hadIsDone || !emIsDone) ) 
00092           {
00093             DetId id = calotower->constituent( cell );
00094             if( !hadIsDone && id.det() == DetId::Hcal ) 
00095               {
00096                 HcalSubdetector subdet = HcalDetId(id).subdet();
00097                 if(subdet == HcalBarrel){
00098                   sign_tower_type = "hadcalotower";
00099                   sign_tower_et = calotower->hadEt();
00100                   sign_tower_sigma_et = resolutions.eval(metsig::caloHB,metsig::ET,sign_tower_et,calotower->phi(),calotower->eta());
00101                   sign_tower_sigma_phi = resolutions.eval(metsig::caloHB,metsig::PHI,sign_tower_et,calotower->phi(),calotower->eta());
00102                 }
00103                 else if(subdet==HcalOuter){
00104                   sign_tower_type = "hadcalotower";
00105                   sign_tower_et = calotower->outerEt();
00106                   sign_tower_sigma_et = resolutions.eval(metsig::caloHO,metsig::ET,sign_tower_et,calotower->phi(),calotower->eta());
00107                   sign_tower_sigma_phi = resolutions.eval(metsig::caloHO,metsig::PHI,sign_tower_et,calotower->phi(),calotower->eta());
00108                 }
00109                 else if(subdet==HcalEndcap){
00110                   sign_tower_type = "hadcalotower";
00111                   sign_tower_et = calotower->hadEt();
00112                   sign_tower_sigma_et = resolutions.eval(metsig::caloHE,metsig::ET,sign_tower_et,calotower->phi(),calotower->eta());
00113                   sign_tower_sigma_phi = resolutions.eval(metsig::caloHE,metsig::PHI,sign_tower_et,calotower->phi(),calotower->eta());
00114                 }
00115                 else if(subdet == HcalForward){
00116                   sign_tower_type = "hadcalotower";
00117                   sign_tower_et = calotower->et();
00118                   sign_tower_sigma_et = resolutions.eval(metsig::caloHF,metsig::ET,sign_tower_et,calotower->phi(),calotower->eta());
00119                   sign_tower_sigma_phi = resolutions.eval(metsig::caloHF,metsig::PHI,sign_tower_et,calotower->phi(),calotower->eta());
00120                 }
00121                 else{
00122                   edm::LogWarning("SignCaloSpecificAlgo") << " HCAL tower cell not assigned to an HCAL subdetector!!!" << std::endl;
00123                 }
00124                 // and book!
00125                 metsig::SigInputObj temp(sign_tower_type,sign_tower_et,sign_tower_phi,sign_tower_sigma_et,sign_tower_sigma_phi);
00126                 if(!noHF || subdet !=HcalForward)
00127                   signInputVec.push_back(temp);
00128                 
00129                 wasused=1;
00130                 hadIsDone = true;
00131               }
00132             else if( !emIsDone && id.det() == DetId::Ecal )
00133               {
00134                 EcalSubdetector subdet = EcalSubdetector( id.subdetId() );
00135                 
00136                 if(subdet == EcalBarrel){
00137                   sign_tower_type = "emcalotower";
00138                   sign_tower_et = calotower->emEt();
00139                   sign_tower_sigma_et = resolutions.eval(metsig::caloEB,metsig::ET,sign_tower_et,calotower->phi(),calotower->eta());
00140                   sign_tower_sigma_phi = resolutions.eval(metsig::caloEB,metsig::PHI,sign_tower_et,calotower->phi(),calotower->eta());
00141                 }
00142                 else if(subdet == EcalEndcap ){
00143                   sign_tower_type = "emcalotower";
00144                   sign_tower_et = calotower->emEt();
00145                   sign_tower_sigma_et = resolutions.eval(metsig::caloEE,metsig::ET,sign_tower_et,calotower->phi(),calotower->eta());
00146                   sign_tower_sigma_phi = resolutions.eval(metsig::caloEE,metsig::PHI,sign_tower_et,calotower->phi(),calotower->eta());
00147                     
00148                 }
00149                 else{
00150                   edm::LogWarning("SignCaloSpecificAlgo") << " ECAL tower cell not assigned to an ECAL subdetector!!!" << std::endl;
00151                 }
00152                 metsig::SigInputObj temp(sign_tower_type,sign_tower_et,sign_tower_phi,sign_tower_sigma_et,sign_tower_sigma_phi);
00153                 signInputVec.push_back(temp);
00154                 wasused=1;
00155                 emIsDone = true;
00156               }
00157           }
00158         if(wasused==0)
00159           edm::LogWarning("SignCaloSpecificAlgo") << "found non-assigned cell, " << std::endl;
00160       }
00161     }
00162   }
00163   return signInputVec;
00164 }
00166 //
00167 // Basic MET algorithm. gets towers, does sum. Very similar to standard MET.
00168 void SignCaloSpecificAlgo::calculateBaseCaloMET(edm::Handle<edm::View<reco::Candidate> > towers, CommonMETData met,const metsig::SignAlgoResolutions& resolutions, bool noHF, double globalThreshold)
00169 { 
00170 
00171   //retreive calo tower information from candidates
00172   //start with the first element of the candidate list
00173 
00174   
00175 
00176   // use this container to calculate the significance. SigInputObj are objects that contain both directional and uncertainty information and are used as input to the significance calculation
00177 
00178   std::vector<metsig::SigInputObj> signInputVec = makeVectorOutOfCaloTowers(towers, resolutions, noHF, globalThreshold);
00179   
00180   // now run the significance algorithm.
00181   
00182   double sign_calo_met_total=0;
00183   double sign_calo_met_phi=0;
00184   double sign_calo_met_set=0;
00185   metsig::significanceAlgo signifalgo;
00186   // check the caloMET, if significance was already run continue with the matrix that is stored..
00187   signifalgo.addSignifMatrix(matrix_);
00188   signifalgo.addObjects(signInputVec);
00189   matrix_=signifalgo.getSignifMatrix();
00190   significance_ = signifalgo.significance( sign_calo_met_total, sign_calo_met_phi, sign_calo_met_set);
00191   // cleanup everything:
00192   signInputVec.clear();
00193   // and return
00194 }
00195 
00196 //-------------------------------------------------------------------------