00001 #include "AtlfastAlgs/SharedConeStrategy.h"
00002 #include "AtlfastAlgs/ClusterConeStrategy.h"
00003 #include "AtlfastAlgs/AssocTypeRecoverer.h"
00004 #include "AtlfastEvent/Cell.h"
00005 #include "AtlfastEvent/Cluster.h"
00006 #include "AtlfastEvent/CollectionDefs.h"
00007
00008 #include "AtlfastUtils/FunctionObjects.h"
00009
00010
00011 #include "GaudiKernel/DataSvc.h"
00012 #include "StoreGate/DataHandle.h"
00013 #include "GaudiKernel/ISvcLocator.h"
00014 #include "GaudiKernel/MsgStream.h"
00015
00016 #include <assert.h>
00017 #include <algorithm>
00018 #include <numeric>
00019 #include <iostream>
00020 namespace Atlfast{
00021
00022 SharedConeStrategy::SharedConeStrategy(double rConeBarrel,
00023 double rConeForward,
00024 double minInitiatorET,
00025 double minClusterET,
00026 double barrelForwardEta):
00027 m_rConeBarrel(rConeBarrel),
00028 m_rConeForward(rConeForward),
00029 m_minClusterET(minClusterET),
00030 m_barrelForwardEta(barrelForwardEta){
00031
00035 m_coneStrategy = new ClusterConeStrategy( rConeBarrel,
00036 rConeForward,
00037 minInitiatorET,
00038 minInitiatorET,
00039 true);
00040 }
00041
00042 SharedConeStrategy::~SharedConeStrategy(){delete m_coneStrategy;}
00043
00044
00045 class EsumIK{
00046 public:
00047 double operator()(double sum, IKinematic* ik){
00048 return sum + ( ik->momentum().e() );
00049 }
00050 };
00051
00052 class CellAssociatedClusterEnergy{
00053 public:
00054 CellAssociatedClusterEnergy(
00055 ClusterCollection* clusters,
00056 std::map<Cluster*,double>& cluMap,
00057 double rConeBarrel
00058 ):
00059 m_clusters(clusters), m_cluMap(cluMap), m_rConeBarrel(rConeBarrel){
00060 }
00061 void operator()(IKinematic* cell){
00062
00063
00064
00065 ClusterCollection::iterator endAssClu =
00066 partition(m_clusters->begin(),
00067 m_clusters->end(),
00068 PartitionCondition::BelowThresholdDeltaR(*cell,m_rConeBarrel)
00069 );
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 double clusterEsum =
00080 std::accumulate(m_clusters->begin(), endAssClu, 0., EsumIK() );
00081
00082
00083
00084 ClusterCollection::iterator itr = m_clusters->begin();
00085 for(; itr != endAssClu; ++itr){
00086
00087 double eCell = cell->momentum().e();
00088 double eCluster = ( *itr)->momentum().e();
00089 m_cluMap[*itr] += eCell*eCluster/clusterEsum;
00090
00091 }
00092
00093 return;
00094 }
00095 private:
00096 ClusterCollection* m_clusters;
00097 std::map<Cluster*,double>& m_cluMap;
00098 double m_rConeBarrel;
00099 };
00100 void
00101 SharedConeStrategy::makeClusters(MsgStream& log,
00102 const std::vector<IKinematic*>& storedCells,
00103 std::vector<IKinematic*>& unusedCells,
00104 ClusterCollection* clusters) const {
00105
00106 m_coneStrategy->makeClusters(log, storedCells, unusedCells, clusters);
00107
00108
00109 std::map<Cluster*,double> aMap;
00110 ClusterCollection::iterator cluIter = clusters->begin();
00111 for(; cluIter != clusters->end(); ++cluIter) {aMap[*cluIter] = 0.0;}
00112
00113
00114 AssocTypeRecoverer<ClusterCollection> atr(clusters);
00115 std::vector<IKinematic*>* usedCells = atr.vectorOfIKinematics();
00116
00117
00118 std::for_each(usedCells->begin(),
00119 usedCells->end(),
00120 CellAssociatedClusterEnergy(
00121 clusters,
00122 aMap,
00123 m_rConeBarrel
00124 )
00125
00126 );
00127 delete usedCells;
00128
00129
00130 cluIter = clusters->begin();
00131 for(; cluIter != clusters->end(); ++cluIter){
00132 if(aMap.find(*cluIter) != aMap.end() && aMap[*cluIter] != 0.0) {
00133 double theta = ( (*cluIter)->momentum() ).theta();
00134 double t = aMap[*cluIter];
00135 double eT = t*sin(theta);
00136
00137 double x = eT * cos( (*cluIter)->phi() ) ;
00138 double y = eT * sin( (*cluIter)->phi() ) ;
00139 double z = t * cos( theta ) ;
00140
00141 (*cluIter)->setMomentum(HepLorentzVector(x,y,z,t));
00142 }
00143 }
00144
00145 ClusterCollection::iterator part =
00146 std::partition(
00147 clusters->begin(),
00148 clusters->end(),
00149 PartitionCondition::AboveThresholdET( m_minClusterET )
00150 );
00151
00152
00153 ClusterCollection unusedClusters(part, clusters->end());
00154 AssocTypeRecoverer<ClusterCollection> atr2(unusedClusters);
00155 IKinematicCollection* recoveredCells= atr2.allAsIKinematics();
00156 unusedCells.reserve(unusedCells.size()+recoveredCells->size());
00157
00158 IKinematicIterator iter;
00159 for(iter = recoveredCells->begin(); iter!= recoveredCells->end(); ++iter){
00160 unusedCells.push_back(*iter);
00161 }
00162
00163
00164 clusters->erase(part,clusters->end());
00165
00166 sort( clusters->begin(),clusters->end(),SortAttribute::DescendingET());
00167 return;
00168 }
00169 }
00170
00171
00172
00173
00174
00175