103 void fillTree(TTree&
tree, std::map<int, TrackerOfflineValidationSummary::ModuleHistos>& moduleHist,
105 std::map<std::string,std::string>& substructureName,
const TrackerTopology* tTopo);
115 void getBinning(
const std::string& binningPSetName,
int& nBinsX,
double& lowerBoundX,
double& upperBoundX)
const;
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();
201 <<
"[TrackerOfflineValidationSummary] Error, tried to get reference for non-tracker subdet " << subdetId
202 <<
" from detector " << detId.
det();
220 TTree*
tree =
new TTree(
"TkOffVal",
"TkOffVal");
226 tree->Branch(
"TkOffTreeVariables", &treeMemPtr);
228 std::map<std::string,std::string> *substructureName =
new std::map<std::string,std::string>;
229 tree->Branch(
"SubstructureName", &substructureName, 32000, 00);
246 delete tree; tree =
nullptr;
247 delete treeMemPtr; treeMemPtr =
nullptr;
248 delete substructureName; substructureName =
nullptr;
255 std::map<std::string,std::string>& substructureName,
258 for(std::map<int, TrackerOfflineValidationSummary::ModuleHistos>::iterator it = moduleHist.begin(),
259 itEnd= moduleHist.end(); it != itEnd;++it ) {
263 const DetId detId = it->first;
269 unsigned int whichHalfBarrel(1), rawId(detId.
rawId());
270 if( (rawId>=302056964 && rawId<302059300) || (rawId>=302123268 && rawId<302127140) || (rawId>=302189572 && rawId<302194980) )whichHalfBarrel=2;
272 treeMem.
half = whichHalfBarrel;
277 unsigned int whichHalfCylinder(1), rawId(detId.
rawId());
278 if( (rawId>=352394500 && rawId<352406032) || (rawId>=352460036 && rawId<352471568) || (rawId>=344005892 && rawId<344017424) || (rawId>=344071428 && rawId<344082960) )whichHalfCylinder=2;
281 treeMem.
half = whichHalfCylinder;
287 unsigned int whichHalfShell(1), rawId(detId.
rawId());
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;
294 treeMem.
half = whichHalfShell;
335 treeMem.
posX = gPModule.
x();
336 treeMem.
posY = gPModule.
y();
337 treeMem.
posZ = gPModule.
z();
342 LocalPoint lUDirection(1.,0.,0.), lVDirection(0.,1.,0.), lWDirection(0.,0.,1.);
344 gVDirection = surface.
toGlobal(lVDirection),
345 gWDirection = surface.
toGlobal(lWDirection);
346 double dR(999.),
dPhi(999.), dZ(999.);
348 dR = gWDirection.perp() - gPModule.
perp();
350 dZ = gVDirection.z() - gPModule.
z();
353 dR = gUDirection.
perp() - gPModule.
perp();
355 dZ = gWDirection.z() - gPModule.
z();
358 dR = gVDirection.perp() - gPModule.
perp();
360 dZ = gWDirection.z() - gPModule.
z();
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();
380 std::pair<float,float> fitResult1 = this->
fitResiduals(it->second.ResXprimeHisto);
381 treeMem.
fitMeanX = fitResult1.first;
384 std::pair<float,float> fitResult2 = this->
fitResiduals(it->second.NormResXprimeHisto);
392 int numberOfBins=it->second.ResXprimeHisto->GetNbinsX();
394 treeMem.
numberOfOverflows = it->second.ResXprimeHisto->GetBinContent(numberOfBins+1);
395 treeMem.
numberOfOutliers = it->second.ResXprimeHisto->GetBinContent(0)+it->second.ResXprimeHisto->GetBinContent(numberOfBins+1);
397 treeMem.
meanNormX = it->second.NormResXprimeHisto->GetMean();
398 treeMem.
rmsNormX = it->second.NormResXprimeHisto->GetRMS();
401 it->second.NormResXprimeHisto->GetStats(stats);
403 if (stats[0]) treeMem.
chi2PerDofX = stats[3]/stats[0];
406 treeMem.
histNameX = it->second.ResXprimeHisto->GetName();
407 treeMem.
histNameNormX = it->second.NormResXprimeHisto->GetName();
411 if(it->second.ResHisto && it->second.NormResHisto){
412 treeMem.
meanLocalX = it->second.ResHisto->GetMean();
413 treeMem.
rmsLocalX = it->second.ResHisto->GetRMS();
422 if (it->second.ResYprimeHisto) {
423 TH1 *
h = it->second.ResYprimeHisto;
424 treeMem.
meanY = h->GetMean();
425 treeMem.
rmsY = h->GetRMS();
428 std::pair<float,float> fitMeanSigma = this->
fitResiduals(h);
429 treeMem.
fitMeanY = fitMeanSigma.first;
439 if (it->second.NormResYprimeHisto) {
440 TH1 *
h = it->second.NormResYprimeHisto;
444 if (stats[0]) treeMem.
chi2PerDofY = stats[3]/stats[0];
447 std::pair<float,float> fitMeanSigma = this->
fitResiduals(h);
456 if(removeModuleLevelHists){
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());
473 std::stringstream
histDir, sSubdetName;
480 if(half==2)ladder = treeMem.
rod -5;
481 else if(treeMem.
rod>15)ladder = treeMem.
rod -10;
482 else ladder = treeMem.
rod;
484 if(half==2)ladder = treeMem.
rod -8;
485 else if(treeMem.
rod>24)ladder = treeMem.
rod -16;
486 else ladder = treeMem.
rod;
488 if(half==2)ladder = treeMem.
rod -11;
489 else if(treeMem.
rod>33)ladder = treeMem.
rod -22;
490 else ladder = treeMem.
rod;
492 componentName =
"Pixel";
493 sSubdetName<<
"TPBBarrel_1";
494 histDir<<componentName<<
"/"<<sSubdetName.str()<<
"/TPBHalfBarrel_"<<treeMem.
half<<
"/TPBLayer_"<<treeMem.
layer<<
"/TPBLadder_"<<
ladder;
496 unsigned int side(treeMem.
side), half(treeMem.
half), blade(0);
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_";
509 if(surface==1)
string = treeMem.
rod -13;
510 else if(surface==2)
string = treeMem.
rod -15;
513 if(surface==1)
string = treeMem.
rod -17;
514 else if(surface==2)
string = treeMem.
rod -19;
517 if(surface==1)
string = treeMem.
rod -22;
518 else if(surface==2)
string = treeMem.
rod -23;
521 if(surface==1)
string = treeMem.
rod -26;
522 else if(surface==2)
string = treeMem.
rod -28;
525 else string = treeMem.
rod;
526 std::stringstream 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();
533 unsigned int side(treeMem.
side), outerInner(0);
537 std::stringstream 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_";
545 std::stringstream detString;
548 componentName =
"Strip";
549 sSubdetName<<
"TOBBarrel_4";
550 histDir<<componentName<<
"/"<<sSubdetName.str()<<
"/TOBHalfBarrel_"<<treeMem.
side<<
"/TOBLayer_"<<treeMem.
layer<<
"/TOBRod_"<<treeMem.
rod<<detString.str();
552 unsigned int side(0), outerInner(0),
ring(0);
553 if(treeMem.
side==1)side=6;
554 else if(treeMem.
side==2)side=5;
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;
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_";
570 substructureName[
"component"] = componentName;
571 substructureName[
"subdet"] = sSubdetName.str();
573 std::stringstream histName;
574 histName<<
"residuals_subdet_"<<treeMem.
subDetId<<wheelOrLayer<<treeMem.
layer<<
"_module_"<<treeMem.
moduleId;
577 fullPath = histDir.str()+
"/h_xprime_"+histName.str();
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!";
584 fullPath = histDir.str()+
"/h_normxprime"+histName.str();
586 fullPath = histDir.str()+
"/h_yprime_"+histName.str();
588 fullPath = histDir.str()+
"/h_normyprime"+histName.str();
590 fullPath = histDir.str()+
"/h_"+histName.str();
592 fullPath = histDir.str()+
"/h_norm"+histName.str();
595 return histDir.str();
599 std::pair<float,float>
602 std::pair<float,float> fitResult(9999., 9999.);
603 if (!hist || hist->GetEntries() < 20)
return fitResult;
605 float mean = hist->GetMean();
606 float sigma = hist->GetRMS();
611 TF1
func(
"tmp",
"gaus", mean - 2.*sigma, mean + 2.*sigma);
612 if (0 == hist->Fit(&func,
"QNR")) {
613 mean = func.GetParameter(1);
614 sigma = func.GetParameter(2);
616 func.SetRange(mean - 3.*sigma, mean + 3.*sigma);
619 if (0 == hist->Fit(&func,
"Q0LR")) {
620 if (hist->GetFunction(func.GetName())) {
621 hist->GetFunction(func.GetName())->ResetBit(TF1::kNotDraw);
623 fitResult.first = func.GetParameter(1);
624 fitResult.second = func.GetParameter(2);
628 edm::LogWarning(
"Alignment") <<
"@SUB=TrackerOfflineValidation::fitResiduals" 629 <<
"Caught this exception during ROOT fit: " 640 const int nbins = histo->GetNbinsX();
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);
649 median = TMath::Median(nbins, x, y);
651 delete[]
x; x =
nullptr;
652 delete []
y; y =
nullptr;
670 std::map<std::string,std::string> *substructureName =
nullptr;
671 tree.SetBranchAddress(
"TkOffTreeVariables", &treeMemPtr);
672 tree.SetBranchAddress(
"SubstructureName", &substructureName);
675 for(
unsigned int iSubdet = 1; iSubdet<7; ++iSubdet){
678 std::vector<unsigned int> treeEntries;
679 for(
unsigned int iSide = 1; iSide<3; ++iSide){
682 for(
int iTree=0; iTree<tree.GetEntries(); ++iTree){
683 tree.GetEntry(iTree);
686 if(treeMemPtr->
subDetId == iSubdet){
688 treeEntries.push_back(iTree);
689 if(hierarchyName.length() == 0){
690 hierarchyName = (*substructureName)[
"subdet"];
691 componentName = (*substructureName)[
"component"];
697 hierarchyName =
""; componentName =
""; treeEntries.clear();
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";
722 if(directoryString.length()!=0)directoryString +=
"/";
723 directoryString += iHier->componentName;
726 int nBinsX(0);
double xMin(0.),
xMax(0.);
727 if(iHier->componentName ==
"Pixel"){
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();
733 else if(iHier->componentName ==
"Strip"){
735 iHier->harvestingHistos.DmrXprime =
dbe_->
book1D(dmrXprimeHistoName.str(),dmrXprimeHistoTitle.str(),nBinsX,
xMin,
xMax)->getTH1();
737 this->
getBinning(
"TH1DmrYprimeStripModules",nBinsX,xMin,xMax);
738 iHier->harvestingHistos.DmrYprime =
dbe_->
book1D(dmrYprimeHistoName.str(),dmrYprimeHistoTitle.str(),nBinsX,
xMin,
xMax)->getTH1();
758 std::map<std::string,std::string> *substructureName =
nullptr;
759 tree.SetBranchAddress(
"TkOffTreeVariables", &treeMemPtr);
760 tree.SetBranchAddress(
"SubstructureName", &substructureName);
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";
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);
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
T getParameter(std::string const &) const
void collateHarvestingHists(TTree &tree)
bool tecIsDoubleSide(const DetId &id) const
bool tobIsDoubleSide(const DetId &id) const
void applyHarvestingHierarchy(TTree &treeMem)
bool tibIsDoubleSide(const DetId &id) const
unsigned int tibLayer(const DetId &id) const
unsigned int tidRing(const DetId &id) const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Float_t numberOfOverflows
const edm::EventSetup * lastSetup_
void removeElement(std::string const &name)
std::string hierarchyName
Put here the histograms created during harvesting.
std::vector< unsigned int > tidModuleInfo(const DetId &id) const
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
unsigned int pxbLadder(const DetId &id) const
constexpr uint32_t rawId() const
get the raw id
unsigned int tidWheel(const DetId &id) const
unsigned int pxbModule(const DetId &id) const
char const * what() const override
edm::ESHandle< TrackerGeometry > tkGeom_
Float_t numberOfUnderflows
std::vector< unsigned int > tibStringInfo(const DetId &id) const
MonitorElement * book1D(char_string const &name, char_string const &title, int const nchX, double const lowX, double const highX)
Book 1D histogram.
const Plane & surface() const
The nominal surface of the GeomDet.
const edm::ParameterSet parSet_
void getBinning(const std::string &binningPSetName, int &nBinsX, double &lowerBoundX, double &upperBoundX) const
std::map< int, TrackerOfflineValidationSummary::ModuleHistos > mTibResiduals_
std::vector< unsigned int > tecPetalInfo(const DetId &id) const
#define DEFINE_FWK_MODULE(type)
std::map< int, TrackerOfflineValidationSummary::ModuleHistos > mTobResiduals_
const Surface::PositionType & position() const
The position (origin of the R.F.)
unsigned int tidSide(const DetId &id) const
std::string histNameNormX
std::map< int, TrackerOfflineValidationSummary::ModuleHistos > mPxeResiduals_
uint32_t tidStereo(const DetId &id) const
std::vector< unsigned int > tobRodInfo(const DetId &id) const
MonitorElement * get(std::string const &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
const std::string associateModuleHistsWithTree(const TkOffTreeVariables &treeMem, TrackerOfflineValidationSummary::ModuleHistos &moduleHists, std::map< std::string, std::string > &substructureName)
bool moduleMapsInitialized
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
const DetIdContainer & detIds() const override
Returm a vector of all GeomDet DetIds (including those of GeomDetUnits)
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
HarvestingHierarchy(const std::string &name, const std::string &component, const std::vector< unsigned int > &entries)
void setCurrentFolder(std::string const &fullpath)
std::string histNameLocalX
bool tidIsDoubleSide(const DetId &id) const
std::map< int, TrackerOfflineValidationSummary::ModuleHistos > mTecResiduals_
std::vector< DetId > DetIdContainer
unsigned int tobModule(const DetId &id) const
const std::string moduleDirectory_
HarvestingHistos harvestingHistos
void clear()
set to empty values
void bookHarvestingHists()
~TrackerOfflineValidationSummary() override
uint32_t tecStereo(const DetId &id) const
const TrackerGeomDet * idToDet(DetId) const override
unsigned int pxfSide(const DetId &id) const
std::string histNameNormY
uint32_t tibStereo(const DetId &id) const
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
std::string componentName
unsigned int pxfPanel(const DetId &id) const
unsigned int pxfBlade(const DetId &id) const
std::vector< unsigned int > treeEntries
unsigned int tobLayer(const DetId &id) const
float getMedian(const TH1 *hist) const
void fillHarvestingHists(TTree &tree)
unsigned int tecSide(const DetId &id) const
constexpr Detector det() const
get the detector field from this detid