]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONPedestalEventGenerator.cxx
o add Reset function to CalPad and CalROC o Add functionality to AliTPCdataQA - Reset...
[u/mrichter/AliRoot.git] / MUON / AliMUONPedestalEventGenerator.cxx
index 2f8dca6dfca2d2779014dffaa17dd9718c2df8cb..3d4b80b759f8eb896f3a4b82f9da7a9dfa8c0fbc 100644 (file)
 
 #include "AliMUONPedestalEventGenerator.h"
 
+#include "AliCodeTimer.h"
+#include "AliDAQ.h"
 #include "AliHeader.h"
 #include "AliLog.h"
 #include "AliMUONCalibrationData.h"
-#include "AliMUONDigitStoreV1.h"
 #include "AliMUONRawWriter.h"
-#include "AliCodeTimer.h"
 #include "AliMUONVCalibParam.h"
 #include "AliMUONVDigit.h"
+#include "AliMUONVDigitStore.h"
 #include "AliMUONVStore.h"
 #include "AliMpCathodType.h"
 #include "AliMpConstants.h"
 #include "AliMpDEStore.h"
 #include "AliMpDetElement.h"
-#include "AliMpIntPair.h"
 #include "AliMpPlaneType.h"
+#include "AliRawDataHeaderSim.h"
+#include "AliLoader.h"
 #include "AliRunLoader.h"
 #include <TClonesArray.h>
 #include <TMath.h>
 #include <TRandom.h>
 #include <TStopwatch.h>
 #include <TSystem.h>
-#include "AliDAQ.h"
+#include <TTree.h>
 
-///
+#include <cstdio>
+
+//-----------------------------------------------------------------------------
 /// \class AliMUONPedestalEventGenerator
 ///
 /// Generate simulated pedestal events for MUON TRK, to be able to e.g. test
@@ -56,7 +60,7 @@
 /// + raw (date files, one per LDC), depending of ctor and MakeDDL() method.
 ///
 /// \author L. Aphecetche
-///
+//-----------------------------------------------------------------------------
 
 /// \cond CLASSIMP
 ClassImp(AliMUONPedestalEventGenerator)
@@ -102,15 +106,14 @@ fRawWriter(0x0)
   }
   
   AliRunLoader* runLoader = LoadRun("recreate");
-  
-  runLoader->SetNumberOfEventsPerFile(nevents);
-  
   if (!runLoader)
   {
     AliError("Could not create RunLoader");
     return;
   }
   
+  runLoader->SetNumberOfEventsPerFile(nevents);
+  
   // Initialize event headers.
   runLoader->MakeTree("E");
 
@@ -146,13 +149,13 @@ AliMUONPedestalEventGenerator::ConvertRawFilesToDate()
   /// convert raw data DDL files to DATE files with the program "dateStream".
   /// we make one file per LDC
   
-  AliCodeTimerAuto("")
+  AliCodeTimerAuto("",0)
   
   AliInfo("Converting raw to date");
   
   const Int_t kIDet = AliDAQ::DetectorID("MUONTRK");
   
-  const Int_t kNLDCs = TMath::CeilNint(AliDAQ::NumberOfLdcs(kIDet));
+  const Int_t kNLDCs = 5;//TMath::CeilNint(AliDAQ::NumberOfLdcs(kIDet));
   
   char* path = gSystem->Which(gSystem->Getenv("PATH"), "dateStream");
   if (!path) 
@@ -174,7 +177,7 @@ AliMUONPedestalEventGenerator::ConvertRawFilesToDate()
     char command[256];
     // Note the option -s. It is used in order to avoid
     // the generation of SOR/EOR events.
-    sprintf(command, "dateStream -s -D -o %s.LDC%d -# %d -C", 
+    snprintf(command, 256, "dateStream -c -D -o %s.LDC%d -# %d -C", 
             fDateFileName.Data(), iFile, runLoader->GetNumberOfEvents());
     pipe[iFile] = gSystem->OpenPipe(command, "w");
   }
@@ -191,7 +194,7 @@ AliMUONPedestalEventGenerator::ConvertRawFilesToDate()
       ldc += AliDAQ::NumberOfLdcs(kIDet) / AliDAQ::NumberOfDdls(kIDet);
       
       char rawFileName[256];
-      sprintf(rawFileName, "raw%d/%s", 
+      snprintf(rawFileName, 256, "raw%d/%s", 
               iEvent, AliDAQ::DdlFileName(kIDet,iDDL));
       
       // check existence and size of raw data file
@@ -217,6 +220,13 @@ AliMUONPedestalEventGenerator::ConvertRawFilesToDate()
     result += gSystem->ClosePipe(pipe[iFile]);
   }
   
+  for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); ++iEvent) 
+  {
+    char command[256];
+    snprintf(command, 256, "rm -r raw%d", iEvent);
+    gSystem->Exec(command);
+  }
+  
   delete [] pipe;
   delete runLoader;
   fLoader=0x0;
@@ -229,7 +239,7 @@ AliMUONPedestalEventGenerator::DigitStore()
 {
 /// Return digt container; create it if it does not exist
 
-  if (!fDigitStore) fDigitStore = new AliMUONDigitStoreV1;
+  if (!fDigitStore) fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
   return fDigitStore;
 }
 
