BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
TagParser2.cxx
Go to the documentation of this file.
1#include "GaudiKernel/IInterface.h"
2#include "GaudiKernel/StatusCode.h"
3#include "GaudiKernel/SvcFactory.h"
4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/ISvcLocator.h"
6#include "GaudiKernel/SmartDataPtr.h"
7#include "GaudiKernel/IDataProviderSvc.h"
8#include "GaudiKernel/PropertyMgr.h"
9#include "GaudiKernel/SmartIF.h"
10#include "GaudiKernel/IAppMgrUI.h"
11#include "GaudiKernel/IProperty.h"
12
13#include "GaudiKernel/IIncidentSvc.h"
14#include "GaudiKernel/Incident.h"
15#include "GaudiKernel/IIncidentListener.h"
16#include "GaudiKernel/ISvcLocator.h"
17#include "GaudiKernel/Bootstrap.h"
18
20#include <iostream>
21#include <fstream>
22#include <map>
23#include "TFile.h"
24#include "TTree.h"
25#include "TFormula.h"
26
28}
29
31}
32
33StatusCode TagParser2::getVEntry(std::vector<int>& ventry) {
34
35 std::map<int, unsigned int> Ds_modeTag, D0_modeTag, Dp_modeTag;
36 Ds_modeTag[400] = 1;
37 Ds_modeTag[401] = 0;
38 Ds_modeTag[402] = 2;
39 Ds_modeTag[403] = 13;
40 Ds_modeTag[404] = 3;
41 Ds_modeTag[405] = 4;
42 Ds_modeTag[406] = 5;
43 Ds_modeTag[407] = 14;
44 Ds_modeTag[420] = 28;
45 Ds_modeTag[421] = 6;
46 Ds_modeTag[422] = 24;
47 Ds_modeTag[423] = 25;
48 Ds_modeTag[424] = 26;
49 Ds_modeTag[425] = 27;
50 Ds_modeTag[440] = 7;
51 Ds_modeTag[441] = 8;
52 Ds_modeTag[442] = 20;
53 Ds_modeTag[450] = 21;
54 Ds_modeTag[451] = 22;
55 Ds_modeTag[452] = 23;
56 Ds_modeTag[460] = 9;
57 Ds_modeTag[461] = 15;
58 Ds_modeTag[470] = 16;
59 Ds_modeTag[471] = 17;
60 Ds_modeTag[480] = 10;
61 Ds_modeTag[481] = 11;
62 Ds_modeTag[500] = 29;
63 Ds_modeTag[501] = 18;
64 Ds_modeTag[502] = 12;
65 Ds_modeTag[503] = 19;
66 Ds_modeTag[504] = 30;
67
68 D0_modeTag[0] = 0;
69 D0_modeTag[1] = 1;
70 D0_modeTag[2] = 2;
71 D0_modeTag[3] = 3;
72 D0_modeTag[4] = 4;
73 D0_modeTag[5] = 5;
74 D0_modeTag[50] = 6;
75 D0_modeTag[51] = 7;
76 D0_modeTag[100] = 8;
77 D0_modeTag[101] = 9;
78 D0_modeTag[102] = 10;
79 D0_modeTag[103] = 11;
80 D0_modeTag[104] = 12;
81 D0_modeTag[105] = 13;
82 D0_modeTag[106] = 14;
83 D0_modeTag[107] = 15;
84 D0_modeTag[108] = 16;
85 D0_modeTag[109] = 17;
86 D0_modeTag[110] = 18;
87 D0_modeTag[111] = 19;
88 D0_modeTag[112] = 20;
89 D0_modeTag[113] = 21;
90 D0_modeTag[114] = 22;
91 D0_modeTag[115] = 23;
92 D0_modeTag[116] = 24;
93 D0_modeTag[117] = 25;
94 D0_modeTag[118] = 26;
95 D0_modeTag[119] = 27;
96 D0_modeTag[120] = 28;
97 D0_modeTag[121] = 29;
98 D0_modeTag[122] = 30;
99 D0_modeTag[123] = 30;
100 D0_modeTag[124] = 30;
101 D0_modeTag[125] = 30;
102 D0_modeTag[126] = 30;
103
104 Dp_modeTag[200] = 0;
105 Dp_modeTag[201] = 1;
106 Dp_modeTag[202] = 2;
107 Dp_modeTag[203] = 3;
108 Dp_modeTag[204] = 4;
109 Dp_modeTag[205] = 5;
110 Dp_modeTag[206] = 6;
111 Dp_modeTag[207] = 7;
112 Dp_modeTag[208] = 8;
113 Dp_modeTag[209] = 9;
114 Dp_modeTag[210] = 10;
115 Dp_modeTag[211] = 11;
116 Dp_modeTag[212] = 12;
117 Dp_modeTag[213] = 13;
118 Dp_modeTag[214] = 14;
119 Dp_modeTag[215] = 15;
120 Dp_modeTag[216] = 16;
121 Dp_modeTag[217] = 17;
122 Dp_modeTag[218] = 18;
123 Dp_modeTag[219] = 19;
124 Dp_modeTag[220] = 20;
125 Dp_modeTag[221] = 21;
126 Dp_modeTag[222] = 22;
127
128 int NumCriteria = m_criteria.size();
129 if (NumCriteria>27) {
130 std::cout<<"the number of criterias too much !"<<std::endl;
131 return StatusCode::SUCCESS;
132 }
133
134 vector<string> name_cut;
135 vector<int> CutDs, CutD0, CutD;
136 CutDs.clear();
137 CutD0.clear();
138 CutD.clear();
139 name_cut.clear();
140 bool allDs=false, allD0=false, allD=false, typeDs=true, typeD0=true, typeD=true;
141
142 string name;
143 int nPos_1, nPos_2, nPos_3;
144 string pat=",";
145 map<string, int> Cut1, Cut2;
146 for (int i=0; i<NumCriteria; i++) {
147 std::cout<<"TagFilterSvc::criteria " << i << " : " << m_criteria[i] << endl;
148 nPos_1 = m_criteria[i].find_first_of("<");
149 nPos_2 = m_criteria[i].find_last_of("<");
150 nPos_3 = m_criteria[i].find_first_of("=");
151 if (nPos_3!=-1) {
152 name = m_criteria[i].substr(0,nPos_3);
153 name_cut.push_back(name);
154 if (name=="tagDs") {
155 CutDs = split(m_criteria[i].substr(nPos_3+1),pat, allDs, typeDs);
156 } else if (name=="tagD0") {
157 CutD0 = split(m_criteria[i].substr(nPos_3+1),pat, allD0, typeD0);
158 } else if (name=="tagD") {
159 CutD = split(m_criteria[i].substr(nPos_3+1),pat, allD, typeD);
160 } else {
161 std::cout<<"pls check your tag criterias"<<std::endl;
162 return StatusCode::SUCCESS;
163 }
164 }
165 else if (nPos_1==-1 || nPos_2==-1 || nPos_1==nPos_2) {
166 std::cout<<"pls check your criterias"<<std::endl;
167 return StatusCode::SUCCESS;
168 }
169 else {
170 name = m_criteria[i].substr(nPos_1+1,nPos_2-nPos_1-1);
171 name_cut.push_back(name);
172 Cut1[name] = atoi(m_criteria[i].substr(0).c_str());
173 Cut2[name] = atoi(m_criteria[i].substr(nPos_2+1).c_str());
174 }
175 }
176
177 TFile* file = TFile::Open( m_fileName.c_str() );
178 TTree* t3 = (TTree*)file->Get("Entries");
179 UInt_t tagData0, tagData1, tagData2, tagData3, tagData4;
180 UInt_t tagData5, tagData6, tagData7;
181 t3->SetBranchAddress("tagData0", &tagData0);
182 t3->SetBranchAddress("tagData1", &tagData1);
183 t3->SetBranchAddress("tagData2", &tagData2);
184 t3->SetBranchAddress("tagData3", &tagData3);
185 t3->SetBranchAddress("tagData4", &tagData4);
186 t3->SetBranchAddress("tagData5", &tagData5);
187 t3->SetBranchAddress("tagData6", &tagData6);
188 t3->SetBranchAddress("tagData7", &tagData7);
189
190 Int_t npip, npim, nkp, nkm, nlambda, nalambda;
191 Int_t npp, npm, nep, nem, nmup, nmum, neta, npi0, ngamma, nks;
192 Int_t nGoodCharged, nCharged, nGoodChargedp, nGoodChargedm, totCharged, nNeutrk, nTottrk;
193
194 for (int i=0;i<t3->GetEntries();i++ ) {
195 t3->GetEntry(i);
196 nGoodCharged = tagData0;
197 Tag1ToInt(tagData1, nNeutrk, nTottrk, ngamma, npi0);
198 Tag2ToInt(tagData2, npip, npim, nkp, nkm, npp, npm);
199 Tag2ToInt(tagData3, nlambda, nalambda, nep, nem, nmup, nmum);
200 Tag2ToInt(tagData4, nks, neta, nCharged, nGoodChargedp, nGoodChargedm, totCharged);
201
202 unsigned int flag = 0;
203 bool isTag = false;
204 int tagvalue=-1;
205 for (unsigned int j=0; j<name_cut.size(); j++ ) {
206 if (name_cut[j]=="tagDs") {
207 if (tagData5>0) {
208 if ( !(tagData5&(1<<31)) && typeDs ) break;
209 if ( !allDs ) {
210 isTag = false;
211 for (unsigned int k=0; k<CutDs.size(); k++) {
212 if ( tagData5&(1<<Ds_modeTag[CutDs[k]]) ) {
213 isTag = true;
214 break;
215 }
216 }
217 if (!isTag) break;
218 }
219 } else {
220 break;
221 }
222 }
223 else if (name_cut[j]=="tagD0") {
224 if (tagData6>0) {
225 if ( !(tagData6&(1<<31)) && typeD0 ) break;
226 if ( !allD0 ) {
227 isTag = false;
228 for (unsigned int k=0; k<CutD0.size(); k++) {
229 if ( tagData6&(1<<D0_modeTag[CutD0[k]]) ) {
230 isTag = true;
231 break;
232 }
233 }
234 if (!isTag) break;
235 }
236 } else {
237 break;
238 }
239 }
240 else if (name_cut[j]=="tagD") {
241 if (tagData7>0) {
242 if ( !(tagData7&(1<<31)) && typeD ) break;
243 if ( !allD ) {
244 isTag = false;
245 for (unsigned int k=0; k<CutD.size(); k++) {
246 if ( tagData7&(1<<Dp_modeTag[CutD[k]]) ) {
247 isTag = true;
248 break;
249 }
250 }
251 if (!isTag) break;
252 }
253 } else {
254 break;
255 }
256 }
257 else {
258 if (name_cut[j]=="NumOfGoodCh") {tagvalue = nGoodCharged;}
259 else if (name_cut[j]=="NumOfNeutrk") {tagvalue = nNeutrk;}
260 else if (name_cut[j]=="NumOfTottrk") {tagvalue = nTottrk;}
261 else if (name_cut[j]=="NumOfGamma") {tagvalue = ngamma;}
262 else if (name_cut[j]=="NumOfPion0") {tagvalue = npi0;}
263 else if (name_cut[j]=="NumOfPionp") {tagvalue = npip;}
264 else if (name_cut[j]=="NumOfPionm") {tagvalue = npim;}
265 else if (name_cut[j]=="NumOfKaonp") {tagvalue = nkp;}
266 else if (name_cut[j]=="NumOfKaonm") {tagvalue = nkm;}
267 else if (name_cut[j]=="NumOfProtonp") {tagvalue = npp;}
268 else if (name_cut[j]=="NumOfProtonm") {tagvalue = npm;}
269 else if (name_cut[j]=="NumOfLambda") {tagvalue = nlambda;}
270 else if (name_cut[j]=="NumOfALambda" ) {tagvalue = nalambda;}
271 else if (name_cut[j]=="NumOfElectronp") {tagvalue = nep;}
272 else if (name_cut[j]=="NumOfElectronm") {tagvalue = nem;}
273 else if (name_cut[j]=="NumOfMuonp") {tagvalue = nmup;}
274 else if (name_cut[j]=="NumOfMuonm") {tagvalue = nmum;}
275 else if (name_cut[j]=="NumOfKs") {tagvalue = nks;}
276 else if (name_cut[j]=="NumOfEta") {tagvalue = neta;}
277 else if (name_cut[j]=="NumOfCharged") {tagvalue = nCharged;}
278 else if (name_cut[j]=="NumOfGoodChp") {tagvalue = nGoodChargedp;}
279 else if (name_cut[j]=="NumOfGoodChm") {tagvalue = nGoodChargedm;}
280 else if (name_cut[j]=="TotCharged") {tagvalue = totCharged;}
281 else {
282 cout << "pls check the name of your criteria !" << endl;
283 break;
284 }
285 if ( tagvalue>=Cut2[name_cut[j]] || tagvalue<=Cut1[name_cut[j]] ) break;
286 }
287 flag++;
288 }
289 if (flag==name_cut.size()) {
290 ventry.push_back(i);
291 }
292 }
293 CutDs.clear();
294 CutD0.clear();
295 CutD.clear();
296 name_cut.clear();
297 delete file;
298 return StatusCode::SUCCESS;
299}
300void TagParser2::Tag1ToInt(unsigned int res, int & val1, int & val2, int & val3, int & val4)
301{
302 val1 = (res>>24) & 0xFF;
303 val2 = (res>>16) & 0xFF;
304 val3 = (res>>8) & 0xFF;
305 val4 = res & 0xFF;
306 return;
307}
308void TagParser2::Tag2ToInt(unsigned int res, int & val1, int & val2, int & val3, int & val4, int & val5, int & val6)
309{
310 val1=(res>>26) & 0x3F;
311 val2=(res>>20) & 0x3F;
312 val3=(res>>15) & 0x1F;
313 val4=(res>>10) & 0x1F;
314 val5=(res>>5) & 0x1F;
315 val6 =res & 0x1F;
316 return;
317}
318vector<int> TagParser2::split(string str, string pattern, bool & all, bool & type)
319{
320 vector<int> result;
321 unsigned int pos;
322 type = true;
323 all = false;
324 str += pattern;
325
326 for (unsigned int i = 0; i<str.size(); i++) {
327 pos = str.find(pattern, i);
328 if (pos<str.size()) {
329 string val = str.substr(i, pos-i);
330 if (val=="all") {
331 all=true;
332 } else if (val=="type0") {
333 type=false;
334 } else {
335 result.push_back(atoi(val.c_str()));
336 }
337 i = pos + pattern.size() - 1;
338 }
339 }
340 return result;
341}
char * file
Definition: DQA_TO_DB.cxx:15
void Tag1ToInt(unsigned int res, int &val1, int &val2, int &val3, int &val4)
Definition: TagParser2.cxx:300
void Tag2ToInt(unsigned int res, int &val1, int &val2, int &val3, int &val4, int &val5, int &val6)
Definition: TagParser2.cxx:308
StatusCode getVEntry(vector< int > &)
Definition: TagParser2.cxx:33
vector< int > split(string str, string pattern, bool &all, bool &type)
Definition: TagParser2.cxx:318