BDTestData.cxx File Reference

#include "BDTestData.h"
#include <BeamDataUtil/BDEarliest.h>
#include <BeamDataUtil/BDTarget.h>
#include <Validity/VldContext.h>
#include <RawData/RawRecord.h>
#include <RawData/RawBeamMonHeaderBlock.h>
#include <RawData/RawBeamMonBlock.h>
#include <RawData/RawDataBlock.h>
#include <RawData/RawBeamData.h>
#include <SpillTiming/SpillTimeFinder.h>
#include <TFile.h>
#include <TTree.h>
#include <TSystem.h>
#include <iostream>
#include <vector>
#include <list>
#include <TGraph.h>
#include <TCanvas.h>
#include <TH1F.h>
#include <TAxis.h>
#include <TGaxis.h>
#include <TDatime.h>
#include <TText.h>
#include <TVirtualPad.h>
#include <TMarker.h>
#include <TPaveText.h>
#include <TImageDump.h>

Go to the source code of this file.

Classes

class  BDTDPlotter

Functions

static void set_toroid (const char *n, float &t, const RawBeamMonBlock &block)
bool fill_bdtest (BDTestData &td, const RawBeamMonBlock &block, const RawBeamMonHeaderBlock &head)
void convert_raw_to_bdtest (const char *raw_file, const char *output_file)
 Convert one raw file to a BDTestData tree file.
void footer ()
void legend (double X1, double Y1, double X2, double Y2, int nlines, int colors[], string keys[], char type= 'l', int padcolor=0)
void generate_bdtd_plots (const char *input_directory, const char *outfile)

Function Documentation

void convert_raw_to_bdtest ( const char *  raw_file,
const char *  output_file 
)

Convert one raw file to a BDTestData tree file.

Definition at line 117 of file BDTestData.cxx.

References fill_bdtest(), RawRecord::GetRawBlockIter(), infile, nentries, and outfile.

00118 {
00119     TFile infile(raw_file,"READ");
00120     TTree* intree=(TTree*)(infile.Get("BeamMon"));
00121 
00122     TFile outfile(output_file,"RECREATE");
00123     TTree* outtree = new TTree("bdtest", "Beam Monitoring Data");
00124     BDTestData* bdtd = new BDTestData;
00125     outtree->Branch("pot","BDTestData",&bdtd);
00126 
00127     RawRecord* record = 0;
00128     int nentries = intree->GetEntries();
00129     for ( Int_t ient = 0; ient < nentries; ient++ ) {
00130         intree -> SetBranchAddress("RawRecord",&record);
00131         intree->GetEntry(ient);
00132 
00133         const RawBeamMonBlock* rbmb = 0;
00134         const RawBeamMonHeaderBlock* rbmhb = 0;
00135         TObject *obj = 0;
00136         TIter itr = record->GetRawBlockIter();
00137         while ((obj = itr())) {
00138             const RawBeamMonBlock* b = dynamic_cast<const RawBeamMonBlock*>(obj);
00139             if (b) rbmb = b;
00140             const RawBeamMonHeaderBlock* h = dynamic_cast<const RawBeamMonHeaderBlock*>(obj);
00141             if (h) rbmhb = h;
00142         }
00143 
00144         if (!(rbmb && rbmhb)) continue;
00145 
00146         if (fill_bdtest(*bdtd,*rbmb,*rbmhb))
00147             outtree->Fill();
00148     }
00149 
00150     outfile.cd();
00151     outtree->Write();
00152     outfile.Close();
00153 
00154     infile.Close();
00155 }

bool fill_bdtest ( BDTestData td,
const RawBeamMonBlock block,
const RawBeamMonHeaderBlock head 
)

Definition at line 54 of file BDTestData.cxx.

References BDTarget::BpmProjection(), BDTestData::earliest, RawBeamData::GetData(), RawBeamData::GetDataLength(), SpillTimeFinder::GetTimeOfNearestSpill(), BDEarliest::GetTimestamps(), RawBeamMonHeaderBlock::GetVldContext(), BDTestData::hitgt, BDTestData::horni, SpillTimeFinder::Instance(), BDTarget::kUnknown, BDTestData::nbunch, BDTarget::ProfileProjection(), BDTestData::Reset(), set_toroid(), BDTarget::SetSpill(), BDEarliest::SetSpill(), BDTestData::spilltimend, BDTarget::TargetIn(), RawBeamMonBlock::TclkTriggerEvent(), BDTestData::tgtdist, BDTestData::tor101, BDTestData::tortgt, BDTestData::tr101d, BDTestData::trtgtd, BDTestData::vitgt, BDTestData::xsigma, BDTestData::xtgt, BDTestData::ysigma, and BDTestData::ytgt.

