ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/yangyong/Pi0Calibration/Common/utils.cc
Revision: 1.1
Committed: Thu Jul 26 08:48:21 2012 UTC (12 years, 9 months ago) by yangyong
Content type: text/plain
Branch: MAIN
CVS Tags: V00-00-01g, V00-00-01f, V00-00-01e, V00-00-01d, V00-00-01c, V00-00-01b, V00-00-01a, pi0calibrator_v01a, HEAD
Log Message:
first commit

File Contents

# Content
1 int convertIetaIphiToSMNumber(int ieta, int iphi){
2
3 if( ! (abs(ieta)>=1 && abs(ieta)<=85 && iphi>=1 && iphi<=360)) {
4 cout<<" convertSMNumber " << ieta <<" "<<iphi<<endl;
5 exit(1);
6 }
7 int ism = (iphi-1)/20+1;
8 if( ieta<0) ism += 18;
9 return ism;
10
11 }
12
13
14
15 //information on the crystal's x/y/z needed to compute cluster position X/Y/Z after
16 //each inter-calibration step.
17 void get_xyzEBrechits(){
18 TChain *ch = new TChain("Analysis");
19 ch->Add("/uscms_data/d2/yongy/tmp1/CMSSW_5_2_4/src/Pi0Calibration/Common/xyzECAL.root");
20
21 ch->SetBranchAddress("xEBAll",xEBAll);
22 ch->SetBranchAddress("yEBAll",yEBAll);
23 ch->SetBranchAddress("zEBAll",zEBAll);
24 ch->SetBranchAddress("etaEBAll",etaEBAll);
25 ch->SetBranchAddress("phiEBAll",phiEBAll);
26
27 ch->SetBranchAddress("dxEBAll",dxEBAll);
28 ch->SetBranchAddress("dyEBAll",dyEBAll);
29 ch->SetBranchAddress("dzEBAll",dzEBAll);
30
31 ch->SetBranchAddress("xEEAll",xEEAll);
32 ch->SetBranchAddress("yEEAll",yEEAll);
33 ch->SetBranchAddress("zEEAll",zEEAll);
34
35 ch->SetBranchAddress("dxEEAll",dxEEAll);
36 ch->SetBranchAddress("dyEEAll",dyEEAll);
37 ch->SetBranchAddress("dzEEAll",dzEEAll);
38
39
40
41 ch->SetBranchAddress("etaEEAll",etaEEAll);
42 ch->SetBranchAddress("phiEEAll",phiEEAll);
43
44
45
46
47
48 ch->GetEntry(0);
49
50 ch->Delete();
51
52 cout<<"got xyzEcal.."<<endl;
53
54
55
56 }
57
58 /////////////////////////////////////////////////////////////////////////////////////////////////
59
60 void convxtalid(Int_t &nphi,Int_t &neta)
61 {
62 // Changed to what Yong's convention; output will give just two indices
63 // phi is unchanged; only eta now runs from
64 //
65 // 03/01/2008 changed to the new definition in CMSSW. The output is still the same...
66 // Barrel only
67 // Output nphi 0...359; neta 0...84; nside=+1 (for eta>0), or 0 (for eta<0).
68 // neta will be [-85,-1] , or [0,84], the minus sign indicates the z<0 side.
69
70 if(neta > 0) neta -= 1;
71 if(nphi > 359) nphi=nphi-360;
72
73 // final check
74 if(nphi >359 || nphi <0 || neta< -85 || neta > 84)
75 {
76 cout <<" output not in range: "<< nphi << " " << neta << " " <<endl;
77 exit(1);
78 }
79 } //end of convxtalid
80
81
82 // Calculate the distance in xtals taking into account possibly different sides
83 // change to coincide with yongs definition
84 Int_t diff_neta(Int_t neta1, Int_t neta2){
85 Int_t mdiff;
86 mdiff=abs(neta1-neta2);
87 return mdiff;
88 }
89
90 // Calculate the absolute distance in xtals taking into account the periodicity of the Barrel
91 Int_t diff_nphi(Int_t nphi1,Int_t nphi2) {
92 Int_t mdiff;
93 mdiff=abs(nphi1-nphi2);
94 if (mdiff > (360-abs(nphi1-nphi2))) mdiff=(360-abs(nphi1-nphi2));
95 return mdiff;
96 }
97
98 // Calculate the distance in xtals taking into account possibly different sides
99 // Then the distance would be from the 1st to the 2nd argument
100 // _s means that it gives the sign; the only difference from the above !
101 // also changed to coincide with Yong's definition
102 Int_t diff_neta_s(Int_t neta1, Int_t neta2){
103 Int_t mdiff;
104 mdiff=(neta1-neta2);
105 return mdiff;
106 }
107
108 // Calculate the distance in xtals taking into account the periodicity of the Barrel
109 Int_t diff_nphi_s(Int_t nphi1,Int_t nphi2) {
110 Int_t mdiff;
111 if(abs(nphi1-nphi2) < (360-abs(nphi1-nphi2))) {
112 mdiff=nphi1-nphi2;
113 }
114 else {
115 mdiff=360-abs(nphi1-nphi2);
116 if(nphi1>nphi2) mdiff=-mdiff;
117 }
118 return mdiff;
119 }
120
121
122 ///to access xEBAll[ieta][iphi]
123 /// input ieta -85,0,84
124 int getIndetaxyzEBAll(int ieta){
125 return ieta+85;
126 }
127
128 ////something not consistent with 167,152?
129
130
131 ///input 0, 359 after convxtalid
132 int getIndphixyzEBAll(int iphi){
133
134 iphi = iphi-1;
135 if(iphi<0) return 359;
136 else return iphi;
137
138 }
139
140 double DeltaPhi(double phi1, double phi2){
141
142 double diff = fabs(phi2 - phi1);
143
144 while (diff >acos(-1)) diff -= 2*acos(-1);
145 while (diff <= -acos(-1)) diff += 2*acos(-1);
146
147 return diff;
148
149 }
150
151
152 double GetDeltaR(double eta1, double eta2, double phi1, double phi2){
153
154 return sqrt( (eta1-eta2)*(eta1-eta2)
155 + DeltaPhi(phi1, phi2)*DeltaPhi(phi1, phi2) );
156
157 }
158
159
160
161
162 Float_t getcosd(Float_t eta1, Float_t phi1, Float_t eta2, Float_t phi2) {
163 Float_t theta1 = 2*atan(exp(-eta1));
164 Float_t theta2 = 2*atan(exp(-eta2));
165 Float_t cosd;
166 Float_t dphi = DeltaPhi(phi1,phi2);
167 cosd = cos(theta1)*cos(theta2)+sin(theta1)*sin(theta2)*cos(dphi); //opening angle
168 return cosd;
169 }
170 void separation(Float_t sceta1, Float_t scphi1, Float_t sceta2, Float_t scphi2, Float_t &dr)
171 {
172 float dphi=fabs(scphi1-scphi2);
173 if(dphi > (2*acos(-1)-fabs(scphi1-scphi2))) dphi = ( 2*acos(-1)-fabs(scphi1-scphi2));
174 dr=sqrt((sceta1- sceta2)*(sceta1- sceta2)+dphi*dphi);
175 }
176
177
178
179 void phinorm(Float_t & PHI)
180 {
181 while (PHI<0) PHI= PHI + 2*acos(-1);
182 if(PHI>2*acos(-1)) PHI= PHI - 2*acos(-1);
183
184 }
185
186
187 ////change to [-pi,pi];
188 float phinorm2(float phi){
189 while( phi > acos(-1) ) phi -= 2*acos(-1);
190 while(phi< -acos(-1)) phi += 2*acos(-1);
191
192 return phi;
193
194
195 }
196
197
198
199 void convertindTTindCrystal(int ietaT,int iphiT, int &ieta, int &iphi){
200
201 if( iphiT >= 71) iphi = (iphiT-71)*5+3;
202 else if( iphiT >=1 && iphiT <=70){
203 iphi = (iphiT+1)*5+3;
204 }else{
205 cout<<"fatal error ..iphiT "<<iphiT<<endl;
206 exit(1);
207 }
208
209 ieta = abs(ietaT)*5-2;
210
211 if(ietaT<0) ieta *= -1;
212
213
214 if( ieta >85 || ieta <-85 || ieta ==0){
215 cout<<"convertindTTindCrystal... "<<ieta<<" "<<ietaT<<endl;
216 exit(1);
217 }
218
219 if( iphi <0 || iphi >360){
220 cout<<"convertindTTindCrystal... "<<iphi<<" "<<iphiT<<endl;
221 exit(1);
222 }
223
224 }