]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - FMD/AliFMDPreprocessor.cxx
Connection to tree in Notify() seems to be safer.
[u/mrichter/AliRoot.git] / FMD / AliFMDPreprocessor.cxx
index 12b2f8ae03ce5b51dc037e607589ebe18ca4c2c7..9d50b4bf215e36c59a258589ef248b1cc2697e35 100644 (file)
@@ -58,7 +58,7 @@
 // Latest changes by Christian Holm Christensen
 //
 
-// #include <iostream>
+ #include <iostream>
 
 #include <fstream>
 #include "AliFMDPreprocessor.h"
@@ -142,17 +142,27 @@ UInt_t AliFMDPreprocessor::Process(TMap* /* dcsAliasMap */)
   Bool_t resultRange = kTRUE;
   Bool_t resultRate  = kTRUE;
   Bool_t resultZero  = kTRUE;
-
+  Bool_t infoCalib   = kTRUE;
+  Bool_t resultDead  = kTRUE;
   // Do we need this ?
   // if(!dcsAliasMap) return 1;
   // 
   // Invoking the cdb manager and the FMD parameters class
   // AliCDBManager* cdb   = AliCDBManager::Instance();
-  // cdb->SetDefaultStorage("local://$ALICE_ROOT");
+  // cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
   // cdb->SetRun(0);
+  
+  // Get the run type 
+  TString runType(GetRunType()); 
+  
   AliFMDParameters* pars = AliFMDParameters::Instance();
-  pars->Init(this, false, AliFMDParameters::kAltroMap);
-
+  if(runType.Contains("PEDESTAL", TString::kIgnoreCase))
+    pars->Init(this, false, AliFMDParameters::kAltroMap|AliFMDParameters::kPulseGain);
+  else if(runType.Contains("GAIN", TString::kIgnoreCase))
+    pars->Init(this, false, AliFMDParameters::kAltroMap|AliFMDParameters::kPedestal);
+  else
+    pars->Init(this, false, AliFMDParameters::kAltroMap);
+  
   // This is if the SOR contains Fee parameters, and we run a DA to
   // extract these parameters.   The same code could work if we get
   // the information from DCS via the FXS 
@@ -160,21 +170,20 @@ UInt_t AliFMDPreprocessor::Process(TMap* /* dcsAliasMap */)
   AliFMDCalibSampleRate*      calibRate  = 0;
   AliFMDCalibStripRange*      calibRange = 0;
   AliFMDCalibZeroSuppression* calibZero  = 0;
-  // Disabled for now. 
-#if 0
+
   if (GetAndCheckFileSources(files, kDAQ,pars->GetConditionsShuttleID()))
-    GetInfoCalibration(files, calibRate, calibRange, calibZero);
+    infoCalib = GetInfoCalibration(files, calibRate, calibRange, calibZero);
   resultRate  = (!calibRate  ? kFALSE : kTRUE);
   resultRange = (!calibRange ? kFALSE : kTRUE);
   resultZero  = (!calibZero  ? kFALSE : kTRUE);
-#endif
-
-  // Gt the run type 
-  TString runType(GetRunType()); 
+  
 
+  
   //Creating calibration objects
   AliFMDCalibPedestal* calibPed  = 0;
   AliFMDCalibGain*     calibGain = 0;
+  AliFMDCalibDeadMap*  calibDead = 0;
   if (runType.Contains("PEDESTAL", TString::kIgnoreCase)) { 
     if (GetAndCheckFileSources(files, kDAQ, pars->GetPedestalShuttleID())) {
       if(files->GetSize())
@@ -189,6 +198,8 @@ UInt_t AliFMDPreprocessor::Process(TMap* /* dcsAliasMap */)
     }
     resultGain = (calibGain ? kTRUE : kFALSE);
   }
+  if(runType.Contains("PEDESTAL", TString::kIgnoreCase) || runType.Contains("GAIN", TString::kIgnoreCase))
+    calibDead = GetDeadChannelMap(calibPed,calibGain);
   
   //Storing Calibration objects  
   AliCDBMetaData metaData;
