CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/Fireworks/Muons/src/SegmentUtils.cc

Go to the documentation of this file.
00001 #include "Fireworks/Muons/interface/SegmentUtils.h"
00002 #include "Fireworks/Core/interface/fwLog.h"
00003 
00004 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00005 
00006 #include <math.h>
00007 
00008 namespace fireworks
00009 {
00010   void createSegment( int detector, 
00011                       bool matchedSegment,
00012                       float segmentLength,
00013                       float segmentLimit,
00014                       float* segmentPosition,   
00015                       float* segmentDirection,
00016                       float* segmentInnerPoint, 
00017                       float* segmentOuterPoint )
00018   {
00019     if( detector == MuonSubdetId::CSC )
00020     {
00021       if( matchedSegment )
00022       {
00023         segmentOuterPoint[0] = segmentPosition[0] + segmentLength*segmentDirection[0];
00024         segmentOuterPoint[1] = segmentPosition[1] + segmentLength*segmentDirection[1];
00025         segmentOuterPoint[2] = segmentLength;
00026 
00027         if( fabs(segmentOuterPoint[1]) > segmentLimit )
00028           segmentOuterPoint[1] = segmentLimit * ( segmentOuterPoint[1] / fabs( segmentOuterPoint[1] ));
00029 
00030         segmentInnerPoint[0] = segmentPosition[0] - segmentLength*segmentDirection[0];
00031         segmentInnerPoint[1] = segmentPosition[1] - segmentLength*segmentDirection[1];
00032         segmentInnerPoint[2] = -segmentLength;
00033 
00034         if( fabs(segmentInnerPoint[1]) > segmentLimit )
00035           segmentInnerPoint[1] = segmentLimit * ( segmentInnerPoint[1] / fabs( segmentInnerPoint[1] ));
00036 
00037         return;
00038       }     
00039       else 
00040       {
00041         segmentOuterPoint[0] = segmentPosition[0] + segmentDirection[0] * ( segmentPosition[2] / segmentDirection[2] );
00042         segmentOuterPoint[1] = segmentPosition[1] + segmentDirection[1] * ( segmentPosition[2] / segmentDirection[2] );
00043         segmentOuterPoint[2] = segmentPosition[2];
00044 
00045         if( fabs( segmentOuterPoint[1] ) > segmentLength )
00046           segmentOuterPoint[1] = segmentLength * ( segmentOuterPoint[1]/fabs( segmentOuterPoint[1] ));
00047 
00048         segmentInnerPoint[0] = segmentPosition[0] - segmentDirection[0] * ( segmentPosition[2] / segmentDirection[2] );
00049         segmentInnerPoint[1] = segmentPosition[1] - segmentDirection[1] * ( segmentPosition[2] / segmentDirection[2] );
00050         segmentInnerPoint[2] = -segmentPosition[2];
00051 
00052         if( fabs( segmentInnerPoint[1] ) > segmentLength )
00053           segmentInnerPoint[1] = segmentLength * ( segmentInnerPoint[1] / fabs( segmentInnerPoint[1] ));
00054       
00055         return;
00056       }
00057     }
00058     
00059     if ( detector == MuonSubdetId::DT )
00060     {
00061       if( matchedSegment )
00062       {
00063         segmentOuterPoint[0] = segmentPosition[0] + segmentLength*segmentDirection[0];
00064         segmentOuterPoint[1] = segmentPosition[1] + segmentLength*segmentDirection[1];
00065         segmentOuterPoint[2] = segmentLength;
00066 
00067         segmentInnerPoint[0] = segmentPosition[0] - segmentLength*segmentDirection[0];
00068         segmentInnerPoint[1] = segmentPosition[1] - segmentLength*segmentDirection[1];
00069         segmentInnerPoint[2] = -segmentLength;
00070          
00071         return;
00072       }
00073       else
00074       {
00075         double mag = sqrt( segmentDirection[0] * segmentDirection[0] + 
00076                            segmentDirection[1] * segmentDirection[1] +
00077                            segmentDirection[2] * segmentDirection[2] );
00078       
00079         double theta = atan2( sqrt( segmentDirection[0] * segmentDirection[0]
00080                                   + segmentDirection[1] * segmentDirection[1] ), segmentDirection[2] );
00081 
00082         double newSegmentLength = segmentLength / cos( theta );
00083 
00084         segmentInnerPoint[0] = segmentPosition[0] + ( segmentDirection[0] / mag ) * newSegmentLength;
00085         segmentInnerPoint[1] = segmentPosition[1] + ( segmentDirection[1] / mag ) * newSegmentLength;
00086         segmentInnerPoint[2] = segmentPosition[2] + ( segmentDirection[2] / mag ) * newSegmentLength;
00087         
00088         segmentOuterPoint[0] = segmentPosition[0] - ( segmentDirection[0] / mag ) * newSegmentLength;
00089         segmentOuterPoint[1] = segmentPosition[1] - ( segmentDirection[1] / mag ) * newSegmentLength;
00090         segmentOuterPoint[2] = segmentPosition[2] - ( segmentDirection[2] / mag ) * newSegmentLength;
00091         
00092         if( fabs(segmentOuterPoint[0]) > segmentLimit )
00093         {         
00094           segmentOuterPoint[0] = segmentLimit * ( segmentOuterPoint[0]/fabs( segmentOuterPoint[0] ));
00095           segmentOuterPoint[1] = ( segmentOuterPoint[1]/fabs( segmentOuterPoint[1] )) * tan( theta );
00096         }
00097         
00098         return;
00099       }  
00100     }
00101     
00102     fwLog( fwlog::kWarning ) << "MuonSubdetId: " << detector << std::endl;
00103     return;
00104   }
00105   
00106 
00107 }