source: JEM-EUSO/esaf_lal/branches/camille/camille_work/KIT_phase1_study/macros/Analysis.C @ 168

Last change on this file since 168 was 168, checked in by moretto, 11 years ago

macro d'analyse marche, suppression de tous les autres essais

File size: 5.4 KB
Line 
1//
2//  Analysis.C
3//
4//
5//  Created by moretto on 29/05/13.
6//
7//
8
9Int_t nb_entries = 0;
10
11const char* inputfile="/Users/moretto/Documents/thesis/ESAF/Code/esaf_lal/esaf/camille_work/KIT_phase1_study/30_ns_TimeResolution__100_event/simu.root";
12const char* inputfile2="/Users/moretto/Documents/thesis/ESAF/Code/esaf_lal/esaf/camille_work/KIT_phase1_study/10_ns_TimeResolution__100_event/simu.root";
13const char* inputfile3="/Users/moretto/Documents/thesis/ESAF/Code/esaf_lal/esaf/camille_work/KIT_phase1_study/5_ns_TimeResolution__100_event/simu.root";
14
15EEvent*          ev = 0;
16EDetector*       gDetector = NULL;
17EDetPhoton*      gDetPhoton = NULL;
18EBunchPhotons*   gBunchPhotons = NULL;
19
20void gettree();
21void init();
22void process_profile();
23Bool_t loadevent(Int_t i=0);
24
25//______________________________________________________________________________
26void Analysis()
27{
28    TProfile *hprof_multi[2];
29   
30    //Initialisation & process
31    init(inputfile);
32    process_profile();
33    hprof_multi[1] = hprof;
34   
35    init(inputfile3);
36    process_profile();
37    hprof_multi[2] = hprof;
38   
39    TCanvas *c4 = new TCanvas("c4", "Efficiency vs GTU");
40    TProfile *hprof_efficiency = new TProfile("hprof_efficiency", "Efficiency vs GTU", 128, 0, 128);
41   
42    for (Int_t i=1; i<128; i++)
43    {
44        Float_t bin1 = hprof_multi[1]->GetBinContent(i);
45        Float_t bin2 = hprof_multi[2]->GetBinContent(i);
46       
47        if (bin2 == 0)
48        {
49            hprof_efficiency->Fill(i, 0); //Il faut entrer des entiers dedans sinon ça ne marchera pas!!!!
50        }
51       
52        else
53        {
54            hprof_efficiency->Fill(i, bin1/bin2); //Il faut entrer des entiers dedans sinon ça ne marchera pas!!!!
55        }
56    }
57   
58    hprof_efficiency->Draw();
59}
60
61//______________________________________________________________________________
62void process_profile ()
63{
64    //Déclaration des histogrammes et autres
65    TH1F *histo_total = new TH1F("histo_total", "Histogram of photons read by the electronics for 100 showers", 128, 0, 128);
66    TH1F *histo_multi[100];
67    TProfile *hprof = new TProfile("hprof", "Average number of photons per GTU", 128, 0, 128);
68   
69    //Boucle sur l'ensemble des événements pour créer une distribution totale
70    for (Int_t  i=0; i<nb_entries ; i++)
71    {
72        loadevent(i);
73       
74        Int_t nb_photon = gDetector->GetNumPhotons();
75       
76        for (Int_t j=0; j<nb_photon; j++)
77        {
78            Int_t macrocell_status = gDetector->GetPhoton(j)->GetMacroCell();
79            Int_t photon_type = gDetector->GetPhoton(j)->GetType();
80           
81            if (macrocell_status == 1 & photon_type != 2) //on ne sélectionne que les photons étant détectés par l'électronique & autre que les Cerenkov
82            {
83                Float_t gtu = gDetector->GetPhoton(j)->GetGtu();
84                histo_total->Fill(gtu);
85            }
86           
87        }
88       
89    }
90
91    TCanvas *c1 = new TCanvas("c1", "Distribution totale");
92    histo_total->GetXaxis()->SetTitle("GTU");
93    histo_total->Draw();
94   
95    //Boucle sur l'ensemble des événements pour tracer séparément les histogrammes
96    TCanvas *c2 = new TCanvas("c2", "Collection of GTU histograms for 100 events");
97    c2->Divide(10,10);
98   
99    for (Int_t i=0; i<nb_entries; i++)
100        histo_multi[i] = new TH1F("histo_multi", "Single shower histograms", 128, 0, 128);
101   
102    for (Int_t  i=0; i<100 ; i++)
103    {
104        loadevent(i);
105       
106        nb_photon = gDetector->GetNumPhotons();
107       
108        for (Int_t j=0; j<nb_photon; j++)
109        {
110            macrocell_status = gDetector->GetPhoton(j)->GetMacroCell();
111            photon_type = gDetector->GetPhoton(j)->GetType();
112           
113            if (macrocell_status == 1 & photon_type != 2) //on ne sélectionne que les photons étant détectés par l'électronique & autre que les Cerenkov
114            {
115                gtu = gDetector->GetPhoton(j)->GetGtu();
116                histo_multi[i]->Fill(gtu);
117            }
118        }
119       
120        c2->cd(i+1);
121        histo_multi[i]->Draw();
122       
123    }
124   
125    //Boucle sur le tableau d'histogrammes précédent afin de réaliser un TProfile
126    for (Int_t j=0; j<nb_entries; j++)
127    {
128        for (Int_t i=1; i<=128; i++)
129        {
130            hprof->Fill(i, histo_multi[j]->GetBinContent(i));
131        }
132       
133    }
134   
135    TCanvas *c3 = new TCanvas("c3", "TProfile of the GTU distribution for 100 events");
136    hprof->Draw();
137
138}
139
140//______________________________________________________________________________
141void init( const char* fname)
142{
143    TFile *f = new TFile(fname);
144    gettree();
145}
146
147//______________________________________________________________________________
148void gettree()
149{
150    TTree *etree = (TTree*)gDirectory->Get("etree");
151    if ( etree )
152    {
153        nb_entries = etree->GetEntries();
154        Printf("etree found with %d events stored.", nb_entries);
155    }
156}
157
158//______________________________________________________________________________
159Bool_t loadevent( Int_t i)
160{
161    TTree *etree = (TTree*)gDirectory->Get("etree");
162   
163    if ( !etree )
164    {
165        Printf("init(): unable to retrieve etree from TFile. Exiting");
166        return kFALSE;
167    }
168   
169    // associate the tree and the event
170    if ( !ev )
171    {
172        ev = new EEvent();
173        ev->SetBranches(etree);
174    }
175   
176    etree->GetEntry(i);
177   
178    EDetector *detector = ev->GetDetector();
179   
180    gDetector = ev->GetDetector();
181   
182    return kTRUE;
183}
Note: See TracBrowser for help on using the repository browser.