CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/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   if (!dbHcalChStatus->topo()) dbHcalChStatus->setTopo(htopo.product());
00156 
00157   // Assignment of severity levels **********************************
00158   edm::ESHandle<HcalSeverityLevelComputer> hcalSevLvlComputerHndl;
00159   c.get<HcalSeverityLevelComputerRcd>().get(hcalSevLvlComputerHndl);
00160   const HcalSeverityLevelComputer* hcalSevLvlComputer = hcalSevLvlComputerHndl.product();
00161 
00162   edm::ESHandle<EcalSeverityLevelAlgo> ecalSevLvlAlgoHndl;
00163   c.get<EcalSeverityLevelAlgoRcd>().get(ecalSevLvlAlgoHndl);
00164   const EcalSeverityLevelAlgo* ecalSevLvlAlgo = ecalSevLvlAlgoHndl.product();
00165 
00166   
00167   algo_.setEBEScale(EBEScale);
00168   algo_.setEEEScale(EEEScale);
00169   algo_.setHBEScale(HBEScale);
00170   algo_.setHESEScale(HESEScale);
00171   algo_.setHEDEScale(HEDEScale);
00172   algo_.setHOEScale(HOEScale);
00173   algo_.setHF1EScale(HF1EScale);
00174   algo_.setHF2EScale(HF2EScale);
00175   algo_.setGeometry(cttopo.product(),htopo.product(),pG.product());
00176 
00177   // for treatment of problematic and anomalous cells
00178 
00179   algo_.setHcalChStatusFromDB(dbHcalChStatus);
00180   algo_.setEcalChStatusFromDB(dbEcalChStatus);
00181    
00182   algo_.setHcalAcceptSeverityLevel(theHcalAcceptSeverityLevel_);
00183   algo_.setEcalSeveritiesToBeExcluded(theEcalSeveritiesToBeExcluded_);
00184 
00185   algo_.setRecoveredHcalHitsAreUsed(theRecoveredHcalHitsAreUsed_);
00186   algo_.setRecoveredEcalHitsAreUsed(theRecoveredEcalHitsAreUsed_);
00187 
00188   algo_.setHcalSevLvlComputer(hcalSevLvlComputer);
00189   algo_.setEcalSevLvlAlgo(ecalSevLvlAlgo);
00190 
00191 
00192   algo_.setUseRejectedHitsOnly(useRejectedHitsOnly_);
00193 
00194   algo_.setHcalAcceptSeverityLevelForRejectedHit(theHcalAcceptSeverityLevelForRejectedHit_);
00195   algo_.SetEcalSeveritiesToBeUsedInBadTowers (theEcalSeveritiesToBeUsedInBadTowers_);
00196 
00197   algo_.setUseRejectedRecoveredHcalHits(useRejectedRecoveredHcalHits_);
00198   algo_.setUseRejectedRecoveredEcalHits(useRejectedRecoveredEcalHits_);
00199 
00200 
00201 
00202 
00203 
00204   algo_.begin(); // clear the internal buffer
00205 
00206   // can't chain these in a big OR statement, or else it'll
00207   // get triggered for each of the first three events
00208   bool check1 = hcalSevLevelWatcher_.check(c);
00209   bool check2 = hcalChStatusWatcher_.check(c);
00210   bool check3 = caloTowerConstituentsWatcher_.check(c);
00211   if(check1 || check2 || check3)
00212   {
00213     algo_.makeHcalDropChMap();
00214   }
00215 
00216   // ----------------------------------------------------------
00217   // For ecal error handling need to 
00218   // have access to the EB and EE collections at the end of 
00219   // tower reconstruction.
00220 
00221   edm::Handle<EcalRecHitCollection> ebHandle;
00222   edm::Handle<EcalRecHitCollection> eeHandle;
00223 
00224   for (std::vector<edm::InputTag>::const_iterator i=ecalLabels_.begin(); 
00225        i!=ecalLabels_.end(); i++) {
00226     
00227     edm::Handle<EcalRecHitCollection> ec_tmp;
00228     
00229     if (! e.getByLabel(*i,ec_tmp) ) continue;
00230     if (ec_tmp->size()==0) continue;
00231 
00232     // check if this is EB or EE
00233     if ( (ec_tmp->begin()->detid()).subdetId() == EcalBarrel ) {
00234       ebHandle = ec_tmp;
00235     }
00236     else if ((ec_tmp->begin()->detid()).subdetId() == EcalEndcap ) {
00237       eeHandle = ec_tmp;
00238     }
00239 
00240   }
00241 
00242   algo_.setEbHandle(ebHandle);
00243   algo_.setEeHandle(eeHandle);
00244 
00245   //-----------------------------------------------------------
00246 
00247 
00248 
00249   bool present;
00250 
00251   // Step A/C: Get Inputs and process (repeatedly)
00252   edm::Handle<HBHERecHitCollection> hbhe;
00253   present=e.getByLabel(hbheLabel_,hbhe);
00254   if (present || !allowMissingInputs_)  algo_.process(*hbhe);
00255 
00256   edm::Handle<HORecHitCollection> ho;
00257   present=e.getByLabel(hoLabel_,ho);
00258   if (present || !allowMissingInputs_) algo_.process(*ho);
00259 
00260   edm::Handle<HFRecHitCollection> hf;
00261   present=e.getByLabel(hfLabel_,hf);
00262   if (present || !allowMissingInputs_) algo_.process(*hf);
00263 
00264   std::vector<edm::InputTag>::const_iterator i;
00265   for (i=ecalLabels_.begin(); i!=ecalLabels_.end(); i++) {
00266     edm::Handle<EcalRecHitCollection> ec;
00267     present=e.getByLabel(*i,ec);
00268     if (present || !allowMissingInputs_) algo_.process(*ec);
00269   }
00270 
00271   // Step B: Create empty output
00272   std::auto_ptr<CaloTowerCollection> prod(new CaloTowerCollection());
00273 
00274   // Step C: Process
00275   algo_.finish(*prod);
00276 
00277   // Step D: Put into the event
00278   if (EScales.instanceLabel=="") e.put(prod);
00279   else e.put(prod,EScales.instanceLabel);
00280 
00281 
00282 }
00283