CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/RecoLocalCalo/CaloTowersCreator/interface/CaloTowersCreationAlgo.h

Go to the documentation of this file.
00001 #ifndef RECOLOCALCALO_CALOTOWERSCREATOR_CALOTOWERSCREATIONALGO_H
00002 #define RECOLOCALCALO_CALOTOWERSCREATOR_CALOTOWERSCREATIONALGO_H 1
00003 
00004 #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
00005 #include "DataFormats/CaloTowers/interface/CaloTowerDetId.h"
00006 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00007 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00008 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00009 
00010 // channel status
00011 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
00012 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
00013 
00014 #include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
00015 #include "CondFormats/DataRecord/interface/HcalChannelQualityRcd.h"
00016 
00017 // severity level assignment for HCAL
00018 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputer.h"
00019 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputerRcd.h"
00020 
00021 // severity level assignment for ECAL
00022 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"
00023 
00024 // need if we want to store the handles
00025 #include "FWCore/Framework/interface/ESHandle.h"
00026 
00027 
00028 #include <map>
00029 class HcalTopology;
00030 class CaloGeometry;
00031 class CaloSubdetectorGeometry;
00032 class CaloTowerConstituentsMap;
00033 class CaloRecHit;
00034 class DetId;
00035 
00043 //
00044 // Modify MetaTower to save energy of rechits for use in tower 4-momentum assignment,
00045 // added containers for timing assignment and for holding status information.
00046 // Anton Anastassov (Northwestern)
00047 //
00048 
00049 class CaloTowersCreationAlgo {
00050 public:
00051   CaloTowersCreationAlgo();
00052 
00053   CaloTowersCreationAlgo(double EBthreshold, double EEthreshold, 
00054 
00055     bool useEtEBTreshold, bool useEtEETreshold,
00056     bool useSymEBTreshold, bool useSymEETreshold,                                   
00057 
00058     double HcalThreshold,
00059     double HBthreshold, double HESthreshold, double HEDthreshold,
00060     double HOthreshold0, double HOthresholdPlus1, double HOthresholdMinus1,  
00061     double HOthresholdPlus2, double HOthresholdMinus2,
00062     double HF1threshold, double HF2threshold, 
00063     double EBweight, double EEweight,
00064     double HBweight, double HESweight, double HEDweight, 
00065     double HOweight, double HF1weight, double HF2weight,
00066     double EcutTower, double EBSumThreshold, double EESumThreshold, bool useHO,
00067     // (for momentum reconstruction algorithm)
00068     int momConstrMethod,
00069     double momHBDepth,
00070     double momHEDepth,
00071     double momEBDepth,
00072     double momEEDepth
00073     );
00074   
00075   CaloTowersCreationAlgo(double EBthreshold, double EEthreshold, 
00076 
00077     bool useEtEBTreshold, bool useEtEETreshold,
00078     bool useSymEBTreshold, bool useSymEETreshold,
00079 
00080     double HcalThreshold,
00081     double HBthreshold, double HESthreshold, double HEDthreshold,
00082     double HOthreshold0, double HOthresholdPlus1, double HOthresholdMinus1,  
00083     double HOthresholdPlus2, double HOthresholdMinus2, 
00084     double HF1threshold, double HF2threshold,
00085     const std::vector<double> & EBGrid, const std::vector<double> & EBWeights,
00086     const std::vector<double> & EEGrid, const std::vector<double> & EEWeights,
00087     const std::vector<double> & HBGrid, const std::vector<double> & HBWeights,
00088     const std::vector<double> & HESGrid, const std::vector<double> & HESWeights,
00089     const std::vector<double> & HEDGrid, const std::vector<double> & HEDWeights,
00090     const std::vector<double> & HOGrid, const std::vector<double> & HOWeights,
00091     const std::vector<double> & HF1Grid, const std::vector<double> & HF1Weights,
00092     const std::vector<double> & HF2Grid, const std::vector<double> & HF2Weights,
00093     double EBweight, double EEweight,
00094     double HBweight, double HESweight, double HEDweight, 
00095     double HOweight, double HF1weight, double HF2weight,
00096     double EcutTower, double EBSumThreshold, double EESumThreshold, bool useHO,
00097     // (for momentum reconstruction algorithm)
00098     int momConstrMethod,
00099     double momHBDepth,
00100     double momHEDepth,
00101     double momEBDepth,
00102     double momEEDepth
00103 );
00104   
00105   void setGeometry(const CaloTowerConstituentsMap* cttopo, const HcalTopology* htopo, const CaloGeometry* geo);
00106 
00107   // pass the containers of channels status from the event record (stored in DB)
00108   // these are called in  CaloTowersCreator
00109   void setHcalChStatusFromDB(const HcalChannelQuality* s) { theHcalChStatus = s; }
00110   void setEcalChStatusFromDB(const EcalChannelStatus* s) { theEcalChStatus = s; }
00111 
00112   // Kake a map of number of channels not used in RecHit production.
00113   // The key is the calotower id.
00114   void makeHcalDropChMap();
00115 
00116   void begin();
00117   void process(const HBHERecHitCollection& hbhe);
00118   void process(const HORecHitCollection& ho);
00119   void process(const HFRecHitCollection& hf); 
00120   void process(const EcalRecHitCollection& ecal); 
00121   
00122   
00123   void process(const CaloTowerCollection& ctc);
00124 
00125   void finish(CaloTowerCollection& destCollection);
00126 
00127   // modified rescale method
00128   void rescaleTowers(const CaloTowerCollection& ctInput, CaloTowerCollection& ctResult);
00129 
00130   void setEBEScale(double scale);
00131   void setEEEScale(double scale);
00132   void setHBEScale(double scale);
00133   void setHESEScale(double scale);
00134   void setHEDEScale(double scale);
00135   void setHOEScale(double scale);
00136   void setHF1EScale(double scale);
00137   void setHF2EScale(double scale);
00138 
00139 
00140   // Assign to categories based on info from DB and RecHit status
00141   // Called in assignHit to check if the energy should be added to
00142   // calotower, and how to flag the channel
00143   unsigned int hcalChanStatusForCaloTower(const CaloRecHit* hit);
00144   unsigned int ecalChanStatusForCaloTower(const CaloRecHit* hit);
00145 
00146   // Channel flagging is based on acceptable severity levels specified in the
00147   // configuration file. These methods are used to pass the values read in
00148   // CaloTowersCreator
00149   // 
00150   // from DB
00151   void setHcalAcceptSeverityLevel(unsigned int level) {theHcalAcceptSeverityLevel = level;} 
00152   void setEcalSeveritiesToBeExcluded(const std::vector<int>& ecalSev ) {theEcalSeveritiesToBeExcluded= ecalSev;} 
00153 
00154   // flag to use recovered hits
00155   void setRecoveredHcalHitsAreUsed(bool flag) {theRecoveredHcalHitsAreUsed = flag; };
00156   void setRecoveredEcalHitsAreUsed(bool flag) {theRecoveredEcalHitsAreUsed = flag; };
00157 
00158   //  severety level calculator for HCAL
00159   void setHcalSevLvlComputer(const HcalSeverityLevelComputer* c) {theHcalSevLvlComputer = c; };
00160 
00161   // severity level calculator for ECAL
00162   void setEcalSevLvlAlgo(const EcalSeverityLevelAlgo* a) { theEcalSevLvlAlgo =  a; }
00163 
00164 
00165   // The following are needed for creating towers from rechits excluded from the  ------------------------------------
00166   // default reconstructions
00167 
00168  // NB! Controls if rejected hits shold be used instead of the default!!!
00169   void setUseRejectedHitsOnly(bool flag) { useRejectedHitsOnly = flag; } 
00170 
00171   void setHcalAcceptSeverityLevelForRejectedHit(unsigned int level) {theHcalAcceptSeverityLevelForRejectedHit = level;} 
00172   //  void setEcalAcceptSeverityLevelForRejectedHit(unsigned int level) {theEcalAcceptSeverityLevelForRejectedHit = level;} 
00173   void SetEcalSeveritiesToBeUsedInBadTowers(const std::vector<int>& ecalSev ) {theEcalSeveritiesToBeUsedInBadTowers= ecalSev;} 
00174 
00175 
00176   void setUseRejectedRecoveredHcalHits(bool flag) {useRejectedRecoveredHcalHits = flag; };
00177   void setUseRejectedRecoveredEcalHits(bool flag) {useRejectedRecoveredEcalHits = flag; };
00178 
00179   //-------------------------------------------------------------------------------------------------------------------
00180 
00181 
00182 
00183   // set the EE EB handles
00184   
00185   void setEbHandle(const edm::Handle<EcalRecHitCollection> eb) { theEbHandle = eb; }
00186   void setEeHandle(const edm::Handle<EcalRecHitCollection> ee) { theEeHandle = ee; }
00187 
00188 
00189 
00190 
00191   // Add methods to get the seperate positions for ECAL/HCAL 
00192   // used in constructing the 4-vectors using new methods
00193   GlobalPoint emCrystalShwrPos (DetId detId, float fracDepth); 
00194   GlobalPoint hadSegmentShwrPos(DetId detId, float fracDepth);
00195   // "effective" point for the EM/HAD shower in CaloTower
00196   //  position based on non-zero energy cells
00197   GlobalPoint hadShwrPos(const std::vector<std::pair<DetId,double> >& metaContains,
00198     float fracDepth, double hadE);
00199   GlobalPoint emShwrPos(const std::vector<std::pair<DetId,double> >& metaContains, 
00200     float fracDepth, double totEmE);
00201 
00202   // overloaded function to get had position based on all had cells in the tower
00203   GlobalPoint hadShwrPos(CaloTowerDetId id, float fracDepth);
00204   GlobalPoint hadShwPosFromCells(DetId frontCell, DetId backCell, float fracDepth);
00205 
00206   // for Chris
00207   GlobalPoint emShwrLogWeightPos(const std::vector<std::pair<DetId,double> >& metaContains, 
00208     float fracDepth, double totEmE);
00209 
00210 
00211 private:
00212 
00213   struct MetaTower {
00214     MetaTower();
00215     double E, E_em, E_had, E_outer;
00216     // contains also energy of RecHit
00217     std::vector< std::pair<DetId, double> > metaConstituents;
00218     double emSumTimeTimesE, hadSumTimeTimesE, emSumEForTime, hadSumEForTime; // Sum(Energy x Timing) : intermediate container
00219 
00220     // needed to set CaloTower status word
00221     int numBadEcalCells, numRecEcalCells, numProbEcalCells, numBadHcalCells, numRecHcalCells, numProbHcalCells; 
00222 
00223  };
00224 
00226   void assignHit(const CaloRecHit * recHit);
00227 
00228   void rescale(const CaloTower * ct);
00229 
00231   MetaTower & find(const CaloTowerDetId & id);
00232   
00234   void getThresholdAndWeight(const DetId & detId, double & threshold, double & weight) const;
00235 
00236   double theEBthreshold, theEEthreshold;
00237   bool theUseEtEBTresholdFlag, theUseEtEETresholdFlag;
00238   bool theUseSymEBTresholdFlag,theUseSymEETresholdFlag;
00239   
00240   
00241   double  theHcalThreshold;
00242 
00243   double theHBthreshold, theHESthreshold,  theHEDthreshold; 
00244   double theHOthreshold0, theHOthresholdPlus1, theHOthresholdMinus1;
00245   double theHOthresholdPlus2, theHOthresholdMinus2, theHF1threshold, theHF2threshold;
00246   std::vector<double> theEBGrid, theEBWeights;
00247   std::vector<double> theEEGrid, theEEWeights;
00248   std::vector<double> theHBGrid, theHBWeights;
00249   std::vector<double> theHESGrid, theHESWeights;
00250   std::vector<double> theHEDGrid, theHEDWeights;
00251   std::vector<double> theHOGrid, theHOWeights;
00252   std::vector<double> theHF1Grid, theHF1Weights;
00253   std::vector<double> theHF2Grid, theHF2Weights;
00254   double theEBweight, theEEweight;
00255   double theHBweight, theHESweight, theHEDweight, theHOweight, theHF1weight, theHF2weight;
00256   double theEcutTower, theEBSumThreshold, theEESumThreshold;
00257 
00258   double theEBEScale;
00259   double theEEEScale;
00260   double theHBEScale;
00261   double theHESEScale;
00262   double theHEDEScale;
00263   double theHOEScale;
00264   double theHF1EScale;
00265   double theHF2EScale;
00266   const HcalTopology* theHcalTopology;
00267   const CaloGeometry* theGeometry;
00268   const CaloTowerConstituentsMap* theTowerConstituentsMap;
00269   const CaloSubdetectorGeometry* theTowerGeometry;
00270 
00271   // for checking the status of ECAL and HCAL channels stored in the DB 
00272   const EcalChannelStatus* theEcalChStatus;
00273   const HcalChannelQuality* theHcalChStatus;
00274 
00275   // calculator of severety level for HCAL
00276   const HcalSeverityLevelComputer* theHcalSevLvlComputer;
00277 
00278   // calculator for severity level for ECAL
00279   const EcalSeverityLevelAlgo* theEcalSevLvlAlgo;
00280 
00281   
00282   // fields that hold the information passed from the CaloTowersCreator configuration file:
00283   // controll what is considered bad/recovered/problematic channel for CaloTower purposes 
00284   //
00285   unsigned int theHcalAcceptSeverityLevel;
00286   std::vector<int> theEcalSeveritiesToBeExcluded;
00287   // flag to use recovered hits
00288   bool theRecoveredHcalHitsAreUsed;
00289   bool theRecoveredEcalHitsAreUsed;
00290 
00291   // controls the tower reconstruction from rejected hits
00292 
00293   bool useRejectedHitsOnly;
00294   unsigned int theHcalAcceptSeverityLevelForRejectedHit;
00295   std::vector<int> theEcalSeveritiesToBeUsedInBadTowers;
00296 
00297 
00298   unsigned int useRejectedRecoveredHcalHits;
00299   unsigned int useRejectedRecoveredEcalHits;
00300 
00301 
00303   bool theHOIsUsed;
00304 
00305   // Switches and paramters for CaloTower 4-momentum assignment
00306   // "depth" variables do not affect all algorithms 
00307   int theMomConstrMethod;
00308   double theMomHBDepth;
00309   double theMomHEDepth;
00310   double theMomEBDepth;
00311   double theMomEEDepth;
00312 
00313   // compactify timing info
00314   int compactTime(float time);
00315 
00316   void convert(const CaloTowerDetId& id, const MetaTower& mt, CaloTowerCollection & collection);
00317   
00318 
00319   // internal map
00320   typedef std::map<CaloTowerDetId, MetaTower> MetaTowerMap;
00321   MetaTowerMap theTowerMap;
00322 
00323   // Number of channels in the tower that were not used in RecHit production (dead/off,...).
00324   // These channels are added to the other "bad" channels found in the recHit collection. 
00325   typedef std::map<CaloTowerDetId, int> HcalDropChMap;
00326   HcalDropChMap hcalDropChMap;
00327 
00328   // clasification of channels in tower construction: the category definition is
00329   // affected by the setting in the configuration file
00330   // 
00331   enum ctHitCategory {GoodChan = 0, BadChan = 1, RecoveredChan = 2, ProblematicChan = 3, IgnoredChan = 99 };
00332 
00333 
00334   // the EE and EB collections for ecal anomalous cell info
00335    
00336   edm::Handle<EcalRecHitCollection> theEbHandle;
00337   edm::Handle<EcalRecHitCollection> theEeHandle;
00338 
00339 
00340 
00341 };
00342 
00343 #endif