Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

AlgFarDetEventList.cxx

Go to the documentation of this file.
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& /*ac*/, 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   // Create TObjArray to store the event information
00054   TObjArray* eventinfo = new TObjArray();
00055   
00056   // Start to find a new event...
00057   // N.B: Assume there is only one event for now!
00058   eventinfo->Clear();
00059     
00060   // Get the track information
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   // Look in the fitted tracks first
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   // Otherwise fall back to the found tracks.
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); // Add bestTrack even if it is null.
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   // Now we've stored the track we want to use in our event, 
00120   // we should try and find a shower to go with it.
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     { // Loop over the shower list and look for a vertex shower.
00130       
00131       Double_t separation(999.),temp(999.),shwenergy(0.0);
00132       if( primaryTrack )
00133         { // We have a track so find the shower closest to it
00134           this->CompareShowersWithTrack(primaryTrack, 
00135                                         shwlist, 
00136                                         vtxshower, 
00137                                         HadronicShowers, 
00138                                         BremsAndDeltas, 
00139                                         separation);
00140         }
00141       
00142       else
00143         { // We have no track so find the largest shower
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   // Add the strip list
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               // record all strips
00187               AllStrips->Add(strp);
00188 
00189               // some association could go here...
00190               AssociatedStrips->Add(strp);
00191 
00192             }
00193         }
00194     }
00195 
00196   eventinfo->Add(AssociatedStrips);
00197   eventinfo->Add(AllStrips);
00198   
00199   // Add event info to CandContext
00200   cxnew.SetDataIn(eventinfo);
00201     
00202   // Make new FarDetEventHandle
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   // Delete temporary objects
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   // Could turn this into a loop and make another event now...
00224   // 
00225 
00226   eventinfo->Clear();
00227   delete eventinfo;
00228 }
00229    
00230 void AlgFarDetEventList::Trace(const char* /*c*/ ) 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           // Look for possible hadronic showers
00268           // (offset by less than 10 planes from track vertex)
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           // Look for possible brems and deltas
00282           // ( loop over the planes in the shower and see if 
00283           //   it is associated with the track in that plane)
00284           else
00285             {
00286 
00287             }
00288         }
00289     }
00290   return;
00291 }
00292 
00294 //
00295 // void AlgFarDetEventList:::RemoveTracksinShowers(AlgConfig &ac, TObjArray * recolist)
00296 // {
00297 //
00298 //   Double_t pMinTrackIsolation = ac.GetDouble("MinTrackIsolation");
00299 //   Double_t pMinTrackIsolationDist = ac.GetDouble("MinTrackIsolationDist");
00300 //
00301 //   for (Int_t i = 0; i <= recolist->GetLast(); i++) {
00302 //     CandTrackHandle *track=0;
00303 //     Int_t nisolated = 0;
00304 //     Int_t nisolatedU = 0;
00305 //     Int_t nisolatedV = 0;
00306 //     Bool_t isolated = true;
00307 //     Int_t longestcontig = 0;
00308 //     Int_t longestcontigU = 0;
00309 //     Int_t longestcontigV = 0;
00310 //
00311 //     if (recolist->At(i)->InheritsFrom("CandTrackHandle")) {
00312 //       track = dynamic_cast<CandTrackHandle*>(recolist->At(i));
00313 //    
00314 //       // count number of planes in each view in which
00315 //       // track is outside shower
00316 //       Int_t firstplane = TMath::Min(track->GetBegPlane(),
00317 //                                  track->GetEndPlane());
00318 //       Int_t lastplane = TMath::Max(track->GetBegPlane(),
00319 //                                 track->GetEndPlane());
00320 //       Int_t firstuplane = TMath::Min(track->GetBegPlane(PlaneView::kU),
00321 //                                   track->GetEndPlane(PlaneView::kU));
00322 //       Int_t firstvplane = TMath::Min(track->GetBegPlane(PlaneView::kV),
00323 //                                   track->GetEndPlane(PlaneView::kV));
00324 //       Int_t lastuplane = TMath::Max(track->GetBegPlane(PlaneView::kU),
00325 //                                track->GetEndPlane(PlaneView::kU) );
00326 //       Int_t lastvplane = TMath::Max(track->GetBegPlane(PlaneView::kV),
00327 //                                track->GetEndPlane(PlaneView::kV) );      
00328 //
00329 //       MSG("FarDetEvent",Msg::kDebug) << " track extent " << firstplane << " " << lastplane <<  " " << track->GetNDaughters() << " " << track->GetBegPlane() << " " << track->GetEndPlane() << endl;
00330 //
00331 //       for(Int_t iplane = firstplane;iplane <= lastplane;iplane++){
00332 //      PlexPlaneId plnid(track->GetVldContext()->GetDetector(),iplane,false);
00333 //      // require that the plane be within the track 
00334 //      // extent for this planeview
00335 //      isolated = true;
00336 //      if((plnid.GetPlaneView() == PlaneView::kU  && 
00337 //          iplane >= firstuplane && iplane <= lastuplane) ||
00338 //         (plnid.GetPlaneView() == PlaneView::kV  && 
00339 //          iplane >= firstvplane && 
00340 //          iplane<=lastvplane)){
00341 //      
00342 //        for (Int_t j = 0; j<=recolist->GetLast(); j++) {
00343 //          if(isolated){
00344 //            if (recolist->At(j)->InheritsFrom("CandShowerHandle")) {
00345 //              CandShowerHandle * shower = dynamic_cast<CandShowerHandle*>(recolist->At(j));
00346 //              if(iplane >= shower->GetBegPlane() &&
00347 //                 iplane <= shower->GetEndPlane()){
00348 //                // if plane within shower extent, compare track position
00349 //                // with shower width. If track outside shower by
00350 //                // a distance pMinTrackIsolationDist, or shower width
00351 //                // is less than this distance, inc isolated.
00352 //                Double_t minPE=2.0;
00353 //                Float_t minUshw = shower->GetMinU(iplane,minPE)+0.02;
00354 //                Float_t minVshw = shower->GetMinV(iplane,minPE)+0.02;
00355 //                Float_t maxUshw = shower->GetMaxU(iplane,minPE)-0.02;
00356 //                Float_t maxVshw = shower->GetMaxV(iplane,minPE)-0.02;
00357 //
00358 //                MSG("FarDetEvent",Msg::kDebug) << " shower extent Plane: " << iplane << " U " << minUshw << "/" <<  track->GetU(iplane) << "/" << maxUshw << " V  " << minVshw << "/" << track->GetV(iplane) << "/" << maxVshw << endl;
00359 //                
00360 //                if(plnid.GetPlaneView() == PlaneView::kU && 
00361 //                   (track->GetU(iplane) >= (minUshw-pMinTrackIsolationDist) && 
00362 //                    track->GetU(iplane) <= (maxUshw+pMinTrackIsolationDist) &&
00363 //                    maxUshw-minUshw > (pMinTrackIsolationDist))){
00364 //                  isolated = false;
00365 //                }
00366 //                if(plnid.GetPlaneView() == PlaneView::kV &&
00367 //                   (track->GetV(iplane) >= (minVshw-pMinTrackIsolationDist)&& 
00368 //                    track->GetV(iplane) <= (maxVshw+pMinTrackIsolationDist)&&
00369 //                    maxVshw-minVshw > (pMinTrackIsolationDist))){
00370 //                  isolated = false;
00371 //                }
00372 //                if(!track->IsTPosValid(iplane))isolated = false;
00373 //              }
00374 //            }      
00375 //          }
00376 //        }
00377 //        if(track->IsTPosValid(iplane)){
00378 //          nisolated++;
00379 //          if(plnid.GetPlaneView() == PlaneView::kU){
00380 //            nisolatedU++;
00381 //          }
00382 //          else{
00383 //            nisolatedV++;
00384 //          }
00385 //        }
00386 //        if(!isolated) {
00387 //          nisolated=0;  // reset contig. isolation counter
00388 //          if(plnid.GetPlaneView() == PlaneView::kU){
00389 //            nisolatedU=0;
00390 //          }
00391 //          else{
00392 //            nisolatedV=0;
00393 //          }
00394 //        }
00395 //        if(nisolated > longestcontig)longestcontig = nisolated;
00396 //        if(nisolatedU > longestcontigU)longestcontigU = nisolatedU;
00397 //        if(nisolatedV > longestcontigV)longestcontigV = nisolatedV;
00398 //         
00399 //        MSG("FarDetEvent",Msg::kDebug) << " nisolated, longest " << nisolated << " " << longestcontig << endl;
00400 //
00401 //        // if the number of contiguous isolated track planes is less than threshold
00402 //        // we remove this track from the event         
00403 //      }
00404 //       } 
00405 //     }
00406 //     MSG("FarDetEvent",Msg::kDebug) << " longest contig:" << longestcontig  << " U " << longestcontigU << " V " << longestcontigV<< "/" << pMinTrackIsolation << endl;
00407 //     if(track && longestcontig < pMinTrackIsolation &&
00408 //        longestcontigU < pMinTrackIsolation &&
00409 //        longestcontigV < pMinTrackIsolation){
00410 //       MSG("FarDetEvent",Msg::kDebug) << " REMOVING TRACK" << endl;
00411 //       recolist->RemoveAt(i);     
00412 //       recolist->Compress();
00413 //       //If you compress here then decrement i so that you 
00414 //       //don't miss any tracks in recolist
00415 //       i-=1;
00416 //     }
00417 //   }
00418 // }
00419 //
00420 //

Generated on Mon Feb 15 11:06:18 2010 for loon by  doxygen 1.3.9.1