00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00017
00018 #include <cassert>
00019 #include <cmath>
00020
00021 #include "Algorithm/AlgFactory.h"
00022 #include "Algorithm/AlgHandle.h"
00023 #include "Algorithm/AlgConfig.h"
00024 #include "Candidate/CandContext.h"
00025 #include "CandShowerSR/AlgShowerSRList.h"
00026 #include "RecoBase/CandShower.h"
00027 #include "RecoBase/CandShower.h"
00028 #include "RecoBase/CandShowerHandle.h"
00029 #include "RecoBase/CandShowerList.h"
00030 #include "RecoBase/CandShowerListHandle.h"
00031 #include "Conventions/PlaneView.h"
00032 #include "MessageService/MsgService.h"
00033 #include "MinosObjectMap/MomNavigator.h"
00034 #include "Navigation/NavKey.h"
00035 #include "Navigation/NavSet.h"
00036 #include "RecoBase/CandClusterHandle.h"
00037 #include "RecoBase/CandClusterListHandle.h"
00038 #include "RecoBase/CandSliceHandle.h"
00039 #include "RecoBase/CandSliceListHandle.h"
00040 #include "UgliGeometry/UgliGeomHandle.h"
00041 #include "Validity/VldContext.h"
00042 #include <string.h>
00043
00044 ClassImp(AlgShowerSRList)
00045
00046
00047
00048 CVSID("$Id: AlgShowerSRList.cxx,v 1.24 2006/12/01 18:50:24 rhatcher Exp $");
00049
00050
00051 AlgShowerSRList::AlgShowerSRList()
00052 {
00053 }
00054
00055
00056 AlgShowerSRList::~AlgShowerSRList()
00057 {
00058 }
00059
00060
00070 void AlgShowerSRList::RunAlg(AlgConfig &ac, CandHandle &ch,CandContext &cx)
00071 {
00072 assert(cx.GetDataIn());
00073
00074 if (!(cx.GetDataIn()->InheritsFrom("TObjArray"))) {
00075 return;
00076 }
00077
00078 Int_t diffViewPlaneMatch = ac.GetInt("DiffViewPlaneMatch");
00079 Double_t diffViewTimeMatch = ac.GetDouble("DiffViewTimeMatch");
00080 Int_t planeScale = ac.GetInt("PlaneScale");
00081 Int_t diffViewPlaneMatchShort = ac.GetInt("DiffViewPlaneMatchShort");
00082 Double_t diffViewPlaneCoverage = ac.GetDouble("DiffViewPlaneCoverage");
00083 Double_t diffViewPulseHeightCut = ac.GetDouble("DiffViewPulseHeightCut");
00084
00085 const CandSliceListHandle *slicelist = 0;
00086 const CandClusterListHandle *clusterlist = 0;
00087 const TObjArray *cxin = dynamic_cast<const TObjArray *>(cx.GetDataIn());
00088 for (Int_t i=0; i<=cxin->GetLast(); i++) {
00089 TObject *tobj = cxin->At(i);
00090 if (tobj->InheritsFrom("CandSliceListHandle")) {
00091 slicelist = dynamic_cast<CandSliceListHandle*>(tobj);
00092 }
00093 if (tobj->InheritsFrom("CandClusterListHandle")) {
00094 clusterlist = dynamic_cast<CandClusterListHandle*>(tobj);
00095 }
00096 }
00097 if (!slicelist || !clusterlist) {
00098 MSG("error",Msg::kError) <<
00099 "CandSliceListHandle or CandClusterListHandle missing\n";
00100 }
00101
00102 CandContext cxx(this,cx.GetMom());
00103 AlgFactory &af = AlgFactory::GetInstance();
00104
00105 const char *showerAlgConfig = 0;
00106 ac.Get("ShowerAlgConfig",showerAlgConfig);
00107 AlgHandle ah = af.GetAlgHandle("AlgShowerSR",showerAlgConfig);
00108
00109 const CandRecord *candrec = cx.GetCandRecord();
00110 assert(candrec);
00111 const VldContext *vldcptr = candrec->GetVldContext();
00112 assert(vldcptr);
00113 VldContext vldc = *vldcptr;
00114
00115 UgliGeomHandle ugh(vldc);
00116
00117
00118 CandSliceHandleItr sliceItr(slicelist->GetDaughterIterator());
00119 while (CandSliceHandle *slice = sliceItr()) {
00120
00121
00122 CandClusterHandleItr clusterItr(clusterlist->GetDaughterIterator());
00123 CandClusterHandleKeyFunc *clusterKf = clusterItr.CreateKeyFunc();
00124 clusterKf->SetFun(CandClusterHandle::KeyFromSlice);
00125 clusterItr.GetSet()->AdoptSortKeyFunc(clusterKf);
00126 clusterKf = 0;
00127 clusterItr.GetSet()->Slice(static_cast<Int_t>(slice->GetUidInt()));
00128
00129
00130 TObjArray showerlist;
00131 TObjArray uclusterlist;
00132 TObjArray vclusterlist;
00133
00134
00135 while (CandClusterHandle *cluster = clusterItr()) {
00136 if (*cluster->GetCandSlice()==*slice) {
00137 switch (cluster->GetPlaneView()) {
00138 case PlaneView::kU:
00139 uclusterlist.Add(cluster);
00140 break;
00141 case PlaneView::kV:
00142 vclusterlist.Add(cluster);
00143 break;
00144 default:
00145 break;
00146 }
00147 }
00148 }
00149
00150
00151 for (Int_t iu=0; iu<=uclusterlist.GetLast(); iu++) {
00152 CandClusterHandle *ucluster =
00153 dynamic_cast<CandClusterHandle*>(uclusterlist.At(iu));
00154 Float_t highesttotE=0;
00155 Int_t bestiv=0;
00156 Bool_t found=false;
00157 for (Int_t iv=0; iv<=vclusterlist.GetLast(); iv++) {
00158 CandClusterHandle *vcluster =
00159 dynamic_cast<CandClusterHandle*>(vclusterlist.At(iv));
00160
00161
00162
00163 Int_t ubeg = ucluster->GetBegPlane();
00164 Int_t uend = ucluster->GetEndPlane();
00165 Int_t vbeg = vcluster->GetBegPlane();
00166 Int_t vend = vcluster->GetEndPlane();
00167 Int_t idir=1;
00168 if (ubeg>uend) idir=-1;
00169 Int_t dplanecover = idir*(min(uend*idir,vend*idir)-max(ubeg*idir,vbeg*idir));
00170 Int_t mincoverage = min(abs(1+uend-ubeg),abs(1+vend-vbeg));
00171 Float_t dplanecoverfrac = (Float_t)(dplanecover)/(Float_t)(mincoverage);
00172
00173
00174 Float_t totE=max(ucluster->GetCharge()+vcluster->GetCharge(),1.)/330.;
00175 Float_t dE = fabs(ucluster->GetCharge()-vcluster->GetCharge())/330.;
00176 Float_t dpulseheight = dE/sqrt(totE);
00177
00178
00179 Int_t ishort=0;
00180 if (abs(vbeg-vend)>planeScale && abs(ubeg-uend)>planeScale) {
00181 ishort = 2;
00182 } else
00183 if (abs(vbeg-vend)>planeScale || abs(ubeg-uend)>planeScale) {
00184 ishort = 1;
00185 } else {
00186 ishort = 0;
00187 }
00188
00189
00190
00191
00192
00193
00194 Bool_t passplanematch(0);
00195 if ((ishort==2 && abs(ubeg-vbeg)<=diffViewPlaneMatch) || (ishort<2 && abs(ubeg-vbeg)<=diffViewPlaneMatchShort)) passplanematch=1;
00196
00197
00198 Bool_t passtimematch(0);
00199 if (fabs(ucluster->GetBegTime()-vcluster->GetBegTime())<diffViewTimeMatch) passtimematch=1;
00200
00201
00202
00203 Bool_t passplanecoverage(1);
00204 if (ishort==2) {
00205 if (dplanecover<0 || dplanecoverfrac<diffViewPlaneCoverage) passplanecoverage=0;
00206 }
00207
00208
00209 Bool_t passpulseheight(1);
00210 if (ishort>=1) {
00211 if (dpulseheight>diffViewPulseHeightCut) passpulseheight=0;
00212 }
00213
00214
00215 if (passplanematch && passtimematch && passplanecoverage && passpulseheight) {
00216
00217
00218
00219
00220 Bool_t foundbetteriu=false;
00221 for (Int_t iu2=0; iu2<=uclusterlist.GetLast(); iu2++) {
00222 CandClusterHandle *ucluster2 =
00223 dynamic_cast<CandClusterHandle*>(uclusterlist.At(iu2));
00224 Int_t ubeg2 = ucluster2->GetBegPlane();
00225 Int_t uend2 = ucluster2->GetEndPlane();
00226 Int_t idir2=1;
00227 if (ubeg2>uend2) idir2=-1;
00228 Int_t dplanecover2 = idir2*(min(uend2*idir,vend*idir)-max(ubeg2*idir,vbeg*idir));
00229 Int_t mincoverage2 = min(abs(1+uend2-ubeg2),abs(1+vend-vbeg));
00230 Float_t dplanecoverfrac2 = (Float_t)(dplanecover2)/(Float_t)(mincoverage2);
00231
00232
00233 Float_t totE2=max(ucluster2->GetCharge()+vcluster->GetCharge(),1.)/330.;
00234 Float_t dE2 = fabs(ucluster2->GetCharge()-vcluster->GetCharge())/330.;
00235 Float_t dpulseheight2 = dE2/sqrt(totE2);
00236
00237 Int_t ishort2=0;
00238 if (abs(vbeg-vend)>planeScale && abs(ubeg2-uend2)>planeScale) {
00239 ishort2 = 2;
00240 } else
00241 if (abs(vbeg-vend)>planeScale || abs(ubeg2-uend2)>planeScale) {
00242 ishort2 = 1;
00243 } else {
00244 ishort2 = 0;
00245 }
00246
00247 Bool_t passplanematch2(0);
00248 if ((ishort2==2 && abs(ubeg2-vbeg)<=diffViewPlaneMatch) ||
00249 (ishort2<2 && abs(ubeg2-vbeg)<=diffViewPlaneMatchShort))
00250 passplanematch2=1;
00251
00252 Bool_t passtimematch2(0);
00253 if (fabs(ucluster2->GetBegTime()-vcluster->GetBegTime())<
00254 diffViewTimeMatch) passtimematch2=1;
00255
00256 Bool_t passplanecoverage2(1);
00257 if (ishort2==2) {
00258 if (dplanecover2<0 ||
00259 dplanecoverfrac2<diffViewPlaneCoverage) passplanecoverage2=0;
00260 }
00261
00262 Bool_t passpulseheight2(1);
00263 if (ishort2>=1) {
00264 if (dpulseheight2>diffViewPulseHeightCut) passpulseheight2=0;
00265 }
00266
00267
00268
00269 if (passplanematch2 &&
00270 passtimematch2 &&
00271 passplanecoverage2 &&
00272 passpulseheight2 &&
00273 totE2>totE) {
00274 foundbetteriu=true;
00275 }
00276 }
00277
00278
00279 if(!foundbetteriu){
00280 found=true;
00281 if(totE>highesttotE){
00282 highesttotE=totE;
00283 bestiv=iv;
00284 }
00285 }
00286 }
00287 }
00288
00289
00290 if(found){
00291 CandClusterHandle *vcluster = dynamic_cast<CandClusterHandle*>(vclusterlist.At(bestiv));
00292 TObjArray newshower;
00293 newshower.Add(ucluster);
00294 newshower.Add(vcluster);
00295 cxx.SetDataIn(&newshower);
00296 CandShowerHandle showerhandle = CandShower::MakeCandidate(ah,cxx);
00297 showerhandle.SetCandSlice(slice);
00298 ch.AddDaughterLink(showerhandle);
00299 }
00300 }
00301 }
00302 }
00303
00304
00305
00306
00307
00308
00309 void AlgShowerSRList::Trace(const char * ) const
00310 {
00311 }
00312
00313