]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/macros/OADB/CompareAODB_OCDB.C
a5b8f5f0876cb2774c11f1d5c2c447edc7052116
[u/mrichter/AliRoot.git] / EMCAL / macros / OADB / CompareAODB_OCDB.C
1 // Compare the contents of the calibration, bad channels, etc in OCDB and AODB
2 // You need connexion to the grid to run this macro
3 // The OADB file can be in a place different than the default in aliroot
4
5 // Author : Gustavo Conesa Balbastre (LPSC-CNRS)
6
7 void CompareAODB_OCDB(Int_t run = 153323, TString pathOADB = "$ALICE_ROOT/OADB/EMCAL",
8                       Int_t checkObject = 1, TString pass = "pass1", Bool_t printAll = kFALSE)
9 {  
10
11   gSystem->Load("libOADB");
12   TGrid::Connect("alien://");
13   
14   AliCDBManager* man = AliCDBManager::Instance();
15   man->SetDefaultStorage("raw://");
16   man->SetRun(run);
17   AliCDBStorage *storage = man->GetDefaultStorage();
18   
19   // Instantiate EMCAL geometry for the first time
20
21   
22   if     (run < 140000) geom = AliEMCALGeometry::GetInstance("EMCAL_FIRSTYEARV1"); // 2010
23   else if(run < 198000) geom = AliEMCALGeometry::GetInstance("EMCAL_COMPLETEV1");  // 2011-2012-2013
24   else                  geom = AliEMCALGeometry::GetInstance("EMCAL_COMPLETE12SMV1_DCAL_8SM"); // Run2
25   
26   if     (checkObject == 0) CheckBadChannels      (run, pathOADB, storage, geom,     printAll);
27   else if(checkObject == 1) CheckEnergyCalibration(run, pathOADB, storage, geom,pass,printAll);
28   else if(checkObject == 2) CheckTimeCalibration  (run, pathOADB, storage, geom,pass,printAll);
29   else printf("non existing object option\n");
30   
31   printf("*** Comparisons ended *** \n");
32 }  
33
34 //___________________________
35 void CheckEnergyCalibration(Int_t run, TString pathOADB, AliCDBStorage * storage, AliEMCALGeometry *geom,
36                             TString pass,Bool_t printAll = kTRUE)
37 {
38   // Check energy recalibration, Uncomplete
39   
40   AliOADBContainer *contRF=new AliOADBContainer("");
41   contRF->InitFromFile(Form("%s/EMCALRecalib.root",pathOADB.Data()),"AliEMCALRecalib");
42   
43   const Int_t nSM = geom->GetNumberOfSuperModules();
44   
45   // Get the OCDB object
46   
47   AliEMCALCalibData* cparam = (AliEMCALCalibData*) (storage->Get("EMCAL/Calib/Data", run)->GetObject());
48
49 //  // Access directly the OCDB file and not the latest version
50 //  TFile * f = TFile::Open("alien:///alice/data/2011/OCDB/EMCAL/Calib/Data/Run144484_999999999_v2_s0.root","READ");
51 //  AliCDBEntry * cdb = (AliCDBEntry*) f->Get("AliCDBEntry");
52 //  AliEMCALCalibData* cparam2 = (AliEMCALCalibData*)  cdb->GetObject();
53
54   // Get the OADB object
55   
56   TH2F *h[12];
57   
58   TObjArray *recal=(TObjArray*)contRF->GetObject(run);
59   
60   if(!recal)
61   {
62     printf("Energy recalibration OADB not found  3\n");
63     return;
64   }
65   
66   TObjArray *recalpass=(TObjArray*)recal->FindObject(pass);
67   
68   if(!recalpass)
69   {
70     printf("Energy recalibration OADB not found 2\n");
71     return;
72   }
73   
74   TObjArray *recalib=(TObjArray*)recalpass->FindObject("Recalib");
75   
76   if(!recalib)
77   {
78     printf("Energy recalibration OADB not found 1\n");
79     return;
80   }
81   
82   for (Int_t i=0; i < nSM; ++i)
83   {
84     h[i] = (TH2F*)recalib->FindObject(Form("EMCALRecalFactors_SM%d",i));
85     if (!h[i])
86     {
87       AliError(Form("Could not load EMCALRecalFactors_SM%d",i));
88       continue;
89     }
90   }
91   
92   // Do the comparison
93   Float_t paramOCDB = -1;
94   Float_t paramAODB = -1;
95   Int_t nDiff = 0;
96 //  Int_t nDiff2 = 0;
97   Int_t iCol = -1, iRow = -1, iSM =-1, iMod = -1,iIphi =-1,iIeta = -1;
98   for(Int_t i=0;i < nSM*24*48; i++)
99   {
100     //printf("AbsID %d\n",i);
101     geom->GetCellIndex(i,iSM,iMod,iIphi,iIeta);
102     geom->GetCellPhiEtaIndexInSModule(iSM,iMod, iIphi, iIeta,iRow,iCol);
103     
104     Float_t paramOCDB = -1;
105     if(cparam) paramOCDB = cparam->GetADCchannel(iSM,iCol,iRow);
106
107 //    Float_t paramOCDB2 = -1;
108 //    if(cparam) paramOCDB2 = cparam2->GetADCchannel(iSM,iCol,iRow);
109     
110     Float_t paramAODB = -1;
111     if(h[iSM]) paramAODB = h[iSM]->GetBinContent(iCol,iRow);
112     paramAODB*=0.0162; // Transformation into OCDB parameter, it will not work for all channels
113     
114     if    (printAll)
115     printf("STATUS: ID %d, col %d, row %d, sm %d  OCDB %1.4f, OADB %1.4f\n",
116            i,iCol,iRow,iSM,paramOCDB, paramAODB);
117     else if(paramAODB > 0)
118     {
119       if (paramOCDB/paramAODB > 1.01 || paramOCDB/paramAODB < 0.99) )
120       {
121         printf("DIFFERENT STATUS: ID %d, col %d, row %d, sm %d  OCDB %1.4f, OADB %1.4f, ratio OCDB/OADB %1.4f\n",//, old OCDB param %1.4f\n",
122                i,iCol,iRow,iSM,paramOCDB, paramAODB,paramOCDB/paramAODB);//,paramOCDB2);
123         nDiff++;
124       }
125       else if(paramAODB <= 0)
126       {
127         printf("DIFFERENT STATUS: ID %d, col %d, row %d, sm %d  OCDB %1.4f, OADB %1.4f\n",//, old OCDB param %1.4f\n",
128                i,iCol,iRow,iSM,paramOCDB, paramAODB);//,paramOCDB2);
129         nDiff++;
130       }
131       
132 //      if(TMath::Abs(paramOCDB2-0.0162)> 0.0001)
133 //      {
134 //        printf("\t Different initial calib! %1.4f\n",paramOCDB2);
135 //        nDiff2++;
136 //      }
137     }
138   }
139   
140   if(!printAll) printf("Total number of different channels %d / %d\n",nDiff,nSM*24*48);//, origin %d\n",nDiff,nSM*24*48,nDiff2);
141 }
142
143 //_____________________
144 void CheckBadChannels(Int_t run, TString pathOADB, AliCDBStorage * storage, AliEMCALGeometry *geom, Bool_t printAll = kTRUE)
145 {
146   // Get the OCDB bad channels and compare to the OADB ones
147   
148   //const Int_t nSM = static_const (geom->GetNumberOfSuperModules());
149   const Int_t nSM = static_cast<const Int_t> (geom->GetNumberOfSuperModules());
150
151   // Access OCDB histograms
152   AliCaloCalibPedestal* caloped  = (AliCaloCalibPedestal*) (storage->Get("EMCAL/Calib/Pedestals", run)->GetObject());
153     
154   // Access directly the OCDB file and not the latest version
155   //TFile * f = TFile::Open("alien:///alice/data/2011/OCDB/EMCAL/Calib/Pedestals/Run145954_146856_v3_s0.root","READ");
156   //AliCDBEntry * cdb = (AliCDBEntry*) f->Get("AliCDBEntry");
157   //AliCaloCalibPedestal * caloped = (AliCaloCalibPedestal *) cdb->GetObject();  
158   
159   TObjArray map = caloped->GetDeadMap();
160
161   // Access OADB histograms
162   TH2I *hbm[12];
163   
164   AliOADBContainer *contBC=new AliOADBContainer("");
165   
166   contBC->InitFromFile(Form("%s/EMCALBadChannels.root",pathOADB.Data()),"AliEMCALBadChannels"); 
167   
168   TObjArray *arrayBC=(TObjArray*)contBC->GetObject(run);
169   
170   if(!arrayBC)
171   {
172     printf("--- Bad map not available \n");
173     return;
174   }
175   
176   for (Int_t i=0; i < nSM; ++i)
177   {
178     hbm[i]=(TH2I*)arrayBC->FindObject(Form("EMCALBadChannelMap_Mod%d",i));
179     
180     if (!hbm)
181     {
182       AliError(Form("Can not get EMCALBadChannelMap_Mod%d",i));
183       continue;
184     }
185   }
186   
187   Int_t badMapOCDB = -1;
188   Int_t badMapAODB = -1;
189   Int_t iCol = -1, iRow = -1, iSM =-1, iMod = -1,iIphi =-1,iIeta = -1;    
190   for(Int_t i=0;i < nSM*24*48; i++)
191   {
192     //printf("AbsID %d\n",i);
193     geom->GetCellIndex(i,iSM,iMod,iIphi,iIeta); 
194     geom->GetCellPhiEtaIndexInSModule(iSM,iMod, iIphi, iIeta,iRow,iCol);
195     if(map.At(iSM))badMapOCDB = ((TH2F*)map.At(iSM))->GetBinContent(iCol,iRow);
196     else badMapOCDB  = -1;
197     if(hbm[iSM])   badMapAODB = hbm[iSM]->GetBinContent(iCol,iRow);
198      else badMapAODB = -1;
199
200     if    (printAll && badMapOCDB > 0)
201       printf("STATUS: ID %d, col %d, row %d, sm %d  OCDB %d, OADB %d\n",
202              i,iCol,iRow,iSM,badMapOCDB, badMapAODB);
203     else if(badMapOCDB!=badMapAODB)
204       printf("DIFFERENT STATUS: ID %d, col %d, row %d, sm %d  OCDB %d, OADB %d\n",
205              i,iCol,iRow,iSM,badMapOCDB, badMapAODB);
206
207   }
208   
209 }
210
211 //_____________________
212 void CheckTimeCalibration(Int_t run, TString pathOADB, AliCDBStorage * storage, AliEMCALGeometry *geom, TString pass, Bool_t printAll = kTRUE)
213 {
214   printf(" === Comparison for this object is not implemented === \n");
215 }
216