Referenced by convert_raw_to_bdtest(), and BDTestDataModuleImp::Fill().

00056 {
00057     td.Reset();
00058 
00059     const int trig_event = block.TclkTriggerEvent();
00060     if (trig_event != 0xa9) return false;
00061 
00062     // time stamp
00063     BDEarliest earliest;
00064     earliest.SetSpill(head,block);
00065     double dae=0, vme=0;
00066     earliest.GetTimestamps(dae,vme);
00067     if (vme) td.earliest = vme;
00068     else td.earliest = dae;
00069 
00070     // toroids
00071     set_toroid("E:TORTGT",td.tortgt,block);
00072     set_toroid("E:TRTGTD",td.trtgtd,block);
00073     set_toroid("E:TOR101",td.tor101,block);
00074     set_toroid("E:TR101D",td.tr101d,block);
00075 
00076     BDTarget targ;
00077     targ.SetSpill(head,block);
00078     vector<double> xp,yp,xi,yi;
00079     targ.BpmProjection(xp,yp,xi,yi);
00080     td.nbunch = xp.size();
00081     for (int ind=0; ind<td.nbunch && ind<8; ++ind) {
00082         td.hitgt[ind] = static_cast<float>(xi[ind]);
00083         td.vitgt[ind] = static_cast<float>(yi[ind]);
00084         td.xtgt[ind] =  static_cast<float>(xp[ind]);
00085         td.ytgt[ind] =  static_cast<float>(yp[ind]);
00086     }
00087     double xm=0, ym=0, xsig=0, ysig=0;
00088 
00089     targ.ProfileProjection(xm,ym,xsig,ysig);
00090     td.xsigma = xsig; 
00091     td.ysigma = ysig; 
00092     bool is_in=false;
00093     double z_loc = 0;
00094     BDTarget::BeamType beam_type = targ.TargetIn(is_in,z_loc);
00095     if (beam_type == BDTarget::kUnknown || !is_in) {
00096         cerr << "Unknown target location: is_in="<<is_in<<" at " << z_loc << endl;
00097     }
00098     if (!is_in)
00099         td.tgtdist = -1e6;
00100     else td.tgtdist = z_loc;
00101 
00102     // horn
00103     const char* dev[] = {"E:NSLINA","E:NSLINB","E:NSLINC","E:NSLIND",0};
00104     float horni = 0;
00105     for (int ind=0; dev[ind]; ++ind) {
00106         const RawBeamData* d = block[dev[ind]];
00107         if (d && d->GetDataLength()) horni += d->GetData()[0];
00108     }
00109     td.horni = horni;
00110 
00111     td.spilltimend =
00112       SpillTimeFinder::Instance().GetTimeOfNearestSpill(head.GetVldContext());
00113 
00114     return true;
00115 }

void footer (  ) 

Definition at line 253 of file BDTestData.cxx.

References Form().

Referenced by BDTDPlotter::write().

00254 {
00255     TDatime t;
00256     double x=0.01, y=0.01;
00257     const char* str = Form("Brett Viren, %d/%02d/%02d",t.GetYear(),t.GetMonth(),t.GetDay());
00258     TText tt(x,y,str);
00259     float siz = tt.GetTextSize();
00260     tt.SetTextSize(0.5*siz);
00261     tt.DrawTextNDC(x,y,str);
00262 
00263 }

void generate_bdtd_plots ( const char *  input_directory,
const char *  outfile 
)

Definition at line 503 of file BDTestData.cxx.

References done(), BDTDPlotter::fill(), gSystem(), it, and BDTDPlotter::write().

