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<std::vector<int> >("pdgIdTP"));
58 
60  pset.getParameter<double>("minRapidityTP"),
61  pset.getParameter<double>("maxRapidityTP"),
62  pset.getParameter<double>("tipTP"),
63  pset.getParameter<double>("lipTP"),
64  pset.getParameter<int>("minHitTP"),
65  pset.getParameter<bool>("chargedOnlyTP"),
66  pset.getParameter<std::vector<int> >("pdgIdTP"));
67 
68  useGsf = pset.getParameter<bool>("useGsf");
69  runStandalone = pset.getParameter<bool>("runStandalone");
70 
71 
72 
73  if (!UseAssociators) {
74  associators.clear();
75  associators.push_back(associatormap.label());
76  }
77 }
78 
79 
81 
82 void MultiTrackValidator::beginRun(Run const&, EventSetup const& setup) {
83  // dbe_->showDirStructure();
84 
85  //int j=0; //is This Necessary ???
86  for (unsigned int ww=0;ww<associators.size();ww++){
87  for (unsigned int www=0;www<label.size();www++){
88  dbe_->cd();
89  InputTag algo = label[www];
90  string dirName=dirName_;
91  if (algo.process()!="")
92  dirName+=algo.process()+"_";
93  if(algo.label()!="")
94  dirName+=algo.label()+"_";
95  if(algo.instance()!="")
96  dirName+=algo.instance()+"_";
97  if (dirName.find("Tracks")<dirName.length()){
98  dirName.replace(dirName.find("Tracks"),6,"");
99  }
100  string assoc= associators[ww];
101  if (assoc.find("Track")<assoc.length()){
102  assoc.replace(assoc.find("Track"),5,"");
103  }
104  dirName+=assoc;
105  std::replace(dirName.begin(), dirName.end(), ':', '_');
106 
107  dbe_->setCurrentFolder(dirName.c_str());
108 
109  // vector of vector initialization
110  histoProducerAlgo_->initialize(); //TO BE FIXED. I'D LIKE TO AVOID THIS CALL
111 
112  dbe_->goUp(); //Is this really necessary ???
113  string subDirName = dirName + "/simulation";
114  dbe_->setCurrentFolder(subDirName.c_str());
115 
116  //Booking histograms concerning with simulated tracks
118 
119  dbe_->cd();
120  dbe_->setCurrentFolder(dirName.c_str());
121 
122  //Booking histograms concerning with reconstructed tracks
125 
126  if (UseAssociators) {
128  for (unsigned int w=0;w<associators.size();w++) {
129  setup.get<TrackAssociatorRecord>().get(associators[w],theAssociator);
130  associator.push_back( theAssociator.product() );
131  }//end loop w
132  }
133  }//end loop www
134  }// end loop ww
135 }
136 
138  using namespace reco;
139 
140  edm::LogInfo("TrackValidator") << "\n====================================================" << "\n"
141  << "Analyzing new event" << "\n"
142  << "====================================================\n" << "\n";
143  edm::ESHandle<ParametersDefinerForTP> parametersDefinerTP;
144  setup.get<TrackAssociatorRecord>().get(parametersDefiner,parametersDefinerTP);
145 
146  edm::Handle<TrackingParticleCollection> TPCollectionHeff ;
147  event.getByLabel(label_tp_effic,TPCollectionHeff);
148  const TrackingParticleCollection tPCeff = *(TPCollectionHeff.product());
149 
150  edm::Handle<TrackingParticleCollection> TPCollectionHfake ;
151  event.getByLabel(label_tp_fake,TPCollectionHfake);
152  const TrackingParticleCollection tPCfake = *(TPCollectionHfake.product());
153 
154  //if (tPCeff.size()==0) {edm::LogInfo("TrackValidator")
155  //<< "TP Collection for efficiency studies has size = 0! Skipping Event." ; return;}
156  //if (tPCfake.size()==0) {edm::LogInfo("TrackValidator")
157  //<< "TP Collection for fake rate studies has size = 0! Skipping Event." ; return;}
158 
159  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
160  event.getByLabel(bsSrc,recoBeamSpotHandle);
161  reco::BeamSpot bs = *recoBeamSpotHandle;
162 
163  int w=0; //counter counting the number of sets of histograms
164  for (unsigned int ww=0;ww<associators.size();ww++){
165  for (unsigned int www=0;www<label.size();www++){
166  //
167  //get collections from the event
168  //
170  if(!event.getByLabel(label[www], trackCollection)&&ignoremissingtkcollection_)continue;
171  //if (trackCollection->size()==0) {
172  //edm::LogInfo("TrackValidator") << "TrackCollection size = 0!" ;
173  //continue;
174  //}
175  reco::RecoToSimCollection recSimColl;
176  reco::SimToRecoCollection simRecColl;
177  //associate tracks
178  if(UseAssociators){
179  edm::LogVerbatim("TrackValidator") << "Analyzing "
180  << label[www].process()<<":"
181  << label[www].label()<<":"
182  << label[www].instance()<<" with "
183  << associators[ww].c_str() <<"\n";
184 
185  LogTrace("TrackValidator") << "Calling associateRecoToSim method" << "\n";
186  recSimColl=associator[ww]->associateRecoToSim(trackCollection,
187  TPCollectionHfake,
188  &event);
189  LogTrace("TrackValidator") << "Calling associateSimToReco method" << "\n";
190  simRecColl=associator[ww]->associateSimToReco(trackCollection,
191  TPCollectionHeff,
192  &event);
193  }
194  else{
195  edm::LogVerbatim("TrackValidator") << "Analyzing "
196  << label[www].process()<<":"
197  << label[www].label()<<":"
198  << label[www].instance()<<" with "
199  << associatormap.process()<<":"
200  << associatormap.label()<<":"
201  << associatormap.instance()<<"\n";
202 
203  Handle<reco::SimToRecoCollection > simtorecoCollectionH;
204  event.getByLabel(associatormap,simtorecoCollectionH);
205  simRecColl= *(simtorecoCollectionH.product());
206 
207  Handle<reco::RecoToSimCollection > recotosimCollectionH;
208  event.getByLabel(associatormap,recotosimCollectionH);
209  recSimColl= *(recotosimCollectionH.product());
210  }
211 
212 
213 
214  // ########################################################
215  // fill simulation histograms (LOOP OVER TRACKINGPARTICLES)
216  // ########################################################
217 
218  //compute number of tracks per eta interval
219  //
220  edm::LogVerbatim("TrackValidator") << "\n# of TrackingParticles: " << tPCeff.size() << "\n";
221  int ats(0); //This counter counts the number of simTracks that are "associated" to recoTracks
222  int st(0); //This counter counts the number of simulated tracks passing the MTV selection (i.e. tpSelector(tp) )
223  for (TrackingParticleCollection::size_type i=0; i<tPCeff.size(); i++){ //loop over TPs collection for tracking efficiency
224  TrackingParticleRef tpr(TPCollectionHeff, i);
225  TrackingParticle* tp=const_cast<TrackingParticle*>(tpr.get());
226  ParticleBase::Vector momentumTP;
227  ParticleBase::Point vertexTP;
228  double dxySim(0);
229  double dzSim(0);
230 
231 
232  //---------- THIS PART HAS TO BE CLEANED UP. THE PARAMETER DEFINER WAS NOT MEANT TO BE USED IN THIS WAY ----------
233  //If the TrackingParticle is collison like, get the momentum and vertex at production state
234  if(parametersDefiner=="LhcParametersDefinerForTP")
235  {
236  if(! tpSelector(*tp)) continue;
237  momentumTP = tp->momentum();
238  vertexTP = tp->vertex();
239  //Calcualte the impact parameters w.r.t. PCA
240  ParticleBase::Vector momentum = parametersDefinerTP->momentum(event,setup,*tp);
241  ParticleBase::Point vertex = parametersDefinerTP->vertex(event,setup,*tp);
242  dxySim = (-vertex.x()*sin(momentum.phi())+vertex.y()*cos(momentum.phi()));
243  dzSim = vertex.z() - (vertex.x()*momentum.x()+vertex.y()*momentum.y())/sqrt(momentum.perp2())
244  * momentum.z()/sqrt(momentum.perp2());
245  }
246  //If the TrackingParticle is comics, get the momentum and vertex at PCA
247  if(parametersDefiner=="CosmicParametersDefinerForTP")
248  {
249  if(! cosmictpSelector(*tp,&bs,event,setup)) continue;
250  momentumTP = parametersDefinerTP->momentum(event,setup,*tp);
251  vertexTP = parametersDefinerTP->vertex(event,setup,*tp);
252  dxySim = (-vertexTP.x()*sin(momentumTP.phi())+vertexTP.y()*cos(momentumTP.phi()));
253  dzSim = vertexTP.z() - (vertexTP.x()*momentumTP.x()+vertexTP.y()*momentumTP.y())/sqrt(momentumTP.perp2())
254  * momentumTP.z()/sqrt(momentumTP.perp2());
255  }
256  //---------- THE PART ABOVE HAS TO BE CLEANED UP. THE PARAMETER DEFINER WAS NOT MEANT TO BE USED IN THIS WAY ----------
257 
258  st++; //This counter counts the number of simulated tracks passing the MTV selection (i.e. tpSelector(tp) )
259 
260  // in the coming lines, histos are filled using as input
261  // - momentumTP
262  // - vertexTP
263  // - dxySim
264  // - dzSim
265 
266  histoProducerAlgo_->fill_generic_simTrack_histos(w,momentumTP,vertexTP);
267 
268 
269  // ##############################################
270  // fill RecoAssociated SimTracks' histograms
271  // ##############################################
272  bool isRecoMatched(false);
273  const reco::Track* matchedTrackPointer=0;
274  std::vector<std::pair<RefToBase<Track>, double> > rt;
275  if(simRecColl.find(tpr) != simRecColl.end()){
276  rt = (std::vector<std::pair<RefToBase<Track>, double> >) simRecColl[tpr];
277  if (rt.size()!=0) {
278  ats++; //This counter counts the number of simTracks that have a recoTrack associated
279  isRecoMatched = true; matchedTrackPointer = rt.begin()->first.get();
280  edm::LogVerbatim("TrackValidator") << "TrackingParticle #" << st
281  << " with pt=" << sqrt(momentumTP.perp2())
282  << " associated with quality:" << rt.begin()->second <<"\n";
283  }
284  }else{
285  edm::LogVerbatim("TrackValidator")
286  << "TrackingParticle #" << st
287  << " with pt,eta,phi: "
288  << sqrt(momentumTP.perp2()) << " , "
289  << momentumTP.eta() << " , "
290  << momentumTP.phi() << " , "
291  << " NOT associated to any reco::Track" << "\n";
292  }
293 
294 
295 
296 
297  std::vector<PSimHit> simhits=tp->trackPSimHit(DetId::Tracker);
298  int nSimHits = simhits.end()-simhits.begin();
299 
300  histoProducerAlgo_->fill_recoAssociated_simTrack_histos(w,*tp,momentumTP,vertexTP,dxySim,dzSim,nSimHits,matchedTrackPointer);
301 
302 
303 
304 
305  } // End for (TrackingParticleCollection::size_type i=0; i<tPCeff.size(); i++){
306 
307  //if (st!=0) h_tracksSIM[w]->Fill(st); // TO BE FIXED
308 
309 
310  // ##############################################
311  // fill recoTracks histograms (LOOP OVER TRACKS)
312  // ##############################################
313  edm::LogVerbatim("TrackValidator") << "\n# of reco::Tracks with "
314  << label[www].process()<<":"
315  << label[www].label()<<":"
316  << label[www].instance()
317  << ": " << trackCollection->size() << "\n";
318 
319  int at(0); //This counter counts the number of recoTracks that are associated to SimTracks
320  int rT(0); //This counter counts the number of recoTracks in general
321 
322 
323  // dE/dx
324  // at some point this could be generalized, with a vector of tags and a corresponding vector of Handles
325  // I'm writing the interface such to take vectors of ValueMaps
328  std::vector<edm::ValueMap<reco::DeDxData> > v_dEdx;
329  v_dEdx.clear();
330  //std::cout << "PIPPO: label is " << label[www] << std::endl;
331  if (label[www].label()=="generalTracks") {
332  try {
333  event.getByLabel(m_dEdx1Tag, dEdx1Handle);
334  const edm::ValueMap<reco::DeDxData> dEdx1 = *dEdx1Handle.product();
335  event.getByLabel(m_dEdx2Tag, dEdx2Handle);
336  const edm::ValueMap<reco::DeDxData> dEdx2 = *dEdx2Handle.product();
337  v_dEdx.push_back(dEdx1);
338  v_dEdx.push_back(dEdx2);
339  } catch (cms::Exception e){
340  LogTrace("TrackValidator") << "exception found: " << e.what() << "\n";
341  }
342  }
343  //end dE/dx
344 
345  for(View<Track>::size_type i=0; i<trackCollection->size(); ++i){
346  RefToBase<Track> track(trackCollection, i);
347  rT++;
348 
349  bool isSimMatched(false);
350  std::vector<std::pair<TrackingParticleRef, double> > tp;
351  if(recSimColl.find(track) != recSimColl.end()){
352  tp = recSimColl[track];
353  if (tp.size()!=0) {
354  isSimMatched = true;
355  at++;
356  edm::LogVerbatim("TrackValidator") << "reco::Track #" << rT << " with pt=" << track->pt()
357  << " associated with quality:" << tp.begin()->second <<"\n";
358  }
359  } else {
360  edm::LogVerbatim("TrackValidator") << "reco::Track #" << rT << " with pt=" << track->pt()
361  << " NOT associated to any TrackingParticle" << "\n";
362  }
363 
364 
365  histoProducerAlgo_->fill_generic_recoTrack_histos(w,*track,bs.position(),isSimMatched);
366 
367  // dE/dx
368  // reco::TrackRef track2 = reco::TrackRef( trackCollection, i );
369  if (v_dEdx.size() > 0) histoProducerAlgo_->fill_dedx_recoTrack_histos(w,track, v_dEdx);
370  //if (v_dEdx.size() > 0) histoProducerAlgo_->fill_dedx_recoTrack_histos(track2, v_dEdx);
371 
372 
373  //Fill other histos
374  //try{ //Is this really necessary ????
375 
376  if (tp.size()==0) continue;
377 
379 
380  TrackingParticleRef tpr = tp.begin()->first;
381 
382  /* TO BE FIXED LATER
383  if (associators[ww]=="TrackAssociatorByChi2"){
384  //association chi2
385  double assocChi2 = -tp.begin()->second;//in association map is stored -chi2
386  h_assochi2[www]->Fill(assocChi2);
387  h_assochi2_prob[www]->Fill(TMath::Prob((assocChi2)*5,5));
388  }
389  else if (associators[ww]=="TrackAssociatorByHits"){
390  double fraction = tp.begin()->second;
391  h_assocFraction[www]->Fill(fraction);
392  h_assocSharedHit[www]->Fill(fraction*track->numberOfValidHits());
393  }
394  */
395 
396 
397  //Get tracking particle parameters at point of closest approach to the beamline
398  ParticleBase::Vector momentumTP = parametersDefinerTP->momentum(event,setup,*(tpr.get()));
399  ParticleBase::Point vertexTP = parametersDefinerTP->vertex(event,setup,*(tpr.get()));
400  int chargeTP = tpr->charge();
401 
402  histoProducerAlgo_->fill_ResoAndPull_recoTrack_histos(w,momentumTP,vertexTP,chargeTP,
403  *track,bs.position());
404 
405 
406  //TO BE FIXED
407  //std::vector<PSimHit> simhits=tpr.get()->trackPSimHit(DetId::Tracker);
408  //nrecHit_vs_nsimHit_rec2sim[w]->Fill(track->numberOfValidHits(), (int)(simhits.end()-simhits.begin() ));
409 
410  /*
411  } // End of try{
412  catch (cms::Exception e){
413  LogTrace("TrackValidator") << "exception found: " << e.what() << "\n";
414  }
415  */
416 
417  } // End of for(View<Track>::size_type i=0; i<trackCollection->size(); ++i){
418 
419  //TO BE FIXED
420  //if (at!=0) h_tracks[w]->Fill(at);
421  //h_fakes[w]->Fill(rT-at);
422  //nrec_vs_nsim[w]->Fill(rT,st);
423 
424  edm::LogVerbatim("TrackValidator") << "Total Simulated: " << st << "\n"
425  << "Total Associated (simToReco): " << ats << "\n"
426  << "Total Reconstructed: " << rT << "\n"
427  << "Total Associated (recoToSim): " << at << "\n"
428  << "Total Fakes: " << rT-at << "\n";
429 
430  w++;
431  } // End of for (unsigned int www=0;www<label.size();www++){
432  } //END of for (unsigned int ww=0;ww<associators.size();ww++){
433 }
434 
436  int w=0;
437  for (unsigned int ww=0;ww<associators.size();ww++){
438  for (unsigned int www=0;www<label.size();www++){
442  w++;
443  }
444  }
445  if ( out.size() != 0 && dbe_ ) dbe_->save(out);
446 }
447 
448 
449 
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:214
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:1883
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
def replace
Definition: linker.py:10
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:130
TrackingParticleSelector tpSelector
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
edm::InputTag associatormap
unsigned int size_type
Definition: View.h:90
tuple pset
Definition: CrabTask.py:85
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:359
#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:248
std::vector< std::string > associators
std::vector< TrackingParticle > TrackingParticleCollection
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:239
const Point & vertex() const
vertex position
Definition: ParticleBase.h:229
std::string const & instance() const
Definition: InputTag.h:26
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:237
T get(const Candidate &c)
Definition: component.h:56
Definition: Run.h:31
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