]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PMD/AliPMDClusterFinder.cxx
Using AliPHOSLoader instead of AliPHOSGetter
[u/mrichter/AliRoot.git] / PMD / AliPMDClusterFinder.cxx
index 532938857e60973181b828f24dd26a6d15690dc5..298b7ce17dc1859ed67d8de79e8f2391b67f6975 100644 (file)
 #include "AliPMDrechit.h"
 #include "AliPMDRawStream.h"
 #include "AliPMDCalibData.h"
+#include "AliPMDPedestal.h"
+#include "AliPMDddldata.h"
 
+#include "AliDAQ.h"
 #include "AliCDBManager.h"
 #include "AliCDBEntry.h"
 
@@ -52,6 +55,8 @@ ClassImp(AliPMDClusterFinder)
 AliPMDClusterFinder::AliPMDClusterFinder():
   fRunLoader(0),
   fPMDLoader(0),
+  fCalibGain(GetCalibGain()),
+  fCalibPed(GetCalibPed()),
   fTreeD(0),
   fTreeR(0),
   fDigits(new TClonesArray("AliPMDdigit", 1000)),
@@ -59,17 +64,19 @@ AliPMDClusterFinder::AliPMDClusterFinder():
   fRechits(new TClonesArray("AliPMDrechit", 1000)),
   fNpoint(0),
   fNhit(0),
+  fDetNo(0),
   fEcut(0.)
 {
 //
 // Constructor
 //
-  fCalibData = GetCalibData();
 }
 // ------------------------------------------------------------------------- //
 AliPMDClusterFinder::AliPMDClusterFinder(AliRunLoader* runLoader):
   fRunLoader(runLoader),
   fPMDLoader(runLoader->GetLoader("PMDLoader")),
+  fCalibGain(GetCalibGain()),
+  fCalibPed(GetCalibPed()),
   fTreeD(0),
   fTreeR(0),
   fDigits(new TClonesArray("AliPMDdigit", 1000)),
@@ -77,12 +84,39 @@ AliPMDClusterFinder::AliPMDClusterFinder(AliRunLoader* runLoader):
   fRechits(new TClonesArray("AliPMDrechit", 1000)),
   fNpoint(0),
   fNhit(0),
+  fDetNo(0),
   fEcut(0.)
 {
 //
 // Constructor
 //
-  fCalibData = GetCalibData();
+}
+// ------------------------------------------------------------------------- //
+AliPMDClusterFinder::AliPMDClusterFinder(const AliPMDClusterFinder & finder):
+  TObject(finder),
+  fRunLoader(0),
+  fPMDLoader(0),
+  fCalibGain(GetCalibGain()),
+  fCalibPed(GetCalibPed()),
+  fTreeD(0),
+  fTreeR(0),
+  fDigits(NULL),
+  fRecpoints(NULL),
+  fRechits(NULL),
+  fNpoint(0),
+  fNhit(0),
+  fDetNo(0),
+  fEcut(0.)
+{
+  // copy constructor
+  AliError("Copy constructor not allowed");
+}
+// ------------------------------------------------------------------------- //
+AliPMDClusterFinder &AliPMDClusterFinder::operator=(const AliPMDClusterFinder & /*finder*/)
+{
+ // assignment op
+  AliError("Assignment Operator not allowed");
+  return *this;
 }
 // ------------------------------------------------------------------------- //
 AliPMDClusterFinder::~AliPMDClusterFinder()
@@ -114,6 +148,7 @@ void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt)
   // Converts digits to recpoints after running clustering
   // algorithm on CPV plane and PREshower plane
   //
+
   Int_t    det = 0,smn = 0;
   Int_t    xpos,ypos;
   Float_t  adc;
@@ -170,13 +205,11 @@ void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt)
          adc    = pmddigit->GetADC();
          
          // CALIBRATION
-         Float_t gain = fCalibData->GetGainFact(det,smn,xpos,ypos);
-         
-        // printf("adc = %d gain = %f\n",adc,gain);
+         Float_t gain = fCalibGain->GetGainFact(det,smn,xpos,ypos);
+         // printf("adc = %d gain = %f\n",adc,gain);
          
          adc = adc*gain;
 
-
          //Int_t trno   = pmddigit->GetTrackNumber();
          fCellADC[xpos][ypos] = (Double_t) adc;
        }
