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();
216 TTree*
tree =
new TTree(
"TkOffVal",
"TkOffVal");
222 tree->Branch(
"TkOffTreeVariables", &treeMemPtr);
224 std::map<std::string,std::string> *substructureName =
new std::map<std::string,std::string>;
225 tree->Branch(
"SubstructureName", &substructureName, 32000, 00);
242 delete tree; tree = 0;
243 delete treeMemPtr; treeMemPtr = 0;
244 delete substructureName; substructureName = 0;
250 std::map<int, TrackerOfflineValidationSummary::ModuleHistos>& moduleHist,
253 for(std::map<int, TrackerOfflineValidationSummary::ModuleHistos>::iterator it = moduleHist.begin(),
254 itEnd= moduleHist.end(); it != itEnd;++it ) {
258 const DetId detId = it->first;
264 unsigned int whichHalfBarrel(1), rawId(detId.
rawId());
265 if( (rawId>=302056964 && rawId<302059300) || (rawId>=302123268 && rawId<302127140) || (rawId>=302189572 && rawId<302194980) )whichHalfBarrel=2;
267 treeMem.
half = whichHalfBarrel;
272 unsigned int whichHalfCylinder(1), rawId(detId.
rawId());
273 if( (rawId>=352394500 && rawId<352406032) || (rawId>=352460036 && rawId<352471568) || (rawId>=344005892 && rawId<344017424) || (rawId>=344071428 && rawId<344082960) )whichHalfCylinder=2;
276 treeMem.
half = whichHalfCylinder;
282 unsigned int whichHalfShell(1), rawId(detId.
rawId());
283 if ( (rawId>=369120484 && rawId<369120688) || (rawId>=369121540 && rawId<369121776) || (rawId>=369136932 && rawId<369137200) || (rawId>=369137988 && rawId<369138288) ||
284 (rawId>=369153396 && rawId<369153744) || (rawId>=369154436 && rawId<369154800) || (rawId>=369169844 && rawId<369170256) || (rawId>=369170900 && rawId<369171344) ||
285 (rawId>=369124580 && rawId<369124784) || (rawId>=369125636 && rawId<369125872) || (rawId>=369141028 && rawId<369141296) || (rawId>=369142084 && rawId<369142384) ||
286 (rawId>=369157492 && rawId<369157840) || (rawId>=369158532 && rawId<369158896) || (rawId>=369173940 && rawId<369174352) || (rawId>=369174996 && rawId<369175440) ) whichHalfShell=2;
289 treeMem.
half = whichHalfShell;
308 treeMem.
rod = tobId.
rod()[1];
330 treeMem.
posX = gPModule.
x();
331 treeMem.
posY = gPModule.
y();
332 treeMem.
posZ = gPModule.
z();
337 LocalPoint lUDirection(1.,0.,0.), lVDirection(0.,1.,0.), lWDirection(0.,0.,1.);
339 gVDirection = surface.
toGlobal(lVDirection),
340 gWDirection = surface.
toGlobal(lWDirection);
341 double dR(999.),
dPhi(999.), dZ(999.);
343 dR = gWDirection.perp() - gPModule.
perp();
345 dZ = gVDirection.z() - gPModule.
z();
348 dR = gUDirection.
perp() - gPModule.
perp();
350 dZ = gWDirection.z() - gPModule.
z();
353 dR = gVDirection.perp() - gPModule.
perp();
355 dZ = gWDirection.z() - gPModule.
z();
368 treeMem.
entries =
static_cast<UInt_t>(it->second.ResXprimeHisto->GetEntries());
369 treeMem.
meanX = it->second.ResXprimeHisto->GetMean();
370 treeMem.
rmsX = it->second.ResXprimeHisto->GetRMS();
375 std::pair<float,float> fitResult1 = this->
fitResiduals(it->second.ResXprimeHisto);
376 treeMem.
fitMeanX = fitResult1.first;
379 std::pair<float,float> fitResult2 = this->
fitResiduals(it->second.NormResXprimeHisto);
387 int numberOfBins=it->second.ResXprimeHisto->GetNbinsX();
389 treeMem.
numberOfOverflows = it->second.ResXprimeHisto->GetBinContent(numberOfBins+1);
390 treeMem.
numberOfOutliers = it->second.ResXprimeHisto->GetBinContent(0)+it->second.ResXprimeHisto->GetBinContent(numberOfBins+1);
392 treeMem.
meanNormX = it->second.NormResXprimeHisto->GetMean();
393 treeMem.
rmsNormX = it->second.NormResXprimeHisto->GetRMS();
396 it->second.NormResXprimeHisto->GetStats(stats);
398 if (stats[0]) treeMem.
chi2PerDofX = stats[3]/stats[0];
401 treeMem.
histNameX = it->second.ResXprimeHisto->GetName();
402 treeMem.
histNameNormX = it->second.NormResXprimeHisto->GetName();
406 if(it->second.ResHisto && it->second.NormResHisto){
407 treeMem.
meanLocalX = it->second.ResHisto->GetMean();
408 treeMem.
rmsLocalX = it->second.ResHisto->GetRMS();
417 if (it->second.ResYprimeHisto) {
418 TH1 *
h = it->second.ResYprimeHisto;
419 treeMem.
meanY = h->GetMean();
420 treeMem.
rmsY = h->GetRMS();
423 std::pair<float,float> fitMeanSigma = this->
fitResiduals(h);
424 treeMem.
fitMeanY = fitMeanSigma.first;
434 if (it->second.NormResYprimeHisto) {
435 TH1 *
h = it->second.NormResYprimeHisto;
439 if (stats[0]) treeMem.
chi2PerDofY = stats[3]/stats[0];
442 std::pair<float,float> fitMeanSigma = this->
fitResiduals(h);
451 if(removeModuleLevelHists){
453 if(it->second.ResHisto)
dbe_->
removeElement(histDir +
"/" + it->second.ResHisto->GetName());
454 if(it->second.NormResHisto)
dbe_->
removeElement(histDir +
"/" + it->second.NormResHisto->GetName());
455 if(it->second.ResXprimeHisto)
dbe_->
removeElement(histDir +
"/" + it->second.ResXprimeHisto->GetName());
456 if(it->second.NormResXprimeHisto)
dbe_->
removeElement(histDir +
"/" + it->second.NormResXprimeHisto->GetName());
457 if(it->second.ResYprimeHisto)
dbe_->
removeElement(histDir +
"/" + it->second.ResYprimeHisto->GetName());
458 if(it->second.NormResYprimeHisto)
dbe_->
removeElement(histDir +
"/" + it->second.NormResYprimeHisto->GetName());
468 std::stringstream histDir, sSubdetName;
469 std::string componentName;
471 std::string wheelOrLayer(
"_layer_");
473 unsigned int half(treeMem.
half), layer(treeMem.
layer), ladder(0);
475 if(half==2)ladder = treeMem.
rod -5;
476 else if(treeMem.
rod>15)ladder = treeMem.
rod -10;
477 else ladder = treeMem.
rod;
479 if(half==2)ladder = treeMem.
rod -8;
480 else if(treeMem.
rod>24)ladder = treeMem.
rod -16;
481 else ladder = treeMem.
rod;
483 if(half==2)ladder = treeMem.
rod -11;
484 else if(treeMem.
rod>33)ladder = treeMem.
rod -22;
485 else ladder = treeMem.
rod;
487 componentName =
"Pixel";
488 sSubdetName<<
"TPBBarrel_1";
489 histDir<<componentName<<
"/"<<sSubdetName.str()<<
"/TPBHalfBarrel_"<<treeMem.
half<<
"/TPBLayer_"<<treeMem.
layer<<
"/TPBLadder_"<<ladder;
491 unsigned int side(treeMem.
side), half(treeMem.
half), blade(0);
493 if(half==2)blade = treeMem.
blade -6;
494 else if(treeMem.
blade>18)blade = treeMem.
blade -12;
495 else blade = treeMem.
blade;
496 componentName =
"Pixel";
497 sSubdetName<<
"TPEEndcap_"<<side;
498 histDir<<componentName<<
"/"<<sSubdetName.str()<<
"/TPEHalfCylinder_"<<treeMem.
half<<
"/TPEHalfDisk_"<<treeMem.
layer<<
"/TPEBlade_"<<blade<<
"/TPEPanel_"<<treeMem.
panel;
499 wheelOrLayer =
"_wheel_";
501 unsigned int half(treeMem.
half), layer(treeMem.
layer), surface(treeMem.
outerInner), string(0);
504 if(surface==1)
string = treeMem.
rod -13;
505 else if(surface==2)
string = treeMem.
rod -15;
508 if(surface==1)
string = treeMem.
rod -17;
509 else if(surface==2)
string = treeMem.
rod -19;
512 if(surface==1)
string = treeMem.
rod -22;
513 else if(surface==2)
string = treeMem.
rod -23;
516 if(surface==1)
string = treeMem.
rod -26;
517 else if(surface==2)
string = treeMem.
rod -28;
520 else string = treeMem.
rod;
521 std::stringstream detString;
524 componentName =
"Strip";
525 sSubdetName<<
"TIBBarrel_1";
526 histDir<<componentName<<
"/"<<sSubdetName.str()<<
"/TIBHalfBarrel_"<<treeMem.
side<<
"/TIBLayer_"<<treeMem.
layer<<
"/TIBHalfShell_"<<treeMem.
half<<
"/TIBSurface_"<<treeMem.
outerInner<<
"/TIBString_"<<
string<<detString.str();
528 unsigned int side(treeMem.
side), outerInner(0);
532 std::stringstream detString;
535 componentName =
"Strip";
536 sSubdetName<<
"TIDEndcap_"<<side;
537 histDir<<componentName<<
"/"<<sSubdetName.str()<<
"/TIDDisk_"<<treeMem.
layer<<
"/TIDRing_"<<treeMem.
ring<<
"/TIDSide_"<<outerInner<<detString.str();
538 wheelOrLayer =
"_wheel_";
540 std::stringstream detString;
543 componentName =
"Strip";
544 sSubdetName<<
"TOBBarrel_4";
545 histDir<<componentName<<
"/"<<sSubdetName.str()<<
"/TOBHalfBarrel_"<<treeMem.
side<<
"/TOBLayer_"<<treeMem.
layer<<
"/TOBRod_"<<treeMem.
rod<<detString.str();
547 unsigned int side(0), outerInner(0),
ring(0);
548 if(treeMem.
side==1)side=6;
549 else if(treeMem.
side==2)side=5;
553 else if(treeMem.
layer==7 || treeMem.
layer==8)ring = treeMem.
ring -2;
554 else if(treeMem.
layer==9)ring = treeMem.
ring -3;
555 else ring = treeMem.
ring;
556 std::stringstream detString;
559 componentName =
"Strip";
560 sSubdetName<<
"TECEndcap_"<<side;
561 histDir<<componentName<<
"/"<<sSubdetName.str()<<
"/TECDisk_"<<treeMem.
layer<<
"/TECSide_"<<outerInner<<
"/TECPetal_"<<treeMem.
petal<<
"/TECRing_"<<ring<<detString.str();
562 wheelOrLayer =
"_wheel_";
565 substructureName[
"component"] = componentName;
566 substructureName[
"subdet"] = sSubdetName.str();
568 std::stringstream histName;
569 histName<<
"residuals_subdet_"<<treeMem.
subDetId<<wheelOrLayer<<treeMem.
layer<<
"_module_"<<treeMem.
moduleId;
571 std::string fullPath;
572 fullPath = histDir.str()+
"/h_xprime_"+histName.str();
574 else{
edm::LogError(
"TrackerOfflineValidationSummary")<<
"Problem with names in input file produced in TrackerOfflineValidation ...\n"
575 <<
"This histogram should exist in every configuration, "
576 <<
"but no histogram with name "<<fullPath<<
" is found!";
579 fullPath = histDir.str()+
"/h_normxprime"+histName.str();
581 fullPath = histDir.str()+
"/h_yprime_"+histName.str();
583 fullPath = histDir.str()+
"/h_normyprime"+histName.str();
585 fullPath = histDir.str()+
"/h_"+histName.str();
587 fullPath = histDir.str()+
"/h_norm"+histName.str();
590 return histDir.str();
594 std::pair<float,float>
597 std::pair<float,float> fitResult(9999., 9999.);
598 if (!hist || hist->GetEntries() < 20)
return fitResult;
600 float mean = hist->GetMean();
601 float sigma = hist->GetRMS();
606 TF1 func(
"tmp",
"gaus", mean - 2.*sigma, mean + 2.*sigma);
607 if (0 == hist->Fit(&func,
"QNR")) {
608 mean = func.GetParameter(1);
609 sigma = func.GetParameter(2);
611 func.SetRange(mean - 3.*sigma, mean + 3.*sigma);
614 if (0 == hist->Fit(&func,
"Q0LR")) {
615 if (hist->GetFunction(func.GetName())) {
616 hist->GetFunction(func.GetName())->ResetBit(TF1::kNotDraw);
618 fitResult.first = func.GetParameter(1);
619 fitResult.second = func.GetParameter(2);
623 edm::LogWarning(
"Alignment") <<
"@SUB=TrackerOfflineValidation::fitResiduals"
624 <<
"Caught this exception during ROOT fit: "
635 const int nbins = histo->GetNbinsX();
638 double *
x =
new double[
nbins];
639 double *
y =
new double[
nbins];
641 x[
j] = histo->GetBinCenter(
j+1);
642 y[
j] = histo->GetBinContent(
j+1);
644 median = TMath::Median(nbins, x, y);
665 std::map<std::string,std::string> *substructureName = 0;
666 tree.SetBranchAddress(
"TkOffTreeVariables", &treeMemPtr);
667 tree.SetBranchAddress(
"SubstructureName", &substructureName);
670 for(
unsigned int iSubdet = 1; iSubdet<7; ++iSubdet){
671 std::string hierarchyName(
"");
672 std::string componentName(
"");
673 std::vector<unsigned int> treeEntries;
674 for(
unsigned int iSide = 1; iSide<3; ++iSide){
677 for(
int iTree=0; iTree<tree.GetEntries(); ++iTree){
678 tree.GetEntry(iTree);
681 if(treeMemPtr->
subDetId == iSubdet){
683 treeEntries.push_back(iTree);
684 if(hierarchyName.length() == 0){
685 hierarchyName = (*substructureName)[
"subdet"];
686 componentName = (*substructureName)[
"component"];
692 hierarchyName =
""; componentName =
""; treeEntries.clear();
710 std::stringstream dmrXprimeHistoName, dmrYprimeHistoName, dmrXprimeHistoTitle, dmrYprimeHistoTitle;
711 dmrXprimeHistoName <<
"h_DmrXprime_" << iHier->hierarchyName;
712 dmrYprimeHistoName <<
"h_DmrYprime_" << iHier->hierarchyName;
713 dmrXprimeHistoTitle<<
"DMR for " << iHier->hierarchyName <<
";<#DeltaX> [cm];# modules";
714 dmrYprimeHistoTitle<<
"DMR for " << iHier->hierarchyName <<
";<#DeltaY> [cm];# modules";
717 if(directoryString.length()!=0)directoryString +=
"/";
718 directoryString += iHier->componentName;
721 int nBinsX(0);
double xMin(0.), xMax(0.);
722 if(iHier->componentName ==
"Pixel"){
723 this->
getBinning(
"TH1DmrXprimePixelModules",nBinsX,xMin,xMax);
724 iHier->harvestingHistos.DmrXprime =
dbe_->
book1D(dmrXprimeHistoName.str(),dmrXprimeHistoTitle.str(),nBinsX,xMin,xMax)->getTH1();
725 this->
getBinning(
"TH1DmrYprimePixelModules",nBinsX,xMin,xMax);
726 iHier->harvestingHistos.DmrYprime =
dbe_->
book1D(dmrYprimeHistoName.str(),dmrYprimeHistoTitle.str(),nBinsX,xMin,xMax)->getTH1();
728 else if(iHier->componentName ==
"Strip"){
729 this->
getBinning(
"TH1DmrXprimeStripModules",nBinsX,xMin,xMax);
730 iHier->harvestingHistos.DmrXprime =
dbe_->
book1D(dmrXprimeHistoName.str(),dmrXprimeHistoTitle.str(),nBinsX,xMin,xMax)->getTH1();
732 this->
getBinning(
"TH1DmrYprimeStripModules",nBinsX,xMin,xMax);
733 iHier->harvestingHistos.DmrYprime =
dbe_->
book1D(dmrYprimeHistoName.str(),dmrYprimeHistoTitle.str(),nBinsX,xMin,xMax)->getTH1();
753 std::map<std::string,std::string> *substructureName = 0;
754 tree.SetBranchAddress(
"TkOffTreeVariables", &treeMemPtr);
755 tree.SetBranchAddress(
"SubstructureName", &substructureName);
757 const unsigned int minEntriesPerModule(
parSet_.
getParameter<
unsigned int>(
"minEntriesPerModuleForDmr"));
758 edm::LogInfo(
"TrackerOfflineValidationSummary")<<
"Median of a module is added to DMR plots if it contains at least "<<minEntriesPerModule<<
" hits";
761 for(std::vector<unsigned int>::const_iterator iTreeEntries = iHier->treeEntries.begin(); iTreeEntries != iHier->treeEntries.end(); ++iTreeEntries){
762 tree.GetEntry(*iTreeEntries);
763 if(treeMemPtr->
entries < minEntriesPerModule)
continue;
764 iHier->harvestingHistos.DmrXprime->Fill(treeMemPtr->
medianX);
765 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
virtual uint32_t stereo() const
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.
double deltaPhi(float phi1, float phi2)
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
Allows conversion between type and name, and vice-versa.
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
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()
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
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Detector det() const
get the detector field from this detid
virtual const BoundPlane & surface() const
The nominal surface of the GeomDet.
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