Subversion Repositories f9daq

Rev

Rev 267 | Rev 272 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 267 Rev 268
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 <TClonesArray.h>
9
#include <TClonesArray.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{
15
public:
15
public:
16
  int id;
16
  int id;
17
  int len;
17
  int len;
18
  int progress;
18
  int progress;
19
};
19
};
20
 
20
 
21
 
21
 
22
class Blab2 {
22
class Blab2 {
23
public:
23
public:
24
UInt_t fNeve;
24
UInt_t fNeve;
25
UInt_t fNfirst;
25
UInt_t fNfirst;
26
UInt_t fPrint;
26
UInt_t fPrint;
27
int fData;
27
int fData;
28
TH1F *fH[100];
28
TH1F *fH[100];
29
UInt_t fHtype[100];
29
UInt_t fHtype[100];
30
TClonesArray *fList[100];
30
TClonesArray *fList[100];
31
 
31
 
32
Blab2();
32
Blab2();
33
~Blab2();
33
~Blab2();
34
void Init();
34
void Init();
35
void event();
35
void event();
36
void Process();
36
void Process();
37
void h1d(const char *varname, const char *name, int nbins, double min, double max, int id );
37
void h1d(const char *varname, const char *name, int nbins, double min, double max, int id );
38
int  selector(int pin, int charge, SIMPLEPID particlename,  int hid, int pout );
38
int  selector(int pin, int charge, SIMPLEPID particlename,  int hid, int pout );
39
int  combiner(int id0 ,int id1 , int same, SIMPLEPID particlename, double min, double max, int hid, int id );
39
int  combiner(int id0 ,int id1 , int same, SIMPLEPID particlename, double min, double max, int hid, int id );
40
int  fix_mass(int id);
40
int  fix_mass(int id);
41
int  Fill(int hid, BParticle *p);
41
int  Fill(int hid, BParticle *p);
42
void plist(int i);
42
void plist(int i);
43
 
43
 
44
 
44
 
45
ClassDef ( Blab2, 1 )
45
ClassDef ( Blab2, 1 )
46
};
46
};
47
 
47
 
48
ClassImp(Blab2)
48
ClassImp(Blab2)
49
 
49
 
50
Blab2::Blab2():fNfirst(0), fNeve(0), fData(0), fPrint(0) {
50
Blab2::Blab2():fNfirst(0), fNeve(0), fData(0), fPrint(0) {
51
 
51
 
52
 Process();
52
 Process();
53
};
53
};
54
 
54
 
55
 
55
 
56
void Blab2::h1d(const char *varname, const char *name, int nbins, double min, double max, int id ){
56
void Blab2::h1d(const char *varname, const char *name, int nbins, double min, double max, int id ){
57
   TString svar(varname);
57
   TString svar(varname);
58
   TString axis[3]={"mass (GeV/c2)","momentum (GeV/c)","energy (GeV)"};
58
   TString axis[3]={"mass (GeV/c2)","momentum (GeV/c)","energy (GeV)"};
59
   fHtype[id] = 0;
59
   fHtype[id] = 0;
60
   if (svar.Contains("GetMass"    )) fHtype[id]=0;
60
   if (svar.Contains("GetMass"    )) fHtype[id]=0;
61
   if (svar.Contains("GetMomentum")) fHtype[id]=1;
61
   if (svar.Contains("GetMomentum")) fHtype[id]=1;
62
   if (svar.Contains("GetEnergy"  )) fHtype[id]=2;
62
   if (svar.Contains("GetEnergy"  )) fHtype[id]=2;
63
 
63
 
64
   fH[id]= new TH1F(TString::Format("h%d",id), TString::Format("%s;%s;N",name,axis[fHtype[id]].Data()), nbins, min, max);
64
   fH[id]= new TH1F(TString::Format("h%d",id), TString::Format("%s;%s;N",name,axis[fHtype[id]].Data()), nbins, min, max);
65
}
65
}
66
 
66
 
67
int Blab2::Fill(int hid, BParticle *p){
67
int Blab2::Fill(int hid, BParticle *p){
68
if (hid>=0 && fH[hid]) {
68
if (hid>=0 && fH[hid]) {
69
      float val;
69
      float val;
70
      switch (fHtype[hid]){
70
      switch (fHtype[hid]){
71
      case 0: val = p->GetMass(); break;
71
      case 0: val = p->GetMass(); break;
72
      case 1: val = p->GetMomentum(); break;
72
      case 1: val = p->GetMomentum(); break;
73
      case 2: val = p->e(); break;
73
      case 2: val = p->e(); break;
74
      default : val = 0 ; break;
74
      default : val = 0 ; break;
75
      }
75
      }
76
   fH[hid]->Fill(val);
76
   fH[hid]->Fill(val);
77
}  
77
}  
78
 
78
 
79
return 0;
79
return 0;
80
}
80
}
81
 
81
 
