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