-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKolja_SetExample.C
More file actions
347 lines (292 loc) · 10.2 KB
/
Kolja_SetExample.C
File metadata and controls
347 lines (292 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
{
#include<set>
int MinHits = 1;
float MinEnergy=5;
double tooHot=100000;
set<int> goodmodules;
// goodmodules.insert(0);
goodmodules.insert(1);
goodmodules.insert(2);
goodmodules.insert(3);
goodmodules.insert(4);
goodmodules.insert(5);
goodmodules.insert(6);
goodmodules.insert(7);
goodmodules.insert(8);
goodmodules.insert(9);
goodmodules.insert(10);
goodmodules.insert(11);
goodmodules.insert(12);
goodmodules.insert(13);
goodmodules.insert(14);
goodmodules.insert(15);
goodmodules.insert(16);
TChain* chain= new TChain("CastorRecoTree");
// TChain* chain1= new TChain("ZDCDigiTree");
chain->Add("/hadoop/store/user/belt/ZDC_PA2013_ForCalibration/211623/running/ZDCTree*");
// chain1->Add("/hadoop/store/user/belt/ZDC_PA2013_ForCalibration/211623/running/ZDCTree*");
// chain->Add("/hadoop/store/user/jgomez2/HeavyIonRun2013/PAUPCMinBias_RAW/ForwardTrees_PAUPCMinBiasRaw_211623merged_castorfix_beamreversal.root");
//chain1->Add("/hadoop/store/user/jgomez2/HeavyIonRun2013/PAUPCMinBias_RAW/ForwardTrees_PAUPCMinBiasRaw_211623merged_castorfix_beamreversal.root");
int NumberOfEvents=0;
// NumberOfEvents = chain->GetEntries();
// NumberOfEvents=1000000;
NumberOfEvents=50000;
// NumberOfEvents=100;
// NumberOfEvents=1;
/////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
//////////////////////VARIABLES////////////////////////////////////
///////////////////////////////////////////////////////////////////
int NumberOfRecHits = 0;
int module=0;
int sector=0;
double TotalHits=0.;
int EventHits=0;
int ModuleHits=0;
double X_n=0.;
double Y_n=0.;
double Psi_n=0.;
double pi=3.14159265;
double Energy=0.;
bool hotevent=false;
//////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
TH1F* histogram_1 = new TH1F("EventPlane","#Psi_{EP} (radians) Odd Modules,E>100",16*8,-pi,pi);
TH1F* histogram_3 = new TH1F("NhitVsPhi","Weighting as a function of Sector Angle",16,-pi, pi);
TH1F* hphi = new TH1F("hphi","N_hit vs Phi (radians) Odd Modules , E>100",16*4,-pi, pi);
TH1F* ephi = new TH1F("ephi","E vs Phi (radians), E>5",20,1,21);
histogram_1->Sumw2();
hphi->Sumw2();
ephi->Sumw2();
// histogram_3->Sumw2();
////////////////////////////////////
/////FIRST LOOP OVER ALL EVENTS/////
///////////////////////////////////
float phi=0;
set<int> sectorused;
for(int i =0;i<NumberOfEvents;i++) {
if ( !(i%10000) ) cout << " 1st round, event # " << i << " / " << NumberOfEvents << endl;
hotevent=false;
chain->GetEntry(i);
CasSec= (TLeaf*) chain->GetLeaf("Castor_Section");
CasMod= (TLeaf*) chain->GetLeaf("Castor_Module");
CasSector= (TLeaf*) chain->GetLeaf("Castor_Sector");
CasHits= (TLeaf*) chain->GetLeaf("Castor_NumberOfHits");
CasEN= (TLeaf*) chain->GetLeaf("Castor_Energy");
NumberOfRecHits= CasHits->GetValue();
// First check if event is acceptable
EventHits=0;
ModuleHits=0;
sectorused.clear();
for (int j=0;j<NumberOfRecHits;j++){
module=0;
sector=0;
Energy=0.;
module=CasMod->GetValue(j);
sector=CasSector->GetValue(j);
Energy=CasEN->GetValue(j);
if (Energy>tooHot)
{
hotevent=true;
std::cout<<"Gosh its hot in sector"<<" " <<sector<<std::endl;
break;
}
// ephi->Fill(sector,Energy);
// std::cout<<sector<<' '<<Energy<<std::endl;
if ( goodmodules.count(module)>0 && sectorused.count(sector)==0 && Energy>MinEnergy)
{
sectorused.insert(sector);
EventHits++;
// The loop below tries to count hits only once
// if they are in the same sector but different modules.
// I think that's not a good thing and it needs to be done differently in any case
// Disabling for now
// if(ModuleHits==0)
// {
// ModuleHits=module;
// EventHits++;
// }
// else if(ModuleHits==module)
// {
// continue;
// }
// else if(ModuleHits!=module)
// {
// EventHits++;
// }
}
}
if ((EventHits<MinHits) || (hotevent)) continue;
////////////////////////////////////////
//////////LOOP OVER CASTOR RECHITS//////
////////////////////////////////////////
sectorused.clear();
for (int j=0;j<NumberOfRecHits;j++)
{
module=0;
sector=0;
Energy=0.;
module=CasMod->GetValue(j);
sector=CasSector->GetValue(j);
Energy=CasEN->GetValue(j);
phi=0;
if ( goodmodules.count(module)>0 && sectorused.count(sector)==0 && Energy>MinEnergy)
{
sectorused.insert(sector);
//KOLJAS WAY
phi = atan2(sin((sector)*(22.5*pi)/180),cos((sector)*(22.5*pi)/180)); // complicated way to map phi into +-pi
// cout << phi << endl;
//////////////////
histogram_3->Fill( phi-0.01 ); // phi sits on sector boundaries, push it inward just to be safe
// cout << atan2(sin((sector)*(22.5*pi)/180),cos((sector)*(22.5*pi)/180)) << endl;
//std::cout<<Energy<<" "<<sector<<std::endl
}//Energy>1000 && module<4
}//END OF LOOP OVER RECHITS
/////////////////////////////////////
/////////////////////////////////////
/////////////////////////////////////
}//END OF FIRST LOOP OVER EVENTS
////////////////////////////////////
////////////////////////////////////
///////////////////////////////////
// weights should for example average out to unity
histogram_3->Scale(1./histogram_3->GetEntries()*16);
// histogram_3->Draw();return;
//Now there is a specific weighting for each sector, when calling the function later to fit the EP using cos, sin of phi_i, there will be a specific weighting for each sector.
//////////////////////////////
//////////////////////////////
//////////////////////////////
////////////////////////////////////
/////SECOND LOOP OVER ALL EVENTS/////
///////////////////////////////////
for(int i =0;i<NumberOfEvents;i++)
{
float w=1;
hotevent=false;
if ( !(i%10000) ) cout << " 2nd round, event # " << i << " / " << NumberOfEvents << endl;
chain->GetEntry(i);
///////////////////////////////////////////////////////////
/////////////////GRAB Leaves///////////////////////////////
//////////////////////////////////////////////////////////
CasSec= (TLeaf*) chain->GetLeaf("Castor_Section");
CasMod= (TLeaf*) chain->GetLeaf("Castor_Module");
CasSector= (TLeaf*) chain->GetLeaf("Castor_Sector");
CasHits= (TLeaf*) chain->GetLeaf("Castor_NumberOfHits");
CasEN= (TLeaf*) chain->GetLeaf("Castor_Energy");
////////////////////
////ZERO THE EP/////
////////////////////
X_n=0.;
Y_n=0.;
Psi_n=0.;
////////////////////
////////////////////////////////////////
//////////LOOP OVER CASTOR RECHITS//////
////////////////////////////////////////
NumberOfRecHits= CasHits->GetValue();
// First check if event is acceptable
EventHits=0;
ModuleHits=0;
sectorused.clear();
for (int j=0;j<NumberOfRecHits;j++)
{
module=0;
sector=0;
Energy=0.;
module=CasMod->GetValue(j);
sector=CasSector->GetValue(j);
Energy=CasEN->GetValue(j);
if (Energy>tooHot)
{
hotevent=true;
break;
}
if ( goodmodules.count(module)>0 && sectorused.count(sector)==0 && Energy>MinEnergy)
{
sectorused.insert(sector);
EventHits++;
// if(ModuleHits==0)
// {
// ModuleHits=module;
// EventHits++;
// }
// else if(ModuleHits==module)
// {
// continue;
// }
// else if(ModuleHits!=module)
// {
// EventHits++;
// }
}
}
if ((EventHits<MinHits) || (hotevent==true)) continue;
sectorused.clear();
for (int j=0;j<NumberOfRecHits;j++)
{
module=0;
sector=0;
Energy=0.;
phi=0;
module=CasMod->GetValue(j);
sector=CasSector->GetValue(j);
Energy=CasEN->GetValue(j);
if ( goodmodules.count(module)>0 && sectorused.count(sector)==0 && Energy>MinEnergy)
{
sectorused.insert(sector);
///KOLJAS WAY
phi = atan2(sin((sector)*(22.5*pi)/180),cos((sector)*(22.5*pi)/180));
// w = 1./ histogram_3->GetBinContent(histogram_3->GetXaxis()->FindBin(phi-0.01)); // boundary stuff again.
w=1;
// smear out. without smearing, the values range from -7*pi/8 .. pi
// so subtract Rndm(pi/8)
phi-=pi/8.*gRandom->Rndm();
///////////////////////
// std::cout<<histogram_3->GetXaxis()->FindBin(phi)<<" "<<sector<<std::endl;
// cout << w << endl;
// cout <<phi << " " << w << endl;
// std::cout<<Energy<<" "<<sector<<std::endl;
X_n+=cos( phi ) * w ;
Y_n+=sin( phi ) * w ;
hphi->Fill(phi, w);
}//Energy>1000
}//END OF LOOP OVER CASTOR RECHITS
////////////////////////////////////////////
////////////////////////////////////////////
////////////////////////////////////////////
Psi_n=atan2(Y_n,X_n);
histogram_1->Fill(Psi_n);
}//END OF SECOND EVENT LOOP
////////////////////////////////////
///////////////////////////////////
///////////////////////////////////
c1 = new TCanvas();
histogram_1->SetXTitle("#Psi_{EP} (radians)");
histogram_1->SetYTitle("Counts");
histogram_1->GetXaxis()->CenterTitle(1);
histogram_1->GetXaxis()->CenterTitle(1);
histogram_1->SetTitleOffset(1.13,"Y");
histogram_1->Draw();
c3 = new TCanvas();
histogram_3->SetXTitle("#phi_{i} (radians)");
histogram_3->SetYTitle("Counts");
histogram_3->GetXaxis()->CenterTitle(1);
histogram_3->GetXaxis()->CenterTitle(1);
histogram_3->SetTitleOffset(1.13,"Y");
histogram_3->Draw();
new TCanvas;
hphi->Draw();
new TCanvas;
ephi->Draw();
}//END OF WHOLE THING
//KOLJA's Special Fix
/*// ------------------------------------------------
// Bring angle value back into +-pi
Float_t mod2pi (Float_t x)
{
while ( x>=TMath::Pi() ) x-= TMath::TwoPi();
while ( x<-TMath::Pi() ) x+= TMath::TwoPi();
return x;
}
*/