38 edm::LogVerbatim(
"ME0SegAlgoMM") <<
"[ME0SegAlgoMM::ctor] Parameters to build segments :: "
39 <<
"preClustering = "<<preClustering<<
" preClustering_useChaining = "<<preClustering_useChaining
40 <<
" dPhiChainBoxMax = "<<dPhiChainBoxMax<<
" dEtaChainBoxMax = "<<dEtaChainBoxMax<<
" dTimeChainBoxMax = "<<dTimeChainBoxMax
41 <<
" minHitsPerSegment = "<<minHitsPerSegment<<
" maxRecHitsInCluster = "<<
maxRecHitsInCluster;
55 #ifdef EDM_ML_DEBUG // have lines below only compiled when in debug mode
56 ME0DetId chId((theEnsamble.first)->id());
57 edm::LogVerbatim(
"GEMSegAlgoMM") <<
"[ME0SegAlgoMM::run] build segments in chamber " << chId <<
" which contains "<<rechits.size()<<
" rechits";
58 for (
auto rh=rechits.begin(); rh!=rechits.end(); ++rh){
59 auto me0id = (*rh)->me0Id();
60 auto rhLP = (*rh)->localPosition();
61 edm::LogVerbatim(
"ME0SegAlgoMM") <<
"[RecHit :: Loc x = "<<std::showpos<<std::setw(9)<<rhLP.x()<<
" Loc y = "<<std::showpos<<std::setw(9)<<rhLP.y()
62 <<
" Time = "<<std::showpos<<(*rh)->tof()<<
" -- "<<me0id.rawId()<<
" = "<<me0id<<
" ]";
67 std::vector<ME0Segment> segments_temp;
68 std::vector<ME0Segment> segments;
76 rechits_clusters = this->
chainHits( rechits );
83 for(
auto sub_rechits = rechits_clusters.begin(); sub_rechits != rechits_clusters.end(); ++sub_rechits ) {
85 segments_temp.clear();
89 segments.insert( segments.end(), segments_temp.begin(), segments_temp.end() );
108 float dXclus_box = 0.0;
109 float dYclus_box = 0.0;
114 std::vector<float> running_meanX;
115 std::vector<float> running_meanY;
117 std::vector<float> seed_minX;
118 std::vector<float> seed_maxX;
119 std::vector<float> seed_minY;
120 std::vector<float> seed_maxY;
125 for(
unsigned int i = 0;
i < rechits.size(); ++
i) {
127 temp.push_back(rechits[
i]);
128 seeds.push_back(temp);
133 running_meanX.push_back( rechits[i]->localPosition().
x() );
134 running_meanY.push_back( rechits[i]->localPosition().
y() );
137 seed_minX.push_back( rechits[i]->localPosition().
x() );
138 seed_maxX.push_back( rechits[i]->localPosition().
x() );
139 seed_minY.push_back( rechits[i]->localPosition().
y() );
140 seed_maxY.push_back( rechits[i]->localPosition().
y() );
145 for(
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
146 for(
size_t MMM = NNN+1; MMM < seeds.size(); ++MMM) {
148 LogDebug(
"ME0SegAlgoMM") <<
"[ME0SegAlgoMM::clusterHits]: ALARM! Skipping used seeds, this should not happen - inform developers!";
156 if ( running_meanX[NNN] > running_meanX[MMM] ) dXclus_box = seed_minX[NNN] - seed_maxX[MMM];
157 else dXclus_box = seed_minX[MMM] - seed_maxX[NNN];
158 if ( running_meanY[NNN] > running_meanY[MMM] ) dYclus_box = seed_minY[NNN] - seed_maxY[MMM];
159 else dYclus_box = seed_minY[MMM] - seed_maxY[NNN];
167 if(seeds[NNN].
size()+seeds[MMM].
size() != 0) {
168 running_meanX[MMM] = (running_meanX[NNN]*seeds[NNN].size() + running_meanX[MMM]*seeds[MMM].size()) / (seeds[NNN].
size()+seeds[MMM].size());
169 running_meanY[MMM] = (running_meanY[NNN]*seeds[NNN].size() + running_meanY[MMM]*seeds[MMM].size()) / (seeds[NNN].
size()+seeds[MMM].size());
173 if ( seed_minX[NNN] < seed_minX[MMM] ) seed_minX[MMM] = seed_minX[NNN];
174 if ( seed_maxX[NNN] > seed_maxX[MMM] ) seed_maxX[MMM] = seed_maxX[NNN];
175 if ( seed_minY[NNN] < seed_minY[MMM] ) seed_minY[MMM] = seed_minY[NNN];
176 if ( seed_maxY[NNN] > seed_maxY[MMM] ) seed_maxY[MMM] = seed_maxY[NNN];
179 seeds[MMM].insert(seeds[MMM].
end(),seeds[NNN].
begin(),seeds[NNN].
end());
194 for(
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
196 rechits_clusters.push_back(seeds[NNN]);
199 return rechits_clusters;
210 std::vector <bool> usedCluster;
215 for(
unsigned int i = 0;
i < rechits.size(); ++
i) {
217 temp.push_back(rechits[
i]);
218 seeds.push_back(temp);
219 usedCluster.push_back(
false);
223 for(
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
224 for(
size_t MMM = NNN+1; MMM < seeds.size(); ++MMM) {
225 if(usedCluster[MMM] || usedCluster[NNN]){
245 seeds[MMM].insert(seeds[MMM].
end(),seeds[NNN].
begin(),seeds[NNN].
end());
248 usedCluster[NNN] =
true;
261 for(
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
262 if(usedCluster[NNN])
continue;
263 rechits_chains.push_back(seeds[NNN]);
268 return rechits_chains;
273 std::vector<float> phi_new, eta_new, time_new, phi_old, eta_old, time_old;
274 std::vector<int> layer_new, layer_old;
276 for(
size_t iRH_new = 0;iRH_new<newChain.size();++iRH_new){
278 layer_new.push_back(newChain[iRH_new]->me0Id().layer());
279 phi_new.push_back(pos_new.
phi());
280 eta_new.push_back(pos_new.
eta());
281 time_new.push_back(newChain[iRH_new]->tof());
283 for(
size_t iRH_old = 0;iRH_old<oldChain.size();++iRH_old){
285 layer_old.push_back(oldChain[iRH_old]->me0Id().layer());
286 phi_old.push_back(pos_old.
phi());
287 eta_old.push_back(pos_old.
eta());
288 time_old.push_back(oldChain[iRH_old]->tof());
291 for(
size_t jRH_new = 0; jRH_new<phi_new.size(); ++jRH_new){
292 for(
size_t jRH_old = 0; jRH_old<phi_old.size(); ++jRH_old){
304 bool etaRequirementOK = fabs(eta_new[jRH_new]-eta_old[jRH_old]) <
dEtaChainBoxMax;
306 bool layerRequirementOK =
abs(layer_new[jRH_new]-layer_old[jRH_old]) < (
theEnsemble.first->id().nlayers()-1);
309 bool timeRequirementOK = fabs(time_new[jRH_new] - time_old[jRH_old]) <
dTimeChainBoxMax;
311 if(layerRequirementOK && phiRequirementOK && etaRequirementOK && timeRequirementOK){
324 std::vector<ME0Segment> me0segs;
326 edm::LogVerbatim(
"ME0SegAlgoMM") <<
"[ME0SegAlgoMM::buildSegments] will now try to fit a ME0Segment from collection of "<<rechits.size()<<
" ME0 RecHits";
327 #ifdef EDM_ML_DEBUG // have lines below only compiled when in debug mode
328 for (
auto rh=rechits.begin(); rh!=rechits.end(); ++rh){
329 auto me0id = (*rh)->me0Id();
330 auto rhLP = (*rh)->localPosition();
331 edm::LogVerbatim(
"ME0SegAlgoMM") <<
"[RecHit :: Loc x = "<<std::showpos<<std::setw(9)<<rhLP.x()<<
" Loc y = "<<std::showpos<<std::setw(9)<<rhLP.y()
332 <<
" Time = "<<std::showpos<<(*rh)->tof()<<
" -- "<<me0id.rawId()<<
" = "<<me0id<<
" ]";
338 for (
auto rh=rechits.begin(); rh!=rechits.end();rh++){
348 edm::LogVerbatim(
"ME0SegAlgoMM") <<
"[ME0SegAlgoMM::buildSegments] ME0Segment fit done";
354 double protoChi2 =
sfit_->chi2();
357 float averageTime=0.;
358 for (
auto rh=rechits.begin(); rh!=rechits.end(); ++rh){
359 averageTime += (*rh)->tof();
361 if(rechits.size() != 0) averageTime=averageTime/(rechits.size());
363 for (
auto rh=rechits.begin(); rh!=rechits.end(); ++rh){
364 timeUncrt +=
pow((*rh)->tof()-averageTime,2);
366 if(rechits.size() > 1) timeUncrt=timeUncrt/(rechits.size()-1);
367 timeUncrt =
sqrt(timeUncrt);
370 edm::LogVerbatim(
"ME0SegAlgoMM") <<
"[ME0SegAlgoMM::buildSegments] will now try to make ME0Segment from collection of "<<rechits.size()<<
" ME0 RecHits";
373 edm::LogVerbatim(
"ME0SegAlgoMM") <<
"[ME0SegAlgoMM::buildSegments] ME0Segment made";
376 me0segs.push_back(tmp);
std::vector< const ME0RecHit * > EnsembleHitContainer
Typedefs.
T getParameter(std::string const &) const
ProtoSegments clusterHits(const EnsembleHitContainer &rechits)
Utility functions.
T getUntrackedParameter(std::string const &, T const &) const
std::vector< EnsembleHitContainer > ProtoSegments
Geom::Phi< T > phi() const
bool preClustering_useChaining
ME0SegAlgoMM(const edm::ParameterSet &ps)
Constructor.
std::pair< const ME0EtaPartition *, std::map< uint32_t, const ME0EtaPartition * > > ME0Ensemble
std::unique_ptr< ME0SegFit > sfit_
bool isGoodToMerge(const EnsembleHitContainer &newChain, const EnsembleHitContainer &oldChain)
unsigned int minHitsPerSegment
std::vector< ME0Segment > run(const ME0Ensemble &ensemble, const EnsembleHitContainer &rechits)
Abs< T >::type abs(const T &t)
ProtoSegments chainHits(const EnsembleHitContainer &rechits)
std::vector< ME0Segment > buildSegments(const EnsembleHitContainer &rechits)
double deltaPhi(double phi1, double phi2)
EnsembleHitContainer proto_segment
std::vector< std::vector< double > > tmp
virtual ~ME0SegAlgoMM()
Destructor.
CLHEP::HepSymMatrix AlgebraicSymMatrix
tuple size
Write out results.
Power< A, B >::type pow(const A &a, const B &b)