102 virtual void endJob()
override ;
104 void fillTree(TTree&
tree, std::map<int, TrackerOfflineValidationSummary::ModuleHistos>& moduleHist,
106 std::map<std::string,std::string>& substructureName,
const TrackerTopology* tTopo);
116 void getBinning(
const std::string& binningPSetName,
int& nBinsX,
double& lowerBoundX,
double& upperBoundX)
const;
156 parSet_(iConfig), moduleDirectory_(parSet_.getParameter<std::
string>(
"moduleDirectoryInOutput")),
157 useFit_(parSet_.getParameter<bool>(
"useFit")),
dbe_(0), moduleMapsInitialized(
false), lastSetup_(
nullptr)
189 std::vector<DetId>::const_iterator iDet;
190 for(iDet = detIdContainer.begin(); iDet != detIdContainer.end(); ++iDet){
191 const DetId& detId = *iDet;
192 const uint32_t rawId = detId.
rawId();
193 const unsigned int subdetId = detId.
subdetId();
202 <<
"[TrackerOfflineValidationSummary] Error, tried to get reference for non-tracker subdet " << subdetId
203 <<
" from detector " << detId.
det();
221 TTree*
tree =
new TTree(
"TkOffVal",
"TkOffVal");
227 tree->Branch(
"TkOffTreeVariables", &treeMemPtr);
229 std::map<std::string,std::string> *substructureName =
new std::map<std::string,std::string>;
230 tree->Branch(
"SubstructureName", &substructureName, 32000, 00);
247 delete tree; tree = 0;
248 delete treeMemPtr; treeMemPtr = 0;
249 delete substructureName; substructureName = 0;
256 std::map<std::string,std::string>& substructureName,
259 for(std::map<int, TrackerOfflineValidationSummary::ModuleHistos>::iterator it = moduleHist.begin(),
260 itEnd= moduleHist.end(); it != itEnd;++it ) {
264 const DetId detId = it->first;
270 unsigned int whichHalfBarrel(1), rawId(detId.
rawId());
271 if( (rawId>=302056964 && rawId<302059300) || (rawId>=302123268 && rawId<302127140) || (rawId>=302189572 && rawId<302194980) )whichHalfBarrel=2;
273 treeMem.
half = whichHalfBarrel;
278 unsigned int whichHalfCylinder(1), rawId(detId.
rawId());
279 if( (rawId>=352394500 && rawId<352406032) || (rawId>=352460036 && rawId<352471568) || (rawId>=344005892 && rawId<344017424) || (rawId>=344071428 && rawId<344082960) )whichHalfCylinder=2;
282 treeMem.
half = whichHalfCylinder;
288 unsigned int whichHalfShell(1), rawId(detId.
rawId());
289 if ( (rawId>=369120484 && rawId<369120688) || (rawId>=369121540 && rawId<369121776) || (rawId>=369136932 && rawId<369137200) || (rawId>=369137988 && rawId<369138288) ||
290 (rawId>=369153396 && rawId<369153744) || (rawId>=369154436 && rawId<369154800) || (rawId>=369169844 && rawId<369170256) || (rawId>=369170900 && rawId<369171344) ||
291 (rawId>=369124580 && rawId<369124784) || (rawId>=369125636 && rawId<369125872) || (rawId>=369141028 && rawId<369141296) || (rawId>=369142084 && rawId<369142384) ||
292 (rawId>=369157492 && rawId<369157840) || (rawId>=369158532 && rawId<369158896) || (rawId>=369173940 && rawId<369174352) || (rawId>=369174996 && rawId<369175440) ) whichHalfShell=2;
295 treeMem.
half = whichHalfShell;
336 treeMem.
posX = gPModule.
x();
337 treeMem.
posY = gPModule.
y();
338 treeMem.
posZ = gPModule.
z();
343 LocalPoint lUDirection(1.,0.,0.), lVDirection(0.,1.,0.), lWDirection(0.,0.,1.);
345 gVDirection = surface.
toGlobal(lVDirection),
346 gWDirection = surface.
toGlobal(lWDirection);
347 double dR(999.),
dPhi(999.), dZ(999.);
349 dR = gWDirection.perp() - gPModule.
perp();
351 dZ = gVDirection.z() - gPModule.
z();
356 dZ = gWDirection.z() - gPModule.
z();
359 dR = gVDirection.perp() - gPModule.
perp();
361 dZ = gWDirection.z() - gPModule.
z();
374 treeMem.
entries =
static_cast<UInt_t
>(it->second.ResXprimeHisto->GetEntries());
375 treeMem.
meanX = it->second.ResXprimeHisto->GetMean();
376 treeMem.
rmsX = it->second.ResXprimeHisto->GetRMS();
381 std::pair<float,float> fitResult1 = this->
fitResiduals(it->second.ResXprimeHisto);
382 treeMem.
fitMeanX = fitResult1.first;
385 std::pair<float,float> fitResult2 = this->
fitResiduals(it->second.NormResXprimeHisto);
393 int numberOfBins=it->second.ResXprimeHisto->GetNbinsX();
395 treeMem.
numberOfOverflows = it->second.ResXprimeHisto->GetBinContent(numberOfBins+1);
396 treeMem.
numberOfOutliers = it->second.ResXprimeHisto->GetBinContent(0)+it->second.ResXprimeHisto->GetBinContent(numberOfBins+1);
398 treeMem.
meanNormX = it->second.NormResXprimeHisto->GetMean();
399 treeMem.
rmsNormX = it->second.NormResXprimeHisto->GetRMS();
402 it->second.NormResXprimeHisto->GetStats(stats);
404 if (stats[0]) treeMem.
chi2PerDofX = stats[3]/stats[0];
407 treeMem.
histNameX = it->second.ResXprimeHisto->GetName();
408 treeMem.
histNameNormX = it->second.NormResXprimeHisto->GetName();
412 if(it->second.ResHisto && it->second.NormResHisto){
413 treeMem.
meanLocalX = it->second.ResHisto->GetMean();
414 treeMem.
rmsLocalX = it->second.ResHisto->GetRMS();
423 if (it->second.ResYprimeHisto) {
424 TH1 *
h = it->second.ResYprimeHisto;
425 treeMem.
meanY = h->GetMean();
426 treeMem.
rmsY = h->GetRMS();
429 std::pair<float,float> fitMeanSigma = this->
fitResiduals(h);
430 treeMem.
fitMeanY = fitMeanSigma.first;
440 if (it->second.NormResYprimeHisto) {
441 TH1 *
h = it->second.NormResYprimeHisto;
445 if (stats[0]) treeMem.
chi2PerDofY = stats[3]/stats[0];
448 std::pair<float,float> fitMeanSigma = this->
fitResiduals(h);
457 if(removeModuleLevelHists){
459 if(it->second.ResHisto)
dbe_->
removeElement(histDir +
"/" + it->second.ResHisto->GetName());
460 if(it->second.NormResHisto)
dbe_->
removeElement(histDir +
"/" + it->second.NormResHisto->GetName());
461 if(it->second.ResXprimeHisto)
dbe_->
removeElement(histDir +
"/" + it->second.ResXprimeHisto->GetName());
462 if(it->second.NormResXprimeHisto)
dbe_->
removeElement(histDir +
"/" + it->second.NormResXprimeHisto->GetName());
463 if(it->second.ResYprimeHisto)
dbe_->
removeElement(histDir +
"/" + it->second.ResYprimeHisto->GetName());
464 if(it->second.NormResYprimeHisto)
dbe_->
removeElement(histDir +
"/" + it->second.NormResYprimeHisto->GetName());
474 std::stringstream histDir, sSubdetName;
479 unsigned int half(treeMem.
half), layer(treeMem.
layer), ladder(0);
481 if(half==2)ladder = treeMem.
rod -5;
482 else if(treeMem.
rod>15)ladder = treeMem.
rod -10;
483 else ladder = treeMem.
rod;
485 if(half==2)ladder = treeMem.
rod -8;
486 else if(treeMem.
rod>24)ladder = treeMem.
rod -16;
487 else ladder = treeMem.
rod;
489 if(half==2)ladder = treeMem.
rod -11;
490 else if(treeMem.
rod>33)ladder = treeMem.
rod -22;
491 else ladder = treeMem.
rod;
493 componentName =
"Pixel";
494 sSubdetName<<
"TPBBarrel_1";
495 histDir<<componentName<<
"/"<<sSubdetName.str()<<
"/TPBHalfBarrel_"<<treeMem.
half<<
"/TPBLayer_"<<treeMem.
layer<<
"/TPBLadder_"<<ladder;
497 unsigned int side(treeMem.
side), half(treeMem.
half), blade(0);
499 if(half==2)blade = treeMem.
blade -6;
500 else if(treeMem.
blade>18)blade = treeMem.
blade -12;
501 else blade = treeMem.
blade;
502 componentName =
"Pixel";
503 sSubdetName<<
"TPEEndcap_"<<side;
504 histDir<<componentName<<
"/"<<sSubdetName.str()<<
"/TPEHalfCylinder_"<<treeMem.
half<<
"/TPEHalfDisk_"<<treeMem.
layer<<
"/TPEBlade_"<<blade<<
"/TPEPanel_"<<treeMem.
panel;
505 wheelOrLayer =
"_wheel_";
510 if(surface==1)
string = treeMem.
rod -13;
511 else if(surface==2)
string = treeMem.
rod -15;
514 if(surface==1)
string = treeMem.
rod -17;
515 else if(surface==2)
string = treeMem.
rod -19;
518 if(surface==1)
string = treeMem.
rod -22;
519 else if(surface==2)
string = treeMem.
rod -23;
522 if(surface==1)
string = treeMem.
rod -26;
523 else if(surface==2)
string = treeMem.
rod -28;
526 else string = treeMem.
rod;
527 std::stringstream detString;
530 componentName =
"Strip";
531 sSubdetName<<
"TIBBarrel_1";
532 histDir<<componentName<<
"/"<<sSubdetName.str()<<
"/TIBHalfBarrel_"<<treeMem.
side<<
"/TIBLayer_"<<treeMem.
layer<<
"/TIBHalfShell_"<<treeMem.
half<<
"/TIBSurface_"<<treeMem.
outerInner<<
"/TIBString_"<<
string<<detString.str();
534 unsigned int side(treeMem.
side), outerInner(0);
538 std::stringstream detString;
541 componentName =
"Strip";
542 sSubdetName<<
"TIDEndcap_"<<side;
543 histDir<<componentName<<
"/"<<sSubdetName.str()<<
"/TIDDisk_"<<treeMem.
layer<<
"/TIDRing_"<<treeMem.
ring<<
"/TIDSide_"<<outerInner<<detString.str();
544 wheelOrLayer =
"_wheel_";
546 std::stringstream detString;
549 componentName =
"Strip";
550 sSubdetName<<
"TOBBarrel_4";
551 histDir<<componentName<<
"/"<<sSubdetName.str()<<
"/TOBHalfBarrel_"<<treeMem.
side<<
"/TOBLayer_"<<treeMem.
layer<<
"/TOBRod_"<<treeMem.
rod<<detString.str();
553 unsigned int side(0), outerInner(0),
ring(0);
554 if(treeMem.
side==1)side=6;
555 else if(treeMem.
side==2)side=5;
559 else if(treeMem.
layer==7 || treeMem.
layer==8)ring = treeMem.
ring -2;
560 else if(treeMem.
layer==9)ring = treeMem.
ring -3;
561 else ring = treeMem.
ring;
562 std::stringstream detString;
565 componentName =
"Strip";
566 sSubdetName<<
"TECEndcap_"<<side;
567 histDir<<componentName<<
"/"<<sSubdetName.str()<<
"/TECDisk_"<<treeMem.
layer<<
"/TECSide_"<<outerInner<<
"/TECPetal_"<<treeMem.
petal<<
"/TECRing_"<<ring<<detString.str();
568 wheelOrLayer =
"_wheel_";
571 substructureName[
"component"] = componentName;
572 substructureName[
"subdet"] = sSubdetName.str();
574 std::stringstream histName;
575 histName<<
"residuals_subdet_"<<treeMem.
subDetId<<wheelOrLayer<<treeMem.
layer<<
"_module_"<<treeMem.
moduleId;
578 fullPath = histDir.str()+
"/h_xprime_"+histName.str();
580 else{
edm::LogError(
"TrackerOfflineValidationSummary")<<
"Problem with names in input file produced in TrackerOfflineValidation ...\n"
581 <<
"This histogram should exist in every configuration, "
582 <<
"but no histogram with name "<<fullPath<<
" is found!";
585 fullPath = histDir.str()+
"/h_normxprime"+histName.str();
587 fullPath = histDir.str()+
"/h_yprime_"+histName.str();
589 fullPath = histDir.str()+
"/h_normyprime"+histName.str();
591 fullPath = histDir.str()+
"/h_"+histName.str();
593 fullPath = histDir.str()+
"/h_norm"+histName.str();
596 return histDir.str();
600 std::pair<float,float>
603 std::pair<float,float> fitResult(9999., 9999.);
604 if (!hist || hist->GetEntries() < 20)
return fitResult;
606 float mean = hist->GetMean();
607 float sigma = hist->GetRMS();
612 TF1
func(
"tmp",
"gaus", mean - 2.*sigma, mean + 2.*sigma);
613 if (0 == hist->Fit(&func,
"QNR")) {
614 mean = func.GetParameter(1);
615 sigma = func.GetParameter(2);
617 func.SetRange(mean - 3.*sigma, mean + 3.*sigma);
620 if (0 == hist->Fit(&func,
"Q0LR")) {
621 if (hist->GetFunction(func.GetName())) {
622 hist->GetFunction(func.GetName())->ResetBit(TF1::kNotDraw);
624 fitResult.first = func.GetParameter(1);
625 fitResult.second = func.GetParameter(2);
629 edm::LogWarning(
"Alignment") <<
"@SUB=TrackerOfflineValidation::fitResiduals"
630 <<
"Caught this exception during ROOT fit: "
641 const int nbins = histo->GetNbinsX();
644 double *
x =
new double[
nbins];
645 double *
y =
new double[
nbins];
647 x[
j] = histo->GetBinCenter(
j+1);
648 y[
j] = histo->GetBinContent(
j+1);
650 median = TMath::Median(nbins, x, y);
671 std::map<std::string,std::string> *substructureName = 0;
672 tree.SetBranchAddress(
"TkOffTreeVariables", &treeMemPtr);
673 tree.SetBranchAddress(
"SubstructureName", &substructureName);
676 for(
unsigned int iSubdet = 1; iSubdet<7; ++iSubdet){
679 std::vector<unsigned int> treeEntries;
680 for(
unsigned int iSide = 1; iSide<3; ++iSide){
683 for(
int iTree=0; iTree<tree.GetEntries(); ++iTree){
684 tree.GetEntry(iTree);
687 if(treeMemPtr->
subDetId == iSubdet){
689 treeEntries.push_back(iTree);
690 if(hierarchyName.length() == 0){
691 hierarchyName = (*substructureName)[
"subdet"];
692 componentName = (*substructureName)[
"component"];
698 hierarchyName =
""; componentName =
""; treeEntries.clear();
716 std::stringstream dmrXprimeHistoName, dmrYprimeHistoName, dmrXprimeHistoTitle, dmrYprimeHistoTitle;
717 dmrXprimeHistoName <<
"h_DmrXprime_" << iHier->hierarchyName;
718 dmrYprimeHistoName <<
"h_DmrYprime_" << iHier->hierarchyName;
719 dmrXprimeHistoTitle<<
"DMR for " << iHier->hierarchyName <<
";<#DeltaX> [cm];# modules";
720 dmrYprimeHistoTitle<<
"DMR for " << iHier->hierarchyName <<
";<#DeltaY> [cm];# modules";
723 if(directoryString.length()!=0)directoryString +=
"/";
724 directoryString += iHier->componentName;
727 int nBinsX(0);
double xMin(0.), xMax(0.);
728 if(iHier->componentName ==
"Pixel"){
729 this->
getBinning(
"TH1DmrXprimePixelModules",nBinsX,xMin,xMax);
730 iHier->harvestingHistos.DmrXprime =
dbe_->
book1D(dmrXprimeHistoName.str(),dmrXprimeHistoTitle.str(),nBinsX,xMin,xMax)->getTH1();
731 this->
getBinning(
"TH1DmrYprimePixelModules",nBinsX,xMin,xMax);
732 iHier->harvestingHistos.DmrYprime =
dbe_->
book1D(dmrYprimeHistoName.str(),dmrYprimeHistoTitle.str(),nBinsX,xMin,xMax)->getTH1();
734 else if(iHier->componentName ==
"Strip"){
735 this->
getBinning(
"TH1DmrXprimeStripModules",nBinsX,xMin,xMax);
736 iHier->harvestingHistos.DmrXprime =
dbe_->
book1D(dmrXprimeHistoName.str(),dmrXprimeHistoTitle.str(),nBinsX,xMin,xMax)->getTH1();
738 this->
getBinning(
"TH1DmrYprimeStripModules",nBinsX,xMin,xMax);
739 iHier->harvestingHistos.DmrYprime =
dbe_->
book1D(dmrYprimeHistoName.str(),dmrYprimeHistoTitle.str(),nBinsX,xMin,xMax)->getTH1();
759 std::map<std::string,std::string> *substructureName = 0;
760 tree.SetBranchAddress(
"TkOffTreeVariables", &treeMemPtr);
761 tree.SetBranchAddress(
"SubstructureName", &substructureName);
763 const unsigned int minEntriesPerModule(
parSet_.
getParameter<
unsigned int>(
"minEntriesPerModuleForDmr"));
764 edm::LogInfo(
"TrackerOfflineValidationSummary")<<
"Median of a module is added to DMR plots if it contains at least "<<minEntriesPerModule<<
" hits";
767 for(std::vector<unsigned int>::const_iterator iTreeEntries = iHier->treeEntries.begin(); iTreeEntries != iHier->treeEntries.end(); ++iTreeEntries){
768 tree.GetEntry(*iTreeEntries);
769 if(treeMemPtr->
entries < minEntriesPerModule)
continue;
770 iHier->harvestingHistos.DmrXprime->Fill(treeMemPtr->
medianX);
771 if(iHier->harvestingHistos.DmrYprime)iHier->harvestingHistos.DmrYprime->Fill(treeMemPtr->
medianY);
virtual char const * what() const
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
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
const edm::EventSetup * lastSetup_
std::string hierarchyName
Put here the histograms created during harvesting.
std::vector< unsigned int > tidModuleInfo(const DetId &id) const
#define DEFINE_FWK_MODULE(type)
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
unsigned int tidWheel(const DetId &id) const
unsigned int pxbModule(const DetId &id) const
~TrackerOfflineValidationSummary()
edm::ESHandle< TrackerGeometry > tkGeom_
Float_t numberOfUnderflows
std::vector< unsigned int > tibStringInfo(const DetId &id) const
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
uint32_t rawId() const
get the raw id
std::map< int, TrackerOfflineValidationSummary::ModuleHistos > mTibResiduals_
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.)
unsigned int tidSide(const DetId &id) const
std::string histNameNormX
std::map< int, TrackerOfflineValidationSummary::ModuleHistos > mPxeResiduals_
double dPhi(double phi1, double phi2)
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)
bool moduleMapsInitialized
void removeElement(const std::string &name)
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
std::pair< float, float > fitResiduals(TH1 *hist) const
TrackerOfflineValidationSummary(const edm::ParameterSet &)
virtual 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)
virtual void endJob() override
std::string histNameLocalX
bool tidIsDoubleSide(const DetId &id) const
T const * product() const
std::map< int, TrackerOfflineValidationSummary::ModuleHistos > mTecResiduals_
unsigned int tobModule(const DetId &id) const
const std::string moduleDirectory_
HarvestingHistos harvestingHistos
void clear()
set to empty values
void bookHarvestingHists()
const DetIdContainer & detIds() const
Returm a vector of all GeomDet DetIds (including those of GeomDetUnits)
uint32_t tecStereo(const DetId &id) const
unsigned int pxfSide(const DetId &id) const
volatile std::atomic< bool > shutdown_flag false
std::string histNameNormY
uint32_t tibStereo(const DetId &id) const
Detector det() const
get the detector field from this detid
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
std::string componentName
unsigned int pxfPanel(const DetId &id) const
unsigned int pxfBlade(const DetId &id) const
void setCurrentFolder(const std::string &fullpath)
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
const TrackerGeomDet * idToDet(DetId) const
std::vector< DetId > DetIdContainer