CMS 3D CMS Logo

EcalDeadChannelRecoveryAlgos.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    EcalDeadChannelRecoveryAlgos
00004 // Class:      EcalDeadChannelRecoveryAlgos
00005 // 
00013 //
00014 // Original Author:  Georgios Daskalakis
00015 //         Created:  Thu Apr 12 17:02:06 CEST 2007
00016 // $Id: EcalDeadChannelRecoveryAlgos.cc,v 1.4 2007/05/18 09:38:08 gdaskal Exp $
00017 //
00018 // May 4th 2007 S. Beauceron : modification of MakeNxNMatrice in order to use vectors
00019 //
00020 
00021 
00022 
00023 // Geometry
00024 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00025 #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"
00026 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00027 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00028 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00029 #include "Geometry/CaloTopology/interface/EcalEndcapTopology.h"
00030 #include "Geometry/CaloTopology/interface/EcalBarrelTopology.h"
00031 #include "Geometry/CaloTopology/interface/EcalBarrelHardcodedTopology.h"
00032 #include "Geometry/CaloTopology/interface/CaloTopology.h"
00033 #include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h"
00034 #include "RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
00035 //#include "Geometry/Vector/interface/GlobalPoint.h"
00036 
00037 // Reconstruction Classes
00038 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00039 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00040 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00041 
00042 #include "RecoLocalCalo/EcalDeadChannelRecoveryAlgos/interface/EcalDeadChannelRecoveryAlgos.h"
00043 #include "RecoLocalCalo/EcalDeadChannelRecoveryAlgos/interface/CorrectDeadChannelsClassic.cc"
00044 #include "RecoLocalCalo/EcalDeadChannelRecoveryAlgos/interface/CorrectDeadChannelsNN.cc"
00045 
00046 #include <string>
00047 using namespace cms;
00048 using namespace std;
00049 
00050 
00051 EcalDeadChannelRecoveryAlgos::EcalDeadChannelRecoveryAlgos(const CaloTopology theCaloTopology)
00052 //EcalDeadChannelRecoveryAlgos::EcalDeadChannelRecoveryAlgos(const edm::ESHandle<CaloTopology> & theCaloTopology)
00053 {
00054   //now do what ever initialization is needed
00055   calotopo = theCaloTopology;
00056 }
00057 
00058 
00059 EcalDeadChannelRecoveryAlgos::~EcalDeadChannelRecoveryAlgos()
00060 {
00061  
00062    // do anything here that needs to be done at desctruction time
00063    // (e.g. close files, deallocate resources etc.)
00064 
00065 }
00066 
00067 
00068 //
00069 // member functions
00070 //
00071 
00072 // ------------ method called to for each event  ------------
00073 EcalRecHit EcalDeadChannelRecoveryAlgos::Correct(const EBDetId Id, const EcalRecHitCollection* hit_collection, string algo_, double Sum8Cut)
00074 {
00075   double NewEnergy=0.0;
00076   
00077   double MNxN[121];
00078 
00079   if(algo_=="Spline"){
00080      
00081     if(MakeNxNMatrice(Id,hit_collection,MNxN)>Sum8Cut){
00082       NewEnergy = CorrectDeadChannelsClassic(MNxN,Id.ieta());
00083     }
00084   }else if(algo_=="NeuralNetworks"){
00085    
00086     if(MakeNxNMatrice(Id,hit_collection,MNxN)>Sum8Cut){
00087       NewEnergy = CorrectDeadChannelsNN(MNxN);
00088     }
00089   }
00090   
00091 
00092   EcalRecHit NewHit(Id,NewEnergy,0);
00093   return NewHit;
00094 
00095 }
00096 
00097 
00098 //==============================================================================================================
00099 //==============================================================================================================
00100 //==============================================================================================================
00101 //==============================================================================================================
00102 
00103 
00104 
00105 double EcalDeadChannelRecoveryAlgos::MakeNxNMatrice(EBDetId itID,const EcalRecHitCollection* hit_collection, double *MNxN){
00106 
00107 
00108 
00109   //Build NxN around a given cristal
00110   for(int i=0; i<121;i++)MNxN[i]=0.0;
00111   
00112   //cout<<"===================================================================="<<endl;
00113   //cout<<" Dead Cell CENTRAL  eta = "<< itID.ieta()<<" ,  phi = "<< itID.iphi()<<endl;
00114 
00115   const CaloSubdetectorTopology* topology=calotopo.getSubdetectorTopology(DetId::Ecal,EcalBarrel);
00116   int size =5;
00117   std::vector<DetId> NxNaroundDC = topology->getWindow(itID,size,size);
00118   
00119   
00120   //cout<<"NxNaroundDC size is = "<<NxNaroundDC.size()<<endl;
00121   vector<DetId>::const_iterator theCells;
00122   
00123   EBDetId EBCellMax = itID;
00124   double EnergyMax = 0.0;
00125 
00126   for(theCells=NxNaroundDC.begin();theCells<NxNaroundDC.end();theCells++){
00127     EBDetId EBCell = EBDetId(*theCells);
00128       
00129     // We Will look for the cristal with maximum energy 
00130     if(!EBCell.null()){
00131       EcalRecHitCollection::const_iterator goS_it = hit_collection->find(EBCell);
00132       if( goS_it !=  hit_collection->end() && goS_it->energy()>=EnergyMax){EnergyMax=goS_it->energy(); EBCellMax = EBCell;}
00133     }else{
00134       continue; 
00135     }
00136   } 
00137   if(EBCellMax.null()){cout<<" Error No maximum found around dead channel, no corrections applied"<<endl;return 0;}
00138   //cout << " Max Cont Crystal eta phi E = " << EBCellMax.ieta() <<" "<< EBCellMax.iphi() <<" "<< EnergyMax<<endl;
00139 
00140 
00141   
00142   //NxNaroundMaxCont with N==11
00143   // 000 is now the maximum containement one:
00145   //Any modification of the following parameters will require changes in the Correction algos
00146   // The window is large enought to avoid modification of the number.
00147   int FixedSize =11;
00148   std::vector<DetId> NxNaroundMaxCont = topology->getWindow(EBCellMax,FixedSize,FixedSize);
00149 
00150   double ESUMis=0.0;
00151   int theIndex=0;
00152 
00153   vector<DetId>::const_iterator itCells;
00154   for(itCells=NxNaroundMaxCont.begin();itCells<NxNaroundMaxCont.end();itCells++){
00155     EBDetId EBitCell = EBDetId(*itCells);
00156     int CReta = EBitCell.ieta();
00157     int CRphi = EBitCell.iphi();
00158 
00159     double Energy = 0.0;
00160     if(!EBitCell.null()){
00161       EcalRecHitCollection::const_iterator goS_it = hit_collection->find(EBitCell);
00162       if( goS_it !=  hit_collection->end() ) Energy=goS_it->energy();
00163     }
00164 
00165     //cout<<"Around DC we have eta,phi,E "<<CReta<<" "<<CRphi<<" "<<Energy<<endl;
00166 
00167     //============
00168     int ietaCorr = 0;
00169     if((CReta * EBCellMax.ieta()) < 0 && EBCellMax.ieta()>0 )ietaCorr= -1;
00170     if((CReta * EBCellMax.ieta()) < 0 && EBCellMax.ieta()<0 )ietaCorr=  1;
00171     if((CReta * EBCellMax.ieta()) > 0 )ietaCorr= 0;
00172     int ieta = -( (CReta -ietaCorr) - EBCellMax.ieta() ) + int((FixedSize - 1)/2);
00173 
00174     int iphiCorr = 0;
00175     if((CRphi - EBCellMax.iphi())> 50)iphiCorr= 360;
00176     if((CRphi - EBCellMax.iphi())<-50)iphiCorr=-360;
00177     int iphi = CRphi - EBCellMax.iphi() - iphiCorr + int((FixedSize - 1)/2);
00178 
00179     int MIndex = ieta+iphi*FixedSize;
00180     if(abs(CReta)<=85)
00181     MNxN[MIndex]=Energy;
00182     
00183     
00184     //============
00185 
00186 
00187 
00188     
00189     //We add up the energy in 5x5 around the MaxCont to decide if we will correct for DCs
00190     if(theIndex>=36 && theIndex<=40)ESUMis +=  Energy;
00191     if(theIndex>=47 && theIndex<=51)ESUMis +=  Energy;
00192     if(theIndex>=58 && theIndex<=62)ESUMis +=  Energy;
00193     if(theIndex>=69 && theIndex<=73)ESUMis +=  Energy;
00194     if(theIndex>=80 && theIndex<=84)ESUMis +=  Energy;
00195     theIndex++;
00196   }
00197   //cout<<"Around MaxCont Collected Energy in 5x5 is =  "<< ESUMis  <<endl;
00198   //So now, we have a vector which is ordered around the Maximum containement and which contains a dead channel as:
00199     //Filling of the vector : NxNaroundDC with N==11 Typo are possible...
00200     // 000 is Maximum containement which is in +/- 5 from DC
00201     //
00202     // 120 119 118 117 116 115 114 113 112 111 110  
00203     // 109 108 107 106 105 104 103 102 101 100 099 
00204     // 098 097 096 095 094 093 092 091 090 089 088
00205     // 087 086 085 084 083 082 081 080 079 078 077
00206     // 076 075 074 073 072 071 070 069 068 067 066
00207     // 065 064 063 062 061 060 059 058 057 056 055
00208     // 054 053 052 051 050 049 048 047 046 045 044
00209     // 043 042 041 040 039 038 037 036 035 034 033
00210     // 032 031 030 029 028 027 026 025 024 023 022
00211     // 021 020 019 018 017 016 015 014 013 012 011
00212     // 010 009 008 007 006 005 004 003 002 001 000
00214   
00215 
00216   
00217   //================
00218 
00219   return ESUMis;
00220 }
00221 

Generated on Tue Jun 9 17:43:44 2009 for CMSSW by  doxygen 1.5.4