AlgMuonRemoval Class Reference

#include <AlgMuonRemoval.h>

Inheritance diagram for AlgMuonRemoval:
AlgBase

List of all members.

Public Member Functions

 AlgMuonRemoval ()
virtual ~AlgMuonRemoval ()
virtual void RunAlg (AlgConfig &ac, CandHandle &ch, CandContext &cx)
virtual void Trace (const char *c) const

Private Member Functions

void Reset ()
void FillTrkInfo (const CandEventHandle *event, const CandTrackHandle *track)

Private Attributes

Int_t cMaxTrackLikePlane
Float_t fTrkQ [500]
Float_t fPlnQ [500]
Float_t fTrkMIPDcosz [500]
Int_t fTrkStrip [500]
Int_t fNTrackStrip [500]
bool fTrkMIPCalibOkay
Int_t fNTrackLikePlanes
Int_t fMaxTrackLikePlane

Detailed Description

Definition at line 10 of file AlgMuonRemoval.h.


Constructor & Destructor Documentation

AlgMuonRemoval::AlgMuonRemoval (  ) 

Definition at line 39 of file AlgMuonRemoval.cxx.

00040 {
00041   Reset();
00042   cMaxTrackLikePlane = 6;
00043 }

AlgMuonRemoval::~AlgMuonRemoval (  )  [virtual]

Definition at line 46 of file AlgMuonRemoval.cxx.

00047 {
00048 }


Member Function Documentation

void AlgMuonRemoval::FillTrkInfo ( const CandEventHandle event,
const CandTrackHandle track 
) [private]

Definition at line 268 of file AlgMuonRemoval.cxx.

References cMaxTrackLikePlane, fMaxTrackLikePlane, fNTrackStrip, fPlnQ, fTrkMIPCalibOkay, fTrkMIPDcosz, fTrkQ, fTrkStrip, CandHandle::GetDaughterIterator(), CandRecoHandle::GetEndDirCosZ(), CandRecoHandle::GetEndPlane(), GetMaxTrackLikePlane(), CandRecoHandle::GetPlaneCharge(), CandRecoHandle::GetStripCharge(), CandTrackHandle::GetU(), CandTrackHandle::GetV(), CandRecoHandle::GetVtxDirCosZ(), CandRecoHandle::GetVtxPlane(), CandTrackHandle::GetZ(), CandTrackHandle::IsTPosValid(), Msg::kDebug, CalStripType::kMIP, CalDigitType::kPE, and MSG.

Referenced by RunAlg().

