ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/L1RpcTriggerAnalysis/macros/makePressureHumidityGraph.C
Revision: 1.1
Committed: Mon Aug 27 10:26:40 2012 UTC (12 years, 8 months ago) by cwiok
Content type: text/plain
Branch: MAIN
CVS Tags: Artur_11_07_2013_B, Artur_11_07_2013_A, Artur_11_07_2013, Artur_28_06_2013, Mikolaj_cmssw533, HEAD
Error occurred while calculating annotation data.
Log Message:
Updated scripts for making the plots

File Contents

# Content
1 #define makePressureHumidityGraph_cxx
2 #include "makePressureHumidityGraph.h"
3 #include <TH2.h>
4 #include <TStyle.h>
5 #include <TCanvas.h>
6 #include <TGraphErrors.h>
7 #include <iostream>
8 #include <fstream>
9 #include <string>
10 #include <cstdio>
11 #include <map>
12
13 void makePressureHumidityGraph::Loop()
14 {
15 // In a ROOT session, you can do:
16 // Root > .L makePressureHumidityGraph.C
17 // Root > makePressureHumidityGraph t
18 // Root > t.GetEntry(12); // Fill t data members with entry number 12
19 // Root > t.Show(); // Show values of entry 12
20 // Root > t.Show(16); // Read and show values of entry 16
21 // Root > t.Loop(); // Loop on all entries
22 //
23
24 // This is the loop skeleton where:
25 // jentry is the global entry number in the chain
26 // ientry is the entry number in the current Tree
27 // Note that the argument to GetEntry must be:
28 // jentry for TChain::GetEntry
29 // ientry for TTree::GetEntry and TBranch::GetEntry
30 //
31 // To read only selected branches, Insert statements like:
32 // METHOD1:
33 // fChain->SetBranchStatus("*",0); // disable all branches
34 // fChain->SetBranchStatus("branchname",1); // activate branchname
35 // METHOD2: replace line
36 // fChain->GetEntry(jentry); //read all branches
37 //by b_branchname->GetEntry(ientry); //read only this branch
38
39 if (fChain == 0) return;
40
41 Long64_t nentries = fChain->GetEntriesFast();
42 Long64_t nbytes = 0, nb = 0;
43
44 std::map<long /* run */, double /* sum or sum of squares */> pressure_sum, pressure_sum2, humidity_sum, humidity_sum2;
45 std::map<long /* run */, int> pressure_points, humidity_points;
46
47 for (Long64_t jentry=0; jentry<nentries;jentry++) {
48 Long64_t ientry = LoadTree(jentry);
49
50 if((long)RUNNUMBER>130094) {
51
52 if (VALUE > 100.0){
53
54 // pressure value [mbar]
55 if(pressure_points.find((long)RUNNUMBER) == pressure_points.end()) {
56 pressure_points[(long)RUNNUMBER]=0;
57 pressure_sum[(long)RUNNUMBER]=0.0;
58 pressure_sum2[(long)RUNNUMBER]=0.0;
59 }
60 pressure_points[(long)RUNNUMBER]++;
61 pressure_sum[(long)RUNNUMBER]+=VALUE;
62 pressure_sum2[(long)RUNNUMBER]+=VALUE*VALUE;
63
64 } else {
65 // relative humidity value [0-100%]
66 if(humidity_points.find((long)RUNNUMBER) == humidity_points.end()) {
67 humidity_points[(long)RUNNUMBER]=0;
68 humidity_sum[(long)RUNNUMBER]=0.0;
69 humidity_sum2[(long)RUNNUMBER]=0.0;
70 }
71 humidity_points[(long)RUNNUMBER]++;
72 humidity_sum[(long)RUNNUMBER]+=VALUE;
73 humidity_sum2[(long)RUNNUMBER]+=VALUE*VALUE;
74 }
75 }
76
77 if (ientry < 0) break;
78 nb = fChain->GetEntry(jentry); nbytes += nb;
79 // if (Cut(ientry) < 0) continue;
80 } // end of loop
81
82 // PRESSURE text and root files
83 TFile fpress(Form("%s.root",foutPressurePrefix),"RECREATE");
84 fpress.cd();
85 TGraphErrors *gpress = new TGraphErrors();
86 gpress->SetName("Graph");
87 gpress->SetTitle("Pressure vs run;Run;Pressure [mbar]");
88
89 std::ofstream ofpress;
90 ofpress.open(Form("%s.dat",foutPressurePrefix),std::ofstream::trunc); // overwrite existing file
91
92 if(!ofpress.good() || !fpress.IsOpen()) {
93 std::cerr << "Can't write to PRESSURE output file" << std::endl;
94 } else {
95 // calculate average and uncertainty
96 int ipoint=0;
97 for(std::map<long,int>::const_iterator it=pressure_points.begin();it!=pressure_points.end();it++) {
98 double pave = pressure_sum[it->first]/pressure_points[it->first];
99 double perr = pressure_accuracy/sqrt(3.);
100 if(pressure_points[it->first]>1) {
101 perr = sqrt( perr*perr +
102 (pressure_sum2[it->first]/pressure_points[it->first]-pave*pave)/(pressure_points[it->first]-1) );
103 }
104 ofpress << Form("%-6ld %-8.3lf %-8.3lf", (long)it->first /* run */, pave, perr) << std::endl;
105 gpress->SetPoint(ipoint, 1.0*it->first, pave);
106 gpress->SetPointError(ipoint, 0.0, perr);
107 ipoint++;
108 }
109 }
110 ofpress.close();
111 gpress->Write();
112 fpress.Close();
113
114 // HUMIDITY text and root files
115 TFile fhum(Form("%s.root",foutHumidityPrefix),"RECREATE");
116 fhum.cd();
117 TGraphErrors *ghum = new TGraphErrors();
118 ghum->SetName("Graph");
119 ghum->SetTitle("Relative humidity vs run;Run;Relative humidity [%]");
120
121 std::ofstream ofhum;
122 ofhum.open(Form("%s.dat",foutHumidityPrefix),std::ofstream::trunc); // overwrite existing file
123
124 if(!ofhum.good() || !fhum.IsOpen()) {
125 std::cerr << "Can't write to HUMIDITY output file" << std::endl;
126 } else {
127 // calculate average and uncertainty
128 int ipoint=0;
129 for(std::map<long,int>::const_iterator it=humidity_points.begin();it!=humidity_points.end();it++) {
130 double have = humidity_sum[it->first]/humidity_points[it->first];
131 double herr = humidity_accuracy/sqrt(3.);
132 if(humidity_points[it->first]>1) {
133 herr = sqrt( herr*herr +
134 (humidity_sum2[it->first]/humidity_points[it->first]-have*have)/(humidity_points[it->first]-1) );
135 }
136 ofhum << Form("%-6ld %-8.3lf %-8.3lf", (long)it->first /* run */, have, herr) << std::endl;
137 ghum->SetPoint(ipoint, 1.0*it->first, have);
138 ghum->SetPointError(ipoint, 0.0, herr);
139 ipoint++;
140 }
141 }
142 ofhum.close();
143 ghum->Write();
144 fhum.Close();
145
146 }
147