1 /**************************************************************************
2 * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 /* $Id: AliITSUv11.cxx */
20 //========================================================================
22 // Geometry for the Upgrade of the Inner Tracking System
24 // Mario Sitta (sitta@to.infn.it)
26 //========================================================================
30 // $Log: AliITSUv11.cxx,v $
32 #include <TClonesArray.h>
33 #include <TGeoGlobalMagField.h>
34 #include <TGeoManager.h>
35 #include <TGeoMatrix.h>
36 #include <TGeoPhysicalNode.h>
37 #include <TGeoVolume.h>
39 #include <TLorentzVector.h>
41 #include <TVirtualMC.h>
44 #include "AliITSUHit.h"
49 #include "AliTrackReference.h"
50 #include "AliITSv11Geometry.h"
51 #include "AliITSUv11Layer.h"
52 #include "AliITSUv11.h"
53 #include "AliITSUGeomTGeo.h"
54 #include "AliGeomManager.h"
55 using namespace TMath;
60 //______________________________________________________________________
61 AliITSUv11::AliITSUv11()
75 // Standard default constructor
84 //______________________________________________________________________
85 AliITSUv11::AliITSUv11(const char *title,const Int_t nlay)
100 // Standard constructor for the Upgrade geometry.
102 // const char * name Ignored, set to "ITS"
103 // const char * title Arbitrary title
104 // const Int_t nlay Number of layers
106 fLayerName = new TString[fNLayers];
108 for (Int_t j=0; j<fNLayers; j++) fLayerName[j].Form("%s%d",AliITSUGeomTGeo::GetITSSensorPattern(),j); // See AliITSUv11Layer
110 fLayTurbo = new Bool_t[fNLayers];
111 fLayPhi0 = new Double_t[fNLayers];
112 fLayRadii = new Double_t[fNLayers];
113 fLayZLength = new Double_t[fNLayers];
114 fLaddPerLay = new Int_t[fNLayers];
115 fModPerLadd = new Int_t[fNLayers];
116 fLadThick = new Double_t[fNLayers];
117 fLadWidth = new Double_t[fNLayers];
118 fLadTilt = new Double_t[fNLayers];
119 fDetThick = new Double_t[fNLayers];
120 fDetTypeID = new UInt_t[fNLayers];
122 fUpGeom = new AliITSUv11Layer*[fNLayers];
124 if (fNLayers > 0) { // if not, we'll Fatal-ize in CreateGeometry
125 for (Int_t j=0; j<fNLayers; j++) {
139 //______________________________________________________________________
140 AliITSUv11::~AliITSUv11() {
141 // Standard destructor
151 delete [] fLayZLength;
152 delete [] fLaddPerLay;
153 delete [] fModPerLadd;
158 delete [] fDetTypeID;
163 //______________________________________________________________________
164 void AliITSUv11::SetT2Lmatrix(Int_t uid, Double_t yShift,
165 Bool_t yFlip, Bool_t yRot180) const {
168 // Creates the TGeo Local to Tracking transformation matrix
169 // and sends it to the corresponding TGeoPNEntry
171 // This function is used in AddAlignableVolumes()
173 TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntryByUID(uid);
174 TGeoHMatrix* globMatrix = alignableEntry->GetGlobalOrig();
175 Double_t *gtrans = globMatrix->GetTranslation(), rotMatrix[9];
176 memcpy(&rotMatrix[0], globMatrix->GetRotationMatrix(), 9*sizeof(Double_t));
177 Double_t al = ATan2(rotMatrix[1], yRot180 ? -rotMatrix[0] : rotMatrix[0]);
178 Double_t xShift = gtrans[0]*Cos(al)+gtrans[1]*Sin(al);
179 Double_t zShift = -gtrans[2];
180 TGeoHMatrix *matLtoT = new TGeoHMatrix;
181 matLtoT->SetDx( xShift ); // translation
182 matLtoT->SetDy( yShift );
183 matLtoT->SetDz( zShift );
184 rotMatrix[0]= 0; rotMatrix[1]= 1; rotMatrix[2]= 0; // + rotation
185 rotMatrix[3]= 1; rotMatrix[4]= 0; rotMatrix[5]= 0;
186 rotMatrix[6]= 0; rotMatrix[7]= 0; rotMatrix[8]=-1;
187 if (yFlip) rotMatrix[3] = rotMatrix[1] = -1; // flipping in y
189 if (yRot180) { // rotation of pi around the axis perpendicular to the wafer
190 if (yFlip) matLtoT->SetDx( -xShift ); // flipping in y (for SPD1)
191 matLtoT->SetDy( -yShift );
192 matLtoT->SetDz( -zShift );
195 if (yFlip) rotMatrix[3] = 1; // flipping in y (for SPD1)
197 // printf("UID:%d xS:%f ZS:%f\n",uid,xShift,zShift);
198 // globMatrix->Print();
202 rot.SetMatrix(rotMatrix);
203 matLtoT->MultiplyLeft(&rot);
204 TGeoHMatrix *matTtoL = new TGeoHMatrix(matLtoT->Inverse());
206 alignableEntry->SetMatrix(matTtoL);
209 //______________________________________________________________________
210 void AliITSUv11::AddAlignableVolumes() const{
211 // Creates entries for alignable volumes associating the symbolic volume
212 // name with the corresponding volume path.
214 // Records in the alignable entries the transformation matrices converting
215 // TGeo local coordinates (in the RS of alignable volumes) to the tracking
217 // For this, this function has to run before the misalignment because we
218 // are using the ideal positions in the AliITSgeom object.
226 AliInfo("Add ITS alignable volumes");
228 if (!gGeoManager) { AliFatal("TGeoManager doesn't exist !"); return; }
231 pth = Form("ALIC_1/%s_2",AliITSUGeomTGeo::GetITSVolPattern());
232 // RS: to be checked with MS
233 if( !gGeoManager->SetAlignableEntry(AliITSUGeomTGeo::ComposeSymNameITS(),pth.Data()) )
234 AliFatal(Form("Unable to set alignable entry ! %s :: %s","ITS",pth.Data()));
238 for (int lr=0; lr<fNLayers; lr++) {
240 pth = Form("ALIC_1/%s_2/%s%d_1",AliITSUGeomTGeo::GetITSVolPattern(),AliITSUGeomTGeo::GetITSLayerPattern(),lr);
241 //printf("SetAlignable: %s %s\n",snm.Data(),pth.Data());
242 gGeoManager->SetAlignableEntry(AliITSUGeomTGeo::ComposeSymNameLayer(lr),pth.Data());
244 for (int ld=0; ld<fLaddPerLay[lr]; ld++) {
246 TString pthL = Form("%s/%s%d_%d",pth.Data(),AliITSUGeomTGeo::GetITSLadderPattern(),lr,ld);
247 //printf("SetAlignable: %s %s\n",snmL.Data(),pthL.Data());
248 gGeoManager->SetAlignableEntry(AliITSUGeomTGeo::ComposeSymNameLadder(lr,ld),pthL.Data());
250 for (int md=0; md<fModPerLadd[lr]; md++) {
252 TString pthM = Form("%s/%s%d_%d",pthL.Data(),AliITSUGeomTGeo::GetITSModulePattern(),lr,md);
254 // RS: Attention, this is a hack: AliGeomManager cannot accomodate all ITSU modules w/o
255 // conflicts with TPC. For this reason we define the UID of the module to be simply its ID
256 // int modUID = AliGeomManager::LayerToVolUID(lr+1,modNum++); // here modNum would be module within the layer
257 int modUID = AliITSUGeomTGeo::ModuleVolUID( modNum++ );
259 gGeoManager->SetAlignableEntry(AliITSUGeomTGeo::ComposeSymNameModule(lr,ld,md),pthM.Data(),modUID);
261 double yshift = -(fUpGeom[lr]->GetSensorThick()-fUpGeom[lr]->GetLadderThick())/2;
262 // SetT2Lmatrix(modUID,yshift, kTRUE,kTRUE); // RS: do we need here special matrix, ask MS
263 // SetT2Lmatrix(modUID,yshift, kTRUE,kFALSE); // RS: do we need here special matrix, ask MS
265 // RS: to clarify: in order to get reasonable tracking frame X,phi with STANDARD SetT2Lmatrix
266 // the yRot180 must be true.
267 SetT2Lmatrix(modUID,yshift, kTRUE,kTRUE); // RS: do we need here special matrix, ask MS
275 //______________________________________________________________________
276 void AliITSUv11::CreateGeometry() {
278 // Create the geometry and insert it in the mother volume ITSV
279 TGeoManager *geoManager = gGeoManager;
281 TGeoVolume *vALIC = geoManager->GetVolume("ALIC");
283 new TGeoVolumeAssembly(AliITSUGeomTGeo::GetITSVolPattern());
284 TGeoVolume *vITSV = geoManager->GetVolume(AliITSUGeomTGeo::GetITSVolPattern());
285 vALIC->AddNode(vITSV, 2, 0); // Copy number is 2 to cheat AliGeoManager::CheckSymNamesLUT
288 const Int_t kLength=100;
289 Char_t vstrng[kLength] = "xxxRS"; //?
290 vITSV->SetTitle(vstrng);
292 // Check that we have all needed parameters
293 if (fNLayers <= 0) AliFatal(Form("Wrong number of layers (%d)",fNLayers));
295 for (Int_t j=0; j<fNLayers; j++) {
296 if (fLayRadii[j] <= 0) AliFatal(Form("Wrong layer radius for layer %d (%f)",j,fLayRadii[j]));
297 if (fLayZLength[j] <= 0) AliFatal(Form("Wrong layer length for layer %d (%f)",j,fLayZLength[j]));
298 if (fLaddPerLay[j] <= 0) AliFatal(Form("Wrong number of ladders for layer %d (%d)",j,fLaddPerLay[j]));
299 if (fModPerLadd[j] <= 0) AliFatal(Form("Wrong number of modules for layer %d (%d)",j,fModPerLadd[j]));
300 if (fLadThick[j] < 0) AliFatal(Form("Wrong ladder thickness for layer %d (%f)",j,fLadThick[j]));
301 if (fLayTurbo[j] && fLadWidth[j] <= 0) AliFatal(Form("Wrong ladder width for layer %d (%f)",j,fLadWidth[j]));
302 if (fDetThick[j] < 0) AliFatal(Form("Wrong module thickness for layer %d (%f)",j,fDetThick[j]));
305 if (fLayRadii[j]<=fLayRadii[j-1]) AliFatal(Form("Layer %d radius (%f) is smaller than layer %d radius (%f)",
306 j,fLayRadii[j],j-1,fLayRadii[j-1]));
309 if (fLadThick[j] == 0) AliInfo(Form("Ladder thickness for layer %d not set, using default",j));
310 if (fDetThick[j] == 0) AliInfo(Form("Module thickness for layer %d not set, using default",j));
312 } // for (Int_t j=0; j<fNLayers; j++)
314 // Now create the actual geometry
315 for (Int_t j=0; j<fNLayers; j++) {
317 fUpGeom[j] = new AliITSUv11Layer(j,kTRUE,kFALSE);
318 fUpGeom[j]->SetLadderWidth(fLadWidth[j]);
319 fUpGeom[j]->SetLadderTilt(fLadTilt[j]);
321 else fUpGeom[j] = new AliITSUv11Layer(j,kFALSE);
323 fUpGeom[j]->SetPhi0(fLayPhi0[j]);
324 fUpGeom[j]->SetRadius(fLayRadii[j]);
325 fUpGeom[j]->SetZLength(fLayZLength[j]);
326 fUpGeom[j]->SetNLadders(fLaddPerLay[j]);
327 fUpGeom[j]->SetNModules(fModPerLadd[j]);
328 fUpGeom[j]->SetDetType(fDetTypeID[j]);
330 if (fLadThick[j] != 0) fUpGeom[j]->SetLadderThick(fLadThick[j]);
331 if (fDetThick[j] != 0) fUpGeom[j]->SetSensorThick(fDetThick[j]);
332 fUpGeom[j]->CreateLayer(vITSV);
337 //______________________________________________________________________
338 void AliITSUv11::CreateMaterials() {
339 // Create ITS materials
340 // This function defines the default materials used in the Geant
341 // Monte Carlo simulations for the geometries AliITSv1, AliITSv3,
343 // In general it is automatically replaced by
344 // the CreateMaterials routine defined in AliITSv?. Should the function
345 // CreateMaterials not exist for the geometry version you are using this
346 // one is used. See the definition found in AliITSv5 or the other routine
347 // for a complete definition.
355 Int_t ifield = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Integ();
356 Float_t fieldm = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Max();
358 Float_t tmaxfd = 0.1; // 1.0; // Degree
359 Float_t stemax = 1.0; // cm
360 Float_t deemax = 0.1; // 30.0; // Fraction of particle's energy 0<deemax<=1
361 Float_t epsil = 1.0E-4; // 1.0; // cm
362 Float_t stmin = 0.0; // cm "Default value used"
364 Float_t tmaxfdSi = 0.1; // .10000E+01; // Degree
365 Float_t stemaxSi = 0.0075; // .10000E+01; // cm
366 Float_t deemaxSi = 0.1; // 0.30000E-02; // Fraction of particle's energy 0<deemax<=1
367 Float_t epsilSi = 1.0E-4;// .10000E+01;
368 Float_t stminSi = 0.0; // cm "Default value used"
370 Float_t tmaxfdAir = 0.1; // .10000E+01; // Degree
371 Float_t stemaxAir = .10000E+01; // cm
372 Float_t deemaxAir = 0.1; // 0.30000E-02; // Fraction of particle's energy 0<deemax<=1
373 Float_t epsilAir = 1.0E-4;// .10000E+01;
374 Float_t stminAir = 0.0; // cm "Default value used"
377 Float_t aAir[4]={12.0107,14.0067,15.9994,39.948};
378 Float_t zAir[4]={6.,7.,8.,18.};
379 Float_t wAir[4]={0.000124,0.755267,0.231781,0.012827};
380 Float_t dAir = 1.20479E-3;
383 AliMaterial(1,"SI$",0.28086E+02,0.14000E+02,0.23300E+01,0.93600E+01,0.99900E+03);
384 AliMedium(1,"SI$",1,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,epsilSi,stminSi);
386 AliMixture(5,"AIR$",aAir,zAir,dAir,4,wAir);
387 AliMedium(5,"AIR$",5,0,ifield,fieldm,tmaxfdAir,stemaxAir,deemaxAir,epsilAir,stminAir);
389 AliMaterial(8,"BERILLIUM$",9.01, 4., 1.848, 35.3, 36.7);// From AliPIPEv3
390 AliMedium(8,"BERILLIUM$",8,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
394 //______________________________________________________________________
395 void AliITSUv11::DefineLayer(const Int_t nlay, const double phi0, const Double_t r,
396 const Double_t zlen, const Int_t nladd,
397 const Int_t nmod, const Double_t lthick,
398 const Double_t dthick, const UInt_t dettypeID)
400 // Sets the layer parameters
406 // nladd number of ladders
407 // nmod number of modules per ladder
408 // lthick ladder thickness (if omitted, defaults to 0)
409 // dthick detector thickness (if omitted, defaults to 0)
415 if (nlay >= fNLayers || nlay < 0) {
416 AliError(Form("Wrong layer number (%d)",nlay));
420 fLayTurbo[nlay] = kFALSE;
421 fLayPhi0[nlay] = phi0;
423 fLayZLength[nlay] = zlen;
424 fLaddPerLay[nlay] = nladd;
425 fModPerLadd[nlay] = nmod;
426 fLadThick[nlay] = lthick;
427 fDetThick[nlay] = dthick;
428 fDetTypeID[nlay] = dettypeID;
432 //______________________________________________________________________
433 void AliITSUv11::DefineLayerTurbo(Int_t nlay, Double_t phi0, Double_t r, Double_t zlen, Int_t nladd,
434 Int_t nmod, Double_t width, Double_t tilt,
435 Double_t lthick,Double_t dthick,
438 // Sets the layer parameters for a "turbo" layer
439 // (i.e. a layer whose ladders overlap in phi)
442 // phi0 phi of 1st ladder
445 // nladd number of ladders
446 // nmod number of modules per ladder
447 // width ladder width
448 // tilt layer tilt angle (degrees)
449 // lthick ladder thickness (if omitted, defaults to 0)
450 // dthick detector thickness (if omitted, defaults to 0)
456 if (nlay >= fNLayers || nlay < 0) {
457 AliError(Form("Wrong layer number (%d)",nlay));
461 fLayTurbo[nlay] = kTRUE;
462 fLayPhi0[nlay] = phi0;
464 fLayZLength[nlay] = zlen;
465 fLaddPerLay[nlay] = nladd;
466 fModPerLadd[nlay] = nmod;
467 fLadThick[nlay] = lthick;
468 fLadWidth[nlay] = width;
469 fLadTilt[nlay] = tilt;
470 fDetThick[nlay] = dthick;
471 fDetTypeID[nlay] = dettypeID;
475 //______________________________________________________________________
476 void AliITSUv11::GetLayerParameters(Int_t nlay, Double_t &phi0,
477 Double_t &r, Double_t &zlen,
478 Int_t &nladd, Int_t &nmod,
479 Double_t &width, Double_t &tilt,
480 Double_t <hick, Double_t &dthick) const
482 // Gets the layer parameters
486 // phi0 phi of 1st ladder
489 // nladd number of ladders
490 // nmod number of modules per ladder
491 // width ladder width
492 // tilt ladder tilt angle
493 // lthick ladder thickness
494 // dthick detector thickness
498 if (nlay >= fNLayers || nlay < 0) {
499 AliError(Form("Wrong layer number (%d)",nlay));
503 phi0 = fLayPhi0[nlay];
505 zlen = fLayZLength[nlay];
506 nladd = fLaddPerLay[nlay];
507 nmod = fModPerLadd[nlay];
508 width = fLadWidth[nlay];
509 tilt = fLadTilt[nlay];
510 lthick = fLadThick[nlay];
511 dthick = fDetThick[nlay];
514 //______________________________________________________________________
515 void AliITSUv11::Init()
517 // Initialise the ITS after it has been created.
518 UpdateInternalGeometry();
523 //______________________________________________________________________
524 Bool_t AliITSUv11::IsLayerTurbo(Int_t nlay)
526 // Returns true if the layer is a "turbo" layer
527 if ( nlay < 0 || nlay > fNLayers ) {
528 AliError(Form("Wrong layer number %d",nlay));
531 else return fUpGeom[nlay]->IsTurbo();
534 //______________________________________________________________________
535 void AliITSUv11::SetDefaults()
537 // sets the default segmentation, response, digit and raw cluster classes
540 //______________________________________________________________________
541 void AliITSUv11::StepManager()
543 // Called for every step in the ITS, then calles the AliITSUHit class
544 // creator with the information to be recoreded about that hit.
545 // The value of the macro ALIITSPRINTGEOM if set to 1 will allow the
546 // printing of information to a file which can be used to create a .det
547 // file read in by the routine CreateGeometry(). If set to 0 or any other
548 // value except 1, the default behavior, then no such file is created nor
549 // it the extra variables and the like used in the printing allocated.
556 if(!(this->IsActive())) return;
557 if(!(gMC->TrackCharge())) return;
560 Int_t id = gMC->CurrentVolID(copy);
562 Bool_t notSens = kFALSE;
563 while ((lay<fNLayers) && (notSens = (id!=fIdSens[lay]))) ++lay;
564 //printf("R: %.1f | Lay: %d NotSens: %d\n",positionRS.Pt(), lay, notSens);
568 if(gMC->IsTrackExiting()) {
569 AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber(), AliTrackReference::kITS);
570 } // if Outer ITS mother Volume
572 static TLorentzVector position, momentum; // Saves on calls to construtors
573 static AliITSUHit hit;// Saves on calls to constructors
575 TClonesArray &lhits = *(Hits());
576 Int_t cpn0, cpn1, mod, status = 0;
579 if(gMC->IsTrackInside()) status += 1;
580 if(gMC->IsTrackEntering()) status += 2;
581 if(gMC->IsTrackExiting()) status += 4;
582 if(gMC->IsTrackOut()) status += 8;
583 if(gMC->IsTrackDisappeared()) status += 16;
584 if(gMC->IsTrackStop()) status += 32;
585 if(gMC->IsTrackAlive()) status += 64;
588 // retrieve the indices with the volume path
590 if (lay < 0 || lay >= fNLayers) {
591 AliError(Form("Invalid value: lay=%d. Not an ITS sensitive volume",lay));
592 return; // not an ITS sensitive volume.
595 gMC->CurrentVolOffID(1,cpn1);
596 gMC->CurrentVolOffID(2,cpn0);
599 mod = fGeomTGeo->GetModuleIndex(lay,cpn0,cpn1);
600 //RS2DEL fInitGeom.DecodeDetector(mod,lay+1,cpn0,cpn1,copy);
602 // Fill hit structure.
605 hit.SetTrack(gAlice->GetMCApp()->GetCurrentTrackNumber());
606 gMC->TrackPosition(position);
607 gMC->TrackMomentum(momentum);
608 hit.SetPosition(position);
609 hit.SetTime(gMC->TrackTime());
610 hit.SetMomentum(momentum);
611 hit.SetStatus(status);
612 hit.SetEdep(gMC->Edep());
613 hit.SetShunt(GetIshunt());
614 if(gMC->IsTrackEntering()){
615 hit.SetStartPosition(position);
616 hit.SetStartTime(gMC->TrackTime());
617 hit.SetStartStatus(status);
618 return; // don't save entering hit.
619 } // end if IsEntering
620 // Fill hit structure with this new hit.
621 //Info("StepManager","Calling Copy Constructor");
622 new(lhits[fNhits++]) AliITSUHit(hit); // Use Copy Construtor.
623 // Save old position... for next hit.
624 hit.SetStartPosition(position);
625 hit.SetStartTime(gMC->TrackTime());
626 hit.SetStartStatus(status);
631 //______________________________________________________________________
632 void AliITSUv11::SetLayerDetTypeID(Int_t lr, UInt_t id)
635 if (!fDetTypeID || fNLayers<=lr) AliFatal(Form("Number of layers %d, %d is manipulated",fNLayers,lr));
639 //______________________________________________________________________
640 Int_t AliITSUv11::GetLayerDetTypeID(Int_t lr)
643 if (!fDetTypeID || fNLayers<=lr) AliFatal(Form("Number of layers %d, %d is manipulated",fNLayers,lr));
644 return fDetTypeID[lr];