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