]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSPreprocessor.cxx
Adding example macro to setup and use comparison tasks
[u/mrichter/AliRoot.git] / PHOS / AliPHOSPreprocessor.cxx
index 1a8262c5ab3591c2e5787975a14b5aaf75dcf6d1..32777508f4a0a6de0e50b54d3cde4650c934136c 100644 (file)
@@ -68,30 +68,243 @@ AliPreprocessor("PHS",shuttle)
 UInt_t AliPHOSPreprocessor::Process(TMap* /*valueSet*/)
 {
   // process data retrieved by the Shuttle
-
-  // The fileName with the histograms which have been produced by
-  // AliPHOSCalibHistoProducer.
-  // It is a responsibility of the SHUTTLE framework to form the fileName
   
   TString runType = GetRunType();
   Log(Form("Run type: %s",runType.Data()));
 
-  if(runType=="LED") {
+  if(runType=="STANDALONE") {
     Bool_t ledOK = ProcessLEDRun();
     if(ledOK) return 0;
     else
       return 1;
   }
+  
+  if(runType=="PHYSICS") {
+    
+    Bool_t badmap_OK = FindBadChannelsEmc();
+    if(!badmap_OK) Log(Form("WARNING!! FindBadChannels() completed with BAD status!"));
+    
+    Bool_t calibEmc_OK = CalibrateEmc();
+
+    if(calibEmc_OK && badmap_OK) return 0;
+    else
+      return 1;
+  }
+
+  Log(Form("Unknown run type %s. Do nothing and return OK.",runType.Data()));
+  return 0;
+
+}
+
+
+Bool_t AliPHOSPreprocessor::ProcessLEDRun()
+{
+  //Process LED run, fill bad channels map.
+
+  AliPHOSEmcBadChannelsMap badMap;
+
+  TList* list = GetFileSources(kDAQ, "LED");
+  if(!list) {
+    Log("Sources list for LED run not found, exit.");
+    return kFALSE;
+  }
+
+  TIter iter(list);
+  TObjString *source;
+  char hnam[80];
+  TH1F* histo=0;
+  
+  while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
+
+    AliInfo(Form("found source %s", source->String().Data()));
+
+    TString fileName = GetFile(kDAQ, "LED", source->GetName());
+    AliInfo(Form("Got filename: %s",fileName.Data()));
+
+    TFile f(fileName);
+
+    if(!f.IsOpen()) {
+      Log(Form("File %s is not opened, something goes wrong!",fileName.Data()));
+      return kFALSE;
+    }
+
+    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
+
+    // Check for dead channels    
+    Log(Form("Begin check for dead 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,"mod%dcol%drow%d",mod,col,row);
+         histo = (TH1F*)f.Get(hnam);
+         if(histo)
+           if (histo->GetMean()<1) {
+             Log(Form("Channel: [%d,%d,%d] seems dead, <E>=%.1f.",mod,col,row,histo->GetMean()));
+             badMap.SetBadChannel(mod,col,row);
+           }
+       }
+      }
+    }
+
+  }
+
+  //Store bad channels map
+  AliCDBMetaData badMapMetaData;
+
+  //Bad channels data valid from current run fRun until updated (validityInfinite=kTRUE)
+  Bool_t result = Store("Calib", "EmcBadChannels", &badMap, &badMapMetaData, fRun, kTRUE);
+  return result;
+
+}
+
+Float_t AliPHOSPreprocessor::HG2LG(Int_t mod, Int_t X, Int_t Z, TFile* f)
+{
+  //Calculates High gain to Low gain ratio 
+  //for crystal at the position (X,Z) in the PHOS module mod.
+  
+  char hname[128];
+  sprintf(hname,"%d_%d_%d",mod,X,Z);
+
+  TH1F* h1 = (TH1F*)f->Get(hname);
+  if(!h1) return 16.;
+
+  if(!h1->GetEntries()) return 16.;
+  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);
+  //       Double_t xmin = max - (h1->GetRMS());
+  //       Double_t xmax = max + (h1->GetRMS());
+
+  TF1* gaus1 = new TF1("gaus1",rgaus,xmin,xmax,3);
+  gaus1->SetParNames("Constant","Mean","Sigma");
+  gaus1->SetParameter("Constant",h1->GetMaximum());
+  gaus1->SetParameter("Mean",max);
+  gaus1->SetParameter("Sigma",1.);
+  gaus1->SetLineColor(kBlue);
+  h1->Fit(gaus1,"LERQ+");
+
+  Log(Form("\t%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");
+
+}
+
+Bool_t AliPHOSPreprocessor::FindBadChannelsEmc()
+{
+  //Creates the bad channels map for PHOS EMC.
+
+  // The file fileName contains histograms which have been produced by DA2 detector algorithm.
+  // It is a responsibility of the SHUTTLE framework to form the fileName.
+
+  AliPHOSEmcBadChannelsMap badMap;
+
+  TList* list = GetFileSources(kDAQ, "BAD_CHANNELS");
+
+  if(!list) {
+    Log("Sources list for BAD_CHANNELS not found, exit.");
+    return kFALSE;
+  }
+
+  if(!list->GetEntries()) {
+    Log(Form("Got empty sources list. It seems DA2 did not produce any files!"));
+    return kFALSE;
+  }
+
+  TIter iter(list);
+  TObjString *source;
+  char hnam[80];
+  TH1F* h1=0;
+
+  const Float_t fQualityCut = 1.;
+  Int_t nGoods[5] = {0,0,0,0,0};
+  
+  while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
+
+    AliInfo(Form("found source %s", source->String().Data()));
+
+    TString fileName = GetFile(kDAQ, "BAD_CHANNELS", source->GetName());
+    AliInfo(Form("Got filename: %s",fileName.Data()));
+
+    TFile f(fileName);
+
+    if(!f.IsOpen()) {
+      Log(Form("File %s is not opened, something goes wrong!",fileName.Data()));
+      return kFALSE;
+    }
+    
+    Log(Form("Begin check for bad channels."));
+    
+    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);
+
+         if(h1) {
+           Double_t mean = h1->GetMean();
+           
+           if(mean)
+             Log(Form("iX=%d iZ=%d gain=%d   mean=%.3f\n",iX,iZ,1,mean));
+
+           if( mean>0 && mean<fQualityCut ) { 
+             nGoods[mod]++; 
+           }
+           else
+             badMap.SetBadChannel(mod+1,iZ+1,iX+1); //module, col,row
+         }
+
+       }
+      }
+
+      if(nGoods[mod])
+       Log(Form("Module %d: %d good channels.",mod,nGoods[mod]));
+    }
+
+    
+  } // end of loop over sources
+  
+  // Store the bad channels map.
+  
+  AliCDBMetaData md;
+  md.SetResponsible("Boris Polishchuk");
+
+  // Data valid from current run fRun until being updated (validityInfinite=kTRUE)
+  Bool_t result = Store("Calib", "EmcBadChannels", &badMap, &md, fRun, kTRUE);
+  return result;
+
+}
+
+Bool_t AliPHOSPreprocessor::CalibrateEmc()
+{
+  // I.  Calculates the set of calibration coefficients to equalyze the mean energies deposited at high gain.
+  // II. Extracts High_Gain/Low_Gain ratio for each channel.
+
+  // The file fileName contains histograms which have been produced by DA1 detector algorithm.
+  // It is a responsibility of the SHUTTLE framework to form the fileName.
 
   gRandom->SetSeed(0); //the seed is set to the current  machine clock!
   AliPHOSEmcCalibData calibData;
-
+  
   TList* list = GetFileSources(kDAQ, "AMPLITUDES");
+  
   if(!list) {
     Log("Sources list not found, exit.");
     return 1;
   }
 
+  if(!list->GetEntries()) {
+    Log(Form("Got empty sources list. It seems DA1 did not produce any files!"));
+    return kFALSE;
+  }
+
   TIter iter(list);
   TObjString *source;
   
@@ -107,7 +320,7 @@ UInt_t AliPHOSPreprocessor::Process(TMap* /*valueSet*/)
       Log(Form("File %s is not opened, something goes wrong!",fileName.Data()));
       return 1;
     }
