Skip to content

Commit

Permalink
Merge pull request #14730 from cms-trackeralign/80X_AddPixelBarycente…
Browse files Browse the repository at this point in the history
…rTool

81x: add pixel barycenter computation tool
  • Loading branch information
cmsbuild committed Jun 2, 2016
2 parents 6aa19bd + a36a6a4 commit 10344c1
Show file tree
Hide file tree
Showing 3 changed files with 333 additions and 0 deletions.
114 changes: 114 additions & 0 deletions Alignment/MillePedeAlignmentAlgorithm/macros/pixelPositionChange.C
@@ -0,0 +1,114 @@
// Take two treeFile names as input,
// plot pixel module positions using PlotMillePede::DrawOrigPos(..)
// for BPIX and (BPIX+FPIX) and get the mean values of the histograms
// (i.e. centre of gravity).
// These are printed (in cm) and the difference is evaluated (in mum).
//
// Before executing this script you have to execute allMillePede.C.

#include <vector>
#include <iostream>
#include "GFUtils/GFHistManager.h"
#include "GFUtils/GFHistArray.h"
#include "PlotMillePede.h"

void pixelPositionChange(const char *treeFile1, const char *treeFile2)
{
std::vector<PlotMillePede*> ps;
ps.push_back(new PlotMillePede(treeFile1));
ps.push_back(new PlotMillePede(treeFile2));

std::vector<double> meanBPIX_X(ps.size());
std::vector<double> meanBPIX_Y(ps.size());
std::vector<double> meanBPIX_Z(ps.size());

std::vector<double> meanPixel_X(ps.size());
std::vector<double> meanPixel_Y(ps.size());
std::vector<double> meanPixel_Z(ps.size());
for (unsigned int i = 0; i < ps.size(); ++i) {
ps[i]->GetHistManager()->SetBatch();
ps[i]->SetSubDetId(1);
ps[i]->DrawOrigPos();
meanBPIX_X[i] = ps[i]->GetHistManager()->GetHistsOf(0,2)->First()->GetMean();
meanBPIX_Y[i] = ps[i]->GetHistManager()->GetHistsOf(0,3)->First()->GetMean();
meanBPIX_Z[i] = ps[i]->GetHistManager()->GetHistsOf(0,4)->First()->GetMean();
ps[i]->SetSubDetIds(1,2);
ps[i]->DrawOrigPos(true);
meanPixel_X[i] = ps[i]->GetHistManager()->GetHistsOf(1,2)->First()->GetMean();
meanPixel_Y[i] = ps[i]->GetHistManager()->GetHistsOf(1,3)->First()->GetMean();
meanPixel_Z[i] = ps[i]->GetHistManager()->GetHistsOf(1,4)->First()->GetMean();

}
ps[0]->GetHistManager()->Overlay(ps[1]->GetHistManager(), 0, 0, "second");
ps[0]->GetHistManager()->Overlay(ps[1]->GetHistManager(), 1, 1, "second");
ps[0]->GetHistManager()->SetBatch(false);
ps[0]->GetHistManager()->SameWithStats(true);
ps[0]->GetHistManager()->Draw();

const char separator[] = "====================================================\n";

std::cout << separator << "BPIX:\n" << separator
<< "x1 x2: " << meanBPIX_X[0] << " " << meanBPIX_X[1]
<< '\n'
// << ", diff (in mum) "
// << (meanBPIX_X[1] - meanBPIX_X[0])* 10000. << '\n'

<< "y1 y2: " << meanBPIX_Y[0] << " " << meanBPIX_Y[1]
<< '\n'
// << ", diff (in mum) "
// << (meanBPIX_Y[1] - meanBPIX_Y[0])* 10000. << '\n'

<< "z1 z2: " << meanBPIX_Z[0] << " " << meanBPIX_Z[1]
<< '\n'
// << ", diff (in mum) "
// << (meanBPIX_Z[1] - meanBPIX_Z[0])* 10000.

<< "Delta(x,y,z) = 2-1 = ("
<< (meanBPIX_X[1] - meanBPIX_X[0])* 10000. << ','
<< (meanBPIX_Y[1] - meanBPIX_Y[0])* 10000. << ','
<< (meanBPIX_Z[1] - meanBPIX_Z[0])* 10000. << ") mum"
<< std::endl;

std::cout << separator << "Pixel:\n" << separator;

std::cout << "x1 x2: " << meanPixel_X[0] << " " << meanPixel_X[1]
<< '\n'
// << ", diff (in mum) "
// << (meanPixel_X[1] - meanPixel_X[0])* 10000. << '\n'

<< "y1 y2 " << meanPixel_Y[0] << " " << meanPixel_Y[1]
<< '\n'
// << ", diff (in mum) "
// << (meanPixel_Y[1] - meanPixel_Y[0])* 10000. << '\n'

<< "z1 z2: " << meanPixel_Z[0] << " " << meanPixel_Z[1]
<< '\n'
// << ", diff (in mum) "
// << (meanPixel_Z[1] - meanPixel_Z[0])* 10000.

<< "Delta(x,y,z) = 2-1 = ("
<< (meanPixel_X[1] - meanPixel_X[0])* 10000. << ','
<< (meanPixel_Y[1] - meanPixel_Y[0])* 10000. << ','
<< (meanPixel_Z[1] - meanPixel_Z[0])* 10000. << ") mum"
<< std::endl;

TString shortFileName1(treeFile1);
if (shortFileName1.Contains("/")) { // remove all directory info
shortFileName1.Remove(0, shortFileName1.Last('/') + 1);
}
TString shortFileName2(treeFile2);
if (shortFileName2.Contains("/")) {
shortFileName2.Remove(0, shortFileName2.Last('/') + 1);
}

std::cout << "| | *" << shortFileName1 << "* || *"<< shortFileName1 << "*||\n"
<< "| *Position* | *BPIX* | *Full Pixel* | *BPIX* | *Full Pixel* |\n"
<< "| x | " << meanBPIX_X[0] << " | " << meanPixel_X[0] << " | " << meanBPIX_X[1] << " | " << meanPixel_X[1] << " |\n"
<< "| y | " << meanBPIX_Y[0] << " | " << meanPixel_Y[0] << " | " << meanBPIX_Y[1] << " | " << meanPixel_Y[1] << " |\n"
<< "| z | " << meanBPIX_Z[0] << " | " << meanPixel_Z[0] << " | " << meanBPIX_Z[1] << " | " << meanPixel_Z[1] << " |\n"
<< std::endl;

std::cout << separator << separator << separator << std::endl;

}

