00001 #include "PrintMcInfo/PrintMcInfo.h"
00002 using namespace std;
00003
00004 void PrintMcInfo::mkmap()
00005 {
00006 string str,str1,str2,str3,str4;
00007 int id;
00008
00009 char* pdt_path=getenv("BESEVTGENROOT");
00010 if(0 == pdt_path)
00011 std::cerr<<"ERROR : Can't get env $BESEVTGENROOT"<<std::endl;
00012 std::string pdtname=std::string(pdt_path) + "/share/pdt.table";
00013 ifstream fin(pdtname.c_str());
00014
00015 while(getline(fin,str))
00016 {
00017 fin>>str;
00018 if(str == "add")
00019 {
00020 fin>>str1>>str2>>str3>>str4;
00021 id = atoi(str4.c_str());
00022 map_pid.insert(map<int, string>::value_type(id,str3));
00023 }
00024 }
00025 }
00026
00027 void PrintMcInfo::printTitle(ofstream& os,int m_OutputLevel)
00028 {
00029 if(m_OutputLevel==1)
00030 {
00031 os.setf(ios::left);
00032 os<<" "<<setw(27)<<"cosTeta phi"<<setw(50)<<"P4 : momentum Energy"
00033 <<setw(10)<<" "<<setw(40)<<"initialPosition"
00034 <<setw(15)<<"finalPosition"<<endl;
00035 os.setf(ios::left);
00036 for (int m = 0; m < 29; m++) {os<< " ";}
00037 os<<"Px, Py, Pz , E (Gev)";
00038 for (int m = 0; m < 35; m++) {os<< " ";}
00039 os<<"x(cm) y(cm) z(cm)";
00040 for (int m = 0; m < 25; m++) {os<< " ";}
00041 os <<"x(cm) y(cm) z(cm)"<<endl;
00042 }
00043
00044
00045
00046
00047
00048
00049
00050 }
00051
00052
00053
00054
00055 void PrintMcInfo::printTree(ofstream& os,Event::McParticle* pmcp,int m_OutputLevel,int tab=0)
00056 {
00057 bool decay = (pmcp->daughterList()).size()==0?false:true;
00058 if(decay)
00059 {
00060 for (int m = 0; m < tab; m++) {os<< '\t';}
00061
00062 m_pid = (*pmcp).particleProperty();
00063 m_trkIndex = (*pmcp).trackIndex();
00064 map<int,string>::iterator iterPar;
00065 iterPar = map_pid.find(m_pid);
00066 if (iterPar!=map_pid.end())
00067 os<<iterPar->second<<"["<<m_trkIndex<<"]"<<" "<<"->";
00068
00069
00070 SmartRefVector<Event::McParticle>::const_iterator begin = (pmcp->daughterList()).begin();
00071 SmartRefVector<Event::McParticle>::const_iterator end = (pmcp->daughterList()).end();
00072 SmartRefVector<Event::McParticle>::const_iterator it;
00073 for(it = begin;it != end;it++)
00074 {
00075 m_trkIndex = (*it)->trackIndex();
00076 map<int,string>::iterator iter;
00077 iter = map_pid.find((*it)->particleProperty());
00078 if(iter!=map_pid.end())
00079 {
00080 daughters = iter->second;
00081 m_trkIndex = (*it)->trackIndex();
00082 os.setf(ios::left);
00083 os<<daughters<<"["<<m_trkIndex<<"]"<<" ";
00084 daughters.erase();
00085 }
00086 else
00087 cout<<"can not find the daughter particle in pdt_table"<<endl;
00088 }
00089 os<<endl;
00090
00091 for(it = begin;it != end;it++)
00092 {
00093 SmartRef<Event::McParticle> pdMc = (*it);
00094 printTree(os,pdMc,m_OutputLevel,tab+1);
00095 }
00096 }
00097 if((!decay)&&(pmcp->primaryParticle()))
00098 {
00099 m_pid = (*pmcp).particleProperty();
00100 map<int,string>::iterator iterPar;
00101 iterPar = map_pid.find(m_pid);
00102 if (iterPar!=map_pid.end())
00103 os<<endl
00104 <<"********************************************************"<<endl
00105 <<" in this tree, there's only one primary particle : "<<iterPar->second<<endl
00106 <<"********************************************************"<<endl;
00107 }
00108 }
00109
00110
00111
00112
00113 void PrintMcInfo::printPartInf(ofstream& os,Event::McParticle* pMc,int m_OutputLevel,int tab=0)
00114 {
00115 bool decay = (pMc->daughterList()).size()==0?false:true;
00116
00117 SmartDataPtr<Event::MdcMcHitCol> mdcMcHitCol(eventSvc(), "/Event/MC/MdcMcHitCol");
00118 SmartDataPtr<Event::TofMcHitCol> tofMcHitCol(eventSvc(), "/Event/MC/TofMcHitCol");
00119 SmartDataPtr<Event::EmcMcHitCol> emcMcHitCol(eventSvc(), "/Event/MC/EmcMcHitCol");
00120 SmartDataPtr<Event::MucMcHitCol> mucMcHitCol(eventSvc(), "/Event/MC/MucMcHitCol");
00121
00122 if((!decay)&&(pMc->primaryParticle()))
00123 {
00124 os.setf(ios::left);
00125 map<int,string>::iterator iter_map;
00126 iter_map = map_pid.find(pMc->particleProperty());
00127 if(iter_map!=map_pid.end())
00128 {
00129 if(m_OutputLevel==1)
00130 {
00131 string name = iter_map->second;
00132 os<<"["<<pMc->trackIndex()<<"]"<<name<<endl;
00133 HepLorentzVector p4 = (pMc)->initialFourMomentum();
00134 os<<" "<<"["<<setw(12)<<p4.vect().cosTheta()<<setw(12)<<p4.vect().phi()<<"] ";
00135 os<<"["<<setw(12)<<p4.x()<<setw(12)<<p4.y()
00136 <<setw(12)<<p4.z()<<" "<<setw(10)<<p4.t()<<"] ";
00137
00138 HepLorentzVector ipst = pMc->initialPosition();
00139 os<<"["<<setw(12)<<ipst.x();
00140 os<<setw(12)<<ipst.y();
00141 os<<setw(10)<<ipst.z()<<"] ";
00142
00143 HepLorentzVector fpst = (pMc)->finalPosition();
00144 os<<"["<<setw(12)<<fpst.x();
00145 os<<setw(12)<<fpst.y();
00146 os<<setw(10)<<fpst.z()<<"] ";
00147 os<<endl;
00148 }
00149 if(m_OutputLevel==2)
00150 {
00151 int trkIdx = pMc->trackIndex();
00152 PrintMcInfo::printHit(os,mdcMcHitCol,tofMcHitCol,emcMcHitCol,mucMcHitCol,trkIdx);
00153 }
00154
00155 }
00156 }
00157 if(decay)
00158 {
00159 SmartRefVector<Event::McParticle>::const_iterator begin = (pMc->daughterList()).begin();
00160 SmartRefVector<Event::McParticle>::const_iterator end = (pMc->daughterList()).end();
00161 SmartRefVector<Event::McParticle>::const_iterator it;
00162 for(it = begin;it != end;it++)
00163 {
00164 m_trkIndex = (*it)->trackIndex();
00165 map<int,string>::iterator iter;
00166 iter = map_pid.find((*it)->particleProperty());
00167 if(iter!=map_pid.end())
00168 {
00169 daughters = iter->second;
00170 if(m_OutputLevel ==1)
00171 {
00172 os.setf(ios::left);
00173 os<<"["<<m_trkIndex<<"]"<<setw(20)<<daughters<<endl;
00174
00175 HepLorentzVector p4 = (*it)->initialFourMomentum();
00176 os<<" "<<"["<<setw(12)<<p4.vect().cosTheta()<<setw(12)<<p4.vect().phi()<<"] ";
00177 os<<"["<<setw(12)<<p4.x()<<setw(12)<<p4.y()
00178 <<setw(12)<<p4.z()<<" "<<setw(10)<<p4.t()<<"] ";
00179
00180
00181 HepLorentzVector ipst = (*it)->initialPosition();
00182 os<<"["<<setw(12)<<ipst.x();
00183 os<<setw(12)<<ipst.y();
00184 os<<setw(10)<<ipst.z()<<"] ";
00185
00186
00187
00188 HepLorentzVector fpst = (*it)->finalPosition();
00189 os<<"["<<setw(12)<<fpst.x();
00190 os<<setw(12)<<fpst.y();
00191 os<<setw(10)<<fpst.z()<<"] ";
00192
00193 }
00194 if(m_OutputLevel==2)
00195 {
00196 if(((*mdcMcHitCol).size()==0&&(*tofMcHitCol).size()==0&&(*emcMcHitCol).size()==0&&(*mucMcHitCol).size()==0)&&tab==0)
00197 os<<" --------------------------------------------------------"<<endl
00198 <<" mdcMcHitCol,tofMcHitCol,emcMcHitCol,mucMcHitCol all empty"<<endl
00199 <<" --------------------------------------------------------"<<endl;
00200 if(!((*mdcMcHitCol).size()==0&&(*tofMcHitCol).size()==0&&(*emcMcHitCol).size()==0&&(*mucMcHitCol).size()==0))
00201
00202 {
00203 os.setf(ios::left);
00204 os<<"["<<m_trkIndex<<"]"<<setw(12)<<daughters<<endl;
00205 }
00206
00207 int trkIdx = (*it)->trackIndex();
00208 PrintMcInfo::printHit(os,mdcMcHitCol,tofMcHitCol,emcMcHitCol,mucMcHitCol,trkIdx);
00209 }
00210 os<<endl;
00211 }
00212 else cout<<"can not find the daughter particle in pdt_table"<<endl;
00213 }
00214 daughters.erase();
00215
00216 for(it = begin;it != end;it++)
00217 {
00218 SmartRef<Event::McParticle> pdMc = (*it);
00219 printPartInf(os,pdMc,m_OutputLevel,tab+1);
00220 }
00221 }
00222 }
00223
00224
00225
00226 void PrintMcInfo::printHit(ofstream& os,Event::MdcMcHitCol& mdcCol,Event::TofMcHitCol& tofCol,Event::EmcMcHitCol& emcCol,Event::MucMcHitCol& mucCol,int& trk_Idx)
00227 {
00228 if(!(mdcCol.size()==0&&tofCol.size()==0&&emcCol.size()==0&&mucCol.size()==0))
00229 {
00230 os<< '\t' <<setw(66)<<"MdcHit"
00231 <<setw(25)<<"TofHit"
00232 <<setw(17)<<"EmcHit"
00233 <<"MucHit"<<endl;
00234 os<< '\t' <<"(layer, wire, position(x,y,z)(mm) ,drift_d(mm), DeDx(MeV/m))"<<" "<<"(B/EC layer phi_module)"<<" "<<"(B/EC theta phi)"<<" "<<"(B/EC segment layer strip)"<<endl;
00235 }
00236 Event::MdcMcHitCol::const_iterator it_mdc = mdcCol.begin();
00237 Event::TofMcHitCol::const_iterator it_tof = tofCol.begin();
00238 Event::EmcMcHitCol::const_iterator it_emc = emcCol.begin();
00239 Event::MucMcHitCol::const_iterator it_muc = mucCol.begin();
00240 vector<Event::MdcMcHitCol::const_iterator> vmdc;
00241 vector<Event::TofMcHitCol::const_iterator> vtof;
00242 vector<Event::EmcMcHitCol::const_iterator> vemc;
00243 vector<Event::MucMcHitCol::const_iterator> vmuc;
00244 if(mdcCol.size() != 0)
00245 {
00246 for(;it_mdc != mdcCol.end();it_mdc++)
00247 {
00248 int trkIndexmdc = (*it_mdc)->getTrackIndex();
00249 if(trkIndexmdc == trk_Idx)
00250 {
00251 vmdc.push_back(it_mdc);
00252 }
00253 }
00254 }
00255 if(tofCol.size() != 0)
00256 {
00257 for(;it_tof != tofCol.end();it_tof++)
00258 {
00259 int trkIndextof = (*it_tof)->getTrackIndex();
00260 if(trkIndextof==trk_Idx) vtof.push_back(it_tof);
00261 }
00262 }
00263
00264 if(emcCol.size() != 0)
00265 {
00266 for(;it_emc != emcCol.end();it_emc++)
00267 {
00268 int trkIndexemc = (*it_emc)->getTrackIndex();
00269 if(trkIndexemc==trk_Idx) vemc.push_back(it_emc);
00270 }
00271 }
00272
00273 if(mucCol.size() != 0)
00274 {
00275 for(;it_muc != mucCol.end();it_muc++)
00276 {
00277 int trkIndexmuc = (*it_muc)->getTrackIndex();
00278 if(trkIndexmuc==trk_Idx) vmuc.push_back(it_muc);
00279 }
00280 }
00281
00282
00283 for(int i=0;;i++)
00284 {
00285 bool bmdc=(i>vmdc.size())?true:false;
00286 bool btof=(i>vtof.size())?true:false;
00287 bool bemc=(i>vemc.size())?true:false;
00288 bool bmuc=(i>vmuc.size())?true:false;
00289 if((i>=vmdc.size())&&(i>=vtof.size())&&(i>=vemc.size())&&(i>=vmuc.size())) break;
00290 os<< '\t' ;
00291 if(vmdc.size()>0)
00292 {
00293 if(i<vmdc.size())
00294 {
00295 const Identifier ident_mdc = (*vmdc[i])->identify();
00296 os<<setw(5)<<MdcID::layer(ident_mdc);
00297 os<<setw(5)<<MdcID::wire(ident_mdc);
00298 os<<"[ ";
00299 os<<setw(10)<<(*vmdc[i])->getPositionX();
00300 os<<setw(10)<<(*vmdc[i])->getPositionY();
00301 os<<setw(10)<<(*vmdc[i])->getPositionZ();
00302 os<<"] ";
00303 os<<setw(10)<<(*vmdc[i])->getDriftDistance();
00304 os<<setw(10)<<(*vmdc[i])->getDepositEnergy();
00305 }else{for (int m = 0; m < 64; m++) os<<" ";}
00306 }else{for (int m = 0; m < 64; m++) os<<" ";}
00307
00308
00309 if(vtof.size()>0)
00310 {
00311 if(i<vtof.size())
00312 {
00313 const Identifier ident_tof =(*vtof[i])->identify();
00314 if(TofID::barrel_ec(ident_tof)==1){os<<"B "<<" ";}
00315 if(TofID::barrel_ec(ident_tof)==0){os<<"E_E"<<" ";}
00316 if(TofID::barrel_ec(ident_tof)==2){os<<"W_E"<<" ";}
00317 os<<setw(3)<<TofID::layer(ident_tof);
00318 os<<setw(17)<<TofID::phi_module(ident_tof);
00319 }else{for (int m = 0; m < 25; m++) os<<" ";}
00320 }else{for (int m = 0; m < 25; m++) os<<" ";}
00321
00322
00323 if(vemc.size()>0)
00324 {
00325 if(i<vemc.size())
00326 {
00327 const Identifier ident_emc = (*vemc[i])->identify();
00328 if(EmcID::barrel_ec(ident_emc)==1){os<<"B "<<" ";}
00329 if(EmcID::barrel_ec(ident_emc)==0){os<<"E_E"<<" ";}
00330 if(EmcID::barrel_ec(ident_emc)==2){os<<"W_E"<<" ";}
00331 os<<setw(5)<<EmcID::theta_module(ident_emc);
00332 os<<setw(9)<<EmcID::phi_module(ident_emc);
00333 }else{for (int m = 0; m < 19; m++) os<<" ";}
00334 }else{for (int m = 0; m < 19; m++) os<<" ";}
00335
00336 if(vmuc.size()>0)
00337 {
00338 if(i<vmuc.size())
00339 {
00340 const Identifier ident_muc = (*vmuc[i])->identify();
00341 if(MucID::barrel_ec(ident_muc)==1){os<<"B "<<" ";}
00342 if(MucID::barrel_ec(ident_muc)==0){os<<"E_E"<<" ";}
00343 if(MucID::barrel_ec(ident_muc)==2){os<<"W_E"<<" ";}
00344 os<<setw(3)<<MucID::segment(ident_muc);
00345 os<<setw(3)<<MucID::layer(ident_muc);
00346 os<<setw(4)<<MucID::strip(ident_muc);
00347 os<<endl;
00348 }else{ os<<endl;}
00349 }else{os<<endl;}
00350
00351
00352
00353 }
00354 vmdc.clear();
00355 vtof.clear();
00356 vemc.clear();
00357 vmuc.clear();
00358
00359 }
00360