CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
CgemSimCheck Class Reference

#include <CgemSimCheck.h>

+ Inheritance diagram for CgemSimCheck:

Public Member Functions

 CgemSimCheck (const std::string &name, ISvcLocator *pSvcLocator)
 
 ~CgemSimCheck ()
 
StatusCode initialize ()
 
StatusCode execute ()
 
StatusCode finalize ()
 
StatusCode beginRun ()
 

Detailed Description

Definition at line 42 of file CgemSimCheck.h.

Constructor & Destructor Documentation

◆ CgemSimCheck()

CgemSimCheck::CgemSimCheck ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

Definition at line 58 of file CgemSimCheck.cxx.

58 :
59 Algorithm(name, pSvcLocator)
60{
61 m_F_McTruth = 1;
62 m_F_Digi = 1;
63 m_F_McParticle=1;
64
65 declareProperty("PostFix", m_postfix = "");
66
67 /* Save McTruth information to compare with Root RawData Information */
68 if (m_F_McTruth == 1)
69 {
70 cout << "INFO : CgemSimCheck::CgemSimCheck(), McTruth Hit will be output to a txt file!"
71 << endl;
72
73 // string outputFile1 = getenv("CGEMSIMCHECKROOT");
74 string outputFile1 = "output_McTruth.txt";
75 cout<<"output_McTruth : "<<outputFile1<<endl;
76
77 // m_output_McTruth.open(outputFile1.c_str(), ios::out | ios::app);
78 m_output_McTruth.open(outputFile1.c_str(), ios::out );
79
80 if (!m_output_McTruth.good())
81 {
82 cout << "ERROR : CgemSimCheck::CgemSimCheck(), Fail to open McTruth output file: "
83 << outputFile1 << endl;
84 return ;
85 }
86
87 } /* End of 'if (m_F_McTruth == 1)' */
88
89 /* Save Digi information to compare with Root RawData Information */
90 if (m_F_Digi == 1)
91 {
92 cout << "INFO : CgemSimCheck::CgemSimCheck(), Digi Hit will be output to a txt file!"
93 << endl;
94
95 // string outputFile2 = getenv("CGEMSIMCHECKROOT");
96 string outputFile2 = "output_Digi.txt";
97 cout<<"Digi file : "<<outputFile2<<endl;
98 // m_output_Digi.open(outputFile2.c_str(), ios::out | ios::app);
99 m_output_Digi.open(outputFile2.c_str(), ios::out );
100
101 if (!m_output_Digi.good())
102 {
103 cout << "ERROR : CgemSimCheck::CgemSimCheck(), Fail to open Digi output file: "
104 << outputFile2 << endl;
105 return ;
106 }
107
108 } /* End of 'if (m_F_Digi == 1)' */
109
110 if (m_F_McParticle == 1 )
111 {
112 cout << "INFO : CgemSimCheck::CgemSimCheck(), MCParticle will be output to a txt file!"
113 << endl;
114
115 // string outputFile3 = getenv("CGEMSIMCHECKROOT");
116 string outputFile3 = "output_McParticle.txt";
117 cout<<"Digi file : "<<outputFile3<<endl;
118 // m_output_Digi.open(outputFile2.c_str(), ios::out | ios::app);
119 m_output_McParticle.open(outputFile3.c_str(), ios::out );
120
121 if (!m_output_McParticle.good())
122 {
123 cout << "ERROR : CgemSimCheck::CgemSimCheck(), Fail to open McParticle output file: "
124 << outputFile3 << endl;
125 return ;
126 }
127
128 } /* End of 'if (m_F_McParticle == 1)' */
129}

◆ ~CgemSimCheck()

CgemSimCheck::~CgemSimCheck ( )

Definition at line 132 of file CgemSimCheck.cxx.

133{
134 m_output_McTruth.close();
135 m_output_Digi.close();
136}

Member Function Documentation

◆ beginRun()

StatusCode CgemSimCheck::beginRun ( )

Definition at line 139 of file CgemSimCheck.cxx.

