00001
00002
00003 #include <cmath>
00004 #include <iostream>
00005
00006
00007 #include "TDirectory.h"
00008 #include "TCanvas.h"
00009 #include "TH1F.h"
00010 #include "TH2F.h"
00011 #include "TGraph.h"
00012
00013
00014 #include "DrawUtil.h"
00015 #include "PhysicsNtuple/Factory.h"
00016 #include "SnarlAdcTab.h"
00017
00018 REGISTER_ANP_OBJECT(EventTab,SnarlAdcTab)
00019
00020 using namespace std;
00021
00022
00023 Anp::SnarlAdcTab::SnarlAdcTab()
00024 :fInit(false),
00025 fDraw(true),
00026 fCanvas(0),
00027 fPadU(0),
00028 fPadV(0),
00029 f2hU(0),
00030 f2hV(0)
00031 {
00032 }
00033
00034
00035 Anp::SnarlAdcTab::~SnarlAdcTab()
00036 {
00037 for(std::vector<TObject *>::iterator it = fObjVec.begin(); it != fObjVec.begin(); ++it)
00038 {
00039 TObject *obj = *it;
00040 delete obj;
00041 }
00042 }
00043
00044
00045 void Anp::SnarlAdcTab::Set(const Event& event, const Record& record)
00046 {
00047 if(!fInit)
00048 {
00049 Init(record);
00050 }
00051 else
00052 {
00053 Reset();
00054 }
00055
00056 if(!f2hU || !f2hV)
00057 {
00058 return;
00059 }
00060
00061 fSpan.FindSpan(event, record);
00062
00063 StripVec uvec = GetStrip(event, record, "U");
00064 StripVec vvec = GetStrip(event, record, "V");
00065
00066 if(uvec.empty() || vvec.empty())
00067 {
00068 cerr << "SnarlAdcTab::SetEvent() - no strips matching a track" << endl;
00069 return;
00070 }
00071
00072 Add(uvec, record, "U");
00073 Add(vvec, record, "V");
00074
00075 for(Draw::SIter sit = uvec.begin(); sit != uvec.end(); ++sit)
00076 {
00077 f2hU -> Fill((*sit) -> ZPos(), (*sit) -> TPos(), (*sit) -> SigCor());
00078 }
00079
00080 for(Draw::SIter sit = vvec.begin(); sit != vvec.end(); ++sit)
00081 {
00082 f2hV -> Fill((*sit) -> ZPos(), (*sit) -> TPos(), (*sit) -> SigCor());
00083 }
00084 }
00085
00086
00087 void Anp::SnarlAdcTab::Init(TCanvas *canvas)
00088 {
00089 if(!canvas)
00090 {
00091 cerr << "SnarlAdcTab::Expose(): null TCanvas pointer" << endl;
00092 return;
00093 }
00094 if(fPadU || fPadV || fCanvas)
00095 {
00096 cerr << "SnarlAdcTab::Expose(): pads have been already initialized" << endl;
00097 return;
00098 }
00099
00100 fCanvas = canvas;
00101
00102 fCanvas -> Divide(0, 2);
00103
00104 fPadU = dynamic_cast<TPad *> (canvas -> cd(1));
00105 fPadV = dynamic_cast<TPad *> (canvas -> cd(2));
00106
00107 if(!fPadU || !fPadV)
00108 {
00109 cerr << "SnarlAdcTab::Expose(): failed to create new pads" << endl;
00110 fCanvas = 0;
00111 fPadU = 0;
00112 fPadV = 0;
00113 return;
00114 }
00115
00116 Draw::Config(fPadU, "", fConfig);
00117 Draw::Config(fPadV, "", fConfig);
00118 }
00119
00120
00121 void Anp::SnarlAdcTab::Expose()
00122 {
00123 if(!fInit)
00124 {
00125 return;
00126 }
00127
00128 if(!fPadU || !fPadV)
00129 {
00130 return;
00131 }
00132
00133 if(fDraw)
00134 {
00135 fPadU -> cd();
00136 f2hU -> Draw("colz");
00137
00138 fPadV -> cd();
00139 f2hV -> Draw("colz");
00140
00141 fDraw = false;
00142 }
00143
00144 fCanvas -> cd();
00145 fCanvas -> Modified();
00146 fCanvas -> Update();
00147 }
00148
00149
00150 void Anp::SnarlAdcTab::Config(const Registry ®)
00151 {
00152 fConfig.UnLockValues();
00153 fConfig.Merge(reg);
00154 fConfig.LockValues();
00155 }
00156
00157
00158 bool Anp::SnarlAdcTab::Init(const Record &)
00159 {
00160 if(fInit)
00161 {
00162 cerr << "SnarlAdcTab is already initialized" << endl;
00163 return false;
00164 }
00165
00166 fInit = true;
00167
00168 f2hU = Draw::CreateTH2("Uview", fConfig);
00169 f2hV = Draw::CreateTH2("Vview", fConfig);
00170
00171 fObjVec.push_back(f2hU);
00172 fObjVec.push_back(f2hV);
00173
00174 return true;
00175 }
00176
00177
00178 void Anp::SnarlAdcTab::Reset()
00179 {
00180 fDraw = true;
00181
00182 fSpan.Reset();
00183
00184 if(f2hU)
00185 {
00186 f2hU -> Reset();
00187 }
00188 if(f2hV)
00189 {
00190 f2hV -> Reset();
00191 }
00192 }
00193
00194
00195 void Anp::SnarlAdcTab::Add(StripVec &svec, const Record &record, const string &view)
00196 {
00197 static double TimeWindow = 20.0e-9;
00198 static bool init = false;
00199 if(!init)
00200 {
00201 TimeWindow = Draw::Read("TimeWindow", TimeWindow, fConfig);
00202 init = true;
00203 }
00204
00205 const double min = fSpan.GetMinTime(TimeWindow);
00206 const double max = fSpan.GetMaxTime(TimeWindow);
00207
00208 for(StripIter strip = record.StripBeg(); strip != record.StripEnd(); ++strip)
00209 {
00210 if(strip -> Time() < min || strip -> Time() > max)
00211 {
00212 continue;
00213 }
00214
00215 if(view == "U" && strip -> IsUview())
00216 {
00217 svec.push_back(strip);
00218 }
00219 if(view == "V" && strip -> IsVview())
00220 {
00221 svec.push_back(strip);
00222 }
00223 }
00224 }
00225
00226
00227 void Anp::SnarlAdcTab::ZoomIn()
00228 {
00229 fDraw = true;
00230
00231 static double ZoomBorderScale = 1.2;
00232 static double ZoomBorderWidth = 0.1;
00233
00234 static bool init = false;
00235 if(!init)
00236 {
00237 init = true;
00238 ZoomBorderScale = Draw::Read("ZoomBorderScale", ZoomBorderScale, fConfig);
00239 ZoomBorderWidth = Draw::Read("ZoomBorderWidth", ZoomBorderWidth, fConfig);
00240
00241 if(ZoomBorderScale < 1.0) ZoomBorderScale = 1.2;
00242 if(ZoomBorderWidth < 0.0) ZoomBorderWidth = 0.1;
00243 }
00244
00245 if(fSpan.InitU())
00246 {
00247 fSpan.SetRangeU(f2hU -> GetYaxis(), ZoomBorderScale, ZoomBorderWidth);
00248 }
00249 if(fSpan.InitZ())
00250 {
00251 fSpan.SetRangeZ(f2hU -> GetXaxis(), ZoomBorderScale, ZoomBorderWidth);
00252 }
00253 if(fSpan.InitV())
00254 {
00255 fSpan.SetRangeV(f2hV -> GetYaxis(), ZoomBorderScale, ZoomBorderWidth);
00256 }
00257 if(fSpan.InitZ())
00258 {
00259 fSpan.SetRangeZ(f2hV -> GetXaxis(), ZoomBorderScale, ZoomBorderWidth);
00260 }
00261 }
00262
00263
00264 void Anp::SnarlAdcTab::ZoomOut()
00265 {
00266 fDraw = true;
00267
00268 f2hU -> GetXaxis() -> UnZoom();
00269 f2hU -> GetYaxis() -> UnZoom();
00270
00271 f2hV -> GetXaxis() -> UnZoom();
00272 f2hV -> GetYaxis() -> UnZoom();
00273 }