Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:46:01

0001 #include <TROOT.h>
0002 #include <TApplication.h>
0003 
0004 #include <sys/stat.h>
0005 
0006 #include "GeometryComparisonPlotter.cc" // TO DO: only include the header and provide the .o file
0007 
0008 ///////////////////////////////////////////////////////////////////////////////////////
0009 // README:                                                                           //
0010 ///////////////////////////////////////////////////////////////////////////////////////
0011 // This script is an example highly documented to present the production             //
0012 // of comparison plots between to geometries of the tracker.                         //
0013 // The main idea is to provide some input file and output destination                //
0014 // and to provide the couples to plot. Each combination gives rise to a single plot  //
0015 // and within a global output.                                                       //
0016 // Some options/cuts/specifications may be added.                                    //
0017 ///////////////////////////////////////////////////////////////////////////////////////
0018 // Any question can be asked to Patrick Connor at the address patrick.connor@desy.de //
0019 ///////////////////////////////////////////////////////////////////////////////////////
0020 
0021 int GeometryComparisonPlotter::canvas_index = 0;
0022 
0023 
0024 void comparisonScript (TString inFile,//="mp1510_vs_mp1509.Comparison_commonTracker.root",
0025                        TString outDir="outputDir/",
0026                        TString modulesToPlot="all",
0027                        TString alignmentName="Alignment",
0028                        TString referenceName="Ideal",
0029                        bool useDefaultRange= false,
0030                        bool plotOnlyGlobal= false,
0031                        bool plotPng= true,
0032                        bool makeProfilePlots= true,
0033                        float dx_min = -99999,
0034                        float dx_max = -99999,
0035                        float dy_min = -99999,
0036                        float dy_max = -99999,
0037                        float dz_min = -99999,
0038                        float dz_max = -99999,
0039                        float dr_min = -99999,
0040                        float dr_max = -99999,
0041                        float rdphi_min = -99999,
0042                        float rdphi_max = -99999,
0043                        float dalpha_min = -99999,
0044                        float dalpha_max = -99999,
0045                        float dbeta_min = -99999,
0046                        float dbeta_max = -99999,
0047                        float dgamma_min = -99999,
0048                        float dgamma_max = -99999
0049                        )
0050 {
0051     // the output directory is created if it does not exist
0052     mkdir(outDir, S_IRWXU);
0053     
0054     // store y-ranges temporaly for the case when the default range is used together with individual ranges
0055     float dx_min_temp = dx_min;
0056     float dx_max_temp = dx_max;
0057     float dy_min_temp = dy_min;
0058     float dy_max_temp = dy_max;
0059     float dz_min_temp = dz_min;
0060     float dz_max_temp = dz_max;
0061     float dr_min_temp = dr_min;
0062     float dr_max_temp = dr_max;
0063     float rdphi_min_temp = rdphi_min;
0064     float rdphi_max_temp = rdphi_max;
0065     float dalpha_min_temp = dalpha_min;
0066     float dalpha_max_temp = dalpha_max;
0067     float dbeta_min_temp = dbeta_min;
0068     float dbeta_max_temp = dbeta_max;
0069     float dgamma_min_temp = dgamma_min;
0070     float dgamma_max_temp = dgamma_max;
0071     
0072     if (useDefaultRange){
0073         dx_min = -200;
0074         dx_max = 200;
0075         dy_min = -200;
0076         dy_max = 200;
0077         dz_min = -200;
0078         dz_max = 200;
0079         dr_min = -200;
0080         dr_max = 200;
0081         rdphi_min = -200;
0082         rdphi_max = 200;
0083         
0084         dalpha_min = -100;
0085         dalpha_max = 100;
0086         dbeta_min = -100;
0087         dbeta_max = 100;
0088         dgamma_min = -100;
0089         dgamma_max = 100;
0090         
0091         // Overwrite single default values if individual ones are given
0092         if (dx_min_temp != -99999){dx_min = dx_min_temp;}
0093         if (dx_max_temp != -99999){dx_max = dx_max_temp;}
0094         if (dy_min_temp != -99999){dy_min = dy_min_temp;}
0095         if (dy_max_temp != -99999){dy_max = dy_max_temp;}
0096         if (dz_min_temp != -99999){dz_min = dz_min_temp;}
0097         if (dz_max_temp != -99999){dz_max = dz_max_temp;}
0098         if (dr_min_temp != -99999){dr_min = dr_min_temp;}
0099         if (dr_max_temp != -99999){dr_max = dr_max_temp;}
0100         if (rdphi_min_temp != -99999){rdphi_min = rdphi_min_temp;}
0101         if (rdphi_max_temp != -99999){rdphi_max = rdphi_max_temp;}
0102         
0103         if (dalpha_min_temp != -99999){dalpha_min = dalpha_min_temp;}
0104         if (dalpha_max_temp != -99999){dalpha_max = dalpha_max_temp;}
0105         if (dbeta_min_temp != -99999){dbeta_min = dbeta_min_temp;}
0106         if (dbeta_max_temp != -99999){dbeta_max = dbeta_max_temp;}
0107         if (dgamma_min_temp != -99999){dgamma_min = dgamma_min_temp;}
0108         if (dgamma_max_temp != -99999){dgamma_max = dgamma_max_temp;}
0109     }
0110     
0111     
0112     // display canvases: be careful, as there are many many ... canvases
0113 
0114     // the name of the variables are the names of the branches
0115     // REMARK: a supplementary branch for rdphi is calculated automatically
0116     //         from r and dphi
0117 
0118     // now the object to produce the comparison plots is created
0119     
0120     // Plot Translations
0121     GeometryComparisonPlotter * trans = new GeometryComparisonPlotter (inFile, outDir,modulesToPlot,alignmentName,referenceName,plotOnlyGlobal,makeProfilePlots);
0122     // x and y contain the couples to plot
0123     // -> every combination possible will be performed
0124     // /!\ always give units (otherwise, unexpected bug from root...)
0125     vector<TString> x,y, xmean;
0126     vector<float> dyMin,dyMax;
0127     x.push_back("r");                                               trans->SetBranchUnits("r",     "cm");
0128     x.push_back("phi");                                             trans->SetBranchUnits("phi",   "rad");
0129     x.push_back("z");                                               trans->SetBranchUnits("z",     "cm");      //trans->SetBranchMax("z", 100); trans->SetBranchMin("z", -100);
0130     y.push_back("dr");      trans->SetBranchSF("dr",    10000);     trans->SetBranchUnits("dr",    "#mum");
0131     dyMin.push_back(dr_min);
0132     dyMax.push_back(dr_max);
0133     y.push_back("dz");      trans->SetBranchSF("dz",    10000);     trans->SetBranchUnits("dz",    "#mum");
0134     dyMin.push_back(dz_min);
0135     dyMax.push_back(dz_max);
0136     y.push_back("rdphi");   trans->SetBranchSF("rdphi",10000);      trans->SetBranchUnits("rdphi", "#mum rad");
0137     dyMin.push_back(rdphi_min);
0138     dyMax.push_back(rdphi_max);
0139     y.push_back("dx");      trans->SetBranchSF("dx",    10000);     trans->SetBranchUnits("dx",    "#mum");    //trans->SetBranchMax("dx", 10); trans->SetBranchMin("dx", -10);
0140     dyMin.push_back(dx_min);
0141     dyMax.push_back(dx_max);
0142     y.push_back("dy");      trans->SetBranchSF("dy",    10000);     trans->SetBranchUnits("dy",    "#mum");    //trans->SetBranchMax("dy", 10); trans->SetBranchMin("dy", -10);
0143     dyMin.push_back(dy_min);
0144     dyMax.push_back(dy_max);
0145     
0146     xmean.push_back("x");                                           
0147     trans->SetBranchUnits("x",     "cm");
0148     xmean.push_back("y");                                               
0149     trans->SetBranchUnits("y",   "cm");
0150     xmean.push_back("z");                         
0151     xmean.push_back("r");                     
0152     
0153     
0154     trans->SetGrid(1,1);
0155     trans->MakePlots(x, y, dyMin, dyMax); // default output is pdf, but png gives a nicer result, so we use it as well
0156     // remark: what takes the more time is the creation of the output files,
0157     //         not the looping on the tree (because the code is perfect, of course :p)
0158     if (plotPng){
0159         trans->SetPrintOption("png");
0160         trans->MakePlots(x, y, dyMin, dyMax);
0161     }
0162     
0163     trans->MakeTables(xmean,y,dyMin,dyMax);
0164 
0165     
0166     // Plot Rotations
0167     GeometryComparisonPlotter * rot = new GeometryComparisonPlotter (inFile, outDir,modulesToPlot,alignmentName,referenceName,plotOnlyGlobal,makeProfilePlots);
0168     // x and y contain the couples to plot
0169     // -> every combination possible will be performed
0170     // /!\ always give units (otherwise, unexpected bug from root...)
0171     vector<TString> b;
0172     vector<float> dbMin,dbMax;
0173     //a.push_back("alpha");                                         rot->SetBranchUnits("alpha",    "rad");  
0174     //a.push_back("beta");                                          rot->SetBranchUnits("beta",   "rad");
0175     //a.push_back("gamma");                                         rot->SetBranchUnits("gamma",   "rad");
0176     rot->SetBranchUnits("r",     "cm");  
0177     rot->SetBranchUnits("phi",   "rad");
0178     rot->SetBranchUnits("z",     "cm"); 
0179     b.push_back("dalpha");  rot->SetBranchSF("dalpha",  1000);      rot->SetBranchUnits("dalpha",    "mrad");
0180     dbMin.push_back(dalpha_min);
0181     dbMax.push_back(dalpha_max);      
0182     b.push_back("dbeta");   rot->SetBranchSF("dbeta",   1000);      rot->SetBranchUnits("dbeta",    "mrad");
0183     dbMin.push_back(dbeta_min);
0184     dbMax.push_back(dbeta_max);     
0185     b.push_back("dgamma");  rot->SetBranchSF("dgamma",  1000);      rot->SetBranchUnits("dgamma",    "mrad");
0186     dbMin.push_back(dgamma_min);
0187     dbMax.push_back(dgamma_max);
0188  
0189     rot->SetGrid(1,1);
0190     rot->SetPrintOption("pdf");
0191     rot->MakePlots(x, b,dbMin, dbMax);
0192     if (plotPng){
0193         rot->SetPrintOption("png");
0194         rot->MakePlots(x, b,dbMin, dbMax);
0195     }   
0196     
0197 
0198     // now the same object can be reused with other specifications/cuts
0199     //void SetPrint               (const bool);           // activates the printing of the individual and global pdf
0200     //void SetLegend              (const bool);           // activates the legends
0201     //void SetWrite               (const bool);           // activates the writing into a Root file
0202     //void Set1dModule            (const bool);           // cut to include 1D modules
0203     //void Set2dModule            (const bool);           // cut to include 2D modules
0204     //void SetLevelCut            (const int);            // module level: level=1 (default)
0205     //void SetBatchMode           (const bool);           // activates the display of the canvases
0206     //void SetGrid                (const int,             // activates the display of the grids
0207     //                             const int);
0208     //void SetBranchMax           (const TString,         // sets a max value for the variable
0209     //                             const float);          // by giving the name and the value
0210     //void SetBranchMin           (const TString,         // sets a min value for the variable
0211     //                             const float);          // by giving the name and the value
0212     //void SetBranchSF            (const TString,         // sets a rescaling factor for the variable
0213     //                             const float);          // by giving the name and the value
0214     //void SetBranchUnits         (const TString,         // writes de units next on the axis
0215     //                             const TString);
0216     //void SetOutputDirectoryName (const TString);        // sets the output name of the directory
0217     //void SetOutputFileName      (const TString);        // sets the name of the root file (if applicable)
0218     //void SetPrintOption         (const Option_t *);     // litteraly the print option of the TPad::Print()
0219     //void SetCanvasSize          (const int window_width  = DEFAULT_WINDOW_WIDTH,
0220     //                             const int window_height = DEFAULT_WINDOW_HEIGHT);
0221 }
0222 
0223 // the following line is necessary for standalone applications
0224 // so in this case just run the makefile and the standalone executable with right arguments:
0225 // - root file containing the tree
0226 // - name of the output directory
0227 // otherwise, juste ignore this part of the code
0228 #ifndef __CINT__
0229 int main (int argc, char * argv[])
0230 {
0231     TApplication * app = new TApplication ("comparisonScript", &argc, argv);
0232     comparisonScript(app->Argv(1),
0233                      app->Argv(2));
0234     app->Run();
0235     // ask René Brun if you wonder why it is needed, I have no damned idea :p
0236 #ifndef DEBUG
0237     delete app;
0238 #endif
0239     return 0;
0240 }
0241 #endif