140{
141 MsgStream log(msgSvc(), name());
142 log << MSG::INFO << "in beginRun()" << endreq;
143 return StatusCode::SUCCESS;
144}
IMessageSvc * msgSvc()

◆ execute()

StatusCode CgemSimCheck::execute ( )

Definition at line 257 of file CgemSimCheck.cxx.

258{
259 MsgStream log(msgSvc(), name());
260 log << MSG::INFO << "in execute()" << endreq;
261
262 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
263 if (!eventHeader)
264 {
265 log << MSG::FATAL << "Could not find Event Header" << endreq;
266 return StatusCode::FAILURE;
267 }
268
269 cout << "" << endl;
270 cout << "Event: " << eventHeader->eventNumber() << endl;
271 int iEvt = eventHeader->eventNumber();
272 int iRun = eventHeader->runNumber();
273
274 m_run = iRun;
275 m_evt = iEvt;
276 cout<<" Run : "<<m_run<<"Event : "<<m_evt<<endl;
277 /* Get McTruth information */
278 if (m_F_McTruth == 1)
279 {
280 SmartDataPtr<Event::CgemMcHitCol> lv_CgemMcHitCol(eventSvc(), "/Event/MC/CgemMcHitCol");
281 if (!lv_CgemMcHitCol)
282 {
283 log << MSG::WARNING << "Could not find event" << endreq;
284 return StatusCode::FAILURE;
285 }
286
287 Event::CgemMcHitCol::iterator iter_truth = lv_CgemMcHitCol->begin();
288 int i=0;
289 for(; iter_truth != lv_CgemMcHitCol->end(); ++iter_truth)
290 {
291 m_output_McTruth << left << setw( 5) << (*iter_truth)->GetTrackID()
292 << left << setw( 3) << (*iter_truth)->GetLayerID()
293 << left << setw(12) << (*iter_truth)->GetTotalEnergyDeposit()
294 << left << setw(12) << (*iter_truth)->GetPositionXOfPrePoint()
295 << left << setw(12) << (*iter_truth)->GetPositionYOfPrePoint()
296 << left << setw(12) << (*iter_truth)->GetPositionZOfPrePoint()
297 << left << setw(12) << (*iter_truth)->GetPositionXOfPostPoint()
298 << left << setw(12) << (*iter_truth)->GetPositionYOfPostPoint()
299 << left << setw(12) << (*iter_truth)->GetPositionZOfPostPoint()
300 << left << setw(12) << (*iter_truth)->GetMomentumXOfPrePoint()
301 << left << setw(12) << (*iter_truth)->GetMomentumYOfPrePoint()
302 << left << setw(12) << (*iter_truth)->GetMomentumZOfPrePoint()
303 << left << setw(12) << (*iter_truth)->GetMomentumXOfPostPoint()
304 << left << setw(12) << (*iter_truth)->GetMomentumYOfPostPoint()
305 << left << setw(12) << (*iter_truth)->GetMomentumZOfPostPoint()
306 << endl;
307
308
309 m_mc_ID_track[i]=(*iter_truth)->GetTrackID();
310 m_mc_ID_layer[i]=(*iter_truth)->GetLayerID();
311 m_mc_E_deposit[i]=(*iter_truth)->GetTotalEnergyDeposit();
312 m_mc_XYZ_pre_X[i] =(*iter_truth)->GetPositionXOfPrePoint() ;
313 m_mc_XYZ_pre_Y[i] =(*iter_truth)->GetPositionYOfPrePoint() ;
314 m_mc_XYZ_pre_Z[i] =(*iter_truth)->GetPositionZOfPrePoint() ;
315 m_mc_XYZ_post_X[i]=(*iter_truth)->GetPositionXOfPostPoint();
316 m_mc_XYZ_post_Y[i]=(*iter_truth)->GetPositionYOfPostPoint();
317 m_mc_XYZ_post_Z[i]=(*iter_truth)->GetPositionZOfPostPoint();
318 m_mc_P_pre_X[i]=(*iter_truth)->GetMomentumXOfPrePoint() ;
319 m_mc_P_pre_Y[i]=(*iter_truth)->GetMomentumYOfPrePoint() ;
320 m_mc_P_pre_Z[i]=(*iter_truth)->GetMomentumZOfPrePoint() ;
321 m_mc_P_post_X[i]=(*iter_truth)->GetMomentumXOfPostPoint();
322 m_mc_P_post_Y[i]=(*iter_truth)->GetMomentumYOfPostPoint();
323 m_mc_P_post_Z[i]=(*iter_truth)->GetMomentumZOfPostPoint();
324 i++;
325 }
326
327 m_mc_nHit=i;
328 cout<<" mc_Hit "<<m_mc_nHit<<endl;
329 mc_tuple->write();
330 } /* End of 'if (m_F_McTruth == 1)' */
331
332 /* Get Digi information */
333 if (m_F_Digi == 1)
334 {
335 SmartDataPtr<CgemDigiCol> lv_CgemDigiCol(eventSvc(),"/Event/Digi/CgemDigiCol");
336
337 if ( !lv_CgemDigiCol )
338 {
339 log << MSG::WARNING << "Could not find event" << endreq;
340 return StatusCode::FAILURE;
341 }
342
343 CgemDigiCol::iterator iter_digi = lv_CgemDigiCol->begin();
344 CgemID *cgemid=new CgemID();
345 int j = 0,x_flag;
346 int m_X=0,m_V=0;
347 bool xflag;
348 for( ; iter_digi != lv_CgemDigiCol->end(); ++iter_digi)
349 {
350 x_flag = 0;
351 m_output_Digi << left << setw( 8) << (*iter_digi)->getTrackIndex()
352 << left << setw( 8) << CgemID::layer((*iter_digi)->identify())
353 << left << setw( 8) << CgemID::sheet((*iter_digi)->identify())
354 << left << setw( 8) << CgemID::strip((*iter_digi)->identify())
355 << left << setw(16) << (*iter_digi)->getTimeChannel()
356 << left << setw(16) << (*iter_digi)->getChargeChannel()
357 << endl;
358 xflag=cgemid->is_xstrip((*iter_digi)->identify());
359 // if (xflag){
360 // x_flag=1;
361 // m_X_ID_strip[j]=CgemID::strip((*iter_digi)->identify());
362 // }
363 // else{
364 // m_V_ID_strip[j]=CgemID::strip((*iter_digi)->identify());
365 // }
366 // cout<<"X_Flag : "<<x_flag<<endl;
367 m_ID_track[j]=(*iter_digi)->getTrackIndex();
368 m_ID_layer[j]=CgemID::layer((*iter_digi)->identify());
369 m_ID_sheet[j]=CgemID::sheet((*iter_digi)->identify());
370 m_ID_strip[j]=CgemID::strip((*iter_digi)->identify());
371 m_globle_time[j]= (*iter_digi)->getTimeChannel();
372 m_E_deposit[j]= (*iter_digi)->getChargeChannel();
373 j++;
374 if (xflag){
375 m_E_X[m_X]=(*iter_digi)->getChargeChannel();
376 m_X++;
377 }
378 else{
379 m_E_V[m_V]=(*iter_digi)->getChargeChannel();
380 m_V++;
381 }
382
383 }
384 m_nHit=j;
385 m_Xnstrip=m_X;
386 m_Vnstrip=m_V;
387 // cout<<"Hit : "<<m_nHit<<endl;
388 // cout<<"Xnsrtip : "<<m_Xnstrip<<endl;
389 // cout<<"Vnsrtip : "<<m_Vnstrip<<endl;
390 m_tuple->write();
391 } /* End of 'if(m_F_Digi == 1)' */
392
393 if (m_F_McParticle == 1 )
394 {
395 SmartDataPtr<Event::McParticleCol> mcParticleCol(eventSvc(),"/Event/MC/McParticleCol");
396 if (!mcParticleCol)
397 {
398 cout<< "Could not retrieve McParticelCol" << endl;
399 }
400
401 Event::McParticleCol::iterator iter_mcP = mcParticleCol->begin();
402 int ii=0;
403 for (; iter_mcP != mcParticleCol->end(); iter_mcP++)
404 {
405 m_trkindex[ii]=(*iter_mcP)->trackIndex();
406 m_mcParticle_x[ii]=((*iter_mcP)->initialPosition()).x();
407 m_mcParticle_y[ii]=((*iter_mcP)->initialPosition()).y();
408 m_mcParticle_z[ii]=((*iter_mcP)->initialPosition()).z();
409 m_mcParticle_px[ii]=((*iter_mcP)->initialFourMomentum()).x();
410 m_mcParticle_py[ii]=((*iter_mcP)->initialFourMomentum()).y();
411 m_mcParticle_pz[ii]=((*iter_mcP)->initialFourMomentum()).z();
412 m_mcParticle_E[ii]=((*iter_mcP)->initialFourMomentum()).e();
413 m_mcParticle_phi[ii]=((*iter_mcP)->initialFourMomentum()).phi();
414 m_mcParticle_costheta[ii]=((*iter_mcP)->initialFourMomentum()).cosTheta();
415 m_mcParticle_theta[ii]=((*iter_mcP)->initialFourMomentum()).theta();
416 m_mcParticle_pt[ii]=(((*iter_mcP)->initialFourMomentum()).mag())*sin(m_mcParticle_theta[ii]);
417 // cout<<(*iter_mcP)->trackIndex()<<endl;
418 m_output_McParticle << left << setw( 8) << (*iter_mcP)->trackIndex()
419 <<left<<setw(10)<<((*iter_mcP)->initialPosition()).x()
420 <<left<<setw(10)<<((*iter_mcP)->initialPosition()).y()
421 <<left<<setw(10)<<((*iter_mcP)->initialPosition()).z()
422 <<left<<setw(10)<<((*iter_mcP)->initialFourMomentum()).px()
423 <<left<<setw(10)<<((*iter_mcP)->initialFourMomentum()).py()
424 <<left<<setw(12)<<((*iter_mcP)->initialFourMomentum()).pz()
425 <<left<<setw(12)<<((*iter_mcP)->initialFourMomentum()).e()
426 <<left<<setw(12)<<((*iter_mcP)->initialFourMomentum()).phi()
427 <<left<<setw(12)<<((*iter_mcP)->initialFourMomentum()).cosTheta()
428 <<left<<setw(12)<<((*iter_mcP)->initialFourMomentum()).theta()
429 <<left<<setw(12)<<m_mcParticle_pt[ii]
430 <<endl;
431 // if (m_evt == 83){
432 ofstream outoneevt("evtput.txt",ios::app);
433
434 outoneevt<<left<<setw(7)<<m_evt
435 // <<left<<setw(6)<<m_ID_track
436 // <<left<<setw(6)<<m_ID_layer<<
437 <<left << setw( 5) << (*iter_mcP)->trackIndex()
438 <<left<<setw(10)<<((*iter_mcP)->initialPosition()).x()
439 <<left<<setw(10)<<((*iter_mcP)->initialPosition()).y()
440 <<left<<setw(10)<<((*iter_mcP)->initialPosition()).z()
441 <<left<<setw(10)<<((*iter_mcP)->initialFourMomentum()).px()
442 <<left<<setw(10)<<((*iter_mcP)->initialFourMomentum()).py()
443 <<left<<setw(12)<<((*iter_mcP)->initialFourMomentum()).pz()
444 <<left<<setw(12)<<((*iter_mcP)->initialFourMomentum()).e()
445 <<left<<setw(12)<<((*iter_mcP)->initialFourMomentum()).phi()
446 <<left<<setw(12)<<((*iter_mcP)->initialFourMomentum()).cosTheta()
447 <<left<<setw(12)<<((*iter_mcP)->initialFourMomentum()).theta()
448 <<left<<setw(12)<<m_mcParticle_pt[ii]
449 <<endl;
450 outoneevt.close();
451 // }
452 ii++;
453 }
454 Nparticle=ii;
455 mcP_tuple->write();
456 }
457 return StatusCode::SUCCESS;
458}
double sin(const BesAngle a)
Definition: BesAngle.h:210
Double_t x[10]
Definition: CgemID.h:15
static int strip(const Identifier &id)
Definition: CgemID.cxx:83
static int sheet(const Identifier &id)
Definition: CgemID.cxx:77
static int layer(const Identifier &id)
Definition: CgemID.cxx:71
static bool is_xstrip(const Identifier &id)
Definition: CgemID.cxx:64
std::ofstream ofstream
Definition: bpkt_streams.h:42

