CMS 3D CMS Logo

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