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

AlgDeMuxCosmics Class Reference

#include <AlgDeMuxCosmics.h>

Inheritance diagram for AlgDeMuxCosmics:

AlgBase List of all members.

Public Member Functions

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

Private Member Functions

void FindFit (DmxPlaneItr &planeItr, Double_t &prevChiSq, Double_t &a1, Double_t &a2, Double_t &a3, Double_t &a4, Int_t *hypotheses, Int_t direction, Int_t leverArm, Float_t offset)
Bool_t FindPlanesToDropFromFit (DmxPlaneItr &planeItr, Double_t a1, Double_t a2, Double_t a3, Double_t a4, Int_t direction, Int_t leverArm, Float_t offset)
void SetPlanesToDeterminedFit (DmxPlaneItr &planeItr, Double_t a1, Double_t a2, Double_t a3, Double_t a4, Float_t offset)
void SetPlanesToDeterminedFit (DmxPlaneItr &planeItr, Double_t a, Double_t b)
void FindCosmicSolution (DmxPlaneItr &planeItr, DmxPlaneItr &validPlaneItr, DmxStatus *status, Double_t &a1, Double_t &a2, Double_t &a3, Double_t &a4, Double_t &chiSq, Float_t offset)
void FindWindowCosmicSolution (DmxPlaneItr &validPlaneItr, DmxStatus *status, Double_t &a1, Double_t &a2, Double_t &a3, Double_t &a4, Double_t &chiSq, Float_t offset)
void UseSingleFit (DmxPlaneItr &planeItr, DmxPlaneItr &validPlaneItr, DmxStatus *status)
void UseSlidingWindow (DmxPlaneItr &planeItr, DmxPlaneItr &validPlaneItr, DmxPlaneItr &windowPlaneItr, DmxStatus *status, Int_t vertex, Int_t endPlane)

Private Attributes

Double_t fRequiredMatedSignalRatio
Double_t fSlopeRMS
Int_t fStrayPlanes
UInt_t fPlanesInSet
Int_t fStrayCut

Constructor & Destructor Documentation

AlgDeMuxCosmics::AlgDeMuxCosmics  ) 
 

Definition at line 73 of file AlgDeMuxCosmics.cxx.

00073                                  :
00074   fRequiredMatedSignalRatio(0.33),
00075   fSlopeRMS(0.),
00076   fStrayPlanes(0),
00077   fPlanesInSet(6),
00078   fStrayCut(6)
00079 {
00080   //default constructor
00081 }

AlgDeMuxCosmics::~AlgDeMuxCosmics  )  [virtual]
 

Definition at line 85 of file AlgDeMuxCosmics.cxx.

00086 {
00087 
00088 }


Member Function Documentation

void AlgDeMuxCosmics::FindCosmicSolution DmxPlaneItr &  planeItr,
DmxPlaneItr &  validPlaneItr,
DmxStatus status,
Double_t &  a1,
Double_t &  a2,
Double_t &  a3,
Double_t &  a4,
Double_t &  chiSq,
Float_t  offset
[private]
 

Definition at line 558 of file AlgDeMuxCosmics.cxx.

References FindFit(), FindPlanesToDropFromFit(), DmxStatus::GetEventDirection(), and DmxUtilities::IsValidFit().

Referenced by UseSingleFit(), and UseSlidingWindow().

00562 {
00563   //variables to keep track of the best reconstruction
00564   Double_t fitA1 = 0.;
00565   Double_t fitA2 = 0.;
00566   Double_t fitA3 = 0.;
00567   Double_t fitA4 = 0.;
00568   Double_t useA1 = -10000.;
00569   Double_t useA2 = -10000.;
00570   Double_t useA3 = -10000.;
00571   Double_t useA4 = -10000.;
00572   Double_t bestChi2 = 1.e20;
00573   Double_t chi2 = 1.000001e20;
00574   Int_t direction = status->GetEventDirection();
00575 
00576   DmxUtilities util;
00577 
00578   //make the lever arm for the demuxer the # of valid planes or 6, whichever
00579   //is smaller
00580   UInt_t leverArm = validPlaneItr.SizeSelect();
00581     
00582   if(leverArm > fPlanesInSet){ leverArm = fPlanesInSet;}
00583   
00584   //MSG("DMXX", Msg::kDebug) << "in FindCosmicSolution" << endl;
00585 
00586   //MSG("DMX", Msg::kDebug) << "\tlever arm = " << leverArm << endl;
00587 
00588   //declare an array to tell the fitter which hypotheses to use
00589   Int_t hypsToUse[] = {0,0,0,0,0,0};
00590   
00591   for(Int_t plane0Hyp = 1; plane0Hyp < 4; plane0Hyp++){
00592     hypsToUse[0] = plane0Hyp;
00593     for(Int_t plane1Hyp = 1; plane1Hyp < 4; plane1Hyp++){
00594       hypsToUse[1] = plane1Hyp;
00595       if(leverArm == 2){
00596         
00597         FindFit(validPlaneItr, chi2, fitA1, fitA2, fitA3, fitA4, hypsToUse, direction, leverArm, offset);
00598         
00599         if(chi2 < bestChi2){
00600           bestChi2 = chi2;
00601           useA1 = fitA1;
00602           useA2 = fitA2;
00603           useA3 = fitA3;
00604           useA4 = fitA4;
00605         }//end if its a better straight line fit
00606       }
00607       else if(leverArm >= 3){
00608         for(Int_t plane2Hyp = 1; plane2Hyp < 4; plane2Hyp++){
00609           hypsToUse[2] = plane2Hyp;
00610           if(leverArm == 3){
00611             
00612             FindFit(validPlaneItr, chi2, fitA1, fitA2, fitA3, fitA4, hypsToUse, direction, leverArm, offset);
00613             
00614             if(chi2 < bestChi2 && util.IsValidFit(planeItr, fitA1, fitA2, fitA3, fitA4, offset) ){
00615               bestChi2 = chi2;
00616               useA1 = fitA1;
00617               useA2 = fitA2;
00618               useA3 = fitA3;
00619               useA4 = fitA4;
00620 
00621               //see if you can drop some planes and improve the fit
00622               if( FindPlanesToDropFromFit(validPlaneItr, fitA1, fitA2, fitA3, fitA4, direction, leverArm, offset) ){
00623                 FindFit(validPlaneItr, chi2, fitA1, fitA2, fitA3, fitA4, hypsToUse, direction, leverArm, offset);
00624                 
00625                 if(chi2 < bestChi2 && util.IsValidFit(planeItr, fitA1, fitA2, fitA3, fitA4, offset) ){
00626                   bestChi2 = chi2;
00627                   useA1 = fitA1;
00628                   useA2 = fitA2;
00629                   useA3 = fitA3;
00630                   useA4 = fitA4;
00631                 }
00632                 validPlaneItr.GetSet()->GetMasks().SetAllMasks(kFALSE);
00633               }//end if planes should be dropped because they are way off
00634             }//end if its a better straight line fit
00635           }
00636           else if(leverArm >= 4){
00637             for(Int_t plane3Hyp = 1; plane3Hyp < 4; plane3Hyp++){
00638               hypsToUse[3] = plane3Hyp;
00639               if(leverArm == 4){
00640                 
00641                 FindFit(validPlaneItr, chi2, fitA1, fitA2, fitA3, fitA4, hypsToUse, direction, leverArm, offset);
00642                 
00643                 if(chi2 < bestChi2 && util.IsValidFit(planeItr, fitA1, fitA2, fitA3, fitA4, offset) ){
00644                   bestChi2 = chi2;
00645                   useA1 = fitA1;
00646                   useA2 = fitA2;
00647                   useA3 = fitA3;
00648                   useA4 = fitA4;
00649 
00650                   //see if you can drop some planes and improve the fit
00651                   if( FindPlanesToDropFromFit(validPlaneItr, fitA1, fitA2, fitA3, fitA4, direction, leverArm, offset) ){
00652                     FindFit(validPlaneItr, chi2, fitA1, fitA2, fitA3, fitA4, hypsToUse, direction, leverArm, offset);
00653                     
00654                     if(chi2 < bestChi2 && util.IsValidFit(planeItr, fitA1, fitA2, fitA3, fitA4, offset) ){
00655                       bestChi2 = chi2;
00656                       useA1 = fitA1;
00657                       useA2 = fitA2;
00658                       useA3 = fitA3;
00659                       useA4 = fitA4;
00660                     }
00661                     validPlaneItr.GetSet()->GetMasks().SetAllMasks(kFALSE);
00662                   }//end if planes should be dropped because they are way off
00663                 }//end if its a better straight line fit
00664               }
00665               else if(leverArm >= 5){
00666                 for(Int_t plane4Hyp = 1; plane4Hyp < 4; plane4Hyp++){
00667                   hypsToUse[4] = plane4Hyp;
00668                   
00669                   if(leverArm == 5){
00670                     
00671                     FindFit(validPlaneItr, chi2, fitA1, fitA2, fitA3, fitA4, hypsToUse, direction, leverArm, offset);
00672                     
00673                     if(chi2 < bestChi2 && util.IsValidFit(planeItr, fitA1, fitA2, fitA3, fitA4, offset) ){
00674                       bestChi2 = chi2;
00675                       useA1 = fitA1;
00676                       useA2 = fitA2;
00677                       useA3 = fitA3;
00678                       useA4 = fitA4;
00679 
00680                       //see if you can drop some planes and improve the fit
00681                       if( FindPlanesToDropFromFit(validPlaneItr, fitA1, fitA2, fitA3, fitA4, direction, leverArm, offset) ){
00682                         FindFit(validPlaneItr, chi2, fitA1, fitA2, fitA3, fitA4, hypsToUse, direction, leverArm, offset);
00683                         
00684                         if(chi2 < bestChi2 && util.IsValidFit(planeItr, fitA1, fitA2, fitA3, fitA4, offset) ){
00685                           bestChi2 = chi2;
00686                           useA1 = fitA1;
00687                           useA2 = fitA2;
00688                           useA3 = fitA3;
00689                           useA4 = fitA4;
00690                         }
00691                         validPlaneItr.GetSet()->GetMasks().SetAllMasks(kFALSE);
00692                       }//end if planes should be dropped because they are way off
00693                     }//end if its a better straight line fit
00694                   }
00695                   else if(leverArm == 6){
00696                     for(Int_t plane5Hyp = 1; plane5Hyp < 4; plane5Hyp++){
00697                       
00698                       hypsToUse[5] = plane5Hyp;
00699                       FindFit(validPlaneItr, chi2, fitA1, fitA2, fitA3, fitA4, hypsToUse, direction, leverArm, offset);
00700                       if(chi2 < bestChi2 && util.IsValidFit(planeItr, fitA1, fitA2, fitA3, fitA4, offset) ){
00701                         bestChi2 = chi2;
00702                         useA1 = fitA1;
00703                         useA2 = fitA2;  
00704                         useA3 = fitA3;
00705                         useA4 = fitA4;
00706                      
00707                         //see if you can drop some planes and improve the fit
00708                         if( FindPlanesToDropFromFit(validPlaneItr, fitA1, fitA2, fitA3, fitA4, direction, leverArm, offset) ){
00709                           FindFit(validPlaneItr, chi2, fitA1, fitA2, fitA3, fitA4, hypsToUse, direction, leverArm, offset);
00710                           if(chi2 < bestChi2 && util.IsValidFit(planeItr, fitA1, fitA2,  fitA3, fitA4, offset) ){
00711                             bestChi2 = chi2;
00712                             useA1 = fitA1;
00713                             useA2 = fitA2;
00714                             useA3 = fitA3;
00715                             useA4 = fitA4;
00716                       
00717                           }
00718                           validPlaneItr.GetSet()->GetMasks().SetAllMasks(kFALSE);
00719                         } //end if planes should be dropped because they are way off
00720                       }//end if its a better straight line fit
00721                     }//end for loop over 6th plane's hyps
00722                   }//end if using 6 planes
00723                 }//end for loop over 5th plane's hyps
00724               }//end if at least 5 planes
00725             } //loop over 4th plane
00726           } //end if at least 4 planes
00727         } //loop over 3rd plane
00728       } //end if at least 3 planes
00729     } //loop over 2nd plane
00730   } //loop over 1st plane
00731   
00732   //force the fit to the one found
00733   if(useA1 != -10000. && useA2 != -10000. && useA3 != 10000. && useA4 != 10000.){
00734     a1 = useA1;
00735     a2 = useA2;
00736     a3 = useA3;
00737     a4 = useA4;
00738     chiSq = bestChi2;
00739   }
00740   
00741   //MSG("DMX", Msg::kDebug) << "finished in FindCosmicsSolution" << endl;
00742   return;
00743 }

