]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSPreprocessor.cxx
Put calibration histograms (TH2F) to the Reference Storage; validity range of the...
[u/mrichter/AliRoot.git] / PHOS / AliPHOSPreprocessor.cxx
index c2ee9e7150e8c9d4bbd852c93945f541b3b40ffd..76dbb4efc62b516b7938c9fe6be11b7507c57500 100644 (file)
@@ -130,7 +130,6 @@ Bool_t AliPHOSPreprocessor::ProcessLEDRun()
   
   TIter iter(list);
   TObjString *source;
-  Bool_t firedOK = kFALSE;
   
   while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
     
@@ -145,26 +144,14 @@ Bool_t AliPHOSPreprocessor::ProcessLEDRun()
       Log(Form("File %s is not opened, something goes wrong!",fileName.Data()));
       return kFALSE;
     }
-
+    
     TH1I* fFiredCells = (TH1I*)f.Get("fFiredCells");
-
-    if(!fFiredCells) {
-      Log(Form("fFiredCells histogram not found in %s, skip this source.",fileName.Data()));
-      firedOK=kFALSE;
-    }
-    else {
+    
+    if(fFiredCells) {
       const Double_t nFiredCells = fFiredCells->GetMean();
-      if(nFiredCells>100 && nFiredCells<600) { 
-       firedOK = kTRUE;
-       Log(Form("Number of fired cells per event is %d.",nFiredCells));
-      }
-      else {
-       Log(Form("Number of fired cells per event is %d, possibly not a LED run!",nFiredCells));
-       firedOK = kFALSE;
-      }
-      
+      Log(Form("Number of fired cells per event is %.1f",nFiredCells));
     }
-
+    
     const Int_t nMod=5; // 1:5 modules
     const Int_t nCol=56; //1:56 columns in each module
     const Int_t nRow=64; //1:64 rows in each module
@@ -172,22 +159,20 @@ Bool_t AliPHOSPreprocessor::ProcessLEDRun()
     for(Int_t mod=0; mod<nMod; mod++) {
       for(Int_t col=0; col<nCol; col++) {
        for(Int_t row=0; row<nRow; row++) {
-
-         //High Gain to Low Gain ratio
-         if(firedOK) {
-           Float_t ratio = HG2LG(mod,row,col,&f);
-           calibData.SetHighLowRatioEmc(mod+1,col+1,row+1,ratio);
-           if(ratio != 16.)
-             AliInfo(Form("mod %d iX %d iZ %d  ratio %.3f\n",mod,row,col,ratio));
-         }       
-
+         
          if(clb) {
-           Double_t coeff = clb->GetADCchannelEmc(mod+1,col+1,row+1);
-           calibData.SetADCchannelEmc(mod+1,col+1,row+1,coeff);
+           Float_t  hg2lg = clb->GetHighLowRatioEmc(5-mod,col+1,row+1);
+           Double_t coeff = clb->GetADCchannelEmc(5-mod,col+1,row+1);
+           calibData.SetADCchannelEmc(5-mod,col+1,row+1,coeff);
+           calibData.SetHighLowRatioEmc(5-mod,col+1,row+1,hg2lg);
+         }     
+  
+         //High Gain to Low Gain ratio
+         Float_t ratio = HG2LG(mod,row,col,&f);
+         if(ratio != 16.) {
+           calibData.SetHighLowRatioEmc(5-mod,col+1,row+1,ratio);
+           AliInfo(Form("mod %d iX %d iZ %d  ratio %.3f\n",mod,row,col,ratio));
          }
-         else
-           calibData.SetADCchannelEmc(mod+1,col+1,row+1,0.005);
-
        }
       }
     }
@@ -197,8 +182,8 @@ Bool_t AliPHOSPreprocessor::ProcessLEDRun()
   //Store the updated High Gain/Low Gain ratios
   AliCDBMetaData emcMetaData;
 
-  //Data valid from current run fRun until updated (validityInfinite=kTRUE)
-  Bool_t result = Store("Calib","EmcGainPedestals",&calibData,&emcMetaData,fRun,kTRUE);
+  //Data valid from current run until updated (validityInfinite=kTRUE)
+  Bool_t result = Store("Calib","EmcGainPedestals",&calibData,&emcMetaData,0,kTRUE);
   return result;
 
 }
@@ -214,11 +199,11 @@ Float_t AliPHOSPreprocessor::HG2LG(Int_t mod, Int_t X, Int_t Z, TFile* f)
   TH1F* h1 = (TH1F*)f->Get(hname);
   if(!h1) return 16.;
   
-  if(!h1->GetEntries()) return 16.;
+  if(h1->GetEntries()<2000.) return 16.;
   
-  h1->Rebin(4);
+  if(h1->GetMaximum()<10.) h1->Rebin(4);
   if(h1->GetMaximum()<10.) return 16.;
