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

In This Package:

NeutronSpLooseData.cc
Go to the documentation of this file.
00001 /*
00002  * NeutronSpLooseData
00003  *
00004  * Store useful spallation neutron data
00005  *
00006  * Created by: zhangfh@ihep.ac.cn 2011/08/04
00007  */
00008 
00009 #include "NeutronSpLooseData.h"
00010 
00011 #include <math.h>
00012 #include "Event/RecHeader.h"
00013 #include "Event/JobInfo.h"
00014 #include "Event/UserDataHeader.h"
00015 #include "Event/CalibReadoutHeader.h"
00016 #include "Conventions/DetectorId.h"
00017 #include "Conventions/JobId.h"
00018 #include "DataSvc/IJobInfoSvc.h"
00019 #include "DataUtilities/DybArchiveList.h"
00020 
00021 #include "GaudiKernel/SystemOfUnits.h"
00022 #include "TMath.h"
00023 #include "TString.h"
00024 
00025 using namespace std;
00026 using namespace DayaBay;
00027 
00028 
00029 NeutronSpLooseData::NeutronSpLooseData(const std::string& name, ISvcLocator* pSvcLocator)
00030   : DybAlgorithm<DayaBay::UserDataHeader>(name,pSvcLocator)
00031 {
00032   declareProperty("NeutronSpTag_location", m_neutronSpTagLoc="/Event/Tag/Physics/NeutronSpLoose", 
00033                   "Path for spallation neutron tag");
00034   declareProperty("first_muon_location", m_muonloc="/Event/Tag/Muon/MuonAll",
00035                   "path for first muon trigger tag");
00036 }
00037 
00038 NeutronSpLooseData::~NeutronSpLooseData()
00039 {
00040 }
00041 
00042 StatusCode NeutronSpLooseData::initialize()
00043 {
00044   debug() << "initialize()" << endreq;
00045 
00046   m_jobInfoSvc = svc<IJobInfoSvc>("JobInfoSvc",true);
00047   if(!m_jobInfoSvc) {
00048     error() << "Failed to initialize JobInfoSvc" << endreq;
00049     return StatusCode::FAILURE;
00050   }
00051 
00052   //Get Archive Svc
00053   StatusCode status = service("EventDataArchiveSvc", m_archiveSvc);
00054   if (status.isFailure()) {
00055     Error("Service [EventDataArchiveSvc] not found", status);
00056     return status;
00057   }
00058 
00059   m_count=0;
00060 
00061   return StatusCode::SUCCESS;
00062 }
00063 
00064 StatusCode NeutronSpLooseData::execute()
00065 {
00066   debug() << "execute() ______________________________ start" << endreq;
00067   
00068   // Get tagged spallation neutron recHeader
00069   if(!exist<HeaderObject>(m_neutronSpTagLoc)) {
00070     return StatusCode::SUCCESS;
00071   }
00072 
00073   HeaderObject *neutronSpTag = get<HeaderObject>(m_neutronSpTagLoc);
00074   if(!neutronSpTag) {
00075     error() << "Get no neutronSpTag from TES." << endreq;
00076     return StatusCode::FAILURE;
00077   }
00078   
00079   const std::vector<const DayaBay::IHeader*>& recHeaderList = neutronSpTag->inputHeaders();
00080 
00081   // For NeutronSpTag, only one recHeader in each inputHeaders.
00082   const RecHeader* recHeader = dynamic_cast<const RecHeader*> (recHeaderList[0]);
00083   if(!recHeader) {
00084     error() << "Get no recHeader from NeutronSpTag!!" << endreq;
00085     return StatusCode::FAILURE;
00086   }
00087 
00088   // Create output user data header
00089   UserDataHeader* neutronSpData = MakeHeaderObject();
00090 
00091   // Copy from the recHeader
00092   neutronSpData->setExecNumber(recHeader->execNumber());
00093   neutronSpData->setContext(recHeader->context());
00094   neutronSpData->setEarliest(recHeader->earliest());
00095   neutronSpData->setLatest(recHeader->latest());
00096 
00097 
00098   // Get job id
00099   const DayaBay::JobId &m_currentJobId = m_jobInfoSvc->currentJobInfo()->jobId();
00100   neutronSpData->setJobId(m_currentJobId);
00101 
00102   float energy=recHeader->recTrigger().energy();
00103   float x=recHeader->recTrigger().position().x();
00104   float y=recHeader->recTrigger().position().y();
00105   float z=recHeader->recTrigger().position().z();
00106   TimeStamp trigTime(recHeader->timeStamp());
00107   int trigTimeSec=trigTime.GetSec();
00108   int trigTimeNanoSec=trigTime.GetNanoSec();
00109   int detectorId = recHeader->context().GetDetId();
00110 
00111   int muonTimeSec=0;
00112   int muonTimeNanoSec=0;
00113   float deltaT = 0;
00114   float muonPESum = 0;
00115 
00116   float nPESum=0;
00117   float nPEMax=0;
00118   float tRMS=0;
00119   //Get muon list         
00120   SmartDataPtr<DybArchiveList>  muonlist(m_archiveSvc, m_muonloc);
00121   if(muonlist)
00122     {
00123       debug() << "Number of muon in the ArchiveList: " << muonlist->size() << endreq;
00124     }
00125   else
00126     {
00127       error() << "No MuonList for NeutronSpTag event?!" << endreq;
00128       return StatusCode::FAILURE;
00129     }
00130   DybArchiveList::const_iterator iter = muonlist->begin();
00131   for(; iter!=muonlist->end(); iter++)
00132     {
00133       HeaderObject* muonTag = dynamic_cast<HeaderObject*>(*iter);
00134       //const std::vector<const DayaBay::IHeader*>& muonTagList = muonTag->inputHeaders();
00135       //HeaderObject* muonTagHeader = dynamic_cast<HeaderObject*>(const_cast<IHeader*>(muonTagList[0]));
00136       //const std::vector<const DayaBay::IHeader*>& muonIHeaders = muonTagHeader->inputHeaders();
00137       //info() << "muonIHeaders=" << muonIHeaders.size() << endreq;
00138       //UserDataHeader* muonClbStsHdr = dynamic_cast<UserDataHeader*>(dynamic_cast<HeaderObject*>(const_cast<IHeader*>(muonIHeaders[1])));
00139 
00140       // Make it compatible with both python and C++ muon tag
00141       // Find CalibReadoutHeader
00142       const std::vector<const IHeader*> &crhs = muonTag->findHeaders(CalibReadoutHeader::classID());
00143       HeaderObject* muonTagHeader = dynamic_cast<HeaderObject*>(const_cast<IHeader*>(crhs[0]));
00144 
00145       /*
00146       for(unsigned int i = 0; i < crhs.size(); i++) {
00147         IHeader* iHeader = const_cast<IHeader*>(crhs[i]);
00148         HeaderObject* header = dynamic_cast<HeaderObject*>(iHeader);
00149         debug() << header->name() << ", " << header->context() << endreq;
00150         if(header->context().GetDetId() == detectorId) {
00151           muonTagHeader = header;
00152           break;
00153         }
00154       }
00155       */
00156 
00157       // Find CalibStatsHeader
00158       const std::vector<const IHeader*> &calibstats = muonTag->findHeaders(UserDataHeader::classID());
00159       UserDataHeader* muonClbStsHdr = dynamic_cast<UserDataHeader*>(const_cast<IHeader*>(calibstats[0]));
00160 
00161       /*
00162       for(unsigned int i = 0; i < calibstats.size(); i++) {
00163         IHeader* iHeader = const_cast<IHeader*>(calibstats[i]);
00164         UserDataHeader* header = dynamic_cast<UserDataHeader*>(iHeader);
00165         debug() << header->name() << ", " << header->context() << endreq;
00166         if(header->name()!="/CalibStats") continue;
00167         if(header->context().GetDetId() == detectorId) {
00168           muonClbStsHdr = header;
00169           break;
00170         }
00171       }
00172       */
00173 
00174       if(muonTagHeader) {
00175         TimeStamp muonTime(muonTag->timeStamp());
00176         muonTimeSec=muonTime.GetSec();
00177         muonTimeNanoSec=muonTime.GetNanoSec();
00178         TimeStamp currentTime(recHeader->timeStamp());
00179         currentTime.Subtract(muonTime);
00180         deltaT = currentTime.GetSeconds();
00181         debug() << "DeltaT: " << deltaT << endreq;
00182       }
00183       if(muonClbStsHdr) {
00184         muonPESum = muonClbStsHdr->getFloat("nPESum");
00185         debug() << "nPESum: " << muonPESum << endreq;
00186       }
00187 
00188       break;
00189     }
00190 
00191   debug()<<"energy:"<<energy<<";x:"<<x<<";y:"<<y<<";z:"<<z<<";timeToMuon:"<<deltaT<<";detectorId:"<<detectorId<<endreq;
00192 
00193   //Get some calibstats data
00194   const std::vector<const IHeader*> &calibstats = neutronSpTag->findHeaders(UserDataHeader::classID());
00195   UserDataHeader* spNeutronClbStsHdr = 0;
00196   for(unsigned int i = 0; i < calibstats.size(); i++) {
00197     IHeader* iHeader = const_cast<IHeader*>(calibstats[i]);
00198     UserDataHeader* header = dynamic_cast<UserDataHeader*>(iHeader);
00199     debug() << header->name() << ", " << header->context() << endreq;
00200     if(header->name()!="/CalibStats") continue;
00201     if(header->context().GetDetId() == detectorId) {
00202       spNeutronClbStsHdr = header;
00203       break;
00204     }
00205   }
00206   if(spNeutronClbStsHdr) {
00207     nPESum = spNeutronClbStsHdr->getFloat("nPESum");
00208     nPEMax = spNeutronClbStsHdr->getFloat("nPEMax");
00209     tRMS   = spNeutronClbStsHdr->getFloat("tRMS");
00210     debug() << "nPESum: " << nPESum <<";nPEMax: "<<nPEMax<<";tRMS: "<<tRMS<< endreq;
00211   }
00212 
00213   // Fill user data
00214   neutronSpData->set("energy", energy);
00215   neutronSpData->set("x", x);
00216   neutronSpData->set("y", y);
00217   neutronSpData->set("z", z);
00218   neutronSpData->set("trigTimeSec", trigTimeSec);
00219   neutronSpData->set("trigTimeNanoSec", trigTimeNanoSec);
00220   neutronSpData->set("timeToMuon", deltaT);
00221   neutronSpData->set("detectorId", detectorId);
00222   neutronSpData->set("muonTimeSec", muonTimeSec);
00223   neutronSpData->set("muonTimeNanoSec", muonTimeNanoSec);
00224   neutronSpData->set("muonPESum", muonPESum);
00225   neutronSpData->set("nPESum", nPESum);
00226   neutronSpData->set("nPEMax", nPEMax);
00227   neutronSpData->set("tRMS", tRMS);
00228   m_count++;
00229   debug() << "execute() ______________________________ end" << endreq;
00230   return StatusCode::SUCCESS;
00231 }
00232 
00233 StatusCode NeutronSpLooseData::finalize()
00234 {
00235   debug() << "finalize()" << endreq;
00236   info() << "Summary: UserData NeutronSpLooseData : "<< m_count <<" events data filled."<< endreq;
00237   return StatusCode::SUCCESS;
00238 }
00239 
00240 
| 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