Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

DeltaT.cxx

Go to the documentation of this file.
00001 #include "DeltaT.h"
00002 
00003 #include <HistMan/HistMan.h>
00004 
00005 #include <BeamData/ana/bmnt/Knot.h>
00006 #include <BeamData/ana/bmnt/Swic.h>
00007 #include <BeamData/ana/bmnt/AcnetDevice.h>
00008 
00009 #include <TTree.h>
00010 #include <TFile.h>
00011 #include <TH2D.h>
00012 
00013 #include <cmath>
00014 #include <cassert>
00015 #include <vector>
00016 #include <iostream>
00017 using namespace std;
00018 
00019 DeltaT::DeltaT()
00020     : fFile(0)
00021 {
00022 }
00023 
00024 DeltaT::~DeltaT()
00025 {
00026     if (fFile) delete fFile; fFile = 0;
00027 }
00028 
00029 void DeltaT::NewFile(const char* filename)
00030 {
00031     if (fFile) delete fFile; fFile = 0;
00032     fFile = new TFile(filename);
00033 
00034     TObject* o = fFile->FindObjectAny("bd");
00035     TTree* bd = dynamic_cast<TTree*>(o);
00036     assert(bd);
00037     fKnot.SetTree(*bd);
00038 }
00039 
00040 void DeltaT::Book(PlotterManager& pm)
00041 {
00042 
00043     vector<const char*> devs = pm.GetSwicDevNames();
00044     size_t siz = devs.size();
00045 
00046     HistMan& hm = pm.GetHistMan();
00047 
00048     TH2D* devhist[3];
00049 
00050     int i=0;
00051     devhist[i++] = hm.Book<TH2D>("dae_vme_dt","DAE-VME time difference",
00052                                  siz,0,siz, 400,0,4);
00053     devhist[i++] = hm.Book<TH2D>("dae_dt_prev","DAE time to previous spill",
00054                                  siz,0,siz, 240,0,240);
00055     devhist[i++] = hm.Book<TH2D>("vme_dt_prev","VME time to previous spill",
00056                                  siz,0,siz, 240,0,240);
00057     devhist[i++] = hm.Book<TH2D>("dae_vme_dt_prev","DAE-VME-(DAE time to prev spill)",
00058                                  siz,0,siz, 400,0,4);
00059 
00060     TH1D* missing =
00061         hm.Book<TH1D>("missing","Number of times the device is missing",
00062                       siz,0,siz);
00063 
00064     hm.Book<TH1D>("earliest_dae_vme_dt","Delta between earliest DAE and VME",
00065                   1000,-5,5);
00066 
00067     for (size_t bin=0; bin<siz; ++bin) {
00068         for (int ind=0; ind<i; ++ind) {
00069             devhist[ind]->GetXaxis()->SetBinLabel(bin+1,devs[bin]);
00070         }
00071         missing->GetXaxis()->SetBinLabel(bin+1,devs[bin]);
00072     }
00073 
00074 
00075 }
00076 bool DeltaT::Fill(PlotterManager& pm)
00077 {
00078     Knot& k = pm.GetKnot();
00079     HistMan& hm = pm.GetHistMan();
00080 
00081     vector<const char*> devs = pm.GetSwicDevNames();
00082     size_t siz = devs.size();
00083     
00084     int entry = k.GetEntryNumber();
00085     if (entry > 0)  fKnot.GetEntry(entry-1);
00086 
00087     double early_dae = -1.0, early_vme = -1.0;
00088 
00089     Swic swic1, swic2;
00090     for (size_t dev=0; dev<siz; ++dev) {
00091         const AcnetDevice* ad1 = k.GetDevice(devs[dev]);
00092         if (!ad1->ndata) {
00093             hm.Fill1d("missing",dev,1);
00094             continue;
00095         }
00096 
00097         swic1.SetAcnetDevice(*ad1);
00098 
00099         double diff0 = ad1->timestamp-swic1.GetVmeTimestamp();
00100         if (fabs(diff0)<1e-6) diff0=0.0;
00101         hm.Fill2d("dae_vme_dt",dev,diff0);
00102 
00103         // Track earliest DAE & VME timestamp.
00104         if (ad1->timestamp > 1.0)
00105             if (early_dae < 0.0 || ad1->timestamp < early_dae)
00106                 early_dae = ad1->timestamp;
00107         double vme_timestamp = swic1.GetVmeTimestamp();
00108         if (vme_timestamp > 1.0)
00109             if (early_vme < 0.0 || vme_timestamp < early_vme)
00110                 early_vme = vme_timestamp;
00111         
00112         // Need to pass the first spill before comparing to previous....
00113         if (entry < 1) continue;
00114 
00115         const AcnetDevice* ad2 = fKnot.GetDevice(devs[dev]);
00116         if (!ad2->ndata) continue;
00117 
00118         swic2.SetAcnetDevice(*ad2);
00119 
00120         double diff1 = ad1->timestamp-ad2->timestamp;
00121         if (fabs(diff1)<1e-6) diff1=0.0;
00122         hm.Fill2d("dae_dt_prev",dev,diff1);
00123 
00124         double diff2 = swic1.GetVmeTimestamp()-swic2.GetVmeTimestamp();
00125         if (fabs(diff2)<1e-6) diff2=0.0;
00126         hm.Fill2d("vme_dt_prev",dev,diff2);
00127 
00128         double diff3 = diff0-diff1;
00129         if (diff0 < 0 || diff0 > 4) {
00130             hm.Fill2d("dae_vme_dt_prev",dev,diff3);
00131         }
00132     }
00133     hm.Fill1d("earliest_dae_vme_dt",early_dae-early_vme);
00134     return true;
00135 }

Generated on Mon Feb 15 11:06:36 2010 for loon by  doxygen 1.3.9.1