CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/RecoLocalCalo/CaloTowersCreator/src/CaloTowersCreator.cc

Go to the documentation of this file.
00001 #include "RecoLocalCalo/CaloTowersCreator/src/CaloTowersCreator.h"
00002 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00003 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 #include "RecoLocalCalo/CaloTowersCreator/interface/EScales.h"
00006 #include "Geometry/CaloTopology/interface/HcalTopology.h"
00007 // severity level for ECAL
00008 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h"
00009 #include "CommonTools/Utils/interface/StringToEnumValue.h"
00010 
00011 const std::vector<double>& 
00012 CaloTowersCreator::getGridValues()
00013 {
00014   static std::vector<double> retval;
00015   
00016   if (retval.size() == 0)
00017     {
00018       retval.push_back(0.);
00019       retval.push_back(10.);
00020       retval.push_back(20.);
00021       retval.push_back(30.);
00022       retval.push_back(40.);
00023       retval.push_back(50.);
00024       retval.push_back(100.);
00025       retval.push_back(1000.); 
00026     }
00027 
00028   return retval;
00029 }
00030 
00031 
00032 CaloTowersCreator::CaloTowersCreator(const edm::ParameterSet& conf) : 
00033   algo_(conf.getParameter<double>("EBThreshold"),
00034               conf.getParameter<double>("EEThreshold"),
00035 
00036         conf.getParameter<bool>("UseEtEBTreshold"),
00037         conf.getParameter<bool>("UseEtEETreshold"),
00038         conf.getParameter<bool>("UseSymEBTreshold"),
00039         conf.getParameter<bool>("UseSymEETreshold"),
00040 
00041 
00042               conf.getParameter<double>("HcalThreshold"),
00043               conf.getParameter<double>("HBThreshold"),
00044               conf.getParameter<double>("HESThreshold"),
00045               conf.getParameter<double>("HEDThreshold"),
00046         conf.getParameter<double>("HOThreshold0"),
00047         conf.getParameter<double>("HOThresholdPlus1"),
00048         conf.getParameter<double>("HOThresholdMinus1"),
00049         conf.getParameter<double>("HOThresholdPlus2"),
00050         conf.getParameter<double>("HOThresholdMinus2"),
00051               conf.getParameter<double>("HF1Threshold"),
00052               conf.getParameter<double>("HF2Threshold"),
00053         conf.getParameter<std::vector<double> >("EBGrid"),
00054         conf.getParameter<std::vector<double> >("EBWeights"),
00055         conf.getParameter<std::vector<double> >("EEGrid"),
00056         conf.getParameter<std::vector<double> >("EEWeights"),
00057         conf.getParameter<std::vector<double> >("HBGrid"),
00058         conf.getParameter<std::vector<double> >("HBWeights"),
00059         conf.getParameter<std::vector<double> >("HESGrid"),
00060         conf.getParameter<std::vector<double> >("HESWeights"),
00061         conf.getParameter<std::vector<double> >("HEDGrid"),
00062         conf.getParameter<std::vector<double> >("HEDWeights"),
00063         conf.getParameter<std::vector<double> >("HOGrid"),
00064         conf.getParameter<std::vector<double> >("HOWeights"),
00065         conf.getParameter<std::vector<double> >("HF1Grid"),
00066         conf.getParameter<std::vector<double> >("HF1Weights"),
00067         conf.getParameter<std::vector<double> >("HF2Grid"),
00068         conf.getParameter<std::vector<double> >("HF2Weights"),
00069               conf.getParameter<double>("EBWeight"),
00070               conf.getParameter<double>("EEWeight"),
00071               conf.getParameter<double>("HBWeight"),
00072               conf.getParameter<double>("HESWeight"),
00073               conf.getParameter<double>("HEDWeight"),
00074               conf.getParameter<double>("HOWeight"),
00075               conf.getParameter<double>("HF1Weight"),
00076               conf.getParameter<double>("HF2Weight"),
00077               conf.getParameter<double>("EcutTower"),
00078               conf.getParameter<double>("EBSumThreshold"),
00079               conf.getParameter<double>("EESumThreshold"),
00080               conf.getParameter<bool>("UseHO"),
00081          // (for momentum reconstruction algorithm)
00082         conf.getParameter<int>("MomConstrMethod"),
00083         conf.getParameter<double>("MomHBDepth"),
00084         conf.getParameter<double>("MomHEDepth"),
00085         conf.getParameter<double>("MomEBDepth"),
00086         conf.getParameter<double>("MomEEDepth")
00087         ),
00088 
00089   hbheLabel_(conf.getParameter<edm::InputTag>("hbheInput")),
00090   hoLabel_(conf.getParameter<edm::InputTag>("hoInput")),
00091   hfLabel_(conf.getParameter<edm::InputTag>("hfInput")),
00092   ecalLabels_(conf.getParameter<std::vector<edm::InputTag> >("ecalInputs")),
00093   allowMissingInputs_(conf.getParameter<bool>("AllowMissingInputs")),
00094 
00095   theHcalAcceptSeverityLevel_(conf.getParameter<unsigned int>("HcalAcceptSeverityLevel")),
00096 
00097   theRecoveredHcalHitsAreUsed_(conf.getParameter<bool>("UseHcalRecoveredHits")),
00098   theRecoveredEcalHitsAreUsed_(conf.getParameter<bool>("UseEcalRecoveredHits")),
00099 
00100   // paramaters controlling the use of rejected hits
00101 
00102   useRejectedHitsOnly_(conf.getParameter<bool>("UseRejectedHitsOnly")),
00103 
00104   theHcalAcceptSeverityLevelForRejectedHit_(conf.getParameter<unsigned int>("HcalAcceptSeverityLevelForRejectedHit")),
00105 
00106 
00107   useRejectedRecoveredHcalHits_(conf.getParameter<bool>("UseRejectedRecoveredHcalHits")),
00108   useRejectedRecoveredEcalHits_(conf.getParameter<bool>("UseRejectedRecoveredEcalHits"))
00109 
00110 
00111 
00112 {
00113   EBEScale=EScales.EBScale; 
00114   EEEScale=EScales.EEScale; 
00115   HBEScale=EScales.HBScale; 
00116   HESEScale=EScales.HESScale; 
00117   HEDEScale=EScales.HEDScale; 
00118   HOEScale=EScales.HOScale; 
00119   HF1EScale=EScales.HF1Scale; 
00120   HF2EScale=EScales.HF2Scale; 
00121 
00122   // get the Ecal severities to be excluded
00123   const std::vector<std::string> severitynames = 
00124     conf.getParameter<std::vector<std::string> >("EcalRecHitSeveritiesToBeExcluded");
00125 
00126    theEcalSeveritiesToBeExcluded_ =  StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynames);
00127 
00128   // get the Ecal severities to be used for bad towers
00129    theEcalSeveritiesToBeUsedInBadTowers_ =  
00130      StringToEnumValue<EcalSeverityLevel::SeverityLevel>(conf.getParameter<std::vector<std::string> >("EcalSeveritiesToBeUsedInBadTowers") );
00131 
00132   if (EScales.instanceLabel=="") produces<CaloTowerCollection>();
00133   else produces<CaloTowerCollection>(EScales.instanceLabel);
00134 }
00135 
00136 void CaloTowersCreator::produce(edm::Event& e, const edm::EventSetup& c) {
00137   // get the necessary event setup objects...
00138   edm::ESHandle<CaloGeometry> pG;
00139   edm::ESHandle<HcalTopology> htopo;
00140   edm::ESHandle<CaloTowerConstituentsMap> cttopo;
00141   c.get<CaloGeometryRecord>().get(pG);
00142   c.get<IdealGeometryRecord>().get(htopo);
00143   c.get<IdealGeometryRecord>().get(cttopo);
00144  
00145   // ECAL channel status map ****************************************
00146   edm::ESHandle<EcalChannelStatus> ecalChStatus;
00147   c.get<EcalChannelStatusRcd>().get( ecalChStatus );
00148   const EcalChannelStatus* dbEcalChStatus = ecalChStatus.product();
00149  
00150   // HCAL channel status map ****************************************
00151   edm::ESHandle<HcalChannelQuality> hcalChStatus;    
00152   c.get<HcalChannelQualityRcd>().get( hcalChStatus );
00153   const HcalChannelQuality* dbHcalChStatus = hcalChStatus.product();
00154  
00155   // Assignment of severity levels **********************************
00156   edm::ESHandle<HcalSeverityLevelComputer> hcalSevLvlComputerHndl;
00157   c.get<HcalSeverityLevelComputerRcd>().get(hcalSevLvlComputerHndl);
00158   const HcalSeverityLevelComputer* hcalSevLvlComputer = hcalSevLvlComputerHndl.product();
00159 
00160   edm::ESHandle<EcalSeverityLevelAlgo> ecalSevLvlAlgoHndl;
00161   c.get<EcalSeverityLevelAlgoRcd>().get(ecalSevLvlAlgoHndl);
00162   const EcalSeverityLevelAlgo* ecalSevLvlAlgo = ecalSevLvlAlgoHndl.product();
00163 
00164   
00165   algo_.setEBEScale(EBEScale);
00166   algo_.setEEEScale(EEEScale);
00167   algo_.setHBEScale(HBEScale);
00168   algo_.setHESEScale(HESEScale);
00169   algo_.setHEDEScale(HEDEScale);
00170   algo_.setHOEScale(HOEScale);
00171   algo_.setHF1EScale(HF1EScale);
00172   algo_.setHF2EScale(HF2EScale);
00173   algo_.setGeometry(cttopo.product(),htopo.product(),pG.product());
00174 
00175   // for treatment of problematic and anomalous cells
00176 
00177   algo_.setHcalChStatusFromDB(dbHcalChStatus);
00178   algo_.setEcalChStatusFromDB(dbEcalChStatus);
00179    
00180   algo_.setHcalAcceptSeverityLevel(theHcalAcceptSeverityLevel_);
00181   algo_.setEcalSeveritiesToBeExcluded(theEcalSeveritiesToBeExcluded_);
00182 
00183   algo_.setRecoveredHcalHitsAreUsed(theRecoveredHcalHitsAreUsed_);
00184   algo_.setRecoveredEcalHitsAreUsed(theRecoveredEcalHitsAreUsed_);
00185 
00186   algo_.setHcalSevLvlComputer(hcalSevLvlComputer);
00187   algo_.setEcalSevLvlAlgo(ecalSevLvlAlgo);
00188 
00189 
00190   algo_.setUseRejectedHitsOnly(useRejectedHitsOnly_);
00191 
00192   algo_.setHcalAcceptSeverityLevelForRejectedHit(theHcalAcceptSeverityLevelForRejectedHit_);
00193   algo_.SetEcalSeveritiesToBeUsedInBadTowers (theEcalSeveritiesToBeUsedInBadTowers_);
00194 
00195   algo_.setUseRejectedRecoveredHcalHits(useRejectedRecoveredHcalHits_);
00196   algo_.setUseRejectedRecoveredEcalHits(useRejectedRecoveredEcalHits_);
00197 
00198 
00199 
00200 
00201 
00202   algo_.begin(); // clear the internal buffer
00203 
00204   // can't chain these in a big OR statement, or else it'll
00205   // get triggered for each of the first three events
00206   bool check1 = hcalSevLevelWatcher_.check(c);
00207   bool check2 = hcalChStatusWatcher_.check(c);
00208   bool check3 = caloTowerConstituentsWatcher_.check(c);
00209   if(check1 || check2 || check3)
00210   {
00211     algo_.makeHcalDropChMap();
00212   }
00213 
00214   // ----------------------------------------------------------
00215   // For ecal error handling need to 
00216   // have access to the EB and EE collections at the end of 
00217   // tower reconstruction.
00218 
00219   edm::Handle<EcalRecHitCollection> ebHandle;
00220   edm::Handle<EcalRecHitCollection> eeHandle;
00221 
00222   for (std::vector<edm::InputTag>::const_iterator i=ecalLabels_.begin(); 
00223        i!=ecalLabels_.end(); i++) {
00224     
00225     edm::Handle<EcalRecHitCollection> ec_tmp;
00226     
00227     if (! e.getByLabel(*i,ec_tmp) ) continue;
00228     if (ec_tmp->size()==0) continue;
00229 
00230     // check if this is EB or EE
00231     if ( (ec_tmp->begin()->detid()).subdetId() == EcalBarrel ) {
00232       ebHandle = ec_tmp;
00233     }
00234     else if ((ec_tmp->begin()->detid()).subdetId() == EcalEndcap ) {
00235       eeHandle = ec_tmp;
00236     }
00237 
00238   }
00239 
00240   algo_.setEbHandle(ebHandle);
00241   algo_.setEeHandle(eeHandle);
00242 
00243   //-----------------------------------------------------------
00244 
00245 
00246 
00247   bool present;
00248 
00249   // Step A/C: Get Inputs and process (repeatedly)
00250   edm::Handle<HBHERecHitCollection> hbhe;
00251   present=e.getByLabel(hbheLabel_,hbhe);
00252   if (present || !allowMissingInputs_)  algo_.process(*hbhe);
00253 
00254   edm::Handle<HORecHitCollection> ho;
00255   present=e.getByLabel(hoLabel_,ho);
00256   if (present || !allowMissingInputs_) algo_.process(*ho);
00257 
00258   edm::Handle<HFRecHitCollection> hf;
00259   present=e.getByLabel(hfLabel_,hf);
00260   if (present || !allowMissingInputs_) algo_.process(*hf);
00261 
00262   std::vector<edm::InputTag>::const_iterator i;
00263   for (i=ecalLabels_.begin(); i!=ecalLabels_.end(); i++) {
00264     edm::Handle<EcalRecHitCollection> ec;
00265     present=e.getByLabel(*i,ec);
00266     if (present || !allowMissingInputs_) algo_.process(*ec);
00267   }
00268 
00269   // Step B: Create empty output
00270   std::auto_ptr<CaloTowerCollection> prod(new CaloTowerCollection());
00271 
00272   // Step C: Process
00273   algo_.finish(*prod);
00274 
00275   // Step D: Put into the event
00276   if (EScales.instanceLabel=="") e.put(prod);
00277   else e.put(prod,EScales.instanceLabel);
00278 
00279 
00280 }
00281