00001 #include "RecoTracker/SiTrackerMRHTools/interface/SimpleMTFHitCollector.h"
00002 #include "RecoTracker/SiTrackerMRHTools/interface/SiTrackerMultiRecHitUpdatorMTF.h"
00003 #include "RecoTracker/TransientTrackingRecHit/interface/TSiTrackerMultiRecHit.h"
00004 #include "TrackingTools/PatternTools/interface/MeasurementEstimator.h"
00005 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00006 #include "TrackingTools/TransientTrackingRecHit/interface/InvalidTransientRecHit.h"
00007 #include "TrackingTools/MeasurementDet/interface/MeasurementDet.h"
00008 #include "RecoTracker/SiTrackerMRHTools/interface/MultiTrajectoryMeasurement.h"
00009 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00010 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
00011 #include "TrackingTools/TrackFitters/interface/TrajectoryStateCombiner.h"
00012 #include <vector>
00013 #include <map>
00014
00015 #define _debug_SimpleMTFHitCollector_
00016
00017 using namespace std;
00018
00019 vector<TrajectoryMeasurement>
00020 SimpleMTFHitCollector::recHits(const std::map<int, vector<TrajectoryMeasurement> >& tmmap,
00021 int i,
00022 double annealing) const{
00023
00024
00025
00026 map< int, vector<TrajectoryMeasurement> >::const_iterator itmeas = tmmap.find(i);
00027 LogDebug("SimpleMTFHitCollector") << "found the element "<< i << "in the map" << std::endl;
00028
00029 vector<TrajectoryMeasurement> meas = itmeas->second;
00030 LogDebug("SimpleMTFHitCollector") << "got the vector corresponding to " << i << " element of the map "<< std::endl;
00031
00032 if (meas.empty())
00033 return vector<TrajectoryMeasurement>();
00034
00035
00036
00037 vector<TrajectoryMeasurement> result;
00038 TrajectoryStateCombiner statecombiner;
00039
00040
00041 for(vector<TrajectoryMeasurement>::reverse_iterator imeas = meas.rbegin(); imeas != meas.rend(); imeas++)
00042
00043 {
00044
00045 if(imeas->recHit()->geographicalId().rawId())
00046 {
00047
00048 TransientTrackingRecHit::ConstRecHitPointer rechit = imeas->recHit();
00049
00050
00051 uint32_t id = imeas->recHit()->geographicalId().rawId();
00052
00053 LogDebug("SimpleMTFHitCollector") << "Detector Id: " << id << std::endl;
00054
00055
00056 std::vector<std::pair<int, TrajectoryMeasurement> > layermeas;
00057 getMeasurements(layermeas, tmmap,*imeas,i);
00058
00059
00060
00061 MultiTrajectoryMeasurement mtm = getTSOS(layermeas, rechit, i);
00062
00063
00064 TransientTrackingRecHit::ConstRecHitContainer hits;
00065
00066 for (vector<std::pair<int, TrajectoryMeasurement> >::const_iterator ittmeas = layermeas.begin(); ittmeas != layermeas.end(); ittmeas++)
00067 {
00068
00069
00070 if(ittmeas->second.recHit()->isValid())
00071 {
00072
00073 LogDebug("SimpleMTFHitCollector") << "this rechit in the vector layermeas is valid." << std::endl;
00074
00075 int k=0;
00076
00077
00078
00079 if (!hits.size())
00080 {
00081 hits.push_back(ittmeas->second.recHit());
00082
00083
00084
00085 }
00086
00087 else
00088 {
00089 for(TransientTrackingRecHit::ConstRecHitContainer::const_iterator ihits = hits.begin(); ihits != hits.end(); ihits++ )
00090 {
00091
00092
00093
00094
00095 if((*ihits)->hit()->sharesInput(ittmeas->second.recHit()->hit(), TrackingRecHit::all))
00096 {
00097 LogDebug("SimpleMTFHitCollector") << "the rechit coming from layermeas is the same as the first rechit "
00098 << "we skip this rechit in building the multirechit" << std::endl;
00099
00100
00101 k++;
00102 break;
00103 }
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 if(k==0)
00116 {
00117 LogTrace("SimpleMTFHitCollector") << "This hit is valid ";
00118 hits.push_back(ittmeas->second.recHit());
00119 }
00120
00121 }
00122
00123 }
00124
00125 else continue;
00126
00127 }
00128
00129
00130 if(hits.size()==0)
00131 {
00132 result.push_back(*imeas);
00133 LogDebug("SimpleMTFHitCollector") << "we found no valid rechits, so we fill the vector with the initial measurement" << std::endl;
00134 }
00135
00136 else
00137 {
00138
00139
00140 TrajectoryStateOnSurface state= statecombiner.combine(layermeas.front().second.predictedState(), layermeas.front().second.backwardPredictedState());
00141
00142 LogDebug("SimpleMTFHitCollector") << "we build a trajectory measurement from a vector of hits of size" << hits.size() <<std::endl;
00143
00144 result.push_back(TrajectoryMeasurement(state,theUpdator->buildMultiRecHit(state, hits, &mtm, annealing)));
00145 }
00146
00147 }
00148
00149
00150
00151
00152 else
00153 {
00154 result.push_back(*imeas);
00155 }
00156
00157 }
00158
00159
00160 LogTrace("MultiRecHitCollector") << "Original Measurement size "
00161 << meas.size() << " SimpleMTFHitCollector returned "
00162 << result.size() << " rechits";
00163
00164 return result;
00165
00166 }
00167
00168
00169 void
00170 SimpleMTFHitCollector::getMeasurements(std::vector<std::pair<int, TrajectoryMeasurement> >& layermeas,
00171 const std::map<int, vector<TrajectoryMeasurement> >& tmmap,
00172 TrajectoryMeasurement& pmeas,
00173 int i) const{
00174
00175 uint32_t id = pmeas.recHit()->geographicalId().rawId();
00176
00177 LogDebug("SimpleMTFHitCollector") << "Detector Id: " << id << std::endl;
00178
00179
00180
00181 if( pmeas.recHit()->geographicalId().rawId() )
00182 {
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 for (std::map< int, vector<TrajectoryMeasurement> >::const_iterator immap=tmmap.begin();
00208 immap!=tmmap.end();
00209 immap++)
00210 {
00211 int ntraj2 = immap->first;
00212
00213
00214 const vector<TrajectoryMeasurement> & vecmeas = immap->second;
00215
00216
00217
00218
00219 for(vector<TrajectoryMeasurement>::const_reverse_iterator itvmeas = vecmeas.rbegin(); itvmeas!=vecmeas.rend(); itvmeas++)
00220 {
00221
00222
00223
00224 if ( (itvmeas->recHit()->geographicalId().rawId() == id) )
00225 {
00226 LogDebug("SimpleMTFHitCollector") << "found a matching rechit in the collector";
00227
00228
00229 layermeas.push_back(make_pair(ntraj2,*itvmeas));
00230
00231 }
00232
00233
00234
00235
00236
00237 }
00238
00239 }
00240
00241
00242
00243
00244
00245
00246
00247
00248 LogDebug("SimpleMTFHitCollector") << " built a vector of Trajectory Measurements all on the same layer, of size: "
00249 << layermeas.size()
00250 << std::endl;
00251 }
00252
00253 else layermeas.push_back(make_pair(i,pmeas));
00254
00255
00256 }
00257
00258 MultiTrajectoryMeasurement SimpleMTFHitCollector::getTSOS(const vector<std::pair<int, TrajectoryMeasurement> >& layermeas,
00259 TransientTrackingRecHit::ConstRecHitPointer rechit,
00260 int i) const{
00261
00262
00263 uint32_t id = rechit->geographicalId().rawId();
00264
00265 LogDebug("SimpleMTFHitCollector") << "Detector Id: " << id << std::endl;
00266
00267 LogDebug("SimpleMTFHitCollector") << "LayerMeas size: " << layermeas.size() << std::endl;
00268
00269 const DetLayer* layer = layermeas.front().second.layer();
00270
00271 std::map<int,TSOS> predictions;
00272 std::map<int,TSOS> updates;
00273 LogDebug("SimpleMTFHitCollector") << " about to build a map with predicted and updated states " << std::endl;
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 TrajectoryStateCombiner statecombiner;
00290
00291 for (std::vector<std::pair<int,TrajectoryMeasurement> >::const_iterator itmeas=layermeas.begin(); itmeas!=layermeas.end(); itmeas++)
00292 {
00293
00294
00295 LogDebug("SimpleMTFHitCollector") << " number of the trajectory examined: " << itmeas->first << std::endl;
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308 if ( (itmeas->second.recHit()->geographicalId().rawId() == id) )
00309 {
00310
00311
00312
00313
00314 if(itmeas->second.predictedState().isValid())
00315 {
00316 predictions[itmeas->first] = itmeas->second.predictedState();
00317
00318 if ( itmeas->second.backwardPredictedState().isValid() ){
00319 updates[itmeas->first]= statecombiner.combine(itmeas->second.predictedState(), itmeas->second.backwardPredictedState());
00320 }
00321 }
00322
00323
00324
00325
00326
00327
00328
00329 else
00330 LogDebug("SimpleMTFHitCollector") << "error:invalid predicted state" << std::endl;
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357 }
00358 }
00359
00360
00361 MultiTrajectoryMeasurement mtm = MultiTrajectoryMeasurement(rechit,predictions,updates,layer);
00362 return mtm;
00363 }
00364
00365
00366
00367 MultiTrajectoryMeasurement SimpleMTFHitCollector::TSOSfinder(const std::map<int, vector<TrajectoryMeasurement> >& tmmap,
00368 TrajectoryMeasurement& pmeas,
00369 int i) const{
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384 vector<TrajectoryMeasurement> result;
00385
00386
00387
00388
00389
00390
00391
00392 TransientTrackingRecHit::ConstRecHitPointer rechit = pmeas.recHit();
00393
00394
00395
00396 uint32_t id = pmeas.recHit()->geographicalId().rawId();
00397
00398 LogDebug("SimpleMTFHitCollector") << "Detector Id: " << id << std::endl;
00399
00400
00401 vector<std::pair<int, TrajectoryMeasurement> > layermeas;
00402 getMeasurements(layermeas, tmmap,pmeas,i);
00403
00404
00405
00406 return getTSOS(layermeas, rechit, i);
00407
00408
00409 }
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428 void SimpleMTFHitCollector::buildMultiRecHits(const vector<std::pair<int, TrajectoryMeasurement> >& vmeas,
00429 MultiTrajectoryMeasurement* mtm,
00430 vector<TrajectoryMeasurement>& result,
00431 double annealing) const {
00432
00433 if (vmeas.empty()) {
00434 LogTrace("SimpleMTFHitCollector") << "the search for the measurement on the same layer returned an empty vector...we have got a problem... " ;
00435
00436
00437 return;
00438 }
00439
00440
00441
00442 TrajectoryStateOnSurface state = vmeas.front().second.predictedState();
00443 LogTrace("SimpleMTFHitCollector") << "Position (local) of the first measurement state: " << state.localPosition();
00444 LogTrace("SimpleMTFHitCollector") << "Position (global) of the first measurement state: " << state.globalPosition();
00445
00446 if (state.isValid()==false){
00447 LogTrace("MultiRecHitCollector") << "first state is invalid; skipping ";
00448 return;
00449 }
00450
00451
00452 TransientTrackingRecHit::ConstRecHitContainer hits;
00453
00454 for (vector<std::pair<int, TrajectoryMeasurement> >::const_iterator ittmeas = vmeas.begin(); ittmeas != vmeas.end(); ittmeas++){
00455 if (ittmeas->second.recHit()->getType() != TrackingRecHit::missing) {
00456 LogTrace("SimpleMTFHitCollector") << "This hit is valid ";
00457 hits.push_back(ittmeas->second.recHit());
00458 }
00459 }
00460
00461 if (hits.empty()){
00462 LogTrace("MultiTrackFilterHitCollector") << "No valid hits found ";
00463 return;
00464 }
00465
00466 LogTrace("SimpleMTFHitCollector") << "The hits vector has size: " << hits.size() << "\n"
00467 << "and has first component global position: " << hits.front()->globalPosition();
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480 result.push_back(TrajectoryMeasurement(state,theUpdator->buildMultiRecHit(state, hits, mtm, annealing)));
00481
00482
00483
00484
00485 }
00486
00487