ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/yangyong/combineICEB/combineCalibConstantv2.C
Revision: 1.5
Committed: Mon Aug 27 21:37:39 2012 UTC (12 years, 8 months ago) by yangyong
Content type: text/plain
Branch: MAIN
CVS Tags: V2012combv2c, HEAD
Changes since 1.4: +42 -16 lines
Error occurred while calculating annotation data.
Log Message:
*** empty log message ***

File Contents

# Content
1 #include "rootheader.h"
2 #include "testSelection_cluster.h"
3
4 #include "common_functions.cc"
5 #include "foldEndcap.cc"
6
7 TRandom3 *rgen_;
8
9 #include "usefullcode.cc"
10
11 float interCalib_preCalib[170][360];
12 float interCalibEndcap_preCalib[2][101][101];
13
14 void copyConstant(float c1[170][360], float c2[170][360]){
15
16 for(int j=0; j<170; j++){
17 for(int k=0; k<360; k++){
18 c2[j][k] = c1[j][k];
19 }
20 }
21
22 }
23
24 void isAtEcalBarrelModuleCracks(int ieta, int iphi, bool &etaCracks, bool &phiCracks){
25 int absieta = abs(ieta);
26
27 etaCracks = false;
28 phiCracks = false;
29
30 if( absieta == 25 || absieta == 26 || absieta == 45 || absieta == 46 || absieta == 65 || absieta == 66) etaCracks = true;
31 if( iphi %20 == 1 || iphi %20 == 0) phiCracks = true;
32
33
34 }
35
36 float ic[50][170][360]; ///at most 20 set
37
38 float icv1[50][170][360];
39
40 int ndeadflagietaiphi_ic[50][170][360];
41
42 float icwt_period[50][170][360]; //pi0&eta combined for each period
43
44
45
46 bool isTestBeamSM(int iSM){
47
48
49
50 //if( iSM == 1 || iSM == 2 || iSM == 11 || iSM == 15 || iSM == 21 || iSM == 24) return true;
51
52 if( iSM == 1 || iSM == 11 || iSM == 15 || iSM == 24) return true;
53
54
55 else return false;
56
57 }
58
59
60 #include "effSigma.C"
61
62 #include "getCrystaldeadflag.cc"
63
64 #include "getCalibConstants.cc"
65
66 #include "gausfit.cc"
67
68 float corrGR10_P_V10_over_GR09_R_V6A[170][360];
69 float corrGR_R_311_V1A_over_GR09_R_V6A[170][360];
70 float corrGR_R_311_V1A_over_GR10_P_V10[170][360];
71
72
73 float CphiCorrin[170][360];
74 float CBSCorrin[170][360];
75
76 float fitWind = 3;
77 float sigmaTB = 0.55;
78 //float sigmaTB = 0.44;
79 //float sigmaTB = 0.95;
80
81 void fitHistogram(TH1F *h1, double res[]){
82
83 float mean = h1->GetMean();
84 float meanErr = h1->GetMeanError();
85 float rmsEff = 100 * h1->GetRMS();
86 float rmsEffErr = 100 * h1->GetRMSError();
87 float rmsGaus = 100 * h1->GetRMS();
88 float rmsGausErr = 100 * h1->GetRMSError();
89 if( h1->Integral()>50){
90 double resd[10];
91 effSigma(h1,resd);
92 rmsEff = resd[2]*100;
93 float resf[20];
94
95 fitgauswind2(h1,fitWind,fitWind,resf);
96 //fitgauswindRefit(h1,resf);
97 rmsGaus = resf[6]*100;
98 rmsGausErr = resf[3] * 100;
99 rmsEffErr = resf[3] * 100;
100 mean = resf[0];
101 meanErr = resf[1];
102 }
103 res[0] = mean;
104 res[1] = meanErr;
105 res[2] = rmsEff;
106 res[3] = rmsEffErr;
107 res[4] = rmsGaus;
108 res[5] = rmsGausErr;
109 }
110
111
112
113 float cpizv1[170][360];
114 float cpizv2[170][360];
115 float cpizv1in[170][360];
116 float cpizv2in[170][360];
117
118 float cetav1[170][360];
119 float cetav2[170][360];
120 float cetav1in[170][360];
121 float cetav2in[170][360];
122
123
124 float cpizoutput[170][360];
125 float cetaoutput[170][360];
126 float cpizetaoutput[170][360];
127
128 float cpizetaphibsoutput[170][360];
129 float cpizetaphibsoutputv1[170][360];
130
131 float cpizetaphibsprecaliboutput[170][360];
132 float cpizetaphibsprecaliboutputFinal[170][360];
133 float cpizetaphibsprecaliboutputv1[170][360];
134
135
136 float cphibsoutput[170][360];
137 float cphibsoutputv1[170][360];
138
139
140 float cpizoutputv1[170][360];
141 float cetaoutputv1[170][360];
142 float cpizetaoutputv1[170][360];
143
144
145 void rescaleConstTo(float Cin[170][360], float Corr[170][360]){
146
147 float mean = 0;
148 int nmean = 0;
149 for(int j=0; j< 170; j++){
150 for(int k=0; k< 360; k++){
151 if( Cin[j][k]> 0){
152 Cin[j][k] /= Corr[j][k];
153 nmean ++;
154 mean += Cin[j][k];
155 }
156 }
157 }
158 mean /= nmean;
159 for(int j=0; j< 170; j++){
160 for(int k=0; k< 360; k++){
161 if( Cin[j][k]> 0){
162 Cin[j][k] /= mean;
163 }
164 }
165 }
166 }
167
168 ///Cprecaib * c1 == c_new * c2
169 ///c2 = c1 / ( c_new / cprecalib)
170
171 void rescaleConstTov1(float Cin[170][360], float Corr[170][360]){
172
173 float mean = 0;
174 int nmean = 0;
175 for(int j=0; j< 170; j++){
176 for(int k=0; k< 360; k++){
177 if( Cin[j][k]> 0){
178 Cin[j][k] *= Corr[j][k];
179 nmean ++;
180 mean += Cin[j][k];
181 }
182 }
183 }
184 mean /= nmean;
185 for(int j=0; j< 170; j++){
186 for(int k=0; k< 360; k++){
187 if( Cin[j][k]> 0){
188 Cin[j][k] /= mean;
189 }
190 }
191 }
192 }
193
194
195 ///code to combined different pi0/eta EB IC for each laserTag
196
197
198 void combineCalibConstantv2(){
199
200
201
202 readInterCalibConstEBSimple("interCalibEB_GR_P_V39.txt",interCalib_preCalib);
203
204
205
206 map<int, string> smScaleFiles;
207
208
209
210
211 //SM-scale files Pi0
212
213 smScaleFiles[0] = "calibres/deriveCalibConst.dflag2.pe1.step1.iter1.root";
214 smScaleFiles[1] = "calibres/deriveCalibConst.dflag3.pe2.step1.iter1.root";
215
216 // number of IC periods
217 int nIC = 1;
218
219
220
221 map<int,string> icFiles;
222
223 //IC Pi0
224 icFiles[0] = "calibres/deriveCalibConst.dflag2.pe1.step4.iter30.txt";
225 //IC Eta
226 icFiles[1] = "calibres/deriveCalibConst.dflag3.pe2.step4.iter30.txt";
227
228 //crystal dead flag
229 getCrystaldeadflagBarrel_v1("crystal_deadflag_eb_dflag2.txt",ndeadflagietaiphi_ic[0]);
230 getCrystaldeadflagBarrel_v1("crystal_deadflag_eb_dflag3.txt",ndeadflagietaiphi_ic[1]);
231
232
233
234 vector<string> inputfileStat;
235 inputfileStat.push_back("calibres/deriveCalibConst.dflag2.pe1.step3.iter11.root");
236 inputfileStat.push_back("calibres/deriveCalibConst.dflag3.pe2.step3.iter11.root");
237
238
239
240 ofstream txtoutTocheck("combinedCalibConstantv2.txt");
241
242
243 int nConstantSet = int(icFiles.size());
244
245 cout<<" nConstantSet " << nConstantSet <<endl;
246
247
248 map<int,TH1F*> hh_smscales;
249 float cc[170][360];
250
251
252 int nMaxICSet = 50;
253 if( nConstantSet > nMaxICSet){
254 cout<<"more than " << nMaxICSet<<" "<< nConstantSet <<endl;
255 return;
256 }
257
258
259
260 float icwt[170][360];
261 float icwtv1[170][360];
262
263
264
265 // float icwt1[170][360];
266 // float icwt2[170][360];
267
268
269
270 for(int n=0; n< nConstantSet; n++){
271 string filename = smScaleFiles[n];
272 TFile *ff = new TFile(filename.c_str(),"read");
273 TH1F *hhtmp = (TH1F*)ff->Get("hh_corr_sm");
274 hh_smscales[n] = hhtmp;
275
276 filename = icFiles[n];
277
278 readInterCalibConstEBSimplev1(filename.c_str(),cc);
279
280 for(int j=0; j< 170; j++){
281 for(int k=0; k< 360; k++){
282 ic[n][j][k] = cc[j][k];
283 }
284 }
285
286
287 NormIetaAbsToUnitTestBeamSMOnly(ic[n]);
288
289 if(n==0) cout<<"check ic[0][1] 1 " << ic[n][0][1]<<endl;
290
291 SetSMScale(ic[n], hh_smscales[n]);
292
293 if(n==0) cout<<"check ic[0][1] 2 " << ic[n][0][1]<<endl;
294
295 NormCrystalDeadFlag_v1(ic[n],ndeadflagietaiphi_ic[n]);
296
297 if(n==0) cout<<"check ic[0][1] 3 " << ic[n][0][1]<<endl;
298
299
300 copyConstant(ic[n],icv1[n]);
301
302 /////for estimating precision
303 NormSMScaleToUnit(icv1[n]);
304 }
305
306 //return;
307
308
309 TFile *fnew = new TFile("combineCalibConstantv2.root","recreate");
310
311
312 TH1F *hh_csm[51][36][3]; //for each SM, all/centra/outer
313
314
315 //|ieta|<=45 , all, removing eta phi boundaries, at eta moduaries, at phi boduaris
316 TH1F *hh_csmtb_ietaMod12[50][5];
317 for(int n=0; n< nConstantSet; n++){
318 for(int k=0; k<5; k++){
319 TString histname = TString(Form("hh_csmtb_ietaMod12_%d_%d",n,k));
320 hh_csmtb_ietaMod12[n][k] = new TH1F(histname,histname,500,0,2);
321 }
322 }
323
324
325
326 TH1F *hh_c_ieta[50][170];
327 TH1F *hh_c_ietaAbs[50][85];
328
329
330
331
332 TH1F *hh_csmtb_ietaTT[50][34];
333 TH1F *hh_csmtb_ietaTTAbs[50][17];
334 TH1F *hh_csmco_ietaTTAbs[50][17];
335
336 TH1F *hh_csmco_ietaTT[50][34];
337
338 TH1F *hh_csmall_ietaTTAbs[50][17];
339
340
341
342 TH1F *hh_wtavg_csmtb_ietaTT[34];
343 TH1F *hh_wtavg_csmtb_ietaTTAbs[17];
344 TH1F *hh_wtavg_csmco_ietaTT[34];
345 TH1F *hh_wtavg_csmco_ietaTTAbs[17];
346
347 TH1F *hh_wtavg_csmall_ietaTTAbs[17];
348
349
350 TH1F *hh_res_csmtbietaTT[50][3];
351 TH1F *hh_res_csmtbietaTTAbs[50][3];
352
353 TH1F *hh_res_csmcoietaTT[50][3];
354 TH1F *hh_res_csmcoietaTTAbs[50][3];
355
356 TH1F *hh_res_csmallietaTTAbs[50][3];
357
358
359
360 TH1F *hh_res_wtavg_csmtbietaTT[3]; //mean/rmsEff/rmsGaus
361
362 TH1F *hh_res_wtavg_csmtbietaTTAbs[3]; //mean/rmsEff/rmsGaus
363
364 TH1F *hh_res_wtavg_csmallietaTTAbs[3]; //mean/rmsEff/rmsGaus
365
366
367 TH1F *hh_res_wtavg_csmcoietaTT[3]; //mean/rmsEff/rmsGaus
368 TH1F *hh_res_wtavg_csmcoietaTTAbs[3]; //mean/rmsEff/rmsGaus
369
370 TH1F *hh_diff_csmtb_ietaTTAbs[50][50][17];
371 TH1F *hh_diff_csmtb_ietaTT[50][50][34];
372 TH1F *hh_diff_csmco_ietaTTAbs[50][50][17];
373 TH1F *hh_diff_csmco_ietaTT[50][50][34];
374 TH1F *hh_diff_csmall_ietaTT[50][50][34];
375 TH1F *hh_diff_csmall_ietaTTAbs[50][50][17];
376
377 TH1F *hh_diff_csm[50][50][36][3]; //by each SM, all/central/outer
378
379
380 TH1F *hh_res_csm[51][3][3];
381
382 TH2F *hh2_c[51];
383 TH2F *hh2_c_period[51];
384
385
386 float xbinLow[35];
387 for(int j=0; j< 35; j++){
388 float xbin = -85 + 5*j;
389 xbinLow[j] = xbin;
390 }
391 float xbinLow1[35];
392 for(int j=0; j<= 17 ; j++){
393 float xbin = 5 * j;
394 xbinLow1[j] = xbin+1;
395 }
396
397
398 TH1F *hh_c_ietaAbs_period[50][85];
399 TH1F *hh_c_ietaTTAbs_period[50][17];
400 TH1F *hh_c_smtbietaTTAbs_period[50][17];
401
402
403 for(int n=0; n< nIC+1; n++){
404 for(int k=0; k< 85; k++){
405 TString histname = TString(Form("hh_c_ietaAbs_period_%d_%d",n,k));
406 hh_c_ietaAbs_period[n][k] = new TH1F(histname,histname,500,0,2);
407 }
408 for(int k=0; k< 17; k++){
409 TString histname = TString(Form("hh_c_ietaTTAbs_period_%d_%d",n,k));
410 hh_c_ietaTTAbs_period[n][k] = new TH1F(histname,histname,500,0,2);
411 histname = TString(Form("hh_c_smtbietaTTAbs_period_%d_%d",n,k));
412 hh_c_smtbietaTTAbs_period[n][k] = new TH1F(histname,histname,500,0,2);
413 }
414 }
415
416
417
418 TH1F *hh_res_cietaAbs_period[50][3];
419 TH1F *hh_res_cietaTTAbs_period[50][3];
420 TH1F *hh_res_csmtbietaTTAbs_period[50][3];
421 for(int n=0; n< nIC+1; n++){
422 for(int k=0;k<3; k++){
423 TString histname = TString(Form("hh_res_cietaAbs_period_%d_%d",n,k));
424 hh_res_cietaAbs_period[n][k] = new TH1F(histname,histname,85,1,86);
425 histname = TString(Form("hh_res_cietaTTAbs_period_%d_%d",n,k));
426 hh_res_cietaTTAbs_period[n][k] = new TH1F(histname,histname,17,xbinLow1);
427 histname = TString(Form("hh_res_csmtbietaTTAbs_period_%d_%d",n,k));
428 hh_res_csmtbietaTTAbs_period[n][k] = new TH1F(histname,histname,17,xbinLow1);
429 }
430 }
431
432
433
434 for(int n=0; n< nIC; n++){
435 TString histname = TString(Form("hh2_c_period_%d",n));
436 hh2_c_period[n] = new TH2F(histname,histname,171,-85,86,360,1,361);
437
438 }
439
440
441 for(int n=0; n< nConstantSet+1; n++){
442 TString histname = TString(Form("hh2_c_%d",n));
443 hh2_c[n] = new TH2F(histname,histname,171,-85,86,360,1,361);
444
445 }
446
447 for(int n=0; n< nConstantSet+1; n++){
448 for(int j=0;j<36;j++){
449 for(int k=0;k<3; k++){
450 TString histname = TString(Form("hh_csm_%d_%d_%d",n,j,k));
451 hh_csm[n][j][k] = new TH1F(histname,histname,500,0,2);
452 }
453 }
454
455 for(int j=0;j<3; j++){
456 for(int k=0;k<3; k++){
457 TString histname = TString(Form("hh_res_csm_%d_%d_%d",n,j,k));
458 hh_res_csm[n][j][k] = new TH1F(histname,histname,36,1,37);
459 }
460 }
461 }
462
463
464
465 for(int n=0; n< nConstantSet; n++){
466
467
468 for(int j=0; j<17; j++){
469 TString histname = TString(Form("hh_csmtb_ietaTTAbs_%d_%d",n,j));
470 hh_csmtb_ietaTTAbs[n][j] = new TH1F(histname,histname,500,0,2);
471 histname = TString(Form("hh_csmco_ietaTTAbs_%d_%d",n,j));
472 hh_csmco_ietaTTAbs[n][j] = new TH1F(histname,histname,500,0,2);
473
474 histname = TString(Form("hh_csmall_ietaTTAbs_%d_%d",n,j));
475 hh_csmall_ietaTTAbs[n][j] = new TH1F(histname,histname,500,0,2);
476
477 }
478
479
480 for(int j=0; j<34; j++){
481 TString histname = TString(Form("hh_csmtb_ietaTT_%d_%d",n,j));
482 hh_csmtb_ietaTT[n][j] = new TH1F(histname,histname,500,0,2);
483 histname = TString(Form("hh_csmco_ietaTT_%d_%d",n,j));
484 hh_csmco_ietaTT[n][j] = new TH1F(histname,histname,500,0,2);
485 }
486 }
487
488 for(int j=0; j<34; j++){
489 TString histname = TString(Form("hh_wtavg_csmtb_ietaTT_%d",j));
490 hh_wtavg_csmtb_ietaTT[j] = new TH1F(histname,histname,500,0,2);
491 histname = TString(Form("hh_wtavg_csmco_ietaTT_%d",j));
492 hh_wtavg_csmco_ietaTT[j] = new TH1F(histname,histname,500,0,2);
493 }
494 for(int j=0; j<17; j++){
495 TString histname = TString(Form("hh_wtavg_csmtb_ietaTTAbs_%d",j));
496 hh_wtavg_csmtb_ietaTTAbs[j] = new TH1F(histname,histname,500,0,2);
497 histname = TString(Form("hh_wtavg_csmco_ietaTTAbs_%d",j));
498 hh_wtavg_csmco_ietaTTAbs[j] = new TH1F(histname,histname,500,0,2);
499
500 histname = TString(Form("hh_wtavg_csmall_ietaTTAbs_%d",j));
501 hh_wtavg_csmall_ietaTTAbs[j] = new TH1F(histname,histname,500,0,2);
502
503 }
504
505
506 TH1F *hh_c_deadflag[50][20];
507
508 TH1F *hh_c_deadflag_period[50][20];
509 TH1F *hh_cc_deadflag_period[50][20];
510 TH1F *hh_cc1_deadflag_period[50][20];
511
512 for(int j=0; j< nConstantSet; j++){
513 for(int k=0; k<20; k++){
514 TString histname = TString(Form("hh_c_deadflag_%d_%d",j,k));
515 hh_c_deadflag[j][k] = new TH1F(histname,histname,500,0,2);
516
517 histname = TString(Form("hh_c_deadflag_period_%d_%d",j,k));
518 hh_c_deadflag_period[j][k] = new TH1F(histname,histname,500,0,2);
519
520 histname = TString(Form("hh_cc_deadflag_period_%d_%d",j,k));
521 hh_cc_deadflag_period[j][k] = new TH1F(histname,histname,500,0,2);
522 histname = TString(Form("hh_cc1_deadflag_period_%d_%d",j,k));
523 hh_cc1_deadflag_period[j][k] = new TH1F(histname,histname,500,0,2);
524
525 }
526 }
527
528
529 for(int j=0; j< nConstantSet; j++){
530 for(int k=0; k<3; k++){
531
532 TString histname = TString(Form("hh_res_csmtbietaTT_%d_%d",j,k));
533 hh_res_csmtbietaTT[j][k] = new TH1F(histname,histname,34,xbinLow);
534 histname = TString(Form("hh_res_csmtbietaTTAbs_%d_%d",j,k));
535 hh_res_csmtbietaTTAbs[j][k] = new TH1F(histname,histname,17,xbinLow1);
536
537
538 histname = TString(Form("hh_res_csmallietaTTAbs_%d_%d",j,k));
539 hh_res_csmallietaTTAbs[j][k] = new TH1F(histname,histname,17,xbinLow1);
540
541
542 histname = TString(Form("hh_res_csmcoietaTT_%d_%d",j,k));
543 hh_res_csmcoietaTT[j][k] = new TH1F(histname,histname,34,xbinLow);
544 histname = TString(Form("hh_res_csmcoietaTTAbs_%d_%d",j,k));
545 hh_res_csmcoietaTTAbs[j][k] = new TH1F(histname,histname,17,xbinLow1);
546
547 }
548 }
549
550 for(int k=0; k<3; k++){
551 TString histname = TString(Form("hh_res_wtavg_csmtbietaTT_%d",k));
552 hh_res_wtavg_csmtbietaTT[k] = new TH1F(histname,histname,34,xbinLow);
553 histname = TString(Form("hh_res_wtavg_csmtbietaTTAbs_%d",k));
554 hh_res_wtavg_csmtbietaTTAbs[k] = new TH1F(histname,histname,17,xbinLow1);
555
556 histname = TString(Form("hh_res_wtavg_csmallietaTTAbs_%d",k));
557 hh_res_wtavg_csmallietaTTAbs[k] = new TH1F(histname,histname,17,xbinLow1);
558
559 histname = TString(Form("hh_res_wtavg_csmcoietaTT_%d",k));
560 hh_res_wtavg_csmcoietaTT[k] = new TH1F(histname,histname,34,xbinLow);
561 histname = TString(Form("hh_res_wtavg_csmcoietaTTAbs_%d",k));
562 hh_res_wtavg_csmcoietaTTAbs[k] = new TH1F(histname,histname,17,xbinLow1);
563 }
564 TH2F *hh2_diff[50][50];
565
566
567 TH1F *hh_res_diff_csmtbietaTTAbs[50][50][3];
568 TH1F *hh_res_diff_csmcoietaTTAbs[50][50][3];
569 TH1F *hh_res_diff_csmtbietaTT[50][50][3];
570 TH1F *hh_res_diff_csmcoietaTT[50][50][3];
571 TH1F *hh_res_diff_csmallietaTT[50][50][3];
572 TH1F *hh_res_diff_csmallietaTTAbs[50][50][3];
573
574
575 for(int n=0; n< nConstantSet; n++){
576 for(int k=n+1; k< nConstantSet; k++){
577 TString histname = TString (Form("hh2_diff_%dand%d",n,k));
578 hh2_diff[n][k] = new TH2F(histname,histname,171,-85,86,360,1,361);
579
580 for(int j=0; j<36; j++){
581 for(int m=0; m<3; m++){
582 histname = TString ( Form("hh_diff_csm_%dand%d_%d_%d",n,k,j,m));
583 hh_diff_csm[n][k][j][m] = new TH1F(histname,histname,50,-0.1,0.1);
584 }
585 }
586
587 for(int j=0; j<17; j++){
588 histname = TString (Form("hh_diff_csmtb_ietaTTAbs_%dand%d_%d",n,k,j));
589 hh_diff_csmtb_ietaTTAbs[n][k][j] = new TH1F(histname,histname,500,-0.1,0.1);
590 histname = TString (Form("hh_diff_csmco_ietaTTAbs_%dand%d_%d",n,k,j));
591 hh_diff_csmco_ietaTTAbs[n][k][j] = new TH1F(histname,histname,500,-0.1,0.1);
592 histname = TString (Form("hh_diff_csmall_ietaTTAbs_%dand%d_%d",n,k,j));
593 hh_diff_csmall_ietaTTAbs[n][k][j] = new TH1F(histname,histname,500,-0.1,0.1);
594
595 }
596 for(int j=0; j<34; j++){
597 histname = TString (Form("hh_diff_csmtb_ietaTT_%dand%d_%d",n,k,j));
598 hh_diff_csmtb_ietaTT[n][k][j] = new TH1F(histname,histname,500,-0.1,0.1);
599 histname = TString (Form("hh_diff_csmco_ietaTT_%dand%d_%d",n,k,j));
600 hh_diff_csmco_ietaTT[n][k][j] = new TH1F(histname,histname,500,-0.1,0.1);
601
602 histname = TString (Form("hh_diff_csmall_ietaTT_%dand%d_%d",n,k,j));
603 hh_diff_csmall_ietaTT[n][k][j] = new TH1F(histname,histname,500,-0.1,0.1);
604
605 }
606 for(int j=0;j<3; j++){
607 histname = TString(Form("hh_res_diff_csmtbietaTTAbs_%dand%d_%d",n,k,j));
608 hh_res_diff_csmtbietaTTAbs[n][k][j] = new TH1F(histname,histname,17,xbinLow1);
609 histname = TString(Form("hh_res_diff_csmcoietaTTAbs_%dand%d_%d",n,k,j));
610 hh_res_diff_csmcoietaTTAbs[n][k][j] = new TH1F(histname,histname,17,xbinLow1);
611 histname = TString(Form("hh_res_diff_csmtbietaTT_%dand%d_%d",n,k,j));
612 hh_res_diff_csmtbietaTT[n][k][j] = new TH1F(histname,histname,34,xbinLow);
613 histname = TString(Form("hh_res_diff_csmcoietaTT_%dand%d_%d",n,k,j));
614 hh_res_diff_csmcoietaTT[n][k][j] = new TH1F(histname,histname,34,xbinLow);
615
616 histname = TString(Form("hh_res_diff_csmallietaTT_%dand%d_%d",n,k,j));
617 hh_res_diff_csmallietaTT[n][k][j] = new TH1F(histname,histname,34,xbinLow);
618 histname = TString(Form("hh_res_diff_csmallietaTTAbs_%dand%d_%d",n,k,j));
619 hh_res_diff_csmallietaTTAbs[n][k][j] = new TH1F(histname,histname,17,xbinLow1);
620 }
621
622 }
623 }
624
625
626 TH2F *hh2_largeICdiff[50][50];
627 for(int n=0; n< nIC; n++){
628 for(int k=n+1; k< nIC; k++){
629 TString histname = TString (Form("hh2_largeICdiff_%dand%d",n,k));
630 hh2_largeICdiff[n][k] =new TH2F(histname,histname,171,-85,86,360,1,361);
631 }
632 }
633 TH2F *hh2_largeICdiff_all =new TH2F("hh2_largeICdiff_all","hh2_largeICdiff_all",171,-85,86,360,1,361);
634
635
636
637 TH1F *hh_res_ieta[50][4];////[4] means the stat error.
638
639 for(int n=0; n< int(inputfileStat.size()); n++){
640 for(int k=0;k<4;k++){
641 string filename = string(Form("hh_res_ieta_%d_%d",n,k));
642 hh_res_ieta[n][k] =new TH1F(filename.c_str(),filename.c_str(),171,-85,86);
643 }
644 }
645 TH1F *hh_statErr_ietaAbs[50];
646 for(int n=0; n< int(inputfileStat.size()); n++){
647 string filename = string(Form("hh_statErr_ietaAbs_%d",n));
648 hh_statErr_ietaAbs[n] =new TH1F(filename.c_str(),filename.c_str(),85,1,86);
649 }
650 TH1F *hh_statErr_ietaTTAbs[50];
651 for(int n=0; n< int(inputfileStat.size()); n++){
652 string filename = string(Form("hh_statErr_ietaTTAbs_%d",n));
653 hh_statErr_ietaTTAbs[n] =new TH1F(filename.c_str(),filename.c_str(),17,xbinLow1);
654 }
655
656 TH1F *hh_statErr_ietaAbs_period[50]; //pi0&eta combined for each period
657 for(int j=0; j< nIC; j++){
658 string filename = string(Form("hh_statErr_ietaAbs_period_%d",j));
659 hh_statErr_ietaAbs_period[j]=new TH1F(filename.c_str(),filename.c_str(),85,1,86);
660 }
661
662
663 ///using MC-based forumula + 0.5/1 % sys.
664 // 7.4/resolution * 17 /sqrt(N) * sqrt( 1+ 1.8/sob) + 0.5/1%
665
666 for(int j=0; j< int(inputfileStat.size());j++){
667 string filename = inputfileStat[j];
668 TFile *f1 = new TFile(filename.c_str(),"read");
669 for(int k=0;k<4;k++){
670 string histname = string (Form("hh_res_ieta_%d",k));
671 TH1F *hhtmp = (TH1F*)f1->Get(histname.c_str());
672 if(hhtmp==0){
673 cout<<"empty hh_res_ieta_ ! "<<endl;
674 return;
675 }
676
677 hh_res_ieta[j][k]->Add(hhtmp);
678 }
679
680 if( f1->Get("hh_res_ietaTTAbs_0") !=0){
681 TH1F *htmp1 = (TH1F*)f1->Get("hh_res_ietaTTAbs_0");
682 TH1F *htmp2 = (TH1F*)f1->Get("hh_res_ietaTTAbs_1");
683 TH1F *htmp3 = (TH1F*)f1->Get("hh_res_ietaTTAbs_2");
684 TH1F *htmp4 = (TH1F*)f1->Get("hh_res_ietaTTAbs_3");
685 for(int b=1; b<= 17; b++){
686 float m0 = htmp1->GetBinContent(b);
687 float sig = htmp3->GetBinContent(b);
688 float sb = htmp4->GetBinContent(b);
689 float n = htmp2->GetBinContent(b)/ (360*5*2*2);
690 float statErr = (sig/m0*100)/7.4 * 17/sqrt(n) * sqrt( 1+ 1.8/sb);
691 hh_statErr_ietaTTAbs[j]->SetBinContent(b,statErr);
692 }
693 }
694
695 }
696
697
698
699
700 for(int j=0; j< int(inputfileStat.size());j++){
701
702 for(int n=1; n<=85 ; n++){
703 float npiz = 0.5*(hh_res_ieta[j][1]->GetBinContent(87+n-1) + hh_res_ieta[j][1]->GetBinContent(85-(n-1)) ) /(360*2) ;
704 float sob = 0.5*(hh_res_ieta[j][3]->GetBinContent(87+n-1) + hh_res_ieta[j][3]->GetBinContent(85-(n-1)) );
705 float reso = 0.5*(hh_res_ieta[j][2]->GetBinContent(87+n-1) + hh_res_ieta[j][2]->GetBinContent(85-(n-1)) )/hh_res_ieta[j][0]->GetBinContent(87+n-1);
706
707 if(npiz<=0){
708 cout<<"empty histogram!!" <<endl;
709 return;
710 }
711
712 float statErr = (reso*100)/7.4 * 17/sqrt(npiz) * sqrt( 1+ 1.8/sob);
713
714 cout<<"statErr " << reso <<" "<< npiz <<" "<< sob <<" "<< statErr <<endl;
715
716 hh_statErr_ietaAbs[j]->SetBinContent(n,statErr);
717 }
718 }
719
720 //return;
721
722
723 ///the combined IC from all ICs
724 ofstream txtout("interCalibConstants.combinedPi0EtaAllPeriod.EcalBarrel.txt",ios::out);
725
726
727 ofstream txtout_period[50]; //pi0eta combined for each period
728 for(int j=0; j< nIC; j++){
729 string filename = string(Form("interCalibConstants.combinedPi0EtaPeriod%d.EcalBarrel.txt",j));
730 txtout_period[j].open(filename.c_str(),ios::out);
731 }
732
733 ofstream txtout_periodv1[50]; //pi0eta combined for each period / averaged all
734 for(int j=0; j< nIC; j++){
735 string filename = string(Form("interCalibConstants.combinedPi0EtaPeriod%d.EcalBarrel.txtv1",j));
736 txtout_periodv1[j].open(filename.c_str(),ios::out);
737 }
738
739
740 cout<<"fill" <<endl;
741
742
743
744
745 for(int n=0; n< nConstantSet; n++){
746
747 for(int j=0; j<170; j++){
748
749 int ieta = j-85;
750 if( ieta >=0) ieta += 1;
751
752 for(int k=0; k<360; k++){
753 int iphi = k;
754 if( k==0) iphi = 360;
755 int ietaTTAbs = (abs(ieta)-1)/5;
756 int iSM = (iphi-1)/20+1;
757 if( ieta<0) iSM += 18;
758 int smTB = isTestBeamSM(iSM);
759 int beta = ieta+85+1;
760 int bphi = iphi;
761 float c = icv1[n][j][k]; ///sm normalized to unit
762 if( c>0){
763
764 int ndflag = -1;
765 ndflag = ndeadflagietaiphi_ic[n][j][k];
766
767 if( ndflag <0){
768 cout<<"wrong dflag? " << ndflag <<" "<<n<<" "<<j<<" "<<k<<endl;
769 return;
770 }
771 hh_c_deadflag[n][ndflag]->Fill(c);
772
773
774 hh2_c[n]->SetBinContent(beta,bphi,ic[n][j][k]);
775
776 int ietaflag[3] = {abs(ieta)<25,abs(ieta)>=25 && abs(ieta)<60,abs(ieta)>=60};
777 for(int jj=0;jj<3; jj++){
778 if( ietaflag[jj]==0) continue;
779 hh_csm[n][iSM-1][jj]->Fill(c);
780 }
781
782 if( smTB){
783 hh_csmtb_ietaTTAbs[n][ietaTTAbs]->Fill(c);
784 hh_csmtb_ietaTT[n][j/5]->Fill(c);
785
786 bool etaCracks;
787 bool phiCracks;
788 isAtEcalBarrelModuleCracks(ieta,iphi,etaCracks,phiCracks);
789 int crackFlag[5] = {1,!etaCracks && !phiCracks, etaCracks, phiCracks, etaCracks || phiCracks};
790 for(int t =0; t<5; t++){
791 if(crackFlag[t]==0) continue;
792 hh_csmtb_ietaMod12[n][t]->Fill(c);
793 }
794
795 }else{
796 hh_csmco_ietaTTAbs[n][ietaTTAbs]->Fill(c);
797 hh_csmco_ietaTT[n][j/5]->Fill(c);
798 }
799
800 hh_csmall_ietaTTAbs[n][ietaTTAbs]->Fill(c);
801
802 }else{
803 hh2_c[n]->SetBinContent(beta,bphi,-1);
804 }
805
806 }
807
808 }
809 }
810
811
812 for(int j=0; j<170; j++){
813
814 int ieta = j-85;
815 if( ieta >=0) ieta += 1;
816
817 for(int k=0; k<360; k++){
818 int iphi = k;
819 if( k==0) iphi = 360;
820 int ietaTTAbs = (abs(ieta)-1)/5;
821 int iSM = (iphi-1)/20+1;
822 if( ieta<0) iSM += 18;
823 int smTB = isTestBeamSM(iSM);
824 int beta = ieta+85+1;
825 int bphi = iphi;
826
827 for(int n1 =0; n1 < nConstantSet; n1++){
828 for(int n2 =n1+1; n2 < nConstantSet; n2++){
829 if(ic[n1][j][k] >0 && ic[n2][j][k] > 0){
830
831 float diff = ic[n1][j][k] - ic[n2][j][k];
832 float average = 0.5*(ic[n1][j][k] + ic[n2][j][k]);
833 diff /= average;
834
835 hh2_diff[n1][n2] ->SetBinContent(beta,bphi, diff);
836
837 if(smTB){
838 hh_diff_csmtb_ietaTTAbs[n1][n2][ietaTTAbs]->Fill(diff);
839 hh_diff_csmtb_ietaTT[n1][n2][j/5]->Fill(diff);
840 }else{
841 hh_diff_csmco_ietaTTAbs[n1][n2][ietaTTAbs]->Fill(diff);
842 hh_diff_csmco_ietaTT[n1][n2][j/5]->Fill(diff);
843 }
844 hh_diff_csmall_ietaTT[n1][n2][j/5]->Fill(diff);
845 hh_diff_csmall_ietaTTAbs[n1][n2][ietaTTAbs]->Fill(diff);
846
847 }else{
848 hh2_diff[n1][n2] ->SetBinContent(beta,bphi,-1);
849 }
850 }
851 }
852 }
853 }
854
855
856
857 cout<<"fitting "<<endl;
858 double resfit[10];
859
860
861
862 for(int n1 =0; n1 < nConstantSet; n1++){
863 for(int n2 =n1+1; n2 < nConstantSet; n2++){
864
865 for(int j=0;j<34; j++){
866 fitHistogram(hh_diff_csmtb_ietaTT[n1][n2][j],resfit);
867 for(int n=0;n<3; n++){
868 hh_res_diff_csmtbietaTT[n1][n2][n]->SetBinContent(j+1,resfit[2*n]);
869 hh_res_diff_csmtbietaTT[n1][n2][n]->SetBinError(j+1,resfit[2*n+1]);
870 }
871 fitHistogram(hh_diff_csmco_ietaTT[n1][n2][j],resfit);
872 for(int n=0;n<3; n++){
873 hh_res_diff_csmcoietaTT[n1][n2][n]->SetBinContent(j+1,resfit[2*n]);
874 hh_res_diff_csmcoietaTT[n1][n2][n]->SetBinError(j+1,resfit[2*n+1]);
875 }
876 fitHistogram(hh_diff_csmall_ietaTT[n1][n2][j],resfit);
877 for(int n=0;n<3; n++){
878 hh_res_diff_csmallietaTT[n1][n2][n]->SetBinContent(j+1,resfit[2*n]);
879 hh_res_diff_csmallietaTT[n1][n2][n]->SetBinError(j+1,resfit[2*n+1]);
880 }
881
882 }
883 for(int j=0;j<17; j++){
884 fitHistogram(hh_diff_csmtb_ietaTTAbs[n1][n2][j],resfit);
885 for(int n=0;n<3; n++){
886 hh_res_diff_csmtbietaTTAbs[n1][n2][n]->SetBinContent(j+1,resfit[2*n]);
887 hh_res_diff_csmtbietaTTAbs[n1][n2][n]->SetBinError(j+1,resfit[2*n+1]);
888 }
889 fitHistogram(hh_diff_csmco_ietaTTAbs[n1][n2][j],resfit);
890 for(int n=0;n<3; n++){
891 hh_res_diff_csmcoietaTTAbs[n1][n2][n]->SetBinContent(j+1,resfit[2*n]);
892 hh_res_diff_csmcoietaTTAbs[n1][n2][n]->SetBinError(j+1,resfit[2*n+1]);
893 }
894 fitHistogram(hh_diff_csmall_ietaTTAbs[n1][n2][j],resfit);
895 for(int n=0;n<3; n++){
896 hh_res_diff_csmallietaTTAbs[n1][n2][n]->SetBinContent(j+1,resfit[2*n]);
897 hh_res_diff_csmallietaTTAbs[n1][n2][n]->SetBinError(j+1,resfit[2*n+1]);
898 }
899
900 }
901
902 }
903 }
904
905
906 for(int k=0;k<nConstantSet; k++){
907
908
909 for(int j=0;j<34; j++){
910 fitHistogram(hh_csmtb_ietaTT[k][j],resfit);
911 for(int n=0;n<3; n++){
912 hh_res_csmtbietaTT[k][n]->SetBinContent(j+1,resfit[2*n]);
913 hh_res_csmtbietaTT[k][n]->SetBinError(j+1,resfit[2*n+1]);
914 }
915 }
916 for(int j=0;j<17; j++){
917 fitHistogram(hh_csmtb_ietaTTAbs[k][j],resfit);
918 for(int n=0;n<3; n++){
919 hh_res_csmtbietaTTAbs[k][n]->SetBinContent(j+1,resfit[2*n]);
920 hh_res_csmtbietaTTAbs[k][n]->SetBinError(j+1,resfit[2*n+1]);
921 }
922 }
923
924 for(int j=0;j<17; j++){
925 fitHistogram(hh_csmall_ietaTTAbs[k][j],resfit);
926 for(int n=0;n<3; n++){
927 hh_res_csmallietaTTAbs[k][n]->SetBinContent(j+1,resfit[2*n]);
928 hh_res_csmallietaTTAbs[k][n]->SetBinError(j+1,resfit[2*n+1]);
929 }
930 }
931
932
933
934 for(int j=0;j<34; j++){
935 fitHistogram(hh_csmco_ietaTT[k][j],resfit);
936 for(int n=0;n<3; n++){
937 hh_res_csmcoietaTT[k][n]->SetBinContent(j+1,resfit[2*n]);
938 hh_res_csmcoietaTT[k][n]->SetBinError(j+1,resfit[2*n+1]);
939 }
940 }
941 for(int j=0;j<17; j++){
942 fitHistogram(hh_csmco_ietaTTAbs[k][j],resfit);
943 for(int n=0;n<3; n++){
944 hh_res_csmcoietaTTAbs[k][n]->SetBinContent(j+1,resfit[2*n]);
945 hh_res_csmcoietaTTAbs[k][n]->SetBinError(j+1,resfit[2*n+1]);
946 }
947 }
948
949 }
950
951 cout<<"combining " <<endl;
952
953
954 float wtSumC_period[50] = {0};
955 float wtSumS_period[50] = {0};
956
957
958
959 for(int j=0; j<170; j++){
960 int ieta = j-85;
961 if( ieta >=0) ieta += 1;
962 for(int k=0; k<360; k++){
963 int iphi = k;
964 if( k==0) iphi = 360;
965 int ietaTTAbs = (abs(ieta)-1)/5;
966 int iSM = (iphi-1)/20+1;
967 if( ieta<0) iSM += 18;
968 int smTB = isTestBeamSM(iSM);
969 int beta = ieta+85+1;
970 int bphi = iphi;
971
972
973 float wtSumC = 0;
974 float wtSumS = 0;
975
976 for(int n=0; n< nIC; n++){ ///for each period
977 wtSumC_period[n] = 0;
978 wtSumS_period[n] = 0;
979 }
980
981
982 for(int n=0; n< nConstantSet; n++){
983 float c = ic[n][j][k];
984
985
986
987
988 //float sigma = hh_res_csmtbietaTTAbs[n][2]->GetBinContent(ietaTTAbs+1);
989 //if( sigma > sigmaTB){
990 //sigma = sqrt( sigma * sigma - sigmaTB * sigmaTB);
991 //}
992 float statErr = 0;
993 float sysErr = 0.5;
994 if(abs(ieta)>=60) sysErr = 1;
995
996 // if(n>=0 && n<=1){
997 // statErr = hh_res_diff_csmallietaTTAbs[0][1][2]->GetBinContent(ietaTTAbs+1)/sqrt(2);
998 // }else if( n>=2 && n<=3){
999 // statErr = hh_res_diff_csmallietaTTAbs[2][3][2]->GetBinContent(ietaTTAbs+1)/sqrt(2);
1000 // }
1001
1002
1003 //now use MC-predicted precision
1004 statErr = hh_statErr_ietaAbs[n]->GetBinContent(abs(ieta));
1005
1006 float sigma = sqrt( statErr * statErr + sysErr * sysErr);
1007
1008 //if( ieta==1) cout<<"sigma " << ieta<<" n"<< n<<" "<< sigma <<" "<< statErr <<" "<< sysErr <<endl;
1009
1010 if( c > 0){
1011
1012 float tmp1 = c/ ( sigma * sigma);
1013 float tmp2 = 1/(sigma * sigma);
1014 int nperiod = n% nIC;
1015
1016 wtSumC_period[nperiod] += tmp1;
1017 wtSumS_period[nperiod] += tmp2;
1018
1019 if( c> 0){ //all combined
1020 wtSumC += tmp1;
1021 wtSumS += tmp2;
1022 }
1023 }
1024 }
1025
1026
1027 if( wtSumC > 0){ //combined all
1028 icwt[j][k] = wtSumC / wtSumS;
1029 hh2_c[nConstantSet]->SetBinContent(beta,bphi,icwt[j][k]);
1030 }else{
1031 icwt[j][k] = -1;
1032 hh2_c[nConstantSet]->SetBinContent(beta,bphi,-1);
1033 }
1034
1035 for(int n=0; n< nIC; n++){ ///for each period
1036 if( wtSumC_period[n] > 0){
1037 icwt_period[n][j][k] = wtSumC_period[n] / wtSumS_period[n];
1038 hh2_c_period[n]->SetBinContent(beta,bphi,icwt_period[n][j][k]);
1039 }else{
1040 icwt_period[n][j][k] = -1;
1041 hh2_c_period[n]->SetBinContent(beta,bphi,-1);
1042 }
1043 }
1044
1045 }
1046 }
1047
1048
1049
1050 float statErr_allCombined[85] = {0} ;
1051
1052 for(int b=1; b<= hh_statErr_ietaAbs[0]->GetNbinsX(); b++){
1053 float sumStatErr2 = 0;
1054 for(int n=0; n< nConstantSet; n++){
1055 float statErr = hh_statErr_ietaAbs[n]->GetBinContent(b);
1056 sumStatErr2 += 1./ ( statErr * statErr );
1057 }
1058 float statErr = sqrt( 1./ sumStatErr2 );
1059 statErr_allCombined[b-1] = statErr;
1060
1061 cout<<" statErr_allCombined " << b <<" "<< statErr_allCombined[b-1] << " % "<<endl;
1062
1063 }
1064
1065
1066 ///Stat error for each period
1067 for(int j=0; j< nIC; j++){
1068 for(int b=1; b<= hh_statErr_ietaAbs[0]->GetNbinsX();b++){
1069 float statErrPi0 = hh_statErr_ietaAbs[j]->GetBinContent(b);
1070 float statErrEta = hh_statErr_ietaAbs[j+nIC]->GetBinContent(b);
1071 float statErr = 1/(statErrPi0*statErrPi0) + 1./(statErrEta*statErrEta);
1072 statErr = sqrt(1/statErr);
1073 hh_statErr_ietaAbs_period[j]->SetBinContent(b,statErr);
1074 }
1075 }
1076
1077
1078 txtoutTocheck <<"checkme " <<endl;
1079
1080 for(int j=0; j<170; j++){
1081
1082 int ieta = j-85;
1083 if( ieta >=0) ieta += 1;
1084
1085
1086 int absieta = abs(ieta);
1087
1088 for(int k=0; k<360; k++){
1089 int iphi = k;
1090 if( k==0) iphi = 360;
1091 int beta = ieta+85+1;
1092 int bphi = iphi;
1093 int ietaTTAbs = (abs(ieta)-1)/5;
1094
1095 bool largeIC = false;
1096
1097 for(int n=0; n< nIC; n++){ ///for each period
1098 if( icwt_period[n][j][k] > 0 && (icwt_period[n][j][k] >1.2 || icwt_period[n][j][k] < 0.8)){
1099 largeIC = true;
1100 }
1101 }
1102 if(largeIC){
1103 txtoutTocheck<<"largeIC "<< j<<" "<<k <<" "<<ieta <<" "<<iphi<<" " ;
1104 for(int n1 =0; n1 < nIC ; n1++){
1105 txtoutTocheck<<icwt_period[n1][j][k]<<" ";
1106 }
1107 txtoutTocheck<<endl;
1108 }
1109
1110 bool checkICdiff = false;
1111 for(int n1=0; n1< nIC; n1++){ ///for each period
1112 for(int n2=n1+1;n2< nIC; n2++){ ///for each period
1113 if( icwt_period[n1][j][k]>0 && icwt_period[n2][j][k]>0){
1114 float reldiff = fabs( icwt_period[n1][j][k] - icwt_period[n2][j][k] )/ ( 0.5* (icwt_period[n1][j][k] + icwt_period[n2][j][k]));
1115
1116 float statErr1 = hh_statErr_ietaAbs_period[n1]->GetBinContent(absieta)/100;
1117 float statErr2 = hh_statErr_ietaAbs_period[n2]->GetBinContent(absieta)/100;
1118
1119 ////assuming same sys.
1120 float diff_statErr = sqrt( statErr1*statErr1 + statErr2*statErr2);
1121
1122 checkICdiff = false;
1123 // if( abs(ieta)<60 && reldiff >0.02){
1124 // checkICdiff = true;
1125 // }
1126 // if( abs(ieta)>=60 && reldiff >0.1){
1127 // checkICdiff = true;
1128 // }
1129 checkICdiff = reldiff > 3 * diff_statErr ;
1130 if(checkICdiff){
1131 hh2_largeICdiff[n1][n2]->SetBinContent(beta,bphi,1);
1132 }else{
1133 hh2_largeICdiff[n1][n2]->SetBinContent(beta,bphi,-1);
1134 }
1135
1136 }else{
1137 hh2_largeICdiff[n1][n2]->SetBinContent(beta,bphi,-1);
1138 }
1139 }
1140 }
1141 if(checkICdiff){
1142 hh2_largeICdiff_all->SetBinContent(beta,bphi,1);
1143 txtoutTocheck<<"checkICdiff "<< j<<" "<<k <<" "<<ieta <<" "<<iphi<<" " ;
1144 for(int n1 =0; n1 < nIC ; n1++){
1145 txtoutTocheck<<icwt_period[n1][j][k]<<" ";
1146 }
1147 txtoutTocheck<<endl;
1148 }else{
1149 hh2_largeICdiff_all->SetBinContent(beta,bphi,-1);
1150 }
1151
1152 }
1153 }
1154
1155
1156
1157
1158 scaleMeanToUnit(icwt);
1159 ///for estimating precision of combined IC
1160 copyConstant(icwt,icwtv1);
1161 NormSMScaleToUnit(icwtv1);
1162
1163
1164 for(int n=0; n< nIC; n++){ ///for each period
1165 scaleMeanToUnit(icwt_period[n]);
1166 }
1167
1168
1169 for(int j=0; j<170; j++){
1170 int ieta = j-85;
1171 if( ieta >=0) ieta += 1;
1172 for(int k=0; k<360; k++){
1173 int iphi = k;
1174 if( k==0) iphi = 360;
1175 int ietaTTAbs = (abs(ieta)-1)/5;
1176 int iSM = (iphi-1)/20+1;
1177 if( ieta<0) iSM += 18;
1178 int smTB = isTestBeamSM(iSM);
1179
1180
1181 float sysErr = 0.5;
1182 if(abs(ieta)>=60) sysErr = 1;
1183
1184 float icErr = sysErr;
1185 float statErr = statErr_allCombined[abs(ieta)-1];
1186 icErr = sqrt(sysErr *sysErr + statErr * statErr);
1187 icErr /=100;
1188
1189
1190 if( icwt[j][k] > 0){
1191 txtout<<ieta<<" "<<iphi<<" "<< icwt[j][k]*interCalib_preCalib[j][k]<<" "<< icErr* icwt[j][k]*interCalib_preCalib[j][k]<<endl;
1192 //txtout<<ieta<<" "<<iphi<<" "<< icwt[j][k]*interCalib_preCalib[j][k]<<endl;
1193 }else{
1194 txtout<<ieta<<" "<<iphi<<" "<< -1 <<" "<< 999 <<endl;
1195 //txtout<<ieta<<" "<<iphi<<" "<< interCalib_preCalib[j][k]<<endl;
1196
1197 }
1198
1199 float c = icwtv1[j][k]; ///sm normalized to unit
1200
1201
1202 int absieta = abs(ieta);
1203
1204 for(int n=0; n< nIC+1; n++){ ///for each period and all combined
1205
1206 if(n< nIC){
1207 if( icwt_period[n][j][k] > 0){
1208 hh_c_ietaAbs_period[n][absieta-1]->Fill(icwt_period[n][j][k]);
1209 hh_c_ietaTTAbs_period[n][ietaTTAbs]->Fill(icwt_period[n][j][k]);
1210
1211 if( smTB){
1212 hh_c_smtbietaTTAbs_period[n][ietaTTAbs]->Fill(icwt_period[n][j][k]);
1213 }
1214 int deadflag = ndeadflagietaiphi_ic[n][j][k];
1215 if( deadflag<0){
1216 cout<<"wrong deadlfag !!! n " << n <<" "<<endl;
1217 exit(1);
1218 }
1219 hh_c_deadflag_period[n][deadflag]->Fill(icwt_period[n][j][k]);
1220
1221 if(deadflag>0){
1222 hh_c_deadflag_period[n][19]->Fill(icwt_period[n][j][k]);
1223 hh_cc_deadflag_period[n][19]->Fill( interCalib_preCalib[j][k] * icwt_period[n][j][k]);
1224 }
1225
1226 }
1227 }else{
1228 if( icwt[j][k] > 0){
1229 hh_c_ietaAbs_period[n][absieta-1]->Fill(icwt[j][k]);
1230 hh_c_ietaTTAbs_period[n][ietaTTAbs]->Fill(icwt[j][k]);
1231
1232 int deadflag = ndeadflagietaiphi_ic[0][j][k];
1233 if( deadflag<0){
1234 cout<<"wrong deadlfag !!! comb " << n <<" "<<endl;
1235 exit(1);
1236 }
1237 hh_c_deadflag_period[n][deadflag]->Fill(icwt[j][k]);
1238 if(deadflag>0){
1239 hh_c_deadflag_period[n][19]->Fill(icwt[j][k]);
1240 }
1241
1242 if( smTB){
1243 hh_c_smtbietaTTAbs_period[n][ietaTTAbs]->Fill(icwt[j][k]);
1244 }
1245
1246 }
1247 }
1248 }
1249
1250
1251 for(int n=0; n< nIC; n++){ ///for each period
1252 statErr = hh_statErr_ietaAbs_period[n]->GetBinContent(absieta);
1253 icErr = sqrt( statErr * statErr + sysErr * sysErr);
1254 icErr /= 100;
1255
1256 if( icwt_period[n][j][k] > 0){
1257 txtout_period[n]<<ieta<<" "<<iphi<<" "<< icwt_period[n][j][k]*interCalib_preCalib[j][k]<<" "<< icErr*icwt_period[n][j][k]*interCalib_preCalib[j][k] <<endl;
1258 //txtout_period[n]<<ieta<<" "<<iphi<<" "<< icwt_period[n][j][k]*interCalib_preCalib[j][k]<<endl;
1259 }else{
1260 txtout_period[n]<<ieta<<" "<<iphi<<" "<< -1<<" "<< 999 <<endl;
1261 //txtout_period[n]<<ieta<<" "<<iphi<<" "<< interCalib_preCalib[j][k]<<" "<< 999 <<endl;
1262
1263 }
1264 }
1265
1266
1267
1268 if( c>0){
1269
1270 int ietaflag[3] = {abs(ieta)<25,abs(ieta)>=25 && abs(ieta)<60,abs(ieta)>=60};
1271 for(int jj=0;jj<3; jj++){
1272 if( ietaflag[jj]==0) continue;
1273 hh_csm[nConstantSet][iSM-1][jj]->Fill(c);
1274 }
1275
1276 if( smTB){
1277 hh_wtavg_csmtb_ietaTT[j/5]->Fill(c);
1278 hh_wtavg_csmtb_ietaTTAbs[ietaTTAbs]->Fill(c);
1279 }else{
1280 hh_wtavg_csmco_ietaTT[j/5]->Fill(c);
1281 hh_wtavg_csmco_ietaTTAbs[ietaTTAbs]->Fill(c);
1282 }
1283
1284 ///all sm
1285 hh_wtavg_csmall_ietaTTAbs[ietaTTAbs]->Fill(c);
1286
1287 }
1288
1289 }
1290 }
1291
1292 cout <<" fitting combined " <<endl;
1293
1294
1295 for(int n=0; n< nConstantSet+1; n++){
1296 for(int j=0; j<36; j++){
1297
1298 for(int k=0;k<3;k++){
1299 fitHistogram(hh_csm[n][j][k],resfit);
1300 for(int jj=0;jj<3; jj++){
1301 hh_res_csm[n][k][jj]->SetBinContent(j+1,resfit[2*jj]);
1302 hh_res_csm[n][k][jj]->SetBinError(j+1,resfit[2*jj+1]);
1303 }
1304 }
1305 }
1306 }
1307
1308
1309
1310 for(int n1=0; n1< nIC+1; n1++){ ///for each period and all combined
1311 for(int j=0; j< 85; j++){
1312 fitHistogram(hh_c_ietaAbs_period[n1][j],resfit);
1313 for(int n=0;n<3; n++){
1314 hh_res_cietaAbs_period[n1][n]->SetBinContent(j+1,resfit[2*n]);
1315 hh_res_cietaAbs_period[n1][n]->SetBinError(j+1,resfit[2*n+1]);
1316 }
1317 }
1318 for(int j=0; j< 17; j++){
1319 fitHistogram(hh_c_ietaTTAbs_period[n1][j],resfit);
1320 for(int n=0;n<3; n++){
1321 hh_res_cietaTTAbs_period[n1][n]->SetBinContent(j+1,resfit[2*n]);
1322 hh_res_cietaTTAbs_period[n1][n]->SetBinError(j+1,resfit[2*n+1]);
1323 }
1324 fitHistogram(hh_c_smtbietaTTAbs_period[n1][j],resfit);
1325 for(int n=0;n<3; n++){
1326 hh_res_csmtbietaTTAbs_period[n1][n]->SetBinContent(j+1,resfit[2*n]);
1327 hh_res_csmtbietaTTAbs_period[n1][n]->SetBinError(j+1,resfit[2*n+1]);
1328 }
1329 }
1330 }
1331
1332
1333 for(int j=0;j<34; j++){
1334 fitHistogram(hh_wtavg_csmtb_ietaTT[j],resfit);
1335 for(int n=0;n<3; n++){
1336 hh_res_wtavg_csmtbietaTT[n]->SetBinContent(j+1,resfit[2*n]);
1337 hh_res_wtavg_csmtbietaTT[n]->SetBinError(j+1,resfit[2*n+1]);
1338 }
1339 fitHistogram(hh_wtavg_csmco_ietaTT[j],resfit);
1340 for(int n=0;n<3; n++){
1341 hh_res_wtavg_csmcoietaTT[n]->SetBinContent(j+1,resfit[2*n]);
1342 hh_res_wtavg_csmcoietaTT[n]->SetBinError(j+1,resfit[2*n+1]);
1343 }
1344 }
1345 for(int j=0;j<17; j++){
1346 fitHistogram(hh_wtavg_csmtb_ietaTTAbs[j],resfit);
1347 for(int n=0;n<3; n++){
1348 hh_res_wtavg_csmtbietaTTAbs[n]->SetBinContent(j+1,resfit[2*n]);
1349 hh_res_wtavg_csmtbietaTTAbs[n]->SetBinError(j+1,resfit[2*n+1]);
1350 }
1351
1352
1353 fitHistogram(hh_wtavg_csmall_ietaTTAbs[j],resfit);
1354 for(int n=0;n<3; n++){
1355 hh_res_wtavg_csmallietaTTAbs[n]->SetBinContent(j+1,resfit[2*n]);
1356 hh_res_wtavg_csmallietaTTAbs[n]->SetBinError(j+1,resfit[2*n+1]);
1357 }
1358
1359 fitHistogram(hh_wtavg_csmco_ietaTTAbs[j],resfit);
1360 for(int n=0;n<3; n++){
1361 hh_res_wtavg_csmcoietaTTAbs[n]->SetBinContent(j+1,resfit[2*n]);
1362 hh_res_wtavg_csmcoietaTTAbs[n]->SetBinError(j+1,resfit[2*n+1]);
1363 }
1364 }
1365
1366
1367 fnew->Write();
1368 fnew->Close();
1369
1370 }