void AlgDeMuxCosmics::FindFit DmxPlaneItr &  planeItr,
Double_t &  prevChiSq,
Double_t &  a1,
Double_t &  a2,
Double_t &  a3,
Double_t &  a4,
Int_t *  hypotheses,
Int_t  direction,
Int_t  leverArm,
Float_t  offset
[private]
 

Definition at line 1476 of file AlgDeMuxCosmics.cxx.

References DmxUtilities::FindLinearFit(), DmxPlane::GetCoG(), DmxPlane::GetPlaneCharge(), DmxPlane::GetPlaneType(), DmxPlane::GetZPosition(), and DmxPlane::IsGolden().

Referenced by FindCosmicSolution().

01480 {
01481 
01482   //MSG("DMXX", Msg::kDebug) << "in FindFit" << endl;
01483 
01484   //cout << "in find fit for first n planes" << endl;
01485   Double_t a1L = 0.;
01486   Double_t a2L = 0.;
01487   Double_t a1Q = 0.;
01488   Double_t a2Q = 0.;
01489   Double_t a3Q = 0.;
01490   
01491   Double_t chiSqL = 1.e20;
01492   Double_t chiSqQ = 1.e20;
01493 
01494   //declare the variables to do a least squares fit to a straight line.  
01495   //weight is the inverse fraction of the total charge on the plane that 
01496   //is on opposite ends of common strips. multiply the inverse by a 
01497   //sensible number to take account for digits with 1000+ adc's
01498 
01499   //the arrays are the number of planes in the set, ie the lever arm
01500   Double_t x[] = {0.,0.,0.,0.,0.,0.};
01501   Double_t y[] = {0.,0.,0.,0.,0.,0.};
01502   Double_t weight[] = {1.,1.,1.,1.,1.,1.};
01503 
01504   DmxUtilities util;
01505 
01506   //cout << "got util object" << endl;
01507   if(direction == -1){ planeItr.ResetLast(); }
01508   else if( direction == 1){ planeItr.ResetFirst(); }
01509 
01510   //planeItr.ResetFirst();
01511 
01512   Int_t planeCtr = 0;
01513   Int_t arrayCtr = 0;
01514   DmxPlane *plane = 0;
01515 
01516   
01517   //MSG("DMX", Msg::kDebug) << "\t" << hypotheses[0] << "\t" << hypotheses[1] 
01518   //             << "\t" << hypotheses[2] << "\t" << hypotheses[3] 
01519   //             << "\t" << hypotheses[4] << "\t" << hypotheses[5] << endl;
01520   
01521   //loop over the plane iterator to fill the variables
01522 
01523   while( (plane = planeItr()) && planeCtr < leverArm){
01524 
01525     if( !planeItr.GetSet()->GetMasks().GetMask(plane) ){
01526       x[arrayCtr] = plane->GetZPosition() - offset;
01527      
01528       //get the maximum possible weight first, then for each hypothesis multiply by the square of the fraction
01529       weight[arrayCtr] = 1./ TMath::Sqrt(plane->GetPlaneCharge());
01530       if(plane->IsGolden()) weight[arrayCtr] /= TMath::Sqrt(10.);
01531       
01532       y[arrayCtr] = plane->GetCoG();
01533       
01534       //only do this if the shower plane is not golden - if it is, you know where it should be
01535       //reconstructed to
01536       if( plane->GetPlaneType() == DmxPlaneTypes::kShower && !plane->IsGolden()){
01537 
01538         if(hypotheses[planeCtr] == 1){
01539           //MSG("DMX", Msg::kDebug) << "\t" << dynamic_cast<DmxShowerPlane *>(plane)->GetBestHypothesis()->GetCoG();
01540           weight[arrayCtr] /= TMath::Sqrt(dynamic_cast<DmxShowerPlane *>(plane)->GetBestHypothesis()->GetMatedSignalRatio()); 
01541         }
01542         //plane->GetCoG() returns the best hypothesis CoG so only change the value of y if you are wanting
01543         //the 2nd or 3rd best hypotheses
01544         else if(hypotheses[planeCtr] == 2){ 
01545           //MSG("DMX", Msg::kDebug) << "\t" << dynamic_cast<DmxShowerPlane *>(plane)->GetSecondBestHypothesis()->GetCoG();
01546           y[arrayCtr] = dynamic_cast<DmxShowerPlane *>(plane)->GetSecondBestCoG();
01547           weight[arrayCtr] /= TMath::Sqrt(dynamic_cast<DmxShowerPlane *>(plane)->GetSecondBestHypothesis()->GetMatedSignalRatio());
01548         }
01549         else if(hypotheses[planeCtr] == 3){ 
01550           //MSG("DMX", Msg::kDebug) << "\t" << dynamic_cast<DmxShowerPlane *>(plane)->GetThirdBestHypothesis()->GetCoG();
01551           y[arrayCtr] = dynamic_cast<DmxShowerPlane *>(plane)->GetThirdBestCoG();
01552           weight[arrayCtr] /= TMath::Sqrt(dynamic_cast<DmxShowerPlane *>(plane)->GetThirdBestHypothesis()->GetMatedSignalRatio());
01553         }
01554       }
01555       ++arrayCtr;
01556       
01557     }//end if the plane isnt marked as sucking && it is in the window bounds
01558     
01559     ++planeCtr;
01560   } //end loop over planes to find variables for fit
01561 
01562   //cout << "filled arrays" << endl;
01563 
01564   Double_t chiSq = 0.;
01565   
01566   //use the DmxUtilities function to find a linear fit
01567   util.FindLinearFit(x, y, weight, arrayCtr, a1L, a2L, chiSqL);
01568   //util.FindQuadraticFit(x, y, weight, arrayCtr, a1Q, a2Q, a3Q, chiSqQ);
01569   //util.FindCubicFit(x, y, weight, arrayCtr, a1, a2, a3, a4, chiSq);
01570 
01571   //MSG("DMXX", Msg::kDebug) << "\tlinear fit " << chiSqL << "\t" << a1L << "\t" << a2L << endl;
01572   //MSG("DMXX", Msg::kDebug) << "\tquadratic fit " << chiSqQ << "\t" << a1Q 
01573   //                      << "\t" << a2Q << "\t" << a3Q << endl;
01574 
01575   //pick the better fit
01576   if(chiSqL<=chiSqQ){
01577     prevChiSq = chiSqL;
01578     a1 = a1L;
01579     a2 = a2L;
01580     a3 = 0.;
01581     a4 = 0.;
01582   }
01583   else{
01584     prevChiSq = chiSqQ;
01585     a1 = a1Q;
01586     a2 = a2Q;
01587     a3 = a3Q;
01588     a4 = 0.;
01589   }
01590   //MSG("DMX", Msg::kDebug) << "\tinitial fit " << a1 << "\t" << a2 << "\t" << a3 << "\t" << a4 << chiSq << endl; 
01591  
01592   planeItr.Reset();
01593   planeCtr = 0;
01594   arrayCtr = 0;
01595   //cout << "reset the iterator" << endl;
01596   
01597   //redo the fit as many times as there are planes, dropping each plane in 
01598   //turn to see if it produces a better chi^2 value - only do it if you have 
01599   //more than 3 planes - ie you can drop one and still do a reasonable fit
01600   //2 planes = great straight line every time.
01601   if(leverArm > 3){
01602     a1L = 0.;
01603     a2L = 0.;
01604     a1Q = 0.;
01605     a2Q = 0.;
01606     a3Q = 0.;
01607 
01608     Double_t fitA1 = 0.;
01609     Double_t fitA2 = 0.;
01610     Double_t fitA3 = 0.;
01611     Double_t fitA4 = 0.;
01612 
01613     for(Int_t i = 0; i < leverArm; i++){
01614       arrayCtr = 0;
01615 
01616       //cout <<"in loop " << i << endl;
01617       //loop over the plane iterator to fill the variables
01618       while( (plane = planeItr()) && planeCtr < leverArm){
01619         
01620         //use those planes not marked as kTRUE - a mark of kTRUE means to drop the plane
01621         //from the set when finding the fit. ie if its true, the plane truely sucks
01622         if( !planeItr.GetSet()->GetMasks().GetMask(plane) ){
01623 
01624           if(i != planeCtr){
01625             x[arrayCtr] = plane->GetZPosition() - offset;
01626             y[arrayCtr] = plane->GetCoG();
01627 
01628             //cout << "filling arrays " << arrayCtr << " " << x[arrayCtr] << " " << y[arrayCtr] 
01629             // << " " << weightSq[arrayCtr] << endl;
01630 
01631             weight[arrayCtr] = 1. / TMath::Sqrt(plane->GetPlaneCharge());
01632             if(plane->IsGolden()) weight[arrayCtr] /= TMath::Sqrt(10.);
01633       
01634             //only make changes if not a golden plane
01635             if( plane->GetPlaneType() == DmxPlaneTypes::kShower  && !plane->IsGolden()){
01636               //only change y if the hypothesis isnt the best one - the unset plane returns the best
01637               //cog from the GetCoG() method
01638               
01639               if(hypotheses[planeCtr] == 1){
01640                 weight[arrayCtr] /= TMath::Sqrt(dynamic_cast<DmxShowerPlane *>(plane)->GetBestHypothesis()->GetMatedSignalRatio());
01641               }
01642               else if(hypotheses[planeCtr] == 2){ 
01643                 y[arrayCtr] = dynamic_cast<DmxShowerPlane *>(plane)->GetSecondBestCoG();
01644                 weight[arrayCtr] /= TMath::Sqrt(dynamic_cast<DmxShowerPlane *>(plane)->GetSecondBestHypothesis()->GetMatedSignalRatio());
01645               }
01646               else if(hypotheses[planeCtr] == 3){ 
01647                 y[arrayCtr] = dynamic_cast<DmxShowerPlane *>(plane)->GetThirdBestCoG();
01648                 weight[arrayCtr] /= TMath::Sqrt(dynamic_cast<DmxShowerPlane *>(plane)->GetThirdBestHypothesis()->GetMatedSignalRatio());
01649               }
01650             }
01651 
01652             ++arrayCtr;
01653             //else{ MSG("DMX", Msg::kDebug) << "\tdrop plane " << plane->GetPlaneNumber() << endl; }
01654           } //end if plane is not the dropped one
01655         }//end if plane is in window bounds
01656         ++planeCtr;
01657       } //end loop over planes to find variables for fit
01658             
01659       //use the DmxUtilities function to find a linear fit
01660       
01661       util.FindLinearFit(x, y, weight, arrayCtr, a1L, a2L, chiSqL);
01662       //util.FindQuadraticFit(x, y, weight, arrayCtr, a1Q, a2Q, a3Q, chiSqQ);
01663       //util.FindCubicFit(x, y, weight, arrayCtr, fitA1, fitA2, fitA3, fitA4, chiSq);
01664             
01665       //MSG("DMXX", Msg::kDebug) << "\tlinear fit " << chiSqL << "\t" << a1L << "\t" << a2L << endl;
01666       //MSG("DMXX", Msg::kDebug) << "\tquadratic fit " << chiSqQ << "\t" << a1Q 
01667       //                              << "\t" << a2Q << "\t" << a3Q << endl;
01668       //pick the better fit
01669       if(chiSqL<=chiSqQ){
01670         chiSq = chiSqL;
01671         fitA1 = a1L;
01672         fitA2 = a2L;
01673       }
01674       else{
01675         chiSq = chiSqQ;
01676         fitA1 = a1Q;
01677         fitA2 = a2Q;
01678         fitA3 = a3Q;
01679       }
01680     
01681       planeItr.Reset();
01682 
01683       planeCtr = 0;
01684       if(chiSq < prevChiSq){
01685         prevChiSq = chiSq;
01686         a1 = fitA1;
01687         a2 = fitA2;
01688         a3 = fitA3;
01689         a4 = fitA4;
01690         //MSG("DMX", Msg::kDebug) << "\trefined fit, drop plane " << i 
01691         //             << "\t" << prevChiSq << "\t" << a << "\t" << b << endl;
01692       }
01693       
01694     }//end for loop to improve fit by dropping a plane
01695   }//end if enough planes to improve fit
01696 
01697   planeItr.ResetFirst();
01698   //MSG("DMX", Msg::kDebug) << "\tfinal fit" << "\t" << a << "\t" << b << "\t" << prevChiSq << endl; 
01699 
01700   //cout << "finished find fit for first n planes" << endl;
01701   
01702   return;
01703 }

