BOSS 7.1.2
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/////////////////////////////////////////////////////////////////////////////
47DECLARE_COMPONENT(DstReformAlg)
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
61 ITagFilterSvc* tmpSvc=0;
62 Gaudi::svcLocator()->service("TagFilterSvc", tmpSvc);
63 m_tagFilterSvc = dynamic_cast<TagFilterSvc *>(tmpSvc);
64
65 m_dstDataType = m_tagFilterSvc->getDstDataType();
66 std::cout<<"init DstReformAlg, m_dstDataType: "<< m_dstDataType <<std::endl;
67
68 return StatusCode::SUCCESS;
69}
70
72 UInt_t tagData0 = m_tagFilterSvc->getTagData0();
73 UInt_t tagData1 = m_tagFilterSvc->getTagData1();
74 UInt_t tagData2 = m_tagFilterSvc->getTagData2();
75 UInt_t tagData3 = m_tagFilterSvc->getTagData3();
76 UInt_t tagData4 = m_tagFilterSvc->getTagData4();
77
78 //tagData0 and tagData1 is for DST reform, tagData0 is first priority
79
80 //for DTagSetAlg and LTagSetAlg, if tagData0=3, then reform these events with tagData1(nGoodCharged).
81 int dstDataType = m_tagFilterSvc->getDstDataType();
82 if( (dstDataType==2||dstDataType==4) && (tagData0==3) )
83 {
84 cmap[tagData0+tagData1].push_back(m_evtNum);
85 }
86 else
87 cmap[tagData0].push_back(m_evtNum);
88
89 //add tag information to each event
90 if (m_dstDataType==1) {
91 evtmap[m_evtNum].push_back(tagData0);
92 evtmap[m_evtNum].push_back(tagData1);
93 evtmap[m_evtNum].push_back(tagData2);
94 evtmap[m_evtNum].push_back(tagData3);
95 evtmap[m_evtNum].push_back(tagData4);
96 } else if ( (m_dstDataType==2) || (m_dstDataType==3) || (m_dstDataType==4) ) {
97 UInt_t tagData5 = m_tagFilterSvc->getTagData5();
98 UInt_t tagData6 = m_tagFilterSvc->getTagData6();
99 UInt_t tagData7 = m_tagFilterSvc->getTagData7();
100 UInt_t tagData8 = m_tagFilterSvc->getTagData8();
101 UInt_t tagData9 = m_tagFilterSvc->getTagData9();
102 evtmap[m_evtNum].push_back(tagData1);
103 evtmap[m_evtNum].push_back(tagData2);
104 evtmap[m_evtNum].push_back(tagData3);
105 evtmap[m_evtNum].push_back(tagData4);
106 evtmap[m_evtNum].push_back(tagData5);
107 evtmap[m_evtNum].push_back(tagData6);
108 evtmap[m_evtNum].push_back(tagData7);
109 evtmap[m_evtNum].push_back(tagData8);
110 evtmap[m_evtNum].push_back(tagData9);
111 }
112
113 m_evtNum++;
114}
115
116// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
118 MsgStream log(msgSvc(), name());
119
120 std::string fn;
121 SmartIF<IJobOptionsSvc> iSvc(Gaudi::svcLocator()->service("JobOptionsSvc"));
122 if ( iSvc.isValid() ) {
123 const std::vector<const Property*>* ps = iSvc->getProperties("EventCnvSvc");
124 std::vector<const Property*>::const_iterator it, end = ps->end();
125 for ( it = ps->begin(); it != end; ++it ) {
126 if ( (*it)->name() == "digiRootInputFile" ) {
127 std::string flist=(*it)->toString();
128 std::string::size_type p1 = flist.find('"') + 1;
129 std::string::size_type p2 = flist.find('"', p1);
130 fn = flist.substr(p1, p2-p1);
131 std::cout<<"input dst file name: "<<fn<<std::endl;
132 }
133 }
134 }
135 TFile* f1 = TFile::Open(fn.c_str(),"READ");
136 TFile* f2 = TFile::Open(m_outputFile.c_str(), "RECREATE");
137 TTree* t1 = (TTree*)f1->Get("Event");
138
139 log << MSG::INFO << "in finalize()" << endmsg;
140 TTree* jt1 = (TTree*)(f1->Get("JobInfoTree"));
141 TTree* jt2 = jt1->CloneTree();
142 TTree* t0 = new TTree("Metadata", "");
143 Int_t mode = -1, begin = 0, end = 0;
144 t0->Branch("mode", &mode, "mode/I");
145 t0->Branch("begin", &begin, "begin/I");
146 t0->Branch("end", &end, "end/I");
147
148 for ( std::map<int, std::vector<long int> >::iterator it = cmap.begin(); it != cmap.end(); ++it ) {
149 mode = it->first;
150 begin = end;
151 end += (it->second).size();
152 std::cout<<"mode: "<<mode<< " begin: "<<begin<< " end: "<<end<<std::endl;
153 t0->Fill();
154 }
155
156 TTree* t2 = t1->CloneTree(0);
157 Int_t nEvents = t1->GetEntries();
158 std::cout<<"Total nEvents: "<<nEvents<<std::endl;
159 Int_t origEntry=0, currEntry=0;
160 UInt_t tagData0, tagData1, tagData2, tagData3, tagData4;
161 UInt_t tagData5, tagData6, tagData7, tagData8;
162 TTree* t3 = new TTree("Entries", "");
163 t3->Branch("origEntry", &origEntry, "origEntry/I");
164 t3->Branch("currEntry", &currEntry, "currEntry/I");
165 t3->Branch("tagData0", &tagData0, "tagData0/i");
166 t3->Branch("tagData1", &tagData1, "tagData1/i");
167 t3->Branch("tagData2", &tagData2, "tagData2/i");
168 t3->Branch("tagData3", &tagData3, "tagData3/i");
169 t3->Branch("tagData4", &tagData4, "tagData4/i");
170 if ( (m_dstDataType==2) || (m_dstDataType==3) || (m_dstDataType==4) ) {
171 t3->Branch("tagData5", &tagData5, "tagData5/i");
172 t3->Branch("tagData6", &tagData6, "tagData6/i");
173 t3->Branch("tagData7", &tagData7, "tagData7/i");
174 t3->Branch("tagData8", &tagData8, "tagData8/i");
175 }
176
177 for ( std::map<int, std::vector<long int> >::iterator it = cmap.begin(); it != cmap.end(); ++it ) {
178 int nNt = it->second.size();
179 std::cout << "Writing " << nNt << "\t events with " << it->first << " TagData0..." << std::endl;
180 for ( int i = 0; i < nNt; ++i ) {
181 origEntry=(it->second)[i];
182 t1->GetEntry(origEntry);
183 tagData0=(evtmap[origEntry])[0];
184 tagData1=(evtmap[origEntry])[1];
185 tagData2=(evtmap[origEntry])[2];
186 tagData3=(evtmap[origEntry])[3];
187 tagData4=(evtmap[origEntry])[4];
188 if ( (m_dstDataType==2) || (m_dstDataType==3) || (m_dstDataType==4) ) {
189 tagData5=(evtmap[origEntry])[5];
190 tagData6=(evtmap[origEntry])[6];
191 tagData7=(evtmap[origEntry])[7];
192 tagData8=(evtmap[origEntry])[8];
193 }
194 t2->Fill();
195 t3->Fill();
196 currEntry++;
197 }
198 (it->second).clear();
199 }
200
201 f2->Write();
202 f2->Close();
203 return StatusCode::SUCCESS;
204}
double p1[4]
double p2[4]
std::ofstream m_outputFile
TFile * f1
HepGeom::Point3D< double > HepPoint3D
IMessageSvc * msgSvc()
StatusCode finalize()
StatusCode execute()
StatusCode initialize()
unsigned int getTagData5()
unsigned int getTagData7()
unsigned int getTagData6()
unsigned int getTagData3()
unsigned int getTagData2()
unsigned int getTagData8()
unsigned int getTagData9()
unsigned int getTagData1()
int getDstDataType()
unsigned int getTagData4()
unsigned int getTagData0()