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

AlgDeMuxGolden.cxx

Go to the documentation of this file.
00001 
00002 // $Id: AlgDeMuxGolden.cxx,v 1.15 2003/05/14 19:28:02 brebel Exp $
00003 //
00004 // AlgDeMuxGolden
00005 //
00006 // An Algorithm class that DeMultiplexes a cosmic ray event and adjusts the
00007 //weights in the PlexSEIdAltLists of the CandDeMuxDigits from that event
00008 //
00009 // Author:  B. Rebel 11/2000
00011 
00012 #include <cassert>
00013 
00014 #include "Candidate/CandContext.h"
00015 #include "Candidate/CandHandle.h"
00016 #include "CandDigit/CandDeMuxDigitHandle.h"
00017 #include "CandDigit/CandDeMuxDigitListHandle.h"
00018 #include "MessageService/MsgService.h"
00019 #include "Algorithm/AlgConfig.h"
00020 #include "DeMux/DmxStatus.h"
00021 #include "DeMux/DmxUtilities.h"
00022 #include "DeMux/DmxHypothesis.h"
00023 #include "DeMux/DmxPlane.h"
00024 #include "DeMux/DmxShowerPlane.h"
00025 #include "DeMux/DmxMuonPlane.h"
00026 #include "Algorithm/AlgFactory.h"
00027 #include "Algorithm/AlgHandle.h"
00028 #include "DeMux/AlgDeMuxGolden.h"
00029 #include "Navigation/NavKey.h"
00030 #include "Navigation/NavSet.h"
00031 #include "TObjArray.h"
00032 #include "TH1.h"
00033 #include "TFolder.h"
00034 #include "TROOT.h"
00035 
00036 
00037 //define the NavKey to sort the planes
00038 static NavKey KeyPlane( const DmxPlane *currentPlane){
00039   return currentPlane->GetPlaneNumber();
00040 }
00041 
00042 //define the NavKeys to select U and V planes
00043 NavKey KeyU( const DmxPlane *currentPlane){
00044   return currentPlane->GetPlaneView() == PlaneView::kU;
00045 }
00046 
00047 NavKey KeyV( const DmxPlane *currentPlane){
00048   return currentPlane->GetPlaneView() == PlaneView::kV;
00049 }
00050 
00051 //define the NavKeys to select only golden U and V planes
00052 NavKey KeyOnGoldenU( const DmxPlane *currentPlane){
00053   return currentPlane->IsGolden() && currentPlane->GetPlaneView() == PlaneView::kU;
00054 }
00055 
00056 NavKey KeyOnGoldenV( const DmxPlane *currentPlane){
00057   return currentPlane->IsGolden() && currentPlane->GetPlaneView() == PlaneView::kV;
00058 }
00059 
00060 //define the NavKeys to select only lead U and V planes
00061 NavKey KeyOnLeadU( const DmxPlane *currentPlane){
00062   return !currentPlane->IsGolden() && currentPlane->GetPlaneView() == PlaneView::kU;
00063 }
00064 
00065 NavKey KeyOnLeadV( const DmxPlane *currentPlane){
00066   return !currentPlane->IsGolden() && currentPlane->GetPlaneView() == PlaneView::kV;
00067 }
00068 
00069 ClassImp(AlgDeMuxGolden)
00070   
00071 
00072 //-----------------------------------------------------------------------
00073 
00074 CVSID("$Id: AlgDeMuxGolden.cxx,v 1.15 2003/05/14 19:28:02 brebel Exp $");
00075 
00076 //-----------------------------------------------------------------------
00077 
00078 AlgDeMuxGolden::AlgDeMuxGolden() :
00079   fStrayPlanes(0),
00080   fPlanesInSet(6),
00081   fStrayCut(6)
00082 {
00083   //default constructor
00084 }
00085 
00086 //-----------------------------------------------------------------------
00087 
00088 AlgDeMuxGolden::~AlgDeMuxGolden()
00089 {
00090 
00091 }
00092 
00093 //-----------------------------------------------------------------------
00094 //run the demuxing on an event
00095 void AlgDeMuxGolden::RunAlg(AlgConfig &acd, CandHandle &ch, CandContext & /* cx */)
00096 {
00097 
00098   assert( ch.InheritsFrom("CandDeMuxDigitListHandle") );
00099   CandDeMuxDigitListHandle &cdlh = dynamic_cast<CandDeMuxDigitListHandle&>(ch);
00100   //get the AlgConfigDeMux object
00101   fPlanesInSet = acd.GetInt("PlanesInSet");
00102   //MSG("DMX", Msg::kInfo) << "window size = " << fPlanesInSet << "\tcut = " << fStrayCut << endl;
00103 
00104   //get the DmxStatus object
00105   // Find the DmxStatus object or create one for needed scratch space
00106   DmxStatus *status = dynamic_cast<DmxStatus *>(gROOT->GetRootFolder()->FindObject("Loon/DeMux/DmxStatus"));
00107   bool tempStatus = false;
00108   if (status == 0) {
00109     MSG("DMXX", Msg::kDebug) << "//root/Loon/DeMux/DmxStatus not found."
00110                               << " Create a temporary DmxStatus." << endl;
00111     status = new DmxStatus;      // Make a temporary DmxStatus if needed
00112     tempStatus = true;
00113   }
00114   else status->ResetStatus(); 
00115       
00116   //instantiate the DmxUtilities object and then fill DmxStatus with the event information      
00117   DmxUtilities util;
00118   
00119   util.FillPlaneArray(status, cdlh, acd);
00120   const TObjArray *planeArray = status->GetPlaneArray();
00121   //DmxPlane *plane = dynamic_cast<DmxPlane *>(planeArray->First());
00122   //MSG("DMX", Msg::kInfo) <<"Event = " <<  status->GetEventNumber() << endl;
00123   
00124   //create the DmxPlaneItr over planes and program it to sort the planes
00125   DmxPlaneItr planeItr(planeArray);
00126   DmxPlaneKeyFunc *pnKF = planeItr.CreateKeyFunc();
00127   pnKF->SetFun(KeyPlane);
00128   planeItr.GetSet()->AdoptSortKeyFunc(pnKF);
00129   pnKF = 0;
00130   
00131   planeItr.ResetFirst();
00132   status->SetNumberOfPlanes(planeItr.SizeSelect());
00133   status->SetVertexPlaneNumber(util.FindVertexPlane(planeItr));
00134   
00135   //demux the event if there is an identified vertex
00136   if( status->GetVertexPlaneNumber() != -1){
00137     
00138     planeItr.ResetFirst();
00139     planeItr.GetSet()->Slice(status->GetVertexPlaneNumber(), 500);
00140     //set the end plane number since there was a vertex plane
00141     status->SetEndPlaneNumber(util.FindEndPlane(planeItr));
00142     planeItr.GetSet()->Slice();
00143     planeItr.ResetFirst();
00144 
00145     //set the z position of the vertex plane
00146     planeItr.GetSet()->Slice(status->GetVertexPlaneNumber());
00147     planeItr.ResetFirst();
00148     status->SetVertexPlaneZPosition(dynamic_cast<DmxPlane *>(planeItr.Ptr())->GetZPosition());
00149 
00150     planeItr.GetSet()->Slice();
00151     planeItr.ResetFirst();
00152 
00153     //DmxPlane *plane = dynamic_cast<DmxPlane *>(planeArray->First());
00154     //MSG("DMX", Msg::kInfo) <<"Event = " <<  status->GetEventNumber() << endl;
00155     
00156     //create two DmxPlaneItrs
00157     DmxPlaneItr leadPlaneItr(planeArray);
00158     DmxPlaneItr vertexPlaneItr(planeArray);
00159     DmxPlaneItr goldenPlaneItr(planeArray);
00160     
00161     //create a KeyFunc to sort planes by number
00162     DmxPlaneKeyFunc *pnKF = leadPlaneItr.CreateKeyFunc();
00163     DmxPlaneKeyFunc *vertexPlaneKF = vertexPlaneItr.CreateKeyFunc();
00164     DmxPlaneKeyFunc *goldenPlaneKF = goldenPlaneItr.CreateKeyFunc();
00165     
00166     //program the KeyFunc with the sort function
00167     pnKF->SetFun(KeyPlane);
00168     vertexPlaneKF->SetFun(KeyPlane);
00169     goldenPlaneKF->SetFun(KeyPlane);
00170     
00171     //get the NavSet from the iterator and pass the KeyFunc to it
00172     leadPlaneItr.GetSet()->AdoptSortKeyFunc(pnKF);
00173     vertexPlaneItr.GetSet()->AdoptSortKeyFunc(vertexPlaneKF);
00174     goldenPlaneItr.GetSet()->AdoptSortKeyFunc(goldenPlaneKF);
00175     
00176     //clear the KF pointer because we no longer own the KeyFunc
00177     
00178     pnKF = 0;
00179     vertexPlaneKF = 0;
00180     goldenPlaneKF = 0;
00181     leadPlaneItr.ResetFirst();
00182     goldenPlaneItr.ResetFirst();
00183     vertexPlaneItr.ResetFirst();
00184 
00185     //now program a key function to select on plane orientation - U first
00186     DmxPlaneKeyFunc *orientGoldenUKF = goldenPlaneItr.CreateKeyFunc();
00187     DmxPlaneKeyFunc *orientLeadUKF = leadPlaneItr.CreateKeyFunc();
00188     DmxPlaneKeyFunc *orientGoldenVKF = goldenPlaneItr.CreateKeyFunc();
00189     DmxPlaneKeyFunc *orientLeadVKF = leadPlaneItr.CreateKeyFunc();
00190     
00191     Int_t viewCtr = 0;
00192     while( viewCtr < 2 ){
00193      
00194       if( viewCtr == 0){
00195         //program this function with the select function
00196         orientLeadUKF->SetFun(KeyOnLeadU);
00197         orientGoldenUKF->SetFun(KeyOnGoldenU);
00198                 
00199         //adopt it as a selection function
00200         leadPlaneItr.GetSet()->AdoptSelectKeyFunc(orientLeadUKF);
00201         orientLeadUKF = 0;
00202         leadPlaneItr.Reset();
00203         goldenPlaneItr.GetSet()->AdoptSelectKeyFunc(orientGoldenUKF);
00204         orientGoldenUKF = 0;
00205         goldenPlaneItr.Reset();
00206       }
00207       else if(viewCtr == 1){
00208         //program this function with the select function
00209         orientLeadVKF->SetFun(KeyOnLeadV);
00210         orientGoldenVKF->SetFun(KeyOnGoldenV);
00211                 
00212         //adopt it as a selection function
00213         leadPlaneItr.GetSet()->AdoptSelectKeyFunc(orientLeadVKF);
00214         orientLeadVKF = 0;
00215         leadPlaneItr.Reset();
00216         goldenPlaneItr.GetSet()->AdoptSelectKeyFunc(orientGoldenVKF);
00217         orientGoldenVKF = 0;
00218         goldenPlaneItr.Reset();
00219       }
00220 
00221       //slice to those planes from the vertex on
00222       goldenPlaneItr.GetSet()->Slice(status->GetVertexPlaneNumber(), status->GetEndPlaneNumber());
00223 
00224       if(goldenPlaneItr.SizeSelect() >=2 ){
00225 
00226         //MSG("DMX", Msg::kInfo) << "event " << status->GetEventNumber() << endl;
00227         //loop over the golden planes and set them
00228         while(goldenPlaneItr.IsValid() ){
00229 
00230           //MSG("DMX", Msg::kInfo) << dynamic_cast<DmxPlane*>(goldenPlaneItr.Ptr())->GetPlaneNumber() << endl;
00231           if(dynamic_cast<DmxPlane*>(goldenPlaneItr.Ptr())->GetPlaneType() == DmxPlaneTypes::kShower){
00232             dynamic_cast<DmxShowerPlane *>(goldenPlaneItr.Ptr())->SetStrips("best");
00233           }
00234           goldenPlaneItr.Next();
00235         }//end setting golden planes
00236 
00237         goldenPlaneItr.Reset();
00238 
00239         UseGoldenFit(leadPlaneItr, goldenPlaneItr, status->GetVertexPlaneNumber(), 
00240                      status->GetEndPlaneNumber());
00241 
00242         //check the fit
00243         fStrayPlanes -= util.CheckFit(leadPlaneItr);
00244 
00245         //what about multiple muons?  look for another vertex after the end plane
00246         leadPlaneItr.GetSet()->Slice();
00247         goldenPlaneItr.GetSet()->Slice();
00248         vertexPlaneItr.GetSet()->Slice(status->GetEndPlaneNumber()+1, 500);
00249         //MSG("DMX1", Msg::kInfo)<< "event =  " << status->GetEventNumber() 
00250         //                   << "\tend plane = " << status->GetEndPlaneNumber() << endl;
00251         
00252         Int_t nextVertex = -1;
00253         if(vertexPlaneItr.SizeSelect() > 3) nextVertex = util.FindVertexPlane(vertexPlaneItr);
00254         
00255         while( nextVertex != -1){
00256           
00257           status->SetMultipleMuon(true); 
00258           vertexPlaneItr.GetSet()->Slice();
00259           vertexPlaneItr.GetSet()->Slice(nextVertex, 500);
00260           
00261           //get the next end plane
00262           Int_t endPlane = util.FindEndPlane(vertexPlaneItr);
00263 
00264           //MSG("DMX1", Msg::kInfo)<< "\tin double muon loop, vertex at plane " << nextVertex 
00265           //             << "\tend plane = " << endPlane << "\tplanes in slice = " 
00266           //             << vertexPlaneItr.SizeSelect() << endl;
00267           
00268           goldenPlaneItr.GetSet()->Slice(nextVertex, endPlane);
00269           
00270           if(goldenPlaneItr.SizeSelect() >= 2 ){
00271             //loop over the golden planes and set them
00272             while(goldenPlaneItr.IsValid() ){
00273               
00274               if(dynamic_cast<DmxPlane*>(goldenPlaneItr.Ptr())->GetPlaneType() == DmxPlaneTypes::kShower){
00275                 dynamic_cast<DmxShowerPlane *>(goldenPlaneItr.Ptr())->SetStrips("best");
00276               }
00277               goldenPlaneItr.Next();
00278             }
00279             
00280             goldenPlaneItr.Reset();
00281             
00282             UseGoldenFit(leadPlaneItr, goldenPlaneItr, status->GetVertexPlaneNumber(), 
00283                          status->GetEndPlaneNumber());
00284             
00285             //check the fit
00286             fStrayPlanes -= util.CheckFit(leadPlaneItr);
00287             
00288             //CheckFitWithTiming(ch, planeItr);
00289             
00290           }//end if enough golden planes to try
00291           
00292           //look for another vertex after the end plane
00293           leadPlaneItr.GetSet()->Slice();
00294           goldenPlaneItr.GetSet()->Slice();
00295           vertexPlaneItr.GetSet()->Slice();
00296           vertexPlaneItr.GetSet()->Slice(endPlane+1, 500);
00297           //MSG("DMX1", Msg::kInfo)<< "\tlook for new vertex, slice from " << endPlane+1 
00298           //             << "\tto plane 500, planes in slice = " 
00299           //             << vertexPlaneItr.SizeSelect() << endl;
00300           
00301           vertexPlaneItr.Reset();
00302           
00303           if(vertexPlaneItr.SizeSelect() > 0){
00304             nextVertex = util.FindVertexPlane(vertexPlaneItr);
00305           }
00306           else{ nextVertex = -1; }
00307         }//end loop over new verticies
00308       }//end if at least 2 golden planes
00309       else{ 
00310         MSG("DMX", Msg::kWarning)<< "Event " << status->GetEventNumber() 
00311                                  << " not demuxed; not enough golden planes in view" << endl;
00312         status->SetValidPlanesFailure(true); 
00313       } //not enough planes to demux
00314 
00315       status->SetFigureOfMerit(goldenPlaneItr.SizeSelect(), fStrayPlanes);
00316       if(viewCtr == 0 && status->GetEventDeMuxed()){ 
00317         status->SetUStrayPlanes(fStrayPlanes);
00318         status->SetUValidPlanes(goldenPlaneItr.SizeSelect());
00319         if( status->GetFigureOfMeritFailure() )
00320         //see if the event failed the figure of Merit test, if so, see if it is an 
00321         //overlapping muon
00322         status->SetUOverlappingMultiple(util.IsOverlappingMultiple(goldenPlaneItr, status->GetVertexZPosition(), 
00323                                                               acd.GetDouble("HoughInterceptRMSLimit"), 
00324                                                               acd.GetDouble("HoughSlopeRMSLimit"),
00325                                                               acd.GetDouble("HoughPeakLimit")));
00326       }
00327       if(viewCtr == 1 && status->GetEventDeMuxed()){ 
00328         status->SetVStrayPlanes(fStrayPlanes);
00329         status->SetVValidPlanes(goldenPlaneItr.SizeSelect());
00330         //see if the event failed the figure of Merit test, if so, see if it is an 
00331         //overlapping muon
00332         if( status->GetFigureOfMeritFailure() )
00333           status->SetVOverlappingMultiple(util.IsOverlappingMultiple(goldenPlaneItr, status->GetVertexZPosition(),
00334                                                                 acd.GetDouble("HoughInterceptRMSLimit"), 
00335                                                                 acd.GetDouble("HoughSlopeRMSLimit"),
00336                                                                 acd.GetDouble("HoughPeakLimit")));
00337       }
00338 
00339       //done using the first view, so clear the selection function
00340       //MSG("Dmx", Msg::kInfo) <<"Done with View " << viewCtr << endl;
00341       vertexPlaneItr.GetSet()->Slice();
00342       leadPlaneItr.GetSet()->Slice();
00343       leadPlaneItr.GetSet()->AdoptSelectKeyFunc(0);
00344       leadPlaneItr.Reset();
00345       goldenPlaneItr.GetSet()->Slice();
00346       goldenPlaneItr.GetSet()->AdoptSelectKeyFunc(0);
00347       goldenPlaneItr.Reset();
00348 
00349       ++viewCtr;
00350     } //end loop over views
00351     
00352   }//end if event has a vertex
00353   return;
00354 }
00355 
00356 //______________________________________________________________________
00357 void AlgDeMuxGolden::Trace(const char * /* c */) const
00358 {
00359 }
00360 
00361 //-----------------------------------------------------------------------------------
00362 //function for implementing the golden plane demux algorithm
00363 void AlgDeMuxGolden::UseGoldenFit(DmxPlaneItr &leadPlaneItr, DmxPlaneItr &goldenPlaneItr,
00364                                   Int_t vertexPlane, Int_t endPlane)
00365 {
00366   
00367   //get the number of loops you have to iterate over.  you have (# golden planes - 1)
00368   //loops to go through them each
00369   Int_t numLoops = goldenPlaneItr.SizeSelect() - 1;
00370   Int_t loopCtr = 0;
00371   DmxUtilities util = DmxUtilities();
00372 
00373   goldenPlaneItr.Reset();
00374   
00375   while(loopCtr < numLoops){
00376     
00377     
00378     Int_t goldCtr = 0;
00379     Float_t goldCoG1 = -1.;
00380     Float_t goldCoG2 = -1.;
00381     Float_t goldZ1 = -1.;
00382     Float_t goldZ2 = -1.;
00383     Int_t firstPlane = -1;
00384     Int_t lastPlane = -1;
00385     //get the cog's for the next two golden planes
00386     while(goldCtr < 2 && goldenPlaneItr.IsValid()){
00387 
00388       //advance the iterator only if on the first plane of the set - that way the first plane
00389       //in the next set is the last in this one
00390       if(goldCtr == 0){
00391         firstPlane = dynamic_cast<DmxPlane*>(goldenPlaneItr.Ptr())->GetPlaneNumber();
00392         goldCoG1 = dynamic_cast<DmxPlane*>(goldenPlaneItr.Ptr())->GetCoG();
00393         goldZ1 = dynamic_cast<DmxPlane*>(goldenPlaneItr.Ptr())->GetZPosition();
00394         goldenPlaneItr.Next();
00395       }
00396       else if(goldCtr == 1){
00397         lastPlane = dynamic_cast<DmxPlane*>(goldenPlaneItr.Ptr())->GetPlaneNumber();
00398         goldCoG2 = dynamic_cast<DmxPlane*>(goldenPlaneItr.Ptr())->GetCoG();
00399         goldZ2 = dynamic_cast<DmxPlane*>(goldenPlaneItr.Ptr())->GetZPosition();
00400       }
00401       ++goldCtr;
00402     }//end loop over golden planes
00403 
00404     //find the slope and intercept between the two golden plane centers of gravity
00405     Float_t slope = (goldCoG2 - goldCoG1)/(goldZ2 - goldZ1);
00406     Float_t intercept = goldCoG2 - goldZ2*slope;
00407     
00408     //MSG("DMX", Msg::kInfo) << "first gold plane " << goldCoG1 << " " << goldZ1 
00409     //             << " second " << goldCoG2 << " " << goldZ2 << " " << slope << " " << intercept << endl; 
00410 
00411     //slice the lead plane iterator to be between the golden planes.
00412     //if first loop, slice from vertex to second golden plane
00413     //if last loop, slice from first golden plane to end plane
00414     
00415     if(loopCtr == 0) firstPlane = vertexPlane;
00416     else if(loopCtr == numLoops-1) lastPlane = endPlane;
00417 
00418     leadPlaneItr.GetSet()->Slice(firstPlane, lastPlane);
00419 
00420     SetPlanesToDeterminedFit(leadPlaneItr, intercept, slope, firstPlane, lastPlane);
00421 
00422     fStrayPlanes += util.FindPlanesOffFit(leadPlaneItr, fStrayCut);
00423 
00424     //clear the lead plane slice
00425     leadPlaneItr.GetSet()->Slice();
00426 
00427     ++loopCtr;
00428   }//end loop over sets of goldenPlanes
00429 
00430   leadPlaneItr.Reset();
00431   goldenPlaneItr.Reset();
00432   return;
00433 
00434 }
00435 
00436 //--------------------------------------------------------------------------
00437 //function to set the planes in the event
00438 void AlgDeMuxGolden::SetPlanesToDeterminedFit(DmxPlaneItr &planeItr, Double_t a, 
00439                                               Double_t b,
00440                                               Int_t firstPlane, Int_t lastPlane)
00441 {
00442   planeItr.ResetFirst();
00443  
00444   while( planeItr.IsValid() ){
00445 
00446     DmxPlane *plane = dynamic_cast<DmxPlane *>(planeItr.Ptr());
00447     //MSG("DMX", Msg::kInfo)<<"\tin SetPlanesToDeterminedFit " << plane->GetPlaneNumber() << endl;
00448       
00449     if(plane->GetPlaneNumber()>=firstPlane && plane->GetPlaneNumber()<=lastPlane){
00450       Double_t fitCoG = a + (plane->GetZPosition() * b);
00451       
00452       plane->SetStrips(fitCoG); 
00453     }//end if plane is in the window bounds
00454   
00455     planeItr.Next();
00456   }
00457 
00458   planeItr.Reset();
00459   
00460   return;
00461 }
00462 

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