Bool_t AlgDeMuxCosmics::FindPlanesToDropFromFit DmxPlaneItr &  planeItr,
Double_t  a1,
Double_t  a2,
Double_t  a3,
Double_t  a4,
Int_t  direction,
Int_t  leverArm,
Float_t  offset
[private]
 

Definition at line 1789 of file AlgDeMuxCosmics.cxx.

References DmxPlane::GetCoG(), DmxPlane::GetPlaneType(), DmxPlane::GetZPosition(), DmxPlane::IsGolden(), and DmxPlane::SetGolden().

Referenced by FindCosmicSolution().

01792 {
01793 
01794   //MSG("DMXX", Msg::kDebug) << "in FindPlanesToDropFromFit" << endl;
01795 
01796   Double_t diff1 = 0.;
01797   Double_t diff2 = 0.;
01798   Double_t diff3 = 0.;
01799   bool planesDropped = false;
01800 
01801   Int_t dropPlanes = 0;
01802   Int_t planeCtr = 0;
01803   if( direction == 1 ){ planeItr.ResetFirst(); }
01804   else if( direction == -1 ){ planeItr.ResetLast(); }
01805  
01806   //MSG("DMX", Msg::kDebug)<<"\tin FindPlanesToDropFromFit"; 
01807   
01808   DmxPlane *plane = 0;
01809   //find the plane farthest off from the fit, keep going until you have just 3 planes left
01810   while( (plane = planeItr()) && dropPlanes<(Int_t)(0.1*leverArm) && planeCtr<leverArm){
01811 
01812     Double_t fitCoG = (a1 + (plane->GetZPosition()-offset)*a2 
01813                        + TMath::Power(plane->GetZPosition()-offset,2)*a3
01814                        + TMath::Power(plane->GetZPosition()-offset,3)*a4);
01815   
01816       //MSG("DMX", Msg::kDebug)<<"\t" << plane->GetPlaneNumber() << endl;
01817       
01818       if( !planeItr.GetSet()->GetMasks().GetMask(plane) ){
01819         if( plane->GetPlaneType() == DmxPlaneTypes::kShower ){
01820           diff1 = TMath::Abs(fitCoG-dynamic_cast<DmxShowerPlane *>(plane)->GetBestCoG());
01821           diff2 = TMath::Abs(fitCoG-dynamic_cast<DmxShowerPlane *>(plane)->GetSecondBestCoG());
01822           diff3 = TMath::Abs(fitCoG-dynamic_cast<DmxShowerPlane *>(plane)->GetThirdBestCoG());
01823         }
01824         else if( plane->GetPlaneType() == DmxPlaneTypes::kMuon ){
01825           diff1 = TMath::Abs(fitCoG - plane->GetCoG());
01826           diff2 = TMath::Abs(fitCoG - plane->GetCoG());
01827           diff3 = TMath::Abs(fitCoG - plane->GetCoG());
01828         }
01829         
01830         //if all the 3 best hypotheses are way off from the fit, that plane is most 
01831         //likely messing up the fit.  so mark it as kTRUE - ie it, it truely sucks
01832         if(diff1 > .504 && diff2 > .504 && diff3 > .504 && !plane->IsGolden() ){
01833           planeItr.GetSet()->GetMasks().SetMask(kTRUE, planeItr.Ptr());
01834           planesDropped = true;
01835           //MSG("DMX", Msg::kDebug)<<"\tmarking plane " << plane->GetPlaneNumber() << endl;
01836           //decrement the number of planes now used for a fit.
01837           ++dropPlanes;
01838         }
01839         else if(diff1 > 0.504 && plane->IsGolden()){
01840           
01841           //if this was a golden plane but it just doesnt work, make a non-golden plane
01842           planeItr.GetSet()->GetMasks().SetMask(kTRUE, planeItr.Ptr());
01843           plane->SetGolden(false);
01844           planesDropped = true;
01845           //MSG("DMX", Msg::kDebug)<<"\tmarking plane " << plane->GetPlaneNumber() << endl;
01846           //decrement the number of planes now used for a fit.
01847           ++dropPlanes;
01848         }//end if dropping a golden plane
01849       } //end if the mask hasnt already been set for this plane
01850       
01851       ++planeCtr;
01852   }
01853   planeItr.ResetFirst();
01854   
01855   //cout << "finished drop planes from fit" << endl;
01856 
01857   return planesDropped;
01858 }

void AlgDeMuxCosmics::FindWindowCosmicSolution DmxPlaneItr &  validPlaneItr,
DmxStatus status,
Double_t &  a1,
Double_t &  a2,
Double_t &  a3,
Double_t &  a4,
Double_t &  chiSq,
Float_t  offset
[private]
 

Definition at line 746 of file AlgDeMuxCosmics.cxx.

References DmxUtilities::FindLinearFit(), DmxPlane::GetCoG(), DmxStatus::GetEventDirection(), DmxPlane::GetPlaneCharge(), DmxPlane::GetPlaneNumber(), DmxPlane::GetPlaneType(), DmxPlane::GetZPosition(), DmxPlane::IsGolden(), MSG, and DmxPlane::SetGolden().

Referenced by UseSlidingWindow().

