00001 #include "Validation/RecoTrack/interface/MultiTrackValidatorGenPs.h"
00002 #include "DQMServices/ClientConfig/interface/FitSlicesYTool.h"
00003
00004 #include "FWCore/Framework/interface/MakerMacros.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006
00007 #include "DataFormats/TrackReco/interface/Track.h"
00008 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00009 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
00010 #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"
00011 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00012 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
00013 #include "SimTracker/TrackAssociation/interface/TrackAssociatorByChi2.h"
00014 #include "SimTracker/TrackAssociation/interface/QuickTrackAssociatorByHits.h"
00015 #include "SimTracker/TrackerHitAssociation/interface/TrackerHitAssociator.h"
00016 #include "SimTracker/Records/interface/TrackAssociatorRecord.h"
00017 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
00018 #include "SimDataFormats/TrackingAnalysis/interface/TrackingVertex.h"
00019 #include "SimDataFormats/TrackingAnalysis/interface/TrackingVertexContainer.h"
00020 #include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
00021 #include "SimDataFormats/EncodedEventId/interface/EncodedEventId.h"
00022 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
00023 #include "TrackingTools/PatternTools/interface/TSCBLBuilderNoMaterial.h"
00024 #include "SimTracker/TrackAssociation/plugins/ParametersDefinerForTPESProducer.h"
00025 #include "SimTracker/TrackAssociation/plugins/CosmicParametersDefinerForTPESProducer.h"
00026 #include "Validation/RecoTrack/interface/MTVHistoProducerAlgoFactory.h"
00027
00028 #include "DataFormats/TrackReco/interface/DeDxData.h"
00029 #include "DataFormats/Common/interface/ValueMap.h"
00030 #include "DataFormats/Common/interface/Ref.h"
00031
00032 #include "TMath.h"
00033 #include <TF1.h>
00034
00035
00036
00037 using namespace std;
00038 using namespace edm;
00039
00040 MultiTrackValidatorGenPs::MultiTrackValidatorGenPs(const edm::ParameterSet& pset):MultiTrackValidator(pset){
00041
00042 gpSelector = GenParticleCustomSelector(pset.getParameter<double>("ptMinGP"),
00043 pset.getParameter<double>("minRapidityGP"),
00044 pset.getParameter<double>("maxRapidityGP"),
00045 pset.getParameter<double>("tipGP"),
00046 pset.getParameter<double>("lipGP"),
00047 pset.getParameter<bool>("chargedOnlyGP"),
00048 pset.getParameter<int>("statusGP"),
00049 pset.getParameter<std::vector<int> >("pdgIdGP"));
00050
00051 }
00052
00053 MultiTrackValidatorGenPs::~MultiTrackValidatorGenPs(){}
00054
00055
00056 void MultiTrackValidatorGenPs::analyze(const edm::Event& event, const edm::EventSetup& setup){
00057 using namespace reco;
00058
00059 edm::LogInfo("TrackValidator") << "\n====================================================" << "\n"
00060 << "Analyzing new event" << "\n"
00061 << "====================================================\n" << "\n";
00062
00063 edm::ESHandle<ParametersDefinerForTP> parametersDefinerTP;
00064 setup.get<TrackAssociatorRecord>().get(parametersDefiner,parametersDefinerTP);
00065
00066 edm::Handle<GenParticleCollection> TPCollectionHeff ;
00067 event.getByLabel(label_tp_effic,TPCollectionHeff);
00068 const GenParticleCollection tPCeff = *(TPCollectionHeff.product());
00069
00070 edm::Handle<GenParticleCollection> TPCollectionHfake ;
00071 event.getByLabel(label_tp_fake,TPCollectionHfake);
00072 const GenParticleCollection tPCfake = *(TPCollectionHfake.product());
00073
00074
00075
00076
00077
00078
00079 edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
00080 event.getByLabel(bsSrc,recoBeamSpotHandle);
00081 reco::BeamSpot bs = *recoBeamSpotHandle;
00082
00083 edm::Handle< vector<PileupSummaryInfo> > puinfoH;
00084 event.getByLabel(label_pileupinfo,puinfoH);
00085 PileupSummaryInfo puinfo;
00086
00087 for (unsigned int puinfo_ite=0;puinfo_ite<(*puinfoH).size();++puinfo_ite){
00088 if ((*puinfoH)[puinfo_ite].getBunchCrossing()==0){
00089 puinfo=(*puinfoH)[puinfo_ite];
00090 break;
00091 }
00092 }
00093
00094 int w=0;
00095 for (unsigned int ww=0;ww<associators.size();ww++){
00096
00097 associatorByChi2 = dynamic_cast<const TrackAssociatorByChi2*>(associator[ww]);
00098 if (associatorByChi2==0) continue;
00099
00100 for (unsigned int www=0;www<label.size();www++){
00101
00102
00103
00104 edm::Handle<View<Track> > trackCollection;
00105 if(!event.getByLabel(label[www], trackCollection)&&ignoremissingtkcollection_)continue;
00106
00107
00108
00109
00110 reco::RecoToGenCollection recGenColl;
00111 reco::GenToRecoCollection genRecColl;
00112
00113 if(UseAssociators){
00114 edm::LogVerbatim("TrackValidator") << "Analyzing "
00115 << label[www].process()<<":"
00116 << label[www].label()<<":"
00117 << label[www].instance()<<" with "
00118 << associators[ww].c_str() <<"\n";
00119
00120 LogTrace("TrackValidator") << "Calling associateRecoToGen method" << "\n";
00121 recGenColl=associatorByChi2->associateRecoToGen(trackCollection,
00122 TPCollectionHfake,
00123 &event);
00124 LogTrace("TrackValidator") << "Calling associateGenToReco method" << "\n";
00125 genRecColl=associatorByChi2->associateGenToReco(trackCollection,
00126 TPCollectionHeff,
00127 &event);
00128 }
00129 else{
00130 edm::LogVerbatim("TrackValidator") << "Analyzing "
00131 << label[www].process()<<":"
00132 << label[www].label()<<":"
00133 << label[www].instance()<<" with "
00134 << associatormap.process()<<":"
00135 << associatormap.label()<<":"
00136 << associatormap.instance()<<"\n";
00137
00138 Handle<reco::GenToRecoCollection > gentorecoCollectionH;
00139 event.getByLabel(associatormap,gentorecoCollectionH);
00140 genRecColl= *(gentorecoCollectionH.product());
00141
00142 Handle<reco::RecoToGenCollection > recotogenCollectionH;
00143 event.getByLabel(associatormap,recotogenCollectionH);
00144 recGenColl= *(recotogenCollectionH.product());
00145 }
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 edm::LogVerbatim("TrackValidator") << "\n# of GenParticles: " << tPCeff.size() << "\n";
00156 int ats(0);
00157 int st(0);
00158 unsigned sts(0);
00159 unsigned asts(0);
00160 for (GenParticleCollection::size_type i=0; i<tPCeff.size(); i++){
00161 GenParticleRef tpr(TPCollectionHeff, i);
00162 GenParticle* tp=const_cast<GenParticle*>(tpr.get());
00163 TrackingParticle::Vector momentumTP;
00164 TrackingParticle::Point vertexTP;
00165 double dxyGen(0);
00166 double dzGen(0);
00167
00168
00169
00170
00171 if(parametersDefiner=="LhcParametersDefinerForTP")
00172 {
00173
00174 if(! gpSelector(*tp)) continue;
00175 momentumTP = tp->momentum();
00176 vertexTP = tp->vertex();
00177
00178 TrackingParticle::Vector momentum = parametersDefinerTP->momentum(event,setup,*tp);
00179 TrackingParticle::Point vertex = parametersDefinerTP->vertex(event,setup,*tp);
00180 dxyGen = (-vertex.x()*sin(momentum.phi())+vertex.y()*cos(momentum.phi()));
00181 dzGen = vertex.z() - (vertex.x()*momentum.x()+vertex.y()*momentum.y())/sqrt(momentum.perp2())
00182 * momentum.z()/sqrt(momentum.perp2());
00183 }
00184
00185 if(parametersDefiner=="CosmicParametersDefinerForTP")
00186 {
00187
00188 momentumTP = parametersDefinerTP->momentum(event,setup,*tp);
00189 vertexTP = parametersDefinerTP->vertex(event,setup,*tp);
00190 dxyGen = (-vertexTP.x()*sin(momentumTP.phi())+vertexTP.y()*cos(momentumTP.phi()));
00191 dzGen = vertexTP.z() - (vertexTP.x()*momentumTP.x()+vertexTP.y()*momentumTP.y())/sqrt(momentumTP.perp2())
00192 * momentumTP.z()/sqrt(momentumTP.perp2());
00193 }
00194
00195
00196 st++;
00197
00198
00199
00200
00201
00202
00203
00204 histoProducerAlgo_->fill_generic_simTrack_histos(w,momentumTP,vertexTP, tp->collisionId());
00205
00206
00207
00208
00209
00210
00211 const reco::Track* matchedTrackPointer=0;
00212 std::vector<std::pair<RefToBase<Track>, double> > rt;
00213 if(genRecColl.find(tpr) != genRecColl.end()){
00214 rt = (std::vector<std::pair<RefToBase<Track>, double> >) genRecColl[tpr];
00215 if (rt.size()!=0) {
00216 ats++;
00217
00218 matchedTrackPointer = rt.begin()->first.get();
00219 edm::LogVerbatim("TrackValidator") << "GenParticle #" << st
00220 << " with pt=" << sqrt(momentumTP.perp2())
00221 << " associated with quality:" << rt.begin()->second <<"\n";
00222 }
00223 }else{
00224 edm::LogVerbatim("TrackValidator")
00225 << "GenParticle #" << st
00226 << " with pt,eta,phi: "
00227 << sqrt(momentumTP.perp2()) << " , "
00228 << momentumTP.eta() << " , "
00229 << momentumTP.phi() << " , "
00230 << " NOT associated to any reco::Track" << "\n";
00231 }
00232
00233
00234
00235
00236
00237
00238
00239 int nSimHits = 0;
00240
00241 double vtx_z_PU = vertexTP.z();
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 histoProducerAlgo_->fill_recoAssociated_simTrack_histos(w,*tp,momentumTP,vertexTP,dxyGen,dzGen,nSimHits,matchedTrackPointer,puinfo.getPU_NumInteractions(), vtx_z_PU);
00252
00253 sts++;
00254 if (matchedTrackPointer) asts++;
00255
00256
00257
00258
00259 }
00260
00261
00262
00263
00264
00265
00266
00267 edm::LogVerbatim("TrackValidator") << "\n# of reco::Tracks with "
00268 << label[www].process()<<":"
00269 << label[www].label()<<":"
00270 << label[www].instance()
00271 << ": " << trackCollection->size() << "\n";
00272
00273
00274 int at(0);
00275 int rT(0);
00276
00277
00278
00279
00280
00281 edm::Handle<edm::ValueMap<reco::DeDxData> > dEdx1Handle;
00282 edm::Handle<edm::ValueMap<reco::DeDxData> > dEdx2Handle;
00283 std::vector<edm::ValueMap<reco::DeDxData> > v_dEdx;
00284 v_dEdx.clear();
00285
00286 if (label[www].label()=="generalTracks") {
00287 try {
00288 event.getByLabel(m_dEdx1Tag, dEdx1Handle);
00289 const edm::ValueMap<reco::DeDxData> dEdx1 = *dEdx1Handle.product();
00290 event.getByLabel(m_dEdx2Tag, dEdx2Handle);
00291 const edm::ValueMap<reco::DeDxData> dEdx2 = *dEdx2Handle.product();
00292 v_dEdx.push_back(dEdx1);
00293 v_dEdx.push_back(dEdx2);
00294 } catch (cms::Exception e){
00295 LogTrace("TrackValidator") << "exception found: " << e.what() << "\n";
00296 }
00297 }
00298
00299
00300 for(View<Track>::size_type i=0; i<trackCollection->size(); ++i){
00301
00302 RefToBase<Track> track(trackCollection, i);
00303 rT++;
00304
00305 bool isSigGenMatched(false);
00306 bool isGenMatched(false);
00307 bool isChargeMatched(true);
00308 int numAssocRecoTracks = 0;
00309 int tpbx = 0;
00310 int nSimHits = 0;
00311 double sharedFraction = 0.;
00312 std::vector<std::pair<GenParticleRef, double> > tp;
00313 if(recGenColl.find(track) != recGenColl.end()){
00314 tp = recGenColl[track];
00315 if (tp.size()!=0) {
00316
00317
00318
00319
00320 sharedFraction = tp[0].second;
00321 isGenMatched = true;
00322 if (tp[0].first->charge() != track->charge()) isChargeMatched = false;
00323 if(genRecColl.find(tp[0].first) != genRecColl.end()) numAssocRecoTracks = genRecColl[tp[0].first].size();
00324
00325
00326
00327
00328 at++;
00329 for (unsigned int tp_ite=0;tp_ite<tp.size();++tp_ite){
00330 GenParticle trackpart = *(tp[tp_ite].first);
00331
00332
00333
00334
00335
00336
00337
00338 }
00339 edm::LogVerbatim("TrackValidator") << "reco::Track #" << rT << " with pt=" << track->pt()
00340 << " associated with quality:" << tp.begin()->second <<"\n";
00341 }
00342 } else {
00343 edm::LogVerbatim("TrackValidator") << "reco::Track #" << rT << " with pt=" << track->pt()
00344 << " NOT associated to any GenParticle" << "\n";
00345 }
00346
00347
00348 histoProducerAlgo_->fill_generic_recoTrack_histos(w,*track,bs.position(),isGenMatched,isSigGenMatched, isChargeMatched, numAssocRecoTracks, puinfo.getPU_NumInteractions(), tpbx, nSimHits, sharedFraction);
00349
00350
00351
00352 if (v_dEdx.size() > 0) histoProducerAlgo_->fill_dedx_recoTrack_histos(w,track, v_dEdx);
00353
00354
00355
00356
00357
00358
00359 if (tp.size()==0) continue;
00360
00361 histoProducerAlgo_->fill_simAssociated_recoTrack_histos(w,*track);
00362
00363 GenParticleRef tpr = tp.begin()->first;
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381 TrackingParticle::Vector momentumTP = parametersDefinerTP->momentum(event,setup,*(tpr.get()));
00382 TrackingParticle::Point vertexTP = parametersDefinerTP->vertex(event,setup,*(tpr.get()));
00383 int chargeTP = tpr->charge();
00384
00385 histoProducerAlgo_->fill_ResoAndPull_recoTrack_histos(w,momentumTP,vertexTP,chargeTP,
00386 *track,bs.position());
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400 }
00401
00402 histoProducerAlgo_->fill_trackBased_histos(w,at,rT,st);
00403
00404 edm::LogVerbatim("TrackValidator") << "Total Simulated: " << st << "\n"
00405 << "Total Associated (genToReco): " << ats << "\n"
00406 << "Total Reconstructed: " << rT << "\n"
00407 << "Total Associated (recoToGen): " << at << "\n"
00408 << "Total Fakes: " << rT-at << "\n";
00409
00410 w++;
00411 }
00412 }
00413
00414 }