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