-
+    
     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
@@ -199,110 +412,10 @@ UInt_t AliPHOSPreprocessor::Process(TMap* /*valueSet*/)
   //Store EMC calibration data
   
   AliCDBMetaData emcMetaData;
-  Bool_t emcOK = Store("Calib", "EmcGainPedestals", &calibData, &emcMetaData);
-
-  if(emcOK) return 0;
-  else
-    return 1;
-
-}
-
-
-Bool_t AliPHOSPreprocessor::ProcessLEDRun()
-{
-  //Process LED run, fill bad channels map.
-
-  AliPHOSEmcBadChannelsMap badMap;
-
-  TList* list = GetFileSources(kDAQ, "LED");
-  if(!list) {
-    Log("Sources list for LED run not found, exit.");
-    return kFALSE;
-  }
-
-  TIter iter(list);
-  TObjString *source;
-  char hnam[80];
-  TH1F* histo=0;
-  
-  while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
-
-    AliInfo(Form("found source %s", source->String().Data()));
-
-    TString fileName = GetFile(kDAQ, "LED", source->GetName());
-    AliInfo(Form("Got filename: %s",fileName.Data()));
-
-    TFile f(fileName);
-
-    if(!f.IsOpen()) {
-      Log(Form("File %s is not opened, something goes wrong!",fileName.Data()));
-      return kFALSE;
-    }
-
-    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
-
-    // Check for dead channels    
-    Log(Form("Begin check for dead 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,"mod%dcol%drow%d",mod,col,row);
-         histo = (TH1F*)f.Get(hnam);
-         if(histo)
-           if (histo->GetMean()<1) {
-             Log(Form("Channel: [%d,%d,%d] seems dead, <E>=%.1f.",mod,col,row,histo->GetMean()));
-             badMap.SetBadChannel(mod,col,row);
-           }
-       }
-      }
-    }
-
-  }
-
-  //Store bad channels map
-  AliCDBMetaData badMapMetaData;
-
-  //Bad channels data valid from current run fRun until updated (validityInfinite=kTRUE)
-  Bool_t result = Store("Calib", "EmcBadChannels", &badMap, &badMapMetaData, fRun, kTRUE);
+  Bool_t result = Store("Calib", "EmcGainPedestals", &calibData, &emcMetaData, 0, kTRUE); // valid from 0 to infinity);
   return result;
 
 }
 
-Float_t AliPHOSPreprocessor::HG2LG(Int_t mod, Int_t X, Int_t Z, TFile* f)
-{
-  //Calculates High gain to Low gain ratio 
-  //for crystal at the position (X,Z) in the PHOS module mod.
-  
-  char hname[128];
-  sprintf(hname,"%d_%d_%d",mod,X,Z);
-
-  TH1F* h1 = (TH1F*)f->Get(hname);
-  if(!h1) return 16.;
-
-  if(!h1->GetEntries()) return 16.;
-  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);
-  //       Double_t xmin = max - (h1->GetRMS());
-  //       Double_t xmax = max + (h1->GetRMS());
+     
 
-  TF1* gaus1 = new TF1("gaus1",rgaus,xmin,xmax,3);
-  gaus1->SetParNames("Constant","Mean","Sigma");
-  gaus1->SetParameter("Constant",h1->GetMaximum());
-  gaus1->SetParameter("Mean",max);
-  gaus1->SetParameter("Sigma",1.);
-  gaus1->SetLineColor(kBlue);
-  h1->Fit(gaus1,"LERQ+");
-
-  Log(Form("\t%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");
-
-}