Changing once more (hopefully we get it correct this time...) the logic to trig the...
[u/mrichter/AliRoot.git] / ITS / readSSDCommonMode.C
CommitLineData
f5a5ae3e 1#if !defined(__CINT__) || defined(__MAKECINT__)
2#include "TString.h"
3#include "TH1.h"
4#include "TH2.h"
5#include "TFile.h"
6#include "TList.h"
7#include "TChain.h"
8#include "TObject.h"
9#include "TCanvas.h"
10#include "TStyle.h"
11#include "TSystem.h"
12#include "Riostream.h"
13
14#include "AliITSgeomTGeo.h"
15#include "AliLog.h"
16#include "AliRawReaderRoot.h"
17#include "AliITSRawStreamSSD.h"
18#include "AliCDBManager.h"
19#include "AliCDBEntry.h"
20#endif
21
22/* $Id: $ */
23
24//============================================================//
af105157 25static const Int_t fgkNumOfChips = 6; //number of SSD chips per module per side
f5a5ae3e 26static const Int_t fgkNumOfLDCs = 8; //number of SSD LDCs
27static const Int_t fgkNumOfDDLs = 16; //number of SSD DDLs
28static const Int_t fgkSSDMODULES = 1698; //total number of SSD modules
29static const Int_t fgkSSDLADDERSLAYER5 = 34; //ladders on layer 5
30static const Int_t fgkSSDLADDERSLAYER6 = 38; //ladders on layer 6
31static const Int_t fgkSSDMODULESPERLADDERLAYER5 = 22; //modules per ladder - layer 5
32static const Int_t fgkSSDMODULESPERLADDERLAYER6 = 25; //modules per ladder - layer 6
33static const Int_t fgkSSDMODULESLAYER5 = 748; //total number of SSD modules - layer5
34static const Int_t fgkSSDMODULESLAYER6 = 950; //total number of SSD modules - layer6
35static const Int_t fgkNumberOfPSideStrips = 768; //number of P-side strips
36//============================================================//
37
38TList *initCM();
39void makeCM(const char* filename, Int_t nEvents, TList *list);
a56fec3e 40void checkCM(const char* filename);
b093e9a0 41void compareChipLists(TString inputFile1,
42 TString inputFile2,
43 TString outputTxt);
f5a5ae3e 44
45//__________________________________________________________//
46void readSSDCommonMode(const char* filename = "raw.root",
47 Int_t nEvents = -1) {
48 //Reads the CM pseudo-channels and produces the CM map for both layers
49 //and for p and n-side.
50 gStyle->SetPalette(1,0);
51
52 TList *list = initCM();
53 //list->ls();
54 Printf("CM histograms: %d",list->GetEntries());
55 makeCM(filename,nEvents,list);
56}
57
58//__________________________________________________________//
59TList *initCM() {
60 //Initializes the histograms and returns the TList object
61 TList *list = new TList();
62
63 Int_t gLayer = 0,gLadder = 0, gModule = 0;
64 Int_t gHistCounter = 0;
65 TString gTitle;
af105157 66 TH1F *gHistSSDCMModule[2*fgkSSDMODULES][fgkNumOfChips];
f5a5ae3e 67 for(Int_t iModule = 500; iModule < fgkSSDMODULES + 500; iModule++) {
68 AliITSgeomTGeo::GetModuleId(iModule,gLayer,gLadder,gModule);
af105157 69 for(Int_t iChip = 0; iChip < fgkNumOfChips; iChip++) {
70 gTitle = "SSD_CM_PSide_Layer"; gTitle += gLayer;
71 gTitle += "_Ladder"; gTitle += gLadder;
72 gTitle += "_Module"; gTitle += gModule;
73 gTitle += "_Chip"; gTitle += iChip+1;
74 gHistSSDCMModule[gHistCounter][iChip] = new TH1F(gTitle.Data(),
75 gTitle.Data(),
76 100,-50.,50.);
77 gHistSSDCMModule[gHistCounter][iChip]->GetXaxis()->SetTitle("CM");
78 list->Add(gHistSSDCMModule[gHistCounter][iChip]);
79 }
f5a5ae3e 80 gHistCounter += 1;
81 }
82 for(Int_t iModule = 500; iModule < fgkSSDMODULES + 500; iModule++) {
83 AliITSgeomTGeo::GetModuleId(iModule,gLayer,gLadder,gModule);
af105157 84 for(Int_t iChip = 0; iChip < fgkNumOfChips; iChip++) {
85 gTitle = "SSD_CM_NSide_Layer"; gTitle += gLayer;
86 gTitle += "_Ladder"; gTitle += gLadder;
87 gTitle += "_Module"; gTitle += gModule;
88 gTitle += "_Chip"; gTitle += iChip+1;
89 gHistSSDCMModule[gHistCounter][iChip] = new TH1F(gTitle.Data(),
90 gTitle.Data(),
91 100,-50.,50.);
92 gHistSSDCMModule[gHistCounter][iChip]->GetXaxis()->SetTitle("CM");
93 list->Add(gHistSSDCMModule[gHistCounter][iChip]);
94 }
f5a5ae3e 95 gHistCounter += 1;
96 }
97
98 return list;
99}
100
101//__________________________________________________________//
102void makeCM(const char* filename, Int_t nEvents, TList *list) {
103 //Function to read the CM values
104 Int_t gStripNumber = 0;
105 Int_t gLayer = 0,gLadder = 0, gModule = 0;
106
107 //==================================================//
108 AliCDBManager *fCDBManager = AliCDBManager::Instance();
109 fCDBManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
110 Int_t runNumber = atoi(gSystem->Getenv("DATE_RUN_NUMBER"));
111 if(!runNumber)
112 Printf("DATE_RUN_NUMBER not defined!!!\n");
113
114 fCDBManager->SetRun(runNumber);
115 AliCDBEntry *geomGRP = fCDBManager->Get("GRP/Geometry/Data");
116 if(!geomGRP) cout<<"GRP geometry not found!!!"<<endl;;
117 //==================================================//
118
119 //==================================================//
af105157 120 TH2F *fHistPSideMeanCMMapLayer5 = new TH2F("fHistPSideMeanCMMapLayer5",
121 "Layer 5 - P side;N_{module};N_{ladder}",
122 22,1,23,
123 34,500,534);
124 fHistPSideMeanCMMapLayer5->GetXaxis()->SetTitleColor(1);
125 fHistPSideMeanCMMapLayer5->GetZaxis()->SetRangeUser(0.,20.);
126 fHistPSideMeanCMMapLayer5->SetStats(kFALSE);
127 fHistPSideMeanCMMapLayer5->GetYaxis()->SetTitleOffset(1.8);
128 fHistPSideMeanCMMapLayer5->GetXaxis()->SetNdivisions(22);
129 fHistPSideMeanCMMapLayer5->GetYaxis()->SetNdivisions(34);
130 fHistPSideMeanCMMapLayer5->GetXaxis()->SetLabelSize(0.03);
131 fHistPSideMeanCMMapLayer5->GetYaxis()->SetLabelSize(0.03);
132 fHistPSideMeanCMMapLayer5->GetZaxis()->SetTitleOffset(1.6);
133 fHistPSideMeanCMMapLayer5->GetZaxis()->SetTitle("RMS(CM) (p-side)");
134
135 TH2F *fHistNSideMeanCMMapLayer5 = new TH2F("fHistNSideMeanCMMapLayer5",
136 "Layer 5 - N side;N_{module};N_{ladder}",
137 22,1,23,
138 34,500,534);
139 fHistNSideMeanCMMapLayer5->GetXaxis()->SetTitleColor(1);
140 fHistNSideMeanCMMapLayer5->GetZaxis()->SetRangeUser(0.,20.);
141 fHistNSideMeanCMMapLayer5->SetStats(kFALSE);
142 fHistNSideMeanCMMapLayer5->GetYaxis()->SetTitleOffset(1.8);
143 fHistNSideMeanCMMapLayer5->GetXaxis()->SetNdivisions(22);
144 fHistNSideMeanCMMapLayer5->GetYaxis()->SetNdivisions(34);
145 fHistNSideMeanCMMapLayer5->GetXaxis()->SetLabelSize(0.03);
146 fHistNSideMeanCMMapLayer5->GetYaxis()->SetLabelSize(0.03);
147 fHistNSideMeanCMMapLayer5->GetZaxis()->SetTitleOffset(1.6);
148 fHistNSideMeanCMMapLayer5->GetZaxis()->SetTitle("RMS(CM) (n-side)");
149
150 TH2F *fHistPSideMeanCMMapLayer6 = new TH2F("fHistPSideMeanCMMapLayer6",
151 "Layer 6 - P side;N_{module};N_{ladder}",
152 25,1,26,
153 38,600,638);
154 fHistPSideMeanCMMapLayer6->GetXaxis()->SetTitleColor(1);
155 fHistPSideMeanCMMapLayer6->GetZaxis()->SetRangeUser(0.,20.);
156 fHistPSideMeanCMMapLayer6->SetStats(kFALSE);
157 fHistPSideMeanCMMapLayer6->GetYaxis()->SetTitleOffset(1.8);
158 fHistPSideMeanCMMapLayer6->GetXaxis()->SetNdivisions(25);
159 fHistPSideMeanCMMapLayer6->GetYaxis()->SetNdivisions(38);
160 fHistPSideMeanCMMapLayer6->GetXaxis()->SetLabelSize(0.03);
161 fHistPSideMeanCMMapLayer6->GetYaxis()->SetLabelSize(0.03);
162 fHistPSideMeanCMMapLayer6->GetZaxis()->SetTitleOffset(1.6);
163 fHistPSideMeanCMMapLayer6->GetZaxis()->SetTitle("RMS(CM) (p-side)");
164
165 TH2F *fHistNSideMeanCMMapLayer6 = new TH2F("fHistNSideMeanCMMapLayer6",
166 "Layer 6 - N side;N_{module};N_{ladder}",
167 25,1,26,
168 38,600,638);
169 fHistNSideMeanCMMapLayer6->GetXaxis()->SetTitleColor(1);
170 fHistNSideMeanCMMapLayer6->GetZaxis()->SetRangeUser(0.,20.);
171 fHistNSideMeanCMMapLayer6->SetStats(kFALSE);
172 fHistNSideMeanCMMapLayer6->GetYaxis()->SetTitleOffset(1.8);
173 fHistNSideMeanCMMapLayer6->GetXaxis()->SetNdivisions(25);
174 fHistNSideMeanCMMapLayer6->GetYaxis()->SetNdivisions(38);
175 fHistNSideMeanCMMapLayer6->GetXaxis()->SetLabelSize(0.03);
176 fHistNSideMeanCMMapLayer6->GetYaxis()->SetLabelSize(0.03);
177 fHistNSideMeanCMMapLayer6->GetZaxis()->SetTitleOffset(1.6);
178 fHistNSideMeanCMMapLayer6->GetZaxis()->SetTitle("RMS(CM) (n-side)");
179
180 //____________________________________________________________//
181 TH2F *fHistPSideRMSCMMapLayer5 = new TH2F("fHistPSideRMSCMMapLayer5",
f5a5ae3e 182 "Layer 5 - P side;N_{module};N_{ladder}",
183 22,1,23,
184 34,500,534);
af105157 185 fHistPSideRMSCMMapLayer5->GetXaxis()->SetTitleColor(1);
186 fHistPSideRMSCMMapLayer5->GetZaxis()->SetRangeUser(0.,20.);
187 fHistPSideRMSCMMapLayer5->SetStats(kFALSE);
188 fHistPSideRMSCMMapLayer5->GetYaxis()->SetTitleOffset(1.8);
189 fHistPSideRMSCMMapLayer5->GetXaxis()->SetNdivisions(22);
190 fHistPSideRMSCMMapLayer5->GetYaxis()->SetNdivisions(34);
191 fHistPSideRMSCMMapLayer5->GetXaxis()->SetLabelSize(0.03);
192 fHistPSideRMSCMMapLayer5->GetYaxis()->SetLabelSize(0.03);
193 fHistPSideRMSCMMapLayer5->GetZaxis()->SetTitleOffset(1.6);
194 fHistPSideRMSCMMapLayer5->GetZaxis()->SetTitle("RMS(CM) (p-side)");
195
196 TH2F *fHistNSideRMSCMMapLayer5 = new TH2F("fHistNSideRMSCMMapLayer5",
f5a5ae3e 197 "Layer 5 - N side;N_{module};N_{ladder}",
198 22,1,23,
199 34,500,534);
af105157 200 fHistNSideRMSCMMapLayer5->GetXaxis()->SetTitleColor(1);
201 fHistNSideRMSCMMapLayer5->GetZaxis()->SetRangeUser(0.,20.);
202 fHistNSideRMSCMMapLayer5->SetStats(kFALSE);
203 fHistNSideRMSCMMapLayer5->GetYaxis()->SetTitleOffset(1.8);
204 fHistNSideRMSCMMapLayer5->GetXaxis()->SetNdivisions(22);
205 fHistNSideRMSCMMapLayer5->GetYaxis()->SetNdivisions(34);
206 fHistNSideRMSCMMapLayer5->GetXaxis()->SetLabelSize(0.03);
207 fHistNSideRMSCMMapLayer5->GetYaxis()->SetLabelSize(0.03);
208 fHistNSideRMSCMMapLayer5->GetZaxis()->SetTitleOffset(1.6);
209 fHistNSideRMSCMMapLayer5->GetZaxis()->SetTitle("RMS(CM) (n-side)");
f5a5ae3e 210
af105157 211 TH2F *fHistPSideRMSCMMapLayer6 = new TH2F("fHistPSideRMSCMMapLayer6",
f5a5ae3e 212 "Layer 6 - P side;N_{module};N_{ladder}",
213 25,1,26,
214 38,600,638);
af105157 215 fHistPSideRMSCMMapLayer6->GetXaxis()->SetTitleColor(1);
216 fHistPSideRMSCMMapLayer6->GetZaxis()->SetRangeUser(0.,20.);
217 fHistPSideRMSCMMapLayer6->SetStats(kFALSE);
218 fHistPSideRMSCMMapLayer6->GetYaxis()->SetTitleOffset(1.8);
219 fHistPSideRMSCMMapLayer6->GetXaxis()->SetNdivisions(25);
220 fHistPSideRMSCMMapLayer6->GetYaxis()->SetNdivisions(38);
221 fHistPSideRMSCMMapLayer6->GetXaxis()->SetLabelSize(0.03);
222 fHistPSideRMSCMMapLayer6->GetYaxis()->SetLabelSize(0.03);
223 fHistPSideRMSCMMapLayer6->GetZaxis()->SetTitleOffset(1.6);
224 fHistPSideRMSCMMapLayer6->GetZaxis()->SetTitle("RMS(CM) (p-side)");
225
226 TH2F *fHistNSideRMSCMMapLayer6 = new TH2F("fHistNSideRMSCMMapLayer6",
f5a5ae3e 227 "Layer 6 - N side;N_{module};N_{ladder}",
228 25,1,26,
229 38,600,638);
af105157 230 fHistNSideRMSCMMapLayer6->GetXaxis()->SetTitleColor(1);
231 fHistNSideRMSCMMapLayer6->GetZaxis()->SetRangeUser(0.,20.);
232 fHistNSideRMSCMMapLayer6->SetStats(kFALSE);
233 fHistNSideRMSCMMapLayer6->GetYaxis()->SetTitleOffset(1.8);
234 fHistNSideRMSCMMapLayer6->GetXaxis()->SetNdivisions(25);
235 fHistNSideRMSCMMapLayer6->GetYaxis()->SetNdivisions(38);
236 fHistNSideRMSCMMapLayer6->GetXaxis()->SetLabelSize(0.03);
237 fHistNSideRMSCMMapLayer6->GetYaxis()->SetLabelSize(0.03);
238 fHistNSideRMSCMMapLayer6->GetZaxis()->SetTitleOffset(1.6);
239 fHistNSideRMSCMMapLayer6->GetZaxis()->SetTitle("RMS(CM) (n-side)");
f5a5ae3e 240 //==================================================//
241
242 TChain *chain = new TChain("RAW");
243 chain->Add(filename);
244 Int_t nTotalEvents = chain->GetEntries();
245 if(nEvents == -1) nEvents = nTotalEvents;
246
247 AliRawReaderRoot *rawReader = new AliRawReaderRoot(filename);
248 Int_t iEvent = 0;
249 Int_t fSSDEvent = 0;
250 for(iEvent = 0; iEvent < nEvents; iEvent++) {
251 cout<<"Event: "<<iEvent+1<<"/"<<nEvents<<endl;
252 rawReader->Select("ITSSSD",-1,-1);
253 rawReader->Reset();
254 rawReader->NextEvent();
255
256 if(rawReader->GetType() != 7) continue;
257
258 fSSDEvent += 1;
259 AliITSRawStreamSSD gSSDStream(rawReader);
260 while (gSSDStream.Next()) {
261 if(gSSDStream.GetModuleID() < 0) continue;
262 AliITSgeomTGeo::GetModuleId(gSSDStream.GetModuleID(),gLayer,gLadder,gModule);
263 //if(gSSDStream.GetModuleID() != 500) continue;
264 //Printf("Module id: %d - Layer: %d - Ladder: %d - Module: %d",gSSDStream.GetModuleID(),gLayer,gLadder,gModule);
265
266 if(gSSDStream.GetStrip() >= 0) continue;
267 gStripNumber = (gSSDStream.GetSideFlag() == 0) ? gSSDStream.GetStrip() : -gSSDStream.GetStrip() + 2*fgkNumberOfPSideStrips;
268 //Printf("Module id: %d - Strip: %d - strip number: %d - Signal: %lf",gSSDStream.GetModuleID(),gSSDStream.GetStrip(),gStripNumber,signal);
269 if(TMath::Abs(gSSDStream.GetStrip()) < 7)
af105157 270 ((TH1*)list->At((gSSDStream.GetModuleID()-500)*fgkNumOfChips+gSSDStream.GetStrip()))->Fill(gSSDStream.GetSignal());
f5a5ae3e 271 if(TMath::Abs(gSSDStream.GetStrip()) > 6)
e9ea501a 272 ((TH1*)list->At(fgkSSDMODULES*fgkNumOfChips+(gSSDStream.GetModuleID()-500)*fgkNumOfChips+gSSDStream.GetStrip()))->Fill(gSSDStream.GetSignal());
f5a5ae3e 273 }//streamer loop
274 }//event loop
275
276 //compute the rms of the CM values
af105157 277 TH1F *gHistCMDummy = new TH1F("gHistCMDummy","",100,-50.,50.);
278 Double_t meanPsideCM = 0.0, meanNsideCM = 0.0;
f5a5ae3e 279 Double_t rmsPsideCM = 0.0, rmsNsideCM = 0.0;
af105157 280 for(Int_t iModule = 0; iModule < fgkSSDMODULES; iModule++) {
281 meanPsideCM = 0.0; meanNsideCM = 0.0;
f5a5ae3e 282 rmsPsideCM = 0.0; rmsNsideCM = 0.0;
af105157 283 AliITSgeomTGeo::GetModuleId(iModule+500,gLayer,gLadder,gModule);
284
285 gHistCMDummy->Clear();
286 for(Int_t iChip = 0; iChip < fgkNumOfChips; iChip++) {
287 //cout<<"Name: "<<dynamic_cast<TH1*>(list->At(iModule*fgkNumOfChips+iChip))->GetName()<<endl;
288 gHistCMDummy->Add((TH1*)list->At(iModule*fgkNumOfChips+iChip));
289 }
290 meanPsideCM = TMath::Abs(gHistCMDummy->GetMean());
291 rmsPsideCM = gHistCMDummy->GetRMS();
292
293 gHistCMDummy->Clear();
294 for(Int_t iChip = 0; iChip < fgkNumOfChips; iChip++) {
295 //cout<<"Name: "<<dynamic_cast<TH1*>(list->At(fgkSSDMODULES*fgkNumOfChips+iModule*fgkNumOfChips+iChip))->GetName()<<endl;
296 gHistCMDummy->Add((TH1*)list->At(fgkSSDMODULES*fgkNumOfChips+iModule*fgkNumOfChips+iChip));
297 }
298 meanNsideCM = TMath::Abs(gHistCMDummy->GetMean());
299 rmsNsideCM = gHistCMDummy->GetRMS();
300
301 if(meanPsideCM == 0) meanPsideCM = 0.001;
302 if(meanNsideCM == 0) meanNsideCM = 0.001;
f5a5ae3e 303 if(rmsPsideCM == 0) rmsPsideCM = 0.001;
304 if(rmsNsideCM == 0) rmsNsideCM = 0.001;
af105157 305
f5a5ae3e 306 if(gLayer == 5) {
af105157 307 fHistPSideMeanCMMapLayer5->SetBinContent(gModule,gLadder,meanPsideCM);
308 fHistNSideMeanCMMapLayer5->SetBinContent(gModule,gLadder,meanNsideCM);
309 fHistPSideRMSCMMapLayer5->SetBinContent(gModule,gLadder,rmsPsideCM);
310 fHistNSideRMSCMMapLayer5->SetBinContent(gModule,gLadder,rmsNsideCM);
f5a5ae3e 311 }
312 if(gLayer == 6) {
af105157 313 fHistPSideMeanCMMapLayer6->SetBinContent(gModule,gLadder,meanPsideCM);
314 fHistNSideMeanCMMapLayer6->SetBinContent(gModule,gLadder,meanNsideCM);
315 fHistPSideRMSCMMapLayer6->SetBinContent(gModule,gLadder,rmsPsideCM);
316 fHistNSideRMSCMMapLayer6->SetBinContent(gModule,gLadder,rmsNsideCM);
f5a5ae3e 317 }
318 }
319
320 TFile *foutput = TFile::Open("SSD.CM.root","recreate");
321 list->Write();
af105157 322 fHistPSideMeanCMMapLayer5->Write(); fHistNSideMeanCMMapLayer5->Write();
323 fHistPSideMeanCMMapLayer6->Write(); fHistNSideMeanCMMapLayer6->Write();
324 fHistPSideRMSCMMapLayer5->Write(); fHistNSideRMSCMMapLayer5->Write();
325 fHistPSideRMSCMMapLayer6->Write(); fHistNSideRMSCMMapLayer6->Write();
f5a5ae3e 326 foutput->Close();
327}
328
329//__________________________________________________________//
330void drawSSDCM(const char* filename = "SSD.CM.root") {
331 gStyle->SetPalette(1,0);
332
333 TFile *f = TFile::Open(filename);
334
af105157 335 TCanvas *c1 = new TCanvas("c1","Mean of CM values",0,0,700,650);
f5a5ae3e 336 c1->SetFillColor(10); c1->SetHighLightColor(10); c1->Divide(2,2);
337 c1->cd(1);
af105157 338 TH2F *fHistPSideMeanCMMapLayer5 = dynamic_cast<TH2F *>(f->Get("fHistPSideMeanCMMapLayer5"));
339 fHistPSideMeanCMMapLayer5->Draw("colz");
f5a5ae3e 340 c1->cd(2);
af105157 341 TH2F *fHistNSideMeanCMMapLayer5 = dynamic_cast<TH2F *>(f->Get("fHistNSideMeanCMMapLayer5"));
342 fHistNSideMeanCMMapLayer5->Draw("colz");
f5a5ae3e 343 c1->cd(3);
af105157 344 TH2F *fHistPSideMeanCMMapLayer6 = dynamic_cast<TH2F *>(f->Get("fHistPSideMeanCMMapLayer6"));
345 fHistPSideMeanCMMapLayer6->Draw("colz");
f5a5ae3e 346 c1->cd(4);
af105157 347 TH2F *fHistNSideMeanCMMapLayer6 = dynamic_cast<TH2F *>(f->Get("fHistNSideMeanCMMapLayer6"));
348 fHistNSideMeanCMMapLayer6->Draw("colz");
349
350 TCanvas *c2 = new TCanvas("c2","RMS of CM values",100,100,700,650);
351 c2->SetFillColor(10); c2->SetHighLightColor(10); c2->Divide(2,2);
352 c2->cd(1);
353 TH2F *fHistPSideRMSCMMapLayer5 = dynamic_cast<TH2F *>(f->Get("fHistPSideRMSCMMapLayer5"));
354 fHistPSideRMSCMMapLayer5->Draw("colz");
355 c2->cd(2);
356 TH2F *fHistNSideRMSCMMapLayer5 = dynamic_cast<TH2F *>(f->Get("fHistNSideRMSCMMapLayer5"));
357 fHistNSideRMSCMMapLayer5->Draw("colz");
358 c2->cd(3);
359 TH2F *fHistPSideRMSCMMapLayer6 = dynamic_cast<TH2F *>(f->Get("fHistPSideRMSCMMapLayer6"));
360 fHistPSideRMSCMMapLayer6->Draw("colz");
361 c2->cd(4);
362 TH2F *fHistNSideRMSCMMapLayer6 = dynamic_cast<TH2F *>(f->Get("fHistNSideRMSCMMapLayer6"));
363 fHistNSideRMSCMMapLayer6->Draw("colz");
f5a5ae3e 364}
a56fec3e 365
366//__________________________________________________________//
367void checkCM(const char* filename) {
368 //Reads the SSD.CM.root file as an input.
369 //For every chip checks the mean and the rms of the CM distributions.
370 //If the absolute value of the mean is beyond 5 ADC counts or/and the
371 //rms is beyond 10, the corresponding histogram is added to the list
372 //of suspicious chips. This list is written to the output file having
373 //the name: SSD.FaultyChips.root
374
375 //Hardcoded check values
376 const Double_t meanMax = 5.;
377 const Double_t rmsMax = 10.;
378
379 //output list
380 TList *listOfSuspiciousChips = new TList();
381
382 //Input file
383 TFile *fInput = TFile::Open(filename);
384
385 Int_t gLayer = 0,gLadder = 0, gModule = 0;
386 TString gTitle;
387 //Double_t meanValue = 0.0, rmsValue = 0.0;
388 TH1F *gHistSSDCMModule = 0x0;
389 //P-side
390 for(Int_t iModule = 500; iModule < fgkSSDMODULES + 500; iModule++) {
391 AliITSgeomTGeo::GetModuleId(iModule,gLayer,gLadder,gModule);
392 for(Int_t iChip = 0; iChip < fgkNumOfChips; iChip++) {
393 gTitle = "SSD_CM_PSide_Layer"; gTitle += gLayer;
394 gTitle += "_Ladder"; gTitle += gLadder;
395 gTitle += "_Module"; gTitle += gModule;
396 gTitle += "_Chip"; gTitle += iChip+1;
397 gHistSSDCMModule = dynamic_cast<TH1F *>(fInput->Get(gTitle.Data()));
398 if((TMath::Abs(gHistSSDCMModule->GetMean(1)) > meanMax)||
399 (TMath::Abs(gHistSSDCMModule->GetRMS(1)) > rmsMax)) {
400 Printf("Name: %s, Mean: %lf - rms: %lf",
401 gHistSSDCMModule->GetName(),
402 TMath::Abs(gHistSSDCMModule->GetMean(1)),
403 TMath::Abs(gHistSSDCMModule->GetRMS(1)));
404 listOfSuspiciousChips->Add(gHistSSDCMModule);
405 }
406 }//chip loop
407 }//module loop
408
409 //N-side
410 for(Int_t iModule = 500; iModule < fgkSSDMODULES + 500; iModule++) {
411 AliITSgeomTGeo::GetModuleId(iModule,gLayer,gLadder,gModule);
412 for(Int_t iChip = 0; iChip < fgkNumOfChips; iChip++) {
413 gTitle = "SSD_CM_NSide_Layer"; gTitle += gLayer;
414 gTitle += "_Ladder"; gTitle += gLadder;
415 gTitle += "_Module"; gTitle += gModule;
416 gTitle += "_Chip"; gTitle += iChip+1;
417 gHistSSDCMModule = dynamic_cast<TH1F *>(fInput->Get(gTitle.Data()));
418 if((TMath::Abs(gHistSSDCMModule->GetMean(1)) > meanMax)||
419 (TMath::Abs(gHistSSDCMModule->GetRMS(1)) > rmsMax)) {
420 Printf("Name: %s, Mean: %lf - rms: %lf",
421 gHistSSDCMModule->GetName(),
422 TMath::Abs(gHistSSDCMModule->GetMean(1)),
423 TMath::Abs(gHistSSDCMModule->GetRMS(1)));
424 listOfSuspiciousChips->Add(gHistSSDCMModule);
425 }
426 //Printf("Name: %s",gHistSSDCMModule->GetName());
427 }//chip loop
428 }//module loop
429
430 Printf("===============================================");
431 Printf("%d suspicious chips were put in the list",
432 listOfSuspiciousChips->GetEntries());
433 Printf("===============================================");
434 TFile *fOutput = new TFile("SSD.FaultyChips.root","recreate");
435 listOfSuspiciousChips->Write();
436 fOutput->Close();
437
438 fInput->Close();
439}
b093e9a0 440
441//__________________________________________________________//
442void compareChipLists(TString inputFile1,
443 TString inputFile2,
444 TString outputTxt){
445 //Compare two different lists of chips and put those present in both files
446 //in a new list
447 //open input lists
448 TFile *fInput1 = TFile::Open(inputFile1.Data());
449 TList *listOfSuspiciousChips1 = new TList();
450 listOfSuspiciousChips1=fInput1->GetListOfKeys();
451 TFile *fInput2 = TFile::Open(inputFile2.Data());
452 TList *listOfSuspiciousChips2 = new TList();
453 listOfSuspiciousChips2=fInput2->GetListOfKeys();
454
455 Int_t Nentries1 = 0, Nentries2 = 0, k = 0;
456 Nentries1 = listOfSuspiciousChips1->GetEntries();
457 Nentries2 = listOfSuspiciousChips2->GetEntries();
458
459 //create new list
460 TList *listOfRecurrentChips = new TList();
461 TString Name1;
462
463 for(Int_t i=0; i<Nentries1; i++){
464 TH1F *h1 = dynamic_cast <TH1F*>(fInput1->Get(listOfSuspiciousChips1->At(i)->GetName()));
465 for(Int_t j=0; j<Nentries2; j++){
466 TH1F *h2 = dynamic_cast <TH1F*>(fInput2->Get(listOfSuspiciousChips2->At(j)->GetName()));
467 Name1=h1->GetName();
468 if (!Name1.CompareTo(h2->GetName())) {
469 cout << Name1.CompareTo(h2->GetName()) <<
470 " " << h2->GetName() << endl;
471 k++;
472 listOfRecurrentChips->Add(h1);
473 }
474 }//second file loop
475 }//first file loop
476
477 Printf("%i Faulty chips in the first file", Nentries1);
478 Printf("%i Faulty chips in the second file", Nentries2);
479 Printf("%i Recurrent Faulty chips", k+1);
480
481 TString outputFile = "SSD.RecurrentFaultyChips."; outputFile += outputTxt;
482 outputFile += ".root";
483
484 TFile *fOutput = new TFile(outputFile.Data(),"recreate");
485 listOfRecurrentChips->Write();
486 fOutput->Close();
487
488 fInput1->Close();
489 fInput2->Close();
490}
e9ea501a 491
492//__________________________________________________________//
493void makeCM2D(const char* filename, Int_t nEvents) {
494 //Function to read the CM values
495 gStyle->SetPalette(1,0);
496 Int_t gStripNumber = 0;
497 Int_t gLayer = 0,gLadder = 0, gModule = 0;
498
499 //==================================================//
500 AliCDBManager *fCDBManager = AliCDBManager::Instance();
501 fCDBManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
502 Int_t runNumber = atoi(gSystem->Getenv("DATE_RUN_NUMBER"));
503 if(!runNumber)
504 Printf("DATE_RUN_NUMBER not defined!!!\n");
505
506 fCDBManager->SetRun(runNumber);
507 AliCDBEntry *geomGRP = fCDBManager->Get("GRP/Geometry/Data");
508 if(!geomGRP) cout<<"GRP geometry not found!!!"<<endl;;
509 //==================================================//
510
511 //==================================================//
512 TList *list = new TList();
513 TH2F *gHistCM2D[fgkSSDMODULES];
514 TString gHistoTitle, gArrayTitle;
515 Int_t gHistCounter = 0;
516 for(Int_t iModule = 500; iModule < fgkSSDMODULES + 500; iModule++) {
517 AliITSgeomTGeo::GetModuleId(iModule,gLayer,gLadder,gModule);
518 gHistoTitle = "SSD_CM_Layer"; gHistoTitle += gLayer;
519 gHistoTitle += "_Ladder"; gHistoTitle += gLadder;
520 gHistoTitle += "_Module"; gHistoTitle += gModule;
521 //Printf("Title: %s",gHistoTitle.Data());
522 gHistCM2D[gHistCounter] = new TH2F(gHistoTitle.Data(),
523 gHistoTitle.Data(),
524 12,0.5,12.5,
525 120,-60.,60.);
526 gHistCM2D[gHistCounter]->SetStats(kFALSE);
527 gHistCM2D[gHistCounter]->GetXaxis()->SetTitleColor(1);
528 gHistCM2D[gHistCounter]->GetZaxis()->SetTitle("Entries");
529 gHistCM2D[gHistCounter]->GetYaxis()->SetTitle("CM");
530 gHistCM2D[gHistCounter]->GetXaxis()->SetTitle("Chip number");
531 gHistCM2D[gHistCounter]->GetXaxis()->SetNdivisions(12);
532 list->Add(gHistCM2D[gHistCounter]);
533 gHistCounter += 1;
534 }
535 //Printf("List entries: %d",list->GetEntries());
536 //==================================================//
537
538 TChain *chain = new TChain("RAW");
539 chain->Add(filename);
540 Int_t nTotalEvents = chain->GetEntries();
541 if(nEvents == -1) nEvents = nTotalEvents;
542
543 AliRawReaderRoot *rawReader = new AliRawReaderRoot(filename);
544 Int_t iEvent = 0;
545 Int_t fSSDEvent = 0;
546 for(iEvent = 0; iEvent < nEvents; iEvent++) {
547 cout<<"Event: "<<iEvent+1<<"/"<<nEvents<<endl;
548 rawReader->Select("ITSSSD",-1,-1);
549 rawReader->Reset();
550 rawReader->NextEvent();
551
552 if(rawReader->GetType() != 7) continue;
553
554 fSSDEvent += 1;
555 AliITSRawStreamSSD gSSDStream(rawReader);
556 while (gSSDStream.Next()) {
557 if(gSSDStream.GetModuleID() < 0) continue;
558 AliITSgeomTGeo::GetModuleId(gSSDStream.GetModuleID(),gLayer,gLadder,gModule);
559 //if(gSSDStream.GetModuleID() != 500) continue;
560 //Printf("Module id: %d - Layer: %d - Ladder: %d - Module: %d",gSSDStream.GetModuleID(),gLayer,gLadder,gModule);
561
562 if(gSSDStream.GetStrip() >= 0) continue;
563 gStripNumber = (gSSDStream.GetSideFlag() == 0) ? gSSDStream.GetStrip() : -gSSDStream.GetStrip() + 2*fgkNumberOfPSideStrips;
564 //Printf("Module id: %d - Strip: %d - strip number: %d - Signal: %lf",gSSDStream.GetModuleID(),gSSDStream.GetStrip(),gStripNumber,gSSDStream.GetSignal());
565 gHistCM2D[gSSDStream.GetModuleID()-500]->Fill(TMath::Abs(gSSDStream.GetStrip()),gSSDStream.GetSignal());
566 }//streamer loop
567 }//event loop
568
569 TCanvas *cLayer5[34];
570 TCanvas *cLayer6[38];
571 TString canvasTitle;
572 for(Int_t iLadder = 1; iLadder < 35; iLadder++) {
573 canvasTitle = "SSD_CM_Layer5_Ladder"; canvasTitle += iLadder;
574 cLayer5[iLadder-1] = new TCanvas(canvasTitle.Data(),
575 canvasTitle.Data());
576 cLayer5[iLadder-1]->Divide(5,5);
577 for(Int_t iModule = 1; iModule < 23; iModule++) {
578 cLayer5[iLadder-1]->cd(iModule);
579 gHistCM2D[(iLadder-1)*fgkSSDMODULESPERLADDERLAYER5 + iModule - 1]->Draw("colz");
580 }
581 if(iLadder == 1) cLayer5[iLadder-1]->Print("CommonModePlotsLayer5.ps(");
582 if(iLadder == 34) cLayer5[iLadder-1]->Print("CommonModePlotsLayer5.ps)");
583 else cLayer5[iLadder-1]->Print("CommonModePlotsLayer5.ps");
584 //Printf("Ladder %d finished...",499+iLadder);
585 }
586
587 for(Int_t iLadder = 1; iLadder < 39; iLadder++) {
588 canvasTitle = "SSD_CM_Layer6_Ladder"; canvasTitle += iLadder;
589 cLayer6[iLadder-1] = new TCanvas(canvasTitle.Data(),
590 canvasTitle.Data());
591 cLayer6[iLadder-1]->Divide(5,5);
592 for(Int_t iModule = 1; iModule < 26; iModule++) {
593 cLayer6[iLadder-1]->cd(iModule);
594 gHistCM2D[fgkSSDMODULESLAYER5 + (iLadder-1)*fgkSSDMODULESPERLADDERLAYER6 + iModule - 1]->Draw("colz");
595 }
596 if(iLadder == 1) cLayer6[iLadder-1]->Print("CommonModePlotsLayer6.ps(");
597 if(iLadder == 38) cLayer6[iLadder-1]->Print("CommonModePlotsLayer6.ps)");
598 else cLayer6[iLadder-1]->Print("CommonModePlotsLayer6.ps");
599 //Printf("Ladder %d finished...",599+iLadder);
600 }
601
602
603 TFile *foutput = TFile::Open("SSD.CM2D.root","recreate");
604 list->Write();
605 foutput->Close();
606}
607