]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/AliHMPIDDigitizer.cxx
Magnetic field properly set in display.
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDDigitizer.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 "AliHMPIDDigitizer.h"
17 #include "AliHMPID.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(AliHMPIDDigitizer)
26
27 Bool_t AliHMPIDDigitizer::fDoNoise=kFALSE;
28 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29 void AliHMPIDDigitizer::Exec(Option_t*)
30 {
31 // This methode is responsible for merging sdigits to a list of digits
32 //Disintegration leeds to the fact that one hit affects several neighbouring pads, which means that the same pad might be 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 HMPID loaders  
37   TClonesArray sdigs("AliHMPIDDigit");//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("HMPIDLoader"); if(pInRichLoader==0) continue;       //no HMPID in this input, check the next input
42     if (!pInRunLoader->GetAliRun()) pInRunLoader->LoadgAlice();
43     AliHMPID* pInRich=(AliHMPID*)pInRunLoader->GetAliRun()->GetDetector("HMPID");                  //take HMPID from current input
44     pInRichLoader->LoadSDigits(); pInRichLoader->TreeS()->GetEntry(0);                          //take list of HMPID sdigits from current input 
45     AliDebug(1,Form("input %i has %i sdigits",inFileN,pInRich->SdiLst()->GetEntries()));
46     for(Int_t i=0;i<pInRich->SdiLst()->GetEntries();i++){                                        //collect sdigits from current input
47       AliHMPIDDigit *pSDig=(AliHMPIDDigit*)pInRich->SdiLst()->At(i);
48       pSDig->AddTidOffset(fManager->GetMask(inFileN));                                          //apply TID shift since all inputs count tracks independently starting from 0
49       new(sdigs[total++]) AliHMPIDDigit(*pSDig);       
50     }
51     pInRichLoader->UnloadSDigits();   pInRich->SdiReset(); //close current input and reset 
52   }//files loop
53
54   //PH  if(sdigs.GetEntries()==0) return;                                                              //no sdigits collected, nothing to convert  
55   
56   AliRunLoader *pOutRunLoader  = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());    //open output stream (only 1 possible)
57   AliLoader    *pOutRichLoader = pOutRunLoader->GetLoader("HMPIDLoader");                         //take output HMPID loader
58   AliHMPID      *pOutRich       = (AliHMPID*)pOutRunLoader->GetAliRun()->GetDetector("HMPID");      //take output HMPID
59   pOutRichLoader->MakeTree("D");   pOutRich->MakeBranch("D");                                    //create TreeD in output stream
60
61   Sdi2Dig(&sdigs,pOutRich->DigLst());
62   
63   pOutRichLoader->TreeD()->Fill();              //fill the output tree with the list of digits
64   pOutRichLoader->WriteDigits("OVERWRITE");     //serialize them to file
65   
66   sdigs.Clear();                      //remove all tmp sdigits
67   pOutRichLoader->UnloadDigits();   pOutRich->DigReset();
68 }//Exec()
69 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
70 void AliHMPIDDigitizer::Sdi2Dig(TClonesArray *pSdiLst,TObjArray *pDigLst)
71 {
72 // Converts list of sdigits to 7 lists of digits, one per each chamber
73 // Arguments: pSDigLst - list of all sdigits
74 //            pDigLst  - list of 7 lists of digits        
75 //   Returns: none  
76   
77   TClonesArray *pLst[7]; Int_t iCnt[7];
78   
79   for(Int_t i=0;i<7;i++){
80     pLst[i]=(TClonesArray*)(*pDigLst)[i];
81     iCnt[i]=0; if(pLst[i]->GetEntries()!=0) AliErrorClass("Some of digits lists is not empty");         //in principle those lists should be empty                                                                       
82   }
83
84   // make noise array
85   Float_t arrNoise[7][6][80][48];
86   if(fDoNoise) {
87     for (Int_t iCh=AliHMPIDDigit::kMinCh;iCh<=AliHMPIDDigit::kMaxCh;iCh++)
88       for (Int_t iPc=AliHMPIDDigit::kMinPc;iPc<=AliHMPIDDigit::kMaxPc;iPc++)
89         for(Int_t iPx=AliHMPIDDigit::kMinPx;iPx<=AliHMPIDDigit::kMaxPx;iPx++)
90           for(Int_t iPy=AliHMPIDDigit::kMinPy;iPy<=AliHMPIDDigit::kMaxPy;iPy++) arrNoise[iCh][iPc][iPx][iPy] = gRandom->Gaus(0,1);
91   }  
92   
93   pSdiLst->Sort();  
94                      
95   Int_t iPad=-1,iCh=-1,iNdigPad=-1,aTids[3]={-1,-1,-1}; Float_t q=-1;
96   for(Int_t i=0;i<pSdiLst->GetEntries();i++){                                                                  //sdigits loop (sorted)
97     AliHMPIDDigit *pSdig=(AliHMPIDDigit*)pSdiLst->At(i);                                                         //take current sdigit
98     if(pSdig->Pad()==iPad){                                                                                    //if the same pad 
99       q+=pSdig->Q();                                                                                           //sum up charge
100       iNdigPad++; if(iNdigPad<=3) aTids[iNdigPad-1]=pSdig->GetTrack(0);                                        //collect TID 
101       continue;
102     }
103     if(i!=0 && AliHMPIDDigit::IsOverTh(q))  new((*pLst[iCh])[iCnt[iCh]++]) AliHMPIDDigit(iPad,(Int_t)q,aTids);   //do not create digit for the very first sdigit 
104     iPad=pSdig->Pad(); iCh=AliHMPIDDigit::A2C(iPad);                                                            //new sdigit comes, reset collectors
105     iNdigPad=1;
106     aTids[0]=pSdig->GetTrack(0);aTids[1]=aTids[2]=-1; 
107     q=pSdig->Q();
108     if(fDoNoise) q+=arrNoise[iCh][pSdig->Pc()][pSdig->PadPcX()][pSdig->PadPcY()];
109     arrNoise[iCh][pSdig->Pc()][pSdig->PadPcX()][pSdig->PadPcY()]=0;
110   }//sdigits loop (sorted)
111   
112   if(AliHMPIDDigit::IsOverTh(q))  new((*pLst[iCh])[iCnt[iCh]++]) AliHMPIDDigit(iPad,(Int_t)q,aTids);           //add the last one, in case of empty sdigits list q=-1
113 // add noise pad above threshold with no signal merged...if any
114   if(!fDoNoise) return;
115   aTids[0]=aTids[1]=aTids[2]=-1;
116   for (Int_t iCh=AliHMPIDDigit::kMinCh;iCh<=AliHMPIDDigit::kMaxCh;iCh++)
117     for (Int_t iPc=AliHMPIDDigit::kMinPc;iPc<=AliHMPIDDigit::kMaxPc;iPc++)
118       for(Int_t iPx=AliHMPIDDigit::kMinPx;iPx<=AliHMPIDDigit::kMaxPx;iPx++)
119         for(Int_t iPy=AliHMPIDDigit::kMinPy;iPy<=AliHMPIDDigit::kMaxPy;iPy++) {
120           Float_t q = arrNoise[iCh][iPc][iPx][iPy];
121           if(AliHMPIDDigit::IsOverTh(q)) new((*pLst[iCh])[iCnt[iCh]++]) AliHMPIDDigit(AliHMPIDDigit::Abs(iCh,iPc,iPx,iPy),(Int_t)q,aTids);
122         }
123         
124 }//Sdi2Dig()
125 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++