/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Event/RootCnvSvc/RootCnvSvc-02-01-12/src/Mc/EmcMcHitCnv.cxx

Go to the documentation of this file.
00001 #ifndef EmcMcHitCnv_CXX
00002 #define EmcMcHitCnv_CXX  1
00003 
00004 #include "GaudiKernel/MsgStream.h"
00005 #include "GaudiKernel/DataObject.h"
00006 #include "GaudiKernel/ObjectVector.h"
00007 
00008 #include "TClonesArray.h"
00009 
00010 
00011 #include "Identifier/Identifier.h"
00012 
00013 #include "EventModel/EventModel.h"
00014 #include "McTruth/McEvent.h"   //TDS object
00015 #include "McTruth/EmcMcHit.h"   //TDS object
00016 #include "RootEventData/TEmcMc.h" // standard root object
00017 #include "RootEventData/TMcEvent.h"
00018 #include "RootCnvSvc/Mc/McCnv.h"
00019 #include "RootCnvSvc/Mc/EmcMcHitCnv.h"
00020 #include "RootCnvSvc/RootAddress.h"
00021 
00022 
00023 // Instantiation of a static factory class used by clients to create
00024 // instances of this service
00025 //static CnvFactory<EmcMcHitCnv> s_factory;
00026 //const ICnvFactory& EmcMcHitCnvFactory = s_factory;
00027 
00028 EmcMcHitCnv::EmcMcHitCnv(ISvcLocator* svc)
00029 : RootEventBaseCnv(classID(), svc)
00030 {
00031     // Here we associate this converter with the /Event path on the TDS.
00032     MsgStream log(msgSvc(), "EmcMcHitCnv");
00033     // log << MSG::DEBUG << "Constructor called for " << objType() << endreq;
00034     m_rootBranchname ="m_emcMcHitCol";
00035     //declareObject(EventModel::MC::EmcMcHitCol, objType(), m_rootTreename, m_rootBranchname);
00036     m_adresses.push_back(&m_emcMcHitCol);
00037     m_emcMcHitCol=0;
00038 }
00039 
00040 StatusCode EmcMcHitCnv::TObjectToDataObject(DataObject*& refpObject) {
00041   // creation of TDS object from root object
00042 
00043     MsgStream log(msgSvc(), "EmcMcHitCnv");
00044     log << MSG::DEBUG << "EmcMcHitCnv::TObjectToDataObject" << endreq;
00045     StatusCode sc=StatusCode::SUCCESS;
00046 
00047     // create the TDS location for the MdcMc Collection
00048     EmcMcHitCol* emcMcTdsCol = new EmcMcHitCol;
00049     refpObject=emcMcTdsCol;
00050 
00051 
00052     // now convert
00053     if (!m_emcMcHitCol) return sc;
00054     TIter emcMcIter(m_emcMcHitCol);
00055     TEmcMc *emcMcRoot = 0;
00056     while ((emcMcRoot = (TEmcMc*)emcMcIter.Next())) {
00057       // unsigned int id = emcMcRoot ->getId();
00058       Identifier id ;
00059          unsigned int id_root = emcMcRoot ->getId();
00060          id = id_root;
00061                 unsigned int trackIndex = emcMcRoot ->getTrackIndex();
00062 
00063     int   hitEmc = emcMcRoot ->getHitEmc();
00064     int   PDGCode = emcMcRoot ->getPDGCode();
00065     double PDGCharge = emcMcRoot ->getPDGCharge();
00066     double time = emcMcRoot ->getTime();
00067 
00068                 double xPosition =   emcMcRoot ->getPositionX() ;
00069                 double yPosition =   emcMcRoot ->getPositionY() ;
00070                 double zPosition =   emcMcRoot ->getPositionZ() ;
00071                 double px=   emcMcRoot ->getPx() ;
00072     double py =   emcMcRoot ->getPy() ;
00073     double pz =   emcMcRoot ->getPz() ;
00074     double depositEnergy = emcMcRoot ->getDepositEnergy() ;
00075 
00076     EmcMcHit *emcMcTds = new EmcMcHit();
00077     m_common.m_rootEmcMcHitMap[emcMcRoot] = emcMcTds;
00078 
00079     emcMcTds->setIdentifier(id);
00080 
00081     map<Int_t, Double_t>  hitMap = emcMcRoot ->getHitMap();
00082     map<Identifier, Double_t>  TdshitMap;
00083     map<Int_t, Double_t> HitMap = emcMcRoot->getHitMap();
00084     map<Int_t, Double_t>::iterator iHitMap;
00085     for(iHitMap=HitMap.begin();
00086             iHitMap!=HitMap.end();
00087             iHitMap++) {
00088 
00089         Identifier id(iHitMap->first);
00090         pair<Identifier, Double_t> TdsHit(id, iHitMap->second);
00091         TdshitMap.insert(TdsHit);
00092 
00093         //RecEmcHitCol::iterator iHit;
00094         //for(iHit=emcRecHitCol->begin();
00095         //        iHit!=emcRecHitCol->end();
00096         //        iHit++) {
00097 
00098         //    RecEmcID idHit((*iHit)->getCellId());
00099 
00100         //    if(id==idHit) {
00101         //        RecEmcFraction frac(*(*iHit));
00102         //        frac.Fraction(iHitMap->second);
00103         //        emcShowerTds->Insert(frac);
00104         //        break;
00105         //    }
00106         //} //RecEmcHitCol
00107     } //CellIdMap
00108     emcMcTds->setHitMap(TdshitMap);
00109 
00110     emcMcTds->setHitEmc(hitEmc);
00111     emcMcTds->setPDGCode(PDGCode);
00112     emcMcTds->setPDGCharge(PDGCharge);
00113     emcMcTds->setTime(time);
00114 
00115     emcMcTds->setTrackIndex(trackIndex);
00116     emcMcTds->setPositionX(xPosition);
00117     emcMcTds->setPositionY(yPosition);
00118     emcMcTds->setPositionZ(zPosition);
00119     emcMcTds->setPx(px);
00120     emcMcTds->setPy(py);
00121     emcMcTds->setPz(pz);
00122     emcMcTds->setDepositEnergy(depositEnergy);
00123 
00124     emcMcTdsCol->push_back(emcMcTds);
00125     }
00126     //m_emcMcHitCol->Delete();  // wensp add 2005/12/30
00127     delete m_emcMcHitCol;
00128     m_emcMcHitCol = 0;
00129     return StatusCode::SUCCESS;
00130 }
00131 
00132 StatusCode EmcMcHitCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
00133 
00134     MsgStream log(msgSvc(), "EmcMcHitCnv");
00135     log << MSG::DEBUG << "EmcMcHitCnv::DataObjectToTObject" << endreq;
00136     StatusCode sc=StatusCode::SUCCESS;
00137 
00138     EmcMcHitCol * emcMcHitCnvTds=dynamic_cast<EmcMcHitCol *> (obj);
00139     if (!emcMcHitCnvTds) {
00140         log << MSG::ERROR << "Could not downcast to EmcMcHitCol" << endreq;
00141         return StatusCode::FAILURE;
00142     }
00143 
00144     DataObject *evt;
00145     m_eds->findObject(EventModel::MC::Event,evt);
00146     if (evt==NULL) {
00147         log << MSG::ERROR << "Could not get McEvent in TDS "  << endreq;
00148         return StatusCode::FAILURE;
00149     }
00150     McEvent * devtTds=dynamic_cast<McEvent *> (evt);
00151     if (!devtTds) {
00152         log << MSG::ERROR << "EmcMcHitCnv:Could not downcast to TDS McEvent" << endreq;
00153     }
00154     IOpaqueAddress *addr;
00155 
00156     m_cnvSvc->getMcCnv()->createRep(evt,addr); 
00157     TMcEvent *McEvt=m_cnvSvc->getMcCnv()->getWriteObject();
00158 
00159     const TObjArray *m_emcMcHitCol = McEvt->getEmcMcHitCol();
00160     if (!m_emcMcHitCol) return sc;
00161     McEvt->clearEmcMcHitCol(); //necessary in case there is I/O at the same time since array is static
00162     EmcMcHitCol::const_iterator emcMcTds;
00163 
00164     for (emcMcTds = emcMcHitCnvTds->begin(); emcMcTds != emcMcHitCnvTds->end(); emcMcTds++) {
00165         UInt_t id  = ((*emcMcTds)->identify()).get_value() ;
00166         UInt_t trackIndex = (*emcMcTds) ->getTrackIndex();
00167 
00168         int   hitEmc = (*emcMcTds) ->getHitEmc();
00169         int   PDGCode = (*emcMcTds) ->getPDGCode();
00170         double PDGCharge = (*emcMcTds) ->getPDGCharge();
00171         double time = (*emcMcTds) ->getTime();
00172         std::map<Identifier, Double_t>  TdshitMap = (*emcMcTds)->getHitMap();
00173 
00174         map<Int_t, Double_t>  HitMap;
00175         map<Identifier, Double_t>::iterator iHitMap;
00176         for(iHitMap=TdshitMap.begin();
00177                 iHitMap!=TdshitMap.end();
00178                 iHitMap++) {
00179 
00180             Int_t id(iHitMap->first.get_value());
00181             pair<Int_t, Double_t> Hit(id, iHitMap->second);
00182             HitMap.insert(Hit);
00183 
00184             //RecEmcHitCol::iterator iHit;
00185             //for(iHit=emcRecHitCol->begin();
00186             //        iHit!=emcRecHitCol->end();
00187             //        iHit++) {
00188 
00189             //    RecEmcID idHit((*iHit)->getCellId());
00190 
00191             //    if(id==idHit) {
00192             //        RecEmcFraction frac(*(*iHit));
00193             //        frac.Fraction(iHitMap->second);
00194             //        emcShowerTds->Insert(frac);
00195             //        break;
00196             //    }
00197             //} //RecEmcHitCol
00198         } //CellIdMap
00199 
00200         Double_t xPosition =   (*emcMcTds) ->getPositionX() ;
00201         Double_t yPosition =   (*emcMcTds) ->getPositionY() ;
00202         Double_t zPosition =   (*emcMcTds) ->getPositionZ() ;
00203         Double_t px=   (*emcMcTds) ->getPx() ;
00204         Double_t py =   (*emcMcTds) ->getPy() ;
00205         Double_t pz =   (*emcMcTds) ->getPz() ;
00206         Double_t depositEnergy = (*emcMcTds) ->getDepositEnergy() ;
00207 
00208         TEmcMc *emcMcRoot = new TEmcMc();
00209         //m_common.m_emcMcHitMap[(*emcMcTds)] = emcMcRoot;
00210 
00211         emcMcRoot->setId(id);
00212         emcMcRoot->setHitMap(HitMap);
00213 
00214         emcMcRoot->setHitEmc(hitEmc);
00215         emcMcRoot->setPDGCode(PDGCode);
00216         emcMcRoot->setPDGCharge(PDGCharge);
00217         emcMcRoot->setTime(time);
00218         //emcMcRoot->setHitMap(hitMap);
00219 
00220         emcMcRoot->setTrackIndex(trackIndex);
00221         emcMcRoot->setPositionX(xPosition);
00222         emcMcRoot->setPositionY(yPosition);
00223         emcMcRoot->setPositionZ(zPosition);
00224         emcMcRoot->setPx(px);
00225         emcMcRoot->setPy(py);
00226         emcMcRoot->setPz(pz);
00227         emcMcRoot->setDepositEnergy(depositEnergy);
00228 
00229         McEvt->addEmcMc(emcMcRoot);
00230     }
00231 
00232     return StatusCode::SUCCESS;
00233 }
00234 #endif
00235 
00236 
00237 
00238 
00239 
00240 
00241 
00242 
00243 
00244 

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