00752 {
00753   //MSG("DMXX", Msg::kDebug) << "in FindWindowCosmicSolution" << endl;
00754 
00755   //variables to keep track of the best reconstruction
00756   Double_t fitA1L = 0.;
00757   Double_t fitA2L = 0.;
00758   Double_t chi2L = 1.0e20;
00759 //   Double_t fitA1Q = 0.;
00760 //   Double_t fitA2Q = 0.;
00761 //   Double_t fitA3Q = 0.;
00762 //   Double_t chi2Q = 1.0e20;
00763   Double_t fitA1 = 0.;
00764   Double_t fitA2 = 0.;
00765   Double_t fitA3 = 0.;
00766   Double_t fitA4 = 0.;
00767   Double_t chi2 = 1.0e20;
00768   Double_t chi2Fit = 1.0e20;
00769 
00770   Int_t direction = status->GetEventDirection();
00771 
00772   //make the lever arm for the demuxer the # of valid planes or 6, whichever
00773   //is smaller
00774   Int_t leverArm = fPlanesInSet;
00775 
00776   //offset is the lowest z pos in the window. subtract it from each x array value
00777   //- this has the effect of changing your y axis location 
00778   //relative to the z = 0 location so that when doing higher order fits, you 
00779   //dont get really stupid numbers
00780  
00781   //declare the variables to do a least squares fit to a straight line.  
00782   //use three chiSq values to keep track of the 3 different hyps in the
00783   //unset plane - also have 3 different y values for those hyps and 3
00784   //different weights
00785   Double_t x[] = {0.,0.,0.,0.,0.,0.};
00786   Double_t y[] = {0.,0.,0.,0.,0.,0.};
00787   Double_t weight[] = {1.,1.,1.,1.,1.,1.};
00788   Double_t weight2 = 1.;
00789   Double_t weight3 = 1.;
00790   Double_t y2 = 0.;
00791   Double_t y3 = 0.;
00792 
00793   //variable to let you know if the unset plane is a golden plane or not
00794   bool lastGolden = false;
00795 
00796   Double_t a1L = 0.;
00797   Double_t a2L = 0.;
00798   Double_t a1LB = 0.;
00799   Double_t a2LB = 0.;
00800   Double_t a1LS = 0.;
00801   Double_t a2LS = 0.;
00802   Double_t a1LT = 0.;
00803   Double_t a2LT = 0.;
00804  //  Double_t a1QB = 0.;
00805 //   Double_t a2QB = 0.;
00806 //   Double_t a3QB = 0.;
00807 //   Double_t a1QS = 0.;
00808 //   Double_t a2QS = 0.;
00809 //   Double_t a3QS = 0.;
00810 //   Double_t a1QT = 0.;
00811 //   Double_t a2QT = 0.;
00812 //   Double_t a3QT = 0.;
00813 //   Double_t a1Q = 0.;
00814 //   Double_t a2Q = 0.;
00815 //   Double_t a3Q = 0.;
00816   
00817   Double_t chiSqL = 1.e20;
00818   Double_t chiSqLB = 1.e20;
00819   Double_t chiSqLS = 1.e20;
00820   Double_t chiSqLT = 1.e20;
00821 //   Double_t chiSqQB = 1.e20;
00822 //   Double_t chiSqQS = 1.e20;
00823 //   Double_t chiSqQT = 1.e20;
00824 //   Double_t chiSqQ = 1.e20;
00825 
00826   Double_t a1Fit = 0.;
00827   Double_t a2Fit = 0.;
00828   Double_t a3Fit = 0.;
00829   Double_t a4Fit = 0.;
00830 
00831   
00832   DmxUtilities util;
00833 
00834   if(direction == -1) validPlaneItr.ResetLast();
00835   else if( direction == 1) validPlaneItr.ResetFirst();
00836   
00837   Int_t planeCtr = 0;
00838   DmxPlane *plane = 0;
00839       
00840   while( (plane = validPlaneItr()) && planeCtr < leverArm){
00841 
00842     //cout << "plane = " << plane->GetPlaneNumber() << endl;
00843 
00844     x[planeCtr] = plane->GetZPosition() - offset;
00845     y[planeCtr] = plane->GetCoG();
00846     weight[planeCtr] = 1. / TMath::Sqrt(plane->GetPlaneCharge());
00847 
00848     if(plane->IsGolden()){
00849 
00850       //golden plane, so make the weight smaller to give it more
00851       //clout in the fit
00852       weight[planeCtr] /= TMath::Sqrt(10.);
00853       if(planeCtr == leverArm-1){
00854         lastGolden = true;
00855         y2 = y[planeCtr];
00856         y3 = y[planeCtr];
00857         weight2 = weight[planeCtr];
00858         weight3 = weight[planeCtr];
00859       }
00860     }
00861 
00862     //only make changes if not a golden plane
00863     if(plane->GetPlaneType() == DmxPlaneTypes::kShower && !plane->IsGolden() ){
00864 
00865       //make sure you dont divide by zero when getting the mated signal ratio of
00866       //the set hypothesis - could be that you set the plane to a hypothesis
00867       //with no mated signal, even though it is a valid plane
00868       if(planeCtr < leverArm-1 
00869          && dynamic_cast<DmxShowerPlane *>(plane)->GetSetHypothesis()->GetMatedSignalRatio() > 0.){
00870         weight[planeCtr] /= TMath::Sqrt(dynamic_cast<DmxShowerPlane *>(plane)->GetSetHypothesis()->GetMatedSignalRatio()); 
00871 //      MSG("Dmx", Msg::kDebug) << dynamic_cast<DmxShowerPlane *>(plane)->GetSetHypothesis()->GetMatedSignalRatio() << endl;
00872       }
00873       else if( planeCtr == leverArm-1 ){          
00874         
00875         y2 = dynamic_cast<DmxShowerPlane *>(plane)->GetSecondBestCoG();
00876         y3 = dynamic_cast<DmxShowerPlane *>(plane)->GetThirdBestCoG();
00877 
00878         //dont have to worry about dividing by zero here because you havent
00879         //set the plane yet and you know that the best hypotheses in the planes
00880         //must have at least 0.3 mated signal
00881         weight2 = weight[planeCtr]/TMath::Sqrt(dynamic_cast<DmxShowerPlane *>(plane)->GetSecondBestHypothesis()->GetMatedSignalRatio()); 
00882         weight3 = weight[planeCtr]/TMath::Sqrt(dynamic_cast<DmxShowerPlane *>(plane)->GetThirdBestHypothesis()->GetMatedSignalRatio());         
00883 
00884         weight[planeCtr] /= TMath::Sqrt(dynamic_cast<DmxShowerPlane *>(plane)->GetBestHypothesis()->GetMatedSignalRatio()); 
00885       }
00886     }
00887 
00888     ++planeCtr;
00889     
00890   } //end loop over planes to find variables for fit
00891       
00892   //do fit using function in DmxUtilities
00893 
00894   //the best hyp fit first
00895   util.FindLinearFit(x, y, weight, leverArm, a1LB, a2LB, chiSqLB);
00896   //util.FindQuadraticFit(x, y, weight, leverArm, a1QB, a2QB, a3QB, chiSqQB);
00897 
00898   //find fit for using the last plane's second best hyp
00899   y[leverArm-1] = y2;
00900   weight[leverArm-1] = weight2;
00901   util.FindLinearFit(x, y, weight, leverArm, a1LS, a2LS, chiSqLS);
00902   //util.FindQuadraticFit(x, y, weight, leverArm, a1QS, a2QS, a3QS, chiSqQS);
00903 
00904   //find fit using the last plane's third best hyp
00905   y[leverArm-1] = y3;
00906   weight[leverArm-1] = weight3;
00907   util.FindLinearFit(x, y, weight, leverArm, a1LT, a2LT, chiSqLT);
00908   //util.FindQuadraticFit(x, y, weight, leverArm, a1QT, a2QT, a3QT, chiSqQT);
00909 
00910   //util.FindCubicFit(x, y, weight, leverArm, a1, a2, a3, a4, chiSq);
00911 
00912  //  MSG("DMXX", Msg::kDebug) << "\tlinear fit1 " << chiSqLB << "\t" << a1LB << "\t" << a2LB << endl;
00913 //   MSG("DMXX", Msg::kDebug) << "\tlinear fit2 " << chiSqLS << "\t" << a1LS << "\t" << a2LS << endl;
00914 //   MSG("DMXX", Msg::kDebug) << "\tlinear fit3 " << chiSqLT << "\t" << a1LT << "\t" << a2LT << endl;
00915   //MSG("DMXX", Msg::kDebug) << "\tquadratic fit " << chiSqQ << "\t" << a1Q 
00916   //              << "\t" << a2Q << "\t" << a3Q << endl;
00917    
00918   //pick the better linear fit
00919   if(chiSqLB<=chiSqLS && chiSqLB<=chiSqLT){
00920     chiSqL = chiSqLB;
00921     a1L = a1LB;
00922     a2L = a2LB;
00923   }
00924   else if(chiSqLS<chiSqLB && chiSqLS<=chiSqLT){
00925     chiSqL = chiSqLS;
00926     a1L = a1LS;
00927     a2L = a2LS;
00928   }
00929   else if(chiSqLT<chiSqLB && chiSqLT<chiSqLS){
00930     chiSqL = chiSqLT;
00931     a1L = a1LT;
00932     a2L = a2LT;
00933   }
00934 
00935   //pick the better quadratic fit
00936   // if(chiSqQB<=chiSqQS && chiSqQB<=chiSqQT){
00937 //     chiSqQ = chiSqQB;
00938 //     a1Q = a1QB;
00939 //     a2Q = a2QB;
00940 //     a3Q = a3QB;
00941 //   }
00942 //   else if(chiSqQS<chiSqQB && chiSqQS<=chiSqQT){
00943 //     chiSqQ = chiSqQS;
00944 //     a1Q = a1QS;
00945 //     a2Q = a2QS;
00946 //     a3Q = a3QS;
00947 //   }
00948 //   else if(chiSqQT<chiSqQB && chiSqQT<chiSqQS){
00949 //     chiSqQ = chiSqQT;
00950 //     a1Q = a1QT;
00951 //     a2Q = a2QT;
00952 //     a3Q = a3QT;
00953 //   }
00954 
00955   //pick the better fit - linear or quadratic
00956   //if(chiSqL<=chiSqQ){
00957     chi2Fit = chiSqL;
00958     a1Fit = a1L;
00959     a2Fit = a2L;
00960     a3Fit = 0.;
00961     a4Fit = 0.;
00962     //}
00963  //  else{
00964 //     chi2Fit = chiSqQ;
00965 //     a1Fit = a1Q;
00966 //     a2Fit = a2Q;
00967 //     a3Fit = a3Q;
00968 //     a4Fit = 0.;
00969 //   }
00970 
00971     //MSG("DMXX", Msg::kDebug) << "\tinitial fit " << chi2Fit << "\t" << a1Fit << "\t" << a2Fit 
00972     //            << "\t" << a3Fit << "\t" << a4Fit << endl;
00973   
00974   //redo the fit using only the previously set planes and only if you have more than 3 planes in the set
00975   if(leverArm > 3){
00976     
00977     //do fit using function in DmxUtilities
00978     util.FindLinearFit(x, y, weight, leverArm-1, fitA1L, fitA2L, chi2L);
00979     //util.FindQuadraticFit(x, y, weight, planeCtr, fitA1Q, fitA2Q, fitA3Q, chi2Q);
00980     //util.FindCubicFit(x, y, weight, planeCtr, fitA1, fitA2, fitA3, fitA4, chiSq);
00981     
00982     //MSG("DMXX", Msg::kDebug) << "\trefined linear fit " << chi2L << "\t" << fitA1L << "\t" << fitA2L << endl;
00983     //MSG("DMXX", Msg::kDebug) << "\tquadratic fit " << chiSqQ << "\t" << a1Q 
00984     //              << "\t" << a2Q << "\t" << a3Q << endl;
00985   
00986     //pick the better fit - linear or quadratic
00987     //if(chi2L<=chi2Q){
00988     chi2 = chi2L;
00989     fitA1 = fitA1L;
00990     fitA2 = fitA2L;
00991     fitA3 = 0.;
00992     fitA4 = 0.;
00993     //}
00994     //  else{
00995     //       chi2 = chi2Q;
00996     //       fitA1 = fitA1Q;
00997     //       fitA2 = fitA2Q;
00998     //       fitA3 = fitA3Q;
00999     //       fitA4 = 0.;
01000     //     }
01001 
01002     
01003     if( lastGolden ){
01004 
01005       if(direction == 1) validPlaneItr.ResetLast();
01006       else if( direction == -1) validPlaneItr.ResetFirst();
01007       
01008       plane = validPlaneItr();
01009       
01010       MSG("AlgDmx", Msg::kDebug) << "last plane number = " << plane->GetPlaneNumber() 
01011                                  << " this is a golden plane " 
01012                                  << plane->IsGolden() << endl;
01013      
01014       
01015       //unset the IsGolden flag for the last plane if the difference between the
01016       //fit center of gravity and the plane's center of gravity is > 0.5m and
01017       //any of the following
01018       //1. the golden CoG is different from the previous set valid plane's
01019       //   CoG by more than 0.25m/plane (plane to plane spacing is 0.1188m)
01020       //2. chi^2 of fit without the golden plane is an order of magnitude
01021       //   smaller than the chi^2 of the fit with it
01022       //3. the average difference between the set CoG's and the golden CoG and
01023       //   the fit CoG's for all planes in the window is greater than 0.5m
01024 
01025       //cout << x[leverArm-1] << " " << x[leverArm-2] << " " << a1Fit << " " << a2Fit << endl;
01026 
01027       Double_t fitCoG = (a1Fit + a2Fit*(x[leverArm-1])
01028                          + a3Fit*TMath::Power(x[leverArm-1],2) 
01029                          + a4Fit*TMath::Power(x[leverArm-1],3));
01030 
01031       Double_t fitDiff = 0.;
01032       for(Int_t ii = 0; ii<leverArm; ii++){
01033         fitDiff += TMath::Abs((a1Fit + a2Fit*(x[ii]) + a3Fit*TMath::Power(x[ii],2) 
01034                                + a4Fit*TMath::Power(x[ii],3) - y[ii]));
01035       }
01036       Double_t planeDiff = TMath::Abs(x[leverArm-1]-x[leverArm-2])/0.1188;
01037       
01038       MSG("DmxAlg", Msg::kDebug) << "fit is " << fitCoG << " golden CoG = " 
01039                                 << plane->GetCoG() << endl
01040                                 <<" y diff = " << TMath::Abs(y[leverArm-2]-plane->GetCoG()) 
01041                                 << "/" << planeDiff*.25 << endl
01042                                 <<" fitDiff = " << fitDiff <<"/" << 0.5*leverArm << endl
01043                                 << "chi2Fit = " << chi2Fit << "/" << 10.*chi2 << endl;
01044       
01045       if(TMath::Abs(plane->GetCoG()-fitCoG)>0.5 && (fitDiff>0.5*leverArm
01046          || TMath::Abs(y[leverArm-2]-plane->GetCoG())>(0.25*planeDiff)
01047          || chi2Fit>10.*chi2)){
01048         
01049         plane->SetGolden(false);
01050         MSG("DmxAlg", Msg::kDebug) << plane->GetPlaneNumber() << " was golden " 
01051                                    << plane->IsGolden() << endl;
01052         lastGolden = false;
01053       }
01054     }//end check of last plane is golden
01055 
01056     //if the fit found by dropping the last plane has a better chi^2 than the 
01057     //fit using all planes, and that last plane was not golden, then pass the
01058     //fit from the first planes in the window out.  if the last plane was initially
01059     //golden, this only happens for the last time through.
01060     //
01061     if(chi2 < chi2Fit && !lastGolden){
01062     
01063       chi2Fit = chi2;
01064       a1Fit = fitA1;
01065       a2Fit = fitA2;
01066       a3Fit = fitA3;
01067       a4Fit = fitA4;
01068     }
01069    
01070   }//end for loop to improve fit by dropping a plane
01071 
01072   chiSq = chi2Fit;  
01073   a1 = a1Fit;
01074   a2 = a2Fit;
01075   a3 = a3Fit;
01076   a4 = a4Fit;
01077   
01078   //MSG("DMXX", Msg::kDebug) << "\tchosen linear fit " << chiSq << "\t" << a1 << "\t" << a2 << endl;
01079 
01080   validPlaneItr.Reset();
01081 
01082   return;
01083 }

void AlgDeMuxCosmics::RunAlg AlgConfig acd,
CandHandle ch,
CandContext cx
[virtual]
 

Implements AlgBase.

Definition at line 93 of file AlgDeMuxCosmics.cxx.

References RawTriggerCodes::AsString(), DmxUtilities::CheckFitWithTiming(), DmxUtilities::FillPlaneArray(), DmxUtilities::FindEndPlane(), DmxUtilities::FindPlanesOffFit(), DmxUtilities::FindVertexPlane(), fPlanesInSet, fRequiredMatedSignalRatio, fSlopeRMS, fStrayCut, fStrayPlanes, DmxStatus::GetAverageTimingOffset(), CandRecord::GetCandHeader(), CandHandle::GetCandRecord(), VldContext::GetDetector(), Registry::GetDouble(), DmxStatus::GetEndPlaneNumber(), DmxStatus::GetEventDeMuxed(), DmxStatus::GetEventNumber(), DmxStatus::GetFigureOfMeritFailure(), Registry::GetInt(), CandHandle::GetNDaughters(), DmxStatus::GetNonPhysicalFailure(), DmxStatus::GetPlaneArray(), CandHeader::GetSnarl(), DmxStatus::GetVertexPlaneNumber(), RecMinosHdr::GetVldContext(), DmxUtilities::IsOverlappingMultiple(), KeyOnPlane(), KeyOnUView(), KeyOnValidU(), KeyOnValidV(), KeyOnVView(), MSG, DmxStatus::ResetStatus(), DmxStatus::SetAverageTimingOffset(), CandDeMuxDigitListHandle::SetAvgTimeOffset(), CandDeMuxDigitListHandle::SetDeMuxDigitListFlagBit(), DmxStatus::SetEndPlaneNumber(), DmxStatus::SetEventNumber(), DmxStatus::SetFigureOfMerit(), DmxStatus::SetMultipleMuon(), DmxStatus::SetNoVertexFailure(), DmxStatus::SetNumberOfPlanes(), CandDeMuxDigitListHandle::SetNumStrayPlanesU(), CandDeMuxDigitListHandle::SetNumStrayPlanesV(), CandDeMuxDigitListHandle::SetNumValidPlanesU(), CandDeMuxDigitListHandle::SetNumValidPlanesV(), SetPlanesToDeterminedFit(), DmxStatus::SetUOverlappingMultiple(), DmxStatus::SetUStrayPlanes(), DmxStatus::SetUValidPlanes(), DmxStatus::SetValidPlanesFailure(), DmxStatus::SetVertexPlaneNumber(), DmxStatus::SetVertexPlaneZPosition(), DmxStatus::SetVOverlappingMultiple(), DmxStatus::SetVStrayPlanes(), DmxStatus::SetVValidPlanes(), UseSingleFit(), and UseSlidingWindow().