@@ -216,13 +227,14 @@ UInt_t AliFMDPreprocessor::Process(TMap* /* dcsAliasMap */)
     resultZero = Store("Calib","ZeroSuppression", calibZero,&metaData,0,kTRUE);
     delete calibZero;
   }
+  if(calibDead) { 
+    resultDead = Store("Calib","Dead", calibDead,&metaData,0,kTRUE);
+    delete calibDead;
+  }
 
-#if 0
-  // Disabled until we implement GetInfoCalibration properly
   Bool_t success = (resultPed && resultGain  && resultRange && 
-                   resultRate  && resultZero);
-#endif
-  Bool_t success = resultPed && resultGain;
+                   resultRate  && resultZero && resultDead && infoCalib);
+  
   Log(Form("FMD preprocessor was %s", (success ? "successful" : "failed")));
   return (success ? 0 : 1);
 }
@@ -242,8 +254,8 @@ AliFMDPreprocessor::GetInfoCalibration(TList* files,
   //     z     On return, newly allocated object 
   // Return: 
   //     kTRUE on success
-  if (!files) return kTRUE; // Should really be false
-  if (files->GetEntries() <= 0) return kTRUE;
+  if (!files) return kFALSE; // Should really be false
+  if (files->GetEntries() <= 0) return kFALSE;
   
   s = new AliFMDCalibSampleRate();
   r = new AliFMDCalibStripRange();
@@ -260,6 +272,8 @@ AliFMDPreprocessor::GetInfoCalibration(TList* files,
       Log(Form("File %s not found!", filename));
       continue;
     }
+    s->ReadFromFile(in);
+    r->ReadFromFile(in);
   }
   return kTRUE;
 }
@@ -295,7 +309,7 @@ AliFMDPreprocessor::GetPedestalCalibration(TList* pedFiles)
     TString header;
     header.ReadLine(in);
     header.ToLower();
-    if(!header.Contains("pedestal")) {
+    if(!header.Contains(pars->GetPedestalShuttleID())) {
       Log("File header is not from pedestal!");
       continue;
     }
@@ -311,36 +325,33 @@ AliFMDPreprocessor::GetPedestalCalibration(TList* pedFiles)
        Log(Form("Bad read at line %d in %s", lineno, filename));
        break;
       }
-      UInt_t ddl=2, board, chip, channel, strip, sample, tb;
+      UShort_t det, sec, strip;
+      Char_t ring;
       Float_t ped, noise, mu, sigma, chi2ndf;
-      Char_t c[11];
+      Char_t c[8];
          
-      in >> ddl      >> c[0] 
-        >> board    >> c[1]
-        >> chip     >> c[2]
-        >> channel  >> c[3]
-        >> strip    >> c[4]
-        >> sample   >> c[5]
-        >> tb       >> c[6]
-        >> ped      >> c[7]
-        >> noise    >> c[8]
-        >> mu       >> c[9]
-        >> sigma    >> c[10]
+      in >> det      >> c[0] 
+        >> ring     >> c[1]
+        >> sec      >> c[2]
+        >> strip    >> c[3]
+        >> ped      >> c[4]
+        >> noise    >> c[5]
+        >> mu       >> c[6]
+        >> sigma    >> c[7]
         >> chi2ndf;
       lineno++;
       
       // Ignore trailing garbage 
-      if (strip > 127) continue;
+      // if (strip > 127) continue;
       
       //Setting DDL to comply with the FMD in DAQ
-      UInt_t FmdDDLBase = 3072; 
-      ddl = ddl - FmdDDLBase;
+      // UInt_t FmdDDLBase = 3072; 
+      // ddl = ddl - FmdDDLBase;
       //Setting the pedestals via the hardware address
-      UShort_t det, sec, str;
-      Char_t ring;
       
-      pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
-      strip += str;
+      
+      // pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
+      // strip += str;
      
       calibPed->Set(det,ring,sec,strip,ped,noise);
      
