00001
00006 #include "ChkMuon.h"
00007
00008
00009
00010
00011 #include "Event/SimHitHeader.h"
00012 #include "Event/SimHitCollection.h"
00013 #include "Event/SimPmtHit.h"
00014 #include "Event/SimHit.h"
00015
00016
00017
00018 #include "Event/SimParticleHistory.h"
00019 #include "Event/SimUnobservableStatisticsHeader.h"
00020 #include "Event/SimStatistic.h"
00021
00022
00023 #include "Conventions/Detectors.h"
00024
00025 #include "GaudiKernel/ITHistSvc.h"
00026
00027 #include <Event/HeaderObject.h>
00028
00029
00030 ChkMuon::ChkMuon(const std::string& name, ISvcLocator* pSvcLocator):
00031 GaudiAlgorithm(name, pSvcLocator)
00032 {
00033 }
00034
00035 ChkMuon::~ChkMuon()
00036 {
00037 }
00038
00039 StatusCode ChkMuon::initialize()
00040 {
00041 this->GaudiAlgorithm::initialize();
00042
00044 m_dbOws = getDet<IDetectorElement>("/dd/Structure/Pool/db-ows");
00045 m_dbOil1 = getDet<IDetectorElement>("/dd/Structure/AD/db-oil1");
00046 m_dbOil2 = getDet<IDetectorElement>("/dd/Structure/AD/db-oil2");
00047 m_dbLso1 = getDet<IDetectorElement>("/dd/Structure/AD/db-lso1");
00048 m_dbLso2 = getDet<IDetectorElement>("/dd/Structure/AD/db-lso2");
00049
00050
00051 m_valiTree=new MuonTree;
00052 m_valiTree->create();
00053
00054 return StatusCode::SUCCESS;
00055 }
00056
00057 StatusCode ChkMuon::execute()
00058 {
00059 info()<<"Executing ... "<<endreq;
00060
00061 StatusCode sc;
00062 DataObject *pObject;
00063
00064
00065 sc=eventSvc()->retrieveObject(SimHeader::defaultLocation(),pObject);
00066 if(sc.isFailure()) {
00067 debug()<<"No SimHeader for this event"<<endreq;
00068 }
00069
00070 const GenHeader *pGenHeader=0;
00071 const SimHeader *pSimHeader=0;
00072
00073 const IHeader* firstHeader=0;
00074
00075 pSimHeader=dynamic_cast<SimHeader*>(pObject);
00076
00077
00078
00079 if(pSimHeader!=0) {
00080
00081 if(pSimHeader->inputHeaders().size() != 0) {
00082 firstHeader=*((pSimHeader->inputHeaders()).begin());
00083 pGenHeader= dynamic_cast<const GenHeader*>(firstHeader);
00084 }
00085 }
00086
00088 m_valiTree->reset();
00089
00090 m_valiTree->evt = pSimHeader->execNumber();
00091
00092
00093 sc = processGenHeader(pGenHeader);
00094 if(sc.isFailure()) return StatusCode::FAILURE;
00095
00096 sc = processSimHeader(pSimHeader);
00097 if(sc.isFailure()) return StatusCode::FAILURE;
00098
00099 m_valiTree->fill();
00100 debug()<<"Leaving Execute()..."<<endreq;
00101
00102 return StatusCode::SUCCESS;
00103 }
00104
00105 StatusCode ChkMuon::finalize()
00106 {
00107 m_valiTree->close();
00108 delete m_valiTree;
00109
00110 return this->GaudiAlgorithm::finalize();
00111 }
00112
00113
00114
00115
00116
00117 StatusCode ChkMuon::processGenHeader(const GenHeader *pGenHeader)
00118 {
00119
00120 if( pGenHeader==0 ) {
00121 return StatusCode::SUCCESS;
00122 }
00123 info()<<"Processing GenHeader"<<endreq;
00124
00125
00126 const HepMC::GenEvent * pgevt = pGenHeader->event();
00127 const HepMC::GenVertex * pvtx = 0;
00128 const HepMC::GenParticle * pptl =0;
00129
00130 debug()<<"vertices_size "<<pgevt->vertices_size()<<endreq;
00131
00132
00133 if ( pgevt->vertices_size() != 1 ) {
00134 error()<<"More than one primary vertex, out of the scope of this analysing program."<<endreq;
00135 return StatusCode::FAILURE;
00136 }
00137 pvtx=*(pgevt->vertices_begin());
00138 debug()<<"vertex: "<<*pvtx<<endreq;
00139
00140
00141 if ( pvtx->particles_out_size() != 1 ) {
00142 warning()<<"More than one primary particle, might be out of the scope of this analysing program."<<endreq;
00143
00144 }
00145 pptl=*(pvtx->particles_out_const_begin());
00146 debug()<<"particle: "<<*pptl<<endreq;
00147
00148
00149
00150 Gaudi::XYZPoint globalP(pvtx->position().x(),
00151 pvtx->position().y(),
00152 pvtx->position().z());
00153
00154 Gaudi::XYZPoint localP = m_dbOws->geometry()->toLocal(globalP);
00155
00156 m_valiTree->trk1_x=localP.X();
00157 m_valiTree->trk1_y=localP.Y();
00158 m_valiTree->trk1_z=localP.Z();
00159 m_valiTree->trk1_r=sqrt((m_valiTree->trk1_x * m_valiTree->trk1_x) +
00160 (m_valiTree->trk1_y * m_valiTree->trk1_y));
00161
00162 static bool first=true;
00163 if(first) {
00164 first=false;
00165 m_t0=pGenHeader->earliest();
00166 info()<<"t0 of this sample: "<<m_t0<<endreq;
00167 }
00168
00169
00170 TimeStamp now=pGenHeader->earliest();
00171 TimeStamp dt=now-m_t0;
00172 m_valiTree->trk1_t=
00173 dt.GetSeconds()
00174 +pvtx->position().t()/1e9;
00175
00176 debug()<<"now: "<<now<<"\t"<<"dt: "<<dt<<endreq;
00177 debug()<<"dt(s): "<<dt.GetSeconds()<<"\t"<<"t_vts(ns): "<<pvtx->position().t()<<endreq;
00178
00179
00181 m_valiTree->trk1_px=pptl->momentum().px();
00182 m_valiTree->trk1_py=pptl->momentum().py();
00183 m_valiTree->trk1_pz=pptl->momentum().pz();
00184 m_valiTree->trk1_e=pptl->momentum().e();
00185
00186
00187 return StatusCode::SUCCESS;
00188 }
00189
00190
00191
00192
00193
00194 StatusCode ChkMuon::processSimHeader(const SimHeader *pSimHeader)
00195 {
00196
00197 if( pSimHeader==0 ) {
00198 return StatusCode::SUCCESS;
00199 }
00200
00201 info()<<"Processing SimHeader. analyze DayaBay site only!"<<endreq;
00202
00205 const SimHitHeader* simhitheader = pSimHeader->hits();
00207 const SimHitHeader::hc_map& hcmap = simhitheader->hitCollection();
00208 SimHitHeader::hc_map::const_iterator it;
00209
00211 debug()<<"size of hit collection "<< hcmap.size()<<endreq;
00212 for (it=hcmap.begin(); it != hcmap.end(); ++it) {
00213
00214 Detector det(it->first);
00215 debug() << "Got hit collection from " << det.detName()<<" id= "
00216 << det.siteDetPackedData()<<endreq;
00217
00219 const std::vector<SimHit*>& hitvec=it->second->collection();
00220 std::vector<SimHit*>::const_iterator it_hvec;
00221
00222 if( det.detectorId() == DetectorId::kAD1 ) {
00223 debug() <<"AD1 has "<< hitvec.size()<<" hits"<<endreq;
00224 m_valiTree->nhits_AD1=hitvec.size();
00225
00226 } else if ( det.detectorId() == DetectorId::kAD2 ) {
00227 debug() <<"AD2 has "<< hitvec.size()<<" hits"<<endreq;
00228 m_valiTree->nhits_AD2=hitvec.size();
00229
00230 } else if ( det.detectorId() == DetectorId::kIWS ) {
00231 debug() <<"IWS has "<< hitvec.size()<<" hits"<<endreq;
00232 m_valiTree->nhits_IWS=hitvec.size();
00233
00234 } else if ( det.detectorId() == DetectorId::kOWS ) {
00235 debug() <<"OWS has "<< hitvec.size()<<" hits"<<endreq;
00236 m_valiTree->nhits_OWS=hitvec.size();
00237
00238 } else if ( det.detectorId() == DetectorId::kRPC ) {
00239 debug() <<"RPC has "<< hitvec.size()<<" hits"<<endreq;
00240 m_valiTree->nhits_RPC=hitvec.size();
00241 }
00242
00243 }
00244
00245
00247
00248
00249 const DayaBay::SimParticleHistory* pHist = pSimHeader->particleHistory();
00250
00251 if(pHist) {
00252 processHistory(pHist);
00253 }
00254
00255
00256 const DayaBay::SimUnobservableStatisticsHeader* unobSt =
00257 pSimHeader->unobservableStatistics();
00258 const DayaBay::SimUnobservableStatisticsHeader::stat_map&
00259 statmap = unobSt->stats();
00260 DayaBay::SimUnobservableStatisticsHeader::stat_map::const_iterator
00261 st, stdone = statmap.end();
00262
00263 debug()<<"UnObs size "<<statmap.size()<<endreq;
00264
00265 if(unobSt) {
00266
00267 for (st=statmap.begin(); st != stdone; ++st) {
00268
00269
00270
00271 if(st->first=="TotDeInOil1")
00272 m_valiTree ->TotDeInOil1 = st->second.sum();
00273 if(st->first=="TotDeInOil2")
00274 m_valiTree ->TotDeInOil2 = st->second.sum();
00275 if(st->first=="TotDeInLso1")
00276 m_valiTree ->TotDeInLso1 = st->second.sum();
00277 if(st->first=="TotDeInLso2")
00278 m_valiTree ->TotDeInLso2 = st->second.sum();
00279
00280
00281 if(st->first=="MuDeInOil1")
00282 m_valiTree ->MuDeInOil1 = st->second.sum();
00283 if(st->first=="MuDeInOil2")
00284 m_valiTree ->MuDeInOil2 = st->second.sum();
00285 if(st->first=="MuDeInLso1")
00286 m_valiTree ->MuDeInLso1 = st->second.sum();
00287 if(st->first=="MuDeInLso2")
00288 m_valiTree ->MuDeInLso2 = st->second.sum();
00289
00290
00291 if(st->first=="MuDxInOil1")
00292 m_valiTree ->MuDxInOil1 = st->second.sum();
00293 if(st->first=="MuDxInOil2")
00294 m_valiTree ->MuDxInOil2 = st->second.sum();
00295 if(st->first=="MuDxInLso1")
00296 m_valiTree ->MuDxInLso1 = st->second.sum();
00297 if(st->first=="MuDxInLso2")
00298 m_valiTree ->MuDxInLso2 = st->second.sum();
00299
00300 }
00301 }
00302
00303
00304 return StatusCode::SUCCESS;
00305 }
00306
00307
00309 StatusCode ChkMuon::processHistory(const DayaBay::SimParticleHistory* pHist)
00310 {
00311 m_muon = 0;
00312 m_neutrons.clear();
00313
00314
00315 const std::list<DayaBay::SimTrack*>& trk=pHist->tracks();
00316 std::list<DayaBay::SimTrack*>::const_iterator tkci, tkEnd=trk.end();
00317
00318 info()<<"History track list size "<<trk.size()<<endreq;
00319 for(tkci = trk.begin(); tkci != tkEnd; tkci++ ) {
00320
00321 if( (*tkci)->trackId() == 1 &&
00322 ( (*tkci)->particle() == 13 || (*tkci)->particle() == -13 ) &&
00323 (*tkci)->ancestorTrack().track() == 0 ) {
00324 m_muon = *tkci;
00325 }
00326
00327
00328 if( (*tkci)->particle() == 2112 ) {
00329 m_neutrons.push_back( *tkci );
00330 }
00331 }
00332 info()<<m_neutrons.size()<<" spallation neutron(s)"<<endreq;
00333
00334 const std::list<DayaBay::SimVertex*>& vtx=pHist->vertices();
00335 std::list<DayaBay::SimVertex*>::const_iterator vtci, vtEnd=vtx.end();
00336 info()<<"History vertex list size "<<vtx.size()<<endreq;
00337
00338
00341 const vector<SimVertex*>& MuonVtx = m_muon->vertices();
00342 for( unsigned int ci=0; ci<MuonVtx.size(); ++ci ) {
00343
00344 }
00345
00346
00347 Gaudi::XYZPoint globalP = MuonVtx[0]->position();
00348 Gaudi::XYZPoint localP = m_dbOws->geometry()->toLocal(globalP);
00349
00350 m_valiTree->his_t1 = MuonVtx[0]->time();
00351 m_valiTree->his_x1 = localP.x();
00352 m_valiTree->his_y1 = localP.y();
00353 m_valiTree->his_z1 = localP.z();
00354
00355
00356
00358 int nMuonInducedNeutron = 0;
00359 int nInOws = 0;
00360 int nInOil1 = 0;
00361 int nInOil2 = 0;
00362 int nInLso1 = 0;
00363 int nInLso2 = 0;
00364
00365 for( unsigned int nn=0; nn<m_neutrons.size(); ++nn ) {
00366 SimTrack* pNeu = m_neutrons[nn];
00367 const vector<SimVertex*>& NeuVtx = pNeu->vertices();
00368
00369 info()<<"spallation neutron: "<<"track id "<<pNeu->trackId()<<" PDG id "<<pNeu->particle()
00370 <<" ancestor "<<pNeu->ancestorTrack().track()->trackId()<<" has "<<NeuVtx.size()<<" vertices."<<endreq;
00371
00372
00373 SimVertex* FirstVtx = NeuVtx[0];
00374 SimVertex* LastVtx = NeuVtx[NeuVtx.size()-1];
00375 info()<<" "<<FirstVtx->time()<<" "<<FirstVtx->position()<<" "<<FirstVtx->totalEnergy()<<" {"
00376 <<FirstVtx->process().type()<<" "<<FirstVtx->process().name()<<" }"<<endreq;
00377 info()<<" "<<LastVtx->time()<<" "<<LastVtx->position()<<" "<<LastVtx->totalEnergy()<<" {"
00378 <<LastVtx->process().type()<<" "<<LastVtx->process().name()<<" }"<<endreq;
00379
00380 if( pNeu->ancestorTrack().track()->trackId() != 1 ) {
00381
00382 info()<<" Not induced by primary muon track"<<endreq;
00383 continue;
00384 }
00385
00387 nMuonInducedNeutron += 1;
00389 globalP.SetZ( globalP.Z()-5000 );
00390 if( m_dbOws->geometry()->isInside( globalP ) ) info()<<"inside"<<endreq;
00391 info()<<"local point "<<m_dbOws->geometry()->toLocal( globalP )<<endreq;
00392
00393 Gaudi::XYZPoint localP = m_dbOws->geometry()->toLocal( FirstVtx->position() );
00394 info()<<"local point of neutron vertex "<<localP<<endreq;
00395
00396 if( m_dbOws->geometry()->isInside( FirstVtx->position() ) ) nInOws++;
00397 if( m_dbOil1->geometry()->isInside( FirstVtx->position() ) ) nInOil1++;
00398 if( m_dbOil2->geometry()->isInside( FirstVtx->position() ) ) nInOil2++;
00399 if( m_dbLso1->geometry()->isInside( FirstVtx->position() ) ) nInLso1++;
00400 if( m_dbLso2->geometry()->isInside( FirstVtx->position() ) ) nInLso2++;
00401
00402
00403
00404
00405
00406
00407
00408
00409 }
00410
00411 info()<<"Number of muon induced spallation neutrons: "<<nMuonInducedNeutron<<endreq;
00412 m_valiTree->nNeutron = nMuonInducedNeutron;
00413 m_valiTree->nInOws = nInOws;
00414 m_valiTree->nInOil1 = nInOil1;
00415 m_valiTree->nInOil2 = nInOil2;
00416 m_valiTree->nInLso1 = nInLso1;
00417 m_valiTree->nInLso2 = nInLso2;
00418
00419
00420 return StatusCode::SUCCESS;
00421
00422 }
00423
00424