Subversion Repositories f9daq

Rev

Rev 268 | Rev 273 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 268 Rev 272
Line 4... Line 4...
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 <TClonesArray.h>
9
#include <TBufferJSON.h>
10
 
10
 
11
#include "BParticle.h"
11
#include "BParticle.h"
12
#include "BEvent.h"
12
#include "BEvent.h"
13
 
13
 
14
class Hdr{
14
class Hdr{
Line 19... Line 19...
19
};
19
};
20
 
20
 
21
 
21
 
22
class Blab2 {
22
class Blab2 {
23
public:
23
public:
-
 
24
const char *names[11]={"photon", "electron", "pion", "muon", "kaon", "proton", "J/Psi", "D", "D*", "B", "Phi"};
-
 
25
 
24
UInt_t fNeve;
26
UInt_t fNeve;
25
UInt_t fNfirst;
27
UInt_t fNfirst;
26
UInt_t fPrint;
28
UInt_t fPrint;
27
int fData;
29
int fData;
28
TH1F *fH[100];
30
TH1F *fH[100];
Line 53... Line 55...
53
};
55
};
54
 
56
 
55
 
57
 
56
void Blab2::h1d(const char *varname, const char *name, int nbins, double min, double max, int id ){
58
void Blab2::h1d(const char *varname, const char *name, int nbins, double min, double max, int id ){
57
   TString svar(varname);
59
   TString svar(varname);
58
   TString axis[3]={"mass (GeV/c2)","momentum (GeV/c)","energy (GeV)"};
60
   TString axis[]={"mass (GeV/c2)","momentum (GeV/c)","energy (GeV)","charge","identity","momentum (GeV/c)","momentum (GeV/c)","momentum (GeV/c)","momentum (GeV/c)"};
59
   fHtype[id] = 0;
61
   fHtype[id] = 0;
60
   if (svar.Contains("GetMass"    )) fHtype[id]=0;
62
   if (svar.Contains("GetMass"    )) fHtype[id]=0;
61
   if (svar.Contains("GetMomentum")) fHtype[id]=1;
63
   if (svar.Contains("GetMomentum")) fHtype[id]=1;
62
   if (svar.Contains("GetEnergy"  )) fHtype[id]=2;
64
   if (svar.Contains("GetEnergy"  )) fHtype[id]=2;
-
 
65
   if (svar.Contains("GetCharge"  )) fHtype[id]=3;
-
 
66
   if (svar.Contains("GetPid"     )) fHtype[id]=4;
-
 
67
   if (svar.Contains("GetXMomentum")) fHtype[id]=5;
-
 
68
   if (svar.Contains("GetYMomentum")) fHtype[id]=6;
-
 
69
   if (svar.Contains("GetZMomentum")) fHtype[id]=7;
-
 
70
   if (svar.Contains("GetTranverseMomentum")) fHtype[id]=8;
63
 
71
 
64
   fH[id]= new TH1F(TString::Format("h%d",id), TString::Format("%s;%s;N",name,axis[fHtype[id]].Data()), nbins, min, max);
72
   fH[id]= new TH1F(TString::Format("h%d",id), TString::Format("%s;%s;N",name,axis[fHtype[id]].Data()), nbins, min, max);
-
 
73
   
-
 
74
   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);
-
 
76
     for (int i=0;i<11;i++) fH[id]->GetXaxis()->SetBinLabel(i+1,names[i]);
-
 
77
   } else {
-
 
78
     fH[id]= new TH1F(TString::Format("h%d",id), TString::Format("%s;%s;N",name,axis[fHtype[id]].Data()), nbins, min, max);  
-
 
79
   }
-
 
80
   
-
 
81
 
65
}
82
}
66
 
83
 
