File indexing completed on 2025-08-05 08:14:41
0001 #include <cmath>
0002 #include <TFile.h>
0003 #include <TString.h>
0004 #include <TLine.h>
0005 #include <TTree.h>
0006 #include <TLatex.h>
0007 #include <TGraphErrors.h>
0008 #include <cassert>
0009 #include "SaveCanvas.C"
0010 #include "SetOKStyle.C"
0011 #include <iostream>
0012 #include <fstream>
0013 #include "TROOT.h"
0014 #include "TH1.h"
0015 #include "TTree.h"
0016 using namespace std;
0017
0018
0019
0020 using std::cout;
0021 using std::endl;
0022 #endif
0023
0024
0025 void FillEnergy()
0026 {
0027 gSystem->Load("libg4eval.so");
0028 gSystem->Load("libqa_modules.so");
0029 gSystem->Load("libPrototype3.so");
0030 gStyle->SetOptFit(0);
0031 gStyle->SetOptStat(0);
0032
0033 double inteval = 1;
0034
0035 double Xmin = 170;
0036 double Xmax = 310.0;
0037
0038 double Ymin = 60;
0039 double Ymax = 245.0;
0040
0041 int XBins =(Xmax - Xmin)/inteval;
0042 int YBins = (Ymax - Ymin)/inteval;
0043
0044
0045
0046 int Ini = 3543;
0047 int Final = 3579;
0048
0049 int step = 1;
0050
0051 int num = (Final - Ini)/step;
0052
0053 cout << "num = " << num << endl;
0054
0055 const int N = 8;
0056
0057 const int NTotal = N * N;
0058
0059 double x;
0060 double y;
0061 char Filename[512];
0062
0063
0064
0065
0066
0067
0068
0069 char inputfile[512];
0070
0071 int j;
0072
0073 double xmax = 0;
0074 double ymax = 0;
0075
0076 double Energy;
0077 double Energy_err;
0078 double Width;
0079 double Width_err;
0080 double Center;
0081 double Center_err;
0082
0083 int index;
0084
0085
0086
0087
0088 for(int i =0; i < num; i ++)
0089 {
0090 index = 0;
0091
0092 gStyle->SetOptFit(0);
0093 gStyle->SetOptStat(0);
0094
0095 TCanvas *c1 = new TCanvas("c1", "c1",0,0,800,600);
0096 c1->cd();
0097
0098
0099 cout << " i = " << i << endl;
0100
0101
0102
0103 j = i * step + Ini;
0104
0105 cout << " j = " << j << endl;
0106
0107 if(j != 3416 && j != 3418 && j != 3420 && j != 3421 && j != 3426)
0108 {
0109
0110
0111
0112 sprintf(inputfile,"/phenix/u/jinhuang/links/sPHENIX_work/Prototype_2017/Production_0130_WithEMCalCalib/beam_0000%d-0000_DSTReader.root",j);
0113
0114
0115 cout << "Infile name = " << inputfile << endl;
0116
0117 ifstream ifile(inputfile);
0118
0119
0120
0121 if(ifile){
0122
0123 TFile *fin = new TFile(inputfile);
0124
0125
0126
0127 TTree *t = (TTree *)fin->Get("T");
0128
0129 t->SetAlias("C2_Inner_e", "1*abs(TOWER_RAW_C2[2].energy)");
0130 t->SetAlias("C2_Outer_e", "1*abs(TOWER_RAW_C2[3].energy)");
0131 t->SetAlias("Average_column", "Sum$(TOWER_CALIB_CEMC.get_column() * TOWER_CALIB_CEMC.get_energy())/Sum$(TOWER_CALIB_CEMC.get_energy())");
0132 t->SetAlias("Average_HODO_HORIZONTAL", "Sum$(TOWER_CALIB_HODO_HORIZONTAL.towerid * (abs(TOWER_CALIB_HODO_HORIZONTAL.energy)>30) * abs(TOWER_CALIB_HODO_HORIZONTAL.energy))/Sum$((abs(TOWER_CALIB_HODO_HORIZONTAL.energy)>30) * abs(TOWER_CALIB_HODO_HORIZONTAL.energy))");
0133 t->SetAlias("Valid_HODO_HORIZONTAL", "Sum$(abs(TOWER_CALIB_HODO_HORIZONTAL.energy)>30) > 0");
0134 t->SetAlias("No_Triger_VETO", "Sum$(abs(TOWER_RAW_TRIGGER_VETO.energy)>15)==0");
0135 t->SetAlias("Valid_HODO_VERTICAL", "Sum$(abs(TOWER_CALIB_HODO_VERTICAL.energy)>30) > 0");
0136 t->SetAlias("C2_Sum_e", "C2_Inner_e + C2_Outer_e");
0137 t->SetAlias("Average_HODO_VERTICAL","Sum$(TOWER_CALIB_HODO_VERTICAL.towerid * (abs(TOWER_CALIB_HODO_VERTICAL.energy)>30) * abs(TOWER_CALIB_HODO_VERTICAL.energy))/Sum$((abs(TOWER_CALIB_HODO_VERTICAL.energy)>30) * abs(TOWER_CALIB_HODO_VERTICAL.energy))");
0138
0139 t->SetAlias("Energy_Sum_CEMC", "1*Sum$(TOWER_CALIB_CEMC.get_energy())");
0140
0141
0142
0143
0144 TCut event_sel = "Valid_HODO_HORIZONTAL && Valid_HODO_VERTICAL && No_Triger_VETO && C2_Sum_e > 200";
0145
0146 t->Draw(">>EventList", event_sel);
0147
0148 TEventList * elist = gDirectory->GetObjectChecked("EventList", "TEventList");
0149
0150
0151
0152 cout << elist->GetN() << " / " << T->GetEntriesFast() << " events selected" << endl;
0153
0154 t->SetEventList(elist);
0155
0156
0157 TH1D *h5= new TH1D("h5","",200, -1, 10);
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173 sprintf(Filename,"Hisfiles130/His%d.root",i);
0174
0175 TFile *fout = new TFile(Filename,"RECREATE");
0176
0177 t->SetAlias("XPos", "beam_2CH_mm - 5* int( Average_HODO_HORIZONTAL + 0.5)");
0178 t->SetAlias("YPos", "beam_2CV_mm + 5* int(Average_HODO_VERTICAL + 0.5)");
0179
0180
0181
0182
0183
0184
0185 TH3F *Energyhis = new TH3F("Energyhis","",200,0,20,YBins,Ymin,Ymax,XBins,Xmin,Xmax);
0186
0187
0188
0189 t->Draw("XPos:YPos:Energy_Sum_CEMC>>Energyhis");
0190
0191
0192 Energyhis->Write();
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286 }
0287
0288 if (!ifile) {
0289
0290 i = i + 1;
0291
0292 cout << "File " << i << "does not exist" << endl;
0293
0294 }
0295
0296
0297 }
0298
0299 }
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378 }