CMS 3D CMS Logo

TrackerOfflineValidationSummary.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TrackerOfflineValidationSummary
4 // Class: TrackerOfflineValidationSummary
5 //
13 //
14 // Original Author: Johannes Hauk
15 // Created: Sat Aug 22 10:31:34 CEST 2009
16 // $Id: TrackerOfflineValidationSummary.cc,v 1.7 2012/06/30 09:09:47 eulisse Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
27 
30 
32 
33 
38 
39 
40 #include "TTree.h"
41 //#include "Alignment/OfflineValidation/interface/TrackerValidationVariables.h"
43 
51 #include "TH1.h"
52 #include "TMath.h"
53 
57 
58 //
59 // class decleration
60 //
61 
63  public:
66 
67 
68  private:
69 
70  struct ModuleHistos{
73  TH1* ResHisto;
79  };
80 
83  HarvestingHistos() : DmrXprime(), DmrYprime() {}
84  TH1* DmrXprime;
85  TH1* DmrYprime;
86  };
87 
90  HarvestingHierarchy(const std::string& name, const std::string& component, const std::vector<unsigned int>& entries) : hierarchyName(name), componentName(component), treeEntries(entries) {}
91  // Needed for naming of histogram according to residual histograms
93  // "Pixel" or "Strip"
95  // Modules belonging to selected hierarchy
96  std::vector<unsigned int> treeEntries;
98  };
99 
100  void analyze(const edm::Event& evt, const edm::EventSetup&) override;
101  void endJob() override ;
102 
103  void fillTree(TTree& tree, std::map<int, TrackerOfflineValidationSummary::ModuleHistos>& moduleHist,
104  TkOffTreeVariables& treeMem, const TrackerGeometry& tkgeom,
105  std::map<std::string,std::string>& substructureName, const TrackerTopology* tTopo);
106 
107  std::pair<float,float> fitResiduals(TH1* hist)const;
108  float getMedian(const TH1* hist)const;
109 
110  const std::string associateModuleHistsWithTree(const TkOffTreeVariables& treeMem, TrackerOfflineValidationSummary::ModuleHistos& moduleHists, std::map<std::string,std::string>& substructureName);
111 
112  void collateHarvestingHists(TTree& tree);
113  void applyHarvestingHierarchy(TTree& treeMem);
114  void bookHarvestingHists();
115  void getBinning(const std::string& binningPSetName, int& nBinsX, double& lowerBoundX, double& upperBoundX)const;
116  void fillHarvestingHists(TTree& tree);
117 
118  // ----------member data ---------------------------
119 
122 
123  // parameters from cfg to steer
125  const bool useFit_;
126 
128 
130 
131  std::map<int,TrackerOfflineValidationSummary::ModuleHistos> mPxbResiduals_;
132  std::map<int,TrackerOfflineValidationSummary::ModuleHistos> mPxeResiduals_;
133  std::map<int,TrackerOfflineValidationSummary::ModuleHistos> mTibResiduals_;
134  std::map<int,TrackerOfflineValidationSummary::ModuleHistos> mTidResiduals_;
135  std::map<int,TrackerOfflineValidationSummary::ModuleHistos> mTobResiduals_;
136  std::map<int,TrackerOfflineValidationSummary::ModuleHistos> mTecResiduals_;
137 
138  std::vector<HarvestingHierarchy> vHarvestingHierarchy_;
139 
141 };
142 
143 //
144 // constants, enums and typedefs
145 //
146 
147 //
148 // static data member definitions
149 //
150 
151 //
152 // constructors and destructor
153 //
155  parSet_(iConfig), moduleDirectory_(parSet_.getParameter<std::string>("moduleDirectoryInOutput")),
157 {
158  //now do what ever initialization is needed
160 }
161 
162 
164 {
165 
166  // do anything here that needs to be done at desctruction time
167  // (e.g. close files, deallocate resources etc.)
168 
169 }
170 
171 
172 //
173 // member functions
174 //
175 
176 // ------------ method called to for each event ------------
177 void
179 {
180  lastSetup_ = &iSetup;
181 
182  // Access of EventSetup is needed to get the list of silicon-modules and their IDs
183  // Since they do not change, it is accessed only once
184  if(moduleMapsInitialized)return;
185  iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom_ );
186  const TrackerGeometry* bareTkGeomPtr = &(*tkGeom_);
187  const TrackingGeometry::DetIdContainer& detIdContainer = bareTkGeomPtr->detIds();
188  std::vector<DetId>::const_iterator iDet;
189  for(iDet = detIdContainer.begin(); iDet != detIdContainer.end(); ++iDet){
190  const DetId& detId = *iDet;
191  const uint32_t rawId = detId.rawId();
192  const unsigned int subdetId = detId.subdetId();
193  if (subdetId == PixelSubdetector::PixelBarrel) mPxbResiduals_[rawId];
194  else if(subdetId == PixelSubdetector::PixelEndcap) mPxeResiduals_[rawId];
195  else if(subdetId == StripSubdetector::TIB) mTibResiduals_[rawId];
196  else if(subdetId == StripSubdetector::TID) mTidResiduals_[rawId];
197  else if(subdetId == StripSubdetector::TOB) mTobResiduals_[rawId];
198  else if(subdetId == StripSubdetector::TEC) mTecResiduals_[rawId];
199  else {
200  throw cms::Exception("Geometry Error")
201  << "[TrackerOfflineValidationSummary] Error, tried to get reference for non-tracker subdet " << subdetId
202  << " from detector " << detId.det();
203  }
204  }
205  moduleMapsInitialized = true;
206 }
207 
208 
209 // ------------ method called once each job just after ending the event loop ------------
210 void
212 {
213  //Retrieve tracker topology from geometry
214  edm::ESHandle<TrackerTopology> tTopoHandle;
215  lastSetup_->get<TrackerTopologyRcd>().get(tTopoHandle);
216  const TrackerTopology* const tTopo = tTopoHandle.product();
217 
218  AlignableTracker aliTracker(&(*tkGeom_), tTopo);
219 
220  TTree* tree = new TTree("TkOffVal","TkOffVal");
221 
222  TkOffTreeVariables *treeMemPtr = new TkOffTreeVariables;
223  // We create branches for all members of 'TkOffTreeVariables' (even if not needed).
224  // This works because we have a dictionary for 'TkOffTreeVariables'
225  // (see src/classes_def.xml and src/classes.h):
226  tree->Branch("TkOffTreeVariables", &treeMemPtr); // address of pointer!
227  // second branch needed for assigning names and titles to harvesting histograms consistent to others
228  std::map<std::string,std::string> *substructureName = new std::map<std::string,std::string>;
229  tree->Branch("SubstructureName", &substructureName, 32000, 00); // SplitLevel must be set to zero
230 
231 
232  this->fillTree(*tree, mPxbResiduals_, *treeMemPtr, *tkGeom_, *substructureName, tTopo);
233  this->fillTree(*tree, mPxeResiduals_, *treeMemPtr, *tkGeom_, *substructureName, tTopo);
234  this->fillTree(*tree, mTibResiduals_, *treeMemPtr, *tkGeom_, *substructureName, tTopo);
235  this->fillTree(*tree, mTidResiduals_, *treeMemPtr, *tkGeom_, *substructureName, tTopo);
236  this->fillTree(*tree, mTobResiduals_, *treeMemPtr, *tkGeom_, *substructureName, tTopo);
237  this->fillTree(*tree, mTecResiduals_, *treeMemPtr, *tkGeom_, *substructureName, tTopo);
238 
239  //dbe_->showDirStructure();
240  //dbe_->save("dqmOut.root");
241 
242  // Method for filling histograms which show summarized values (mean, rms, median ...)
243  // of the module-based histograms from TrackerOfflineValidation
244  this->collateHarvestingHists(*tree);
245 
246  delete tree; tree = nullptr;
247  delete treeMemPtr; treeMemPtr = nullptr;
248  delete substructureName; substructureName = nullptr;
249 }
250 
251 
252 void
253 TrackerOfflineValidationSummary::fillTree(TTree& tree, std::map<int, TrackerOfflineValidationSummary::ModuleHistos>& moduleHist,
254  TkOffTreeVariables& treeMem, const TrackerGeometry& tkgeom,
255  std::map<std::string,std::string>& substructureName,
256  const TrackerTopology* tTopo)
257 {
258  for(std::map<int, TrackerOfflineValidationSummary::ModuleHistos>::iterator it = moduleHist.begin(),
259  itEnd= moduleHist.end(); it != itEnd;++it ) {
260  treeMem.clear(); // make empty/default
261 
262  //variables concerning the tracker components/hierarchy levels
263  const DetId detId = it->first;
264  treeMem.moduleId = detId;
265  treeMem.subDetId = detId.subdetId();
266 
268 
269  unsigned int whichHalfBarrel(1), rawId(detId.rawId()); //DetId does not know about halfBarrels is PXB ...
270  if( (rawId>=302056964 && rawId<302059300) || (rawId>=302123268 && rawId<302127140) || (rawId>=302189572 && rawId<302194980) )whichHalfBarrel=2;
271  treeMem.layer = tTopo->pxbLayer(detId);
272  treeMem.half = whichHalfBarrel;
273  treeMem.rod = tTopo->pxbLadder(detId); // ... so, ladder is not per halfBarrel-Layer, but per barrel-layer! Needs complicated calculation in associateModuleHistsWithTree()
274  treeMem.module = tTopo->pxbModule(detId);
275  } else if(treeMem.subDetId == PixelSubdetector::PixelEndcap){
276 
277  unsigned int whichHalfCylinder(1), rawId(detId.rawId()); //DetId does not kmow about halfCylinders in PXF
278  if( (rawId>=352394500 && rawId<352406032) || (rawId>=352460036 && rawId<352471568) || (rawId>=344005892 && rawId<344017424) || (rawId>=344071428 && rawId<344082960) )whichHalfCylinder=2;
279  treeMem.layer = tTopo->pxfDisk(detId);
280  treeMem.side = tTopo->pxfSide(detId);
281  treeMem.half = whichHalfCylinder;
282  treeMem.blade = tTopo->pxfBlade(detId);
283  treeMem.panel = tTopo->pxfPanel(detId);
284  treeMem.module = tTopo->pxfModule(detId);
285  } else if(treeMem.subDetId == StripSubdetector::TIB){
286 
287  unsigned int whichHalfShell(1), rawId(detId.rawId()); //DetId does not kmow about halfShells in TIB
288  if ( (rawId>=369120484 && rawId<369120688) || (rawId>=369121540 && rawId<369121776) || (rawId>=369136932 && rawId<369137200) || (rawId>=369137988 && rawId<369138288) ||
289  (rawId>=369153396 && rawId<369153744) || (rawId>=369154436 && rawId<369154800) || (rawId>=369169844 && rawId<369170256) || (rawId>=369170900 && rawId<369171344) ||
290  (rawId>=369124580 && rawId<369124784) || (rawId>=369125636 && rawId<369125872) || (rawId>=369141028 && rawId<369141296) || (rawId>=369142084 && rawId<369142384) ||
291  (rawId>=369157492 && rawId<369157840) || (rawId>=369158532 && rawId<369158896) || (rawId>=369173940 && rawId<369174352) || (rawId>=369174996 && rawId<369175440) ) whichHalfShell=2;
292  treeMem.layer = tTopo->tibLayer(detId);
293  treeMem.side = tTopo->tibStringInfo(detId)[0];
294  treeMem.half = whichHalfShell;
295  treeMem.rod = tTopo->tibStringInfo(detId)[2];
296  treeMem.outerInner = tTopo->tibStringInfo(detId)[1];
297  treeMem.module = tTopo->tibModule(detId);
298  treeMem.isStereo = tTopo->tibStereo(detId);
299  treeMem.isDoubleSide = tTopo->tibIsDoubleSide(detId);
300  } else if(treeMem.subDetId == StripSubdetector::TID){
301 
302  treeMem.layer = tTopo->tidWheel(detId);
303  treeMem.side = tTopo->tidSide(detId);
304  treeMem.ring = tTopo->tidRing(detId);
305  treeMem.outerInner = tTopo->tidModuleInfo(detId)[0];
306  treeMem.module = tTopo->tidModuleInfo(detId)[1];
307  treeMem.isStereo = tTopo->tidStereo(detId);
308  treeMem.isDoubleSide = tTopo->tidIsDoubleSide(detId);
309  } else if(treeMem.subDetId == StripSubdetector::TOB){
310 
311  treeMem.layer = tTopo->tobLayer(detId);
312  treeMem.side = tTopo->tobRodInfo(detId)[0];
313  treeMem.rod = tTopo->tobRodInfo(detId)[1];
314  treeMem.module = tTopo->tobModule(detId);
315  treeMem.isStereo = tTopo->tobStereo(detId);
316  treeMem.isDoubleSide = tTopo->tobIsDoubleSide(detId);
317  } else if(treeMem.subDetId == StripSubdetector::TEC) {
318 
319  treeMem.layer = tTopo->tecWheel(detId);
320  treeMem.side = tTopo->tecSide(detId);
321  treeMem.ring = tTopo->tecRing(detId);
322  treeMem.petal = tTopo->tecPetalInfo(detId)[1];
323  treeMem.outerInner = tTopo->tecPetalInfo(detId)[0];
324  treeMem.module = tTopo->tecModule(detId);
325  treeMem.isStereo = tTopo->tecStereo(detId);
326  treeMem.isDoubleSide = tTopo->tecIsDoubleSide(detId);
327  }
328 
329  //variables concerning the tracker geometry
330 
331  const Surface::PositionType &gPModule = tkgeom.idToDet(detId)->position();
332  treeMem.posPhi = gPModule.phi();
333  treeMem.posEta = gPModule.eta();
334  treeMem.posR = gPModule.perp();
335  treeMem.posX = gPModule.x();
336  treeMem.posY = gPModule.y();
337  treeMem.posZ = gPModule.z();
338 
339  const Surface& surface = tkgeom.idToDet(detId)->surface();
340 
341  //global Orientation of local coordinate system of dets/detUnits
342  LocalPoint lUDirection(1.,0.,0.), lVDirection(0.,1.,0.), lWDirection(0.,0.,1.);
343  GlobalPoint gUDirection = surface.toGlobal(lUDirection),
344  gVDirection = surface.toGlobal(lVDirection),
345  gWDirection = surface.toGlobal(lWDirection);
346  double dR(999.), dPhi(999.), dZ(999.);
348  dR = gWDirection.perp() - gPModule.perp();
349  dPhi = deltaPhi(gUDirection.barePhi(),gPModule.barePhi());
350  dZ = gVDirection.z() - gPModule.z();
351  if(dZ>=0.)treeMem.rOrZDirection = 1; else treeMem.rOrZDirection = -1;
352  }else if(treeMem.subDetId==PixelSubdetector::PixelEndcap){
353  dR = gUDirection.perp() - gPModule.perp();
354  dPhi = deltaPhi(gVDirection.barePhi(),gPModule.barePhi());
355  dZ = gWDirection.z() - gPModule.z();
356  if(dR>=0.)treeMem.rOrZDirection = 1; else treeMem.rOrZDirection = -1;
357  }else if(treeMem.subDetId==StripSubdetector::TID || treeMem.subDetId==StripSubdetector::TEC){
358  dR = gVDirection.perp() - gPModule.perp();
359  dPhi = deltaPhi(gUDirection.barePhi(),gPModule.barePhi());
360  dZ = gWDirection.z() - gPModule.z();
361  if(dR>=0.)treeMem.rOrZDirection = 1; else treeMem.rOrZDirection = -1;
362  }
363  if(dR>=0.)treeMem.rDirection = 1; else treeMem.rDirection = -1;
364  if(dPhi>=0.)treeMem.phiDirection = 1; else treeMem.phiDirection = -1;
365  if(dZ>=0.)treeMem.zDirection = 1; else treeMem.zDirection = -1;
366 
367 
368  // Assign histos from first step (TrackerOfflineValidation) to the module's entry in the TTree for retrieving mean, rms, median ...
369  const std::string histDir = associateModuleHistsWithTree(treeMem, it->second, substructureName);
370 
371 
372  //mean and RMS values (extracted from histograms Xprime on module level)
373  treeMem.entries = static_cast<UInt_t>(it->second.ResXprimeHisto->GetEntries());
374  treeMem.meanX = it->second.ResXprimeHisto->GetMean();
375  treeMem.rmsX = it->second.ResXprimeHisto->GetRMS();
376  //treeMem.sigmaX = Fwhm(it->second.ResXprimeHisto)/2.355;
377  if (useFit_) {
378  //call fit function which returns mean and sigma from the fit
379  //for absolute residuals
380  std::pair<float,float> fitResult1 = this->fitResiduals(it->second.ResXprimeHisto);
381  treeMem.fitMeanX = fitResult1.first;
382  treeMem.fitSigmaX = fitResult1.second;
383  //for normalized residuals
384  std::pair<float,float> fitResult2 = this->fitResiduals(it->second.NormResXprimeHisto);
385  treeMem.fitMeanNormX = fitResult2.first;
386  treeMem.fitSigmaNormX = fitResult2.second;
387  }
388 
389  //get median for absolute residuals
390  treeMem.medianX = this->getMedian(it->second.ResXprimeHisto);
391 
392  int numberOfBins=it->second.ResXprimeHisto->GetNbinsX();
393  treeMem.numberOfUnderflows = it->second.ResXprimeHisto->GetBinContent(0);
394  treeMem.numberOfOverflows = it->second.ResXprimeHisto->GetBinContent(numberOfBins+1);
395  treeMem.numberOfOutliers = it->second.ResXprimeHisto->GetBinContent(0)+it->second.ResXprimeHisto->GetBinContent(numberOfBins+1);
396  //mean and RMS values (extracted from histograms(normalized Xprime on module level)
397  treeMem.meanNormX = it->second.NormResXprimeHisto->GetMean();
398  treeMem.rmsNormX = it->second.NormResXprimeHisto->GetRMS();
399 
400  double stats[20];
401  it->second.NormResXprimeHisto->GetStats(stats);
402  // GF treeMem.chi2PerDofX = stats[3]/(stats[0]-1);
403  if (stats[0]) treeMem.chi2PerDofX = stats[3]/stats[0];
404 
405  //treeMem.sigmaNormX = Fwhm(it->second.NormResXprimeHisto)/2.355;
406  treeMem.histNameX = it->second.ResXprimeHisto->GetName();
407  treeMem.histNameNormX = it->second.NormResXprimeHisto->GetName();
408 
409 
410  // fill tree variables in local coordinates if set in cfg of TrackerOfllineValidation
411  if(it->second.ResHisto && it->second.NormResHisto){ // if(lCoorHistOn_) {
412  treeMem.meanLocalX = it->second.ResHisto->GetMean();
413  treeMem.rmsLocalX = it->second.ResHisto->GetRMS();
414  treeMem.meanNormLocalX = it->second.NormResHisto->GetMean();
415  treeMem.rmsNormLocalX = it->second.NormResHisto->GetRMS();
416  treeMem.histNameLocalX = it->second.ResHisto->GetName();
417  treeMem.histNameNormLocalX = it->second.NormResHisto->GetName();
418  }
419 
420  // mean and RMS values in local y (extracted from histograms Yprime on module level)
421  // might exist in pixel only
422  if (it->second.ResYprimeHisto) { //(stripYResiduals_){
423  TH1 *h = it->second.ResYprimeHisto;
424  treeMem.meanY = h->GetMean();
425  treeMem.rmsY = h->GetRMS();
426 
427  if (useFit_) { // fit function which returns mean and sigma from the fit
428  std::pair<float,float> fitMeanSigma = this->fitResiduals(h);
429  treeMem.fitMeanY = fitMeanSigma.first;
430  treeMem.fitSigmaY = fitMeanSigma.second;
431  }
432 
433  //get median for absolute residuals
434  treeMem.medianY = this->getMedian(h);
435 
436  treeMem.histNameY = h->GetName();
437  }
438 
439  if (it->second.NormResYprimeHisto) {
440  TH1 *h = it->second.NormResYprimeHisto;
441  treeMem.meanNormY = h->GetMean();
442  treeMem.rmsNormY = h->GetRMS();
443  h->GetStats(stats); // stats buffer defined above
444  if (stats[0]) treeMem.chi2PerDofY = stats[3]/stats[0];
445 
446  if (useFit_) { // fit function which returns mean and sigma from the fit
447  std::pair<float,float> fitMeanSigma = this->fitResiduals(h);
448  treeMem.fitMeanNormY = fitMeanSigma.first;
449  treeMem.fitSigmaNormY = fitMeanSigma.second;
450  }
451  treeMem.histNameNormY = h->GetName();
452  }
453 
454  // Delete module level hists if set in cfg
455  const bool removeModuleLevelHists(parSet_.getParameter<bool>("removeModuleLevelHists"));
456  if(removeModuleLevelHists){
457  dbe_->setCurrentFolder("");
458  if(it->second.ResHisto) dbe_->removeElement(histDir + "/" + it->second.ResHisto->GetName());
459  if(it->second.NormResHisto) dbe_->removeElement(histDir + "/" + it->second.NormResHisto->GetName());
460  if(it->second.ResXprimeHisto) dbe_->removeElement(histDir + "/" + it->second.ResXprimeHisto->GetName());
461  if(it->second.NormResXprimeHisto)dbe_->removeElement(histDir + "/" + it->second.NormResXprimeHisto->GetName());
462  if(it->second.ResYprimeHisto) dbe_->removeElement(histDir + "/" + it->second.ResYprimeHisto->GetName());
463  if(it->second.NormResYprimeHisto)dbe_->removeElement(histDir + "/" + it->second.NormResYprimeHisto->GetName());
464  }
465 
466  tree.Fill();
467  }
468 }
469 
470 
471 const std::string
472 TrackerOfflineValidationSummary::associateModuleHistsWithTree(const TkOffTreeVariables& treeMem, TrackerOfflineValidationSummary::ModuleHistos& moduleHists, std::map<std::string,std::string>& substructureName){
473  std::stringstream histDir, sSubdetName;
474  std::string componentName;
475  if(moduleDirectory_.length() != 0)histDir<<moduleDirectory_<<"/";
476  std::string wheelOrLayer("_layer_");
478  unsigned int half(treeMem.half), layer(treeMem.layer), ladder(0);
479  if(layer==1){
480  if(half==2)ladder = treeMem.rod -5;
481  else if(treeMem.rod>15)ladder = treeMem.rod -10;
482  else ladder = treeMem.rod;
483  }else if(layer==2){
484  if(half==2)ladder = treeMem.rod -8;
485  else if(treeMem.rod>24)ladder = treeMem.rod -16;
486  else ladder = treeMem.rod;
487  }else if(layer==3){
488  if(half==2)ladder = treeMem.rod -11;
489  else if(treeMem.rod>33)ladder = treeMem.rod -22;
490  else ladder = treeMem.rod;
491  }
492  componentName = "Pixel";
493  sSubdetName<<"TPBBarrel_1";
494  histDir<<componentName<<"/"<<sSubdetName.str()<<"/TPBHalfBarrel_"<<treeMem.half<<"/TPBLayer_"<<treeMem.layer<<"/TPBLadder_"<<ladder;
495  }else if(treeMem.subDetId == PixelSubdetector::PixelEndcap){
496  unsigned int side(treeMem.side), half(treeMem.half), blade(0);
497  if(side==1)side=3;
498  if(half==2)blade = treeMem.blade -6;
499  else if(treeMem.blade>18)blade = treeMem.blade -12;
500  else blade = treeMem.blade;
501  componentName = "Pixel";
502  sSubdetName<<"TPEEndcap_"<<side;
503  histDir<<componentName<<"/"<<sSubdetName.str()<<"/TPEHalfCylinder_"<<treeMem.half<<"/TPEHalfDisk_"<<treeMem.layer<<"/TPEBlade_"<<blade<<"/TPEPanel_"<<treeMem.panel;
504  wheelOrLayer = "_wheel_";
505  }else if(treeMem.subDetId == StripSubdetector::TIB){
506  unsigned int half(treeMem.half), layer(treeMem.layer), surface(treeMem.outerInner), string(0);
507  if(half==2){
508  if(layer==1){
509  if(surface==1)string = treeMem.rod -13;
510  else if(surface==2)string = treeMem.rod -15;
511  }
512  if(layer==2){
513  if(surface==1)string = treeMem.rod -17;
514  else if(surface==2)string = treeMem.rod -19;
515  }
516  if(layer==3){
517  if(surface==1)string = treeMem.rod -22;
518  else if(surface==2)string = treeMem.rod -23;
519  }
520  if(layer==4){
521  if(surface==1)string = treeMem.rod -26;
522  else if(surface==2)string = treeMem.rod -28;
523  }
524  }
525  else string = treeMem.rod;
526  std::stringstream detString;
527  if(treeMem.layer<3 && !treeMem.isDoubleSide)detString<<"/Det_"<<treeMem.module;
528  else detString<<"";
529  componentName = "Strip";
530  sSubdetName<<"TIBBarrel_1";
531  histDir<<componentName<<"/"<<sSubdetName.str()<<"/TIBHalfBarrel_"<<treeMem.side<<"/TIBLayer_"<<treeMem.layer<<"/TIBHalfShell_"<<treeMem.half<<"/TIBSurface_"<<treeMem.outerInner<<"/TIBString_"<<string<<detString.str();
532  }else if(treeMem.subDetId == StripSubdetector::TID){
533  unsigned int side(treeMem.side), outerInner(0);
534  if(side==1)side=3;
535  if(treeMem.outerInner==1)outerInner=2;
536  else if(treeMem.outerInner==2)outerInner=1;
537  std::stringstream detString;
538  if(treeMem.ring<3 && !treeMem.isDoubleSide)detString<<"/Det_"<<treeMem.module;
539  else detString<<"";
540  componentName = "Strip";
541  sSubdetName<<"TIDEndcap_"<<side;
542  histDir<<componentName<<"/"<<sSubdetName.str()<<"/TIDDisk_"<<treeMem.layer<<"/TIDRing_"<<treeMem.ring<<"/TIDSide_"<<outerInner<<detString.str();
543  wheelOrLayer = "_wheel_";
544  }else if(treeMem.subDetId == StripSubdetector::TOB){
545  std::stringstream detString;
546  if(treeMem.layer<3 && !treeMem.isDoubleSide)detString<<"/Det_"<<treeMem.module;
547  else detString<<"";
548  componentName = "Strip";
549  sSubdetName<<"TOBBarrel_4";
550  histDir<<componentName<<"/"<<sSubdetName.str()<<"/TOBHalfBarrel_"<<treeMem.side<<"/TOBLayer_"<<treeMem.layer<<"/TOBRod_"<<treeMem.rod<<detString.str();
551  }else if(treeMem.subDetId == StripSubdetector::TEC) {
552  unsigned int side(0), outerInner(0), ring(0);
553  if(treeMem.side==1)side=6;
554  else if(treeMem.side==2)side=5;
555  if(treeMem.outerInner==1)outerInner = 2;
556  else if(treeMem.outerInner==2)outerInner=1;
557  if(treeMem.layer>3 && treeMem.layer<7)ring = treeMem.ring -1;
558  else if(treeMem.layer==7 || treeMem.layer==8)ring = treeMem.ring -2;
559  else if(treeMem.layer==9)ring = treeMem.ring -3;
560  else ring = treeMem.ring;
561  std::stringstream detString;
562  if((treeMem.ring<3 || treeMem.ring==5) && !treeMem.isDoubleSide)detString<<"/Det_"<<treeMem.module;
563  else detString<<"";
564  componentName = "Strip";
565  sSubdetName<<"TECEndcap_"<<side;
566  histDir<<componentName<<"/"<<sSubdetName.str()<<"/TECDisk_"<<treeMem.layer<<"/TECSide_"<<outerInner<<"/TECPetal_"<<treeMem.petal<<"/TECRing_"<<ring<<detString.str();
567  wheelOrLayer = "_wheel_";
568  }
569 
570  substructureName["component"] = componentName;
571  substructureName["subdet"] = sSubdetName.str();
572 
573  std::stringstream histName;
574  histName<<"residuals_subdet_"<<treeMem.subDetId<<wheelOrLayer<<treeMem.layer<<"_module_"<<treeMem.moduleId;
575 
576  std::string fullPath;
577  fullPath = histDir.str()+"/h_xprime_"+histName.str();
578  if(dbe_->get(fullPath)) moduleHists.ResXprimeHisto = dbe_->get(fullPath)->getTH1();
579  else{edm::LogError("TrackerOfflineValidationSummary")<<"Problem with names in input file produced in TrackerOfflineValidation ...\n"
580  <<"This histogram should exist in every configuration, "
581  <<"but no histogram with name "<<fullPath<<" is found!";
582  return "";
583  }
584  fullPath = histDir.str()+"/h_normxprime"+histName.str();
585  if(dbe_->get(fullPath)) moduleHists.NormResXprimeHisto = dbe_->get(fullPath)->getTH1();
586  fullPath = histDir.str()+"/h_yprime_"+histName.str();
587  if(dbe_->get(fullPath)) moduleHists.ResYprimeHisto = dbe_->get(fullPath)->getTH1();
588  fullPath = histDir.str()+"/h_normyprime"+histName.str();
589  if(dbe_->get(fullPath)) moduleHists.NormResYprimeHisto = dbe_->get(fullPath)->getTH1();
590  fullPath = histDir.str()+"/h_"+histName.str();
591  if(dbe_->get(fullPath)) moduleHists.ResHisto = dbe_->get(fullPath)->getTH1();
592  fullPath = histDir.str()+"/h_norm"+histName.str();
593  if(dbe_->get(fullPath)) moduleHists.NormResHisto = dbe_->get(fullPath)->getTH1();
594 
595  return histDir.str();
596 }
597 
598 
599 std::pair<float,float>
601 {
602  std::pair<float,float> fitResult(9999., 9999.);
603  if (!hist || hist->GetEntries() < 20) return fitResult;
604 
605  float mean = hist->GetMean();
606  float sigma = hist->GetRMS();
607 
608  try { // for < CMSSW_2_2_0 since ROOT warnings from fit are converted to exceptions
609  // Remove the try/catch for more recent CMSSW!
610  // first fit: two RMS around mean
611  TF1 func("tmp", "gaus", mean - 2.*sigma, mean + 2.*sigma);
612  if (0 == hist->Fit(&func,"QNR")) { // N: do not blow up file by storing fit!
613  mean = func.GetParameter(1);
614  sigma = func.GetParameter(2);
615  // second fit: three sigma of first fit around mean of first fit
616  func.SetRange(mean - 3.*sigma, mean + 3.*sigma);
617  // I: integral gives more correct results if binning is too wide
618  // L: Likelihood can treat empty bins correctly (if hist not weighted...)
619  if (0 == hist->Fit(&func, "Q0LR")) {
620  if (hist->GetFunction(func.GetName())) { // Take care that it is later on drawn:
621  hist->GetFunction(func.GetName())->ResetBit(TF1::kNotDraw);
622  }
623  fitResult.first = func.GetParameter(1);
624  fitResult.second = func.GetParameter(2);
625  }
626  }
627  } catch (cms::Exception const & e) {
628  edm::LogWarning("Alignment") << "@SUB=TrackerOfflineValidation::fitResiduals"
629  << "Caught this exception during ROOT fit: "
630  << e.what();
631  }
632  return fitResult;
633 }
634 
635 
636 float
638 {
639  float median = 999;
640  const int nbins = histo->GetNbinsX();
641 
642  //extract median from histogram
643  double *x = new double[nbins];
644  double *y = new double[nbins];
645  for (int j = 0; j < nbins; j++) {
646  x[j] = histo->GetBinCenter(j+1);
647  y[j] = histo->GetBinContent(j+1);
648  }
649  median = TMath::Median(nbins, x, y);
650 
651  delete[] x; x = nullptr;
652  delete [] y; y = nullptr;
653 
654  return median;
655 }
656 
657 
658 void
660 {
661  this->applyHarvestingHierarchy(tree);
662  this->fillHarvestingHists(tree);
663 }
664 
665 
666 void
668 {
669  TkOffTreeVariables *treeMemPtr = nullptr;
670  std::map<std::string,std::string> *substructureName = nullptr;
671  tree.SetBranchAddress("TkOffTreeVariables", &treeMemPtr);
672  tree.SetBranchAddress("SubstructureName", &substructureName);
673 
674  // Loop over modules to select accumulation criteria for harvesting plots
675  for(unsigned int iSubdet = 1; iSubdet<7; ++iSubdet){
676  std::string hierarchyName("");
677  std::string componentName("");
678  std::vector<unsigned int> treeEntries;
679  for(unsigned int iSide = 1; iSide<3; ++iSide){
680  // Set up only one collection for Barrels, not separated for side
681  if(iSide==1 && (iSubdet==PixelSubdetector::PixelBarrel || iSubdet==StripSubdetector::TIB || iSubdet==StripSubdetector::TOB))continue;
682  for(int iTree=0; iTree<tree.GetEntries(); ++iTree){
683  tree.GetEntry(iTree);
684  // Do not use glued Dets
685  if(treeMemPtr->isDoubleSide)continue;
686  if(treeMemPtr->subDetId == iSubdet){
687  if(iSide!=treeMemPtr->side && (iSubdet==PixelSubdetector::PixelEndcap || iSubdet==StripSubdetector::TID || iSubdet==StripSubdetector::TEC))continue;
688  treeEntries.push_back(iTree);
689  if(hierarchyName.length() == 0){
690  hierarchyName = (*substructureName)["subdet"];
691  componentName = (*substructureName)["component"];
692  }
693  }
694  }
695  HarvestingHierarchy harvestingHierarchy(hierarchyName,componentName,treeEntries);
696  vHarvestingHierarchy_.push_back(harvestingHierarchy);
697  hierarchyName = ""; componentName = ""; treeEntries.clear();
698  }
699  }
700  // Here could be a further separation of the HarvestingHierarchy.
701  // E.g. separate the existing ones by layer and add them to the vector without deleting any element from the vector.
702  // The existing hists will stay and the new ones are added
703 
704  // Now, book the corresponding histos
705  this->bookHarvestingHists();
706 }
707 
708 
709 void
711 {
712  edm::LogInfo("TrackerOfflineValidationSummary")<<"Harvesting histograms will be booked for "<<vHarvestingHierarchy_.size()<<" different hierarchy selections";
713  for(std::vector<HarvestingHierarchy>::iterator iHier = vHarvestingHierarchy_.begin(); iHier != vHarvestingHierarchy_.end(); ++iHier){
714 
715  std::stringstream dmrXprimeHistoName, dmrYprimeHistoName, dmrXprimeHistoTitle, dmrYprimeHistoTitle;
716  dmrXprimeHistoName << "h_DmrXprime_" << iHier->hierarchyName;
717  dmrYprimeHistoName << "h_DmrYprime_" << iHier->hierarchyName;
718  dmrXprimeHistoTitle<< "DMR for " << iHier->hierarchyName <<";<#DeltaX> [cm];# modules";
719  dmrYprimeHistoTitle<< "DMR for " << iHier->hierarchyName <<";<#DeltaY> [cm];# modules";
720 
721  std::string directoryString(moduleDirectory_);
722  if(directoryString.length()!=0)directoryString += "/";
723  directoryString += iHier->componentName;
724  dbe_->setCurrentFolder(directoryString);
725 
726  int nBinsX(0); double xMin(0.), xMax(0.);
727  if(iHier->componentName == "Pixel"){
728  this->getBinning("TH1DmrXprimePixelModules",nBinsX,xMin,xMax);
729  iHier->harvestingHistos.DmrXprime = dbe_->book1D(dmrXprimeHistoName.str(),dmrXprimeHistoTitle.str(),nBinsX,xMin,xMax)->getTH1();
730  this->getBinning("TH1DmrYprimePixelModules",nBinsX,xMin,xMax);
731  iHier->harvestingHistos.DmrYprime = dbe_->book1D(dmrYprimeHistoName.str(),dmrYprimeHistoTitle.str(),nBinsX,xMin,xMax)->getTH1();
732  }
733  else if(iHier->componentName == "Strip"){
734  this->getBinning("TH1DmrXprimeStripModules",nBinsX,xMin,xMax);
735  iHier->harvestingHistos.DmrXprime = dbe_->book1D(dmrXprimeHistoName.str(),dmrXprimeHistoTitle.str(),nBinsX,xMin,xMax)->getTH1();
736  if(!parSet_.getParameter<bool>("stripYDmrs"))continue;
737  this->getBinning("TH1DmrYprimeStripModules",nBinsX,xMin,xMax);
738  iHier->harvestingHistos.DmrYprime = dbe_->book1D(dmrYprimeHistoName.str(),dmrYprimeHistoTitle.str(),nBinsX,xMin,xMax)->getTH1();
739  }
740  }
741 }
742 
743 
744 void
745 TrackerOfflineValidationSummary::getBinning(const std::string& binningPSetName, int& nBinsX, double& lowerBoundX, double& upperBoundX)const
746 {
747  const edm::ParameterSet& binningPSet = parSet_.getParameter<edm::ParameterSet>(binningPSetName);
748  nBinsX = binningPSet.getParameter<int>("Nbinx");
749  lowerBoundX = binningPSet.getParameter<double>("xmin");
750  upperBoundX = binningPSet.getParameter<double>("xmax");
751 }
752 
753 
754 void
756 {
757  TkOffTreeVariables *treeMemPtr = nullptr;
758  std::map<std::string,std::string> *substructureName = nullptr;
759  tree.SetBranchAddress("TkOffTreeVariables", &treeMemPtr);
760  tree.SetBranchAddress("SubstructureName", &substructureName);
761 
762  const unsigned int minEntriesPerModule(parSet_.getParameter<unsigned int>("minEntriesPerModuleForDmr"));
763  edm::LogInfo("TrackerOfflineValidationSummary")<<"Median of a module is added to DMR plots if it contains at least "<<minEntriesPerModule<<" hits";
764 
765  for(std::vector<HarvestingHierarchy>::iterator iHier = vHarvestingHierarchy_.begin(); iHier != vHarvestingHierarchy_.end(); ++iHier){
766  for(std::vector<unsigned int>::const_iterator iTreeEntries = iHier->treeEntries.begin(); iTreeEntries != iHier->treeEntries.end(); ++iTreeEntries){
767  tree.GetEntry(*iTreeEntries);
768  if(treeMemPtr->entries < minEntriesPerModule)continue;
769  iHier->harvestingHistos.DmrXprime->Fill(treeMemPtr->medianX);
770  if(iHier->harvestingHistos.DmrYprime)iHier->harvestingHistos.DmrYprime->Fill(treeMemPtr->medianY);
771  }
772  }
773 }
774 
775 
776 //define this as a plug-in
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:106
T getParameter(std::string const &) const
bool tecIsDoubleSide(const DetId &id) const
bool tobIsDoubleSide(const DetId &id) const
bool tibIsDoubleSide(const DetId &id) const
T perp() const
Definition: PV3DBase.h:72
unsigned int tibLayer(const DetId &id) const
unsigned int tidRing(const DetId &id) const
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:1041
Put here the histograms created during harvesting.
std::vector< unsigned int > tidModuleInfo(const DetId &id) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
unsigned int pxfDisk(const DetId &id) const
container to hold data to be written into TTree
unsigned int tecRing(const DetId &id) const
ring id
std::map< int, TrackerOfflineValidationSummary::ModuleHistos > mPxbResiduals_
uint32_t tobStereo(const DetId &id) const
std::vector< HarvestingHierarchy > vHarvestingHierarchy_
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
unsigned int pxbLadder(const DetId &id) const
TH1 * getTH1() const
T y() const
Definition: PV3DBase.h:63
unsigned int tidWheel(const DetId &id) const
unsigned int pxbModule(const DetId &id) const
char const * what() const override
Definition: Exception.cc:141
edm::ESHandle< TrackerGeometry > tkGeom_
#define nullptr
std::vector< unsigned int > tibStringInfo(const DetId &id) const
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
void getBinning(const std::string &binningPSetName, int &nBinsX, double &lowerBoundX, double &upperBoundX) const
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
T barePhi() const
Definition: PV3DBase.h:68
std::map< int, TrackerOfflineValidationSummary::ModuleHistos > mTibResiduals_
int iEvent
Definition: GenABIO.cc:230
std::vector< unsigned int > tecPetalInfo(const DetId &id) const
std::map< int, TrackerOfflineValidationSummary::ModuleHistos > mTobResiduals_
const Surface::PositionType & position() const
The position (origin of the R.F.)
Definition: GeomDet.h:48
unsigned int tidSide(const DetId &id) const
std::map< int, TrackerOfflineValidationSummary::ModuleHistos > mPxeResiduals_
uint32_t tidStereo(const DetId &id) const
std::vector< unsigned int > tobRodInfo(const DetId &id) const
const std::string associateModuleHistsWithTree(const TkOffTreeVariables &treeMem, TrackerOfflineValidationSummary::ModuleHistos &moduleHists, std::map< std::string, std::string > &substructureName)
T z() const
Definition: PV3DBase.h:64
void removeElement(const std::string &name)
Definition: DQMStore.cc:3396
const DetIdContainer & detIds() const override
Returm a vector of all GeomDet DetIds (including those of GeomDetUnits)
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
Definition: DQMStore.cc:1813
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
std::pair< float, float > fitResiduals(TH1 *hist) const
TrackerOfflineValidationSummary(const edm::ParameterSet &)
void analyze(const edm::Event &evt, const edm::EventSetup &) override
std::string histNameNormLocalX
unsigned int tibModule(const DetId &id) const
unsigned int pxfModule(const DetId &id) const
std::map< int, TrackerOfflineValidationSummary::ModuleHistos > mTidResiduals_
unsigned int pxbLayer(const DetId &id) const
unsigned int tecModule(const DetId &id) const
Definition: DetId.h:18
HarvestingHierarchy(const std::string &name, const std::string &component, const std::vector< unsigned int > &entries)
std::string histNameLocalX
const T & get() const
Definition: EventSetup.h:58
bool tidIsDoubleSide(const DetId &id) const
std::map< int, TrackerOfflineValidationSummary::ModuleHistos > mTecResiduals_
std::vector< DetId > DetIdContainer
unsigned int tobModule(const DetId &id) const
T eta() const
Definition: PV3DBase.h:76
void clear()
set to empty values
uint32_t tecStereo(const DetId &id) const
const TrackerGeomDet * idToDet(DetId) const override
unsigned int pxfSide(const DetId &id) const
Definition: tree.py:1
uint32_t tibStereo(const DetId &id) const
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
T x() const
Definition: PV3DBase.h:62
void fillTree(TTree &tree, std::map< int, TrackerOfflineValidationSummary::ModuleHistos > &moduleHist, TkOffTreeVariables &treeMem, const TrackerGeometry &tkgeom, std::map< std::string, std::string > &substructureName, const TrackerTopology *tTopo)
unsigned int tecWheel(const DetId &id) const
T const * product() const
Definition: ESHandle.h:86
unsigned int pxfPanel(const DetId &id) const
unsigned int pxfBlade(const DetId &id) const
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:747
unsigned int tobLayer(const DetId &id) const
unsigned int tecSide(const DetId &id) const