82
int Blab2::combiner(int _p0, int _p1,int same, SIMPLEPID pid, double min, double max, int hid, int _p2 ){
82
int Blab2::combiner(int _p0, int _p1,int same, SIMPLEPID pid, double min, double max, int hid, int _p2 ){
83
   // Loop over all the particles in both lists.
83
   // Loop over all the particles in both lists.
84
 if (_p0 < 0 ) _p0 =0;
84
 if (_p0 < 0 ) _p0 =0;
85
 if (_p1 < 0 ) _p1 =0;
85
 if (_p1 < 0 ) _p1 =0;
86
 
86
 
87
 
87
 
88
 fList[_p2]->Clear();
88
 fList[_p2]->Clear();
89
 int nprt=0;
89
 int nprt=0;
90
 
90
 
91
 for(TIter next1(fList[_p0]);BParticle * p1 =(BParticle *) next1();) {
91
 for(TIter next1(fList[_p0]);BParticle * p1 =(BParticle *) next1();) {
92
    // the second loop
92
    // the second loop
93
   // in the case the second parti 
93
   // in the case the second parti 
94
   for(TIter next2 = (_p0!=_p1 && same==0) ?  TIter(fList[_p1]): TIter(next1) ; BParticle * p2 =(BParticle *) next2();) {  
94
   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
95
      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   
96
      BParticle  p = *p1 + *p2; // Combine two particles into a new particle   
97
      if (p.InMassRange(min, max)){
97
      if (p.InMassRange(min, max)){
98
            p.SetPid(pid); // set PID to particlename to fix the particle mass
98
            p.SetPid(pid); // set PID to particlename to fix the particle mass
99
            TClonesArray& list = *fList[_p2];
99
            TClonesArray& list = *fList[_p2];
100
            new (list[nprt++]) BParticle ( p ); // create a new entry in kslist list of particles
100
            new (list[nprt++]) BParticle ( p ); // create a new entry in kslist list of particles
101
            Fill(hid, &p);
101
            Fill(hid, &p);
102
      }
102
      }
103
       
103
       
104
   }
104
   }
105
               
105
               
106
 }
106
 }
107
 return _p2;
107
 return _p2;
108
}
108
}
109
 
109
 
110
 
110
 
111
int Blab2::selector(int pin, int charge, SIMPLEPID type ,  int hid, int pout ){
111
int Blab2::selector(int pin, int charge, SIMPLEPID type ,  int hid, int pout ){
112
 if (pin < 0 ) pin =0;
112
 if (pin < 0 ) pin =0;
113
 
113
 
114
  fList[pout]->Clear();
114
  fList[pout]->Clear();
115
  int nprt=0;
115
  int nprt=0;
116
 
116
 
117
  for(TIter next(fList[pin]); BParticle * p =(BParticle *) next();) {
117
  for(TIter next(fList[pin]); BParticle * p =(BParticle *) next();) {
118
        if (p->charge()== charge && ( p->pid()== type || type == ALL )) {
118
        if (p->charge()== charge && ( p->pid()== type || type == ALL )) {
119
          TClonesArray& list = *fList[pout];
119
          TClonesArray& list = *fList[pout];
120
          new (list[nprt++]) BParticle ( *p );
120
          new (list[nprt++]) BParticle ( *p );
121
          Fill(hid, p);
121
          Fill(hid, p);
122
        }
122
        }
123
  }      
123
  }      
124
   return pout;
124
   return pout;
125
}
125
}
126
 
126
 
127
 
127
 
128
int Blab2::fix_mass(int pin){
128
int Blab2::fix_mass(int pin){
129
   if (pin < 0 ) pin =0;
129
   if (pin < 0 ) pin =0;
130
   for(TIter next(fList[pin]); BParticle * p =(BParticle *) next();)  p->SetEnergyFromPid();
130
   for(TIter next(fList[pin]); BParticle * p =(BParticle *) next();)  p->SetEnergyFromPid();
131
   return pin;
131
   return pin;
132
}
132
}
133
 
133
 
134
void Blab2::plist(int i){
134
void Blab2::plist(int i){
135
  fList[i]= new TClonesArray( "BParticle", 500 );
135
  fList[i]= new TClonesArray( "BParticle", 500 );
136
}
136
}
137
Blab2::~Blab2(){};
137
Blab2::~Blab2(){};
138
 
138
 
139
 
139
 
140
void send_message(int id, TString msg, int progress){
140
void send_message(int id, TString msg, int progress){
141
static Hdr hdr;
141
static Hdr hdr;
142
 
142
 
143
   hdr.id = id;
143
   hdr.id = id;
144
   hdr.len= msg.Length();
144
   hdr.len= msg.Length();
145
   hdr.progress= progress;
145
   hdr.progress= progress;
146
   fwrite(&hdr,3*sizeof(int),1,stdout);
146
   fwrite(&hdr,3*sizeof(int),1,stdout);
147
   fwrite(msg.Data(),hdr.len,1,stdout);
147
   fwrite(msg.Data(),hdr.len,1,stdout);
148
   fflush(stdout);
148
   fflush(stdout);
149
 
149
 
150
}
150
}
151
 
151
 
152
 
152
 