@@ -378,7 +389,7 @@ AliFMDPreprocessor::GetGainCalibration(TList* gainFiles)
     TString header;
     header.ReadLine(in);
     header.ToLower();
-    if(!header.Contains("gain")) {
+    if(!header.Contains(pars->GetGainShuttleID())) {
       Log("File header is not from gain!");
       continue;
     }
@@ -394,37 +405,80 @@ AliFMDPreprocessor::GetGainCalibration(TList* gainFiles)
        Log(Form("Bad read at line %d in %s", lineno, filename));
        break;
       }
-      UInt_t ddl=2, board, chip, channel, strip;
+      UShort_t det, sec, strip;
+      Char_t ring;
+      
       Float_t gain,error,  chi2ndf;
-      Char_t c[7];
-             
-      in >> ddl      >> c[0] 
-        >> board    >> c[1]
-        >> chip     >> c[2]
-        >> channel  >> c[3]
-        >> strip    >> c[4]
-        >> gain     >> c[5]
-        >> error    >> c[6]
+      Char_t c[6];
+      
+      in >> det      >> c[0] 
+        >> ring     >> c[1]
+        >> sec      >> c[2]
+        >> strip    >> c[3]
+        >> gain     >> c[4]
+        >> error    >> c[5]
         >> chi2ndf;
       lineno++;
       // Ignore trailing garbage
-      if(strip > 127) continue;
+      //if(strip > 127) continue;
       
       //Setting DDL to comply with the FMD in DAQ
-      UInt_t FmdDDLBase = 3072; 
-      ddl = ddl - FmdDDLBase;
+      // UInt_t FmdDDLBase = 3072; 
+      // ddl = ddl - FmdDDLBase;
       //Setting the pedestals via the hardware address
-      UShort_t det, sec, str;
-      Char_t ring;
-      pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
+      //   pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
 
-      strip += str;
+      // strip += str;
       calibGain->Set(det,ring,sec,strip,gain);
     }
   }
   return calibGain;
 }
+//____________________________________________________________________
+AliFMDCalibDeadMap*    
+AliFMDPreprocessor::GetDeadChannelMap(AliFMDCalibPedestal* pedcalib,
+                                     AliFMDCalibGain*     gaincalib) {
+  //creating dead channel map. '0' means 51200 entries
+  AliFMDCalibDeadMap* deadmap = new AliFMDCalibDeadMap(0);
+  //deadmap->Reset(kTRUE);
+  Float_t noise = 0;
+  Float_t gain  = 0;
+  
+  AliFMDParameters* pars = AliFMDParameters::Instance();
+  //Looping over the channels.
+  for(UShort_t det=1;det<=3;det++) {
+    Int_t nRings = (det==1 ? 1 : 2);
+    for (UShort_t ir = 0; ir < nRings; ir++) {
+      Char_t   ring = (ir == 0 ? 'I' : 'O');
+      UShort_t nsec = (ir == 0 ? 20  : 40);
+      UShort_t nstr = (ir == 0 ? 512 : 256);
+      
+      for(UShort_t sec =0; sec < nsec;  sec++) {
+       
+       for(UShort_t strip = 0; strip < nstr; strip++) {
+         
+         Bool_t isDead = kFALSE;
+         if(pedcalib)
+           noise = pedcalib->Width(det, ring, sec, strip);
+         else 
+           noise = pars->GetPedestalWidth(det, ring, sec, strip);
+       
+         if(gaincalib)
+           gain  = gaincalib->Value(det, ring, sec, strip);
+         else 
+           gain  = pars->GetPulseGain(det, ring, sec, strip);
+         
+         //marking these channels dead.
+         if (gain < 0.5 || gain > 5 || noise > 10 || noise == 0) isDead = kTRUE;
+         
+         deadmap->operator()(det, ring, sec, strip) = isDead;
+       }
+      }
+    }
+  }
 
+  return deadmap;
+}
 //____________________________________________________________________
 //
 // EOF