1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 // By Ch. Finck, Subatech
20 #if !defined(__CINT__) || defined(__MAKECINT__)
22 #include <Riostream.h>
29 #include "TObjArray.h"
30 #include "TObjString.h"
32 #include "AliCDBManager.h"
33 #include "AliMpHelper.h"
34 #include "AliMpConstants.h"
35 #include "AliMpDEIterator.h"
36 #include "AliMpIntPair.h"
37 #include "AliMpFiles.h"
38 #include "AliMpSegmentation.h"
39 #include "AliMpVSegmentation.h"
40 #include "AliMpDEManager.h"
41 #include "AliMpDetElement.h"
42 #include "AliMpDDLStore.h"
47 const Int_t kStrangeBin = 26;
48 const Int_t kUndefBin = 36;
49 const Int_t kBadCalBin = 46;
50 const Int_t kBadBin = 5;
52 const Int_t kNotScanSerial = 40000;
54 void MUONCheckManu(Int_t iCh = 10, Bool_t rootFile = kFALSE)
57 // Macro to check the bin number for manu in the CDB for each chamber
58 // chamber = 0 means all chambers
59 // The normal bin number ranges from 0-4.
60 // the abnormal bin number are as follow:
62 // 35 ->undefined to be re-tested,
64 // 5-10 -> reading error on manu.
65 // cath: 0 -> bending, 1 -> non-bending
68 static Int_t nBad = 0;
69 static Int_t nBadS = 0;
70 static Int_t nBadU = 0;
72 static Int_t nManu = 0;
73 static Int_t badDE = 0;
77 if ( !AliMpCDB::LoadMpSegmentation() ) {
78 printf("Could not access mapping from OCDB !\n");
82 if ( !AliMpCDB::LoadDDLStore() ) {
83 printf("Could not access DDL Store from OCDB !\n");
86 AliMpDDLStore* ddlStore = AliMpDDLStore::Instance();
89 TExMap serialNbtoBinId;
90 TExMap serialNbtoGain;
93 char fileNameOut[255];
94 sprintf(fileNameOut,"serial_number_%d.dat",iCh);
96 char fileNameOut1[255];
97 sprintf(fileNameOut1,"serial_number_bad_%d.dat",iCh);
101 TFile* fileOut = 0x0;
104 sprintf(histoFile,"GainDE_%d.root",iCh);
105 fileOut = new TFile(histoFile,"RECREATE","DE manu gain");
109 fileNameIn = AliMpFiles::SerialToBinFilePath();
111 ifstream in(fileNameIn, ios::in);
112 if (!in) printf("file %s not found\n", fileNameIn.Data());
114 ofstream out(fileNameOut, ios::out);
116 ofstream out1(fileNameOut1, ios::out);
120 Int_t manuSerial = 0;
124 while ( in.getline(line,255) ) {
126 if ( line[0] == '#' ) continue;
127 if ( line[0] == '\n' ) continue;
128 if ( line[0] == '\0' ) continue;
130 TString tmp(AliMpHelper::Normalize(line));
132 TObjArray* stringList = tmp.Tokenize(TString(" "));
134 TString sSM = ((TObjString*)stringList->At(2))->GetString();
136 TString sBin = ((TObjString*)stringList->At(4))->GetString();
138 TString sGain = ((TObjString*)stringList->At(6))->GetString();
140 manuSerial = atoi(sSM.Data());
141 binId = atoi(sBin.Data()) + 1;
143 if (sBin.CompareTo("S") == 0) {
147 if (sBin.CompareTo("I") == 0) {
151 if (sBin.CompareTo("C") == 0) {
155 gain = atof(sGain.Data());
156 //printf("%s %d %s %d %s %f\n", sSM.Data(), manuSerial, sBin.Data(), binId, sGain.Data(), gain);
161 // to avoid that a manu that is at the same time in a normal bin and in a bin S, stays in bin S
162 if (serialNbtoBinId.GetValue(manuSerial) != 0 && binId == kStrangeBin)
166 if (serialNbtoBinId.GetValue(manuSerial) != 0) {
167 serialNbtoBinId.Remove((Long_t)manuSerial);
168 serialNbtoGain.Remove((Long_t)manuSerial);
172 serialNbtoBinId.Add((Long_t)manuSerial, (Long_t)binId);
173 serialNbtoGain.Add((Long_t)manuSerial, (Long_t)(gain*100000));
182 // // iterates over DE
189 out1 << "Bin:" << endl;
190 out1 << " 25 -> Strange, 35 -> re-tested, 45 -> bad calib0" << endl;
191 out1 << " >= 5 error id, 10 -> 1" << endl;
192 out1 << "cath: 0 -> bending, 1 -> non-bending" << endl;
195 TH1F* hslat_manu_bp[1100];
196 TH1F* hslat_manu_nbp[1100];
198 TH1F* hCh_manu_bp[11];
199 TH1F* hCh_manu_nbp[11];
201 static TH1F* hAll_manu_bp;
202 static TH1F* hAll_manu_nbp;
203 static TH1F* hAll_manu;
210 sprintf(name,"hAll_manu_bp");
211 sprintf(title,"MANU gain total for bending");
212 hAll_manu_bp = new TH1F(name,title,300,1.5,5.0);
213 hAll_manu_bp->SetDirectory(fileOut);
215 sprintf(name,"hAll_manu_npb");
216 sprintf(title,"MANU gain total for non-bending");
217 hAll_manu_nbp = new TH1F(name,title,300,1.5,5.0);
218 hAll_manu_nbp->SetDirectory(fileOut);
220 sprintf(name,"hAll_manu");
221 sprintf(title,"MANU gain total");
222 hAll_manu = new TH1F(name,title,300,1.5,5.0);
223 hAll_manu->SetDirectory(fileOut);
225 sprintf(name,"hBin_DE");
226 sprintf(title,"DE versus Bin");
227 hBin_DE = new TH2F(name,title,5,0,5, 1100, 1, 1100);
228 hBin_DE->SetDirectory(fileOut);
230 sprintf(name,"hBin_S");
231 sprintf(title,"Bin_S");
232 hBinS = new TH1F(name,title, 300, 600, 1100);
233 hBinS->SetDirectory(fileOut);
247 for (iCh = begCh; iCh < endCh; ++iCh) {
251 sprintf(name,"hCh_manu_bp_CH%d", iCh);
252 sprintf(title,"MANU gain total for CH%d bending", iCh);
253 hCh_manu_bp[iCh] = new TH1F(name,title,300,1.5,5.0);
254 hCh_manu_bp[iCh]->SetDirectory(fileOut);
256 sprintf(name,"hCh_manu_nbp_CH%d", iCh);
257 sprintf(title,"MANU gain total for CH%d non-bending", iCh);
258 hCh_manu_nbp[iCh] = new TH1F(name,title,300,1.5,5.0);
259 hCh_manu_nbp[iCh]->SetDirectory(fileOut);
262 for ( it.First(iCh-1); ! it.IsDone(); it.Next() ) {
265 Int_t iDE = it.CurrentDE()->GetId();
267 AliMpDetElement* detElem = AliMpDEManager::GetDetElement(iDE);
268 TString nameDE = detElem->GetDEName();
271 out << " DE: " << iDE << endl;
272 out << "manuId serial binId" << endl;
275 out1 << " DE: " << iDE << " name: " << nameDE.Data() << endl;
276 out1 << "manuId serial binId cath" << endl;
278 printf("\nDE:%d\n", iDE);
282 sprintf(name,"hslat_manu_bp%d",iDE);
283 sprintf(title,"MANU gain for DE %d bending",iDE);
284 hslat_manu_bp[iDE] = new TH1F(name,title,300,1.5,4.5);
285 hslat_manu_bp[iDE]->SetDirectory(fileOut);
287 sprintf(name,"hslat_manu_nbp%d",iDE);
288 sprintf(title,"MANU gain for DE %d non-bending",iDE);
289 hslat_manu_nbp[iDE] = new TH1F(name,title,300,1.5,4.5);
290 hslat_manu_nbp[iDE]->SetDirectory(fileOut);
295 for ( Int_t cath = 0; cath <=1 ; ++cath ) {
296 const AliMpVSegmentation* seg
297 = AliMpSegmentation::Instance()->GetMpSegmentation(iDE,AliMp::GetCathodType(cath));
301 seg->GetAllElectronicCardIDs(manus);
304 for ( Int_t im = 0; im < manus.GetSize(); ++im ) {
305 AliMpIntPair* manu = 0x0;
306 if (manus[im] > AliMpConstants::ManuMask(AliMp::kNonBendingPlane))
307 manu = new AliMpIntPair(manus[im], 1, kTRUE);
309 manu = new AliMpIntPair(manus[im], 0, kTRUE);
319 for (Int_t iEntry = 0; iEntry < manuList.GetEntries(); ++iEntry) {
320 AliMpIntPair* manuPtr = (AliMpIntPair*)manuList.At(iEntry);
322 AliMpDetElement* detElem = ddlStore->GetDetElement(iDE);
323 manuSerial = detElem->GetManuSerialFromId(manuPtr->GetFirst());
325 binId = (Int_t)serialNbtoBinId.GetValue(manuSerial);
326 if (manuSerial == 0) {
327 printf("manu %d not found in mapping\n",manuPtr->GetFirst());
334 printf("Bin for manu %d with serial %d not available\n",manuPtr->GetFirst(), manuSerial);
336 if (binId > kBadBin && binId < kStrangeBin)
337 printf("Bin for manu %d with serial %d is bad\n",manuPtr->GetFirst(), manuSerial);
339 if (binId == kStrangeBin)
340 printf("Bin for manu %d with serial %d is strange\n",manuPtr->GetFirst(), manuSerial);
342 if (binId == kUndefBin)
343 printf("Bin for manu %d with serial %d is unidentified\n",manuPtr->GetFirst(), manuSerial);
345 gain = (Float_t)(serialNbtoGain.GetValue(manuSerial)/100000.);
347 out << setw(4) << ( manuPtr->GetFirst() & 0x3FF) << " " << setw(5) << manuSerial
348 << " " << setw(2) << binId-1 << " " << manuPtr->GetSecond()
349 << " " << setw(7) << gain << endl;
352 if ((binId == 0 || binId == kUndefBin) && manuSerial < kNotScanSerial) nBadU++;
353 if (binId == 0 && manuSerial >= kNotScanSerial) nDB++;
355 // check whether serial number appears twice
356 if (serial.GetValue(manuSerial) == 0)
357 serial.Add((Long_t)manuSerial, (Long_t)binId);
359 out1 << setw(4) << ( manuPtr->GetFirst() & 0x3FF) << " " << setw(5) << manuSerial
360 << " " << setw(2) << binId-1 << " " << manuPtr->GetSecond()
361 << " " << setw(7) << gain << " Serial number Twice" << endl;
364 // count bad/strange manus
365 if (!binId || binId > kBadBin) {
366 if (binId == kStrangeBin) nBadS++;
367 if (binId > kBadBin) {
372 out1 << setw(4) << ( manuPtr->GetFirst() & 0x3FF) << " " << setw(5) << manuSerial
373 << " " << setw(2) << binId-1 << " " << manuPtr->GetSecond()
374 << " " << setw(7) << gain << endl;
377 if (rootFile && binId == kStrangeBin)
380 if (rootFile && binId != kStrangeBin) {
381 hAll_manu->Fill(gain);
382 hBin_DE->Fill(binId-1, iDE);
384 if(manuPtr->GetSecond()) {
385 hslat_manu_nbp[iDE]->Fill(gain);
386 hAll_manu_nbp->Fill(gain);
387 hCh_manu_nbp[iCh]->Fill(gain);
389 hslat_manu_bp[iDE]->Fill(gain);
390 hAll_manu_bp->Fill(gain);
391 hCh_manu_bp[iCh]->Fill(gain);
404 serialNbtoBinId.Delete();
405 serialNbtoGain.Delete();
416 printf("Number of bad manus %d and strange manus %d total %d\n", nBad, nBadS, nManu);
417 printf("Number of unidentified manus %d\n", nBadU);
418 printf("Number of manus not scanned %d\n", nDB);
419 printf("Number of bad DE %d\n", badDE);