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

In This Package:

ADSingleTag.cc
Go to the documentation of this file.
00001 #include "ADSingleTag.h"
00002 #include "Event/ReadoutHeader.h"
00003 #include "Event/JobInfo.h"
00004 #include "Conventions/DetectorId.h"
00005 #include "Conventions/JobId.h"
00006 #include "DataSvc/IJobInfoSvc.h"
00007 #include "Event/RecHeader.h"
00008 #include <math.h>
00009 #include "DataUtilities/DybArchiveList.h"
00010 
00011 using namespace std;
00012 using namespace DayaBay;
00013 
00014 ADSingleTag::ADSingleTag(const string& name, ISvcLocator* svcloc) :
00015   GaudiAlgorithm(name, svcloc) {
00016     declareProperty("dtCut",timeCut,
00017         "single time Cut");
00018     declareProperty("location",reclocation,
00019         "location of inputfile");
00020     declareProperty("muonVeto",veto ,
00021         "muon veto or not");
00022     declareProperty("numTag",NumTag,
00023         "every NumTag singles tag a single");
00024     declareProperty("vetoTime",muonVetoTime,
00025         "muon veto window");
00026     declareProperty("outcomelocation",outcomelocation,
00027         "outcomelocation of TES");
00028     declareProperty("maxGapWindow", m_maxGapWindow=0.2*Gaudi::Units::second,
00029         "Maximum Gap between two triggers in one AD"); 
00030   }
00031 
00032 ADSingleTag::~ADSingleTag() {
00033 }
00034 
00035 StatusCode ADSingleTag::initialize() {
00036   debug() << "initialize()" << endreq;
00037 
00038   m_jobInfoSvc = svc<IJobInfoSvc> ("JobInfoSvc", true);
00039   if (!m_jobInfoSvc) {
00040     error() << "Failed to initialize JobInfoSvc" << endreq;
00041     return StatusCode::FAILURE;
00042   }
00043   //Get Archive Svc
00044   StatusCode status = service("EventDataArchiveSvc", p_archiveSvc);
00045   if (status.isFailure()) {
00046     Error("Service [EventDataArchiveSvc] not found", status);
00047   }
00048 
00049   return StatusCode::SUCCESS;
00050 }
00051 
00052 StatusCode ADSingleTag::execute() {
00053   debug() << "execute() ______________________________ start" << endreq;
00054 
00055   // Get ReadoutHeader from TES
00056   if(!exist<RecHeader>(reclocation)) return StatusCode::SUCCESS;
00057   RecHeader* recHeader = get<RecHeader> (reclocation);
00058   DetectorId::DetectorId_t detectorId = recHeader->context().GetDetId();
00059   TimeStamp currentTime(recHeader->timeStamp());
00060   double time = currentTime.GetSec() * 1e9 + currentTime.GetNanoSec();
00061   //  cout <<currentTime.GetNanoSec()<<" "<<detectorId<<endl;
00062   //get muon information caculate deadtime
00063   int i = 0;
00064   SmartDataPtr < DybArchiveList > muonlist(p_archiveSvc, "/Event/Tag/Muon/FirstMuonTrigger");
00065   if (muonlist) {
00066     DybArchiveList::const_iterator iter = muonlist->begin();
00067     for (; iter != muonlist->end(); iter++) {
00068       HeaderObject* muonTag = dynamic_cast<HeaderObject*> (*iter);
00069       TimeStamp muonTime(muonTag->timeStamp());
00070       if (i == 0) {
00071         double muontime = muonTime.GetSec() * 1e9 + muonTime.GetNanoSec();
00072         if (time == muontime) {
00073           if ((muontime - lastmuontime) > 1000000) {
00074             deadtime = deadtime + 1000000;
00075             i = i + 1;
00076             lastmuontime = muontime;
00077           } else {
00078             deadtime = deadtime + muontime - lastmuontime;
00079             i = i + 1;
00080             lastmuontime = muontime;
00081           }
00082           //cout << "muon " << muonTime.GetSec() << " "
00083           //            << muonTime.GetNanoSec() << " " << detectorId << endl;
00084         }
00085       }
00086     }
00087   }
00088 
00089   double dt = currentTime.GetSec() * 1e9 + currentTime.GetNanoSec() - m_lastTimeStamp_map[detectorId].GetSec() * 1e9 - m_lastTimeStamp_map[detectorId].GetNanoSec();
00090   if(dt > m_maxGapWindow && detectorId < 5) {  // long gap in DAQ, the previous multiplets not in memory any more
00091      warning() << "Event gap in AD " << detectorId << ": " << dt/Gaudi::Units::second << " sec" << endreq;
00092   } else {
00093     double lasttimeSec1;
00094     double lasttimeNano1;
00095     double dtSec;
00096     double dtNano;
00097     //  int dtveto=2000000;
00098     //int k = 0;
00099     int b =-1;
00100     //  cout <<dt << endl;
00101     if (dt > timeCut && detectorId < 5) {
00102       int multiplicity = m_adSingleBuffer_map[detectorId].size();
00103       if (multiplicity > 1) {
00104         m_adSingleBuffer_map[detectorId].clear();
00105       }
00106       else if (multiplicity == 1) {
00107         if (veto == 0) {
00108           //      cout<<"muon veto"<<endl;
00109           SmartDataPtr < DybArchiveList > muonlist1(p_archiveSvc, "/Event/Tag/Muon/FirstMuonTrigger");
00110           if (muonlist1) {
00111             DybArchiveList::const_iterator iter1 = muonlist1->begin();
00112             for (; iter1 != muonlist1->end(); iter1++) {
00113               HeaderObject* muonTag1 = dynamic_cast<HeaderObject*> (*iter1);
00114               TimeStamp muonTime1(muonTag1->timeStamp());
00115               TimeStamp lasttime1(m_lastTimeStamp_map[detectorId]);
00116               //   cout <<"muon "<<muonTime1.GetNanoSec()<<" "<<lasttime1.GetNanoSec()<<endl;
00117               if (lasttime1>muonTime1){
00118                 dtveto=lasttime1.GetSec()*1e9+lasttime1.GetNanoSec()-muonTime1.GetSec()*1e9-muonTime1.GetNanoSec();
00119                 //         cout<<"good "<<dtveto<<endl;
00120                 break;
00121               }
00122             }
00123           }
00124           else {dtveto=2000000;
00125           }
00126           //            cout << "dtveto=" << dtveto << endl;
00127           if (dtveto > muonVetoTime) {
00128             //each Numtag tag single
00129             n = n + 1;
00130             b = n % NumTag;
00131           }
00132           if (b == 0) {
00133             // Make a new Header as a tag
00134             HeaderObject *ADSingleTag = new HeaderObject();
00135             // Use inputHeaders to record the RecoutHeader which is connect to this tag
00136             vector<const IHeader*> inputHeaders;
00137             RecHeader* recheader = *(m_adSingleBuffer_map[detectorId].begin());
00138             inputHeaders.push_back(recheader);
00139             ADSingleTag->setInputHeaders(inputHeaders);
00140             // Copy from the RecoutHeader
00141             ADSingleTag->setExecNumber(recheader->execNumber());
00142             ADSingleTag->setContext(recheader->context());
00143             ADSingleTag->setEarliest(recheader->earliest());
00144             ADSingleTag->setLatest(recheader->latest());
00145             // Get job id
00146             const DayaBay::JobId &m_currentJobId = m_jobInfoSvc->currentJobInfo()->jobId();
00147             ADSingleTag->setJobId(m_currentJobId);
00148             // Make different tag according to the detector's id
00149             if (detectorId == DetectorId::kAD1) {
00150               put(ADSingleTag,outcomelocation);
00151             } else if (detectorId == DetectorId::kAD2) {
00152               put(ADSingleTag,outcomelocation);
00153             } else if (detectorId == DetectorId::kAD3) {
00154               put(ADSingleTag,outcomelocation);
00155             } else if (detectorId == DetectorId::kAD4) {
00156               put(ADSingleTag,outcomelocation);
00157             }
00158 
00159             //         cout<<"single veto"<<m_lastTimeStamp_map[detectorId].GetNanoSec()<<" det "<<detectorId<<" "<<n<<endl;
00160             m_adSingleBuffer_map[detectorId].clear();
00161           }
00162 
00163           m_adSingleBuffer_map[detectorId].clear();
00164         }
00165         else if (veto == 1) {
00166           {
00167             n = n + 1;
00168             b = n % NumTag;
00169           }
00170 
00171           if (b == 0) {
00172             // Make a new Header as a tag
00173             HeaderObject *ADSingleTag = new HeaderObject();
00174             // Use inputHeaders to record the RecoutHeader which is connect to this tag
00175             vector<const IHeader*> inputHeaders;
00176             RecHeader* recheader = *(m_adSingleBuffer_map[detectorId].begin());
00177             inputHeaders.push_back(recheader);
00178             ADSingleTag->setInputHeaders(inputHeaders);
00179             // Copy from the RecoutHeader
00180             ADSingleTag->setExecNumber(recheader->execNumber());
00181             ADSingleTag->setContext(recheader->context());
00182             ADSingleTag->setEarliest(recheader->earliest());
00183             ADSingleTag->setLatest(recheader->latest());
00184             // Get job id
00185             const DayaBay::JobId &m_currentJobId =
00186               m_jobInfoSvc->currentJobInfo()->jobId();
00187             ADSingleTag->setJobId(m_currentJobId);
00188             // Make different tag according to the detector's id
00189             if (detectorId == DetectorId::kAD1) {
00190               put(ADSingleTag,outcomelocation);
00191             } else if (detectorId == DetectorId::kAD2) {
00192               put(ADSingleTag,outcomelocation);
00193             } else if (detectorId == DetectorId::kAD3) {
00194               put(ADSingleTag,outcomelocation);
00195             } else if (detectorId == DetectorId::kAD4) {
00196               put(ADSingleTag,outcomelocation);
00197             }
00198 
00199             //      cout<<"single "<<m_lastTimeStamp_map[detectorId].GetNanoSec()<<" det "<<detectorId<<endl;
00200             m_adSingleBuffer_map[detectorId].clear();
00201           }
00202           m_adSingleBuffer_map[detectorId].clear();
00203         }
00204       }
00205     }
00206   }
00207 
00208   m_lastTimeStamp_map[detectorId] = currentTime;
00209   m_adSingleBuffer_map[detectorId].push_back(recHeader);
00210 
00211   //k = k + 1;
00212 
00213   debug() << "execute() ______________________________ end" << endreq;
00214   return StatusCode::SUCCESS;
00215 
00216 }
00217 
00218 StatusCode ADSingleTag::finalize() {
00219   //  string deadtimefile="test.txt";
00220   //    ofstream outputfile;
00221   //      outputfile.open(deadtimefile.c_str());
00222   debug() << "finalize()" << endreq;
00223   info() << "Summary: ADSingleTag : "<<n <<" was tagged."<< endreq;
00224   info() << "deadtime: ADSingleTag : "<<deadtime <<" is."<< endreq;
00225   //  outputfile<< deadtime<< endl;
00226   return StatusCode::SUCCESS;
00227 }
00228 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:11:36 for ADSinglesTagging by doxygen 1.7.4