]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/readSSDOCDBEntry.C
Fix for DA's
[u/mrichter/AliRoot.git] / ITS / readSSDOCDBEntry.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include "TString.h"
3 #include "TH1.h"
4 #include "TH2.h"
5 #include "TFile.h"
6 #include "TObjArray.h"
7 #include "TObject.h"
8 #include "TCanvas.h"
9 #include "TStyle.h"
10 #include "Riostream.h"
11
12 #include "AliITSgeomTGeo.h"
13 #include "AliITSGainSSDv2.h"
14 #include "AliITSBadChannelsSSDv2.h"
15 #include "AliITSNoiseSSDv2.h"
16 #include "AliITSPedestalSSDv2.h"
17 #include "AliITSGainSSD.h"
18 #include "AliITSBadChannelsSSD.h"
19 #include "AliITSNoiseSSD.h"
20 #include "AliITSPedestalSSD.h"
21 #include "AliCDBManager.h"
22 #include "AliCDBEntry.h"
23 #endif
24
25 /*  $Id$    */
26
27
28
29 //====================================================================//
30 void Noise(AliCDBManager * man);
31 void Pedestal(AliCDBManager * man);
32 void BadChannelMap(AliCDBManager * man);
33 void GainCalibration(AliCDBManager * man);
34 void ReadOldSSDPedestal(TObjArray *array, AliITSPedestalSSDv2 *pedestalSSD);
35 void ReadOldSSDNoise(TObjArray *array, AliITSNoiseSSDv2 *noiseSSD);
36 void ReadOldSSDBadChannels(TObjArray *array, AliITSBadChannelsSSDv2 *badChannelsSSD);
37 void ReadOldSSDGain(TObjArray *array, AliITSGainSSDv2 *gainSSD);
38 void drawNoiseDistributions(Int_t runNumber);
39 void drawPedestalDistributions(Int_t runNumber);
40 //====================================================================//
41
42 //_____________________________________________________________________//
43 void readSSDOCDBEntry(const char* type = "alien", Int_t runNumber = 0) {
44   //This macro allows to visualize the bad channels in the OCDB
45   //The type can be either "local" or "alien" (where the OCDB file comes from)
46   //The run nmber is the pedestal one
47   gStyle->SetPalette(1,0);
48   TString gType = type;
49   
50   AliCDBManager * man = AliCDBManager::Instance();
51   
52   if(gType == "alien") {
53     //man->SetDefaultStorage("alien://folder=/alice/data/2009/Reference/");
54     man->SetDefaultStorage("alien://folder=/alice/data/2009/OCDB/");
55   }
56   else if(gType == "local") 
57     man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
58   else {
59     cout<<"Allowed types: local or alien!!!"<<endl;
60     abort();
61   }
62   
63   man->SetRun(runNumber);
64     
65   //Pedestal(man);
66   Noise(man);
67   BadChannelMap(man);
68   GainCalibration(man);
69 }
70
71 //_____________________________________________________________________//
72 void drawNoiseDistributions(Int_t runNumber) {
73   //Draws the noise distributions for each side and layer
74   TString filename = "noiseDistributionsSSD."; filename += runNumber;
75   filename += ".root";
76   TFile *f = TFile::Open(filename.Data());
77   TH1F *gHistNoisePSideLayer5 = dynamic_cast<TH1F *>(f->Get("gHistNoisePSideLayer5"));
78   TH1F *gHistNoiseNSideLayer5 = dynamic_cast<TH1F *>(f->Get("gHistNoiseNSideLayer5"));
79   TH1F *gHistNoisePSideLayer6 = dynamic_cast<TH1F *>(f->Get("gHistNoisePSideLayer6"));
80   TH1F *gHistNoiseNSideLayer6 = dynamic_cast<TH1F *>(f->Get("gHistNoiseNSideLayer6"));
81
82   TCanvas *c1 = new TCanvas("c1","Noise distribution (P-side, Layer 5)",
83                             0,0,400,400);
84   c1->SetFillColor(10); c1->SetHighLightColor(10); c1->SetLogy();
85   gHistNoisePSideLayer5->SetStats(kFALSE); gHistNoisePSideLayer5->Draw();
86
87   TCanvas *c2 = new TCanvas("c2","Noise distribution (N-side, Layer 5)",
88                             400,0,400,400);
89   c2->SetFillColor(10); c2->SetHighLightColor(10); c2->SetLogy();
90   gHistNoiseNSideLayer5->SetStats(kFALSE); gHistNoiseNSideLayer5->Draw();
91
92   TCanvas *c3 = new TCanvas("c3","Noise distribution (P-side, Layer 6)",
93                             0,400,400,400);
94   c3->SetFillColor(10); c3->SetHighLightColor(10); c3->SetLogy();
95   gHistNoisePSideLayer6->SetStats(kFALSE); gHistNoisePSideLayer6->Draw();
96
97   TCanvas *c4 = new TCanvas("c4","Noise distribution (N-side, Layer 6)",
98                             400,400,400,400);
99   c4->SetFillColor(10); c4->SetHighLightColor(10); c4->SetLogy();
100   gHistNoiseNSideLayer6->SetStats(kFALSE); gHistNoiseNSideLayer6->Draw();
101 }
102
103 //_____________________________________________________________________//
104 void drawPedestalDistributions(Int_t runNumber) {
105   //Draws the pedestal distributions for each side and layer
106   TString filename = "pedestalDistributionsSSD."; filename += runNumber;
107   filename += ".root";
108   TFile *f = TFile::Open(filename.Data());
109   TH1F *gHistPedestalPSideLayer5 = dynamic_cast<TH1F *>(f->Get("gHistPedestalPSideLayer5"));
110   TH1F *gHistPedestalNSideLayer5 = dynamic_cast<TH1F *>(f->Get("gHistPedestalNSideLayer5"));
111   TH1F *gHistPedestalPSideLayer6 = dynamic_cast<TH1F *>(f->Get("gHistPedestalPSideLayer6"));
112   TH1F *gHistPedestalNSideLayer6 = dynamic_cast<TH1F *>(f->Get("gHistPedestalNSideLayer6"));
113
114   TCanvas *c1 = new TCanvas("c1","Pedestal distribution (P-side, Layer 5)",
115                             0,0,400,400);
116   c1->SetFillColor(10); c1->SetHighLightColor(10); c1->SetLogy();
117   gHistPedestalPSideLayer5->SetStats(kFALSE); gHistPedestalPSideLayer5->Draw();
118   
119   TCanvas *c2 = new TCanvas("c2","Pedestal distribution (N-side, Layer 5)",
120                             400,0,400,400);
121   c2->SetFillColor(10); c2->SetHighLightColor(10); c2->SetLogy();
122   gHistPedestalNSideLayer5->SetStats(kFALSE); gHistPedestalNSideLayer5->Draw();
123   
124   TCanvas *c3 = new TCanvas("c3","Pedestal distribution (P-side, Layer 6)",
125                             0,400,400,400);
126   c3->SetFillColor(10); c3->SetHighLightColor(10); c3->SetLogy();
127   gHistPedestalPSideLayer6->SetStats(kFALSE); gHistPedestalPSideLayer6->Draw();
128   
129   TCanvas *c4 = new TCanvas("c4","Pedestal distribution (N-side, Layer 6)",
130                             400,400,400,400);
131   c4->SetFillColor(10); c4->SetHighLightColor(10); c4->SetLogy();
132   gHistPedestalNSideLayer6->SetStats(kFALSE); gHistPedestalNSideLayer6->Draw();
133 }
134
135 //_____________________________________________________________________//
136 void Pedestal(AliCDBManager * man) {
137   //Reads the noise OCDB file
138   const Int_t fgkSSDMODULES = 1698;
139   const Int_t fgkSSDSTRIPSPERMODULE = 1536;
140   static const Int_t fgkDefaultNStripsSSD = 768;
141
142   Int_t runNumber = man->GetRun();
143
144   //pedestal histograms
145   TH1F *gHistPedestalPSideLayer5 = new TH1F("gHistPedestalPSideLayer5",
146                                             "Pedestal values (P-side, Layer5); ADC counts; Entries;",
147                                             1000,-100,100);
148   TH1F *gHistPedestalNSideLayer5 = new TH1F("gHistPedestalNSideLayer5",
149                                             "Pedestal values (N-side, Layer5); ADC counts; Entries;",
150                                             1000,-100,100);
151   TH1F *gHistPedestalPSideLayer6 = new TH1F("gHistPedestalPSideLayer6",
152                                             "Pedestal values (P-side, Layer6); ADC counts; Entries;",
153                                             1000,-100,100);
154   TH1F *gHistPedestalNSideLayer6 = new TH1F("gHistPedestalNSideLayer6",
155                                             "Pedestal values (N-side, Layer6); ADC counts; Entries;",
156                                             1000,-100,100);
157
158   Int_t fLayer = 0,fLadder = 0, fModule = 0;
159   
160   AliITSPedestalSSDv2 *pedestalSSD = new AliITSPedestalSSDv2();
161   AliCDBEntry *entryPedestalSSD = man->Get("ITS/Ref/PedestalSSD");
162   TObject *empty = (TObject *)entryPedestalSSD->GetObject();
163   TString objectname = empty->GetName();
164   if(objectname=="TObjArray") {
165     TObjArray *pedestalSSDOld = (TObjArray *)entryPedestalSSD->GetObject();
166     ReadOldSSDPedestal(pedestalSSDOld, pedestalSSD);
167   }
168   else if(objectname=="AliITSPedestalSSDv2") {
169     cout<<"Reading the new format of the calibration file..."<<endl;
170     pedestalSSD = (AliITSPedestalSSDv2 *)entryPedestalSSD->GetObject();
171   }
172
173   Double_t pedestal = 0.0;
174   for (Int_t i = 0; i < fgkSSDMODULES; i++) {
175     AliITSgeomTGeo::GetModuleId(i+500,fLayer,fLadder,fModule);      
176     //cout<<"Pedestal for module: "<<i+500<<" - Layer: "<<fLayer<<endl;
177     for(Int_t j = 0; j < fgkDefaultNStripsSSD; j++) {
178       pedestal = pedestalSSD->GetPedestalP(i,j);
179       //Printf("Pedestal value: %lf",pedestal);
180       if(fLayer == 5) 
181         gHistPedestalPSideLayer5->Fill(pedestal);
182       if(fLayer == 6) 
183         gHistPedestalPSideLayer6->Fill(pedestal);
184       
185       pedestal = pedestalSSD->GetPedestalN(i,j);
186       if(fLayer == 5) 
187         gHistPedestalNSideLayer5->Fill(pedestal);
188       if(fLayer == 6) 
189         gHistPedestalNSideLayer6->Fill(pedestal);
190     }//loop over strips
191   }//loop over modules
192
193   TString output = "pedestalDistributionsSSD."; output += runNumber; 
194   output += ".root";
195   TFile *f = TFile::Open(output.Data(),"recreate");
196   gHistPedestalPSideLayer5->Write();
197   gHistPedestalNSideLayer5->Write();
198   gHistPedestalPSideLayer6->Write();
199   gHistPedestalNSideLayer6->Write();
200   f->Close();
201 }
202
203 //_____________________________________________________________________//
204 void Noise(AliCDBManager * man) {
205   //Reads the noise OCDB file
206   const Int_t fgkSSDMODULES = 1698;
207   const Int_t fgkSSDSTRIPSPERMODULE = 1536;
208   static const Int_t fgkDefaultNStripsSSD = 768;
209
210   Int_t runNumber = man->GetRun();
211
212   //noise histograms
213   TH1F *gHistNoisePSideLayer5 = new TH1F("gHistNoisePSideLayer5",
214                                          "Noise values (P-side, Layer5); ADC counts; Entries;",
215                                          1000,0,1000);
216   TH1F *gHistNoiseNSideLayer5 = new TH1F("gHistNoiseNSideLayer5",
217                                          "Noise values (N-side, Layer5); ADC counts; Entries;",
218                                          1000,0,1000);
219   TH1F *gHistNoisePSideLayer6 = new TH1F("gHistNoisePSideLayer6",
220                                          "Noise values (P-side, Layer6); ADC counts; Entries;",
221                                          1000,0,1000);
222   TH1F *gHistNoiseNSideLayer6 = new TH1F("gHistNoiseNSideLayer6",
223                                          "Noise values (N-side, Layer6); ADC counts; Entries;",
224                                          1000,0,1000);
225
226   Int_t fLayer = 0,fLadder = 0, fModule = 0;
227   Int_t fHistCounter = 0;
228   TString fTitle;
229   TObjArray *array = new TObjArray();
230   TH1D *hNoiseModule[fgkSSDMODULES];   
231   for(Int_t i = 500; i < fgkSSDMODULES + 500; i++) {
232     AliITSgeomTGeo::GetModuleId(i,fLayer,fLadder,fModule);
233     fTitle = "SSD_Noise_Layer"; fTitle += fLayer;
234     fTitle += "_Ladder"; fTitle += fLadder;
235     fTitle += "_Module"; fTitle += fModule;
236     
237     hNoiseModule[fHistCounter] = new TH1D(fTitle.Data(),fTitle.Data(),1540,0,1540);
238     hNoiseModule[fHistCounter]->GetXaxis()->SetTitleColor(1);
239     hNoiseModule[fHistCounter]->GetXaxis()->SetTitle("Strip number");
240     hNoiseModule[fHistCounter]->GetYaxis()->SetTitle("Noise");
241     array->AddLast(hNoiseModule[fHistCounter]);
242     fHistCounter += 1;
243   }
244   
245   AliITSNoiseSSDv2 *noiseSSD = new AliITSNoiseSSDv2();
246   AliCDBEntry *entryNoiseSSD = man->Get("ITS/Calib/NoiseSSD");
247   TObject *empty = (TObject *)entryNoiseSSD->GetObject();
248   TString objectname = empty->GetName();
249   if(objectname=="TObjArray") {
250     TObjArray *noiseSSDOld = (TObjArray *)entryNoiseSSD->GetObject();
251     ReadOldSSDNoise(noiseSSDOld, noiseSSD);
252   }
253   else if(objectname=="AliITSNoiseSSDv2") {
254     cout<<"Reading the new format of the calibration file..."<<endl;
255     noiseSSD = (AliITSNoiseSSDv2 *)entryNoiseSSD->GetObject();
256   }
257   
258   Double_t noise = 0.0;
259   for (Int_t i = 0; i < fgkSSDMODULES; i++) {
260     AliITSgeomTGeo::GetModuleId(i+500,fLayer,fLadder,fModule);      
261     //cout<<"Noise for module: "<<i+500<<" - Layer: "<<fLayer<<endl;
262     for(Int_t j = 0; j < fgkDefaultNStripsSSD; j++) {
263       noise = noiseSSD->GetNoiseP(i,j);
264       hNoiseModule[i]->SetBinContent(j+1,noise);
265       if(fLayer == 5) 
266         gHistNoisePSideLayer5->Fill(noise);
267       if(fLayer == 6) 
268         gHistNoisePSideLayer6->Fill(noise);
269       
270       noise = noiseSSD->GetNoiseN(i,j);
271       hNoiseModule[i]->SetBinContent(fgkSSDSTRIPSPERMODULE-j,noise);
272       if(fLayer == 5) 
273         gHistNoiseNSideLayer5->Fill(noise);
274       if(fLayer == 6) 
275         gHistNoiseNSideLayer6->Fill(noise);
276     }//loop over strips
277   }//loop over modules
278   
279   TString output1 = "noiseSSD."; output1 += runNumber; output1 += ".root";
280   TFile *f1 = TFile::Open(output1.Data(),"recreate");
281   array->Write();
282   f1->Close();
283
284   TString output2 = "noiseDistributionsSSD."; output2 += runNumber; 
285   output2 += ".root";
286   TFile *f2 = TFile::Open(output2.Data(),"recreate");
287   gHistNoisePSideLayer5->Write();
288   gHistNoiseNSideLayer5->Write();
289   gHistNoisePSideLayer6->Write();
290   gHistNoiseNSideLayer6->Write();
291   f2->Close();
292 }
293
294 //_____________________________________________________________________//
295 void BadChannelMap(AliCDBManager * man) {
296   const Int_t fgkSSDMODULES = 1698;
297   static const Int_t fgkDefaultNStripsSSD = 768;
298
299   //_____________________________________________________________________________//
300   TH2F *fHistPSideBadChannelMapLayer5 = new TH2F("fHistPSideBadChannelMapLayer5",
301                                                  "Layer 5;N_{module};N_{ladder}",
302                                                  22,1,23,
303                                                  34,500,534);
304   fHistPSideBadChannelMapLayer5->GetXaxis()->SetTitleColor(1);
305   fHistPSideBadChannelMapLayer5->GetZaxis()->SetRangeUser(0.,100.);
306   fHistPSideBadChannelMapLayer5->SetStats(kFALSE);
307   fHistPSideBadChannelMapLayer5->GetYaxis()->SetTitleOffset(1.8);
308   fHistPSideBadChannelMapLayer5->GetXaxis()->SetNdivisions(22);
309   fHistPSideBadChannelMapLayer5->GetYaxis()->SetNdivisions(34);
310   fHistPSideBadChannelMapLayer5->GetXaxis()->SetLabelSize(0.03);
311   fHistPSideBadChannelMapLayer5->GetYaxis()->SetLabelSize(0.03);
312   fHistPSideBadChannelMapLayer5->GetZaxis()->SetTitleOffset(1.6);
313   fHistPSideBadChannelMapLayer5->GetZaxis()->SetTitle("Bad channels (p-side)[%]");
314   TH2F *fHistNSideBadChannelMapLayer5 = new TH2F("fHistNSideBadChannelMapLayer5",
315                                                  "Layer 5;N_{module};N_{ladder}",
316                                                  22,1,23,
317                                                  34,500,534);
318   fHistNSideBadChannelMapLayer5->GetXaxis()->SetTitleColor(1);
319   fHistNSideBadChannelMapLayer5->GetZaxis()->SetRangeUser(0.,100.);
320   fHistNSideBadChannelMapLayer5->SetStats(kFALSE);
321   fHistNSideBadChannelMapLayer5->GetYaxis()->SetTitleOffset(1.8);
322   fHistNSideBadChannelMapLayer5->GetXaxis()->SetNdivisions(22);
323   fHistNSideBadChannelMapLayer5->GetYaxis()->SetNdivisions(34);
324   fHistNSideBadChannelMapLayer5->GetXaxis()->SetLabelSize(0.03);
325   fHistNSideBadChannelMapLayer5->GetYaxis()->SetLabelSize(0.03);
326   fHistNSideBadChannelMapLayer5->GetZaxis()->SetTitleOffset(1.6);
327   fHistNSideBadChannelMapLayer5->GetZaxis()->SetTitle("Bad channels (n-side)[%]");
328
329   TH2F *fHistPSideBadChannelMapLayer6 = new TH2F("fHistPSideBadChannelMapLayer6",
330                                             "Layer 6;N_{module};N_{ladder}",
331                                             25,1,26,
332                                             38,600,638);
333   fHistPSideBadChannelMapLayer6->GetXaxis()->SetTitleColor(1);
334   fHistPSideBadChannelMapLayer6->GetZaxis()->SetRangeUser(0.,100.);
335   fHistPSideBadChannelMapLayer6->SetStats(kFALSE);
336   fHistPSideBadChannelMapLayer6->GetYaxis()->SetTitleOffset(1.8);
337   fHistPSideBadChannelMapLayer6->GetXaxis()->SetNdivisions(25);
338   fHistPSideBadChannelMapLayer6->GetYaxis()->SetNdivisions(38);
339   fHistPSideBadChannelMapLayer6->GetXaxis()->SetLabelSize(0.03);
340   fHistPSideBadChannelMapLayer6->GetYaxis()->SetLabelSize(0.03);
341   fHistPSideBadChannelMapLayer6->GetZaxis()->SetTitleOffset(1.6);
342   fHistPSideBadChannelMapLayer6->GetZaxis()->SetTitle("Bad channels (p-side)[%]");
343   TH2F *fHistNSideBadChannelMapLayer6 = new TH2F("fHistNSideBadChannelMapLayer6",
344                                             "Layer 6;N_{module};N_{ladder}",
345                                             25,1,26,
346                                             38,600,638);
347   fHistNSideBadChannelMapLayer6->GetXaxis()->SetTitleColor(1);
348   fHistNSideBadChannelMapLayer6->GetZaxis()->SetRangeUser(0.,100.);
349   fHistNSideBadChannelMapLayer6->SetStats(kFALSE);
350   fHistNSideBadChannelMapLayer6->GetYaxis()->SetTitleOffset(1.8);
351   fHistNSideBadChannelMapLayer6->GetXaxis()->SetNdivisions(25);
352   fHistNSideBadChannelMapLayer6->GetYaxis()->SetNdivisions(38);
353   fHistNSideBadChannelMapLayer6->GetXaxis()->SetLabelSize(0.03);
354   fHistNSideBadChannelMapLayer6->GetYaxis()->SetLabelSize(0.03);
355   fHistNSideBadChannelMapLayer6->GetZaxis()->SetTitleOffset(1.6);
356   fHistNSideBadChannelMapLayer6->GetZaxis()->SetTitle("Bad channels (n-side)[%]");
357   //_____________________________________________________________________________//
358   
359   //_____________________________________________________________________________//
360   AliITSBadChannelsSSDv2 *badChannelsSSD = new AliITSBadChannelsSSDv2();
361   AliCDBEntry *entryBadChannelsSSD = man->Get("ITS/Calib/BadChannelsSSD");
362   TObject *empty = (TObject *)entryBadChannelsSSD->GetObject();
363   TString objectname = empty->GetName();
364   if(objectname=="TObjArray") {
365     TObjArray *badChannelsSSDOld = (TObjArray *)entryBadChannelsSSD->GetObject();
366     ReadOldSSDBadChannels(badChannelsSSDOld, badChannelsSSD);
367   }
368   else if(objectname=="AliITSBadChannelsSSDv2") {
369     cout<<"Reading the new format of the calibration file..."<<endl;
370     badChannelsSSD = (AliITSBadChannelsSSDv2 *)entryBadChannelsSSD->GetObject();
371   }
372   //_____________________________________________________________________________//
373
374   //_____________________________________________________________________________//
375   Int_t nPSideChannelsTotal = 0, nNSideChannelsTotal = 0;
376   Int_t nBadPSideChannelsTotal = 0, nBadNSideChannelsTotal = 0;
377   Int_t nBadPSideChannels = 0, nBadNSideChannels = 0;
378   Int_t layer = 0, ladder = 0, module = 0;
379   Int_t nPSideChannelsLayer5 = 0, nNSideChannelsLayer5 = 0;
380   Int_t nPSideChannelsLayer6 = 0, nNSideChannelsLayer6 = 0;
381   //_____________________________________________________________________________//
382
383   for(Int_t i = 0; i < fgkSSDMODULES; i++) {
384     //for(Int_t i = 0; i < 1; i++) {
385     AliITSgeomTGeo::GetModuleId(i+500,layer,ladder,module);
386     nBadPSideChannels = 0, nBadNSideChannels = 0;
387     nPSideChannelsLayer5 = 0, nNSideChannelsLayer5 = 0;
388     nPSideChannelsLayer6 = 0, nNSideChannelsLayer6 = 0;
389
390     Int_t badChannel = 0;
391     for(Int_t j = 0; j < fgkDefaultNStripsSSD; j++) {
392       badChannel = (Int_t)(badChannelsSSD->GetBadChannelP(i,j));
393       //cout<<"Module: "<<i+500<< " Strip: "<<j<<" - "<<badChannel<<endl;
394       if(badChannel != 0) {
395         if(layer == 5)
396           nPSideChannelsLayer5 += 1;
397         if(layer == 6)
398           nPSideChannelsLayer6 += 1;
399         nBadPSideChannels += 1;
400       }
401       badChannel = (Int_t)(badChannelsSSD->GetBadChannelN(i,j));
402       //cout<<"Module: "<<i+500<< " Strip: "<<fgkDefaultNStripsSSD+j+1<<" - "<<badChannel<<endl;
403       if(badChannel != 0) {
404         if(layer == 5)                                                    
405           nNSideChannelsLayer5 += 1;
406         if(layer == 6)
407           nNSideChannelsLayer6 += 1;
408         nBadNSideChannels += 1;
409       }
410     }
411     if(layer == 5) {
412       if(nPSideChannelsLayer5 > 0)
413         fHistPSideBadChannelMapLayer5->Fill(module,499+ladder,
414                                             100.*nPSideChannelsLayer5/fgkDefaultNStripsSSD);
415       else fHistPSideBadChannelMapLayer5->Fill(module,499+ladder,0.0001);
416       if(nNSideChannelsLayer5 > 0)
417         fHistNSideBadChannelMapLayer5->Fill(module,499+ladder,
418                                             100.*nNSideChannelsLayer5/fgkDefaultNStripsSSD);
419       else fHistNSideBadChannelMapLayer5->Fill(module,499+ladder,0.0001);
420     }//layer 5
421     if(layer == 6) {
422       if(nPSideChannelsLayer6 > 0) 
423         fHistPSideBadChannelMapLayer6->Fill(module,599+ladder,
424                                             100.*nPSideChannelsLayer6/fgkDefaultNStripsSSD);
425       else fHistPSideBadChannelMapLayer6->Fill(module,599+ladder,0.0001);
426       if(nNSideChannelsLayer6 > 0) 
427         fHistNSideBadChannelMapLayer6->Fill(module,599+ladder,
428                                             100.*nNSideChannelsLayer6/fgkDefaultNStripsSSD);
429       else fHistNSideBadChannelMapLayer6->Fill(module,599+ladder,0.0001);
430     }//layer 6
431       
432     nBadPSideChannelsTotal += nBadPSideChannels;
433     nBadNSideChannelsTotal += nBadNSideChannels;
434     nPSideChannelsTotal += fgkDefaultNStripsSSD;
435     nNSideChannelsTotal += fgkDefaultNStripsSSD;
436   }
437
438   cout<<"================================="<<endl;
439   cout<<"Bad p-Side channels: "<<100.*nBadPSideChannelsTotal/nPSideChannelsTotal<<endl;
440   cout<<"Bad n-Side channels: "<<100.*nBadNSideChannelsTotal/nNSideChannelsTotal<<endl;
441   cout<<"================================="<<endl;
442
443   TCanvas *cBadChannel = new TCanvas("cBadChannel",
444                                      "Bad channel list",0,0,900,900);
445   cBadChannel->SetHighLightColor(10); cBadChannel->SetFillColor(10); 
446   cBadChannel->Divide(2,2);
447
448   cBadChannel->cd(1)->SetBottomMargin(.2); 
449   cBadChannel->cd(1)->SetLeftMargin(.15);
450   cBadChannel->cd(1)->SetRightMargin(.2);
451   cBadChannel->cd(1)->SetGridx(); cBadChannel->cd(1)->SetGridy();
452   cBadChannel->cd(1); fHistPSideBadChannelMapLayer5->Draw("colz"); 
453   cBadChannel->cd(2)->SetBottomMargin(.2); 
454   cBadChannel->cd(2)->SetLeftMargin(.15);
455   cBadChannel->cd(2)->SetRightMargin(.2);
456   cBadChannel->cd(2)->SetGridx(); cBadChannel->cd(2)->SetGridy();
457   cBadChannel->cd(2); fHistPSideBadChannelMapLayer6->Draw("colz");
458   cBadChannel->cd(3)->SetBottomMargin(.2); 
459   cBadChannel->cd(3)->SetLeftMargin(.15);
460   cBadChannel->cd(3)->SetRightMargin(.2);
461   cBadChannel->cd(3)->SetGridx(); cBadChannel->cd(3)->SetGridy();
462   cBadChannel->cd(3); fHistNSideBadChannelMapLayer5->Draw("colz"); 
463   cBadChannel->cd(4)->SetBottomMargin(.2); 
464   cBadChannel->cd(4)->SetLeftMargin(.15);
465   cBadChannel->cd(4)->SetRightMargin(.2);
466   cBadChannel->cd(4)->SetGridx(); cBadChannel->cd(4)->SetGridy();
467   cBadChannel->cd(4); fHistNSideBadChannelMapLayer6->Draw("colz");
468   cBadChannel->SaveAs("Run-BadChannels.gif");
469
470   TFile *fOutput = new TFile("badChannelsSSD.root","recreate");
471   fHistPSideBadChannelMapLayer5->Write();
472   fHistNSideBadChannelMapLayer5->Write();
473   fHistPSideBadChannelMapLayer6->Write();
474   fHistNSideBadChannelMapLayer6->Write();
475   fOutput->Close();
476 }
477
478 //_____________________________________________________________________//
479 void GainCalibration(AliCDBManager * man) {
480   const Int_t fgkSSDMODULES = 1698;
481   static const Int_t fgkDefaultNStripsSSD = 768;
482
483   TH2F *fHistGainMapLayer5 = new TH2F("fHistGainMapLayer5",
484                                       "Layer 5;N_{strip};N_{module}",
485                                       1537,0,1537,
486                                       750,499,1249);
487   fHistGainMapLayer5->GetXaxis()->SetTitleColor(1);
488   fHistGainMapLayer5->SetStats(kFALSE);
489   fHistGainMapLayer5->GetYaxis()->SetTitleOffset(1.8);
490   TH2F *fHistGainMapLayer6 = new TH2F("fHistGainMapLayer6",
491                                       "Layer 6;N_{strip};N_{module}",
492                                       1537,0,1537,
493                                       952,1249,2199);
494   fHistGainMapLayer6->GetXaxis()->SetTitleColor(1);
495   fHistGainMapLayer6->SetStats(kFALSE);
496   fHistGainMapLayer6->GetYaxis()->SetTitleOffset(1.8);
497
498   AliITSGainSSDv2 *gainSSD = new AliITSGainSSDv2();
499   AliCDBEntry *entryGainSSD = man->Get("ITS/Calib/GainSSD");
500   TObject *empty = (TObject *)entryGainSSD->GetObject();
501   TString objectname = empty->GetName();
502   if(objectname=="Gain") {
503     TObjArray *gainSSDOld = (TObjArray *)entryGainSSD->GetObject();
504     ReadOldSSDGain(gainSSDOld, gainSSD);
505   }
506   else if(objectname=="AliITSGainSSDv2") {
507     cout<<"Reading the new format of the calibration file..."<<endl;
508     gainSSD = (AliITSGainSSDv2 *)entryGainSSD->GetObject();
509   }
510   
511   Int_t layer = 0, ladder = 0, module = 0;
512   Double_t gain = 0;
513   for (Int_t i = 0; i < fgkSSDMODULES; i++) {
514   //for (Int_t i = 0; i < 1; i++) {
515     AliITSgeomTGeo::GetModuleId(i+500,layer,ladder,module);
516     for(Int_t j = 0; j < fgkDefaultNStripsSSD; j++) {
517       gain = gainSSD->GetGainP(i,j);
518       //cout<<"GainP: "<<gain<<endl;
519       if(layer == 5)
520         fHistGainMapLayer5->Fill(j,i+500,gain);
521       if(layer == 6)
522         fHistGainMapLayer6->Fill(j,i+500,gain);
523       
524       gain = gainSSD->GetGainN(i,j);
525       //cout<<"GainN: "<<gain<<endl;
526       if(layer == 5)
527         fHistGainMapLayer5->Fill(fgkDefaultNStripsSSD+j,i+500,gain);
528       if(layer == 6)
529         fHistGainMapLayer6->Fill(fgkDefaultNStripsSSD+j,i+500,gain);
530     }//strip loop
531   }//module loop
532
533   TCanvas *cGain = new TCanvas("cGain","Gain calibration map",0,300,600,300);
534   cGain->SetHighLightColor(10); cGain->SetFillColor(10); cGain->Divide(2,1);
535   
536   cGain->cd(1)->SetBottomMargin(.2); cGain->cd(1)->SetLeftMargin(.15);
537   cGain->cd(1); fHistGainMapLayer5->Draw("colz");
538   cGain->cd(2)->SetBottomMargin(.2); cGain->cd(2)->SetLeftMargin(.15);
539   cGain->cd(2); fHistGainMapLayer6->Draw("colz");
540 }
541
542 //_____________________________________________________________________//
543 void ReadOldSSDNoise(TObjArray *array, 
544                      AliITSNoiseSSDv2 *noiseSSD) {
545   const Int_t fgkSSDSTRIPSPERMODULE = 1536;
546   const Int_t fgkSSDPSIDESTRIPSPERMODULE = 768;
547
548   Int_t fNMod = array->GetEntries();
549   cout<<"Converting old calibration object for noise..."<<endl;
550
551   //NOISE
552   Double_t noise = 0.0;
553   for (Int_t iModule = 0; iModule < fNMod; iModule++) {
554     AliITSNoiseSSD *noiseModule = (AliITSNoiseSSD*) (array->At(iModule));
555     for(Int_t iStrip = 0; iStrip < fgkSSDSTRIPSPERMODULE; iStrip++) {
556       noise = (iStrip < fgkSSDPSIDESTRIPSPERMODULE) ? noiseModule->GetNoiseP(iStrip) : noiseModule->GetNoiseN(1535 - iStrip);
557       if(iStrip < fgkSSDPSIDESTRIPSPERMODULE)
558         noiseSSD->AddNoiseP(iModule,iStrip,noise);
559       if(iStrip >= fgkSSDPSIDESTRIPSPERMODULE)
560         noiseSSD->AddNoiseN(iModule,1535 - iStrip,noise);
561     }//loop over strips
562   }//loop over modules      
563 }
564
565 //_____________________________________________________________________//
566 void ReadOldSSDPedestal(TObjArray *array, 
567                         AliITSPedestalSSDv2 *pedestalSSD) {
568   const Int_t fgkSSDSTRIPSPERMODULE = 1536;
569   const Int_t fgkSSDPSIDESTRIPSPERMODULE = 768;
570
571   Int_t fNMod = array->GetEntries();
572   cout<<"Converting old calibration object for pedestal..."<<endl;
573
574   //PEDESTAL
575   Double_t pedestal = 0.0;
576   for (Int_t iModule = 0; iModule < fNMod; iModule++) {
577     AliITSPedestalSSD *pedestalModule = (AliITSPedestalSSD*) (array->At(iModule));
578     for(Int_t iStrip = 0; iStrip < fgkSSDSTRIPSPERMODULE; iStrip++) {
579       pedestal = (iStrip < fgkSSDPSIDESTRIPSPERMODULE) ? pedestalModule->GetPedestalP(iStrip) : pedestalModule->GetPedestalN(1535 - iStrip);
580       if(iStrip < fgkSSDPSIDESTRIPSPERMODULE)
581         pedestalSSD->AddPedestalP(iModule,iStrip,pedestal);
582       if(iStrip >= fgkSSDPSIDESTRIPSPERMODULE)
583         pedestalSSD->AddPedestalN(iModule,1535 - iStrip,pedestal);
584     }//loop over strips
585   }//loop over modules      
586 }
587
588 //_____________________________________________________________________//
589 void ReadOldSSDBadChannels(TObjArray *array, 
590                            AliITSBadChannelsSSDv2 *badChannelsSSD) {
591   Int_t fNMod = array->GetEntries();
592   cout<<"Converting old calibration object for bad channels..."<<endl;
593   for (Int_t iModule = 0; iModule < fNMod; iModule++) {
594     //for (Int_t iModule = 0; iModule < 1; iModule++) {
595     AliITSBadChannelsSSD *bad = (AliITSBadChannelsSSD*) (array->At(iModule));
596     TArrayI arrayPSide = bad->GetBadPChannelsList();
597     for(Int_t iPCounter = 0; iPCounter < arrayPSide.GetSize(); iPCounter++) 
598       badChannelsSSD->AddBadChannelP(iModule,
599                                      iPCounter,
600                                      (Char_t)arrayPSide.At(iPCounter));
601         
602     TArrayI arrayNSide = bad->GetBadNChannelsList();
603     for(Int_t iNCounter = 0; iNCounter < arrayNSide.GetSize(); iNCounter++) 
604       badChannelsSSD->AddBadChannelN(iModule,
605                                      iNCounter,
606                                      (Char_t)arrayNSide.At(iNCounter));
607     
608   }//loop over modules      
609 }
610
611 //_____________________________________________________________________//
612 void ReadOldSSDGain(TObjArray *array, 
613                     AliITSGainSSDv2 *gainSSD) {
614   Int_t fNMod = array->GetEntries();
615   cout<<"Converting old calibration object for gain..."<<endl;
616
617   //GAIN
618   for (Int_t iModule = 0; iModule < fNMod; iModule++) {
619     AliITSGainSSD *gainModule = (AliITSGainSSD*) (array->At(iModule));
620     TArrayF arrayPSide = gainModule->GetGainP();
621     for(Int_t iPCounter = 0; iPCounter < arrayPSide.GetSize(); iPCounter++)
622       gainSSD->AddGainP(iModule,
623                         iPCounter,
624                         arrayPSide.At(iPCounter));
625     TArrayF arrayNSide = gainModule->GetGainN();
626     for(Int_t iNCounter = 0; iNCounter < arrayNSide.GetSize(); iNCounter++)
627       gainSSD->AddGainN(iModule,
628                         iNCounter,
629                         arrayNSide.At(iNCounter));
630   }//loop over modules 
631 }