00094 {
00095 
00096   assert( ch.InheritsFrom("CandDigitListHandle") );
00097   CandDeMuxDigitListHandle &cdlh = dynamic_cast<CandDeMuxDigitListHandle&>(ch);
00098   
00099   MSG("AlgDeMuxCosmics", Msg::kDebug) << cdlh.GetNDaughters() << " digits in AlgDeMuxCosmics" << endl;
00100   
00101   VldContext vldc = ch.GetCandRecord()->GetCandHeader()->GetVldContext();
00102   if (vldc.GetDetector() != Detector::kFar) {
00103     static int msglimit = 20; // no more than 20 warnings about the detector
00104     if (msglimit) {
00105       MSG("DMX",Msg::kDebug) 
00106         << "AlgDeMuxCosmics::RunAlg() can not DeMux "
00107         << Detector::AsString(vldc.GetDetector())
00108         << " detector.  Skip futher DeMux processing."
00109         << endl;
00110       if (--msglimit == 0) 
00111         MSG("DMX",Msg::kDebug) 
00112           << " ... last message of this type." << endl;
00113     }
00114     return;
00115   }
00116 
00117   //get the AlgConfigDeMux object
00118   fPlanesInSet = acd.GetInt("PlanesInSet");
00119   fRequiredMatedSignalRatio = acd.GetDouble("RatioMatedSignalForValid");
00120   fStrayCut = acd.GetInt("StrayDeltaStripLimit");
00121   //MSG("DMX", Msg::kDebug) << "starting cosmics algorithm" << endl;
00122 
00123   //get the DmxStatus object
00124   // Find the DmxStatus object or create one for needed scratch space
00125   DmxStatus *status = dynamic_cast<DmxStatus *>(gROOT->GetRootFolder()->FindObject("Loon/DeMux/DmxStatus"));
00126   bool tempStatus = false;
00127   if (status == 0) {
00128     MSG("DMXX", Msg::kDebug) << "//root/Loon/DeMux/DmxStatus not found."
00129                               << " Create a temporary DmxStatus." << endl;
00130     status = new DmxStatus;      // Make a temporary DmxStatus if needed
00131     tempStatus = true;
00132   }
00133   else status->ResetStatus(); 
00134 
00135   status->SetEventNumber(ch.GetCandRecord()->GetCandHeader()->GetSnarl());
00136   
00137   //instantiate the DmxInitialize object and then fill DmxStatus with the event information     
00138   DmxUtilities util;
00139   
00140   util.FillPlaneArray(status, cdlh, acd);
00141   const TObjArray *planeArray = status->GetPlaneArray();
00142   
00143   //create the TObjectItr over planes and program it to sort the planes
00144   DmxPlaneItr planeItr(planeArray);
00145   DmxPlaneKeyFunc *pnKF = planeItr.CreateKeyFunc();
00146   pnKF->SetFun(KeyOnPlane);
00147   planeItr.GetSet()->AdoptSortKeyFunc(pnKF);
00148   pnKF = 0;
00149   
00150   planeItr.ResetFirst();
00151 
00152   // while(planeItr.IsValid()){
00153 //     cout << dynamic_cast<DmxPlane *>(planeItr.Ptr())->GetPlaneNumber() << endl;
00154 //     planeItr.Next();
00155 //   }
00156 //   planeItr.ResetFirst();
00157 
00158   status->SetNumberOfPlanes(planeItr.SizeSelect());
00159   status->SetVertexPlaneNumber(util.FindVertexPlane(planeItr));
00160   
00161   //demux the event if there is an identified vertex
00162   if( status->GetVertexPlaneNumber() != -1){
00163     
00164     planeItr.ResetFirst();
00165     planeItr.GetSet()->Slice(status->GetVertexPlaneNumber(), 500);
00166     planeItr.GetSet()->Update();
00167     //set the end plane number since there was a vertex plane
00168     status->SetEndPlaneNumber(util.FindEndPlane(planeItr));
00169     planeItr.GetSet()->ClearSlice(false);
00170     planeItr.ResetFirst();
00171 
00172     //set the z position of the vertex plane
00173     planeItr.GetSet()->Slice(status->GetVertexPlaneNumber());
00174     planeItr.GetSet()->Update();
00175     planeItr.ResetFirst();
00176     status->SetVertexPlaneZPosition(dynamic_cast<DmxPlane *>(planeItr.Ptr())->GetZPosition());
00177 
00178     planeItr.GetSet()->ClearSlice(false);
00179     planeItr.ResetFirst();
00180 
00181     //make the iterators for the window, valid planes, and vertex
00182     DmxPlaneItr vertexPlaneItr(planeArray);
00183     DmxPlaneItr validPlaneItr(planeArray);
00184     DmxPlaneItr windowPlaneItr(planeArray);
00185        
00186     //create a KeyFunc to sort planes by number
00187     DmxPlaneKeyFunc *vertexPlaneKF = vertexPlaneItr.CreateKeyFunc();
00188     DmxPlaneKeyFunc *validPlaneKF = validPlaneItr.CreateKeyFunc();
00189     DmxPlaneKeyFunc *validWindowPlaneKF = windowPlaneItr.CreateKeyFunc();
00190        
00191     //program the KeyFunc with the sort function
00192     vertexPlaneKF->SetFun(KeyOnPlane);
00193     validPlaneKF->SetFun(KeyOnPlane);
00194     validWindowPlaneKF->SetFun(KeyOnPlane);
00195        
00196     //get the NavSet from the iterator and pass the KeyFunc to it
00197     vertexPlaneItr.GetSet()->AdoptSortKeyFunc(vertexPlaneKF);
00198     validPlaneItr.GetSet()->AdoptSortKeyFunc(validPlaneKF);
00199     windowPlaneItr.GetSet()->AdoptSortKeyFunc(validWindowPlaneKF);
00200        
00201     //clear the KF pointer because we no longer own the KeyFunc
00202     vertexPlaneKF = 0;
00203     validPlaneKF = 0;
00204     validWindowPlaneKF = 0;
00205     planeItr.ResetFirst();
00206     validPlaneItr.ResetFirst();
00207     windowPlaneItr.ResetFirst();
00208         
00209     //now program a key function to select on plane orientation - U first
00210     DmxPlaneKeyFunc *orientValidUKF = validPlaneItr.CreateKeyFunc();
00211     DmxPlaneKeyFunc *orientValidWindowUKF = windowPlaneItr.CreateKeyFunc();
00212     DmxPlaneKeyFunc *orientUKF = planeItr.CreateKeyFunc();
00213     DmxPlaneKeyFunc *orientValidVKF = validPlaneItr.CreateKeyFunc();
00214     DmxPlaneKeyFunc *orientValidWindowVKF = windowPlaneItr.CreateKeyFunc();
00215     DmxPlaneKeyFunc *orientVKF = planeItr.CreateKeyFunc();
00216     
00217     Int_t viewCtr = 0;
00218     while( viewCtr < 2 ){
00219       fSlopeRMS = 0.;
00220       fStrayPlanes = 0;
00221       
00222       if( viewCtr == 0){
00223         //program this function with the select function
00224         orientUKF->SetFun(KeyOnUView);
00225         orientValidUKF->SetFun(KeyOnValidU);
00226         orientValidWindowUKF->SetFun(KeyOnValidU);
00227                 
00228         //adopt it as a selection function
00229         planeItr.GetSet()->AdoptSelectKeyFunc(orientUKF);
00230         orientUKF = 0;
00231         planeItr.Reset();
00232         validPlaneItr.GetSet()->AdoptSelectKeyFunc(orientValidUKF);
00233         orientValidUKF = 0;
00234         validPlaneItr.Reset();
00235         windowPlaneItr.GetSet()->AdoptSelectKeyFunc(orientValidWindowUKF);
00236         orientValidWindowUKF = 0;
00237         windowPlaneItr.Reset();
00238       }
00239       else if(viewCtr == 1){
00240         //program this function with the select function
00241         orientVKF->SetFun(KeyOnVView);
00242         orientValidVKF->SetFun(KeyOnValidV);
00243         orientValidWindowVKF->SetFun(KeyOnValidV);
00244                 
00245         //adopt it as a selection function
00246         planeItr.GetSet()->AdoptSelectKeyFunc(orientVKF);
00247         orientVKF = 0;
00248         planeItr.Reset();
00249         validPlaneItr.GetSet()->AdoptSelectKeyFunc(orientValidVKF);
00250         orientValidVKF = 0;
00251         validPlaneItr.Reset();
00252         windowPlaneItr.GetSet()->AdoptSelectKeyFunc(orientValidWindowVKF);
00253         orientValidWindowVKF = 0;
00254         windowPlaneItr.Reset();
00255       }
00256 
00257       //  validPlaneItr.ResetLast();
00258 //      MSG("AlgDeMuxCosmics", Msg::kDebug)<<"event " << status->GetEventNumber() << endl;
00259 //        while(validPlaneItr.IsValid()){
00260 //      MSG("DMX1", Msg::kDebug)<<"\tvalid plane " 
00261 //                             << dynamic_cast<DmxPlane* >(validPlaneItr.Ptr())->GetPlaneNumber() << endl; 
00262 //      validPlaneItr.Prev();
00263 //        }
00264       
00265 //        validPlaneItr.Reset();
00266       
00267       //  DmxPlane *plane = 0;
00268       
00269 //        while( (plane = dynamic_cast<DmxPlane *>(validPlaneItr())) ){
00270 //      MSG("DMX1", Msg::kDebug) << "\t" << plane->GetPlaneNumber() <<endl;
00271 //        }
00272 //        validPlaneItr.Reset();
00273 
00274       //slice to those planes from the vertex on
00275       planeItr.GetSet()->Slice(status->GetVertexPlaneNumber(), status->GetEndPlaneNumber());
00276       planeItr.GetSet()->Update();
00277 
00278       validPlaneItr.GetSet()->Slice(status->GetVertexPlaneNumber(), status->GetEndPlaneNumber());
00279       validPlaneItr.GetSet()->Update();
00280 
00281       windowPlaneItr.GetSet()->Slice(status->GetVertexPlaneNumber(), status->GetEndPlaneNumber());
00282       windowPlaneItr.GetSet()->Update();
00283       
00284       //if only 2 planes set them to their best hyps
00285       if(validPlaneItr.SizeSelect() == 2){
00286         validPlaneItr.ResetFirst();
00287 
00288         //variables for straight line fit
00289         Float_t cogBeg = -1., zBeg = -1., cogEnd = -1., zEnd = -1.;
00290 
00291         while( validPlaneItr.IsValid() ){
00292           
00293           //only set it if it is a shower plane, muon planes are set in the constructor
00294           if(validPlaneItr.Ptr()->GetPlaneType() == DmxPlaneTypes::kShower
00295              && !validPlaneItr.Ptr()->IsGolden())
00296             dynamic_cast<DmxShowerPlane *>(validPlaneItr.Ptr())->SetStrips("best");
00297 
00298           //cout << dynamic_cast<DmxPlane *>(validPlaneItr.Ptr())->GetCoG() << "\t" 
00299           //   << dynamic_cast<DmxPlane *>(validPlaneItr.Ptr())->GetPlaneNumber() 
00300           //   << "\t" << dynamic_cast<DmxPlane *>(validPlaneItr.Ptr())->GetZPosition() << endl;
00301           
00302           //set the variables for the straighe line fit between the two planes
00303           if(cogBeg == -1.){
00304             cogBeg = validPlaneItr.Ptr()->GetCoG();
00305             zBeg = validPlaneItr.Ptr()->GetZPosition();
00306           }
00307           else{
00308             cogEnd = validPlaneItr.Ptr()->GetCoG();
00309             zEnd = validPlaneItr.Ptr()->GetZPosition();
00310           }
00311           
00312           validPlaneItr.Next();
00313         }//end loop over planes
00314         
00315         //set the nonvalid planes if they exist
00316         if(planeItr.SizeSelect()>2 && cogEnd-cogBeg != 0. && cogBeg != -1. && cogEnd != -1.){
00317           Double_t slope = (cogEnd-cogBeg)/(zEnd - zBeg);
00318           Double_t intercept = cogBeg - slope*zBeg;
00319           //cout << slope << "\t" << intercept << endl;
00320           SetPlanesToDeterminedFit(planeItr, intercept, slope);
00321           fStrayPlanes += util.FindPlanesOffFit(planeItr, fStrayCut);
00322         }
00323 
00324         //fStrayPlanes -= util.CheckFit(validPlaneItr);
00325         validPlaneItr.ResetFirst();
00326 
00327       }//end if only 2 valid planes
00328       else if(validPlaneItr.SizeSelect() >2 ){
00329 
00330         //if there are only enough planes for 1 instances of the sliding window + initial fit,
00331         //change fPlanesInSet to give you 3 + the initial fit, but at least 4 always
00332         if(validPlaneItr.SizeSelect() == (fPlanesInSet+1) && fPlanesInSet==6) fPlanesInSet -= 2;
00333         else if(validPlaneItr.SizeSelect() == (fPlanesInSet+1) 
00334                 && fPlanesInSet==5) fPlanesInSet -= 1;
00335 
00336         if(validPlaneItr.SizeSelect() > fPlanesInSet ){
00337           UseSlidingWindow(planeItr, validPlaneItr, windowPlaneItr, status, 
00338                            status->GetVertexPlaneNumber(),
00339                            status->GetEndPlaneNumber());        
00340         }
00341         else if(validPlaneItr.SizeSelect() <= fPlanesInSet){
00342           UseSingleFit(planeItr, validPlaneItr, status);
00343         }
00344         
00345         //check the end points of the event - send the validPlaneItr to the function
00346         //fStrayPlanes -= util.CheckFit(validPlaneItr);
00347         
00348         //what about multiple muons?  look for another vertex after the end plane
00349         planeItr.GetSet()->ClearSlice(false);
00350         validPlaneItr.GetSet()->ClearSlice(false);
00351         windowPlaneItr.GetSet()->ClearSlice(false);
00352         vertexPlaneItr.GetSet()->Slice(status->GetEndPlaneNumber()+1, 500);
00353         vertexPlaneItr.GetSet()->Update();
00354 
00355         //MSG("DMX1", Msg::kDebug)<< "event =  " << status->GetEventNumber() 
00356         //                   << "\tend plane = " << status->GetEndPlaneNumber() << endl;
00357         
00358         Int_t nextVertex = -1;
00359         if(vertexPlaneItr.SizeSelect() > 3){ nextVertex = util.FindVertexPlane(vertexPlaneItr);}
00360         
00361         while( nextVertex != -1){
00362           
00363           status->SetMultipleMuon(true); 
00364           cdlh.SetDeMuxDigitListFlagBit(CandDeMuxDigitList::kMultipleMuonEvent);
00365           vertexPlaneItr.GetSet()->ClearSlice(false);
00366           vertexPlaneItr.GetSet()->Slice(nextVertex, 500);
00367           vertexPlaneItr.GetSet()->Update();
00368           
00369           //get the next end plane
00370           Int_t endPlane = util.FindEndPlane(vertexPlaneItr);
00371 
00372           //MSG("DMX1", Msg::kDebug)<< "\tin double muon loop, vertex at plane " << nextVertex 
00373           //             << "\tend plane = " << endPlane << "\tplanes in slice = " 
00374           //             << vertexPlaneItr.SizeSelect() << endl;
00375           
00376           planeItr.GetSet()->Slice(nextVertex, endPlane);
00377           planeItr.GetSet()->Update();
00378           
00379           validPlaneItr.GetSet()->Slice(nextVertex, endPlane);
00380           validPlaneItr.GetSet()->Update();
00381           
00382           windowPlaneItr.GetSet()->Slice(nextVertex, endPlane);
00383           windowPlaneItr.GetSet()->Update();
00384                     
00385           //if only 2 planes set them to their best hyps
00386           if(validPlaneItr.SizeSelect() == 2){
00387             validPlaneItr.ResetFirst();
00388             
00389             //variables for straight line fit
00390             Float_t cogBeg = -1., zBeg = -1., cogEnd = -1., zEnd = -1.;
00391             
00392             while( validPlaneItr.IsValid() ){
00393               
00394               //only set it if it is a shower plane, muon planes are set in the constructor
00395               if(validPlaneItr.Ptr()->GetPlaneType() == DmxPlaneTypes::kShower
00396                  && !validPlaneItr.Ptr()->IsGolden())
00397                 dynamic_cast<DmxShowerPlane *>(validPlaneItr.Ptr())->SetStrips("best");
00398               
00399               //set the variables for the straighe line fit between the two planes
00400               if(cogBeg == -1.){
00401                 cogBeg = validPlaneItr.Ptr()->GetCoG();
00402                 zBeg = validPlaneItr.Ptr()->GetZPosition();
00403               }
00404               else{
00405                 cogEnd = validPlaneItr.Ptr()->GetCoG();
00406                 zEnd = validPlaneItr.Ptr()->GetZPosition();
00407               }
00408               
00409               validPlaneItr.Next();
00410             }//end loop over planes
00411             
00412             if(planeItr.SizeSelect()>2 && cogEnd-cogBeg != 0. && cogBeg != -1. && cogEnd != -1.){
00413               Double_t slope = (cogEnd-cogBeg)/(zEnd - zBeg);
00414               Double_t intercept = cogBeg - slope*zBeg;
00415               SetPlanesToDeterminedFit(planeItr, intercept, slope);
00416               fStrayPlanes += util.FindPlanesOffFit(planeItr, fStrayCut);
00417             }
00418             
00419             //fStrayPlanes -= util.CheckFit(validPlaneItr);
00420             validPlaneItr.ResetFirst();
00421             
00422           }//end if only 2 valid planes
00423           else if(validPlaneItr.SizeSelect() > 2){
00424             //if there are only enough planes for 1 instances of the sliding window + initial fit,
00425             //change fPlanesInSet to give you 3 + the initial fit
00426             if(validPlaneItr.SizeSelect() == (fPlanesInSet+1) && fPlanesInSet==6) fPlanesInSet -= 2;
00427             else if(validPlaneItr.SizeSelect() == (fPlanesInSet+1) 
00428                     && fPlanesInSet==5) fPlanesInSet -= 1;
00429                     
00430             if(validPlaneItr.SizeSelect() > fPlanesInSet ){
00431               UseSlidingWindow(planeItr, validPlaneItr, windowPlaneItr, status, 
00432                                nextVertex, endPlane);   
00433             }
00434             else if(validPlaneItr.SizeSelect() <= fPlanesInSet ){
00435               UseSingleFit(planeItr, validPlaneItr, status);
00436             }
00437           }//end if more than 2 valid planes in event
00438 
00439           //check the end points of the event - send the validPlaneItr to the function
00440           //fStrayPlanes -= util.CheckFit(validPlaneItr);
00441 
00442           //look for another vertex after the end plane
00443           planeItr.GetSet()->ClearSlice(false);
00444           validPlaneItr.GetSet()->ClearSlice(false);
00445           windowPlaneItr.GetSet()->ClearSlice(false);
00446           vertexPlaneItr.GetSet()->ClearSlice(false);
00447 
00448           vertexPlaneItr.GetSet()->Slice(endPlane+1, 500);
00449           vertexPlaneItr.GetSet()->Update();
00450 
00451           //MSG("DMX1", Msg::kDebug)<< "\tlook for new vertex, slice from " << endPlane+1 
00452           //             << "\tto plane 500, planes in slice = " 
00453           //             << vertexPlaneItr.SizeSelect() << endl;
00454           
00455           vertexPlaneItr.Reset();
00456           
00457           if(vertexPlaneItr.SizeSelect() > 0){
00458             nextVertex = util.FindVertexPlane(vertexPlaneItr);
00459           }
00460           else{ nextVertex = -1; }
00461         }//end loop to find next vertex for spread out multiples
00462       }//end if more than 2 valid planes in set
00463       else if(validPlaneItr.SizeSelect() < 2){ 
00464         MSG("DMX", Msg::kDebug)<< "Event " << status->GetEventNumber() 
00465                                << " not demuxed; only " 
00466                                << validPlaneItr.SizeSelect() 
00467                                << " valid planes in view" << endl;
00468 
00469         status->SetValidPlanesFailure(true); 
00470         cdlh.SetDeMuxDigitListFlagBit(CandDeMuxDigitList::kTooFewValidPlanes);
00471       } //not enough planes to demux
00472 
00473       //done using the first view, so clear the selection function
00474       //MSG("Dmx", Msg::kDebug) <<"Done with View " << viewCtr << endl;
00475       
00476       status->SetFigureOfMerit(validPlaneItr.SizeSelect(), fStrayPlanes);
00477       if(viewCtr == 0 && status->GetEventDeMuxed() ){ 
00478         status->SetUStrayPlanes(fStrayPlanes);
00479         status->SetUValidPlanes(validPlaneItr.SizeSelect());
00480         cdlh.SetNumValidPlanesU(validPlaneItr.SizeSelect());
00481         cdlh.SetNumStrayPlanesU(fStrayPlanes);
00482         if( status->GetFigureOfMeritFailure() ){
00483           //see if the event failed the figure of Merit test, if so, see if it is an 
00484           //overlapping muon
00485           cdlh.SetDeMuxDigitListFlagBit(CandDeMuxDigitList::kEventFailedFilter);
00486           if(util.IsOverlappingMultiple(validPlaneItr, 1.*status->GetVertexPlaneNumber(), 
00487                                         acd.GetDouble("HoughInterceptRMSLimit"), 
00488                                         acd.GetDouble("HoughSlopeRMSLimit"),
00489                                         acd.GetDouble("HoughPeakLimit"))){
00490             status->SetUOverlappingMultiple(true);
00491             cdlh.SetDeMuxDigitListFlagBit(CandDeMuxDigitList::kMultipleMuonEvent);
00492           }
00493         }
00494       }
00495       if(viewCtr == 1 && status->GetEventDeMuxed() ){ 
00496         status->SetVStrayPlanes(fStrayPlanes);
00497         status->SetVValidPlanes(validPlaneItr.SizeSelect());
00498         cdlh.SetNumValidPlanesV(validPlaneItr.SizeSelect());
00499         cdlh.SetNumStrayPlanesV(fStrayPlanes);
00500         //see if the event failed the figure of Merit test, if so, see if it is an 
00501         //overlapping muon
00502         if( status->GetFigureOfMeritFailure() ){
00503           cdlh.SetDeMuxDigitListFlagBit(CandDeMuxDigitList::kEventFailedFilter);
00504           if(util.IsOverlappingMultiple(validPlaneItr, 1.*status->GetVertexPlaneNumber(), 
00505                                         acd.GetDouble("HoughInterceptRMSLimit"), 
00506                                         acd.GetDouble("HoughSlopeRMSLimit"),
00507                                         acd.GetDouble("HoughPeakLimit"))){
00508             status->SetVOverlappingMultiple(true);
00509             cdlh.SetDeMuxDigitListFlagBit(CandDeMuxDigitList::kMultipleMuonEvent);
00510           }
00511         }
00512       }
00513       vertexPlaneItr.GetSet()->ClearSlice(false);
00514       planeItr.GetSet()->ClearSlice(false);
00515       planeItr.GetSet()->AdoptSelectKeyFunc(0);
00516       planeItr.Reset();
00517       validPlaneItr.GetSet()->ClearSlice(false);
00518       validPlaneItr.GetSet()->AdoptSelectKeyFunc(0);
00519       validPlaneItr.Reset();
00520       windowPlaneItr.GetSet()->ClearSlice(false);
00521       windowPlaneItr.GetSet()->AdoptSelectKeyFunc(0);
00522       windowPlaneItr.Reset();
00523 
00524       ++viewCtr;
00525     } //end loop over views
00526 
00527     //if the event was demuxed, check to see how the demuxing and timing jive
00528     //otherwise see if you need to set the nonphysical solution flag
00529     if( status->GetEventDeMuxed() ){
00530       status->SetAverageTimingOffset(util.CheckFitWithTiming(validPlaneItr));
00531       cdlh.SetAvgTimeOffset(status->GetAverageTimingOffset());
00532     }
00533     else if(status->GetNonPhysicalFailure() )  
00534       cdlh.SetDeMuxDigitListFlagBit(CandDeMuxDigitList::kNonPhysicalStripSolution);
00535          
00536     
00537   }//end if there was a vertex
00538   else{ 
00539     status->SetNoVertexFailure(true);
00540     cdlh.SetDeMuxDigitListFlagBit(CandDeMuxDigitList::kNoVertex);
00541     MSG("DMX", Msg::kDebug) << "no vertex found for event " << status->GetEventNumber() << endl;
00542   }
00543 
00544   //get rid of the temporary status object if you made it.
00545   if(tempStatus) delete status;
00546 
00547   return;
00548 }

