BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
DstReformAlg.cxx
Go to the documentation of this file.
1#include "GaudiKernel/MsgStream.h"
2#include "GaudiKernel/AlgFactory.h"
3#include "GaudiKernel/ISvcLocator.h"
4#include "GaudiKernel/SmartDataPtr.h"
5#include "GaudiKernel/IDataProviderSvc.h"
7#include "EventModel/Event.h"
8
12
14
15#include "GaudiKernel/SmartIF.h"
16#include "GaudiKernel/IJobOptionsSvc.h"
18#include "GaudiKernel/Bootstrap.h"
19#include "GaudiKernel/ISvcLocator.h"
20#include "CLHEP/Vector/ThreeVector.h"
21#include "CLHEP/Vector/LorentzVector.h"
22#include "CLHEP/Vector/TwoVector.h"
23using CLHEP::Hep3Vector;
24using CLHEP::Hep2Vector;
25using CLHEP::HepLorentzVector;
26#include "CLHEP/Geometry/Point3D.h"
27#ifndef ENABLE_BACKWARDS_COMPATIBILITY
29#endif
30#include "CLHEP/Matrix/SymMatrix.h"
31#include "VertexFit/Helix.h"
32
38#include <TFile.h>
39#include <TTree.h>
40#include <map>
41#include <vector>
42#include <iostream>
43#include <cmath>
44using namespace CLHEP;
45
46/////////////////////////////////////////////////////////////////////////////
47
48DstReformAlg::DstReformAlg(const std::string& name, ISvcLocator* pSvcLocator) :
49 Algorithm(name, pSvcLocator) {
50
51 declareProperty("OutputDstFile", m_outputFile);
52}
53
54// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
56 MsgStream log(msgSvc(), name());
57
58 log << MSG::INFO << "in initialize()" << endmsg;
59 m_evtNum=0;
60 Gaudi::svcLocator()->service("TagFilterSvc", m_tagFilterSvc);
61
62 m_dstDataType = m_tagFilterSvc->getDstDataType();
63 std::cout<<"init DstReformAlg, m_dstDataType: "<< m_dstDataType <<std::endl;
64
65 return StatusCode::SUCCESS;
66}
67
69 UInt_t tagData0 = m_tagFilterSvc->getTagData0();
70 UInt_t tagData1 = m_tagFilterSvc->getTagData1();
71 UInt_t tagData2 = m_tagFilterSvc->getTagData2();
72 UInt_t tagData3 = m_tagFilterSvc->getTagData3();
73 UInt_t tagData4 = m_tagFilterSvc->getTagData4();
74
75 //tagData0 and tagData1 is for DST reform, tagData0 is first priority
76
77 //for DTagSetAlg and LTagSetAlg, if tagData0=3, then reform these events with tagData1(nGoodCharged).
78 int dstDataType = m_tagFilterSvc->getDstDataType();
79 if( (dstDataType==4) && (tagData0==3) )
80 {
81 cmap[tagData0+tagData1].push_back(m_evtNum);
82 }
83 else
84 cmap[tagData0].push_back(m_evtNum);
85
86 //add tag information to each event
87 if (m_dstDataType==1) {
88 evtmap[m_evtNum].push_back(tagData0);
89 evtmap[m_evtNum].push_back(tagData1);
90 evtmap[m_evtNum].push_back(tagData2);
91 evtmap[m_evtNum].push_back(tagData3);
92 evtmap[m_evtNum].push_back(tagData4);
93 } else if (m_dstDataType==2) {
94 UInt_t tagData5 = m_tagFilterSvc->getTagData5();
95 UInt_t tagData6 = m_tagFilterSvc->getTagData6();
96 UInt_t tagData7 = m_tagFilterSvc->getTagData7();
97 UInt_t tagData8 = m_tagFilterSvc->getTagData8();
98 evtmap[m_evtNum].push_back(tagData1);
99 evtmap[m_evtNum].push_back(tagData2);
100 evtmap[m_evtNum].push_back(tagData3);
101 evtmap[m_evtNum].push_back(tagData4);
102 evtmap[m_evtNum].push_back(tagData5);
103 evtmap[m_evtNum].push_back(tagData6);
104 evtmap[m_evtNum].push_back(tagData7);
105 evtmap[m_evtNum].push_back(tagData8);
106 } else if ( (m_dstDataType==3) || (m_dstDataType==4) ) {
107 UInt_t tagData5 = m_tagFilterSvc->getTagData5();
108 UInt_t tagData6 = m_tagFilterSvc->getTagData6();
109 UInt_t tagData7 = m_tagFilterSvc->getTagData7();
110 UInt_t tagData8 = m_tagFilterSvc->getTagData8();
111 UInt_t tagData9 = m_tagFilterSvc->getTagData9();
112 evtmap[m_evtNum].push_back(tagData1);
113 evtmap[m_evtNum].push_back(tagData2);
114 evtmap[m_evtNum].push_back(tagData3);
115 evtmap[m_evtNum].push_back(tagData4);
116 evtmap[m_evtNum].push_back(tagData5);
117 evtmap[m_evtNum].push_back(tagData6);
118 evtmap[m_evtNum].push_back(tagData7);
119 evtmap[m_evtNum].push_back(tagData8);
120 evtmap[m_evtNum].push_back(tagData9);
121
122 }
123
124 m_evtNum++;
125}
126
127// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
129 MsgStream log(msgSvc(), name());
130
131 std::string fn;
132 SmartIF<IJobOptionsSvc> iSvc(Gaudi::svcLocator()->service("JobOptionsSvc"));
133 if ( iSvc.isValid() ) {
134 const std::vector<const Property*>* ps = iSvc->getProperties("EventCnvSvc");
135 std::vector<const Property*>::const_iterator it, end = ps->end();
136 for ( it = ps->begin(); it != end; ++it ) {
137 if ( (*it)->name() == "digiRootInputFile" ) {
138 std::string flist=(*it)->toString();
139 std::string::size_type p1 = flist.find('"') + 1;
140 std::string::size_type p2 = flist.find('"', p1);
141 fn = flist.substr(p1, p2-p1);
142 std::cout<<"input dst file name: "<<fn<<std::endl;
143 }
144 }
145 }
146 TFile* f1 = TFile::Open(fn.c_str(),"READ");
147 TFile* f2 = TFile::Open(m_outputFile.c_str(), "RECREATE");
148 TTree* t1 = (TTree*)f1->Get("Event");
149
150 log << MSG::INFO << "in finalize()" << endmsg;
151 TTree* jt1 = (TTree*)(f1->Get("JobInfoTree"));
152 TTree* jt2 = jt1->CloneTree();
153 TTree* t0 = new TTree("Metadata", "");
154 Int_t mode = -1, begin = 0, end = 0;
155 t0->Branch("mode", &mode, "mode/I");
156 t0->Branch("begin", &begin, "begin/I");
157 t0->Branch("end", &end, "end/I");
158
159 for ( std::map<int, std::vector<long int> >::iterator it = cmap.begin(); it != cmap.end(); ++it ) {
160 mode = it->first;
161 begin = end;
162 end += (it->second).size();
163 std::cout<<"mode: "<<mode<< " begin: "<<begin<< " end: "<<end<<std::endl;
164 t0->Fill();
165 }
166
167 TTree* t2 = t1->CloneTree(0);
168 Int_t nEvents = t1->GetEntries();
169 std::cout<<"Total nEvents: "<<nEvents<<std::endl;
170 Int_t origEntry=0, currEntry=0;
171 UInt_t tagData0, tagData1, tagData2, tagData3, tagData4;
172 UInt_t tagData5, tagData6, tagData7, tagData8;
173 TTree* t3 = new TTree("Entries", "");
174 t3->Branch("origEntry", &origEntry, "origEntry/I");
175 t3->Branch("currEntry", &currEntry, "currEntry/I");
176 t3->Branch("tagData0", &tagData0, "tagData0/i");
177 t3->Branch("tagData1", &tagData1, "tagData1/i");
178 t3->Branch("tagData2", &tagData2, "tagData2/i");
179 t3->Branch("tagData3", &tagData3, "tagData3/i");
180 t3->Branch("tagData4", &tagData4, "tagData4/i");
181 if (m_dstDataType==2) {
182 t3->Branch("tagData5", &tagData5, "tagData5/i");
183 t3->Branch("tagData6", &tagData6, "tagData6/i");
184 t3->Branch("tagData7", &tagData7, "tagData7/i");
185 }
186 if ( (m_dstDataType==3) || (m_dstDataType==4) ) {
187 t3->Branch("tagData5", &tagData5, "tagData5/i");
188 t3->Branch("tagData6", &tagData6, "tagData6/i");
189 t3->Branch("tagData7", &tagData7, "tagData7/i");
190 t3->Branch("tagData8", &tagData8, "tagData8/i");
191 }
192
193 for ( std::map<int, std::vector<long int> >::iterator it = cmap.begin(); it != cmap.end(); ++it ) {
194 int nNt = it->second.size();
195 std::cout << "Writing " << nNt << "\t events with " << it->first << " TagData0..." << std::endl;
196 for ( int i = 0; i < nNt; ++i ) {
197 origEntry=(it->second)[i];
198 t1->GetEntry(origEntry);
199 tagData0=(evtmap[origEntry])[0];
200 tagData1=(evtmap[origEntry])[1];
201 tagData2=(evtmap[origEntry])[2];
202 tagData3=(evtmap[origEntry])[3];
203 tagData4=(evtmap[origEntry])[4];
204 if (m_dstDataType==2) {
205 tagData5=(evtmap[origEntry])[5];
206 tagData6=(evtmap[origEntry])[6];
207 tagData7=(evtmap[origEntry])[7];
208 }
209 if ( (m_dstDataType==3) || (m_dstDataType==4) ) {
210 tagData5=(evtmap[origEntry])[5];
211 tagData6=(evtmap[origEntry])[6];
212 tagData7=(evtmap[origEntry])[7];
213 tagData8=(evtmap[origEntry])[8];
214 }
215 t2->Fill();
216 t3->Fill();
217 currEntry++;
218 }
219 (it->second).clear();
220 }
221
222 f2->Write();
223 f2->Close();
224 return StatusCode::SUCCESS;
225}
HepGeom::Point3D< double > HepPoint3D
IMessageSvc * msgSvc()
DstReformAlg(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode finalize()
StatusCode execute()
StatusCode initialize()
virtual unsigned int getTagData1()=0
virtual unsigned int getTagData2()=0
virtual int getDstDataType()=0
virtual unsigned int getTagData8()=0
virtual unsigned int getTagData9()=0
virtual unsigned int getTagData6()=0
virtual unsigned int getTagData4()=0
virtual unsigned int getTagData5()=0
virtual unsigned int getTagData7()=0
virtual unsigned int getTagData3()=0
virtual unsigned int getTagData0()=0