2 // Macro adds ether ladder, module or channel to the SSD bad channels map.
3 // Input parameter: file name with original SSD bad channels map (optional),
4 // equipment identifier (DDL),
5 // Slot number, ADC number (optional) and channel number (optional)
6 // Author: Oleksandr.Borysov@cern.ch
10 #if !defined(__CINT__) || defined(__MAKECINT__)
12 #include <Riostream.h>
19 #include "AliRawReaderRoot.h"
20 #include "AliITSRawStreamSSDv1.h"
21 #include "AliITSBadChannelsSSDv2.h"
22 #include "AliITSModuleDaSSD.h"
23 #include "AliITSHandleDaSSD.h"
27 #define EQUIPMENTTODDLMASK 0xFF
28 #define NUMBEROFSSDMODULESPERSLOT 12
29 #define MAXSSDDDLID 15
30 #define MINSSDMODULEID 500
32 Bool_t readBCMap(const Char_t *filename, AliITSBadChannelsSSDv2*& bcl);
33 Int_t addModuleBCMap(AliITSBadChannelsSSDv2 *bcl, const Int_t EqId, const Int_t SlotId, const Int_t adc);
34 Int_t addLadderBCMap(AliITSBadChannelsSSDv2 *bcl, const Int_t EqId, const Int_t SlotId);
35 Int_t addChannelBCMap(AliITSBadChannelsSSDv2 *bcl, const Int_t EqId, const Int_t SlotId, const Int_t adc, const Int_t strp);
37 void drawBadChannelMapDAQDB(const char* filename);
39 //class gives an access to the protected array with SSD_DDL_Map in case the geometry is not initialized
40 class AliITSRawStreamSSDtmp : public AliITSRawStreamSSDv1 {
42 AliITSRawStreamSSDtmp(AliRawReader* rawReader): AliITSRawStreamSSDv1(rawReader) {
43 Setv11HybridDDLMapping();
44 AliInfo("Using SSD DDL Map initialized by AliITSRawStreamSSDv1::Setv11HybridDDLMapping()");
46 virtual ~AliITSRawStreamSSDtmp() {};
47 Int_t GetModId(Int_t iDDL, Int_t iModule) {return fgkDDLModuleMap[iDDL][iModule];}
48 ClassDef(AliITSRawStreamSSDtmp, 0)
51 //_________________________________________________________//
52 Int_t patchSSDBadChannelsMap(const Char_t *fname = 0,
53 const Int_t EqId = -1,
54 const Int_t SlotId = -1,
56 const Int_t strp = -1) {
57 //Macro to patch the bad channel list
58 TString bcfname, pathstr;
59 AliITSBadChannelsSSDv2 *bc = 0;
60 if (EqId < 0) { Usage(); cerr << "Equipment number (that is DDL) must be specified! Exit.\n"; return 0; }
61 else if ((EqId & EQUIPMENTTODDLMASK) > MAXSSDDDLID) {
62 cerr << "Icorrect equipment number (that is DDL)! Exit.\n";
65 if (SlotId < 1 || SlotId > 9) {
66 cerr << "Slot number must be specified (in the range 1 - 9)! Exit.\n";
70 if (!fname || fname[0]==0) {
71 cout << "File name with bad channels map is not specified, an empty map is used!\n";
72 bc = new AliITSBadChannelsSSDv2();
73 if (!bc) { cerr << "Error creating the AliITSBadChannelsSSDv2 object! Exit.\n"; return -1; }
78 if (!readBCMap(fname, bc)) {
79 cerr << "Error reading file " << fname << " with Static Bad Channels Map! Exit.\n";
83 if (adc < 0) addLadderBCMap(bc, EqId, SlotId);
84 else if ((adc < 6) || (adc > 7 && (adc - 2) < NUMBEROFSSDMODULESPERSLOT) ) {
85 if (strp < 0) addModuleBCMap(bc, EqId, SlotId, adc);
86 else if (strp < AliITSModuleDaSSD::GetStripsPerModuleConst()) addChannelBCMap(bc, EqId, SlotId, adc, strp);
88 cerr << "Incorrect number for Strip. Exit\n";
95 cerr << "Incorrect number for ADC. Exit\n";
99 bcfname = pathstr(0, pathstr.Last('/')+1);
100 bcfname.Append(Form("ssdbcmap_%i.root", time(NULL)));
101 TFile *bcfile = new TFile (bcfname.Data(),"RECREATE");
102 if (bcfile->IsZombie()) {
103 cerr << "Error open file " << bcfname.Data() << " for writing new bad channels map!\n";
107 bcfile->WriteTObject(bc);
110 cout << "New SSD bad channels map was saved in file " << bcfname.Data() << endl;
115 //_________________________________________________________//
116 Bool_t readBCMap(const Char_t *filename, AliITSBadChannelsSSDv2*& bcl) {
117 // Reads Static Bad Channels Map from the file
120 cout << "No file name is specified for Static Bad Channels Map!\n";
123 cout << "Reading SSD Bad Channels Map from the file " << filename << endl;
124 bcfile = new TFile(filename, "READ");
125 if (bcfile->IsZombie()) {
126 cerr << "Error reading file " << filename << " with Static Bad Channels Map!\n";
129 bcfile->GetObject("AliITSBadChannelsSSDv2;1", bcl);
131 cout << "Error bcl == NULL!\n";
141 //_________________________________________________________//
142 Int_t addModuleBCMap(AliITSBadChannelsSSDv2 *bcl,
143 const Int_t EqId, const Int_t SlotId, const Int_t adc) {
144 // Add module to bad channels map.
145 const Char_t isbad = 3;
146 Int_t ddl, mn, modid;
147 AliRawReaderRoot *rwr = 0;
148 AliITSRawStreamSSDtmp *rst = 0;
149 rwr = new AliRawReaderRoot();
150 rst = new AliITSRawStreamSSDtmp(rwr);
151 ddl = EqId & EQUIPMENTTODDLMASK;
152 mn = (SlotId - 1) * NUMBEROFSSDMODULESPERSLOT + (adc<8 ? adc : adc-2);
153 modid = rst->GetModId(ddl, mn);
154 modid -= MINSSDMODULEID;
155 if (modid < 0) return 0;
156 for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetPNStripsPerModule(); strind++) {
157 bcl->AddBadChannelP(modid, strind, isbad);
158 bcl->AddBadChannelN(modid, strind, isbad);
162 cout << "Module added: ModId = " << modid + MINSSDMODULEID << "; Ddl/Ad/Adc: " << ddl
163 << " / " << SlotId << " / " << adc << endl;
167 //_________________________________________________________//
168 Int_t addLadderBCMap(AliITSBadChannelsSSDv2 *bcl,
169 const Int_t EqId, const Int_t SlotId) {
170 // Add ladder to bad channels map.
171 for (Int_t adc = 0; adc < NUMBEROFSSDMODULESPERSLOT; adc++)
172 addModuleBCMap(bcl, EqId, SlotId, (adc<6 ? adc : adc+2));
176 //_________________________________________________________//
177 Int_t addChannelBCMap(AliITSBadChannelsSSDv2 *bcl,
178 const Int_t EqId, const Int_t SlotId,
179 const Int_t adc, const Int_t strp) {
180 // Add strip to bad channels map.
181 const Char_t isbad = 3;
182 Int_t ddl, mn, modid;
183 AliRawReaderRoot *rwr = 0;
184 AliITSRawStreamSSDtmp *rst = 0;
185 rwr = new AliRawReaderRoot();
186 rst = new AliITSRawStreamSSDtmp(rwr);
187 ddl = EqId & EQUIPMENTTODDLMASK;
188 mn = (SlotId - 1) * NUMBEROFSSDMODULESPERSLOT + (adc<8 ? adc : adc-2);
189 modid = rst->GetModId(ddl, mn);
190 modid -= MINSSDMODULEID;
191 if (modid < 0) { cout << "There is no module with given Equipment, Slot, adc.\n" ; return 0; }
192 if (strp < AliITSModuleDaSSD::GetPNStripsPerModule() ) {
193 bcl->AddBadChannelP(modid, strp, isbad);
195 bcl->AddBadChannelN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strp), isbad);
199 cout << "Channel added (ModId/Ddl/Ad/Adc/Strip): " << modid + MINSSDMODULEID << " / " << ddl << " / " << SlotId
200 << " / " << adc << " / " << strp << endl;
204 //_________________________________________________________//
207 cout << "Usage: PatchSSDBadChannelsMap(bc_fname /* can be \"\" */, EqipmentId, SlotId, adc /*optional*/, strip /*optional*/)\n";
210 //_______________________________________//
211 void drawBadChannelMapDAQDB(const char* filename) {
212 //Draws the 2D plots of the bad channels maps
213 const Int_t fgkSSDMODULES = 1698;
214 static const Int_t fgkDefaultNStripsSSD = 768;
215 gStyle->SetPalette(1,0);
217 TH2F *fHistDAQDBPSideBadChannelMapLayer5 = new TH2F("fHistDAQDBPSideBadChannelMapLayer5",
218 "Layer 5;N_{module};N_{ladder}",
221 fHistDAQDBPSideBadChannelMapLayer5->GetXaxis()->SetTitleColor(1);
222 fHistDAQDBPSideBadChannelMapLayer5->SetStats(kFALSE);
223 fHistDAQDBPSideBadChannelMapLayer5->GetYaxis()->SetTitleOffset(1.8);
224 fHistDAQDBPSideBadChannelMapLayer5->GetXaxis()->SetNdivisions(22);
225 fHistDAQDBPSideBadChannelMapLayer5->GetYaxis()->SetNdivisions(34);
226 fHistDAQDBPSideBadChannelMapLayer5->GetXaxis()->SetLabelSize(0.03);
227 fHistDAQDBPSideBadChannelMapLayer5->GetYaxis()->SetLabelSize(0.03);
228 fHistDAQDBPSideBadChannelMapLayer5->GetZaxis()->SetTitleOffset(1.6);
229 fHistDAQDBPSideBadChannelMapLayer5->GetZaxis()->SetTitle("Bad channels (p-side)[%]");
231 TH2F *fHistDAQDBNSideBadChannelMapLayer5 = new TH2F("fHistDAQDBNSideBadChannelMapLayer5",
232 "Layer 5;N_{module};N_{ladder}",
235 fHistDAQDBNSideBadChannelMapLayer5->GetXaxis()->SetTitleColor(1);
236 fHistDAQDBNSideBadChannelMapLayer5->SetStats(kFALSE);
237 fHistDAQDBNSideBadChannelMapLayer5->GetYaxis()->SetTitleOffset(1.8);
238 fHistDAQDBNSideBadChannelMapLayer5->GetXaxis()->SetNdivisions(22);
239 fHistDAQDBNSideBadChannelMapLayer5->GetYaxis()->SetNdivisions(34);
240 fHistDAQDBNSideBadChannelMapLayer5->GetXaxis()->SetLabelSize(0.03);
241 fHistDAQDBNSideBadChannelMapLayer5->GetYaxis()->SetLabelSize(0.03);
242 fHistDAQDBNSideBadChannelMapLayer5->GetZaxis()->SetTitleOffset(1.6);
243 fHistDAQDBNSideBadChannelMapLayer5->GetZaxis()->SetTitle("Bad channels (n-side)[%]");
245 TH2F *fHistDAQDBPSideBadChannelMapLayer6 = new TH2F("fHistDAQDBPSideBadChannelMapLayer6",
246 "Layer 6;N_{module};N_{ladder}",
249 fHistDAQDBPSideBadChannelMapLayer6->GetXaxis()->SetTitleColor(1);
250 fHistDAQDBPSideBadChannelMapLayer6->SetStats(kFALSE);
251 fHistDAQDBPSideBadChannelMapLayer6->GetYaxis()->SetTitleOffset(1.8);
252 fHistDAQDBPSideBadChannelMapLayer6->GetXaxis()->SetNdivisions(25);
253 fHistDAQDBPSideBadChannelMapLayer6->GetYaxis()->SetNdivisions(38);
254 fHistDAQDBPSideBadChannelMapLayer6->GetXaxis()->SetLabelSize(0.03);
255 fHistDAQDBPSideBadChannelMapLayer6->GetYaxis()->SetLabelSize(0.03);
256 fHistDAQDBPSideBadChannelMapLayer6->GetZaxis()->SetTitleOffset(1.6);
257 fHistDAQDBPSideBadChannelMapLayer6->GetZaxis()->SetTitle("Bad channels (p-side)[%]");
259 TH2F *fHistDAQDBNSideBadChannelMapLayer6 = new TH2F("fHistDAQDBNSideBadChannelMapLayer6",
260 "Layer 6;N_{module};N_{ladder}",
263 fHistDAQDBNSideBadChannelMapLayer6->GetXaxis()->SetTitleColor(1);
264 fHistDAQDBNSideBadChannelMapLayer6->SetStats(kFALSE);
265 fHistDAQDBNSideBadChannelMapLayer6->GetYaxis()->SetTitleOffset(1.8);
266 fHistDAQDBNSideBadChannelMapLayer6->GetXaxis()->SetNdivisions(25);
267 fHistDAQDBNSideBadChannelMapLayer6->GetYaxis()->SetNdivisions(38);
268 fHistDAQDBNSideBadChannelMapLayer6->GetXaxis()->SetLabelSize(0.03);
269 fHistDAQDBNSideBadChannelMapLayer6->GetYaxis()->SetLabelSize(0.03);
270 fHistDAQDBNSideBadChannelMapLayer6->GetZaxis()->SetTitleOffset(1.6);
271 fHistDAQDBNSideBadChannelMapLayer6->GetZaxis()->SetTitle("Bad channels (n-side)[%]");
273 //===============================//
274 TFile *f = TFile::Open(filename);
276 Printf("File poiter not valid");
281 Printf("The file was not found");
284 //===============================//
286 AliITSBadChannelsSSDv2 *badChannelsSSD = new AliITSBadChannelsSSDv2();
287 badChannelsSSD = dynamic_cast<AliITSBadChannelsSSDv2 *>(f->Get("AliITSBadChannelsSSDv2"));
289 //_____________________________________________________________________________//
290 Int_t nPSideChannelsTotal = 0, nNSideChannelsTotal = 0;
291 Int_t nBadPSideChannelsTotal = 0, nBadNSideChannelsTotal = 0;
292 Int_t nBadPSideChannels = 0, nBadNSideChannels = 0;
293 Int_t layer = 0, ladder = 0, module = 0;
294 Int_t nPSideChannelsLayer5 = 0, nNSideChannelsLayer5 = 0;
295 Int_t nPSideChannelsLayer6 = 0, nNSideChannelsLayer6 = 0;
296 //_____________________________________________________________________________//
298 for(Int_t i = 0; i < fgkSSDMODULES; i++) {
299 //for(Int_t i = 0; i < 1; i++) {
300 AliITSgeomTGeo::GetModuleId(i+500,layer,ladder,module);
301 nBadPSideChannels = 0, nBadNSideChannels = 0;
302 nPSideChannelsLayer5 = 0, nNSideChannelsLayer5 = 0;
303 nPSideChannelsLayer6 = 0, nNSideChannelsLayer6 = 0;
305 Int_t badChannel = 0;
306 for(Int_t j = 0; j < fgkDefaultNStripsSSD; j++) {
307 badChannel = (Int_t)(badChannelsSSD->GetBadChannelP(i,j));
308 //cout<<"Module: "<<i+500<< " Strip: "<<j<<" - "<<badChannel<<endl;
309 if(badChannel != 0) {
311 nPSideChannelsLayer5 += 1;
313 nPSideChannelsLayer6 += 1;
314 nBadPSideChannels += 1;
316 badChannel = (Int_t)(badChannelsSSD->GetBadChannelN(i,j));
317 //cout<<"Module: "<<i+500<< " Strip: "<<fgkDefaultNStripsSSD+j+1<<" - "<<badChannel<<endl;
318 if(badChannel != 0) {
320 nNSideChannelsLayer5 += 1;
322 nNSideChannelsLayer6 += 1;
323 nBadNSideChannels += 1;
327 if(nPSideChannelsLayer5 > 0)
328 fHistDAQDBPSideBadChannelMapLayer5->Fill(module,499+ladder,
329 100.*nPSideChannelsLayer5/fgkDefaultNStripsSSD);
330 else fHistDAQDBPSideBadChannelMapLayer5->Fill(module,499+ladder,0.0001);
331 if(nNSideChannelsLayer5 > 0)
332 fHistDAQDBNSideBadChannelMapLayer5->Fill(module,499+ladder,
333 100.*nNSideChannelsLayer5/fgkDefaultNStripsSSD);
334 else fHistDAQDBNSideBadChannelMapLayer5->Fill(module,499+ladder,0.0001);
337 if(nPSideChannelsLayer6 > 0)
338 fHistDAQDBPSideBadChannelMapLayer6->Fill(module,599+ladder,
339 100.*nPSideChannelsLayer6/fgkDefaultNStripsSSD);
340 else fHistDAQDBPSideBadChannelMapLayer6->Fill(module,599+ladder,0.0001);
341 if(nNSideChannelsLayer6 > 0)
342 fHistDAQDBNSideBadChannelMapLayer6->Fill(module,599+ladder,
343 100.*nNSideChannelsLayer6/fgkDefaultNStripsSSD);
344 else fHistDAQDBNSideBadChannelMapLayer6->Fill(module,599+ladder,0.0001);
347 nBadPSideChannelsTotal += nBadPSideChannels;
348 nBadNSideChannelsTotal += nBadNSideChannels;
349 nPSideChannelsTotal += fgkDefaultNStripsSSD;
350 nNSideChannelsTotal += fgkDefaultNStripsSSD;
353 cout<<"================================="<<endl;
354 cout<<"Bad p-Side channels: "<<100.*nBadPSideChannelsTotal/nPSideChannelsTotal<<endl;
355 cout<<"Bad n-Side channels: "<<100.*nBadNSideChannelsTotal/nNSideChannelsTotal<<endl;
356 cout<<"================================="<<endl;
358 TCanvas *cBadChannelDAQDB = new TCanvas("cBadChannelDAQDB",
359 "Bad channel list - DAQ DB",
361 cBadChannelDAQDB->SetHighLightColor(10); cBadChannelDAQDB->SetFillColor(10);
362 cBadChannelDAQDB->Divide(2,2);
364 cBadChannelDAQDB->cd(1)->SetBottomMargin(.2);
365 cBadChannelDAQDB->cd(1)->SetLeftMargin(.15);
366 cBadChannelDAQDB->cd(1)->SetRightMargin(.2);
367 cBadChannelDAQDB->cd(1)->SetGridx(); cBadChannelDAQDB->cd(1)->SetGridy();
368 cBadChannelDAQDB->cd(1); fHistDAQDBPSideBadChannelMapLayer5->Draw("colz");
369 cBadChannelDAQDB->cd(2)->SetBottomMargin(.2);
370 cBadChannelDAQDB->cd(2)->SetLeftMargin(.15);
371 cBadChannelDAQDB->cd(2)->SetRightMargin(.2);
372 cBadChannelDAQDB->cd(2)->SetGridx(); cBadChannelDAQDB->cd(2)->SetGridy();
373 cBadChannelDAQDB->cd(2); fHistDAQDBPSideBadChannelMapLayer6->Draw("colz");
374 cBadChannelDAQDB->cd(3)->SetBottomMargin(.2);
375 cBadChannelDAQDB->cd(3)->SetLeftMargin(.15);
376 cBadChannelDAQDB->cd(3)->SetRightMargin(.2);
377 cBadChannelDAQDB->cd(3)->SetGridx(); cBadChannelDAQDB->cd(3)->SetGridy();
378 cBadChannelDAQDB->cd(3); fHistDAQDBNSideBadChannelMapLayer5->Draw("colz");
379 cBadChannelDAQDB->cd(4)->SetBottomMargin(.2);
380 cBadChannelDAQDB->cd(4)->SetLeftMargin(.15);
381 cBadChannelDAQDB->cd(4)->SetRightMargin(.2);
382 cBadChannelDAQDB->cd(4)->SetGridx(); cBadChannelDAQDB->cd(4)->SetGridy();
383 cBadChannelDAQDB->cd(4); fHistDAQDBNSideBadChannelMapLayer6->Draw("colz");