100 changes: 100 additions & 0 deletions Alignment/TrackerAlignment/test/alignment_forGeomComp_cfg_TEMPLATE.py
@@ -0,0 +1,100 @@
# Config file template to produce a treeFile.root usable as input for
# .../CMSSW/Alignment/MillePedeAlignmentAlgorithm/macros/CompareMillePede.h
# to compare two different geometries.
#
#GLOBALTAG # without '::All'
#RUNNUMBER
#TREEFILE
#LOGFILE

import FWCore.ParameterSet.Config as cms

process = cms.Process("Alignment")

process.options = cms.untracked.PSet(
Rethrow = cms.untracked.vstring("ProductNotFound") # do not accept this exception
)

# initialize magnetic field
process.load("Configuration.StandardSequences.MagneticField_cff")
# geometry
process.load("Configuration.Geometry.GeometryRecoDB_cff")
# global tag and other conditions
process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
# take your favourite global tag
from Configuration.AlCa.GlobalTag import GlobalTag
process.GlobalTag = GlobalTag(process.GlobalTag, "GLOBALTAG")
usedGlobalTag = process.GlobalTag.globaltag._value

process.load("FWCore.MessageService.MessageLogger_cfi")
process.MessageLogger.LOGFILE = cms.untracked.PSet(
DEBUG = cms.untracked.PSet(
limit = cms.untracked.int32(-1)
),
INFO = cms.untracked.PSet(
limit = cms.untracked.int32(5),
reportEvery = cms.untracked.int32(5)
),
WARNING = cms.untracked.PSet(
limit = cms.untracked.int32(10)
),
ERROR = cms.untracked.PSet(
limit = cms.untracked.int32(-1)
),
Alignment = cms.untracked.PSet(
limit = cms.untracked.int32(-1),
reportEvery = cms.untracked.int32(1)
)
)
process.MessageLogger.cerr.placeholder = cms.untracked.bool(True)
process.MessageLogger.destinations = ['LOGFILE']
process.MessageLogger.statistics = ['LOGFILE']
process.MessageLogger.categories = ['Alignment']

## if alignment constants not from global tag, add this
from CondCore.CondDB.CondDB_cfi import *
CondDBReference = CondDB.clone(connect = cms.string('sqlite_file:remove_me.db'))

