00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00021
00022 #include <cassert>
00023
00024 #include "Algorithm/AlgConfig.h"
00025 #include "Algorithm/AlgFactory.h"
00026 #include "Algorithm/AlgHandle.h"
00027 #include "Candidate/CandContext.h"
00028 #include "MessageService/MsgService.h"
00029 #include "RecoBase/CandSliceHandle.h"
00030 #include "RecoBase/CandSliceListHandle.h"
00031 #include "UgliGeometry/UgliGeomHandle.h"
00032 #include "BubbleSpeak/AlgBandClusterList.h"
00033 #include "BubbleSpeak/CandMSTCluster.h"
00034 #include "BubbleSpeak/CandMSTClusterHandle.h"
00035 #include "BubbleSpeak/CandDigiPairHandle.h"
00036
00037 ClassImp(AlgBandClusterList)
00038
00039
00040
00041 CVSID("$Id: AlgBandClusterList.cxx,v 1.5 2003/08/22 18:35:43 miyagawa Exp $");
00042
00043
00044
00045 AlgBandClusterList::AlgBandClusterList()
00046 {
00047
00048
00049
00050
00051
00052
00053
00054 }
00055
00056
00057
00058 AlgBandClusterList::~AlgBandClusterList()
00059 {
00060
00061
00062
00063
00064
00065
00066
00067 }
00068
00069
00070
00071 void AlgBandClusterList::RunAlg(AlgConfig &ac, CandHandle &ch,
00072 CandContext &cx)
00073 {
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 MSG("BubAlg", Msg::kVerbose)
00088 << "Starting AlgBandClusterList::RunAlg()" << endl;
00089
00090
00091 assert(cx.GetDataIn());
00092 assert(cx.GetDataIn()->InheritsFrom("CandSliceListHandle"));
00093 const CandSliceListHandle *cslh =
00094 dynamic_cast<const CandSliceListHandle*>(cx.GetDataIn());
00095
00096
00097 TIter cshItr(cslh->GetDaughterIterator());
00098 while (CandSliceHandle *csh =
00099 dynamic_cast<CandSliceHandle *>(cshItr())) {
00100 RunAlgOnSlice(ac, ch, cx, csh);
00101 }
00102 }
00103
00104
00105
00106 void AlgBandClusterList::RunAlgOnSlice(AlgConfig &ac, CandHandle &ch,
00107 CandContext &cx, CandSliceHandle *csh)
00108 {
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 MSG("BubAlg", Msg::kVerbose)
00125 << "Starting AlgBandClusterList::RunAlgOnSlice()" << endl;
00126
00127
00128 Double_t bandspan = ac.GetDouble("BandSpan");
00129
00130
00131 Double_t utsum = 0;
00132 Double_t ut2sum = 0;
00133 Double_t utzsum = 0;
00134 Double_t uzsum = 0;
00135 Double_t uz2sum = 0;
00136 Double_t uwtsum = 0;
00137 Double_t vtsum = 0;
00138 Double_t vt2sum = 0;
00139 Double_t vtzsum = 0;
00140 Double_t vzsum = 0;
00141 Double_t vz2sum = 0;
00142 Double_t vwtsum = 0;
00143 TIter chhItr(csh->GetDaughterIterator());
00144 while (const CandDigiPairHandle *chh =
00145 dynamic_cast<const CandDigiPairHandle *>(chhItr())) {
00146
00147
00148 Bool_t east = kFALSE;
00149 Bool_t west = kFALSE;
00150 TIter cdhItr(chh->GetDaughterIterator());
00151 while (const CandDigitHandle *cdh =
00152 dynamic_cast<const CandDigitHandle *>(cdhItr())) {
00153 StripEnd::StripEnd_t ende = cdh->GetPlexSEIdAltL().GetEnd();
00154 if (ende == StripEnd::kEast) east = kTRUE;
00155 else if (ende == StripEnd::kWest) west = kTRUE;
00156
00157
00158 if (east && west) {
00159 Double_t tpos = chh->GetTPos();
00160 Double_t zpos = chh->GetZPos();
00161 Double_t wt = chh->GetCharge();
00162 switch (chh->GetPlaneView()) {
00163 case PlaneView::kU:
00164 utsum += wt * tpos;
00165 ut2sum += wt * tpos * tpos;
00166 utzsum += wt * tpos * zpos;
00167 uzsum += wt * zpos;
00168 uz2sum += wt * zpos * zpos;
00169 uwtsum += wt;
00170 break;
00171 case PlaneView::kV:
00172 vtsum += wt * tpos;
00173 vt2sum += wt * tpos * tpos;
00174 vtzsum += wt * tpos * zpos;
00175 vzsum += wt * zpos;
00176 vz2sum += wt * zpos * zpos;
00177 vwtsum += wt;
00178 break;
00179 default:
00180 break;
00181 }
00182 continue;
00183 }
00184 }
00185 }
00186
00187
00188 Double_t udet = uwtsum * uz2sum - uzsum * uzsum;
00189 Double_t uinter, uslope;
00190 if (udet != 0.) {
00191 uinter = (utsum * uz2sum - utzsum * uzsum) / udet;
00192 uslope = (uwtsum * utzsum - uzsum * utsum) / udet;
00193 }
00194 else {
00195 uinter = (uwtsum!=0. ? utsum / uwtsum : -1e12);
00196 uslope = 1e12;
00197 }
00198 Double_t uslope2_1 = uslope * uslope + 1;
00199
00200 Double_t vdet = vwtsum * vz2sum - vzsum * vzsum;
00201 Double_t vinter, vslope;
00202 if (vdet != 0.) {
00203 vinter = (vtsum * vz2sum - vtzsum * vzsum) / vdet;
00204 vslope = (vwtsum * vtzsum - vzsum * vtsum) / vdet;
00205 }
00206 else {
00207 vinter = (vwtsum!=0. ? vtsum / vwtsum : -1e12);
00208 vslope = 1e12;
00209 }
00210 Double_t vslope2_1 = vslope * vslope + 1;
00211
00212
00213 Float_t cellwidth = 0;
00214 chhItr.Reset();
00215 while (const CandDigiPairHandle *chht =
00216 dynamic_cast<const CandDigiPairHandle *>(chhItr())) {
00217 UgliGeomHandle ugh(*chht->GetVldContext());
00218 UgliStripHandle ush = ugh.GetStripHandle(chht->GetStripEndId());
00219 if (ush.IsValid()) {
00220 cellwidth = ush.GetHalfWidth();
00221 cellwidth *= 2.0;
00222 break;
00223 }
00224 }
00225
00226
00227 Double_t d2check = bandspan * cellwidth;
00228 d2check *= d2check;
00229
00230
00231 TObjArray *mainU = 0;
00232 TObjArray *mainV = 0;
00233 TObjArray *others = 0;
00234 TObjArray *arrayA = 0;
00235 TObjArray *arrayB = 0;
00236 TObjArray *shield = 0;
00237 chhItr.Reset();
00238 while (CandDigiPairHandle *chh =
00239 dynamic_cast<CandDigiPairHandle *>(chhItr())) {
00240 Double_t xdat = chh->GetZPos();
00241 Double_t ydat = chh->GetTPos();
00242 Double_t d2diff = 0;
00243
00244
00245 if (chh->GetStripEndId().IsVetoShield()) {
00246 if (!shield) shield = new TObjArray();
00247 shield->Add(chh);
00248 continue;
00249 }
00250
00251
00252 switch (chh->GetPlaneView()) {
00253
00254 case PlaneView::kU:
00255 d2diff = ydat - uinter - uslope * xdat;
00256 d2diff *= d2diff;
00257 d2diff /= uslope2_1;
00258 if (d2diff <= d2check) {
00259 if (!mainU) mainU = new TObjArray();
00260 mainU->Add(chh);
00261 }
00262 else {
00263 if (!others) others = new TObjArray();
00264 others->Add(chh);
00265 }
00266 break;
00267
00268 case PlaneView::kV:
00269 d2diff = ydat - vinter - vslope * xdat;
00270 d2diff *= d2diff;
00271 d2diff /= vslope2_1;
00272 if (d2diff <= d2check) {
00273 if (!mainV) mainV = new TObjArray();
00274 mainV->Add(chh);
00275 }
00276 else {
00277 if (!others) others = new TObjArray();
00278 others->Add(chh);
00279 }
00280 break;
00281
00282 case PlaneView::kA:
00283 if (!arrayA) arrayA = new TObjArray();
00284 arrayA->Add(chh);
00285 break;
00286
00287 case PlaneView::kB:
00288 if (!arrayB) arrayB = new TObjArray();
00289 arrayB->Add(chh);
00290 break;
00291
00292 default:
00293 MSG("BubAlg", Msg::kWarning)
00294 << "Invalid plane orientation." << endl;
00295 }
00296 }
00297
00298
00299 MSG("BubAlg", Msg::kVerbose)
00300 << "AlgFactory &af = AlgFactory::GetInstance();" << endl;
00301 AlgFactory &af = AlgFactory::GetInstance();
00302
00303 MSG("BubAlg", Msg::kVerbose)
00304 << "AlgHandle ah = af.GetAlgHandle(\"AlgMSTCluster\","
00305 << "\"default\");" << endl;
00306 AlgHandle ah = af.GetAlgHandle("AlgMSTCluster", "default");
00307
00308 MSG("BubAlg", Msg::kVerbose)
00309 << "Create CandContext instance." << endl;
00310 CandContext cxx(this, cx.GetMom());
00311 cxx.SetCandRecord(cx.GetCandRecord());
00312
00313
00314
00315 if (mainU) {
00316 cxx.SetDataIn(mainU);
00317 CandMSTClusterHandle clh = CandMSTCluster::MakeCandidate(ah, cxx);
00318 clh.SetCandSlice(csh);
00319 ch.AddDaughterLink(clh);
00320 delete mainU;
00321 mainU = 0;
00322 }
00323
00324
00325 if (mainV) {
00326 cxx.SetDataIn(mainV);
00327 CandMSTClusterHandle clh = CandMSTCluster::MakeCandidate(ah, cxx);
00328 clh.SetCandSlice(csh);
00329 ch.AddDaughterLink(clh);
00330 delete mainV;
00331 mainV = 0;
00332 }
00333
00334
00335 if (others) {
00336 TIter chhItr(others);
00337 while (CandDigiPairHandle *chh =
00338 dynamic_cast<CandDigiPairHandle *>(chhItr())) {
00339 TObjArray *toay = new TObjArray();
00340 toay->Add(chh);
00341 cxx.SetDataIn(toay);
00342 CandMSTClusterHandle clh
00343 = CandMSTCluster::MakeCandidate(ah, cxx);
00344 clh.SetCandSlice(csh);
00345 ch.AddDaughterLink(clh);
00346 delete toay;
00347 toay = 0;
00348 }
00349 delete others;
00350 others = 0;
00351 }
00352
00353
00354 if (arrayA) {
00355 cxx.SetDataIn(arrayA);
00356 CandMSTClusterHandle clh = CandMSTCluster::MakeCandidate(ah, cxx);
00357 clh.SetCandSlice(csh);
00358 ch.AddDaughterLink(clh);
00359 delete arrayA;
00360 arrayA = 0;
00361 }
00362
00363
00364 if (arrayB) {
00365 cxx.SetDataIn(arrayB);
00366 CandMSTClusterHandle clh = CandMSTCluster::MakeCandidate(ah, cxx);
00367 clh.SetCandSlice(csh);
00368 ch.AddDaughterLink(clh);
00369 delete arrayB;
00370 arrayB = 0;
00371 }
00372
00373
00374 if (shield) {
00375 cxx.SetDataIn(shield);
00376 CandMSTClusterHandle clh = CandMSTCluster::MakeCandidate(ah, cxx);
00377 clh.SetCandSlice(csh);
00378 ch.AddDaughterLink(clh);
00379 delete shield;
00380 shield = 0;
00381 }
00382 }
00383
00384
00385
00386 void AlgBandClusterList::Trace(const char *c) const
00387 {
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397 MSG("BubCand", Msg::kDebug)
00398 << "**********Begin AlgBandClusterList::Trace(\"" << c << "\")"
00399 << endl
00400 << "**********End AlgBandClusterList::Trace(\"" << c << "\")"
00401 << endl;
00402 }