00269                                                               {
00270   //
00271   //fill info about track direction at each plane
00272   //
00273   const double nplanes  = track->GetEndPlane() - track->GetVtxPlane() + 1;
00274   const int    vtxplane = track->GetVtxPlane();
00275   const int    endplane = track->GetEndPlane();
00276   
00277   for(int ipln = vtxplane; ipln<=endplane; ++ipln){
00278     double dcosz = track->GetVtxDirCosZ() + ((ipln - vtxplane)/nplanes)*(track->GetEndDirCosZ() - track->GetVtxDirCosZ() );
00279     int ip1 =-1;
00280     int ip2 =-1;
00281     if(track->IsTPosValid(ipln-1) && track->IsTPosValid(ipln+1)){
00282       ip2 = ipln+1; ip1 = ipln-1;
00283     }else if(track->IsTPosValid(ipln) && track->IsTPosValid(ipln+1)){
00284       ip2 = ipln+1; ip1 = ipln;
00285     }else if(track->IsTPosValid(ipln) && track->IsTPosValid(ipln-1)){
00286       ip2 = ipln; ip1 = ipln-1;
00287     }
00288     if(ip1!=-1 && ip2!=-1){
00289       const double l = sqrt( (track->GetU(ip2) - track->GetU(ip1)) * 
00290                              (track->GetU(ip2) - track->GetU(ip1)) 
00291                            + (track->GetV(ip2) - track->GetV(ip1)) * 
00292                              (track->GetV(ip2) - track->GetV(ip1)) 
00293                            + (track->GetZ(ip2) - track->GetZ(ip1)) *
00294                              (track->GetZ(ip2) - track->GetZ(ip1)) ); 
00295       if(l!=0) dcosz = fabs( track->GetZ(ip2) - track->GetZ(ip1) ) / l;
00296       else dcosz = 1;
00297     }
00298     fTrkMIPDcosz[ipln] = track->GetPlaneCharge(ipln, CalStripType::kMIP)*dcosz;
00299     if(track->GetPlaneCharge(ipln, CalStripType::kMIP)==0){
00300       fTrkMIPDcosz[ipln] =1.;
00301     }
00302   }
00303 
00304   TIter trkstpIter(track->GetDaughterIterator());
00305   int ntrkcalibstps = 0;
00306   while(const CandStripHandle* strip = dynamic_cast<const CandStripHandle*>(trkstpIter())){
00307     fTrkQ[strip->GetPlane()]+=strip->GetCharge(CalDigitType::kPE);
00308     if(track->GetStripCharge(strip, CalStripType::kMIP)!=0) ntrkcalibstps++; 
00309     fTrkStrip[strip->GetPlane()] = strip->GetStrip();
00310   }
00311   fTrkMIPCalibOkay = (ntrkcalibstps>4);
00312 
00313   //
00314   //Find where the track like planes stop
00315   //
00316   fMaxTrackLikePlane = GetMaxTrackLikePlane(event,track,cMaxTrackLikePlane);
00317   MSG("RmMu", Msg::kDebug) << " Max track like plane " << fMaxTrackLikePlane<< endl; 
00318 
00319   /*
00320     const int minplane = (track->GetVtxPlane()<track->GetEndPlane())?track->GetVtxPlane():track->GetEndPlane();
00321     const int maxplane = (track->GetVtxPlane()>track->GetEndPlane())?track->GetVtxPlane():track->GetEndPlane();
00322     fNTrackLikePlanes = 0;
00323     fMaxTrackLikePlane = 0;
00324     for(int ipln = minplane; ipln<=maxplane  && fNTrackLikePlanes<cMaxTrackLikePlane; ipln++){
00325     if(fTrkQ[ipln]>0){
00326     MSG("RmMu", Msg::kDebug) << "Track: " << fTrkQ[ipln] << "  Plane: " << fPlnQ[ipln] << "  Frac: " << fTrkQ[ipln]/fPlnQ[ipln] << endl;
00327     if(fTrkQ[ipln]/fPlnQ[ipln]>.8 && fTrkQ[ipln]>3.0){
00328     fNTrackLikePlanes++;
00329     fMaxTrackLikePlane = ipln;
00330     }
00331     }
00332     }
00333     if(fNTrackLikePlanes!=cMaxTrackLikePlane) fMaxTrackLikePlane = 9999;
00334   */
00335 
00336   TIter stpIter(event->GetDaughterIterator());
00337   while(const CandStripHandle* strip = 
00338         dynamic_cast<const CandStripHandle*>(stpIter())){
00339     const int plane = strip->GetPlane();
00340     if(plane>0 && plane<500) {
00341       fPlnQ[plane]+=strip->GetCharge(CalDigitType::kPE);
00342       if (TMath::Abs(strip->GetStrip()-fTrkStrip[plane])<=1){
00343         fNTrackStrip[plane]++;
00344       }
00345     }
00346   }
00347 }

void AlgMuonRemoval::Reset (  )  [private]

Definition at line 50 of file AlgMuonRemoval.cxx.

References fNTrackStrip, fPlnQ, fTrkMIPCalibOkay, fTrkMIPDcosz, fTrkQ, and fTrkStrip.

Referenced by RunAlg().

00051 {
00052   for(int ipln=0; ipln<500; ++ipln){
00053     fTrkQ[ipln] = 0;
00054     fPlnQ[ipln] = 0;    
00055     fTrkMIPDcosz[ipln] = 0;
00056     fTrkStrip[ipln] = 0;
00057     fNTrackStrip[ipln] = 0;
00058 
00059   }
00060   fTrkMIPCalibOkay = false;
00061 
00062 
00063   
00064 }

void AlgMuonRemoval::RunAlg ( AlgConfig ac,
CandHandle ch,
CandContext cx 
) [virtual]

Implements AlgBase.

Definition at line 66 of file AlgMuonRemoval.cxx.