# Alignment producer
process.load("Alignment.CommonAlignmentProducer.AlignmentProducer_cff")

process.AlignmentProducer.ParameterBuilder.Selector = cms.PSet(
alignParams = cms.vstring(
'TrackerTPBModule,111111',
'TrackerTPEModule,111111',
# 'TrackerTIBModuleUnit,101111',
# 'TrackerTIDModuleUnit,101111',
'TrackerTOBModuleUnit,101111',
# 'TrackerTECModuleUnit,101111'
)
)

process.AlignmentProducer.doMisalignmentScenario = False #True
process.AlignmentProducer.applyDbAlignment = True # either globalTag or trackerAlignment
process.AlignmentProducer.checkDbAlignmentValidity = False

# assign by reference (i.e. could change MillePedeAlignmentAlgorithm as well):
process.AlignmentProducer.algoConfig = process.MillePedeAlignmentAlgorithm

process.AlignmentProducer.algoConfig.mode = 'pedeRead'
process.AlignmentProducer.algoConfig.treeFile = 'TREEFILE'
process.AlignmentProducer.algoConfig.pedeReader.readFile = 'FILE_MUST_NOT_EXIST.res'

process.source = cms.Source("EmptySource",
firstRun = cms.untracked.uint32(RUNNUMBER) # choose your run!
)
process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(1) )


process.dump = cms.EDAnalyzer("EventContentAnalyzer")
process.p = cms.Path(process.dump)

process.AlignmentProducer.saveToDB = True # should not be needed, but is: otherwise AlignmentProducer does not call relevant algorithm part
process.PoolDBOutputService = cms.Service("PoolDBOutputService",
CondDBReference,
timetype = cms.untracked.string('runnumber'),
toPut = cms.VPSet(cms.PSet(record = cms.string('TrackerAlignmentRcd'),
tag = cms.string('dummyTagAlignment')
)
)
)
119 changes: 119 additions & 0 deletions Alignment/TrackerAlignment/test/pixelPositions.sh
@@ -0,0 +1,119 @@
#!/bin/zsh
#

# Script to prepare the tables in TkAlignmentPixelPosition.
#
# In the beginning you have to state
# - the paths to the template config for the geometry comparison and
# the plotting macros
# - which run numbers to test
# - which global tags and possibly which tracker alignment tags in which DB paths

#CONFIG_TEMPLATE="src/Alignment/MillePedeAlignmentAlgorithm/test/alignment_forGeomComp_cfg_TEMPLATE.py"
#PLOTMILLEPEDEDIR=
CONFIG_TEMPLATE="$CMSSW_BASE/src/Alignment/TrackerAlignment/test/alignment_forGeomComp_cfg_TEMPLATE.py"
PLOTMILLEPEDEDIR="$CMSSW_BASE/src/Alignment/MillePedeAlignmentAlgorithm/macros/"
echo Using template $CONFIG_TEMPLATE
echo and plotting macros from $PLOTMILLEPEDEDIR
echo

RUN_NUMBERS=(273000)

# First conditions to check
# (if ALIGNMENT_TAG1 and DB_PATH_TAG1 are empty takes content from GLOBALTAG1)
# also symbolic Global Tags are allowed
GLOBALTAG1="auto:run2_data"
#GLOBALTAG1="80X_dataRun2_Prompt_v8"
ALIGNMENT_TAG1="TrackerAlignment_2009_v1_express"
DB_PATH_TAG1="frontier://FrontierProd/CMS_CONDITIONS"

# Second conditions to check
# also symbolic Global Tags are allowed
GLOBALTAG2="auto:run2_data"
#GLOBALTAG2="80X_dataRun2_Prompt_v8"
ALIGNMENT_TAG2="SiPixelAli_PCL_v0_prompt"
DB_PATH_TAG2="frontier://FrontierPrep/CMS_CONDITIONS"

for RUN in $RUN_NUMBERS ; do
echo "============================================================"
echo " Run $RUN: $GLOBALTAG1 / $ALIGNMENT_TAG1 (=1) vs $GLOBALTAG2 / $ALIGNMENT_TAG2 (=2)"
echo "============================================================"
CONFIG1=alignment_forGeomComp_${GLOBALTAG1}_${ALIGNMENT_TAG1}_r$RUN.py
TREEFILE1=treeFile_${GLOBALTAG1}_${ALIGNMENT_TAG1}_r${RUN}.root
TREEFILE1=`echo ${TREEFILE1//"auto:"/"auto_"}`
LOGFILE1=alignment_${GLOBALTAG1}_${ALIGNMENT_TAG1}r${RUN}
LOGFILE1=`echo ${LOGFILE1//"auto:"/"auto_"}`
#echo $TREEFILE1 $LOGFILE1

