]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RICH/AliRICHDigitizer.cxx
some minor changes to adpat for the situation when no digits or clusters avalbale
[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
17 #include <Riostream.h> 
18
19 #include <TTree.h> 
20 #include <TObjArray.h>
21 #include <TFile.h>
22 #include <TDirectory.h>
23 #include <TParticle.h>
24
25 #include <AliRunLoader.h>
26 #include <AliLoader.h>
27
28 #include "AliRICHDigitizer.h"
29 #include "AliRICH.h"
30 #include "AliRunDigitizer.h"
31
32 ClassImp(AliRICHDigitizer)
33
34 //__________________________________________________________________________________________________
35 Bool_t AliRICHDigitizer::Init()
36 {
37 //This methode is called from AliRunDigitizer after the corresponding file is open
38   if(GetDebug())Info("Init","Start.");
39   fRich=(AliRICH*)gAlice->GetDetector("RICH");
40   Rich()->P()->GenSigmaThMap();
41   return kTRUE;
42 }//Init()
43 //__________________________________________________________________________________________________
44 void AliRICHDigitizer::Exec(Option_t*)
45 {
46   if(GetDebug())Info("Exec","Start with %i input(s) for event %i",fManager->GetNinputs(),fManager->GetOutputEventNr());
47   
48   AliRunLoader *pInAL=0, *pOutAL;//in and out Run loaders
49   AliLoader    *pInRL=0, *pOutRL;//in and out RICH loaders
50  
51   pOutAL = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
52   pOutRL = pOutAL->GetLoader("RICHLoader");
53   pOutRL->MakeTree("D");   Rich()->MakeBranch("D"); //create TreeD with RICH branches in output stream
54   
55   TClonesArray tmpCA("AliRICHdigit");//tmp storage for sdigits sum up from all input files
56   Int_t total=0;
57   for(Int_t inFileN=0;inFileN<fManager->GetNinputs();inFileN++){//files loop
58     pInAL = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inFileN)); 
59     pInRL = pInAL->GetLoader("RICHLoader"); if(pInRL==0) continue;//no RICH in this input, check the next input
60     pInRL->LoadSDigits(); pInAL->GetEvent(fManager->GetInputEventNumber(fManager->GetOutputEventNr(),0)); pInRL->TreeS()->GetEntry(0);
61     Info("Exec","input %i has %i sdigits",inFileN,Rich()->SDigits()->GetEntries());
62     for(Int_t i=0;i<Rich()->SDigits()->GetEntries();i++) new(tmpCA[total++]) AliRICHdigit(*(AliRICHdigit*)Rich()->SDigits()->At(i)); 
63     pInRL->UnloadSDigits();   Rich()->ResetSDigits();
64   }//files loop
65   
66   tmpCA.Sort();                     //sort them according to Id() methode
67   
68   Int_t chFbMip=0,chamber=0,x=0,y=0,tid[3],id=0; Double_t q=0;
69   Int_t iNdigitsPerPad=0;//how many sdigits for a given pad
70   for(Int_t i=0;i<tmpCA.GetEntries();i++){//sdigits loop (sorted)
71     AliRICHdigit *pSdig=(AliRICHdigit*)tmpCA.At(i);//get new sdigit
72     if(pSdig->Id()==id){//still the same pad
73       iNdigitsPerPad++;         q+=pSdig->Q();       chFbMip+=pSdig->ChFbMi();//sum up charge and cfm
74       if(iNdigitsPerPad<=3)        tid[iNdigitsPerPad-1]=pSdig->Tid(0);
75       else                         if(GetDebug())Warning("Exec","More then 3 sdigits for the given pad");
76     }else{//new pad, add the pevious one
77         if(id!=kBad&&Rich()->P()->IsOverTh(chamber,x,y,q)) Rich()->AddDigit(chamber,x,y,(Int_t)q,chFbMip,tid); //add newly created dig
78         chFbMip=pSdig->ChFbMi(); chamber=pSdig->C(); id=pSdig->Id();  x=pSdig->X(); y=pSdig->Y(); q=pSdig->Q();  //init all values by current sdig
79         iNdigitsPerPad=1; tid[0]=pSdig->Tid(0); tid[1]=tid[2]=kBad;
80       }
81   }//sdigits loop (sorted)
82   if(tmpCA.GetEntries()&&Rich()->P()->IsOverTh(chamber,x,y,q)) Rich()->AddDigit(chamber,x,y,(Int_t)q,chFbMip,tid);//add the last dig
83   
84   pOutRL->TreeD()->Fill();              //fill the tree with the list of digits
85   pOutRL->WriteDigits("OVERWRITE");     //serialize them to file
86   
87   tmpCA.Clear();
88   pOutRL->UnloadDigits();   Rich()->ResetDigits();
89             
90   if(GetDebug())Info("Exec","Stop.");
91 }//Exec()
92 //__________________________________________________________________________________________________