00001
00002
00003
00004 #include "Registry/Registry.h"
00005
00006
00007 #include "PhysicsNtuple/Default.h"
00008 #include "PhysicsNtuple/Factory.h"
00009
00010
00011 #include "FillSnarl.h"
00012
00013 REGISTER_ANP_OBJECT(AlgSnarl,FillSnarl)
00014
00015 using namespace std;
00016
00017
00018 Anp::FillSnarl::FillSnarl()
00019 :fData(true),
00020 fBase(1000),
00021 fJump(80),
00022 fStep(40),
00023 fStop(400),
00024 fOver(8)
00025 {
00026 }
00027
00028
00029 Anp::FillSnarl::~FillSnarl()
00030 {
00031 }
00032
00033
00034 bool Anp::FillSnarl::Run(Record &record)
00035 {
00036
00037
00038
00039
00040
00041
00042
00043 vector<CountPlaneStrip> cvec;
00044
00045 for(StripIter istrip = record.StripBeg(); istrip != record.StripEnd(); ++istrip)
00046 {
00047
00048
00049
00050 CountPlaneStrip count(istrip -> GetPlane(), istrip -> GetStrip());
00051
00052
00053
00054
00055 if(std::find(cvec.begin(), cvec.end(), count) == cvec.end())
00056 {
00057 cvec.push_back(std::for_each(record.StripBeg(), record.StripEnd(), count));
00058 }
00059 }
00060
00061
00062
00063
00064
00065 vector<pair<short,short> > ignorevec;
00066 map<unsigned int, unsigned int> cmap;
00067
00068 for(vector<CountPlaneStrip>::const_iterator cit = cvec.begin(); cit != cvec.end(); ++cit)
00069 {
00070
00071
00072
00073 const unsigned int count = std::min<unsigned int>(cit -> GetCount(), fOver);
00074
00075 map<unsigned int, unsigned int>::iterator it =
00076 cmap.insert(map<unsigned int, unsigned int>::value_type(count, 0)).first;
00077
00078 ++(it -> second);
00079
00080 if(cit -> GetCount() >= fOver)
00081 {
00082 ignorevec.push_back(std::pair<short, short>(cit -> GetPlane(), cit -> GetStrip()));
00083 }
00084 }
00085
00086 for(map<unsigned int, unsigned int>::const_iterator it = cmap.begin(); it != cmap.end(); ++it)
00087 {
00088 record.Add(fBase + it -> first, static_cast<float>(it -> second));
00089 }
00090
00091
00092
00093
00094 record.Add(fBase, static_cast<float>(record.GetNStrips()));
00095
00096
00097
00098
00099
00100 for(int istep = fJump; istep <= fStop; istep += fStep)
00101 {
00102 CountAboveBelow count(static_cast<float>(istep), ignorevec);
00103
00104 count = std::for_each(record.StripBeg(), record.StripEnd(), count);
00105
00106 record.Add(fBase + istep + 1, static_cast<float>(count.GetNBelow()));
00107 record.Add(fBase + istep + 2, static_cast<float>(count.GetNAbove()));
00108
00109 record.Add(fBase + istep + 3, static_cast<float>(count.GetMeanBelow()));
00110 record.Add(fBase + istep + 4, static_cast<float>(count.GetMeanAbove()));
00111 }
00112
00113
00114
00115
00116
00117 double asum = 0.0, acount = 0.0;
00118 double isum = 0.0, icount = 0.0;
00119
00120 for(StripIter istrip = record.StripBeg(); istrip != record.StripEnd(); ++istrip)
00121 {
00122 const pair<short, short> plane_strip(istrip -> GetPlane(), istrip -> GetStrip());
00123
00124 if(std::find(ignorevec.begin(), ignorevec.end(), plane_strip) == ignorevec.end())
00125 {
00126 asum += istrip -> SigCor();
00127 acount += 1.0;
00128 }
00129 else
00130 {
00131 isum += istrip -> SigCor();
00132 icount += 1.0;
00133 }
00134 }
00135
00136 if(icount > 0.0) record.Add(fBase + fOver + 1, static_cast<float>(isum/icount));
00137 if(acount > 0.0) record.Add(fBase + fOver + 2, static_cast<float>(asum/acount));
00138
00139 return true;
00140 }
00141
00142
00143 void Anp::FillSnarl::Config(const Registry ®)
00144 {
00145
00146
00147
00148
00149
00150
00151
00152 Anp::Read(reg, "FillSnarlData", fData);
00153
00154
00155
00156
00157 reg.Get("FillSnarlBase", fBase);
00158 reg.Get("FillSnarlJump", fJump);
00159 reg.Get("FillSnarlStep", fStep);
00160 reg.Get("FillSnarlStop", fStop);
00161
00162 int value_int = 0;
00163 if(reg.Get("FillSnarlOver", value_int) && value_int > 0)
00164 {
00165 fOver = static_cast<unsigned int>(value_int);
00166 }
00167
00168 assert(fJump >= 0 && fStep > 0 && fStop >= 0 && "wrong input parameters");
00169
00170 if(reg.KeyExists("PrintConfig"))
00171 {
00172 cout << "FillSnarl::Config" << endl
00173 << " Data = " << fData << endl
00174 << " Base = " << fBase << endl
00175 << " Jump = " << fJump << endl
00176 << " Step = " << fStep << endl
00177 << " Stop = " << fStop << endl
00178 << " Over = " << fOver << endl;
00179 }
00180 }
00181
00182
00183 Anp::CountPlaneStrip::CountPlaneStrip()
00184 :plane(-1),
00185 strip(-1),
00186 count(0)
00187 {
00188 }
00189
00190
00191 Anp::CountPlaneStrip::CountPlaneStrip(const short plane_, const short strip_)
00192 :plane(plane_),
00193 strip(strip_),
00194 count(0)
00195 {
00196 }
00197
00198
00199 void Anp::CountPlaneStrip::operator()(const Strip &strip_)
00200 {
00201 assert(!(plane < 0) && !(strip < 0) && "logic error");
00202
00203 if(strip_.GetPlane() == plane && strip_.GetStrip() == strip)
00204 {
00205 ++count;
00206 }
00207 }
00208
00209
00210 unsigned int Anp::CountPlaneStrip::GetCount() const
00211 {
00212 return count;
00213 }
00214
00215
00216 short Anp::CountPlaneStrip::GetPlane() const
00217 {
00218 return plane;
00219 }
00220
00221
00222 short Anp::CountPlaneStrip::GetStrip() const
00223 {
00224 return strip;
00225 }
00226
00227
00228 bool Anp::operator==(const CountPlaneStrip &lhs, const CountPlaneStrip &rhs)
00229 {
00230 if(lhs.GetPlane() == rhs.GetPlane() && lhs.GetStrip() == rhs.GetStrip())
00231 {
00232 return true;
00233 }
00234
00235 return false;
00236 }
00237
00238
00239 Anp::CountAboveBelow::CountAboveBelow()
00240 :ignorevec(),
00241 threshold(-1.0),
00242 nabove(0),
00243 nbelow(0),
00244 sumabove(0.0),
00245 sumbelow(0.0)
00246 {
00247 }
00248
00249
00250 Anp::CountAboveBelow::CountAboveBelow(const float threshold_, const vector<pair<short,short> > &ivec)
00251 :ignorevec(ivec),
00252 threshold(threshold_),
00253 nabove(0),
00254 nbelow(0),
00255 sumabove(0.0),
00256 sumbelow(0.0)
00257 {
00258 }
00259
00260
00261 void Anp::CountAboveBelow::operator()(const Strip &strip)
00262 {
00263 assert(!(threshold < 0.0) && "logic error");
00264
00265 const pair<short, short> plane_strip(strip.GetPlane(), strip.GetStrip());
00266
00267 if(std::find(ignorevec.begin(), ignorevec.end(), plane_strip) != ignorevec.end())
00268 {
00269 return;
00270 }
00271
00272 if(strip.SigCor() > threshold)
00273 {
00274 ++nabove;
00275 sumabove += strip.SigCor();
00276 }
00277 else
00278 {
00279 ++nbelow;
00280 sumbelow += strip.SigCor();
00281 }
00282 }
00283
00284
00285 unsigned int Anp::CountAboveBelow::GetNAbove() const
00286 {
00287 return nabove;
00288 }
00289
00290
00291 unsigned int Anp::CountAboveBelow::GetNBelow() const
00292 {
00293 return nbelow;
00294 }
00295
00296
00297
00298 double Anp::CountAboveBelow::GetMeanAbove() const
00299 {
00300 if(nabove > 0)
00301 {
00302 return sumabove/static_cast<double>(nabove);
00303 }
00304
00305 return 0.0;
00306 }
00307
00308
00309 double Anp::CountAboveBelow::GetMeanBelow() const
00310 {
00311 if(nbelow > 0)
00312 {
00313 return sumbelow/static_cast<double>(nbelow);
00314 }
00315
00316 return 0.0;
00317 }
00318