Fix to flag checking for running on MC
[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>
78#include "AliDetector.h"
79#include "AliITSU.h"
80#include "AliITSLoader.h"
81#include "AliITSULoader.h"
82#include "AliITSUHit.h"
83#include "AliITSUSDigit.h"
84#include "AliITSUSimulation.h"
85#include "AliITSUSimulationPix.h"
86#include "AliITSsimulationFastPoints.h"
87#include "AliMC.h"
88#include "AliITSUDigitizer.h"
89#include "AliITSRecPoint.h"
90#include "AliRawReader.h"
91#include "AliRun.h"
92#include "AliLog.h"
93#include "AliITSdigit.h"
94#include "AliITSUModule.h"
95#include "AliITSUDigitPix.h"
96#include "AliITSsegmentation.h"
97#include "AliITSUSegmentationPix.h"
98#include "AliITSUSimuParam.h"
99#include "AliITSFOSignalsSPD.h"
100
101ClassImp(AliITSU)
102
103//______________________________________________________________________
104AliITSU::AliITSU() :
105AliDetector()
106 ,fEuclidOut(0)
107 ,fNLayers(0)
108 ,fIdSens(0)
109 ,fLayerName(0)
110 ,fTiming(kFALSE)
451f5018 111 ,fGeomTGeo(0)
02d6eccc 112 ,fSimuParam(0)
451f5018 113 ,fModA(0)
114 ,fpSDigits(0)
115 ,fSDigits(0)
116 ,fDetHits(0)
117 ,fModuleHits(0)
118 ,fDetDigits(0)
119 ,fSensMap(0)
120 ,fSimulation(0)
121 ,fSegmentation(0)
122 ,fCalibration(0)
123 ,fRunNumber(0)
124 ,fSimInitDone(kFALSE)
125{
126 // Default initializer for ITS
127}
128
129//______________________________________________________________________
130AliITSU::AliITSU(const Char_t *title, Int_t nlay) :
131 AliDetector("ITS",title)
132 ,fEuclidOut(0)
133 ,fNLayers(nlay)
134 ,fIdSens(0)
135 ,fLayerName(0)
136 ,fTiming(kFALSE)
451f5018 137 ,fGeomTGeo(0)
02d6eccc 138 ,fSimuParam(0)
451f5018 139 ,fModA(0)
140 ,fpSDigits(0)
141 ,fSDigits(0)
142 ,fDetHits(0)
143 ,fModuleHits(0)
144 ,fDetDigits(0)
145 ,fSensMap(0)
146 ,fSimulation(0)
147 ,fSegmentation(0)
148 ,fCalibration(0)
149 ,fRunNumber(0)
150 ,fSimInitDone(kFALSE)
151{
152 // The standard Constructor for the ITS class.
02d6eccc 153 AliMC* mc = gAlice->GetMCApp();
154 if( mc && mc->GetHitLists() ) {
155 fHits = new TClonesArray("AliITSUHit",100); // from AliDetector
156 mc->AddHitList(fHits);
157 }
451f5018 158}
159
160
161//______________________________________________________________________
162AliITSU::~AliITSU()
163{
164 // Default destructor for ITS.
165 //
166 delete fHits;
451f5018 167 delete fSimuParam;
168 delete fSensMap;
169 if (fSimulation) fSimulation->Delete();
170 delete fSimulation;
171 delete fSegmentation;
172 delete[] fLayerName; // Array of TStrings
173 delete[] fIdSens;
174 //
175 int nmod = fGeomTGeo ? fGeomTGeo->GetNModules() : 0;
176 if (fModuleHits) fModuleHits->Delete();
177 delete fModuleHits;
178 if(fModA){
179 for(Int_t j=0; j<nmod; j++){
180 fModA[j]->Delete();
181 delete fModA[j];
182 }
183 delete[] fModA;
184 }
185 if (fpSDigits) { fpSDigits->Delete(); delete fpSDigits; }
186 if (fSDigits) { fSDigits->Delete(); delete fSDigits; }
187 delete fGeomTGeo;
188 //
189}
190
191//______________________________________________________________________
192AliDigitizer* AliITSU::CreateDigitizer(AliDigitizationInput* manager) const
193{
194 // Creates the AliITSDigitizer in a standard way for use via AliModule.
195 // This function can not be included in the .h file because of problems
196 // with the order of inclusion (recursive).
197 // Inputs:
198 // AliDigitizationInput *manager The Manger class for Digitization
199 // Output:
200 // none.
201 // Return:
202 // A new AliITSRunDigitizer (cast as a AliDigitizer).
203 //
451f5018 204 return new AliITSUDigitizer(manager);
205}
206
207//______________________________________________________________________
208void AliITSU::Init()
209{
210 // Initializer ITS after it has been built
211 // This routine initializes the AliITS class. It is intended to be
212 // called from the Init function in AliITSv?. Besides displaying a banner
213 // indicating that it has been called it initializes the array fIdSens
214 // and sets the default segmentation, response, digit and raw cluster
215 // classes therefore it should be called after a call to CreateGeometry.
216 //
217 if (!fIdSens) fIdSens = new Int_t[fNLayers];
218 for(int i=0;i<fNLayers;i++) fIdSens[i] = gMC ? gMC->VolId(fLayerName[i]) : 0;
02d6eccc 219 fGeomTGeo = new AliITSUGeomTGeo(kTRUE);
220 InitSimulation();
451f5018 221 //
222}
223
224//______________________________________________________________________
225void AliITSU::MakeBranch(Option_t* option)
226{
227 // Creates Tree branches for the ITS.
228 // Inputs:
229 // Option_t *option String of Tree types S,D, and/or R.
230 // const char *file String of the file name where these branches
231 // are to be stored. If blank then these branches
232 // are written to the same tree as the Hits were
233 // read from.
234 // Outputs:
235 // none.
236 // Return:
237 // none.
238
239 Bool_t cH = (strstr(option,"H")!=0);
240 Bool_t cS = (strstr(option,"S")!=0);
241 Bool_t cD = (strstr(option,"D")!=0);
242
243 if(cH && (fHits == 0x0)) fHits = new TClonesArray("AliITSUHit", 1560);
244 AliDetector::MakeBranch(option);
245
246 if(cS) MakeBranchS(0);
247 if(cD) MakeBranchD(0);
248 //
249}
250
251//___________________________________________________________________
252void AliITSU::MakeBranchS(const char* fl)
253{
254 // Creates Tree Branch for the ITS summable digits.
255 // Inputs:
256 // cont char *fl File name where SDigits branch is to be written
257 // to. If blank it write the SDigits to the same
258 // file in which the Hits were found.
259 //
260 Int_t buffersize = 4000;
261 char branchname[31];
262 //
263 // only one branch for SDigits.
264 snprintf(branchname,30,"%s",GetName());
265 if(fLoader->TreeS()) MakeBranchInTree(fLoader->TreeS(),branchname,&fSDigits,buffersize,fl);
266 //
267}
268
269//______________________________________________________________________
270void AliITSU::MakeBranchD(const char* file)
271{
272 //Make branch for digits
273 MakeBranchInTreeD(fLoader->TreeD(),file);
274}
275
276//___________________________________________________________________
277void AliITSU:: MakeBranchInTreeD(TTree* treeD, const char* file)
278{
279 // Creates Tree branches for the ITS.
280 //
281 if (!treeD) {AliFatal("No tree provided");}
282 Int_t buffersize = 4000;
283 if (!fDetDigits) InitArrays();
284 //
285 for (Int_t i=0;i<kNDetTypes;i++) {
286 ResetDigits(i);
287 TClonesArray* darr = (TClonesArray*)fDetDigits->At(i);
288 AliDetector::MakeBranchInTree(treeD,Form("%sDigits%s",GetName(),fGeomTGeo->GetDetTypeName(i)),
289 &darr,buffersize,file);
290 }
291 //
292}
293
294//______________________________________________________________________
295void AliITSU::InitArrays()
296{
297 // initialize arrays
298 //
451f5018 299 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
300 //
301 fDetDigits = new TObjArray(kNDetTypes);
302 for (Int_t i=0;i<kNDetTypes;i++) fDetDigits->AddAt(new TClonesArray(GetDigitClassName(i),100),i);
303 //
304 fSDigits = new TClonesArray("AliITSUSDigit",100);
305 //
306 fDetHits = new TClonesArray("AliITSUHit",100);
307 //
308 fModuleHits = new TObjArray(fGeomTGeo->GetNModules());
309 for (int i=0;i<fGeomTGeo->GetNModules();i++) fModuleHits->AddLast( new AliITSUModule(i,fGeomTGeo) );
310 //
311}
312
313//______________________________________________________________________
314void AliITSU::SetTreeAddress()
315{
316 // Set branch address for the Trees.
317 TTree *treeS = fLoader->TreeS();
02d6eccc 318 if (treeS) {
319 TBranch* br = treeS->GetBranch(GetName());
320 if (br) br->SetAddress(&fSDigits);
321 }
451f5018 322 //
323 TTree *treeD = fLoader->TreeD();
324 if (treeD) {
325 if (!fDetDigits) InitArrays();
326 for (int i=0;i<kNDetTypes;i++) {
327 TString brname = Form("%sDigits%s",GetName(),GetDetTypeName(i));
328 TBranch* br = treeD->GetBranch(brname.Data());
02d6eccc 329 if (!br) continue;
451f5018 330 TClonesArray* darr = (TClonesArray*)fDetDigits->At(i);
331 br->SetAddress(&darr);
332 }
333 }
334 if (fLoader->TreeH() && (fHits == 0x0)) fHits = new TClonesArray("AliITSUHit", 1560);
335 AliDetector::SetTreeAddress();
336 //
337}
338
339//______________________________________________________________________
340void AliITSU::AddHit(Int_t track, Int_t *vol, Float_t *hits)
341{
342 // Add an ITS hit
343 // The function to add information to the AliITSUHit class. See the
344 // AliITSUHit class for a full description. This function allocates the
345 // necessary new space for the hit information and passes the variable
346 // track, and the pointers *vol and *hits to the AliITSUHit constructor
347 // function.
348 // Inputs:
349 // Int_t track Track number which produced this hit.
350 // Int_t *vol Array of Integer Hit information. See AliITSUHit.h
351 // Float_t *hits Array of Floating Hit information. see AliITSUHit.h
352 TClonesArray &lhits = *fHits;
353 new(lhits[fNhits++]) AliITSUHit(fIshunt,track,vol,hits);
354 //
355}
356
357//______________________________________________________________________
358void AliITSU::FillModules(Int_t bgrev, Option_t *option, const char *filename)
359{
360 // fill the modules with the sorted by module hits; add hits from
361 // background if option=Add.
362 //
363 static TTree *trH1=0; //Tree with background hits
364 static Bool_t first=kTRUE;
365 static TFile *file = 0;
366 const char *addBgr = strstr(option,"Add");
367 //
368 if (addBgr ) {
369 if(first) {
370 file = new TFile(filename);
371 first=kFALSE;
372 }
373 file->cd();
374 file->ls();
375 // Get Hits Tree header from file
376 if (trH1) {delete trH1; trH1=0;}
377 //
378 char treeName[21];
379 snprintf(treeName,20,"TreeH%d",bgrev);
380 trH1 = (TTree*)gDirectory->Get(treeName);
381 if (!trH1) Error("FillModules","cannot find Hits Tree for event:%d",bgrev);
382 // Set branch addresses
383 } // end if addBgr
384
385 FillModules(fLoader->TreeH(),0); // fill from this file's tree.
386 //
387 if (addBgr ) {
388 FillModules(trH1,10000000); // Default mask 10M.
389 TTree *fAli=fLoader->GetRunLoader()->TreeK();
390 TFile *fileAli=0;
391 if (fAli) {
392 fileAli = fAli->GetCurrentFile();
393 fileAli->cd();
394 }
395 } // end if add
396 //
397}
398
399//______________________________________________________________________
400void AliITSU::FillModules(TTree *treeH, Int_t /*mask*/)
401{
402 // fill the modules with the sorted by module hits;
403 // can be called many times to do a merging
404 // Inputs:
405 // TTree *treeH The tree containing the hits to be copied into
406 // the modules.
407 // Int_t mask The track number mask to indecate which file
408 // this hits came from.
409 //
410 if (treeH == 0x0) { AliError("Tree H is NULL"); return; }
411 //
412 Int_t lay,lad,det,index;
413 AliITSUHit *itsHit=0;
414 char branchname[21];
415 snprintf(branchname,20,"%s",GetName());
416 TBranch *branch = treeH->GetBranch(branchname);
417 if (!branch) {Error("FillModules","%s branch in TreeH not found",branchname); return;} // end if !branch
418 //
419 branch->SetAddress(&fHits);
420 Int_t nTracks =(Int_t) treeH->GetEntries();
421 Int_t iPrimTrack,h;
422 for (iPrimTrack=0; iPrimTrack<nTracks; iPrimTrack++) {
423 ResetHits();
424 Int_t nBytes = treeH->GetEvent(iPrimTrack);
425 if (nBytes <= 0) continue;
426 Int_t nHits = fHits->GetEntriesFast();
427 for (h=0; h<nHits; h++){
428 itsHit = (AliITSUHit *)fHits->UncheckedAt(h);
429 itsHit->GetDetectorID(lay,lad,det);
02d6eccc 430 index = fGeomTGeo->GetModuleIndex(lay,lad,det); // !!! AliITSHit counts indices from 1!
451f5018 431 itsHit = new( (*fDetHits)[fDetHits->GetEntriesFast()] ) AliITSUHit(*itsHit);
432 itsHit->SetUniqueID(h);
433 GetModule(index)->AddHit(itsHit);
434 // do we need to add a mask?
435 // itsHit->SetTrack(itsHit->GetTrack()+mask);
436 } // end loop over hits
437 } // end loop over tracks
438}
439
440//______________________________________________________________________
441void AliITSU::ClearModules()
442{
443 // clear accumulated hits
444 if (!fModuleHits || !fDetHits) AliFatal("Hits accumulation arrays are not defined");
445 for (int i=fGeomTGeo->GetNModules();i--;) GetModule(i)->Clear();
446 fDetHits->Clear();
447}
448
449//______________________________________________________________________
450void AliITSU::Hits2SDigits()
451{
452 // Standard Hits to summable Digits function.
451f5018 453 if (!IsSimInitDone()) InitSimulation();
454 fLoader->LoadHits("read");
455 fLoader->LoadSDigits("recreate");
456 AliRunLoader* rl = fLoader->GetRunLoader();
457 //
458 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
459 rl->GetEvent(iEvent);
460 if (!fLoader->TreeS()) fLoader->MakeTree("S");
461 MakeBranch("S");
462 SetTreeAddress();
463 Hits2SDigits(iEvent,0," "," ");
464 } // end for iEvent
465 //
466 fLoader->UnloadHits();
467 fLoader->UnloadSDigits();
468 //
469}
470
471//______________________________________________________________________
472void AliITSU::Hits2SDigits(Int_t evNumber,Int_t bgrev,Option_t *option,const char *filename)
473{
474 // Keep galice.root for signal and name differently the file for
475 // background when add! otherwise the track info for signal will be lost !
476 // Inputs:
477 // Int_t evnt Event to be processed.
478 // Int_t bgrev Background Hit tree number.
479 // Int_t nmodules Not used.
480 // Option_t *option String indicating if merging hits or not. To
481 // merge hits set equal to "Add". Otherwise no
482 // background hits are considered.
483 // Test_t *filename File name containing the background hits..
484 //
485 if (!IsSimInitDone()) InitSimulation();
486 FillModules(bgrev,option,filename);
487 //
488 Int_t nmodules = fGeomTGeo->GetNModules();
489 for(int module=0;module<nmodules;module++) {
490 int id = fGeomTGeo->GetModuleDetTypeID(module);
491 AliITSUSimulation* sim = GetSimulationModel(id);
492 if (!sim) AliFatal(Form("The sim.class for module %d of DetTypeID %d is missing",module,id));
493 sim->SDigitiseModule( GetModule(module), module, evNumber, GetSegmentation(id));
494 fLoader->TreeS()->Fill(); // fills all branches - wasted disk space
495 ResetSDigits();
496 }
497 //
498 ClearModules();
499 //
500 fLoader->TreeS()->GetEntries();
501 fLoader->TreeS()->AutoSave();
502 fLoader->WriteSDigits("OVERWRITE");
503 fLoader->TreeS()->Reset();
504}
505
506//______________________________________________________________________
02d6eccc 507void AliITSU::Hits2Digits()
508{
509 // Standard Hits to Digits function.
510 if (!IsSimInitDone()) InitSimulation();
511 fLoader->LoadHits("read");
512 fLoader->LoadDigits("recreate");
513 AliRunLoader* rl = fLoader->GetRunLoader();
514 //
515 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
516 rl->GetEvent(iEvent);
517 if (!fLoader->TreeS()) fLoader->MakeTree("S");
518 MakeBranch("D");
519 SetTreeAddress();
520 Hits2Digits(iEvent,0," "," ");
521 } // end for iEvent
522 //
523 fLoader->UnloadHits();
524 fLoader->UnloadSDigits();
525 //
526}
527
528//______________________________________________________________________
451f5018 529void AliITSU::Hits2Digits(Int_t evNumber,Int_t bgrev,Option_t *option,const char *filename)
530{
531 // Keep galice.root for signal and name differently the file for
532 // background when add! otherwise the track info for signal will be lost !
533 // Inputs:
534 // Int_t evnt Event to be processed.
535 // Int_t bgrev Background Hit tree number.
536 // Option_t *option String indicating if merging hits or not. To
537 // merge hits set equal to "Add". Otherwise no
538 // background hits are considered.
539 // Test_t *filename File name containing the background hits..
540 // Outputs:
541 //
542 if (!IsSimInitDone()) InitSimulation();
543 FillModules(bgrev,option,filename);
544 //
545 Int_t nmodules = fGeomTGeo->GetNModules();
546 for (Int_t module=0;module<nmodules;module++) {
547 int id = fGeomTGeo->GetModuleDetTypeID(module);
548 AliITSUSimulation* sim = GetSimulationModel(id);
549 if (!sim) AliFatal(Form("The sim.class for module %d of DetTypeID %d is missing",module,id));
550 sim->DigitiseModule( GetModule(module) ,module, evNumber, GetSegmentation(id));
551 // fills all branches - wasted disk space
552 fLoader->TreeD()->Fill();
553 ResetDigits();
554 } // end for module
555 //
556 ClearModules();
557 //
558 // WriteFOSignals(); // Add Fast-OR signals to event (only one object per event)
559 fLoader->TreeD()->GetEntries();
560 fLoader->TreeD()->AutoSave();
561 fLoader->TreeD()->Reset();
562 //
563}
564
565//_____________________________________________________________________
566void AliITSU::Hits2FastRecPoints(Int_t bgrev,Option_t *opt,const char *flnm)
567{
568 // keep galice.root for signal and name differently the file for
569 // background when add! otherwise the track info for signal will be lost !
570 // Inputs:
571 // Int_t evnt Event to be processed.
572 // Int_t bgrev Background Hit tree number.
573 // Option_t *opt Option passed to FillModules. See FillModules.
574 // Test_t *flnm File name containing the background hits..
575 // Outputs:
576 // none.
577 // Return:
578 // none.
579 if (!IsSimInitDone()) InitSimulation();
580 AliITSULoader *pITSloader = (AliITSULoader*)fLoader;
581 Int_t nmodules = fGeomTGeo->GetNModules();
582 FillModules(bgrev,opt,flnm);
583 //
584 TTree *lTR = pITSloader->TreeR();
585 if(!lTR) {
586 pITSloader->MakeTree("R");
587 lTR = pITSloader->TreeR();
588 }
589 //
590 TClonesArray* ptarray = new TClonesArray("AliITSRecPoint",1000);
591 TBranch* branch = (TBranch*)lTR->Branch("ITSRecPointsF",&ptarray);
592 branch->SetAddress(&ptarray);
593 for (int module=0;module<nmodules;module++){
594 int id = fGeomTGeo->GetModuleDetTypeID(module);
595 AliITSUSimulation* sim = GetSimulationModel(id);
596 if (!sim) AliFatal(Form("The sim.class for module %d of DetTypeID %d is missing",module,id));
597 sim->CreateFastRecPoints( GetModule(module) ,module,gRandom,ptarray);
598 lTR->Fill();
599 ptarray->Clear();
600 } // end for module
601 //
602 ClearModules();
603 fLoader->WriteRecPoints("OVERWRITE");
604 delete ptarray;
605}
606
607//_____________________________________________________________________
f9c7eb32 608Int_t AliITSU::Hits2Clusters(TTree */*hTree*/, TTree */*cTree*/)
451f5018 609{
610 /* RS: TODO
611 // This function creates ITS clusters
612 if (!IsSimInitDone()) InitSimulation();
613 Int_t mmax = 0;
614 FillModules(hTree,0);
615 //
616 TClonesArray *points = new TClonesArray("AliITSRecPoint",1000);
617 TBranch *branch=cTree->GetBranch("ITSRecPoints");
618 if (!branch) cTree->Branch("ITSRecPoints",&points);
619 else branch->SetAddress(&points);
620 //
621 AliITSsimulationFastPoints sim;
622 Int_t ncl=0;
623 for (Int_t m=0; m<mmax; m++) {
624 sim.CreateFastRecPoints(GetModule(m),m,gRandom,points);
625 ncl+=points->GetEntriesFast();
626 cTree->Fill();
627 points->Clear();
628 }
629 //
630 ClearModules();
631 //
632 AliDebug(1,Form("Number of found fast clusters : %d",ncl));
633 //cTree->Write();
634 delete points;
635 */
636 return 0;
637}
638
639//_____________________________________________________________________
640void AliITSU::CheckLabels(Int_t lab[3]) const //RSDONE
641{
642 // Tries to find mother's labels
643 //
644 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
645 //
646 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
647 for (Int_t i=0;i<3;i++){
648 Int_t label = lab[i];
649 if (label>=0 && label<ntracks) {
650 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
651 if (part->P() < 0.005) {
652 Int_t m=part->GetFirstMother();
653 if (m<0) continue;
654 if (part->GetStatusCode()>0) continue;
655 lab[i]=m;
656 }
657 }
658 }
659 //
660}
661
662//______________________________________________________________________
663void AliITSU::ResetDigits() //RSDONE?
664{
665 // Reset number of digits and the digits array for the ITS detector.
666 if (fDetDigits) for (int i=kNDetTypes;i--;) ResetDigits(i);
667 //
668}
669
670//______________________________________________________________________
671void AliITSU::ResetDigits(Int_t branch)
672{
673 // Reset number of digits and the digits array for this branch.
674 if (fDetDigits) ((TClonesArray*)fDetDigits->At(branch))->Clear();
675 //
676}
677
678//______________________________________________________________________
679void AliITSU::AddSumDigit(AliITSUSDigit &sdig)
680{
681 // Adds the module summable digits to the summable digits tree.
682 new( (*fSDigits)[fSDigits->GetEntriesFast()]) AliITSUSDigit(sdig);
683 //
684}
685
686//______________________________________________________________________
687void AliITSU::AddSimDigit(Int_t branch, AliITSdigit *d)
688{
689 // Add a simulated digit.
690 // Inputs:
691 // Int_t id Detector type number.
692 // AliITSdigit *d Digit to be added to the Digits Tree. See
693 // AliITSdigit.h
694 TClonesArray &ldigits = *((TClonesArray*)fDetDigits->At(branch));
695 int nd = ldigits.GetEntriesFast();
696 switch(branch){
02d6eccc 697 case AliITSUGeomTGeo::kDetTypePix:
451f5018 698 new(ldigits[nd]) AliITSUDigitPix(*((AliITSUDigitPix*)d));
699 break;
700 default:
701 AliFatal(Form("Unknown digits branch %d",branch));
702 }
703}
704
705//______________________________________________________________________
f9c7eb32 706void AliITSU::AddSimDigit(Int_t branch,Float_t /*phys*/,Int_t *digits,Int_t *tracks,
707 Int_t *hits,Float_t */*charges*/, Int_t /*sigexpanded*/)
451f5018 708{
709 // Add a simulated digit to the list.
710 // Inputs:
711 // Int_t id Detector type number.
712 // Float_t phys Physics indicator. See AliITSdigits.h
713 // Int_t *digits Integer array containing the digits info. See
714 // AliITSdigit.h
715 // Int_t *tracks Integer array [AliITSdigitS?D::GetNTracks()]
716 // containing the track numbers that contributed to
717 // this digit.
718 // Int_t *hits Integer array [AliITSdigitS?D::GetNTracks()]
719 // containing the hit numbers, from AliITSmodule, that
720 // contributed to this digit.
721 // Float_t *charge Floating point array of the signals contributed
722 // to this digit by each track.
723 TClonesArray &ldigits = *((TClonesArray*)fDetDigits->At(branch));
724 int nd = ldigits.GetEntriesFast();
725 switch(branch){
02d6eccc 726 case AliITSUGeomTGeo::kDetTypePix:
451f5018 727 new(ldigits[nd]) AliITSUDigitPix(digits,tracks,hits);
728 break;
729 default:
730 AliFatal(Form("Unknown digits branch %d",branch));
731 }
732 //
733}
734
735//______________________________________________________________________
736void AliITSU::Digits2Raw()
737{
738 AliError("Not ready");
739}
740
741//______________________________________________________________________
742AliLoader* AliITSU::MakeLoader(const char* topfoldername)
743{
744 //builds ITSgetter (AliLoader type)
745 //if detector wants to use castomized getter, it must overload this method
746
747 AliDebug(1,Form("Creating AliITSULoader. Top folder is %s.",topfoldername));
748 fLoader = new AliITSULoader(GetName(),topfoldername);
749 return fLoader;
750}
751
752//______________________________________________________________________
f9c7eb32 753Bool_t AliITSU::Raw2SDigits(AliRawReader* /*rawReader*/)
451f5018 754{
755 AliError("Not ready");
756 return kFALSE;
757}
758
759//______________________________________________________________________
760/*
761AliTriggerDetector* AliITSU::CreateTriggerDetector() const
762{
763 // create an AliITSTrigger object (and set trigger conditions as input)
764 return new AliITSTrigger(fDetTypeSim->GetTriggerConditions());
765}
766*/
767
768//______________________________________________________________________
769void AliITSU::WriteFOSignals()
770{
771 // This method write FO signals in Digits tree both in Hits2Digits
772 // or SDigits2Digits
773 AliError("Not ready");
774 // fDetTypeSim->ProcessNoiseForFastOr();
775}
776
777//_______________________________________________________________________
778void AliITSU::SDigits2Digits()
779{
780 // Standard Summable digits to Digits function.
781 //
782 if (!IsSimInitDone()) InitSimulation();
783 TTree* trees = fLoader->TreeS();
784 if( !(trees && fSDigits) ) AliFatal("Error: No trees or SDigits.");
785 TBranch* brchSDigits = trees->GetBranch(GetName());
786 //
787 int nmodules = fGeomTGeo->GetNModules();
788 for (int module=0;module<nmodules;module++) {
789 int id = fGeomTGeo->GetModuleDetTypeID(module);
790 AliITSUSimulation *sim = GetSimulationModel(id);
791 if(!sim){
792 AliFatal(Form("The sim.class for module %d of DetTypeID %d is missing",module,id));
793 exit(1);
794 }
795 sim->InitSimulationModule(module,gAlice->GetEvNumber(),GetSegmentation(id));
796 fSDigits->Clear();
797 brchSDigits->GetEvent(module);
798 sim->AddSDigitsToModule(fSDigits,0);
799 sim->FinishSDigitiseModule();
800 fLoader->TreeD()->Fill();
801 ResetDigits();
802 }
803 // WriteFOSignals();
804 fLoader->TreeD()->GetEntries();
805 fLoader->TreeD()->AutoSave();
806 fLoader->TreeD()->Reset();
807}
808
809//_______________________________________________________________________
810void AliITSU::InitSimulation()
811{
812 // Initialize arrays, segmentations ets, needed for simulation
813 // Equivalent of old AliITSDetTypeSim construction
814 //
815 if (fSimInitDone) {AliInfo("Already done"); return;}
816 //
451f5018 817 fSimuParam = new AliITSUSimuParam();
818 fSensMap = new AliITSUSensMap("AliITSUSDigit",0,0);
819 fSimulation = new TObjArray(kNDetTypes);
820 fSegmentation = new TObjArray();
821 AliITSUSegmentationPix::LoadSegmentations(fSegmentation, AliITSUGeomTGeo::GetITSsegmentationFileName());
822 fSegmentation->SetOwner(kTRUE);
823 //
824 // add known simulation types used in the setup
825 for (int i=fNLayers;i--;) {
826 int sType = fGeomTGeo->GetLayerDetTypeID(i)/AliITSUGeomTGeo::kMaxSegmPerDetType;
827 if (fSimulation->At(sType)) continue;
828 //
829 AliITSUSimulation* simUpg = 0;
830 switch (sType) {
02d6eccc 831 case AliITSUGeomTGeo::kDetTypePix :
451f5018 832 simUpg = new AliITSUSimulationPix(fSimuParam,fSensMap);
833 break;
834 default: AliFatal(Form("No %d detector type is defined",sType));
835 };
836 fSimulation->AddAtAndExpand(simUpg,sType);
837 }
838 //
839 InitArrays();
840 //
841 fSimInitDone = kTRUE;
842 //
843}