CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MultiTrackValidator.cc
Go to the documentation of this file.
3 
6 
23 
27 
28 #include "TMath.h"
29 #include <TF1.h>
30 
31 using namespace std;
32 using namespace edm;
33 
35  //theExtractor = IsoDepositExtractorFactory::get()->create( extractorName, extractorPSet);
36 
37  ParameterSet psetForHistoProducerAlgo = pset.getParameter<ParameterSet>("histoProducerAlgoBlock");
38  string histoProducerAlgoName = psetForHistoProducerAlgo.getParameter<string>("ComponentName");
39  histoProducerAlgo_ = MTVHistoProducerAlgoFactory::get()->create(histoProducerAlgoName ,psetForHistoProducerAlgo);
40  histoProducerAlgo_->setDQMStore(dbe_);
41 
42  dirName_ = pset.getParameter<std::string>("dirName");
43  associatormap = pset.getParameter< edm::InputTag >("associatormap");
44  UseAssociators = pset.getParameter< bool >("UseAssociators");
45 
46  m_dEdx1Tag = pset.getParameter< edm::InputTag >("dEdx1Tag");
47  m_dEdx2Tag = pset.getParameter< edm::InputTag >("dEdx2Tag");
48 
49  tpSelector = TrackingParticleSelector(pset.getParameter<double>("ptMinTP"),
50  pset.getParameter<double>("minRapidityTP"),
51  pset.getParameter<double>("maxRapidityTP"),
52  pset.getParameter<double>("tipTP"),
53  pset.getParameter<double>("lipTP"),
54  pset.getParameter<int>("minHitTP"),
55  pset.getParameter<bool>("signalOnlyTP"),
56  pset.getParameter<bool>("chargedOnlyTP"),
57  pset.getParameter<bool>("stableOnlyTP"),
58  pset.getParameter<std::vector<int> >("pdgIdTP"));
59 
61  pset.getParameter<double>("minRapidityTP"),
62  pset.getParameter<double>("maxRapidityTP"),
63  pset.getParameter<double>("tipTP"),
64  pset.getParameter<double>("lipTP"),
65  pset.getParameter<int>("minHitTP"),
66  pset.getParameter<bool>("chargedOnlyTP"),
67  pset.getParameter<std::vector<int> >("pdgIdTP"));
68 
69  useGsf = pset.getParameter<bool>("useGsf");
70  runStandalone = pset.getParameter<bool>("runStandalone");
71 
72 
73 
74  if (!UseAssociators) {
75  associators.clear();
76  associators.push_back(associatormap.label());
77  }
78 }
79 
80 
82 
84  // dbe_->showDirStructure();
85 
86  //int j=0; //is This Necessary ???
87  for (unsigned int ww=0;ww<associators.size();ww++){
88  for (unsigned int www=0;www<label.size();www++){
89  dbe_->cd();
90  InputTag algo = label[www];
91  string dirName=dirName_;
92  if (algo.process()!="")
93  dirName+=algo.process()+"_";
94  if(algo.label()!="")
95  dirName+=algo.label()+"_";
96  if(algo.instance()!="")
97  dirName+=algo.instance()+"_";
98  if (dirName.find("Tracks")<dirName.length()){
99  dirName.replace(dirName.find("Tracks"),6,"");
100  }
101  string assoc= associators[ww];
102  if (assoc.find("Track")<assoc.length()){
103  assoc.replace(assoc.find("Track"),5,"");
104  }
105  dirName+=assoc;
106  std::replace(dirName.begin(), dirName.end(), ':', '_');
107 
108  dbe_->setCurrentFolder(dirName.c_str());
109 
110  // vector of vector initialization
111  histoProducerAlgo_->initialize(); //TO BE FIXED. I'D LIKE TO AVOID THIS CALL
112 
113  dbe_->goUp(); //Is this really necessary ???
114  string subDirName = dirName + "/simulation";
115  dbe_->setCurrentFolder(subDirName.c_str());
116 
117  //Booking histograms concerning with simulated tracks
119 
120  dbe_->cd();
121  dbe_->setCurrentFolder(dirName.c_str());
122 
123  //Booking histograms concerning with reconstructed tracks
126 
127  if (UseAssociators) {
129  for (unsigned int w=0;w<associators.size();w++) {
130  setup.get<TrackAssociatorRecord>().get(associators[w],theAssociator);
131  associator.push_back( theAssociator.product() );
132  }//end loop w
133  }
134  }//end loop www
135  }// end loop ww
136 }
137 
139  using namespace reco;
140 
141  edm::LogInfo("TrackValidator") << "\n====================================================" << "\n"
142  << "Analyzing new event" << "\n"
143  << "====================================================\n" << "\n";
144  edm::ESHandle<ParametersDefinerForTP> parametersDefinerTP;
145  setup.get<TrackAssociatorRecord>().get(parametersDefiner,parametersDefinerTP);
146 
147  edm::Handle<TrackingParticleCollection> TPCollectionHeff ;
148  event.getByLabel(label_tp_effic,TPCollectionHeff);
149  const TrackingParticleCollection tPCeff = *(TPCollectionHeff.product());
150 
151  edm::Handle<TrackingParticleCollection> TPCollectionHfake ;
152  event.getByLabel(label_tp_fake,TPCollectionHfake);
153  const TrackingParticleCollection tPCfake = *(TPCollectionHfake.product());
154 
155  //if (tPCeff.size()==0) {edm::LogInfo("TrackValidator")
156  //<< "TP Collection for efficiency studies has size = 0! Skipping Event." ; return;}
157  //if (tPCfake.size()==0) {edm::LogInfo("TrackValidator")
158  //<< "TP Collection for fake rate studies has size = 0! Skipping Event." ; return;}
159 
160  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
161  event.getByLabel(bsSrc,recoBeamSpotHandle);
162  reco::BeamSpot bs = *recoBeamSpotHandle;
163 
164  int w=0; //counter counting the number of sets of histograms
165  for (unsigned int ww=0;ww<associators.size();ww++){
166  for (unsigned int www=0;www<label.size();www++){
167  //
168  //get collections from the event
169  //
170  edm::Handle<View<Track> > trackCollection;
171  if(!event.getByLabel(label[www], trackCollection)&&ignoremissingtkcollection_)continue;
172  //if (trackCollection->size()==0) {
173  //edm::LogInfo("TrackValidator") << "TrackCollection size = 0!" ;
174  //continue;
175  //}
176  reco::RecoToSimCollection recSimColl;
177  reco::SimToRecoCollection simRecColl;
178  //associate tracks
179  if(UseAssociators){
180  edm::LogVerbatim("TrackValidator") << "Analyzing "
181  << label[www].process()<<":"
182  << label[www].label()<<":"
183  << label[www].instance()<<" with "
184  << associators[ww].c_str() <<"\n";
185 
186  LogTrace("TrackValidator") << "Calling associateRecoToSim method" << "\n";
187  recSimColl=associator[ww]->associateRecoToSim(trackCollection,
188  TPCollectionHfake,
189  &event);
190  LogTrace("TrackValidator") << "Calling associateSimToReco method" << "\n";
191  simRecColl=associator[ww]->associateSimToReco(trackCollection,
192  TPCollectionHeff,
193  &event);
194  }
195  else{
196  edm::LogVerbatim("TrackValidator") << "Analyzing "
197  << label[www].process()<<":"
198  << label[www].label()<<":"
199  << label[www].instance()<<" with "
200  << associatormap.process()<<":"
201  << associatormap.label()<<":"
202  << associatormap.instance()<<"\n";
203 
204  Handle<reco::SimToRecoCollection > simtorecoCollectionH;
205  event.getByLabel(associatormap,simtorecoCollectionH);
206  simRecColl= *(simtorecoCollectionH.product());
207 
208  Handle<reco::RecoToSimCollection > recotosimCollectionH;
209  event.getByLabel(associatormap,recotosimCollectionH);
210  recSimColl= *(recotosimCollectionH.product());
211  }
212 
213 
214 
215  // ########################################################
216  // fill simulation histograms (LOOP OVER TRACKINGPARTICLES)
217  // ########################################################
218 
219  //compute number of tracks per eta interval
220  //
221  edm::LogVerbatim("TrackValidator") << "\n# of TrackingParticles: " << tPCeff.size() << "\n";
222  int ats(0); //This counter counts the number of simTracks that are "associated" to recoTracks
223  int st(0); //This counter counts the number of simulated tracks passing the MTV selection (i.e. tpSelector(tp) )
224  for (TrackingParticleCollection::size_type i=0; i<tPCeff.size(); i++){ //loop over TPs collection for tracking efficiency
225  TrackingParticleRef tpr(TPCollectionHeff, i);
226  TrackingParticle* tp=const_cast<TrackingParticle*>(tpr.get());
227  ParticleBase::Vector momentumTP;
228  ParticleBase::Point vertexTP;
229  double dxySim(0);
230  double dzSim(0);
231 
232 
233  //---------- THIS PART HAS TO BE CLEANED UP. THE PARAMETER DEFINER WAS NOT MEANT TO BE USED IN THIS WAY ----------
234  //If the TrackingParticle is collison like, get the momentum and vertex at production state
235  if(parametersDefiner=="LhcParametersDefinerForTP")
236  {
237  if(! tpSelector(*tp)) continue;
238  momentumTP = tp->momentum();
239  vertexTP = tp->vertex();
240  //Calcualte the impact parameters w.r.t. PCA
241  ParticleBase::Vector momentum = parametersDefinerTP->momentum(event,setup,*tp);
242  ParticleBase::Point vertex = parametersDefinerTP->vertex(event,setup,*tp);
243  dxySim = (-vertex.x()*sin(momentum.phi())+vertex.y()*cos(momentum.phi()));
244  dzSim = vertex.z() - (vertex.x()*momentum.x()+vertex.y()*momentum.y())/sqrt(momentum.perp2())
245  * momentum.z()/sqrt(momentum.perp2());
246  }
247  //If the TrackingParticle is comics, get the momentum and vertex at PCA
248  if(parametersDefiner=="CosmicParametersDefinerForTP")
249  {
250  if(! cosmictpSelector(*tp,&bs,event,setup)) continue;
251  momentumTP = parametersDefinerTP->momentum(event,setup,*tp);
252  vertexTP = parametersDefinerTP->vertex(event,setup,*tp);
253  dxySim = (-vertexTP.x()*sin(momentumTP.phi())+vertexTP.y()*cos(momentumTP.phi()));
254  dzSim = vertexTP.z() - (vertexTP.x()*momentumTP.x()+vertexTP.y()*momentumTP.y())/sqrt(momentumTP.perp2())
255  * momentumTP.z()/sqrt(momentumTP.perp2());
256  }
257  //---------- THE PART ABOVE HAS TO BE CLEANED UP. THE PARAMETER DEFINER WAS NOT MEANT TO BE USED IN THIS WAY ----------
258 
259  st++; //This counter counts the number of simulated tracks passing the MTV selection (i.e. tpSelector(tp) )
260 
261  // in the coming lines, histos are filled using as input
262  // - momentumTP
263  // - vertexTP
264  // - dxySim
265  // - dzSim
266 
267  histoProducerAlgo_->fill_generic_simTrack_histos(w,momentumTP,vertexTP);
268 
269 
270  // ##############################################
271  // fill RecoAssociated SimTracks' histograms
272  // ##############################################
273  bool isRecoMatched(false);
274  const reco::Track* matchedTrackPointer=0;
275  std::vector<std::pair<RefToBase<Track>, double> > rt;
276  if(simRecColl.find(tpr) != simRecColl.end()){
277  rt = (std::vector<std::pair<RefToBase<Track>, double> >) simRecColl[tpr];
278  if (rt.size()!=0) {
279  ats++; //This counter counts the number of simTracks that have a recoTrack associated
280  isRecoMatched = true; matchedTrackPointer = rt.begin()->first.get();
281  edm::LogVerbatim("TrackValidator") << "TrackingParticle #" << st
282  << " with pt=" << sqrt(momentumTP.perp2())
283  << " associated with quality:" << rt.begin()->second <<"\n";
284  }
285  }else{
286  edm::LogVerbatim("TrackValidator")
287  << "TrackingParticle #" << st
288  << " with pt,eta,phi: "
289  << sqrt(momentumTP.perp2()) << " , "
290  << momentumTP.eta() << " , "
291  << momentumTP.phi() << " , "
292  << " NOT associated to any reco::Track" << "\n";
293  }
294 
295 
296 
297 
298  std::vector<PSimHit> simhits=tp->trackPSimHit(DetId::Tracker);
299  int nSimHits = simhits.end()-simhits.begin();
300 
301  histoProducerAlgo_->fill_recoAssociated_simTrack_histos(w,*tp,momentumTP,vertexTP,dxySim,dzSim,nSimHits,matchedTrackPointer);
302 
303 
304 
305 
306  } // End for (TrackingParticleCollection::size_type i=0; i<tPCeff.size(); i++){
307 
308  //if (st!=0) h_tracksSIM[w]->Fill(st); // TO BE FIXED
309 
310 
311  // ##############################################
312  // fill recoTracks histograms (LOOP OVER TRACKS)
313  // ##############################################
314  edm::LogVerbatim("TrackValidator") << "\n# of reco::Tracks with "
315  << label[www].process()<<":"
316  << label[www].label()<<":"
317  << label[www].instance()
318  << ": " << trackCollection->size() << "\n";
319 
320  int at(0); //This counter counts the number of recoTracks that are associated to SimTracks
321  int rT(0); //This counter counts the number of recoTracks in general
322 
323 
324  // dE/dx
325  // at some point this could be generalized, with a vector of tags and a corresponding vector of Handles
326  // I'm writing the interface such to take vectors of ValueMaps
329  std::vector<edm::ValueMap<reco::DeDxData> > v_dEdx;
330  v_dEdx.clear();
331  //std::cout << "PIPPO: label is " << label[www] << std::endl;
332  if (label[www].label()=="generalTracks") {
333  try {
334  event.getByLabel(m_dEdx1Tag, dEdx1Handle);
335  const edm::ValueMap<reco::DeDxData> dEdx1 = *dEdx1Handle.product();
336  event.getByLabel(m_dEdx2Tag, dEdx2Handle);
337  const edm::ValueMap<reco::DeDxData> dEdx2 = *dEdx2Handle.product();
338  v_dEdx.push_back(dEdx1);
339  v_dEdx.push_back(dEdx2);
340  } catch (cms::Exception e){
341  LogTrace("TrackValidator") << "exception found: " << e.what() << "\n";
342  }
343  }
344  //end dE/dx
345 
346  for(View<Track>::size_type i=0; i<trackCollection->size(); ++i){
347  RefToBase<Track> track(trackCollection, i);
348  rT++;
349 
350  bool isSimMatched(false);
351  std::vector<std::pair<TrackingParticleRef, double> > tp;
352  if(recSimColl.find(track) != recSimColl.end()){
353  tp = recSimColl[track];
354  if (tp.size()!=0) {
355  isSimMatched = true;
356  at++;
357  edm::LogVerbatim("TrackValidator") << "reco::Track #" << rT << " with pt=" << track->pt()
358  << " associated with quality:" << tp.begin()->second <<"\n";
359  }
360  } else {
361  edm::LogVerbatim("TrackValidator") << "reco::Track #" << rT << " with pt=" << track->pt()
362  << " NOT associated to any TrackingParticle" << "\n";
363  }
364 
365 
366  histoProducerAlgo_->fill_generic_recoTrack_histos(w,*track,bs.position(),isSimMatched);
367 
368  // dE/dx
369  // reco::TrackRef track2 = reco::TrackRef( trackCollection, i );
370  if (v_dEdx.size() > 0) histoProducerAlgo_->fill_dedx_recoTrack_histos(w,track, v_dEdx);
371  //if (v_dEdx.size() > 0) histoProducerAlgo_->fill_dedx_recoTrack_histos(track2, v_dEdx);
372 
373 
374  //Fill other histos
375  //try{ //Is this really necessary ????
376 
377  if (tp.size()==0) continue;
378 
380 
381  TrackingParticleRef tpr = tp.begin()->first;
382 
383  /* TO BE FIXED LATER
384  if (associators[ww]=="TrackAssociatorByChi2"){
385  //association chi2
386  double assocChi2 = -tp.begin()->second;//in association map is stored -chi2
387  h_assochi2[www]->Fill(assocChi2);
388  h_assochi2_prob[www]->Fill(TMath::Prob((assocChi2)*5,5));
389  }
390  else if (associators[ww]=="TrackAssociatorByHits"){
391  double fraction = tp.begin()->second;
392  h_assocFraction[www]->Fill(fraction);
393  h_assocSharedHit[www]->Fill(fraction*track->numberOfValidHits());
394  }
395  */
396 
397 
398  //Get tracking particle parameters at point of closest approach to the beamline
399  ParticleBase::Vector momentumTP = parametersDefinerTP->momentum(event,setup,*(tpr.get()));
400  ParticleBase::Point vertexTP = parametersDefinerTP->vertex(event,setup,*(tpr.get()));
401  int chargeTP = tpr->charge();
402 
403  histoProducerAlgo_->fill_ResoAndPull_recoTrack_histos(w,momentumTP,vertexTP,chargeTP,
404  *track,bs.position());
405 
406 
407  //TO BE FIXED
408  //std::vector<PSimHit> simhits=tpr.get()->trackPSimHit(DetId::Tracker);
409  //nrecHit_vs_nsimHit_rec2sim[w]->Fill(track->numberOfValidHits(), (int)(simhits.end()-simhits.begin() ));
410 
411  /*
412  } // End of try{
413  catch (cms::Exception e){
414  LogTrace("TrackValidator") << "exception found: " << e.what() << "\n";
415  }
416  */
417 
418  } // End of for(View<Track>::size_type i=0; i<trackCollection->size(); ++i){
419 
420  //TO BE FIXED
421  //if (at!=0) h_tracks[w]->Fill(at);
422  //h_fakes[w]->Fill(rT-at);
423  //nrec_vs_nsim[w]->Fill(rT,st);
424 
425  edm::LogVerbatim("TrackValidator") << "Total Simulated: " << st << "\n"
426  << "Total Associated (simToReco): " << ats << "\n"
427  << "Total Reconstructed: " << rT << "\n"
428  << "Total Associated (recoToSim): " << at << "\n"
429  << "Total Fakes: " << rT-at << "\n";
430 
431  w++;
432  } // End of for (unsigned int www=0;www<label.size();www++){
433  } //END of for (unsigned int ww=0;ww<associators.size();ww++){
434 }
435 
437  int w=0;
438  for (unsigned int ww=0;ww<associators.size();ww++){
439  for (unsigned int www=0;www<label.size();www++){
443  w++;
444  }
445  }
446  if ( out.size() != 0 && dbe_ ) dbe_->save(out);
447 }
448 
449 
450 
virtual char const * what() const
Definition: Exception.cc:97
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
void endRun(edm::Run const &, edm::EventSetup const &)
Method called at the end of the event loop.
CosmicTrackingParticleSelector cosmictpSelector
const_iterator end() const
last iterator over the map (read only)
virtual void fill_dedx_recoTrack_histos(int count, edm::RefToBase< reco::Track > &trackref, std::vector< edm::ValueMap< reco::DeDxData > > v_dEdx)=0
const std::vector< PSimHit > & trackPSimHit() const
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:209
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:1898
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
const_iterator find(const key_type &k) const
find element with specified reference key
std::vector< const TrackAssociatorBase * > associator
void analyze(const edm::Event &, const edm::EventSetup &)
Method called once per event.
virtual void bookSimHistos()=0
void beginRun(edm::Run const &, edm::EventSetup const &)
Method called before the event loop.
math::XYZVectorD Vector
point in the space
Definition: ParticleBase.h:31
uint16_t size_type
virtual void bookRecoHistos()=0
virtual void fill_ResoAndPull_recoTrack_histos(int count, ParticleBase::Vector momentumTP, ParticleBase::Point vertexTP, int chargeTP, const reco::Track &track, math::XYZPoint bsPosition)=0
SingleObjectSelector< TrackingParticleCollection,::TrackingParticleSelector > TrackingParticleSelector
math::XYZPointD Point
point in the space
Definition: ParticleBase.h:29
virtual void fill_generic_recoTrack_histos(int count, const reco::Track &track, math::XYZPoint bsPosition, bool isMatched)=0
std::vector< edm::InputTag > label
T sqrt(T t)
Definition: SSEVec.h:28
double pt() const
track transverse momentum
Definition: TrackBase.h:131
TrackingParticleSelector tpSelector
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
edm::InputTag associatormap
unsigned int size_type
Definition: View.h:90
virtual void fillProfileHistosFromVectors(int counter)=0
virtual void initialize()=0
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
MultiTrackValidator(const edm::ParameterSet &pset)
Constructor.
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
#define LogTrace(id)
ObjectSelector< CosmicTrackingParticleSelector > CosmicTrackingParticleSelector
virtual void fill_generic_simTrack_histos(int counter, ParticleBase::Vector, ParticleBase::Point vertex)=0
virtual void finalHistoFits(int counter)=0
MTVHistoProducerAlgo * histoProducerAlgo_
virtual void fill_simAssociated_recoTrack_histos(int count, const reco::Track &track)=0
const T & get() const
Definition: EventSetup.h:55
virtual void fillHistosFromVectors(int counter)=0
T const * product() const
Definition: ESHandle.h:62
Vector momentum() const
spatial momentum vector
Definition: ParticleBase.h:87
T const * product() const
Definition: Handle.h:74
std::string const & label() const
Definition: InputTag.h:25
std::string const & process() const
Definition: InputTag.h:29
virtual void bookRecoHistosForStandaloneRunning()=0
void goUp(void)
equivalent to &quot;cd ..&quot;
Definition: DQMStore.cc:243
std::vector< std::string > associators
std::vector< TrackingParticle > TrackingParticleCollection
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:241
const Point & vertex() const
vertex position
Definition: ParticleBase.h:229
std::string const & instance() const
Definition: InputTag.h:26
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:232
T get(const Candidate &c)
Definition: component.h:56
Definition: Run.h:32
virtual ~MultiTrackValidator()
Destructor.
list at
Definition: asciidump.py:428
virtual void fill_recoAssociated_simTrack_histos(int count, const TrackingParticle &tp, ParticleBase::Vector momentumTP, ParticleBase::Point vertexTP, double dxy, double dz, int nSimHits, const reco::Track *track)=0