BOSS 7.1.1
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
29
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 unsigned int Ncut_oth=0;
135 vector<string> name_tag, name_oth;
136 vector<int> CutDs, CutD0, CutD;
137 CutDs.clear();
138 CutD0.clear();
139 CutD.clear();
140 name_tag.clear();
141 name_oth.clear();
142 bool allDs=false, allD0=false, allD=false, typeDs=true, typeD0=true, typeD=true, QC=false;
143
144 string name;
145 int nPos_1, nPos_2, nPos_3, nPos_4;
146 string pat=",";
147 map<string, int> Cut1, Cut2;
148 for (int i=0; i<NumCriteria; i++) {
149 std::cout<<"TagFilterSvc::criteria " << i << " : " << m_criteria[i];
150 nPos_1 = m_criteria[i].find_first_of("<");
151 nPos_2 = m_criteria[i].find_last_of("<");
152 nPos_3 = m_criteria[i].find_first_of("=");
153 nPos_4 = m_criteria[i].find("QCon");
154 if (nPos_4!=-1) {
155 QC=true;
156 cout << " -> Turn on QC";
157 }
158 else if (nPos_3!=-1) {
159 name = m_criteria[i].substr(0,nPos_3);
160 name_tag.push_back(name);
161 if (name=="tagDs") {
162 CutDs = split(m_criteria[i].substr(nPos_3+1),pat, allDs, typeDs);
163 } else if (name=="tagD0") {
164 CutD0 = split(m_criteria[i].substr(nPos_3+1),pat, allD0, typeD0);
165 } else if (name=="tagD") {
166 CutD = split(m_criteria[i].substr(nPos_3+1),pat, allD, typeD);
167 } else {
168 std::cout<<"pls check your tag criterias"<<std::endl;
169 return StatusCode::SUCCESS;
170 }
171 }
172 else if (nPos_1==-1 || nPos_2==-1 || nPos_1==nPos_2) {
173 std::cout<<"pls check your criterias"<<std::endl;
174 return StatusCode::SUCCESS;
175 }
176 else {
177 name = m_criteria[i].substr(nPos_1+1,nPos_2-nPos_1-1);
178 name_oth.push_back(name);
179 Ncut_oth++;
180 Cut1[name] = atoi(m_criteria[i].substr(0).c_str());
181 Cut2[name] = atoi(m_criteria[i].substr(nPos_2+1).c_str());
182 }
183 std::cout<<std::endl;
184 }
185
186 TFile* file = TFile::Open( m_fileName.c_str() );
187 TTree* t3 = (TTree*)file->Get("Entries");
188 UInt_t tagData0, tagData1, tagData2, tagData3, tagData4;
189 UInt_t tagData5, tagData6, tagData7, tagData8;
190 t3->SetBranchAddress("tagData0", &tagData0);
191 t3->SetBranchAddress("tagData1", &tagData1);
192 t3->SetBranchAddress("tagData2", &tagData2);
193 t3->SetBranchAddress("tagData3", &tagData3);
194 t3->SetBranchAddress("tagData4", &tagData4);
195 t3->SetBranchAddress("tagData5", &tagData5);
196 t3->SetBranchAddress("tagData6", &tagData6);
197 t3->SetBranchAddress("tagData7", &tagData7);
198 t3->SetBranchAddress("tagData8", &tagData8);
199
200 Int_t npip, npim, nkp, nkm, nlambda, nalambda;
201 Int_t npp, npm, nep, nem, nmup, nmum, neta, npi0, ngamma, nks;
202 Int_t nGoodCharged, nCharged, nGoodChargedp, nGoodChargedm, totCharged, nNeutrk, nTottrk;
203 bool isTag, isPID;
204 unsigned int flag;
205
206 for (int i=0;i<t3->GetEntries();i++ ) {
207 t3->GetEntry(i);
208 nGoodCharged = tagData0;
209 Tag1ToInt(tagData1, nNeutrk, nTottrk, ngamma, npi0);
210 Tag2ToInt(tagData2, npip, npim, nkp, nkm, npp, npm);
211 Tag2ToInt(tagData3, nlambda, nalambda, nep, nem, nmup, nmum);
212 Tag2ToInt(tagData4, nks, neta, nCharged, nGoodChargedp, nGoodChargedm, totCharged);
213
214 if ( QC && tagData8==0 ) continue;
215 if ( name_tag.size()==0 && Ncut_oth==0 ) {
216 ventry.push_back(i);
217 continue;
218 }
219 isTag = false;
220 for (unsigned int j=0; j<name_tag.size(); j++ ) {
221 if (name_tag[j]=="tagD0") {
222 if (tagData6>0) {
223 isPID = true;
224 if ( !(tagData6&(1<<31)) && typeD0 ) isPID = false;
225 if ( isPID ) {
226 if ( !allD0 ) {
227 for (unsigned int k=0; k<CutD0.size(); k++) {
228 if ( tagData6&(1<<D0_modeTag[CutD0[k]]) ) {
229 isTag = true;
230 break;
231 }
232 }
233 } else {
234 isTag = true;
235 }
236 }
237 }
238 }
239 else if (name_tag[j]=="tagD") {
240 if (tagData7>0) {
241 isPID = true;
242 if ( !(tagData7&(1<<31)) && typeD ) isPID = false;
243 if ( isPID ) {
244 if ( !allD ) {
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 } else {
252 isTag = true;
253 }
254 }
255 }
256 }
257 else if (name_tag[j]=="tagDs") {
258 if (tagData5>0) {
259 isPID = true;
260 if ( !(tagData5&(1<<31)) && typeDs ) isPID = false;
261 if ( isPID ) {
262 if ( !allDs ) {
263 for (unsigned int k=0; k<CutDs.size(); k++) {
264 if ( tagData5&(1<<Ds_modeTag[CutDs[k]]) ) {
265 isTag = true;
266 break;
267 }
268 }
269 } else {
270 isTag = true;
271 }
272 }
273 }
274 }
275 if (isTag) break;
276 }
277 if (isTag) {
278 ventry.push_back(i);
279 continue;
280 }
281
282 flag = 0;
283 int tagvalue=-1;
284 for (unsigned int j=0; j<name_oth.size(); j++ ) {
285 if (name_oth[j]=="NumOfGoodCh") {tagvalue = nGoodCharged;}
286 else if (name_oth[j]=="NumOfNeutrk") {tagvalue = nNeutrk;}
287 else if (name_oth[j]=="NumOfTottrk") {tagvalue = nTottrk;}
288 else if (name_oth[j]=="NumOfGamma") {tagvalue = ngamma;}
289 else if (name_oth[j]=="NumOfPion0") {tagvalue = npi0;}
290 else if (name_oth[j]=="NumOfPionp") {tagvalue = npip;}
291 else if (name_oth[j]=="NumOfPionm") {tagvalue = npim;}
292 else if (name_oth[j]=="NumOfKaonp") {tagvalue = nkp;}
293 else if (name_oth[j]=="NumOfKaonm") {tagvalue = nkm;}
294 else if (name_oth[j]=="NumOfProtonp") {tagvalue = npp;}
295 else if (name_oth[j]=="NumOfProtonm") {tagvalue = npm;}
296 else if (name_oth[j]=="NumOfLambda") {tagvalue = nlambda;}
297 else if (name_oth[j]=="NumOfALambda" ) {tagvalue = nalambda;}
298 else if (name_oth[j]=="NumOfElectronp") {tagvalue = nep;}
299 else if (name_oth[j]=="NumOfElectronm") {tagvalue = nem;}
300 else if (name_oth[j]=="NumOfMuonp") {tagvalue = nmup;}
301 else if (name_oth[j]=="NumOfMuonm") {tagvalue = nmum;}
302 else if (name_oth[j]=="NumOfKs") {tagvalue = nks;}
303 else if (name_oth[j]=="NumOfEta") {tagvalue = neta;}
304 else if (name_oth[j]=="NumOfCharged") {tagvalue = nCharged;}
305 else if (name_oth[j]=="NumOfGoodChp") {tagvalue = nGoodChargedp;}
306 else if (name_oth[j]=="NumOfGoodChm") {tagvalue = nGoodChargedm;}
307 else if (name_oth[j]=="TotCharged") {tagvalue = totCharged;}
308 else {
309 cout << "pls check the name of your criteria !" << endl;
310 break;
311 }
312 if ( tagvalue>=Cut2[name_oth[j]] || tagvalue<=Cut1[name_oth[j]] ) break;
313 flag++;
314 }
315 if (Ncut_oth>0&&Ncut_oth==flag) ventry.push_back(i);
316 }
317 cout << "TagFilterSvc::" << ventry.size() << " out of " << t3->GetEntries() << " events selected" << endl;
318 CutDs.clear();
319 CutD0.clear();
320 CutD.clear();
321 name_tag.clear();
322 name_oth.clear();
323 delete file;
324 return StatusCode::SUCCESS;
325}
326void TagParser2::Tag1ToInt(unsigned int res, int & val1, int & val2, int & val3, int & val4)
327{
328 val1 = (res>>24) & 0xFF;
329 val2 = (res>>16) & 0xFF;
330 val3 = (res>>8) & 0xFF;
331 val4 = res & 0xFF;
332 return;
333}
334void TagParser2::Tag2ToInt(unsigned int res, int & val1, int & val2, int & val3, int & val4, int & val5, int & val6)
335{
336 val1=(res>>26) & 0x3F;
337 val2=(res>>20) & 0x3F;
338 val3=(res>>15) & 0x1F;
339 val4=(res>>10) & 0x1F;
340 val5=(res>>5) & 0x1F;
341 val6 =res & 0x1F;
342 return;
343}
344vector<int> TagParser2::split(string str, string pattern, bool & all, bool & type)
345{
346 vector<int> result;
347 unsigned int pos;
348 type = true;
349 all = false;
350 str += pattern;
351
352 for (unsigned int i = 0; i<str.size(); i++) {
353 pos = str.find(pattern, i);
354 if (pos<str.size()) {
355 string val = str.substr(i, pos-i);
356 if (val=="all") {
357 all=true;
358 } else if (val=="type0") {
359 type=false;
360 } else {
361 result.push_back(atoi(val.c_str()));
362 }
363 i = pos + pattern.size() - 1;
364 }
365 }
366 return result;
367}
char * file
Definition DQA_TO_DB.cxx:15
void Tag1ToInt(unsigned int res, int &val1, int &val2, int &val3, int &val4)
void Tag2ToInt(unsigned int res, int &val1, int &val2, int &val3, int &val4, int &val5, int &val6)
StatusCode getVEntry(vector< int > &)
vector< int > split(string str, string pattern, bool &all, bool &type)