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