]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RICH/AliRICHDigitizer.cxx
fix in Gain
[u/mrichter/AliRoot.git] / RICH / AliRICHDigitizer.cxx
index 05d8448c28334257aeb0593e49221f1d4cce878b..c95af38e2f869e992d9498c798b04f7e69e28a96 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-
-#include <Riostream.h> 
-
-#include <TTree.h> 
-#include <TObjArray.h>
-#include <TFile.h>
-#include <TDirectory.h>
-#include <TParticle.h>
-
-#include <AliRunLoader.h>
-#include <AliLoader.h>
-
 #include "AliRICHDigitizer.h"
 #include "AliRICH.h"
+#include <AliRun.h>
+#include <AliRunLoader.h>
 #include "AliRunDigitizer.h"
+#include <AliLoader.h>
+#include <AliLog.h>
+
 
 ClassImp(AliRICHDigitizer)
 
-//__________________________________________________________________________________________________
-AliRICHDigitizer::AliRICHDigitizer() 
-{//default constructor
-}//default ctor
-//__________________________________________________________________________________________________
-AliRICHDigitizer::AliRICHDigitizer(AliRunDigitizer *pManager) 
-                 :AliDigitizer(pManager)
-{
-//main ctor which should be used
-  Info("main ctor","Start.");
-  fRich=(AliRICH*)gAlice->GetDetector("RICH");
-  Rich()->Param()->GenSigmaThMap();
-}//main ctor
-//__________________________________________________________________________________________________
-AliRICHDigitizer::~AliRICHDigitizer()
-{
-//dtor
-  Info("dtor","Start.");
-}//dtor
 //__________________________________________________________________________________________________
 void AliRICHDigitizer::Exec(Option_t*)
 {
-  Info("Exec","\n\n\n\n");
-  Info("Exec","Start with %i input(s) for event %i",fManager->GetNinputs(),fManager->GetOutputEventNr());
-  
-  AliRunLoader *pInAL=0, *pOutAL;//in and out Run loaders
-  AliLoader    *pInRL=0, *pOutRL;//in and out RICH loaders
-  pOutAL = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
-  pOutRL = pOutAL->GetLoader("RICHLoader");
-  pOutRL->MakeTree("D");   Rich()->MakeBranch("D"); //create TreeD with RICH branches in output stream
-
+//This methode is responsible for merging sdigits to a list of digits
+//Disintegration leeds to the fact that one hit affected several neighbouring pads, which means that the same pad might be
+//affected by few hits.     
+  AliDebug(1,Form("Start with %i input(s) for event %i",fManager->GetNinputs(),fManager->GetOutputEventNr()));
+//First we read all sdigits from all inputs  
+  AliRunLoader *pInRunLoader=0;//in and out Run loaders
+  AliLoader    *pInRichLoader=0;//in and out RICH loaders  
+  TClonesArray tmpCA("AliRICHDigit");//tmp storage for sdigits sum up from all input files
+  Int_t total=0;
   for(Int_t inFileN=0;inFileN<fManager->GetNinputs();inFileN++){//files loop
-    pInAL = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inFileN)); pInRL = pInAL->GetLoader("RICHLoader");
-    pInAL->GetEvent(fManager->GetOutputEventNr());    pInRL->LoadSDigits();    pInRL->TreeS()->GetEntry(0);
-    Info("Exec","Run Loader %p RICH Loader %p RICH %p",pInAL,pInRL,Rich());
-    Rich()->SDigits()->Print();
-    pInRL->UnloadSDigits();
+    pInRunLoader  = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inFileN));          //get run loader from current input 
+    pInRichLoader = pInRunLoader->GetLoader("RICHLoader"); if(pInRichLoader==0) continue;       //no RICH in this input, check the next input
+    if (!pInRunLoader->GetAliRun()) pInRunLoader->LoadgAlice();
+    AliRICH* pInRich=(AliRICH*)pInRunLoader->GetAliRun()->GetDetector("RICH");                  //take RICH from current input
+    pInRichLoader->LoadSDigits(); pInRichLoader->TreeS()->GetEntry(0);                          //take list of RICH sdigits from current input 
+    AliDebug(1,Form("input %i has %i sdigits",inFileN,pInRich->SDigits()->GetEntries()));
+    for(Int_t i=0;i<pInRich->SDigits()->GetEntries();i++){//collect sdigits from current input to tmpCA
+      new(tmpCA[total++]) AliRICHDigit(*(AliRICHDigit*)pInRich->SDigits()->At(i)); 
+      ((AliRICHDigit*)tmpCA[total-1])->AddTidOffset(fManager->GetMask(inFileN));//apply TID shift since all inputs count tracks independently starting from 0
+    }
+    pInRichLoader->UnloadSDigits();   pInRich->SDigitsReset(); //close current input and reset 
   }//files loop
   
