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

STND_BMS.cxx

Go to the documentation of this file.
00001 #include "STND_BMS.h"
00002 #include "FileGap.h"
00003 
00004 #include <SpillTiming/SpillTimeFinder.h>
00005 #include <BeamDataUtil/BDSpillAccessor.h>
00006 #include <BeamDataUtil/BeamMonSpill.h>
00007 
00008 #include <Validity/VldContext.h>
00009 #include <Validity/VldTimeStamp.h>
00010 
00011 #include <HistMan/HistMan.h>
00012 
00013 #include <TH1F.h>
00014 #include <TProfile.h>
00015 
00016 #include <iostream>
00017 using namespace std;
00018 
00019 STND_BMS::STND_BMS()
00020 {
00021 }
00022 STND_BMS::~STND_BMS()
00023 {
00024 }
00025 
00026 void STND_BMS::Scan(VldTimeStamp begin_run, VldTimeStamp end_run,
00027                     const char* folder)
00028 {
00029 
00030     FileGap fg;
00031     FileGap::BoundList bounds = fg.GetFileBounds(begin_run,end_run);
00032     FileGap::Bound& first = bounds.front();
00033     if (first.first < begin_run) first.first = begin_run;
00034     FileGap::Bound& last = bounds.back();
00035     if (last.second > end_run) last.second = end_run;
00036 
00037     int nfiles = bounds.size();
00038 
00039     HistMan hm(folder);
00040     TProfile* h_dt_file =
00041         hm.Book<TProfile>("dt_file",
00042                           "SpillTimeND - BeamMonSPill vs file",
00043                           nfiles,0,nfiles);
00044     TH1F* h_missing_file =
00045         hm.Book<TH1F>("missing_file","Number BMS > .5 sec away from STND",
00046                       nfiles,0,nfiles);
00047     TH1F* h_miss_per_file =
00048         hm.Book<TH1F>("miss_per_file","Percent BMS > .5 sec away from STND",
00049                       nfiles,0,nfiles);
00050 
00051 
00052     TH1F* h_notor_file =
00053         hm.Book<TH1F>("notor_file","Number BMS < .5 sec away from STND, no toroids",
00054                       nfiles,0,nfiles);
00055     TH1F* h_notor_per_file =
00056         hm.Book<TH1F>("notor_per_file","Percent BMS < .5 sec away from STND, no toroids",
00057                       nfiles,0,nfiles);
00058     
00059     TH1F* h_dt_in = hm.Book<TH1F>("dt_in","SpillTimeND - BeamMonSPill",
00060                                   2000,-0.1,0.1);
00061     TH1F* h_dt_out = hm.Book<TH1F>("dt_out","SpillTimeND - BeamMonSPill",
00062                                    2000,-10,10);
00063 
00064     TH1F* h_rep_stnd = hm.Book<TH1F>("rep_stnd","Rep period for SpillTimeND",
00065                                      600,0,60);
00066     TH1F* h_rep_bms = hm.Book<TH1F>("rep_bms","Rep period for BeamMonSpill",
00067                                     600,0,60);
00068     
00069     SpillTimeFinder& stf = SpillTimeFinder::Instance();
00070     BDSpillAccessor& sa = BDSpillAccessor::Get();
00071 
00072     Detector::Detector_t det = Detector::kNear;
00073     SimFlag::SimFlag_t simflag = SimFlag::kData;
00074 
00075     VldTimeStamp numi_start(2005,1,1,0,0,0);
00076     
00077 
00078     FileGap::BoundList::iterator it, done = bounds.end();
00079 
00080     VldTimeStamp last_stnd(VldTimeStamp::GetBOT()), last_bms(VldTimeStamp::GetBOT());
00081 
00082     int file=0;
00083     for (it = bounds.begin(); it != done; ++it) {
00084         int missing_stnd=0;
00085         int no_toroids = 0;
00086         
00087         VldTimeStamp beg = it->first;
00088         VldTimeStamp end = it->second;
00089 
00090         cerr << beg << " --> " << end << endl;
00091 
00092         VldTimeStamp vts = beg;
00093         int nspills = 0;
00094 
00095         while (vts <= end) {
00096             ++nspills;
00097 
00098             const BeamMonSpill* bms = sa.LoadSpill(vts,+1);
00099             VldTimeStamp bms_vts;
00100             if (!bms) {
00101                 cerr << "No BeamMonSpill for " << vts << endl;
00102                 bms_vts = VldTimeStamp::GetEOT();
00103             }
00104             else bms_vts = bms->SpillTime();
00105 
00106             VldContext vc(det,simflag,bms_vts);
00107             VldTimeStamp stnd_vts = stf.GetTimeOfNearestSpill(vc);
00108 
00109             if (stnd_vts < numi_start) {
00110                 cerr << "Bailing on file after " << nspills
00111                      << " due to getting early SpillTimeND: "
00112                      << stnd_vts
00113                      << " last vts = " << vts
00114                      << endl;
00115                 break;
00116             }
00117 
00118             h_rep_stnd->Fill(stnd_vts-last_stnd);
00119             h_rep_bms->Fill(bms_vts-last_bms);
00120 
00121             last_stnd = stnd_vts;
00122             last_bms  =  bms_vts;
00123 
00124             double dt = stnd_vts-bms_vts;
00125             h_dt_in->Fill(dt);
00126             h_dt_out->Fill(dt);
00127             h_dt_file->Fill(file,dt);
00128 
00129             if (fabs(dt)>0.5) {
00130                 ++missing_stnd;
00131                 h_missing_file->Fill(file,1);
00132             }
00133 
00134             if (bms->fTor101 == 0.0 && bms->fTr101d == 0.0 &&
00135                 bms->fTortgt == 0.0 && bms->fTrtgtd == 0.0)
00136             {
00137                 ++no_toroids;
00138                 h_notor_file->Fill(file,1);
00139             }
00140 
00141             if (vts >= stnd_vts) {
00142                 cerr << "Error, infinite loop, bailing with\n\tbms= " << vts
00143                      << " stnd= " << stnd_vts << endl;
00144                 break;
00145             }
00146             vts = bms_vts;
00147             
00148         } // loop over one file
00149         if (missing_stnd)
00150             cerr << "File " << file << " no SpillTimeND "
00151                  << missing_stnd << " times\n";
00152 
00153         h_miss_per_file->Fill(file,(1.0*missing_stnd)/nspills);
00154         h_notor_per_file->Fill(file,(1.0*no_toroids)/nspills);
00155         ++file;
00156     }
00157 
00158 
00159     HistMan io("");
00160     io.WriteOut("stnd_bms.root");
00161 }

Generated on Mon Nov 23 05:28:29 2009 for loon by  doxygen 1.3.9.1