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