ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/yangyong/combineICEB/combineCalibConstantv2.C
Revision: 1.3
Committed: Fri Aug 10 14:54:03 2012 UTC (12 years, 9 months ago) by yangyong
Content type: text/plain
Branch: MAIN
CVS Tags: V2012combv2a, V2012combv2
Changes since 1.2: +93 -413 lines
Log Message:
*** empty log message ***

File Contents

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