BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
BesTuningIO.cc
Go to the documentation of this file.
1//---------------------------------------------------------------------------//
2//// BOOST --- BESIII Object_Oriented Simulation Tool //
3////---------------------------------------------------------------------------//
4////Description:
5////Author: Yuan Ye
6////Created: Dec, 2007
7////Modified:
8////Comment:
9//
14#include "BesMdcHit.hh"
15#include "BesTofHit.hh"
16#include "BesEmcHit.hh"
17#include "BesEmcDigi.hh"
18#include "BesMucHit.hh"
19#include "ReadBoostRoot.hh"
20#include "BesTuningIO.hh"
21#include "AsciiDmp/AsciiData.hh"
22
23#include "G4HCofThisEvent.hh"
24#include "G4SDManager.hh"
25#include "G4DigiManager.hh"
26#include "G4ThreeVector.hh"
27
28#include "GaudiKernel/ISvcLocator.h"
29#include "GaudiKernel/Bootstrap.h"
30#include "GaudiKernel/IDataProviderSvc.h"
31
32#include "G4Svc/IG4Svc.h"
33#include "G4Svc/G4Svc.h"
34
35#include "ReadBoostRoot.hh"
36#include "TVector3.h"
37
38using namespace std;
39BesTuningIO::BesTuningIO(std::vector<std::string> name)
40 :m_tuningFile(name),m_evt(0)
41{
42 m_DigiMan = G4DigiManager::GetDMpointer();
43 m_inputFileStream = new std::ifstream();
44
46 //tuning input root file
47 //TFile *f = new TFile(m_tuningFile);
48 //HitTree = (TTree*)f->Get("HitTree");
49 //m_TMcHitEvent = new TMcHitEvent();
50 //TBranch *branch = HitTree->GetBranch("TMcHitEvent");
51 // begin change from TTree to TChain
52 HitChain = new TChain("HitTree");
53 if (m_tuningFile.size()==0){
54 std::cout << "there is no tuning file" << std::endl;
55 }
56 std::cout << "file number: " << m_tuningFile.size() << std::endl;
57 for (int i = 0 ; i < m_tuningFile.size(); i++){
58
59 //std::cout << "________________________________________________________________________________fileName : " << m_tuningFile[i] << std::endl;
60 //HitChain->Add(&m_tuningFile[i]);
61 HitChain->Add(m_tuningFile[i].c_str());
62 }
63 m_TMcHitEvent = new TMcHitEvent();
64 TBranch *branch = HitChain->GetBranch("TMcHitEvent");
65
66 // end change from TTree to TChain
67 branch->SetAddress(&m_TMcHitEvent);
68 std::cout << "HitChain entries: " << HitChain->GetEntries() << std::endl;
69 }
70 else{// tuning input ascii file
71 //m_inputFileStream->open(m_tuningFile.c_str());
72 //if ((*m_inputFileStream).good()) {
73 // try {
74 // (*m_inputFileStream) >> m_version;
75 // } catch (AsciiDumpException& ) {
76 // std::cerr << "BesTuningIO::Got AsciiDumpException eror while reading VERSION block !!!" << std::endl;
77 // }
78 //}else{
79 // std::cerr << "BesTuningIO::Open tuning input file error!!!" << std::endl;
80 //}
81 }
82}
83
85 if (m_inputFileStream) delete m_inputFileStream;
86 if (m_evt) delete m_evt;
87}
88
90 if (m_evt) delete m_evt;
91
92 m_evt = new HitEVENT;
93 try {
94 (*m_inputFileStream) >> *m_evt;
95 } catch (AsciiWrongTag& ex) {
96 std::cerr << "wrong tag, got " << ex.got()
97 << " expected: " << ex.expected()
98 << std::endl;
99 delete m_evt;
100 m_evt=0;
101 return;
102 } catch (AsciiDumpException&) {
103 std::cerr<<"BesTuningIO: Reach file end!"<<std::endl;
104 delete m_evt;
105 m_evt=0;
106 return;
107 }
108
110
112
114
116}
117
119 G4int mdcHitCollID = -1;
120 mdcHitCollID = m_DigiMan->GetHitsCollectionID("BesMdcHitsCollection");
121 if (mdcHitCollID>=0){
122 BesMdcHitsCollection* mdcDC = (BesMdcHitsCollection*)m_DigiMan->GetHitsCollection(mdcHitCollID);
123 if (mdcDC){
124 G4int nHit = mdcDC->entries();
125 if (nHit>0){
126 for (G4int i=0;i<nHit;i++)
127 {
128 delete (*mdcDC)[i];
129 }
130 mdcDC->GetVector()->clear();
131 }
132
133 std::vector<MdcHitType>::iterator iter;
134 iter = (m_evt->mdcHit).hitCol.begin();
135 // Loop over mdc hits
136 for (; iter != (m_evt->mdcHit).hitCol.end(); iter++) {
137 BesMdcHit* newHit = new BesMdcHit();
138 newHit->SetTrackID ((*iter).trackIndex);
139 newHit->SetLayerNo ((*iter).layerNo);
140 newHit->SetCellNo ((*iter).cellNo);
141 newHit->SetEdep ((*iter).energyDeposit);
142 newHit->SetPos (G4ThreeVector((*iter).posX,(*iter).posY,(*iter).posZ));
143 newHit->SetDriftD ((*iter).driftDistance);
144 newHit->SetTheta((*iter).theta);
145 newHit->SetPosFlag((*iter).posFlag);
146 newHit->SetEnterAngle((*iter).enterAngle);
147 newHit->SetDriftT (0.);
148 newHit->SetGlobalT((*iter).globalT);
149 mdcDC->insert(newHit);
150
151 }
152 //mdcDC->PrintAllHits();
153 }else{
154 std::cerr << "BesTuningIO::can't get mdcHitsCollection"<<std::endl;
155 }
156 }else{
157 std::cerr << "BesTuningIO::can't get mdcHitCollID"<<std::endl;
158 }
159}
160
162 G4int THCID = -1;
163 THCID = m_DigiMan->GetDigiCollectionID("BesEmcDigitsCollection");
164 if (THCID>=0) {
165 BesEmcDigitsCollection* emcDC = new BesEmcDigitsCollection("BesEmcDigitizer","BesEmcDigitsCollection");
166 m_DigiMan->SetDigiCollection(THCID,emcDC);
167 }
168}
169
170//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
171
172//Below use root format tuning not ascii format
174 //std::cout << "evtID: " << evtID << std::endl;
175 //HitTree->GetEntry(evtID);
176 HitChain->GetEntry(evtID);
177 //std::cout << "HitChain" << std::endl;
182}
183
184
186 G4int THCID = -1;
187 THCID = m_DigiMan->GetDigiCollectionID("BesEmcDigitsCollection");
188 //cout << "THCID " << THCID << endl;
189 if (THCID>=0) {
190 BesEmcDigitsCollection* emcDC = new BesEmcDigitsCollection("BesEmcDigitizer","BesEmcDigitsCollection");
191
192 //std::cout << "GetEmcRootDigi " << emcDC << std::endl;
193 if(emcDC){
194 int nHit = emcDC->entries();
195 //std::cout << "nHit: " << nHit << std::endl;
196 if(nHit > 0){
197 for(int i = 0; i < nHit; i++){
198 delete (*emcDC)[i];
199 }
200 emcDC->GetVector()->clear();
201 }
202 }
203
204 int nHits = m_TMcHitEvent->getMcDigiEmcCol()->GetEntries();
205 //std::cout << "nHits: " << nHits << std::endl;
206 for(int i = 0; i < nHits; i++){
207 m_TMcDigiEmc = m_TMcHitEvent->getMcDigiEmc(i);
208
209 BesEmcDigi* emcDigi = new BesEmcDigi();
210
211 emcDigi->SetPartId(m_TMcDigiEmc->GetPartId());
212 emcDigi->SetThetaNb(m_TMcDigiEmc->GetThetaNb());
213 emcDigi->SetPhiNb(m_TMcDigiEmc->GetPhiNb());
214 emcDigi->SetEnergy(m_TMcDigiEmc->GetEnergy());
215 emcDigi->SetTime(m_TMcDigiEmc->GetTime());
216 emcDigi->SetTrackIndex(m_TMcDigiEmc->GetTrackIndex());
217 //emcDigi->Print();
218 //std::cout << "SetEnergy" << emcDigi->GetEnergy() << std::endl;
219
220 emcDC->insert(emcDigi);
221 delete m_TMcDigiEmc;
222
223 }
224
225 //std::cout << "insert" << std::endl;
226 m_DigiMan->SetDigiCollection(THCID,emcDC);
227
228
229 }
230
231}
232
234
235 G4int THCID = -1;
236 THCID = m_DigiMan->GetHitsCollectionID("BesMdcHitsCollection");
237 if (THCID>=0) {
238 BesMdcHitsCollection* mdcDC = (BesMdcHitsCollection*) (m_DigiMan->GetHitsCollection(THCID));
239 if(mdcDC){
240 int nHit = mdcDC->entries();
241 if(nHit > 0){
242 for(int i = 0; i < nHit; i++){
243 delete (*mdcDC)[i];
244 }
245 mdcDC->GetVector()->clear();
246 }
247 }
248
249 int nHits = m_TMcHitEvent->getMcHitMdcCol()->GetEntries();
250 //std::cout << "nHits: " << nHits << std::endl;
251 for(int i = 0; i < nHits; i++){
252 m_TMcHitMdc = m_TMcHitEvent->getMcHitMdc(i);
253
254 BesMdcHit* mdcHit = new BesMdcHit();
255
256 mdcHit->SetTrackID(m_TMcHitMdc->GetTrackID());
257 mdcHit->SetLayerNo(m_TMcHitMdc->GetLayerNo());
258 mdcHit->SetCellNo(m_TMcHitMdc->GetCellNo());
259 mdcHit->SetEdep(m_TMcHitMdc->GetEdep());
260 mdcHit->SetDriftD(m_TMcHitMdc->GetDriftD());
261 mdcHit->SetDriftT(m_TMcHitMdc->GetDriftT());
262 mdcHit->SetGlobalT(m_TMcHitMdc->GetGlobalT());
263 mdcHit->SetTheta(m_TMcHitMdc->GetTheta());
264 mdcHit->SetEnterAngle(m_TMcHitMdc->GetEnterAngle());
265 mdcHit->SetPosFlag(m_TMcHitMdc->GetPosFlag());
266
267 TVector3 tTemp = m_TMcHitMdc->GetPos();
268 G4ThreeVector gTemp = G4ThreeVector(tTemp.X(), tTemp.Y(), tTemp.Z());
269 mdcHit->SetPos(gTemp);
270 //mdcHit->Print();
271
272 mdcDC->insert(mdcHit);
273 delete m_TMcHitMdc;
274
275 }
276
277
278 }
279
280}
281
283
284 //retrieve G4Svc
285 ISvcLocator* svcLocator = Gaudi::svcLocator();
286 IG4Svc* tmpSvc;
287 StatusCode sc = svcLocator->service("G4Svc", tmpSvc);
288 G4Svc* m_G4Svc = dynamic_cast<G4Svc *>(tmpSvc);
289
290 const double m_beamTime = m_TMcHitEvent->getBeamTime();
291 m_G4Svc->SetBeamTime(m_beamTime);
292 //std::cout << "beamtime: " << m_beamTime << std::endl;
293
294 G4int THCID = -1;
295 THCID = m_DigiMan->GetHitsCollectionID("BesTofHitsCollection");
296 if (THCID>=0) {
297 BesTofHitsCollection* tofDC = (BesTofHitsCollection*) (m_DigiMan->GetHitsCollection(THCID));
298 if(tofDC){
299 int nHit = tofDC->entries();
300 if(nHit > 0){
301 for(int i = 0; i < nHit; i++){
302 delete (*tofDC)[i];
303 }
304 tofDC->GetVector()->clear();
305 }
306 }
307
308 int nHits = m_TMcHitEvent->getMcHitTofCol()->GetEntries();
309 //std::cout << "nHits: " << nHits << std::endl;
310 for(int i = 0; i < nHits; i++){
311 m_TMcHitTof = m_TMcHitEvent->getMcHitTof(i);
312
313 BesTofHit* tofHit = new BesTofHit();
314
315 tofHit->SetTrackIndex(m_TMcHitTof->GetTrackIndex());
316 tofHit->SetG4Index(m_TMcHitTof->GetG4Index());
317 tofHit->SetPartId(m_TMcHitTof->GetPartId());
318 tofHit->SetScinNb(m_TMcHitTof->GetScinNb());
319 tofHit->SetEdep(m_TMcHitTof->GetEdep());
320 tofHit->SetStepL(m_TMcHitTof->GetStepL());
321 tofHit->SetTrackL(m_TMcHitTof->GetTrackL());
322 tofHit->SetTime(m_TMcHitTof->GetTime());
323 tofHit->SetDeltaT(m_TMcHitTof->GetDeltaT());
324 tofHit->SetCharge(m_TMcHitTof->GetCharge());
325
326 TVector3 tTemp = m_TMcHitTof->GetPos();
327 G4ThreeVector gTemp(tTemp.X(), tTemp.Y(), tTemp.Z());
328 tofHit->SetPos(gTemp);
329
330 tTemp = m_TMcHitTof->GetPDirection();
331 gTemp = G4ThreeVector(tTemp.X(), tTemp.Y(), tTemp.Z());
332 tofHit->SetPDirection(gTemp);
333
334 tTemp = m_TMcHitTof->GetMomentum();
335 gTemp = G4ThreeVector(tTemp.X(), tTemp.Y(), tTemp.Z());
336 tofHit->SetMomentum(gTemp);
337
338 //tofHit->Print();
339
340 tofDC->insert(tofHit);
341 delete m_TMcHitTof;
342
343 }
344
345 //std::cout << "tofDC: " << tofDC->entries() << std::endl;
346
347 }
348
349}
G4TDigiCollection< BesEmcDigi > BesEmcDigitsCollection
Definition: BesEmcDigi.hh:69
G4THitsCollection< BesMdcHit > BesMdcHitsCollection
Definition: BesMdcHit.hh:78
G4THitsCollection< BesTofHit > BesTofHitsCollection
Definition: BesTofHit.hh:108
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
std::string got() const
Definition: dmplib.hh:22
std::string expected() const
Definition: dmplib.hh:21
void SetTrackIndex(G4int index)
Definition: BesEmcDigi.hh:46
void SetTime(G4double time)
Definition: BesEmcDigi.hh:45
void SetPartId(G4int id)
Definition: BesEmcDigi.hh:41
void SetEnergy(G4double energy)
Definition: BesEmcDigi.hh:44
void SetThetaNb(G4int nTheta)
Definition: BesEmcDigi.hh:42
void SetPhiNb(G4int nPhi)
Definition: BesEmcDigi.hh:43
void SetEdep(G4double de)
Definition: BesMdcHit.hh:41
void SetDriftT(G4double time)
Definition: BesMdcHit.hh:44
void SetEnterAngle(G4double angle)
Definition: BesMdcHit.hh:47
void SetCellNo(G4int cell)
Definition: BesMdcHit.hh:40
void SetPos(G4ThreeVector xyz)
Definition: BesMdcHit.hh:42
void SetTrackID(G4int track)
Definition: BesMdcHit.hh:38
void SetLayerNo(G4int layer)
Definition: BesMdcHit.hh:39
void SetTheta(G4double angle)
Definition: BesMdcHit.hh:46
void SetDriftD(G4double distance)
Definition: BesMdcHit.hh:43
void SetGlobalT(G4double time)
Definition: BesMdcHit.hh:45
void SetPosFlag(G4int flag)
Definition: BesMdcHit.hh:48
void SetPos(G4ThreeVector pos)
Definition: BesTofHit.hh:48
void SetDeltaT(G4double deltaT)
Definition: BesTofHit.hh:50
void SetCharge(G4double charge)
Definition: BesTofHit.hh:55
void SetTrackIndex(G4int trackIndex)
Definition: BesTofHit.hh:41
void SetPDirection(G4ThreeVector pDirection)
Definition: BesTofHit.hh:51
void SetPartId(G4int partId)
Definition: BesTofHit.hh:43
void SetScinNb(G4int scinNb)
Definition: BesTofHit.hh:44
void SetStepL(G4double stepL)
Definition: BesTofHit.hh:46
void SetTrackL(G4double length)
Definition: BesTofHit.hh:47
void SetTime(G4double time)
Definition: BesTofHit.hh:49
void SetEdep(G4double edep)
Definition: BesTofHit.hh:45
void SetMomentum(G4ThreeVector momentum)
Definition: BesTofHit.hh:52
void SetG4Index(G4int index)
Definition: BesTofHit.hh:42
void GetMdcHits(void)
Definition: BesTuningIO.cc:118
BesTuningIO(std::vector< std::string >)
Definition: BesTuningIO.cc:39
TChain * HitChain
Definition: BesTuningIO.hh:44
void GetEmcRootDigi()
Definition: BesTuningIO.cc:185
void GetTofRootHits()
Definition: BesTuningIO.cc:282
void GetEmcDigi(void)
Definition: BesTuningIO.cc:161
void GetMucHits(void)
Definition: BesTuningIO.hh:39
void GetTofHits(void)
Definition: BesTuningIO.hh:37
void GetMdcRootHits()
Definition: BesTuningIO.cc:233
void GetRootEvent(int evtID)
Definition: BesTuningIO.cc:173
void GetNextEvents(void)
Definition: BesTuningIO.cc:89
Definition: G4Svc.h:32
void SetBeamTime(double value)
Definition: G4Svc.h:86
MDCHIT mdcHit
Definition: AsciiData.hh:418
Definition: IG4Svc.h:30
static G4int GetFormatAR()
static G4int GetMdc()
static G4int GetMuc()
static G4int GetTof()
static G4int GetEmc()
Int_t GetPartId() const
Definition: TMcDigiEmc.h:24
Double_t GetTime() const
Definition: TMcDigiEmc.h:28
Int_t GetThetaNb() const
Definition: TMcDigiEmc.h:25
Int_t GetPhiNb() const
Definition: TMcDigiEmc.h:26
Int_t GetTrackIndex() const
Definition: TMcDigiEmc.h:29
Double_t GetEnergy() const
Definition: TMcDigiEmc.h:27
const TObjArray * getMcHitTofCol() const
retrieve the whole TObjArray of McHitTof Data
Definition: TMcHitEvent.h:23
const TMcHitTof * getMcHitTof(Int_t i) const
retrieve a McHitTof From the collection, using the index into the array
Definition: TMcHitEvent.cxx:68
const TObjArray * getMcDigiEmcCol() const
retrieve the whole TObjArray of McHitMdc Data
Definition: TMcHitEvent.h:41
const TMcHitMdc * getMcHitMdc(Int_t i) const
retrieve a McHitMdc From the collection, using the index into the array
Definition: TMcHitEvent.cxx:79
const TMcDigiEmc * getMcDigiEmc(Int_t i) const
retrieve a McHitMdc From the collection, using the index into the array
Definition: TMcHitEvent.cxx:57
const TObjArray * getMcHitMdcCol() const
retrieve the whole TObjArray of McHitMdc Data
Definition: TMcHitEvent.h:32
Double_t getBeamTime() const
Definition: TMcHitEvent.h:50
Double_t GetTheta() const
Definition: TMcHitMdc.h:36
Double_t GetGlobalT() const
Definition: TMcHitMdc.h:35
Int_t GetLayerNo() const
Definition: TMcHitMdc.h:29
TVector3 GetPos() const
Definition: TMcHitMdc.h:32
Double_t GetEdep() const
Definition: TMcHitMdc.h:31
Double_t GetDriftT() const
Definition: TMcHitMdc.h:34
Double_t GetEnterAngle() const
Definition: TMcHitMdc.h:37
Double_t GetDriftD() const
Definition: TMcHitMdc.h:33
Int_t GetPosFlag() const
Definition: TMcHitMdc.h:38
Int_t GetCellNo() const
Definition: TMcHitMdc.h:30
Int_t GetTrackID() const
Definition: TMcHitMdc.h:28
Int_t GetG4Index() const
Definition: TMcHitTof.h:32
Int_t GetTrackIndex() const
Definition: TMcHitTof.h:31
Double_t GetEdep() const
Definition: TMcHitTof.h:35
TVector3 GetPDirection() const
Definition: TMcHitTof.h:41
TVector3 GetMomentum() const
Definition: TMcHitTof.h:42
Int_t GetPartId() const
Definition: TMcHitTof.h:33
Double_t GetStepL() const
Definition: TMcHitTof.h:36
Double_t GetTrackL() const
Definition: TMcHitTof.h:37
Double_t GetDeltaT() const
Definition: TMcHitTof.h:40
Int_t GetScinNb() const
Definition: TMcHitTof.h:34
Double_t GetTime() const
Definition: TMcHitTof.h:39
Int_t GetCharge() const
Definition: TMcHitTof.h:43
TVector3 GetPos() const
Definition: TMcHitTof.h:38