void AlgDeMuxCosmics::SetPlanesToDeterminedFit DmxPlaneItr &  planeItr,
Double_t  a,
Double_t  b
[private]
 

Definition at line 1751 of file AlgDeMuxCosmics.cxx.

References DmxPlane::GetZPosition(), DmxPlane::IsGolden(), and DmxPlane::SetStrips().

01752 {
01753 
01754   //MSG("DMXX", Msg::kDebug) << "in SetPlanesToDeterminedFit" << endl;
01755 
01756   planeItr.ResetFirst();
01757 
01758   DmxPlane *plane = 0;
01759 
01760   while( planeItr.IsValid() ){
01761 
01762     plane = planeItr.Ptr();
01763       
01764     //if(plane->GetPlaneNumber()>=firstPlane && plane->GetPlaneNumber()<=lastPlane){
01765     //MSG("DMXX", Msg::kDebug)<<"\tin SetPlanesToDeterminedFit " << plane->GetPlaneNumber() 
01766     //             <<" has golden flag " << (Int_t)plane->IsGolden() << endl;
01767     Float_t fitCoG = a + (plane->GetZPosition() * b);
01768     //MSG("DMXX", Msg::kDebug)<< a << "\t" << b << "\t" << fitCoG << endl;
01769     
01770     //golden planes have already been set in their constructors
01771     if( !plane->IsGolden() ){
01772       //MSG("DMXX", Msg::kDebug)<<"\tsetting plane " << plane->GetPlaneNumber() << endl;
01773       plane->SetStrips(fitCoG); 
01774     }
01775     //}//end if plane is in the window bounds
01776     
01777     planeItr.Next();
01778   }
01779 
01780   planeItr.Reset();
01781   
01782   return;
01783 }

