00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <HistMan/HistMan.h>
00011 #include <BeamData/ana/bmnt/ProfMon.h>
00012 #include <BeamData/ana/bmnt/Knot.h>
00013 #include <BeamData/ana/bmnt/Pedestals.h>
00014 #include <BeamData/ana/bmnt/AcnetDevice.h>
00015
00016 #include <TCanvas.h>
00017 #include <TSystem.h>
00018 #include <TTree.h>
00019 #include <TFile.h>
00020 #include <TH1D.h>
00021 #include <TH2D.h>
00022
00023 #include <iostream>
00024 #include <string>
00025 #include <cassert>
00026 #include <cmath>
00027 using namespace std;
00028
00029 const double MIN_ETOR101 = 0.15;
00030
00031
00032
00033 const char* toroids [] = {
00034 "E:TOR101",
00035 "E:TORTGT",
00036 0
00037 };
00038
00039 const char* profile_monitor[] = {
00040 "E:M101DS",
00041 "E:M105DS",
00042 "E:M107DS",
00043 "E:M108DS",
00044 "E:M112DS",
00045 "E:M114DS",
00046 "E:M115DS",
00047 "E:M117DS",
00048 "E:M121DS",
00049 "E:MTGTDS",
00050 0
00051 };
00052
00053 void book_once()
00054 {
00055 HistMan hm("bv");
00056
00057
00058 hm.Book<TH1D>("max_dae_dt","Maximum difference between 2 DAEs in data block",1200,-60,60);
00059
00060 }
00061 void fill(Knot& k, ProfMon& , Pedestals& , int )
00062 {
00063 double max_dt = 0;
00064
00065 for (int ind1=0; profile_monitor[ind1]; ++ind1) {
00066 const AcnetDevice* ad1 = k.GetDevice(profile_monitor[ind1]);
00067 for (int ind2=ind1; profile_monitor[ind2]; ++ind2) {
00068 const AcnetDevice* ad2 = k.GetDevice(profile_monitor[ind2]);
00069 double diff = fabs(ad1->timestamp - ad2->timestamp);
00070 if (diff > max_dt) max_dt = diff;
00071 }
00072 }
00073 HistMan hm("bv");
00074 hm.Fill1d("max_dae_dt",max_dt);
00075
00076 }
00077
00078 void fill_profile(ProfMon& pm, int count,
00079 TH1D& xh, TH1D& yh, TH2D& xa, TH2D& ya)
00080 {
00081 for (int ch=pm.MIN_CHANNEL; ch<=pm.MAX_CHANNEL; ++ch) {
00082 xh.Fill(pm.WirePosition(ch),pm.GetVoltage(pm.Xindex(ch)));
00083 xa.Fill(count,pm.WirePosition(ch),pm.GetVoltage(pm.Xindex(ch)));
00084 yh.Fill(pm.WirePosition(ch),pm.GetVoltage(pm.Yindex(ch)));
00085 ya.Fill(count,pm.WirePosition(ch),pm.GetVoltage(pm.Yindex(ch)));
00086
00087 }
00088 }
00089
00090
00091 void book_and_fill(Knot& k, ProfMon& pm, Pedestals& peds, int count)
00092 {
00093 HistMan hm(Form("bv/spill%03d",count));
00094
00095 double min = ProfMon::WirePosition(ProfMon::MIN_CHANNEL);
00096 double max = ProfMon::WirePosition(ProfMon::MAX_CHANNEL);
00097 min -= ProfMon::WIRE_SPACING;
00098 max -= ProfMon::WIRE_SPACING;
00099 int nbins = ProfMon::MAX_CHANNEL - ProfMon::MIN_CHANNEL + 1;
00100
00101 int npms = 0;
00102 for (; profile_monitor[npms]; ++npms);
00103 TH2D* xall =
00104 hm.Book<TH2D>(Form("xallpm_%03d",count),
00105 Form("All X Profiles for spill %d",count),
00106 npms,0,npms,nbins,min,max);
00107 TH2D* yall =
00108 hm.Book<TH2D>(Form("yallpm_%03d",count),
00109 Form("All Y Profiles for spill %d",count),
00110 npms,0,npms,nbins,min,max);
00111
00112 for (int ind=0; profile_monitor[ind]; ++ind) {
00113 const AcnetDevice* ad = k.GetDevice(profile_monitor[ind]);
00114 if (!pm.SetPeds(peds.GetPeds(profile_monitor[ind]))) {
00115 cerr << "Failed to set peds for " << profile_monitor[ind]
00116 << " skipping\n";
00117 continue;
00118 }
00119 int ret = pm.SetAcnetDevice(*ad);
00120 if (! ret) {
00121 cerr << "Failed to set acnet device for spill " << count << endl;
00122 continue;
00123 }
00124
00125 string pms = profile_monitor[ind];
00126 pms[1]='_';
00127 TH1D* xhist =
00128 hm.Book<TH1D>(Form("%sX_%03d",pms.c_str(),count),
00129 Form("ProfMon %s X view spill %d",pms.c_str(),count),
00130 nbins,min,max);
00131 TH1D* yhist =
00132 hm.Book<TH1D>(Form("%sY_%03d",pms.c_str(),count),
00133 Form("ProfMon %s Y view spill %d",pms.c_str(),count),
00134 nbins,min,max);
00135
00136 fill_profile(pm,ind,*xhist,*yhist,*xall,*yall);
00137 ++npms;
00138 }
00139
00140 }
00141
00142 void write_plots()
00143 {
00144 HistMan hm("bv");
00145 TFile file("plots.root","RECREATE");
00146 hm.WriteOut(file);
00147 file.Close();
00148 }
00149
00150 static int nentries=0;
00151
00152 void make_plots()
00153 {
00154
00155 TFile f("second.bmnt.root");
00156 TTree* bd = dynamic_cast<TTree*>(f.FindObjectAny("bd"));
00157 assert(bd);
00158 Knot k(*bd);
00159
00160 book_once();
00161
00162 Pedestals peds;
00163 peds.LoadPedFile("peds.txt");
00164
00165 nentries = k.GetSize();
00166 int count = 0;
00167 for (int entry=0; entry<nentries; ++entry) {
00168 cerr << entry << " ";
00169 k.GetEntry(entry);
00170
00171 const AcnetDevice* ad = k.GetDevice("E:TOR101");
00172 if (ad->ndata == 0) {
00173 cerr << "No E:TOR101!\n";
00174 continue;
00175 }
00176 double cut = fabs(ad->data[0]);
00177 if (cut < MIN_ETOR101) continue;
00178 ++count;
00179
00180 ProfMon pm;
00181 pm.SetScale(cut/MIN_ETOR101);
00182 book_and_fill(k,pm,peds,count);
00183 fill(k,pm,peds,count);
00184 }
00185
00186 }
00187
00188 void make_prints() {
00189 TCanvas c("c","BeamData Plots",850,1100);
00190
00191 c.Print("bdplots.ps[");
00192
00193 HistMan hm("bv");
00194 hm.Get<TH1D>("max_dae_dt")->Draw();
00195 c.Print("bdplots.ps");
00196
00197 #if 0
00198 for (int ind=1; ind <= nentries; ++ind) {
00199 HistMan hm(Form("bv/spill%03d",ind));
00200 TH2D* hx = hm.Get<TH2D>(Form("xallpm_%03d",ind));
00201 TH2D* hy = hm.Get<TH2D>(Form("yallpm_%03d",ind));
00202
00203 if (!hx || !hy) {
00204 cerr << "Failed to get hists for spill " << ind << endl;
00205 continue;
00206 }
00207
00208 c.Clear();
00209 c.Divide(1,2);
00210 c.cd(1);
00211 hx->Draw("colz");
00212 c.cd(2);
00213 hy->Draw("colz");
00214
00215 c.Print("bdplots.ps");
00216 }
00217 #endif
00218
00219 c.Print("bdplots.ps]");
00220
00221 }
00222
00223 void plots()
00224 {
00225 make_plots();
00226 make_prints();
00227 write_plots();
00228 }