]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDDigitizer.cxx
eliminate warnings
[u/mrichter/AliRoot.git] / FMD / AliFMDDigitizer.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 <TTree.h> 
18 #include <TVector.h>
19 #include <TObjArray.h>
20 #include <TFile.h>
21 #include <TDirectory.h>
22 #include <TRandom.h>
23
24
25 #include "AliFMDDigitizer.h"
26 #include "AliFMD.h"
27 #include "AliFMDhit.h"
28 #include "AliFMDdigit.h"
29 #include "AliRunDigitizer.h"
30
31 #include "AliRun.h"
32 #include "AliPDG.h"
33 #include "AliLoader.h"
34 #include "AliRunLoader.h"
35
36 #include <stdlib.h>
37 #include <Riostream.h>
38 #include <Riostream.h>
39
40 ClassImp(AliFMDDigitizer)
41
42 //___________________________________________
43   AliFMDDigitizer::AliFMDDigitizer()  :AliDigitizer()
44 {
45 // Default ctor - don't use it
46   ;
47 }
48
49 //___________________________________________
50 AliFMDDigitizer::AliFMDDigitizer(AliRunDigitizer* manager) 
51     :AliDigitizer(manager) 
52 {
53      cout<<"AliFMDDigitizer::AliFMDDigitizer"<<endl;
54 // ctor which should be used
55 //  fDebug =0;
56  // if (GetDebug()>2)
57   //  cerr<<"AliFMDDigitizer::AliFMDDigitizer"
58    //     <<"(AliRunDigitizer* manager) was processed"<<endl;
59 }
60
61 //------------------------------------------------------------------------
62 AliFMDDigitizer::~AliFMDDigitizer()
63 {
64 // Destructor
65 }
66
67  //------------------------------------------------------------------------
68 Bool_t AliFMDDigitizer::Init()
69 {
70 // Initialization
71  cout<<"AliFMDDigitizer::Init"<<endl;
72  return kTRUE;
73 }
74  
75
76 //---------------------------------------------------------------------
77
78 void AliFMDDigitizer::Exec(Option_t * option)
79 {
80
81   /*
82    Conver hits to digits:
83    - number of detector;
84    - number of ring;
85    - number of sector;
86    - ADC signal in this channel
87   */
88   cout<<"AliFMDDigitizer::Exec Nachali Exec>> "<<endl;
89
90   AliRunLoader *inRL, *outRL;//in and out Run Loaders
91   AliLoader *ingime, *outgime;// in and out ITSLoaders
92
93   outRL = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
94   outgime = outRL->GetLoader("FMDLoader");
95   cout<<"AliFMDDigitizer::Exec >> "<<outgime<<endl;
96
97 #ifdef DEBUG
98   cout<<"AliFMDDigitizer::>SDigits2Digits start...\n";
99 #endif
100
101
102   Int_t volume, sector, ring, charge;
103   Float_t e;
104   Float_t de[10][50][520];
105   Int_t hit;
106   Int_t digit[5];
107   Int_t ivol, iSector, iRing;
108   for (Int_t i=0; i<10; i++)
109     for(Int_t j=0; j<50; j++)
110       for(Int_t ij=0; ij<520; ij++)
111      de[i][j][ij]=0;
112   Int_t NumberOfRings[5]=
113   {512,256,512,256,512};
114   Int_t NumberOfSectors[5]=
115   {20,40,20,40,20}; 
116   
117   AliFMDhit *fmdHit=0;
118   TTree *TH=0;
119   TBranch *brHits=0;
120   TBranch *brD=0;
121
122   inRL = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
123   if (inRL == 0x0)
124     {
125       Error("Exec","Can not find Run Loader for input stream 0");
126       return;
127     }
128   Info("Exec","inRL->GetAliRun() %#x",inRL->GetAliRun());
129
130   inRL->LoadgAlice();
131
132   AliFMD * fFMD = (AliFMD *) inRL->GetAliRun()->GetDetector("FMD");
133   Info("Exec","inRL->GetAliRun(): %#x, FMD: %#x, InRL %#x.",inRL->GetAliRun(),fFMD,inRL);
134   if (fFMD == 0x0)
135    {
136      Error("Exec","Can not get FMD from gAlice");
137      return;
138    }
139 // Loop over files to digitize
140
141   Int_t nFiles=GetManager()->GetNinputs();
142   for (Int_t inputFile=0; inputFile<nFiles;inputFile++) 
143    {
144     cout<<" event "<<fManager->GetOutputEventNr()<<endl;
145     if (fFMD)
146      {
147
148       inRL = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
149       ingime = inRL->GetLoader("FMDLoader");
150       ingime->LoadHits("READ");//probably it is necessary to load them before
151       
152       
153       TH = ingime->TreeH();
154       if (TH == 0x0)
155        {
156          ingime->LoadHits("read");
157          TH = ingime->TreeH();
158        }
159       brHits = TH->GetBranch("FMD");
160       if (brHits) {
161   //      brHits->SetAddress(&fHits);
162           fFMD->SetHitsAddressBranch(brHits);
163       }else{
164         Fatal("Exec","EXEC Branch FMD hit not found");
165       }
166       TClonesArray *FMDhits = fFMD->Hits ();
167       
168       Int_t ntracks    = (Int_t) TH->GetEntries();
169       cout<<"Number of tracks TreeH"<<ntracks<<endl;
170       for (Int_t track = 0; track < ntracks; track++)
171        {
172          brHits->GetEntry(track);
173          Int_t nhits = FMDhits->GetEntries ();
174          // if(nhits>0) cout<<"nhits "<<nhits<<endl;
175          for (hit = 0; hit < nhits; hit++)
176            {
177              fmdHit = (AliFMDhit *) FMDhits->UncheckedAt(hit);
178
179              volume = fmdHit->Volume ();
180              sector = fmdHit->NumberOfSector ();
181              ring = fmdHit->NumberOfRing ();
182              e = fmdHit->Edep ();
183              de[volume][sector][ring] += e;
184              //   if (fManager->GetOutputEventNr()>1)
185                     //      cout<<" "<<volume<<" "<<sector<<" "<<ring<<endl;
186            }          //hit loop
187        }               //track loop
188     }               
189 //if FMD
190
191  
192   // Put noise and make ADC signal
193    Float_t I = 1.664 * 0.04 * 2.33 / 22400;     // = 6.923e-6;
194    for ( ivol=1; ivol<=5; ivol++){
195      for ( iSector=1; iSector<=NumberOfSectors[ivol-1]; iSector++){
196        for ( iRing=1; iRing<=NumberOfRings[ivol-1]; iRing++){
197          digit[0]=ivol;
198          digit[1]=iSector;
199          digit[2]=iRing;
200          charge = Int_t (de[ivol][iSector][iRing] / I);
201          Int_t pedestal=Int_t(gRandom->Gaus(500,250));
202   //       digit[3]=PutNoise(charge);
203          digit[3]=charge + pedestal;
204          if(digit[3]<= 500) digit[3]=500; 
205     //dynamic range from MIP(0.155MeV) to 30MIP(4.65MeV)
206     //1024 ADC channels 
207          Float_t channelWidth=(22400*50)/1024;
208          digit[4]=Int_t(digit[3]/channelWidth);
209          if (digit[4]>1024) digit[4]=1024; 
210          fFMD->AddDigit(digit);
211        } //ivol
212      } //iSector
213    } //iRing
214
215    TTree* treeD = outgime->TreeD();
216    cout<<" treeD "<<treeD;
217    if (treeD == 0x0) {
218      outgime->MakeTree("D");
219      treeD = outgime->TreeD();
220      cout<<" After MakeTree "<<treeD<<endl;
221    }
222    cout<<" Before reset "<<treeD<<endl;
223    //   treeD->Clear();
224    treeD->Reset();
225    fFMD->MakeBranchInTreeD(treeD);
226    brD = treeD->GetBranch("FMD");
227    cout<<" Make branch "<<brD<<endl;
228
229    treeD->Fill();  //this operator does not work for events >1
230    treeD->Print();
231    outgime->WriteDigits("OVERWRITE");
232   
233    gAlice->ResetDigits();
234    }
235 }
236  
237
238
239
240