]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITS.cxx
major dielectron update (included also the data and plotting macros for paper)
[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
679379e8 256//______________________________________________________________________
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}
2aea926d 270//______________________________________________________________________
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
7d62fb64 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}
9c74c52b 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
e0fc0305 650
7d62fb64 651 fLoader->UnloadHits();
652 fLoader->UnloadSDigits();
653
2aea926d 654}
655//______________________________________________________________________
656void AliITS::Hits2Digits(){
2aea926d 657
7d62fb64 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){
4a5bebc2 688 // Keep galice.root for signal and name differently the file for
2aea926d 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
4a5bebc2 691 // initialized for all versions - for the moment it is only for v5 !
692 // 7 is the SDD beam test version.
693 // Inputs:
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..
701 // Outputs:
702 // none.
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();
714
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 Fast-OR signals to event (only one object per event)
752 if (all || det[0]) { // SPD present
662026ab 753 WriteFOSignals();
ad7f2bfa 754 }
ad7f2bfa 755
7d62fb64 756 fLoader->TreeD()->GetEntries();
757 fLoader->TreeD()->AutoSave();
758 // reset tree
759 fLoader->TreeD()->Reset();
2aea926d 760}
7d62fb64 761//_____________________________________________________________________
762void AliITS::Hits2PreDigits(){
763 // Turn hits into SDigits
764
765 if(!fDetTypeSim) {
766 Error("Hits2SDigits","fDetTypeSim is 0!");
767 return;
768 }
769
023ae34b 770 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 771 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 772 SetDefaults();
773
774 HitsToPreDigits(fLoader->GetRunLoader()->GetEventNumber(),
775 0,-1," ",fOpt," ");
776}
777
2aea926d 778//______________________________________________________________________
7d62fb64 779void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
780 Option_t *option,Option_t *opt,
781 const char *filename){
4a5bebc2 782 // Keep galice.root for signal and name differently the file for
2aea926d 783 // background when add! otherwise the track info for signal will be lost !
784 // the condition below will disappear when the geom class will be
4a5bebc2 785 // initialized for all versions - for the moment it is only for v5 !
786 // 7 is the SDD beam test version.
787 // Inputs:
788 // Int_t evnt Event to be processed.
789 // Int_t bgrev Background Hit tree number.
790 // Int_t nmodules Not used.
791 // Option_t *option String indicating if merging hits or not. To
792 // merge hits set equal to "Add". Otherwise no
793 // background hits are considered.
794 // Test_t *filename File name containing the background hits..
795 // Outputs:
796 // none.
797 // Return:
798 // none.
799
7d62fb64 800
801 if(!fDetTypeSim) {
802 Error("HitsToPreDigits","fDetTypeSim is null!");
803 return;
804 }
023ae34b 805 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 806 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 807
808 if(!GetITSgeom()){
809 Error("HitsToPreDigits","fGeom is null!");
810 return; // need transformations to do digitization.
811 }
812 AliITSgeom *geom = GetITSgeom();
813
814 const char *all = strstr(opt,"All");
815 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
816 strstr(opt,"SSD")};
817 static Bool_t setDef=kTRUE;
818 if (setDef) SetDefaultSimulation();
819 setDef=kFALSE;
820
821 Int_t nmodules;
822 InitModules(size,nmodules);
823 FillModules(evNumber,bgrev,nmodules,option,filename);
824
825
826 AliITSsimulation *sim = 0;
827 AliITSmodule *mod = 0;
828 Int_t id,module;
829 for(module=0;module<geom->GetIndexMax();module++){
830 id = geom->GetModuleType(module);
831 if (!all && !det[id]) continue;
832 sim = (AliITSsimulation*)GetSimulationModel(id);
833 if (!sim) {
834 Error("HitsToPreDigits","The simulation class was not "
835 "instanciated for module %d type %s!",module,
836 geom->GetModuleTypeName(module));
837 exit(1);
838 } // end if !sim
839 mod = (AliITSmodule *)fITSmodules->At(module);
840 sim->SDigitiseModule(mod,module,evNumber);
841 // fills all branches - wasted disk space
842 fLoader->TreeS()->Fill();
843 fDetTypeSim->ResetSDigits();
844 } // end for module
04366a57 845
7d62fb64 846 ClearModules();
847
848
849 fLoader->TreeS()->GetEntries();
850 fLoader->TreeS()->AutoSave();
851 fLoader->WriteSDigits("OVERWRITE");
852 // reset tree
853 fLoader->TreeS()->Reset();
2aea926d 854}
7d62fb64 855
856//_____________________________________________________________________
857void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
858 Option_t *opt0,Option_t *opt1,
859 const char *flnm){
860 // keep galice.root for signal and name differently the file for
861 // background when add! otherwise the track info for signal will be lost !
862 // the condition below will disappear when the geom class will be
863 // initialized for all versions - for the moment it is only for v5 !
864 // Inputs:
865 // Int_t evnt Event to be processed.
866 // Int_t bgrev Background Hit tree number.
867 // Int_t size Size used by InitModules. See InitModules.
868 // Option_t *opt0 Option passed to FillModules. See FillModules.
869 // Option_t *opt1 String indicating if merging hits or not. To
870 // merge hits set equal to "Add". Otherwise no
871 // background hits are considered.
872 // Test_t *flnm File name containing the background hits..
873 // Outputs:
874 // none.
875 // Return:
876 // none.
877
878
00a7cc50 879
7d62fb64 880 if(!GetITSgeom()){
881 Error("HitsToPreDigits","fGeom is null!");
882 return; // need transformations to do digitization.
883 }
884 AliITSgeom *geom = GetITSgeom();
885
886 AliITSLoader *pITSloader = (AliITSLoader*)fLoader;
887
888 const char *all = strstr(opt1,"All");
889 const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
890 strstr(opt1,"SSD")};
891 Int_t nmodules;
892 InitModules(size,nmodules);
893 FillModules(evNumber,bgrev,nmodules,opt0,flnm);
894
895 AliITSsimulation *sim = 0;
896 AliITSmodule *mod = 0;
897 Int_t id,module;
898
899 TTree *lTR = pITSloader->TreeR();
00a7cc50 900 if(!lTR) {
901 pITSloader->MakeTree("R");
902 lTR = pITSloader->TreeR();
903 }
904
7d62fb64 905 TClonesArray* ptarray = new TClonesArray("AliITSRecPoint",1000);
00a7cc50 906 TBranch* branch = (TBranch*)lTR->Branch("ITSRecPointsF",&ptarray);
907 branch->SetAddress(&ptarray);
7d62fb64 908 //m.b. : this change is nothing but a nice way to make sure
023ae34b 909 //the CPU goes up !
7d62fb64 910 for(module=0;module<geom->GetIndexMax();module++){
911 id = geom->GetModuleType(module);
912 if (!all && !det[id]) continue;
913 sim = (AliITSsimulation*)GetSimulationModel(id);
914 if (!sim) {
915 Error("HitsToFastPoints","The simulation class was not "
a5a317a9 916 "instantiated for module %d type %s!",module,
7d62fb64 917 geom->GetModuleTypeName(module));
918 exit(1);
919 } // end if !sim
920 mod = (AliITSmodule *)fITSmodules->At(module);
921 sim->CreateFastRecPoints(mod,module,gRandom,ptarray);
922 lTR->Fill();
f1bfe73f 923 ptarray->Clear();
7d62fb64 924 } // end for module
925
926 ClearModules();
927 fLoader->WriteRecPoints("OVERWRITE");
928 delete ptarray;
929}
930//_____________________________________________________________________
931Int_t AliITS::Hits2Clusters(TTree *hTree, TTree *cTree) {
932 //------------------------------------------------------------
933 // This function creates ITS clusters
934 //------------------------------------------------------------
935 if(!GetITSgeom()){
936 Error("HitsToPreDigits","fGeom is null!");
937 return 1; // need transformations to do digitization.
938 }
939 AliITSgeom *geom=GetITSgeom();
940 Int_t mmax=geom->GetIndexMax();
941
942 InitModules(-1,mmax);
943 FillModules(hTree,0);
944
7d62fb64 945 TClonesArray *points = new TClonesArray("AliITSRecPoint",1000);
00a7cc50 946 TBranch *branch=cTree->GetBranch("ITSRecPoints");
947 if (!branch) cTree->Branch("ITSRecPoints",&points);
948 else branch->SetAddress(&points);
7d62fb64 949
950 AliITSsimulationFastPoints sim;
951 Int_t ncl=0;
952 for (Int_t m=0; m<mmax; m++) {
953 AliITSmodule *mod=GetModule(m);
954 sim.CreateFastRecPoints(mod,m,gRandom,points);
00a7cc50 955 ncl+=points->GetEntriesFast();
7d62fb64 956 cTree->Fill();
7d62fb64 957 points->Clear();
958 }
959
15e6a32c 960 AliDebug(1,Form("Number of found fast clusters : %d",ncl));
7d62fb64 961
962 //cTree->Write();
963
7d62fb64 964 delete points;
965 return 0;
966}
7d62fb64 967
7d62fb64 968//_____________________________________________________________________
969void AliITS::CheckLabels(Int_t lab[3]) const {
970 //------------------------------------------------------------
971 // Tries to find mother's labels
972 //------------------------------------------------------------
973
974 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
975
976 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
977 for (Int_t i=0;i<3;i++){
978 Int_t label = lab[i];
979 if (label>=0 && label<ntracks) {
980 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
981 if (part->P() < 0.005) {
982 Int_t m=part->GetFirstMother();
983 if (m<0) {
984 continue;
985 }
986 if (part->GetStatusCode()>0) {
987 continue;
988 }
989 lab[i]=m;
990 }
991 }
992 }
993
994}
995
996//______________________________________________________________________
997void AliITS::SDigitsToDigits(Option_t *opt){
ad7f2bfa 998 // Standard Summable digits to Digits function.
999 // Inputs:
1000 // none.
1001 // Outputs:
1002 // none.
1003 if (!fDetTypeSim) {
1004 AliError("fDetTypeSim is 0!");
1005 return;
1006 }
ad7f2bfa 1007 const char *all = strstr(opt,"All");
1008 const char *det[3] ={strstr(opt,"SPD"),strstr(opt,"SDD"),
1009 strstr(opt,"SSD")};
1010
1011 // Reset Fast-OR signals for this event
1012 fDetTypeSim->ResetFOSignals();
1013
1014 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1015 SetDefaults();
c8af5b8f 1016 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
ad7f2bfa 1017 fDetTypeSim->SDigitsToDigits(opt,(Char_t*)GetName());
1018
ad7f2bfa 1019 // Add Fast-OR signals to event (only one object per event)
1020 if (all || det[0]) { // SPD present
662026ab 1021 WriteFOSignals();
ad7f2bfa 1022 }
7d62fb64 1023}
1024
2aea926d 1025//______________________________________________________________________
2aea926d 1026void AliITS::ResetDigits(){
4a5bebc2 1027 // Reset number of digits and the digits array for the ITS detector.
1028 // Inputs:
1029 // none.
1030 // Outputs:
1031 // none.
7d62fb64 1032 if(!fDetTypeSim) {
1033 Error("ResetDigits","fDetTypeSim is 0!");
1034 return;
1035 }
1036
1037 fDetTypeSim->ResetDigits();
3bd79107 1038
1039
2aea926d 1040}
1041//______________________________________________________________________
7d62fb64 1042void AliITS::ResetDigits(Int_t branch){
4a5bebc2 1043 // Reset number of digits and the digits array for this branch.
1044 // Inputs:
1045 // none.
1046 // Outputs:
1047 // none.
828e06c7 1048
7d62fb64 1049 if(!fDetTypeSim) {
1050 Error("ResetDigits","fDetTypeSim is 0!");
1051 return;
1052 }
1053
1054 fDetTypeSim->ResetDigits(branch);
1055
2aea926d 1056}
1057//______________________________________________________________________
1058void AliITS::AddSumDigit(AliITSpListItem &sdig){
4a5bebc2 1059 // Adds the a module full of summable digits to the summable digits tree.
1060 // Inputs:
1061 // AliITSpListItem &sdig SDigit to be added to SDigits tree.
1062 // Outputs:
1063 // none.
1064 // Return:
1065 // none.
828e06c7 1066
7d62fb64 1067 if(!fDetTypeSim) {
1068 Error("AddSumDigit","fDetTypeSim is 0!");
1069 return;
1070 }
1071 fDetTypeSim->AddSumDigit(sdig);
1072
2aea926d 1073}
1074//______________________________________________________________________
7d62fb64 1075void AliITS::AddSimDigit(Int_t branch, AliITSdigit *d){
4a5bebc2 1076 // Add a simulated digit.
1077 // Inputs:
1078 // Int_t id Detector type number.
1079 // AliITSdigit *d Digit to be added to the Digits Tree. See
1080 // AliITSdigit.h
1081 // Outputs:
1082 // none.
1083 // Return:
1084 // none.
2aea926d 1085
7d62fb64 1086 if(!fDetTypeSim) {
1087 Error("AddSimDigit","fDetTypeSim is 0!");
1088 return;
1089 }
1090 fDetTypeSim->AddSimDigit(branch,d);
1091
2aea926d 1092}
1093//______________________________________________________________________
7d62fb64 1094void AliITS::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,Int_t *tracks,
83ec5e27 1095 Int_t *hits,Float_t *charges, Int_t sigexpanded){
7f1a504b 1096 // Add a simulated digit to the list.
1097 // Inputs:
1098 // Int_t id Detector type number.
1099 // Float_t phys Physics indicator. See AliITSdigits.h
1100 // Int_t *digits Integer array containing the digits info. See
1101 // AliITSdigit.h
1102 // Int_t *tracks Integer array [AliITSdigitS?D::GetNTracks()]
1103 // containing the track numbers that contributed to
1104 // this digit.
1105 // Int_t *hits Integer array [AliITSdigitS?D::GetNTracks()]
1106 // containing the hit numbers, from AliITSmodule, that
1107 // contributed to this digit.
1108 // Float_t *charge Floating point array of the signals contributed
1109 // to this digit by each track.
1110 // Outputs:
1111 // none.
1112 // Return:
1113 // none.
2aea926d 1114
7d62fb64 1115 if(!fDetTypeSim) {
1116 Error("AddSimDigit","fDetTypeSim is 0!");
1117 return;
1118 }
83ec5e27 1119 fDetTypeSim->AddSimDigit(branch,phys,digits,tracks,hits,charges,sigexpanded);
7d62fb64 1120
2aea926d 1121}
0421c3d1 1122//______________________________________________________________________
aacedc3e 1123void AliITS::Digits2Raw(){
1124 // convert digits of the current event to raw data
0421c3d1 1125
7d62fb64 1126 if(!fDetTypeSim) {
1127 Error("Digits2Raw","fDetTypeSim is 0!");
1128 return;
1129 }
023ae34b 1130 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
7d62fb64 1131 SetDefaults();
c8af5b8f 1132 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 1133 fDetTypeSim->GetLoader()->LoadDigits();
1134 TTree* digits = fDetTypeSim->GetLoader()->TreeD();
0421c3d1 1135 if (!digits) {
aacedc3e 1136 Error("Digits2Raw", "no digits tree");
1137 return;
0421c3d1 1138 }
7d62fb64 1139 fDetTypeSim->SetTreeAddressD(digits,(Char_t*)GetName());
ad7f2bfa 1140
1141 // Get the FO signals for this event
1142 AliITSFOSignalsSPD* foSignals = NULL;
1143 AliRunLoader* runLoader = AliRunLoader::Instance();
1144 AliITSLoader* itsLoader = (AliITSLoader*) runLoader->GetLoader("ITSLoader");
1145 if (!itsLoader) {
1146 AliError("ITS loader is NULL.");
1147 }
a0d76912 1148 else {
1149 if(!itsLoader->TreeD()) AliError(" !!! No TreeD available !!!");
1150 foSignals = (AliITSFOSignalsSPD*)itsLoader->TreeD()->GetUserInfo()->FindObject("AliITSFOSignalsSPD");
1151 if(!foSignals) AliError("FO signals not retrieved");
1152 }
1153
ad7f2bfa 1154 Bool_t deleteFOsignalsLater = kFALSE;
1155 if (!foSignals) {
1156 AliError("FO signals not available. No FO bits will be written.");
1157 foSignals = new AliITSFOSignalsSPD(); // make a temporary dummy signals object
1158 deleteFOsignalsLater = kTRUE;
1159 }
1160
1161
979b5a5f 1162 AliITSDDLModuleMapSDD* ddlsdd=fDetTypeSim->GetDDLModuleMapSDD();
d9ed1779 1163 Char_t rawSDD=fDetTypeSim->GetSimuParam()->GetSDDRawDataFormat();
0421c3d1 1164 AliITSDDLRawData rawWriter;
d9ed1779 1165
1166 rawWriter.SetSDDRawFormat(rawSDD);
0421c3d1 1167 //Verbose level
1168 // 0: Silent
1169 // 1: cout messages
1170 // 2: txt files with digits
1171 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
1172 //it is highly suggested to use this mode only for debugging digits files
1173 //reasonably small, because otherwise the size of the txt files can reach
1174 //quickly several MB wasting time and disk space.
1175 rawWriter.SetVerbose(0);
1176
1177 //SILICON PIXEL DETECTOR
15e6a32c 1178 AliDebug(1,"Formatting raw data for SPD");
ad7f2bfa 1179 rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"),foSignals);
1180 if(deleteFOsignalsLater) delete foSignals;
0421c3d1 1181
1182 //SILICON DRIFT DETECTOR
d9ed1779 1183 AliDebug(1,Form("Formatting raw data for SDD - Format code =%d",rawSDD));
979b5a5f 1184 rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"),ddlsdd);
0421c3d1 1185
1186 //SILICON STRIP DETECTOR
15e6a32c 1187 AliDebug(1,"Formatting raw data for SSD");
0421c3d1 1188 rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
1189
1190 fLoader->UnloadDigits();
2aea926d 1191}
2aea926d 1192//______________________________________________________________________
aacedc3e 1193AliLoader* AliITS::MakeLoader(const char* topfoldername){
1194 //builds ITSgetter (AliLoader type)
1195 //if detector wants to use castomized getter, it must overload this method
1196
64f311fe 1197 AliDebug(1,Form("Creating AliITSLoader. Top folder is %s.",
1198 topfoldername));
aacedc3e 1199 fLoader = new AliITSLoader(GetName(),topfoldername);
1200 return fLoader;
2aea926d 1201}
ad7f2bfa 1202//______________________________________________________________________
0b5bf101 1203Bool_t AliITS::Raw2SDigits(AliRawReader* rawReader)
1204{
1205 //
1206 // Converts RAW data to SDigits
1207 //
1208 // Get TreeS
1209 //
afbc83e9 1210 Int_t last = -1;
773af0c4 1211 Int_t size = AliITSgeomTGeo::GetNModules();
afbc83e9 1212 if(!fModA) {
1213 fModA = new TClonesArray*[size];
1214 for (Int_t mod = 0; mod < size; mod++) fModA[mod] = new TClonesArray("AliITSpListItem", 10000);
1215 }
1216 AliLoader* loader = (AliRunLoader::Instance())->GetLoader("ITSLoader");
1217 if (!loader){
1218 Error("Open","Can not get ITS loader from Run Loader");
1219 return kFALSE;
1220 }
0b5bf101 1221
afbc83e9 1222 TTree* tree = 0;
1223 tree = loader->TreeS();
1224 if (!tree){
1225 loader->MakeTree("S");
0b5bf101 1226 tree = loader->TreeS();
afbc83e9 1227 }
1228 //
1229 // Array for SDigits
1230 //
1231 if(!fpSDigits){
1232 fpSDigits = new TClonesArray("AliITSpListItem",10000);
1233 }
1234 TClonesArray& aSDigits = *fpSDigits;
1235 Int_t bufsize = 32000;
1236 tree->Branch("ITS", &fpSDigits, bufsize);
1237 Int_t npx = 0;
1238 //
1239 // SPD
1240 //
1241 AliITSsegmentationSPD* segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1242 if(!segSPD){
1243 AliWarning("Set AliITS defaults");
1244 SetDefaults();
1245 segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1246 }
1247 npx = segSPD->Npx();
1248 Double_t thr, sigma;
0b5bf101 1249
afbc83e9 1250 AliITSRawStreamSPD inputSPD(rawReader);
1251 while(1){
1252 Bool_t next = inputSPD.Next();
1253 if (!next) break;
0b5bf101 1254
afbc83e9 1255 Int_t module = inputSPD.GetModuleID();
1256 Int_t column = inputSPD.GetColumn();
1257 Int_t row = inputSPD.GetRow();
1258 Int_t index = npx * column + row;
0b5bf101 1259
afbc83e9 1260 if (module >= size) continue;
0b5bf101 1261
afbc83e9 1262 last = (fModA[module])->GetEntries();
1263 TClonesArray& dum = *fModA[module];
1264 fDetTypeSim->GetSimuParam()->SPDThresholds(module,thr,sigma);
1265 thr += 1.;
1266 new (dum[last]) AliITSpListItem(-1, -1, module, index, thr);
1267 }
1268 rawReader->Reset();
1269
1270 //
1271 // SDD
1272 //
1273 AliITSsegmentationSDD* segSDD = (AliITSsegmentationSDD*) fDetTypeSim->GetSegmentationModel(1);
1274 npx = segSDD->Npx();
1275 Int_t scalef=AliITSsimulationSDD::ScaleFourier(segSDD);
1276 Int_t firstSDD=AliITSgeomTGeo::GetModuleIndex(3,1,1);
1277 Int_t firstSSD=AliITSgeomTGeo::GetModuleIndex(5,1,1);
1278
1279 AliITSRawStream* inputSDD=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader);
1280 for(Int_t iMod=firstSDD; iMod<firstSSD; iMod++){
1281 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)fDetTypeSim->GetCalibrationModel(iMod);
1282 Bool_t isZeroSupp=cal->GetZeroSupp();
1283 if(isZeroSupp){
1284 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,cal->GetZSLowThreshold(iSid));
1285 }else{
1286 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,0);
dee45d79 1287 }
afbc83e9 1288 }
dee45d79 1289
afbc83e9 1290 AliITSDDLModuleMapSDD* ddlmap=fDetTypeSim->GetDDLModuleMapSDD();
1291 inputSDD->SetDDLModuleMap(ddlmap);
1292 while(inputSDD->Next()){
1293 if(inputSDD->IsCompletedModule()==kFALSE &&
1294 inputSDD->IsCompletedDDL()==kFALSE){
1295
1296 Int_t module = inputSDD->GetModuleID();
1297 Int_t anode = inputSDD->GetCoord1()+segSDD->NpzHalf()*inputSDD->GetChannel();
1298 Int_t time = inputSDD->GetCoord2();
1299 Int_t signal10 = inputSDD->GetSignal();
1300 Int_t index = AliITSpList::GetIndex(anode,time,scalef*npx);
1301
1302 if (module >= size) continue;
1303 last = fModA[module]->GetEntries();
1304 TClonesArray& dum = *fModA[module];
1305 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal10));
1306 ((AliITSpListItem*) dum.At(last))->AddSignalAfterElect(module, index, Double_t(signal10));
0b5bf101 1307 }
afbc83e9 1308 }
1309 delete inputSDD;
1310 rawReader->Reset();
a4998655 1311
afbc83e9 1312 //
1313 // SSD
1314 //
1315 AliITSsegmentationSSD* segSSD = (AliITSsegmentationSSD*) fDetTypeSim->GetSegmentationModel(2);
1316 npx = segSSD->Npx();
1317 AliITSRawStreamSSD inputSSD(rawReader);
1318 while(1){
1319 Bool_t next = inputSSD.Next();
1320 if (!next) break;
1321
1322 Int_t module = inputSSD.GetModuleID();
773af0c4 1323 if(module<0)AliError(Form("Invalid SSD module %d \n",module));
1324 if(module<0)continue;
afbc83e9 1325 Int_t side = inputSSD.GetSideFlag();
1326 Int_t strip = inputSSD.GetStrip();
1327 Int_t signal = inputSSD.GetSignal();
1328 Int_t index = npx * side + strip;
1329
1330 if (module >= size) continue;
0b5bf101 1331
afbc83e9 1332 last = fModA[module]->GetEntries();
1333 TClonesArray& dum = *fModA[module];
1334 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal));
1335 }
1336 rawReader->Reset();
1337 AliITSpListItem* sdig = 0;
0b5bf101 1338
afbc83e9 1339 Int_t firstssd = GetITSgeom()->GetStartDet(kSSD);
1340 Double_t adcToEv = 1.;
1341 for (Int_t mod = 0; mod < size; mod++)
1342 {
8b3448d3 1343 if(mod>=firstssd) {
1344 AliITSCalibrationSSD* calssd = (AliITSCalibrationSSD*)fDetTypeSim->GetCalibrationModel(mod);
1345 adcToEv = 1./calssd->GetSSDDEvToADC(1.);
1346 }
afbc83e9 1347 Int_t nsdig = fModA[mod]->GetEntries();
8b3448d3 1348 for (Int_t ie = 0; ie < nsdig; ie++) {
afbc83e9 1349 sdig = (AliITSpListItem*) (fModA[mod]->At(ie));
463ae357 1350 Double_t digsig = sdig->GetSignal();
8b3448d3 1351 if(mod>=firstssd) digsig*=adcToEv; // for SSD: convert back charge from ADC to electron
1352 new (aSDigits[ie]) AliITSpListItem(-1, -1, mod, sdig->GetIndex(), digsig);
afbc83e9 1353 Float_t sig = sdig->GetSignalAfterElect();
1354 if(mod>=firstssd) sig*=adcToEv;
1355 if (sig > 0.) {
1356 sdig = (AliITSpListItem*)aSDigits[ie];
1357 sdig->AddSignalAfterElect(mod, sdig->GetIndex(), Double_t(sig));
0b5bf101 1358 }
afbc83e9 1359 }
0b5bf101 1360
afbc83e9 1361 tree->Fill();
1362 aSDigits.Clear();
1363 fModA[mod]->Clear();
0b5bf101 1364 }
afbc83e9 1365 loader->WriteSDigits("OVERWRITE");
1366 return kTRUE;
0b5bf101 1367}
1368
ef7ff1f9 1369//______________________________________________________________________
1370void AliITS::UpdateInternalGeometry(){
ed9289c8 1371 //reads new geometry from TGeo
012f0f4c 1372// AliDebug(1,"Delete ITSgeom and create a new one reading TGeo");
1373
108bd0fe 1374 AliITSVersion_t version = (AliITSVersion_t)IsVersion();
1375 Int_t minor = 0;
012f0f4c 1376 AliITSInitGeometry initgeom;
1377 AliITSgeom* geom = initgeom.CreateAliITSgeom(version,minor);
ef7ff1f9 1378 SetITSgeom(geom);
ef7ff1f9 1379}
ad7f2bfa 1380//______________________________________________________________________
1381AliTriggerDetector* AliITS::CreateTriggerDetector() const {
1382 // create an AliITSTrigger object (and set trigger conditions as input)
1383 return new AliITSTrigger(fDetTypeSim->GetTriggerConditions());
1384}
662026ab 1385//______________________________________________________________________
1386void AliITS::WriteFOSignals(){
1387// This method write FO signals in Digits tree both in Hits2Digits
1388// or SDigits2Digits
1389
1390 fDetTypeSim->ProcessNoiseForFastOr();
1391 fDetTypeSim->WriteFOSignals();
1392}