107 void fillTree(TTree&
tree, std::map<int, TrackerOfflineValidationSummary::ModuleHistos>& moduleHist,
118 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)
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();
200 <<
"[TrackerOfflineValidationSummary] Error, tried to get reference for non-tracker subdet " << subdetId
201 <<
" from detector " << detId.
det();
214 TTree*
tree =
new TTree(
"TkOffVal",
"TkOffVal");
220 tree->Branch(
"TkOffTreeVariables", &treeMemPtr);
222 std::map<std::string,std::string> *substructureName =
new std::map<std::string,std::string>;
223 tree->Branch(
"SubstructureName", &substructureName, 32000, 00);
240 delete tree; tree = 0;
241 delete treeMemPtr; treeMemPtr = 0;
242 delete substructureName; substructureName = 0;
248 std::map<int, TrackerOfflineValidationSummary::ModuleHistos>& moduleHist,
251 for(std::map<int, TrackerOfflineValidationSummary::ModuleHistos>::iterator it = moduleHist.begin(),
252 itEnd= moduleHist.end(); it != itEnd;++it ) {
256 const DetId detId = it->first;
262 unsigned int whichHalfBarrel(1), rawId(detId.
rawId());
263 if( (rawId>=302056964 && rawId<302059300) || (rawId>=302123268 && rawId<302127140) || (rawId>=302189572 && rawId<302194980) )whichHalfBarrel=2;
265 treeMem.
half = whichHalfBarrel;
270 unsigned int whichHalfCylinder(1), rawId(detId.
rawId());
271 if( (rawId>=352394500 && rawId<352406032) || (rawId>=352460036 && rawId<352471568) || (rawId>=344005892 && rawId<344017424) || (rawId>=344071428 && rawId<344082960) )whichHalfCylinder=2;
274 treeMem.
half = whichHalfCylinder;
280 unsigned int whichHalfShell(1), rawId(detId.
rawId());
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;
287 treeMem.
half = whichHalfShell;
306 treeMem.
rod = tobId.
rod()[1];
328 treeMem.
posX = gPModule.
x();
329 treeMem.
posY = gPModule.
y();
330 treeMem.
posZ = gPModule.
z();
335 LocalPoint lUDirection(1.,0.,0.), lVDirection(0.,1.,0.), lWDirection(0.,0.,1.);
337 gVDirection = surface.
toGlobal(lVDirection),
338 gWDirection = surface.
toGlobal(lWDirection);
339 double dR(999.),
dPhi(999.), dZ(999.);
341 dR = gWDirection.perp() - gPModule.
perp();
343 dZ = gVDirection.z() - gPModule.
z();
348 dZ = gWDirection.z() - gPModule.
z();
351 dR = gVDirection.perp() - gPModule.
perp();
353 dZ = gWDirection.z() - gPModule.
z();
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();
373 std::pair<float,float> fitResult1 = this->
fitResiduals(it->second.ResXprimeHisto);
374 treeMem.
fitMeanX = fitResult1.first;
377 std::pair<float,float> fitResult2 = this->
fitResiduals(it->second.NormResXprimeHisto);
385 int numberOfBins=it->second.ResXprimeHisto->GetNbinsX();
387 treeMem.
numberOfOverflows = it->second.ResXprimeHisto->GetBinContent(numberOfBins+1);
388 treeMem.
numberOfOutliers = it->second.ResXprimeHisto->GetBinContent(0)+it->second.ResXprimeHisto->GetBinContent(numberOfBins+1);
390 treeMem.
meanNormX = it->second.NormResXprimeHisto->GetMean();
391 treeMem.
rmsNormX = it->second.NormResXprimeHisto->GetRMS();
394 it->second.NormResXprimeHisto->GetStats(stats);
396 if (stats[0]) treeMem.
chi2PerDofX = stats[3]/stats[0];
399 treeMem.
histNameX = it->second.ResXprimeHisto->GetName();
400 treeMem.
histNameNormX = it->second.NormResXprimeHisto->GetName();
404 if(it->second.ResHisto && it->second.NormResHisto){
405 treeMem.
meanLocalX = it->second.ResHisto->GetMean();
406 treeMem.
rmsLocalX = it->second.ResHisto->GetRMS();
415 if (it->second.ResYprimeHisto) {
416 TH1 *
h = it->second.ResYprimeHisto;
417 treeMem.
meanY = h->GetMean();
418 treeMem.
rmsY = h->GetRMS();
421 std::pair<float,float> fitMeanSigma = this->
fitResiduals(h);
422 treeMem.
fitMeanY = fitMeanSigma.first;
432 if (it->second.NormResYprimeHisto) {
433 TH1 *
h = it->second.NormResYprimeHisto;
437 if (stats[0]) treeMem.
chi2PerDofY = stats[3]/stats[0];
440 std::pair<float,float> fitMeanSigma = this->
fitResiduals(h);
449 if(removeModuleLevelHists){
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());
466 std::stringstream histDir, sSubdetName;
467 std::string componentName;
469 std::string wheelOrLayer(
"_layer_");
471 unsigned int half(treeMem.
half), layer(treeMem.
layer), ladder(0);
473 if(half==2)ladder = treeMem.
rod -5;
474 else if(treeMem.
rod>15)ladder = treeMem.
rod -10;
475 else ladder = treeMem.
rod;
477 if(half==2)ladder = treeMem.
rod -8;
478 else if(treeMem.
rod>24)ladder = treeMem.
rod -16;
479 else ladder = treeMem.
rod;
481 if(half==2)ladder = treeMem.
rod -11;
482 else if(treeMem.
rod>33)ladder = treeMem.
rod -22;
483 else ladder = treeMem.
rod;
485 componentName =
"Pixel";
486 sSubdetName<<
"TPBBarrel_1";
487 histDir<<componentName<<
"/"<<sSubdetName.str()<<
"/TPBHalfBarrel_"<<treeMem.
half<<
"/TPBLayer_"<<treeMem.
layer<<
"/TPBLadder_"<<ladder;
489 unsigned int side(treeMem.
side), half(treeMem.
half), blade(0);
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_";
499 unsigned int half(treeMem.
half), layer(treeMem.
layer), surface(treeMem.
outerInner), string(0);
502 if(surface==1)
string = treeMem.
rod -13;
503 else if(surface==2)
string = treeMem.
rod -15;
506 if(surface==1)
string = treeMem.
rod -17;
507 else if(surface==2)
string = treeMem.
rod -19;
510 if(surface==1)
string = treeMem.
rod -22;
511 else if(surface==2)
string = treeMem.
rod -23;
514 if(surface==1)
string = treeMem.
rod -26;
515 else if(surface==2)
string = treeMem.
rod -28;
518 else string = treeMem.
rod;
519 std::stringstream 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();
526 unsigned int side(treeMem.
side), outerInner(0);
530 std::stringstream 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_";
538 std::stringstream detString;
541 componentName =
"Strip";
542 sSubdetName<<
"TOBBarrel_4";
543 histDir<<componentName<<
"/"<<sSubdetName.str()<<
"/TOBHalfBarrel_"<<treeMem.
side<<
"/TOBLayer_"<<treeMem.
layer<<
"/TOBRod_"<<treeMem.
rod<<detString.str();
545 unsigned int side(0), outerInner(0),
ring(0);
546 if(treeMem.
side==1)side=6;
547 else if(treeMem.
side==2)side=5;
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;
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_";
563 substructureName[
"component"] = componentName;
564 substructureName[
"subdet"] = sSubdetName.str();
566 std::stringstream histName;
567 histName<<
"residuals_subdet_"<<treeMem.
subDetId<<wheelOrLayer<<treeMem.
layer<<
"_module_"<<treeMem.
moduleId;
569 std::string fullPath;
570 fullPath = histDir.str()+
"/h_xprime_"+histName.str();
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!";
577 fullPath = histDir.str()+
"/h_normxprime"+histName.str();
579 fullPath = histDir.str()+
"/h_yprime_"+histName.str();
581 fullPath = histDir.str()+
"/h_normyprime"+histName.str();
583 fullPath = histDir.str()+
"/h_"+histName.str();
585 fullPath = histDir.str()+
"/h_norm"+histName.str();
588 return histDir.str();
592 std::pair<float,float>
595 std::pair<float,float> fitResult(9999., 9999.);
596 if (!hist || hist->GetEntries() < 20)
return fitResult;
598 float mean = hist->GetMean();
599 float sigma = hist->GetRMS();
604 TF1 func(
"tmp",
"gaus", mean - 2.*sigma, mean + 2.*sigma);
605 if (0 == hist->Fit(&func,
"QNR")) {
606 mean = func.GetParameter(1);
607 sigma = func.GetParameter(2);
609 func.SetRange(mean - 3.*sigma, mean + 3.*sigma);
612 if (0 == hist->Fit(&func,
"Q0LR")) {
613 if (hist->GetFunction(func.GetName())) {
614 hist->GetFunction(func.GetName())->ResetBit(TF1::kNotDraw);
616 fitResult.first = func.GetParameter(1);
617 fitResult.second = func.GetParameter(2);
621 edm::LogWarning(
"Alignment") <<
"@SUB=TrackerOfflineValidation::fitResiduals"
622 <<
"Caught this exception during ROOT fit: "
633 const int nbins = histo->GetNbinsX();
636 double *
x =
new double[
nbins];
637 double *
y =
new double[
nbins];
639 x[
j] = histo->GetBinCenter(
j+1);
640 y[
j] = histo->GetBinContent(
j+1);
642 median = TMath::Median(nbins, x, y);
663 std::map<std::string,std::string> *substructureName = 0;
664 tree.SetBranchAddress(
"TkOffTreeVariables", &treeMemPtr);
665 tree.SetBranchAddress(
"SubstructureName", &substructureName);
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){
675 for(
int iTree=0; iTree<tree.GetEntries(); ++iTree){
676 tree.GetEntry(iTree);
679 if(treeMemPtr->
subDetId == iSubdet){
681 treeEntries.push_back(iTree);
682 if(hierarchyName.length() == 0){
683 hierarchyName = (*substructureName)[
"subdet"];
684 componentName = (*substructureName)[
"component"];
690 hierarchyName =
""; componentName =
""; treeEntries.clear();
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";
715 if(directoryString.length()!=0)directoryString +=
"/";
716 directoryString += iHier->componentName;
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();
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();
730 this->
getBinning(
"TH1DmrYprimeStripModules",nBinsX,xMin,xMax);
731 iHier->harvestingHistos.DmrYprime =
dbe_->
book1D(dmrYprimeHistoName.str(),dmrYprimeHistoTitle.str(),nBinsX,xMin,xMax)->getTH1();
751 std::map<std::string,std::string> *substructureName = 0;
752 tree.SetBranchAddress(
"TkOffTreeVariables", &treeMemPtr);
753 tree.SetBranchAddress(
"SubstructureName", &substructureName);
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";
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);
virtual char const * what() const
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
T getParameter(std::string const &) const
void collateHarvestingHists(TTree &tree)
bool isDoubleSide() const
unsigned int panel() const
panel id
void applyHarvestingHierarchy(TTree &treeMem)
unsigned int layer() const
layer id
Float_t numberOfOverflows
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
std::string hierarchyName
Put here the histograms created during harvesting.
bool isDoubleSide() const
#define DEFINE_FWK_MODULE(type)
container to hold data to be written into TTree
std::map< int, TrackerOfflineValidationSummary::ModuleHistos > mPxbResiduals_
std::vector< HarvestingHierarchy > vHarvestingHierarchy_
Geom::Phi< T > phi() const
unsigned int ladder() const
ladder id
~TrackerOfflineValidationSummary()
edm::ESHandle< TrackerGeometry > tkGeom_
Float_t numberOfUnderflows
std::vector< unsigned int > string() const
string id
unsigned int module() const
det id
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
unsigned int side() const
positive or negative id
const edm::ParameterSet parSet_
void getBinning(const std::string &binningPSetName, int &nBinsX, double &lowerBoundX, double &upperBoundX) const
std::vector< unsigned int > rod() const
rod id
unsigned int blade() const
blade id
uint32_t rawId() const
get the raw id
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
std::map< int, TrackerOfflineValidationSummary::ModuleHistos > mTobResiduals_
const Surface::PositionType & position() const
The position (origin of the R.F.)
std::string histNameNormX
std::map< int, TrackerOfflineValidationSummary::ModuleHistos > mPxeResiduals_
double dPhi(double phi1, double phi2)
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)
unsigned int ring() const
ring id
unsigned int module() const
det id
unsigned int module() const
det id
std::vector< unsigned int > module() const
det id
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 const GeomDet * idToDet(DetId) const
unsigned int disk() const
disk id
std::string histNameNormLocalX
std::map< int, TrackerOfflineValidationSummary::ModuleHistos > mTidResiduals_
HarvestingHierarchy(const std::string &name, const std::string &component, const std::vector< unsigned int > &entries)
unsigned int module() const
detector id
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
unsigned int side() const
positive or negative id
std::string histNameLocalX
unsigned int wheel() const
wheel id
std::map< int, TrackerOfflineValidationSummary::ModuleHistos > mTecResiduals_
unsigned int layer() const
layer id
const std::string moduleDirectory_
HarvestingHistos harvestingHistos
void clear()
set to empty values
void bookHarvestingHists()
const BoundPlane & surface() const
The nominal surface of the GeomDet.
unsigned int ring() const
ring id
bool isDoubleSide() const
unsigned int side() const
positive or negative id
virtual void analyze(const edm::Event &evt, const edm::EventSetup &)
unsigned int module() const
detector id
std::string histNameNormY
Detector det() const
get the detector field from this detid
std::string componentName
void setCurrentFolder(const std::string &fullpath)
std::vector< unsigned int > treeEntries
bool isDoubleSide() const
float getMedian(const TH1 *hist) const
void fillHarvestingHists(TTree &tree)
unsigned int wheel() const
wheel id
std::vector< DetId > DetIdContainer