]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RICH/AliRICHDigitizer.cxx
0129130f9cc8a4ba13cdede0b065486ebb771525
[u/mrichter/AliRoot.git] / RICH / AliRICHDigitizer.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 #include "AliRICHDigitizer.h"
17 #include "AliRICH.h"
18 #include <AliRun.h>
19 #include <AliRunLoader.h>
20 #include "AliRunDigitizer.h"
21 #include <AliLoader.h>
22 #include <AliLog.h>
23
24
25 ClassImp(AliRICHDigitizer)
26
27 //__________________________________________________________________________________________________
28 void AliRICHDigitizer::Exec(Option_t*)
29 {
30 //This methode is responsible for merging sdigits to a list of digits
31 //Disintegration leeds to the fact that one hit affected several neighbouring pads, which means that the same pad might be
32 //affected by few hits.     
33   AliDebug(1,Form("Start with %i input(s) for event %i",fManager->GetNinputs(),fManager->GetOutputEventNr()));
34 //First we read all sdigits from all inputs  
35   AliRunLoader *pInRunLoader=0;//in and out Run loaders
36   AliLoader    *pInRichLoader=0;//in and out RICH loaders  
37   TClonesArray tmpCA("AliRICHDigit");//tmp storage for sdigits sum up from all input files
38   Int_t total=0;
39   for(Int_t inFileN=0;inFileN<fManager->GetNinputs();inFileN++){//files loop
40     pInRunLoader  = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inFileN));          //get run loader from current input 
41     pInRichLoader = pInRunLoader->GetLoader("RICHLoader"); if(pInRichLoader==0) continue;       //no RICH in this input, check the next input
42     if (!pInRunLoader->GetAliRun()) pInRunLoader->LoadgAlice();
43     AliRICH* pInRich=(AliRICH*)pInRunLoader->GetAliRun()->GetDetector("RICH");                  //take RICH from current input
44     pInRichLoader->LoadSDigits(); pInRichLoader->TreeS()->GetEntry(0);                          //take list of RICH sdigits from current input 
45     AliDebug(1,Form("input %i has %i sdigits",inFileN,pInRich->SDigs()->GetEntries()));
46     for(Int_t i=0;i<pInRich->SDigs()->GetEntries();i++){//collect sdigits from current input to tmpCA
47       new(tmpCA[total++]) AliRICHDigit(*(AliRICHDigit*)pInRich->SDigs()->At(i)); 
48       ((AliRICHDigit*)tmpCA[total-1])->AddTidOffset(fManager->GetMask(inFileN));//apply TID shift since all inputs count tracks independently starting from 0
49     }
50     pInRichLoader->UnloadSDigits();   pInRich->SDigReset(); //close current input and reset 
51   }//files loop
52   
53   tmpCA.Sort();                     //at this point we have a list of all sdigits from all inputs, now sort them according to fPad field
54   
55   AliRunLoader *pOutRunLoader  = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());    //open output stream (only 1 possible)
56   AliLoader    *pOutRichLoader = pOutRunLoader->GetLoader("RICHLoader");                         //take output RICH loader
57   AliRICH      *pOutRich       = (AliRICH*)pOutRunLoader->GetAliRun()->GetDetector("RICH");      //take output RICH
58   pOutRichLoader->MakeTree("D");   pOutRich->MakeBranch("D");                                    //create TreeD in output stream
59   
60   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   
61   Int_t iNdigsPerPad=0;                   //how many sdigits for a given pad
62   for(Int_t i=0;i<tmpCA.GetEntries();i++){//sdigits loop (sorted)
63     AliRICHDigit *pSdig=(AliRICHDigit*)tmpCA.At(i);//get new sdigit
64     if(pSdig->PadAbs()==iId){//still the same pad
65       iNdigsPerPad++;         dQdc+=pSdig->Qdc();      iCfm+=pSdig->Cfm();//sum up charge and cfm
66       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
67       if(iNdigsPerPad<=3)        aTids[iNdigsPerPad-1]=pSdig->GetTrack(0);
68       else                         AliDebug(1,Form("More then 3 sdigits in (%d,%d,%f,%f) with Q= %f",pSdig->Chamber(),-1,pSdig->Pad()(0),pSdig->Pad()(1),pSdig->Qdc()));
69     }else{//new pad, add the pevious one
70         if(iId!=-1 && AliRICHParam::IsOverTh(iChamber,pad,dQdc)) pOutRich->DigAdd(iChamber,pad,(Int_t)dQdc,iCfm,aTids); //add newly created dig
71         iChamber=pSdig->Chamber(); pad=pSdig->Pad(); iCfm=pSdig->Cfm(); dQdc=pSdig->Qdc();  iId=pSdig->PadAbs();                    //init all values by current sdig
72         iNdigsPerPad=1; aTids[0]=pSdig->GetTrack(0); aTids[1]=aTids[2]=-1;
73       }
74   }//sdigits loop (sorted)
75   if(tmpCA.GetEntries() && AliRICHParam::IsOverTh(iChamber,pad,dQdc)) pOutRich->DigAdd(iChamber,pad,(Int_t)dQdc,iCfm,aTids);//add the last dig
76   
77   pOutRichLoader->TreeD()->Fill();              //fill the output tree with the list of digits
78   pOutRichLoader->WriteDigits("OVERWRITE");     //serialize them to file
79   
80   tmpCA.Clear();                      //remove all tmp sdigits
81   pOutRichLoader->UnloadDigits();   pOutRich->DigReset();
82 }//Exec()