References CandHandle::AddDaughterLink(), cMaxTrackLikePlane, digit(), FillTrkInfo(), CandRecord::FindCandHandle(), CandHandle::FindDaughter(), fMaxTrackLikePlane, fNTrackStrip, fPlnQ, fTrkMIPCalibOkay, fTrkMIPDcosz, fTrkQ, fTrkStrip, Registry::Get(), CandDigitListHandle::GetAbsTime(), AlgHandle::GetAlgConfig(), AlgFactory::GetAlgHandle(), CandContext::GetCandRecord(), CandContext::GetDataIn(), CandHandle::GetDaughterIterator(), RecMinos::GetHeader(), AlgFactory::GetInstance(), CandDigitListHandle::GetIsSparse(), CandContext::GetMom(), GetRemovableTrack(), CandHeader::GetRun(), CandHeader::GetSnarl(), header, Msg::kDebug, Msg::kError, Msg::kVerbose, Registry::LockKeys(), Registry::LockValues(), CandDigit::MakeCandidate(), MSG, Reset(), SelectEvent(), Registry::Set(), CandDigitListHandle::SetAbsTime(), CandDigitListHandle::SetIsSparse(), Registry::UnLockKeys(), and Registry::UnLockValues().

00067 {
00068    //
00069    //set up the sub-algs
00070    //  
00071   //const VldContext &vldc = *(cx.GetCandRecord()->GetVldContext());      
00072   AlgFactory &algfactory = AlgFactory::GetInstance();
00073   const char *tmpcs = 0;
00074   Int_t tmpi = 6;
00075   const char *pass_algorithm = 0;
00076   const char *pass_algconfig = 0;
00077   
00078   if (ac.Get("PassThruAlgorithm", tmpcs)) pass_algorithm = tmpcs;
00079   if (ac.Get("PassThruAlgConfig", tmpcs)) pass_algconfig = tmpcs;
00080   if (ac.Get("MaxTrackLikePlanes", tmpi)) cMaxTrackLikePlane = tmpi;
00081 
00082   AlgHandle pass_alg = algfactory.GetAlgHandle(pass_algorithm, pass_algconfig);
00083   CandContext cxx(this, cx.GetMom());
00084   cxx.SetCandRecord(cx.GetCandRecord());
00085   
00086   MSG("RmMu",Msg::kDebug) << " AlgMuonRemoval::RunAlg() " <<endl;
00087 //   MSG("RmMu",Msg::kDebug) << "   SubAlg         :  " <<pass_algorithm<<endl;
00088 //   MSG("RmMu",Msg::kDebug) << "   SubAlg Config  :  " <<pass_algconfig<<endl;
00089  
00090   //
00091   //Do event setup
00092   //
00093   Reset();
00094 
00095   TObjArray *input = (TObjArray *)(cx.GetDataIn());  
00096   const CandRecord* record = dynamic_cast<const CandRecord*>(input->At(0));
00097   assert(record);
00098   const CandHeader* header  = dynamic_cast<const CandHeader*>(record->GetHeader());
00099   if(header){
00100     MSG("RmMu",Msg::kDebug) << " Snarl: " << header->GetRun() << " / "<< header->GetSnarl() <<endl; 
00101   }
00102 
00103   const CandEventListHandle * eventlist = dynamic_cast<CandEventListHandle*>(record->FindCandHandle("CandEventListHandle"));
00104   const CandDigitListHandle* digitlist = dynamic_cast<const CandDigitListHandle*>(record->FindCandHandle("CandDigitListHandle"));
00105 
00106   if(eventlist==NULL || digitlist==NULL){
00107     MSG("RmMu",Msg::kError) << " Bailing out of Event eventlist = " << eventlist<< " digitlist = " << digitlist <<endl; 
00108     return; //bail out   
00109   }
00110 
00111 
00112   //
00113   //A list of digits to chuck/modify
00114   //
00115   std::vector<int> digitidx;
00116   std::vector<float> digitweight;
00117   long ntrackdigits = 0;
00118 
00119   TIter event_iter(eventlist->GetDaughterIterator());
00120   while( const CandEventHandle* event = dynamic_cast<const CandEventHandle*>(event_iter()) ){
00121     MSG("RmMu",Msg::kDebug) << " New event " <<endl; 
00122     if(SelectEvent(event)){      
00123       MSG("RmMu",Msg::kDebug) << "   Event is selected for muon removal " <<endl; 
00124       Reset();
00125       const CandTrackHandle* track = GetRemovableTrack(event);
00126       if(!track){
00127         MSG("RmMu",Msg::kError) << "   NO removalable track! "<<endl;
00128       }
00129       //
00130       //Fill some local info
00131       //
00132       FillTrkInfo(event,track);
00133       
00134       MSG("RmMu",Msg::kDebug) << "   fTrkMIPCalibOkay:  "<< fTrkMIPCalibOkay <<endl
00135                               << "   fMaxTrackLikePlane : " << fMaxTrackLikePlane <<endl;
00136       
00137       //TY loop through hits in the slice instead of event
00138       const CandSliceHandle *csh = event->GetCandSlice();
00139                               
00140 
00141       //TIter stpIter(event->GetDaughterIterator());
00142       TIter stpIter(csh->GetDaughterIterator());
00143       while(const CandStripHandle* strip = dynamic_cast<const CandStripHandle*>(stpIter())){
00144         const int planeno = strip->GetPlane();
00145         const int stripno = strip->GetStrip();
00146         const bool isintrack =(track->FindDaughter(strip)!=NULL);
00147         const bool ismuon    =  ((fTrkMIPDcosz[planeno]>0.3 && fTrkMIPDcosz[planeno]<1.2) || (fTrkMIPDcosz[planeno]>=1.2 && (fTrkQ[planeno]/fPlnQ[planeno]) > 0.8));      
00148         bool doscale = planeno< fMaxTrackLikePlane && isintrack  && fTrkMIPCalibOkay && fTrkMIPDcosz[planeno]>=1.2;
00149         
00150         const double scale = ((fTrkMIPDcosz[planeno]!=0)? (fTrkMIPDcosz[planeno] - 1.)/fTrkMIPDcosz[planeno] : 1.);             
00151         int modifydigit = 0;
00152         if(!isintrack || stripno<0 || (isintrack && !ismuon && fTrkMIPCalibOkay)){ // we are going to keep this digit.    
00153           if(doscale) modifydigit = 1;
00154         }else{
00155 
00156           modifydigit = 2;
00157         }
00158 
00159         if(planeno>=fMaxTrackLikePlane) modifydigit = 2;
00160 
00161         //TY remove isolated track hits
00162         if(isintrack&&fNTrackStrip[planeno]==1) modifydigit = 2;
00163         if(TMath::Abs(stripno-fTrkStrip[planeno])<=1&&fNTrackStrip[planeno]<=2){
00164           if (planeno>0&&planeno<499&&
00165               fNTrackStrip[planeno-1]==1&&
00166               fNTrackStrip[planeno+1]==1) modifydigit = 2;
00167         }
00168 
00169         if(modifydigit==0){
00170           MSG("RmMu",Msg::kVerbose) << " KEEP : " << planeno << "/"<< stripno 
00171                                     << " Q: " << strip->GetCharge() 
00172                                     << " TrkMIP: " <<  fTrkMIPDcosz[planeno]
00173                                     << " TrkQ: " <<  fTrkQ[planeno]
00174                                     << " PlnQ: " <<  fPlnQ[planeno]
00175                                     << " intrk: " << isintrack 
00176                                     << " ismuon: " << ismuon 
00177                                     << " doscale: " << doscale 
00178                                     << " scale: " << scale <<endl;
00179         }else if(modifydigit==1){
00180           MSG("RmMu",Msg::kVerbose) << " SCALE : " << planeno << "/"<< stripno 
00181                                     << " Q: " << strip->GetCharge() 
00182                                     << " TrkMIP: " <<  fTrkMIPDcosz[planeno]
00183                                     << " TrkQ: " <<  fTrkQ[planeno]
00184                                     << " PlnQ: " <<  fPlnQ[planeno]
00185                                     << " intrk: " << isintrack 
00186                                     << " ismuon: " << ismuon 
00187                                     << " doscale: " << doscale 
00188                                     << " scale: " << scale <<endl;
00189 
00190         }else if(modifydigit==2){
00191           MSG("RmMu",Msg::kVerbose) << " REJECT : " << planeno << "/"<< stripno 
00192                                     << " Q: " << strip->GetCharge() 
00193                                     << " TrkMIP: " <<  fTrkMIPDcosz[planeno]
00194                                     << " TrkQ: " <<  fTrkQ[planeno]
00195                                     << " PlnQ: " <<  fPlnQ[planeno]
00196                                     << " intrk: " << isintrack 
00197                                     << " ismuon: " << ismuon 
00198                                     << " doscale: " << doscale 
00199                                     << " scale: " << scale <<endl;
00200 
00201         }
00202         
00203         if(modifydigit || isintrack){ //        
00204           TIter digitIter(strip->GetDaughterIterator());
00205           while( CandDigitHandle* digit = dynamic_cast<CandDigitHandle*>(digitIter()) ) {    
00206             if(modifydigit){
00207               digitidx.push_back(digit->GetRawDigitIndex());
00208               if(modifydigit==1) digitweight.push_back(scale);
00209               else digitweight.push_back(-1.);
00210             }
00211             if(isintrack) ntrackdigits++;
00212           }
00213         }
00214       }            
00215     }
00216   }
00217    
00218   MSG("RmMu",Msg::kDebug) << " There are " << digitidx.size()<< " digits to be modified  and " << ntrackdigits <<" track digits"  <<endl; 
00219 
00220   //iterate over base digits and do modifications
00221   TIter digitIter(digitlist->GetDaughterIterator());
00222   const unsigned int nmoddigit = digitidx.size();
00223   while( CandDigitHandle* digit = dynamic_cast<CandDigitHandle*>(digitIter()) ) {    
00224     const int thisidx = digit->GetRawDigitIndex(); 
00225     bool ditch = 0;
00226     bool scale = 0;
00227     float scale_factor = 0;
00228     for(unsigned int idig = 0; idig<nmoddigit; ++idig){
00229       if(digitidx[idig] == thisidx ){
00230         if(digitweight[idig]>0){
00231           scale = 1;
00232           scale_factor = digitweight[idig];
00233         }else{
00234           ditch = 1;
00235         }
00236         digitidx[idig] = -1;
00237       }
00238     }
00239     if(!ditch){
00240       AlgConfig& algconfig = pass_alg.GetAlgConfig();
00241       algconfig.UnLockKeys();
00242       algconfig.UnLockValues();
00243       if(scale){
00244         algconfig.Set("doscale", 1);
00245         algconfig.Set("scalefactor", scale_factor);
00246       }else{
00247         algconfig.Set("doscale", 0);
00248         algconfig.Set("scalefactor", 1.);
00249       }
00250       algconfig.LockKeys();
00251       algconfig.LockValues();
00252       TObjArray digitalg_input;
00253       digitalg_input.Add(digit);
00254       cxx.SetDataIn(&digitalg_input);
00255       CandDigitHandle cdh = CandDigit::MakeCandidate(pass_alg, cxx);
00256       ch.AddDaughterLink(cdh, kFALSE); 
00257     }
00258   }
00259   
00260   //
00261   //global list stuff
00262   //
00263   CandDigitListHandle &cdlh = dynamic_cast<CandDigitListHandle &>(ch);
00264   cdlh.SetAbsTime(digitlist->GetAbsTime());                   
00265   cdlh.SetIsSparse(digitlist->GetIsSparse());   
00266 }

