]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - FMD/AliFMDInput.cxx
Adding calibration object for the sharing efficiency
[u/mrichter/AliRoot.git] / FMD / AliFMDInput.cxx
index 4496982720aa754bdee0b3cedfe832d37bcd167f..d1c8daa5257d469d42401b50305bf02183fec6f0 100644 (file)
@@ -37,6 +37,7 @@
 #include "AliRawReaderFile.h"   // ALIRAWREADERFILE_H
 #include "AliRawReaderRoot.h"   // ALIRAWREADERROOT_H
 #include "AliRawReaderDate.h"   // ALIRAWREADERDATE_H
+#include "AliRawEventHeaderBase.h" 
 #include "AliFMD.h"             // ALIFMD_H
 #include "AliFMDHit.h"         // ALIFMDHIT_H
 #include "AliFMDDigit.h"       // ALIFMDDigit_H
@@ -49,6 +50,7 @@
 #include <AliCDBManager.h>
 #include <AliCDBEntry.h>
 #include <AliAlignObjParams.h>
+#include <AliTrackReference.h>
 #include <TTree.h>              // ROOT_TTree
 #include <TChain.h>             // ROOT_TChain
 #include <TParticle.h>          // ROOT_TParticle
@@ -84,6 +86,7 @@ AliFMDInput::AliFMDInput()
     fESDEvent(0),
     fTreeE(0),
     fTreeH(0),
+    fTreeTR(0),
     fTreeD(0),
     fTreeS(0),
     fTreeR(0), 
@@ -91,6 +94,7 @@ AliFMDInput::AliFMDInput()
     fChainE(0),
     fArrayE(0),
     fArrayH(0),
+    fArrayTR(0), 
     fArrayD(0),
     fArrayS(0), 
     fArrayR(0), 
@@ -126,6 +130,7 @@ AliFMDInput::AliFMDInput(const char* gAliceFile)
     fESDEvent(0),
     fTreeE(0),
     fTreeH(0),
+    fTreeTR(0),
     fTreeD(0),
     fTreeS(0),
     fTreeR(0), 
@@ -133,6 +138,7 @@ AliFMDInput::AliFMDInput(const char* gAliceFile)
     fChainE(0),
     fArrayE(0),
     fArrayH(0),
+    fArrayTR(0), 
     fArrayD(0),
     fArrayS(0), 
     fArrayR(0), 
@@ -156,7 +162,9 @@ Int_t
 AliFMDInput::NEvents() const 
 {
   // Get number of events
-  if (TESTBIT(fTreeMask, kRaw)) return -1;
+  if (TESTBIT(fTreeMask, kRaw) || 
+      TESTBIT(fTreeMask, kRawCalib)) return fReader->GetNumberOfEvents();
+  if (fChainE) return fChainE->GetEntriesFast();
   if (fTreeE) return fTreeE->GetEntries();
   return -1;
 }
@@ -172,37 +180,73 @@ AliFMDInput::Init()
     AliWarning("Already initialized");
     return fIsInit;
   }
+  Info("Init","Initialising w/mask 0x%04x\n"
+       "\tHits:          %d\n"
+       "\tKinematics:    %d\n"
+       "\tDigits:        %d\n"
+       "\tSDigits:       %d\n"
+       "\tHeader:        %d\n"
+       "\tRecPoints:     %d\n"
+       "\tESD:           %d\n"
+       "\tRaw:           %d\n"
+       "\tRawCalib:      %d\n"
+       "\tGeometry:      %d\n"
+       "\tTracks:        %d\n"
+       "\tTracksRefs:    %d",
+       fTreeMask,
+       TESTBIT(fTreeMask, kHits),
+       TESTBIT(fTreeMask, kKinematics),
+       TESTBIT(fTreeMask, kDigits),
+       TESTBIT(fTreeMask, kSDigits),
+       TESTBIT(fTreeMask, kHeader),
+       TESTBIT(fTreeMask, kRecPoints),
+       TESTBIT(fTreeMask, kESD),
+       TESTBIT(fTreeMask, kRaw),
+       TESTBIT(fTreeMask, kRawCalib),
+       TESTBIT(fTreeMask, kGeometry),
+       TESTBIT(fTreeMask, kTracks),
+       TESTBIT(fTreeMask, kTrackRefs));
   // Get the run 
