CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ValidationMisalignedTracker.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ValidationMisalignedTracker
4 // Class: ValidationMisalignedTracker
5 //
13 //
14 // Original Author: Nicola De Filippis
15 // Created: Thu Dec 14 13:13:32 CET 2006
16 // $Id: ValidationMisalignedTracker.cc,v 1.8 2013/01/07 20:46:23 wmtan Exp $
17 //
18 //
19 
20 
22 
23 
24 // user include files
25 
29 
36 
37 //
38 // constructors and destructor
39 //
41 {
42 
43  //now do what ever initialization is needed
45  recenezmu=0., enezmu=0., pLzmu=0., recpLzmu=0.,yzmu=0.,recyzmu=0.,mxptmu=0.,recmxptmu=0., minptmu=0.,recminptmu=0.;
46  // mzele=0.,recmzele=0.
47 
48  flag=0,flagrec=0,count=0,countrec=0;
49  nAssoc=0;
50 
51  for (int i=0;i<2;i++){
52  countpart[i]=0;
53  countpartrec[i]=0;
54  for (int j=0;j<2;j++){
55  ene[i][j]=0.;
56  p[i][j]=0.;
57  px[i][j]=0.;
58  py[i][j]=0.;
59  pz[i][j]=0.;
60  ptmu[i][j]=0.;
61  recene[i][j]=0.;
62  recp[i][j]=0.;
63  recpx[i][j]=0.;
64  recpy[i][j]=0.;
65  recpz[i][j]=0.;
66  recptmu[i][j]=0.;
67  }
68  }
69 
70 
71  eventCount_ = 0;
72 
73  selection_eff = iConfig.getUntrackedParameter<bool>("selection_eff", false);
74  selection_fake = iConfig.getUntrackedParameter<bool>("selection_fake", true);
75  ZmassSelection_ = iConfig.getUntrackedParameter<bool>("ZmassSelection", false);
76  simobject = iConfig.getUntrackedParameter<std::string>("simobject","g4SimHits");
77  trackassociator = iConfig.getUntrackedParameter<std::string>("TrackAssociator","ByHits");
78  associators = iConfig.getParameter< std::vector<std::string> >("associators");
79  label = iConfig.getParameter< std::vector<edm::InputTag> >("label");
80  label_tp_effic = iConfig.getParameter< edm::InputTag >("label_tp_effic");
81  label_tp_fake = iConfig.getParameter< edm::InputTag >("label_tp_fake");
82 
83  rootfile_ = iConfig.getUntrackedParameter<std::string>("rootfile","myroot.root");
84  file_ = new TFile(rootfile_.c_str(),"RECREATE");
85 
86  // initialize the tree
87  tree_eff = new TTree("EffTracks","Efficiency Tracks Tree");
88 
89  tree_eff->Branch("Run",&irun,"irun/i");
90  tree_eff->Branch("Event",&ievt,"ievt/i");
91 
92  // SimTrack
93  tree_eff->Branch("TrackID",&trackType,"trackType/i");
94  tree_eff->Branch("pt",&pt,"pt/F");
95  tree_eff->Branch("eta",&eta,"eta/F");
96  tree_eff->Branch("CotTheta",&cottheta,"cottheta/F");
97  tree_eff->Branch("phi",&phi,"phi/F");
98  tree_eff->Branch("d0",&d0,"d0/F");
99  tree_eff->Branch("z0",&z0,"z0/F");
100  tree_eff->Branch("nhit",&nhit,"nhit/i");
101 
102  // RecTrack
103  tree_eff->Branch("recpt",&recpt,"recpt/F");
104  tree_eff->Branch("receta",&receta,"receta/F");
105  tree_eff->Branch("CotRecTheta",&reccottheta,"reccottheta/F");
106  tree_eff->Branch("recphi",&recphi,"recphi/F");
107  tree_eff->Branch("recd0",& recd0,"recd0/F");
108  tree_eff->Branch("recz0",& recz0,"recz0/F");
109  tree_eff->Branch("nAssoc",&nAssoc,"nAssoc/i");
110  tree_eff->Branch("recnhit",&recnhit,"recnhit/i");
111  tree_eff->Branch("CHISQ",&recchiq,"recchiq/F");
112 
113  tree_eff->Branch("reseta",&reseta,"reseta/F");
114  tree_eff->Branch("respt",&respt,"respt/F");
115  tree_eff->Branch("resd0",&resd0,"resd0/F");
116  tree_eff->Branch("resz0",&resz0,"resz0/F");
117  tree_eff->Branch("resphi",&resphi,"resphi/F");
118  tree_eff->Branch("rescottheta",&rescottheta,"rescottheta/F");
119  tree_eff->Branch("eff",&eff,"eff/F");
120 
121  // Invariant masses, pt of Z
122  tree_eff->Branch("mzmu",&mzmu,"mzmu/F");
123  tree_eff->Branch("ptzmu",&ptzmu,"ptzmu/F");
124  tree_eff->Branch("pLzmu",&pLzmu,"pLzmu/F");
125  tree_eff->Branch("enezmu",&enezmu,"enezmu/F");
126  tree_eff->Branch("etazmu",&etazmu,"etazmu/F");
127  tree_eff->Branch("thetazmu",&thetazmu,"thetazmu/F");
128  tree_eff->Branch("phizmu",&phizmu,"phizmu/F");
129  tree_eff->Branch("yzmu",&yzmu,"yzmu/F");
130  tree_eff->Branch("mxptmu",&mxptmu,"mxptmu/F");
131  tree_eff->Branch("minptmu",&minptmu,"minptmu/F");
132 
133  tree_eff->Branch("recmzmu",&recmzmu,"recmzmu/F");
134  tree_eff->Branch("recptzmu",&recptzmu,"recptzmu/F");
135  tree_eff->Branch("recpLzmu",&recpLzmu,"recpLzmu/F");
136  tree_eff->Branch("recenezmu",&recenezmu,"recenezmu/F");
137  tree_eff->Branch("recetazmu",&recetazmu,"recetazmu/F");
138  tree_eff->Branch("recthetazmu",&recthetazmu,"recthetazmu/F");
139  tree_eff->Branch("recphizmu",&recphizmu,"recphizmu/F");
140  tree_eff->Branch("recyzmu",&recyzmu,"recyzmu/F");
141  tree_eff->Branch("recmxptmu",&recmxptmu,"recmxptmu/F");
142  tree_eff->Branch("recminptmu",&recminptmu,"recminptmu/F");
143 
144 
145  //tree->Branch("mzele",&ntmzele,"ntmzele/F");
146  //tree->Branch("recmzele",&ntmzeleRec,"ntmzeleRec/F");
147  tree_eff->Branch("chi2Associator",&recchiq,"recchiq/F");
148 
149  // Fake
150 
151  tree_fake = new TTree("FakeTracks","Fake Rate Tracks Tree");
152 
153  tree_fake->Branch("Run",&irun,"irun/i");
154  tree_fake->Branch("Event",&ievt,"ievt/i");
155 
156  // SimTrack
157  tree_fake->Branch("fakeTrackID",&faketrackType,"faketrackType/i");
158  tree_fake->Branch("fakept",&fakept,"fakept/F");
159  tree_fake->Branch("fakeeta",&fakeeta,"fakeeta/F");
160  tree_fake->Branch("fakeCotTheta",&fakecottheta,"fakecottheta/F");
161  tree_fake->Branch("fakephi",&fakephi,"fakephi/F");
162  tree_fake->Branch("faked0",&faked0,"faked0/F");
163  tree_fake->Branch("fakez0",&fakez0,"fakez0/F");
164  tree_fake->Branch("fakenhit",&fakenhit,"fakenhit/i");
165 
166  // RecTrack
167  tree_fake->Branch("fakerecpt",&fakerecpt,"fakerecpt/F");
168  tree_fake->Branch("fakereceta",&fakereceta,"fakereceta/F");
169  tree_fake->Branch("fakeCotRecTheta",&fakereccottheta,"fakereccottheta/F");
170  tree_fake->Branch("fakerecphi",&fakerecphi,"fakerecphi/F");
171  tree_fake->Branch("fakerecd0",& fakerecd0,"fakerecd0/F");
172  tree_fake->Branch("fakerecz0",& fakerecz0,"fakerecz0/F");
173  tree_fake->Branch("fakenAssoc",&fakenAssoc,"fakenAssoc/i");
174  tree_fake->Branch("fakerecnhit",&fakerecnhit,"fakerecnhit/i");
175  tree_fake->Branch("fakeCHISQ",&fakerecchiq,"fakerecchiq/F");
176 
177  tree_fake->Branch("fakereseta",&fakereseta,"fakereseta/F");
178  tree_fake->Branch("fakerespt",&fakerespt,"fakerespt/F");
179  tree_fake->Branch("fakeresd0",&fakeresd0,"fakeresd0/F");
180  tree_fake->Branch("fakeresz0",&fakeresz0,"fakeresz0/F");
181  tree_fake->Branch("fakeresphi",&fakeresphi,"fakeresphi/F");
182  tree_fake->Branch("fakerescottheta",&fakerescottheta,"fakerescottheta/F");
183  tree_fake->Branch("fake",&fake,"fake/F");
184 
185  // Invariant masses, pt of Z
186  tree_fake->Branch("fakemzmu",&fakemzmu,"fakemzmu/F");
187  tree_fake->Branch("fakeptzmu",&fakeptzmu,"fakeptzmu/F");
188  tree_fake->Branch("fakepLzmu",&fakepLzmu,"fakepLzmu/F");
189  tree_fake->Branch("fakeenezmu",&fakeenezmu,"fakeenezmu/F");
190  tree_fake->Branch("fakeetazmu",&fakeetazmu,"fakeetazmu/F");
191  tree_fake->Branch("fakethetazmu",&fakethetazmu,"fakethetazmu/F");
192  tree_fake->Branch("fakephizmu",&fakephizmu,"fakephizmu/F");
193  tree_fake->Branch("fakeyzmu",&fakeyzmu,"fakeyzmu/F");
194  tree_fake->Branch("fakemxptmu",&fakemxptmu,"fakemxptmu/F");
195  tree_fake->Branch("fakeminptmu",&fakeminptmu,"fakeminptmu/F");
196 
197  tree_fake->Branch("fakerecmzmu",&fakerecmzmu,"fakerecmzmu/F");
198  tree_fake->Branch("fakerecptzmu",&fakerecptzmu,"fakerecptzmu/F");
199  tree_fake->Branch("fakerecpLzmu",&fakerecpLzmu,"fakerecpLzmu/F");
200  tree_fake->Branch("fakerecenezmu",&fakerecenezmu,"fakerecenezmu/F");
201  tree_fake->Branch("fakerecetazmu",&fakerecetazmu,"fakerecetazmu/F");
202  tree_fake->Branch("fakerecthetazmu",&fakerecthetazmu,"fakerecthetazmu/F");
203  tree_fake->Branch("fakerecphizmu",&fakerecphizmu,"fakerecphizmu/F");
204  tree_fake->Branch("fakerecyzmu",&fakerecyzmu,"fakerecyzmu/F");
205  tree_fake->Branch("fakerecmxptmu",&fakerecmxptmu,"fakerecmxptmu/F");
206  tree_fake->Branch("fakerecminptmu",&fakerecminptmu,"fakerecminptmu/F");
207 
208  tree_fake->Branch("fakechi2Associator",&fakerecchiq,"fakerecchiq/F");
209 
210 }
211 
212 
214 {
215 
216 
217  std::cout << "ValidationMisalignedTracker::endJob Processed " << eventCount_
218  << " events" << std::endl;
219 
220  // store the tree in the output file
221  file_->Write();
222 
223 
224  // Closing the file deletes the tree.
225  file_->Close();
226  tree_eff=0;
227  tree_fake=0;
228 }
229 
230 
231 //
232 // member functions
233 //
234 
235 // ------------ method called to for each event ------------
236 void
238 {
239  if (watchTrackAssociatorRecord_.check(iSetup)) {
240  associatore.clear();
242  for (unsigned int w=0;w<associators.size();w++) {
243  iSetup.get<TrackAssociatorRecord>().get(associators[w], theAssociator);
244  associatore.push_back( theAssociator.product() );
245  }
246  }
247 
248  edm::LogInfo("Tracker Misalignment Validation") << "\n Starting!";
249 
250  // Monte Carlo Z selection
251  skip=false;
252  std::vector<int> indmu;
253 
254  if ( selection_eff && ZmassSelection_){
256  iEvent.getByLabel("source", evt);
257  bool accepted = false;
258  bool foundmuons=false;
259  HepMC::GenEvent * myGenEvent = new HepMC::GenEvent(*(evt->GetEvent()));
260 
261  for ( HepMC::GenEvent::particle_iterator p = myGenEvent->particles_begin(); p != myGenEvent->particles_end(); ++p ) {
262  if ( !accepted && ( (*p)->pdg_id() == 23 ) && (*p)->status() == 3 ) {
263  accepted=true;
264  for( HepMC::GenVertex::particle_iterator aDaughter=(*p)->end_vertex()->particles_begin(HepMC::descendants); aDaughter !=(*p)->end_vertex()->particles_end(HepMC::descendants);aDaughter++){
265  if ( abs((*aDaughter)->pdg_id())==13) {
266  foundmuons=true;
267  if ((*aDaughter)->status()!=1 ) {
268  for( HepMC::GenVertex::particle_iterator byaDaughter=(*aDaughter)->end_vertex()->particles_begin(HepMC::descendants); byaDaughter !=(*aDaughter)->end_vertex()->particles_end(HepMC::descendants);byaDaughter++){
269  if ((*byaDaughter)->status()==1 && abs((*byaDaughter)->pdg_id())==13) {
270  indmu.push_back((*byaDaughter)->barcode());
271  std::cout << "Stable muon from Z with charge " << (*byaDaughter)->pdg_id() << " and index "<< (*byaDaughter)->barcode() << std::endl;
272  }
273  }
274  }
275  else {
276  indmu.push_back((*aDaughter)->barcode());
277  std::cout << "Stable muon from Z with charge " << (*aDaughter)->pdg_id() << " and index "<< (*aDaughter)->barcode() << std::endl;
278  }
279  }
280  }
281  if (!foundmuons){
282  std::cout << "No muons from Z ...skip event" << std::endl;
283  skip=true;
284  }
285  }
286  }
287  if ( !accepted) {
288  std::cout << "No Z particles in the event ...skip event" << std::endl;
289  skip=true;
290  }
291  }
292  else {
293  skip=false;
294  }
295 
296  //
297  // Retrieve tracker geometry from event setup
298  //
299  edm::ESHandle<TrackerGeometry> trackerGeometry;
300  iSetup.get<TrackerDigiGeometryRecord>().get( trackerGeometry );
301  auto testGeomDet = trackerGeometry->detsTOB().front();
302  std::cout << testGeomDet->position() << std::endl;
303 
304 
305  //Dump Run and Event
306  irun=iEvent.id().run();
307  ievt=iEvent.id().event();
308 
309  // Reset tree variables
310  int countpart[2]={0,0},countpartrec[2]={0,0},flag=0,flagrec=0,count=0,countrec=0;
311  //int countsim=0;
312  float ene[2][2],px[2][2],py[2][2],pz[2][2],ptmu[2][2];
313  float recene[2][2],recp[2][2],recpx[2][2],recpy[2][2],recpz[2][2],recptmu[2][2];
314 
315  for (int i=0;i<2;i++){
316  for (int j=0;j<2;j++){
317  ene[i][j]=0.;
318  px[i][j]=0.;
319  py[i][j]=0.;
320  pz[i][j]=0.;
321  ptmu[i][j]=0.;
322  recene[i][j]=0.;
323  recp[i][j]=0.;
324  recpx[i][j]=0.;
325  recpy[i][j]=0.;
326  recpz[i][j]=0.;
327  recptmu[i][j]=0.;
328  }
329  }
330 
331 
332  edm::Handle<TrackingParticleCollection> TPCollectionHeff ;
333  iEvent.getByLabel(label_tp_effic,TPCollectionHeff);
334  const TrackingParticleCollection tPCeff = *(TPCollectionHeff.product());
335 
336  edm::Handle<TrackingParticleCollection> TPCollectionHfake ;
337  iEvent.getByLabel(label_tp_fake,TPCollectionHfake);
338  const TrackingParticleCollection tPCfake = *(TPCollectionHfake.product());
339 
340 
341  int w=0;
342  for (unsigned int ww=0;ww<associators.size();ww++){
343  //
344  //get collections from the event
345  //
346 
347  edm::InputTag algo = label[0];
348 
349  edm::Handle<edm::View<reco::Track> > trackCollection;
350  iEvent.getByLabel(algo, trackCollection);
351  const edm::View<reco::Track> tC = *(trackCollection.product());
352 
353 
354  //associate tracks
355  LogTrace("TrackValidator") << "Calling associateRecoToSim method" << "\n";
356  reco::RecoToSimCollection recSimColl=associatore[ww]->associateRecoToSim(trackCollection,
357  TPCollectionHfake,
358  &iEvent,&iSetup);
359 
360  LogTrace("TrackValidator") << "Calling associateSimToReco method" << "\n";
361  reco::SimToRecoCollection simRecColl=associatore[ww]->associateSimToReco(trackCollection,
362  TPCollectionHeff,
363  &iEvent, &iSetup);
364 
365 
366 
367  //
368  //compute number of tracks per eta interval
369  //
370 
371  if (selection_eff && !skip ) {
372  std::cout << "Computing Efficiency" << std::endl;
373 
374  edm::LogVerbatim("TrackValidator") << "\n# of TrackingParticles (before cuts): " << tPCeff.size() << "\n";
375  int ats = 0;
376  int st=0;
377  for (TrackingParticleCollection::size_type i=0; i<tPCeff.size(); i++){
378 
379  // Initialize variables
380  eta = 0.,theta=0.,phi=0.,pt=0.,cottheta=0.,costheta=0.;
381  d0=0.,z0=0.;
382  nhit=0;
383  receta = 0.,rectheta = 0.,recphi = 0.,recpt = 0.,reccottheta=0.,recd0=0.,recz0=0.;
384  respt = 0.,resd0 = 0.,resz0 = 0.,reseta = 0.,resphi=0.,rescottheta=0.;
385  recchiq = 0.;
386  recnhit = 0;
387  trackType = 0;
388  eff=0;
389 
390  // typedef edm::Ref<TrackingParticleCollection> TrackingParticleRef;
391  TrackingParticleRef tp(TPCollectionHeff, i);
392  if (tp->charge()==0) continue;
393  st++;
394  //pt=sqrt(tp->momentum().perp2());
395  //eta=tp->momentum().eta();
396  //vpos=tp->vertex().perp2()));
397 
398  const SimTrack * simulatedTrack = &(*tp->g4Track_begin());
399 
401  iSetup.get<IdealMagneticFieldRecord>().get(theMF);
403  ftsAtProduction(GlobalPoint(tp->vertex().x(),tp->vertex().y(),tp->vertex().z()),
404  GlobalVector(simulatedTrack->momentum().x(),simulatedTrack->momentum().y(),simulatedTrack->momentum().z()),
405  TrackCharge(tp->charge()),
406  theMF.product());
407  TSCPBuilderNoMaterial tscpBuilder;
408  TrajectoryStateClosestToPoint tsAtClosestApproach
409  = tscpBuilder(ftsAtProduction,GlobalPoint(0,0,0));//as in TrackProducerAlgorithm
410  GlobalPoint v = tsAtClosestApproach.theState().position();
411  GlobalVector p = tsAtClosestApproach.theState().momentum();
412 
413  // double qoverpSim = tsAtClosestApproach.charge()/p.mag();
414  // double lambdaSim = M_PI/2-p.theta();
415  // double phiSim = p.phi();
416  double dxySim = (-v.x()*sin(p.phi())+v.y()*cos(p.phi()));
417  double dszSim = v.z()*p.perp()/p.mag() - (v.x()*p.x()+v.y()*p.y())/p.perp() * p.z()/p.mag();
418  d0 = float(-dxySim);
419  z0 = float(dszSim*p.mag()/p.perp());
420 
421 
422  if (abs(simulatedTrack->type())==13 && simulatedTrack->genpartIndex() != -1 ) {
423  std::cout << " TRACCIA SIM DI MUONI " << std::endl;
424  std::cout << "Gen part " << simulatedTrack->genpartIndex()<< std::endl;
425  trackType=simulatedTrack->type();
426  theta=simulatedTrack->momentum().theta();
427  costheta=cos(theta);
428  cottheta=1./tan(theta);
429 
430  eta=simulatedTrack->momentum().eta();
431  phi=simulatedTrack->momentum().phi();
432  pt=simulatedTrack->momentum().pt();
433  nhit=tp->matchedHit();
434 
435 
436  std::cout << "3) Before assoc: SimTrack of type = " << simulatedTrack->type()
437  << " ,at eta = " << eta
438  << " ,with pt at vertex = " << simulatedTrack->momentum().pt() << " GeV/c"
439  << " ,d0 =" << d0
440  << " ,z0 =" << z0
441  << " ,nhit=" << nhit
442  << std::endl;
443 
444  if ( ZmassSelection_ ){
445  if (abs(trackType)==13 && (simulatedTrack->genpartIndex()==indmu[0] || simulatedTrack->genpartIndex()==indmu[1] )) {
446  std::cout << " TRACK sim of muons from Z " << std::endl;
447  flag=0;
448  count=countpart[0];
449  countpart[0]++;
450  }
451  else if (abs(trackType)==11) {
452  //std::cout << " TRACCIA SIM DI ELETTRONI " << std::endl;
453  flag=1;
454  count=countpart[1];
455  countpart[1]++;
456  }
457 
458 
459  px[flag][count]=simulatedTrack->momentum().x();
460  py[flag][count]=simulatedTrack->momentum().y();
461  pz[flag][count]=simulatedTrack->momentum().z();
462  ptmu[flag][count]=simulatedTrack->momentum().pt();
463  ene[flag][count]=simulatedTrack->momentum().e();
464  }
465 
466 
467  std::vector<std::pair<edm::RefToBase<reco::Track>, double> > rt;
468  if(simRecColl.find(tp) != simRecColl.end()){
469 
470  rt = simRecColl[tp];
471  if (rt.size()!=0) {
472 
473  edm::RefToBase<reco::Track> t = rt.begin()->first;
474  ats++;
475 
476  // bool flagptused=false;
477  // for (unsigned int j=0;j<ptused.size();j++){
478  // if (fabs(t->pt()-ptused[j])<0.001) {
479  // flagptused=true;
480  // }
481  // }
482 
483  edm::LogVerbatim("TrackValidator") << "TrackingParticle #" << st << " with pt=" << t->pt()
484  << " associated with quality:" << rt.begin()->second <<"\n";
485  std::cout << "Reconstructed Track:" << t->pt()<< std::endl;
486  std::cout << "\tpT: " << t->pt()<< std::endl;
487  std::cout << "\timpact parameter:d0: " << t->d0()<< std::endl;
488  std::cout << "\timpact parameter:z0: " << t->dz()<< std::endl;
489  std::cout << "\tAzimuthal angle of point of closest approach:" << t->phi()<< std::endl;
490  std::cout << "\tcharge: " << t->charge()<< std::endl;
491  std::cout << "\teta: " << t->eta()<< std::endl;
492  std::cout << "\tnormalizedChi2: " << t->normalizedChi2()<< std::endl;
493 
495  recchiq=t->normalizedChi2();
496  rectheta=t->theta();
498  //receta=-log(tan(rectheta/2.));
499  receta=t->momentum().eta();
500  // reccostheta=cos(matchedrectrack->momentum().theta());
501  recphi=t->phi();
502  recpt=t->pt();
503  ptused.push_back(recpt);
504  recd0=t->d0();
505  recz0=t->dz();
506 
507  std::cout << "5) After call to associator: the best match has "
508  << recnhit << " hits, Chi2 = "
509  << recchiq << ", pt at vertex = "
510  << recpt << " GeV/c, "
511  << ", recd0 = " << recd0
512  << ", recz0= " << recz0
513  << std::endl;
514 
515 
516  respt=recpt - pt;
517  resd0=recd0-d0;
518  resz0=recz0-z0;
519  reseta=receta-eta;
520  resphi=recphi-phi;
522  eff=1;
523 
524  std::cout << "6) Transverse momentum residual=" << respt
525  << " ,d0 residual=" << resd0
526  << " ,z0 residual=" << resz0
527  << " with eff=" << eff << std::endl;
528 
529  if ( ZmassSelection_ ){
530 
531  if (abs(trackType)==13) {
532  std::cout << " TRACCIA RECO DI MUONI " << std::endl;
533  flagrec=0;
535  countpartrec[0]++;
536  }
537  else if (abs(trackType)==11) {
538  std::cout << " TRACCIA RECO DI ELETTRONI " << std::endl;
539  flagrec=1;
541  countpartrec[1]++;
542  }
543 
544  recp[flagrec][countrec]=sqrt(t->momentum().mag2());
545  recpx[flagrec][countrec]=t->momentum().x();
546  recpy[flagrec][countrec]=t->momentum().y();
547  recpz[flagrec][countrec]=t->momentum().z();
548  recptmu[flagrec][countrec]=sqrt( (t->momentum().x()*t->momentum().x()) + (t->momentum().y()*t->momentum().y()) );
549  if (abs(trackType)==13) recene[flagrec][countrec]=sqrt(recp[flagrec][countrec]*recp[flagrec][countrec]+0.105*0.105);
550  if (abs(trackType)==11) recene[flagrec][countrec]=sqrt(recp[flagrec][countrec]*recp[flagrec][countrec]+0.0005*0.0005);
551  }
552 
553  std::cout << "7) Transverse momentum reconstructed =" << recpt
554  << " at eta= " << receta
555  << " and phi= " << recphi
556  << std::endl;
557 
558  }
559  }
560  else{
561  edm::LogVerbatim("TrackValidator") << "TrackingParticle #" << st
562  << " with pt=" << sqrt(tp->momentum().perp2())
563  << " NOT associated to any reco::Track" << "\n";
564  receta =-100.;
565  recphi =-100.;
566  recpt =-100.;
567  recd0 =-100.;
568  recz0 =-100;
569  respt =-100.;
570  resd0 =-100.;
571  resz0 =-100.;
572  resphi =-100.;
573  reseta =-100.;
574  rescottheta=-100.;
575  recnhit=100;
576  recchiq=-100;
577  eff=0;
578  flagrec=100;
579  }
580 
581  std::cout << "Eff=" << eff << std::endl;
582 
583  // simulated muons
584 
585  std::cout <<"Flag is" << flag << std::endl;
586  std::cout <<"RecFlag is" << flagrec << std::endl;
587 
588  if (countpart[0]==2 && flag==0) {
589  mzmu=sqrt(
590  (ene[0][0]+ene[0][1])*(ene[0][0]+ene[0][1])-
591  (px[0][0]+px[0][1])*(px[0][0]+px[0][1])-
592  (py[0][0]+py[0][1])*(py[0][0]+py[0][1])-
593  (pz[0][0]+pz[0][1])*(pz[0][0]+pz[0][1])
594  );
595  std::cout << "Mzmu " << mzmu << std::endl;
596  ptzmu=sqrt(
597  (px[0][0]+px[0][1])*(px[0][0]+px[0][1])+
598  (py[0][0]+py[0][1])*(py[0][0]+py[0][1])
599  );
600 
601  pLzmu=pz[0][0]+pz[0][1];
602  enezmu=ene[0][0]+ene[0][1];
603  phizmu=atan2((py[0][0]+py[0][1]),(px[0][0]+px[0][1]));
604  thetazmu=atan2(ptzmu,(pz[0][0]+pz[0][1]));
605  etazmu=-log(tan(thetazmu*3.14/360.));
606  yzmu=0.5*log((enezmu+pLzmu)/(enezmu-pLzmu));
607  mxptmu=std::max( ptmu[0][0], ptmu[0][1]);
608  minptmu=std::min( ptmu[0][0], ptmu[0][1]);
609  }
610  else {
611  mzmu=-100.;
612  ptzmu=-100.;
613  pLzmu=-100.;
614  enezmu=-100.;
615  etazmu=-100.;
616  phizmu=-100.;
617  thetazmu=-100.;
618  yzmu=-100.;
619  mxptmu=-100.;
620  minptmu=-100.;
621  }
622 
623  // reconstructed muons
624  if (countpartrec[0]==2 && flagrec==0 ){
625  recmzmu=sqrt(
626  (recene[0][0]+recene[0][1])*(recene[0][0]+recene[0][1])-
627  (recpx[0][0]+recpx[0][1])*(recpx[0][0]+recpx[0][1])-
628  (recpy[0][0]+recpy[0][1])*(recpy[0][0]+recpy[0][1])-
629  (recpz[0][0]+recpz[0][1])*(recpz[0][0]+recpz[0][1])
630  );
631  std::cout << "RecMzmu " << recmzmu << std::endl;
632  recptzmu=sqrt(
633  (recpx[0][0]+recpx[0][1])*(recpx[0][0]+recpx[0][1])+
634  (recpy[0][0]+recpy[0][1])*(recpy[0][0]+recpy[0][1])
635  );
636 
637  recpLzmu=recpz[0][0]+recpz[0][1];
638  recenezmu=recene[0][0]+recene[0][1];
639  recphizmu=atan2((recpy[0][0]+recpy[0][1]),(recpx[0][0]+recpx[0][1]));
640  recthetazmu=atan2(recptzmu,(recpz[0][0]+recpz[0][1]));
641  recetazmu=-log(tan(recthetazmu*3.14/360.));
643  recmxptmu=std::max(recptmu[0][0], recptmu[0][1]);
644  recminptmu=std::min( recptmu[0][0], recptmu[0][1]);
645  }
646  else {
647  recmzmu=-100.;
648  recptzmu=-100.;
649  recpLzmu=-100.;
650  recenezmu=-100.;
651  recetazmu=-100.;
652  recphizmu=-100.;
653  recthetazmu=-100.;
654  recyzmu=-100.;
655  recmxptmu=-100;
656  recminptmu=-100.;
657  }
658 
659  tree_eff->Fill();
660 
661  } // end of loop on muons
662  } // end of loop for tracking particle
663  } // end of loop for efficiency
664 
665  //
666  // Fake Rate
667  //
668  if (selection_fake ) {
669  std::cout << "Computing Fake Rate" << std::endl;
670 
672  faked0=0.,fakez0=0.;
673  fakenhit=0;
676  fakerecchiq = 0.;
677  fakerecnhit = 0;
678  faketrackType = 0;
679  fake=0;
680 
681 
682  // int at=0;
683  int rT=0;
684  for(reco::TrackCollection::size_type i=0; i<tC.size(); ++i){
685  edm::RefToBase<reco::Track> track(trackCollection, i);
686  rT++;
687 
689  faked0=0.,fakez0=0.;
690  fakenhit=0;
693  fakerecchiq = 0.;
694  fakerecnhit = 0;
695  faketrackType = 0;
696  fake=0;
697 
699  fakerecchiq=track->normalizedChi2();
700  fakerectheta=track->theta();
702  //fakereceta=-log(tan(rectheta/2.));
703  fakereceta=track->momentum().eta();
704  // fakereccostheta=cos(track->momentum().theta());
705  fakerecphi=track->phi();
706  fakerecpt=track->pt();
707  fakerecd0=track->d0();
708  fakerecz0=track->dz();
709 
710  std::cout << "1) Before assoc: TkRecTrack at eta = " << fakereceta << std::endl;
711  std::cout << "Track number "<< i << std::endl ;
712  std::cout << "\tPT: " << track->pt()<< std::endl;
713  std::cout << "\timpact parameter:d0: " << track->d0()<< std::endl;
714  std::cout << "\timpact parameter:z0: " << track->dz()<< std::endl;
715  std::cout << "\tAzimuthal angle of point of closest approach:" << track->phi()<< std::endl;
716  std::cout << "\tcharge: " << track->charge()<< std::endl;
717  std::cout << "\teta: " << track->eta()<< std::endl;
718  std::cout << "\tnormalizedChi2: " << track->normalizedChi2()<< std::endl;
719 
720 
721  std::vector<std::pair<TrackingParticleRef, double> > tp;
722 
723  //Compute fake rate vs eta
724  if(recSimColl.find(track) != recSimColl.end()){
725  tp = recSimColl[track];
726  if (tp.size()!=0) {
727  edm::LogVerbatim("TrackValidator") << "reco::Track #" << rT << " with pt=" << track->pt()
728  << " associated with quality:" << tp.begin()->second <<"\n";
729 
730 
731  TrackingParticleRef tpr = tp.begin()->first;
732  const SimTrack * fakeassocTrack = &(*tpr->g4Track_begin());
733 
735  iSetup.get<IdealMagneticFieldRecord>().get(theMF);
737  ftsAtProduction(GlobalPoint(tpr->vertex().x(),tpr->vertex().y(),tpr->vertex().z()),
738  GlobalVector(fakeassocTrack->momentum().x(),fakeassocTrack->momentum().y(),fakeassocTrack->momentum().z()),
739  TrackCharge(tpr->charge()),
740  theMF.product());
741  TSCPBuilderNoMaterial tscpBuilder;
742  TrajectoryStateClosestToPoint tsAtClosestApproach
743  = tscpBuilder(ftsAtProduction,GlobalPoint(0,0,0));//as in TrackProducerAlgorithm
744  GlobalPoint v = tsAtClosestApproach.theState().position();
745  GlobalVector p = tsAtClosestApproach.theState().momentum();
746 
747  // double qoverpSim = tsAtClosestApproach.charge()/p.mag();
748  // double lambdaSim = M_PI/2-p.theta();
749  // double phiSim = p.phi();
750  double dxySim = (-v.x()*sin(p.phi())+v.y()*cos(p.phi()));
751  double dszSim = v.z()*p.perp()/p.mag() - (v.x()*p.x()+v.y()*p.y())/p.perp() * p.z()/p.mag();
752  faked0 = float(-dxySim);
753  fakez0 = float(dszSim*p.mag()/p.perp());
754 
755 
756  faketrackType=fakeassocTrack->type();
757  faketheta=fakeassocTrack->momentum().theta();
759  fakeeta=fakeassocTrack->momentum().eta();
760  fakephi=fakeassocTrack->momentum().phi();
761  fakept=fakeassocTrack->momentum().pt();
762  fakenhit=tpr->matchedHit();
763 
764  std::cout << "4) After call to associator: the best SimTrack match is of type" << fakeassocTrack->type()
765  << " ,at eta = " << fakeeta
766  << " and phi = " << fakephi
767  << " ,with pt at vertex = " << fakept << " GeV/c"
768  << " ,d0 global = " << faked0
769  << " ,z0 = " << fakez0
770  << std::endl;
771  fake=1;
772 
779 
780  }
781  }
782  else{
783  edm::LogVerbatim("TrackValidator") << "reco::Track #" << rT << " with pt=" << track->pt()
784  << " NOT associated to any TrackingParticle" << "\n";
785 
786  fakeeta =-100.;
787  faketheta=-100;
788  fakephi =-100.;
789  fakept =-100.;
790  faked0 =-100.;
791  fakez0 =-100;
792  fakerespt =-100.;
793  fakeresd0 =-100.;
794  fakeresz0 =-100.;
795  fakeresphi =-100.;
796  fakereseta =-100.;
797  fakerescottheta=-100.;
798  fakenhit=100;
799  fake=0;
800  }
801 
802  tree_fake->Fill();
803  }
804 
805  } // End of loop on fakerate
806 
807  w++;
808 
809  } // End of loop on associators
810 }
811 
812 // ------------ method called once each job just after ending the event loop ------------
814 
815  std::cout << "\t Misalignment analysis completed \n" << std::endl;
816 
817 }
818 
RunNumber_t run() const
Definition: EventID.h:42
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
T perp() const
Definition: PV3DBase.h:72
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:148
double d0() const
dxy parameter in perigee convention (d0 = - dxy)
Definition: TrackBase.h:121
std::vector< TrackingParticle > TrackingParticleCollection
const_iterator end() const
last iterator over the map (read only)
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
Definition: TrackBase.h:109
const FreeTrajectoryState & theState() const
double theta() const
polar angle
Definition: TrackBase.h:115
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void analyze(const edm::Event &, const edm::EventSetup &)
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
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:63
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:137
uint16_t size_type
ValidationMisalignedTracker(const edm::ParameterSet &)
int TrackCharge
Definition: TrackCharge.h:4
int iEvent
Definition: GenABIO.cc:230
T mag() const
Definition: PV3DBase.h:67
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:139
const T & max(const T &a, const T &b)
T sqrt(T t)
Definition: SSEVec.h:48
double pt() const
track transverse momentum
Definition: TrackBase.h:129
T z() const
Definition: PV3DBase.h:64
int genpartIndex() const
index of the corresponding Generator particle in the Event container (-1 if no Genpart) ...
Definition: SimTrack.h:33
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:230
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
GlobalVector momentum() const
#define LogTrace(id)
std::vector< std::string > associators
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:125
std::vector< edm::InputTag > label
GlobalPoint position() const
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
size_type size() const
T const * product() const
Definition: Handle.h:81
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:58
edm::EventID id() const
Definition: EventBase.h:56
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:25
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:22
tuple cout
Definition: gather_cfg.py:121
int charge() const
track electric charge
Definition: TrackBase.h:111
T w() const
T x() const
Definition: PV3DBase.h:62
edm::ESHandle< MagneticField > theMF
edm::ESWatcher< TrackAssociatorRecord > watchTrackAssociatorRecord_
Global3DVector GlobalVector
Definition: GlobalVector.h:10
std::vector< const TrackAssociatorBase * > associatore