CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
HcalCholeskyDecomp Class Reference

#include <HcalCholeskyDecomp.h>

Inheritance diagram for HcalCholeskyDecomp:
edm::EDAnalyzer

Public Member Functions

 HcalCholeskyDecomp (const edm::ParameterSet &)
 
 ~HcalCholeskyDecomp ()
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 

Private Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
virtual void beginJob ()
 
virtual void endJob ()
 

Private Attributes

std::string outfile
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
typedef WorkerT< EDAnalyzerWorkerType
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDAnalyzer
CurrentProcessingContext const * currentContext () const
 

Detailed Description

Definition at line 42 of file HcalCholeskyDecomp.h.

Constructor & Destructor Documentation

HcalCholeskyDecomp::HcalCholeskyDecomp ( const edm::ParameterSet iConfig)
explicit

Definition at line 6 of file HcalCholeskyDecomp.cc.

References edm::ParameterSet::getUntrackedParameter(), and outfile.

7 {
8  outfile = iConfig.getUntrackedParameter<std::string>("outFile","CholeskyMatrices.txt");
9 }
T getUntrackedParameter(std::string const &, T const &) const
HcalCholeskyDecomp::~HcalCholeskyDecomp ( )

Definition at line 12 of file HcalCholeskyDecomp.cc.

13 {
14 }

Member Function Documentation

void HcalCholeskyDecomp::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
privatevirtual

Implements edm::EDAnalyzer.

Definition at line 17 of file HcalCholeskyDecomp.cc.

References HcalElectronicsMap::allPrecisionId(), trackerHits::c, prof2calltree::count, gather_cfg::cout, HcalDbASCIIIO::dumpObject(), spr::find(), edm::EventSetup::get(), HcalCovarianceMatrix::getValue(), i, j, gen::k, m, outfile, HcalCholeskyMatrix::setValue(), and mathSSE::sqrt().