-  if (!TESTBIT(fTreeMask, kRaw)) { 
-    if (fGAliceFile.IsNull()) fGAliceFile = "galice.root";
-    // Get the loader
-    fLoader = AliRunLoader::Open(fGAliceFile.Data(), "Alice", "read");
-    if (!fLoader) {
-      AliError(Form("Coulnd't read the file %s", fGAliceFile.Data()));
-      return kFALSE;
-    }
-  
-    if  (fLoader->LoadgAlice()) return kFALSE;
-    fRun = fLoader->GetAliRun();
-  
-    // Get the FMD 
-    fFMD = static_cast<AliFMD*>(fRun->GetDetector("FMD"));
-    if (!fFMD) {
-      AliError("Failed to get detector FMD from loader");
-      return kFALSE;
-    }
-  
-    // Get the FMD loader
-    fFMDLoader = fLoader->GetLoader("FMDLoader");
-    if (!fFMDLoader) {
-      AliError("Failed to get detector FMD loader from loader");
-      return kFALSE;
+  if (TESTBIT(fTreeMask, kDigits)     ||
+      TESTBIT(fTreeMask, kSDigits)    || 
+      TESTBIT(fTreeMask, kKinematics) || 
+      TESTBIT(fTreeMask, kTrackRefs)  || 
+      TESTBIT(fTreeMask, kTracks)     || 
+      TESTBIT(fTreeMask, kHeader)) {
+    if (!gSystem->FindFile(".:/", fGAliceFile)) {
+      AliWarning(Form("Cannot find file %s in .:/", fGAliceFile.Data()));
     }
-    if (fLoader->LoadHeader()) { 
-      AliError("Failed to get event header information from loader");
-      return kFALSE;
+    else {
+      fLoader = AliRunLoader::Open(fGAliceFile.Data(), "Alice", "read");
+      if (!fLoader) {
+       AliError(Form("Coulnd't read the file %s", fGAliceFile.Data()));
+       return kFALSE;
+      }
+      AliInfo(Form("Opened GAlice file %s", fGAliceFile.Data()));
+
+      if  (fLoader->LoadgAlice()) return kFALSE;
+      
+      fRun = fLoader->GetAliRun();
+      
+      // Get the FMD 
+      fFMD = static_cast<AliFMD*>(fRun->GetDetector("FMD"));
+      if (!fFMD) {
+       AliError("Failed to get detector FMD from loader");
+       return kFALSE;
+      }
+      
+      // Get the FMD loader
+      fFMDLoader = fLoader->GetLoader("FMDLoader");
+      if (!fFMDLoader) {
+       AliError("Failed to get detector FMD loader from loader");
+       return kFALSE;
+      }
+      if (fLoader->LoadHeader()) { 
+       AliError("Failed to get event header information from loader");
+       return kFALSE;
+      }
+      fTreeE = fLoader->TreeE();
     }
-    fTreeE = fLoader->TreeE();
   }
 
   // Optionally, get the ESD files
@@ -227,7 +271,8 @@ AliFMDInput::Init()
     
   }
     
-  if (TESTBIT(fTreeMask, kRaw)) {
+  if (TESTBIT(fTreeMask, kRaw) || 
+      TESTBIT(fTreeMask, kRawCalib)) {
     AliInfo("Getting FMD raw data digits");
     fArrayA = new TClonesArray("AliFMDDigit");
 #if 0
@@ -323,7 +368,16 @@ AliFMDInput::Begin(Int_t event)
     fTreeH = fFMDLoader->TreeH();
     if (!fArrayH) fArrayH = fFMD->Hits(); 
   }
-
+  
+  // Possibly load FMD TrackReference information 
+  if (TESTBIT(fTreeMask, kTrackRefs) || TESTBIT(fTreeMask, kTracks)) {
+    // AliInfo("Getting FMD hits");
+    if (!fLoader || fLoader->LoadTrackRefs("READ")) return kFALSE;
+    fTreeTR = fLoader->TreeTR();
+    if (!fArrayTR) fArrayTR = new TClonesArray("AliTrackReference");
+    fTreeTR->SetBranchAddress("TrackReferences",  &fArrayTR);
+  }
+  
   // Possibly load heaedr information 
   if (TESTBIT(fTreeMask, kHeader)) {
     // AliInfo("Getting FMD hits");
@@ -348,7 +402,10 @@ AliFMDInput::Begin(Int_t event)
   // Possibly load FMD Sdigit information 
   if (TESTBIT(fTreeMask, kSDigits)) {
     // AliInfo("Getting FMD summable digits");
-    if (!fFMDLoader || fFMDLoader->LoadSDigits("READ")) return kFALSE;
+    if (!fFMDLoader || fFMDLoader->LoadSDigits("READ")) { 
+      AliWarning("Failed to load SDigits!");
+      return kFALSE;
+    }
     fTreeS = fFMDLoader->TreeS();
     if (!fArrayS) fArrayS = fFMD->SDigits();
   }
@@ -384,9 +441,24 @@ AliFMDInput::Begin(Int_t event)
   }
 
   // Possibly load FMD Digit information 
-  if (TESTBIT(fTreeMask, kRaw)) {
+  if (TESTBIT(fTreeMask, kRaw) || TESTBIT(fTreeMask, kRawCalib)) {
+    Bool_t mon = fRawFile.Contains("mem://");
     // AliInfo("Getting FMD raw data digits");
-    if (!fReader->NextEvent()) return kFALSE;
+    if (mon) std::cout << "Waiting for event ..." << std::flush;
+    do { 
+      if (!fReader->NextEvent()) { 
+       if (mon) { 
+         gSystem->Sleep(3);
+         continue;
+       }
+       return kFALSE;
+      }
+      UInt_t eventType = fReader->GetType();
+      if(eventType == AliRawEventHeaderBase::kPhysicsEvent ||
+        eventType == AliRawEventHeaderBase::kCalibrationEvent) 
+       break;
+    } while (true);
+    if (mon) std::cout << "got it" << std::endl;
     // AliFMDRawReader r(fReader, 0);
     fArrayA->Clear();
     fFMDReader->ReadAdcs(fArrayA);
@@ -411,18 +483,24 @@ AliFMDInput::Event()
   // 
   if (TESTBIT(fTreeMask, kHits)) 
     if (!ProcessHits()) return kFALSE; 
+  if (TESTBIT(fTreeMask, kTrackRefs)) 
+    if (!ProcessTrackRefs()) return kFALSE; 
   if (TESTBIT(fTreeMask, kTracks)) 
     if (!ProcessTracks()) return kFALSE; 
-  if (TESTBIT(fTreeMask, kDigits)) 
-    if (!ProcessDigits()) return kFALSE;
   if (TESTBIT(fTreeMask, kSDigits)) 
     if (!ProcessSDigits()) return kFALSE;
+  if (TESTBIT(fTreeMask, kDigits)) 
+    if (!ProcessDigits()) return kFALSE;
   if (TESTBIT(fTreeMask, kRaw)) 
     if (!ProcessRawDigits()) return kFALSE;
+  if (TESTBIT(fTreeMask, kRawCalib)) 
+    if (!ProcessRawCalibDigits()) return kFALSE;
   if (TESTBIT(fTreeMask, kRecPoints)) 
     if (!ProcessRecPoints()) return kFALSE;
   if (TESTBIT(fTreeMask, kESD))
     if (!ProcessESDs()) return kFALSE;
+  if (TESTBIT(fTreeMask, kUser))
+    if (!ProcessUsers()) return kFALSE;
   
   return kTRUE;
 }
@@ -464,7 +542,40 @@ AliFMDInput::ProcessHits()
   }
   return kTRUE;
 }
+//____________________________________________________________________
+Bool_t 
+AliFMDInput::ProcessTrackRefs()
+{
+  // Read the reconstrcted points tree, and pass each reconstruction
+  // object (AliFMDRecPoint) to either ProcessRecPoint.
+  if (!fTreeTR) {
+    AliError("No track reference tree defined");
+    return kFALSE;
+  }
+  if (!fArrayTR) {
+    AliError("No track reference array defined");
+    return kFALSE;
+  }
 
+  Int_t nEv = fTreeTR->GetEntries();
+  for (Int_t i = 0; i < nEv; i++) {
+    Int_t trRead  = fTreeTR->GetEntry(i);
+    if (trRead <= 0) continue;
+    Int_t nTrackRefs = fArrayTR->GetEntries();
+    for (Int_t j = 0; j < nTrackRefs; j++) {
+      AliTrackReference* trackRef = static_cast<AliTrackReference*>(fArrayTR->At(j));
+      if (!trackRef) continue;
+      if (trackRef->DetectorId() != AliTrackReference::kFMD) continue;
+      TParticle* track = 0;
+      if (TESTBIT(fTreeMask, kKinematics) && fStack) {
+       Int_t trackno = trackRef->GetTrack();
+       track = fStack->Particle(trackno);
+      }
+      if (!ProcessTrackRef(trackRef,track)) return kFALSE;
+    }    
+  }
+  return kTRUE;
+}
 //____________________________________________________________________
 Bool_t 
 AliFMDInput::ProcessTracks()
@@ -558,9 +669,13 @@ AliFMDInput::ProcessSDigits()
   Int_t nEv = fTreeS->GetEntries();
   for (Int_t i = 0; i < nEv; i++) {
     Int_t sdigitRead  = fTreeS->GetEntry(i);
-    if (sdigitRead <= 0) continue;
-    Int_t nSdigit = fArrayS->GetEntries();
+    if (sdigitRead <= 0) { 
+      AliInfo(Form("Read nothing from tree"));
+      continue;
+    }
+    Int_t nSdigit = fArrayS->GetEntriesFast();
     AliFMDDebug(0, ("Got %5d digits for this event", nSdigit));
+    AliInfo(Form("Got %5d digits for this event", nSdigit));
     if (nSdigit <= 0) continue;
     for (Int_t j = 0; j < nSdigit; j++) {
       AliFMDSDigit* sdigit = static_cast<AliFMDSDigit*>(fArrayS->At(j));
@@ -594,6 +709,29 @@ AliFMDInput::ProcessRawDigits()
   return kTRUE;
 }
 
+//____________________________________________________________________
+Bool_t 
+AliFMDInput::ProcessRawCalibDigits()
+{
+  // Read the digit tree, and pass each digit to the member function
+  // ProcessDigit.
+  if (!fArrayA) {
+    AliError("No raw digit array defined");
+    return kFALSE;
+  }
+
+  Int_t nDigit = fArrayA->GetEntries();
+  if (nDigit <= 0) return kTRUE;
+  for (Int_t j = 0; j < nDigit; j++) {
+    AliFMDDigit* digit = static_cast<AliFMDDigit*>(fArrayA->At(j));
+    if (!digit) continue;
+    if (AliLog::GetDebugLevel("FMD","") >= 40 && j < 30) 
+      digit->Print();
+    if (!ProcessRawCalibDigit(digit)) return kFALSE;
+  }    
+  return kTRUE;
+}
+
 //____________________________________________________________________
 Bool_t 
 AliFMDInput::ProcessRecPoints()
@@ -648,6 +786,27 @@ AliFMDInput::ProcessESDs()
   return kTRUE;
 }
 
+//____________________________________________________________________
+Bool_t 
+AliFMDInput::ProcessUsers()
+{
+  // Process event summary data
+  for (UShort_t det = 1; det <= 3; det++) {
+    Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
+    for (Char_t* rng = rings; *rng != '\0'; rng++) {
+      UShort_t nsec = (*rng == 'I' ?  20 :  40);
+      UShort_t nstr = (*rng == 'I' ? 512 : 256);
+      for (UShort_t sec = 0; sec < nsec; sec++) {
+       for (UShort_t str = 0; str < nstr; str++) {
+         Float_t v  = GetSignal(det,*rng,sec,str);
+         if (!ProcessUser(det, *rng, sec, str, v)) continue;
+       }
+      }
+    }
+  }
+  return kTRUE;
+}
+
 //____________________________________________________________________
 Bool_t
 AliFMDInput::End()