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