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