@@ -231,14 +264,130 @@ void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt)
 }
 // ------------------------------------------------------------------------- //
 
+void AliPMDClusterFinder::Digits2RecPoints(TTree *digitsTree,
+                                          TTree *clustersTree)
+{
+  // Converts digits to recpoints after running clustering
+  // algorithm on CPV plane and PREshower plane
+  //
+
+  Int_t    det = 0,smn = 0;
+  Int_t    xpos,ypos;
+  Float_t  adc;
+  Int_t    ismn;
+  Int_t    idet;
+  Float_t  clusdata[6];
+
+  TObjArray *pmdcont = new TObjArray();
+  AliPMDClustering *pmdclust = new AliPMDClusteringV1();
+
+  pmdclust->SetEdepCut(fEcut);
+
+  AliPMDdigit  *pmddigit;
+  TBranch *branch = digitsTree->GetBranch("PMDDigit");
+  branch->SetAddress(&fDigits);
+
+  ResetRecpoint();
+
+  Int_t bufsize = 16000;
+  TBranch * branch1 = clustersTree->Branch("PMDRecpoint", &fRecpoints, bufsize); 
+  TBranch * branch2 = clustersTree->Branch("PMDRechit", &fRechits, bufsize); 
+
+  Int_t nmodules = (Int_t) digitsTree->GetEntries();
+
+  for (Int_t imodule = 0; imodule < nmodules; imodule++)
+    {
+      ResetCellADC();
+      digitsTree->GetEntry(imodule); 
+      Int_t nentries = fDigits->GetLast();
+      for (Int_t ient = 0; ient < nentries+1; ient++)
+       {
+         pmddigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
+         
+         det    = pmddigit->GetDetector();
+         smn    = pmddigit->GetSMNumber();
+         xpos   = pmddigit->GetRow();
+         ypos   = pmddigit->GetColumn();
+         adc    = pmddigit->GetADC();
+
+         // Pedestal Subtraction
+         Int_t   pedmeanrms = fCalibPed->GetPedMeanRms(det,smn,xpos,ypos);
+         Int_t   pedrms1    = (Int_t) pedmeanrms%1000;
+         Float_t pedrms     = (Float_t)pedrms1/10.;
+         Float_t pedmean    = (Float_t) (pedmeanrms - pedrms1)/1000.0;
+         //printf("%f %f\n",pedmean, pedrms);
+
+         Float_t adc1 = adc - (pedmean + 3.0*pedrms);
+
+         // CALIBRATION
+         Float_t gain = fCalibGain->GetGainFact(det,smn,xpos,ypos);
+         // printf("adc = %d gain = %f\n",adc,gain);
+
+         adc = adc1*gain;
+
+         //Int_t trno   = pmddigit->GetTrackNumber();
+         fCellADC[xpos][ypos] = (Double_t) adc;
+       }
+
+      idet = det;
+      ismn = smn;
+      pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
+      
+      Int_t nentries1 = pmdcont->GetEntries();
+
+      AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
+
+      for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
+       {
+         AliPMDcluster *pmdcl = (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
+         idet        = pmdcl->GetDetector();
+         ismn        = pmdcl->GetSMN();
+         clusdata[0] = pmdcl->GetClusX();
+         clusdata[1] = pmdcl->GetClusY();
+         clusdata[2] = pmdcl->GetClusADC();
+         clusdata[3] = pmdcl->GetClusCells();
+         clusdata[4] = pmdcl->GetClusSigmaX();
+         clusdata[5] = pmdcl->GetClusSigmaY();
+
+         AddRecPoint(idet,ismn,clusdata);
+
+         Int_t ncell = (Int_t) clusdata[3];
+         for(Int_t ihit = 0; ihit < ncell; ihit++)
+           {
+             Int_t celldataX = pmdcl->GetClusCellX(ihit);
+             Int_t celldataY = pmdcl->GetClusCellY(ihit);
+             AddRecHit(celldataX, celldataY);
+           }
+         branch2->Fill();
+         ResetRechit();
+       }
+      pmdcont->Clear();
+      
+      branch1->Fill();
+      ResetRecpoint();
+
+    } // modules
+
+  ResetCellADC();
+
+  //   delete the pointers
+  delete pmdclust;
+  delete pmdcont;
+    
+}
+// ------------------------------------------------------------------------- //
+
 void AliPMDClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
                                           TTree *clustersTree)
 {
   // Converts RAW data to recpoints after running clustering
   // algorithm on CPV and PREshower plane
   //
+  // This method is called at the time of reconstruction
+
 
   Float_t  clusdata[6];
+  TObjArray pmdddlcont;
 
   TObjArray *pmdcont = new TObjArray();
   AliPMDClustering *pmdclust = new AliPMDClusteringV1();
@@ -252,13 +401,14 @@ void AliPMDClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
 
   TBranch * branch2 = clustersTree->Branch("PMDRechit", &fRechits, bufsize); 
 
-  const Int_t kDDL = 6;
+  const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
   const Int_t kRow = 48;
   const Int_t kCol = 96;
 
   Int_t idet = 0;
   Int_t iSMN = 0;
-  
+
+
   for (Int_t indexDDL = 0; indexDDL < kDDL; indexDDL++)
     {
       if (indexDDL < 4)
@@ -289,27 +439,40 @@ void AliPMDClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
       ResetCellADC();
       rawReader->Reset();
       AliPMDRawStream pmdinput(rawReader);
-      rawReader->Select(12, indexDDL, indexDDL);
-      while(pmdinput.Next())
+
+      rawReader->Select("PMD", indexDDL, indexDDL);
+
+      pmdinput.DdlData(indexDDL,&pmdddlcont);
+
+      Int_t indexsmn = 0;
+      Int_t ientries = pmdddlcont.GetEntries();
+      for (Int_t ient = 0; ient < ientries; ient++)
        {
-         Int_t det = pmdinput.GetDetector();
-         Int_t smn = pmdinput.GetSMN();
-         //Int_t mcm = pmdinput.GetMCM();
-         //Int_t chno = pmdinput.GetChannel();
-         Int_t row = pmdinput.GetRow();
-         Int_t col = pmdinput.GetColumn();
-         Int_t sig = pmdinput.GetSignal();
+         AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
          
-         Float_t sig1 = (Float_t) sig;
+         Int_t det = pmdddl->GetDetector();
+         Int_t smn = pmdddl->GetSMN();
+         //Int_t mcm = pmdddl->GetMCM();
+         //Int_t chno = pmdddl->GetChannel();
+         Int_t row = pmdddl->GetRow();
+         Int_t col = pmdddl->GetColumn();
+         Int_t sig = pmdddl->GetSignal();
+
+         // Pedestal Subtraction
+         Int_t   pedmeanrms = fCalibPed->GetPedMeanRms(det,smn,row,col);
+         Int_t   pedrms1    = (Int_t) pedmeanrms%1000;
+         Float_t pedrms     = (Float_t)pedrms1/10.;
+         Float_t pedmean    = (Float_t) (pedmeanrms - pedrms1)/1000.0;
+
+         //printf("%f %f\n",pedmean, pedrms);
+
+         // Float_t sig1 = (Float_t) sig;
+         Float_t sig1 = (Float_t) sig - (pedmean + 3.0*pedrms);
 
          // CALIBRATION
-         Float_t gain = fCalibData->GetGainFact(det,smn,row,col);
-         
-       //  printf("sig = %d gain = %f\n",sig,gain);
-         
+         Float_t gain = fCalibGain->GetGainFact(det,smn,row,col);
+         //printf("sig = %d gain = %f\n",sig,gain);
          sig = (Int_t) (sig1*gain);
-         
-         Int_t indexsmn = 0;
 
          if (indexDDL < 4)
            {
@@ -327,9 +490,9 @@ void AliPMDClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
                {
                  indexsmn = smn;
                }
-             else if (smn >= 12 && smn < 18)
+             else if (smn >= 18 && smn < 24)
                {
-                 indexsmn = smn - 6;
+                 indexsmn = smn - 12;
                }
            }
          else if (indexDDL == 5)
@@ -341,13 +504,15 @@ void AliPMDClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
                {
                  indexsmn = smn - 6;
                }
-             else if (smn >= 18 && smn < 24)
+             else if (smn >= 12 && smn < 18)
                {
-                 indexsmn = smn - 12;
+                 indexsmn = smn - 6;
                }
            }         
          precpvADC[indexsmn][row][col] = sig;
-       } // while loop
+       }
+      
+      pmdddlcont.Clear();
 
       Int_t ismn = 0;
       for (Int_t indexsmn = 0; indexsmn < iSMN; indexsmn++)