18 {
19  using namespace edm;
20  using namespace std;
21 
23  iSetup.get<HcalCovarianceMatricesRcd>().get("reference",refCov);
24  const HcalCovarianceMatrices* myCov = refCov.product(); //Fill emap from database
25 
26  double sig[4][10][10];
27  double c[4][10][10], cikik[4], cikjk[4], ct[4][10][10];
28 
29  HcalCholeskyMatrices * outMatrices = new HcalCholeskyMatrices();
30 
31  std::vector<DetId> listChan = myCov->getAllChannels();
32  std::vector<DetId>::iterator cell;
33 
34  int HBcount = 0;
35  int HEcount = 0;
36  int HFcount = 0;
37  int HOcount = 0;
38 
39  double HBmatrix[4][10][10];
40  double HEmatrix[4][10][10];
41  double HFmatrix[4][10][10];
42  double HOmatrix[4][10][10];
43 
44  double tempmatrix[4][10][10] ;
45 
46 
47  for(int m= 0; m != 4; m++){
48  for(int i = 0; i != 10; i++){
49  for(int j = 0; j!=10; j++){
50  HBmatrix[m][i][j] = 0;
51  HEmatrix[m][i][j] = 0;
52  HFmatrix[m][i][j] = 0;
53  HOmatrix[m][i][j] = 0;
54  }
55  }
56  }
57 
58  for (std::vector<DetId>::iterator it = listChan.begin(); it != listChan.end(); it++)
59  {
60  for(int m= 0; m != 4; m++){
61  for(int i = 0; i != 10; i++){
62  for(int j = 0; j!=10; j++){
63  sig[m][i][j] = 0;
64  c[m][i][j] = 0;
65  ct[m][i][j] = 0;
66  cikik[m] =0;
67  cikjk[m] = 0;
68  tempmatrix[m][i][j] = 0;
69  }
70  }
71  }
72 
73  const HcalCovarianceMatrix * CMatrix = myCov->getValues(*it);
74  HcalDetId hcalid(it->rawId());
75 
76  for(int m = 0; m != 4; m++){
77  for(int i = 0; i != 10; i++){
78  for(int j = 0; j != 10; j++) {sig[m][i][j] = CMatrix->getValue(m,i,j);}
79  }
80  }
81 
82 //Method to check 4x10 storage
83 // for(int m = 0; m != 4; m++){
84 // for(int i = 0; i != 6; i++){
85 // for(int j=(i+4); j!=10; j++) {sig[m][i][j] = 0;}
86 // }
87 // }
88 
89 
90  for(int m = 0; m != 4; m++){
91  for(int i = 0; i != 10; i++){
92  for(int j = i; j != 10; j++){ sig[m][j][i] = sig[m][i][j];}
93  }
94  }
95  //.......................Cholesky Decomposition.............................
96  //Step 1a
97  for(int m = 0; m!=4; m++)
98  {
99 
100  c[m][0][0]=sqrt(sig[m][0][0]);
101  }
102  for(int m = 0; m!=4; m++)
103  {
104  for(int i = 1; i != 10; i++)
105  {
106  c[m][i][0] = (sig[m][0][i] / c[m][0][0]);
107  }
108  }
109 
110  //Chelesky Matrices
111  for(int m = 0; m!=4; m++)
112  {
113  c[m][1][1] = sqrt(sig[m][1][1] - (c[m][1][0]*c[m][1][0])); // i) step 2a of chelesky decomp
114  if (((sig[m][1][1]) - (c[m][1][0]*c[m][1][0]))<=0) continue;
115  for(int i = 2; i !=10; i++)
116  {
117  cikik[m] = 0;
118  for(int j=1; j!= i; j++)
119  {
120  cikjk[m] = 0;
121  for(int k=0; k != j; k++)
122  {
123  cikjk[m] += (c[m][i][k]*c[m][j][k]); // ii) step 2a of chelesky decomp
124  }
125  c[m][i][j] = (sig[m][i][j] - cikjk[m])/c[m][j][j]; // step 3a of chelesky decomp
126  }//end of j loop
127 
128  for( int k = 0; k != i; k++)
129  {
130  cikik[m] += (c[m][i][k]*c[m][i][k]);
131  }
132  double test = (sig[m][i][i] - cikik[m]);
133  if(test > 0 )
134  {
135  c[m][i][i] = sqrt(test);
136  }
137  else
138  {
139  c[m][i][i] = 1000;
140  }
141  }//end of i loop
142 /*
143  //Cholesky Matrix for rechit (2-5 ts)
144  for (int i = 0; i!=2; i++)
145  {
146  for (int j=0; j!=10; j++)
147  {
148  c[m][i][j] = 0;
149  }
150  }
151  for (int i = 6; i!=10; i++)
152  {
153  for (int j=0; j!=10; j++)
154  {
155  c[m][i][j] = 0;
156  }
157  }
158 */
159 
160 
161  }//end of m loop
162 
163 
164  HcalCholeskyMatrix * item = new HcalCholeskyMatrix(it->rawId());
165  for(int m = 0; m != 4; m++){
166  for(int i = 0; i != 10; i++){
167  for(int j = i; j != 10; j++){
168  item->setValue(m,j,i, c[m][j][i]);
169  tempmatrix[m][j][i] = c[m][j][i];
170  }//sig[m][j][i]
171  }
172  }
173 
174  if(hcalid.subdet()==1)
175  {
176  for(int m = 0; m != 4; m++)
177  for(int i = 0; i != 10; i++)
178  for(int j = 0; j != 10; j++)
179  HBmatrix[m][i][j] += tempmatrix[m][i][j];
180  HBcount++;
181  }
182  if(hcalid.subdet()==2)
183  {
184  for(int m = 0; m != 4; m++)
185  for(int i = 0; i != 10; i++)
186  for(int j = 0; j != 10; j++)
187  HEmatrix[m][i][j] += tempmatrix[m][i][j];
188  HEcount++;
189  }
190  if(hcalid.subdet()==3)
191  {
192  for(int m = 0; m != 4; m++)
193  for(int i = 0; i != 10; i++)
194  for(int j = 0; j != 10; j++)
195  HOmatrix[m][i][j] += tempmatrix[m][i][j];
196  HOcount++;
197  }
198  if(hcalid.subdet()==4)
199  {
200  for(int m = 0; m != 4; m++)
201  for(int i = 0; i != 10; i++)
202  for(int j = 0; j != 10; j++)
203  HFmatrix[m][i][j] += tempmatrix[m][i][j];
204  HFcount++;
205  }
206 
207 
208 
209  outMatrices->addValues(*item);
210 
211  }
212 
213  for(int m = 0; m != 4; m++)
214  {
215  for(int i = 0; i != 10; i++)
216  {
217  for(int j = 0; j != 10; j++)
218  {
219  HBmatrix [m][i][j] /= HBcount;
220  HEmatrix [m][i][j] /= HEcount;
221  HFmatrix [m][i][j] /= HFcount;
222  HOmatrix [m][i][j] /= HOcount;
223  }
224  }
225  }
226 
227  std::vector<DetId> listResult = outMatrices->getAllChannels();
228 
229  int n_avg = 0;
230 
232  iSetup.get<HcalElectronicsMapRcd>().get(refEMap);
233 // iSetup.get<HcalElectronicsMapRcd>().get("reference",refEMap);
234  const HcalElectronicsMap* myRefEMap = refEMap.product();
235  std::vector<HcalGenericDetId> listEMap = myRefEMap->allPrecisionId();
236 
237  for (std::vector<HcalGenericDetId>::const_iterator it = listEMap.begin(); it != listEMap.end(); it++)
238  {
239  DetId mydetid = DetId(it->rawId());
240  if (std::find(listResult.begin(), listResult.end(), mydetid ) == listResult.end() )
241  {
242 // std::cout << "Cholesky Matrix not found for cell " << HcalGenericDetId(it->rawId());
243  if(it->isHcalDetId())
244  {
245  std::cout << "Cholesky Matrix not found for cell " << HcalGenericDetId(it->rawId());
246  HcalDetId hcalid2(it->rawId());
247  HcalCholeskyMatrix * item = new HcalCholeskyMatrix(it->rawId());
248  for(int m = 0; m != 4; m++)
249  {
250  for(int i = 0; i != 10; i++)
251  {
252  for(int j = 0; j != 10; j++)
253  {
254  if(j <= i){
255  if(hcalid2.subdet()==1) item->setValue(m,i,j,HBmatrix [m][i][j]);
256  if(hcalid2.subdet()==2) item->setValue(m,i,j,HEmatrix [m][i][j]);
257  if(hcalid2.subdet()==3) item->setValue(m,i,j,HFmatrix [m][i][j]);
258  if(hcalid2.subdet()==4) item->setValue(m,i,j,HOmatrix [m][i][j]);
259  }else{
260  if(hcalid2.subdet()==1) item->setValue(m,i,j,0);
261  if(hcalid2.subdet()==2) item->setValue(m,i,j,0);
262  if(hcalid2.subdet()==3) item->setValue(m,i,j,0);
263  if(hcalid2.subdet()==4) item->setValue(m,i,j,0);
264  }
265  }
266  }
267  }
268  outMatrices->addValues(*item);
269  std::cout << "... Average Matrix used\n";
270  n_avg++;
271  }
272  }
273  }
274 
275  std::vector<DetId> checkResult = outMatrices->getAllChannels();
276  int count = 0;
277  for(std::vector<DetId>::const_iterator it = checkResult.begin(); it != checkResult.end(); it++) count ++;
278 
279  std::cout << "There are " << count << " channels with Cholesky matrices.\n" << "Used " << n_avg << " average values.\n";
280 
281  ofstream cmatout(outfile.c_str());
282  HcalDbASCIIIO::dumpObject(cmatout, *outMatrices);
283 }
int i
Definition: DBlmapReader.cc:9
void setValue(int capid, int i, int j, float val)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
float getValue(int capid, int i, int j) const
T sqrt(T t)
Definition: SSEVec.h:28
int j
Definition: DBlmapReader.cc:9
std::vector< HcalGenericDetId > allPrecisionId() const
int k[5][pyjets_maxn]
Definition: DetId.h:20
const T & get() const
Definition: EventSetup.h:55
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
tuple cout
Definition: gather_cfg.py:41
void HcalCholeskyDecomp::beginJob ( void  )
privatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 287 of file HcalCholeskyDecomp.cc.

288 {
289 }
void HcalCholeskyDecomp::endJob ( void  )
privatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 293 of file HcalCholeskyDecomp.cc.

293  {
294 }

Member Data Documentation

std::string HcalCholeskyDecomp::outfile
private

Definition at line 52 of file HcalCholeskyDecomp.h.

Referenced by analyze(), and HcalCholeskyDecomp().