00001 #include <cstdlib>
00002
00003 #include "AlgFarDetEventList.h"
00004 #include "FarDetEventHandle.h"
00005 #include "FarDetEventListHandle.h"
00006
00007 #include "Algorithm/AlgFactory.h"
00008 #include "Algorithm/AlgHandle.h"
00009 #include "Algorithm/AlgConfig.h"
00010
00011 #include "MessageService/MsgService.h"
00012 #include "MinosObjectMap/MomNavigator.h"
00013
00014 #include "RecoBase/CandFitTrackListHandle.h"
00015 #include "RecoBase/CandFitTrackHandle.h"
00016 #include "RecoBase/CandTrackListHandle.h"
00017 #include "RecoBase/CandTrackHandle.h"
00018 #include "RecoBase/CandShowerListHandle.h"
00019 #include "RecoBase/CandShowerHandle.h"
00020 #include "RecoBase/CandStripListHandle.h"
00021 #include "RecoBase/CandStripHandle.h"
00022
00023 #include "Candidate/CandContext.h"
00024
00025 ClassImp(AlgFarDetEventList)
00026
00027 CVSID("$Id: AlgFarDetEventList.cxx,v 1.4 2009/02/28 21:46:10 gmieg Exp $");
00028
00029 AlgFarDetEventList::AlgFarDetEventList()
00030 {
00031
00032 }
00033
00034 AlgFarDetEventList::~AlgFarDetEventList()
00035 {
00036
00037 }
00038
00039 void AlgFarDetEventList::RunAlg(AlgConfig& , CandHandle &ch, CandContext &cx)
00040 {
00041 MSG("FarDetEvent",Msg::kDebug) << " AlgFarDetEventList::RunAlg(...) " << endl;
00042
00043 FarDetEventListHandle& fdeventlist = dynamic_cast<FarDetEventListHandle&>(ch);
00044
00045 const TObjArray* arr = dynamic_cast<const TObjArray*>(cx.GetDataIn());
00046
00047 AlgFactory &af = AlgFactory::GetInstance();
00048 AlgHandle ah = af.GetAlgHandle("AlgFarDetEvent","default");
00049 CandRecord* candrec = (CandRecord*)(cx.GetCandRecord());
00050 CandContext cxnew(this, cx.GetMom());
00051 cxnew.SetCandRecord(candrec);
00052
00053
00054 TObjArray* eventinfo = new TObjArray();
00055
00056
00057
00058 eventinfo->Clear();
00059
00060
00061 MSG("FarDetEvent",Msg::kVerbose) << " GET TRACK INFORMATION " << endl;
00062 CandFitTrackListHandle* fitlist = (CandFitTrackListHandle*)(arr->At(0));
00063 CandFitTrackHandle* bestFitTrack=0;
00064
00065 CandTrackListHandle* trklist = (CandTrackListHandle*)(arr->At(1));
00066 CandTrackHandle* bestTrack=0;
00067
00068
00069 if( fitlist )
00070 {
00071 Double_t bestFitTracklength=-1.0;
00072 TIter fititr(fitlist->GetDaughterIterator());
00073 while(CandFitTrackHandle* fit = (CandFitTrackHandle*)(fititr()))
00074 {
00075 if(fit)
00076 {
00077 if(fit->GetRange()>bestFitTracklength)
00078 {
00079 bestFitTrack = fit;
00080 bestFitTracklength = bestFitTrack->GetRange();
00081 }
00082 }
00083 }
00084
00085 }
00086
00087
00088 else if( trklist )
00089 {
00090 Double_t bestTracklength=-1.0;
00091 TIter trkitr(trklist->GetDaughterIterator());
00092 while(CandTrackHandle* trk = (CandTrackHandle*)(trkitr()))
00093 {
00094 if(trk)
00095 {
00096 if(trk->GetRange()>bestTracklength)
00097 {
00098 bestTrack = trk;
00099 bestTracklength = bestTrack->GetRange();
00100 }
00101 }
00102 }
00103 }
00104
00105 eventinfo->Add(bestFitTrack);
00106 eventinfo->Add(bestTrack);
00107
00108 CandTrackHandle* primaryTrack = 0;
00109 if( bestFitTrack ) primaryTrack=(CandTrackHandle*)bestFitTrack;
00110 else if( bestTrack ) primaryTrack=(CandTrackHandle*)bestTrack;
00111
00112 if( primaryTrack ){
00113 MSG("FarDetEvent",Msg::kVerbose) << " ...found a primary track " << endl;
00114 }
00115 else{
00116 MSG("FarDetEvent",Msg::kVerbose) << " ...there is no primary track " << endl;
00117 }
00118
00119
00120
00121 MSG("FarDetEvent",Msg::kVerbose) << " GET SHOWER INFORMATION " << endl;
00122 CandShowerListHandle* shwlist = (CandShowerListHandle*)(arr->At(2));
00123
00124 CandShowerHandle* vtxshower = 0;
00125 TObjArray* HadronicShowers = new TObjArray();
00126 TObjArray* BremsAndDeltas = new TObjArray();
00127
00128 if( shwlist )
00129 {
00130
00131 Double_t separation(999.),temp(999.),shwenergy(0.0);
00132 if( primaryTrack )
00133 {
00134 this->CompareShowersWithTrack(primaryTrack,
00135 shwlist,
00136 vtxshower,
00137 HadronicShowers,
00138 BremsAndDeltas,
00139 separation);
00140 }
00141
00142 else
00143 {
00144 TIter shwitr(shwlist->GetDaughterIterator());
00145 while(CandShowerHandle* shw = (CandShowerHandle*)(shwitr()))
00146 {
00147 if( shw )
00148 {
00149 temp=shw->GetEnergy();
00150 if(temp>shwenergy)
00151 {
00152 vtxshower=shw;
00153 shwenergy=temp;
00154 }
00155 }
00156 }
00157 }
00158 }
00159
00160 if( vtxshower ){
00161 MSG("FarDetEvent",Msg::kVerbose) << " ...found a primary shower " << endl;
00162 }
00163 else{
00164 MSG("FarDetEvent",Msg::kVerbose) << " ...there is no primary shower " << endl;
00165 }
00166
00167 eventinfo->Add(vtxshower);
00168 eventinfo->Add(HadronicShowers);
00169 eventinfo->Add(BremsAndDeltas);
00170
00171
00172 MSG("FarDetEvent",Msg::kVerbose) << " GET STRIP INFORMATION " << endl;
00173 CandStripListHandle* strplist = (CandStripListHandle*)(arr->At(3));
00174
00175 TObjArray* AssociatedStrips = new TObjArray();
00176 TObjArray* AllStrips = new TObjArray();
00177
00178 if( strplist )
00179 {
00180 TIter strpitr(strplist->GetDaughterIterator());
00181 while(CandStripHandle* strp = (CandStripHandle*)(strpitr()))
00182 {
00183 if( strp )
00184 {
00185
00186
00187 AllStrips->Add(strp);
00188
00189
00190 AssociatedStrips->Add(strp);
00191
00192 }
00193 }
00194 }
00195
00196 eventinfo->Add(AssociatedStrips);
00197 eventinfo->Add(AllStrips);
00198
00199
00200 cxnew.SetDataIn(eventinfo);
00201
00202
00203 MSG("FarDetEvent",Msg::kVerbose) << " MAKING FARDETEVENT " << endl;
00204 FarDetEventHandle fdevent = FarDetEvent::MakeCandidate(ah,cxnew);
00205 fdevent.SetName("FarDetEvent");
00206 fdevent.SetTitle(TString("Created by AlgFarDetEventList"));
00207 fdeventlist.AddDaughterLink(fdevent);
00208
00209
00210 HadronicShowers->Clear();
00211 delete HadronicShowers;
00212
00213 BremsAndDeltas->Clear();
00214 delete BremsAndDeltas;
00215
00216 AssociatedStrips->Clear();
00217 delete AssociatedStrips;
00218
00219 AllStrips->Clear();
00220 delete AllStrips;
00221
00222
00223
00224
00225
00226 eventinfo->Clear();
00227 delete eventinfo;
00228 }
00229
00230 void AlgFarDetEventList::Trace(const char* ) const
00231 {
00232
00233 }
00234
00235 void AlgFarDetEventList::CompareShowersWithTrack(CandTrackHandle* bestTrack, CandShowerListHandle* shwlist, CandShowerHandle*& vtxshower, TObjArray* HadronicShowers, TObjArray* BremsAndDeltas, Double_t& separation)
00236 {
00237 MSG("FarDetEvent",Msg::kVerbose) << " CompareShowersWithTrack(...) " << endl;
00238
00239 if(!bestTrack)
00240 {
00241 MSG("FarDetEvent",Msg::kError) << " AlgFarDetEventList::CompareShowersWithTrack * Not Given A Track To Compare With Showers!" << endl;
00242 return;
00243 }
00244 if(!shwlist)
00245 {
00246 MSG("FarDetEvent",Msg::kError) << " AlgFarDetEventList::CompareShowersWithTrack * Not Given A List of Showers To Compare With Track!" << endl;
00247 return;
00248 }
00249 if(shwlist->GetNDaughters()<=0)
00250 {
00251 MSG("FarDetEvent",Msg::kWarning) << " AlgFarDetEventList::CompareShowersWithTrack * Given An Empty Showerlist To Compare With Track!" << endl;
00252 return;
00253 }
00254
00255 HadronicShowers->Clear(); BremsAndDeltas->Clear();
00256
00257 int vtxpln = bestTrack->GetVtxPlane();
00258 double trku = bestTrack->GetVtxU();
00259 double trkv = bestTrack->GetVtxV();
00260 double trkz = bestTrack->GetVtxZ();
00261
00262 TIter shwitr(shwlist->GetDaughterIterator());
00263 while(CandShowerHandle* shw = (CandShowerHandle*)(shwitr()))
00264 {
00265 if( shw )
00266 {
00267
00268
00269 if( abs(shw->GetVtxPlane()-vtxpln)<20 )
00270 {
00271 HadronicShowers->Add(shw);
00272 double temp = (shw->GetVtxU()-trku)*(shw->GetVtxU()-trku)
00273 + (shw->GetVtxV()-trkv)*(shw->GetVtxV()-trkv)
00274 + (shw->GetVtxZ()-trkz)*(shw->GetVtxZ()-trkz);
00275 if(temp<separation)
00276 {
00277 vtxshower=shw;
00278 separation=temp;
00279 }
00280 }
00281
00282
00283
00284 else
00285 {
00286
00287 }
00288 }
00289 }
00290 return;
00291 }
00292
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420