Subversion Repositories f9daq

Rev

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

Rev 193 Rev 266
Line 20... Line 20...
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
int fData;
26
int fData;
26
TH1F *fH[100];
27
TH1F *fH[100];
-
 
28
UInt_t fHtype[100];
27
TClonesArray *fList[100];
29
TClonesArray *fList[100];
28
 
30
 
29
Blab2();
31
Blab2();
30
~Blab2();
32
~Blab2();
31
void Init();
33
void Init();
Line 33... Line 35...
33
void Process();
35
void Process();
34
void h1d(const char *varname, const char *name, int nbins, double min, double max, int id );
36
void h1d(const char *varname, const char *name, int nbins, double min, double max, int id );
35
int  selector(int pin, int charge, SIMPLEPID particlename,  int hid, int pout );
37
int  selector(int pin, int charge, SIMPLEPID particlename,  int hid, int pout );
36
int  combiner(int id0 ,int id1 , SIMPLEPID particlename, double min, double max, int hid, int id );
38
int  combiner(int id0 ,int id1 , SIMPLEPID particlename, double min, double max, int hid, int id );
37
int  fix_mass(int id);
39
int  fix_mass(int id);
-
 
40
int  Fill(int hid, BParticle *p);
38
void plist(int i);
41
void plist(int i);
39
 
42
 
40
 
43
 
41
ClassDef ( Blab2, 1 )
44
ClassDef ( Blab2, 1 )
42
};
45
};
43
 
46
 
44
ClassImp(Blab2)
47
ClassImp(Blab2)
45
 
48
 
46
Blab2::Blab2():fNeve(0), fData(0){
49
Blab2::Blab2():fNfirst(0), fNeve(0), fData(0){
47
 
50
 
48
 Process();
51
 Process();
49
};
52
};
-
 
53
 
50
 
54
 
51
void Blab2::h1d(const char *varname, const char *name, int nbins, double min, double max, int id ){
55
void Blab2::h1d(const char *varname, const char *name, int nbins, double min, double max, int id ){
-
 
56
   TString svar(varname);
-
 
57
   TString axis[3]={"mass (GeV/c2)","momentum (GeV/c)","energy (GeV)"};
-
 
58
   fHtype[id] = 0;
-
 
59
   if (svar.Contains("GetMass"    )) fHtype[id]=0;
-
 
60
   if (svar.Contains("GetMomentum")) fHtype[id]=1;
-
 
61
   if (svar.Contains("GetEnergy"  )) fHtype[id]=2;
-
 
62
 
52
   fH[id]= new TH1F(TString::Format("h%d",id), name, nbins, min, max);
63
   fH[id]= new TH1F(TString::Format("h%d",id), TString::Format("%s;%s;N",name,axis[fHtype[id]].Data()), nbins, min, max);
-
 
64
}
-
 
65
 
-
 
66
int Blab2::Fill(int hid, BParticle *p){
-
 
67
if (hid>=0 && fH[hid]) {
-
 
68
      float val;
-
 
69
      switch (fHtype[hid]){
-
 
70
      case 0: val = p->GetMass(); break;
-
 
71
      case 1: val = p->GetMomentum(); break;
-
 
72
      case 2: val = p->e(); break;
-
 
73
      default : val = 0 ; break;
-
 
74
      }
-
 
75
   fH[hid]->Fill(val);
-
 
76
}  
-
 
77
 
-
 
78
return 0;
53
}
79
}
54
 
80
 
55
int Blab2::combiner(int _p0, int _p1,SIMPLEPID pid, double min, double max, int hid, int _p2 ){
81
int Blab2::combiner(int _p0, int _p1,SIMPLEPID pid, double min, double max, int hid, int _p2 ){
56
   // Loop over all the particles in both lists.
82
   // Loop over all the particles in both lists.
57
 if (_p0 < 0 ) _p0 =0;
83
 if (_p0 < 0 ) _p0 =0;
Line 70... Line 96...
70
      if (p.InMassRange(min, max)){
96
      if (p.InMassRange(min, max)){
71
            //SIMPLEPID pid = PION; // should be set to particlename
97
            //SIMPLEPID pid = PION; // should be set to particlename
72
            p.SetPid(pid);
98
            p.SetPid(pid);
73
            TClonesArray& list = *fList[_p2];
99
            TClonesArray& list = *fList[_p2];
74
            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
75
            if (hid>=0 && fH[hid]) fH[hid]->Fill(p.GetMass());
101
            Fill(hid, &p);
76
      }
102
      }
77
       
103
       
78
   }
104
   }
79
               
105
               
80
 }
106
 }
Line 83... Line 109...
83
 
109
 
84
 
110
 
85
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 ){
86
 if (pin < 0 ) pin =0;
112
 if (pin < 0 ) pin =0;
87
 
113
 
88
 
-
 
89
  fList[pout]->Clear();
114
  fList[pout]->Clear();
90
  int nprt=0;
115
  int nprt=0;
91
 
116
 
92
  for(TIter next(fList[pin]); BParticle * p =(BParticle *) next();) {
117
  for(TIter next(fList[pin]); BParticle * p =(BParticle *) next();) {
93
        if (p->charge()== charge && p->pid()== type ) {
118
        if (p->charge()== charge && ( p->pid()== type || type == ALL )) {
94
          TClonesArray& list = *fList[pout];
119
          TClonesArray& list = *fList[pout];
95
          new (list[nprt++]) BParticle ( *p );
120
          new (list[nprt++]) BParticle ( *p );
96
          if (hid>=0 && fH[hid]) fH[hid]->Fill(p->GetMass());
121
          Fill(hid, p);
97
        }
122
        }
98
  }      
123
  }      
99
   return pout;
124
   return pout;
100
}
125
}
101
 