67
int Blab2::Fill(int hid, BParticle *p){
84
int Blab2::Fill(int hid, BParticle *p){
68
if (hid>=0 && fH[hid]) {
85
if (hid>=0 && fH[hid]) {
69
      float val;
86
      float val;
70
      switch (fHtype[hid]){
87
      switch (fHtype[hid]){
71
      case 0: val = p->GetMass(); break;
88
      case 0: val = p->GetMass(); break;
72
      case 1: val = p->GetMomentum(); break;
89
      case 1: val = p->GetMomentum(); break;
73
      case 2: val = p->e(); break;
90
      case 2: val = p->e(); break;
-
 
91
      case 3: val = p->charge(); break;
-
 
92
      case 4: val = p->pid(); break;
-
 
93
      case 5: val = p->px(); break;
-
 
94
      case 6: val = p->py(); break;
-
 
95
      case 7: val = p->pz(); break;
-
 
96
      case 8: val = sqrt(p->px()*p->px()+p->py()*p->py()); break;
74
      default : val = 0 ; break;
97
      default : val = 0 ; break;
75
      }
98
      }
76
   fH[hid]->Fill(val);
99
   fH[hid]->Fill(val);
77
}  
100
}  
78
 
101
 
Line 84... Line 107...
84
 if (_p0 < 0 ) _p0 =0;
107
 if (_p0 < 0 ) _p0 =0;
85
 if (_p1 < 0 ) _p1 =0;
108
 if (_p1 < 0 ) _p1 =0;
86
 
109
 
87
 
110
 
88
 fList[_p2]->Clear();
111
 fList[_p2]->Clear();
89
 int nprt=0;
112
 int nprt=0;
90
 
113
 
91
 for(TIter next1(fList[_p0]);BParticle * p1 =(BParticle *) next1();) {
114
 for(TIter next1(fList[_p0]);BParticle * p1 =(BParticle *) next1();) {
92
    // the second loop
115
    // the second loop
93
   // in the case the second parti 
116
   // in the case the second parti 
94
   for(TIter next2 = (_p0!=_p1 && same==0) ?  TIter(fList[_p1]): TIter(next1) ; BParticle * p2 =(BParticle *) next2();) {  
117
   for(TIter next2 = (_p0!=_p1 && same==0) ?  TIter(fList[_p1]): TIter(next1) ; BParticle * p2 =(BParticle *) next2();) {  
95
      if (p1==p2) continue;     // do not use the same particle in the combinations
118
      if (p1==p2) continue;     // do not use the same particle in the combinations
96
      BParticle  p = *p1 + *p2; // Combine two particles into a new particle   
119
      BParticle  p = *p1 + *p2; // Combine two particles into a new particle   
97
      if (p.InMassRange(min, max)){
120
      if (p.InMassRange(min, max)){
-
 
121
            Fill(hid, &p);
98
            p.SetPid(pid); // set PID to particlename to fix the particle mass
122
            p.SetPid(pid); // set PID to particlename to fix the particle mass
-
 
123
            p.SetEnergyFromPid();
99
            TClonesArray& list = *fList[_p2];
124
            TClonesArray& list = *fList[_p2];          
100
            new (list[nprt++]) BParticle ( p ); // create a new entry in kslist list of particles
125
            new (list[nprt++]) BParticle ( p ); // create a new entry in kslist list of particles
101
            Fill(hid, &p);
126
           
102
      }
127
      }
103
       
128
       
104
   }
129
   }
105
               
130
               
106
 }
131
 }
Line 108... Line 133...
108
}
133
}
109
 
134
 
110
 
135
 
111
int Blab2::selector(int pin, int charge, SIMPLEPID type ,  int hid, int pout ){
136
int Blab2::selector(int pin, int charge, SIMPLEPID type ,  int hid, int pout ){
112
 if (pin < 0 ) pin =0;
137
 if (pin < 0 ) pin =0;
113
 
138
 
114
  fList[pout]->Clear();
139
  fList[pout]->Clear();
115
  int nprt=0;
140
  int nprt=0;
116
 
141
 
117
  for(TIter next(fList[pin]); BParticle * p =(BParticle *) next();) {
142
  for(TIter next(fList[pin]); BParticle * p =(BParticle *) next();) {
-
 
143
        if (p->charge()== charge || charge > 1){
118
        if (p->charge()== charge && ( p->pid()== type || type == ALL )) {
144
          if ( p->pid()== type || type == ALL ) {
119
          TClonesArray& list = *fList[pout];
145
            TClonesArray& list = *fList[pout];
120
          new (list[nprt++]) BParticle ( *p );
146
            new (list[nprt++]) BParticle ( *p );
121
          Fill(hid, p);
147
            Fill(hid, p);
-
 
148
          }
122
        }
149
        }
123
  }      
150
  }      
124
   return pout;
151
   return pout;
125
}
152
}
126
 
153
 
127
 
154
 
128
int Blab2::fix_mass(int pin){
155
int Blab2::fix_mass(int pin){
129
   if (pin < 0 ) pin =0;
156
   if (pin < 0 ) pin =0;
130
   for(TIter next(fList[pin]); BParticle * p =(BParticle *) next();)  p->SetEnergyFromPid();
157
   for(TIter next(fList[pin]); BParticle * p =(BParticle *) next();)  p->SetEnergyFromPid();
131
   return pin;
158
   return pin;
132
}
159
}
133
 
160
 
134
void Blab2::plist(int i){
161
void Blab2::plist(int i){
135
  fList[i]= new TClonesArray( "BParticle", 500 );
162
  fList[i]= new TClonesArray( "BParticle", 500 );
136
}
163
}
137
Blab2::~Blab2(){};
164
Blab2::~Blab2(){};
138
 
165
 
139
 
166
 