-
+  
   Double_t max = h1->GetBinCenter(h1->GetMaximumBin()); // peak
   Double_t xmin = max - (h1->GetRMS()/3);
   Double_t xmax = max + (h1->GetRMS()/2);
@@ -231,14 +216,20 @@ Float_t AliPHOSPreprocessor::HG2LG(Int_t mod, Int_t X, Int_t Z, TFile* f)
   gaus1->SetParameter("Mean",max);
   gaus1->SetParameter("Sigma",1.);
   gaus1->SetLineColor(kBlue);
-  h1->Fit(gaus1,"LERQ+");
-
-  AliInfo(Form("%s: %d entries, mean=%.3f, peak=%.3f, rms= %.3f. HG/LG = %.3f\n",
-          h1->GetTitle(),h1->GetEntries(),h1->GetMean(),max,h1->GetRMS(),
-          gaus1->GetParameter("Mean"))); 
-
-  return gaus1->GetParameter("Mean");
+  
+  Double_t mean_min = h1->GetXaxis()->GetXmin();
+  Double_t mean_max = h1->GetXaxis()->GetXmax();
+  gaus1->SetParLimits(1,mean_min,mean_max);
+  
+  h1->Fit(gaus1,"RQ+");
+  Double_t hg2lg = gaus1->GetParameter("Mean");
+  if( (hg2lg-mean_min<0.001) || (mean_max-hg2lg<0.001)) hg2lg=max;
+  
+  AliInfo(Form("%s: %.1f entries, mean=%.3f, peak=%.3f, rms= %.3f. HG/LG = %.3f\n",
+         h1->GetTitle(),h1->GetEntries(),h1->GetMean(),max,h1->GetRMS(),hg2lg)); 
 
+  return hg2lg;
+  
 }
 
 Bool_t AliPHOSPreprocessor::FindBadChannelsEmc()
@@ -282,8 +273,8 @@ Bool_t AliPHOSPreprocessor::FindBadChannelsEmc()
     else 
       path = "HLT";
   
-    // Data valid from current run fRun until being updated (validityInfinite=kTRUE)
-    result[i] *= Store(path.Data(), "EmcBadChannels", &badMap, &md, fRun, kTRUE);
+    // Data valid from current run until being updated (validityInfinite=kTRUE)
+    result[i] *= Store(path.Data(), "EmcBadChannels", &badMap, &md, 0, kTRUE);
     
   }
   
@@ -320,26 +311,12 @@ Bool_t AliPHOSPreprocessor::DoFindBadChannelsEmc(Int_t system, TList* list, AliP
       return kFALSE;
     }
 
-    TH1I* fFiredCells = (TH1I*)f.Get("fFiredCells");
-
-    if(!fFiredCells) {
-      Log(Form("fFiredCells histogram not found in %s, skip this source.",fileName.Data()));
-      continue;
-    }
-
-    const Double_t nFiredCells = fFiredCells->GetMean();
+    Log(Form("Begin check for bad channels."));
 
-    if(nFiredCells<100. || nFiredCells>600. ) {
-      Log(Form("Number of fired cells per event is %d, possibly not a LED run!",nFiredCells));
-      continue; // not a LED run!
-    }
-    
-    Log(Form("Number of fired cells per event %d. Begin check for bad channels.",nFiredCells));
-    
     for(Int_t mod=0; mod<5; mod++) {
       for(Int_t iX=0; iX<64; iX++) {
        for(Int_t iZ=0; iZ<56; iZ++) {
-
+         
          sprintf(hnam,"%d_%d_%d_%d",mod,iX,iZ,1); // high gain 
          h1 = (TH1F*)f.Get(hnam);
 
@@ -374,8 +351,10 @@ Bool_t AliPHOSPreprocessor::CalibrateEmc()
   //Loop over two systems: DAQ and HLT.
   //For each system the same algorithm implemented in DoCalibrateEmc() invokes.
 
+  AliPHOSEmcCalibData*   lastCalib=0;
   const AliPHOSEmcBadChannelsMap* badMap=0;
   AliCDBEntry* entryBCM=0;
+  AliCDBEntry* entryEmc=0;
   TList* list=0;
   TString path;
   
@@ -417,19 +396,75 @@ Bool_t AliPHOSPreprocessor::CalibrateEmc()
     if(!badMap)
       Log(Form("WARNING!! Nothing for %s in AliCDBEntry. All cells considered GOOD!",sysn[i]));
 
-    result[i] *= DoCalibrateEmc(system[i],list,badMap,calibData);
+    // Retrieve  the last EMC calibration object
+    
+    entryEmc = GetFromOCDB(path.Data(), "EmcGainPedestals");
+    
+    if(!entryEmc) 
+      Log(Form("Cannot find any EmcGainPedestals entry for this run and path %s",path.Data()));
+    else
+      lastCalib = (AliPHOSEmcCalibData*)entryEmc->GetObject();
 
+    if(lastCalib) 
+      result[i] *= DoCalibrateEmc(system[i],list,badMap,*lastCalib);    
+    else 
+      result[i] *= DoCalibrateEmc(system[i],list,badMap,calibData);
+    
     //Store EMC calibration data
-
     AliCDBMetaData emcMetaData;
-    result[i] *= Store(path.Data(), "EmcGainPedestals", &calibData, &emcMetaData, 0, kTRUE);
-  
+    
+    if(lastCalib)
+      result[i] *= Store(path.Data(), "EmcGainPedestals", lastCalib, &emcMetaData, 0, kFALSE);
+    else
+      result[i] *= Store(path.Data(), "EmcGainPedestals", &calibData, &emcMetaData, 0, kFALSE);
+
+    //Store reference data
+    Bool_t refOK = StoreReferenceEmc(system[i],list,path.Data());
+    if(refOK) Log(Form("Reference data for EMC Amplitudes successfully stored."));
+    
   }
   
   if(result[0] || result[1]) return kTRUE;
   else return kFALSE;
 }
 
+Bool_t AliPHOSPreprocessor::StoreReferenceEmc(Int_t system, TList* list, const char* path)
+{
+  //Put 2D calibration histograms (E vs Time) prepared by DAQ/HLT to the reference storage.
+  //system is DAQ or HLT, TList is the list of FES sources.
+
+  TIter iter(list);
+  TObjString *source;
+  TObjArray objArr;
+  
+  while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
+    
+    TString fileName = GetFile(system, "AMPLITUDES", source->GetName());
+    TFile f(fileName);
+    
+    if(!f.IsOpen()) {
+      Log(Form("Source file %s is not opened, EMC reference data will not be stored!",fileName.Data()));
+      return kFALSE;
+    }
+    
+    TList * keylist = f.GetListOfKeys();
+    Int_t nkeys   = f.GetNkeys();
+    
+    for(Int_t ikey=0; ikey<nkeys; ikey++) {
+      TKey* key = (TKey*)keylist->At(ikey);
+      TObject* obj = f.Get(key->GetName());
+      objArr.Add(obj);
+    }
+  }
+
+  AliCDBMetaData metaData;
+  metaData.SetResponsible("Boris Polishchuk");
+  
+  Bool_t resultRef = StoreReferenceData(path,"Amplitudes",&objArr, &metaData);
+  return resultRef;
+
+}
+
 
 Bool_t AliPHOSPreprocessor::DoCalibrateEmc(Int_t system, TList* list, const AliPHOSEmcBadChannelsMap* badMap, AliPHOSEmcCalibData& calibData)
 {
@@ -441,6 +476,7 @@ Bool_t AliPHOSPreprocessor::DoCalibrateEmc(Int_t system, TList* list, const AliP
   // It is a responsibility of the SHUTTLE framework to form the fileName.
 
   gRandom->SetSeed(0); //the seed is set to the current  machine clock!
+  Int_t minEntries=1000; // recalculate calibration coeff. if Nentries > minEntries.
 
   TIter iter(list);
   TObjString *source;
@@ -495,9 +531,9 @@ Bool_t AliPHOSPreprocessor::DoCalibrateEmc(Int_t system, TList* list, const AliP
        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
+         hRef->GetXaxis()->SetRangeUser(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;
+         if(hRef->GetMean() && hRef->GetEntries()>minEntries) ok=kTRUE;
 
          const TString delim = "_";
          TString str = hRef->GetName();
@@ -507,9 +543,9 @@ Bool_t AliPHOSPreprocessor::DoCalibrateEmc(Int_t system, TList* list, const AliP
          const Int_t Z   = ((TObjString*)tks->At(2))->GetString().Atoi();
 
          if(badMap) {
-           if(badMap->IsBadChannel(md+1,Z+1,X+1)) {
+           if(badMap->IsBadChannel(5-md,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()));
+                          5-md,Z+1,X+1,hRef->GetName()));
              ok=kFALSE;
            }
          }
@@ -543,16 +579,13 @@ Bool_t AliPHOSPreprocessor::DoCalibrateEmc(Int_t system, TList* list, const AliP
          //TODO: dead channels exclusion!
          if(h2) {
            h1 = h2->ProjectionX();
-           h1->GetXaxis()->SetRange(10,1000); //to cut off saturation peak and noise
+           h1->GetXaxis()->SetRangeUser(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));
+           if(coeff>0 && h1->GetEntries()>minEntries) {
+             calibData.SetADCchannelEmc(5-mod,col+1,row+1,0.005/coeff);
+             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); 
        }
       }
     }