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