]>
Commit | Line | Data |
---|---|---|
40164976 | 1 | // Script to create dead channel map and store them into CDB |
2 | // - 4 sets of maps parameters can be created, with now dead channels | |
3 | // and 5%, 10%, 20% and 30% of dead channels | |
4 | // - it reads the stored map in a given file. | |
5 | // Author: Gustavo Conesa | |
6 | ||
7 | //.x $ALICE_ROOT/EMCAL/macros/CalibrationDB/AliEMCALSetTowerStatusCDB.C | |
8 | ||
9 | #if !defined(__CINT__) | |
10 | #include <TControlBar.h> | |
11 | #include <TString.h> | |
12 | #include <TRandom.h> | |
13 | #include <TStyle.h> | |
14 | #include <TH2.h> | |
15 | #include <TF1.h> | |
16 | #include <TCanvas.h> | |
17 | ||
18 | #include "AliRun.h" | |
19 | #include "AliCaloCalibPedestal.h" | |
20 | #include "AliEMCALGeoParams.h" | |
21 | #include "AliCDBMetaData.h" | |
22 | #include "AliCDBId.h" | |
23 | #include "AliCDBEntry.h" | |
24 | #include "AliCDBManager.h" | |
25 | #include "AliCDBStorage.h" | |
26 | #endif | |
27 | ||
28 | ||
29 | void AliEMCALPedestalCDB() | |
30 | { | |
31 | TControlBar *menu = new TControlBar("vertical","EMCAL CDB"); | |
32 | menu->AddButton("Help to run EMCAL CDB","Help()", | |
33 | "Explains how to use EMCAL CDS menus"); | |
34 | menu->AddButton("Equal Tower Status Map, all Alive","SetTowerStatusMap(0)", | |
35 | "Set all channels to alive"); | |
36 | menu->AddButton("Create Random Status Map, 5% dead","SetTowerStatusMap(5)", | |
37 | "Set randomly 5% of the channels dead"); | |
38 | menu->AddButton("Create Random Status Map, 10% dead","SetTowerStatusMap(10)", | |
39 | "Set randomly 10% of the channels dead"); | |
40 | menu->AddButton("Create Random Status Map, 20% dead","SetTowerStatusMap(20)", | |
41 | "Set randomly 20% of the channels dead"); | |
42 | menu->AddButton("Create Random Status Map, 30% dead","SetTowerStatusMap(30)", | |
43 | "Set randomly 30% of the channels dead"); | |
1769b3d1 | 44 | menu->AddButton("Set Map from txt file","SetTowerStatusMap(\"map.txt\")", |
45 | "Read bad channels from txt file and set them in root file"); | |
40164976 | 46 | menu->AddButton("Read Tower Status Map","GetTowerStatusMap()", |
47 | "Read initial equal calibration coefficients"); | |
48 | menu->Show(); | |
49 | } | |
50 | ||
51 | //------------------------------------------------------------------------ | |
52 | void Help() | |
53 | { | |
54 | char *string = | |
55 | "\nSet tower status map (dead, hot, alive) and write them into ALICE CDB. Press button \"Equal kAlive\" to set all channels alive. Press button \"Random, 5% dead\" to create random dead channel map at 5%\n"; | |
56 | printf(string); | |
57 | } | |
58 | ||
59 | //------------------------------------------------------------------------ | |
60 | void SetTowerStatusMap(Int_t percent=0) | |
61 | { | |
62 | // Writing status of all the channels in the OCDB with equal value | |
63 | // except a percent to be not alive. Right now only "alive" or "dead", | |
64 | // we need to implement the other cases like "hot" | |
65 | ||
66 | TString sDBFolder ="local://PedestalsDB"; | |
67 | Int_t firstRun = 0; | |
68 | Int_t lastRun = 999999999; | |
69 | Int_t beamPeriod = 1; | |
1769b3d1 | 70 | char* objFormat = Form("%d percent of bad channels", percent); |
40164976 | 71 | |
72 | AliCaloCalibPedestal *caloped=new AliCaloCalibPedestal(AliCaloCalibPedestal::kEmCal); | |
73 | TObjArray map = caloped->GetDeadMap(); | |
74 | printf("MAP entries %d\n",map.GetEntries()); | |
75 | TRandom rn; | |
76 | //for(Int_t iSM = 0; iSM < AliEMCALGeoParams::fgkEMCALModules; iSM ++){ | |
77 | for(Int_t iSM = 0; iSM < map.GetEntries(); iSM ++){ | |
78 | Int_t ndead = 0; | |
79 | printf(" >>> SM %d <<< Entries %d, NbinsX %d, NbinsY %d\n",iSM,((TH2D*)map[iSM])->GetEntries(),((TH2D*)map[iSM])->GetNbinsX(),((TH2D*)map[iSM])->GetNbinsY()); | |
80 | for(Int_t i = 0; i < ((TH2D*)map[iSM])->GetNbinsX() ; i++){ | |
81 | for(Int_t j = 0; j < ((TH2D*)map[iSM])->GetNbinsY() ; j++){ | |
82 | //printf("Bin (%d-%d) Content, before: %d ",i,j,((TH2D*)map[iSM])->GetBinContent(i, j)); | |
83 | ||
84 | if(rn.Uniform(0,100) > percent) | |
85 | ((TH2D*)map[iSM])->SetBinContent(i, j, AliCaloCalibPedestal::kAlive); | |
86 | else{ | |
87 | ((TH2D*)map[iSM])->SetBinContent(i, j, AliCaloCalibPedestal::kDead); | |
88 | ndead++; | |
89 | } | |
90 | //printf("; after: %d \n",((TH2D*)map[iSM])->GetBinContent(i, j)); | |
91 | } | |
92 | } | |
93 | caloped->SetDeadTowerCount(caloped->GetDeadTowerCount()+ndead); | |
94 | printf("--- dead %d\n",ndead); | |
95 | } | |
96 | ||
97 | printf("--- total dead %d\n",caloped->GetDeadTowerCount()); | |
98 | ||
99 | caloped->SetDeadMap(map); | |
100 | ||
101 | //Store map into database | |
102 | ||
103 | AliCDBMetaData md; | |
104 | md.SetComment(objFormat); | |
105 | md.SetBeamPeriod(beamPeriod); | |
106 | md.SetResponsible("Gustavo Conesa"); | |
107 | ||
108 | AliCDBId id("EMCAL/Calib/Pedestals",firstRun,lastRun); // create in EMCAL/Calib/Pedestal sDBFolder | |
109 | ||
110 | AliCDBManager* man = AliCDBManager::Instance(); | |
111 | AliCDBStorage* loc = man->GetStorage(sDBFolder.Data()); | |
112 | loc->Put(caloped, id, &md); | |
113 | ||
114 | } | |
115 | ||
1769b3d1 | 116 | //____________________________________________ |
117 | ||
118 | ||
119 | ||
120 | ||
121 | //------------------------------------------------------------------------ | |
122 | void SetTowerStatusMap(char * file = "map.txt") | |
123 | { | |
124 | // Get the list of dead/hot channels from file and set them in OCDB | |
125 | ||
126 | TString sDBFolder ="local://PedestalsDB"; | |
127 | Int_t firstRun = 0; | |
128 | Int_t lastRun = 999999999; | |
129 | Int_t beamPeriod = 1; | |
130 | char* objFormat = Form("bad channels extracted from file %s", file); | |
131 | ||
132 | AliCaloCalibPedestal *caloped=new AliCaloCalibPedestal(AliCaloCalibPedestal::kEmCal); | |
133 | TObjArray map = caloped->GetDeadMap(); | |
134 | printf("MAP entries %d\n",map.GetEntries()); | |
135 | ||
136 | ||
137 | // Read parameter file line-by-line | |
138 | ifstream f; | |
139 | f.open(file); | |
140 | ||
141 | Int_t iSM=-1, icol=-1, irow=-1, istatus=-1, ndead=0 ; | |
142 | TString string; | |
143 | if (f.good()) { | |
144 | while(string.ReadLine(f, kFALSE) && !f.eof()) { | |
145 | ||
146 | sscanf(string.Data(), "%d %d %d %d",&iSM,&icol,&irow,&istatus); | |
147 | cout<<"SM= "<<iSM<<", col= "<<icol<<", row= "<<irow<<", status="<<istatus<<endl; | |
148 | if(iSM==-1) continue; | |
149 | ((TH2D*)map[iSM])->SetBinContent(icol, irow, istatus); | |
150 | ndead++; | |
151 | } | |
152 | } | |
153 | caloped->SetDeadTowerCount(ndead-2); | |
154 | printf("--- dead %d\n",ndead-2); | |
155 | ||
156 | printf("--- total dead %d\n",caloped->GetDeadTowerCount()); | |
157 | ||
158 | caloped->SetDeadMap(map); | |
159 | ||
160 | //Store map into database | |
161 | ||
162 | AliCDBMetaData md; | |
163 | md.SetComment(objFormat); | |
164 | md.SetBeamPeriod(beamPeriod); | |
165 | md.SetResponsible("Gustavo Conesa"); | |
166 | ||
167 | AliCDBId id("EMCAL/Calib/Pedestals",firstRun,lastRun); // create in EMCAL/Calib/Pedestal sDBFolder | |
168 | ||
169 | AliCDBManager* man = AliCDBManager::Instance(); | |
170 | AliCDBStorage* loc = man->GetStorage(sDBFolder.Data()); | |
171 | loc->Put(caloped, id, &md); | |
172 | ||
173 | } | |
174 | ||
175 | ||
40164976 | 176 | //------------------------------------------------------------------------ |
177 | void GetTowerStatusMap() | |
178 | { | |
179 | // Read status map | |
180 | ||
181 | TString sDBFolder ="local://PedestalsDB"; | |
182 | Int_t runNumber = 0; | |
183 | ||
184 | AliCaloCalibPedestal* caloped = (AliCaloCalibPedestal*) | |
185 | (AliCDBManager::Instance() | |
186 | ->GetStorage(sDBFolder.Data()) | |
187 | ->Get("EMCAL/Calib/Pedestals", | |
188 | runNumber)->GetObject()); | |
189 | ||
190 | cout<<endl; | |
191 | TObjArray map = caloped->GetDeadMap(); | |
192 | printf("MAP entries %d\n",map.GetEntries()); | |
193 | for(Int_t iSM = 0; iSM < map.GetEntries(); iSM ++){ | |
194 | TCanvas *cMap = new TCanvas(Form("cMap%d",iSM),Form("SM %d dead map",iSM), 12,12,400,400); | |
195 | cMap->Divide(1,1); | |
196 | Int_t ndead = 0; | |
197 | printf(" >>> SM %d <<< Entries %d, NbinsX %d, NbinsY %d\n",iSM,((TH2D*)map[iSM])->GetEntries(),((TH2D*)map[iSM])->GetNbinsX(),((TH2D*)map[iSM])->GetNbinsY()); | |
198 | for(Int_t i = 0; i < ((TH2D*)map[iSM])->GetNbinsX() ; i++){ | |
1769b3d1 | 199 | for(Int_t j = 0; j < ((TH2D*)map[iSM])->GetNbinsY() ; j++){ |
200 | if(((TH2D*)map[iSM])->GetBinContent(i, j)!=AliCaloCalibPedestal::kAlive) | |
201 | printf("Bin (%d-%d) Content: %d \n",i,j,((TH2D*)map[iSM])->GetBinContent(i, j)); | |
202 | ||
203 | if(((TH2D*)map[iSM])->GetBinContent(i, j)==AliCaloCalibPedestal::kDead || | |
204 | ((TH2D*)map[iSM])->GetBinContent(i, j)==AliCaloCalibPedestal::kHot) | |
205 | ndead++; | |
206 | } | |
40164976 | 207 | } |
208 | printf("--- dead %d\n",ndead); | |
209 | cMap->cd(iSM); | |
210 | (TH2D*)map[iSM])->Draw("lego2"); | |
1769b3d1 | 211 | } |
212 | ||
213 | printf("Total DEAD %d\n", caloped->GetDeadTowerCount()); | |
40164976 | 214 | |
40164976 | 215 | } |