@@ -361,6 +526,7 @@ void AliPMDClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
                    (Double_t) precpvADC[indexsmn][irow][icol];
                } // row
            }     // col
+         
          if (indexDDL < 4)
            {
              ismn = indexsmn + indexDDL * 6;
@@ -374,7 +540,7 @@ void AliPMDClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
                }
              else if (indexsmn >= 6 && indexsmn < 12)
                {
-                 ismn = indexsmn + 6;
+                 ismn = indexsmn + 12;
                }
              idet = 1;
            }
@@ -386,12 +552,11 @@ void AliPMDClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
                }
              else if (indexsmn >= 6 && indexsmn < 12)
                {
-                 ismn = indexsmn + 12;
+                 ismn = indexsmn + 6;
                }
              idet = 1;
            }
 
-
          pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
          Int_t nentries1 = pmdcont->GetEntries();
 
@@ -455,7 +620,7 @@ void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt, AliRawReader *rawReader)
   //
 
   Float_t  clusdata[6];
-
+  TObjArray pmdddlcont;
   TObjArray *pmdcont = new TObjArray();
 
   AliPMDClustering *pmdclust = new AliPMDClusteringV1();
@@ -476,7 +641,7 @@ void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt, AliRawReader *rawReader)
   TBranch *branch1 = fTreeR->Branch("PMDRecpoint", &fRecpoints, bufsize); 
   TBranch *branch2 = fTreeR->Branch("PMDRechit", &fRechits, bufsize); 
 