void AlgDeMuxCosmics::SetPlanesToDeterminedFit DmxPlaneItr &  planeItr,
Double_t  a1,
Double_t  a2,
Double_t  a3,
Double_t  a4,
Float_t  offset
[private]
 

Definition at line 1708 of file AlgDeMuxCosmics.cxx.

References DmxPlane::GetZPosition(), DmxPlane::IsGolden(), and DmxPlane::SetStrips().

Referenced by RunAlg(), UseSingleFit(), and UseSlidingWindow().

01710 {
01711   //MSG("DMXX", Msg::kDebug) << "in SetPlanesToDeterminedFit" << endl;
01712 
01713   planeItr.ResetFirst();
01714 
01715   DmxPlane *plane = 0;
01716 
01717   while( planeItr.IsValid() ){
01718 
01719     plane = planeItr.Ptr();
01720     
01721     //MSG("DMXX", Msg::kDebug)<<"\tin SetPlanesToDeterminedFit " << plane->GetPlaneNumber() 
01722     //             <<" has golden flag " << (Int_t)plane->IsGolden() << endl;
01723     
01724     Float_t fitCoG = (a1 + (plane->GetZPosition()-offset)*a2 
01725                       + TMath::Power(plane->GetZPosition()-offset,2)*a3
01726                       + TMath::Power(plane->GetZPosition()-offset,3)*a4);
01727 
01728     //MSG("DMXX", Msg::kDebug)<< a1 << "\t" << a2 << "\t" << a3 
01729     //             << "\t" << a4 << "\t" << fitCoG 
01730     //             << "\t" << plane->GetZPosition() << endl;
01731     
01732     //golden planes have already been set in their constructors
01733     if( !plane->IsGolden() ){
01734       //MSG("DMXX", Msg::kDebug)<<"\tsetting plane " << plane->GetPlaneNumber() 
01735       //                     << " to " << fitCoG << endl;
01736       plane->SetStrips(fitCoG); 
01737     }
01738         
01739     planeItr.Next();
01740   }
01741 
01742   planeItr.Reset();
01743   
01744   //cout << "finished set planes for fit" << endl;
01745   return;
01746 }

void AlgDeMuxCosmics::Trace const char *  c  )  const [virtual]
 

Reimplemented from AlgBase.

Definition at line 551 of file AlgDeMuxCosmics.cxx.

00552 {
00553 }

void AlgDeMuxCosmics::UseSingleFit DmxPlaneItr &  planeItr,
DmxPlaneItr &  validPlaneItr,
DmxStatus status
[private]
 

Definition at line 1087 of file AlgDeMuxCosmics.cxx.

References FindCosmicSolution(), DmxUtilities::FindPlanesOffFit(), fStrayCut, fStrayPlanes, DmxPlane::GetCoG(), DmxStatus::GetEventNumber(), DmxPlane::GetZPosition(), DmxPlane::IsGolden(), MSG, DmxStatus::SetEventDirection(), DmxPlane::SetGolden(), DmxStatus::SetNonPhysicalFailure(), and SetPlanesToDeterminedFit().

Referenced by RunAlg().

01089 {
01090   //MSG("DMXX", Msg::kDebug) << "in UseSingleFit" << endl;
01091 
01092   DmxUtilities util = DmxUtilities();
01093   
01094   Double_t a1F = -10000.;
01095   Double_t a2F = -10000.;
01096   Double_t a3F = -10000.;
01097   Double_t a4F = -10000.;
01098   Double_t chiSqF = 1.1e20;
01099   Double_t a1B = -10000.;
01100   Double_t a2B = -10000.;
01101   Double_t a3B = -10000.;
01102   Double_t a4B = -10000.;
01103   Double_t chiSqB = 1.1e20;
01104  
01105   validPlaneItr.ResetFirst();
01106   Float_t offset = validPlaneItr.Ptr()->GetZPosition();
01107   validPlaneItr.ResetLast();
01108   //set the event direction forwards
01109   status->SetEventDirection(1);
01110   
01111   //cout << "calling FindCosmicSolution" << endl;
01112   FindCosmicSolution(planeItr, validPlaneItr, status, a1F, a2F, a3F, a4F, chiSqF, offset);
01113   
01114   //set the event direction to backwards
01115   status->SetEventDirection(-1);
01116   
01117   FindCosmicSolution(planeItr, validPlaneItr, status, a1B, a2B, a3B, a4B, chiSqB, offset);
01118   
01119   DmxPlane *plane = 0;
01120   if( chiSqF <= chiSqB && a1F != -10000. && a2F != -10000. 
01121       && a3F != -10000. && a4F != 10000.){
01122     
01123     //loop over the planes and if a golden plane cog is more than 0.25m off from the fit
01124     //set it as non-golden.
01125     validPlaneItr.Reset();
01126 
01127     while( (plane = planeItr()) ){
01128       Double_t fitCoG = (a1F + a2F*plane->GetZPosition() 
01129                          + a3F*TMath::Power(plane->GetZPosition(),2) 
01130                          + a4F*TMath::Power(plane->GetZPosition(),3));
01131       if(plane->IsGolden() && TMath::Abs(plane->GetCoG()-fitCoG)>0.25) plane->SetGolden(false);
01132     }
01133 
01134     SetPlanesToDeterminedFit(planeItr, a1F, a2F, a3F, a4F, offset); 
01135    
01136     fStrayPlanes += util.FindPlanesOffFit(planeItr, fStrayCut);
01137   }
01138   else if(chiSqB < chiSqF && a1B != -10000. && a2B != -10000. 
01139           && a3B != 10000. && a4B != 10000.){
01140    
01141     //loop over the planes and if a golden plane cog is more than 0.25m off from the fit
01142     //set it as non-golden.
01143     validPlaneItr.Reset();
01144   
01145     while( (plane = planeItr()) ){
01146       Double_t fitCoG = (a1B + a2B*plane->GetZPosition() 
01147                          + a3B*TMath::Power(plane->GetZPosition(),2) 
01148                          + a4B*TMath::Power(plane->GetZPosition(),3));
01149       if(plane->IsGolden() && TMath::Abs(plane->GetCoG()-fitCoG)>0.25) plane->SetGolden(false);
01150     }
01151 
01152     SetPlanesToDeterminedFit(planeItr, a1B, a2B, a3B, a4B, offset); 
01153     
01154     fStrayPlanes += util.FindPlanesOffFit(planeItr, fStrayCut);
01155 }
01156   else if( a1B == -10000. && a2B == -10000. && a3B != 10000. && a4B != 10000.
01157            && a1F == -10000. && a2F == -10000. && a3F != -10000. && a4F != 10000.){
01158     
01159     MSG("DMX", Msg::kDebug)<< "Event " << status->GetEventNumber() 
01160                            << " not demuxed; can't find a physical solution" 
01161                            << endl;
01162     status->SetNonPhysicalFailure(true); 
01163   }
01164   
01165   
01166   return;
01167 }

void AlgDeMuxCosmics::UseSlidingWindow DmxPlaneItr &  planeItr,
DmxPlaneItr &  validPlaneItr,
DmxPlaneItr &  windowPlaneItr,
DmxStatus status,
Int_t  vertex,
Int_t  endPlane
[private]
 

Definition at line 1171 of file AlgDeMuxCosmics.cxx.

References FindCosmicSolution(), DmxUtilities::FindPlanesOffFit(), FindWindowCosmicSolution(), fPlanesInSet, fStrayCut, fStrayPlanes, DmxPlane::GetCoG(), DmxStatus::GetEventNumber(), DmxPlane::GetPlaneNumber(), DmxStatus::GetVertexZPosition(), DmxPlane::GetZPosition(), DmxPlane::IsGolden(), MSG, DmxStatus::SetEventDirection(), DmxPlane::SetGolden(), DmxStatus::SetNonPhysicalFailure(), and SetPlanesToDeterminedFit().

Referenced by RunAlg().

