/search.css" rel="stylesheet" type="text/css"/> /search.js">
00001 #include "Co60Tag.h" 00002 #include "Event/ReadoutHeader.h" 00003 #include "Event/CalibReadoutHeader.h" 00004 #include "Event/RecHeader.h" 00005 #include "Event/HeaderObject.h" 00006 #include "Event/UserDataHeader.h" 00007 #include "Event/JobInfo.h" 00008 #include "Conventions/JobId.h" 00009 #include "DataSvc/IJobInfoSvc.h" 00010 #include "GaudiKernel/SystemOfUnits.h" 00011 00012 00013 Co60Tag::Co60Tag(const std::string& name, ISvcLocator* svcloc) 00014 : GaudiAlgorithm(name, svcloc) 00015 { 00016 declareProperty("CalibStatsLocation", m_calibStatsLocation="/Event/Data/CalibStats", 00017 "Location of CalibStats User data"); 00018 declareProperty("RecHeaderLocation", m_recHeaderLocation="/Event/Rec/AdSimple", 00019 "Location of RecHeader"); 00020 declareProperty("MuonLooseLocation", m_muonLooseLocation="/Event/Tag/Physics/MuonLoose", 00021 "Location of Muon Loose Tags"); 00022 declareProperty("Co60Location", m_Co60Location="/Event/Tag/Calib/Co60", 00023 "Location of Co60 Tag"); 00024 00025 declareProperty("VertexCut", m_vertexCut = 0.5 * Gaudi::Units::m, 00026 "Radius of the spherical vertex cut"); 00027 declareProperty("MuonVetoTime", m_muonVetoTime = 1.0 * Gaudi::Units::ms, 00028 "Duration of muon veto after a \" loose muon\"."); 00029 } 00030 00031 Co60Tag::~Co60Tag() 00032 { 00033 } 00034 00035 StatusCode Co60Tag::initialize() 00036 { 00037 debug() << "initialize()" << endreq; 00038 00039 m_jobInfoSvc = svc<IJobInfoSvc>("JobInfoSvc",true); 00040 if(!m_jobInfoSvc) { 00041 error() << "Failed to initialize JobInfoSvc" << endreq; 00042 return StatusCode::FAILURE; 00043 } 00044 m_tagged = 0; 00045 m_freshStart = true; 00046 00047 return StatusCode::SUCCESS; 00048 } 00049 00050 StatusCode Co60Tag::execute() 00051 { 00052 debug() << "execute() ______________________________ start" << endreq; 00053 00054 //---------------------------------------- 00055 // Get all necessary headers 00056 //---------------------------------------- 00057 00058 const DayaBay::RecHeader * recHdr = 0; 00059 DayaBay::UserDataHeader *calibStatsHdr = 0; // 00060 00061 // Get CalibStats Header 00062 if (!exist<DayaBay::UserDataHeader>(evtSvc(), m_calibStatsLocation)) { 00063 warning() << "Cannot find header at " << m_calibStatsLocation << endreq; 00064 return StatusCode::FAILURE; 00065 } else { 00066 calibStatsHdr = get<DayaBay::UserDataHeader>(m_calibStatsLocation); 00067 } 00068 00069 // Get Rec Header 00070 if ( !exist<DayaBay::RecHeader>(evtSvc(), m_recHeaderLocation)) { 00071 warning() << "Cannot find header at " << m_recHeaderLocation << endreq; 00072 return StatusCode::FAILURE; 00073 } else { 00074 recHdr = get<DayaBay::RecHeader>(m_recHeaderLocation); 00075 } 00076 const DayaBay::RecTrigger& recTrigger = recHdr->recTrigger(); 00077 00078 DetectorId::DetectorId_t detectorId = recHdr->context().GetDetId(); 00079 TimeStamp triggerTime = recTrigger.triggerTime(); 00080 00081 //---------------------------------------- 00082 // Actual checking 00083 //---------------------------------------- 00084 00085 // Fresh start! Assume it is muon event and skip. 00086 if(m_freshStart){ 00087 debug() << "Fresh start! Assume it is muon event and skip." << endreq; 00088 m_lastMuonTime = triggerTime; 00089 m_freshStart = false; 00090 return StatusCode::SUCCESS; 00091 } 00092 00093 // Check if it is a muon, if so, start veto and skip. 00094 bool isMuon = exist<DayaBay::HeaderObject>(evtSvc(), m_muonLooseLocation); 00095 if (isMuon){ 00096 debug() << "Muon found! Start veto and skip." << endreq; 00097 m_lastMuonTime = triggerTime; 00098 return StatusCode::SUCCESS; 00099 } 00100 00101 // Only consider AD triggers 00102 if (!(detectorId == DetectorId::kAD1 || detectorId == DetectorId::kAD2 00103 || detectorId == DetectorId::kAD3 || detectorId == DetectorId::kAD4)) { 00104 debug() << "Non-AD trigger. Skip." << endreq; 00105 return StatusCode::SUCCESS; 00106 } 00107 00108 // Apply muon veto 00109 TimeStamp timeSinceLastMuon = TimeStamp(triggerTime); 00110 timeSinceLastMuon.Subtract(m_lastMuonTime); 00111 debug() << "Current trigger time: " << triggerTime.AsString() << endreq; 00112 debug() << "Last muon time : " << m_lastMuonTime.AsString() << endreq; 00113 debug() << "Time since last muon: " << timeSinceLastMuon.GetSeconds() << endreq; 00114 if (timeSinceLastMuon.GetSeconds() * Gaudi::Units::s < m_muonVetoTime){ 00115 //Muon veto on! 00116 debug() << "Muon veto on! Skip." << endreq; 00117 return StatusCode::SUCCESS; 00118 } 00119 00120 // Skip if recon has failed 00121 float recES = recTrigger.energyStatus(); 00122 float recPS = recTrigger.positionStatus(); 00123 if (recES != 1 || recPS != 1){ 00124 debug() << "Recon failed. Skip." << endreq; 00125 return StatusCode::SUCCESS; 00126 } 00127 00128 // Apply spherical position cut 00129 // FIXME: Source position is hard-coded to be AD center! 00130 float recX = recTrigger.position().x() / Gaudi::Units::mm; 00131 float recY = recTrigger.position().y() / Gaudi::Units::mm; 00132 float recZ = recTrigger.position().z() / Gaudi::Units::mm; 00133 float posX = 0; 00134 float posY = 0; 00135 float posZ = 0; 00136 float delX = recX - posX; 00137 float delY = recY - posY; 00138 float delZ = recZ - posZ; 00139 float delR2 = delX*delX + delY*delY + delZ*delZ; 00140 debug() << "Source position: ("<< posX << ", " << posY << ", " << posZ << ")" << endreq; 00141 debug() << "Recon position : ("<< recX << ", " << recY << ", " << recZ << ")" << endreq; 00142 if (delR2 > m_vertexCut * m_vertexCut){ 00143 debug() << "Recon position lies outside of the vertex cut! Skip." << endreq; 00144 return StatusCode::SUCCESS; 00145 } 00146 00147 //---------------------------------------- 00148 // Got a candidate, let's tag it! 00149 //---------------------------------------- 00150 00151 // Tag as Co60 event 00152 DayaBay::HeaderObject *header = new DayaBay::HeaderObject(); 00153 std::vector<const DayaBay::IHeader*> inputHeaders; 00154 inputHeaders.push_back(recHdr); 00155 inputHeaders.push_back(calibStatsHdr); 00156 header->setInputHeaders(inputHeaders); 00157 header->setExecNumber(recHdr->execNumber()); 00158 header->setContext(recHdr->context()); 00159 header->setEarliest(recHdr->earliest()); 00160 header->setLatest(recHdr->latest()); 00161 m_tagged++; 00162 00163 const DayaBay::JobId &m_currentJobId = m_jobInfoSvc->currentJobInfo()->jobId(); 00164 header->setJobId(m_currentJobId); 00165 00166 put(header, m_Co60Location); 00167 00168 debug() << "execute() ______________________________ end" << endreq; 00169 return StatusCode::SUCCESS; 00170 } 00171 00172 StatusCode Co60Tag::finalize() 00173 { 00174 debug() << "finalize()" << endreq; 00175 switch(m_tagged){ 00176 case 0: info () << "No trigger was tagged as Co60 event." << endreq; break; 00177 case 1: info () << "Only one trigger was tagged as Co60 event." << endreq; break; 00178 default: info () << m_tagged << " triggers were tagged as Co60 events." << endreq; 00179 } 00180 return StatusCode::SUCCESS; 00181 } 00182