Rev 333 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 333 | Rev 344 | ||
|---|---|---|---|
| 1 | #include <TClonesArray.h> |
1 | #include <TClonesArray.h> |
| 2 | #include <TH1F.h> |
2 | #include <TH1F.h> |
| 3 | #include <TStopwatch.h> |
3 | #include <TStopwatch.h> |
| 4 | #include <TDatime.h> |
4 | #include <TDatime.h> |
| 5 | #include <TString.h> |
5 | #include <TString.h> |
| 6 | #include <TFile.h> |
6 | #include <TFile.h> |
| 7 | #include <TTree.h> |
7 | #include <TTree.h> |
| 8 | #include <TBranch.h> |
8 | #include <TBranch.h> |
| 9 | #include <TBufferJSON.h> |
9 | #include <TBufferJSON.h> |
| 10 | #include <TMath.h> |
10 | #include <TMath.h> |
| 11 | #include <vector> |
11 | #include <vector> |
| 12 | #include "BParticle.h" |
12 | #include "BParticle.h" |
| 13 | #include "BEvent.h" |
13 | #include "BEvent.h" |
| 14 | 14 | ||
| 15 | class Hdr{ |
15 | class Hdr{ |
| 16 | public: |
16 | public: |
| 17 | int id; |
17 | int id; |
| 18 | int len; |
18 | int len; |
| 19 | int progress; |
19 | int progress; |
| 20 | }; |
20 | }; |
| 21 | 21 | ||
| 22 | std::vector<int> histogram(int n, ...){ |
22 | std::vector<int> histogram(int n, ...){ |
| 23 | std::vector<int> result; |
23 | std::vector<int> result; |
| 24 | int val = 0; |
24 | int val = 0; |
| 25 | va_list ap; |
25 | va_list ap; |
| 26 | int i; |
26 | int i; |
| 27 | 27 | ||
| 28 | va_start(ap, n); |
28 | va_start(ap, n); |
| 29 | for(i = 0; i < n; i++) { |
29 | for(i = 0; i < n; i++) { |
| 30 | result.push_back( va_arg(ap, int) ); |
30 | result.push_back( va_arg(ap, int) ); |
| 31 | } |
31 | } |
| 32 | va_end(ap); |
32 | va_end(ap); |
| 33 | return result; |
33 | return result; |
| 34 | } |
34 | } |
| 35 | 35 | ||
| 36 | class Blab2 { |
36 | class Blab2 { |
| 37 | public: |
37 | public: |
| 38 | const char *names[12]={"photon", "electron", "pion", "muon", "kaon", "proton", "J/Psi", "D", "D*", "B", "Phi","Lambda0"}; |
38 | const char *names[12]={"photon", "electron", "pion", "muon", "kaon", "proton", "J/Psi", "D", "D*", "B", "Phi","Lambda0"}; |
| 39 | 39 | ||
| 40 | UInt_t fNeve; |
40 | UInt_t fNeve; |
| 41 | UInt_t fNfirst; |
41 | UInt_t fNfirst; |
| 42 | UInt_t fPrint; |
42 | UInt_t fPrint; |
| 43 |
|
43 | TString fData; |
| 44 | TH1F *fH[100]; |
44 | TH1F *fH[100]; |
| 45 | UInt_t fHtype[100]; |
45 | UInt_t fHtype[100]; |
| 46 | TClonesArray *fList[100]; |
46 | TClonesArray *fList[100]; |
| 47 | 47 | ||
| 48 | Blab2(); |
48 | Blab2(); |
| 49 | ~Blab2(); |
49 | ~Blab2(); |
| 50 | void Init(); |
50 | void Init(); |
| 51 | void event(); |
51 | void event(); |
| 52 | void Process(); |
52 | void Process(); |
| 53 | void h1d(const char *varname, const char *name, int nbins, double min, double max, int id ); |
53 | void h1d(const char *varname, const char *name, int nbins, double min, double max, int id ); |
| 54 | int selector(int pin, int charge, SIMPLEPID particlename, int hid, int pout ); |
54 | int selector(int pin, int charge, SIMPLEPID particlename, int hid, int pout ); |
| 55 | int selector(int pin, int charge, SIMPLEPID particlename, std::vector<int> hid, int pout ); |
55 | int selector(int pin, int charge, SIMPLEPID particlename, std::vector<int> hid, int pout ); |
| 56 | int combiner(int id0 ,int id1 , int same, SIMPLEPID particlename, double min, double max, int hid, int id ); |
56 | int combiner(int id0 ,int id1 , int same, SIMPLEPID particlename, double min, double max, int hid, int id ); |
| 57 | int combiner(int id0 ,int id1 , int same, SIMPLEPID particlename, double min, double max, std::vector<int>hid, int id ); |
57 | int combiner(int id0 ,int id1 , int same, SIMPLEPID particlename, double min, double max, std::vector<int>hid, int id ); |
| 58 | int combiner3(int id0 ,int id1 , int id2, int same, SIMPLEPID particlename, double min, double max, int hid, int id ); |
58 | int combiner3(int id0 ,int id1 , int id2, int same, SIMPLEPID particlename, double min, double max, int hid, int id ); |
| 59 | int combiner3(int id0 ,int id1 , int id2, int same, SIMPLEPID particlename, double min, double max, std::vector<int>hid, int id ); |
59 | int combiner3(int id0 ,int id1 , int id2, int same, SIMPLEPID particlename, double min, double max, std::vector<int>hid, int id ); |
| 60 | int fix_mass(int id); |
60 | int fix_mass(int id); |
| 61 | int Fill(std::vector<int> hid, |
61 | int Fill(std::vector<int> hid, BParticle *p); |
| 62 | void plist(int i); |
62 | void plist(int i); |
| 63 | 63 | ||
| 64 | 64 | ||
| 65 | ClassDef ( Blab2, 1 ) |
65 | ClassDef ( Blab2, 1 ) |
| 66 | }; |
66 | }; |
| 67 | 67 | ||
| 68 | ClassImp(Blab2) |
68 | ClassImp(Blab2) |
| 69 | 69 | ||
| 70 | Blab2::Blab2():fNfirst(0), fNeve(0), fData( |
70 | Blab2::Blab2():fNfirst(0), fNeve(0), fData(), fPrint(0) { |
| 71 | 71 | ||
| 72 | Process(); |
72 | Process(); |
| 73 | }; |
73 | }; |
| 74 | 74 | ||
| 75 | 75 | ||
| 76 | void Blab2::h1d(const char *varname, const char *name, int nbins, double min, double max, int id ){ |
76 | void Blab2::h1d(const char *varname, const char *name, int nbins, double min, double max, int id ){ |
| 77 | TString svar(varname); |
77 | TString svar(varname); |
| 78 | TString axis[]={"mass (GeV/c2)", |
78 | TString axis[]={"mass (GeV/c2)", |
| 79 | "momentum (GeV/c)", |
79 | "momentum (GeV/c)", |
| 80 | "energy (GeV)","charge", |
80 | "energy (GeV)","charge", |
| 81 | "identity", |
81 | "identity", |
| 82 | "momentum (GeV/c)", |
82 | "momentum (GeV/c)", |
| 83 | "momentum (GeV/c)", |
83 | "momentum (GeV/c)", |
| 84 | "momentum (GeV/c)", |
84 | "momentum (GeV/c)", |
| 85 | "momentum (GeV/c)", |
85 | "momentum (GeV/c)", |
| 86 | "angle (deg.)", |
86 | "angle (deg.)", |
| 87 | "cos(theta |
87 | "cos(theta)"}; |
| 88 | fHtype[id] = 0; |
88 | fHtype[id] = 0; |
| 89 | if (svar.Contains("GetMass" )) fHtype[id]=0; |
89 | if (svar.Contains("GetMass" )) fHtype[id]=0; |
| 90 | if (svar.Contains("GetMomentum")) fHtype[id]=1; |
90 | if (svar.Contains("GetMomentum")) fHtype[id]=1; |
| 91 | if (svar.Contains("GetEnergy" )) fHtype[id]=2; |
91 | if (svar.Contains("GetEnergy" )) fHtype[id]=2; |
| 92 | if (svar.Contains("GetCharge" )) fHtype[id]=3; |
92 | if (svar.Contains("GetCharge" )) fHtype[id]=3; |
| 93 | if (svar.Contains("GetPid" )) fHtype[id]=4; |
93 | if (svar.Contains("GetPid" )) fHtype[id]=4; |
| 94 | if (svar.Contains("GetXMomentum")) fHtype[id]=5; |
94 | if (svar.Contains("GetXMomentum")) fHtype[id]=5; |
| 95 | if (svar.Contains("GetYMomentum")) fHtype[id]=6; |
95 | if (svar.Contains("GetYMomentum")) fHtype[id]=6; |
| 96 | if (svar.Contains("GetZMomentum")) fHtype[id]=7; |
96 | if (svar.Contains("GetZMomentum")) fHtype[id]=7; |
| 97 | if (svar.Contains("GetTransverseMomentum")) fHtype[id]=8; |
97 | if (svar.Contains("GetTransverseMomentum")) fHtype[id]=8; |
| 98 | if (svar.Contains("GetTheta")) fHtype[id]=9; |
98 | if (svar.Contains("GetTheta")) fHtype[id]=9; |
| 99 | if (svar.Contains("GetCosTheta")) fHtype[id]=10; |
99 | if (svar.Contains("GetCosTheta")) fHtype[id]=10; |
| 100 | if (svar.Contains("GetDeltaMass1" )) fHtype[id]=11; |
- | |
| 101 | if (svar.Contains("GetDeltaMass2" )) fHtype[id]=12; |
- | |
| 102 | if (svar.Contains("GetDeltaMass3" )) fHtype[id]=13; |
- | |
| 103 | 100 | ||
| 104 | //fH[id]= new TH1F(TString::Format("h%d",id), TString::Format("%s;%s;N",name,axis[fHtype[id]].Data()), nbins, min, max); |
101 | //fH[id]= new TH1F(TString::Format("h%d",id), TString::Format("%s;%s;N",name,axis[fHtype[id]].Data()), nbins, min, max); |
| 105 | if (fHtype[id]==4) { |
102 | if (fHtype[id]==4) { |
| 106 | fH[id]= new TH1F(TString::Format("h%d",id), TString::Format("%s;%s;N",name,axis[fHtype[id]].Data()), 11, 0, 11); |
103 | fH[id]= new TH1F(TString::Format("h%d",id), TString::Format("%s;%s;N",name,axis[fHtype[id]].Data()), 11, 0, 11); |
| 107 | for (int i=0;i<11;i++) fH[id]->GetXaxis()->SetBinLabel(i+1,names[i]); |
104 | for (int i=0;i<11;i++) fH[id]->GetXaxis()->SetBinLabel(i+1,names[i]); |
| 108 | } else { |
105 | } else { |
| 109 | fH[id]= new TH1F(TString::Format("h%d",id), TString::Format("%s;%s;N",name,axis[fHtype[id]].Data()), nbins, min, max); |
106 | fH[id]= new TH1F(TString::Format("h%d",id), TString::Format("%s;%s;N",name,axis[fHtype[id]].Data()), nbins, min, max); |
| 110 | } |
107 | } |
| 111 | 108 | ||
| 112 | 109 | ||
| 113 | } |
110 | } |
| 114 | 111 | ||
| 115 | 112 | ||
| 116 | 113 | ||
| 117 | int Blab2::Fill(std::vector<int> id, |
114 | int Blab2::Fill(std::vector<int> id, BParticle *p){ |
| 118 | for (int i=0; i< id.size(); i++){ |
115 | for (int i=0; i< id.size(); i++){ |
| 119 |
|
116 | int hid = id[i]; |
| 120 | BParticle *p= particle[0]; |
- | |
| 121 | if (hid>=0 && fH[hid]) { |
117 | if (hid>=0 && fH[hid]) { |
| 122 | double val; |
118 | double val; |
| 123 | switch (fHtype[hid]){ |
119 | switch (fHtype[hid]){ |
| 124 | case 0 : val = p->GetMass(); break; |
120 | case 0 : val = p->GetMass(); break; |
| 125 | case 1 : val = p->GetMomentum(); break; |
121 | case 1 : val = p->GetMomentum(); break; |
| 126 | case 2 : val = p->e(); break; |
122 | case 2 : val = p->e(); break; |
| 127 | case 3 : val = p->charge(); break; |
123 | case 3 : val = p->charge(); break; |
| 128 | case 4 : val = p->pid(); break; |
124 | case 4 : val = p->pid(); break; |
| 129 | case 5 : val = p->px(); break; |
125 | case 5 : val = p->px(); break; |
| 130 | case 6 : val = p->py(); break; |
126 | case 6 : val = p->py(); break; |
| 131 | case 7 : val = p->pz(); break; |
127 | case 7 : val = p->pz(); break; |
| 132 | case 8 : val = p->GetTransverseMomentum(); break; |
128 | case 8 : val = p->GetTransverseMomentum(); break; |
| 133 | case 9 : val = (p->GetMomentum()!=0) ? p->pz()/p->GetMomentum() : 0; val = 180.0*TMath::ACos(val)/TMath::Pi(); break; |
129 | case 9 : val = (p->GetMomentum()!=0) ? p->pz()/p->GetMomentum() : 0; val = 180.0*TMath::ACos(val)/TMath::Pi(); break; |
| 134 | case 10: val = (p->GetMomentum()!=0) ? p->pz()/p->GetMomentum() : 0; break; |
130 | case 10: val = (p->GetMomentum()!=0) ? p->pz()/p->GetMomentum() : 0; break; |
| 135 | case 11 : |
- | |
| 136 | case 12 : |
- | |
| 137 | case 13 : { |
- | |
| 138 | int idx = fHtype[hid]-10; |
- | |
| 139 | val = (particle.size()>idx) ? p->GetMass() - particle[idx]->GetMass() : 0; break; |
- | |
| 140 | } |
- | |
| 141 | default: val = 0 ; break; |
131 | default: val = 0 ; break; |
| 142 | } |
132 | } |
| 143 | fH[hid]->Fill(val); |
133 | fH[hid]->Fill(val); |
| 144 | } |
134 | } |
| 145 | 135 | ||
| 146 | } |
136 | } |
| 147 | 137 | ||
| 148 | return 0; |
138 | return 0; |
| 149 | } |
139 | } |
| 150 | int Blab2::combiner(int _p0, int _p1,int same, SIMPLEPID pid, double min, double max, int hid, int _p2 ){ |
140 | int Blab2::combiner(int _p0, int _p1,int same, SIMPLEPID pid, double min, double max, int hid, int _p2 ){ |
| 151 | std::vector<int> a; |
141 | std::vector<int> a; |
| 152 | return combiner(_p0,_p1,same,pid,min,max,a,_p2); |
142 | return combiner(_p0,_p1,same,pid,min,max,a,_p2); |
| 153 | } |
143 | } |
| 154 | 144 | ||
| 155 | int Blab2::combiner3(int _p0, int _p1, int _p2, int same, SIMPLEPID pid, double min, double max, int hid, int _p3 ){ |
145 | int Blab2::combiner3(int _p0, int _p1, int _p2, int same, SIMPLEPID pid, double min, double max, int hid, int _p3 ){ |
| 156 | std::vector<int> a; |
146 | std::vector<int> a; |
| 157 | return combiner3(_p0,_p1,_p2, same,pid,min,max,a,_p3); |
147 | return combiner3(_p0,_p1,_p2, same,pid,min,max,a,_p3); |
| 158 | } |
148 | } |
| 159 | 149 | ||
| 160 | int Blab2::combiner(int _p0, int _p1,int same, SIMPLEPID pid, double min, double max, std::vector<int> hid, int _p2 ){ |
150 | int Blab2::combiner(int _p0, int _p1,int same, SIMPLEPID pid, double min, double max, std::vector<int> hid, int _p2 ){ |
| 161 | // Loop over all the particles in both lists. |
151 | // Loop over all the particles in both lists. |
| 162 | if (_p0 < 0 ) _p0 =0; |
152 | if (_p0 < 0 ) _p0 =0; |
| 163 | if (_p1 < 0 ) _p1 =0; |
153 | if (_p1 < 0 ) _p1 =0; |
| 164 | 154 | ||
| 165 | 155 | ||
| 166 | fList[_p2]->Clear(); |
156 | fList[_p2]->Clear(); |
| 167 | std::vector<BParticle *> pall(3); |
- | |
| 168 | int nprt=0; |
157 | int nprt=0; |
| 169 | 158 | ||
| 170 | for(TIter next1(fList[_p0]);BParticle * p1 =(BParticle *) next1();) { |
159 | for(TIter next1(fList[_p0]);BParticle * p1 =(BParticle *) next1();) { |
| 171 | // the second loop |
160 | // the second loop |
| 172 | // in the case the second parti |
161 | // in the case the second parti |
| 173 | for(TIter next2 = (_p0!=_p1 && same==0) ? TIter(fList[_p1]): TIter(next1) ; BParticle * p2 =(BParticle *) next2();) { |
162 | for(TIter next2 = (_p0!=_p1 && same==0) ? TIter(fList[_p1]): TIter(next1) ; BParticle * p2 =(BParticle *) next2();) { |
| 174 | if (p1==p2) continue; // do not use the same particle in the combinations |
163 | if (p1==p2) continue; // do not use the same particle in the combinations |
| 175 | BParticle p = *p1 + *p2; // Combine two particles into a new particle |
164 | BParticle p = *p1 + *p2; // Combine two particles into a new particle |
| 176 | pall[0] = &p; |
- | |
| 177 | pall[1] = p1; |
- | |
| 178 | pall[2] = p2; |
- | |
| 179 | - | ||
| 180 | if (p.InMassRange(min, max)){ |
165 | if (p.InMassRange(min, max)){ |
| 181 | Fill(hid, |
166 | Fill(hid, &p); |
| 182 | p.SetPid(pid); // set PID to particlename to fix the particle mass |
167 | p.SetPid(pid); // set PID to particlename to fix the particle mass |
| 183 | p.SetEnergyFromPid(); |
168 | p.SetEnergyFromPid(); |
| 184 | TClonesArray& list = *fList[_p2]; |
169 | TClonesArray& list = *fList[_p2]; |
| 185 | new (list[nprt++]) BParticle ( p ); // create a new entry in kslist list of particles |
170 | new (list[nprt++]) BParticle ( p ); // create a new entry in kslist list of particles |
| 186 | 171 | ||
| 187 | } |
172 | } |
| 188 | 173 | ||
| 189 | } |
174 | } |
| 190 | 175 | ||
| 191 | } |
176 | } |
| 192 | return _p2; |
177 | return _p2; |
| 193 | } |
178 | } |
| 194 | 179 | ||
| 195 | 180 | ||
| 196 | int Blab2::combiner3(int _p0, int _p1,int _p2, int same, SIMPLEPID pid, double min, double max, std::vector<int> hid, int _p3 ){ |
181 | int Blab2::combiner3(int _p0, int _p1,int _p2, int same, SIMPLEPID pid, double min, double max, std::vector<int> hid, int _p3 ){ |
| 197 | // Loop over all the particles in both lists. |
182 | // Loop over all the particles in both lists. |
| 198 | if (_p0 < 0 ) _p0 =0; |
183 | if (_p0 < 0 ) _p0 =0; |
| 199 | if (_p1 < 0 ) _p1 =0; |
184 | if (_p1 < 0 ) _p1 =0; |
| 200 | if (_p2 < 0 ) _p2 =0; |
185 | if (_p2 < 0 ) _p2 =0; |
| 201 | 186 | ||
| 202 | 187 | ||
| 203 | fList[_p3]->Clear(); |
188 | fList[_p3]->Clear(); |
| 204 | std::vector<BParticle *> pall(4); |
- | |
| 205 | - | ||
| 206 | int nprt=0; |
189 | int nprt=0; |
| 207 | 190 | ||
| 208 | for(TIter next1(fList[_p0]);BParticle * p1 =(BParticle *) next1();) { |
191 | for(TIter next1(fList[_p0]);BParticle * p1 =(BParticle *) next1();) { |
| 209 | // the second loop |
192 | // the second loop |
| 210 | // in the case the second parti |
193 | // in the case the second parti |
| 211 | for(TIter next2 = (_p0!=_p1 && same==0) ? TIter(fList[_p1]): TIter(next1) ; BParticle * p2 =(BParticle *) next2();) { |
194 | for(TIter next2 = (_p0!=_p1 && same==0) ? TIter(fList[_p1]): TIter(next1) ; BParticle * p2 =(BParticle *) next2();) { |
| 212 | if (p1==p2) continue; // do not use the same particle in the combinations |
195 | if (p1==p2) continue; // do not use the same particle in the combinations |
| 213 | for(TIter next3 = (_p1!=_p2 && same==0) ? TIter(fList[_p2]): TIter(next2) ; BParticle * p3 =(BParticle *) next3();) { |
196 | for(TIter next3 = (_p1!=_p2 && same==0) ? TIter(fList[_p2]): TIter(next2) ; BParticle * p3 =(BParticle *) next3();) { |
| 214 | if (p2==p3) continue; // do not use the same particle in the combinations |
197 | if (p2==p3) continue; // do not use the same particle in the combinations |
| 215 | BParticle p = |
198 | BParticle p = *p1 + *p2 + *p3; // Combine two particles into a new particle |
| 216 | pall[0] = &p; |
- | |
| 217 | pall[1] = p1; |
- | |
| 218 | pall[2] = p2; |
- | |
| 219 | pall[3] = p3; |
- | |
| 220 | - | ||
| 221 | - | ||
| 222 | if (p.InMassRange(min, max)){ |
199 | if (p.InMassRange(min, max)){ |
| 223 | Fill(hid, |
200 | Fill(hid, &p); |
| 224 | p.SetPid(pid); // set PID to particlename to fix the particle mass |
201 | p.SetPid(pid); // set PID to particlename to fix the particle mass |
| 225 | p.SetEnergyFromPid(); |
202 | p.SetEnergyFromPid(); |
| 226 | TClonesArray& list = *fList[_p3]; |
203 | TClonesArray& list = *fList[_p3]; |
| 227 | new (list[nprt++]) BParticle ( p ); // create a new entry in kslist list of particles |
204 | new (list[nprt++]) BParticle ( p ); // create a new entry in kslist list of particles |
| 228 | } |
205 | } |
| 229 | } |
206 | } |
| 230 | 207 | ||
| 231 | } |
208 | } |
| 232 | 209 | ||
| 233 | } |
210 | } |
| 234 | return _p3; |
211 | return _p3; |
| 235 | } |
212 | } |
| 236 | 213 | ||
| 237 | 214 | ||
| 238 | int Blab2::selector(int pin, int charge, SIMPLEPID type , int hid, int pout ){ |
215 | int Blab2::selector(int pin, int charge, SIMPLEPID type , int hid, int pout ){ |
| 239 | std::vector<int> a; |
216 | std::vector<int> a; |
| 240 | return selector(pin,charge,type,a,pout); |
217 | return selector(pin,charge,type,a,pout); |
| 241 | } |
218 | } |
| 242 | int Blab2::selector(int pin, int charge, SIMPLEPID type , std::vector<int> hid, int pout ){ |
219 | int Blab2::selector(int pin, int charge, SIMPLEPID type , std::vector<int> hid, int pout ){ |
| 243 | if (pin < 0 ) pin =0; |
220 | if (pin < 0 ) pin =0; |
| 244 | 221 | ||
| 245 | fList[pout]->Clear(); |
222 | fList[pout]->Clear(); |
| 246 | int nprt=0; |
223 | int nprt=0; |
| 247 | std::vector<BParticle *> pall(1); |
- | |
| 248 | 224 | ||
| 249 | for(TIter next(fList[pin]); BParticle * p =(BParticle *) next();) { |
225 | for(TIter next(fList[pin]); BParticle * p =(BParticle *) next();) { |
| 250 | if (p->charge()== charge || charge > 1){ |
226 | if (p->charge()== charge || charge > 1){ |
| 251 | if ( p->pid()== type || type == ALL ) { |
227 | if ( p->pid()== type || type == ALL ) { |
| 252 | TClonesArray& list = *fList[pout]; |
228 | TClonesArray& list = *fList[pout]; |
| 253 | new (list[nprt++]) BParticle ( *p ); |
229 | new (list[nprt++]) BParticle ( *p ); |
| 254 | pall[0] = p ; |
- | |
| 255 | Fill(hid, |
230 | Fill(hid, p); |
| 256 | } |
231 | } |
| 257 | } |
232 | } |
| 258 | } |
233 | } |
| 259 | return pout; |
234 | return pout; |
| 260 | } |
235 | } |
| 261 | 236 | ||
| 262 | 237 | ||
| 263 | int Blab2::fix_mass(int pin){ |
238 | int Blab2::fix_mass(int pin){ |
| 264 | if (pin < 0 ) pin =0; |
239 | if (pin < 0 ) pin =0; |
| 265 | for(TIter next(fList[pin]); BParticle * p =(BParticle *) next();) p->SetEnergyFromPid(); |
240 | for(TIter next(fList[pin]); BParticle * p =(BParticle *) next();) p->SetEnergyFromPid(); |
| 266 | return pin; |
241 | return pin; |
| 267 | } |
242 | } |
| 268 | 243 | ||
| 269 | void Blab2::plist(int i){ |
244 | void Blab2::plist(int i){ |
| 270 | fList[i]= new TClonesArray( "BParticle", 500 ); |
245 | fList[i]= new TClonesArray( "BParticle", 500 ); |
| 271 | } |
246 | } |
| 272 | Blab2::~Blab2(){}; |
247 | Blab2::~Blab2(){}; |
| 273 | 248 | ||
| 274 | 249 | ||
| 275 | void send_message(int id, TString msg, int progress){ |
250 | void send_message(int id, TString msg, int progress){ |
| 276 | static Hdr hdr; |
251 | static Hdr hdr; |
| 277 | 252 | ||
| 278 | hdr.id = id; |
253 | hdr.id = id; |
| 279 | hdr.len= msg.Length(); |
254 | hdr.len= msg.Length(); |
| 280 | hdr.progress= progress; |
255 | hdr.progress= progress; |
| 281 | fwrite(&hdr,3*sizeof(int),1,stdout); |
256 | fwrite(&hdr,3*sizeof(int),1,stdout); |
| 282 | fwrite(msg.Data(),hdr.len,1,stdout); |
257 | fwrite(msg.Data(),hdr.len,1,stdout); |
| 283 | fflush(stdout); |
258 | fflush(stdout); |
| 284 | 259 | ||
| 285 | } |
260 | } |
| 286 | 261 | ||
| 287 | 262 | ||
| 288 | void Blab2::Process(){ |
263 | void Blab2::Process(){ |
| 289 | 264 | ||
| 290 | char sList[0xFFFF]; |
265 | char sList[0xFFFF]; |
| 291 | for (int i=0;i<100;i++) fH[i]=NULL; |
266 | for (int i=0;i<100;i++) fH[i]=NULL; |
| 292 | for (int i=0;i<100;i++) fHtype[i]=0; |
267 | for (int i=0;i<100;i++) fHtype[i]=0; |
| 293 | for (int i=0;i<100;i++) fList[i]=NULL; |
268 | for (int i=0;i<100;i++) fList[i]=NULL; |
| 294 | 269 | ||
| 295 | Init(); |
270 | Init(); |
| 296 | 271 | ||
| 297 | TFile * f = new TFile(TString::Format("../../data/ |
272 | TFile * f = new TFile(TString::Format("../../data/%s",fData.Data())); // Open a data file |
| 298 | if(f->IsZombie()) { send_message(0,TString::Format("File |
273 | if(f->IsZombie()) { send_message(0,TString::Format("File %s not found\n",fData.Data()), 0 ); return; } |
| 299 | TTree * t =(TTree *) f-> Get( "T"); // Obtain a pointer to a tree of "event" data in the file |
274 | TTree * t =(TTree *) f-> Get( "T"); // Obtain a pointer to a tree of "event" data in the file |
| 300 | BEvent * mevent = new BEvent(); // Create a "BEvent" object where data from the file will be loaded |
275 | BEvent * mevent = new BEvent(); // Create a "BEvent" object where data from the file will be loaded |
| 301 | TBranch * branch = t-> GetBranch( "BEvent"); // Obtain a branch for "BEvent" in the tree |
276 | TBranch * branch = t-> GetBranch( "BEvent"); // Obtain a branch for "BEvent" in the tree |
| 302 | branch-> SetAddress(&mevent); // Register created "BEvent" object to the branch |
277 | branch-> SetAddress(&mevent); // Register created "BEvent" object to the branch |
| 303 | TH1F *fHnprt= new TH1F("h100", "Number of particles in the event;N particles;N events", 50, -0.5, 49.5); |
278 | TH1F *fHnprt= new TH1F("h100", "Number of particles in the event;N particles;N events", 50, -0.5, 49.5); |
| 304 | 279 | ||
| 305 | 280 | ||
| 306 | 281 | ||
| 307 | send_message(0, TString::Format("<br>Number of Events in the file %lld<br>\n", t->GetEntries() ),0); |
282 | send_message(0, TString::Format("<br>Number of Events in the file %lld<br>\n", t->GetEntries() ),0); |
| 308 | TStopwatch timer; |
283 | TStopwatch timer; |
| 309 | timer.Start(); |
284 | timer.Start(); |
| 310 | int nev = 0; |
285 | int nev = 0; |
| 311 | int i =TMath::Min(fNfirst, (UInt_t) t-> GetEntries()); |
286 | int i =TMath::Min(fNfirst, (UInt_t) t-> GetEntries()); |
| 312 | int cNeve=TMath::Min(fNfirst+fNeve, (UInt_t) t-> GetEntries()); |
287 | int cNeve=TMath::Min(fNfirst+fNeve, (UInt_t) t-> GetEntries()); |
| 313 | int fPart = fPrint; |
288 | int fPart = fPrint; |
| 314 | int totaltracks = 0; |
289 | int totaltracks = 0; |
| 315 | while (i<cNeve){ |
290 | while (i<cNeve){ |
| 316 | t-> GetEntry(i); // Read the content of the event from the file |
291 | t-> GetEntry(i); // Read the content of the event from the file |
| 317 | fList[0]= mevent->GetParticleList(); |
292 | fList[0]= mevent->GetParticleList(); |
| 318 | 293 | ||
| 319 | event(); |
294 | event(); |
| 320 | 295 | ||
| 321 | int progress = (100*i)/cNeve; |
296 | int progress = (100*i)/cNeve; |
| 322 | if (i%10000==0) send_message(2, TString::Format("Event %d\n",i), progress); |
297 | if (i%10000==0) send_message(2, TString::Format("Event %d\n",i), progress); |
| 323 | 298 | ||
| 324 | int nprt=0; |
299 | int nprt=0; |
| 325 | if (nev>100) fPrint = 0; // disable particle prints for huge numer of events |
300 | if (nev>100) fPrint = 0; // disable particle prints for huge numer of events |
| 326 | if (fPrint) sprintf(sList,"Primary particle list for Event %d<br/><table class='plist' ><tr><th>N<th>px(GeV/c)<th>py(GeV/c)<th>pz(GeV/c)<th>p(GeV/c)<th>Energy(GeV)<th>Charge<th>ID<th></tr>", i); |
301 | if (fPrint) sprintf(sList,"Primary particle list for Event %d<br/><table class='plist' ><tr><th>N<th>px(GeV/c)<th>py(GeV/c)<th>pz(GeV/c)<th>p(GeV/c)<th>Energy(GeV)<th>Charge<th>ID<th></tr>", i); |
| 327 | for(TIter next(fList[0]); BParticle * p =(BParticle *) next();) { |
302 | for(TIter next(fList[0]); BParticle * p =(BParticle *) next();) { |
| 328 | nprt++; |
303 | nprt++; |
| 329 | if (fPrint) sprintf(sList,"%s<tr><td>%d<td>%g<td>%g<td>%g<td>%g<td>%g<td>%1.0f<td>%s</tr>",sList,nprt, p->px(),p->py(),p->pz(),p->GetMomentum(),p->e(), p->charge(),names[p->pid()] ); |
304 | if (fPrint) sprintf(sList,"%s<tr><td>%d<td>%g<td>%g<td>%g<td>%g<td>%g<td>%1.0f<td>%s</tr>",sList,nprt, p->px(),p->py(),p->pz(),p->GetMomentum(),p->e(), p->charge(),names[p->pid()] ); |
| 330 | } |
305 | } |
| 331 | if (fPart) fHnprt->Fill(nprt); |
306 | if (fPart) fHnprt->Fill(nprt); |
| 332 | totaltracks += nprt; |
307 | totaltracks += nprt; |
| 333 | if (fPrint) { |
308 | if (fPrint) { |
| 334 | sprintf(sList,"%s</table>",sList); |
309 | sprintf(sList,"%s</table>",sList); |
| 335 | send_message(0, TString(sList),progress); |
310 | send_message(0, TString(sList),progress); |
| 336 | nev++; |
311 | nev++; |
| 337 | } |
312 | } |
| 338 | mevent-> Clear(); // Clear the memory. |
313 | mevent-> Clear(); // Clear the memory. |
| 339 | for (int k=0;k<100;k++) if (fList[k]!=0) fList[k]->Clear(); |
314 | for (int k=0;k<100;k++) if (fList[k]!=0) fList[k]->Clear(); |
| 340 | i++; |
315 | i++; |
| 341 | } |
316 | } |
| 342 | double avgtracks=(i)?float(totaltracks)/i:0; |
317 | double avgtracks=(i)?float(totaltracks)/i:0; |
| 343 | send_message(0, TString::Format("Number of events processed: %d<br/>\nNumber of particles: %d<br/>\nAverage number of particles per event %f<br/>\n", i, totaltracks, avgtracks ),100); |
318 | send_message(0, TString::Format("Number of events processed: %d<br/>\nNumber of particles: %d<br/>\nAverage number of particles per event %f<br/>\n", i, totaltracks, avgtracks ),100); |
| 344 | 319 | ||
| 345 | if (fPart) send_message(1,TBufferJSON::ConvertToJSON(fHnprt),100 ); |
320 | if (fPart) send_message(1,TBufferJSON::ConvertToJSON(fHnprt),100 ); |
| 346 | 321 | ||
| 347 | 322 | ||
| 348 | for (int i=0;i<100;i++) if (fH[i]!=0) send_message(1,TBufferJSON::ConvertToJSON(fH[i]),100 ); |
323 | for (int i=0;i<100;i++) if (fH[i]!=0) send_message(1,TBufferJSON::ConvertToJSON(fH[i]),100 ); |
| 349 | 324 | ||
| 350 | TDatime d; |
325 | TDatime d; |
| 351 | timer.Stop(); |
326 | timer.Stop(); |
| 352 | send_message(3, TString::Format("'%s', %d, %f, %f", d.AsSQLString(),i, timer.RealTime(), timer.CpuTime() ),100); |
327 | send_message(3, TString::Format("'%s', %d, %f, %f", d.AsSQLString(),i, timer.RealTime(), timer.CpuTime() ),100); |
| 353 | 328 | ||
| 354 | } |
329 | } |
| 355 | 330 | ||
| 356 | 331 | ||
| 357 | 332 | ||