BOSS 7.0.8
BESIII Offline Software System
Loading...
Searching...
No Matches
BesTuningIO Class Reference

#include <BesTuningIO.hh>

Public Member Functions

 BesTuningIO (std::vector< std::string >)
 
 ~BesTuningIO ()
 
void GetNextEvents (void)
 
void GetMdcHits (void)
 
void GetTofHits (void)
 
void GetEmcDigi (void)
 
void GetMucHits (void)
 
void GetRootEvent (int evtID)
 
void GetMdcRootHits ()
 
void GetTofRootHits ()
 
void GetEmcRootDigi ()
 

Public Attributes

TFile * f
 
TTree * HitTree
 
TChain * HitChain
 

Detailed Description

Definition at line 26 of file BesTuningIO.hh.

Constructor & Destructor Documentation

◆ BesTuningIO()

BesTuningIO::BesTuningIO ( std::vector< std::string >  name)

Definition at line 39 of file BesTuningIO.cc.

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}
TChain * HitChain
Definition: BesTuningIO.hh:44
static G4int GetFormatAR()
char * c_str(Index i)
Definition: EvtCyclic3.cc:252

◆ ~BesTuningIO()

BesTuningIO::~BesTuningIO ( )

Definition at line 84 of file BesTuningIO.cc.

84 {
85 if (m_inputFileStream) delete m_inputFileStream;
86 if (m_evt) delete m_evt;
87}

Member Function Documentation

◆ GetEmcDigi()

void BesTuningIO::GetEmcDigi ( void  )

Definition at line 161 of file BesTuningIO.cc.

161 {
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}
G4TDigiCollection< BesEmcDigi > BesEmcDigitsCollection
Definition: BesEmcDigi.hh:69

Referenced by GetNextEvents().

◆ GetEmcRootDigi()

void BesTuningIO::GetEmcRootDigi ( )

Definition at line 185 of file BesTuningIO.cc.

185 {
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}
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
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 * getMcDigiEmcCol() const
retrieve the whole TObjArray of McHitMdc Data
Definition: TMcHitEvent.h:41
const TMcDigiEmc * getMcDigiEmc(Int_t i) const
retrieve a McHitMdc From the collection, using the index into the array
Definition: TMcHitEvent.cxx:57

Referenced by GetRootEvent().

◆ GetMdcHits()

void BesTuningIO::GetMdcHits ( void  )

Definition at line 118 of file BesTuningIO.cc.

118 {
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}
G4THitsCollection< BesMdcHit > BesMdcHitsCollection
Definition: BesMdcHit.hh:78
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
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
MDCHIT mdcHit
Definition: AsciiData.hh:418

Referenced by GetNextEvents().

◆ GetMdcRootHits()

void BesTuningIO::GetMdcRootHits ( )

Definition at line 233 of file BesTuningIO.cc.

233 {
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}
const TMcHitMdc * getMcHitMdc(Int_t i) const
retrieve a McHitMdc From the collection, using the index into the array
Definition: TMcHitEvent.cxx:79
const TObjArray * getMcHitMdcCol() const
retrieve the whole TObjArray of McHitMdc Data
Definition: TMcHitEvent.h:32
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

Referenced by GetRootEvent().

◆ GetMucHits()

void BesTuningIO::GetMucHits ( void  )
inline

Definition at line 39 of file BesTuningIO.hh.

39{};

Referenced by GetNextEvents(), and GetRootEvent().

◆ GetNextEvents()

void BesTuningIO::GetNextEvents ( void  )

Definition at line 89 of file BesTuningIO.cc.

89 {
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}
std::string got() const
Definition: dmplib.hh:22
std::string expected() const
Definition: dmplib.hh:21
void GetMdcHits(void)
Definition: BesTuningIO.cc:118
void GetEmcDigi(void)
Definition: BesTuningIO.cc:161
void GetMucHits(void)
Definition: BesTuningIO.hh:39
void GetTofHits(void)
Definition: BesTuningIO.hh:37
static G4int GetMdc()
static G4int GetMuc()
static G4int GetTof()
static G4int GetEmc()

Referenced by BesEventAction::EndOfEventAction().

◆ GetRootEvent()

void BesTuningIO::GetRootEvent ( int  evtID)

Definition at line 173 of file BesTuningIO.cc.

173 {
174 //std::cout << "evtID: " << evtID << std::endl;
175 //HitTree->GetEntry(evtID);
176 HitChain->GetEntry(evtID);
177 //std::cout << "HitChain" << std::endl;
182}
void GetEmcRootDigi()
Definition: BesTuningIO.cc:185
void GetTofRootHits()
Definition: BesTuningIO.cc:282
void GetMdcRootHits()
Definition: BesTuningIO.cc:233

Referenced by BesEventAction::EndOfEventAction().

◆ GetTofHits()

void BesTuningIO::GetTofHits ( void  )
inline

Definition at line 37 of file BesTuningIO.hh.

37{};

Referenced by GetNextEvents().

◆ GetTofRootHits()

void BesTuningIO::GetTofRootHits ( )

Definition at line 282 of file BesTuningIO.cc.

282 {
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}
G4THitsCollection< BesTofHit > BesTofHitsCollection
Definition: BesTofHit.hh:116
void SetPos(G4ThreeVector pos)
Definition: BesTofHit.hh:50
void SetDeltaT(G4double deltaT)
Definition: BesTofHit.hh:52
void SetCharge(G4double charge)
Definition: BesTofHit.hh:57
void SetTrackIndex(G4int trackIndex)
Definition: BesTofHit.hh:43
void SetPDirection(G4ThreeVector pDirection)
Definition: BesTofHit.hh:53
void SetPartId(G4int partId)
Definition: BesTofHit.hh:45
void SetScinNb(G4int scinNb)
Definition: BesTofHit.hh:46
void SetStepL(G4double stepL)
Definition: BesTofHit.hh:48
void SetTrackL(G4double length)
Definition: BesTofHit.hh:49
void SetTime(G4double time)
Definition: BesTofHit.hh:51
void SetEdep(G4double edep)
Definition: BesTofHit.hh:47
void SetMomentum(G4ThreeVector momentum)
Definition: BesTofHit.hh:54
void SetG4Index(G4int index)
Definition: BesTofHit.hh:44
Definition: G4Svc.h:32
void SetBeamTime(double value)
Definition: G4Svc.h:86
Definition: IG4Svc.h:30
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
Double_t getBeamTime() const
Definition: TMcHitEvent.h:50
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

Referenced by GetRootEvent().

Member Data Documentation

◆ f

TFile* BesTuningIO::f

Definition at line 42 of file BesTuningIO.hh.

◆ HitChain

TChain* BesTuningIO::HitChain

Definition at line 44 of file BesTuningIO.hh.

Referenced by BesTuningIO(), and GetRootEvent().

◆ HitTree

TTree* BesTuningIO::HitTree

Definition at line 43 of file BesTuningIO.hh.


The documentation for this class was generated from the following files: