+ //Check if the file contains any histogram
+
+ if(nkeys< 2){
+ Log(Form("Not enough histograms (%d) for calibration.",nkeys));
+ return 1; // it's not fatal! May be short run..
+ }
+
+ while(!ok){
+ ikey = gRandom->Integer(nkeys);
+ key = (TKey*)keylist->At(ikey);
+ TObject* obj = f.Get(key->GetName());
+ TString cname(obj->ClassName());
+ if(cname == "TH2F") {
+ h2 = (TH2F*)obj;
+ TString htitl = h2->GetTitle();
+ if(htitl.Contains("and gain 1")) {
+ hRef = h2->ProjectionX();
+ hRef->GetXaxis()->SetRange(10,1000); // to cut off saturation peak and noise
+ // Check if the reference histogram has too little statistics
+ if(hRef->GetMean() && hRef->GetEntries()>2) ok=kTRUE;
+
+ const TString delim = "_";
+ TString str = hRef->GetName();
+ TObjArray* tks = str.Tokenize(delim);
+ const Int_t md = ((TObjString*)tks->At(0))->GetString().Atoi();
+ const Int_t X = ((TObjString*)tks->At(1))->GetString().Atoi();
+ const Int_t Z = ((TObjString*)tks->At(2))->GetString().Atoi();
+
+ if(badMap) {
+ if(badMap->IsBadChannel(md+1,Z+1,X+1)) {
+ AliInfo(Form("Cell mod=%d col=%d row=%d is bad. Histogram %s rejected.",
+ md+1,Z+1,X+1,hRef->GetName()));
+ ok=kFALSE;
+ }
+ }
+
+ }
+ }
+
+ counter++;
+
+ if(!ok && counter > nkeys){
+ Log("No histogram with enough statistics for reference. Exit.");
+ return 1; // Not fatal, just wait..
+ }
+ }
+
+ Log(Form("reference histogram %s, %.1f entries, mean=%.3f, rms=%.3f.",
+ hRef->GetName(),hRef->GetEntries(),
+ hRef->GetMean(),hRef->GetRMS()));
+
+ Double_t refMean=hRef->GetMean();
+
+ // Calculates relative calibration coefficients for all non-zero channels
+
+ for(Int_t mod=0; mod<nMod; mod++) {
+ for(Int_t col=0; col<nCol; col++) {
+ for(Int_t row=0; row<nRow; row++) {
+
+ sprintf(hnam,"%d_%d_%d_1",mod,row,col); // high gain!
+ h2 = (TH2F*)f.Get(hnam);
+
+ //TODO: dead channels exclusion!
+ if(h2) {
+ h1 = h2->ProjectionX();
+ h1->GetXaxis()->SetRange(10,1000); //to cut off saturation peak and noise
+ coeff = h1->GetMean()/refMean;
+ if(coeff>0)
+ calibData.SetADCchannelEmc(mod+1,col+1,row+1,0.005/coeff);
+ else
+ calibData.SetADCchannelEmc(mod+1,col+1,row+1,0.005);
+ AliInfo(Form("mod %d col %d row %d coeff %f\n",mod,col,row,coeff));
+ }
+ else
+ calibData.SetADCchannelEmc(mod+1,col+1,row+1,0.005);
+ }
+ }
+ }
+
+ f.Close();
+ }
+
+ return 1;