CMS 3D CMS Logo

SiStripLAProfileBooker.cc
Go to the documentation of this file.
1 /* VI Janurary 2012
2  * This file need to be migrated to the new interface of matched hit as the mono/stero are not there anymore
3  * what is returned are hits w/o localpoistion, just cluster and id
4  */
5 #include <string>
6 #include <iostream>
7 #include <fstream>
8 
9 
13 
19 
24 
34 
39 
43 
44 #include <TProfile.h>
45 #include <TStyle.h>
46 #include <TF1.h>
47 
48 #include<list>
49 
50 class DetIdLess {
51 public:
52 
53  DetIdLess() {}
54 
55  bool operator()( const SiStripRecHit2D* a, const SiStripRecHit2D* b) const {
56  return *(a->cluster())<*(b->cluster());
57  }
58 };
59 
60 
61  //Constructor
62 
64  conf_(conf)
65 {
66 }
67 
68  //BeginRun
69 
71 
72  //Retrieve tracker topology from geometry
74  c.get<TrackerTopologyRcd>().get(tTopoHandle);
75  const TrackerTopology* const tTopo = tTopoHandle.product();
76 
77  //get magnetic field and geometry from ES
79  c.get<IdealMagneticFieldRecord>().get(esmagfield);
80  const MagneticField * magfield=&(*esmagfield);
81 
83  c.get<TrackerDigiGeometryRecord>().get(estracker);
84  tracker=&(*estracker);
85 
86  std::vector<uint32_t> activeDets;
87  edm::ESHandle<SiStripDetCabling> tkmechstruct=nullptr;
88  if (conf_.getParameter<bool>("UseStripCablingDB")){
89  c.get<SiStripDetCablingRcd>().get(tkmechstruct);
90  activeDets.clear();
91  tkmechstruct->addActiveDetectorsRawIds(activeDets);
92  }
93  else {
94  const TrackerGeometry::DetIdContainer& Id = estracker->detIds();
95  TrackerGeometry::DetIdContainer::const_iterator Iditer;
96  activeDets.clear();
97  for(Iditer=Id.begin();Iditer!=Id.end();Iditer++){
98  activeDets.push_back(Iditer->rawId());
99  }
100  }
101 
102  edm::InputTag TkTag = conf_.getParameter<edm::InputTag>("Tracks");
103  //Get Ids;
104  double ModuleRangeMin=conf_.getParameter<double>("ModuleXMin");
105  double ModuleRangeMax=conf_.getParameter<double>("ModuleXMax");
106  double TIBRangeMin=conf_.getParameter<double>("TIBXMin");
107  double TIBRangeMax=conf_.getParameter<double>("TIBXMax");
108  double TOBRangeMin=conf_.getParameter<double>("TOBXMin");
109  double TOBRangeMax=conf_.getParameter<double>("TOBXMax");
110  int TIB_bin=conf_.getParameter<int>("TIB_bin");
111  int TOB_bin=conf_.getParameter<int>("TOB_bin");
112  int SUM_bin=conf_.getParameter<int>("SUM_bin");
113 
114  hFile = new TFile (conf_.getUntrackedParameter<std::string>("treeName").c_str(), "RECREATE" );
115 
116  Hit_Tree = hFile->mkdir("Hit_Tree");
117  Track_Tree = hFile->mkdir("Track_Tree");
118  Event_Tree = hFile->mkdir("Event_Tree");
119 
120  HitsTree = new TTree("HitsTree", "HitsTree");
121 
122  HitsTree->Branch("RunNumber", &RunNumber, "RunNumber/I");
123  HitsTree->Branch("EventNumber", &EventNumber, "EventNumber/I");
124  HitsTree->Branch("TanTrackAngle", &TanTrackAngle, "TanTrackAngle/F");
125  HitsTree->Branch("TanTrackAngleParallel", &TanTrackAngleParallel, "TanTrackAngleParallel/F");
126  HitsTree->Branch("ClSize", &ClSize, "ClSize/I");
127  HitsTree->Branch("HitCharge", &HitCharge, "HitCharge/I");
128  HitsTree->Branch("Hit_Std_Dev", &hit_std_dev, "hit_std_dev/F");
129  HitsTree->Branch("Type", &Type, "Type/I");
130  HitsTree->Branch("Layer", &Layer, "Layer/I");
131  HitsTree->Branch("Wheel", &Wheel, "Wheel/I");
132  HitsTree->Branch("bw_fw", &bw_fw, "bw_fw/I");
133  HitsTree->Branch("Ext_Int", &Ext_Int, "Ext_Int/I");
134  HitsTree->Branch("MonoStereo", &MonoStereo, "MonoStereo/I");
135  HitsTree->Branch("MagField", &MagField, "MagField/F");
136  HitsTree->Branch("SignCorrection", &SignCorrection, "SignCorrection/F");
137  HitsTree->Branch("XGlobal", &XGlobal, "XGlobal/F");
138  HitsTree->Branch("YGlobal", &YGlobal, "YGlobal/F");
139  HitsTree->Branch("ZGlobal", &ZGlobal, "ZGlobal/F");
140  HitsTree->Branch("ParticleCharge", &ParticleCharge, "ParticleCharge/I");
141  HitsTree->Branch("Momentum", &Momentum, "Momentum/F");
142  HitsTree->Branch("pt", &pt, "pt/F");
143  HitsTree->Branch("chi2norm", &chi2norm, "chi2norm/F");
144  HitsTree->Branch("EtaTrack", &EtaTrack, "EtaTrack/F");
145  HitsTree->Branch("PhiTrack", &PhiTrack, "PhiTrack/F");
146  HitsTree->Branch("TrajSize", &trajsize, "trajsize/I");
147  HitsTree->Branch("HitNr", &HitNr, "HitNr/I");
148  HitsTree->Branch("HitPerTrack", &HitPerTrack, "HitPerTrack/I");
149  HitsTree->Branch("id_detector", &id_detector, "id_detector/I");
150  HitsTree->Branch("thick_detector", &thick_detector, "thick_detector/F");
151  HitsTree->Branch("pitch_detector", &pitch_detector, "pitch_detector/F");
152  HitsTree->Branch("Amplitudes", Amplitudes, "Amplitudes[ClSize]/I");
153 
154  HitsTree->SetDirectory(Hit_Tree);
155 
156  TrackTree = new TTree("TrackTree", "TrackTree");
157 
158  TrackTree->Branch("TrackCounter", &TrackCounter, "TrackCounter/I");
159 
160  TrackTree->SetDirectory(Track_Tree);
161 
162  EventTree = new TTree("EventTree", "EventTree");
163 
164  EventTree->Branch("EventCounter", &EventCounter, "EventCounter/I");
165 
166  EventTree->SetDirectory(Event_Tree);
167 
168 
169  // use SistripHistoId for producing histogram id (and title)
170  SiStripHistoId hidmanager;
171 
172  // create SiStripFolderOrganizer
173  SiStripFolderOrganizer folder_organizer;
174 
176 
177  //get all detids
178 
179  for(std::vector<uint32_t>::const_iterator Id = activeDets.begin(); Id!=activeDets.end(); Id++){
180 
181  // for(Iditer=Id.begin();Iditer!=Id.end();Iditer++){ //loop on detids
182  DetId Iditero=DetId(*Id);
183  DetId *Iditer=&Iditero;
184  if((Iditer->subdetId() == int(StripSubdetector::TIB)) || (Iditer->subdetId() == int(StripSubdetector::TOB))){ //include only barrel
185 
186  int module_bin = 0;
187  if(Iditer->subdetId() == int(StripSubdetector::TIB)){
188  module_bin = TIB_bin;
189  }else{
190  module_bin = TOB_bin;
191  }
192 
193  // create a TProfile for each module
194  StripSubdetector subid(*Iditer);
195  std::string hid;
196  //Mono single sided detectors
197  LocalPoint p;
198  auto stripdet = tracker->idToDet(subid);
199  if(!stripdet->isLeaf())continue;
200  const StripTopology& topol=(const StripTopology&)stripdet->topology();
201  float thickness=stripdet->specificSurface().bounds().thickness();
202 
203  folder_organizer.setDetectorFolder(Iditer->rawId(), tTopo);
204  hid = hidmanager.createHistoId(TkTag.label(),"det",Iditer->rawId());
205  MonitorElement * profile=dbe_->bookProfile(hid,hid,module_bin,ModuleRangeMin,ModuleRangeMax,20,0,5,"");
206  detparameters *param=new detparameters;
207  histos[Iditer->rawId()] = profile;
208  detmap[Iditer->rawId()] = param;
209  param->thickness = thickness*10000;
210  param->pitch = topol.localPitch(p)*10000;
211 
212  const GlobalPoint globalp = (stripdet->surface()).toGlobal(p);
213  GlobalVector globalmagdir = magfield->inTesla(globalp);
214  param->magfield=(stripdet->surface()).toLocal(globalmagdir);
215 
216  profile->setAxisTitle("tan(#theta_{t})",1);
217  profile->setAxisTitle("Cluster size",2);
218 
219  // create a summary histo if it does not exist already
221  unsigned int layerid;
222  getlayer(subid,tTopo,name,layerid);
223  name+=TkTag.label();
224  if(summaryhisto.find(layerid)==(summaryhisto.end())){
225  folder_organizer.setSiStripFolder();
226  MonitorElement * summaryprofile=nullptr;
228  summaryprofile=dbe_->bookProfile(name,name,SUM_bin,TIBRangeMin,TIBRangeMax,20,0,5,"");
229  else if (subid.subdetId()==int (StripSubdetector::TOB)||subid.subdetId()==int (StripSubdetector::TEC))
230  summaryprofile=dbe_->bookProfile(name,name,SUM_bin,TOBRangeMin,TOBRangeMax,20,0,5,"");
231  if(summaryprofile){
232  detparameters *summaryparam=new detparameters;
233  summaryhisto[layerid] = summaryprofile;
234  summarydetmap[layerid] = summaryparam;
235  summaryparam->thickness = thickness*10000;
236  summaryparam->pitch = topol.localPitch(p)*10000;
237  summaryprofile->setAxisTitle("tan(#theta_{t})",1);
238  summaryprofile->setAxisTitle("Cluster size",2);
239  }
240  }
241 
242  }
243  }
244 
245  trackcollsize = 0;
246  trajsize = 0;
247  RunNumber = 0;
248  EventNumber = 0;
249  hitcounter = 0;
250  hitcounter_2ndloop = 0;
251  worse_double_hit = 0;
252  better_double_hit = 0;
253  eventcounter = 0;
254 
255  EventCounter = 1;
256  TrackCounter = 1;
257 
258 }
259 
261  detparmap::iterator detpariter;
262  for( detpariter=detmap.begin(); detpariter!=detmap.end();++detpariter)delete detpariter->second;
263  for( detpariter=summarydetmap.begin(); detpariter!=summarydetmap.end();++detpariter)delete detpariter->second;
264  delete hFile;
265 }
266 
267 // Analyzer: Functions that gets called by framework every event
268 
270 {
271  //Retrieve tracker topology from geometry
272  edm::ESHandle<TrackerTopology> tTopoHandle;
273  es.get<TrackerTopologyRcd>().get(tTopoHandle);
274  const TrackerTopology* const tTopo = tTopoHandle.product();
275 
276  RunNumber = e.id().run();
277  EventNumber = e.id().event();
278 
279  eventcounter++;
280 
281  EventTree->Fill();
282 
283  //Analysis of Trajectory-RecHits
284 
285  edm::InputTag TkTag = conf_.getParameter<edm::InputTag>("Tracks");
286 
288  e.getByLabel(TkTag,trackCollection);
289 
291  e.getByLabel(TkTag,TrajectoryCollection);
292 
294  e.getByLabel(TkTag, TrajTrackMap);
295 
296  const reco::TrackCollection *tracks=trackCollection.product();
297 
298  // FIXME this has to be changed to use pointers to clusters...
299  std::map<const SiStripRecHit2D*,std::pair<float,float>,DetIdLess> hitangleassociation;
300  std::list<SiStripRecHit2D> cache; // ugly, inefficient, effective in making the above working
301 
302  trackcollsize=tracks->size();
303  trajsize=TrajectoryCollection->size();
304 
305  edm::LogInfo("SiStripLAProfileBooker::analyze") <<" Number of tracks in event = "<<trackcollsize<<"\n";
306  edm::LogInfo("SiStripLAProfileBooker::analyze") <<" Number of trajectories in event = "<<trajsize<<"\n";
307 
309 
310  for(TrajTrackIter = TrajTrackMap->begin(); TrajTrackIter!= TrajTrackMap->end(); TrajTrackIter++){ //loop on trajectories
311 
312  if(TrajTrackIter->key->foundHits()>=5){
313 
314  TrackTree->Fill();
315 
316  ParticleCharge = -99;
317  Momentum = -99;
318  pt = -99;
319  chi2norm = -99;
320  HitPerTrack = -99;
321  EtaTrack = -99;
322  PhiTrack = -99;
323 
324  ParticleCharge = TrajTrackIter->val->charge();
325  pt = TrajTrackIter->val->pt();
326  Momentum = TrajTrackIter->val->p();
327  chi2norm = TrajTrackIter->val->normalizedChi2();
328  EtaTrack = TrajTrackIter->val->eta();
329  PhiTrack = TrajTrackIter->val->phi();
330  HitPerTrack = TrajTrackIter->key->foundHits();
331 
332  std::vector<TrajectoryMeasurement> TMeas=TrajTrackIter->key->measurements();
333  std::vector<TrajectoryMeasurement>::iterator itm;
334 
335  for (itm=TMeas.begin();itm!=TMeas.end();itm++){ //loop on hits
336 
337  int i;
338  for(i=0;i<100;i++){Amplitudes[i]=0;}
339 
340  TanTrackAngle = -99;
342  ClSize = -99;
343  HitCharge = 0;
344  Type = -99;
345  Layer = -99;
346  Wheel = -99;
347  bw_fw = -99;
348  Ext_Int = -99;
349  MonoStereo = -99;
350  MagField = -99;
351  SignCorrection = -99;
352  XGlobal = -99;
353  YGlobal = -99;
354  ZGlobal = -99;
355  barycenter = -99;
356  hit_std_dev = -99;
357  sumx = 0;
358  id_detector=-1;
359  thick_detector=-1;
360  pitch_detector=-1;
361  HitNr = 1;
362 
363  SiStripRecHit2D lhit;
364  TrajectoryStateOnSurface tsos=itm->updatedState();
365  const TransientTrackingRecHit::ConstRecHitPointer thit=itm->recHit();
366  if((thit->geographicalId().subdetId() == int(StripSubdetector::TIB)) || thit->geographicalId().subdetId()== int(StripSubdetector::TOB)){ //include only barrel
367  const SiStripMatchedRecHit2D* matchedhit=dynamic_cast<const SiStripMatchedRecHit2D*>((*thit).hit());
368  const ProjectedSiStripRecHit2D* phit=dynamic_cast<const ProjectedSiStripRecHit2D*>((*thit).hit());
369  const SiStripRecHit2D* hit=dynamic_cast<const SiStripRecHit2D*>((*thit).hit());
370  if(phit) {lhit = phit->originalHit(); hit = &lhit;}
371 
372  LocalVector trackdirection=tsos.localDirection();
373 
374  if(matchedhit){//if matched hit...
375 
376  GluedGeomDet * gdet=(GluedGeomDet *)tracker->idToDet(matchedhit->geographicalId());
377 
378  GlobalVector gtrkdir=gdet->toGlobal(trackdirection);
379 
380  // THIS THE POINTER TO THE MONO HIT OF A MATCHED HIT
381 
382  // top be migrated to the more direct interface of matchedhit
383  cache.push_back(matchedhit->monoHit());
384  const SiStripRecHit2D * monohit = &cache.back();
385  const SiStripRecHit2D::ClusterRef & monocluster=monohit->cluster();
386  const GeomDetUnit * monodet=gdet->monoDet();
387  // this does not exists anymore! either project the matched or use CPE
388  const LocalPoint monoposition = monohit->localPosition();
389 
391  id_detector = detid.rawId();
393  const StripTopology& mtopol=(StripTopology&)monodet->topology();
394  pitch_detector = mtopol.localPitch(monoposition);
395  const GlobalPoint monogposition = (monodet->surface()).toGlobal(monoposition);
396  ClSize = (monocluster->amplitudes()).size();
397 
398  const auto & amplitudes = monocluster->amplitudes();
399 
400  barycenter = monocluster->barycenter()- 0.5;
401  uint16_t FirstStrip = monocluster->firstStrip();
402  auto begin=amplitudes.begin();
403  nstrip=0;
404  for(auto idigi=begin; idigi!=amplitudes.end(); idigi++){
405  Amplitudes[nstrip]=*idigi;
406  sumx+=pow(((FirstStrip+idigi-begin)-barycenter),2)*(*idigi);
407  HitCharge+=*idigi;
408  }
410 
411 
412  XGlobal = monogposition.x();
413  YGlobal = monogposition.y();
414  ZGlobal = monogposition.z();
415 
416  Type = detid.subdetId();
417  MonoStereo=detid.stereo();
418 
419  if(detid.subdetId() == int (StripSubdetector::TIB)){
420 
421  Layer = tTopo->tibLayer(detid);
422  bw_fw = tTopo->tibStringInfo(detid)[0];
423  Ext_Int = tTopo->tibStringInfo(detid)[1];
424  }
425  if(detid.subdetId() == int (StripSubdetector::TOB)){
426 
427  Layer = tTopo->tobLayer(detid);
428  bw_fw = tTopo->tobRodInfo(detid)[0];
429  }
430  if(detid.subdetId() == int (StripSubdetector::TID)){
431 
432  Wheel = tTopo->tidWheel(detid);
433  bw_fw = tTopo->tidModuleInfo(detid)[0];
434  }
435  if(detid.subdetId() == int (StripSubdetector::TEC)){
436 
437  Wheel = tTopo->tecWheel(detid);
438  bw_fw = tTopo->tecPetalInfo(detid)[0];
439  }
440 
441 
442  LocalVector monotkdir=monodet->toLocal(gtrkdir);
443 
444  if(monotkdir.z()!=0){
445 
446  // THE LOCAL ANGLE (MONO)
447  float tanangle = monotkdir.x()/monotkdir.z();
448  TanTrackAngleParallel = monotkdir.y()/monotkdir.z();
449  TanTrackAngle = tanangle;
450  detparmap::iterator TheDet=detmap.find(detid.rawId());
451  LocalVector localmagdir;
452  if(TheDet!=detmap.end())localmagdir=TheDet->second->magfield;
453  MagField = localmagdir.mag();
454  if(MagField != 0.){
455  LocalVector monoylocal(0,1,0);
456  float signcorrection = (localmagdir * monoylocal)/(MagField);
457  if(signcorrection!=0)SignCorrection=1/signcorrection;
458  }
459 
460  std::map<const SiStripRecHit2D *,std::pair<float,float>,DetIdLess>::iterator alreadystored=hitangleassociation.find(monohit);
461 
462 
463  if(alreadystored != hitangleassociation.end()){//decide which hit take
464  if(itm->estimate() > alreadystored->second.first){
465  worse_double_hit++;}
466  if(itm->estimate() < alreadystored->second.first){
468  hitangleassociation.insert(std::make_pair(monohit, std::make_pair(itm->estimate(),tanangle)));
469 
470  }}
471  else{
472  hitangleassociation.insert(make_pair(monohit, std::make_pair(itm->estimate(),tanangle)));
473  HitsTree->Fill();
474  hitcounter++;}
475 
476  // THIS THE POINTER TO THE STEREO HIT OF A MATCHED HIT
477 
478  // top be migrated to the more direct interface of matchedhit
479  cache.push_back(matchedhit->stereoHit());
480  const SiStripRecHit2D * stereohit = &cache.back();
481  const SiStripRecHit2D::ClusterRef & stereocluster=stereohit->cluster();
482  const GeomDetUnit * stereodet=gdet->stereoDet();
483  // this does not exists anymore! either project the matched or use CPE
484  const LocalPoint stereoposition = stereohit->localPosition();
486  id_detector = detid.rawId();
488  const StripTopology& stopol=(StripTopology&)stereodet->topology();
489  pitch_detector = stopol.localPitch(stereoposition);
490  const GlobalPoint stereogposition = (stereodet->surface()).toGlobal(stereoposition);
491 
492  ClSize = (stereocluster->amplitudes()).size();
493 
494  const auto & amplitudes = stereocluster->amplitudes();
495 
496  barycenter = stereocluster->barycenter()- 0.5;
497  uint16_t FirstStrip = stereocluster->firstStrip();
498  auto begin=amplitudes.begin();
499  nstrip=0;
500  for(auto idigi=begin; idigi!=amplitudes.end(); idigi++){
501  Amplitudes[nstrip]=*idigi;
502  sumx+=pow(((FirstStrip+idigi-begin)-barycenter),2)*(*idigi);
503  HitCharge+=*idigi;
504  }
506 
507  XGlobal = stereogposition.x();
508  YGlobal = stereogposition.y();
509  ZGlobal = stereogposition.z();
510 
511  Type = detid.subdetId();
512  MonoStereo=detid.stereo();
513 
514  if(detid.subdetId() == int (StripSubdetector::TIB)){
515 
516  Layer = tTopo->tibLayer(detid);
517  bw_fw = tTopo->tibStringInfo(detid)[0];
518  Ext_Int = tTopo->tibStringInfo(detid)[1];
519  }
520  if(detid.subdetId() == int (StripSubdetector::TOB)){
521 
522  Layer = tTopo->tobLayer(detid);
523  bw_fw = tTopo->tobRodInfo(detid)[0];
524  }
525  if(detid.subdetId() == int (StripSubdetector::TID)){
526 
527  Wheel = tTopo->tidWheel(detid);
528  bw_fw = tTopo->tidModuleInfo(detid)[0];
529  }
530  if(detid.subdetId() == int (StripSubdetector::TEC)){
531 
532  Wheel = tTopo->tecWheel(detid);
533  bw_fw = tTopo->tecPetalInfo(detid)[0];
534  }
535 
536 
537  LocalVector stereotkdir=stereodet->toLocal(gtrkdir);
538 
539  if(stereotkdir.z()!=0){
540 
541  // THE LOCAL ANGLE (STEREO)
542  float tanangle = stereotkdir.x()/stereotkdir.z();
543  TanTrackAngleParallel = stereotkdir.y()/stereotkdir.z();
544  TanTrackAngle = tanangle;
545  detparmap::iterator TheDet=detmap.find(detid.rawId());
546  LocalVector localmagdir;
547  if(TheDet!=detmap.end())localmagdir=TheDet->second->magfield;
548  MagField = localmagdir.mag();
549  LocalVector stereoylocal(0,1,0);
550  if(MagField != 0.){
551  float signcorrection = (localmagdir * stereoylocal)/(MagField);
552  if(signcorrection!=0)SignCorrection=1/signcorrection;}
553 
554  std::map<const SiStripRecHit2D *,std::pair<float,float>,DetIdLess>::iterator alreadystored=hitangleassociation.find(stereohit);
555 
556  if(alreadystored != hitangleassociation.end()){//decide which hit take
557  if(itm->estimate() > alreadystored->second.first){
558  worse_double_hit++;}
559  if(itm->estimate() < alreadystored->second.first){
561  hitangleassociation.insert(std::make_pair(stereohit, std::make_pair(itm->estimate(),tanangle)));
562 
563  }}
564  else{
565  hitangleassociation.insert(std::make_pair(stereohit, std::make_pair(itm->estimate(),tanangle)));
566  HitsTree->Fill();
567  hitcounter++;}
568 
569  }
570  }
571  }
572  else if(hit){
573 
574 
575  // hit= POINTER TO THE RECHIT
576 
577  const SiStripRecHit2D::ClusterRef & cluster=hit->cluster();
578 
580  const LocalPoint position = hit->localPosition();
582  id_detector = detid.rawId();
584  const StripTopology& topol=(StripTopology&)gdet->topology();
585  pitch_detector = topol.localPitch(position);
586  const GlobalPoint gposition = (gdet->surface()).toGlobal(position);
587 
588  ClSize = (cluster->amplitudes()).size();
589 
590  const auto & amplitudes = cluster->amplitudes();
591 
592  barycenter = cluster->barycenter()- 0.5;
593  uint16_t FirstStrip = cluster->firstStrip();
594  nstrip=0;
595  auto begin =amplitudes.begin();
596  for(auto idigi=amplitudes.begin(); idigi!=amplitudes.end(); idigi++){
597  Amplitudes[nstrip]=*idigi;
598  sumx+=pow(((FirstStrip+idigi-begin)-barycenter),2)*(*idigi);
599  HitCharge+=*idigi;
600  }
602 
603  XGlobal = gposition.x();
604  YGlobal = gposition.y();
605  ZGlobal = gposition.z();
606 
607  Type = detid.subdetId();
608  MonoStereo=detid.stereo();
609 
610  if(detid.subdetId() == int (StripSubdetector::TIB)){
611 
612  Layer = tTopo->tibLayer(detid);
613  bw_fw = tTopo->tibStringInfo(detid)[0];
614  Ext_Int = tTopo->tibStringInfo(detid)[1];
615  }
616  if(detid.subdetId() == int (StripSubdetector::TOB)){
617 
618  Layer = tTopo->tobLayer(detid);
619  bw_fw = tTopo->tobRodInfo(detid)[0];
620  }
621  if(detid.subdetId() == int (StripSubdetector::TID)){
622 
623  Wheel = tTopo->tidWheel(detid);
624  bw_fw = tTopo->tidModuleInfo(detid)[0];
625  }
626  if(detid.subdetId() == int (StripSubdetector::TEC)){
627 
628  Wheel = tTopo->tecWheel(detid);
629  bw_fw = tTopo->tecPetalInfo(detid)[0];
630  }
631 
632  if(trackdirection.z()!=0){
633 
634  // THE LOCAL ANGLE
635  float tanangle = trackdirection.x()/trackdirection.z();
636  TanTrackAngleParallel = trackdirection.y()/trackdirection.z();
637  TanTrackAngle = tanangle;
638  detparmap::iterator TheDet=detmap.find(detid.rawId());
639  LocalVector localmagdir;
640  if(TheDet!=detmap.end())localmagdir=TheDet->second->magfield;
641  MagField = localmagdir.mag();
642  if(MagField != 0.){
643  LocalVector ylocal(0,1,0);
644  float signcorrection = (localmagdir * ylocal)/(MagField);
645  if(signcorrection!=0)SignCorrection=1/signcorrection;}
646 
647  std::map<const SiStripRecHit2D *,std::pair<float,float>, DetIdLess>::iterator alreadystored=hitangleassociation.find(hit);
648 
649  if(alreadystored != hitangleassociation.end()){//decide which hit take
650  if(itm->estimate() > alreadystored->second.first){
651  worse_double_hit++;}
652  if(itm->estimate() < alreadystored->second.first){
654  hitangleassociation.insert(std::make_pair(hit, std::make_pair(itm->estimate(),tanangle)));
655 
656  }}
657  else{
658  hitangleassociation.insert(std::make_pair(hit,std::make_pair(itm->estimate(), tanangle) ) );
659  HitsTree->Fill();
660  hitcounter++;}
661 
662 
663  }
664  }
665  }
666  }
667  }
668  }
669  std::map<const SiStripRecHit2D *,std::pair<float,float>,DetIdLess>::iterator hitsiter;
670 
671 
672  for(hitsiter=hitangleassociation.begin();hitsiter!=hitangleassociation.end();hitsiter++){
673 
675 
676  const SiStripRecHit2D* hit=hitsiter->first;
677  const SiStripRecHit2D::ClusterRef & cluster=hit->cluster();
678 
679  size=(cluster->amplitudes()).size();
680 
682 
683  float tangent = hitsiter->second.second;
684 
685  //Sign and XZ plane projection correction applied in TrackLocalAngle (TIB|TOB layers)
686 
687  detparmap::iterator thedet=detmap.find(detid.rawId());
688  LocalVector localmagdir;
689  if(thedet!=detmap.end())localmagdir=thedet->second->magfield;
690  float localmagfield = localmagdir.mag();
691 
692  if(localmagfield != 0.){
693 
694  LocalVector ylocal(0,1,0);
695 
696  float normprojection = (localmagdir * ylocal)/(localmagfield);
697 
698  if(normprojection == 0.)LogDebug("SiStripLAProfileBooker::analyze")<<"Error: YBprojection = 0";
699 
700  else{
701  float signprojcorrection = 1/normprojection;
702  tangent*=signprojcorrection;
703  }
704  }
705 
706  //Filling histograms
707 
708  histomap::iterator thehisto=histos.find(detid.rawId());
709 
710  if(thehisto==histos.end())edm::LogError("SiStripLAProfileBooker::analyze")<<"Error: the profile associated to"<<detid.rawId()<<"does not exist! ";
711  else thehisto->second->Fill(tangent,size);
712 
713  //Summary histograms
715  unsigned int layerid;
716  getlayer(detid,tTopo,name,layerid);
717  histomap::iterator thesummaryhisto=summaryhisto.find(layerid);
718  if(thesummaryhisto==summaryhisto.end())edm::LogError("SiStripLAProfileBooker::analyze")<<"Error: the profile associated to subdet "<<name<<"does not exist! ";
719  else thesummaryhisto->second->Fill(tangent,size);
720 
721  }
722 
723 
724 }
725 
726 
727 //Makename function
728 
729 void SiStripLAProfileBooker::getlayer(const DetId & detid, const TrackerTopology* tTopo, std::string &name,unsigned int &layerid){
730  int layer=0;
731  std::stringstream layernum;
732 
733  if(detid.subdetId() == int (StripSubdetector::TIB)){
734 
735  name+="TIB_Layer_";
736  layer = tTopo->tibLayer(detid);
737  }
738 
739  else if(detid.subdetId() == int (StripSubdetector::TID)){
740 
741  name+="TID_Ring_";
742  layer = tTopo->tidRing(detid);
743  }
744 
745  else if(detid.subdetId() == int (StripSubdetector::TOB)){
746 
747  name+="TOB_Layer_";
748  layer = tTopo->tobLayer(detid);
749 
750  }
751 
752  else if(detid.subdetId() == int (StripSubdetector::TEC)){
753 
754  name+="TEC_Ring_";
755  layer = tTopo->tecRing(detid);
756  }
757  layernum<<layer;
758  name+=layernum.str();
759  layerid=detid.subdetId()*10+layer;
760 
761 }
762 
764 
765  std::string outputFile_ =conf_.getUntrackedParameter<std::string>("fileName", "LorentzAngle.root");
766  dbe_->save(outputFile_);
767 
768  hFile->Write();
769  hFile->Close();
770 }
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
void addActiveDetectorsRawIds(std::vector< uint32_t > &) const
unsigned int tibLayer(const DetId &id) const
unsigned int tidRing(const DetId &id) const
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:20
const_iterator end() const
last iterator over the map (read only)
virtual const Topology & topology() const
Definition: GeomDet.cc:81
std::vector< unsigned int > tidModuleInfo(const DetId &id) const
LocalVector localDirection() const
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
unsigned int tecRing(const DetId &id) const
ring id
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:15
T y() const
Definition: PV3DBase.h:63
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:69
const Bounds & bounds() const
Definition: Surface.h:120
unsigned int tidWheel(const DetId &id) const
LocalVector toLocal(const reco::Track::Vector &v, const Surface &s)
std::vector< unsigned int > tibStringInfo(const DetId &id) const
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
void setDetectorFolder(uint32_t rawdetid, const TrackerTopology *tTopo)
std::vector< unsigned int > tecPetalInfo(const DetId &id) const
T mag() const
Definition: PV3DBase.h:67
std::vector< unsigned int > tobRodInfo(const DetId &id) const
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
void getlayer(const DetId &detid, const TrackerTopology *tTopo, std::string &name, unsigned int &layerid)
T sqrt(T t)
Definition: SSEVec.h:18
T z() const
Definition: PV3DBase.h:64
void analyze(const edm::Event &e, const edm::EventSetup &c) override
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
const DetIdContainer & detIds() const override
Returm a vector of all GeomDet DetIds (including those of GeomDetUnits)
ClusterRef cluster() const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
SiStripRecHit2D originalHit() const
Definition: DetId.h:18
unsigned int stereo() const
stereo
MonitorElement * bookProfile(char_string const &name, char_string const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, char const *option="s")
Definition: DQMStore.cc:1285
SiStripRecHit2D stereoHit() const
virtual float thickness() const =0
std::string createHistoId(std::string description, std::string id_type, uint32_t component_id)
bool operator()(const SiStripRecHit2D *a, const SiStripRecHit2D *b) const
double b
Definition: hdecay.h:120
std::vector< DetId > DetIdContainer
void save(std::string const &filename, std::string const &path="", std::string const &pattern="", std::string const &rewrite="", uint32_t run=0, uint32_t lumi=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, std::string const &fileupdate="RECREATE")
Definition: DQMStore.cc:2465
virtual float localPitch(const LocalPoint &) const =0
std::string const & label() const
Definition: InputTag.h:36
std::vector< Trajectory > TrajectoryCollection
SiStripRecHit2D monoHit() const
void beginRun(edm::Run const &, const edm::EventSetup &c) override
edm::EventID id() const
Definition: EventBase.h:59
#define begin
Definition: vmac.h:32
double a
Definition: hdecay.h:121
static int position[264][3]
Definition: ReadPGInfo.cc:509
def cache(function)
Definition: utilities.py:3
T get() const
Definition: EventSetup.h:71
const TrackerGeomDet * idToDet(DetId) const override
LocalPoint localPosition() const final
const_iterator begin() const
first iterator over the map (read only)
DetId geographicalId() const
SiStripLAProfileBooker(const edm::ParameterSet &conf)
T x() const
Definition: PV3DBase.h:62
unsigned int tecWheel(const DetId &id) const
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
T const * product() const
Definition: ESHandle.h:86
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:21
const Plane & specificSurface() const
Same as surface(), kept for backward compatibility.
Definition: GeomDet.h:45
unsigned int tobLayer(const DetId &id) const
Definition: Run.h:45
const TrackerGeometry * tracker