126
 
Line 126... Line 151...
126
 
151
 
127
 
152
 
128
void Blab2::Process(){
153
void Blab2::Process(){
129
 
154
 
130
for (int i=0;i<100;i++) fH[i]=NULL;
155
for (int i=0;i<100;i++) fH[i]=NULL;
-
 
156
for (int i=0;i<100;i++) fHtype[i]=0;
131
for (int i=0;i<100;i++) fList[i]=NULL;
157
for (int i=0;i<100;i++) fList[i]=NULL;
132
 
158
 
133
Init();
159
Init();
134
 
160
 
135
TFile * f = new TFile(TString::Format("../../data/hadron-%d.root",fData)); // Open a data file
161
TFile * f = new TFile(TString::Format("../../data/hadron-%d.root",fData)); // Open a data file
136
if(f->IsZombie()) {  send_message(0,TString::Format("File %d not found\n",fData), 0 );  return; }  
162
if(f->IsZombie()) {  send_message(0,TString::Format("File %d not found\n",fData), 0 );  return; }  
137
TTree * t =(TTree *) f-> Get( "T"); // Obtain a pointer to a tree of "event" data in the file
163
TTree * t =(TTree *) f-> Get( "T"); // Obtain a pointer to a tree of "event" data in the file
138
BEvent * mevent = new BEvent(); // Create a  "BEvent" object where data from the file will be loaded
164
BEvent * mevent = new BEvent(); // Create a  "BEvent" object where data from the file will be loaded
139
TBranch * branch = t-> GetBranch( "BEvent"); // Obtain a branch for "BEvent" in the tree
165
TBranch * branch = t-> GetBranch( "BEvent"); // Obtain a branch for "BEvent" in the tree
140
branch-> SetAddress(&mevent); // Register created "BEvent" object to the branch
166
branch-> SetAddress(&mevent); // Register created "BEvent" object to the branch
-
 
167
TH1F *fHnprt= new TH1F("h100", "Number of particles in the event;N particles;N events", 50, -0.5, 49.5);
-
 
168
TH1F *fHid= new TH1F("h101", "Particle type;ID;N particles", 6, -0, 6);
-
 
169
 
-
 
170
const char *names[6]={"PHOTON", "ELECTRON", "PION", "MUON", "KAON", "PROTON"};
-
 
171
for (int i=1;i<=6;i++) fHid->GetXaxis()->SetBinLabel(i,names[i-1]);
141
 
172
 
142
send_message(0, TString::Format("Number of Entries in the file %lld\n", t->GetEntries() ),0);
173
send_message(0, TString::Format("Number of Entries in the file %lld\n", t->GetEntries() ),0);
143
TStopwatch timer;
174
TStopwatch timer;
144
timer.Start();
175
timer.Start();
145
int i=0;
176
int i    =TMath::Min(fNfirst, (UInt_t) t-> GetEntries());
146
int cNeve=TMath::Min(fNeve, (UInt_t) t-> GetEntries());
177
int cNeve=TMath::Min(fNfirst+fNeve, (UInt_t) t-> GetEntries());
147
while (i<cNeve){
178
while (i<cNeve){
148
 t-> GetEntry(i); // Read the content of the event from the file
179
 t-> GetEntry(i); // Read the content of the event from the file
149
 fList[0]= mevent->GetParticleList();
180
 fList[0]= mevent->GetParticleList();
-
 
181
 
150
 event();
182
 event();
151
 
183
 
152
 if (i%10000==0) send_message(2, TString::Format("Event %d\n",i), (100*i)/cNeve);
184
 if (i%10000==0) send_message(2, TString::Format("Event %d\n",i), (100*i)/cNeve);
-
 
185
 
-
 
186
 int nprt=0;
-
 
187
 for(TIter next(fList[0]); BParticle * p =(BParticle *) next();) {
-
 
188
   nprt++;
-
 
189
   fHid->Fill(p->pid());
-
 
190
 }
-
 
191
 fHnprt->Fill(nprt);
-
 
192
 
153
 mevent-> Clear();  // Clear the memory.
193
 mevent-> Clear();  // Clear the memory.
154
 for (int k=0;k<100;k++) if (fList[k]!=0) fList[k]->Clear();
194
 for (int k=0;k<100;k++) if (fList[k]!=0) fList[k]->Clear();
155
 i++;
195
 i++;
156
}
196
}
157
 
197
 
158
send_message(2, TString::Format("Number of events processed %d\n", i ),100);
198
send_message(2, TString::Format("Number of events processed %d\n", i ),100);
159
for (int i=0;i<100;i++) if (fH[i]!=0) send_message(1,TBufferJSON::ConvertToJSON(fH[i]),100 );
199
for (int i=0;i<100;i++) if (fH[i]!=0) send_message(1,TBufferJSON::ConvertToJSON(fH[i]),100 );
160
 
-
 
-
 
200
send_message(1,TBufferJSON::ConvertToJSON(fHnprt),100 );
-
 
201
send_message(1,TBufferJSON::ConvertToJSON(fHid),100 );
161
TDatime d;
202
TDatime d;
162
timer.Stop();
203
timer.Stop();
163
send_message(3, TString::Format("'%s', %d, %f, %f", d.AsSQLString(),i, timer.RealTime(), timer.CpuTime() ),100);
204
send_message(3, TString::Format("'%s', %d, %f, %f", d.AsSQLString(),i, timer.RealTime(), timer.CpuTime() ),100);
164
 
205
 
165
}
206
}