-//     Rich()->SDigits()->Sort();                     //sort them according to Id() methode
-//       
-//     Int_t combiPid=0,chamber=0,x=0,y=0,tid[3],id=0; Double_t q=0;
-//     Int_t iNdigitsPerPad=0;//how many sdigits for a given pad
-//     for(Int_t i=0;i<Rich()->SDigits()->GetEntries();i++){//sdigits loop (sorted)
-//       AliRICHdigit *pSdig=(AliRICHdigit*)Rich()->SDigits()->At(i);
-//       if(pSdig->Id()==id){//still the same pad
-//         iNdigitsPerPad++;
-//         q+=pSdig->Q();
-//         combiPid+=pSdig->CombiPid();
-//         if(iNdigitsPerPad<=3)
-//           tid[iNdigitsPerPad-1]=pSdig->Tid(0);
-//         else
-//           Warning("SDigits2Digits","More then 3 sdigits for the given pad");
-//       }else{//new pad, add the pevious one
-//         if(id!=kBad&&Rich()->Param()->IsOverTh(chamber,x,y,q)) {
-//            Rich()->AddDigit(chamber,x,y,(Int_t)q,combiPid,tid); //add newly created digit to the list of digits
-//          }
-//         combiPid=pSdig->CombiPid();chamber=pSdig->C();id=pSdig->Id();
-//         x=pSdig->X();y=pSdig->Y();
-//         q=pSdig->Q();
-//         tid[0]=pSdig->Tid(0);
-//         iNdigitsPerPad=1;tid[1]=tid[2]=kBad;
-//       }
-//     }//sdigits loop (sorted)
-//   
-//     if(Rich()->SDigits()->GetEntries()&&Rich()->Param()->IsOverTh(chamber,x,y,q))
-//       Rich()->AddDigit(chamber,x,y,(Int_t)q,combiPid,tid);//add the last digit
-//         
-  pOutRL->TreeD()->Fill();              //fill the tree with the list of digits
-  pOutRL->WriteDigits("OVERWRITE");     //serialize them to file
-            
-  Info("Exec","Stop\n\n\n\n");
+  tmpCA.Sort();                     //at this point we have a list of all sdigits from all inputs, now sort them according to fPad field
+  
+  AliRunLoader *pOutRunLoader  = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());    //open output stream (only 1 possible)
+  AliLoader    *pOutRichLoader = pOutRunLoader->GetLoader("RICHLoader");                         //take output RICH loader
+  AliRICH      *pOutRich       = (AliRICH*)pOutRunLoader->GetAliRun()->GetDetector("RICH");      //take output RICH
+  pOutRichLoader->MakeTree("D");   pOutRich->MakeBranch("D");                                    //create TreeD in output stream
+  
+  TVector pad(2); pad[0]=0; pad[1]=0; Int_t iChamber=0,iCfm=0,aTids[3]={0,0,0},iId=-1; Double_t dQdc=0;//current pad info   
+  Int_t iNdigsPerPad=0;                   //how many sdigits for a given pad
+  for(Int_t i=0;i<tmpCA.GetEntries();i++){//sdigits loop (sorted)
+    AliRICHDigit *pSdig=(AliRICHDigit*)tmpCA.At(i);//get new sdigit
+    if(pSdig->PadAbs()==iId){//still the same pad
+      iNdigsPerPad++;         dQdc+=pSdig->Qdc();      iCfm+=pSdig->Cfm();//sum up charge and cfm
+      if(pSdig->Cfm()==1) aTids[0] = pSdig->GetTrack(0); // force the first tid to be mip's tid if it exists in the current pad
+      if(iNdigsPerPad<=3)        aTids[iNdigsPerPad-1]=pSdig->GetTrack(0);
+      else                         AliDebug(1,Form("More then 3 sdigits in (%d,%d,%f,%f) with Q= %f",pSdig->Chamber(),pSdig->Sector(),pSdig->Pad()(0),pSdig->Pad()(1),pSdig->Qdc()));
+    }else{//new pad, add the pevious one
+        if(iId!=-1 && AliRICHParam::IsOverTh(iChamber,pad,dQdc)) pOutRich->DigitAdd(iChamber,pad,(Int_t)dQdc,iCfm,aTids); //add newly created dig
+        iChamber=pSdig->Chamber(); pad=pSdig->Pad(); iCfm=pSdig->Cfm(); dQdc=pSdig->Qdc();  iId=pSdig->PadAbs();                    //init all values by current sdig
+        iNdigsPerPad=1; aTids[0]=pSdig->GetTrack(0); aTids[1]=aTids[2]=-1;
+      }
+  }//sdigits loop (sorted)
+  if(tmpCA.GetEntries() && AliRICHParam::IsOverTh(iChamber,pad,dQdc)) pOutRich->DigitAdd(iChamber,pad,(Int_t)dQdc,iCfm,aTids);//add the last dig
+  
+  pOutRichLoader->TreeD()->Fill();              //fill the output tree with the list of digits
+  pOutRichLoader->WriteDigits("OVERWRITE");     //serialize them to file
+  
+  tmpCA.Clear();                      //remove all tmp sdigits
+  pOutRichLoader->UnloadDigits();   pOutRich->DigitsReset();
 }//Exec()
-//__________________________________________________________________________________________________