140
void send_message(int id, TString msg, int progress){
167
void send_message(int id, TString msg, int progress){
141
static Hdr hdr;
168
static Hdr hdr;
142
 
169
 
143
   hdr.id = id;
170
   hdr.id = id;
144
   hdr.len= msg.Length();
171
   hdr.len= msg.Length();
145
   hdr.progress= progress;
172
   hdr.progress= progress;
146
   fwrite(&hdr,3*sizeof(int),1,stdout);
173
   fwrite(&hdr,3*sizeof(int),1,stdout);
147
   fwrite(msg.Data(),hdr.len,1,stdout);
174
   fwrite(msg.Data(),hdr.len,1,stdout);
Line 156... Line 183...
156
for (int i=0;i<100;i++) fH[i]=NULL;
183
for (int i=0;i<100;i++) fH[i]=NULL;
157
for (int i=0;i<100;i++) fHtype[i]=0;
184
for (int i=0;i<100;i++) fHtype[i]=0;
158
for (int i=0;i<100;i++) fList[i]=NULL;
185
for (int i=0;i<100;i++) fList[i]=NULL;
159
 
186
 
160
Init();
187
Init();
161
 
188
 
162
TFile * f = new TFile(TString::Format("../../data/hadron-%d.root",fData)); // Open a data file
189
TFile * f = new TFile(TString::Format("../../data/hadron-%d.root",fData)); // Open a data file
163
if(f->IsZombie()) {  send_message(0,TString::Format("File %d not found\n",fData), 0 );  return; }  
190
if(f->IsZombie()) {  send_message(0,TString::Format("File %d not found\n",fData), 0 );  return; }  
164
TTree * t =(TTree *) f-> Get( "T"); // Obtain a pointer to a tree of "event" data in the file
191
TTree * t =(TTree *) f-> Get( "T"); // Obtain a pointer to a tree of "event" data in the file
165
BEvent * mevent = new BEvent(); // Create a  "BEvent" object where data from the file will be loaded
192
BEvent * mevent = new BEvent(); // Create a  "BEvent" object where data from the file will be loaded
166
TBranch * branch = t-> GetBranch( "BEvent"); // Obtain a branch for "BEvent" in the tree
193
TBranch * branch = t-> GetBranch( "BEvent"); // Obtain a branch for "BEvent" in the tree
167
branch-> SetAddress(&mevent); // Register created "BEvent" object to the branch
194
branch-> SetAddress(&mevent); // Register created "BEvent" object to the branch
168
TH1F *fHnprt= new TH1F("h100", "Number of particles in the event;N particles;N events", 50, -0.5, 49.5);
195
TH1F *fHnprt= new TH1F("h100", "Number of particles in the event;N particles;N events", 50, -0.5, 49.5);
169
TH1F *fHid= new TH1F("h101", "Particle types;ID;N particles", 6, -0, 6);
-
 
170
const char *names[12]={"PHOTON", "ELECTRON", "PION", "MUON", "KAON", "PROTON", "JPSI", "D", "DSTAR", "B","KS", "ALL" };
-
 
171
for (int i=1;i<=6;i++) fHid->GetXaxis()->SetBinLabel(i,names[i-1]);
-
 
-
 
196
 
-
 
197
 
172
 
198
 
173
send_message(0, TString::Format("<br>Number of Events in the file %lld<br>\n", t->GetEntries() ),0);
199
send_message(0, TString::Format("<br>Number of Events in the file %lld<br>\n", t->GetEntries() ),0);
174
TStopwatch timer;
200
TStopwatch timer;
175
timer.Start();
201
timer.Start();
176
int nev  = 0;
202
int nev  = 0;
Line 188... Line 214...
188
 int nprt=0;
214
 int nprt=0;
189
 if (nev>100) fPrint = 0; // disable particle prints for huge numer of events
215
 if (nev>100) fPrint = 0; // disable particle prints for huge numer of events
190
 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);
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);
191
 for(TIter next(fList[0]); BParticle * p =(BParticle *) next();) {
217
 for(TIter next(fList[0]); BParticle * p =(BParticle *) next();) {
192
   nprt++;
218
   nprt++;
193
   fHid->Fill(p->pid());
-
 
194
   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()] );
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()] );
195
 }
220
 }
196
 fHnprt->Fill(nprt);
221
 fHnprt->Fill(nprt);
197
 if (fPrint) {
222
 if (fPrint) {
198
   sprintf(sList,"%s</table>",sList);
223
   sprintf(sList,"%s</table>",sList);
Line 205... Line 230...
205
}
230
}
206
 
231
 
207
send_message(2, TString::Format("Number of events processed %d\n", i ),100);
232
send_message(2, TString::Format("Number of events processed %d\n", i ),100);
208
 
233
 
209
send_message(1,TBufferJSON::ConvertToJSON(fHnprt),100 );
234
send_message(1,TBufferJSON::ConvertToJSON(fHnprt),100 );
210
send_message(1,TBufferJSON::ConvertToJSON(fHid),100 );
-
 
-
 
235
 
211
 
236
 
212
for (int i=0;i<100;i++) if (fH[i]!=0) send_message(1,TBufferJSON::ConvertToJSON(fH[i]),100 );
237
for (int i=0;i<100;i++) if (fH[i]!=0) send_message(1,TBufferJSON::ConvertToJSON(fH[i]),100 );
213
 
238
 
214
TDatime d;
239
TDatime d;
215
timer.Stop();
240
timer.Stop();