153
void Blab2::Process(){
153
void Blab2::Process(){
154
 
154
 
155
char sList[0xFFFF];
155
char sList[0xFFFF];
156
for (int i=0;i<100;i++) fH[i]=NULL;
156
for (int i=0;i<100;i++) fH[i]=NULL;
157
for (int i=0;i<100;i++) fHtype[i]=0;
157
for (int i=0;i<100;i++) fHtype[i]=0;
158
for (int i=0;i<100;i++) fList[i]=NULL;
158
for (int i=0;i<100;i++) fList[i]=NULL;
159
 
159
 
160
Init();
160
Init();
161
 
161
 
162
TFile * f = new TFile(TString::Format("../../data/hadron-%d.root",fData)); // Open a data file
162
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; }  
163
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
164
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
165
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
166
TBranch * branch = t-> GetBranch( "BEvent"); // Obtain a branch for "BEvent" in the tree
167
branch-> SetAddress(&mevent); // Register created "BEvent" object to the branch
167
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);
168
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);
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" };
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]);
171
for (int i=1;i<=6;i++) fHid->GetXaxis()->SetBinLabel(i,names[i-1]);
172
 
172
 
173
send_message(0, TString::Format("<br>Number of Events in the file %lld<br>\n", t->GetEntries() ),0);
173
send_message(0, TString::Format("<br>Number of Events in the file %lld<br>\n", t->GetEntries() ),0);
174
TStopwatch timer;
174
TStopwatch timer;
175
timer.Start();
175
timer.Start();
176
int nev  = 0;
176
int nev  = 0;
177
int i    =TMath::Min(fNfirst, (UInt_t) t-> GetEntries());
177
int i    =TMath::Min(fNfirst, (UInt_t) t-> GetEntries());
178
int cNeve=TMath::Min(fNfirst+fNeve, (UInt_t) t-> GetEntries());
178
int cNeve=TMath::Min(fNfirst+fNeve, (UInt_t) t-> GetEntries());
179
while (i<cNeve){
179
while (i<cNeve){
180
 t-> GetEntry(i); // Read the content of the event from the file
180
 t-> GetEntry(i); // Read the content of the event from the file
181
 fList[0]= mevent->GetParticleList();
181
 fList[0]= mevent->GetParticleList();
182
 
182
 
183
 event();
183
 event();
184
 
184
 
185
 int progress = (100*i)/cNeve;
185
 int progress = (100*i)/cNeve;
186
 if (i%10000==0) send_message(2, TString::Format("Event %d\n",i), progress);
186
 if (i%10000==0) send_message(2, TString::Format("Event %d\n",i), progress);
187
 
187
 
188
 int nprt=0;
188
 int nprt=0;
189
 if (nev>100) fPrint = 0; // disable particle prints for huge numer of events
189
 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);
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);
191
 for(TIter next(fList[0]); BParticle * p =(BParticle *) next();) {
191
 for(TIter next(fList[0]); BParticle * p =(BParticle *) next();) {
192
   nprt++;
192
   nprt++;
193
   fHid->Fill(p->pid());
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()] );
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()] );
195
 }
195
 }
196
 fHnprt->Fill(nprt);
196
 fHnprt->Fill(nprt);
197
 if (fPrint) {
197
 if (fPrint) {
198
   sprintf(sList,"%s</table>",sList);
198
   sprintf(sList,"%s</table>",sList);
199
   send_message(0, TString(sList),progress);
199
   send_message(0, TString(sList),progress);
200
   nev++;
200
   nev++;
201
 }
201
 }
202
 mevent-> Clear();  // Clear the memory.
202
 mevent-> Clear();  // Clear the memory.
203
 for (int k=0;k<100;k++) if (fList[k]!=0) fList[k]->Clear();
203
 for (int k=0;k<100;k++) if (fList[k]!=0) fList[k]->Clear();
204
 i++;
204
 i++;
205
}
205
}
206
 
206
 
207
send_message(2, TString::Format("Number of events processed %d\n", i ),100);
207
send_message(2, TString::Format("Number of events processed %d\n", i ),100);
208
for (int i=0;i<100;i++) if (fH[i]!=0) send_message(1,TBufferJSON::ConvertToJSON(fH[i]),100 );
-
 
-
 
208
 
209
send_message(1,TBufferJSON::ConvertToJSON(fHnprt),100 );
209
send_message(1,TBufferJSON::ConvertToJSON(fHnprt),100 );
210
send_message(1,TBufferJSON::ConvertToJSON(fHid),100 );
210
send_message(1,TBufferJSON::ConvertToJSON(fHid),100 );
-
 
211
 
-
 
212
for (int i=0;i<100;i++) if (fH[i]!=0) send_message(1,TBufferJSON::ConvertToJSON(fH[i]),100 );
-
 
213
 
211
TDatime d;
214
TDatime d;
212
timer.Stop();
215
timer.Stop();
213
send_message(3, TString::Format("'%s', %d, %f, %f", d.AsSQLString(),i, timer.RealTime(), timer.CpuTime() ),100);
216
send_message(3, TString::Format("'%s', %d, %f, %f", d.AsSQLString(),i, timer.RealTime(), timer.CpuTime() ),100);
214
 
217
 
215
}
218
}
216
 
219
 
217
 
220
 
218
 
221