00504 {
00505     void* dir = gSystem->OpenDirectory(input_directory);
00506     if (!dir) {
00507         cerr << "Failed to open directory \"" << input_directory << "\"\n";
00508         return;
00509     }
00510     
00511     BDTDPlotter* plotter = new BDTDPlotter; // leak it!
00512 
00513     list<string> file_names;
00514     const char* cptr=0;
00515     while ( (cptr = gSystem->GetDirEntry(dir)) ) if (cptr) file_names.push_back(cptr);
00516     if (!file_names.size()) return;
00517     file_names.sort();
00518     list<string>::iterator it, done = file_names.end();
00519     for (it=file_names.begin(); it != done; ++it) {
00520         string file = *it;
00521         if (string::npos == file.find(".bdtd.root")) {
00522             cerr << "Skipping unmatched file \"" << file << "\"\n";
00523             continue;
00524         }
00525 
00526         string path = input_directory;
00527         path += "/" + file;
00528         cerr << "Processing " << path << endl;
00529         TFile tfile(path.c_str(),"READ");
00530         TTree* tree = (TTree*)(tfile.Get("bdtest"));
00531         BDTestData* bd_test_data = 0;
00532         int ninds = tree->GetEntries();
00533         for (int ind=0; ind<ninds; ++ind) {
00534             tree->SetBranchAddress("pot",&bd_test_data);
00535             tree->GetEntry(ind);
00536 
00537             plotter->fill(*bd_test_data);
00538         }
00539         tfile.Close();
00540     }
00541 
00542     plotter->write(outfile);
00543 }

void legend ( double  X1,
double  Y1,
double  X2,
double  Y2,
int  nlines,
int  colors[],
string  keys[],
char  type = 'l',
int  padcolor = 0 
)

Definition at line 274 of file BDTestData.cxx.

Referenced by CDAnalysis::Bb(), CDAnalysis::BbVsGminos(), NNTrain::Train(), and BDTDPlotter::write().

00277 {
00278     TVirtualPad* oldpad = gPad;
00279 
00280     TPad* newpad = new TPad("newpad","Legend",X1,Y1,X2,Y2,0,1);
00281     newpad->SetBorderSize(1);
00282     newpad->SetBorderMode(0);
00283     newpad->SetFillColor(padcolor);
00284     newpad->SetFillStyle(4090);
00285     newpad->Draw();
00286     newpad->cd();
00287 
00288     double t = 1.0/nlines;
00289 
00290     int ind;
00291     for (ind=0; ind < nlines; ++ind) {
00292         double y2   = (1.0 + ind)*t;
00293         double ymid = (0.5 + ind)*t;
00294         double y1   = (0.0 + ind)*t;
00295 
00296         switch (type) {
00297         case 'm': {             // markers
00298             TMarker marker;
00299             marker.SetMarkerColor(colors[ind]);
00300             if (colors[ind] == 1)
00301                 marker.SetMarkerStyle(8);
00302             else
00303                 marker.SetMarkerStyle(colors[ind]);
00304             marker.DrawMarker(0.125,ymid);
00305             break;
00306         }
00307         case 'l': default: {    // lines
00308             TLine line;
00309             line.SetLineColor(colors[ind]);
00310             //line.SetLineStyle(colors[ind]);
00311             line.SetLineWidth(5);
00312             line.DrawLine(0.0,ymid,0.25,ymid);
00313             break;
00314         }
00315         }
00316         TPaveText* pt = new TPaveText(0.25,y1,1.0,y2,"NDC");
00317         pt->SetBorderSize(0);
00318         pt->SetFillColor(0);
00319         pt->SetFillStyle(0);
00320         pt->AddText(keys[ind].c_str());
00321         pt->Draw();
00322 
00323         cerr << ind << ": " << colors[ind] << ", " << keys[ind] << endl;
00324     }
00325     newpad->Modified();
00326     newpad->Update();
00327 
00328     oldpad->cd();
00329 }

static void set_toroid ( const char *  n,
float &  t,
const RawBeamMonBlock block 
) [static]

Definition at line 45 of file BDTestData.cxx.

References RawBeamData::GetData(), and RawBeamData::GetDataLength().

Referenced by fill_bdtest().

00046 {
00047     t=0.0;
00048     const RawBeamData* d = block[n];
00049     if (d && d->GetDataLength()) t=d->GetData()[0];
00050     if (t>50)
00051         cerr << n << " " << t << endl;
00052 }


Generated on 10 Oct 2018 for loon by  doxygen 1.6.1