CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalDeadChannelRecoveryAlgos.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EcalDeadChannelRecoveryAlgos
4 // Class: EcalDeadChannelRecoveryAlgos
5 //
13 //
14 // Original Author: Georgios Daskalakis
15 // Created: Thu Apr 12 17:02:06 CEST 2007
16 //
17 // May 4th 2007 S. Beauceron : modification of MakeNxNMatrice in order to use vectors
18 //
19 
20 
21 
22 // Geometry
34 //#include "Geometry/Vector/interface/GlobalPoint.h"
35 
36 // Reconstruction Classes
40 
44 
45 #include <string>
46 using namespace cms;
47 using namespace std;
48 
49 
51 //EcalDeadChannelRecoveryAlgos::EcalDeadChannelRecoveryAlgos(const edm::ESHandle<CaloTopology> & theCaloTopology)
52 {
53  //now do what ever initialization is needed
54  calotopo = theCaloTopology;
55 }
56 
57 
59 {
60 
61  // do anything here that needs to be done at desctruction time
62  // (e.g. close files, deallocate resources etc.)
63 
64 }
65 
66 
67 //
68 // member functions
69 //
70 
71 // ------------ method called to for each event ------------
72 EcalRecHit EcalDeadChannelRecoveryAlgos::correct(const EBDetId Id, const EcalRecHitCollection* hit_collection, std::string algo_, double Sum8Cut)
73 {
74  double NewEnergy=0.0;
75 
76  double MNxN[121];
77  int IndDeadChannel[1]={-1};
78 
79  double sum8 = MakeNxNMatrice(Id,hit_collection,IndDeadChannel,MNxN);
80 
81  if(algo_=="Spline"){
82 
83  if(sum8>Sum8Cut){
84  if(IndDeadChannel[0]>0)NewEnergy = CorrectDeadChannelsClassic(MNxN,Id.ieta());
85  }
86  }else if(algo_=="NeuralNetworks"){
87  if(sum8>Sum8Cut){
88  if(IndDeadChannel[0]>0)NewEnergy = CorrectDeadChannelsNN(MNxN);
89  }
90  }
91 
92  // protect against non physical high values
93  // < sum(energy in neighbours) > = 0.8 * xtal with maximum energy
94  // => can choose 5 as highest possible energy to be assigned to
95  // the dead channel
96  uint32_t flag = 0;
97  if ( NewEnergy > 5. * sum8 ) {
98  NewEnergy = 0;
99  //flag = EcalRecHit::kDead;
100  }
101 
102  EcalRecHit NewHit(Id,NewEnergy,0, flag);
103  return NewHit;
104 
105 }
106 
107 // FIXME -- temporary backward compatibility
108 EcalRecHit EcalDeadChannelRecoveryAlgos::Correct(const EBDetId Id, const EcalRecHitCollection* hit_collection, std::string algo_, double Sum8Cut)
109 {
110  return correct(Id, hit_collection, algo_, Sum8Cut);
111 }
112 
113 //==============================================================================================================
114 //==============================================================================================================
115 //==============================================================================================================
116 //==============================================================================================================
117 
118 
119 
120 double EcalDeadChannelRecoveryAlgos::MakeNxNMatrice(EBDetId itID,const EcalRecHitCollection* hit_collection, int *IndDeadChannel, double *MNxN){
121 
122  // std::cout<<" In MakeNxNMatrice "<<std::endl;
123 
124  //Build NxN around a given cristal
125  for(int i=0; i<121;i++)MNxN[i]=0.0;
126 
127 // std::cout<<"===================================================================="<<std::endl;
128 // std::cout<<" Dead Cell CENTRAL eta = "<< itID.ieta()<<" , phi = "<< itID.iphi()<<std::endl;
129 
130  const CaloSubdetectorTopology* topology=calotopo->getSubdetectorTopology(DetId::Ecal,EcalBarrel);
131  int size =5;
132  std::vector<DetId> NxNaroundDC = topology->getWindow(itID,size,size);
133  // std::cout<<"===================================================================="<<std::endl;
134 
135 
136  // std::cout<<"NxNaroundDC size is = "<<NxNaroundDC.size()<<std::endl;
137  std::vector<DetId>::const_iterator theCells;
138 
139  EBDetId EBCellMax = itID;
140  double EnergyMax = 0.0;
141 
142  for(theCells=NxNaroundDC.begin();theCells<NxNaroundDC.end();theCells++){
143  EBDetId EBCell = EBDetId(*theCells);
144 
145  // We Will look for the cristal with maximum energy
146  if(!EBCell.null()){
147  EcalRecHitCollection::const_iterator goS_it = hit_collection->find(EBCell);
148  if( goS_it != hit_collection->end() && goS_it->energy()>=EnergyMax){EnergyMax=goS_it->energy(); EBCellMax = EBCell;}
149  }else{
150  continue;
151  }
152  }
153  if(EBCellMax.null()){/*cout<<" Error No maximum found around dead channel, no corrections applied"<<std::endl;*/return 0;}
154  // std::cout << " Max Cont Crystal eta phi E = " << EBCellMax.ieta() <<" "<< EBCellMax.iphi() <<" "<< EnergyMax<<std::endl;
155 
156 
157 
158  //NxNaroundMaxCont with N==11
159  // 000 is now the maximum containement one:
161  //Any modification of the following parameters will require changes in the Correction algos
162  // The window is large enought to avoid modification of the number.
163  int FixedSize =11;
164  std::vector<DetId> NxNaroundMaxCont = topology->getWindow(EBCellMax,FixedSize,FixedSize);
165 
166  double ESUMis=0.0;
167  int theIndex=0;
168 
169  std::vector<DetId>::const_iterator itCells;
170  for(itCells=NxNaroundMaxCont.begin();itCells<NxNaroundMaxCont.end();itCells++){
171  EBDetId EBitCell = EBDetId(*itCells);
172  int CReta = EBitCell.ieta();
173  int CRphi = EBitCell.iphi();
174 
175  double Energy = 0.0;
176  if(!EBitCell.null()){
177  EcalRecHitCollection::const_iterator goS_it = hit_collection->find(EBitCell);
178  if( goS_it != hit_collection->end() ) Energy=goS_it->energy();
179  }
180 
181  // std::cout<<"Around DC we have eta,phi,E "<<CReta<<" "<<CRphi<<" "<<Energy<<std::endl;
182 
183  //============
184  int ietaCorr = 0;
185  if((CReta * EBCellMax.ieta()) < 0 && EBCellMax.ieta()>0 )ietaCorr= -1;
186  if((CReta * EBCellMax.ieta()) < 0 && EBCellMax.ieta()<0 )ietaCorr= 1;
187  if((CReta * EBCellMax.ieta()) > 0 )ietaCorr= 0;
188  int ieta = -( (CReta -ietaCorr) - EBCellMax.ieta() ) + int((FixedSize - 1)/2);
189 
190  int iphiCorr = 0;
191  if((CRphi - EBCellMax.iphi())> 50)iphiCorr= 360;
192  if((CRphi - EBCellMax.iphi())<-50)iphiCorr=-360;
193  int iphi = CRphi - EBCellMax.iphi() - iphiCorr + int((FixedSize - 1)/2);
194 
195  int MIndex = ieta+iphi*FixedSize;
196  if(abs(CReta)<=85)
197  MNxN[MIndex]=Energy;
198  if(EBitCell == itID)IndDeadChannel[0]= MIndex;
199 
200 
201  //============
202 
203 
204 
205 
206  //We add up the energy in 5x5 around the MaxCont to decide if we will correct for DCs
207  // if(theIndex>=36 && theIndex<=40)ESUMis += Energy;
208  //SB: Modify to sum8 only
209  if(theIndex>=48 && theIndex<=50)ESUMis += Energy;
210  if(theIndex>=59 && theIndex<=61)ESUMis += Energy;
211  if(theIndex>=70 && theIndex<=72)ESUMis += Energy;
212  // if(theIndex>=80 && theIndex<=84)ESUMis += Energy;
213  theIndex++;
214  }
215  // std::cout<<"Around MaxCont Collected Energy in 5x5 is = "<< ESUMis <<std::endl;
216  //So now, we have a vector which is ordered around the Maximum containement and which contains a dead channel as:
217  //Filling of the vector : NxNaroundDC with N==11 Typo are possible...
218  // 000 is Maximum containement which is in +/- 5 from DC
219  //
220  // 120 119 118 117 116 115 114 113 112 111 110
221  // 109 108 107 106 105 104 103 102 101 100 099
222  // 098 097 096 095 094 093 092 091 090 089 088
223  // 087 086 085 084 083 082 081 080 079 078 077
224  // 076 075 074 073 072 071 070 069 068 067 066
225  // 065 064 063 062 061 060 059 058 057 056 055
226  // 054 053 052 051 050 049 048 047 046 045 044
227  // 043 042 041 040 039 038 037 036 035 034 033
228  // 032 031 030 029 028 027 026 025 024 023 022
229  // 021 020 019 018 017 016 015 014 013 012 011
230  // 010 009 008 007 006 005 004 003 002 001 000
232 
233 
234 
235  //================
236 
237  return ESUMis;
238 }
239 
int i
Definition: DBlmapReader.cc:9
double CorrectDeadChannelsClassic(double *M11x11Input, const int DCeta)
std::vector< EcalRecHit >::const_iterator const_iterator
EcalRecHit correct(const EBDetId Id, const EcalRecHitCollection *hit_collection, std::string algo_, double Sum8Cut)
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
double MakeNxNMatrice(EBDetId itID, const EcalRecHitCollection *hit_collection, int *IndDeadChannel, double *MNxN)
const_iterator end() const
double CorrectDeadChannelsNN(double *M5x5Input)
EcalRecHit Correct(const EBDetId Id, const EcalRecHitCollection *hit_collection, std::string algo_, double Sum8Cut)
virtual std::vector< DetId > getWindow(const DetId &id, const int &northSouthSize, const int &eastWestSize) const
bool null() const
is this a null id ?
Definition: DetId.h:45
iterator find(key_type k)
tuple size
Write out results.