/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Event/EventTag/EventTag-00-01-07/src/EventTagSvc.cxx

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 #include <sstream>
00004 #include <cstdio>
00005 #include <cstdlib>
00006 #include <climits>
00007 #include <algorithm>
00008 
00009 #include "EventTag/EventTagSvc.h"
00010 
00011 #ifndef BEAN
00012 #include "GaudiKernel/MsgStream.h"
00013 #include "GaudiKernel/SmartDataPtr.h"
00014 #endif
00015 
00016 using namespace std;
00017 
00018 #ifndef BEAN
00019 bool mcPartPrtLess( Event::McParticle* p1, Event::McParticle* p2){
00020 return p1->particleProperty()<p2->particleProperty();}
00021  
00022 EventTagSvc::EventTagSvc(const std::string& name, ISvcLocator* svc ) :
00023   Service(name,svc)
00024 {
00025 
00026   declareProperty("pdgFile", m_pdtFile="pdt.table");
00027   declareProperty("decayCodesFile", m_decayTabsFile="decay.codes");
00028   //  declareProperty("userDecayCodesFile", 
00029   //                            m_userDecayTabsFile="userdecay.codes");
00030   declareProperty("userDecayCodesFile", m_userDecayTabsFile="");
00031   declareProperty("buildAntiPartTable", m_buildAntiTabs=true);
00032   declareProperty("ignorePhotons", m_ignorePhotons=true);
00033   declareProperty("ignoreFSR", m_ignoreFSR=true);
00034   declareProperty("chainTrigParticles", userChainTrig);
00035   declareProperty("digK0", m_digK0=true);
00036 }
00037 #else  // BEAN
00038 EventTagSvc* EventTagSvc::m_evtag = 0;
00039 
00040 bool mcPartPrtLess (TMcParticle * p1, TMcParticle * p2) {
00041    return p1->getParticleID () < p2->getParticleID ();
00042 }
00043 
00044 EventTagSvc::EventTagSvc () {
00045    m_pdtFile = "Analysis/EventTag/share/pdt.table";
00046    m_decayTabsFile = "Analysis/EventTag/share/decay.codes";
00047 
00048    m_userDecayTabsFile = "";
00049    m_buildAntiTabs = true;
00050    m_ignorePhotons = true;
00051    m_ignoreFSR = true;
00052    m_digK0 = true;
00053    verbose = 0;
00054 }
00055 #endif
00056 
00057 
00058 StatusCode EventTagSvc::initialize(){
00059 #ifndef BEAN
00060   Service::initialize();
00061   MsgStream log(msgSvc(), name());
00062 
00063   setProperties();
00064   log << MSG::INFO << "EventTagSvc initialize()" << endreq;
00065   log << MSG::INFO << "         pdgFile="<<m_pdtFile<<endreq;
00066   log << MSG::INFO << "         decayCodesFile="<<m_decayTabsFile<<endreq;
00067   log << MSG::INFO << "         userDecayTabsFile="<<m_userDecayTabsFile
00068       <<endreq;
00069   log << MSG::INFO << "         buildAntiPartTable="<<m_buildAntiTabs<<endreq;
00070   log << MSG::INFO << "         Ignore Photons="<<m_ignorePhotons<<endreq;
00071   log << MSG::INFO << " Chain trigger particles:"<<endreq; 
00072   for(std::vector<string>::iterator it=userChainTrig.begin();
00073    it!=userChainTrig.end();it++){
00074     log << MSG::INFO<<"                         " <<(*it)<<endreq;
00075   }
00076 #else
00077    if( verbose ) {
00078       cout << "EventTagSvc initialize()" << endl;
00079       cout << "         pdgFile=" << m_pdtFile << endl;
00080       cout << "         decayCodesFile=" << m_decayTabsFile << endl;
00081       cout << "         userDecayTabsFile=" << m_userDecayTabsFile << endl;
00082       cout << "         buildAntiPartTable=" << m_buildAntiTabs << endl;
00083       cout << "         Ignore Photons=" << m_ignorePhotons << endl;
00084       cout << " Chain trigger particles:" << endl;
00085 
00086       for (std::vector < string >::iterator it = userChainTrig.begin ();
00087         it != userChainTrig.end (); it++) {
00088          cout << "                         " << (*it) << endl;
00089       }
00090    }
00091 #endif
00092 
00093   //  static const bool CREATEIFNOTTHERE(true);
00094   if(readPdtFile(m_pdtFile.c_str())){
00095 #ifndef BEAN
00096     log << MSG::ERROR<<"Can not read pdgFile "<< m_pdtFile<<endreq;
00097     return StatusCode::StatusCode::FAILURE;
00098 #else
00099     cerr << "Can not read pdgFile " << m_pdtFile << endl;
00100     return false;
00101 #endif
00102   }
00103 
00104   if(readDecayTabFile(m_decayTabsFile)){
00105 #ifndef BEAN
00106     log << MSG::ERROR<<"Can not read decayTabsFile "<< m_decayTabsFile<<endreq;
00107     return StatusCode::StatusCode::FAILURE;
00108 #else
00109     cerr << "Can not read decayTabsFile " << m_decayTabsFile << endl;
00110     return false;
00111 #endif
00112   }
00113 
00114   if(m_userDecayTabsFile.size()){
00115     if(readDecayTabFile(m_userDecayTabsFile)){
00116 #ifndef BEAN
00117       log << MSG::ERROR<<"Can not read userDecayTabsFile "<<m_userDecayTabsFile
00118           <<endreq;
00119       return StatusCode::StatusCode::FAILURE;
00120 #else
00121       cerr << "Can not read userDecayTabsFile " << m_userDecayTabsFile << endl;
00122       return false;
00123 #endif
00124     }
00125   }
00126 
00127   if(m_buildAntiTabs){
00128     if(buildAntiPartTabs()){
00129 #ifndef BEAN
00130       log << MSG::ERROR<<"fail to build decay code table for anti-particles"
00131           <<endreq;
00132       return StatusCode::StatusCode::FAILURE;
00133 #else
00134       cerr << "fail to build decay code table for anti-particles" << endl;
00135       return false;
00136 #endif
00137     }
00138   }
00139   
00140   // fill the set with trigger chain particles
00141   for(std::vector<string>::iterator it=userChainTrig.begin();
00142    it!=userChainTrig.end();it++){
00143     long int pdg=labs(name2pdg(*it));
00144     if(pdg==0){
00145 #ifndef BEAN
00146       log << MSG::ERROR<<"Unknown ChainTrigger particle "<< (*it)
00147           <<" ..ignoring"<<endreq;
00148 #else
00149       cerr << "Unknown ChainTrigger particle " << (*it) 
00150            <<  " ..ignoring" << endl;
00151 #endif
00152       continue;
00153     }
00154     chainTrigParticles.insert(pdg);
00155   }
00156 
00157 #ifndef BEAN
00158   log << MSG::DEBUG << "sorted chain trigger particles:"<<endreq; 
00159   for(set<long int>::iterator it=chainTrigParticles.begin();
00160    it!=chainTrigParticles.end();it++){
00161     log << MSG::DEBUG<<"                         "<<(*it)<<"  " 
00162         <<pdg2name(*it)<<endreq;
00163   }
00164 #else
00165    if (verbose) {
00166       cout << "sorted chain trigger particles:" << endl;
00167       for (set < long int >::iterator it = chainTrigParticles.begin ();
00168         it != chainTrigParticles.end (); it++) {
00169          cout << "                         " << (*it) << "  " 
00170               << pdg2name(*it) << endl;
00171       }
00172    }
00173 #endif
00174 
00175 
00176 #ifndef BEAN
00177   return StatusCode::SUCCESS;
00178 #else
00179   return true;
00180 #endif
00181 }
00182   
00183 #ifndef BEAN
00184 StatusCode EventTagSvc::finalize() {
00185   // Part 1: Get the messaging service, print where you are
00186   MsgStream log(msgSvc(), name());
00187   log << MSG::INFO << "EventTagSvc finalize()" << endreq;
00188   return StatusCode::SUCCESS;
00189 }
00190 
00191 StatusCode 
00192 EventTagSvc::queryInterface(const InterfaceID& riid, void** ppvInterface) {
00193   if ( IEventTagSvc::interfaceID().versionMatch(riid) )    {
00194     *ppvInterface = (IEventTagSvc*)this;
00195   }
00196   else  {
00197     // Interface is not directly available: try out a base class
00198     return Service::queryInterface(riid, ppvInterface);
00199   }
00200   addRef();
00201   return StatusCode::SUCCESS;
00202 }
00203 #endif
00204 
00205 
00206 
00207 string EventTagSvc::pdg2name(long int pdg){
00208   map<long int,string>::iterator it=pdg2nameTab.find(pdg);
00209   if(it!=pdg2nameTab.end())return it->second;
00210   return string("");
00211 }
00212 
00213 long int EventTagSvc::name2pdg(string pname){
00214   map<string,long int>::iterator it=name2pdgTab.find(pname);
00215   if(it!=name2pdgTab.end())return it->second;
00216   return 0;
00217 }
00218 
00219 
00220 int EventTagSvc::readPdtFile(string fname){
00221 #ifndef BEAN
00222   MsgStream log(msgSvc(), name());
00223 #endif
00224   ifstream infile;
00225   infile.open(fname.c_str());
00226   if(!infile.is_open()){
00227 #ifndef BEAN
00228     log<<MSG::ERROR<< "Can not open pdg-code file :" <<fname<<endreq;
00229 #else
00230     cerr << "Can not open pdg-code file :" << fname << endl;
00231 #endif
00232     return 1;
00233   }
00234 #ifndef BEAN
00235   log<<MSG::INFO<<"reading pdg codes table from "<<fname<<endreq; 
00236 #else
00237   if (verbose)
00238       cout << "reading pdg codes table from " << fname << endl;
00239 #endif
00240   string ln;
00241   int nstr=0;
00242   long int pcode;
00243   string cmd,dummy,pname,pcode_str;
00244   stringstream* lns;
00245   while (! infile.eof() ){
00246     getline (infile,ln);
00247     nstr++;
00248 #ifndef BEAN
00249     log<<MSG::DEBUG<<"parsing line:"<<ln<<endreq;
00250 #else
00251     if (verbose) 
00252       cout << "parsing line:" << ln << endl;
00253 #endif
00254     if(ln.empty())continue;
00255     if(ln[0]=='*')continue;
00256     lns=new stringstream;
00257     (*lns)<<ln;
00258     cmd="";
00259     (*lns)>>cmd;
00260     if(!strcmp(cmd.c_str(),"add")){
00261       pcode=0;
00262       pname="";
00263       pcode_str="";
00264       (*lns)>>dummy>>dummy>>pname>>pcode_str;
00265       pcode=atol(pcode_str.c_str());
00266       if(pcode==0||pcode==LONG_MAX||pcode==LONG_MIN){
00267 #ifndef BEAN
00268         log<<MSG::ERROR<<"Unrecognized particle code in line "
00269            <<nstr<<"  of file" <<fname<<endreq;
00270 #else
00271         cerr << "Unrecognized particle code in line "
00272              << nstr << "  of file" << fname << endl;
00273 #endif
00274         infile.close();
00275         return 1;
00276       }
00277 #ifndef BEAN
00278       log<<MSG::DEBUG<<" find particle: " <<pname<<" pgd:"<<pcode <<endreq;
00279 #else
00280       if (verbose)
00281         cout << " find particle: " << pname << " pgd:" << pcode << endl;
00282 #endif
00283       if(pdg2nameTab.find(pcode)!=pdg2nameTab.end()){
00284 #ifndef BEAN
00285         log<<MSG::ERROR<< "pdg code "<<pcode
00286            <<" is repeated in line "<<nstr<<". Aborting"<<endreq;
00287 #else
00288         cerr << "pdg code " << pcode
00289              << " is repeated in line " << nstr << ". Aborting" << endl;
00290 #endif
00291         infile.close();
00292         return 1;
00293       }
00294       if(name2pdgTab.find(pname)!=name2pdgTab.end()){
00295 #ifndef BEAN
00296         log<<MSG::ERROR<< "particle name "<<pcode
00297            <<" is repeated in line "<<nstr<<". Aborting"<<endreq;
00298 #else
00299         cerr << "particle name " << pcode
00300              << " is repeated in line " << nstr << ". Aborting" << endl;
00301 #endif
00302         infile.close();
00303         return 1;
00304       }
00305       pdg2nameTab[pcode]=pname;
00306       name2pdgTab[pname]=pcode;
00307     }
00308     delete lns;
00309   }
00310   infile.close();
00311   return 0;
00312 }
00313 
00314 
00315 int EventTagSvc::readDecayTabFile(string fname){
00316 #ifndef BEAN
00317   MsgStream log(msgSvc(), name());
00318 #endif
00319   ifstream infile;
00320   infile.open(fname.c_str());
00321   if(!infile.is_open()){
00322 #ifndef BEAN
00323     log<<MSG::ERROR<< "Can not open decay table file :" <<fname<<endreq;
00324 #else
00325     cerr << "Can not open decay table file :" << fname << endl;
00326 #endif
00327     infile.close();
00328     return 1;
00329   }
00330 #ifndef BEAN
00331   log<<MSG::INFO<<"Reading decay codes from file " << fname<<endreq;  
00332 #else
00333   if (verbose)
00334     cout << "Reading decay codes from file " << fname << endl;
00335 #endif
00336   string ln;
00337   long int pdg,mo_pdg;
00338   int dcode;
00339   int nstr=0;
00340   char* pch;
00341   char str[256],mother[256];
00342   char whitespaces[]=" \t\f\v\n\r";
00343   while (! infile.eof() ){
00344     getline (infile,ln);
00345     nstr++;
00346     if(ln.empty())continue;
00347     if(ln[0]=='#'||ln[0]=='*')continue;
00348     if(ln.size()>255){
00349 #ifndef BEAN
00350       log<<MSG::ERROR<<"line "<< nstr <<"in " 
00351          <<fname<<" is too big" <<endreq;
00352 #else
00353       cerr << "line " << nstr << "in " << fname << " is too big" << endl;
00354 #endif
00355       infile.close();
00356       return 1;
00357     }
00358     strcpy(str,ln.c_str());
00359     pch = strtok (str,whitespaces);
00360     if(pch==NULL)continue;
00361     if(strcmp(pch,"Decay")!=0){
00362 #ifndef BEAN
00363       log<<MSG::ERROR<<"No open  decay, unrecognized token in line "
00364          <<nstr <<" of " <<fname<<endreq;
00365 #else
00366       cerr << "No open  decay, unrecognized token in line "
00367            << nstr << " of " << fname << endl;
00368 #endif
00369       infile.close();
00370       return 1;
00371     }
00372     pch = strtok (NULL, whitespaces);
00373     if(pch==NULL) {
00374 #ifndef BEAN
00375       log<<MSG::ERROR<< "Can not find  particles in line "
00376          << nstr <<" of " <<fname<<endreq;
00377 #else
00378       cerr << "Can not find  particles in line "
00379            << nstr << " of " << fname << endl;
00380 #endif
00381       infile.close();
00382       return 1;
00383     }
00384     mo_pdg=name2pdg(string(pch));
00385     strcpy(mother,pch);
00386     if(mo_pdg==0){
00387 #ifndef BEAN
00388       log<<MSG::ERROR<< "Unrecognized  particle "<<pch<<" in line " << nstr
00389          <<" of " <<fname<<endreq;
00390 #else
00391       cerr << "Unrecognized  particle " << pch << " in line " << nstr
00392            << " of " << fname << endl;
00393 #endif
00394       infile.close();
00395       return 1;
00396     }
00397 #ifndef BEAN
00398     log<<MSG::INFO<<"START DECAY TABLE FOR " << mother<<", pdg_code:"
00399        <<mo_pdg<<endl; 
00400 #else
00401     cout << "START DECAY TABLE FOR " << mother << ", pdg_code:" 
00402          << mo_pdg << endl;
00403 #endif
00404     decayModeTab* dTab;
00405     map<int,decayModeTab*>::iterator itlist=m_decayTabList.find(mo_pdg);
00406     if(itlist!=m_decayTabList.end()){
00407 #ifndef BEAN
00408       log<<MSG::WARNING<< "add new info into existing decay tab for "
00409          <<mother<<endreq;
00410 #else
00411       if (verbose)
00412         cout << "add new info into existing decay tab for " << mother << endl;
00413 #endif
00414       dTab=itlist->second;
00415     }
00416     else{
00417 #ifndef BEAN
00418       log<<MSG::INFO<< "Create new decay code table for "<<mother<<endreq;
00419 #else
00420       if (verbose)
00421         cout << "Create new decay code table for " << mother << endl;
00422 #endif
00423       dTab=new decayModeTab;
00424       m_decayTabList[mo_pdg]=dTab;
00425     }
00426 
00427     while(true){
00428       getline (infile,ln);
00429       if( infile.eof() ){
00430 #ifndef BEAN
00431         log<<MSG::ERROR << "Enexpected EOF for dacay code file "
00432            <<fname <<endreq;
00433 #else
00434         cerr << "Enexpected EOF for dacay code file " << fname << endl;
00435 #endif
00436         infile.close();
00437         return 1;
00438       }
00439       nstr++;
00440       if(ln.empty())continue;
00441       if(ln[0]=='#')continue;
00442       if(ln.size()>255){
00443 #ifndef BEAN
00444         log<<MSG::ERROR<<"line "<< nstr <<"in decay table file " 
00445            <<fname<<" is too big" <<endreq;
00446 #else
00447         cerr << "line " << nstr << "in decay table file "
00448              << fname << " is too big" << endl;
00449 #endif
00450         infile.close();
00451         return 1;
00452       }
00453       strcpy(str,ln.c_str());
00454       pch = strtok (str,whitespaces);
00455       if(pch==NULL)continue;
00456       if(strcmp(pch,"Enddecay")==0){
00457 #ifndef BEAN
00458         log<<MSG::INFO <<" End of "<< mother <<" decay table" <<endreq;
00459 #else
00460         if (verbose)
00461           cout << " End of " << mother << " decay table" << endl;
00462 #endif
00463         break;
00464       }
00465 #ifndef BEAN
00466       log<<MSG::DEBUG<<"parsing line "<<ln<<endreq;
00467 #else
00468       if (verbose)
00469         cout << "parsing line " << ln << endl;
00470 #endif
00471       dcode=atoi(pch);
00472       if(dcode<=0||dcode>255){
00473 #ifndef BEAN
00474         log<<MSG::ERROR<< " wrong decay code  in line "<<nstr
00475            <<", file "<<fname<< endreq; 
00476 #else
00477         cerr << " wrong decay code  in line " << nstr
00478              << ", file " << fname << endl;
00479 #endif
00480         infile.close();
00481         return 1;
00482       }
00483       //      decayModeTab::iterator itTab=dTab->find(code);
00484       //if( itTab != dTab->end()){
00485         
00486 #ifndef BEAN
00487       log<<MSG::DEBUG<<"   dcode:"<<dcode<<",  particles: ";
00488 #else
00489       if (verbose)
00490         cout << "   dcode:" << dcode << ",  particles: ";
00491 #endif
00492       pch = strtok (NULL, whitespaces);
00493       if(pch==NULL){
00494         //        if(
00495 #ifndef BEAN
00496         log<<MSG::ERROR<< " no decay found in line "<<nstr
00497            <<", file "<<fname<< endreq;
00498 #else
00499         cerr << " no decay found in line " << nstr
00500              << ", file " << fname << endl;
00501 #endif
00502         infile.close();
00503         return 1;
00504       }
00505       //      keyVector* pKey=new keyVector;
00506       keyVector key;
00507       key.clear();
00508       //      keyVector* pKey=&key;
00509       while (pch != NULL){
00510 #ifndef BEAN
00511         log<<MSG::DEBUG <<pch<<" ";        
00512 #else
00513         if (verbose)
00514           cout << pch << " ";
00515 #endif
00516         pdg=name2pdg(string(pch));
00517         if(pdg==0){
00518 #ifndef BEAN
00519            log<<MSG::ERROR<<endl<< "Unrecognized  particle " <<pch 
00520               <<" in line " << nstr <<" of " <<fname<<endreq;
00521 #else
00522             cerr << endl << "Unrecognized  particle " << pch 
00523                  << " in line " << nstr << " of " << fname << endl;
00524 #endif
00525           infile.close();
00526            return 1;
00527          }
00528         //        pKey->push_back(pdg);
00529         key.push_back(pdg);
00530         pch = strtok (NULL, whitespaces);
00531       }
00532  
00533       //      sort(pKey->begin(),pKey->end());
00534       sort(key.begin(),key.end());
00535 #ifndef BEAN
00536       log<<MSG::DEBUG<<"    sorted pdg" ;
00537 #else
00538       if (verbose) {
00539         cout << "    sorted pdg";
00540 #endif
00541       //      for(keyVector::iterator it=pKey->begin(); it!=pKey->end(); it++)
00542       for(keyVector::iterator it=key.begin(); it!=key.end(); it++)
00543 #ifndef BEAN
00544         log<<MSG::DEBUG <<"  "<<(*it);
00545       log<<MSG::DEBUG<<endreq;
00546 #else
00547         cout << "  " << (*it);
00548       cout << endl;
00549       } // end of if (verbose)
00550 #endif
00551       //      decayModeTab::iterator itdec=dTab->find(*pKey);
00552       decayModeTab::iterator itdec=dTab->find(key);
00553       if(itdec!=dTab->end()){
00554         if(itdec->second !=dcode){
00555 #ifndef BEAN
00556           log<<MSG::ERROR << "line "<<nstr<<" of file " <<fname
00557              <<"has an error : "<<endreq ;
00558           log<<MSG::ERROR<<"decay of "<<mother<< " to";
00559 #else
00560           cerr << "line " << nstr << " of file " << fname 
00561                << "has an error : " << endl;
00562           cerr << "decay of " << mother << " to";
00563 #endif
00564           //          for(keyVector::iterator it=pKey->begin(); it!=pKey->end(); it++)
00565           for(keyVector::iterator it=key.begin(); it!=key.end(); it++)
00566 #ifndef BEAN
00567             log<<MSG::ERROR<<" "<<pdg2name(*it);
00568           log<<MSG::ERROR<<" is already in table. Aborting."<<endreq;
00569           log<<MSG::ERROR<<"check line "<<nstr<<" of " <<fname<<endreq;
00570 #else
00571             cerr << " " << pdg2name (*it);
00572           cerr << " is already in table. Aborting." << endl;
00573           cerr << "check line " << nstr << " of " << fname << endl;
00574 #endif
00575           infile.close();
00576           return 1;
00577         }
00578       }
00579       //      (*dTab)[*pKey]=dcode;
00580       (*dTab)[key]=dcode;
00581     }
00582   } // end if file read loop
00583   infile.close();
00584   return 0;
00585 }
00586 
00587 #ifndef BEAN
00588 int EventTagSvc::getDecayCode(Event::McParticle* part){
00589   MsgStream log(msgSvc(), name());
00590 #else
00591 int EventTagSvc::getDecayCode (TMcParticle * part){
00592    if (!m_TMcEvent) {
00593       cerr << "(ERROR) EventTag: you must set TMcEvent first!" << endl;
00594       return -1;
00595    }
00596 #endif
00597   keyVector key;
00598 
00599 #ifndef BEAN
00600   long int mother_pdg=part->particleProperty();
00601 #else
00602   long int mother_pdg = part->getParticleID ();
00603 #endif
00604 
00605   map<int,decayModeTab*>::iterator itlist=m_decayTabList.find(mother_pdg);
00606   if(itlist==m_decayTabList.end())return 0;
00607   decayModeTab* dTab=itlist->second;
00608 
00609 #ifndef BEAN
00610   SmartRefVector<Event::McParticle> dref=part->daughterList();
00611 #else
00612   vector < int >dref = part->getDaughters ();
00613 #endif
00614   if(dref.size()==0)return 0;
00615   key.clear();
00616 
00617 #ifndef BEAN
00618   for(SmartRefVector<Event::McParticle>::iterator it=dref.begin();
00619    it!=dref.end();it++){
00620     int pdg=(*it)->particleProperty();
00621 #else
00622    for (unsigned int i = 0; i < dref.size (); i++) {
00623       const TMcParticle *daughter = m_TMcEvent->getMcParticle (dref[i]);
00624 
00625       int pdg = daughter->getParticleID ();
00626 #endif
00627     if(m_digK0&&(abs(pdg)==311)){
00628 #ifndef BEAN
00629       SmartRefVector<Event::McParticle> dref1=(*it)->daughterList();
00630 #else
00631       vector < int >dref1 = daughter->getDaughters ();
00632 #endif
00633       if(dref1.size()!=1){
00634 #ifndef BEAN
00635         log<< MSG::WARNING<<"unknown decay of K0, aborting"<<endreq;
00636 #else
00637         cout << "unknown decay of K0, aborting" << endl;
00638 #endif
00639         return 0;
00640       }
00641 #ifndef BEAN
00642       pdg=dref1[0]->particleProperty();
00643 #else
00644       pdg = m_TMcEvent->getMcParticle (dref1[0])->getParticleID ();
00645 #endif
00646     }
00647     if((abs(pdg)==22)&&m_ignorePhotons)continue;
00648     if((pdg==-22)&&m_ignoreFSR)continue;
00649     key.push_back(pdg);
00650   }
00651 
00652   sort(key.begin(),key.end());
00653   if(m_ignorePhotons&&(key.size()==0))key.push_back(22);
00654   decayModeTab::iterator ittab=dTab->find(key);
00655   if(ittab==dTab->end())return 0;
00656   return ittab->second;
00657 }
00658 
00659 int EventTagSvc::buildAntiPartTabs(){
00660 #ifndef BEAN
00661   MsgStream log(msgSvc(), name());
00662 #endif
00663   decayModeTab* dTab;
00664   decayModeTab* adTab;
00665   keyVector key,akey;
00666   int mother,amother,code;
00667   for(std::map<int,decayModeTab*>::iterator itl=m_decayTabList.begin(); 
00668       itl!=m_decayTabList.end();itl++){
00669     mother=itl->first;
00670     amother=-mother;
00671     if(m_decayTabList.find(amother)!=m_decayTabList.end())
00672       continue;// aparticle tab already exist
00673     if(pdg2name(mother).size()==0){
00674 #ifndef BEAN
00675       log<<MSG::ERROR
00676       <<" buildAntiPartTabs :: Unknown pdg code for mother particle "<<endreq;
00677 #else
00678       cerr << " buildAntiPartTabs :: Unknown pdg code for mother particle " 
00679            << endl;
00680 #endif
00681       return 1;
00682     }
00683     if(pdg2name(amother).size()==0)continue; //Aparticle==particle??
00684 #ifndef BEAN
00685     log<<MSG::INFO<<" buildAntiPartTabs :: create new table for particle "
00686        << amother<<"("<<pdg2name(amother)<<")"<<endreq;
00687 #else
00688     if (verbose)
00689       cout << " buildAntiPartTabs :: create new table for particle "
00690            << amother << "(" << pdg2name (amother) << ")" << endl;
00691 #endif
00692     dTab=itl->second;
00693     adTab=new decayModeTab;
00694     m_decayTabList[amother]=adTab;
00695     key.clear();
00696     for(decayModeTab::iterator it=dTab->begin();it!=dTab->end();it++){
00697       key=it->first;
00698       code=it->second;
00699       for(keyVector::iterator it=key.begin();it!=key.end();it++){
00700         if(pdg2name(*it).size()==0){
00701 #ifndef BEAN
00702           log<<MSG::ERROR<<" buildAntiPartTabs :: Unknown pdg code"
00703              << "for  particle in keyVector"<<endreq;
00704 #else
00705           cerr << " buildAntiPartTabs :: Unknown pdg code"
00706                << "for  particle in keyVector" << endl;
00707 #endif
00708           return 1;
00709         }
00710         if(pdg2name(-(*it)).size()==0)continue ; // true neutral ??
00711         (*it) *= -1;
00712       }
00713       sort(key.begin(),key.end());
00714       (*adTab)[key]=code;
00715     }
00716   }
00717   return 0;
00718 }
00719 
00720 #ifndef BEAN
00721 unsigned  int EventTagSvc::getCharmDecayType(Event::McParticle* part){
00722 #else
00723 unsigned int EventTagSvc::getCharmDecayType (TMcParticle * part){
00724    if (!m_TMcEvent) {
00725       cerr << "(ERROR) EventTag: you must set TMcEvent first!" << endl;
00726       return -1;
00727    }
00728 #endif
00729   unsigned int a=0;
00730   //  int type=0;
00731   if(! part) return 0xF;
00732 #ifndef BEAN
00733   SmartRefVector<Event::McParticle> dref=part->daughterList();
00734 #else
00735   vector < int >dref = part->getDaughters ();
00736 #endif
00737   if(dref.size()==0) return 0;
00738   int nhad=0;
00739   long int pdg1=0;
00740   bool dd=false;
00741 #ifndef BEAN
00742   for(SmartRefVector<Event::McParticle>::iterator it=dref.begin(); 
00743    it!=dref.end();it++){
00744     int pdg=abs((*it)->particleProperty());
00745 #else
00746   for (unsigned int i = 0; i < dref.size (); i++) {
00747     const TMcParticle *daughter = m_TMcEvent->getMcParticle (dref[i]);
00748 
00749     int pdg = abs (daughter->getParticleID ());
00750 #endif
00751     if((pdg==22)&&m_ignorePhotons)continue;
00752     if(pdg==22){a|=1;}
00753     else if( (pdg>10)&&(pdg<19) ){a |=(1<<1);}
00754     else if( pdg>110) {
00755       if( ((pdg%1000)/100==4)&&((pdg%100)/10==4)){
00756         a |= 1<<3;
00757       }
00758       else{
00759         a |= 1<<2;
00760         nhad+=1;
00761         if(nhad==1)pdg1=pdg;
00762         dd=(pdg1==pdg);
00763       }
00764     }
00765     else a |=1<<4;
00766   }
00767   if(a>0xF)return 0xf;        //unknown particle
00768   if(a==4){                   //  hadronic
00769     if((nhad!=2)||(!dd))return 6;
00770     //    long int pdg1=dref[0]->particleProperty();
00771     //    long int pdg2=dref[1]->particleProperty();
00772     //    if(abs(pdg1)!=abs(pdg2)) return 6;
00773     switch (abs(pdg1)){
00774     case 411:
00775       return 7;
00776       break;
00777     case 421:
00778       return 8;
00779       break;
00780     case 413:
00781       return 9;
00782       break;
00783     case 423:
00784       return 10;
00785       break;
00786     case 431:
00787       return 11;
00788       break;
00789     case 433:
00790       return 12;
00791       break;
00792     default:
00793       return 6;
00794       break;
00795     }
00796   }
00797   if((a&0xE)==2)return 1;     // leptonic 
00798   if((a&0x6)==0x6)return 2;   // semileptonic 
00799   if((a&0xE)==0xC)return 4;   //  hadronic charmonium transition
00800   if((a&0xE)==0x8)return 3;   //  radiative charmonium transition   !!use 0XE mask for correct work with "ignore photons" options; 
00801   if((a&1)==1)return 5;       //  radiative
00802   return 0xf;                 //unknown
00803 }
00804  
00805 
00806 #ifndef BEAN
00807 unsigned long long int EventTagSvc::getChainCode(Event::McParticle* part){
00808 #else
00809 unsigned long long int EventTagSvc::getChainCode (TMcParticle * part){
00810    if (!m_TMcEvent) {
00811       cerr << "(ERROR) EventTag: you must set TMcEvent first!" << endl;
00812       return -1;
00813    }
00814 #endif
00815   unsigned long long int code=0;
00816   int shift=0;
00817 #ifndef BEAN
00818   vector<Event::McParticle*> chainVect;
00819 #else
00820   vector < TMcParticle * >chainVect;
00821 #endif
00822   while(shift<57){
00823     code |=  (getDecayCode(part)&0xFF)<<shift;  
00824 #ifndef BEAN
00825     SmartRefVector<Event::McParticle> dref=part->daughterList();
00826 #else
00827     vector < int >dref = part->getDaughters ();
00828 #endif
00829     chainVect.clear();
00830 #ifndef BEAN
00831     for(SmartRefVector<Event::McParticle>::iterator it=dref.begin();
00832      it!=dref.end();it++){
00833       int abspdg=abs((*it)->particleProperty());
00834 #else
00835     for (unsigned int i = 0; i < dref.size (); i++) {
00836       const TMcParticle *daughter = m_TMcEvent->getMcParticle (dref[i]);
00837 
00838       int abspdg = abs (daughter->getParticleID ());
00839 #endif
00840       if(((((abspdg%1000)/10)<45) && (((abspdg%1000)/10)>40)) // select particles with *4?? pdg code
00841          ||(chainTrigParticles.find(abspdg)!=chainTrigParticles.end())) { 
00842 #ifndef BEAN
00843         chainVect.push_back(*it);
00844 #else
00845         chainVect.push_back (const_cast < TMcParticle * >(daughter));
00846 #endif
00847       }
00848     }
00849     if(chainVect.size()==0 ||chainVect.size()>2)break;
00850     if(chainVect.size()==1){part=chainVect[0];}
00851     else{
00852       sort(chainVect.begin(),chainVect.end(),mcPartPrtLess);
00853       code |= ((getDecayCode(chainVect[0])&0xFF)<<(shift+8));
00854       code |= ((getDecayCode(chainVect[1])&0xFF)<<(shift+16));
00855       break;
00856     }
00857     shift+=8;
00858   }
00859   return code;
00860 }
00861 
00862 #ifdef BEAN
00863 unsigned int EventTagSvc::getEventTag (unsigned int initialEventTag){
00864    if (!m_TMcEvent) {
00865       cerr << "(ERROR) EventTag: you must set TMcEvent first!" << endl;
00866       return -1;
00867    }
00868 
00869    // Get McParticle Collections
00870    unsigned int m_EventTag = initialEventTag;
00871 
00872 
00873    const TObjArray *mcParticles = m_TMcEvent->getMcParticleCol ();
00874 
00875 
00876 
00877    if (!mcParticles) {
00878       cerr << "Can not open McParticleCollection" << endl;
00879       return true;
00880    }
00881 
00882    if (m_EventTag == 0) {       //try autodetect general event type: check for ccbar resonance;
00883       TIterator *mcParticlesIter = mcParticles->MakeIterator ();
00884       while (TMcParticle * particle =
00885              (TMcParticle *) (mcParticlesIter->Next ())) {
00886 
00887          //      if((*it)->itdecayInFlight())!!((*it)->primaryParticle())continue;
00888          long int pdg = abs (particle->getParticleID ());
00889          if (((pdg % 1000) / 10) == 44) {
00890             m_EventTag =
00891                ((int) (pdg == 443)) * 4 +
00892                ((int) (pdg == 100443)) * 5 +
00893                ((int) (pdg == 30443)) * 6 +
00894                ((int) (pdg == 9000443)) * 7 +
00895                ((int) (pdg == 9010443)) * 8 + ((int) (pdg == 9020443)) * 9;
00896             break;
00897          }
00898       }
00899    }
00900 
00901    if (m_EventTag == 0) {       //try autodetect general event type;
00902       m_EventTag = 2;           //off-resonance data
00903       TIterator *mcParticlesIter2 = mcParticles->MakeIterator ();
00904 
00905       while (TMcParticle * particle =
00906              (TMcParticle *) (mcParticlesIter2->Next ())) {
00907          if (particle->decayInFlight () || particle->primaryParticle ())
00908             continue;
00909          long int pdg = abs (particle->getParticleID ());
00910          if (pdg == 11) {
00911             m_EventTag |= 0X20;
00912             break;
00913          }
00914          else if (pdg == 13) {
00915             m_EventTag |= 0X30;
00916             break;
00917          }
00918          else if (pdg == 15) {
00919             m_EventTag |= 0X40;
00920             break;
00921          }
00922          else if ((pdg > 0) && (pdg < 9)) {
00923             m_EventTag |= 0X50;
00924             break;
00925          }
00926       }
00927    }
00928 
00929 
00930    if (((m_EventTag & 0xf) > 3) && ((m_EventTag & 0xf) < 9)) {  
00931       m_EventTag &= 0xf;
00932       // find initial charmonium resonance;
00933       TIterator *mcParticlesIter3 = mcParticles->MakeIterator ();
00934       while (TMcParticle * particle =
00935              (TMcParticle *) (mcParticlesIter3->Next ())) {
00936          long int pdg = particle->getParticleID ();
00937          if (((pdg % 1000) / 10) != 44)
00938             continue;
00939          //      part=(*it);
00940          m_EventTag |= (getCharmDecayType (particle)) << 4;
00941          m_EventTag |= (getChainCode (particle)) << 8;
00942          //      printf("Chain code %20llX \n",(m_EventTagSvc->getChainCode(*it)));
00943          break;
00944       }
00945    }
00946    else if ((m_EventTag & 0xf) == 0x2) {        //off-resonance
00947       //save topology info:
00948       int ncha = 0;
00949       int nneu = 0;
00950       TIterator *mcParticlesIter4 = mcParticles->MakeIterator ();
00951       while (TMcParticle * particle =
00952              (TMcParticle *) (mcParticlesIter4->Next ())) {
00953          long int pdg = abs (particle->getParticleID ());
00954          bool good = (!particle->decayInFlight ())
00955             && (!particle->primaryParticle ());
00956          ncha += ((int)
00957                   (good && ((pdg == 11) || (pdg == 13) || (pdg == 211)
00958                             || (pdg == 321)
00959                             || (pdg == 2212) || (pdg == 1011))));
00960          nneu += ((int)
00961                   (good && ((pdg == 111) || (pdg == 310) || (pdg == 130)
00962                             || (pdg == 2112))));
00963 //       printf("%2i %6i  %2i %2i  Nneu:%3i    Ncha:%3i \n",
00964 //           (*it)->trackIndex(),pdg,
00965 //           ((pdg==11)||(pdg==13)||(pdg==211)||(pdg==321)||(pdg==2212)||(pdg==1011)),
00966 //           ((pdg==111)||(pdg==310)||(pdg==130)||(pdg==2112)),
00967 //           nneu,ncha);  
00968       }
00969       m_EventTag |= ((ncha & 0xF) << 8);
00970       m_EventTag |= ((nneu & 0xF) << 12);
00971       if ((m_EventTag & 0xf0) == 0x40) {        //tau-tau event
00972          //cout<< "XXXXXXXXX" <<endl;
00973          TIterator *mcParticlesIter5 = mcParticles->MakeIterator ();
00974          while (TMcParticle * particle =
00975                 (TMcParticle *) (mcParticlesIter5->Next ())) {
00976             long int pdg = particle->getParticleID ();
00977             //      cout<<"    YYY: "<<pdg<<endl;
00978             if (pdg == -15) {
00979                m_EventTag |= (getDecayCode (particle)) << 16;
00980                // cout <<"DEcay cod for a-tau:" <<(m_EventTagSvc->getDecayCode(*it))<<endl;
00981             }
00982             else if (pdg == 15) {
00983                m_EventTag |= (getDecayCode (particle)) << 24;
00984                //cout <<"DEcay cod for tau:" <<(m_EventTagSvc->getDecayCode(*it))<<endl;
00985             }
00986          }
00987 
00988       }
00989    }
00990 
00991 
00992    return m_EventTag;
00993 }
00994 #endif

Generated on Tue Nov 29 22:58:29 2016 for BOSS_7.0.2 by  doxygen 1.4.7