/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

NeutronSpTightTag.cc
Go to the documentation of this file.
00001 /*****************************
00002 A tight spallation neutron tag, for energy calibration, by FeiHong.
00003 zhangfh@ihep.ac.cn 2011-07-18
00004 *****************************/
00005 
00006 #include <math.h>
00007 #include "NeutronSpTightTag.h"
00008 #include "Event/CalibReadoutHeader.h"
00009 #include "Event/RecHeader.h"
00010 #include "Event/JobInfo.h"
00011 #include "Event/UserDataHeader.h"
00012 #include "Conventions/DetectorId.h"
00013 #include "Conventions/JobId.h"
00014 #include "DataSvc/IJobInfoSvc.h"
00015 #include "DataUtilities/DybArchiveList.h"
00016 #include "GaudiKernel/SystemOfUnits.h"
00017 
00018 
00019 
00020 using namespace std;
00021 using namespace DayaBay;
00022 
00023 
00024 NeutronSpTightTag::NeutronSpTightTag(const string& name, ISvcLocator* svcloc)
00025 : GaudiAlgorithm(name, svcloc)
00026 {
00027   declareProperty("location", m_recHeaderLoc="/Event/Rec/AdSimple", 
00028                   "the TES path of target event header location");
00029   declareProperty("NeutronSpTag_location", m_tagloc="/Event/Tag/Physics/NeutronSpTight", 
00030                   "tagPath: path for spallation neutron tag to put");
00031   declareProperty("first_muon_location", m_muonloc="/Event/Tag/Muon/MuonAll",
00032                   "path for first muon trigger tag");
00033   declareProperty("low_energy_cut", m_eCutLow=6*Gaudi::Units::MeV, 
00034                   "low energy cut, units MeV");
00035   declareProperty("high_energy_cut", m_eCutHigh=10*Gaudi::Units::MeV, 
00036                   "high energy cut, units MeV");
00037   declareProperty("zcut", m_zCut=1500*Gaudi::Units::millimeter, 
00038                   "vertex cut on z direction, units mm");
00039   declareProperty("rcut", m_rCut=1500*Gaudi::Units::millimeter, 
00040                   "vertex cut on r direction, units mm");
00041   declareProperty("time_window_start", m_timeCutLow=15*Gaudi::Units::microsecond, 
00042                   "time window start time, units micro second");
00043   declareProperty("time_window_end", m_timeCutHigh=100*Gaudi::Units::microsecond, 
00044                   "time window end time, units micro second");
00045 }
00046 
00047 NeutronSpTightTag::~NeutronSpTightTag()
00048 {
00049 }
00050 
00051 StatusCode NeutronSpTightTag::initialize()
00052 {
00053   debug() << "initialize()" << endreq;
00054 
00055   m_jobInfoSvc = svc<IJobInfoSvc>("JobInfoSvc",true);
00056   if(!m_jobInfoSvc) {
00057     error() << "Failed to initialize JobInfoSvc" << endreq;
00058     return StatusCode::FAILURE;
00059   }
00060 
00061   //Get Archive Svc
00062   StatusCode status = service("EventDataArchiveSvc", m_archiveSvc);
00063   if (status.isFailure()) {
00064     Error("Service [EventDataArchiveSvc] not found", status);
00065   }
00066 
00067   m_count=0;
00068 
00069   return StatusCode::SUCCESS;
00070 }
00071 
00072 StatusCode NeutronSpTightTag::execute()
00073 {
00074   debug() << "execute() ______________________________ start" << endreq;
00075   
00076   // Get AdSimple
00077   RecHeader* recHeader = get<RecHeader>(m_recHeaderLoc);
00078   if(!recHeader) {
00079     error() << "Get no recHeader from TES!!" << endreq;
00080     return StatusCode::FAILURE;
00081   }
00082 
00083   DetectorId::DetectorId_t detectorId = recHeader->context().GetDetId();
00084   //Only in AD
00085   if(detectorId == DetectorId::kAD1 || detectorId == DetectorId::kAD2
00086       || detectorId == DetectorId::kAD3 || detectorId == DetectorId::kAD4)
00087     {
00088       double E = recHeader->recTrigger().energy()*Gaudi::Units::MeV;
00089       double Z = fabs(recHeader->recTrigger().position().z())*Gaudi::Units::millimeter;
00090       double R = sqrt((recHeader->recTrigger().position().x())*(recHeader->recTrigger().position().x())+(recHeader->recTrigger().position().y())*(recHeader->recTrigger().position().y()))*Gaudi::Units::millimeter;
00091       debug() << "Energy: " << E/Gaudi::Units::MeV << endreq;
00092       debug() << "Z: " << Z/Gaudi::Units::millimeter << endreq;
00093       debug() << "R: " << R/Gaudi::Units::millimeter << endreq;
00094 
00095       //Energy Cut & Vertex Cut
00096       if(E>m_eCutLow && E<m_eCutHigh && Z<m_zCut && R<m_rCut)
00097         {
00098           //Get muon list
00099           
00100           SmartDataPtr<DybArchiveList>  muonlist(m_archiveSvc, m_muonloc);
00101           if(muonlist)
00102             {
00103               debug() << "Number of muon in the ArchiveList: " << muonlist->size() << endreq;
00104             }
00105           else
00106             {
00107               debug() << "No MuonList in AES" << endreq;
00108               return StatusCode::SUCCESS;
00109             }
00110           
00111           DybArchiveList::const_iterator iter = muonlist->begin();
00112           for(; iter!=muonlist->end(); iter++)
00113             {
00114               bool getMuon = false;
00115               HeaderObject* muonTag = dynamic_cast<HeaderObject*>(*iter);
00116               const std::vector<const DayaBay::IHeader*>& muonTagList = muonTag->inputHeaders();
00117               vector<const IHeader*>::const_iterator mit = muonTagList.begin();
00118               for(;mit!=muonTagList.end();mit++)
00119                 {
00120                   HeaderObject* muonTagHeader = dynamic_cast<HeaderObject*>(const_cast<IHeader*>(*mit));
00121                   DetectorId::DetectorId_t muonDetId = muonTagHeader->context().GetDetId();
00122                   TimeStamp muonTime(muonTagHeader->timeStamp());
00123                   TimeStamp currentTime(recHeader->timeStamp());
00124                   currentTime.Subtract(muonTime);
00125                   double deltaT = currentTime.GetSeconds()*Gaudi::Units::second;
00126                   if(deltaT>m_timeCutLow && deltaT<m_timeCutHigh && muonDetId == detectorId)
00127                     {
00128                       //Make a new Header as a tag
00129                       HeaderObject *SpalNTightTag = new HeaderObject();
00130                       // Use inputHeaders to record the RecHeader which is connect to this tag
00131                       vector<const IHeader*> inputHeaders;
00132                       inputHeaders.push_back(recHeader);
00133                       SpalNTightTag->setInputHeaders(inputHeaders);
00134                       // Copy from the recHeader
00135                       SpalNTightTag->setExecNumber(recHeader->execNumber());
00136                       SpalNTightTag->setContext(recHeader->context());
00137                       SpalNTightTag->setEarliest(recHeader->earliest());
00138                       SpalNTightTag->setLatest(recHeader->latest());
00139                       // Get job id
00140                       const DayaBay::JobId &m_currentJobId = m_jobInfoSvc->currentJobInfo()->jobId();
00141                       SpalNTightTag->setJobId(m_currentJobId);
00142                       
00143                       put(SpalNTightTag, m_tagloc);
00144                       m_count++;
00145                       debug() << "N Tagged: " << m_count<< endreq;
00146                       debug() << "DeltaT: " << deltaT/Gaudi::Units::second << endreq;
00147                       getMuon = true;
00148                       break;
00149                     }
00150                 }
00151               if(getMuon==true) break;
00152             }
00153         }
00154     }
00155   debug() << "execute() ______________________________ end" << endreq;
00156   return StatusCode::SUCCESS;
00157 }
00158 
00159 StatusCode NeutronSpTightTag::finalize()
00160 {
00161   debug() << "finalize()" << endreq;
00162   info() << "Summary: Tagger NeutronSpLooseTag : "<< m_count <<" events tagged at "<< m_tagloc << endreq;
00163   return StatusCode::SUCCESS;
00164 }
00165 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:10:37 for SpNeutronTagging by doxygen 1.7.4