CONFIG2=alignment_forGeomComp_${GLOBALTAG2}_${ALIGNMENT_TAG2}_r$RUN.py
TREEFILE2=treeFile_${GLOBALTAG2}_${ALIGNMENT_TAG2}_r${RUN}.root
TREEFILE2=`echo ${TREEFILE2//"auto:"/"auto_"}`
LOGFILE2=alignment_${GLOBALTAG2}_${ALIGNMENT_TAG2}r${RUN}
LOGFILE2=`echo ${LOGFILE2//"auto:"/"auto_"}`
#echo $TREEFILE2 $LOGFILE2

if [ -e $TREEFILE1 ] ; then
echo "Removing old file" $TREEFILE1
rm $TREEFILE1
fi
sed -e "s/RUNNUMBER/${RUN}/g" $CONFIG_TEMPLATE > ${CONFIG1}_tmp
sed -e "s/TREEFILE/${TREEFILE1}/g" ${CONFIG1}_tmp > ${CONFIG1}_tmp2
sed -e "s/GLOBALTAG/${GLOBALTAG1}/g" ${CONFIG1}_tmp2 > ${CONFIG1}_tmp3
sed -e "s/LOGFILE/${LOGFILE1}/g" ${CONFIG1}_tmp3 > ${CONFIG1}

# maybe we need to overwrite GlobalTag alignment?
if [ $#ALIGNMENT_TAG1 != 0 ]; then
cat >>! ${CONFIG1} <<EOF
from CondCore.CondDB.CondDB_cfi import *
CondDBReference = CondDB.clone(connect = cms.string("$DB_PATH_TAG1"))
process.trackerAlignment = cms.ESSource("PoolDBESSource",
CondDBReference,
toGet = cms.VPSet(cms.PSet(record = cms.string("TrackerAlignmentRcd"),
tag = cms.string("$ALIGNMENT_TAG1")
)
)
)
process.es_prefer_trackerAlignment = cms.ESPrefer("PoolDBESSource", "trackerAlignment")
EOF
fi

rm ${CONFIG1}_tmp*
cmsRun $CONFIG1
rm remove_me.db

if [ -e $TREEFILE2 ] ; then
echo "Removing old file " $TREEFILE2
rm $TREEFILE2
fi
sed -e "s/RUNNUMBER/${RUN}/g" $CONFIG_TEMPLATE > ${CONFIG2}_tmp
sed -e "s/TREEFILE/${TREEFILE2}/g" ${CONFIG2}_tmp > ${CONFIG2}_tmp2
sed -e "s/GLOBALTAG/${GLOBALTAG2}/g" ${CONFIG2}_tmp2 > ${CONFIG2}_tmp3
sed -e "s/LOGFILE/${LOGFILE2}/g" ${CONFIG2}_tmp3 > ${CONFIG2}

# maybe we need to overwrite GlobalTag alignment?
if [ $#ALIGNMENT_TAG2 != 0 ]; then
cat >>! ${CONFIG2} <<EOF
from CondCore.CondDB.CondDB_cfi import *
CondDBReference = CondDB.clone(connect = cms.string("$DB_PATH_TAG2"))
process.trackerAlignment = cms.ESSource("PoolDBESSource",
CondDBReference,
toGet = cms.VPSet(cms.PSet(record = cms.string("TrackerAlignmentRcd"),
tag = cms.string("$ALIGNMENT_TAG2")
)
)
)
process.es_prefer_trackerAlignment = cms.ESPrefer("PoolDBESSource", "trackerAlignment")
EOF
fi

rm ${CONFIG2}_tmp*
cmsRun $CONFIG2
rm remove_me.db

HEREIAM=$(pwd)
cd $PLOTMILLEPEDEDIR
root -b -q -l allMillePede.C "pixelPositionChange.C+(\"${HEREIAM}/$TREEFILE1\", \"${HEREIAM}/$TREEFILE2\")"
cd $HEREIAM
done

0 comments on commit 10344c1

Please sign in to comment.