Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:17

0001 #!/usr/bin/perl
0002 
0003 $baseofall = `pwd`;
0004 chop($baseofall);
0005 
0006 $dirname = $ARGV[0];
0007 $initial = "wheeldisk_nocut";
0008 # $initial = "wheeldisk_cut3sig";
0009 # $initial = "wheeldisk_cut5sig";
0010 $filetemplate = "rfio:///?svcclass=cmscaf&path=//castor/cern.ch/cms/store/cmscaf/alca/alignment/CSA07/MuonHIP/AlCaRecoMu/wmunu_100pb-1/%02d.root";
0011 # $filetemplate = "rfio:///?svcclass=cmscaf&path=//castor/cern.ch/cms/store/cmscaf/alca/alignment/CSA07/MuonHIP/AlCaRecoMu/wmunu_100pb-1_cut3sig/%02d.root";
0012 # $filetemplate = "rfio:///?svcclass=cmscaf&path=//castor/cern.ch/cms/store/cmscaf/alca/alignment/CSA07/MuonHIP/AlCaRecoMu/wmunu_100pb-1_cut5sig/%02d.root";
0013 # $filetemplate = "rfio:///castor/cern.ch/user/p/pivarski/tmp2/%02d.root";
0014 # $filetemplate = "rfio:///castor/cern.ch/user/p/pivarski/tmp2_cut3sig/%02d.root";
0015 # $filetemplate = "rfio:///castor/cern.ch/user/p/pivarski/tmp2_cut5sig/%02d.root";
0016 
0017 $muonSourceLabel = "ALCARECOMuAlZMuMu";
0018 # $muonSourceLabel = "StraightMuonCutProducer";
0019 
0020 $theConstraint = "NONE";
0021 # $theConstraint = "/afs/cern.ch/user/p/pivarski/scratch0/cmssw_dest/constraints/constraint_10";
0022 
0023 $last = $initial;
0024 $lastwhere = "$baseofall/$initial";
0025 
0026 if (-e $dirname) {
0027     die "Delete the old one first: rm -rf $dirname";
0028 }
0029 
0030 if ($dirname eq "") {
0031     die "Give this trial a name as an argument: ./makestandard.pl SOMETHING";
0032 }
0033 
0034 system("mkdir $dirname");
0035 &common_cff($dirname);
0036 &source_cff($dirname);
0037 
0038 open(RUNALL, "> $dirname/runall.sh");
0039 print RUNALL "#!/bin/sh
0040 cd $baseofall
0041 eval `scramv1 run -sh`
0042 ";
0043 
0044 foreach $pass ("pass1", "pass2_mb2_me12", "pass3_mb3_me21", "pass4_mb4_me13", "pass5_me22_me31", "pass6_me32_me41", "stage3", "stage4") {
0045     system("mkdir $dirname/$pass");
0046 
0047     if ($pass eq "pass1") {
0048     $alignParams = "{\"MuonDTChambers,111111,mb1\", \"MuonDTChambers,111111,mb2\", \"MuonDTChambers,111111,mb3\", \"MuonDTChambers,101011,mb4\", \"MuonCSCChambers,110011,me11\", \"MuonCSCChambers,110011,me12\", \"MuonCSCChambers,110011,me13\", \"MuonCSCChambers,110011,me21\", \"MuonCSCChambers,110011,me22\", \"MuonCSCChambers,110011,me31\", \"MuonCSCChambers,110011,me32\", \"MuonCSCChambers,110011,me41\"}";
0049     $APEs = "";
0050     }
0051     elsif ($pass eq "pass2_mb2_me12") {
0052     $alignParams = "{\"MuonDTChambers,111111,mb2\", \"MuonCSCChambers,110011,me12\"}";
0053     $APEs = ", {
0054     PSet Selector = { vstring alignParams = {\"MuonDTChambers,111111,mb1\"} using MuonAlignmentStationSelector }
0055     string function = \"linear\"
0056     vdouble apeSPar = {0., 0., 10.}
0057     vdouble apeRPar = {0., 0., 10.}
0058 }, {
0059     PSet Selector = { vstring alignParams = {\"MuonCSCChambers,111111,me11\"} using MuonAlignmentStationSelector }
0060     string function = \"linear\"
0061     vdouble apeSPar = {0., 0., 10.}
0062     vdouble apeRPar = {0., 0., 10.}
0063 }
0064 ";
0065     }
0066     elsif ($pass eq "pass3_mb3_me21") {
0067     $alignParams = "{\"MuonDTChambers,111111,mb3\", \"MuonCSCChambers,110011,me21\"}";
0068     $APEs = ", {
0069     PSet Selector = { vstring alignParams = {\"MuonDTChambers,111111,mb1\"} using MuonAlignmentStationSelector }
0070     string function = \"linear\"
0071     vdouble apeSPar = {0., 0., 10.}
0072     vdouble apeRPar = {0., 0., 10.}
0073 }, {
0074     PSet Selector = { vstring alignParams = {\"MuonDTChambers,111111,mb2\"} using MuonAlignmentStationSelector }
0075     string function = \"linear\"
0076     vdouble apeSPar = {0., 0., 10.}
0077     vdouble apeRPar = {0., 0., 10.}
0078 }, {
0079     PSet Selector = { vstring alignParams = {\"MuonCSCChambers,111111,me11\"} using MuonAlignmentStationSelector }
0080     string function = \"linear\"
0081     vdouble apeSPar = {0., 0., 10.}
0082     vdouble apeRPar = {0., 0., 10.}
0083 }, {
0084     PSet Selector = { vstring alignParams = {\"MuonCSCChambers,111111,me12\"} using MuonAlignmentStationSelector }
0085     string function = \"linear\"
0086     vdouble apeSPar = {0., 0., 10.}
0087     vdouble apeRPar = {0., 0., 10.}
0088 }
0089 ";
0090     }
0091     elsif ($pass eq "pass4_mb4_me13") {
0092     $alignParams = "{\"MuonDTChambers,101011,mb4\", \"MuonCSCChambers,110011,me13\"}";
0093     $APEs = ", {
0094     PSet Selector = { vstring alignParams = {\"MuonDTChambers,111111,mb1\"} using MuonAlignmentStationSelector }
0095     string function = \"linear\"
0096     vdouble apeSPar = {0., 0., 10.}
0097     vdouble apeRPar = {0., 0., 10.}
0098 }, {
0099     PSet Selector = { vstring alignParams = {\"MuonDTChambers,111111,mb2\"} using MuonAlignmentStationSelector }
0100     string function = \"linear\"
0101     vdouble apeSPar = {0., 0., 10.}
0102     vdouble apeRPar = {0., 0., 10.}
0103 }, {
0104     PSet Selector = { vstring alignParams = {\"MuonDTChambers,111111,mb3\"} using MuonAlignmentStationSelector }
0105     string function = \"linear\"
0106     vdouble apeSPar = {0., 0., 10.}
0107     vdouble apeRPar = {0., 0., 10.}
0108 }, {
0109     PSet Selector = { vstring alignParams = {\"MuonCSCChambers,111111,me11\"} using MuonAlignmentStationSelector }
0110     string function = \"linear\"
0111     vdouble apeSPar = {0., 0., 10.}
0112     vdouble apeRPar = {0., 0., 10.}
0113 }, {
0114     PSet Selector = { vstring alignParams = {\"MuonCSCChambers,111111,me12\"} using MuonAlignmentStationSelector }
0115     string function = \"linear\"
0116     vdouble apeSPar = {0., 0., 10.}
0117     vdouble apeRPar = {0., 0., 10.}
0118 }, {
0119     PSet Selector = { vstring alignParams = {\"MuonCSCChambers,111111,me21\"} using MuonAlignmentStationSelector }
0120     string function = \"linear\"
0121     vdouble apeSPar = {0., 0., 10.}
0122     vdouble apeRPar = {0., 0., 10.}
0123 }
0124 ";
0125     }
0126     elsif ($pass eq "pass5_me22_me31") {
0127     $alignParams = "{\"MuonCSCChambers,110011,me22\", \"MuonCSCChambers,110011,me31\"}";
0128     $APEs = ", {
0129     PSet Selector = { vstring alignParams = {\"MuonDTChambers,111111,mb1\"} using MuonAlignmentStationSelector }
0130     string function = \"linear\"
0131     vdouble apeSPar = {0., 0., 10.}
0132     vdouble apeRPar = {0., 0., 10.}
0133 }, {
0134     PSet Selector = { vstring alignParams = {\"MuonDTChambers,111111,mb2\"} using MuonAlignmentStationSelector }
0135     string function = \"linear\"
0136     vdouble apeSPar = {0., 0., 10.}
0137     vdouble apeRPar = {0., 0., 10.}
0138 }, {
0139     PSet Selector = { vstring alignParams = {\"MuonDTChambers,111111,mb3\"} using MuonAlignmentStationSelector }
0140     string function = \"linear\"
0141     vdouble apeSPar = {0., 0., 10.}
0142     vdouble apeRPar = {0., 0., 10.}
0143 }, {
0144     PSet Selector = { vstring alignParams = {\"MuonDTChambers,111111,mb4\"} using MuonAlignmentStationSelector }
0145     string function = \"linear\"
0146     vdouble apeSPar = {0., 0., 10.}
0147     vdouble apeRPar = {0., 0., 10.}
0148 }, {
0149     PSet Selector = { vstring alignParams = {\"MuonCSCChambers,111111,me11\"} using MuonAlignmentStationSelector }
0150     string function = \"linear\"
0151     vdouble apeSPar = {0., 0., 10.}
0152     vdouble apeRPar = {0., 0., 10.}
0153 }, {
0154     PSet Selector = { vstring alignParams = {\"MuonCSCChambers,111111,me12\"} using MuonAlignmentStationSelector }
0155     string function = \"linear\"
0156     vdouble apeSPar = {0., 0., 10.}
0157     vdouble apeRPar = {0., 0., 10.}
0158 }, {
0159     PSet Selector = { vstring alignParams = {\"MuonCSCChambers,111111,me13\"} using MuonAlignmentStationSelector }
0160     string function = \"linear\"
0161     vdouble apeSPar = {0., 0., 10.}
0162     vdouble apeRPar = {0., 0., 10.}
0163 }, {
0164     PSet Selector = { vstring alignParams = {\"MuonCSCChambers,111111,me21\"} using MuonAlignmentStationSelector }
0165     string function = \"linear\"
0166     vdouble apeSPar = {0., 0., 10.}
0167     vdouble apeRPar = {0., 0., 10.}
0168 }
0169 ";
0170     }
0171     elsif ($pass eq "pass6_me32_me41") {
0172     $alignParams = "{\"MuonCSCChambers,110011,me32\", \"MuonCSCChambers,110011,me41\"}";
0173     $APEs = ", {
0174     PSet Selector = { vstring alignParams = {\"MuonDTChambers,111111,mb1\"} using MuonAlignmentStationSelector }
0175     string function = \"linear\"
0176     vdouble apeSPar = {0., 0., 10.}
0177     vdouble apeRPar = {0., 0., 10.}
0178 }, {
0179     PSet Selector = { vstring alignParams = {\"MuonDTChambers,111111,mb2\"} using MuonAlignmentStationSelector }
0180     string function = \"linear\"
0181     vdouble apeSPar = {0., 0., 10.}
0182     vdouble apeRPar = {0., 0., 10.}
0183 }, {
0184     PSet Selector = { vstring alignParams = {\"MuonDTChambers,111111,mb3\"} using MuonAlignmentStationSelector }
0185     string function = \"linear\"
0186     vdouble apeSPar = {0., 0., 10.}
0187     vdouble apeRPar = {0., 0., 10.}
0188 }, {
0189     PSet Selector = { vstring alignParams = {\"MuonDTChambers,111111,mb4\"} using MuonAlignmentStationSelector }
0190     string function = \"linear\"
0191     vdouble apeSPar = {0., 0., 10.}
0192     vdouble apeRPar = {0., 0., 10.}
0193 }, {
0194     PSet Selector = { vstring alignParams = {\"MuonCSCChambers,111111,me11\"} using MuonAlignmentStationSelector }
0195     string function = \"linear\"
0196     vdouble apeSPar = {0., 0., 10.}
0197     vdouble apeRPar = {0., 0., 10.}
0198 }, {
0199     PSet Selector = { vstring alignParams = {\"MuonCSCChambers,111111,me12\"} using MuonAlignmentStationSelector }
0200     string function = \"linear\"
0201     vdouble apeSPar = {0., 0., 10.}
0202     vdouble apeRPar = {0., 0., 10.}
0203 }, {
0204     PSet Selector = { vstring alignParams = {\"MuonCSCChambers,111111,me13\"} using MuonAlignmentStationSelector }
0205     string function = \"linear\"
0206     vdouble apeSPar = {0., 0., 10.}
0207     vdouble apeRPar = {0., 0., 10.}
0208 }, {
0209     PSet Selector = { vstring alignParams = {\"MuonCSCChambers,111111,me21\"} using MuonAlignmentStationSelector }
0210     string function = \"linear\"
0211     vdouble apeSPar = {0., 0., 10.}
0212     vdouble apeRPar = {0., 0., 10.}
0213 }, {
0214     PSet Selector = { vstring alignParams = {\"MuonCSCChambers,111111,me22\"} using MuonAlignmentStationSelector }
0215     string function = \"linear\"
0216     vdouble apeSPar = {0., 0., 10.}
0217     vdouble apeRPar = {0., 0., 10.}
0218 }, {
0219     PSet Selector = { vstring alignParams = {\"MuonCSCChambers,111111,me31\"} using MuonAlignmentStationSelector }
0220     string function = \"linear\"
0221     vdouble apeSPar = {0., 0., 10.}
0222     vdouble apeRPar = {0., 0., 10.}
0223 }
0224 ";
0225     }
0226     elsif ($pass eq "stage3") {
0227     $alignParams = "{\"MuonDTChambers,111111,mb1\", \"MuonDTChambers,111111,mb2\", \"MuonDTChambers,111111,mb3\", \"MuonDTChambers,101011,mb4\", \"MuonCSCChambers,110011,me11\", \"MuonCSCChambers,110011,me12\", \"MuonCSCChambers,110011,me13\", \"MuonCSCChambers,110011,me21\", \"MuonCSCChambers,110011,me22\", \"MuonCSCChambers,110011,me31\", \"MuonCSCChambers,110011,me32\", \"MuonCSCChambers,110011,me41\"}";
0228     $APEs = ", {
0229     PSet Selector = { vstring alignParams = {\"MuonDTChambers,111111\", \"MuonCSCChambers,111111\"} }
0230     string function = \"linear\"
0231     vdouble apeSPar = {0.1, 0.1, 10.}
0232     vdouble apeRPar = {0.1, 0.1, 10.}
0233 }
0234 ";
0235     }
0236     elsif ($pass eq "stage4") {
0237     $alignParams = "{\"MuonDTChambers,111111,mb2\", \"MuonDTChambers,111111,mb3\", \"MuonDTChambers,101011,mb4\", \"MuonCSCChambers,110011,me13\", \"MuonCSCChambers,110011,me21\", \"MuonCSCChambers,110011,me22\", \"MuonCSCChambers,110011,me31\", \"MuonCSCChambers,110011,me32\", \"MuonCSCChambers,110011,me41\"}";
0238     $APEs = ", {
0239     PSet Selector = { vstring alignParams = {\"MuonDTChambers,111111\", \"MuonCSCChambers,111111\"} }
0240     string function = \"linear\"
0241     vdouble apeSPar = {0.1, 0.1, 10.}
0242     vdouble apeRPar = {0.1, 0.1, 10.}
0243 }, {
0244     PSet Selector = { vstring alignParams = {\"MuonDTChambers,111111,mb1\"} using MuonAlignmentStationSelector }
0245     string function = \"linear\"
0246     vdouble apeSPar = {0., 0., 10.}
0247     vdouble apeRPar = {0., 0., 10.}
0248 }, {
0249     PSet Selector = { vstring alignParams = {\"MuonCSCChambers,111111,me11\"} using MuonAlignmentStationSelector }
0250     string function = \"linear\"
0251     vdouble apeSPar = {0., 0., 10.}
0252     vdouble apeRPar = {0., 0., 10.}
0253 }, {
0254     PSet Selector = { vstring alignParams = {\"MuonCSCChambers,111111,me12\"} using MuonAlignmentStationSelector }
0255     string function = \"linear\"
0256     vdouble apeSPar = {0., 0., 10.}
0257     vdouble apeRPar = {0., 0., 10.}
0258 }
0259 ";
0260     }
0261 
0262     @iters = ("iter1", "iter2", "iter3", "iter4", "iter5");
0263 
0264     foreach $iter (@iters) {
0265     system("mkdir $dirname/$pass/$iter");
0266 
0267     print RUNALL "cd $baseofall/$dirname/$pass/$iter\n";
0268 
0269     foreach $N (1..50) {
0270         printf(RUNALL "cd job%d
0271 bsub -q cmscaf ./$dirname\_$pass\_$iter\_job%d.sh
0272 cd ..\n", $N, $N);
0273     }
0274     foreach $N (1..50) {
0275         printf(RUNALL "while (test ! -e job%d/DONE.txt); do sleep 1; done\n", $N);
0276     }
0277 
0278     system("ln -s $lastwhere.db $dirname/$pass/$iter/$last.db");
0279     system("ln -s $lastwhere.xml $dirname/$pass/$iter/$last.xml");
0280 
0281     foreach $N (1..50) {
0282         $job = sprintf("job%d", $N);
0283         system("mkdir $dirname/$pass/$iter/$job");
0284         open(FILE, "> $dirname/$pass/$iter/$job/$dirname\_$pass\_$iter\_$job.cfg");
0285 
0286         print FILE "process align = {
0287     include \"$dirname/sources/$job.cff\"
0288     include \"$dirname/common.cff\"
0289 
0290     replace AlignmentProducer.ParameterBuilder.Selector = {
0291         vstring alignParams = $alignParams
0292         using MuonAlignmentStationSelector
0293     }
0294 
0295     replace AlignmentProducer.algoConfig.applyAPE = true
0296     replace AlignmentProducer.algoConfig.apeParam = {
0297     {
0298         PSet Selector = {vstring alignParams = {\"MuonDTChambers,111111\", \"MuonCSCChambers,111111\"}}
0299         string function = \"linear\"
0300         vdouble apeSPar = {1000., 1000., 10.}
0301         vdouble apeRPar = {1000., 1000., 10.}
0302     }$APEs
0303     }
0304 
0305     include \"Alignment/CommonAlignmentMonitor/data/AlignmentMonitorMuonResidualsDefaults.cff\"
0306     replace AlignmentProducer.monitorConfig = {
0307     untracked vstring monitors = {\"AlignmentMonitorMuonResiduals\"}
0308     
0309     untracked PSet AlignmentMonitorMuonResiduals = {
0310         string outfile = \"$dirname\_$pass\_$iter.root\"
0311         using AlignmentMonitorMuonResidualsDefaults
0312     }
0313     }
0314 
0315     replace PoolDBESSource.connect = \"sqlite_file:$last.db\"
0316     replace PoolDBESSource.catalog = \"xmlcatalog_file:$last.xml\"
0317 
0318     path p = {recoMuon2recoTrack, TrackRefitter}
0319 
0320 ";
0321         if ($theConstraint ne "NONE") {
0322         print FILE "
0323     es_source constraints = PoolDBESSource {
0324         using CondDBCommon
0325         untracked uint32 authenticationMethod = 1
0326         VPSet toGet = {
0327             {
0328                 string record = \"DTSurveyRcd\"
0329                 string tag = \"DTSurveyRcd\"
0330             },
0331             {
0332                 string record = \"DTSurveyErrorExtendedRcd\"
0333                 string tag = \"DTSurveyErrorExtendedRcd\"
0334             },
0335             {
0336                 string record = \"CSCSurveyRcd\"
0337                 string tag = \"CSCSurveyRcd\"
0338             },
0339             {
0340                 string record = \"CSCSurveyErrorExtendedRcd\"
0341                 string tag = \"CSCSurveyErrorExtendedRcd\"
0342             }
0343         }
0344     }
0345     replace constraints.connect = \"sqlite_file:$theConstraint.db\"
0346     replace constraints.catalog = \"xmlcatalog_file:$theConstraint\_catalog.xml\"
0347     replace AlignmentProducer.useSurvey = true
0348 ";
0349         }
0350         print FILE "
0351 }
0352 ";
0353         close(FILE);
0354 
0355         open(FILE, "> $dirname/$pass/$iter/$job/$dirname\_$pass\_$iter\_$job.sh");
0356             print FILE "#!/bin/sh
0357 cd $baseofall
0358 eval `scramv1 run -sh`
0359 # export STAGE_SVCCLASS=cmscaf
0360 cd $dirname/$pass/$iter/$job
0361 
0362 echo \"Start\"
0363 date
0364 
0365 echo \"About to rm -rf /pool/lsf/pivarski/$dirname\_$pass\_$iter\_$job\"
0366 rm -rf /pool/lsf/pivarski/$dirname\_$pass\_$iter\_$job
0367 date
0368 
0369 echo \"About to mkdir -p /pool/lsf/pivarski/$dirname\_$pass\_$iter\_$job\"
0370 mkdir -p /pool/lsf/pivarski/$dirname\_$pass\_$iter\_$job
0371 date
0372 
0373 echo \"About to cp $dirname\_$pass\_$iter\_$job.cfg $lastwhere.db $lastwhere.xml /pool/lsf/pivarski/$dirname\_$pass\_$iter\_$job/\"
0374 cp $dirname\_$pass\_$iter\_$job.cfg $lastwhere.db $lastwhere.xml /pool/lsf/pivarski/$dirname\_$pass\_$iter\_$job/
0375 date
0376 
0377 ";
0378         if ($theConstraint ne "NONE") {
0379         print FILE "
0380 echo \"About to copy $theConstraint to /pool/lsf/pivarski/$dirname\_$pass\_$iter\_$job\"
0381 cp $theConstraint.db /pool/lsf/pivarski/$dirname\_$pass\_$iter\_$job/
0382 cp $theConstraint\_catalog.xml /pool/lsf/pivarski/$dirname\_$pass\_$iter\_$job/
0383 date
0384 ";
0385         }
0386 
0387         print FILE "
0388 echo \"About to cd /pool/lsf/pivarski/$dirname\_$pass\_$iter\_$job\"
0389 cd /pool/lsf/pivarski/$dirname\_$pass\_$iter\_$job
0390 date
0391 
0392 echo \"About to pwd and ls\"
0393 pwd
0394 ls
0395 date
0396 
0397 echo \"About to cmsRun\"
0398 cmsRun $dirname\_$pass\_$iter\_$job.cfg  &&  echo DONE > DONE.txt
0399 date
0400 
0401 echo \"About to cp *.root *.txt $baseofall/$dirname/$pass/$iter/$job/\"
0402 cp *.root *.txt $baseofall/$dirname/$pass/$iter/$job/
0403 date
0404 
0405 echo \"About to cd $baseofall/$dirname/$pass/$iter/$job\"
0406 cd $baseofall/$dirname/$pass/$iter/$job
0407 date
0408 
0409 echo \"About to rm -rf /pool/lsf/pivarski/$dirname\_$pass\_$iter\_$job\"
0410 rm -rf /pool/lsf/pivarski/$dirname\_$pass\_$iter\_$job
0411 date
0412 ";
0413         close(FILE);
0414         system("chmod +x $dirname/$pass/$iter/$job/$dirname\_$pass\_$iter\_$job.sh");
0415     } # end loop over jobs
0416 
0417     open(FILE, "> $dirname/$pass/$iter/collect.cfg");
0418     print FILE "process collect = {
0419     source = EmptySource {}
0420     untracked PSet maxEvents = {untracked int32 input = 0}
0421     include \"$dirname/common.cff\"
0422 
0423     replace AlignmentProducer.algoConfig.collectorActive = true
0424     replace AlignmentProducer.algoConfig.collectorNJobs = 50
0425     replace AlignmentProducer.algoConfig.collectorPath = \"./\"
0426 
0427     replace AlignmentProducer.algoConfig.applyAPE = false
0428     replace AlignmentProducer.algoConfig.apeParam = {
0429     {
0430         PSet Selector = {vstring alignParams = {\"MuonDTChambers,111111\", \"MuonCSCChambers,111111\"}}
0431         string function = \"linear\"
0432         vdouble apeSPar = {0., 0., 10.}
0433         vdouble apeRPar = {0., 0., 10.}
0434     }
0435     }
0436 
0437     replace AlignmentProducer.ParameterBuilder.Selector = {
0438         vstring alignParams = $alignParams
0439         using MuonAlignmentStationSelector
0440     }
0441 
0442     replace AlignmentProducer.monitorConfig = {
0443         untracked vstring monitors = {}
0444     }
0445 
0446     replace PoolDBESSource.connect = \"sqlite_file:$last.db\"
0447     replace PoolDBESSource.catalog = \"xmlcatalog_file:$last.xml\"
0448 
0449     service = PoolDBOutputService {
0450         using CondDBCommon
0451         untracked uint32 authenticationMethod = 1
0452         VPSet toPut = {
0453             {
0454                 string record = \"DTAlignmentRcd\"
0455                 string tag = \"DTAlignmentRcd\"
0456             },
0457             {
0458                 string record = \"DTAlignmentErrorExtendedRcd\"
0459                 string tag = \"DTAlignmentErrorExtendedRcd\"
0460             },
0461             {
0462                 string record = \"CSCAlignmentRcd\"
0463                 string tag = \"CSCAlignmentRcd\"
0464             },
0465             {
0466                 string record = \"CSCAlignmentErrorExtendedRcd\"
0467                 string tag = \"CSCAlignmentErrorExtendedRcd\"
0468             }
0469         }
0470     }
0471     replace AlignmentProducer.saveToDB = true
0472     replace PoolDBOutputService.connect = \"sqlite_file:$dirname\_$pass\_$iter.db\"
0473     replace PoolDBOutputService.catalog = \"xmlcatalog_file:$dirname\_$pass\_$iter.xml\"
0474 
0475     path p = {recoMuon2recoTrack, TrackRefitter}
0476 }
0477 ";
0478     close(FILE);
0479     print RUNALL "cmsRun collect.cfg\n";
0480 
0481     open(FILE, "> $dirname/$pass/$iter/dbtoxml.cfg");
0482     print FILE "process dbtoxml = {
0483     source = EmptySource {}
0484     untracked PSet maxEvents = {untracked int32 input = 0}
0485     
0486     include \"Geometry/CMSCommonData/data/cmsIdealGeometryXML.cfi\"
0487     include \"Geometry/MuonNumbering/data/muonNumberingInitialization.cfi\"
0488     
0489     include \"CondCore/DBCommon/data/CondDBCommon.cfi\"
0490     es_source = PoolDBESSource {
0491     using CondDBCommon
0492     untracked uint32 authenticationMethod = 1
0493     VPSet toGet = {
0494         {
0495         string record = \"DTAlignmentRcd\"
0496         string tag = \"DTAlignmentRcd\"
0497         },
0498         {
0499         string record = \"DTAlignmentErrorExtendedRcd\"
0500         string tag = \"DTAlignmentErrorExtendedRcd\"
0501         },
0502         {
0503         string record = \"CSCAlignmentRcd\"
0504         string tag = \"CSCAlignmentRcd\"
0505         },
0506         {
0507         string record = \"CSCAlignmentErrorExtendedRcd\"
0508         string tag = \"CSCAlignmentErrorExtendedRcd\"
0509         }
0510     }
0511     }
0512     replace PoolDBESSource.connect = \"sqlite_file:$dirname\_$pass\_$iter.db\"
0513     replace PoolDBESSource.catalog = \"xmlcatalog_file:$dirname\_$pass\_$iter.xml\"
0514 
0515     module MuonGeometryDBConverter = MuonGeometryDBConverter {
0516     string input = \"db\"
0517     string dtLabel = \"\"
0518         string cscLabel = \"\"
0519         double shiftErr = 1000.
0520         double angleErr = 6.28
0521 
0522     string output = \"xml\"
0523         PSet outputXML = {
0524             string fileName = \"geom_$dirname\_$pass\_$iter.xml\"
0525         string relativeto = \"ideal\"
0526         bool survey = false
0527         bool rawIds = false
0528         bool eulerAngles = false
0529 
0530         untracked bool suppressDTBarrel = true
0531         untracked bool suppressDTWheels = true
0532         untracked bool suppressDTStations = true
0533         untracked bool suppressDTChambers = false
0534         untracked bool suppressDTSuperLayers = true
0535         untracked bool suppressDTLayers = true
0536         untracked bool suppressCSCEndcaps = true
0537         untracked bool suppressCSCStations = true
0538         untracked bool suppressCSCRings = true
0539         untracked bool suppressCSCChambers = false
0540         untracked bool suppressCSCLayers = true
0541         }
0542     }
0543 
0544     path p = {MuonGeometryDBConverter}
0545 }
0546 ";
0547     close(FILE);
0548     print RUNALL "cmsRun dbtoxml.cfg\n";
0549     print RUNALL "../../../Alignment/MuonAlignment/python/geometryXMLtoCSV.py < geom_$dirname\_$pass\_$iter.xml > geom_$dirname\_$pass\_$iter.csv\n";
0550 
0551     &collect_py($dirname, $pass, $iter);
0552     print RUNALL "python collect.py\n";
0553     print RUNALL "rm -f job*/$dirname\_$pass\_$iter.root\n\n";
0554 
0555     $last = "$dirname\_$pass\_$iter";
0556     $lastwhere = "$baseofall/$dirname/$pass/$iter/$last";
0557 
0558     } # end loop over iters
0559 } # end loop over passes
0560 
0561 close(RUNALL);
0562 system("chmod +x $dirname/runall.sh");
0563 
0564 ###############################################################################################
0565 
0566 sub common_cff($dirname) {
0567     open(FILE, "> $dirname/common.cff");
0568 
0569     print FILE "service = MessageLogger {
0570     untracked vstring destinations = {\"cout\"}
0571     untracked PSet cout = {
0572         untracked string threshold = \"ERROR\"
0573     }
0574 }
0575 
0576 include \"MagneticField/Engine/data/volumeBasedMagneticField.cfi\"
0577 include \"Geometry/CMSCommonData/data/cmsIdealGeometryXML.cfi\"
0578 include \"Geometry/CommonDetUnit/data/bareGlobalTrackingGeometry.cfi\"
0579 include \"Geometry/TrackerNumberingBuilder/data/trackerNumberingGeometry.cfi\"
0580 include \"Geometry/MuonNumbering/data/muonNumberingInitialization.cfi\"
0581 include \"Geometry/RPCGeometry/data/rpcGeometry.cfi\"
0582 include \"TrackingTools/TrackRefitter/data/TracksToTrajectories.cff\"
0583 include \"RecoTracker/TransientTrackingRecHit/data/TransientTrackingRecHitBuilderWithoutRefit.cfi\"
0584 include \"Geometry/TrackerGeometryBuilder/data/trackerGeometry.cfi\"
0585 include \"CondCore/DBCommon/data/CondDBCommon.cfi\"
0586 
0587 module recoMuon2recoTrack = AlignmentMuonSelector from \"Alignment/CommonAlignmentProducer/data/AlignmentMuonSelector.cfi\"
0588 replace recoMuon2recoTrack.src = $muonSourceLabel
0589 replace recoMuon2recoTrack.filter = false
0590 replace recoMuon2recoTrack.applyBasicCuts = false
0591 replace recoMuon2recoTrack.applyNHighestPt = false
0592 replace recoMuon2recoTrack.applyMultiplicityFilter = false
0593 replace recoMuon2recoTrack.applyMassPairFilter = false
0594 
0595 module TrackRefitter = TracksToTrajectories {
0596     InputTag Tracks = recoMuon2recoTrack:GlobalMuon
0597     PSet TrackTransformer = {
0598         string Fitter = \"KFFitterForRefitInsideOut\"
0599         string Smoother = \"KFSmootherForRefitInsideOut\"
0600         string Propagator = \"SmartPropagatorAnyOpposite\"
0601         string TrackerRecHitBuilder = \"WithoutRefit\"
0602         string MuonRecHitBuilder = \"MuonRecHitBuilder\"
0603         string RefitDirection = \"insideOut\"
0604         untracked bool RefitRPCHits = false
0605     }
0606 }
0607 
0608 include \"Alignment/CommonAlignmentProducer/data/AlignmentProducer.cff\"
0609 replace AlignmentProducer.doTracker = false
0610 replace AlignmentProducer.doMuon = true
0611 replace AlignmentProducer.tjTkAssociationMapTag = TrackRefitter
0612 replace AlignmentProducer.algoConfig.minimumNumberOfHits = 50 # optimized (min in 10k-event sample)
0613 replace AlignmentProducer.algoConfig.maxRelParameterError = 1e12
0614 replace AlignmentProducer.maxLoops = 1
0615 
0616 es_source = PoolDBESSource {
0617     using CondDBCommon
0618     untracked uint32 authenticationMethod = 1
0619     VPSet toGet = {
0620       {
0621           string record = \"DTAlignmentRcd\"
0622           string tag = \"DTAlignmentRcd\"
0623       },
0624       {
0625           string record = \"DTAlignmentErrorExtendedRcd\"
0626           string tag = \"DTAlignmentErrorExtendedRcd\"
0627       },
0628       {
0629           string record = \"CSCAlignmentRcd\"
0630           string tag = \"CSCAlignmentRcd\"
0631       },
0632       {
0633           string record = \"CSCAlignmentErrorExtendedRcd\"
0634           string tag = \"CSCAlignmentErrorExtendedRcd\"
0635       }
0636     }
0637 }
0638 replace AlignmentProducer.applyDbAlignment = true
0639 
0640 block MuonAlignmentStationSelector = {
0641     PSet mb1 = {
0642         vdouble rRanges   = {370., 470.}
0643         vdouble zRanges   = {-560., 560.}
0644         vdouble etaRanges = {} vdouble phiRanges = {} vdouble xRanges = {} vdouble yRanges = {}
0645     }
0646     PSet mb2 = {
0647         vdouble rRanges   = {470., 570.}
0648         vdouble zRanges   = {-560., 560.}
0649         vdouble etaRanges = {} vdouble phiRanges = {} vdouble xRanges = {} vdouble yRanges = {}
0650     }
0651     PSet mb3 = {
0652         vdouble rRanges   = {570., 670.}
0653         vdouble zRanges   = {-560., 560.}
0654         vdouble etaRanges = {} vdouble phiRanges = {} vdouble xRanges = {} vdouble yRanges = {}
0655     }
0656     PSet mb4 = {
0657         vdouble rRanges   = {670., 870.}
0658         vdouble zRanges   = {-560., 560.}
0659         vdouble etaRanges = {} vdouble phiRanges = {} vdouble xRanges = {} vdouble yRanges = {}
0660     }
0661     PSet me11 = {
0662         vdouble rRanges   = {50., 275.}
0663         vdouble zRanges   = {-700., -500., 500., 700.}
0664         vdouble etaRanges = {} vdouble phiRanges = {} vdouble xRanges = {} vdouble yRanges = {}
0665     }
0666     PSet me12 = {
0667         vdouble rRanges   = {275., 480.}
0668         vdouble zRanges   = {-750., -650., 650., 750.}
0669         vdouble etaRanges = {} vdouble phiRanges = {} vdouble xRanges = {} vdouble yRanges = {}
0670     }
0671     PSet me13 = {
0672         vdouble rRanges   = {480., 800.}
0673         vdouble zRanges   = {-750., -650., 650., 750.}
0674         vdouble etaRanges = {} vdouble phiRanges = {} vdouble xRanges = {} vdouble yRanges = {}
0675     }
0676     PSet me21 = {
0677         vdouble rRanges   = {50., 350.}
0678         vdouble zRanges   = {-875., -750., 750., 875.}
0679         vdouble etaRanges = {} vdouble phiRanges = {} vdouble xRanges = {} vdouble yRanges = {}
0680     }
0681     PSet me22 = {
0682         vdouble rRanges   = {350., 800.}
0683         vdouble zRanges   = {-875., -750., 750., 875.}
0684         vdouble etaRanges = {} vdouble phiRanges = {} vdouble xRanges = {} vdouble yRanges = {}
0685     }
0686     PSet me31 = {
0687         vdouble rRanges   = {50., 350.}
0688         vdouble zRanges   = {-980., -875., 875., 980.}
0689         vdouble etaRanges = {} vdouble phiRanges = {} vdouble xRanges = {} vdouble yRanges = {}
0690     }
0691     PSet me32 = {
0692         vdouble rRanges   = {350., 800.}
0693         vdouble zRanges   = {-980., -875., 875., 980.}
0694         vdouble etaRanges = {} vdouble phiRanges = {} vdouble xRanges = {} vdouble yRanges = {}
0695     }
0696     PSet me41 = {
0697         vdouble rRanges   = {50., 350.}
0698         vdouble zRanges   = {-1100., -980., 980., 1100.}
0699         vdouble etaRanges = {} vdouble phiRanges = {} vdouble xRanges = {} vdouble yRanges = {}
0700     }
0701 }
0702 ";
0703 
0704     close(FILE);
0705 }
0706 
0707 sub source_cff($dirname) {
0708     system("mkdir $dirname/sources");
0709 
0710     foreach $N (1..50) {
0711     open(FILE, sprintf("> $dirname/sources/job%d.cff", $N));
0712 
0713     printf FILE "source = PoolSource {
0714     untracked vstring fileNames = {
0715         \"$filetemplate\",
0716         \"$filetemplate\"
0717     }
0718 }
0719 untracked PSet maxEvents = {untracked int32 input = -1}
0720 ", ($N-1), ($N-1+50);
0721 
0722     close(FILE);
0723     } # end loop over N
0724 }
0725 
0726 sub collect_py($dirname, $pass, $iter) {
0727     open(FILE, "> $dirname/$pass/$iter/collect.py");
0728     print FILE "import Alignment.CommonAlignmentMonitor.muonHIP as muonHIP
0729 
0730 njobs = range(1, 50+1)
0731 
0732 merged_residual_hists = muonHIP.ROOT.TFile(\"$dirname\_$pass\_$iter.root\", \"recreate\")
0733 iter1dir = merged_residual_hists.mkdir(\"iter1\")
0734 wxresiddir = iter1dir.mkdir(\"wxresid_chamber\")
0735 wyresiddir = iter1dir.mkdir(\"wyresid_chamber\")
0736 
0737 wxresid = {}
0738 wyresid = {}
0739 for rawid in muonHIP.chambers.keys():
0740   wxresiddir.cd()
0741   wxresid[rawid] = muonHIP.ROOT.TH1F(\"wxresid_chamber_\%d\" \% rawid, \"wxresid_chamber_\%d\" \% rawid, 250, -5., 5.)
0742   if not muonHIP.chambers[rawid].barrel:
0743     wyresiddir.cd()
0744     wyresid[rawid] = muonHIP.ROOT.TH1F(\"wyresid_chamber_\%d\" \% rawid, \"wyresid_chamber_\%d\" \% rawid, 250, -5., 5.)
0745 
0746 tfile = {}
0747 for n in njobs:
0748   tfile[n] = muonHIP.ROOT.TFile(\"job\%d/$dirname\_$pass\_$iter.root\" \% n)
0749 
0750 for rawid in muonHIP.chambers.keys():
0751   tl = muonHIP.ROOT.TList()
0752   for t in tfile.values():
0753     thehist = tfile[n].Get(\"iter1/wxresid_chamber/wxresid_chamber_\%d\" \% rawid)
0754     tl.Add(thehist)
0755   wxresid[rawid].Merge(tl)
0756 
0757   if not muonHIP.chambers[rawid].barrel:
0758     tl = muonHIP.ROOT.TList()
0759     for t in tfile.values():
0760       thehist = tfile[n].Get(\"iter1/wyresid_chamber/wyresid_chamber_\%d\" \% rawid)
0761       tl.Add(thehist)
0762     wyresid[rawid].Merge(tl)
0763 
0764 merged_residual_hists.Write()
0765 merged_residual_hists.Close()
0766 ";
0767     close(FILE);
0768 }