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
|
#include <vector>
#include <fstream>
#include <iostream>
#include <algorithm>
#include "TFile.h"
#include "TTree.h"
using namespace std;
struct DATA
{
long d;
int f;
};
void Counting(vector<DATA>* data,long x)
{
for(unsigned int i=0;i<data->size();i++)
{
if( (data->at(i).d)==x)
{
data->at(i).f++;
return;
}
}
DATA d = {x,1};
data->push_back(d);
return;
}
void CosmicRateTool_MakeIdList(const char* fileName)
{
TString InputFile= Form("%s",fileName);
TFile *file = new TFile(InputFile);
bool IsFileExist;
IsFileExist = file->IsZombie();
if(IsFileExist)
{
cout<<endl<<"====================================================================================================="<<endl;
cout<<fileName << " is not found. Check the file!"<<endl;
cout<<"====================================================================================================="<<endl<<endl;
exit (EXIT_FAILURE);
}
TTree *tree;
tree = (TTree*)file->Get("cosmicRateAnalyzer/Cluster");
ofstream output("IdList.txt");
UInt_t Id;
long x;
tree->SetBranchAddress("DetID",&Id);
vector<DATA>* dataIn = new vector<DATA>();
long int nentries = (int)tree->GetEntries();
cout<<"entries : "<<nentries<<endl;
for(long int i=0; i < nentries; i++)
{
tree->GetEntry(i);
x=Id;
Counting(dataIn,x);
if(i%10000==0)cout<<"At : "<<i<<endl;
// if (i==10000) break;
}
for(unsigned int j=0;j<dataIn->size();)
{
output<<(dataIn->at(j).d)<<" "<<(dataIn->at(j).f)<<endl;
j++;
}
output.close();
}
|