Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:41

0001 #!/bin/bash
0002 
0003 # The script accepts 4 command line parameters:
0004 # Example: Data2012/Beam
0005 export TkMapDir=$1
0006 # Example: MinimumBias
0007 export Dataset=$2
0008 
0009 homedir=`pwd`
0010 echo $homedir
0011 
0012 baseName=PCLBadComponents.log
0013 
0014 export workdir=/data/users/event_display/$TkMapDir
0015 
0016 if [[ !( -d $workdir ) ]]
0017 then
0018   echo "Directory $workdir does not exist!"
0019   echo "Exiting."
0020   exit 1
0021 fi
0022 
0023 # [Temporary] text file with summary data for each iteration step
0024 export outFileTK=./TrackerSummary.txt
0025 
0026 # File with output histograms
0027 export outRootFileTK=./TrackerSummary.root
0028 
0029 # File with prettier plots
0030 export outRootPlotsTK=./TrackerPlots.root
0031 
0032 # In order to make the for loop work properly, I insert underscores here, and transform them to spaces afterwards
0033 for partName0 in Tracker TIB TID TOB TEC TIB_Layer_1_ TIB_Layer_2_ TIB_Layer_3_ TIB_Layer_4_ TID+_Disk_1_ TID+_Disk_2_ TID+_Disk_3_ TID-_Disk_1_ TID-_Disk_2_ TID-_Disk_3_ TOB_Layer_1_ TOB_Layer_2_ TOB_Layer_3_ TOB_Layer_4_ TOB_Layer_5_ TOB_Layer_6_ TEC+_Disk_1_ TEC+_Disk_2_ TEC+_Disk_3_ TEC+_Disk_4_ TEC+_Disk_5_ TEC+_Disk_6_ TEC+_Disk_7_ TEC+_Disk_8_ TEC+_Disk_9_ TEC-_Disk_1_ TEC-_Disk_2_ TEC-_Disk_3_ TEC-_Disk_4_ TEC-_Disk_5_ TEC-_Disk_6_ TEC-_Disk_7_ TEC-_Disk_8_ TEC-_Disk_9_ ;
0034 #for partName0 in Tracker TIB TID TOB TEC ;
0035 
0036 do
0037   # Change underscores to spaces, and add a colon at the end
0038   partName=`echo $partName0 | sed s/_/\ /g | sed s/$/:/g`
0039   if [[ $partName0 == "Tracker" || $partName0 == "TIB" || $partName0 == "TID" || $partName0 == "TOB" || $partName0 == "TEC" ]] ;
0040   then
0041     subDetName=$partName0
0042     partType="All"
0043     partNumber=0
0044   else
0045     subDetName=`echo $partName | awk '{print $1}'`
0046     partType=`echo $partName | awk '{print $2}'`
0047     partNumber=`echo $partName | awk '{print $3}'`
0048   fi
0049   if [ -f $outFileTK ]; then rm -f $outFileTK; fi
0050   touch $outFileTK
0051   echo Processing subDetName $subDetName, partType $partType, partNumber $partNumber
0052  
0053   for fileName in `ls $workdir/*/*/$Dataset/$baseName` ;
0054   do
0055 #    echo $fileName
0056         # Extract run number from first row of file
0057         runNumber=`grep "New IOV" $fileName | awk '{print $6}'`
0058         line=`grep -A 10000 "Global Info" $fileName | grep -B 10000 Detid | grep "$partName" | awk -F ":" '{print $2}'`
0059 #       echo $line
0060 #       echo $runNumber
0061         nBadModulesTK=`echo $line | awk {'print $1'}`
0062         nAllBadFibersTK=`echo $line | awk '{print $2}'`
0063         nAllBadAPVsTK=`echo $line | awk '{print $3}'`
0064         let nBadAPVsFromFibersTK=$nAllBadFibersTK*2
0065         let nBadAPVsTK=$nAllBadAPVsTK-$nBadAPVsFromFibersTK
0066         nAllBadStripsTK=`echo $line | awk '{print $4}'`
0067         let nBadStripsFromAPVsTK=$nAllBadAPVsTK*128;
0068         let nBadStripsTK=$nAllBadStripsTK-$nBadStripsFromAPVsTK
0069         echo $runNumber $nBadModulesTK $nAllBadFibersTK $nAllBadAPVsTK $nBadStripsTK $nBadStripsFromAPVsTK $nAllBadStripsTK >> $outFileTK
0070   done
0071   if [[ -f tmp.txt ]] ;
0072   then
0073 #    echo "Temporary file tmp.txt exists! remove it and retry!"
0074 #    exit 1
0075     rm tmp.txt;
0076   fi
0077   # Remove last newline from file, otherwise the macro will read twice the last line
0078   cat $outFileTK | awk '{if(NR>1)print l;l=$0};END{if(NR>=1)printf("%s",l);}' > tmp.txt
0079   mv tmp.txt $outFileTK
0080   # Now we have the file with all the data for the given partName. Process it with the ROOT macro
0081   makeTKTrend $outFileTK $outRootFileTK $subDetName $partType $partNumber
0082   rm $outFileTK
0083 done
0084 
0085 # Run a macro that creates prettier plots
0086 if [[ -f $outRootFileTK ]] ;
0087 then
0088     if [ ! -d $workdir/Trends ]; then mkdir $workdir/Trends; fi
0089     if [ ! -d $workdir/Trends/$Dataset ]; then mkdir $workdir/Trends/$Dataset ; fi
0090     if [ ! -d $workdir/Trends/$Dataset/PCLBadComponents ]; then mkdir $workdir/Trends/$Dataset/PCLBadComponents ; fi
0091 
0092     RepositoryDir=$workdir/Trends/$Dataset/PCLBadComponents
0093 
0094     mv $outRootFileTK $RepositoryDir/.
0095     cd $RepositoryDir
0096     makePlots $outRootFileTK $outRootPlotsTK
0097 
0098     if [ ! -d $RepositoryDir/TIB ]; then mkdir $RepositoryDir/TIB ; fi
0099     for i in {1..4}; do
0100         for Plot in `ls *.png | grep TIBLayer$i`; do
0101             if [ ! -d $RepositoryDir/TIB/Layer$i ]; then mkdir $RepositoryDir/TIB/Layer$i ; fi
0102             mv $Plot $RepositoryDir/TIB/Layer$i;
0103         done
0104     done
0105     
0106     if [ ! -d $RepositoryDir/TOB ]; then mkdir $RepositoryDir/TOB ; fi
0107     for i in {1..6}; do
0108         for Plot in `ls *.png | grep TOBLayer$i`; do
0109             if [ ! -d $RepositoryDir/TOB/Layer$i ]; then mkdir $RepositoryDir/TOB/Layer$i ; fi
0110             mv $Plot $RepositoryDir/TOB/Layer$i;
0111         done
0112     done
0113     
0114     if [ ! -d $RepositoryDir/TID ]; then mkdir $RepositoryDir/TID ; fi
0115     if [ ! -d $RepositoryDir/TID/Side1 ]; then mkdir $RepositoryDir/TID/Side1 ; fi
0116     if [ ! -d $RepositoryDir/TID/Side2 ]; then mkdir $RepositoryDir/TID/Side2 ; fi
0117     for i in {1..3}; do
0118         for Plot in `ls *.png | grep TID-Disk$i`; do
0119             if [ ! -d $RepositoryDir/TID/Side1/Disk$i ]; then mkdir $RepositoryDir/TID/Side1/Disk$i ; fi
0120             mv $Plot $RepositoryDir/TID/Side1/Disk$i;
0121         done
0122         for Plot in `ls *.png | grep TID+Disk$i`; do
0123             if [ ! -d $RepositoryDir/TID/Side2/Disk$i ]; then mkdir $RepositoryDir/TID/Side2/Disk$i ; fi
0124             mv $Plot $RepositoryDir/TID/Side2/Disk$i;
0125         done
0126     done
0127     
0128     if [ ! -d $RepositoryDir/TEC ]; then mkdir $RepositoryDir/TEC ; fi
0129     if [ ! -d $RepositoryDir/TEC/Side1 ]; then mkdir $RepositoryDir/TEC/Side1 ; fi
0130     if [ ! -d $RepositoryDir/TEC/Side2 ]; then mkdir $RepositoryDir/TEC/Side2 ; fi
0131     for i in {1..9}; do
0132         for Plot in `ls *.png | grep TEC-Disk$i`; do
0133             if [ ! -d $RepositoryDir/TEC/Side1/Disk$i ]; then mkdir $RepositoryDir/TEC/Side1/Disk$i ; fi
0134             mv $Plot $RepositoryDir/TEC/Side1/Disk$i;
0135         done
0136         for Plot in `ls *.png | grep TEC+Disk$i`; do
0137             if [ ! -d $RepositoryDir/TEC/Side2/Disk$i ]; then mkdir $RepositoryDir/TEC/Side2/Disk$i ; fi
0138             mv $Plot $RepositoryDir/TEC/Side2/Disk$i;
0139         done
0140     done
0141     
0142     for Plot in `ls *.png | grep TIB`; do
0143         mv $Plot $RepositoryDir/TIB;
0144     done
0145     
0146     for Plot in `ls *.png | grep TOB`; do
0147         mv $Plot $RepositoryDir/TOB;
0148     done
0149     
0150     for Plot in `ls *.png | grep TID-`; do
0151         mv $Plot $RepositoryDir/TID/Side1;
0152     done
0153     
0154     for Plot in `ls *.png | grep TID+`; do
0155         mv $Plot $RepositoryDir/TID/Side2;
0156     done
0157     
0158     for Plot in `ls *.png | grep TEC-`; do
0159         mv $Plot $RepositoryDir/TEC/Side1;
0160     done
0161     
0162     for Plot in `ls *.png | grep TEC+`; do
0163         mv $Plot $RepositoryDir/TEC/Side2;
0164     done
0165     
0166 #    for Plot in `ls *.png | grep Tracker`; do
0167 #       mv $Plot $RepositoryDir;
0168 #    done
0169     
0170     cd $homedir
0171 fi