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

AcdValsTool.cxx

Go to the documentation of this file.
00001 
00009 #include "ValBase.h"
00010 
00011 #include "GaudiKernel/MsgStream.h"   
00012 #include "GaudiKernel/IDataProviderSvc.h"
00013 #include "GaudiKernel/SmartDataPtr.h"
00014 #include "GaudiKernel/AlgTool.h"
00015 #include "GaudiKernel/ToolFactory.h"
00016 #include "GaudiKernel/IToolSvc.h"
00017 
00018 #include "Event/TopLevel/EventModel.h"
00019 #include "Event/TopLevel/Event.h"
00020 
00021 #include "Event/Recon/TkrRecon/TkrVertex.h"
00022 #include "Event/Recon/AcdRecon/AcdRecon.h"
00023 #include "Event/Recon/CalRecon/CalCluster.h"
00024 #include "Event/Recon/CalRecon/CalEventEnergy.h"
00025 #include "Event/Digi/AcdDigi.h"
00026 
00027 #include "GlastSvc/GlastDetSvc/IGlastDetSvc.h"
00028 // Point used by AcdDigi
00029 //#include "CLHEP/Geometry/Point3D.h"  //<=== check this
00030 #include "CLHEP/Geometry/Transform3D.h"
00031 // Point used by TKR
00032 //#include "geometry/Point.h"  <=== check this
00033 
00034 #include "AcdUtil/AcdTileFuncs.h"
00035 //#include "AcdRecon/AcdGap.h" (Don't include AcdRecon, use ints instead of enums)
00036 
00037 #include <algorithm>
00038 #include <numeric>
00039 #include <map>
00040 
00045 class AcdValsTool : public ValBase
00046 {
00047 public:
00048 
00049     AcdValsTool( const std::string& type, 
00050         const std::string& name, 
00051         const IInterface* parent);
00052 
00053     virtual ~AcdValsTool() { }
00054 
00055     StatusCode initialize();
00056 
00057     StatusCode calculate();
00058 
00059     void tkrHitsCount();
00060 
00061     void setId(const std::vector<Event::AcdTkrIntersection*> vertexUp, 
00062         const std::vector<Event::AcdTkrIntersection*> vertexDown,
00063         const std::vector<Event::AcdTkrIntersection*> trackUp,
00064         const std::vector<Event::AcdTkrIntersection*> trackDown,
00065         unsigned int &retId, bool findRibbon=false);
00066 
00067 
00068     void findId(const std::vector<Event::AcdTkrIntersection*> vec, 
00069         idents::AcdId &retId, bool findRibbon=false);
00070 
00071     void reconId(const Event::AcdRecon *pACD);
00072 
00073 private:
00074 
00075     //Global ACDTuple Items
00076     unsigned int ACD_Tile_Count; 
00077     unsigned int ACD_Ribbon_Count;
00078     float ACD_Total_Energy;
00079     float ACD_Total_Ribbon_Energy;
00080     unsigned int ACD_TileIdRecon;
00081     unsigned int ACD_RibbonIdRecon;
00082     int          ACD_ActiveDist_TrackNum;
00083 
00084     // Variables computed by looping over all tracks w.r.t. hit tiles
00085     float ACD_ActiveDist3D;
00086     float ACD_ActiveDist3D_Err;
00087     float ACD_ActiveDist_Energy;
00088 
00089 
00090     // Variables computed by looping over all tracks w.r.t. hit ribbons
00091     float ACD_ribbon_ActiveDist;
00092     float ACD_ribbon_ActiveDist_Err;
00093     float ACD_ribbon_ActiveLength;
00094     float ACD_ribbon_EnergyPmtA;
00095     float ACD_ribbon_EnergyPmtB;
00096 
00097     // Variables computed by looping over all tracks w.r.t. gaps in the ACD
00098     float ACD_Corner_DOCA;
00099     float ACD_TkrHole_Dist;
00100     float ACD_TkrRibbon_Dist; 
00101     float ACD_TkrRibbonLength; 
00102 
00103     // Variables computed by taking best track w.r.t. hit tiles
00104     float ACD_Tkr1ActiveDist;
00105     float ACD_Tkr1ActiveDist_Err;
00106     float ACD_Tkr1ActiveDist_Energy;
00107 
00108     // Variables computed by taking best track w.r.t. hit ribbons
00109     float ACD_Tkr1_ribbon_ActiveDist;
00110     float ACD_Tkr1_ribbon_ActiveDist_Err;
00111     float ACD_Tkr1_ribbon_ActiveLength;
00112     float ACD_Tkr1_ribbon_EnergyPmtA;
00113     float ACD_Tkr1_ribbon_EnergyPmtB;
00114 
00115     // Variables computed by taking best w.r.t. gaps in the ACD    
00116     float ACD_Tkr1Corner_DOCA;
00117     float ACD_Tkr1Hole_Dist;
00118     float ACD_Tkr1Ribbon_Dist;
00119     float ACD_Tkr1RibbonLength;
00120 
00121     // Variables computed by taking vertex w.r.t. hit tiles
00122     float ACD_VtxActiveDist;
00123     float ACD_VtxActiveDist_Energy;
00124     float ACD_VtxActiveDist_Down;
00125     float ACD_VtxActiveDist_EnergyDown;
00126 
00127     // Variables about number of ACD tiles by row
00128     unsigned int ACD_tileTopCount;
00129     unsigned int ACD_tileCount0;
00130     unsigned int ACD_tileCount1;
00131     unsigned int ACD_tileCount2;
00132     unsigned int ACD_tileCount3;
00133 
00134     unsigned int   ACD_countRow3Readout;
00135 
00136     float ACD_energyTop;
00137     float ACD_energyRow0;
00138     float ACD_energyRow1;
00139     float ACD_energyRow2;
00140     float ACD_energyRow3;
00141 
00142     // Services
00143     IGlastDetSvc *m_detSvc;
00144 
00145     // Algorithm parameters
00146     double m_vetoThresholdMeV;
00147 };
00148 
00149 
00257 // predicate to identify top, (row -1) or  side  (row 0-2)
00258 namespace {
00259     class acd_row { 
00260     public:
00261         acd_row(int row):m_row(row){}
00262         bool operator() ( std::pair<idents::AcdId ,double> entry){
00263             return m_row==-1? entry.first.face() == 0 : entry.first.row()==m_row;
00264         }
00265         int m_row;
00266     };
00267 } 
00268 
00269 // Static factory for instantiation of algtool objects
00270 static ToolFactory<AcdValsTool> s_factory;
00271 const IToolFactory& AcdValsToolFactory = s_factory;
00272 
00273 // Standard Constructor
00274 AcdValsTool::AcdValsTool(const std::string& type, 
00275                          const std::string& name, 
00276                          const IInterface* parent)
00277                          : ValBase( type, name, parent )
00278 {    
00279     // Declare additional interface
00280     declareInterface<IValsTool>(this); 
00281 
00282     // in MeV
00283     declareProperty("VetoThresholdMeV", m_vetoThresholdMeV=0.0);
00284 }
00285 
00286 StatusCode AcdValsTool::initialize()
00287 {
00288     StatusCode sc = StatusCode::SUCCESS;
00289 
00290     MsgStream log(msgSvc(), name());
00291 
00292     if( ValBase::initialize().isFailure()) return StatusCode::FAILURE;
00293 
00294     setProperties();
00295     // get the services
00296 
00297     // use the pointer from ValBase
00298 
00299     if( serviceLocator() ) {
00300 
00301         // find GlastDevSvc service
00302         if (service("GlastDetSvc", m_detSvc, true).isFailure()){
00303             log << MSG::INFO << "Couldn't find the GlastDetSvc!" << endreq;
00304             log << MSG::INFO << "Will be unable to calculate ACD_TkrHitsCount" << endreq;
00305             m_vetoThresholdMeV = 0.4;
00306         } else {
00307             StatusCode sc = m_detSvc->getNumericConstByName("acd.vetoThreshold", 
00308                 &m_vetoThresholdMeV);
00309             if (sc.isFailure()) {
00310                 log << MSG::INFO << 
00311                     "Unable to retrieve threshold, setting the value to 0.4 MeV" << endreq;
00312                 m_vetoThresholdMeV = 0.4;
00313             }
00314         }
00315     } else {
00316         return StatusCode::FAILURE;
00317     }
00318 
00319     // load up the map
00320     addItem("AcdTileCount",    &ACD_Tile_Count);
00321     addItem("AcdRibbonCount", &ACD_Ribbon_Count);
00322     addItem("AcdTotalEnergy", &ACD_Total_Energy);
00323     addItem("AcdRibbonEnergy", &ACD_Total_Ribbon_Energy);
00324     addItem("AcdTileIdRecon", &ACD_TileIdRecon);
00325     addItem("AcdRibbonIdRecon", &ACD_RibbonIdRecon);
00326 
00327     addItem("AcdActiveDist3D",   &ACD_ActiveDist3D);
00328     addItem("AcdActiveDist3DErr",   &ACD_ActiveDist3D_Err);
00329     addItem("AcdActDistTileEnergy",   &ACD_ActiveDist_Energy);
00330     addItem("AcdActDistTrackNum", &ACD_ActiveDist_TrackNum);
00331 
00332     addItem("AcdRibbonActDist", &ACD_ribbon_ActiveDist);
00333     addItem("AcdRibbonActDistErr", &ACD_ribbon_ActiveDist_Err);
00334     addItem("AcdRibbonActLength", &ACD_ribbon_ActiveLength);
00335     addItem("AcdRibbonActEnergyPmtA", &ACD_ribbon_EnergyPmtA);
00336     addItem("AcdRibbonActEnergyPmtB", &ACD_ribbon_EnergyPmtB);
00337 
00338     addItem("AcdCornerDoca",    &ACD_Corner_DOCA);
00339     addItem("AcdTkrHoleDist",    &ACD_TkrHole_Dist);
00340     addItem("AcdTkrRibbonDist",    &ACD_TkrRibbon_Dist);
00341     addItem("AcdTkrRibbonLength",    &ACD_TkrRibbonLength);
00342 
00343     addItem("AcdTkr1ActiveDist", &ACD_Tkr1ActiveDist);
00344     addItem("AcdTkr1ActiveDistErr", &ACD_Tkr1ActiveDist_Err);
00345     addItem("AcdTkr1ActDistTileEnergy", &ACD_Tkr1ActiveDist_Energy);
00346 
00347     addItem("AcdTkr1RibbonActDist", &ACD_Tkr1_ribbon_ActiveDist);
00348     addItem("AcdTkr1RibbonActDistErr", &ACD_Tkr1_ribbon_ActiveDist_Err);
00349     addItem("AcdTkr1RibbonActLength", &ACD_Tkr1_ribbon_ActiveLength);
00350     addItem("AcdTkr1RibbonActEnergyPmtA", &ACD_Tkr1_ribbon_EnergyPmtA);
00351     addItem("AcdTkr1RibbonActEnergyPmtB", &ACD_Tkr1_ribbon_EnergyPmtB);
00352 
00353     addItem("AcdTkr1CornerDoca",    &ACD_Tkr1Corner_DOCA);
00354     addItem("AcdTkr1HoleDist",    &ACD_Tkr1Hole_Dist);
00355     addItem("AcdTkr1RibbonDist",    &ACD_Tkr1Ribbon_Dist);
00356     addItem("AcdTkr1RibbonLength",    &ACD_Tkr1RibbonLength);    
00357 
00358     addItem("AcdVtxActiveDist", &ACD_VtxActiveDist);
00359     addItem("AcdVtxActDistTileEnergy", &ACD_VtxActiveDist_Energy);
00360     addItem("AcdVtxActiveDist_Down", &ACD_VtxActiveDist_Down);
00361     addItem("AcdVtxActDistTileEnergy_Down", &ACD_VtxActiveDist_EnergyDown);
00362 
00363     addItem("AcdNoTop",        &ACD_tileTopCount);
00364     addItem("AcdNoSideRow0",   &ACD_tileCount0);
00365     addItem("AcdNoSideRow1",   &ACD_tileCount1);
00366     addItem("AcdNoSideRow2",   &ACD_tileCount2);   
00367     addItem("AcdNoSideRow3",   &ACD_tileCount3);
00368 
00369     addItem("AcdNoRow3Readout", &ACD_countRow3Readout);
00370     addItem("AcdEnergyTop",  & ACD_energyTop);
00371     addItem("AcdEnergyRow0", & ACD_energyRow0);
00372     addItem("AcdEnergyRow1", & ACD_energyRow1);
00373     addItem("AcdEnergyRow2", & ACD_energyRow2);
00374     addItem("AcdEnergyRow3", & ACD_energyRow3);
00375 
00376     zeroVals();
00377     ACD_ActiveDist_TrackNum = -1;
00378 
00379     return sc;
00380 }
00381 
00382 
00383 StatusCode AcdValsTool::calculate()
00384 {
00385     StatusCode sc = StatusCode::SUCCESS;
00386 
00387     // Recover pointers to ACD Recon results
00388     SmartDataPtr<Event::AcdRecon> pACD(m_pEventSvc,EventModel::AcdRecon::Event);
00389     // Recover pointers to CalClusters and Xtals
00390     SmartDataPtr<Event::CalClusterCol>     
00391         pCals(m_pEventSvc,EventModel::CalRecon::CalClusterCol);
00392 
00393     // Recover Track associated info. (not currently used 
00394     //SmartDataPtr<Event::TkrFitTrackCol>  pTracks(m_pEventSvc,EventModel::TkrRecon::TkrFitTrackCol);
00395     //SmartDataPtr<Event::TkrVertexCol>    pVerts(m_pEventSvc,EventModel::TkrRecon::TkrVertexCol);
00396     // Recover pointer to ACD info  
00397 
00398     //Make sure we have valid ACD data
00399     if (pACD)
00400     {
00401         reconId(pACD);
00402 
00403         // Make a map relating AcdId to energy in the tile
00404         std::map<idents::AcdId, double> tileEnergyIdMap;
00405         std::map<idents::AcdId, std::pair<double,double> > ribbonEnergyIdMap;
00406 
00407         const Event::AcdHitCol& hitCol = pACD->getAcdHitCol();
00408         int nHit = hitCol.size();
00409 
00410         static const float MeVMipTile10 = 1.9;
00411         static const float MeVMipTile12 = 2.28;
00412         static const float MeVMipRibbon = 0.5;
00413         static const float TileCountThreshold = 0.8;
00414 
00415         ACD_Total_Ribbon_Energy = 0.;
00416         ACD_Tile_Count = 0;
00417         ACD_Ribbon_Count = 0;
00418 
00419         // Loop over the hits and fill the maps
00420         for (int iHit(0); iHit < nHit; iHit++ ){
00421             const Event::AcdHit* aHit = hitCol[iHit];
00422             const idents::AcdId& id = aHit->getAcdId();
00423             if ( id.na() ) {
00424                 continue;
00425             } else if ( id.ribbon() ) {
00426                 float MeV_A = aHit->mips(Event::AcdHit::A) * MeVMipRibbon;
00427                 float MeV_B = aHit->mips(Event::AcdHit::B) * MeVMipRibbon;
00428                 ACD_Total_Ribbon_Energy += (MeV_A + MeV_B);
00429                 ribbonEnergyIdMap[id] = std::pair<double,double>(MeV_A,MeV_B);
00430                 ACD_Ribbon_Count++;
00431             } else {
00432                 // check for 10mm v. 12mm tiles
00433                 float MeVMip = id.top() && id.row() == 2 ? MeVMipTile12 : MeVMipTile10;
00434                 float MeV = aHit->mips() * MeVMip;
00435                 ACD_Total_Energy += MeV;
00436                 tileEnergyIdMap[id] = MeV;
00437                 ACD_Tile_Count++;
00438 
00439                 // WBA: Insert the Tile_counts_by region here with energy threshold
00440                 if(MeV > TileCountThreshold) {
00441                     if(id.top()) {ACD_tileTopCount += 1.0;}
00442                     else {
00443                         if(id.row()==0) ACD_tileCount0 += 1.0;
00444                         if(id.row()==1) ACD_tileCount1 += 1.0;
00445                         if(id.row()==2) ACD_tileCount2 += 1.0;
00446                         if(id.row()==3) ACD_tileCount3 += 1.0;
00447                     }
00448                 } 
00449 
00450 
00451                 // Bill's new variables 17-Jul-2008
00452                 if(id.top()) {ACD_energyTop  += MeV;}
00453                 else {
00454                     if(id.row()==0) ACD_energyRow0 += MeV;
00455                     if(id.row()==1) ACD_energyRow1 += MeV;
00456                     if(id.row()==2) ACD_energyRow2 += MeV;
00457                     if(id.row()==3) {
00458                         ACD_energyRow3 += MeV;
00459                         ACD_countRow3Readout += 1.0;
00460                     }
00461                 }
00462             }     
00463         }
00464 
00465         //Make sure we have valid cluster data and some energy
00466         double CAL_EnergyRaw = 10.; //Default min. Event Energy
00467         if (pCals) {
00468             if (!pCals->empty()) {
00469                 Event::CalCluster* calCluster = pCals->front();
00470                 CAL_EnergyRaw  = calCluster->getCalParams().getEnergy();
00471             }
00472         }
00473         // Find *Safe* Active Distance for this event given the energy
00474         double min_ActiveDistance = -300./sqrt(CAL_EnergyRaw/100); //-300mm @ 100 MeV
00475 
00476         // Reset variables for loop over all tracks
00477         ACD_ActiveDist3D = ACD_ribbon_ActiveDist = -2000.;
00478         ACD_ActiveDist_Energy = ACD_ribbon_EnergyPmtA = ACD_ribbon_EnergyPmtB = 0.;
00479         ACD_ActiveDist3D_Err = ACD_ribbon_ActiveDist_Err = -1.; 
00480         ACD_Corner_DOCA = ACD_TkrRibbon_Dist = ACD_TkrHole_Dist = -2000.;
00481         ACD_ribbon_ActiveLength = ACD_TkrRibbonLength = -10000.;
00482 
00483         // Reset variables for best track
00484         ACD_Tkr1ActiveDist = ACD_Tkr1_ribbon_ActiveDist = -2000.;
00485         ACD_Tkr1ActiveDist_Energy = ACD_Tkr1_ribbon_EnergyPmtA 
00486             = ACD_Tkr1_ribbon_EnergyPmtB = 0.;
00487         ACD_Tkr1ActiveDist_Err = ACD_Tkr1_ribbon_ActiveDist_Err = -1.;
00488         ACD_Tkr1Corner_DOCA = ACD_Tkr1Ribbon_Dist = ACD_Tkr1Hole_Dist = -2000.;
00489         ACD_Tkr1_ribbon_ActiveLength = ACD_Tkr1RibbonLength = -10000.;
00490 
00491         // Reset vertex variables
00492         ACD_VtxActiveDist = ACD_VtxActiveDist_Down = -2000.;
00493         ACD_VtxActiveDist_Energy = ACD_VtxActiveDist_EnergyDown = 0.;
00494 
00495         // LOOP over AcdTkrHitPoca & get least distance sutff
00496         // Note that the Poca are sorted.  
00497         // Once we have filled all the variables we can split
00498         const Event::AcdTkrHitPoca* tile_vetoPoca = 0;
00499         double max_tile_energy = 0.; 
00500 
00501         const Event::AcdTkrHitPocaCol& pocas = pACD->getAcdTkrHitPocaCol();
00502         Event::AcdTkrHitPocaCol::const_iterator itrPoca = pocas.begin();
00503         for ( ; itrPoca != pocas.end(); itrPoca++ ) {
00504 
00505             const Event::AcdTkrHitPoca* aPoca = (*itrPoca);
00506             // check to see if this is the vertex (-1) 
00507             // or the best track (0) and direction
00508             bool isVertex = aPoca->trackIndex() == -1;
00509             bool isBestTrack = aPoca->trackIndex() == 0;
00510             bool isUpGoing = aPoca->getArcLength() > 0.;
00511             bool isTrack = aPoca->trackIndex() >= 0;
00512 
00513             bool doneHole = false;
00514             double holeDoca(0.), holeDocaError(0.); 
00515             int iHole = -1;
00516 
00517             bool donePlaneError = false;
00518             double planeError = 0.;
00519 
00520             // get the id
00521             idents::AcdId theId = aPoca->getId();
00522 
00523             if ( isUpGoing && isTrack) {
00524                 // Fill variables for all tracks
00525                 if ( theId.tile() ) {
00526                     if ( ACD_ActiveDist3D < -1999.99 
00527                         || aPoca->getDoca() > min_ActiveDistance) 
00528                     {
00529                         if(tileEnergyIdMap[theId] > max_tile_energy ) {
00530                             max_tile_energy = tileEnergyIdMap[theId];
00531                             tile_vetoPoca = aPoca;
00532                             ACD_ActiveDist3D = aPoca->getDoca();
00533                         }
00534                     }   
00535                 } else if ( theId.ribbon() ) {
00536                     if ( ACD_ribbon_ActiveDist < -1999.99 ) {
00537                         if ( ! donePlaneError ) {
00538                             donePlaneError = true;
00539                             AcdTileUtil::planeErrorProjection(
00540                                 aPoca->getActiveX(),aPoca->getActiveY(),
00541                                 aPoca->getLocalXXCov(),aPoca->getLocalYYCov(),
00542                                 planeError);  
00543                         }
00544                         ACD_ribbon_ActiveDist =  aPoca->getDoca();
00545                         ACD_ribbon_ActiveDist_Err = planeError;
00546                         ACD_ribbon_ActiveLength = aPoca->getActiveY();
00547                         ACD_ribbon_EnergyPmtA = ribbonEnergyIdMap[theId].first;
00548                         ACD_ribbon_EnergyPmtB = ribbonEnergyIdMap[theId].second;
00549                     }
00550                 }
00551                 // Fill variables for best track, if appropiate
00552                 if ( isBestTrack ) {
00553                     // check tile or ribbon
00554                     if ( theId.tile() ) {
00555                         // check to see if vars already filled
00556                         if ( ACD_Tkr1ActiveDist < -1999.99 ) {
00557                             if ( ! doneHole ) {
00558                                 doneHole = true;
00559                                 //AcdTileUtil::tileScrewHoleDoca(aPoca->getId(),aPoca->getActiveX(),aPoca->getActiveY(),
00560                                 //                                 aPoca->getLocalXXCov(),aPoca->getLocalYYCov(),aPoca->getLocalXYCov(),
00561                                 //                                 holeDoca,holeDocaError,iHole);
00562                             }
00563                             if ( ! donePlaneError ) {
00564                                 donePlaneError = true;
00565                                 AcdTileUtil::planeErrorProjection(
00566                                     aPoca->getActiveX(),aPoca->getActiveY(),
00567                                     aPoca->getLocalXXCov(),aPoca->getLocalYYCov(),
00568                                     planeError);  
00569                             }
00570                             ACD_Tkr1ActiveDist = aPoca->getDoca();
00571                             ACD_Tkr1ActiveDist_Err = planeError;
00572                             ACD_Tkr1ActiveDist_Energy = tileEnergyIdMap[theId];
00573                             ACD_Tkr1Hole_Dist = holeDoca;
00574                         } 
00575                     } else if ( theId.ribbon() ) {
00576                         // check to see if vars already filled
00577                         if ( ACD_Tkr1_ribbon_ActiveDist < -1999.99 ) {
00578                             if ( ! donePlaneError ) {
00579                                 donePlaneError = true;
00580                                 AcdTileUtil::planeErrorProjection(aPoca->getActiveX(),aPoca->getActiveY(),
00581                                     aPoca->getLocalXXCov(),aPoca->getLocalYYCov(),planeError);  
00582                             }
00583                             ACD_Tkr1_ribbon_ActiveDist =  aPoca->getDoca();
00584                             ACD_Tkr1_ribbon_ActiveDist_Err = planeError;
00585                             ACD_Tkr1_ribbon_ActiveLength = aPoca->getActiveY();
00586                             ACD_Tkr1_ribbon_EnergyPmtA = ribbonEnergyIdMap[theId].first;
00587                             ACD_Tkr1_ribbon_EnergyPmtB = ribbonEnergyIdMap[theId].second;
00588                         }
00589                     }
00590                     // Of fill variables for vertex, if appropraite
00591                 } else if ( isVertex ) {
00592                     // only fill this one for tiles
00593                     if ( theId.tile() ) {
00594                         // check to see if vars already filled
00595                         if ( ACD_VtxActiveDist < -1999.99 ) {
00596                             ACD_VtxActiveDist = aPoca->getDoca();
00597                             ACD_VtxActiveDist_Energy = tileEnergyIdMap[theId];
00598                         }
00599                     }
00600                 }
00601             } else {
00602                 // Down going, only fill vertex variables
00603                 if ( isVertex ) {
00604                     // only fill this one for tiles
00605                     if ( theId.tile() ) {
00606                         // check to see if vars already filled
00607                         if ( ACD_VtxActiveDist_Down < -1999.99 ) {
00608                             ACD_VtxActiveDist_Down = aPoca->getDoca();
00609                             ACD_VtxActiveDist_EnergyDown = tileEnergyIdMap[theId];
00610                         }
00611                     }
00612                 }
00613             }
00614         }
00615         // Now fill in the values for the most likely Track-Tile Veto Poca
00616         if(tile_vetoPoca) {
00617             double planeError = 0.;
00618             AcdTileUtil::planeErrorProjection(tile_vetoPoca->getActiveX(),
00619                 tile_vetoPoca->getActiveY(),
00620                 tile_vetoPoca->getLocalXXCov(),
00621                 tile_vetoPoca->getLocalYYCov(),planeError);  
00622             //ACD_ActiveDist3D = tile_vetoPoca->getDoca(); Already done in selection process
00623             ACD_ActiveDist3D_Err = planeError;
00624             idents::AcdId theId = tile_vetoPoca->getId();
00625             ACD_ActiveDist_Energy = tileEnergyIdMap[theId];
00626             ACD_ActiveDist_TrackNum = tile_vetoPoca->trackIndex(); // Index starts from 0
00627             double holeDoca(0.), holeDocaError(0.); 
00628             int iHole = -1;
00629             //AcdTileUtil::tileScrewHoleDoca(aPoca->getId(),aPoca->getActiveX(),aPoca->getActiveY(),
00630             //                             aPoca->getLocalXXCov(),aPoca->getLocalYYCov(),aPoca->getLocalXYCov(),
00631             //                             holeDoca,holeDocaError,iHole);
00632             ACD_TkrHole_Dist = holeDoca;
00633         }
00634 
00635         float  bestCornerGapMeasure= 2000.;
00636 
00637         // loop over AcdGaps & get least distance between track extrapolation 
00638         // & ribbon / corner gaps
00639         const Event::AcdTkrGapPocaCol& gaps = pACD->getAcdTkrGapPocaCol();
00640         Event::AcdTkrGapPocaCol::const_iterator itrGap = gaps.begin();
00641         for ( ; itrGap != gaps.end(); itrGap++ ) {
00642 
00643             // check to see if this is the vertex (-1) 
00644             // or the best track (0) and direction
00645             bool isVertex = (*itrGap)->trackIndex() == -1;
00646             bool isBestTrack = (*itrGap)->trackIndex() == 0;
00647             bool isUpGoing = (*itrGap)->getArcLength() > 0.;
00648             bool isRibbonGap = false;
00649             bool isCornerGap = false;
00650 
00651             // for now we ignore vertex and down going
00652             if ( isVertex || (! isUpGoing) ) continue;
00653 
00654             // Classify gap type
00655             switch ( (*itrGap)->getId().gapType() ) 
00656             {
00657             case 1: //AcdRecon::X_RibbonSide: 
00658             case 2: //AcdRecon::Y_RibbonSide:
00659             case 3: //AcdRecon::Y_RibbonTop:
00660                 isRibbonGap = true;
00661                 break;
00662             case 7: //AcdRecon::CornerRay:
00663                 isCornerGap = true;
00664                 break;
00665             default:
00666                 break;
00667             }
00668 
00669             float gapDoca = (*itrGap)->getDoca();
00670             if ( isRibbonGap ) {
00671                 // Fill variables for best track
00672                 if ( isBestTrack ) {
00673                     if ( gapDoca > ACD_Tkr1Ribbon_Dist ) {
00674                         ACD_Tkr1Ribbon_Dist = gapDoca;
00675                         ACD_Tkr1RibbonLength = (*itrGap)->getActiveY();
00676                     }
00677                 }
00678                 // Fill variables for all tracks
00679                 if ( gapDoca > ACD_TkrRibbon_Dist ) {
00680                     ACD_TkrRibbon_Dist = gapDoca;
00681                     ACD_TkrRibbonLength = (*itrGap)->getActiveY();
00682                 }
00683             } else if ( isCornerGap ) {
00684                 //if ( (*itrGap)->getArcLength() < 0. ) continue;
00685                 if ( isBestTrack ) {
00686                     if ( fabs( gapDoca ) < fabs(ACD_Tkr1Corner_DOCA) ) {
00687                         ACD_Tkr1Corner_DOCA = gapDoca;
00688                     }
00689                 }
00690                 float cornerGapMeasure = gapDoca > 0 ? gapDoca : gapDoca / -5.;
00691                 if ( cornerGapMeasure < bestCornerGapMeasure ) {
00692                     ACD_Corner_DOCA = gapDoca;
00693                     bestCornerGapMeasure = cornerGapMeasure;
00694                 }
00695             }
00696         }    
00697 
00698         /*
00699         // -------------- deleted code! ------------
00700         // use acd_row predicate to count number of tiles per side row
00701         unsigned int m_acd_tileCount[5] = {0,0,0,0,0};
00702         for( int row = -1; row<=3; row++ ) { 
00703             m_acd_tileCount[row+1] = 
00704                 std::count_if(tileEnergyIdMap.begin(), 
00705                 tileEnergyIdMap.end(), acd_row(row) );
00706         }
00707         ACD_tileTopCount = m_acd_tileCount[0];
00708         ACD_tileCount0 = m_acd_tileCount[1];
00709         ACD_tileCount1 = m_acd_tileCount[2];
00710         ACD_tileCount2 = m_acd_tileCount[3];       
00711         ACD_tileCount3 = m_acd_tileCount[4];  
00712 
00713     } else {
00714         return StatusCode::FAILURE;
00715         // -----------------------------------------
00716     */     
00717     }
00718 
00719 return sc;
00720 }
00721 
00722 
00723 void AcdValsTool::reconId(const Event::AcdRecon *pACD) 
00724 {
00725     std::vector<Event::AcdTkrIntersection*> bestTrackUp, 
00726         bestTrackDown, vertexUp, vertexDown;
00727 
00728     Event::AcdTkrIntersectionCol::const_iterator itrTrackIntersect; 
00729 
00730     idents::AcdId resetId;
00731     resetId.na(1);
00732     ACD_TileIdRecon = resetId.id();
00733     ACD_RibbonIdRecon = resetId.id();
00734 
00735     // loop over the AcdTrackIntersections
00736     const Event::AcdTkrIntersectionCol& trackIntersectCol = 
00737         pACD->getAcdTkrIntersectionCol();
00738     itrTrackIntersect = trackIntersectCol.begin();
00739     for ( ; itrTrackIntersect != trackIntersectCol.end(); itrTrackIntersect++ ) {
00740 
00741         // could be vertex (-1) or best track (0)            
00742         if ((*itrTrackIntersect)->getTrackIndex() > 0 ) continue;
00743 
00744         double arcLen = (*itrTrackIntersect)->getArcLengthToIntersection();
00745 
00746         if (((*itrTrackIntersect)->getTrackIndex() == 0)){ // tracks
00747             if (arcLen > 0) // upward track
00748                 bestTrackUp.push_back(*itrTrackIntersect);
00749             else  // downward track
00750                 bestTrackDown.push_back(*itrTrackIntersect);
00751         } else if ( ((*itrTrackIntersect)->getTrackIndex() == -1)) { // vertices 
00752             if (arcLen > 0)
00753                 vertexUp.push_back(*itrTrackIntersect);
00754             else 
00755                 vertexDown.push_back(*itrTrackIntersect);
00756         }
00757     }
00758 
00759 
00760     setId(vertexUp, vertexDown, bestTrackUp, bestTrackDown, ACD_TileIdRecon, false);
00761     setId(vertexUp, vertexDown, bestTrackUp, bestTrackDown, ACD_RibbonIdRecon, true);
00762 
00763     bestTrackUp.clear();
00764     bestTrackDown.clear();
00765     vertexUp.clear();
00766     vertexDown.clear();
00767 }
00768 
00769 
00770 void AcdValsTool::findId(const std::vector<Event::AcdTkrIntersection*> vec, 
00771                          idents::AcdId &retId, bool findRibbon) 
00772 {
00773 
00774     //Point tilePos, ribbonPos;
00775     int tileIndex = -1, ribIndex = -1;
00776 
00777     //idents::AcdId tileId;  //, ribId;
00778     //tileI d.na(1);
00779     //ribId.na(1);
00780     retId.na(1);
00781     if (vec.size() <= 0) {
00782         //retId = tileId;
00783         return;
00784     }
00785 
00786     //if ( (!findRibbon) && (vec[0]->getTileId().tile()) {
00787     //    tileIndex = 0;
00788     //    tileId = vec[0]->getTileId();
00789     //} else {
00790     //    ribIndex = 0;
00791     //    ribId = vec[0]->getTileId();
00792     // }
00793 
00794     // If there is only one TkrIntesection object, then we can return the one id we have
00795     if (vec.size() == 1) {
00796         if ( (!findRibbon) && (vec[0]->getTileId().tile()) )
00797             retId = vec[0]->getTileId();
00798         else if ( (findRibbon) && (vec[0]->getTileId().ribbon()) ) 
00799             retId = vec[0]->getTileId();
00800         return;
00801     }
00802 
00803     // otherwise, loop over the remaining TkrIntesection objects
00804     unsigned int ind=0;
00805     Event::AcdTkrIntersectionCol::const_iterator itrTrackIntersect;
00806     itrTrackIntersect = vec.begin();
00807     for ( ; itrTrackIntersect != vec.end(); itrTrackIntersect++ ) {
00808         idents::AcdId id = (*itrTrackIntersect)->getTileId();
00809         if ( (!findRibbon) && (id.tile()) ) {
00810             if (tileIndex < 0) {  // haven't seen another tile yet
00811                 tileIndex = ind;
00812                 retId = id;
00813             } else { // there was another tile found already
00814                 // use Z coordinates to choose if one of the found tiles is a "top" tile
00815                 // chose the greater Z value
00816                 if ( (retId.top()) || (id.top()) ) {
00817                     if (vec[tileIndex]->getGlobalPosition().z() < (*itrTrackIntersect)->getGlobalPosition().z()) {
00818                         retId = (*itrTrackIntersect)->getTileId();
00819                         tileIndex = ind;
00820                     }
00821                 }   
00822                 // assume side tiles do not overlap in Gleam, so no worries 
00823                 // about handling that case now
00824                 // right now we just pick up the tile we find first
00825             }
00826         } else if (findRibbon && id.ribbon() ) { // ribbon
00827             if (ribIndex < 0) { // first ribbon intersection found
00828                 ribIndex = ind;
00829                 retId = id;
00830             } 
00831             // don't worry about overlapping ribbons, 
00832             // just pick up the first ribbon we find
00833         }
00834 
00835         ind++;
00836     }
00837 
00838 
00839     return;
00840 }
00841 
00842 void AcdValsTool::setId(const std::vector<Event::AcdTkrIntersection*> vertexUp, 
00843                         const std::vector<Event::AcdTkrIntersection*> vertexDown,
00844                         const std::vector<Event::AcdTkrIntersection*> bestTrackUp,
00845                         const std::vector<Event::AcdTkrIntersection*> bestTrackDown,
00846                         unsigned int &retId, bool findRibbon) 
00847 {
00848 
00849     idents::AcdId vUpId, vDownId, tUpId, tDownId;
00850     vUpId.na(1);
00851     vDownId.na(1);
00852     tUpId.na(1);
00853     tDownId.na(1);
00854 
00855     findId(vertexUp, vUpId, findRibbon);
00856     findId(vertexDown, vDownId, findRibbon);
00857     findId(bestTrackUp, tUpId, findRibbon);
00858     findId(bestTrackDown, tDownId, findRibbon);
00859 
00860     // Prefer vertices over tracks
00861     // up versus down
00862     bool found = false;
00863     if (!vUpId.na()) {
00864         retId = vUpId.id();
00865         found = true;
00866     } else if (!tUpId.na()) { 
00867         retId = tUpId.id();
00868         found = true;
00869     }
00870 
00871     // no upward intersections found - check downward
00872     if (!found) {
00873         if (!vDownId.na()) 
00874             retId = vDownId.id();
00875         else if (!tDownId.na()) 
00876             retId = tDownId.id();
00877     }
00878 }

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