| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

SimHeaderCnvHits.cc

Go to the documentation of this file.
00001 #include "SimHeaderCnv.h"
00002 #include "PerSimEvent/PerSimHitHeader.h"
00003 #include "Event/SimHitHeader.h"
00004 
00005 #include "PerSimEvent/PerSimPmtHit.h"
00006 #include "PerSimEvent/PerSimRpcHit.h"
00007 #include "Event/SimPmtHit.h"
00008 #include "Event/SimRpcHit.h"
00009 
00010 #include <iostream>
00011 
00012 using namespace DayaBay;
00013 using namespace std;
00014 
00015 
00016 DayaBay::SimHitCollection* SimHeaderCnv::convert(vector<SimTrack*>& timap,
00017                                                  const PerSimHitCollection& phc)
00018 {
00019     const PerSimHitCollection::phit_container& phits = phc.hits;
00020 
00021     size_t nphits = phits.size();
00022 
00023     SimHitCollection* hc = new SimHitCollection;
00024     hc->setDetector(Detector(phc.detId));
00025 
00026     if (!nphits) return hc; // empty
00027 
00028     bool is_pmt = (0 != dynamic_cast<const PerSimPmtHit*>(phits[0]));
00029 
00030     SimHitCollection::hit_container hits;
00031 
00032     if (is_pmt) {
00033         for (size_t ihit=0; ihit < nphits; ++ihit) {
00034             const PerSimPmtHit* phit = dynamic_cast<const PerSimPmtHit*>(phits[ihit]);
00035             SimPmtHit* pmt_hit = new SimPmtHit;
00036             pmt_hit->setHc(hc);
00037             pmt_hit->setDir(phit->dir);
00038             pmt_hit->setPol(phit->pol);
00039             pmt_hit->setWavelength(phit->wavelength);
00040             pmt_hit->setType(phit->type);
00041             hits.push_back(pmt_hit);
00042         }
00043     }
00044     else {
00045         for (size_t ihit=0; ihit < nphits; ++ihit) {
00046             const PerSimRpcHit* phit = dynamic_cast<const PerSimRpcHit*>(phits[ihit]);
00047             SimRpcHit* rpc_hit = new SimRpcHit;
00048             rpc_hit->setHc(hc);
00049             rpc_hit->setEnergyDep(phit->energy);
00050             hits.push_back(rpc_hit);
00051         }
00052     }
00053 
00054     // Now copy the common part
00055     for (size_t ihit=0; ihit < nphits; ++ihit) {
00056         const PerSimHit *phit = phits[ihit];
00057 
00058         if (0 == (0x0000ff00&phit->sensDetId) && (0x000000ff&phit->sensDetId) > 6) {
00059             cerr << "SimHeaderCnvHits: warning got bogus PMTid: " << (void*)phit->sensDetId << endl;
00060         }
00061 
00062         SimHit *hit = hits[ihit];
00063         hit->setSensDetId(phit->sensDetId);
00064         hit->setHitTime(phit->time);
00065         hit->setLocalPos(phit->pos);
00066         hit->setWeight(phit->weight);
00067 
00068         int index = phit->ancestor.index;
00069         if (phit->ancestor.index < 0) {
00070             // emit error to log
00071             continue;
00072         }
00073         int count = phit->ancestor.count;
00074         hit->setAncestor(SimTrackReference(timap[index],count));
00075     }
00076 
00077 
00078     hc->setCollection(hits);
00079     return hc;
00080 }
00081 
00082 PerSimHitCollection* SimHeaderCnv::convert(map<const SimTrack*,int>& trackMap,
00083                                            const DayaBay::SimHitCollection& hc)
00084 {
00085     MsgStream log(msgSvc(), "SimHeaderCnvHits::convert(t2p)");
00086 
00087     const SimHitCollection::hit_container &hits = hc.collection();
00088 
00089     PerSimHitCollection* phc = new PerSimHitCollection;
00090     phc->detId = hc.detector().siteDetPackedData();
00091 
00092     size_t nhits = hits.size();
00093 
00094     if (!nhits) return phc; // empty
00095 
00096     bool is_pmt = (0 != dynamic_cast<const SimPmtHit*>(hits[0]));
00097 
00098     PerSimHitCollection::phit_container& phits = phc->hits;
00099 
00100     // First create the output hit of specific type and fill specific data
00101     if (is_pmt) {
00102         for (size_t ihit=0; ihit < nhits; ++ihit) {
00103             const SimPmtHit *hit = dynamic_cast<const SimPmtHit*>(hits[ihit]);
00104             PerSimPmtHit* pmt_hit = new PerSimPmtHit(hit->dir(),
00105                                                      hit->pol(),
00106                                                      hit->wavelength(),
00107                                                      hit->type());
00108             phits.push_back(pmt_hit);
00109         }
00110     }
00111     else {
00112         for (size_t ihit=0; ihit < nhits; ++ihit) {
00113             const SimRpcHit *hit = dynamic_cast<const SimRpcHit*>(hits[ihit]);
00114             PerSimRpcHit* rpc_hit = new PerSimRpcHit(hit->energyDep());
00115             phits.push_back(rpc_hit);
00116         }
00117     }
00118 
00119     // Now copy the common part
00120     int nfailed = 0;
00121     for (size_t ihit=0; ihit < nhits; ++ihit) {
00122         const SimHit *hit = hits[ihit];
00123         PerSimHit *phit = phits[ihit];
00124         phit->sensDetId = hit->sensDetId();
00125         phit->time = hit->hitTime();
00126         phit->pos = hit->localPos();
00127         phit->weight = hit->weight();
00128 
00129         const SimTrack* ancestor = hit->ancestor().track();
00130         if (!ancestor) {
00131             ++nfailed;
00132             continue;
00133         }
00134 
00135         map<const SimTrack*,int>::const_iterator ait = trackMap.find(ancestor);
00136         if (ait == trackMap.end()) {
00137             log << MSG::ERROR
00138                 << "No ancestor track index found for #" 
00139                 << ancestor->trackId()
00140                 << endreq;
00141             continue;
00142         }
00143         int count = hit->ancestor().indirection();
00144         phit->ancestor = PerSimIndirection(ait->second,count);
00145     }
00146     if (nfailed) {
00147         log << MSG::DEBUG
00148             << "Failed to find ancestor for hit " << nfailed << " times"  << endreq;
00149     }
00150         
00151     return phc;
00152 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:35:45 2011 for PerSimEvent by doxygen 1.4.7