Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

CalMipValsTool.cxx

Go to the documentation of this file.
00001     
00009 // Include files
00010 
00011 
00012 #include "ValBase.h"
00013 
00014 #include "GaudiKernel/MsgStream.h"
00015 #include "GaudiKernel/IDataProviderSvc.h"
00016 #include "GaudiKernel/SmartDataPtr.h"
00017 #include "GaudiKernel/ToolFactory.h"
00018 #include "GaudiKernel/IToolSvc.h"
00019 
00020 #include "Event/TopLevel/EventModel.h"
00021 #include "Event/TopLevel/Event.h"
00022 
00023 #include "Event/Recon/TkrRecon/TkrCluster.h"
00024 #include "Event/Recon/TkrRecon/TkrTrack.h"
00025 #include "Event/Recon/TkrRecon/TkrVertex.h"
00026 #include "Event/Recon/CalRecon/CalCluster.h"
00027 #include "Event/Recon/CalRecon/CalEventEnergy.h"
00028 #include "Event/Recon/CalRecon/CalParams.h"
00029 #include "Event/Recon/CalRecon/CalXtalRecData.h"
00030 //@@@FP 07/09/05
00031 #include "Event/Recon/CalRecon/CalMipClasses.h"
00032 //@@@FP 07/09/05
00033 #include "geometry/Ray.h"
00034 
00035 #include "GlastSvc/Reco/IPropagatorTool.h"
00036 #include "GlastSvc/Reco/IPropagator.h" 
00037 
00038 #include "GlastSvc/GlastDetSvc/IGlastDetSvc.h"
00039 #include "TkrUtil/ITkrGeometrySvc.h"
00040 
00041 #include "idents/TowerId.h" 
00042 #include "idents/VolumeIdentifier.h"
00043 
00044 #include "CLHEP/Geometry/Transform3D.h"
00045 #include "CLHEP/Vector/Rotation.h"
00046 
00047 #include "geometry/Ray.h"
00048 
00049 #include "TMath.h"
00050 
00057 class CalMipValsTool :   public ValBase
00058 {
00059 public:  
00060   CalMipValsTool( const std::string& type, 
00061                   const std::string& name, 
00062                   const IInterface* parent);
00063   
00064   virtual ~CalMipValsTool() { }
00065   
00066   StatusCode initialize();
00067   
00068   StatusCode calculate();
00069   
00070 private:
00071   float m_num;
00072   float m_x0;
00073   float m_y0;
00074   float m_z0;
00075   float m_xDir;
00076   float m_yDir;
00077   float m_zDir;
00078   float m_d2edge;
00079   float m_arcLen;
00080   float m_ecor;
00081   float m_ecorRms;
00082   float m_chi2;
00083   float m_erm;
00084   //2007-04-05 Sylvain Guiriec
00085   float m_ermc;
00086   float m_derr;
00087   float m_barDist;
00088   //2007-04-05 Sylvain Guiriec End 
00089 };
00090   
00121 // Static factory for instantiation of algtool objects
00122 static ToolFactory<CalMipValsTool> s_factory;
00123 const IToolFactory& CalMipValsToolFactory = s_factory;
00124   
00125 // Standard Constructor
00126 CalMipValsTool::CalMipValsTool(const std::string& type, 
00127                                const std::string& name, 
00128                                const IInterface* parent)
00129                : ValBase( type, name, parent )
00130 {    
00131     // Declare additional interface
00132     declareInterface<IValsTool>(this); 
00133 }
00134   
00135 StatusCode CalMipValsTool::initialize()
00136 {
00137     StatusCode sc = StatusCode::SUCCESS;
00138     
00139     MsgStream log(msgSvc(), name());
00140     
00141     if( ValBase::initialize().isFailure()) return StatusCode::FAILURE;
00142 
00143     
00144     addItem("CalMipNum",     &m_num);      
00145     addItem("CalMipX0",      &m_x0);      
00146     addItem("CalMipY0",      &m_y0);      
00147     addItem("CalMipZ0",      &m_z0);      
00148     addItem("CalMipXDir",    &m_xDir);   
00149     addItem("CalMipYDir",    &m_yDir);    
00150     addItem("CalMipZDir",    &m_zDir);    
00151     addItem("CalMipD2edge",  &m_d2edge);  
00152     addItem("CalMipArcLen",  &m_arcLen);  
00153     addItem("CalMipEcor",    &m_ecor);    
00154     addItem("CalMipEcorRms", &m_ecorRms); 
00155     addItem("CalMipChi2",    &m_chi2);    
00156     addItem("CalMipErm",     &m_erm);
00157 
00158     //2007-04-05 Sylvain Guiriec
00159     addItem("CalMipErmc",    &m_ermc);
00160     addItem("CalMipDerr",    &m_derr);
00161     addItem("CalMipBarDist", &m_barDist);
00162     //2007-04-05 Sylvain Guiriec End 
00163     
00164     return sc;
00165 }
00166 
00167 StatusCode CalMipValsTool::calculate()
00168 {
00169     StatusCode sc = StatusCode::SUCCESS;
00170 
00171     // Retrieve the calMipTrack collection   
00172 
00173     MsgStream log(msgSvc(), name());
00174     log << MSG::DEBUG << "FP : readCalMipTrackCol in CalMipValsTool" << endreq;
00175 
00176     SmartDataPtr<Event::CalMipTrackCol> p_calMipTrackCol(m_pEventSvc, EventModel::CalRecon::CalMipTrackCol); 
00177 
00178     Point  point(-1.,-1.,-1.);
00179     Vector dir(-1.,-1.,-1.);
00180     double d2c=-6.;
00181     double d2edge=-6.;
00182     int    calEdge=-6;
00183     double arcLen=-6.;
00184     double ecor=-6.;
00185     double ecorRms=-6.;
00186     double chi2=-6.;
00187     double erm=-6.;
00188     //100 tracks maxi, and 2 criteria :
00189     //   1/ at the CAL boundary
00190     //   2/ Ecor in energy interval given by 25% of MIP Landau function maximum
00191     int ipassed[100][2];
00192     for(int j=0;j<100;j++)
00193     {
00194         ipassed[j][0]=0;
00195         ipassed[j][1]=0;
00196     }
00197     int n1=0,n2=0;
00198 
00199     m_num=0;
00200     m_x0=-5.;
00201     m_y0=-5.;
00202     m_z0=-5.;
00203     m_xDir=-5.;
00204     m_yDir=-5.;
00205     m_zDir=-5.;
00206     m_d2edge=-5.;
00207     m_arcLen=-5.;
00208     m_ecor=-5.;
00209     m_ecorRms=-5.;
00210     m_chi2=-5.;
00211     m_erm=-5.;
00212 
00213     if (p_calMipTrackCol==0)
00214       return sc;
00215     m_num=p_calMipTrackCol->size();
00216     int it=-1;
00217     for(Event::CalMipTrackCol::const_iterator calMipTrackIter=p_calMipTrackCol->begin(); calMipTrackIter != p_calMipTrackCol->end(); calMipTrackIter++)
00218     {
00219         it++;
00220         log << "------------------------------------------------------------" << endreq;
00221         log << "counter col=" << it << " / size = " << m_num << endreq;
00222         Event::CalMipTrack* p_calMipTrack    =  *calMipTrackIter;
00223         p_calMipTrack->writeOut(log);
00224         log << "------------------------------------------------------------" << endreq;
00225 
00226         point   = p_calMipTrack->getPoint   ();
00227         dir     = p_calMipTrack->getDir     ();
00228         d2c     = p_calMipTrack->getD2C     ();
00229         d2edge  = p_calMipTrack->getD2Edge  ();
00230         calEdge = p_calMipTrack->getCalEdge ();
00231         arcLen  = p_calMipTrack->getArcLen  ();
00232         ecor    = p_calMipTrack->getEcor    ();
00233         ecorRms = p_calMipTrack->getEcorRms ();
00234         chi2    = p_calMipTrack->getChi2    ();
00235         erm     = p_calMipTrack->getErm     ();
00236             
00237         if (d2edge<1000000)
00238         {
00239             n1++;
00240             ipassed[it][0]=1;
00241             if (ecor>10.0 && ecor<14.2)
00242             {
00243                 n2++;
00244                 ipassed[it][1]=1;
00245             }
00246         }
00247     }
00248         
00249 //     if (n2<=0)
00250     if (n1<=0)
00251       return sc;
00252     else
00253     {
00254         // loop again over tracks to keep the track with best chi2
00255         int it=-1;
00256         double chi2min=999999;
00257         for(Event::CalMipTrackCol::const_iterator calMipTrackIter=p_calMipTrackCol->begin(); calMipTrackIter != p_calMipTrackCol->end(); calMipTrackIter++)
00258         {
00259             it++;
00260             //        if (!ipassed[it][1])
00261             if (!ipassed[it][0])
00262                 continue;
00263             
00264             Event::CalMipTrack* p_calMipTrack    =  *calMipTrackIter;
00265         
00266             double chi2Cur    = p_calMipTrack->getChi2    ();
00267             if (chi2Cur<chi2min)
00268             {
00269                 chi2min=chi2Cur;
00270                 chi2=chi2Cur;
00271                 point   = p_calMipTrack->getPoint   ();
00272                 dir     = p_calMipTrack->getDir     ();
00273                 d2c     = p_calMipTrack->getD2C     ();
00274                 d2edge  = p_calMipTrack->getD2Edge  ();
00275                 calEdge = p_calMipTrack->getCalEdge ();
00276                 arcLen  = p_calMipTrack->getArcLen  ();
00277                 ecor    = p_calMipTrack->getEcor    ();
00278                 ecorRms = p_calMipTrack->getEcorRms ();
00279                 erm     = p_calMipTrack->getErm     ();
00280             }
00281         }
00282     }
00283     
00284     m_x0=point.x();
00285     m_y0=point.y();
00286     m_z0=point.z();
00287     m_xDir=dir.x();
00288     m_yDir=dir.y();
00289     m_zDir=dir.z();
00290     m_d2edge=d2edge;
00291     m_arcLen=arcLen;
00292     m_ecor=ecor;
00293     m_ecorRms=ecorRms;
00294     m_chi2=chi2;
00295     m_erm=erm;
00296 
00297     //2007-04-05 Sylvain Guiriec
00298 
00299     double ermc=0.;
00300     double derr=0.;
00301     double barDist=0.;
00302 
00303     m_ermc=-100.;
00304     m_derr=-100.;
00305     m_barDist=-100.;
00306 
00307     //Recover EventHeader Pointer
00308     //SmartDataPtr<Event::EventHeader> pEvent(m_pEventSvc, EventModel::EventHeader);
00309 
00310     // Recover Track associated info. 
00311     SmartDataPtr<Event::TkrTrackCol>   pTracks(m_pEventSvc,EventModel::TkrRecon::TkrTrackCol);
00312     if(!pTracks) return sc;
00313 
00314     //SmartDataPtr<Event::TkrVertexCol>  pVerts(m_pEventSvc,EventModel::TkrRecon::TkrVertexCol);
00315     //SmartDataPtr<Event::TkrClusterCol> pClusters(m_pEventSvc,EventModel::TkrRecon::TkrClusterCol);
00316 
00317     // all variable values are preset to zero. Be sure to re-initialize the ones you care about  
00318 
00319     //double die_width = m_tkrGeom->ladderPitch();
00320     //int nDies = m_tkrGeom->nWaferAcross();
00321 
00322     if (!pTracks || n1<=0)
00323       return sc;
00324     else
00325       {
00326         // Count number of tracks
00327         int nTracks = pTracks->size();
00328         int Tkr_No_Tracks   = nTracks;
00329         
00330         if(nTracks < 1) return sc;
00331         
00332         // Get the first Track - it should be the "Best Track"
00333         Event::TkrTrackColConPtr pTrack = pTracks->begin();
00334         
00335         const Event::TkrTrack* track_1 = *pTrack;
00336         
00337         Point  x1 = track_1->getInitialPosition();
00338         Vector t1 = track_1->getInitialDirection();
00339         
00340         float Tkr_1_xdir        = t1.x();
00341         float Tkr_1_ydir        = t1.y();
00342         float Tkr_1_zdir        = t1.z();
00343         
00344         float Tkr_1_x0          = x1.x();
00345         float Tkr_1_y0          = x1.y();
00346         float Tkr_1_z0          = x1.z();
00347 
00348         if (m_arcLen>0)
00349           ermc=m_erm/m_arcLen;
00350         else if (m_arcLen<=0)
00351           ermc=-100.;
00352         //@@@@@
00353         derr=TMath::ACos(m_xDir*Tkr_1_xdir+
00354                                 m_yDir*Tkr_1_ydir+
00355                                 m_zDir*Tkr_1_zdir);
00356         
00357         //@@@@@ Distance between tracker track & calorimeter track's centroid point
00358         double l=(Tkr_1_xdir*(m_x0-Tkr_1_x0)+Tkr_1_ydir*(m_y0-Tkr_1_y0)+Tkr_1_zdir*(m_z0-Tkr_1_z0))/(TMath::Power(Tkr_1_xdir,2)+TMath::Power(Tkr_1_ydir,2)+TMath::Power(Tkr_1_zdir,2));
00359         double Bx   = l*Tkr_1_xdir+Tkr_1_x0;
00360         double By   = l*Tkr_1_ydir+Tkr_1_y0;
00361         double Bz   = l*Tkr_1_zdir+Tkr_1_z0;
00362         barDist = TMath::Sqrt(TMath::Power(m_x0-Bx,2)+TMath::Power(m_y0-By,2)+TMath::Power(m_z0-Bz,2));
00363       }
00364 
00365     m_ermc=ermc;
00366     m_derr=derr;
00367     m_barDist=barDist;
00368 
00369     //2007-04-05 Sylvain Guiriec End  
00370 
00371     log << MSG::DEBUG << " FP : readCalMipTrackCol in CalMipValsTool End  " << m_num << endreq;
00372     return sc;
00373 }
00374 

Generated on Mon Dec 1 20:09:04 2008 by doxygen 1.3.3