01174 {
01175   //MSG("DMXX", Msg::kDebug) << "in UseSlidingWindow" << endl;
01176 
01177   //start the sliding window - keep the window to 6 valid planes 
01178   //and use the fit parameters you found for the previous set.  if the 
01179   //new plane is a shower plane, set to the hypothesis nearest the fit.  
01180   //if none of the 3 best hypotheses is within 12 strips of the fit, then
01181   //just use the same fit parameters.  redo the fit, and then set all 
01182   //non-set planes in the window. move the the window down another plane 
01183   //and do it again.
01184 
01185   DmxUtilities util;
01186 
01187   UInt_t validPlaneCnt = validPlaneItr.SizeSelect();
01188   UInt_t loopCtr = 0;
01189   UInt_t ctr = 0;
01190   Int_t firstPlane = 0;
01191   Int_t almostLastPlane = 0;
01192   Int_t lastPlane = 0;
01193   Double_t a1 = -10000.;
01194   Double_t a2 = -10000.;
01195   Double_t a3 = -10000.;
01196   Double_t a4 = -10000.;
01197   Double_t chiSq = 1.1e20;
01198   Float_t offset = 0.;
01199   DmxPlane *plane = 0;
01200   Int_t direction = 1;  //status->GetEventDirection();
01201 
01202   // MSG("dmx", Msg::kDebug) << "Event = " << status->GetEventNumber() << "\tvertex = " << vertex 
01203 //               << "\tend = " << endPlane << endl;
01204 //   while(validPlaneItr.IsValid() ){
01205 //     MSG("dmx", Msg::kDebug) << "\t" << dynamic_cast<DmxPlane *>(validPlaneItr.Ptr())->GetPlaneNumber()
01206 //                         << "\t" << dynamic_cast<DmxPlane *>(validPlaneItr.Ptr())->IsGolden()
01207 //                         <<endl;
01208 //     validPlaneItr.Next();
01209 //   }
01210 
01211   validPlaneItr.ResetFirst();
01212   windowPlaneItr.ResetFirst();
01213 
01214   //now demux the event the <= makes sure that you find an initial fit for the first
01215   //set of planes, then go from there
01216   while(loopCtr <= (validPlaneCnt - fPlanesInSet) ){
01217 
01218       ctr = 0;
01219       
01220       //MSG("dmx", Msg::kDebug) << "find new window" << endl;
01221       //MSG("dmx", Msg::kDebug) << "\tdirection = " << direction;
01222 
01223       while( validPlaneItr.IsValid() && ctr < fPlanesInSet){
01224         
01225         plane = validPlaneItr.Ptr();
01226         //MSG("dmx", Msg::kDebug) << "plane number = " << plane->GetPlaneNumber()
01227         //             << endl;
01228         
01229         if(direction == 1){ 
01230           if( ctr == 0){ 
01231             firstPlane = plane->GetPlaneNumber(); 
01232             offset = plane->GetZPosition();
01233           }
01234           if( ctr == fPlanesInSet-2){ almostLastPlane = plane->GetPlaneNumber(); }
01235           if( ctr == fPlanesInSet-1){ lastPlane = plane->GetPlaneNumber(); }
01236           validPlaneItr.Next();
01237         }
01238         else if(direction == -1){ 
01239           if( ctr == 0){ lastPlane = plane->GetPlaneNumber(); }
01240           if( ctr == fPlanesInSet-2){ almostLastPlane = plane->GetPlaneNumber(); }
01241           if( ctr == fPlanesInSet-1){ 
01242             firstPlane = plane->GetPlaneNumber(); 
01243             offset = plane->GetZPosition();
01244           }
01245           validPlaneItr.Prev();
01246         }
01247         ++ctr;
01248         
01249       }
01250 
01251       //MSG("dmx", Msg::kDebug) << "end find new window" << endl;
01252       ctr = 0;
01253             
01254       //MSG("dmx", Msg::kDebug) << "\tfirst plane = " << firstPlane << "\talmost last plane = " 
01255       //                     << almostLastPlane << "\tlast plane = " << lastPlane << endl;
01256       
01257       //move the window
01258       windowPlaneItr.GetSet()->ClearSlice(false);
01259       planeItr.GetSet()->ClearSlice(false);
01260 
01261       windowPlaneItr.GetSet()->Slice(firstPlane, lastPlane);
01262       windowPlaneItr.GetSet()->Update();
01263       planeItr.GetSet()->Slice(firstPlane, lastPlane);
01264       planeItr.GetSet()->Update();
01265 
01266       if( loopCtr == 0){
01267         
01268         //set the initial window - try it both ways and take the best one as
01269         //determined by the chiSq
01270         Double_t a1B = -10000.;
01271         Double_t a2B = -10000.;
01272         Double_t a3B = -10000.;
01273         Double_t a4B = -10000.;
01274         Double_t chiSqB = 1.1e20;
01275         
01276         //set the event direction forwards
01277         status->SetEventDirection(1);
01278 
01279         //you are looking at the first planes of the event, so your offset should be the
01280         //z position of the vertex
01281         Float_t offsetF = status->GetVertexZPosition();
01282 
01283         FindCosmicSolution(planeItr, windowPlaneItr, status, a1, a2, a3, a4, chiSq, offsetF);
01284 
01285         //MSG("dmx", Msg::kDebug) << "\tforward direction" << a1 << "\t" << a2 
01286         //             << "\t" << chiSq << "\t" << offset << endl;
01287         
01288         //set the event direction to backwards
01289         Int_t forwardLastPlane = lastPlane;
01290 
01291         status->SetEventDirection(-1);
01292         direction = -1;
01293         validPlaneItr.ResetLast();
01294         windowPlaneItr.GetSet()->ClearSlice(false);
01295         planeItr.GetSet()->ClearSlice(false);
01296         windowPlaneItr.ResetLast();
01297         ctr = 0;
01298         
01299         //MSG("dmx", Msg::kDebug) << "check reverse direction" << endl;
01300         while( validPlaneItr.IsValid() && ctr < fPlanesInSet){
01301 
01302           plane = validPlaneItr.Ptr();
01303           // MSG("dmx", Msg::kDebug) << "plane number = " << plane->GetPlaneNumber()
01304           //              << endl;
01305           
01306           if( ctr == 0){ lastPlane = plane->GetPlaneNumber(); }
01307           if( ctr == fPlanesInSet-2){ almostLastPlane = plane->GetPlaneNumber(); }
01308           if( ctr == fPlanesInSet-1){ 
01309             firstPlane = plane->GetPlaneNumber(); 
01310             offset = plane->GetZPosition();
01311           }
01312           ++ctr;
01313           validPlaneItr.Prev();
01314         }
01315         //MSG("dmx", Msg::kDebug) << "end check reverse direction" << endl;
01316         ctr = 0;
01317         
01318         //MSG("dmx", Msg::kDebug) << "first plane = " << firstPlane << "\talmost last plane = " 
01319         //              << almostLastPlane << "\tlast plane = " << lastPlane << endl;
01320                 
01321         windowPlaneItr.GetSet()->Slice(firstPlane, lastPlane);
01322         windowPlaneItr.GetSet()->Update();
01323         windowPlaneItr.ResetLast();
01324         planeItr.GetSet()->Slice(firstPlane, lastPlane);
01325         planeItr.GetSet()->Update();
01326 
01327         FindCosmicSolution(planeItr, windowPlaneItr, status, a1B, a2B, a3B, a4B, chiSqB, offset);
01328         
01329         //MSG("dmx", Msg::kDebug) << "\tbackward direction" << a1B << "\t" << a2B 
01330         //             << "\t" << chiSqB << "\t" << offset << endl;
01331         
01332         if( chiSq <= chiSqB && a1 != -10000. && a2 != -10000. && a3 != 10000. && a4 != 10000.){
01333           planeItr.GetSet()->ClearSlice(false);
01334 
01335           //slice from the vertex to the last plane in the forward direction to get them
01336           //all
01337           planeItr.GetSet()->Slice(vertex, forwardLastPlane);
01338           planeItr.GetSet()->Update();
01339 
01340           //loop over the planes and if a golden plane cog is more than 0.25m off from the fit
01341           //set it as non-golden.
01342           windowPlaneItr.GetSet()->ClearSlice(false);
01343           windowPlaneItr.GetSet()->Slice(vertex, forwardLastPlane);
01344           windowPlaneItr.GetSet()->Update();
01345 
01346           while( (plane = windowPlaneItr()) ){
01347             Double_t fitCoG = (a1 + a2*plane->GetZPosition() 
01348                                + a3*TMath::Power(plane->GetZPosition(),2) 
01349                                + a4*TMath::Power(plane->GetZPosition(),3));
01350             if(plane->IsGolden() && TMath::Abs(plane->GetCoG()-fitCoG)>0.25) plane->SetGolden(false);
01351           }
01352 
01353           //MSG("dmx", Msg::kDebug) << "\tloop = " << loopCtr << "\tsetting planes " << vertex 
01354           //     << "\tto " << forwardLastPlane << endl;
01355 
01356           SetPlanesToDeterminedFit(planeItr, a1, a2, a3, a4, offsetF); 
01357 
01358           fStrayPlanes += util.FindPlanesOffFit(planeItr, fStrayCut);
01359             
01360           status->SetEventDirection(1);
01361           direction = 1;
01362           validPlaneItr.ResetFirst();
01363           ctr = 0;
01364           
01365           //get the validPlaneItr back to where it should be for this direction
01366           while(ctr<fPlanesInSet){
01367             validPlaneItr.Next();
01368             ++ctr;
01369           }
01370           
01371           ctr = 0;
01372           
01373         }           
01374         else if(chiSqB < chiSq && a1B != -10000. && a2B != -10000. && a3B != 10000. && a4B != 10000.){
01375           
01376           //set a, b, and chiSq to the backwards values
01377           a1 = a1B;
01378           a2 = a2B;
01379           a3 = a3B;
01380           a4 = a4B;
01381           chiSq = chiSqB;
01382 
01383           //slice from the end plane to the first plane
01384           planeItr.GetSet()->ClearSlice(false);
01385           planeItr.GetSet()->Slice(firstPlane, endPlane);
01386           planeItr.GetSet()->Update();
01387 
01388           //loop over the planes and if a golden plane cog is more than 0.25m off from the fit
01389           //set it as non-golden.
01390           windowPlaneItr.ResetFirst();
01391           while( (plane = windowPlaneItr()) ){
01392             Double_t fitCoG = (a1 + a2*plane->GetZPosition() 
01393                                + a3*TMath::Power(plane->GetZPosition(),2) 
01394                                + a4*TMath::Power(plane->GetZPosition(),3));
01395             if(plane->IsGolden() && TMath::Abs(plane->GetCoG()-fitCoG)>0.25) plane->SetGolden(false);
01396           }
01397           //MSG("dmx", Msg::kDebug) << "\tloop = " << loopCtr << "\tsetting planes " << firstPlane 
01398           //             << "\tto " << endPlane << endl;
01399 
01400           SetPlanesToDeterminedFit(planeItr, a1, a2, a3, a4, offset);
01401 
01402           fStrayPlanes += util.FindPlanesOffFit(planeItr, fStrayCut);
01403 
01404           //event direction is already backwards and the validPlaneItr is where it should be
01405         }
01406         else if( a1B == -10000. && a2B == -10000. && a1 == -10000. 
01407                  && a2 == -10000. && a3 == -10000. && a4 == -10000. 
01408                  && a3B == -10000. && a4B == -10000.){
01409            
01410           MSG("dmx", Msg::kDebug)<< "Event " << status->GetEventNumber() 
01411                                  << " not demuxed;" 
01412                                  << " can't find a physical solution" << endl;
01413           status->SetNonPhysicalFailure(true);
01414         }
01415         //MSG("dmx", Msg::kDebug) << "\tloop 0 fit - " << a1 << "\t" << a2 << "\t" << a3 << "\tchi^2 = " 
01416         //             << chiSq << "\tstray planes = " << fStrayPlanes << endl;
01417       }//end if initial set
01418       else{
01419         //set the window
01420         
01421         FindWindowCosmicSolution(windowPlaneItr, status, a1, a2, a3, a4, chiSq, offset);
01422 
01423         //MSG("dmx", Msg::kDebug) << "\tloop " << loopCtr << " " << firstPlane << " " << lastPlane 
01424         //             << "\t" << a1 << "\t" << a2 << "\t" << a3 << "\tchi^2 = " 
01425         //             << chiSq << "\tstray planes = " << fStrayPlanes << endl;
01426         
01427         planeItr.GetSet()->ClearSlice(false);
01428         if(direction == 1 ){
01429           firstPlane = almostLastPlane + 1;
01430           //if its the last loop, select the rest of the unset planes to set, otherwise
01431           //stay in the loop bounds
01432           if(loopCtr == (validPlaneItr.SizeSelect()-fPlanesInSet)) lastPlane = endPlane;
01433         }
01434         else if(direction == -1 ){
01435           lastPlane = almostLastPlane-1;
01436           if(loopCtr == (validPlaneItr.SizeSelect()-fPlanesInSet)) firstPlane = vertex;
01437         }
01438         planeItr.GetSet()->Slice(firstPlane, lastPlane);
01439         planeItr.GetSet()->Update();
01440 
01441         //MSG("dmx", Msg::kDebug) << "\tloop = " << loopCtr << "\tsetting planes " << firstPlane 
01442         //             << "\tto " << lastPlane << endl;
01443         
01444         SetPlanesToDeterminedFit(planeItr, a1, a2, a3, a4, offset);
01445         fStrayPlanes += util.FindPlanesOffFit(planeItr,  fStrayCut);
01446         //status->SetHistogramEntries(b, a, plane->GetPlaneView());
01447       }
01448 
01449 
01450       ctr = 0;
01451 
01452       //set the validPlaneItr to the opposite direction and back up 5 planes
01453       //MSG("dmx", Msg::kDebug) << "move iterator to first plane in new window" << endl;
01454       while(ctr<fPlanesInSet-1 && validPlaneItr.IsValid()){
01455         
01456         //MSG("dmx", Msg::kDebug) << "plane number = " 
01457         //             << dynamic_cast<DmxPlane *>(validPlaneItr.Ptr())->GetPlaneNumber()
01458         //             << endl;
01459         ++ctr;
01460         if(direction == 1){ validPlaneItr.Prev(); }
01461         else if(direction == -1){ validPlaneItr.Next(); }
01462       }
01463       //MSG("dmx", Msg::kDebug) << "end move iterator to first plane in new window" << endl;
01464       ctr = 0;
01465  
01466       //should go through the loop and get the new window
01467       ++loopCtr;
01468   }
01469 
01470   return;
01471 }


Member Data Documentation

UInt_t AlgDeMuxCosmics::fPlanesInSet [private]
 

Definition at line 40 of file AlgDeMuxCosmics.h.

Referenced by RunAlg(), and UseSlidingWindow().

Double_t AlgDeMuxCosmics::fRequiredMatedSignalRatio [private]
 

Definition at line 37 of file AlgDeMuxCosmics.h.

Referenced by RunAlg().

Double_t AlgDeMuxCosmics::fSlopeRMS [private]
 

Definition at line 38 of file AlgDeMuxCosmics.h.

Referenced by RunAlg().

Int_t AlgDeMuxCosmics::fStrayCut [private]
 

Definition at line 41 of file AlgDeMuxCosmics.h.

Referenced by RunAlg(), UseSingleFit(), and UseSlidingWindow().

Int_t AlgDeMuxCosmics::fStrayPlanes [private]
 

Definition at line 39 of file AlgDeMuxCosmics.h.

Referenced by RunAlg(), UseSingleFit(), and UseSlidingWindow().


The documentation for this class was generated from the following files:
Generated on Thu Nov 1 15:55:23 2007 for loon by  doxygen 1.3.9.1