From 7d95147e72a041afdd60709f063542a530f00ff1 Mon Sep 17 00:00:00 2001 From: Christian Schomakers Date: Wed, 3 Jun 2015 12:32:15 +0200 Subject: [PATCH 1/2] Changes from 75X backported --- .../python/TkAlAllInOneTool/alignment.py | 5 +- .../TkAlAllInOneTool/configTemplates.py | 2 +- .../TkAlAllInOneTool/geometryComparison.py | 52 +++++++++----- .../geometryComparisonTemplates.py | 28 +++----- .../scripts/comparisonScript.C | 69 +++++++++++++++---- .../scripts/makeArrowPlots.C | 17 ++--- 6 files changed, 108 insertions(+), 65 deletions(-) diff --git a/Alignment/OfflineValidation/python/TkAlAllInOneTool/alignment.py b/Alignment/OfflineValidation/python/TkAlAllInOneTool/alignment.py index 309990df329f7..c9c61ddc8aeec 100644 --- a/Alignment/OfflineValidation/python/TkAlAllInOneTool/alignment.py +++ b/Alignment/OfflineValidation/python/TkAlAllInOneTool/alignment.py @@ -8,8 +8,9 @@ def __init__(self, name, config, runGeomComp = "1"): self.condShorts = { "TrackerAlignmentErrorExtendedRcd": {"zeroAPE":{"connectString": ("frontier://FrontierProd" - "/CMS_COND_31X_FROM21X"), - "tagName": "TrackerIdealGeometryErrors210_mc", + "/CMS_CONDITIONS"), + "tagName": "TrackerAlignmentExtendedErr_2009_v2_express_IOVs", + "labelName": ""}}} section = "alignment:%s"%name if not config.has_section( section ): diff --git a/Alignment/OfflineValidation/python/TkAlAllInOneTool/configTemplates.py b/Alignment/OfflineValidation/python/TkAlAllInOneTool/configTemplates.py index 60c22ae718d94..f7017ebcd9874 100644 --- a/Alignment/OfflineValidation/python/TkAlAllInOneTool/configTemplates.py +++ b/Alignment/OfflineValidation/python/TkAlAllInOneTool/configTemplates.py @@ -44,7 +44,7 @@ cd .oO[CMSSW_BASE]Oo./src export SCRAM_ARCH=.oO[SCRAM_ARCH]Oo. eval `scramv1 ru -sh` -rfmkdir -p .oO[datadir]Oo. &>! /dev/null +#rfmkdir -p .oO[datadir]Oo. &>! /dev/null #remove possible result file from previous runs previous_results=$(cmsLs -l /store/caf/user/$USER/.oO[eosdir]Oo. | awk '{print $5}') diff --git a/Alignment/OfflineValidation/python/TkAlAllInOneTool/geometryComparison.py b/Alignment/OfflineValidation/python/TkAlAllInOneTool/geometryComparison.py index c2ec796e287a2..f150d2a669f99 100644 --- a/Alignment/OfflineValidation/python/TkAlAllInOneTool/geometryComparison.py +++ b/Alignment/OfflineValidation/python/TkAlAllInOneTool/geometryComparison.py @@ -97,7 +97,7 @@ def createConfiguration(self, path ): cfgs[cfgName] = configTemplates.compareTemplate repMaps[cfgName] = repMap - cfgSchedule.append( cfgName ) + cfgSchedule.append( cfgName ) GenericValidation.createConfiguration(self, cfgs, path, cfgSchedule, repMaps = repMaps) def createScript(self, path): @@ -107,6 +107,8 @@ def createScript(self, path): %self.name), repMap) for name in self.__compares: if '"DetUnit"' in self.__compares[name][0].split(","): + repMap["outputFile"] = (".oO[name]Oo..Comparison_common"+name+".root") + repMap["nIndex"] = ("") repMap["runComparisonScripts"] += \ ("rfcp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation" "/scripts/comparisonScript.C .\n" @@ -122,33 +124,45 @@ def createScript(self, path): ("rfmkdir -p .oO[datadir]Oo./.oO[name]Oo." ".Comparison_common"+name+"_Images\n") repMap["runComparisonScripts"] += \ - ("find . -maxdepth 1 -name \"*PXB*\" " - "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo." - "/.oO[name]Oo..Comparison_common"+name+"_Images/\" \n") + ("rfmkdir -p .oO[datadir]Oo./.oO[name]Oo." + ".Comparison_common"+name+"_Images/Translations\n") + repMap["runComparisonScripts"] += \ + ("rfmkdir -p .oO[datadir]Oo./.oO[name]Oo." + ".Comparison_common"+name+"_Images/Rotations\n") + repMap["runComparisonScripts"] += \ + ("rfmkdir -p .oO[datadir]Oo./.oO[name]Oo." + ".Comparison_common"+name+"_Images/CrossTalk\n") + + ### At the moment translations are images with suffix _1 and _2, rotations _3 and _4, and cross talk _5 and _6 + ### The numeration depends on the order of the MakePlots(x, y) commands in comparisonScript.C + ### If comparisonScript.C is changed, check if the following lines need to be changed as well repMap["runComparisonScripts"] += \ - ("find . -maxdepth 1 -name \"*PXF*\" " + ("find . -maxdepth 1 -name \"*_1*\" " "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo." - "/.oO[name]Oo..Comparison_common"+name+"_Images/\" \n") + "/.oO[name]Oo..Comparison_common"+name+"_Images/Translations/\" \n") repMap["runComparisonScripts"] += \ - ("find . -maxdepth 1 -name \"*TIB*\" " + ("find . -maxdepth 1 -name \"*_2*\" " "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo." - "/.oO[name]Oo..Comparison_common"+name+"_Images/\" \n") + "/.oO[name]Oo..Comparison_common"+name+"_Images/Translations/\" \n") + repMap["runComparisonScripts"] += \ - ("find . -maxdepth 1 -name \"*TID*\" " + ("find . -maxdepth 1 -name \"*_3*\" " "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo." - "/.oO[name]Oo..Comparison_common"+name+"_Images/\" \n") + "/.oO[name]Oo..Comparison_common"+name+"_Images/Rotations/\" \n") repMap["runComparisonScripts"] += \ - ("find . -maxdepth 1 -name \"*TEC*\" " + ("find . -maxdepth 1 -name \"*_4*\" " "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo." - "/.oO[name]Oo..Comparison_common"+name+"_Images/\" \n") + "/.oO[name]Oo..Comparison_common"+name+"_Images/Rotations/\" \n") + repMap["runComparisonScripts"] += \ - ("find . -maxdepth 1 -name \"*TOB*\" " + ("find . -maxdepth 1 -name \"*_5*\" " "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo." - "/.oO[name]Oo..Comparison_common"+name+"_Images/\" \n") + "/.oO[name]Oo..Comparison_common"+name+"_Images/CrossTalk/\" \n") repMap["runComparisonScripts"] += \ - ("find . -maxdepth 1 -name \"*tracker*\" " + ("find . -maxdepth 1 -name \"*_6*\" " "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo." - "/.oO[name]Oo..Comparison_common"+name+"_Images/\" \n") + "/.oO[name]Oo..Comparison_common"+name+"_Images/CrossTalk/\" \n") + repMap["runComparisonScripts"] += \ ("find . -maxdepth 1 -name " "\"TkMap_SurfDeform*.pdf\" -print | xargs -I {} bash -c" @@ -171,7 +185,7 @@ def createScript(self, path): repMap["runComparisonScripts"] += \ ("rfcp .oO[CMSSW_BASE]Oo./src/Alignment" "/OfflineValidation/scripts/makeArrowPlots.C " - "$CWD/TkAllInOneTool\n" + ".\n" "root -b -q 'makeArrowPlots.C(\"" ".oO[name]Oo..Comparison_common"+name +".root\",\".oO[name]Oo.." @@ -199,7 +213,8 @@ def createScript(self, path): for cfg in self.configFiles: # FIXME: produce this line only for enabled dbOutput # postProcess = "rfcp .oO[workdir]Oo./*.db .oO[datadir]Oo.\n" - postProcess = "rfcp *.db .oO[datadir]Oo.\n" + # postProcess = "rfcp *.db .oO[datadir]Oo.\n" + postProcess = "" repMap["CommandLine"]+= \ repMap["CommandLineTemplate"]%{"cfgFile":cfg, "postProcess":postProcess} @@ -207,6 +222,7 @@ def createScript(self, path): ".oO[runComparisonScripts]Oo.\n" ) + #~ print configTemplates.scriptTemplate scripts = {scriptName: replaceByMap( configTemplates.scriptTemplate, repMap ) } return GenericValidation.createScript(self, scripts, path) diff --git a/Alignment/OfflineValidation/python/TkAlAllInOneTool/geometryComparisonTemplates.py b/Alignment/OfflineValidation/python/TkAlAllInOneTool/geometryComparisonTemplates.py index 9c9bac7867075..84f15579e7b29 100644 --- a/Alignment/OfflineValidation/python/TkAlAllInOneTool/geometryComparisonTemplates.py +++ b/Alignment/OfflineValidation/python/TkAlAllInOneTool/geometryComparisonTemplates.py @@ -9,11 +9,11 @@ process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") process.GlobalTag.globaltag = ".oO[GlobalTag]Oo." -process.load("Configuration.Geometry.GeometryDB_cff") -#process.load("Geometry.TrackerNumberingBuilder.trackerNumberingGeometry_cfi") -#process.load("Geometry.TrackerGeometryBuilder.trackerGeometry_cfi") +process.load('Configuration.Geometry.GeometryExtended2015_cff') +process.TrackerTopologyEP = cms.ESProducer("TrackerTopologyEP") + +process.load("Geometry.TrackerGeometryBuilder.trackerGeometry_cfi") -#process.load("Alignment.CommonAlignmentProducer.GlobalPosition_Frontier_cff") process.load("CondCore.DBCommon.CondDBSetup_cfi") process.MessageLogger = cms.Service("MessageLogger", @@ -31,7 +31,6 @@ input = cms.untracked.int32(1) ) process.dump = cms.EDAnalyzer("TrackerGeometryIntoNtuples", - # outputFile = cms.untracked.string('.oO[workdir]Oo./.oO[alignmentName]Oo.ROOTGeometry.root'), outputFile = cms.untracked.string('.oO[alignmentName]Oo.ROOTGeometry.root'), outputTreename = cms.untracked.string('alignTree') ) @@ -50,15 +49,11 @@ # global tag process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") process.GlobalTag.globaltag = ".oO[GlobalTag]Oo." -process.load("Configuration.Geometry.GeometryDB_cff") - -#process.load("Geometry.TrackerNumberingBuilder.trackerNumberingGeometry_cfi") -#process.load("Geometry.TrackerGeometryBuilder.trackerGeometry_cfi") +process.load('Configuration.Geometry.GeometryExtended2015_cff') +process.TrackerTopologyEP = cms.ESProducer("TrackerTopologyEP") -#process.load("Alignment.CommonAlignmentProducer.GlobalPosition_Frontier_cff") -# the input .GlobalPosition_Frontier_cff is providing the frontier://FrontierProd/CMS_COND_31X_ALIGNMENT in the release which does not provide the ideal geometry -#process.GlobalPosition.connect = 'frontier://FrontierProd/CMS_COND_31X_FROM21X' +process.load("Geometry.TrackerGeometryBuilder.trackerGeometry_cfi") process.load("CondCore.DBCommon.CondDBSetup_cfi") @@ -76,11 +71,8 @@ process.load("DQM.SiStripCommon.TkHistoMap_cfi") process.DQMStore=cms.Service("DQMStore") -#process.TkDetMap = cms.Service("TkDetMap") -#process.SiStripDetInfoFileReader = cms.Service("SiStripDetInfoFileReader") process.load("DQMServices.Core.DQMStore_cfg") -#process.DQMStore=cms.Service("DQMStore") # configuration of the Tracker Geometry Comparison Tool # Tracker Geometry Comparison @@ -89,13 +81,9 @@ process.TrackerGeometryCompare.inputROOTFile1 = '.oO[comparedGeometry]Oo.' process.TrackerGeometryCompare.inputROOTFile2 = '.oO[referenceGeometry]Oo.' -# process.TrackerGeometryCompare.outputFile = ".oO[workdir]Oo./.oO[name]Oo..Comparison_common.oO[common]Oo..root" process.TrackerGeometryCompare.outputFile = ".oO[name]Oo..Comparison_common.oO[common]Oo..root" process.load("CommonTools.UtilAlgos.TFileService_cfi") -#process.TFileService = cms.Service("TFileService", -# fileName = cms.string('TkSurfDeform.root') -# ) process.TFileService.fileName = cms.string("TkSurfDeform_.oO[name]Oo..Comparison_common.oO[common]Oo..root") process.TrackerGeometryCompare.levels = [ .oO[levels]Oo. ] @@ -113,7 +101,7 @@ dbOutputTemplate= """ //_________________________ db Output ____________________________ # setup for writing out to DB - include "CondCore/DBCommon/data/CondDBSetup.cfi" + include "CondCore/DBCommon/CondDBSetup.cfi" # include "CondCore/DBCommon/data/CondDBCommon.cfi" service = PoolDBOutputService { diff --git a/Alignment/OfflineValidation/scripts/comparisonScript.C b/Alignment/OfflineValidation/scripts/comparisonScript.C index f5c9e3c441ba1..c1a27ccab3813 100644 --- a/Alignment/OfflineValidation/scripts/comparisonScript.C +++ b/Alignment/OfflineValidation/scripts/comparisonScript.C @@ -33,25 +33,68 @@ void comparisonScript (TString inFile,//="mp1510_vs_mp1509.Comparison_commonTrac // from r and dphi // now the object to produce the comparison plots is created - GeometryComparisonPlotter * cp = new GeometryComparisonPlotter (inFile, outDir); + + // Plot Translations + GeometryComparisonPlotter * trans = new GeometryComparisonPlotter (inFile, outDir); // x and y contain the couples to plot // -> every combination possible will be performed // /!\ always give units (otherwise, unexpected bug from root...) vector x,y; - x.push_back("r"); cp->SetBranchUnits("r", "cm"); - x.push_back("phi"); cp->SetBranchUnits("phi", "rad"); - x.push_back("z"); cp->SetBranchUnits("z", "cm"); //cp->SetBranchMax("z", 100); cp->SetBranchMin("z", -100); - y.push_back("dr"); cp->SetBranchSF("dr", 10000); cp->SetBranchUnits("dr", "#mum"); - y.push_back("dz"); cp->SetBranchSF("dz", 10000); cp->SetBranchUnits("dz", "#mum"); - y.push_back("rdphi"); cp->SetBranchSF("rdphi",10000); cp->SetBranchUnits("rdphi", "#mum rad"); - y.push_back("dx"); cp->SetBranchSF("dx", 10000); cp->SetBranchUnits("dx", "#mum"); //cp->SetBranchMax("dx", 10); cp->SetBranchMin("dx", -10); - y.push_back("dy"); cp->SetBranchSF("dy", 10000); cp->SetBranchUnits("dy", "#mum"); //cp->SetBranchMax("dy", 10); cp->SetBranchMin("dy", -10); - cp->MakePlots(x, y); // default output is pdf, but png gives a nicer result, so we use it as well + x.push_back("r"); trans->SetBranchUnits("r", "cm"); + x.push_back("phi"); trans->SetBranchUnits("phi", "rad"); + x.push_back("z"); trans->SetBranchUnits("z", "cm"); //trans->SetBranchMax("z", 100); trans->SetBranchMin("z", -100); + y.push_back("dr"); trans->SetBranchSF("dr", 10000); trans->SetBranchUnits("dr", "#mum"); + y.push_back("dz"); trans->SetBranchSF("dz", 10000); trans->SetBranchUnits("dz", "#mum"); + y.push_back("rdphi"); trans->SetBranchSF("rdphi",10000); trans->SetBranchUnits("rdphi", "#mum rad"); + y.push_back("dx"); trans->SetBranchSF("dx", 10000); trans->SetBranchUnits("dx", "#mum"); //trans->SetBranchMax("dx", 10); trans->SetBranchMin("dx", -10); + y.push_back("dy"); trans->SetBranchSF("dy", 10000); trans->SetBranchUnits("dy", "#mum"); //trans->SetBranchMax("dy", 10); trans->SetBranchMin("dy", -10); + trans->MakePlots(x, y); // default output is pdf, but png gives a nicer result, so we use it as well // remark: what takes the more time is the creation of the output files, // not the looping on the tree (because the code is perfect, of course :p) - cp->SetGrid(1,1); - cp->SetPrintOption("png"); - cp->MakePlots(x, y); + trans->SetGrid(1,1); + trans->SetPrintOption("png"); + trans->MakePlots(x, y); + + + // Plot Rotations + GeometryComparisonPlotter * rot = new GeometryComparisonPlotter (inFile, outDir); + // x and y contain the couples to plot + // -> every combination possible will be performed + // /!\ always give units (otherwise, unexpected bug from root...) + vector a,b; + a.push_back("alpha"); rot->SetBranchUnits("alpha", "rad"); + a.push_back("beta"); rot->SetBranchUnits("beta", "rad"); + a.push_back("gamma"); rot->SetBranchUnits("gamma", "rad"); + b.push_back("dalpha"); rot->SetBranchSF("dalpha", 1000); rot->SetBranchUnits("dalpha", "mrad"); + b.push_back("dbeta"); rot->SetBranchSF("dbeta", 1000); rot->SetBranchUnits("dbeta", "mrad"); + b.push_back("dgamma"); rot->SetBranchSF("dgamma", 1000); rot->SetBranchUnits("dgamma", "mrad"); + rot->MakePlots(a, b); // default output is pdf, but png gives a nicer result, so we use it as well + // remark: what takes the more time is the creation of the output files, + // not the looping on the tree (because the code is perfect, of course :p) + rot->SetGrid(1,1); + rot->SetPrintOption("png"); + rot->MakePlots(a, b); + + // Plot cross talk + GeometryComparisonPlotter * cross = new GeometryComparisonPlotter (inFile, outDir); + // x and y contain the couples to plot + // -> every combination possible will be performed + // /!\ always give units (otherwise, unexpected bug from root...) + vector dx,dy; + dx.push_back("dalpha"); cross->SetBranchSF("dalpha", 1000); cross->SetBranchUnits("dalpha", "mrad"); + dx.push_back("dbeta"); cross->SetBranchSF("dbeta", 1000); cross->SetBranchUnits("dbeta", "mrad"); + dx.push_back("dgamma"); cross->SetBranchSF("dgamma", 1000); cross->SetBranchUnits("dgamma", "mrad"); + dy.push_back("dr"); cross->SetBranchSF("dr", 10000); cross->SetBranchUnits("dr", "#mum"); + dy.push_back("dz"); cross->SetBranchSF("dz", 10000); cross->SetBranchUnits("dz", "#mum"); + dy.push_back("rdphi"); cross->SetBranchSF("rdphi",10000); cross->SetBranchUnits("rdphi", "#mum rad"); + dy.push_back("dx"); cross->SetBranchSF("dx", 10000); cross->SetBranchUnits("dx", "#mum"); + dy.push_back("dy"); cross->SetBranchSF("dy", 10000); cross->SetBranchUnits("dy", "#mum"); + cross->MakePlots(dx,dy); // default output is pdf, but png gives a nicer result, so we use it as well + // remark: what takes the more time is the creation of the output files, + // not the looping on the tree (because the code is perfect, of course :p) + cross->SetGrid(1,1); + cross->SetPrintOption("png"); + cross->MakePlots(dx, dy); // now the same object can be reused with other specifications/cuts //void SetPrint (const bool); // activates the printing of the individual and global pdf diff --git a/Alignment/OfflineValidation/scripts/makeArrowPlots.C b/Alignment/OfflineValidation/scripts/makeArrowPlots.C index af26db4cf5126..cf678daa5fdca 100644 --- a/Alignment/OfflineValidation/scripts/makeArrowPlots.C +++ b/Alignment/OfflineValidation/scripts/makeArrowPlots.C @@ -12,7 +12,7 @@ float y_,x_,z_,phi_,r_,dphi_,dr_,dx_,dz_,dy_; int level_,sublevel_; char outputDir_[192]; -void Plot10Mu(char* text,float X, float Y, float size) +void Plot10Mu(const char* text,float X, float Y, float size) { TPaveText* atext = new TPaveText(X,Y,X+size,Y+size); atext->AddText(text); @@ -48,13 +48,8 @@ void DrawRPhiLegend(double xLim, double yLim, double barrelRPhiRescale) normArrow(xTest+dYTest,yTest-4*dYTest-disty,500./10000*barrelRPhiRescale); } -void Write() -{ - output->Write(); -} - -int makeRPhiArrowPlot( TTree* data, char* name, double xLim, double yLim, double level, double sublevel, double zMin, double zMax, double rMin, double rMax, double barrelRPhiRescale){ +int makeRPhiArrowPlot( TTree* data, const char* name, double xLim, double yLim, double level, double sublevel, double zMin, double zMax, double rMin, double rMax, double barrelRPhiRescale){ TCanvas* OBPCanvas = new TCanvas(name,name,1050,875); @@ -80,7 +75,7 @@ int makeRPhiArrowPlot( TTree* data, char* name, double xLim, double yLim, double DrawRPhiLegend( xLim, yLim, barrelRPhiRescale ); char sliceLeg[192]; - sprintf( sliceLeg, "%s: %d < z <= %d", name, zMin, zMax ); + sprintf( sliceLeg, "%s: %f < z <= %f", name, zMin, zMax ); //Plot10Mu( name, xLim/2, yLim, 0.2*xLim ); TPaveText* atext = new TPaveText(0.2*xLim,0.85*yLim,0.66*xLim,0.99*yLim); atext->AddText(sliceLeg); @@ -99,7 +94,7 @@ int makeRPhiArrowPlot( TTree* data, char* name, double xLim, double yLim, double return passcut; } -int makeZPhiArrowPlot( TTree* data, char* name, double zLim, double phiLim, double level, double sublevel, double zMin, double zMax, double rMin, double rMax, double barrelRPhiRescale){ +int makeZPhiArrowPlot( TTree* data, const char* name, double zLim, double phiLim, double level, double sublevel, double zMin, double zMax, double rMin, double rMax, double barrelRPhiRescale){ TCanvas* OBPCanvas = new TCanvas(name,name,1050,875); @@ -125,7 +120,7 @@ int makeZPhiArrowPlot( TTree* data, char* name, double zLim, double phiLim, doub DrawRPhiLegend( zLim, phiLim, barrelRPhiRescale ); char sliceLeg[192]; - sprintf( sliceLeg, "%s: %d < r <= %d", name, rMin, rMax ); + sprintf( sliceLeg, "%s: %f < r <= %f", name, rMin, rMax ); //Plot10Mu( name, xLim/2, yLim, 0.2*xLim ); TPaveText* atext = new TPaveText(0.2*zLim,0.85*phiLim,0.66*zLim,0.99*phiLim); atext->AddText(sliceLeg); @@ -198,7 +193,7 @@ int makeRZArrowPlot( TTree* data, char* name, double zLim, double zLimMax, doubl } */ -void makeArrowPlots(char* filename, char* outputDir) +void makeArrowPlots(const char* filename, const char* outputDir) { fin = new TFile(filename); From 76a675c74ff70a9998cbfec9933bd8f75f150ea6 Mon Sep 17 00:00:00 2001 From: Jered McInerney Date: Thu, 4 Jun 2015 17:45:16 +0200 Subject: [PATCH 2/2] integrated 3D geometry comparison visualization into all-in-one tool --- .../TkAlAllInOneTool/betterConfigParser.py | 2 +- .../TkAlAllInOneTool/geometryComparison.py | 31 +- .../geometryComparisonTemplates.py | 52 ++ .../scripts/visualizationTracker.C | 614 +++++++++++++----- 4 files changed, 545 insertions(+), 154 deletions(-) diff --git a/Alignment/OfflineValidation/python/TkAlAllInOneTool/betterConfigParser.py b/Alignment/OfflineValidation/python/TkAlAllInOneTool/betterConfigParser.py index 86e2eaad2cd76..8b6608382e22d 100644 --- a/Alignment/OfflineValidation/python/TkAlAllInOneTool/betterConfigParser.py +++ b/Alignment/OfflineValidation/python/TkAlAllInOneTool/betterConfigParser.py @@ -122,7 +122,7 @@ def getCompares( self ): if "compare:" in section: self.checkInput(section, knownSimpleOptions = ["levels", "dbOutput", - "jobmode"]) + "jobmode", "3DSubdetector1", "3Dubdetector2", "3DTranslationalScaleFactor"]) levels = self.get( section, "levels" ) dbOutput = self.get( section, "dbOutput" ) compares[section.split(":")[1]] = ( levels, dbOutput ) diff --git a/Alignment/OfflineValidation/python/TkAlAllInOneTool/geometryComparison.py b/Alignment/OfflineValidation/python/TkAlAllInOneTool/geometryComparison.py index f150d2a669f99..06b0ef65d0906 100644 --- a/Alignment/OfflineValidation/python/TkAlAllInOneTool/geometryComparison.py +++ b/Alignment/OfflineValidation/python/TkAlAllInOneTool/geometryComparison.py @@ -28,8 +28,15 @@ def __init__( self, valName, alignment, referenceAlignment, generated to create unique path names for the individual validation instances. """ + defaults = { + "3DSubdetector1":"1", + "3DSubdetector2":"2", + "3DTranslationalScaleFactor":"50" + } mandatories = ["levels", "dbOutput"] - GenericValidation.__init__(self, valName, alignment, config, "compare", addMandatories = mandatories) + GenericValidation.__init__(self, valName, alignment, config, + "compare", addDefaults=defaults, + addMandatories = mandatories) if not randomWorkdirPart == None: self.randomWorkdirPart = randomWorkdirPart self.referenceAlignment = referenceAlignment @@ -60,7 +67,9 @@ def getRepMap(self, alignment = None): "ROOTGeometry.root"), "referenceGeometry": "IDEAL", # will be replaced later # if not compared to IDEAL - "reference": referenceName + "reference": referenceName, + "referenceTitle": self.referenceAlignment.title, + "alignmentTitle": self.alignmentToValidate.title }) if not referenceName == "IDEAL": repMap["referenceGeometry"] = (".oO[reference]Oo." @@ -118,7 +127,9 @@ def createScript(self, path): "/scripts/GeometryComparisonPlotter.cc .\n" "root -b -q 'comparisonScript.C+(\"" ".oO[name]Oo..Comparison_common"+name+".root\",\"" - "./\")'\n") + "./\")'\n" + "rfcp "+path+"/TkAl3DVisualization_.oO[name]Oo..C .\n" + "root -l -b -q TkAl3DVisualization_.oO[name]Oo..C+\n") if self.copyImages: repMap["runComparisonScripts"] += \ ("rfmkdir -p .oO[datadir]Oo./.oO[name]Oo." @@ -132,8 +143,9 @@ def createScript(self, path): repMap["runComparisonScripts"] += \ ("rfmkdir -p .oO[datadir]Oo./.oO[name]Oo." ".Comparison_common"+name+"_Images/CrossTalk\n") - - ### At the moment translations are images with suffix _1 and _2, rotations _3 and _4, and cross talk _5 and _6 + + + ### At the moment translations are immages with suffix _1 and _2, rotations _3 and _4, and cross talk _5 and _6 ### The numeration depends on the order of the MakePlots(x, y) commands in comparisonScript.C ### If comparisonScript.C is changed, check if the following lines need to be changed as well repMap["runComparisonScripts"] += \ @@ -198,6 +210,11 @@ def createScript(self, path): "-maxdepth 1 -name \"*.png\" -print | xargs -I {} bash " "-c \"rfcp {} .oO[datadir]Oo./.oO[name]Oo." ".Comparison_common"+name+"_Images/ArrowPlots\"\n") + repMap["runComparisonScripts"] += \ + ("find . " + "-maxdepth 1 -name \".oO[name]Oo..Visualization_rotated.gif\" -print | xargs -I {} bash " + "-c \"rfcp {} .oO[datadir]Oo./.oO[name]Oo." + ".Comparison_common"+name+"_Images/.oO[name]Oo..Visualization.gif\"\n") resultingFile = replaceByMap(("/store/caf/user/$USER/.oO[eosdir]Oo./compared%s_" ".oO[name]Oo..root"%name), repMap) @@ -223,7 +240,9 @@ def createScript(self, path): ) #~ print configTemplates.scriptTemplate - scripts = {scriptName: replaceByMap( configTemplates.scriptTemplate, repMap ) } + scripts = {scriptName: replaceByMap( configTemplates.scriptTemplate, repMap )} + files = {replaceByMap("TkAl3DVisualization_.oO[name]Oo..C", repMap ): replaceByMap(configTemplates.visualizationTrackerTemplate, repMap )} + self.createFiles(files, path) return GenericValidation.createScript(self, scripts, path) def createCrabCfg(self, path): diff --git a/Alignment/OfflineValidation/python/TkAlAllInOneTool/geometryComparisonTemplates.py b/Alignment/OfflineValidation/python/TkAlAllInOneTool/geometryComparisonTemplates.py index 84f15579e7b29..68f53a9532d7a 100644 --- a/Alignment/OfflineValidation/python/TkAlAllInOneTool/geometryComparisonTemplates.py +++ b/Alignment/OfflineValidation/python/TkAlAllInOneTool/geometryComparisonTemplates.py @@ -117,3 +117,55 @@ } """ +###################################################################### +###################################################################### +visualizationTrackerTemplate= """ +#include ".oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation/scripts/visualizationTracker.C" +void TkAl3DVisualization_.oO[name]Oo.(){ + //------------------------------ONLY NEEDED INPUTS-------------------------------// +//------Tree Read In-------- + TString inputFileName = ".oO[outputFile]Oo."; + //output file name + string outputFileName = ".oO[name]Oo..Visualization"; + //title + string line1 = ".oO[alignmentTitle]Oo."; + string line2 = "vs. .oO[referenceTitle]Oo."; + //set subdetectors to see + int subdetector1 = .oO[3DSubdetector1]Oo.; + int subdetector2 = .oO[3DSubdetector2]Oo.; + //translation scale factor + int sclftr = .oO[3DTranslationalScaleFactor]Oo.; + //rotation scale factor + int sclfrt = 1; + //module size scale factor + float sclfmodulesizex = 1; + float sclfmodulesizey = 1; + float sclfmodulesizez = 1; + //beam pipe radius + float piperadius = 2.25; + //beam pipe xy coordinates + float pipexcoord = 0; + float pipeycoord = 0; + //beam line xy coordinates + float linexcoord = 0; + float lineycoord = 0; +//------------------------------End of ONLY NEEDED INPUTS-------------------------------// + cout << "running visualizer" << endl; + runVisualizer(inputFileName, + outputFileName, + line1, + line2, + subdetector1, + subdetector2, + sclftr, + sclfrt, + sclfmodulesizex, + sclfmodulesizey, + sclfmodulesizez, + piperadius, + pipexcoord, + pipeycoord, + linexcoord, + lineycoord ); +} +""" diff --git a/Alignment/OfflineValidation/scripts/visualizationTracker.C b/Alignment/OfflineValidation/scripts/visualizationTracker.C index 602e2ae0fc6bb..33aa5c5a52b71 100644 --- a/Alignment/OfflineValidation/scripts/visualizationTracker.C +++ b/Alignment/OfflineValidation/scripts/visualizationTracker.C @@ -1,3 +1,5 @@ +#include "TText.h" +#include "TPaveText.h" #include "TGeoManager.h" #include "TGeoMaterial.h" #include "TH1F.h" @@ -7,10 +9,17 @@ #include "TStyle.h" #include "TLine.h" #include "TCanvas.h" +#include "TFile.h" +#include "TTree.h" +#include "TMath.h" +#include "TSystem.h" +#include "TError.h" #include #include #include - +#include +#include +#include using namespace std; //using namespace ROOT::Math; @@ -22,159 +31,470 @@ float _dxVal, _dyVal, _dzVal, _drVal, _dphiVal, _dalphaVal, _dbetaVal, _dgammaVa float _surWidth, _surLength; int _identifiers[6]; double _surRot[9]; +int _i; // global variables -std::vector< int > _moduleList; TTree* _inTree; -std::string _moduleListName; -float _sclf; - -bool readModuleList(){ - - - std::ifstream inFile; - //inFile.open( "PXBdetids.txt" ); - inFile.open( _moduleListName.c_str() ); - int ctr = 0; - while ( !inFile.eof() ){ - ctr++; - int listId; - inFile >> listId; - inFile.ignore(256, '\n'); - - _moduleList.push_back( listId ); - //if (listId == aliId) foundId = true; - } - - +int _sclftr; +int _sclfrt; +float _sclfmodulesizex; +float _sclfmodulesizey; +float _sclfmodulesizez; +int _subdetector1; +int _subdetector2; +string _outputFileName; +string _line1, _line2, _line3; +float _piperadius; +float _pipexcoord, _pipeycoord; +float _linexcoord, _lineycoord; + +TTree *t; +float zval; +vector vz; + +bool iszilessthanzj(int i, int j) +{ + return vz[i] < vz[j]; +} + +void sortbyz(TString infile) +{ + TFile *f = TFile::Open(infile); + if(f == 0) { + cout << "***Exception Thrown: null input file***" << endl; + assert(0); + } + t = (TTree*)f->Get("alignTree"); + if(t == 0){ + cout << "***Exception Thrown: tree is null***" << endl; + assert(0); + } + if(t->GetEntries() == 0) { + cout << "***Exception Thrown: tree has no entries***" << endl; + assert(0); + } + + t->SetBranchAddress("z", &zval); + + TString outfile = infile.ReplaceAll(".root","_sorted.root"); + TFile *newf = TFile::Open(outfile, "RECREATE"); + TTree *newt = t->CloneTree(0); + + vector v; + vz.clear(); + int length = t->GetEntries(); + for (int i = 0; i < length; i++) + { + v.push_back(i); + + t->GetEntry(i); + vz.push_back(zval); + } + + sort(v.begin(), v.end(), iszilessthanzj); + + for (int i = 0; i < length; i++) + { + t->GetEntry(v[i]); + newt->Fill(); + } + newt->Write(); + delete newf; } +void getBeamVisuals(TGeoManager* geom, TGeoVolume* top, float minZ, float maxZ) { + TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0,0,0); + TGeoMedium *Vacuum = new TGeoMedium("Vacuum",1, matVacuum); + TGeoVolume *xyaxis = geom->MakeBox( "xyaxis", Vacuum, 90., 90., 40. ); + + TGeoMaterial *matAl = new TGeoMaterial("Al", 26.98,13,2.7); + TGeoMedium *Al = new TGeoMedium("Root Material",1, matAl); + //TGeoVolume *line = geom->MakeTube( "BeamLine", Al, 0, .3, (maxZ - minZ) / 2 + 5); + TGeoVolume *xaxis = geom->MakeTube( "XAxis", Al, 0, .1, 30.); + TGeoVolume *yaxis = geom->MakeTube( "YAxis", Al, 0, .1, 30.); + //TGeoVolume *pipe = geom->MakeTube( "BeamPipe", Al, _piperadius-.05, _piperadius+.05, (maxZ - minZ) / 2 + 5); + //line->SetLineColor(kRed); + xaxis->SetLineColor(kBlue); + yaxis->SetLineColor(kBlue); + //pipe->SetLineColor(kBlack); + + xyaxis->AddNode(xaxis, 1, new TGeoRotation( "rtyz", 0, 90, 0)); + xyaxis->AddNode(yaxis, 1, new TGeoRotation( "rtxz", 90, 90, 0)); + + TGeoCombiTrans * pipecenter = new TGeoCombiTrans( *new TGeoTranslation(_pipexcoord, _pipeycoord, 0), *new TGeoRotation()); + //TGeoCombiTrans * linecenter = new TGeoCombiTrans( *new TGeoTranslation(_linexcoord, _lineycoord, 0), *new TGeoRotation()); + //top->AddNode( pipe, 1, pipecenter); + //top->AddNode( line, 1, linecenter); + top->AddNode( xyaxis, 1, pipecenter); +} void getModule(TGeoManager* geom, TGeoVolume* top, TGeoVolume* mod){ - //--- define some materials - TGeoMaterial *matAl = new TGeoMaterial("Al", 26.98,13,2.7); - //--- define some media - TGeoMedium *Al = new TGeoMedium("Root Material",1, matAl); - - TGeoVolume *refMod = geom->MakeBox( "refMod", Al, 0.5*_surWidth, 0.5*_surLength, 0.30 ); - refMod->SetLineColor( 38 ); - refMod->SetFillColor( 13 ); - TGeoVolume *curMod = geom->MakeBox( "curMod", Al, 0.5*_surWidth, 0.5*_surLength, 0.30 ); - if ((_xVal < 0)&&(_zVal>=0)) curMod->SetLineColor( kRed ); - if ((_xVal < 0)&&(_zVal<0)) curMod->SetLineColor( kGreen ); - if ((_xVal >= 0)&&(_zVal>=0)) curMod->SetLineColor( kBlue ); - if ((_xVal >= 0)&&(_zVal<0)) curMod->SetLineColor( kMagenta ); - - const Double_t radc = 180./TMath::Pi(); - TGeoTranslation *tr1 = new TGeoTranslation( 0., 0., 0. ); - TGeoRotation *rt1 = new TGeoRotation(); - double rota[9]; - rota[0] = _surRot[0]; rota[1] = _surRot[3]; rota[2] = _surRot[6]; - rota[3] = _surRot[1]; rota[4] = _surRot[4]; rota[5] = _surRot[7]; - rota[6] = _surRot[2]; rota[7] = _surRot[5]; rota[8] = _surRot[8]; - rt1->SetMatrix( rota ); - - TGeoTranslation *tr2 = new TGeoTranslation( _sclf*_dxVal, _sclf*_dyVal, _sclf*_dzVal ); - TGeoRotation *rt2 = new TGeoRotation( "rt2", _sclf*_dalphaVal*radc, _sclf*_dbetaVal*radc, _sclf*_dgammaVal*radc ); - rt2->MultiplyBy( rt1 ); - TGeoCombiTrans *combi1 = new TGeoCombiTrans( *tr1, *rt1 ); - TGeoCombiTrans *combi2 = new TGeoCombiTrans( *tr2, *rt2 ); - - mod->AddNode( curMod, 1, combi2 ); - - - TGeoTranslation *trG = new TGeoTranslation( _xVal, _yVal, _zVal ); - TGeoRotation *rtG = new TGeoRotation( "rtG", 0., 0., 0. ); - TGeoCombiTrans *combi = new TGeoCombiTrans( *trG, *rtG ); - top->AddNode( mod, 1, combi ); +//--- define some materials + TGeoMaterial *matAl = new TGeoMaterial("Al", 26.98,13,2.7); +//--- define some media + TGeoMedium *Al = new TGeoMedium("Root Material",1, matAl); + TGeoVolume *refMod = geom->MakeBox( "refMod", Al, 0.5*_surWidth*_sclfmodulesizex, 0.5*_surLength*_sclfmodulesizey, 0.30*_sclfmodulesizez ); + refMod->SetLineColor( 38 ); + refMod->SetFillColor( 13 ); + TGeoVolume *curMod = geom->MakeBox( "curMod", Al, 0.5*_surWidth*_sclfmodulesizex, 0.5*_surLength*_sclfmodulesizey, 0.30*_sclfmodulesizez ); + + if ((_yVal < 0)&&(_zVal>=0)) curMod->SetLineColor( kRed ); + if ((_yVal < 0)&&(_zVal<0)) curMod->SetLineColor( kGreen ); + if ((_yVal >= 0)&&(_zVal>=0)) curMod->SetLineColor( kBlue ); + if ((_yVal >= 0)&&(_zVal<0)) curMod->SetLineColor( kMagenta ); + refMod->SetLineColor( 14 ); + //curMod->SetLineColor(kBlue); + //refMod->SetLineColor(kRed); + + const Double_t radc = 180./TMath::Pi(); + TGeoTranslation *tr1 = new TGeoTranslation( 0., 0., 0. ); + TGeoRotation *rt1 = new TGeoRotation(); + double rota[9]; + rota[0] = _surRot[0]; rota[1] = _surRot[3]; rota[2] = _surRot[6]; + rota[3] = _surRot[1]; rota[4] = _surRot[4]; rota[5] = _surRot[7]; + rota[6] = _surRot[2]; rota[7] = _surRot[5]; rota[8] = _surRot[8]; + rt1->SetMatrix( rota ); + TGeoTranslation *tr2 = new TGeoTranslation( _sclftr*_dxVal, _sclftr*_dyVal, _sclftr*_dzVal ); + TGeoRotation *rt2 = new TGeoRotation( "rt2", _sclfrt*_dalphaVal*radc, _sclfrt*_dbetaVal*radc, _sclfrt*_dgammaVal*radc ); + rt2->MultiplyBy( rt1 ); + TGeoCombiTrans *combi1 = new TGeoCombiTrans( *tr1, *rt1 ); + TGeoCombiTrans *combi2 = new TGeoCombiTrans( *tr2, *rt2 ); + mod->AddNode( curMod, 1, combi2 ); + mod->AddNode( refMod, 1, combi1 ); + TGeoTranslation *trG = new TGeoTranslation( _xVal - _dxVal, _yVal - _dyVal, _zVal - _dzVal); + TGeoRotation *rtG = new TGeoRotation( "rtG", -1*_dalphaVal, -1*_dbetaVal, -1*_dgammaVal ); + TGeoCombiTrans *combi = new TGeoCombiTrans( *trG, *rtG ); + top->AddNode( mod, 1, combi ); +} + +bool isRightSubDet() { + return (_sublevel == _subdetector1 || _sublevel == _subdetector2); +} + +int visualizationTracker(float minZ, float maxZ, float minX, float maxX, float theta, float phi){ + gSystem->Load("libGeom"); +//++++++++++++++++++++ Set up stuff ++++++++++++++++++++// + TGeoManager *geom = new TGeoManager("simple1", "Simple geometry"); +//--- define some materials and media + TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0,0,0); + TGeoMedium *Vacuum = new TGeoMedium("Vacuum",1, matVacuum); +//--- make the top container volume + TGeoVolume *top = geom->MakeBox("TOP", Vacuum, 500., 500., 500.); +//TGeoVolume *toptop = geom->MakeBox("TOPTOP", Vacuum, 1000., 1000., 500.); + geom->SetTopVolume(top); + + int count = 0; + for (int i = 0; i < _nEntries; ++i){ + _inTree->GetEntry(i); + if (isRightSubDet()&&(_zVal >= minZ && _zVal < maxZ)&&(_xVal >= minX && _xVal < maxX)/*&&(_rVal <= 12)&&(_rVal >=8)*/){ + char modName[192]; + sprintf(modName, "testModule%i", i); + TGeoVolume* testMod = geom->MakeBox( modName, Vacuum, 90., 90., 40. ); + getModule( geom, top, testMod ); + count++; + } + } + + if(count == 0) return -1; + + getBeamVisuals(geom, top, minZ, maxZ); + +//--- close the geometry + geom->CloseGeometry(); +// -- draw + geom->SetVisLevel(4); + + TCanvas * c = new TCanvas(); + c->SetTheta(theta); + c->SetPhi(phi); + top->Draw(); + +//--- putting words on canvas... + bool with0T = true; + + //can play with these numbers + double widthofeach = 0.07; + double textsize = 0.05; + + double xmax = 2*widthofeach; + if (with0T) xmax = widthofeach; + + TPaveText* pt = new TPaveText(0,0,xmax,1,"brNDC"); + pt->SetBorderSize(0); + pt->SetFillStyle(0); + pt->SetTextAlign(22); + pt->SetTextFont(42); + pt->SetTextSize(0.1); + TText *text = pt->AddText(0,0,TString("#font[42]{"+_line1+"}")); + text->SetTextSize(textsize); + text->SetTextAngle(90); + pt->Draw(); + + TPaveText *pt2 = new TPaveText(widthofeach, 0, 2*widthofeach, 1, "brNDC"); + pt2->SetBorderSize(0); + pt2->SetFillStyle(0); + pt2->SetTextAlign(22); + pt2->SetTextFont(42); + pt2->SetTextSize(0.1); + TText *text2 = pt2->AddText(0,0,TString("#font[42]{"+_line2+"}")); + text2->SetTextSize(textsize); + text2->SetTextAngle(90); + pt2->Draw(); + + TPaveText *pt3 = new TPaveText(2*widthofeach, 0, 3*widthofeach, 1, "brNDC"); + pt3->SetBorderSize(0); + pt3->SetFillStyle(0); + pt3->SetTextAlign(22); + pt3->SetTextFont(42); + pt3->SetTextSize(0.1); + TText *text3 = pt3->AddText(0,0,TString("#font[42]{"+_line3+"}")); + text3->SetTextSize(textsize); + text3->SetTextAngle(90); + pt3->Draw(); + + string str = string("i") + to_string(_i) + string(".gif"); + c->SaveAs(TString(str)); + gSystem->Exec(TString("mv "+str+" images/"+str)); + delete c; + cout << "Created image " << str << endl; + return 0; +} + +//gets minimum and maximum values of Z and Y in the specified subdetectors +void getMinMax(float & minZ, float & maxZ, float & minX, float & maxX) { + int i = 0; + while(i < _nEntries){ + _inTree->GetEntry(i); + if(isRightSubDet()) { + _inTree->GetEntry(i); + maxX = _xVal; + minX = _xVal; + maxZ = _zVal; + minZ = _zVal; + break; + } + ++i; + } + while ( i < _nEntries ) { + _inTree->GetEntry(i); + if (isRightSubDet()) { + if( _xVal > maxX ) { + maxX = _xVal; + } + if( _xVal < minX ) { + minX = _xVal; + } + if( _zVal > maxZ ) { + maxZ = _zVal; + } + if( _zVal < minZ ) { + minZ = _zVal; + } + } + ++i; + } + cout << minX << endl; + cout << maxX << endl; + cout << minZ << endl; + cout << maxZ << endl; +} + +//gets string that is a unix command that merges gifs using gifmerge (download at http://the-labs.com/GIFMerge/) +string getGifMergeCommand(int start, int breakspot1, int breakspot2, int end) { + string str = ""; + str += "./gifmerge -192,192,192 -l0 -5 "; + for (int i = start; i < breakspot1; i++) { + str += "images/i"+to_string(i)+".gif "; + } + str += "-50 "; + for (int i = breakspot1; i < breakspot2; i++) { + str += "images/i"+to_string(i)+".gif "; + } + str += "-5 "; + for (int i = breakspot2; i < end-1; i++) { + str += "images/i"+to_string(i)+".gif "; + } + str += "-100 images/i"+to_string(end-1)+".gif > "+_outputFileName+".gif"; + return str; +} + +//gets string that is a unix command that merges gifs using ImageMagick +string getConvertCommand(int start, int breakspot1, int breakspot2, int end) { + string str = ""; + str += "convert -loop 0 -delay 5 "; + for (int i = start; i < breakspot1; i++) { + str += "images/i"+to_string(i)+".gif "; + } + str += "-delay 50 "; + for (int i = breakspot1; i < breakspot2; i++) { + str += "images/i"+to_string(i)+".gif "; + } + str += "-delay 5 "; + for (int i = breakspot2; i < end-1; i++) { + str += "images/i"+to_string(i)+".gif "; + } + str += "-delay 100 images/i"+to_string(end-1)+".gif "+_outputFileName+".gif"; + return str; +} + +void runVisualizer(TString input, + string output, + string line1, + string line2, + int subdetector1, + int subdetector2, + int sclftr, + int sclfrt, + float sclfmodulesizex, + float sclfmodulesizey, + float sclfmodulesizez, + float piperadius, + float pipexcoord, + float pipeycoord, + float linexcoord, + float lineycoord ) { + gErrorIgnoreLevel = kError; + +//------Tree Read In-------- + TString inputFileName = input; + //output file name + _outputFileName = output; + //title + _line1 = line1; + _line2 = line2; + //set subdetectors to see + _subdetector1 = subdetector1; + _subdetector2 = subdetector2; + //translation scale factor + _sclftr = sclftr; + //rotation scale factor + _sclfrt = sclfrt; + //module size scale factor + _sclfmodulesizex = sclfmodulesizex; + _sclfmodulesizey = sclfmodulesizey; + _sclfmodulesizez = sclfmodulesizez; + //beam pipe radius + _piperadius = piperadius; + //beam pipe xy coordinates + _pipexcoord = pipexcoord; + _pipeycoord = pipeycoord; + //beam line xy coordinates + _linexcoord = linexcoord; + _lineycoord = lineycoord; + + + sortbyz( inputFileName ); + TFile *fin = TFile::Open( inputFileName.ReplaceAll(".root", "_sorted.root") ); + _line3 = Form("Translational Scale Factor: %i",_sclftr); + //++++++++++++++++++++ Read in tree ++++++++++++++++++++// + _inTree = (TTree*) fin->Get("alignTree"); + _nEntries = _inTree->GetEntries(); + _inTree->SetBranchAddress( "id", &_id ); + _inTree->SetBranchAddress( "level", &_level); + _inTree->SetBranchAddress("mid", &_mid); + _inTree->SetBranchAddress("mlevel", &_mlevel); + _inTree->SetBranchAddress("sublevel", &_sublevel); + _inTree->SetBranchAddress("x", &_xVal); + _inTree->SetBranchAddress("y", &_yVal); + _inTree->SetBranchAddress("z", &_zVal); + _inTree->SetBranchAddress("r", &_rVal); + _inTree->SetBranchAddress("phi", &_phiVal); + _inTree->SetBranchAddress("alpha", &_alphaVal); + _inTree->SetBranchAddress("beta", &_betaVal); + _inTree->SetBranchAddress("gamma", &_gammaVal); + _inTree->SetBranchAddress("dx", &_dxVal); + _inTree->SetBranchAddress("dy", &_dyVal); + _inTree->SetBranchAddress("dz", &_dzVal); + _inTree->SetBranchAddress("dr", &_drVal); + _inTree->SetBranchAddress("dphi", &_dphiVal); + _inTree->SetBranchAddress("dalpha", &_dalphaVal); + _inTree->SetBranchAddress("dbeta", &_dbetaVal); + _inTree->SetBranchAddress("dgamma", &_dgammaVal); + _inTree->SetBranchAddress("surW", &_surWidth); + _inTree->SetBranchAddress("surL", &_surLength); + _inTree->SetBranchAddress("surRot", &_surRot); +//_inTree->SetBranchAddress("useid", &_useid); + _inTree->SetBranchAddress("identifiers", &_identifiers); + + float minZ, maxZ, minX, maxX; + int zpos; + int numincrements; + getMinMax(minZ, maxZ, minX, maxX); + + gSystem->mkdir("images"); + + _i = 0; + for (int i = 0; i < 90; i+=1, _i++) { + visualizationTracker(minZ, maxZ, minX, maxX, i, 90); + } + + numincrements = 12; + float length; + int start1 = _i; + length = (maxZ - minZ) / numincrements; + for(int i = numincrements-1; i >= 0; i--) { + zpos = minZ + i*length; + if(visualizationTracker(zpos, zpos+length, minX, maxX, 90, 90) == 0) { + _i++; + } + } + + int start2 = _i; + for (int i = 90; i >= 0; i-=1, _i++){ + visualizationTracker(minZ, maxZ, (minX + maxX) / 2 - 3, (minX + maxX) / 2 + 1, i, 90); + } + delete fin; + + //gSystem->Exec(TString(getGifMergeCommand(0, start1, start2, _i))); + gSystem->Exec(TString(getConvertCommand(0, start1, start2, _i))); + cout << "images merged." << endl; + gSystem->Exec(TString("convert "+_outputFileName+".gif -rotate 90 "+_outputFileName+"_rotated.gif")); + cout << "images rotated." << endl; } -void visualizationTracker(){ - - gSystem->Load("libGeom"); - - //------------------------------ONLY NEEDED INPUTS-------------------------------// - //------Tree Read In-------- - TFile *fin = new TFile( "craftData/comparison_craft3900k_pxbDetswSCladders_special3.root" ); - int subdetector = 1; - _moduleListName = "PXBdetids.txt"; - _sclf = 25; - //------------------------------End of ONLY NEEDED INPUTS-------------------------------// - - //++++++++++++++++++++ Set up stuff ++++++++++++++++++++// - TGeoManager *geom = new TGeoManager("simple1", "Simple geometry"); - //--- define some materials and media - TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0,0,0); - TGeoMedium *Vacuum = new TGeoMedium("Vacuum",1, matVacuum); - //--- make the top container volume - TGeoVolume *top = geom->MakeBox("TOP", Vacuum, 500., 500., 500.); - //TGeoVolume *toptop = geom->MakeBox("TOPTOP", Vacuum, 1000., 1000., 500.); - geom->SetTopVolume(top); - - //++++++++++++++++++++ Read in tree ++++++++++++++++++++// - _inTree = (TTree*) fin->Get("alignTree"); - _nEntries = _inTree->GetEntries(); - - _inTree->SetBranchAddress( "id", &_id ); - _inTree->SetBranchAddress( "level", &_level); - _inTree->SetBranchAddress("mid", &_mid); - _inTree->SetBranchAddress("mlevel", &_mlevel); - _inTree->SetBranchAddress("sublevel", &_sublevel); - _inTree->SetBranchAddress("x", &_xVal); - _inTree->SetBranchAddress("y", &_yVal); - _inTree->SetBranchAddress("z", &_zVal); - _inTree->SetBranchAddress("r", &_rVal); - _inTree->SetBranchAddress("phi", &_phiVal); - _inTree->SetBranchAddress("alpha", &_alphaVal); - _inTree->SetBranchAddress("beta", &_betaVal); - _inTree->SetBranchAddress("gamma", &_gammaVal); - _inTree->SetBranchAddress("dx", &_dxVal); - _inTree->SetBranchAddress("dy", &_dyVal); - _inTree->SetBranchAddress("dz", &_dzVal); - _inTree->SetBranchAddress("dr", &_drVal); - _inTree->SetBranchAddress("dphi", &_dphiVal); - _inTree->SetBranchAddress("dalpha", &_dalphaVal); - _inTree->SetBranchAddress("dbeta", &_dbetaVal); - _inTree->SetBranchAddress("dgamma", &_dgammaVal); - _inTree->SetBranchAddress("surW", &_surWidth); - _inTree->SetBranchAddress("surL", &_surLength); - _inTree->SetBranchAddress("surRot", &_surRot); - //_inTree->SetBranchAddress("useid", &_useid); - _inTree->SetBranchAddress("identifiers", &_identifiers); - - - //reading list ... - readModuleList(); - - - //draw modules in the list - for (int i = 0; i < _nEntries; ++i){ - _inTree->GetEntry(i); - if ((_sublevel == subdetector)&&(_rVal <= 12)&&(_rVal >=8)){ - bool foundID = false; - for (int j = 0; j < _moduleList.size(); ++j){ - if (_id == _moduleList[j]) foundID = true; - } - if (foundID){ - char modName[192]; - sprintf(modName, "testModule%i", i); - TGeoVolume* testMod = geom->MakeBox( modName, Vacuum, 90., 90., 40. ); - getModule( geom, top, testMod ); - } - } - } - - TGeoTranslation *tr1 = new TGeoTranslation( 0., 0., 0. ); - TGeoRotation *rt1 = new TGeoRotation( "rt1", 90., 0., 0. ); - TGeoCombiTrans *combi1 = new TGeoCombiTrans( *tr1, *rt1 ); - - // --- crate the top volume - //toptop->AddNode(top, 1, combi1); - //top->AddNode(disk, 1, 0); - //--- close the geometry - geom->CloseGeometry(); - // -- draw - geom->SetVisLevel(4); - top->Draw(); +void runVisualizer() { + //------------------------------ONLY NEEDED INPUTS-------------------------------// +//------Tree Read In-------- + TString inputFileName = "~/normal_vs_test.Comparison_commonTracker.root"; + //output file name + string outputFileName = "animation"; + //title + string line1 = ""; + string line2 = ""; + //set subdetectors to see + int subdetector1 = 1; + int subdetector2 = 2; + //translation scale factor + int sclftr = 50; + //rotation scale factor + int sclfrt = 1; + //module size scale factor + float sclfmodulesizex = 1; + float sclfmodulesizey = 1; + float sclfmodulesizez = 1; + //beam pipe radius + float piperadius = 2.25; + //beam pipe xy coordinates + float pipexcoord = 0; + float pipeycoord = 0; + //beam line xy coordinates + float linexcoord = 0; + float lineycoord = 0; +//------------------------------End of ONLY NEEDED INPUTS-------------------------------// + runVisualizer(inputFileName, + outputFileName, + line1, + line2, + subdetector1, + subdetector2, + sclftr, + sclfrt, + sclfmodulesizex, + sclfmodulesizey, + sclfmodulesizez, + piperadius, + pipexcoord, + pipeycoord, + linexcoord, + lineycoord ); } - \ No newline at end of file