void AlgMuonRemoval::Trace ( const char *  c  )  const [virtual]

Reimplemented from AlgBase.

Definition at line 349 of file AlgMuonRemoval.cxx.

00349                                                     {
00350 }


Member Data Documentation

Definition at line 21 of file AlgMuonRemoval.h.

Referenced by FillTrkInfo(), and RunAlg().

Definition at line 31 of file AlgMuonRemoval.h.

Referenced by FillTrkInfo(), and RunAlg().

Definition at line 30 of file AlgMuonRemoval.h.

Int_t AlgMuonRemoval::fNTrackStrip[500] [private]

Definition at line 28 of file AlgMuonRemoval.h.

Referenced by FillTrkInfo(), Reset(), and RunAlg().

Float_t AlgMuonRemoval::fPlnQ[500] [private]

Definition at line 25 of file AlgMuonRemoval.h.

Referenced by FillTrkInfo(), Reset(), and RunAlg().

Definition at line 29 of file AlgMuonRemoval.h.

Referenced by FillTrkInfo(), Reset(), and RunAlg().

Float_t AlgMuonRemoval::fTrkMIPDcosz[500] [private]

Definition at line 26 of file AlgMuonRemoval.h.

Referenced by FillTrkInfo(), Reset(), and RunAlg().

Float_t AlgMuonRemoval::fTrkQ[500] [private]

Definition at line 24 of file AlgMuonRemoval.h.

Referenced by FillTrkInfo(), Reset(), and RunAlg().

Int_t AlgMuonRemoval::fTrkStrip[500] [private]

Definition at line 27 of file AlgMuonRemoval.h.

Referenced by FillTrkInfo(), Reset(), and RunAlg().


The documentation for this class was generated from the following files:

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1