Added charge to the clusters tree
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSU.cxx
CommitLineData
451f5018 1/*
2*/
3
4/**************************************************************************
5 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * *
7 * Author: The ALICE Off-line Project. *
8 * Contributors are mentioned in the code where appropriate. *
9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
19/* $Id: AliITSU.cxx $ */
20
21
22///////////////////////////////////////////////////////////////////////////////
23// //
24// An overview of the basic philosophy of the ITS code development //
25// and analysis is show in the figure below. //
26//Begin_Html //
27/*
28<img src="picts/ITS/ITS_Analysis_schema.gif">
29</pre>
30<br clear=left>
31<font size=+2 color=red>
32<p>Roberto Barbera is in charge of the ITS Offline code (1999).
33<a href="mailto:roberto.barbera@ct.infn.it">Roberto Barbera</a>.
34</font>
35<pre>
36*/
37//End_Html
38//
39// AliITSU. Inner Traking System base class.
40// This class contains the base procedures for the Inner Tracking System
41//
42//Begin_Html
43/*
44<img src="picts/ITS/AliITS_Class_Diagram.gif">
45</pre>
46<br clear=left>
47<font size=+2 color=red>
48<p>This show the class diagram of the different elements that are part of
49the AliITS class.
50</font>
51<pre>
52*/
53//End_Html
54//
55// Version: 0
56// Written by Rene Brun, Federico Carminati, and Roberto Barbera
57//
58// Version: 1
59// Modified and documented by Bjorn S. Nilsen
60// July 11 1999
61//
62// Version: 2
63// Modified and documented by A. Bologna
64// October 18 1999
65//
66// AliITSU is the general base class for the ITS. Also see AliDetector for
67// futher information.
68//
69///////////////////////////////////////////////////////////////////////////////
70
71#include <stdlib.h>
72#include <TClonesArray.h>
73#include <TFile.h>
74#include <TParticle.h>
75#include <TString.h>
76#include <TTree.h>
77#include <TVirtualMC.h>
344d4ff3 78#include <TMath.h>
451f5018 79#include "AliDetector.h"
80#include "AliITSU.h"
81#include "AliITSLoader.h"
82#include "AliITSULoader.h"
83#include "AliITSUHit.h"
84#include "AliITSUSDigit.h"
85#include "AliITSUSimulation.h"
86#include "AliITSUSimulationPix.h"
87#include "AliITSsimulationFastPoints.h"
88#include "AliMC.h"
89#include "AliITSUDigitizer.h"
90#include "AliITSRecPoint.h"
91#include "AliRawReader.h"
92#include "AliRun.h"
93#include "AliLog.h"
94#include "AliITSdigit.h"
95#include "AliITSUModule.h"
96#include "AliITSUDigitPix.h"
97#include "AliITSsegmentation.h"
98#include "AliITSUSegmentationPix.h"
99#include "AliITSUSimuParam.h"
100#include "AliITSFOSignalsSPD.h"
29ad4146 101#include "AliITSUParamList.h"
c92b1537 102#include "AliCDBManager.h" // tmp! Later the simuparam should be loaded centrally
103#include "AliCDBEntry.h"
451f5018 104
344d4ff3 105using namespace TMath;
106
451f5018 107ClassImp(AliITSU)
108
109//______________________________________________________________________
110AliITSU::AliITSU() :
111AliDetector()
112 ,fEuclidOut(0)
113 ,fNLayers(0)
114 ,fIdSens(0)
115 ,fLayerName(0)
116 ,fTiming(kFALSE)
451f5018 117 ,fGeomTGeo(0)
02d6eccc 118 ,fSimuParam(0)
451f5018 119 ,fModA(0)
120 ,fpSDigits(0)
121 ,fSDigits(0)
122 ,fDetHits(0)
123 ,fModuleHits(0)
124 ,fDetDigits(0)
125 ,fSensMap(0)
c92b1537 126 ,fSimModelLr(0)
127 ,fSegModelLr(0)
128 ,fResponseLr(0)
451f5018 129 ,fCalibration(0)
130 ,fRunNumber(0)
131 ,fSimInitDone(kFALSE)
132{
133 // Default initializer for ITS
134}
135
136//______________________________________________________________________
137AliITSU::AliITSU(const Char_t *title, Int_t nlay) :
138 AliDetector("ITS",title)
139 ,fEuclidOut(0)
140 ,fNLayers(nlay)
141 ,fIdSens(0)
142 ,fLayerName(0)
143 ,fTiming(kFALSE)
451f5018 144 ,fGeomTGeo(0)
02d6eccc 145 ,fSimuParam(0)
451f5018 146 ,fModA(0)
147 ,fpSDigits(0)
148 ,fSDigits(0)
149 ,fDetHits(0)
150 ,fModuleHits(0)
151 ,fDetDigits(0)
152 ,fSensMap(0)
c92b1537 153 ,fSimModelLr(0)
154 ,fSegModelLr(0)
155 ,fResponseLr(0)
451f5018 156 ,fCalibration(0)
157 ,fRunNumber(0)
158 ,fSimInitDone(kFALSE)
159{
160 // The standard Constructor for the ITS class.
02d6eccc 161 AliMC* mc = gAlice->GetMCApp();
162 if( mc && mc->GetHitLists() ) {
163 fHits = new TClonesArray("AliITSUHit",100); // from AliDetector
164 mc->AddHitList(fHits);
165 }
451f5018 166}
167
168
169//______________________________________________________________________
170AliITSU::~AliITSU()
171{
172 // Default destructor for ITS.
173 //
174 delete fHits;
c92b1537 175 // delete fSimuParam; // provided by the CDBManager
451f5018 176 delete fSensMap;
c92b1537 177 if (fSimModelLr) {
178 for (int i=fNLayers;i--;) { // different layers may use the same simulation model
179 for (int j=i;j--;) if (fSimModelLr[j]==fSimModelLr[i]) fSimModelLr[j] = 0;
180 delete fSimModelLr[i];
181 }
182 delete[] fSimModelLr;
183 }
184 if (fSegModelLr) {
185 for (int i=fNLayers;i--;) { // different layers may use the same simulation model
186 for (int j=i;j--;) if (fSegModelLr[j]==fSegModelLr[i]) fSegModelLr[j] = 0;
187 delete fSegModelLr[i];
188 }
189 delete[] fSegModelLr;
190 }
191 //
9a2806bf 192 delete[] fResponseLr; // note: the response data is owned by the CDBManager, we don't delete them
c92b1537 193 //
451f5018 194 delete[] fLayerName; // Array of TStrings
195 delete[] fIdSens;
196 //
197 int nmod = fGeomTGeo ? fGeomTGeo->GetNModules() : 0;
198 if (fModuleHits) fModuleHits->Delete();
199 delete fModuleHits;
200 if(fModA){
201 for(Int_t j=0; j<nmod; j++){
202 fModA[j]->Delete();
203 delete fModA[j];
204 }
205 delete[] fModA;
206 }
207 if (fpSDigits) { fpSDigits->Delete(); delete fpSDigits; }
208 if (fSDigits) { fSDigits->Delete(); delete fSDigits; }
209 delete fGeomTGeo;
210 //
211}
212
213//______________________________________________________________________
214AliDigitizer* AliITSU::CreateDigitizer(AliDigitizationInput* manager) const
215{
216 // Creates the AliITSDigitizer in a standard way for use via AliModule.
217 // This function can not be included in the .h file because of problems
218 // with the order of inclusion (recursive).
219 // Inputs:
220 // AliDigitizationInput *manager The Manger class for Digitization
221 // Output:
222 // none.
223 // Return:
224 // A new AliITSRunDigitizer (cast as a AliDigitizer).
225 //
451f5018 226 return new AliITSUDigitizer(manager);
227}
228
229//______________________________________________________________________
230void AliITSU::Init()
231{
232 // Initializer ITS after it has been built
233 // This routine initializes the AliITS class. It is intended to be
234 // called from the Init function in AliITSv?. Besides displaying a banner
235 // indicating that it has been called it initializes the array fIdSens
236 // and sets the default segmentation, response, digit and raw cluster
237 // classes therefore it should be called after a call to CreateGeometry.
238 //
239 if (!fIdSens) fIdSens = new Int_t[fNLayers];
240 for(int i=0;i<fNLayers;i++) fIdSens[i] = gMC ? gMC->VolId(fLayerName[i]) : 0;
02d6eccc 241 fGeomTGeo = new AliITSUGeomTGeo(kTRUE);
242 InitSimulation();
451f5018 243 //
244}
245
246//______________________________________________________________________
247void AliITSU::MakeBranch(Option_t* option)
248{
249 // Creates Tree branches for the ITS.
250 // Inputs:
251 // Option_t *option String of Tree types S,D, and/or R.
252 // const char *file String of the file name where these branches
253 // are to be stored. If blank then these branches
254 // are written to the same tree as the Hits were
255 // read from.
256 // Outputs:
257 // none.
258 // Return:
259 // none.
260
261 Bool_t cH = (strstr(option,"H")!=0);
262 Bool_t cS = (strstr(option,"S")!=0);
263 Bool_t cD = (strstr(option,"D")!=0);
264
265 if(cH && (fHits == 0x0)) fHits = new TClonesArray("AliITSUHit", 1560);
266 AliDetector::MakeBranch(option);
267
268 if(cS) MakeBranchS(0);
269 if(cD) MakeBranchD(0);
270 //
271}
272
273//___________________________________________________________________
274void AliITSU::MakeBranchS(const char* fl)
275{
276 // Creates Tree Branch for the ITS summable digits.
277 // Inputs:
278 // cont char *fl File name where SDigits branch is to be written
279 // to. If blank it write the SDigits to the same
280 // file in which the Hits were found.
281 //
282 Int_t buffersize = 4000;
283 char branchname[31];
284 //
285 // only one branch for SDigits.
286 snprintf(branchname,30,"%s",GetName());
287 if(fLoader->TreeS()) MakeBranchInTree(fLoader->TreeS(),branchname,&fSDigits,buffersize,fl);
288 //
289}
290
291//______________________________________________________________________
292void AliITSU::MakeBranchD(const char* file)
293{
294 //Make branch for digits
295 MakeBranchInTreeD(fLoader->TreeD(),file);
296}
297
298//___________________________________________________________________
299void AliITSU:: MakeBranchInTreeD(TTree* treeD, const char* file)
300{
301 // Creates Tree branches for the ITS.
302 //
303 if (!treeD) {AliFatal("No tree provided");}
304 Int_t buffersize = 4000;
305 if (!fDetDigits) InitArrays();
306 //
307 for (Int_t i=0;i<kNDetTypes;i++) {
308 ResetDigits(i);
309 TClonesArray* darr = (TClonesArray*)fDetDigits->At(i);
310 AliDetector::MakeBranchInTree(treeD,Form("%sDigits%s",GetName(),fGeomTGeo->GetDetTypeName(i)),
311 &darr,buffersize,file);
312 }
313 //
314}
315
316//______________________________________________________________________
317void AliITSU::InitArrays()
318{
319 // initialize arrays
320 //
451f5018 321 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
322 //
323 fDetDigits = new TObjArray(kNDetTypes);
324 for (Int_t i=0;i<kNDetTypes;i++) fDetDigits->AddAt(new TClonesArray(GetDigitClassName(i),100),i);
325 //
326 fSDigits = new TClonesArray("AliITSUSDigit",100);
327 //
328 fDetHits = new TClonesArray("AliITSUHit",100);
329 //
330 fModuleHits = new TObjArray(fGeomTGeo->GetNModules());
331 for (int i=0;i<fGeomTGeo->GetNModules();i++) fModuleHits->AddLast( new AliITSUModule(i,fGeomTGeo) );
332 //
333}
334
335//______________________________________________________________________
336void AliITSU::SetTreeAddress()
337{
338 // Set branch address for the Trees.
339 TTree *treeS = fLoader->TreeS();
02d6eccc 340 if (treeS) {
341 TBranch* br = treeS->GetBranch(GetName());
342 if (br) br->SetAddress(&fSDigits);
343 }
451f5018 344 //
345 TTree *treeD = fLoader->TreeD();
346 if (treeD) {
347 if (!fDetDigits) InitArrays();
348 for (int i=0;i<kNDetTypes;i++) {
349 TString brname = Form("%sDigits%s",GetName(),GetDetTypeName(i));
350 TBranch* br = treeD->GetBranch(brname.Data());
02d6eccc 351 if (!br) continue;
451f5018 352 TClonesArray* darr = (TClonesArray*)fDetDigits->At(i);
353 br->SetAddress(&darr);
354 }
355 }
356 if (fLoader->TreeH() && (fHits == 0x0)) fHits = new TClonesArray("AliITSUHit", 1560);
357 AliDetector::SetTreeAddress();
358 //
359}
360
361//______________________________________________________________________
362void AliITSU::AddHit(Int_t track, Int_t *vol, Float_t *hits)
363{
364 // Add an ITS hit
365 // The function to add information to the AliITSUHit class. See the
366 // AliITSUHit class for a full description. This function allocates the
367 // necessary new space for the hit information and passes the variable
368 // track, and the pointers *vol and *hits to the AliITSUHit constructor
369 // function.
370 // Inputs:
371 // Int_t track Track number which produced this hit.
372 // Int_t *vol Array of Integer Hit information. See AliITSUHit.h
373 // Float_t *hits Array of Floating Hit information. see AliITSUHit.h
374 TClonesArray &lhits = *fHits;
375 new(lhits[fNhits++]) AliITSUHit(fIshunt,track,vol,hits);
376 //
377}
378
379//______________________________________________________________________
380void AliITSU::FillModules(Int_t bgrev, Option_t *option, const char *filename)
381{
382 // fill the modules with the sorted by module hits; add hits from
383 // background if option=Add.
384 //
385 static TTree *trH1=0; //Tree with background hits
386 static Bool_t first=kTRUE;
387 static TFile *file = 0;
388 const char *addBgr = strstr(option,"Add");
389 //
390 if (addBgr ) {
391 if(first) {
392 file = new TFile(filename);
393 first=kFALSE;
394 }
395 file->cd();
396 file->ls();
397 // Get Hits Tree header from file
398 if (trH1) {delete trH1; trH1=0;}
399 //
400 char treeName[21];
401 snprintf(treeName,20,"TreeH%d",bgrev);
402 trH1 = (TTree*)gDirectory->Get(treeName);
403 if (!trH1) Error("FillModules","cannot find Hits Tree for event:%d",bgrev);
404 // Set branch addresses
405 } // end if addBgr
406
407 FillModules(fLoader->TreeH(),0); // fill from this file's tree.
408 //
409 if (addBgr ) {
410 FillModules(trH1,10000000); // Default mask 10M.
411 TTree *fAli=fLoader->GetRunLoader()->TreeK();
412 TFile *fileAli=0;
413 if (fAli) {
414 fileAli = fAli->GetCurrentFile();
415 fileAli->cd();
416 }
417 } // end if add
418 //
419}
420
421//______________________________________________________________________
422void AliITSU::FillModules(TTree *treeH, Int_t /*mask*/)
423{
424 // fill the modules with the sorted by module hits;
425 // can be called many times to do a merging
426 // Inputs:
427 // TTree *treeH The tree containing the hits to be copied into
428 // the modules.
429 // Int_t mask The track number mask to indecate which file
430 // this hits came from.
431 //
432 if (treeH == 0x0) { AliError("Tree H is NULL"); return; }
433 //
434 Int_t lay,lad,det,index;
435 AliITSUHit *itsHit=0;
436 char branchname[21];
437 snprintf(branchname,20,"%s",GetName());
438 TBranch *branch = treeH->GetBranch(branchname);
439 if (!branch) {Error("FillModules","%s branch in TreeH not found",branchname); return;} // end if !branch
440 //
441 branch->SetAddress(&fHits);
442 Int_t nTracks =(Int_t) treeH->GetEntries();
443 Int_t iPrimTrack,h;
444 for (iPrimTrack=0; iPrimTrack<nTracks; iPrimTrack++) {
445 ResetHits();
446 Int_t nBytes = treeH->GetEvent(iPrimTrack);
447 if (nBytes <= 0) continue;
448 Int_t nHits = fHits->GetEntriesFast();
449 for (h=0; h<nHits; h++){
450 itsHit = (AliITSUHit *)fHits->UncheckedAt(h);
451 itsHit->GetDetectorID(lay,lad,det);
02d6eccc 452 index = fGeomTGeo->GetModuleIndex(lay,lad,det); // !!! AliITSHit counts indices from 1!
451f5018 453 itsHit = new( (*fDetHits)[fDetHits->GetEntriesFast()] ) AliITSUHit(*itsHit);
454 itsHit->SetUniqueID(h);
455 GetModule(index)->AddHit(itsHit);
456 // do we need to add a mask?
457 // itsHit->SetTrack(itsHit->GetTrack()+mask);
458 } // end loop over hits
459 } // end loop over tracks
460}
461
462//______________________________________________________________________
463void AliITSU::ClearModules()
464{
465 // clear accumulated hits
466 if (!fModuleHits || !fDetHits) AliFatal("Hits accumulation arrays are not defined");
467 for (int i=fGeomTGeo->GetNModules();i--;) GetModule(i)->Clear();
468 fDetHits->Clear();
469}
470
471//______________________________________________________________________
472void AliITSU::Hits2SDigits()
473{
474 // Standard Hits to summable Digits function.
451f5018 475 if (!IsSimInitDone()) InitSimulation();
476 fLoader->LoadHits("read");
477 fLoader->LoadSDigits("recreate");
478 AliRunLoader* rl = fLoader->GetRunLoader();
479 //
480 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
481 rl->GetEvent(iEvent);
482 if (!fLoader->TreeS()) fLoader->MakeTree("S");
483 MakeBranch("S");
484 SetTreeAddress();
485 Hits2SDigits(iEvent,0," "," ");
486 } // end for iEvent
487 //
488 fLoader->UnloadHits();
489 fLoader->UnloadSDigits();
490 //
491}
492
493//______________________________________________________________________
494void AliITSU::Hits2SDigits(Int_t evNumber,Int_t bgrev,Option_t *option,const char *filename)
495{
496 // Keep galice.root for signal and name differently the file for
497 // background when add! otherwise the track info for signal will be lost !
498 // Inputs:
499 // Int_t evnt Event to be processed.
500 // Int_t bgrev Background Hit tree number.
501 // Int_t nmodules Not used.
502 // Option_t *option String indicating if merging hits or not. To
503 // merge hits set equal to "Add". Otherwise no
504 // background hits are considered.
505 // Test_t *filename File name containing the background hits..
506 //
507 if (!IsSimInitDone()) InitSimulation();
508 FillModules(bgrev,option,filename);
509 //
510 Int_t nmodules = fGeomTGeo->GetNModules();
344d4ff3 511 int prevLr = -1;
512 float roPhase=0; // synchronysation type between layers/modules
513 Bool_t randomyzeModules = kFALSE; // do we need to randomize layers
514 //
451f5018 515 for(int module=0;module<nmodules;module++) {
c92b1537 516 int lr = fGeomTGeo->GetLayer(module);
517 AliITSUSimulation* sim = GetSimulationModel(lr);
518 sim->InitSimulationModule(GetModule(module),evNumber/*,gAlice->GetEvNumber()*/,GetSegmentation(lr),GetResponseParam(lr));
344d4ff3 519 //
520 if (prevLr!=lr) { // new layer started)
521 roPhase = fSimuParam->GetLrROCycleShift(lr);
35a853ed 522 if (Abs(roPhase)<1.) roPhase = roPhase*sim->GetReadOutCycleLength(); // modules synchronized within layer with this offset
344d4ff3 523 else randomyzeModules = kTRUE; // modules have random offset
524 }
525 if (randomyzeModules) sim->GenerateReadOutCycleOffset();
526 else sim->SetReadOutCycleOffset(roPhase);
527 //
c92b1537 528 sim->SDigitiseModule();
451f5018 529 fLoader->TreeS()->Fill(); // fills all branches - wasted disk space
530 ResetSDigits();
344d4ff3 531 prevLr = lr;
451f5018 532 }
533 //
534 ClearModules();
535 //
536 fLoader->TreeS()->GetEntries();
537 fLoader->TreeS()->AutoSave();
538 fLoader->WriteSDigits("OVERWRITE");
539 fLoader->TreeS()->Reset();
540}
541
542//______________________________________________________________________
02d6eccc 543void AliITSU::Hits2Digits()
544{
545 // Standard Hits to Digits function.
546 if (!IsSimInitDone()) InitSimulation();
547 fLoader->LoadHits("read");
548 fLoader->LoadDigits("recreate");
549 AliRunLoader* rl = fLoader->GetRunLoader();
550 //
551 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
552 rl->GetEvent(iEvent);
7f51dd15 553 if (!fLoader->TreeD()) fLoader->MakeTree("D");
02d6eccc 554 MakeBranch("D");
555 SetTreeAddress();
556 Hits2Digits(iEvent,0," "," ");
557 } // end for iEvent
558 //
559 fLoader->UnloadHits();
560 fLoader->UnloadSDigits();
561 //
562}
563
564//______________________________________________________________________
451f5018 565void AliITSU::Hits2Digits(Int_t evNumber,Int_t bgrev,Option_t *option,const char *filename)
566{
567 // Keep galice.root for signal and name differently the file for
568 // background when add! otherwise the track info for signal will be lost !
569 // Inputs:
570 // Int_t evnt Event to be processed.
571 // Int_t bgrev Background Hit tree number.
572 // Option_t *option String indicating if merging hits or not. To
573 // merge hits set equal to "Add". Otherwise no
574 // background hits are considered.
575 // Test_t *filename File name containing the background hits..
576 // Outputs:
577 //
578 if (!IsSimInitDone()) InitSimulation();
579 FillModules(bgrev,option,filename);
580 //
581 Int_t nmodules = fGeomTGeo->GetNModules();
344d4ff3 582 int prevLr = -1;
583 float roPhase=0; // synchronysation type between layers/modules
584 Bool_t randomyzeModules = kFALSE; // do we need to randomize layers
585 //
451f5018 586 for (Int_t module=0;module<nmodules;module++) {
c92b1537 587 int lr = fGeomTGeo->GetLayer(module);
588 AliITSUSimulation* sim = GetSimulationModel(lr);
344d4ff3 589 //
c92b1537 590 sim->InitSimulationModule(GetModule(module),evNumber/*gAlice->GetEvNumber()*/,GetSegmentation(lr),GetResponseParam(lr));
344d4ff3 591 if (prevLr!=lr) { // new layer started)
592 roPhase = fSimuParam->GetLrROCycleShift(lr);
593 if (Abs(roPhase)<1.) roPhase = roPhase*sim->GenerateReadOutCycleOffset(); // modules synchronized within layer with this offset
594 else randomyzeModules = kTRUE; // modules have random offset
595 }
596 if (randomyzeModules) sim->GenerateReadOutCycleOffset();
597 else sim->SetReadOutCycleOffset(roPhase);
c92b1537 598 sim->DigitiseModule();
451f5018 599 // fills all branches - wasted disk space
600 fLoader->TreeD()->Fill();
601 ResetDigits();
344d4ff3 602 prevLr = lr;
451f5018 603 } // end for module
604 //
605 ClearModules();
606 //
607 // WriteFOSignals(); // Add Fast-OR signals to event (only one object per event)
608 fLoader->TreeD()->GetEntries();
609 fLoader->TreeD()->AutoSave();
610 fLoader->TreeD()->Reset();
611 //
612}
613
614//_____________________________________________________________________
615void AliITSU::Hits2FastRecPoints(Int_t bgrev,Option_t *opt,const char *flnm)
616{
617 // keep galice.root for signal and name differently the file for
618 // background when add! otherwise the track info for signal will be lost !
619 // Inputs:
620 // Int_t evnt Event to be processed.
621 // Int_t bgrev Background Hit tree number.
622 // Option_t *opt Option passed to FillModules. See FillModules.
623 // Test_t *flnm File name containing the background hits..
624 // Outputs:
625 // none.
626 // Return:
627 // none.
628 if (!IsSimInitDone()) InitSimulation();
629 AliITSULoader *pITSloader = (AliITSULoader*)fLoader;
630 Int_t nmodules = fGeomTGeo->GetNModules();
631 FillModules(bgrev,opt,flnm);
632 //
633 TTree *lTR = pITSloader->TreeR();
634 if(!lTR) {
635 pITSloader->MakeTree("R");
636 lTR = pITSloader->TreeR();
637 }
638 //
639 TClonesArray* ptarray = new TClonesArray("AliITSRecPoint",1000);
640 TBranch* branch = (TBranch*)lTR->Branch("ITSRecPointsF",&ptarray);
641 branch->SetAddress(&ptarray);
642 for (int module=0;module<nmodules;module++){
643 int id = fGeomTGeo->GetModuleDetTypeID(module);
644 AliITSUSimulation* sim = GetSimulationModel(id);
645 if (!sim) AliFatal(Form("The sim.class for module %d of DetTypeID %d is missing",module,id));
646 sim->CreateFastRecPoints( GetModule(module) ,module,gRandom,ptarray);
647 lTR->Fill();
648 ptarray->Clear();
649 } // end for module
650 //
651 ClearModules();
652 fLoader->WriteRecPoints("OVERWRITE");
653 delete ptarray;
654}
655
656//_____________________________________________________________________
f9c7eb32 657Int_t AliITSU::Hits2Clusters(TTree */*hTree*/, TTree */*cTree*/)
451f5018 658{
659 /* RS: TODO
660 // This function creates ITS clusters
661 if (!IsSimInitDone()) InitSimulation();
662 Int_t mmax = 0;
663 FillModules(hTree,0);
664 //
665 TClonesArray *points = new TClonesArray("AliITSRecPoint",1000);
666 TBranch *branch=cTree->GetBranch("ITSRecPoints");
667 if (!branch) cTree->Branch("ITSRecPoints",&points);
668 else branch->SetAddress(&points);
669 //
670 AliITSsimulationFastPoints sim;
671 Int_t ncl=0;
672 for (Int_t m=0; m<mmax; m++) {
673 sim.CreateFastRecPoints(GetModule(m),m,gRandom,points);
674 ncl+=points->GetEntriesFast();
675 cTree->Fill();
676 points->Clear();
677 }
678 //
679 ClearModules();
680 //
681 AliDebug(1,Form("Number of found fast clusters : %d",ncl));
682 //cTree->Write();
683 delete points;
684 */
685 return 0;
686}
687
688//_____________________________________________________________________
689void AliITSU::CheckLabels(Int_t lab[3]) const //RSDONE
690{
691 // Tries to find mother's labels
692 //
693 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
694 //
695 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
696 for (Int_t i=0;i<3;i++){
697 Int_t label = lab[i];
698 if (label>=0 && label<ntracks) {
699 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
700 if (part->P() < 0.005) {
701 Int_t m=part->GetFirstMother();
702 if (m<0) continue;
703 if (part->GetStatusCode()>0) continue;
704 lab[i]=m;
705 }
706 }
707 }
708 //
709}
710
711//______________________________________________________________________
712void AliITSU::ResetDigits() //RSDONE?
713{
714 // Reset number of digits and the digits array for the ITS detector.
715 if (fDetDigits) for (int i=kNDetTypes;i--;) ResetDigits(i);
716 //
717}
718
719//______________________________________________________________________
720void AliITSU::ResetDigits(Int_t branch)
721{
722 // Reset number of digits and the digits array for this branch.
723 if (fDetDigits) ((TClonesArray*)fDetDigits->At(branch))->Clear();
724 //
725}
726
727//______________________________________________________________________
728void AliITSU::AddSumDigit(AliITSUSDigit &sdig)
729{
730 // Adds the module summable digits to the summable digits tree.
731 new( (*fSDigits)[fSDigits->GetEntriesFast()]) AliITSUSDigit(sdig);
732 //
733}
734
735//______________________________________________________________________
736void AliITSU::AddSimDigit(Int_t branch, AliITSdigit *d)
737{
738 // Add a simulated digit.
739 // Inputs:
740 // Int_t id Detector type number.
741 // AliITSdigit *d Digit to be added to the Digits Tree. See
742 // AliITSdigit.h
743 TClonesArray &ldigits = *((TClonesArray*)fDetDigits->At(branch));
744 int nd = ldigits.GetEntriesFast();
745 switch(branch){
02d6eccc 746 case AliITSUGeomTGeo::kDetTypePix:
451f5018 747 new(ldigits[nd]) AliITSUDigitPix(*((AliITSUDigitPix*)d));
748 break;
749 default:
750 AliFatal(Form("Unknown digits branch %d",branch));
751 }
752}
753
754//______________________________________________________________________
f9c7eb32 755void AliITSU::AddSimDigit(Int_t branch,Float_t /*phys*/,Int_t *digits,Int_t *tracks,
756 Int_t *hits,Float_t */*charges*/, Int_t /*sigexpanded*/)
451f5018 757{
758 // Add a simulated digit to the list.
759 // Inputs:
760 // Int_t id Detector type number.
761 // Float_t phys Physics indicator. See AliITSdigits.h
762 // Int_t *digits Integer array containing the digits info. See
763 // AliITSdigit.h
764 // Int_t *tracks Integer array [AliITSdigitS?D::GetNTracks()]
765 // containing the track numbers that contributed to
766 // this digit.
767 // Int_t *hits Integer array [AliITSdigitS?D::GetNTracks()]
768 // containing the hit numbers, from AliITSmodule, that
769 // contributed to this digit.
770 // Float_t *charge Floating point array of the signals contributed
771 // to this digit by each track.
772 TClonesArray &ldigits = *((TClonesArray*)fDetDigits->At(branch));
773 int nd = ldigits.GetEntriesFast();
774 switch(branch){
02d6eccc 775 case AliITSUGeomTGeo::kDetTypePix:
451f5018 776 new(ldigits[nd]) AliITSUDigitPix(digits,tracks,hits);
777 break;
778 default:
779 AliFatal(Form("Unknown digits branch %d",branch));
780 }
781 //
782}
783
784//______________________________________________________________________
785void AliITSU::Digits2Raw()
786{
787 AliError("Not ready");
788}
789
790//______________________________________________________________________
791AliLoader* AliITSU::MakeLoader(const char* topfoldername)
792{
793 //builds ITSgetter (AliLoader type)
794 //if detector wants to use castomized getter, it must overload this method
795
796 AliDebug(1,Form("Creating AliITSULoader. Top folder is %s.",topfoldername));
797 fLoader = new AliITSULoader(GetName(),topfoldername);
798 return fLoader;
799}
800
801//______________________________________________________________________
f9c7eb32 802Bool_t AliITSU::Raw2SDigits(AliRawReader* /*rawReader*/)
451f5018 803{
804 AliError("Not ready");
805 return kFALSE;
806}
807
808//______________________________________________________________________
809/*
810AliTriggerDetector* AliITSU::CreateTriggerDetector() const
811{
812 // create an AliITSTrigger object (and set trigger conditions as input)
813 return new AliITSTrigger(fDetTypeSim->GetTriggerConditions());
814}
815*/
816
817//______________________________________________________________________
818void AliITSU::WriteFOSignals()
819{
820 // This method write FO signals in Digits tree both in Hits2Digits
821 // or SDigits2Digits
822 AliError("Not ready");
823 // fDetTypeSim->ProcessNoiseForFastOr();
824}
825
826//_______________________________________________________________________
827void AliITSU::SDigits2Digits()
828{
829 // Standard Summable digits to Digits function.
830 //
831 if (!IsSimInitDone()) InitSimulation();
832 TTree* trees = fLoader->TreeS();
833 if( !(trees && fSDigits) ) AliFatal("Error: No trees or SDigits.");
834 TBranch* brchSDigits = trees->GetBranch(GetName());
835 //
836 int nmodules = fGeomTGeo->GetNModules();
344d4ff3 837 int prevLr = -1;
838 float roPhase=0; // synchronysation type between layers/modules
839 Bool_t randomyzeModules = kFALSE; // do we need to randomize layers
840 //
451f5018 841 for (int module=0;module<nmodules;module++) {
c92b1537 842 int lr = fGeomTGeo->GetLayer(module);
843 AliITSUSimulation* sim = GetSimulationModel(lr);
844 sim->InitSimulationModule(GetModule(module),gAlice->GetEvNumber(),GetSegmentation(lr),GetResponseParam(lr));
344d4ff3 845 //
846 if (prevLr!=lr) { // new layer started)
847 roPhase = fSimuParam->GetLrROCycleShift(lr);
848 if (Abs(roPhase)<1.) roPhase = roPhase*sim->GenerateReadOutCycleOffset(); // modules synchronized within layer with this offset
849 else randomyzeModules = kTRUE; // modules have random offset
850 }
851 if (randomyzeModules) sim->GenerateReadOutCycleOffset();
852 else sim->SetReadOutCycleOffset(roPhase);
853 //
451f5018 854 fSDigits->Clear();
855 brchSDigits->GetEvent(module);
856 sim->AddSDigitsToModule(fSDigits,0);
857 sim->FinishSDigitiseModule();
858 fLoader->TreeD()->Fill();
859 ResetDigits();
344d4ff3 860 prevLr = lr;
451f5018 861 }
862 // WriteFOSignals();
863 fLoader->TreeD()->GetEntries();
864 fLoader->TreeD()->AutoSave();
865 fLoader->TreeD()->Reset();
866}
867
868//_______________________________________________________________________
869void AliITSU::InitSimulation()
870{
871 // Initialize arrays, segmentations ets, needed for simulation
872 // Equivalent of old AliITSDetTypeSim construction
873 //
874 if (fSimInitDone) {AliInfo("Already done"); return;}
875 //
c92b1537 876 AliCDBEntry* cdbEnt = AliCDBManager::Instance()->Get("ITS/Calib/SimuParam"); // tmp: load it centrally
877 if (!cdbEnt) {AliFatal("Failed to find ITS/Calib/SimuParam on CDB"); exit(1);}
878 fSimuParam = (AliITSUSimuParam*)cdbEnt->GetObject();
879 //
451f5018 880 fSensMap = new AliITSUSensMap("AliITSUSDigit",0,0);
c92b1537 881 fSimModelLr = new AliITSUSimulation*[fNLayers];
882 fSegModelLr = new AliITSsegmentation*[fNLayers];
29ad4146 883 fResponseLr = new AliITSUParamList*[fNLayers];
c92b1537 884 //
885 TObjArray arrSeg;
886 AliITSUSegmentationPix::LoadSegmentations(&arrSeg, AliITSUGeomTGeo::GetITSsegmentationFileName());
451f5018 887 //
888 // add known simulation types used in the setup
889 for (int i=fNLayers;i--;) {
69e0f089 890 fSimModelLr[i] = 0;
891 fSegModelLr[i] = 0;
892 fResponseLr[i] = 0;
c92b1537 893 int dType = fGeomTGeo->GetLayerDetTypeID(i); // fine detector type: class + segmentation
894 int sType = dType/AliITSUGeomTGeo::kMaxSegmPerDetType; // detector simulation class
451f5018 895 //
c92b1537 896 // check if the simulation of this sType was already created for preceeding layers
451f5018 897 AliITSUSimulation* simUpg = 0;
69e0f089 898 for (int j=fNLayers-1;j>i;j--) {
c92b1537 899 simUpg = GetSimulationModel(j);
69e0f089 900 if (simUpg && int(simUpg->GetUniqueID())==sType) break;
c92b1537 901 else simUpg = 0;
902 }
903 //
904 if (!simUpg) { // need to create simulation for detector class sType
905 switch (sType)
906 {
907 case AliITSUGeomTGeo::kDetTypePix :
908 simUpg = new AliITSUSimulationPix(fSimuParam,fSensMap);
909 break;
910 default: AliFatal(Form("No %d detector type is defined",sType));
911 }
912 }
913 fSimModelLr[i] = simUpg;
914 //
915 // add segmentations used in the setup
916 if (!(fSegModelLr[i]=(AliITSsegmentation*)arrSeg[dType])) {AliFatal(Form("Segmentation for DetType#%d is not found",dType)); exit(1);}
917 //
918 // add response function for the detectors of this layer
29ad4146 919 if ( !(fResponseLr[i]=(AliITSUParamList*)fSimuParam->FindRespFunParams(dType)) ) {AliFatal(Form("Response for DetType#%d is not found in SimuParams",dType)); exit(1);}
451f5018 920 }
c92b1537 921 // delete non needed segmentations
922 for (int i=fNLayers;i--;) arrSeg.Remove(fSegModelLr[i]);
923 arrSeg.Delete();
451f5018 924 //
925 InitArrays();
926 //
927 fSimInitDone = kTRUE;
928 //
929}