| 34 | |
| 35 | == Optimize Disp == |
| 36 | |
| 37 | The following root-macro (to be compiled!) |
| 38 | |
| 39 | {{{!cpp |
| 40 | #include <iostream> |
| 41 | #include <iomanip> |
| 42 | |
| 43 | #include <TMath.h> |
| 44 | #include <TH1.h> |
| 45 | #include <TH2.h> |
| 46 | #include <TProfile.h> |
| 47 | #include <TChain.h> |
| 48 | #include <TGraph.h> |
| 49 | #include <TCanvas.h> |
| 50 | #include <TStopwatch.h> |
| 51 | |
| 52 | void optimdisp() |
| 53 | { |
| 54 | // Create chain for the tree Result |
| 55 | // This is just easier than using TFile/TTree |
| 56 | TChain c("Result"); |
| 57 | |
| 58 | // Add the input file to the |
| 59 | c.AddFile("simulation.root"); |
| 60 | |
| 61 | // Define variables for all leaves to be accessed |
| 62 | // By definition rootifysql writes only doubles |
| 63 | double X, Y, MeanX, MeanY, Width, Length, CosDelta, SinDelta, M3Long, SlopeLong, |
| 64 | Leakage1, Size, ConcCore, ConcCOG, NumIslands, NumUsedPixels, Zd; |
| 65 | |
| 66 | // Connect the variables to the cordesponding leaves |
| 67 | c.SetBranchAddress("X", &X); |
| 68 | c.SetBranchAddress("Y", &Y); |
| 69 | c.SetBranchAddress("MeanX", &MeanX); |
| 70 | c.SetBranchAddress("MeanY", &MeanY); |
| 71 | c.SetBranchAddress("Width", &Width); |
| 72 | c.SetBranchAddress("Length", &Length); |
| 73 | c.SetBranchAddress("CosDelta", &CosDelta); |
| 74 | c.SetBranchAddress("SinDelta", &SinDelta); |
| 75 | c.SetBranchAddress("M3Long", &M3Long); |
| 76 | c.SetBranchAddress("SlopeLong", &SlopeLong); |
| 77 | c.SetBranchAddress("Leakage1", &Leakage1); |
| 78 | c.SetBranchAddress("NumIslands", &NumIslands); |
| 79 | c.SetBranchAddress("NumUsedPixels", &NumUsedPixels); |
| 80 | c.SetBranchAddress("Size", &Size); |
| 81 | c.SetBranchAddress("Zd", &Zd); |
| 82 | |
| 83 | // Set some constants (they could be included in the database |
| 84 | // in the future) |
| 85 | double mm2deg = +0.0117193246260285378; |
| 86 | |
| 87 | // -------------------- Source dependent parameter calculation ------------------- |
| 88 | |
| 89 | // Create a histogram for on- and off-data |
| 90 | TH1F hold("old", "", 100, 0, 1); |
| 91 | TH1F hnew("onew", "", 100, 0, 1); |
| 92 | |
| 93 | TH2F h2slope("H_VsSlope", "", 75, -8, 7, 100, -2.5, 1.5); |
| 94 | TProfile p2slope("P_VsSlope", "", 75, -8, 7); |
| 95 | TH2F h2leak( "H_VsLeakage", "", 75, 0, 0.15, 100, -2.5, 1.5); |
| 96 | TH2F h2m3l( "H_M3long", "", 75, -0.2, 0.6, 100, -2.5, 1.5); |
| 97 | TH2F h2zd( "H_Zd", "", 30, 30, 60, 100, -2.5, 1.5); |
| 98 | TH2F h2ni( "H_NumIsl", "", 10, 0.5, 10.5, 100, -2.5, 1.5); |
| 99 | TH2F h2np( "H_NumPix", "", 10, 0.5, 100.5, 100, -2.5, 1.5); |
| 100 | TH2F h2size( "H_Size", "", 30, 1.5, 4.5, 100, -2.5, 1.5); |
| 101 | |
| 102 | // Loop over all wobble positions in the camera |
| 103 | for (int i=0; i<c.GetEntries(); i++) |
| 104 | { |
| 105 | // read the i-th event from the file |
| 106 | c.GetEntry(i); |
| 107 | |
| 108 | // First calculate all cuts to speedup the analysis |
| 109 | double area = TMath::Pi()*Width*Length; |
| 110 | |
| 111 | bool cutq = NumIslands<3.5 && NumUsedPixels>5.5 && Leakage1<0.1; |
| 112 | if (!cutq) |
| 113 | continue; |
| 114 | |
| 115 | bool cut0 = area < log10(Size)*898-1535; |
| 116 | if (!cut0) |
| 117 | continue; |
| 118 | |
| 119 | // -------------------- Source dependent parameter calculation ------------------- |
| 120 | |
| 121 | int angle = 0; |
| 122 | |
| 123 | double cr = cos(angle*TMath::DegToRad()); |
| 124 | double sr = sin(angle*TMath::DegToRad()); |
| 125 | |
| 126 | double px = cr*X-sr*Y; |
| 127 | double py = cr*Y+sr*X; |
| 128 | |
| 129 | double dx = MeanX - px*1.022; |
| 130 | double dy = MeanY - py*1.022; |
| 131 | |
| 132 | double norm = sqrt(dx*dx + dy*dy); |
| 133 | double dist = norm*mm2deg; |
| 134 | |
| 135 | double lx = min(max((CosDelta*dy - SinDelta*dx)/norm, -1.), 1.); |
| 136 | double ly = min(max((CosDelta*dx + SinDelta*dy)/norm, -1.), 1.); |
| 137 | |
| 138 | double alpha = asin(lx); |
| 139 | double sgn = TMath::Sign(1., ly); |
| 140 | |
| 141 | // ------------------------------- Application ---------------------------------- |
| 142 | |
| 143 | double m3l = M3Long*sgn*mm2deg; |
| 144 | double slope = SlopeLong*sgn/mm2deg; |
| 145 | |
| 146 | // --------------------------------- Analysis ----------------------------------- |
| 147 | |
| 148 | //double xi = 1.34723 + 0.15214 *slope + 0.970704*(1-1/(1+8.89826*Leakage1)); |
| 149 | double xi_old = 1.39252 + 0.154247*slope + 1.67972 *(1-1/(1+4.86232*Leakage1)); |
| 150 | double xi_new = 1.340 + 0.0755 *slope + 1.67972 *(1-1/(1+4.86232*Leakage1)); |
| 151 | |
| 152 | double sign1 = m3l+0.07; |
| 153 | double sign2 = (dist-0.5)*7.2-slope; |
| 154 | |
| 155 | double disp_old = (sign1<0 || sign2<0 ? -xi_old : xi_old)*(1-Width/Length); |
| 156 | double disp_new = (sign1<0 || sign2<0 ? -xi_new : xi_new)*(1-Width/Length); |
| 157 | |
| 158 | double thetasq_old = disp_old*disp_old + dist*dist - 2*disp_old*dist*sqrt(1-lx*lx); |
| 159 | double thetasq_new = disp_new*disp_new + dist*dist - 2*disp_new*dist*sqrt(1-lx*lx); |
| 160 | |
| 161 | // Fill the on- and off-histograms |
| 162 | hold.Fill(thetasq_old); |
| 163 | hnew.Fill(thetasq_new); |
| 164 | |
| 165 | double residual = xi_new-dist/(1-Width/Length); |
| 166 | |
| 167 | h2slope.Fill(slope, residual); |
| 168 | p2slope.Fill(slope, residual); |
| 169 | |
| 170 | h2leak.Fill(Leakage1, residual); |
| 171 | h2m3l.Fill( m3l, residual); |
| 172 | h2zd.Fill( Zd, residual); |
| 173 | h2ni.Fill( NumIslands, residual); |
| 174 | h2np.Fill( NumUsedPixels, residual); |
| 175 | h2size.Fill(log10(Size), residual); |
| 176 | } |
| 177 | |
| 178 | cout << hnew.GetBinContent(1) << endl; |
| 179 | |
| 180 | clock.Print(); |
| 181 | |
| 182 | TCanvas *canv = new TCanvas; |
| 183 | canv->Divide(2,2); |
| 184 | |
| 185 | canv->cd(1); |
| 186 | gPad->SetGridy(); |
| 187 | h2slope.DrawCopy("colz"); |
| 188 | p2slope.DrawCopy("same"); |
| 189 | |
| 190 | canv->cd(2); |
| 191 | gPad->SetGridy(); |
| 192 | h2leak.DrawCopy("colz"); |
| 193 | |
| 194 | canv->cd(3); |
| 195 | gPad->SetGridy(); |
| 196 | //h2m3l.DrawCopy("colz"); |
| 197 | h2zd.DrawCopy("colz"); |
| 198 | //h2ni.DrawCopy("colz"); |
| 199 | //h2np.DrawCopy("colz"); |
| 200 | //h2size.DrawCopy("colz"); |
| 201 | |
| 202 | canv->cd(4); |
| 203 | // Plot the result |
| 204 | hold.SetLineColor(kRed); |
| 205 | hnew.SetMinimum(0); |
| 206 | hnew.DrawCopy(); |
| 207 | hold.DrawCopy("same"); |
| 208 | } |
| 209 | }}} |