following a suggestion from Gustavo - add extra/dummy/unity object at end of runnumbe...
[u/mrichter/AliRoot.git] / EMCAL / macros / OADB / CreateEMCAL_OADB_RunByRunTemperatureECalibCorrection.C
CommitLineData
f9155ba2 1// ******* Example to Create or Read OADB Container
2// ******* for EMCal Run by Run calibration dependent
3// ******* on Temperature variations
4// Author : Gustavo Conesa Balbastre (LPSC-Grenoble)
5
ca6c1a02 6// rescale some 2011 runs slightly (0.5%):
a04c9444 7const Float_t rescaleFactor = 1.005;
8//const Float_t rescaleFactor = 0.9975;
ca6c1a02 9const Int_t kFirst = 156620;
10const Int_t kLast = 162740;
11
f9155ba2 12void CreateEMCAL_OADB_RunByRunTemperatureECalibCorrection(Int_t opt = 1, Int_t runNumber = 170387)
13{
14 if(opt == 0) Read(runNumber);
15 if(opt == 1) Create();
16}
17
18void Create()
19{
20 //Create OADB container for Temperature calibration parameters
21
22 gSystem->Load("libOADB");
23
24 AliOADBContainer* con = new AliOADBContainer("AliEMCALRunDepTempCalibCorrections");
25
26 // Get the list of run numbers to be added to the OADB, parameters provided usually in a
27 // root file per run
28 // Tar ball with all the files can be found here
29 // https://twiki.cern.ch/twiki/bin/viewauth/ALICE/EMCalTimeDependentCalibrations
30
31 ifstream fList;
32 fList.open("CorrectionFiles/runlist.txt");
33
34 Int_t runNumber = 0;
a04c9444 35 Float_t multiplier = 10000; // allows us to store the values in TH1S with some precision
f9155ba2 36 TString string;
37 Int_t nRuns=0;
38 Int_t nSM = 12;
39
40 AliEMCALGeometry* geom = AliEMCALGeometry::GetInstance("EMCAL_COMPLETE12SMV1");
41
42 if (fList.good())
43 {
ca6c1a02 44
a04c9444 45 while( string.ReadLine(fList, kFALSE) )
f9155ba2 46 {
47 sscanf(string.Data(), "%d",&runNumber);
48
f9155ba2 49 if (runNumber < 140000) nSM = 4;
a04c9444 50 else if(runNumber < 200000) nSM = 10;
ca6c1a02 51
a04c9444 52 if(runNumber>100000){
53
54 multiplier = 10000; // allows us to store the values in TH1S with some precision
ca6c1a02 55 if (runNumber>=kFirst && runNumber<=kLast) { // rescale some runs
56 multiplier *= rescaleFactor;
57 }
ca6c1a02 58 printf("Run %d multiplier %5.0f\n", runNumber, multiplier);
a04c9444 59
60 // Access class that contains methods to read the content of
61 // the calibration file per run
62 AliEMCALCalibTimeDepCorrection *corr = new AliEMCALCalibTimeDepCorrection();
63 corr->ReadRootInfo(Form("CorrectionFiles/Run%d_Correction.root",runNumber));
64
f9155ba2 65 // Init the histogram
66 TH1S *h = new TH1S(Form("h%d",runNumber),"",24*48*nSM,0,24*48*nSM);
67
a04c9444 68 for(Int_t ism = 0; ism < nSM; ism++) {
69 for(Int_t icol = 0; icol < 48; icol++) {
70 for(Int_t irow = 0; irow < 24; irow++) {
71 Float_t recalFactor = corr->GetCorrection(ism, icol,irow,0);
f9155ba2 72 Int_t absID = geom->GetAbsCellIdFromCellIndexes(ism, irow, icol);
73
ca6c1a02 74 h->SetBinContent(absID,(Short_t)(recalFactor*multiplier));
f9155ba2 75 }
76 }
77 }
78
79 con->AddDefaultObject(h);
80
81 //Establishing run number with the correct objects
82 con->AppendObject(h,runNumber,runNumber);
83
84 delete corr;
85
86 nRuns++;
87 }
88 }
89 }
f9155ba2 90 fList.close();
f9155ba2 91 printf(" *** nRuns *** %d\n",nRuns);
a04c9444 92
93 // add dummy object at the end of file:
94 runNumber++;
95 multiplier = 10000;
96 // Init the histogram
97 printf("Dummy/extra Run %d at EOF multiplier %5.0f\n", runNumber, multiplier);
98 TH1S *h = new TH1S(Form("h%d",runNumber),"",24*48*nSM,0,24*48*nSM);
99
100 for(Int_t ism = 0; ism < nSM; ism++) {
101 for(Int_t icol = 0; icol < 48; icol++) {
102 for(Int_t irow = 0; irow < 24; irow++) {
103 Float_t recalFactor = 1;
104 Int_t absID = geom->GetAbsCellIdFromCellIndexes(ism, irow, icol);
105
106 h->SetBinContent(absID,(Short_t)(recalFactor*multiplier));
107 }
108 }
109 }
110
111 con->AddDefaultObject(h);
112 //Establishing run number with the correct objects
113 con->AppendObject(h,runNumber,runNumber);
f9155ba2 114
115 con->WriteToFile("EMCALTemperatureCorrCalib.root");
116
f9155ba2 117}
118
119void Read(Int_t runNumber = 170387)
120{
121
122 gSystem->Load("libOADB");
123
124 AliOADBContainer *cont=new AliOADBContainer("");
125 cont->InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALTemperatureCorrCalib.root", "AliEMCALRunDepTempCalibCorrections");
126
127 //cout<<"_________--------------- dump ---------------------___________"<<endl;
128 //cont->Dump();
129
130 //cout<<"cont->GetDefaultList()->Print()"<<endl;
131 //cont->GetDefaultList()->Print();
132
133 TH1S *h=cont->GetObject(runNumber); //GetObject(int runnumber)
134
ca6c1a02 135 if (h) {
136 printf("runNumber %d found\n", runNumber);
137 }
138 else {
139 printf("runNumber %d not found\n", runNumber);
140 // let's get the closest runnumber
141 Int_t lower = 0;
142 Int_t ic = 0;
143 Int_t maxEntry = cont->GetNumberOfEntries();
144
145 while ( (ic < maxEntry) && (cont->UpperLimit(ic) < runNumber) ) {
146 lower = ic;
147 ic++;
148 }
149
150 Int_t closest = lower;
151 if ( (ic<maxEntry) &&
152 (cont->LowerLimit(ic)-runNumber) < (runNumber - cont->UpperLimit(lower)) ) {
153 closest = ic;
154 }
155
156 cout << "found closest id " << closest
157 << " from run " << cont->LowerLimit(closest) << endl;
158 h = (TH1S*) cont->GetObjectByIndex(closest);
159 h->Print(); // tmp debug
160 cout << endl;
161 }
f9155ba2 162
ca6c1a02 163
f9155ba2 164 AliEMCALGeometry* geom = AliEMCALGeometry::GetInstance("EMCAL_COMPLETE12SMV1");
165
166 // Read parameter file line-by-line
167 // Get number of lines first
168
169 Int_t nSM = 10;
170
171 for(Int_t iabsID = 0; iabsID < 24*48*nSM; iabsID++)
172 {
173 printf("absID %d, content %d\n",iabsID,h->GetBinContent(iabsID));
174
175 }
176
177 h->Draw();
ca6c1a02 178
f9155ba2 179}
180
181