@@ -239,7 +249,7 @@ AliMUONPedestalEventGenerator::Exec(Option_t*)
 {  
   /// Main steering method
   
-  AliCodeTimerAuto("")
+  AliCodeTimerAuto("",0)
   
   if (!fPedestals)
   {
@@ -283,10 +293,9 @@ AliMUONPedestalEventGenerator::Exec(Option_t*)
     
     if ( fMakeDDL )
     {
+      AliCodeTimerAuto("Digits2Raw",1);
       Digits2Raw(i);
     }
-    
-//    gROOT->ProcessLine(Form("gObjectTable->Print(); > generate.txt.%d",i));
   }
     
   runLoader->WriteRunLoader("OVERWRITE");
@@ -296,10 +305,11 @@ AliMUONPedestalEventGenerator::Exec(Option_t*)
   // Finally, if instructed to do so, convert DDL files to DATE file(s)
   if ( fMakeDDL && fDateFileName.Length() > 0 ) 
   {
+    AliCodeTimerAuto("ConvertRawFilesToDate",1)
     Bool_t dateOutput = ConvertRawFilesToDate();
     if (!dateOutput) 
     {
-      AliError("DATE output failed. Aborting.");
+      AliError("DATE output failed. Exiting.");
       return;
     }    
   }
@@ -311,9 +321,14 @@ AliMUONPedestalEventGenerator::Digits2Raw(Int_t event)
 {
   /// Converts digits (from MUON.Digits.root file) to Raw DDL ascii files.
   
-  AliCodeTimerAuto("")
+  AliCodeTimerAuto("",0)
   
-  if (!fRawWriter) fRawWriter = new AliMUONRawWriter;
+  if (!fRawWriter) 
+  {
+      AliRawDataHeaderSim header;
+      fRawWriter = new AliMUONRawWriter;
+      fRawWriter->SetHeader(header);
+  }
   
   // Generate RAW data from the digits
   // Be carefull to create&change to the correct directory first...
@@ -321,7 +336,7 @@ AliMUONPedestalEventGenerator::Digits2Raw(Int_t event)
   TString baseDir = gSystem->WorkingDirectory();
   
   char dirName[256];
-  sprintf(dirName, "raw%d", event);
+  snprintf(dirName, 256, "raw%d", event);
   gSystem->MakeDirectory(dirName);
   if (!gSystem->ChangeDirectory(dirName)) 
   {
@@ -341,7 +356,7 @@ AliMUONPedestalEventGenerator::GenerateDigits(AliMUONVDigitStore& digitStore)
   /// Generate digits (where ADC is set to pedestal value) for all MUON TRK
   /// and for 1 event.
   
-  AliCodeTimerAuto("")
+  AliCodeTimerAuto("",0)
 
   digitStore.Clear();
   
@@ -372,19 +387,37 @@ AliMUONPedestalEventGenerator::GenerateDigits(AliMUONVDigitStore& digitStore)
       {
         // This is a poor's man way of knowing if that channel really exists.
         // Better and safer way (but much slower too) would be to check pad existence
-        // using AliMpVSegmentation::PadByLocation(AliMpIntPair(manuId,manuChannel))
+        // using AliMpVSegmentation::PadByLocation(manuId,manuChannel)
         continue;
       }
+      else if ( mean < 1 || mean >  4095 ) 
+      {
+        AliFatal(Form("Got an invalid mean pedestal value for DE %d Manu %d"
+                      " channel %d : mean = %e",detElemId,manuId,manuChannel,
+                      mean));
+      }
       else
       {
         Float_t sigma = pedestals->ValueAsFloat(manuChannel,1);
         
-
+        if ( sigma < 0 ) 
+        {
+          AliWarning(Form("Got a negative sigma pedestal value for DE %d Manu %d"
+                          " channel %d : sigma = %e, will use Abs()=%e",
+                          detElemId,manuId,manuChannel,
+                          sigma,-sigma));
+          sigma = -sigma;
+        }
+        
         AliMUONVDigit* d = digitStore.Add(detElemId,manuId,manuChannel,
                                           cathode,
                                           AliMUONVDigitStore::kIgnore);
         
-        Float_t ped = gRandom->Gaus(mean,sigma);
+        Float_t ped = -1;
+        while ( ped <= 0 ) 
+        {
+          ped = gRandom->Gaus(mean,sigma);
+        }
         Int_t pedADC = TMath::FloorNint(ped);
 
         d->SetADC(pedADC);
@@ -405,10 +438,10 @@ AliRunLoader*
 AliMUONPedestalEventGenerator::LoadRun(const char* mode)
 {
   /// Get access to AliRunLoader object
-  while (AliRunLoader::GetRunLoader()) 
+  while (AliRunLoader::Instance()) 
   {
-    AliDebug(1,Form("Deleting AliRunLoader %p",AliRunLoader::GetRunLoader()));
-    delete AliRunLoader::GetRunLoader();
+    AliDebug(1,Form("Deleting AliRunLoader %p",AliRunLoader::Instance()));
+    delete AliRunLoader::Instance();
   }
   
   AliRunLoader* runLoader = 
@@ -420,6 +453,7 @@ AliMUONPedestalEventGenerator::LoadRun(const char* mode)
   if (!runLoader) 
   {
     AliError("No run loader found in file galice.root");
+    return 0x0;
   }
     
   TString smode(mode);