◆ finalize()

StatusCode CgemSimCheck::finalize ( )

Definition at line 461 of file CgemSimCheck.cxx.

462{
463 MsgStream log(msgSvc(), name());
464 log << MSG::INFO << "in finalize()" << endreq;
465
466 return StatusCode::SUCCESS;
467}

◆ initialize()

StatusCode CgemSimCheck::initialize ( )

Definition at line 147 of file CgemSimCheck.cxx.

148{
149 MsgStream log(msgSvc(), name());
150 log << MSG::INFO << "in initialize()" << endreq;
151
152 StatusCode sc;
153 ICgemGeomSvc* ISvcCgem;
154 sc = service("CgemGeomSvc", ISvcCgem);
155 if(sc != StatusCode::SUCCESS)
156 {
157 log << MSG::ERROR << "can not use CgemGeomSvc" << endreq;
158 return StatusCode::FAILURE;
159 }
160
161 // ofstream outoneevt("evtput.txt");
162
163 int postfixlen = m_postfix.length();
164 char *foldername = (char *)malloc((postfixlen + 6) * sizeof(char));
165
166 INTupleSvc* ntupleSvc;
167 sc = service("NTupleSvc", ntupleSvc);
168
169 free(foldername);
170 foldername = (char *)malloc((postfixlen + 12) * sizeof(char));
171 sprintf(foldername, "FILE135/Digi%s", m_postfix.c_str());
172 NTuplePtr nt(ntupleSvc, foldername);
173 if ( nt ) m_tuple = nt;
174 else{
175 m_tuple = ntupleSvc->book(foldername, CLID_ColumnWiseTuple, "mdcTrack");
176 if(m_tuple){
177 m_tuple->addItem("run", m_run);
178 m_tuple->addItem("evt", m_evt);
179 m_tuple->addItem("nhit", m_nHit, 0, 100000);
180 m_tuple->addItem("X_nstrip", m_Xnstrip,0,30000);
181 m_tuple->addItem("V_nstrip", m_Vnstrip,0,30000);
182
183 m_tuple->addIndexedItem("hittrackID",m_nHit, m_ID_track);
184 m_tuple->addIndexedItem("CgemlayerID",m_nHit, m_ID_layer);
185 m_tuple->addIndexedItem("Readout_sheetID", m_nHit,m_ID_sheet);
186 // m_tuple->addIndexedItem("X_stripID", m_nHit,m_X_ID_strip);
187 // m_tuple->addIndexedItem("V_stripID", m_nHit,m_V_ID_strip);
188 m_tuple->addIndexedItem("Read_stripID", m_nHit,m_ID_strip);
189 m_tuple->addIndexedItem("Deposit_Energy", m_nHit,m_E_deposit);
190 m_tuple->addIndexedItem("Ex", m_Xnstrip,m_E_X);
191 m_tuple->addIndexedItem("Ev", m_Vnstrip,m_E_V);
192 m_tuple->addIndexedItem("Globletime", m_nHit,m_globle_time);
193 }
194 }
195
196
197 free(foldername);
198 foldername = (char *)malloc((postfixlen + 12) * sizeof(char));
199 sprintf(foldername, "FILE135/McTruth%s", m_postfix.c_str());
200 NTuplePtr nt1(ntupleSvc, foldername);
201 if ( nt1 ) mc_tuple = nt1;
202 else{
203 mc_tuple = ntupleSvc->book(foldername, CLID_ColumnWiseTuple, "mdcTrack");
204 if(mc_tuple){
205 // mc_tuple->addItem("run", m_run);
206 // mc_tuple->addItem("evt", m_evt);
207 mc_tuple->addItem("MC_nhit", m_mc_nHit, 0, 100);
208
209 mc_tuple->addIndexedItem("hittrackID",m_mc_nHit, m_mc_ID_track);
210 mc_tuple->addIndexedItem("CgemlayerID",m_mc_nHit, m_mc_ID_layer);
211 mc_tuple->addIndexedItem("Deposit_Energy", m_mc_nHit,m_mc_E_deposit);
212 mc_tuple->addIndexedItem("X_pre_point", m_mc_nHit, m_mc_XYZ_pre_X );
213 mc_tuple->addIndexedItem("Y_pre_point", m_mc_nHit, m_mc_XYZ_pre_Y );
214 mc_tuple->addIndexedItem("Z_pre_point", m_mc_nHit, m_mc_XYZ_pre_Z );
215 mc_tuple->addIndexedItem("X_post_point", m_mc_nHit, m_mc_XYZ_post_X );
216 mc_tuple->addIndexedItem("Y_post_point", m_mc_nHit, m_mc_XYZ_post_Y );
217 mc_tuple->addIndexedItem("Z_post_point", m_mc_nHit, m_mc_XYZ_post_Z );
218 mc_tuple->addIndexedItem("P_X_pre_point", m_mc_nHit, m_mc_P_pre_X);
219 mc_tuple->addIndexedItem("P_Y_pre_point", m_mc_nHit, m_mc_P_pre_Y);
220 mc_tuple->addIndexedItem("P_Z_pre_point", m_mc_nHit, m_mc_P_pre_Z);
221 mc_tuple->addIndexedItem("P_X_post_point",m_mc_nHit, m_mc_P_post_X);
222 mc_tuple->addIndexedItem("P_Y_post_point",m_mc_nHit, m_mc_P_post_Y);
223 mc_tuple->addIndexedItem("P_Z_post_point",m_mc_nHit, m_mc_P_post_Z);
224 }
225 }
226
227 free(foldername);
228 foldername = (char *)malloc((postfixlen + 12) * sizeof(char));
229 sprintf(foldername, "FILE135/McPar%s", m_postfix.c_str());
230 NTuplePtr nt2(ntupleSvc, foldername);
231 if ( nt2 ) mcP_tuple = nt2;
232 else{
233 mcP_tuple = ntupleSvc->book(foldername, CLID_ColumnWiseTuple, "mdcTrack");
234 if(mcP_tuple){
235 // mcP_tuple->addItem("run", m_run);
236 // mcP_tuple->addItem("evt", m_evt);
237 mcP_tuple->addItem("nParticle", Nparticle, 0, 1000);
238
239 mcP_tuple->addIndexedItem("trkindex", Nparticle, m_trkindex);
240 mcP_tuple->addIndexedItem("x", Nparticle, m_mcParticle_x);
241 mcP_tuple->addIndexedItem("y", Nparticle, m_mcParticle_y);
242 mcP_tuple->addIndexedItem("z", Nparticle, m_mcParticle_z);
243 mcP_tuple->addIndexedItem("px", Nparticle, m_mcParticle_px);
244 mcP_tuple->addIndexedItem("py", Nparticle, m_mcParticle_py);
245 mcP_tuple->addIndexedItem("pz", Nparticle, m_mcParticle_pz);
246 mcP_tuple->addIndexedItem("E", Nparticle, m_mcParticle_E);
247 mcP_tuple->addIndexedItem("phi", Nparticle, m_mcParticle_phi);
248 mcP_tuple->addIndexedItem("costheta", Nparticle, m_mcParticle_costheta);
249 mcP_tuple->addIndexedItem("theta", Nparticle, m_mcParticle_theta);
250 mcP_tuple->addIndexedItem("pt", Nparticle, m_mcParticle_pt);
251 }
252 }
253 return StatusCode::SUCCESS;
254}
INTupleSvc * ntupleSvc()

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