Rev 272 | Rev 277 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 272 | Rev 273 | ||
|---|---|---|---|
| Line 5... | Line 5... | ||
| 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 | 11 | ||
| 11 | #include "BParticle.h" |
12 | #include "BParticle.h" |
| 12 | #include "BEvent.h" |
13 | #include "BEvent.h" |
| 13 | 14 | ||
| 14 | class Hdr{ |
15 | class Hdr{ |
| Line 55... | Line 56... | ||
| 55 | }; |
56 | }; |
| 56 | 57 | ||
| 57 | 58 | ||
| 58 | void Blab2::h1d(const char *varname, const char *name, int nbins, double min, double max, int id ){ |
59 | void Blab2::h1d(const char *varname, const char *name, int nbins, double min, double max, int id ){ |
| 59 | TString svar(varname); |
60 | TString svar(varname); |
| 60 | TString axis[]={"mass (GeV/c2)", |
61 | TString axis[]={"mass (GeV/c2)", |
| - | 62 | "momentum (GeV/c)", |
|
| - | 63 | "energy (GeV)","charge", |
|
| - | 64 | "identity", |
|
| - | 65 | "momentum (GeV/c)", |
|
| - | 66 | "momentum (GeV/c)", |
|
| - | 67 | "momentum (GeV/c)", |
|
| - | 68 | "momentum (GeV/c)", |
|
| - | 69 | "angle (deg.)", |
|
| - | 70 | "cos(theta)"}; |
|
| 61 | fHtype[id] = 0; |
71 | fHtype[id] = 0; |
| 62 | if (svar.Contains("GetMass" )) fHtype[id]=0; |
72 | if (svar.Contains("GetMass" )) fHtype[id]=0; |
| 63 | if (svar.Contains("GetMomentum")) fHtype[id]=1; |
73 | if (svar.Contains("GetMomentum")) fHtype[id]=1; |
| 64 | if (svar.Contains("GetEnergy" )) fHtype[id]=2; |
74 | if (svar.Contains("GetEnergy" )) fHtype[id]=2; |
| 65 | if (svar.Contains("GetCharge" )) fHtype[id]=3; |
75 | if (svar.Contains("GetCharge" )) fHtype[id]=3; |
| 66 | if (svar.Contains("GetPid" )) fHtype[id]=4; |
76 | if (svar.Contains("GetPid" )) fHtype[id]=4; |
| 67 | if (svar.Contains("GetXMomentum")) fHtype[id]=5; |
77 | if (svar.Contains("GetXMomentum")) fHtype[id]=5; |
| 68 | if (svar.Contains("GetYMomentum")) fHtype[id]=6; |
78 | if (svar.Contains("GetYMomentum")) fHtype[id]=6; |
| 69 | if (svar.Contains("GetZMomentum")) fHtype[id]=7; |
79 | if (svar.Contains("GetZMomentum")) fHtype[id]=7; |
| 70 | if (svar.Contains("GetTranverseMomentum")) fHtype[id]=8; |
80 | if (svar.Contains("GetTranverseMomentum")) fHtype[id]=8; |
| - | 81 | if (svar.Contains("GetTheta")) fHtype[id]=9; |
|
| - | 82 | if (svar.Contains("GetCosTheta")) fHtype[id]=10; |
|
| 71 | 83 | ||
| 72 | fH[id]= new TH1F(TString::Format("h%d",id), TString::Format("%s;%s;N",name,axis[fHtype[id]].Data()), nbins, min, max); |
84 | fH[id]= new TH1F(TString::Format("h%d",id), TString::Format("%s;%s;N",name,axis[fHtype[id]].Data()), nbins, min, max); |
| 73 | 85 | ||
| 74 | if (fHtype[id]==4) { |
86 | if (fHtype[id]==4) { |
| 75 | fH[id]= new TH1F(TString::Format("h%d",id), TString::Format("%s;%s;N",name,axis[fHtype[id]].Data()), 11, 0, 11); |
87 | fH[id]= new TH1F(TString::Format("h%d",id), TString::Format("%s;%s;N",name,axis[fHtype[id]].Data()), 11, 0, 11); |
| Line 80... | Line 92... | ||
| 80 | 92 | ||
| 81 | 93 | ||
| 82 | } |
94 | } |
| 83 | 95 | ||
| 84 | int Blab2::Fill(int hid, BParticle *p){ |
96 | int Blab2::Fill(int hid, BParticle *p){ |
| 85 | if (hid>=0 && fH[hid]) { |
97 | if (hid>=0 && fH[hid]) { |
| 86 |
|
98 | double val; |
| 87 | switch (fHtype[hid]){ |
99 | switch (fHtype[hid]){ |
| 88 | case 0: val = p->GetMass(); break; |
100 | case 0 : val = p->GetMass(); break; |
| 89 | case 1: val = p->GetMomentum(); break; |
101 | case 1 : val = p->GetMomentum(); break; |
| 90 | case 2: val = p->e(); break; |
102 | case 2 : val = p->e(); break; |
| 91 | case 3: val = p->charge(); break; |
103 | case 3 : val = p->charge(); break; |
| 92 | case 4: val = p->pid(); break; |
104 | case 4 : val = p->pid(); break; |
| 93 | case 5: val = p->px(); break; |
105 | case 5 : val = p->px(); break; |
| 94 | case 6: val = p->py(); break; |
106 | case 6 : val = p->py(); break; |
| 95 | case 7: val = p->pz(); break; |
107 | case 7 : val = p->pz(); break; |
| - | 108 | case 8 : val = p->GetTransverseMomentum(); break; |
|
| - | 109 | case 9 : val = (p->GetMomentum()!=0) ? p->pz()/p->GetMomentum() : 0; val = 180*acos(val)/TMath::Pi(); break; |
|
| 96 | case |
110 | case 10: val = (p->GetMomentum()!=0) ? p->pz()/p->GetMomentum() : 0; break; |
| 97 | default |
111 | default: val = 0 ; break; |
| 98 |
|
112 | } |
| 99 | fH[hid]->Fill(val); |
113 | fH[hid]->Fill(val); |
| 100 | } |
114 | } |
| 101 | 115 | ||
| 102 | return 0; |
116 | return 0; |
| 103 | } |
117 | } |
| Line 126... | Line 140... | ||
| 126 | 140 | ||
| 127 | } |
141 | } |
| 128 | 142 | ||
| 129 | } |
143 | } |
| 130 | 144 | ||
| 131 | } |
145 | } |
| 132 | return _p2; |
146 | return _p2; |
| 133 | } |
147 | } |
| 134 | 148 | ||
| 135 | 149 | ||
| 136 | int Blab2::selector(int pin, int charge, SIMPLEPID type , int hid, int pout ){ |
150 | int Blab2::selector(int pin, int charge, SIMPLEPID type , int hid, int pout ){ |
| Line 171... | Line 185... | ||
| 171 | hdr.len= msg.Length(); |
185 | hdr.len= msg.Length(); |
| 172 | hdr.progress= progress; |
186 | hdr.progress= progress; |
| 173 | fwrite(&hdr,3*sizeof(int),1,stdout); |
187 | fwrite(&hdr,3*sizeof(int),1,stdout); |
| 174 | fwrite(msg.Data(),hdr.len,1,stdout); |
188 | fwrite(msg.Data(),hdr.len,1,stdout); |
| 175 | fflush(stdout); |
189 | fflush(stdout); |
| 176 | 190 | ||
| 177 | } |
191 | } |
| 178 | 192 | ||
| 179 | 193 | ||
| 180 | void Blab2::Process(){ |
194 | void Blab2::Process(){ |
| 181 | 195 | ||
| 182 | char sList[0xFFFF]; |
196 | char sList[0xFFFF]; |
| 183 | for (int i=0;i<100;i++) fH[i]=NULL; |
197 | for (int i=0;i<100;i++) fH[i]=NULL; |
| 184 | for (int i=0;i<100;i++) fHtype[i]=0; |
198 | for (int i=0;i<100;i++) fHtype[i]=0; |
| 185 | for (int i=0;i<100;i++) fList[i]=NULL; |
199 | for (int i=0;i<100;i++) fList[i]=NULL; |
| 186 | 200 | ||
| 187 | Init(); |
201 | Init(); |
| 188 | 202 | ||
| 189 | TFile * f = new TFile(TString::Format("../../data/hadron-%d.root",fData)); // Open a data file |
203 | TFile * f = new TFile(TString::Format("../../data/hadron-%d.root",fData)); // Open a data file |
| 190 | if(f->IsZombie()) { send_message(0,TString::Format("File %d not found\n",fData), 0 ); return; } |
204 | if(f->IsZombie()) { send_message(0,TString::Format("File %d not found\n",fData), 0 ); return; } |
| 191 | TTree * t =(TTree *) f-> Get( "T"); // Obtain a pointer to a tree of "event" data in the file |
205 | TTree * t =(TTree *) f-> Get( "T"); // Obtain a pointer to a tree of "event" data in the file |
| 192 | BEvent * mevent = new BEvent(); // Create a "BEvent" object where data from the file will be loaded |
206 | BEvent * mevent = new BEvent(); // Create a "BEvent" object where data from the file will be loaded |
| 193 | TBranch * branch = t-> GetBranch( "BEvent"); // Obtain a branch for "BEvent" in the tree |
207 | TBranch * branch = t-> GetBranch( "BEvent"); // Obtain a branch for "BEvent" in the tree |
| 194 | branch-> SetAddress(&mevent); // Register created "BEvent" object to the branch |
208 | branch-> SetAddress(&mevent); // Register created "BEvent" object to the branch |
| 195 | TH1F *fHnprt= new TH1F("h100", "Number of particles in the event;N particles;N events", 50, -0.5, 49.5); |
209 | TH1F *fHnprt= new TH1F("h100", "Number of particles in the event;N particles;N events", 50, -0.5, 49.5); |
| 196 | 210 | ||
| 197 | 211 | ||
| 198 | 212 | ||
| 199 | send_message(0, TString::Format("<br>Number of Events in the file %lld<br>\n", t->GetEntries() ),0); |
213 | send_message(0, TString::Format("<br>Number of Events in the file %lld<br>\n", t->GetEntries() ),0); |
| 200 | TStopwatch timer; |
214 | TStopwatch timer; |
| 201 | timer.Start(); |
215 | timer.Start(); |
| 202 | int nev = 0; |
216 | int nev = 0; |
| 203 | int i =TMath::Min(fNfirst, (UInt_t) t-> GetEntries()); |
217 | int i =TMath::Min(fNfirst, (UInt_t) t-> GetEntries()); |
| 204 | int cNeve=TMath::Min(fNfirst+fNeve, (UInt_t) t-> GetEntries()); |
218 | int cNeve=TMath::Min(fNfirst+fNeve, (UInt_t) t-> GetEntries()); |
| - | 219 | int fPart = fPrint; |
|
| - | 220 | int totaltracks = 0; |
|
| 205 | while (i<cNeve){ |
221 | while (i<cNeve){ |
| 206 | t-> GetEntry(i); // Read the content of the event from the file |
222 | t-> GetEntry(i); // Read the content of the event from the file |
| 207 | fList[0]= mevent->GetParticleList(); |
223 | fList[0]= mevent->GetParticleList(); |
| 208 | 224 | ||
| 209 | event(); |
225 | event(); |
| Line 216... | Line 232... | ||
| 216 | 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); |
232 | 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); |
| 217 | for(TIter next(fList[0]); BParticle * p =(BParticle *) next();) { |
233 | for(TIter next(fList[0]); BParticle * p =(BParticle *) next();) { |
| 218 | nprt++; |
234 | nprt++; |
| 219 | 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()] ); |
235 | 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()] ); |
| 220 | } |
236 | } |
| 221 | fHnprt->Fill(nprt); |
237 | if (fPart) fHnprt->Fill(nprt); |
| - | 238 | totaltracks += nprt; |
|
| 222 | if (fPrint) { |
239 | if (fPrint) { |
| 223 | sprintf(sList,"%s</table>",sList); |
240 | sprintf(sList,"%s</table>",sList); |
| 224 | send_message(0, TString(sList),progress); |
241 | send_message(0, TString(sList),progress); |
| 225 | nev++; |
242 | nev++; |
| 226 | } |
243 | } |
| 227 | mevent-> Clear(); // Clear the memory. |
244 | mevent-> Clear(); // Clear the memory. |
| 228 | for (int k=0;k<100;k++) if (fList[k]!=0) fList[k]->Clear(); |
245 | for (int k=0;k<100;k++) if (fList[k]!=0) fList[k]->Clear(); |
| 229 | i++; |
246 | i++; |
| 230 | } |
247 | } |
| - | 248 | double avgtracks=(i)?float(totaltracks)/i:0; |
|
| - | 249 | 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); |
|
| 231 | 250 | ||
| 232 | send_message(2, TString::Format("Number of events processed %d\n", i ),100); |
- | |
| 233 | - | ||
| 234 | send_message(1,TBufferJSON::ConvertToJSON(fHnprt),100 ); |
251 | if (fPart) send_message(1,TBufferJSON::ConvertToJSON(fHnprt),100 ); |
| 235 | 252 | ||
| 236 | 253 | ||
| 237 | for (int i=0;i<100;i++) if (fH[i]!=0) send_message(1,TBufferJSON::ConvertToJSON(fH[i]),100 ); |
254 | for (int i=0;i<100;i++) if (fH[i]!=0) send_message(1,TBufferJSON::ConvertToJSON(fH[i]),100 ); |
| 238 | 255 | ||
| 239 | TDatime d; |
256 | TDatime d; |