CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/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     std::vector<double> EBGrid, std::vector<double> EBWeights,
00086     std::vector<double> EEGrid, std::vector<double> EEWeights,
00087     std::vector<double> HBGrid, std::vector<double> HBWeights,
00088     std::vector<double> HESGrid, std::vector<double> HESWeights,
00089     std::vector<double> HEDGrid, std::vector<double> HEDWeights,
00090     std::vector<double> HOGrid, std::vector<double> HOWeights,
00091     std::vector<double> HF1Grid, std::vector<double> HF1Weights,
00092     std::vector<double> HF2Grid, 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 setEcalAcceptSeverityLevel(unsigned int level) {theEcalAcceptSeverityLevel = level;} 
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   // derault reconstructions
00167 
00168  // NB! Controls if rejected jits 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 
00174   void setUseRejectedRecoveredHcalHits(bool flag) {useRejectedRecoveredHcalHits = flag; };
00175   void setUseRejectedRecoveredEcalHits(bool flag) {useRejectedRecoveredEcalHits = flag; };
00176 
00177   //-------------------------------------------------------------------------------------------------------------------
00178 
00179 
00180 
00181   // set the EE EB handles
00182   
00183   void setEbHandle(const edm::Handle<EcalRecHitCollection> eb) { theEbHandle = eb; }
00184   void setEeHandle(const edm::Handle<EcalRecHitCollection> ee) { theEeHandle = ee; }
00185 
00186 
00187 
00188 
00189   // Add methods to get the seperate positions for ECAL/HCAL 
00190   // used in constructing the 4-vectors using new methods
00191   GlobalPoint emCrystalShwrPos (DetId detId, float fracDepth); 
00192   GlobalPoint hadSegmentShwrPos(DetId detId, float fracDepth);
00193   // "effective" point for the EM/HAD shower in CaloTower
00194   //  position based on non-zero energy cells
00195   GlobalPoint hadShwrPos(std::vector<std::pair<DetId,double> >& metaContains,
00196     float fracDepth, double hadE);
00197   GlobalPoint emShwrPos(std::vector<std::pair<DetId,double> >& metaContains, 
00198     float fracDepth, double totEmE);
00199 
00200   // overloaded function to get had position based on all had cells in the tower
00201   GlobalPoint hadShwrPos(CaloTowerDetId id, float fracDepth);
00202   GlobalPoint hadShwPosFromCells(DetId frontCell, DetId backCell, float fracDepth);
00203 
00204   // for Chris
00205   GlobalPoint emShwrLogWeightPos(std::vector<std::pair<DetId,double> >& metaContains, 
00206     float fracDepth, double totEmE);
00207 
00208 
00209 private:
00210 
00211   struct MetaTower {
00212     MetaTower();
00213     double E, E_em, E_had, E_outer;
00214     // contains also energy of RecHit
00215     std::vector< std::pair<DetId, double> > metaConstituents;
00216     double emSumTimeTimesE, hadSumTimeTimesE, emSumEForTime, hadSumEForTime; // Sum(Energy x Timing) : intermediate container
00217 
00218     // needed to set CaloTower status word
00219     int numBadEcalCells, numRecEcalCells, numProbEcalCells, numBadHcalCells, numRecHcalCells, numProbHcalCells; 
00220 
00221  };
00222 
00224   void assignHit(const CaloRecHit * recHit);
00225 
00226   void rescale(const CaloTower * ct);
00227 
00229   MetaTower & find(const CaloTowerDetId & id);
00230   
00232   void getThresholdAndWeight(const DetId & detId, double & threshold, double & weight) const;
00233 
00234   double theEBthreshold, theEEthreshold;
00235   bool theUseEtEBTresholdFlag, theUseEtEETresholdFlag;
00236   bool theUseSymEBTresholdFlag,theUseSymEETresholdFlag;
00237   
00238   
00239   double  theHcalThreshold;
00240 
00241   double theHBthreshold, theHESthreshold,  theHEDthreshold; 
00242   double theHOthreshold0, theHOthresholdPlus1, theHOthresholdMinus1;
00243   double theHOthresholdPlus2, theHOthresholdMinus2, theHF1threshold, theHF2threshold;
00244   std::vector<double> theEBGrid, theEBWeights;
00245   std::vector<double> theEEGrid, theEEWeights;
00246   std::vector<double> theHBGrid, theHBWeights;
00247   std::vector<double> theHESGrid, theHESWeights;
00248   std::vector<double> theHEDGrid, theHEDWeights;
00249   std::vector<double> theHOGrid, theHOWeights;
00250   std::vector<double> theHF1Grid, theHF1Weights;
00251   std::vector<double> theHF2Grid, theHF2Weights;
00252   double theEBweight, theEEweight;
00253   double theHBweight, theHESweight, theHEDweight, theHOweight, theHF1weight, theHF2weight;
00254   double theEcutTower, theEBSumThreshold, theEESumThreshold;
00255 
00256   double theEBEScale;
00257   double theEEEScale;
00258   double theHBEScale;
00259   double theHESEScale;
00260   double theHEDEScale;
00261   double theHOEScale;
00262   double theHF1EScale;
00263   double theHF2EScale;
00264   const HcalTopology* theHcalTopology;
00265   const CaloGeometry* theGeometry;
00266   const CaloTowerConstituentsMap* theTowerConstituentsMap;
00267   const CaloSubdetectorGeometry* theTowerGeometry;
00268 
00269   // for checking the status of ECAL and HCAL channels stored in the DB 
00270   const EcalChannelStatus* theEcalChStatus;
00271   const HcalChannelQuality* theHcalChStatus;
00272 
00273   // calculator of severety level for HCAL
00274   const HcalSeverityLevelComputer* theHcalSevLvlComputer;
00275 
00276   // calculator for severity level for ECAL
00277   const EcalSeverityLevelAlgo* theEcalSevLvlAlgo;
00278 
00279   
00280   // fields that hold the information passed from the CaloTowersCreator configuration file:
00281   // controll what is considered bad/recovered/problematic channel for CaloTower purposes 
00282   //
00283   unsigned int theHcalAcceptSeverityLevel;
00284   unsigned int theEcalAcceptSeverityLevel;
00285   // flag to use recovered hits
00286   bool theRecoveredHcalHitsAreUsed;
00287   bool theRecoveredEcalHitsAreUsed;
00288 
00289   // controls the tower reconstruction from rejected hits
00290 
00291   bool useRejectedHitsOnly;
00292   unsigned int theHcalAcceptSeverityLevelForRejectedHit;
00293   unsigned int theEcalAcceptSeverityLevelForRejectedHit;
00294   unsigned int useRejectedRecoveredHcalHits;
00295   unsigned int useRejectedRecoveredEcalHits;
00296 
00297 
00299   bool theHOIsUsed;
00300 
00301   // Switches and paramters for CaloTower 4-momentum assignment
00302   // "depth" variables do not affect all algorithms 
00303   int theMomConstrMethod;
00304   double theMomEmDepth;
00305   double theMomHadDepth;
00306 
00307   double theMomHBDepth;
00308   double theMomHEDepth;
00309   double theMomEBDepth;
00310   double theMomEEDepth;
00311 
00312   // compactify timing info
00313   int compactTime(float time);
00314 
00315   CaloTower convert(const CaloTowerDetId& id, const MetaTower& mt);
00316 
00317   // internal map
00318   typedef std::map<CaloTowerDetId, MetaTower> MetaTowerMap;
00319   MetaTowerMap theTowerMap;
00320 
00321   // Number of channels in the tower that were not used in RecHit production (dead/off,...).
00322   // These channels are added to the other "bad" channels found in the recHit collection. 
00323   std::map<CaloTowerDetId, int> hcalDropChMap;
00324 
00325   // clasification of channels in tower construction: the category definition is
00326   // affected by the setting in the configuration file
00327   // 
00328   enum ctHitCategory {GoodChan = 0, BadChan = 1, RecoveredChan = 2, ProblematicChan = 3, IgnoredChan = 99 };
00329 
00330 
00331   // the EE and EB collections for ecal anomalous cell info
00332    
00333   edm::Handle<EcalRecHitCollection> theEbHandle;
00334   edm::Handle<EcalRecHitCollection> theEeHandle;
00335 
00336 
00337 
00338 };
00339 
00340 #endif