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

In This Package:

DetLatency.cc
Go to the documentation of this file.
00001 #include "DetLatency.h"
00002 #include "Event/Readout.h"
00003 #include "Event/CalibReadout.h"
00004 #include "Event/CalibReadoutPmtCrate.h"
00005 #include "Event/CalibReadoutPmtChannel.h"
00006 #include "Event/RunData.h"
00007 #include "DataSvc/ICableSvc.h"
00008 #include "DataSvc/ICalibDataSvc.h"
00009 #include "Event/RawEventHeader.h"
00010 #include <math.h>
00011 #include <fstream>
00012 #include "TMath.h"
00013 
00014 #include "Event/RegistrationSequence.h"
00015 #include "Event/CalibReadoutHeader.h"
00016 #include "Event/CalibReadoutPmtCrate.h"
00017 #include "Event/ReadoutHeader.h"
00018 #include "Event/ReadoutPmtCrate.h"
00019 #include "Event/RawEventHeader.h"
00020 #include "Event/GenHeader.h"
00021 #include "HepMC/GenEvent.h"
00022 #include "HepMC/GenVertex.h"
00023 #include "Event/RecHeader.h"
00024 #include "Event/TagHeader.h"
00025 #include "DataUtilities/DybArchiveList.h"
00026 #include "GaudiKernel/SmartDataPtr.h"
00027 
00028 DetLatency::DetLatency(const std::string& name, ISvcLocator* pSvcLocator):
00029   GaudiAlgorithm(name, pSvcLocator)
00030 {
00031   declareProperty("FileName", m_fileName = "AdcFit.root", "Root file name");
00032   declareProperty("FitPeriod", m_fitPeriod = 30*60, "Fit period in second, Default is 30 minutes");
00033   declareProperty("Fix", m_Fix = 0, "a temp fix for 40M noise");
00034   declareProperty("Offset",  m_Trig_Interval_Offset_ns=1000, "Muon trigger time calculate range for latency in ns");
00035 
00036   m_NTrigger=0;
00037   m_NStop = 1;
00038   m_startrun = -1;
00039   m_currentrun = -1;
00040   m_execNum=0;  
00041 }
00042 
00043 
00044 DetLatency::~DetLatency()
00045 {
00046 }
00047 
00048 
00049 void DetLatency::Fit(){
00050 
00051   //cout<<"Fitting"<<endl;
00052   ostringstream tmp;
00053   tmp <<setw(2) <<setfill('0') << m_NStop;
00054   string filename = "trigLatencyTable_"+tmp.str()+".txt";
00055   FILE* outfile = fopen(filename.c_str(), "w+");
00056   
00057   fprintf(outfile, "# First Trigger time: (TrigSecond, TrigNanoSec) = (%d,%d).\n", m_FirstTrigSecond, m_FirstTrigNanoSec);
00058   fprintf(outfile, "# Last Trigger time: (TrigSecond, TrigNanoSec) = (%d,%d).\n", m_LastTrigSecond, m_LastTrigNanoSec);
00059   fprintf(outfile, "# [detId] [description] [status] [trigLat] [trigLatErr] [trigLatSigma] [trigLatSigmaErr]\n");
00060 
00061   m_rootfile->cd();
00062   string newdir = tmp.str();
00063   m_rootfile->mkdir(newdir.c_str());
00064   m_rootfile->cd(newdir.c_str());
00065 
00066   m_masterfile = fopen("Master.trigLatencyCalibMap.txt", "a");
00067   TimeStamp lastT1(m_LastTrigSecond,m_LastTrigNanoSec+1);
00068   fprintf(m_masterfile, "0000000 0000000 %4.0d %4.0d %10.0d %10.0d %10.0d %10.0d %s\n",
00069           m_site, m_simFlag, m_FirstTrigSecond,m_FirstTrigNanoSec,(int)lastT1.GetSec(),lastT1.GetNanoSec(),filename.c_str());
00070   fclose(m_masterfile);
00071 
00072   m_StartTime = m_FirstTrigSecond + m_FirstTrigNanoSec*1e-9;
00073   m_EndTime = m_LastTrigSecond + m_LastTrigNanoSec*1e-9;
00074   
00075   //cout<<"Test 0"<<endl;
00076 
00077 
00078       double pedarea=0;
00079       double pedmean=0;
00080       double pedsigm=0;
00081       int status1=0;
00082      int tester=0;
00083   //cout<<"Test 1"<<endl;
00084   //cout<<"h_TrigT_AD1->GetEntries()="<<h_TrigT_AD1->GetEntries()<<endl;
00085   if(h_TrigT_AD1->GetEntries()>0)
00086   {    
00087       pedarea = h_TrigT_AD1->GetEntries();
00088       pedmean = h_TrigT_AD1->GetMean();
00089       pedsigm = h_TrigT_AD1->GetRMS();
00090       f1->SetParameters(pedarea,pedmean,pedsigm);
00091       f1->SetRange(pedmean-3*pedsigm,pedmean+3*pedsigm);
00092       status1 = h_TrigT_AD1->Fit("f1","R");
00093       
00095 
00096       trigLatencyAD1Status=status1;
00097        trigLatencyAD1= f1->GetParameter(1);
00098       trigLatencyAD1Err= f1->GetParError(1);
00099       trigLatencyAD1Sigma = f1->GetParameter(2);
00100       trigLatencyAD1SigmaErr= f1->GetParError(2);
00101 
00102       //cout<<"1"<<tester++<<endl;
00103      fprintf(outfile, "%d %s %2d %8.3f %8.3f %8.3f %8.3f\n",DetectorId::kAD1, DetectorId::AsString(DetectorId::kAD1),trigLatencyAD1Status, trigLatencyAD1, trigLatencyAD1Err, trigLatencyAD1Sigma, trigLatencyAD1SigmaErr);
00104 
00105       //cout<<"2"<<tester++<<endl;   
00106 
00107       h_TrigT_AD1->Write();
00108       //cout<<"3"<<tester++<<endl;
00109       h_CalibTrigT->Fill(trigLatencyAD1);
00110       //cout<<"4"<<tester++<<endl;
00111       h_CalibTrigTErr->Fill(trigLatencyAD1Err);
00112       //cout<<"5"<<tester++<<endl;
00113       //cout<<"trigLatencyAD1Sigma="<<trigLatencyAD1Sigma<<endl;
00114       h_CalibTrigTSigma->Fill(trigLatencyAD1Sigma);
00115       //cout<<"6"<<tester++<<endl;
00116       h_CalibTrigTSigmaErr->Fill(trigLatencyAD1SigmaErr);
00117       //cout<<"7"<<tester++<<endl;
00118   }
00119   //cout<<"h_TrigT_AD2->GetEntries()="<<h_TrigT_AD2->GetEntries()<<endl;
00120   if(h_TrigT_AD2->GetEntries()>0)
00121   {
00122       pedarea = h_TrigT_AD2->GetEntries();
00123       pedmean = h_TrigT_AD2->GetMean();
00124       pedsigm = h_TrigT_AD2->GetRMS();
00125       f2->SetParameters(pedarea,pedmean,pedsigm);
00126       f2->SetRange(pedmean-3*pedsigm,pedmean+3*pedsigm);
00127       status1 = h_TrigT_AD2->Fit("f2","R");
00128 
00129       trigLatencyAD2Status=status1;
00130       h_TrigT_All->Fill(trigLatencyAD1);
00131       trigLatencyAD2= f2->GetParameter(1);
00132       trigLatencyAD2Err= f2->GetParError(1);
00133       trigLatencyAD2Sigma = f2->GetParameter(2);
00134       trigLatencyAD2SigmaErr= f2->GetParError(2);
00135 
00136       fprintf(outfile, "%d %s %2d %8.3f %8.3f %8.3f %8.3f\n", DetectorId::kAD2, DetectorId::AsString(DetectorId::kAD2), trigLatencyAD2Status, trigLatencyAD2, trigLatencyAD2Err, trigLatencyAD2Sigma, trigLatencyAD2SigmaErr);
00137       
00138       h_TrigT_AD2->Write();
00139       h_TrigT_All->Fill(trigLatencyAD2);
00140       h_CalibTrigT->Fill(trigLatencyAD2);
00141       h_CalibTrigTErr->Fill(trigLatencyAD2Err);
00142       h_CalibTrigTSigma->Fill(trigLatencyAD2Sigma);
00143       h_CalibTrigTSigmaErr->Fill(trigLatencyAD2SigmaErr);
00144   }
00145   
00146     //cout<<"h_TrigT_AD3->GetEntries()="<<h_TrigT_AD3->GetEntries()<<endl;
00147   if(h_TrigT_AD3->GetEntries()>0)
00148   {
00149       pedarea = h_TrigT_AD3->GetEntries();
00150       pedmean = h_TrigT_AD3->GetMean();
00151       pedsigm = h_TrigT_AD3->GetRMS();
00152       f3->SetParameters(pedarea,pedmean,pedsigm);
00153       f3->SetRange(pedmean-3*pedsigm,pedmean+3*pedsigm);
00154       status1 = h_TrigT_AD3->Fit("f3","R");
00155 
00156       trigLatencyAD3Status=status1;
00157        trigLatencyAD3= f3->GetParameter(1);
00158       trigLatencyAD3Err= f3->GetParError(1);
00159       trigLatencyAD3Sigma = f3->GetParameter(2);
00160       trigLatencyAD3SigmaErr= f3->GetParError(2);
00161       fprintf(outfile, "%d %s %2d %8.3f %8.3f %8.3f %8.3f\n", DetectorId::kAD3, DetectorId::AsString(DetectorId::kAD3),trigLatencyAD3Status, trigLatencyAD3, trigLatencyAD3Err, trigLatencyAD3Sigma, trigLatencyAD3SigmaErr);
00162 
00163       h_TrigT_AD3->Write();
00164       h_TrigT_All->Fill(trigLatencyAD3);
00165       h_CalibTrigT->Fill(trigLatencyAD3);
00166       h_CalibTrigTErr->Fill(trigLatencyAD3Err);
00167       h_CalibTrigTSigma->Fill(trigLatencyAD3Sigma);
00168       h_CalibTrigTSigmaErr->Fill(trigLatencyAD3SigmaErr);
00169   }
00170   if(h_TrigT_AD4->GetEntries()>0)
00171   {
00172       pedarea = h_TrigT_AD4->GetEntries();
00173       pedmean = h_TrigT_AD4->GetMean();
00174       pedsigm = h_TrigT_AD4->GetRMS();
00175       f4->SetParameters(pedarea,pedmean,pedsigm);
00176       f4->SetRange(pedmean-3*pedsigm,pedmean+3*pedsigm);
00177       status1 = h_TrigT_AD4->Fit("f4","R");
00178 
00179       trigLatencyAD4Status=status1;
00180        trigLatencyAD4= f4->GetParameter(1);
00181       trigLatencyAD4Err= f4->GetParError(1);
00182       trigLatencyAD4Sigma = f4->GetParameter(2);
00183       trigLatencyAD4SigmaErr= f4->GetParError(2);
00184       fprintf(outfile, "%d %s %2d %8.3f %8.3f %8.3f %8.3f\n", DetectorId::kAD4, DetectorId::AsString(DetectorId::kAD4),trigLatencyAD4Status, trigLatencyAD4, trigLatencyAD4Err, trigLatencyAD4Sigma, trigLatencyAD4SigmaErr);
00185 
00186       h_TrigT_AD4->Write();
00187       h_TrigT_All->Fill(trigLatencyAD4);
00188       h_CalibTrigT->Fill(trigLatencyAD4);
00189       h_CalibTrigTErr->Fill(trigLatencyAD4Err);
00190       h_CalibTrigTSigma->Fill(trigLatencyAD4Sigma);
00191       h_CalibTrigTSigmaErr->Fill(trigLatencyAD4SigmaErr);
00192   }
00193     //cout<<"h_TrigT_IWS->GetEntries()="<<h_TrigT_IWS->GetEntries()<<endl;
00194   if(h_TrigT_IWS->GetEntries()>0)
00195   {
00196       pedarea = h_TrigT_IWS->GetEntries();
00197       pedmean = h_TrigT_IWS->GetMean();
00198       pedsigm = h_TrigT_IWS->GetRMS();
00199       f5->SetParameters(pedarea,pedmean,pedsigm);
00200       f5->SetRange(pedmean-3*pedsigm,pedmean+3*pedsigm);
00201       status1 = h_TrigT_IWS->Fit("f5","R");
00202 
00203       trigLatencyIWSStatus=status1;
00204        trigLatencyIWS= f5->GetParameter(1);
00205       trigLatencyIWSErr= f5->GetParError(1);
00206       trigLatencyIWSSigma = f5->GetParameter(2);
00207       trigLatencyIWSSigmaErr= f5->GetParError(2);
00208       fprintf(outfile, "%d %s %2d %8.3f %8.3f %8.3f %8.3f\n", DetectorId::kIWS, DetectorId::AsString(DetectorId::kIWS), trigLatencyIWSStatus, trigLatencyIWS, trigLatencyIWSErr, trigLatencyIWSSigma, trigLatencyIWSSigmaErr);
00209 
00210       h_TrigT_IWS->Write();
00211       h_TrigT_All->Fill(trigLatencyIWS);
00212       h_CalibTrigT->Fill(trigLatencyIWS);
00213       h_CalibTrigTErr->Fill(trigLatencyIWSErr);
00214       h_CalibTrigTSigma->Fill(trigLatencyIWSSigma);
00215       h_CalibTrigTSigmaErr->Fill(trigLatencyIWSSigmaErr);
00216   }
00217 
00218  // //cout<<"h_TrigT_OWS->GetEntries()="<<h_TrigT_OWS->GetEntries()<<endl;
00219   if(h_TrigT_OWS->GetEntries()>0)
00220   {
00221       pedarea = h_TrigT_OWS->GetEntries();
00222       pedmean = h_TrigT_OWS->GetMean();
00223       pedsigm = h_TrigT_OWS->GetRMS();
00224       f6->SetParameters(pedarea,pedmean,pedsigm);
00225       f6->SetRange(pedmean-3*pedsigm,pedmean+3*pedsigm);
00226       status1 = h_TrigT_OWS->Fit("f6","R");
00227 
00228       trigLatencyOWSStatus=status1;
00229        trigLatencyOWS= f6->GetParameter(1);
00230       trigLatencyOWSErr= f6->GetParError(1);
00231       trigLatencyOWSSigma = f6->GetParameter(2);
00232       trigLatencyOWSSigmaErr= f6->GetParError(2);
00233       fprintf(outfile, "%d %s %2d %8.3f %8.3f %8.3f %8.3f\n", DetectorId::kOWS, DetectorId::AsString(DetectorId::kOWS), trigLatencyOWSStatus, trigLatencyOWS, trigLatencyOWSErr, trigLatencyOWSSigma, trigLatencyOWSSigmaErr);
00234 
00235       h_TrigT_OWS->Write();
00236       h_TrigT_All->Fill(trigLatencyOWS);
00237       h_CalibTrigT->Fill(trigLatencyOWS);
00238       h_CalibTrigTErr->Fill(trigLatencyOWSErr);
00239       h_CalibTrigTSigma->Fill(trigLatencyOWSSigma);
00240       h_CalibTrigTSigmaErr->Fill(trigLatencyOWSSigmaErr);
00241   }
00242   if(h_TrigT_RPC->GetEntries()>0)
00243   {
00244       pedarea = h_TrigT_RPC->GetEntries();
00245       pedmean = h_TrigT_RPC->GetMean();
00246       pedsigm = h_TrigT_RPC->GetRMS();
00247       f7->SetParameters(pedarea,pedmean,pedsigm);
00248       f7->SetRange(pedmean-3*pedsigm,pedmean+3*pedsigm);
00249       status1 = h_TrigT_RPC->Fit("f7","R");
00250 
00251       trigLatencyRPCStatus=status1;
00252        trigLatencyRPC= f7->GetParameter(1);
00253       trigLatencyRPCErr= f7->GetParError(1);
00254       trigLatencyRPCSigma = f7->GetParameter(2);
00255       trigLatencyRPCSigmaErr= f7->GetParError(2);
00256       fprintf(outfile, "%d %s %2d %8.3f %8.3f %8.3f %8.3f\n", DetectorId::kRPC, DetectorId::AsString(DetectorId::kRPC), trigLatencyRPCStatus, trigLatencyRPC, trigLatencyRPCErr, trigLatencyRPCSigma, trigLatencyRPCSigmaErr);
00257 
00258       h_TrigT_RPC->Write();
00259       h_TrigT_All->Fill(trigLatencyRPC);
00260       h_CalibTrigT->Fill(trigLatencyRPC);
00261       h_CalibTrigTErr->Fill(trigLatencyRPCErr);
00262       h_CalibTrigTSigma->Fill(trigLatencyRPCSigma);
00263       h_CalibTrigTSigmaErr->Fill(trigLatencyRPCSigmaErr);
00264   }
00265 
00266 
00267    //cout<<"fitting finished"<<endl;
00268   //m_tree->Fill();
00269   fclose(outfile);
00270 }
00271 
00272 int DetLatency::InitPmtProp(const ServiceMode& svc)
00273 {
00274 
00275   string hname = "h_TrigT_AD1";
00276   h_TrigT_AD1=new TH1F(hname.c_str(),hname.c_str(),2000,-1000,1000);
00277 
00278   hname = "h_TrigT_AD2";
00279   h_TrigT_AD2=new TH1F(hname.c_str(),hname.c_str(),2000,-1000,1000);
00280  
00281   hname = "h_TrigT_AD3";
00282   h_TrigT_AD3=new TH1F(hname.c_str(),hname.c_str(),2000,-1000,1000);
00283 
00284   hname = "h_TrigT_AD4";
00285   h_TrigT_AD4=new TH1F(hname.c_str(),hname.c_str(),2000,-1000,1000);
00286 
00287   hname = "h_TrigT_IWS";
00288   h_TrigT_IWS=new TH1F(hname.c_str(),hname.c_str(),2000,-1000,1000);
00289 
00290   hname = "h_TrigT_OWS";
00291   h_TrigT_OWS=new TH1F(hname.c_str(),hname.c_str(),2000,-1000,1000);
00292 
00293   hname = "h_TrigT_RPC";
00294   h_TrigT_RPC=new TH1F(hname.c_str(),hname.c_str(),2000,-1000,1000);
00295 
00296   hname = "h_TrigT_All";
00297   h_TrigT_All=new TH1F(hname.c_str(),hname.c_str(),8000,-400,400);
00298 
00299   hname = "h_CalibTrigT";
00300   h_CalibTrigT=new TH1F(hname.c_str(),hname.c_str(),8000,-400,400);
00301 
00302   hname = "h_CalibTrigTErr";
00303   h_CalibTrigTErr=new TH1F(hname.c_str(),hname.c_str(),8000,-400,400);
00304 
00305   hname = "h_CalibTrigTSigma";
00306   h_CalibTrigTSigma=new TH1F(hname.c_str(),hname.c_str(),8000,-400,400);
00307 
00308   hname = "h_CalibTrigTSigmaErr";
00309   h_CalibTrigTSigmaErr=new TH1F(hname.c_str(),hname.c_str(),8000,-400,400);
00310 
00311 
00312   //map<int,PmtProp>::iterator it,idend=m_PmtPropMap.end(); //pmtID
00313   //for(it=m_PmtPropMap.begin(); it!=idend; it++) {
00314   //  PmtProp& curr = it->second;
00315   //}
00316   
00317   ResetPmtProp();//reset
00318 
00319   m_NStop = 1;
00320   m_startrun = -1;
00321   m_currentrun = -1;
00322   m_execNum=0;  
00323   m_NTrigger=0;
00324 
00325   return 1;
00326 }
00327 
00328 int DetLatency::ResetPmtProp()
00329 {
00330   h_TrigT_AD1->Reset();
00331   h_TrigT_AD2->Reset();
00332   h_TrigT_AD3->Reset();
00333     h_TrigT_AD4->Reset();
00334   h_TrigT_IWS->Reset();
00335     h_TrigT_OWS->Reset();
00336     h_TrigT_RPC->Reset();
00337 
00338 
00339   m_NTrigger = 0;
00340   m_startrun = -1;
00341 
00342   m_execNum=0;
00343   return 1;
00344 }
00345 
00346 StatusCode DetLatency::initialize()
00347 {
00349 
00350   StatusCode sc;
00351   sc = this->GaudiAlgorithm::initialize();
00352   if( sc.isFailure() ) {
00353     error() << "Base class initialization error" << endreq;
00354     return sc;
00355   }
00356 
00358   sc = service("RunDataSvc",m_runDataSvc);
00359   if( sc.isFailure() ) {
00360     error() << "Can't get RunDataSvc" << endreq;
00361     return sc;
00362   }
00363 
00365   sc = service("CableSvc",m_cableSvc);
00366   if( sc.isFailure() ) {
00367     error() << "Can't get CableSvc" << endreq;
00368     return sc;
00369   }
00370 
00371   StatusCode status = service("EventDataArchiveSvc", p_archiveSvc);
00372   if (status.isFailure()) {
00373     Error("Service [EventDataArchiveSvc] not found", status);
00374   }
00375 
00376   f1 = new TF1("f1","gaus",-500,500);
00377   f2 = new TF1("f2","gaus",-500,500);
00378 
00379   f3 = new TF1("f3","gaus",-500,500);
00380   f4 = new TF1("f4","gaus",-500,500);
00381   f5 = new TF1("f5","gaus",-500,500);
00382   f6 = new TF1("f6","gaus",-500,500);
00383   f7 = new TF1("f7","gaus",-500,500);
00384   m_rootfile = new TFile(m_fileName.c_str(),"recreate");
00385   //m_tree = new TTree("t", "My Tree");
00386   //m_tree->SetMaxTreeSize(200000000);  // 200M
00387 
00388   m_masterfile = fopen("Master.trigLatencyCalibMap.txt", "a");
00389   fprintf(m_masterfile, "# [StartRun] [EndRun] [Sites] [SimFlag] [StartTimeSec] [StartTimeNanoSec] [EndTimeSec] [EndTimeNanoSec] [map file]\n");
00390   fclose(m_masterfile);
00391 
00392   return sc;
00393 
00394   return 1;
00395 }
00396 
00397 StatusCode DetLatency::execute()
00398 {
00399   debug()<<"DetLatency executing ... "<<endreq;
00401 
00402   StatusCode sc;
00403   
00405   //RawEventHeader* reh = get<RawEventHeader>(RawEventHeader::defaultLocation());
00406   //if(!reh) {
00407   //  warning()<<"Failed to get raw event header"<<endreq;
00408   //}
00409 
00411   ReadoutHeader* readoutHdr = get<ReadoutHeader>( ReadoutHeader::defaultLocation() );
00412   if(!readoutHdr) {
00413     error()<<"Failed to get readout header"<<endreq;
00414     return StatusCode::FAILURE;
00415   }
00416   const DaqCrate* daqCrate = readoutHdr->daqCrate();
00417   if(!daqCrate) {
00418     error()<<"Failed to get daqCrate from header"<<endreq;
00419     return StatusCode::FAILURE;
00420   }
00421 
00422   TimeStamp trigTime = daqCrate->triggerTime();
00423   m_currentTime = trigTime.GetSec();
00424 
00425   static bool first = true;
00427   if( first ) {
00428     first = false;
00430     Context ctx = readoutHdr->context();
00431     m_site=ctx.GetSite();
00432     m_simFlag=ctx.GetSimFlag();
00433     ctx.SetSite(Site::kAll);
00434     ctx.SetDetId(DetectorId::kAll);
00435     ServiceMode svc(ctx,0);
00436     //
00437     InitPmtProp(svc);
00438     //
00439     m_prevTrigTime = trigTime.GetSec();
00440     m_lastFitTime = trigTime.GetSec();
00441   }
00442 
00448   if((daqCrate->detector().isAD()))
00449   {
00450     const DaqPmtCrate* pmtCrate = daqCrate->asPmtCrate();
00451     if (!pmtCrate) {
00452       error()<<"Failed to get DaqPmtCrate"<<endreq;
00453     return StatusCode::SUCCESS;
00454     }
00455     Detector det = pmtCrate->detector();
00457   }
00458   ServiceMode svcMode( readoutHdr->context(),0 );
00459 
00460   m_NTrigger++;
00462   // Keep tracking the first trigger time and 
00463   // the laster trigger for this group of fit
00464   m_LastTrigSecond = trigTime.GetSec();
00465   m_LastTrigNanoSec = trigTime.GetNanoSec();
00466  //m_LastTrigSecond= readoutHdr->timeStamp().GetSec();
00467   //m_LastTrigNanoSec= readoutHdr->timeStamp().GetNanoSec();
00468 
00469   if(m_NTrigger==1){
00470     m_FirstTrigSecond = trigTime.GetSec();
00471     m_FirstTrigNanoSec = trigTime.GetNanoSec();
00472   }
00473 
00474 
00475     bool Range_exceed_flag=false;
00477     double trig_interval=0;
00478      int AES_counter=0;
00479     TimeStamp tagTimeStamp;
00480     TimeStamp trigTime2;
00481     TimeStamp tagTimeStamp_begin;
00482     //SmartDataPtr<DybArchiveList>  muonlist(p_archiveSvc,"/Event/Tag/Muon/MuonAll");
00483     SmartDataPtr<DybArchiveList>  muonlist(p_archiveSvc,"/Event/Readout/ReadoutHeader");
00484     if(muonlist) {
00486       //info() << "Number of muon in the ArchiveList: " << muonlist->size() << endreq;
00487     DybArchiveList::const_iterator iter = muonlist->begin();
00488     HeaderObject* muonAll_begin=dynamic_cast<HeaderObject*>(*iter);
00489     vector<const IHeader*> ihs_begin = muonAll_begin->inputHeaders();
00490     IHeader* iHeader_begin = const_cast<IHeader*>(ihs_begin[0]);
00491     HeaderObject* header_begin = dynamic_cast<HeaderObject*>(iHeader_begin);
00492       tagTimeStamp_begin=header_begin->timeStamp();
00493      // //cout<<"muonlist->size()="<<muonlist->size()<<endl;
00494       bool Valid_flag = false;
00495       for(; iter != muonlist->end(); iter++){
00496       AES_counter++;
00497       HeaderObject* muonAll = dynamic_cast<HeaderObject*>(*iter);
00498       vector<const IHeader*> ihs = muonAll->inputHeaders();
00499       
00500        // //cout<<"header size="<<ihs.size()<<endl;
00501         int i;
00502        for(i = 0; i < ihs.size(); i++) {
00503           IHeader* iHeader = const_cast<IHeader*>(ihs[i]);
00504           HeaderObject* header = dynamic_cast<HeaderObject*>(iHeader);
00506           int loopDet = header->context().GetDetId();
00507           //string SiteName = Site::AsString(detector.site());
00508           //string DetName  = DetectorId::AsString(detector.detectorId());
00509           //if(daqCrate->detector().isAD())
00510           if(loopDet==DetectorId::kAD1)// all the time is related to AD1
00511           //if(DetName=="AD1")
00512           {
00513              tagTimeStamp = header->timeStamp();
00514             trig_interval=(tagTimeStamp_begin.GetSec()-tagTimeStamp.GetSec())*1000000000+(tagTimeStamp_begin.GetNanoSec()-tagTimeStamp.GetNanoSec());
00515               if(abs(trig_interval)>=m_Trig_Interval_Offset_ns)
00516               {
00517                   m_tagTimeStamp=tagTimeStamp;
00518                   if((m_tagTimeStamp.GetSec()-m_tagTimeStamp_last.GetSec())*1000000000+(m_tagTimeStamp.GetNanoSec()-m_tagTimeStamp_last.GetNanoSec())>0)
00519                   {
00520                      m_tagTimeStamp_last=tagTimeStamp;
00522                     Valid_flag=true;
00523                     m_execNum++;
00524                   }
00525                   else
00526                   {
00527                     Range_exceed_flag=true;
00528                     break;
00529                   }
00530                }
00531               if(Valid_flag)
00532                   break;
00533               if(Range_exceed_flag)
00534                   break;
00535             }
00536           }//for(unsigned int i = 0; i < ihs.size(); i++)
00537           if(Valid_flag)
00538             break;
00539           if(Range_exceed_flag)
00540             break;
00541       }//end of Muonlist at 1st time
00542       
00543       if(Valid_flag)
00544       {
00545       Range_exceed_flag=false;
00546       //DybArchiveList::const_iterator iter = muonlist->begin();
00547       DybArchiveList::const_iterator iter2 = muonlist->begin();
00548         AES_counter=0;
00549       for(; iter2 != muonlist->end(); iter2++){
00550       AES_counter++;
00552       HeaderObject* muonAll2 = dynamic_cast<HeaderObject*>(*iter2);
00553       vector<const IHeader*> ihs2 = muonAll2->inputHeaders();
00554       for(unsigned int i = 0; i < ihs2.size(); i++) {
00555           IHeader* iHeader2 = const_cast<IHeader*>(ihs2[i]);
00556           HeaderObject* header2 = dynamic_cast<HeaderObject*>(iHeader2);
00558           int loopDet = header2->context().GetDetId();
00559 
00560           trigTime2 =header2->timeStamp();
00561           //if(AES_counter==1)
00562           //{
00563            // //cout<<"begin="<<trigTime2.GetNanoSec()<<endl;
00564           //}
00566           trig_interval=(trigTime2.GetSec()-m_tagTimeStamp.GetSec())*1000000000+(trigTime2.GetNanoSec()-m_tagTimeStamp.GetNanoSec());
00567           if(abs(trig_interval)<=m_Trig_Interval_Offset_ns)
00568           {
00569           if(loopDet==DetectorId::kAD1)
00570           {
00571           
00574           // //cout<<"trig_interval="<<trig_interval<<endl;
00576             h_TrigT_AD1->Fill(trig_interval);
00577           }         
00578           if(loopDet==DetectorId::kAD2)
00579           {
00582             h_TrigT_AD2->Fill(trig_interval);
00583           }
00584           if(loopDet==DetectorId::kAD3)
00585           {
00586             h_TrigT_AD3->Fill(trig_interval);
00588           }
00589           if(loopDet==DetectorId::kAD4)
00590           {
00591             h_TrigT_AD4->Fill(trig_interval);
00592           }
00593           if(loopDet==DetectorId::kIWS)
00594           {
00595            // //cout<<"kIWS"<<endl;
00596                  // //cout<<"IWS find ="<<trigTime2.GetNanoSec()<<" zero="<<m_tagTimeStamp.GetNanoSec()<<"  trig_interval="<<trig_interval<<endl;
00597             h_TrigT_IWS->Fill(trig_interval);
00598           }
00599           if(loopDet==DetectorId::kOWS)
00600           {
00601            // //cout<<"kOWS"<<endl;
00603             h_TrigT_OWS->Fill(trig_interval);
00604           }
00605           if(loopDet==DetectorId::kRPC)
00606           {
00607             h_TrigT_RPC->Fill(trig_interval);
00608           }
00609           }
00610           else if(trig_interval<-1*m_Trig_Interval_Offset_ns)
00611           {
00612             Range_exceed_flag=true;
00613             break;
00614            }
00615       }//for(unsigned int i = 0; i < ihs.size(); i++)
00616         if(Range_exceed_flag)
00617           break;
00618      }// for(; iter != muonlist->end(); iter++)
00619    // //cout<<endl;
00620     }//if true
00621     }//end of if(muonlist)
00623 
00624   //  //cout << "run number:" << m_runDataSvc->runData(svcMode)->runNumber() << endl;
00625   
00627   //int TrigType = pmtCrate->triggerType();
00628   //if( TrigType != 7 ) {
00629 
00630 
00631   //-------------------------------------
00632   //fit the data
00633   if(m_currentTime - m_lastFitTime > m_fitPeriod) {
00634     //Fit
00635     Fit();
00636     //after fit
00637     ResetPmtProp();
00638     m_NStop++;
00639     m_lastFitTime = m_currentTime;
00640   }
00641   
00642   m_prevTrigTime = m_currentTime;
00643 
00645 
00646   return StatusCode::SUCCESS;
00647 }
00648 
00649 StatusCode DetLatency::finalize()
00650 {
00651   //cout<<"DetLatency finalize...."<<endl;
00652 
00653   //Fit
00654   Fit();
00655 
00657       h_TrigT_All->Write();
00658       h_CalibTrigT->Write();
00659       h_CalibTrigTErr->Write();
00660       h_CalibTrigTSigma->Write();
00661       h_CalibTrigTSigmaErr->Write();
00662 
00663   m_rootfile->Write();
00664   m_rootfile->Close();
00665 
00667 
00668   delete f1;
00669   delete f2;
00670   delete f3;
00671   delete f4;
00672   delete f5;
00673   delete f6;
00674   delete f7;
00675   //delete m_tree;
00676   delete m_rootfile;
00677 
00678  // //cout<<"Test 3"<<endl;
00679 
00680   if (0 != p_archiveSvc) {
00681     p_archiveSvc->release();
00682   }
00684 
00685   delete h_TrigT_AD1;
00686    delete  h_TrigT_AD2;
00687   delete   h_TrigT_AD3;
00688   delete   h_TrigT_AD4;
00689   delete   h_TrigT_IWS;
00690     delete h_TrigT_OWS;
00691     delete h_TrigT_RPC;
00692 
00693 
00694  // //cout<<"Test 5"<<endl;
00695 
00696        delete h_TrigT_All;
00697        delete h_CalibTrigT;
00698        delete h_CalibTrigTErr;
00699        delete h_CalibTrigTSigma;
00700         delete h_CalibTrigTSigmaErr;
00701 
00702 
00703  //cout<<"Finished"<<endl;
00704 
00705 
00706   StatusCode sc;
00707   sc = this->GaudiAlgorithm::finalize();
00708   return sc;
00709 
00710   return 1;
00711 }
00712 
00713 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:09:25 for DetLatency by doxygen 1.7.4