Don't symmetrise x,y.
[u/mrichter/AliRoot.git] / ITS / AliITSBeamTestDigitizer.cxx
CommitLineData
38300302 1////////////////////////////////////////////////////
2// Class to manage the //
3// ITS beam test conversion from rawdata //
4// to digits. It executes the digitization for //
5// SPD, SDD and SSD. //
6// Origin: E. Crescio crescio@to.infn.it //
7// J. Conrad Jan.Conrad@cern.ch //
8////////////////////////////////////////////////////
9#include "AliHeader.h"
10#include "AliRun.h"
11#include "AliRunLoader.h"
12#include "AliITSEventHeader.h"
13#include "AliITSLoader.h"
5ba31760 14#include "AliITSvBeamTestITS04.h"
15#include "AliITSvSDD03.h"
38300302 16#include "AliITSBeamTestDigSDD.h"
17#include "AliITSBeamTestDigSPD.h"
18#include "AliITSBeamTestDigSSD.h"
19#include "AliITSBeamTestDigitizer.h"
20#include "AliRawReaderDate.h"
5ba31760 21#include "TGeoManager.h"
22#include "TGeoMaterial.h"
23#include "TGeoMedium.h"
24#include "TGeoVolume.h"
557c1d26 25#include <TVirtualMC.h>
26//#include <TGeant3.h>
38300302 27
5ba31760 28const TString AliITSBeamTestDigitizer::fgkDefaultDigitsFileName="ITS.Digits.root";
38300302 29
30ClassImp(AliITSBeamTestDigitizer)
31
32
33//_____________________________________________________________
34AliITSBeamTestDigitizer::AliITSBeamTestDigitizer():TTask()
35{
36 //
37 // Default constructor
38 //
39 fRunLoader = 0;
40 fLoader =0;
41 fEvIn=0;
42 fEvFin=0;
43 fFlagHeader=kTRUE;
44 fDATEEvType=7;
45 fRunNumber=-1;
46 SetFlagInit();
47 fBt=0;
5ba31760 48 fPeriod=kNov04;
38300302 49}
50
51//_____________________________________________________________
5ba31760 52 AliITSBeamTestDigitizer::AliITSBeamTestDigitizer(const Text_t* name, const Text_t* title, Char_t* opt):TTask(name,title)
38300302 53{
54 //
55 // Standard constructor
56 //
5ba31760 57 fRunLoader=0;
58 fLoader=0;
59 fBt=0;
38300302 60 fEvIn=0;
61 fEvFin=0;
62 fDATEEvType=7;
63 fFlagHeader=kTRUE;
64 fRunNumber=-1;
5ba31760 65
66 TString choice(opt);
67 Bool_t aug04 = choice.Contains("Aug04");
68 Bool_t nov04 = choice.Contains("Nov04");
69 if(aug04) fPeriod=kAug04;
70 if(nov04) fPeriod=kNov04;
71 Init();
38300302 72 }
73
74//_____________________________________________________________
5ba31760 75 AliITSBeamTestDigitizer::AliITSBeamTestDigitizer(const Text_t* name, const Text_t* title, Int_t run, Char_t* opt):TTask(name,title)
38300302 76
77{
78 //
79 // Constructor
80 //
5ba31760 81 fRunLoader=0;
82 fLoader=0;
83 fBt=0;
38300302 84 fEvIn=0;
85 fEvFin=0;
86 fDATEEvType=7;
87 fFlagHeader=kTRUE;
88 fRunNumber=run;
5ba31760 89 TString choice(opt);
90 Bool_t aug04 = choice.Contains("Aug04");
91 Bool_t nov04 = choice.Contains("Nov04");
92 if(aug04) fPeriod=kAug04;
93 if(nov04) fPeriod=kNov04;
94
95 Init();
38300302 96 }
97
98//___________________________________________________________
99void AliITSBeamTestDigitizer::Init(){
100
101 //
102 //Initialization of run loader and its loader
103 //creation of galice.root
104 //
5ba31760 105
38300302 106 fRunLoader = AliRunLoader::Open("galice.root",
107 AliConfig::GetDefaultEventFolderName(),"recreate");
108
109 gAlice->SetRunLoader(fRunLoader);
110 fRunLoader->SetEventFolderName();
5ba31760 111 if(GetBeamTestPeriod()==kNov04){
112 if(gGeoManager) delete gGeoManager;
113 gGeoManager = new TGeoManager("ITSGeometry","ITS Simulation Geometry Manager");
114 TGeoMaterial *vacmat = new TGeoMaterial("Vacuum",0,0,0);
115 TGeoMedium *vacmed = new TGeoMedium("Vacuum_med",1,vacmat);
116 TGeoVolume *aLICE = gGeoManager->MakeBox("ALICE",vacmed,100.,100.,200.);
117 gGeoManager->SetTopVolume(aLICE);
118 fBt = new AliITSvBeamTestITS04("ITS","ITS beam test");
119 fBt->CreateGeometry();
120 fBt->Init();
121
122 }
123 if(GetBeamTestPeriod()==kAug04){
124 fBt = new AliITSvSDD03("ITS",2004);
125 gSystem->Load("libgeant321");
557c1d26 126 // new TGeant3("C++ Interface to Geant3");
127 if(strcmp(gMC->GetName(),"TGeant3")) {
128 Fatal("Init","TGeant3 should be instantiated in advance");
129 return;
130 }
5ba31760 131 fBt->CreateMaterials();
132 fBt->CreateGeometry();
133 fBt->Init();
134 }
38300302 135 gAlice->AddModule(fBt);
5ba31760 136 fBt->SetDefaults();
38300302 137 fRunLoader->AddLoader(fBt);
138 fLoader = (AliITSLoader*)fRunLoader->GetLoader("ITSLoader");
139 fRunLoader->MakeTree("E");
5ba31760 140 fRunLoader->WriteHeader("OVERWRITE");
38300302 141 fRunLoader->WriteRunLoader("OVERWRITE");
5ba31760 142 fRunLoader->WriteAliRun("OVERWRITE");
143
38300302 144 fDigitsFileName=fgkDefaultDigitsFileName;
145 this->Add(new AliITSBeamTestDigSPD("DigSPD","SPD Digitization"));
146 this->Add(new AliITSBeamTestDigSDD("DigSDD","SDD Digitization"));
147 this->Add(new AliITSBeamTestDigSSD("DigSSD","SSD Digitization"));
148
149 SetFlagInit(kTRUE);
150}
151
152//_____________________________________________________________
153 AliITSBeamTestDigitizer::AliITSBeamTestDigitizer(const char* filename)
154{
155 //
156 // Constructor for reading (reads galice.root)
157 //
158
159 fRunLoader = AliRunLoader::Open(filename);
160 if (fRunLoader == 0x0)
161 {
162 Error("AliITSBeamTestDigitizer","Can not load the session",filename);
163 return;
164 }
165 fRunLoader->LoadgAlice();
166 gAlice = fRunLoader->GetAliRun();
167
168 if(!gAlice) {
169 Error("AliITSBeamTestDigitizer","gAlice not found on file. Aborting.");
170 return;
171 }
172
173 fLoader = (AliITSLoader*)fRunLoader->GetLoader("ITSLoader");
174
5ba31760 175 //fBt = (AliITSBeamTest*)gAlice->GetDetector("ITS");
38300302 176 fBt->SetDefaults();
177
178 fDigitsFileName=fgkDefaultDigitsFileName;
179
180 fEvIn=0;
181 fEvFin=0;
182
183}
184
185//______________________________________________________________________
186AliITSBeamTestDigitizer::AliITSBeamTestDigitizer(const AliITSBeamTestDigitizer &bt):TTask(bt){
187 // Copy constructor.
188 //not allowed
189 if(this==&bt) return;
190 Error("Copy constructor",
191 "You are not allowed to make a copy of the AliITSBeamTestDigitizer");
192 exit(1);
193
194}
195//______________________________________________________________________
5ba31760 196AliITSBeamTestDigitizer& AliITSBeamTestDigitizer::operator=(const AliITSBeamTestDigitizer &source){
38300302 197 // Assignment operator. This is a function which is not allowed to be
198 // done to the ITS beam test digitizer. It exits with an error.
199 // Inputs:
5ba31760 200 if(this==&source) return *this;
38300302 201 Error("operator=","You are not allowed to make a copy of the AliITSBeamTestDigitizer");
202 exit(1);
203 return *this; //fake return
204}
205
206
207//______________________________________________________________
208AliITSBeamTestDigitizer::~AliITSBeamTestDigitizer(){
209
210 //Destructor
211 if(fBt) delete fBt;
212 if(fLoader) delete fLoader;
5ba31760 213 if(fHeader) delete fHeader;
38300302 214}
215
216
217//_____________________________________________________________
218void AliITSBeamTestDigitizer::SetNumberOfEventsPerFile(Int_t nev)
219{
220 //Sets number of events per file
221
222 if(fRunLoader) fRunLoader->SetNumberOfEventsPerFile(nev);
223 else Warning("SetNumberOfEventsPerFile","fRunLoader is 0");
224}
225
226
227//____________________________________________________
228void AliITSBeamTestDigitizer::ExecDigitization(){
229
230 // Execution of digitisation for SPD,SDD and SSD
231
232 if(!GetFlagInit()){
233 Warning("ExecDigitization()","Run Init() please..");
234 return;
235 }
236 fLoader->SetDigitsFileName(fDigitsFileName);
237 fLoader->LoadDigits("recreate");
238
239 AliRawReaderDate rd(fRawdataFileName,fEvIn);
240 AliHeader* header = fRunLoader->GetHeader();
241
242 Int_t iev=fEvIn-1;
243
244
245 AliITSBeamTestDigSDD* digSDD = (AliITSBeamTestDigSDD*)fTasks->FindObject("DigSDD");
246 AliITSBeamTestDigSPD* digSPD = (AliITSBeamTestDigSPD*)fTasks->FindObject("DigSPD");
247 AliITSBeamTestDigSSD* digSSD = (AliITSBeamTestDigSSD*)fTasks->FindObject("DigSSD");
248
249
250 do{
251 iev++;
252 if(fEvFin!=0){
253 if(iev>fEvFin) break;
254 }
255 AliITSEventHeader* itsh = new AliITSEventHeader("ITSHeader");
256 fRunLoader->SetEventNumber(iev);
257
258 rd.RequireHeader(fFlagHeader);
259 rd.SelectEvents(fDATEEvType);
260
261 digSDD->SetRawReaderDate(&rd);
262 digSPD->SetRawReaderDate(&rd);
263 digSSD->SetRawReaderDate(&rd);
264
265 if(fLoader->TreeD() == 0x0) fLoader->MakeTree("D");
266
267 TTree* treeD = (TTree*)fLoader->TreeD();
268
269 // Make branches outside the dig-classes
270
271 TClonesArray* digitsSPD = new TClonesArray("AliITSdigitSPD",1000);
5ba31760 272 treeD->Branch("ITSDigitsSPD",&digitsSPD);
38300302 273
274 TClonesArray* digitsSDD = new TClonesArray("AliITSdigitSDD",1000);
5ba31760 275 treeD->Branch("ITSDigitsSDD",&digitsSDD);
38300302 276
277 TClonesArray* digitsSSD = new TClonesArray("AliITSdigitSSD",1000);
5ba31760 278 treeD->Branch("ITSDigitsSSD",&digitsSSD);
38300302 279
280
281 digSSD->SetTree(treeD);
282 digSDD->SetTree(treeD);
283 digSPD->SetTree(treeD);
5ba31760 284
38300302 285 digSSD->SetBeamTest(fBt);
286 digSDD->SetBeamTest(fBt);
287 digSPD->SetBeamTest(fBt);
5ba31760 288
38300302 289 digSSD->SetITSEventHeader(itsh);
290 digSDD->SetITSEventHeader(itsh);
291 digSPD->SetITSEventHeader(itsh);
292
293 digSDD->SetBtPeriod(GetBeamTestPeriod());
5ba31760 294 if(GetBeamTestPeriod()==1)digSDD->SetThreshold(16);
295 else digSDD->SetThreshold(0);
38300302 296 ExecuteTask(0);
297
298 header->SetEventNrInRun(iev);
299 header->SetEvent(iev);
300 header->SetRun(fRunNumber);
301 fRunLoader->GetHeader()->AddDetectorEventHeader(itsh);
302 fRunLoader->TreeE()->Fill();
303 header->Reset(fRunNumber,iev);
304
305 delete digitsSPD;
306 delete digitsSDD;
307 delete digitsSSD;
308
309 }while(rd.NextEvent());
310
5ba31760 311
38300302 312 fRunLoader->WriteHeader("OVERWRITE");
313 fRunLoader->WriteRunLoader("OVERWRITE");
5ba31760 314
38300302 315 fLoader->UnloadDigits();
316 fLoader->UnloadRawClusters();
317 fRunLoader->UnloadHeader();
5ba31760 318
38300302 319
320}
321
322
323
324//_______________________________________________
325void AliITSBeamTestDigitizer:: SetActive(const TString& subdet,Bool_t value){
326
327 //Sets active sub-tasks (detectors)
328
329 Bool_t sdd = subdet.Contains("SDD");
330 Bool_t spd = subdet.Contains("SPD");
331 Bool_t ssd = subdet.Contains("SSD");
332
333 if(sdd){
334 AliITSBeamTestDigSDD* digSDD = (AliITSBeamTestDigSDD*)fTasks->FindObject("DigSDD");
335 digSDD->SetActive(value);
336 }
337
338 if(spd){
339 AliITSBeamTestDigSPD* digSPD = (AliITSBeamTestDigSPD*)fTasks->FindObject("DigSPD");
340 digSPD->SetActive(value);
341
342 }
343
344 if(ssd){
345 AliITSBeamTestDigSSD* digSSD = (AliITSBeamTestDigSSD*)fTasks->FindObject("DigSSD");
346 digSSD->SetActive(value);
347
348 }
349
350
351
352}
353