Changes between Version 22 and Version 23 of DatabaseBasedAnalysis/Examples


Ignore:
Timestamp:
08/16/18 20:33:20 (7 years ago)
Author:
tbretz
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DatabaseBasedAnalysis/Examples

    v22 v23  
    574574Note that this query can easily run 30min or more!
    575575
    576 == Optim Disp Plot1 ==
     576== Optim Disp (Leakage==0) ==
    577577
    578578{{{#!Spoiler
     
    716716
    717717[[Image(Result.png)]]
     718
     719== Optim Disp (Leakage>0) ==
     720
     721{{{#!Spoiler
     722{{{#!cpp
     723#include <iostream>
     724#include <iomanip>
     725
     726#include <TMath.h>
     727#include <TH2.h>
     728#include <TChain.h>
     729#include <TCanvas.h>
     730
     731void optimdisp3()
     732{
     733    // Create chain for the tree Result
     734    // This is just easier than using TFile/TTree
     735    TChain c("Result");
     736
     737    // Add the input file to the
     738    c.AddFile("simulation.root");
     739
     740    // Define variables for all leaves to be accessed
     741    // By definition rootifysql writes only doubles
     742    double FileId, EvtNumber, X, Y, MeanX, MeanY, Width, Length, CosDelta, SinDelta,
     743        M3Long, SlopeLong, Leakage1, SlopeSpreadWeighted, Size,
     744        ConcCore, ConcCOG, NumIslands, NumUsedPixels, Zd;
     745
     746    // Connect the variables to the cordesponding leaves
     747    c.SetBranchAddress("FileId", &FileId);
     748    c.SetBranchAddress("EvtNumber", &EvtNumber);
     749    c.SetBranchAddress("X", &X);
     750    c.SetBranchAddress("Y", &Y);
     751    c.SetBranchAddress("MeanX", &MeanX);
     752    c.SetBranchAddress("MeanY", &MeanY);
     753    c.SetBranchAddress("Width", &Width);
     754    c.SetBranchAddress("Length", &Length);
     755    c.SetBranchAddress("CosDelta", &CosDelta);
     756    c.SetBranchAddress("SinDelta", &SinDelta);
     757    c.SetBranchAddress("M3Long", &M3Long);
     758    c.SetBranchAddress("SlopeLong", &SlopeLong);
     759    c.SetBranchAddress("Leakage1", &Leakage1);
     760    c.SetBranchAddress("NumIslands", &NumIslands);
     761    c.SetBranchAddress("NumUsedPixels", &NumUsedPixels);
     762    //c.SetBranchAddress("SlopeSpreadWeighted", &SlopeSpreadWeighted);
     763    c.SetBranchAddress("Size", &Size);
     764    c.SetBranchAddress("Zd", &Zd);
     765    //c.SetBranchAddress("ConcCOG", &ConcCOG);
     766    //c.SetBranchAddress("ConcCore", &ConcCore);
     767
     768    // Set some constants (they could be included in the database
     769    // in the future)
     770    double mm2deg = +0.0117193246260285378;
     771    //double abberation = 1.02;
     772
     773    // -------------------- Source dependent parameter calculation -------------------
     774
     775    TH2F hist("", "",
     776              32, 0.800-0.0250, 2.400-0.0250,
     777              60, 3.000-0.0250, 6.000-0.0250);
     778
     779
     780    for (float l0=0.8; l0<2.4; l0+=0.05)
     781        for (float l1=3; l1<6; l1+=0.05)
     782        {
     783            int cnt_on = 0;
     784
     785            for (int i=0; i<c.GetEntries(); i++)
     786            {
     787                // read the i-th event from the file
     788                c.GetEntry(i);
     789
     790                // First calculate all cuts to speedup the analysis
     791                double area = TMath::Pi()*Width*Length;
     792
     793                // The abberation correction does increase also Width and Length by 1.02
     794
     795                bool cutq = NumIslands<3.5 && NumUsedPixels>5.5 && Leakage1>0;
     796                if (!cutq)
     797                    continue;
     798
     799                bool cut0 = area < log10(Size)*898-1535;
     800                if (!cut0)
     801                    continue;
     802
     803                int angle = 0;
     804
     805                // -------------------- Source dependent parameter calculation -------------------
     806
     807                double cr = cos(angle*TMath::DegToRad());
     808                double sr = sin(angle*TMath::DegToRad());
     809
     810                double px = cr*X-sr*Y;
     811                double py = cr*Y+sr*X;
     812
     813                double dx = MeanX - px*1.02;
     814                double dy = MeanY - py*1.02;
     815
     816                double norm = sqrt(dx*dx + dy*dy);
     817                double dist = norm*mm2deg;
     818
     819                double lx = min(max((CosDelta*dy - SinDelta*dx)/norm, -1.), 1.);
     820                double ly = min(max((CosDelta*dx + SinDelta*dy)/norm, -1.), 1.);
     821
     822                double alpha = asin(lx);
     823                double sgn   = TMath::Sign(1., ly);
     824
     825                // ------------------------------- Application ----------------------------------
     826
     827                double m3l   = M3Long*sgn*mm2deg;
     828                double slope = SlopeLong*sgn/mm2deg;
     829
     830                // --------------------------------- Analysis -----------------------------------
     831
     832                double xi = 1.36 + 0.085*slope + l0 *(1-1/(1+l1*Leakage1));
     833
     834                // Optim: 1.36 + 0.085
     835
     836                double sign1 = m3l+0.07;
     837                double sign2 = (dist-0.5)*7.2-slope;
     838
     839                double disp  = (sign1<0 || sign2<0 ? -xi : xi)*(1-Width/Length);
     840
     841                double thetasq = disp*disp + dist*dist - 2*disp*dist*sqrt(1-lx*lx);
     842
     843                if (thetasq<0.024)
     844                    cnt_on++;
     845            }
     846
     847            hist.Fill(l0, l1, cnt_on);
     848
     849            cout << l0 << " " << l1 << " " << cnt_on << endl;
     850        }
     851
     852    TCanvas *canv = new TCanvas;
     853    canv->SetTopMargin(0.01);
     854
     855    hist.SetStats(kFALSE);
     856    hist.SetContour(100);
     857    hist.SetXTitle("L_{0} / deg");
     858    hist.SetYTitle("L_{1} / deg");
     859    hist.GetYaxis()->SetTitleOffset(1.2);
     860    hist.DrawCopy("colz cont2");
     861
     862}
     863}}}
     864}}}
     865
     866Results in
     867
     868[[Image(Result2.png)]]
    718869
    719870== Energy Optimization ==