-  const Int_t kDDL = 6;
+  const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
   const Int_t kRow = 48;
   const Int_t kCol = 96;
 
@@ -512,27 +677,41 @@ void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt, AliRawReader *rawReader)
        }
       ResetCellADC();
       rawReader->Reset();
+      rawReader->Select("PMD", indexDDL, indexDDL);
+
       AliPMDRawStream pmdinput(rawReader);
-      rawReader->Select(12, indexDDL, indexDDL);
-      while(pmdinput.Next())
+      pmdinput.DdlData(indexDDL,&pmdddlcont);
+    
+      Int_t indexsmn = 0;
+      Int_t ientries = pmdddlcont.GetEntries();
+      for (Int_t ient = 0; ient < ientries; ient++)
        {
-         Int_t det = pmdinput.GetDetector();
-         Int_t smn = pmdinput.GetSMN();
-         //Int_t mcm = pmdinput.GetMCM();
-         //Int_t chno = pmdinput.GetChannel();
-         Int_t row = pmdinput.GetRow();
-         Int_t col = pmdinput.GetColumn();
-         Int_t sig = pmdinput.GetSignal();
-
-         Float_t sig1 = (Float_t) sig;
-         // CALIBRATION
-         Float_t gain = fCalibData->GetGainFact(det,smn,row,col);
-         
-        // printf("sig = %d gain = %f\n",sig,gain);
+         AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
          
+         Int_t det = pmdddl->GetDetector();
+         Int_t smn = pmdddl->GetSMN();
+         //Int_t mcm = pmdddl->GetMCM();
+         //Int_t chno = pmdddl->GetChannel();
+         Int_t row = pmdddl->GetRow();
+         Int_t col = pmdddl->GetColumn();
+         Int_t sig = pmdddl->GetSignal();
+
+         // Pedestal Subtraction
+         Int_t   pedmeanrms = fCalibPed->GetPedMeanRms(det,smn,row,col);
+         Int_t   pedrms1    = (Int_t) pedmeanrms%1000;
+         Float_t pedrms     = (Float_t)pedrms1/10.;
+         Float_t pedmean    = (Float_t) (pedmeanrms - pedrms1)/1000.0;
+
+         //printf("%f %f\n",pedmean, pedrms);
+
+         //Float_t sig1 = (Float_t) sig;
+         Float_t sig1 = (Float_t) sig - (pedmean + 3.0*pedrms);
+         // CALIBRATION
+         Float_t gain = fCalibGain->GetGainFact(det,smn,row,col);
+
+         //printf("sig = %d gain = %f\n",sig,gain);
          sig = (Int_t) (sig1*gain);
-         
-         Int_t indexsmn = 0;
+
 
          if (indexDDL < 4)
            {
@@ -550,9 +729,9 @@ void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt, AliRawReader *rawReader)
                {
                  indexsmn = smn;
                }
-             else if (smn >= 12 && smn < 18)
+             else if (smn >= 18 && smn < 24)
                {
-                 indexsmn = smn - 6;
+                 indexsmn = smn - 12;
                }
            }
          else if (indexDDL == 5)
