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)
 
static void prevalidate (ConfigurationDescriptions &)
 
- 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(), mathSSE::sqrt(), and run_regression::test.

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];
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  cikik[m] =0;
66  cikjk[m] = 0;
67  tempmatrix[m][i][j] = 0;
68  }
69  }
70  }
71 
72  const HcalCovarianceMatrix * CMatrix = myCov->getValues(*it);
73  HcalDetId hcalid(it->rawId());
74 
75  for(int m = 0; m != 4; m++){
76  for(int i = 0; i != 10; i++){
77  for(int j = 0; j != 10; j++) {sig[m][i][j] = CMatrix->getValue(m,i,j);}
78  }
79  }
80 
81 //Method to check 4x10 storage
82 // for(int m = 0; m != 4; m++){
83 // for(int i = 0; i != 6; i++){
84 // for(int j=(i+4); j!=10; j++) {sig[m][i][j] = 0;}
85 // }
86 // }
87 
88 
89  for(int m = 0; m != 4; m++){
90  for(int i = 0; i != 10; i++){
91  for(int j = i; j != 10; j++){ sig[m][j][i] = sig[m][i][j];}
92  }
93  }
94  //.......................Cholesky Decomposition.............................
95  //Step 1a
96  for(int m = 0; m!=4; m++)
97  {
98 
99  c[m][0][0]=sqrt(sig[m][0][0]);
100  }
101  for(int m = 0; m!=4; m++)
102  {
103  for(int i = 1; i != 10; i++)
104  {
105  c[m][i][0] = (sig[m][0][i] / c[m][0][0]);
106  }
107  }
108 
109  //Chelesky Matrices
110  for(int m = 0; m!=4; m++)
111  {
112  c[m][1][1] = sqrt(sig[m][1][1] - (c[m][1][0]*c[m][1][0])); // i) step 2a of chelesky decomp
113  if (((sig[m][1][1]) - (c[m][1][0]*c[m][1][0]))<=0) continue;
114  for(int i = 2; i !=10; i++)
115  {
116  cikik[m] = 0;
117  for(int j=1; j!= i; j++)
118  {
119  cikjk[m] = 0;
120  for(int k=0; k != j; k++)
121  {
122  cikjk[m] += (c[m][i][k]*c[m][j][k]); // ii) step 2a of chelesky decomp
123  }
124  c[m][i][j] = (sig[m][i][j] - cikjk[m])/c[m][j][j]; // step 3a of chelesky decomp
125  }//end of j loop
126 
127  for( int k = 0; k != i; k++)
128  {
129  cikik[m] += (c[m][i][k]*c[m][i][k]);
130  }
131  double test = (sig[m][i][i] - cikik[m]);
132  if(test > 0 )
133  {
134  c[m][i][i] = sqrt(test);
135  }
136  else
137  {
138  c[m][i][i] = 1000;
139  }
140  }//end of i loop
141 /*
142  //Cholesky Matrix for rechit (2-5 ts)
143  for (int i = 0; i!=2; i++)
144  {
145  for (int j=0; j!=10; j++)
146  {
147  c[m][i][j] = 0;
148  }
149  }
150  for (int i = 6; i!=10; i++)
151  {
152  for (int j=0; j!=10; j++)
153  {
154  c[m][i][j] = 0;
155  }
156  }
157 */
158 
159 
160  }//end of m loop
161 
162 
163  HcalCholeskyMatrix * item = new HcalCholeskyMatrix(it->rawId());
164  for(int m = 0; m != 4; m++){
165  for(int i = 0; i != 10; i++){
166  for(int j = i; j != 10; j++){
167  item->setValue(m,j,i, c[m][j][i]);
168  tempmatrix[m][j][i] = c[m][j][i];
169  }//sig[m][j][i]
170  }
171  }
172 
173  if(hcalid.subdet()==1)
174  {
175  for(int m = 0; m != 4; m++)
176  for(int i = 0; i != 10; i++)
177  for(int j = 0; j != 10; j++)
178  HBmatrix[m][i][j] += tempmatrix[m][i][j];
179  HBcount++;
180  }
181  if(hcalid.subdet()==2)
182  {
183  for(int m = 0; m != 4; m++)
184  for(int i = 0; i != 10; i++)
185  for(int j = 0; j != 10; j++)
186  HEmatrix[m][i][j] += tempmatrix[m][i][j];
187  HEcount++;
188  }
189  if(hcalid.subdet()==3)
190  {
191  for(int m = 0; m != 4; m++)
192  for(int i = 0; i != 10; i++)
193  for(int j = 0; j != 10; j++)
194  HOmatrix[m][i][j] += tempmatrix[m][i][j];
195  HOcount++;
196  }
197  if(hcalid.subdet()==4)
198  {
199  for(int m = 0; m != 4; m++)
200  for(int i = 0; i != 10; i++)
201  for(int j = 0; j != 10; j++)
202  HFmatrix[m][i][j] += tempmatrix[m][i][j];
203  HFcount++;
204  }
205 
206 
207 
208  outMatrices->addValues(*item);
209 
210  }
211 
212  for(int m = 0; m != 4; m++)
213  {
214  for(int i = 0; i != 10; i++)
215  {
216  for(int j = 0; j != 10; j++)
217  {
218  HBmatrix [m][i][j] /= HBcount;
219  HEmatrix [m][i][j] /= HEcount;
220  HFmatrix [m][i][j] /= HFcount;
221  HOmatrix [m][i][j] /= HOcount;
222  }
223  }
224  }
225 
226  std::vector<DetId> listResult = outMatrices->getAllChannels();
227 
228  int n_avg = 0;
229 
231  iSetup.get<HcalElectronicsMapRcd>().get(refEMap);
232 // iSetup.get<HcalElectronicsMapRcd>().get("reference",refEMap);
233  const HcalElectronicsMap* myRefEMap = refEMap.product();
234  std::vector<HcalGenericDetId> listEMap = myRefEMap->allPrecisionId();
235 
236  for (std::vector<HcalGenericDetId>::const_iterator it = listEMap.begin(); it != listEMap.end(); it++)
237  {
238  DetId mydetid = DetId(it->rawId());
239  if (std::find(listResult.begin(), listResult.end(), mydetid ) == listResult.end() )
240  {
241 // std::cout << "Cholesky Matrix not found for cell " << HcalGenericDetId(it->rawId());
242  if(it->isHcalDetId())
243  {
244  std::cout << "Cholesky Matrix not found for cell " << HcalGenericDetId(it->rawId());
245  HcalDetId hcalid2(it->rawId());
246  HcalCholeskyMatrix * item = new HcalCholeskyMatrix(it->rawId());
247  for(int m = 0; m != 4; m++)
248  {
249  for(int i = 0; i != 10; i++)
250  {
251  for(int j = 0; j != 10; j++)
252  {
253  if(j <= i){
254  if(hcalid2.subdet()==1) item->setValue(m,i,j,HBmatrix [m][i][j]);
255  if(hcalid2.subdet()==2) item->setValue(m,i,j,HEmatrix [m][i][j]);
256  if(hcalid2.subdet()==3) item->setValue(m,i,j,HFmatrix [m][i][j]);
257  if(hcalid2.subdet()==4) item->setValue(m,i,j,HOmatrix [m][i][j]);
258  }else{
259  if(hcalid2.subdet()==1) item->setValue(m,i,j,0);
260  if(hcalid2.subdet()==2) item->setValue(m,i,j,0);
261  if(hcalid2.subdet()==3) item->setValue(m,i,j,0);
262  if(hcalid2.subdet()==4) item->setValue(m,i,j,0);
263  }
264  }
265  }
266  }
267  outMatrices->addValues(*item);
268  std::cout << "... Average Matrix used\n";
269  n_avg++;
270  }
271  }
272  }
273 
274  std::vector<DetId> checkResult = outMatrices->getAllChannels();
275  int count = 0;
276  for(std::vector<DetId>::const_iterator it = checkResult.begin(); it != checkResult.end(); it++) count ++;
277 
278  std::cout << "There are " << count << " channels with Cholesky matrices.\n" << "Used " << n_avg << " average values.\n";
279 
280  ofstream cmatout(outfile.c_str());
281  HcalDbASCIIIO::dumpObject(cmatout, *outMatrices);
282 }
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:46
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:121
void HcalCholeskyDecomp::beginJob ( void  )
privatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 286 of file HcalCholeskyDecomp.cc.

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

Reimplemented from edm::EDAnalyzer.

Definition at line 292 of file HcalCholeskyDecomp.cc.

292  {
293 }

Member Data Documentation

std::string HcalCholeskyDecomp::outfile
private

Definition at line 52 of file HcalCholeskyDecomp.h.

Referenced by analyze(), and HcalCholeskyDecomp().