Coding conventions.
[u/mrichter/AliRoot.git] / ITS / AliITS.cxx
CommitLineData
4c039060 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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
88cb7938 16/* $Id$ */
2ab0c725 17
4c039060 18
fe4da5cc 19///////////////////////////////////////////////////////////////////////////////
04366a57 20// //
21// An overview of the basic philosophy of the ITS code development //
22// and analysis is show in the figure below. //
23//Begin_Html //
24/*
a92b2b7d 25<img src="picts/ITS/ITS_Analysis_schema.gif">
fe4da5cc 26</pre>
27<br clear=left>
28<font size=+2 color=red>
58005f18 29<p>Roberto Barbera is in charge of the ITS Offline code (1999).
fe4da5cc 30<a href="mailto:roberto.barbera@ct.infn.it">Roberto Barbera</a>.
31</font>
32<pre>
33*/
34//End_Html
58005f18 35//
36// AliITS. Inner Traking System base class.
37// This class contains the base procedures for the Inner Tracking System
38//
39//Begin_Html
40/*
a92b2b7d 41<img src="picts/ITS/AliITS_Class_Diagram.gif">
58005f18 42</pre>
43<br clear=left>
44<font size=+2 color=red>
45<p>This show the class diagram of the different elements that are part of
46the AliITS class.
47</font>
48<pre>
49*/
50//End_Html
51//
52// Version: 0
53// Written by Rene Brun, Federico Carminati, and Roberto Barbera
54//
55// Version: 1
56// Modified and documented by Bjorn S. Nilsen
57// July 11 1999
58//
3bd79107 59// Version: 2
60// Modified and documented by A. Bologna
61// October 18 1999
62//
58005f18 63// AliITS is the general base class for the ITS. Also see AliDetector for
64// futher information.
65//
fe4da5cc 66///////////////////////////////////////////////////////////////////////////////
88cb7938 67
143d1056 68#include <stdlib.h>
caf37aec 69#include <TClonesArray.h>
9c74c52b 70#include <TFile.h>
7d62fb64 71#include <TParticle.h>
d5da1ecf 72#include <TString.h>
88cb7938 73#include <TTree.h>
88cb7938 74#include <TVirtualMC.h>
7d62fb64 75#include "AliDetector.h"
3bd79107 76#include "AliITS.h"
7d62fb64 77#include "AliITSDetTypeSim.h"
f77f13c8 78#include "AliITSDDLRawData.h"
88cb7938 79#include "AliITSLoader.h"
88cb7938 80#include "AliITShit.h"
81#include "AliITSmodule.h"
7d62fb64 82#include "AliITSpListItem.h"
83#include "AliITSsimulation.h"
84#include "AliITSsimulationFastPoints.h"
5d12ce38 85#include "AliMC.h"
679379e8 86#include "AliITSDigitizer.h"
7d62fb64 87#include "AliITSRecPoint.h"
0b5bf101 88#include "AliITSsegmentationSPD.h"
89#include "AliITSsegmentationSDD.h"
dee45d79 90#include "AliITSsimulationSDD.h"
91#include "AliITSCalibrationSDD.h"
8b3448d3 92#include "AliITSCalibrationSSD.h"
0b5bf101 93#include "AliITSsegmentationSSD.h"
94#include "AliITSRawStreamSPD.h"
95#include "AliITSRawStreamSSD.h"
96#include "AliITSRawStreamSDD.h"
0b5bf101 97#include "AliRawReader.h"
f77f13c8 98#include "AliRun.h"
7d62fb64 99#include "AliLog.h"
ef7ff1f9 100#include "AliITSInitGeometry.h"
ad7f2bfa 101#include "AliITSFOSignalsSPD.h"
828e06c7 102
3bd79107 103ClassImp(AliITS)
3bd79107 104
2aea926d 105//______________________________________________________________________
ed9289c8 106AliITS::AliITS() : AliDetector(),
107fDetTypeSim(0),
108fEuclidOut(0),
109fOpt("All"),
110fIdN(0),
111fIdSens(0),
112fIdName(0),
012f0f4c 113fITSmodules(0),
c8af5b8f 114fTiming(kFALSE),
afbc83e9 115fSimuParam(0),
116fModA(0),
117fpSDigits(0)
ed9289c8 118{
7d62fb64 119 // Default initializer for ITS
120 // The default constructor of the AliITS class. In addition to
121 // creating the AliITS class it zeros the variables fIshunt (a member
122 // of AliDetector class), fEuclidOut, and fIdN, and zeros the pointers
123 // fIdSens, and fIdName. The AliDetector default constructor
124 // is also called.
125
aa044888 126// SetDetectors(); // default to fOpt="All". This variable not written out.
e939a978 127//PH SetMarkerColor(kRed);
fe4da5cc 128}
2aea926d 129//______________________________________________________________________
c8af5b8f 130AliITS::AliITS(const Char_t *title):
131 AliDetector("ITS",title),
132 fDetTypeSim(0),
133 fEuclidOut(0),
134 fOpt("All"),
135 fIdN(0),
136 fIdSens(0),
137 fIdName(0),
138 fITSmodules(0),
139 fTiming(kFALSE),
afbc83e9 140 fSimuParam(0),
141 fModA(0),
142 fpSDigits(0)
012f0f4c 143{
144 // The standard Constructor for the ITS class.
145 // It also zeros the variables
146 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
147 // the pointers fIdSens and fIdName. To help in displaying hits via the
148 // ROOT macro display.C AliITS also sets the marker color to red. The
149 // variables passes with this constructor, const char *name and *title,
150 // are used by the constructor of AliDetector class. See AliDetector
151 // class for a description of these parameters and its constructor
152 // functions.
153 // Inputs:
154 // Char_t *title Simulation title for the ITS
155 // Outputs:
156 // none.
157 // Return:
158 // none.
159
160 fHits = new TClonesArray("AliITShit",1560); // from AliDetector
161 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
162 //fNhits=0; //done in AliDetector(name,title)
163 SetDetectors(); // default to fOpt="All". This variable not written out.
164 fDetTypeSim = new AliITSDetTypeSim();
165 //PH SetMarkerColor(kRed);
166 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
167 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
168}
169//______________________________________________________________________
c8af5b8f 170AliITS::AliITS(const char *name, const char *title):
171 AliDetector(name,title),
172 fDetTypeSim(0),
173 fEuclidOut(0),
174 fOpt("All"),
175 fIdN(0),
176 fIdSens(0),
177 fIdName(0),
178 fITSmodules(0),
179 fTiming(kFALSE),
afbc83e9 180 fSimuParam(0),
181 fModA(0),
182 fpSDigits(0)
ed9289c8 183{
7d62fb64 184 // The standard Constructor for the ITS class.
185 // It also zeros the variables
186 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
187 // the pointers fIdSens and fIdName. To help in displaying hits via the
188 // ROOT macro display.C AliITS also sets the marker color to red. The
189 // variables passes with this constructor, const char *name and *title,
190 // are used by the constructor of AliDetector class. See AliDetector
191 // class for a description of these parameters and its constructor
192 // functions.
193
7d62fb64 194 fHits = new TClonesArray("AliITShit",1560);
195 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
ed9289c8 196 //fNhits=0; //done in AliDetector(name,title)
7d62fb64 197
7d62fb64 198 SetDetectors(); // default to fOpt="All". This variable not written out.
ed9289c8 199
7d62fb64 200 fDetTypeSim = new AliITSDetTypeSim();
e939a978 201 //PH SetMarkerColor(kRed);
023ae34b 202 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
203 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
fe4da5cc 204
3bd79107 205}
2aea926d 206//______________________________________________________________________
58005f18 207AliITS::~AliITS(){
4a5bebc2 208 // Default destructor for ITS.
2aea926d 209 // The default destructor of the AliITS class. In addition to deleting
7d62fb64 210 // the AliITS class it deletes the memory pointed to by
211 // fIdSens, fIdName, fDetTypeSim and it's contents.
4a5bebc2 212 // Inputs:
213 // none.
214 // Outputs:
215 // none.
216 // Return:
217 // none.
023ae34b 218
88cb7938 219 if (fHits) {
220 fHits->Delete();
221 delete fHits;
222 fHits=0;
223 }
88cb7938 224 if(fITSmodules) {
225 this->ClearModules();
226 delete fITSmodules;
279a35d7 227 fITSmodules = 0;
88cb7938 228 }// end if fITSmodules!=0
229
7d62fb64 230 delete[] fIdName; // Array of TStrings
231 delete[] fIdSens;
773af0c4 232 Int_t size = AliITSgeomTGeo::GetNModules();
7d62fb64 233 if (fDetTypeSim){
234 delete fDetTypeSim;
235 fDetTypeSim = 0;
c8af5b8f 236 }
237 if(fSimuParam){
238 delete fSimuParam;
239 fSimuParam=0;
240 }
afbc83e9 241 if(fModA){
242 if(size>0){
243 for(Int_t j=0; j<size; j++){
244 fModA[j]->Delete();
245 delete fModA[j];
246 }
247 }
248 delete []fModA;
249 }
250 if(fpSDigits){
251 fpSDigits->Delete();
252 delete fpSDigits;
253 }
3bd79107 254}
3bd79107 255
2aea926d 256//______________________________________________________________________
679379e8 257AliDigitizer* AliITS::CreateDigitizer(AliRunDigitizer* manager)const{
258 // Creates the AliITSDigitizer in a standard way for use via AliModule.
259 // This function can not be included in the .h file because of problems
260 // with the order of inclusion (recursive).
261 // Inputs:
262 // AliRunDigitizer *manager The Manger class for Digitization
263 // Output:
264 // none.
265 // Return:
266 // A new AliITSRunDigitizer (cast as a AliDigitizer).
267
268 return new AliITSDigitizer(manager);
269}
270//______________________________________________________________________
2aea926d 271void AliITS::Init(){
4a5bebc2 272 // Initializer ITS after it has been built
2aea926d 273 // This routine initializes the AliITS class. It is intended to be
274 // called from the Init function in AliITSv?. Besides displaying a banner
275 // indicating that it has been called it initializes the array fIdSens
276 // and sets the default segmentation, response, digit and raw cluster
277 // classes therefore it should be called after a call to CreateGeometry.
4a5bebc2 278 // Inputs:
279 // none.
280 // Outputs:
281 // none.
282 // Return:
283 // none.
3bd79107 284 Int_t i;
2aea926d 285 // Array of TStrings
0e73d04c 286 if(gMC) for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
7d62fb64 287
3bd79107 288}
2aea926d 289//______________________________________________________________________
290void AliITS::SetDefaults(){
4a5bebc2 291 // sets the default segmentation, response, digit and raw cluster classes.
292 // Inputs:
293 // none.
294 // Outputs:
295 // none.
296 // Return:
297 // none.
023ae34b 298 AliInfoClass("AliITS::Setting Defaults");
7d62fb64 299 if(!fDetTypeSim) {
300 Error("SetDefaults()","fDetTypeSim is 0!");
301 return;
302 }
303
304 fDetTypeSim->SetDefaults();
c8af5b8f 305 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 306
3bd79107 307}
2aea926d 308//______________________________________________________________________
309void AliITS::SetDefaultSimulation(){
4a5bebc2 310 // sets the default simulation.
311 // Inputs:
312 // none.
313 // Outputs:
314 // none.
315 // Return:
316 // none.
7d62fb64 317 if(!fDetTypeSim) {
318 Error("SetDefaultSimulation()","fDetTypeSim is 0!");
319 return;
320 }
321
322 fDetTypeSim->SetDefaultSimulation();
c8af5b8f 323 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
04366a57 324
04366a57 325}
326
327
2aea926d 328//______________________________________________________________________
88cb7938 329void AliITS::MakeBranch(Option_t* option){
2aea926d 330 // Creates Tree branches for the ITS.
4a5bebc2 331 // Inputs:
332 // Option_t *option String of Tree types S,D, and/or R.
333 // const char *file String of the file name where these branches
334 // are to be stored. If blank then these branches
335 // are written to the same tree as the Hits were
336 // read from.
337 // Outputs:
338 // none.
339 // Return:
340 // none.
7d62fb64 341 if(!fDetTypeSim) {
342 Error("MakeBranch","fDetTypeSim is 0!");
343 return;
344 }
04366a57 345
7d62fb64 346 Bool_t cH = (strstr(option,"H")!=0);
347 Bool_t cS = (strstr(option,"S")!=0);
348 Bool_t cD = (strstr(option,"D")!=0);
349
350 if(cH && (fHits == 0x0)) fHits = new TClonesArray("AliITShit", 1560);
351 AliDetector::MakeBranch(option);
352
353 if(cS) MakeBranchS(0);
354 if(cD) MakeBranchD(0);
355
356
357}
358//___________________________________________________________________
359void AliITS::MakeBranchS(const char* fl){
360
361 // Creates Tree Branch for the ITS summable digits.
362 // Inputs:
363 // cont char *fl File name where SDigits branch is to be written
364 // to. If blank it write the SDigits to the same
365 // file in which the Hits were found.
366
367
368 if(!fDetTypeSim){
369 Error("MakeBranchS","fDetTypeSim is 0!");
370 }
371 Int_t buffersize = 4000;
0f812aa0 372 char branchname[31];
7d62fb64 373
374 // only one branch for SDigits.
0f812aa0 375 snprintf(branchname,30,"%s",GetName());
7d62fb64 376
377 if(fLoader->TreeS()){
7d62fb64 378 TClonesArray* sdig = (TClonesArray*)fDetTypeSim->GetSDigits();
379 MakeBranchInTree(fLoader->TreeS(),branchname,&sdig,buffersize,fl);
380 }
381}
382//______________________________________________________________________
383void AliITS::MakeBranchD(const char* file){
384
385 //Make branch for digits
386 if(!fDetTypeSim) {
387 Warning("MakeBranchD","fDetTypeSim is 0!");
388 return;
389 }
023ae34b 390 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 391 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 392 MakeBranchInTreeD(fLoader->TreeD(),file);
393}
394
395//___________________________________________________________________
396void AliITS:: MakeBranchInTreeD(TTree* treeD, const char* file){
397 // Creates Tree branches for the ITS.
398
399 if(!fDetTypeSim){
400 Error("MakeBranchS","fDetTypeSim is 0!");
401 }
023ae34b 402 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 403 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 404
405 const Char_t *det[3] = {"SPD","SDD","SSD"};
a6e0ebfe 406 const Char_t* digclass;
7d62fb64 407 Int_t buffersize = 4000;
0f812aa0 408 Char_t branchname[31];
7d62fb64 409
410 if(!fDetTypeSim->GetDigits()){
411 fDetTypeSim->SetDigits(new TObjArray(fgkNTYPES));
412 }
413 for(Int_t i=0;i<fgkNTYPES;i++){
414 digclass = fDetTypeSim->GetDigitClassName(i);
415 TString classn = digclass;
416 if(!((fDetTypeSim->GetDigits())->At(i))){
417 (fDetTypeSim->GetDigits())->AddAt(new TClonesArray(classn.Data(),1000),i);
418 }
419 else ResetDigits(i);
0f812aa0 420 if(fgkNTYPES==3) snprintf(branchname,30,"%sDigits%s",GetName(),det[i]);
7d62fb64 421 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
422 TObjArray* dig = DigitsAddress(i);
423 if(GetDigits() && treeD) AliDetector::MakeBranchInTree(treeD,branchname, &dig,buffersize,file);
424 }
2aea926d 425
fe4da5cc 426}
2aea926d 427//______________________________________________________________________
428void AliITS::SetTreeAddress(){
429 // Set branch address for the Trees.
4a5bebc2 430 // Inputs:
431 // none.
432 // Outputs:
433 // none.
434 // Return:
435 // none.
023ae34b 436
7d62fb64 437 if(!fDetTypeSim) {
438 Error("SetTreeAddress","fDetTypeSim is 0!");
439 return;
440 }
441
023ae34b 442 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 443 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 444
445 TTree *treeS = fLoader->TreeS();
446 TTree *treeD = fLoader->TreeD();
447 if (fLoader->TreeH() && (fHits == 0x0)) {
448 fHits = new TClonesArray("AliITShit", 1560);
449 }
450 AliDetector::SetTreeAddress();
451
452 fDetTypeSim->SetTreeAddressS(treeS, (Char_t*)GetName());
453 fDetTypeSim->SetTreeAddressD(treeD, (Char_t*)GetName());
fe4da5cc 454}
2aea926d 455//______________________________________________________________________
2aea926d 456void AliITS::AddHit(Int_t track, Int_t *vol, Float_t *hits){
457 // Add an ITS hit
458 // The function to add information to the AliITShit class. See the
459 // AliITShit class for a full description. This function allocates the
460 // necessary new space for the hit information and passes the variable
461 // track, and the pointers *vol and *hits to the AliITShit constructor
462 // function.
4a5bebc2 463 // Inputs:
464 // Int_t track Track number which produced this hit.
465 // Int_t *vol Array of Integer Hit information. See AliITShit.h
466 // Float_t *hits Array of Floating Hit information. see AliITShit.h
467 // Outputs:
468 // none.
469 // Return:
470 // none.
7d62fb64 471 TClonesArray &lhits = *fHits;
472 new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
3bd79107 473}
3bd79107 474
2aea926d 475//______________________________________________________________________
755bb5cb 476void AliITS::FillModules(Int_t /* evnt */,Int_t bgrev,Int_t /* nmodules */,
8e8eae84 477 Option_t *option, const char *filename){
7d62fb64 478 // fill the modules with the sorted by module hits; add hits from
479 // background if option=Add.
480
481 static TTree *trH1; //Tree with background hits
482 static Bool_t first=kTRUE;
483 static TFile *file;
484 const char *addBgr = strstr(option,"Add");
485
7d62fb64 486 if (addBgr ) {
487 if(first) {
488 file=new TFile(filename);
489 } // end if first
490 first=kFALSE;
491 file->cd();
492 file->ls();
493 // Get Hits Tree header from file
494 if(trH1) delete trH1;
495 trH1=0;
496
0f812aa0 497 char treeName[21];
498 snprintf(treeName,20,"TreeH%d",bgrev);
7d62fb64 499 trH1 = (TTree*)gDirectory->Get(treeName);
500 if (!trH1) {
501 Error("FillModules","cannot find Hits Tree for event:%d",bgrev);
502 } // end if !trH1
503 // Set branch addresses
504 } // end if addBgr
505
506 FillModules(fLoader->TreeH(),0); // fill from this file's tree.
3bd79107 507
7d62fb64 508 if (addBgr ) {
509 FillModules(trH1,10000000); // Default mask 10M.
510 TTree *fAli=fLoader->GetRunLoader()->TreeK();
511 TFile *fileAli=0;
0f812aa0 512 if (fAli) {
513 fileAli =fAli->GetCurrentFile();
514 fileAli->cd();
515 }
7d62fb64 516 } // end if add
517
518
3bd79107 519}
2aea926d 520//______________________________________________________________________
b4012daf 521void AliITS::FillModules(TTree *treeH, Int_t mask) {
522 // fill the modules with the sorted by module hits;
523 // can be called many times to do a merging
524 // Inputs:
525 // TTree *treeH The tree containing the hits to be copied into
526 // the modules.
527 // Int_t mask The track number mask to indecate which file
528 // this hits came from.
529 // Outputs:
530 // none.
531 // Return:
532 // none.
533
88cb7938 534 if (treeH == 0x0)
535 {
0f812aa0 536 AliError("Tree H is NULL");
537 return;
88cb7938 538 }
b4012daf 539 Int_t lay,lad,det,index;
540 AliITShit *itsHit=0;
541 AliITSmodule *mod=0;
0f812aa0 542 char branchname[21];
543 snprintf(branchname,20,"%s",GetName());
b4012daf 544 TBranch *branch = treeH->GetBranch(branchname);
545 if (!branch) {
88cb7938 546 Error("FillModules","%s branch in TreeH not found",branchname);
547 return;
b4012daf 548 } // end if !branch
549 branch->SetAddress(&fHits);
550 Int_t nTracks =(Int_t) treeH->GetEntries();
551 Int_t iPrimTrack,h;
552 for(iPrimTrack=0; iPrimTrack<nTracks; iPrimTrack++){
88cb7938 553 ResetHits();
554 Int_t nBytes = treeH->GetEvent(iPrimTrack);
555 if (nBytes <= 0) continue;
556 Int_t nHits = fHits->GetEntriesFast();
557 for(h=0; h<nHits; h++){
558 itsHit = (AliITShit *)fHits->UncheckedAt(h);
559 itsHit->GetDetectorID(lay,lad,det);
7d62fb64 560 if (GetITSgeom()) {
561 index = GetITSgeom()->GetModuleIndex(lay,lad,det);
88cb7938 562 } else {
563 index=det-1; // This should not be used.
564 } // end if [You must have fITSgeom for this to work!]
565 mod = GetModule(index);
566 itsHit->SetTrack(itsHit->GetTrack()+mask); // Set track mask.
567 mod->AddHit(itsHit,iPrimTrack,h);
568 } // end loop over hits
b4012daf 569 } // end loop over tracks
570}
7d62fb64 571
b4012daf 572//______________________________________________________________________
6f5308d9 573Bool_t AliITS::InitModules(Int_t size,Int_t &nmodules){
7d62fb64 574 // Initialize the modules array.
4a5bebc2 575 // Inputs:
7d62fb64 576 // Int_t size Size of array of the number of modules to be
577 // created. If size <=0 then the number of modules
578 // is gotten from AliITSgeom class kept in fITSgeom.
4a5bebc2 579 // Outputs:
7d62fb64 580 // Int_t &nmodules The number of modules existing.
4a5bebc2 581 // Return:
582 // none.
2ab0c725 583
7d62fb64 584 if(fITSmodules){
585 fITSmodules->Delete();
586 delete fITSmodules;
587 } // end fir fITSmoudles
88cb7938 588
7d62fb64 589 if(!fDetTypeSim) {
590 Error("InitModules","fDetTypeSim is null!");
6f5308d9 591 return kFALSE;
7d62fb64 592 }
c8af5b8f 593 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
828e06c7 594
7d62fb64 595 Int_t nl,indexMAX,index;
596
597 if(size<=0){ // default to using data stored in AliITSgeom
598 if(fDetTypeSim->GetITSgeom()==0) {
599 Error("InitModules","fITSgeom not defined");
6f5308d9 600 return kFALSE;
7d62fb64 601 } // end if fITSgeom==0
602 nl = fDetTypeSim->GetITSgeom()->GetNlayers();
603 indexMAX = fDetTypeSim->GetITSgeom()->GetIndexMax();
604 nmodules = indexMAX;
605 fITSmodules = new TObjArray(indexMAX);
606 for(index=0;index<indexMAX;index++){
607 fITSmodules->AddAt( new AliITSmodule(index),index);
608 } // end for index
609 }else{
610 fITSmodules = new TObjArray(size);
611 for(index=0;index<size;index++) {
612 fITSmodules->AddAt( new AliITSmodule(index),index);
613 } // end for index
614
615 nmodules = size;
616 } // end i size<=0
6f5308d9 617 return kTRUE;
2aea926d 618}
619//______________________________________________________________________
620void AliITS::Hits2SDigits(){
621 // Standard Hits to summable Digits function.
4a5bebc2 622 // Inputs:
623 // none.
624 // Outputs:
625 // none.
7d62fb64 626
2aea926d 627
7d62fb64 628 if(!fDetTypeSim) {
629 Error("Hits2SDigits","fDetTypeSim is null!");
ad7f2bfa 630 return;
7d62fb64 631 }
632
633 SetDefaults();
634 fLoader->LoadHits("read");
635 fLoader->LoadSDigits("recreate");
636 AliRunLoader* rl = fLoader->GetRunLoader();
023ae34b 637 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 638 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
639
7d62fb64 640 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
aacedc3e 641 // Do the Hits to Digits operation. Use Standard input values.
642 // Event number from file, no background hit merging , use size from
643 // AliITSgeom class, option="All", input from this file only.
7d62fb64 644 rl->GetEvent(iEvent);
645 if (!fLoader->TreeS()) fLoader->MakeTree("S");
646 MakeBranch("S");
647 SetTreeAddress();
648 HitsToPreDigits(iEvent,0,-1," ",fOpt," ");
649 } // end for iEvent
88cb7938 650
7d62fb64 651 fLoader->UnloadHits();
652 fLoader->UnloadSDigits();
653
85a5290f 654}
655//______________________________________________________________________
7d62fb64 656void AliITS::Hits2Digits(){
657
658 //Conversion from hits to digits
659 if(!fDetTypeSim) {
660 Error("Hits2SDigits","fDetTypeSim is 0!");
661 return;
662 }
663
023ae34b 664 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 665 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 666 SetDefaults();
667
668 fLoader->LoadHits("read");
669 fLoader->LoadDigits("recreate");
670 AliRunLoader* rl = fLoader->GetRunLoader();
671 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
672 rl->GetEvent(iEvent);
673 if (!fLoader->TreeD()) fLoader->MakeTree("D");
674 MakeBranch("D");
675 SetTreeAddress();
676 HitsToDigits(iEvent,0,-1," ",fOpt," ");
677 }
678
679 fLoader->UnloadHits();
680 fLoader->UnloadDigits();
681
2aea926d 682}
7d62fb64 683
2aea926d 684//______________________________________________________________________
7d62fb64 685void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
686 Option_t *option,Option_t *opt,
687 const char *filename){
688 // Keep galice.root for signal and name differently the file for
689 // background when add! otherwise the track info for signal will be lost !
690 // the condition below will disappear when the geom class will be
691 // initialized for all versions - for the moment it is only for v5 !
692 // 7 is the SDD beam test version.
4a5bebc2 693 // Inputs:
7d62fb64 694 // Int_t evnt Event to be processed.
695 // Int_t bgrev Background Hit tree number.
696 // Int_t nmodules Not used.
697 // Option_t *option String indicating if merging hits or not. To
698 // merge hits set equal to "Add". Otherwise no
699 // background hits are considered.
700 // Test_t *filename File name containing the background hits..
4a5bebc2 701 // Outputs:
702 // none.
7d62fb64 703 // Return:
704 // none.
2aea926d 705
7d62fb64 706 if(!fDetTypeSim) {
707 Error("HitsToDigits","fDetTypeSim is null!");
708 return;
709 }
023ae34b 710 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 711 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 712 if(!GetITSgeom()) return; // need transformations to do digitization.
713 AliITSgeom *geom = GetITSgeom();
85a5290f 714
7d62fb64 715 const char *all = strstr(opt,"All");
716 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
717 strstr(opt,"SSD")};
718 static Bool_t setDef=kTRUE;
719 if (setDef) SetDefaultSimulation();
720 setDef=kFALSE;
721
722 Int_t nmodules;
723 InitModules(size,nmodules);
724 FillModules(evNumber,bgrev,nmodules,option,filename);
ad7f2bfa 725
726 // Reset Fast-OR signals for this event
727 fDetTypeSim->ResetFOSignals();
7d62fb64 728
729 AliITSsimulation *sim = 0;
730 AliITSmodule *mod = 0;
731 Int_t id;
732 for(Int_t module=0;module<geom->GetIndexMax();module++){
733 id = geom->GetModuleType(module);
734 if (!all && !det[id]) continue;
735 sim = (AliITSsimulation*)fDetTypeSim->GetSimulationModel(id);
736 if (!sim) {
737 Error("HitsToDigits","The simulation class was not "
738 "instanciated for module %d type %s!",module,
739 geom->GetModuleTypeName(module));
740 exit(1);
741 } // end if !sim
742 mod = (AliITSmodule *)fITSmodules->At(module);
743 sim->DigitiseModule(mod,module,evNumber);
744 // fills all branches - wasted disk space
745 fLoader->TreeD()->Fill();
746 ResetDigits();
747 } // end for module
748
749 ClearModules();
a0d76912 750
ad7f2bfa 751 // Add random noise to FO signals
752 if (all || det[0]) { // SPD present
753 fDetTypeSim->ProcessNoiseForFastOr();
754 }
755
756 // Add Fast-OR signals to event (only one object per event)
757 if (all || det[0]) { // SPD present
758 fDetTypeSim->WriteFOSignals();
759 }
760
761
7d62fb64 762 fLoader->TreeD()->GetEntries();
763 fLoader->TreeD()->AutoSave();
764 // reset tree
765 fLoader->TreeD()->Reset();
2aea926d 766}
7d62fb64 767//_____________________________________________________________________
768void AliITS::Hits2PreDigits(){
769 // Turn hits into SDigits
770
771 if(!fDetTypeSim) {
772 Error("Hits2SDigits","fDetTypeSim is 0!");
773 return;
774 }
775
023ae34b 776 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 777 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 778 SetDefaults();
779
780 HitsToPreDigits(fLoader->GetRunLoader()->GetEventNumber(),
781 0,-1," ",fOpt," ");
782}
783
2aea926d 784//______________________________________________________________________
2aea926d 785void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
aacedc3e 786 Option_t *option,Option_t *opt,
787 const char *filename){
4a5bebc2 788 // Keep galice.root for signal and name differently the file for
2aea926d 789 // background when add! otherwise the track info for signal will be lost !
790 // the condition below will disappear when the geom class will be
4a5bebc2 791 // initialized for all versions - for the moment it is only for v5 !
792 // 7 is the SDD beam test version.
793 // Inputs:
794 // Int_t evnt Event to be processed.
795 // Int_t bgrev Background Hit tree number.
796 // Int_t nmodules Not used.
797 // Option_t *option String indicating if merging hits or not. To
798 // merge hits set equal to "Add". Otherwise no
799 // background hits are considered.
800 // Test_t *filename File name containing the background hits..
801 // Outputs:
802 // none.
803 // Return:
804 // none.
2aea926d 805
7d62fb64 806
807 if(!fDetTypeSim) {
808 Error("HitsToPreDigits","fDetTypeSim is null!");
809 return;
810 }
023ae34b 811 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 812 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 813
814 if(!GetITSgeom()){
815 Error("HitsToPreDigits","fGeom is null!");
816 return; // need transformations to do digitization.
817 }
818 AliITSgeom *geom = GetITSgeom();
819
820 const char *all = strstr(opt,"All");
821 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
822 strstr(opt,"SSD")};
823 static Bool_t setDef=kTRUE;
824 if (setDef) SetDefaultSimulation();
825 setDef=kFALSE;
826
827 Int_t nmodules;
828 InitModules(size,nmodules);
829 FillModules(evNumber,bgrev,nmodules,option,filename);
830
831
832 AliITSsimulation *sim = 0;
833 AliITSmodule *mod = 0;
834 Int_t id,module;
835 for(module=0;module<geom->GetIndexMax();module++){
836 id = geom->GetModuleType(module);
837 if (!all && !det[id]) continue;
838 sim = (AliITSsimulation*)GetSimulationModel(id);
839 if (!sim) {
840 Error("HitsToPreDigits","The simulation class was not "
841 "instanciated for module %d type %s!",module,
842 geom->GetModuleTypeName(module));
843 exit(1);
844 } // end if !sim
845 mod = (AliITSmodule *)fITSmodules->At(module);
846 sim->SDigitiseModule(mod,module,evNumber);
847 // fills all branches - wasted disk space
848 fLoader->TreeS()->Fill();
849 fDetTypeSim->ResetSDigits();
850 } // end for module
851
852 ClearModules();
853
854
855 fLoader->TreeS()->GetEntries();
856 fLoader->TreeS()->AutoSave();
857 fLoader->WriteSDigits("OVERWRITE");
858 // reset tree
859 fLoader->TreeS()->Reset();
2aea926d 860}
7d62fb64 861
862//_____________________________________________________________________
863void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
864 Option_t *opt0,Option_t *opt1,
865 const char *flnm){
866 // keep galice.root for signal and name differently the file for
2aea926d 867 // background when add! otherwise the track info for signal will be lost !
868 // the condition below will disappear when the geom class will be
4a5bebc2 869 // initialized for all versions - for the moment it is only for v5 !
4a5bebc2 870 // Inputs:
871 // Int_t evnt Event to be processed.
872 // Int_t bgrev Background Hit tree number.
7d62fb64 873 // Int_t size Size used by InitModules. See InitModules.
874 // Option_t *opt0 Option passed to FillModules. See FillModules.
875 // Option_t *opt1 String indicating if merging hits or not. To
4a5bebc2 876 // merge hits set equal to "Add". Otherwise no
877 // background hits are considered.
7d62fb64 878 // Test_t *flnm File name containing the background hits..
4a5bebc2 879 // Outputs:
880 // none.
881 // Return:
882 // none.
883
04366a57 884
00a7cc50 885
7d62fb64 886 if(!GetITSgeom()){
887 Error("HitsToPreDigits","fGeom is null!");
888 return; // need transformations to do digitization.
889 }
890 AliITSgeom *geom = GetITSgeom();
891
892 AliITSLoader *pITSloader = (AliITSLoader*)fLoader;
893
894 const char *all = strstr(opt1,"All");
895 const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
896 strstr(opt1,"SSD")};
897 Int_t nmodules;
898 InitModules(size,nmodules);
899 FillModules(evNumber,bgrev,nmodules,opt0,flnm);
900
901 AliITSsimulation *sim = 0;
902 AliITSmodule *mod = 0;
903 Int_t id,module;
904
905 TTree *lTR = pITSloader->TreeR();
00a7cc50 906 if(!lTR) {
907 pITSloader->MakeTree("R");
908 lTR = pITSloader->TreeR();
909 }
910
7d62fb64 911 TClonesArray* ptarray = new TClonesArray("AliITSRecPoint",1000);
00a7cc50 912 TBranch* branch = (TBranch*)lTR->Branch("ITSRecPointsF",&ptarray);
913 branch->SetAddress(&ptarray);
7d62fb64 914 //m.b. : this change is nothing but a nice way to make sure
023ae34b 915 //the CPU goes up !
7d62fb64 916 for(module=0;module<geom->GetIndexMax();module++){
917 id = geom->GetModuleType(module);
918 if (!all && !det[id]) continue;
919 sim = (AliITSsimulation*)GetSimulationModel(id);
920 if (!sim) {
921 Error("HitsToFastPoints","The simulation class was not "
a5a317a9 922 "instantiated for module %d type %s!",module,
7d62fb64 923 geom->GetModuleTypeName(module));
924 exit(1);
925 } // end if !sim
926 mod = (AliITSmodule *)fITSmodules->At(module);
927 sim->CreateFastRecPoints(mod,module,gRandom,ptarray);
928 lTR->Fill();
f1bfe73f 929 ptarray->Clear();
7d62fb64 930 } // end for module
931
932 ClearModules();
933 fLoader->WriteRecPoints("OVERWRITE");
934 delete ptarray;
2aea926d 935}
7d62fb64 936//_____________________________________________________________________
937Int_t AliITS::Hits2Clusters(TTree *hTree, TTree *cTree) {
938 //------------------------------------------------------------
939 // This function creates ITS clusters
940 //------------------------------------------------------------
941 if(!GetITSgeom()){
942 Error("HitsToPreDigits","fGeom is null!");
943 return 1; // need transformations to do digitization.
944 }
945 AliITSgeom *geom=GetITSgeom();
946 Int_t mmax=geom->GetIndexMax();
947
948 InitModules(-1,mmax);
949 FillModules(hTree,0);
950
7d62fb64 951 TClonesArray *points = new TClonesArray("AliITSRecPoint",1000);
00a7cc50 952 TBranch *branch=cTree->GetBranch("ITSRecPoints");
953 if (!branch) cTree->Branch("ITSRecPoints",&points);
954 else branch->SetAddress(&points);
7d62fb64 955
956 AliITSsimulationFastPoints sim;
957 Int_t ncl=0;
958 for (Int_t m=0; m<mmax; m++) {
959 AliITSmodule *mod=GetModule(m);
960 sim.CreateFastRecPoints(mod,m,gRandom,points);
00a7cc50 961 ncl+=points->GetEntriesFast();
7d62fb64 962 cTree->Fill();
7d62fb64 963 points->Clear();
964 }
965
15e6a32c 966 AliDebug(1,Form("Number of found fast clusters : %d",ncl));
7d62fb64 967
968 //cTree->Write();
969
7d62fb64 970 delete points;
971 return 0;
972}
7d62fb64 973
7d62fb64 974//_____________________________________________________________________
975void AliITS::CheckLabels(Int_t lab[3]) const {
976 //------------------------------------------------------------
977 // Tries to find mother's labels
978 //------------------------------------------------------------
979
980 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
981
982 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
983 for (Int_t i=0;i<3;i++){
984 Int_t label = lab[i];
985 if (label>=0 && label<ntracks) {
986 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
987 if (part->P() < 0.005) {
988 Int_t m=part->GetFirstMother();
989 if (m<0) {
990 continue;
991 }
992 if (part->GetStatusCode()>0) {
993 continue;
994 }
995 lab[i]=m;
996 }
997 }
998 }
999
1000}
1001
1002//______________________________________________________________________
1003void AliITS::SDigitsToDigits(Option_t *opt){
ad7f2bfa 1004 // Standard Summable digits to Digits function.
1005 // Inputs:
1006 // none.
1007 // Outputs:
1008 // none.
1009 if (!fDetTypeSim) {
1010 AliError("fDetTypeSim is 0!");
1011 return;
1012 }
7d62fb64 1013
ad7f2bfa 1014 const char *all = strstr(opt,"All");
1015 const char *det[3] ={strstr(opt,"SPD"),strstr(opt,"SDD"),
1016 strstr(opt,"SSD")};
1017
1018 // Reset Fast-OR signals for this event
1019 fDetTypeSim->ResetFOSignals();
1020
1021 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1022 SetDefaults();
c8af5b8f 1023 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
ad7f2bfa 1024 fDetTypeSim->SDigitsToDigits(opt,(Char_t*)GetName());
1025
1026 // Add random noise to FO signals
1027 if (all || det[0]) { // SPD present
1028 fDetTypeSim->ProcessNoiseForFastOr();
1029 }
1030 // Add Fast-OR signals to event (only one object per event)
1031 if (all || det[0]) { // SPD present
1032 fDetTypeSim->WriteFOSignals();
1033 }
7d62fb64 1034}
1035
2aea926d 1036//______________________________________________________________________
2aea926d 1037void AliITS::ResetDigits(){
4a5bebc2 1038 // Reset number of digits and the digits array for the ITS detector.
1039 // Inputs:
1040 // none.
1041 // Outputs:
1042 // none.
7d62fb64 1043 if(!fDetTypeSim) {
1044 Error("ResetDigits","fDetTypeSim is 0!");
1045 return;
1046 }
1047
1048 fDetTypeSim->ResetDigits();
3bd79107 1049
1050
2aea926d 1051}
1052//______________________________________________________________________
7d62fb64 1053void AliITS::ResetDigits(Int_t branch){
4a5bebc2 1054 // Reset number of digits and the digits array for this branch.
1055 // Inputs:
1056 // none.
1057 // Outputs:
1058 // none.
828e06c7 1059
7d62fb64 1060 if(!fDetTypeSim) {
1061 Error("ResetDigits","fDetTypeSim is 0!");
1062 return;
1063 }
1064
1065 fDetTypeSim->ResetDigits(branch);
1066
2aea926d 1067}
1068//______________________________________________________________________
1069void AliITS::AddSumDigit(AliITSpListItem &sdig){
4a5bebc2 1070 // Adds the a module full of summable digits to the summable digits tree.
1071 // Inputs:
1072 // AliITSpListItem &sdig SDigit to be added to SDigits tree.
1073 // Outputs:
1074 // none.
1075 // Return:
1076 // none.
828e06c7 1077
7d62fb64 1078 if(!fDetTypeSim) {
1079 Error("AddSumDigit","fDetTypeSim is 0!");
1080 return;
1081 }
1082 fDetTypeSim->AddSumDigit(sdig);
1083
828e06c7 1084}
2aea926d 1085//______________________________________________________________________
7d62fb64 1086void AliITS::AddSimDigit(Int_t branch, AliITSdigit *d){
4a5bebc2 1087 // Add a simulated digit.
1088 // Inputs:
1089 // Int_t id Detector type number.
1090 // AliITSdigit *d Digit to be added to the Digits Tree. See
1091 // AliITSdigit.h
1092 // Outputs:
1093 // none.
1094 // Return:
1095 // none.
2aea926d 1096
7d62fb64 1097 if(!fDetTypeSim) {
1098 Error("AddSimDigit","fDetTypeSim is 0!");
1099 return;
1100 }
1101 fDetTypeSim->AddSimDigit(branch,d);
1102
2aea926d 1103}
1104//______________________________________________________________________
7d62fb64 1105void AliITS::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,Int_t *tracks,
83ec5e27 1106 Int_t *hits,Float_t *charges, Int_t sigexpanded){
7f1a504b 1107 // Add a simulated digit to the list.
1108 // Inputs:
1109 // Int_t id Detector type number.
1110 // Float_t phys Physics indicator. See AliITSdigits.h
1111 // Int_t *digits Integer array containing the digits info. See
1112 // AliITSdigit.h
1113 // Int_t *tracks Integer array [AliITSdigitS?D::GetNTracks()]
1114 // containing the track numbers that contributed to
1115 // this digit.
1116 // Int_t *hits Integer array [AliITSdigitS?D::GetNTracks()]
1117 // containing the hit numbers, from AliITSmodule, that
1118 // contributed to this digit.
1119 // Float_t *charge Floating point array of the signals contributed
1120 // to this digit by each track.
1121 // Outputs:
1122 // none.
1123 // Return:
1124 // none.
2aea926d 1125
7d62fb64 1126 if(!fDetTypeSim) {
1127 Error("AddSimDigit","fDetTypeSim is 0!");
1128 return;
1129 }
83ec5e27 1130 fDetTypeSim->AddSimDigit(branch,phys,digits,tracks,hits,charges,sigexpanded);
7d62fb64 1131
2aea926d 1132}
0421c3d1 1133//______________________________________________________________________
aacedc3e 1134void AliITS::Digits2Raw(){
1135 // convert digits of the current event to raw data
0421c3d1 1136
7d62fb64 1137 if(!fDetTypeSim) {
1138 Error("Digits2Raw","fDetTypeSim is 0!");
1139 return;
1140 }
023ae34b 1141 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
7d62fb64 1142 SetDefaults();
c8af5b8f 1143 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 1144 fDetTypeSim->GetLoader()->LoadDigits();
1145 TTree* digits = fDetTypeSim->GetLoader()->TreeD();
0421c3d1 1146 if (!digits) {
aacedc3e 1147 Error("Digits2Raw", "no digits tree");
1148 return;
0421c3d1 1149 }
7d62fb64 1150 fDetTypeSim->SetTreeAddressD(digits,(Char_t*)GetName());
ad7f2bfa 1151
1152 // Get the FO signals for this event
1153 AliITSFOSignalsSPD* foSignals = NULL;
1154 AliRunLoader* runLoader = AliRunLoader::Instance();
1155 AliITSLoader* itsLoader = (AliITSLoader*) runLoader->GetLoader("ITSLoader");
1156 if (!itsLoader) {
1157 AliError("ITS loader is NULL.");
1158 }
a0d76912 1159 else {
1160 if(!itsLoader->TreeD()) AliError(" !!! No TreeD available !!!");
1161 foSignals = (AliITSFOSignalsSPD*)itsLoader->TreeD()->GetUserInfo()->FindObject("AliITSFOSignalsSPD");
1162 if(!foSignals) AliError("FO signals not retrieved");
1163 }
1164
ad7f2bfa 1165 Bool_t deleteFOsignalsLater = kFALSE;
1166 if (!foSignals) {
1167 AliError("FO signals not available. No FO bits will be written.");
1168 foSignals = new AliITSFOSignalsSPD(); // make a temporary dummy signals object
1169 deleteFOsignalsLater = kTRUE;
1170 }
1171
1172
979b5a5f 1173 AliITSDDLModuleMapSDD* ddlsdd=fDetTypeSim->GetDDLModuleMapSDD();
d9ed1779 1174 Char_t rawSDD=fDetTypeSim->GetSimuParam()->GetSDDRawDataFormat();
0421c3d1 1175 AliITSDDLRawData rawWriter;
d9ed1779 1176
1177 rawWriter.SetSDDRawFormat(rawSDD);
0421c3d1 1178 //Verbose level
1179 // 0: Silent
1180 // 1: cout messages
1181 // 2: txt files with digits
1182 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
1183 //it is highly suggested to use this mode only for debugging digits files
1184 //reasonably small, because otherwise the size of the txt files can reach
1185 //quickly several MB wasting time and disk space.
1186 rawWriter.SetVerbose(0);
1187
1188 //SILICON PIXEL DETECTOR
15e6a32c 1189 AliDebug(1,"Formatting raw data for SPD");
ad7f2bfa 1190 rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"),foSignals);
1191 if(deleteFOsignalsLater) delete foSignals;
0421c3d1 1192
1193 //SILICON DRIFT DETECTOR
d9ed1779 1194 AliDebug(1,Form("Formatting raw data for SDD - Format code =%d",rawSDD));
979b5a5f 1195 rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"),ddlsdd);
0421c3d1 1196
1197 //SILICON STRIP DETECTOR
15e6a32c 1198 AliDebug(1,"Formatting raw data for SSD");
0421c3d1 1199 rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
1200
1201 fLoader->UnloadDigits();
2aea926d 1202}
04366a57 1203//______________________________________________________________________
aacedc3e 1204AliLoader* AliITS::MakeLoader(const char* topfoldername){
1205 //builds ITSgetter (AliLoader type)
1206 //if detector wants to use castomized getter, it must overload this method
1207
64f311fe 1208 AliDebug(1,Form("Creating AliITSLoader. Top folder is %s.",
1209 topfoldername));
aacedc3e 1210 fLoader = new AliITSLoader(GetName(),topfoldername);
1211 return fLoader;
2aea926d 1212}
ad7f2bfa 1213//______________________________________________________________________
0b5bf101 1214Bool_t AliITS::Raw2SDigits(AliRawReader* rawReader)
1215{
1216 //
1217 // Converts RAW data to SDigits
1218 //
1219 // Get TreeS
1220 //
afbc83e9 1221 Int_t last = -1;
773af0c4 1222 Int_t size = AliITSgeomTGeo::GetNModules();
afbc83e9 1223 if(!fModA) {
1224 fModA = new TClonesArray*[size];
1225 for (Int_t mod = 0; mod < size; mod++) fModA[mod] = new TClonesArray("AliITSpListItem", 10000);
1226 }
1227 AliLoader* loader = (AliRunLoader::Instance())->GetLoader("ITSLoader");
1228 if (!loader){
1229 Error("Open","Can not get ITS loader from Run Loader");
1230 return kFALSE;
1231 }
0b5bf101 1232
afbc83e9 1233 TTree* tree = 0;
1234 tree = loader->TreeS();
1235 if (!tree){
1236 loader->MakeTree("S");
0b5bf101 1237 tree = loader->TreeS();
afbc83e9 1238 }
1239 //
1240 // Array for SDigits
1241 //
1242 if(!fpSDigits){
1243 fpSDigits = new TClonesArray("AliITSpListItem",10000);
1244 }
1245 TClonesArray& aSDigits = *fpSDigits;
1246 Int_t bufsize = 32000;
1247 tree->Branch("ITS", &fpSDigits, bufsize);
1248 Int_t npx = 0;
1249 //
1250 // SPD
1251 //
1252 AliITSsegmentationSPD* segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1253 if(!segSPD){
1254 AliWarning("Set AliITS defaults");
1255 SetDefaults();
1256 segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1257 }
1258 npx = segSPD->Npx();
1259 Double_t thr, sigma;
0b5bf101 1260
afbc83e9 1261 AliITSRawStreamSPD inputSPD(rawReader);
1262 while(1){
1263 Bool_t next = inputSPD.Next();
1264 if (!next) break;
0b5bf101 1265
afbc83e9 1266 Int_t module = inputSPD.GetModuleID();
1267 Int_t column = inputSPD.GetColumn();
1268 Int_t row = inputSPD.GetRow();
1269 Int_t index = npx * column + row;
0b5bf101 1270
afbc83e9 1271 if (module >= size) continue;
0b5bf101 1272
afbc83e9 1273 last = (fModA[module])->GetEntries();
1274 TClonesArray& dum = *fModA[module];
1275 fDetTypeSim->GetSimuParam()->SPDThresholds(module,thr,sigma);
1276 thr += 1.;
1277 new (dum[last]) AliITSpListItem(-1, -1, module, index, thr);
1278 }
1279 rawReader->Reset();
1280
1281 //
1282 // SDD
1283 //
1284 AliITSsegmentationSDD* segSDD = (AliITSsegmentationSDD*) fDetTypeSim->GetSegmentationModel(1);
1285 npx = segSDD->Npx();
1286 Int_t scalef=AliITSsimulationSDD::ScaleFourier(segSDD);
1287 Int_t firstSDD=AliITSgeomTGeo::GetModuleIndex(3,1,1);
1288 Int_t firstSSD=AliITSgeomTGeo::GetModuleIndex(5,1,1);
1289
1290 AliITSRawStream* inputSDD=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader);
1291 for(Int_t iMod=firstSDD; iMod<firstSSD; iMod++){
1292 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)fDetTypeSim->GetCalibrationModel(iMod);
1293 Bool_t isZeroSupp=cal->GetZeroSupp();
1294 if(isZeroSupp){
1295 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,cal->GetZSLowThreshold(iSid));
1296 }else{
1297 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,0);
dee45d79 1298 }
afbc83e9 1299 }
dee45d79 1300
afbc83e9 1301 AliITSDDLModuleMapSDD* ddlmap=fDetTypeSim->GetDDLModuleMapSDD();
1302 inputSDD->SetDDLModuleMap(ddlmap);
1303 while(inputSDD->Next()){
1304 if(inputSDD->IsCompletedModule()==kFALSE &&
1305 inputSDD->IsCompletedDDL()==kFALSE){
1306
1307 Int_t module = inputSDD->GetModuleID();
1308 Int_t anode = inputSDD->GetCoord1()+segSDD->NpzHalf()*inputSDD->GetChannel();
1309 Int_t time = inputSDD->GetCoord2();
1310 Int_t signal10 = inputSDD->GetSignal();
1311 Int_t index = AliITSpList::GetIndex(anode,time,scalef*npx);
1312
1313 if (module >= size) continue;
1314 last = fModA[module]->GetEntries();
1315 TClonesArray& dum = *fModA[module];
1316 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal10));
1317 ((AliITSpListItem*) dum.At(last))->AddSignalAfterElect(module, index, Double_t(signal10));
0b5bf101 1318 }
afbc83e9 1319 }
1320 delete inputSDD;
1321 rawReader->Reset();
a4998655 1322
afbc83e9 1323 //
1324 // SSD
1325 //
1326 AliITSsegmentationSSD* segSSD = (AliITSsegmentationSSD*) fDetTypeSim->GetSegmentationModel(2);
1327 npx = segSSD->Npx();
1328 AliITSRawStreamSSD inputSSD(rawReader);
1329 while(1){
1330 Bool_t next = inputSSD.Next();
1331 if (!next) break;
1332
1333 Int_t module = inputSSD.GetModuleID();
773af0c4 1334 if(module<0)AliError(Form("Invalid SSD module %d \n",module));
1335 if(module<0)continue;
afbc83e9 1336 Int_t side = inputSSD.GetSideFlag();
1337 Int_t strip = inputSSD.GetStrip();
1338 Int_t signal = inputSSD.GetSignal();
1339 Int_t index = npx * side + strip;
1340
1341 if (module >= size) continue;
0b5bf101 1342
afbc83e9 1343 last = fModA[module]->GetEntries();
1344 TClonesArray& dum = *fModA[module];
1345 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal));
1346 }
1347 rawReader->Reset();
1348 AliITSpListItem* sdig = 0;
0b5bf101 1349
afbc83e9 1350 Int_t firstssd = GetITSgeom()->GetStartDet(kSSD);
1351 Double_t adcToEv = 1.;
1352 for (Int_t mod = 0; mod < size; mod++)
1353 {
8b3448d3 1354 if(mod>=firstssd) {
1355 AliITSCalibrationSSD* calssd = (AliITSCalibrationSSD*)fDetTypeSim->GetCalibrationModel(mod);
1356 adcToEv = 1./calssd->GetSSDDEvToADC(1.);
1357 }
afbc83e9 1358 Int_t nsdig = fModA[mod]->GetEntries();
8b3448d3 1359 for (Int_t ie = 0; ie < nsdig; ie++) {
afbc83e9 1360 sdig = (AliITSpListItem*) (fModA[mod]->At(ie));
463ae357 1361 Double_t digsig = sdig->GetSignal();
8b3448d3 1362 if(mod>=firstssd) digsig*=adcToEv; // for SSD: convert back charge from ADC to electron
1363 new (aSDigits[ie]) AliITSpListItem(-1, -1, mod, sdig->GetIndex(), digsig);
afbc83e9 1364 Float_t sig = sdig->GetSignalAfterElect();
1365 if(mod>=firstssd) sig*=adcToEv;
1366 if (sig > 0.) {
1367 sdig = (AliITSpListItem*)aSDigits[ie];
1368 sdig->AddSignalAfterElect(mod, sdig->GetIndex(), Double_t(sig));
0b5bf101 1369 }
afbc83e9 1370 }
0b5bf101 1371
afbc83e9 1372 tree->Fill();
1373 aSDigits.Clear();
1374 fModA[mod]->Clear();
0b5bf101 1375 }
afbc83e9 1376 loader->WriteSDigits("OVERWRITE");
1377 return kTRUE;
0b5bf101 1378}
1379
ef7ff1f9 1380//______________________________________________________________________
1381void AliITS::UpdateInternalGeometry(){
ed9289c8 1382 //reads new geometry from TGeo
012f0f4c 1383// AliDebug(1,"Delete ITSgeom and create a new one reading TGeo");
1384
108bd0fe 1385 AliITSVersion_t version = (AliITSVersion_t)IsVersion();
1386 Int_t minor = 0;
012f0f4c 1387 AliITSInitGeometry initgeom;
1388 AliITSgeom* geom = initgeom.CreateAliITSgeom(version,minor);
ef7ff1f9 1389 SetITSgeom(geom);
ef7ff1f9 1390}
ad7f2bfa 1391//______________________________________________________________________
1392AliTriggerDetector* AliITS::CreateTriggerDetector() const {
1393 // create an AliITSTrigger object (and set trigger conditions as input)
1394 return new AliITSTrigger(fDetTypeSim->GetTriggerConditions());
1395}