CMS 3D CMS Logo

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