@@ -564,13 +743,16 @@ void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt, AliRawReader *rawReader)
                {
                  indexsmn = smn - 6;
                }
-             else if (smn >= 18 && smn < 24)
+             else if (smn >= 12 && smn < 18)
                {
-                 indexsmn = smn - 12;
+                 indexsmn = smn - 6;
                }
            }         
          precpvADC[indexsmn][row][col] = sig;
-       } // while loop
+
+       }
+      
+      pmdddlcont.Clear();
 
       Int_t ismn = 0;
       for (Int_t indexsmn = 0; indexsmn < iSMN; indexsmn++)
@@ -584,6 +766,8 @@ void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt, AliRawReader *rawReader)
                    (Double_t) precpvADC[indexsmn][irow][icol];
                } // row
            }     // col
+
+         
          if (indexDDL < 4)
            {
              ismn = indexsmn + indexDDL * 6;
@@ -597,7 +781,7 @@ void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt, AliRawReader *rawReader)
                }
              else if (indexsmn >= 6 && indexsmn < 12)
                {
-                 ismn = indexsmn + 6;
+                 ismn = indexsmn + 12;
                }
              idet = 1;
            }
@@ -609,12 +793,11 @@ void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt, AliRawReader *rawReader)
                }
              else if (indexsmn >= 6 && indexsmn < 12)
                {
-                 ismn = indexsmn + 12;
+                 ismn = indexsmn + 6;
                }
              idet = 1;
            }
 
-
          pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
          Int_t nentries1 = pmdcont->GetEntries();
 
@@ -759,30 +942,37 @@ void AliPMDClusterFinder::UnLoadClusters()
 }
 // ------------------------------------------------------------------------- //
 
-AliPMDCalibData* AliPMDClusterFinder::GetCalibData() const
+AliPMDCalibData* AliPMDClusterFinder::GetCalibGain() const
 {
   // The run number will be centralized in AliCDBManager,
   // you don't need to set it here!
   // Added by ZA
-  AliCDBEntry  *entry = AliCDBManager::Instance()->Get("PMD/Calib/Data");
+  AliCDBEntry  *entry = AliCDBManager::Instance()->Get("PMD/Calib/Gain");
   
-  if(!entry){
-    AliWarning("Calibration object retrieval failed! Dummy calibration will be used.");
-    
-    // this just remembers the actual default storage. No problem if it is null.
-    AliCDBStorage *origStorage = AliCDBManager::Instance()->GetDefaultStorage();
-    AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
-    
-    entry = AliCDBManager::Instance()->Get("PMD/Calib/Data");
-    
-    // now reset the original default storage to AliCDBManager...
-    AliCDBManager::Instance()->SetDefaultStorage(origStorage);  
-  }
+  if(!entry)  AliFatal("Calibration object retrieval failed! ");
   
   AliPMDCalibData *calibdata=0;
   if (entry) calibdata = (AliPMDCalibData*) entry->GetObject();
   
-  if (!calibdata)  AliError("No calibration data from calibration database !");
+  if (!calibdata)  AliFatal("No calibration data from calibration database !");
   
   return calibdata;
 }
+
+// ------------------------------------------------------------------------- //
+
+AliPMDPedestal* AliPMDClusterFinder::GetCalibPed() const
+{
+  // The run number will be centralized in AliCDBManager,
+  // you don't need to set it here!
+  AliCDBEntry  *entry = AliCDBManager::Instance()->Get("PMD/Calib/Ped");
+  
+  if(!entry) AliFatal("Pedestal object retrieval failed!");
+    
+  AliPMDPedestal *pedestal = 0;
+  if (entry) pedestal = (AliPMDPedestal*) entry->GetObject();
+  
+  if (!pedestal)  AliFatal("No pedestal data from pedestal database !");
+  
+  return pedestal;
+}