]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/MakeTOFFullMisAlignment.C
DAs optimize flag
[u/mrichter/AliRoot.git] / TOF / MakeTOFFullMisAlignment.C
CommitLineData
4d6eaa95 1void MakeTOFFullMisAlignment() {
2 //
1895a097 3 // Create TClonesArray of full misalignment objects for TOF
6fce62af 4 // Expects to read objects for FRAME
1895a097 5 //
4d6eaa95 6
6fce62af 7 const char* macroname = "MakeTOFFullMisAlignment.C";
4d6eaa95 8
9 TClonesArray *array = new TClonesArray("AliAlignObjParams",2000);
6fce62af 10
11 // Activate CDB storage and load geometry from CDB
12 AliCDBManager* cdb = AliCDBManager::Instance();
4d6eaa95 13 if (!cdb->IsDefaultStorageSet())
14 cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
6fce62af 15 cdb->SetRun(0);
4d6eaa95 16
6fce62af 17 AliCDBStorage* storage;
a24be56b 18 TString Storage;
4d6eaa95 19
20 if ( TString(gSystem->Getenv("TOCDB")) == TString("kTRUE") ) {
a24be56b 21 Storage = gSystem->Getenv("STORAGE");
4d6eaa95 22 if (!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) {
6fce62af 23 Error(macroname,"STORAGE variable set to %s is not valid. Exiting\n",Storage.Data());
24 return;
25 }
26 storage = cdb->GetStorage(Storage.Data());
4d6eaa95 27 if (!storage) {
6fce62af 28 Error(macroname,"Unable to open storage %s\n",Storage.Data());
29 return;
30 }
31 AliCDBPath path("GRP","Geometry","Data");
32 AliCDBEntry *entry = storage->Get(path.GetPath(),cdb->GetRun());
4d6eaa95 33 if (!entry)
34 Fatal(macroname,"Could not get the specified CDB entry!");
6fce62af 35 entry->SetOwner(0);
36 TGeoManager* geom = (TGeoManager*) entry->GetObject();
37 AliGeomManager::SetGeometry(geom);
4d6eaa95 38 } else
6fce62af 39 AliGeomManager::LoadGeometry(); //load geom from default CDB storage
4d6eaa95 40
6fce62af 41 // load FRAME full misalignment objects (if needed, the macro
42 // for FRAME has to be run in advance) and apply them to geometry
6fce62af 43 AliCDBPath fpath("GRP","Align","Data");
4d6eaa95 44 if ( TString(gSystem->Getenv("TOCDB")) == TString("kTRUE") ) {
a24be56b 45 Info(macroname,"Loading FRAME alignment objects from CDB storage %s",
4d6eaa95 46 Storage.Data());
6fce62af 47 AliCDBEntry *eFrame = storage->Get(fpath.GetPath(),cdb->GetRun());
4d6eaa95 48 } else
6fce62af 49 AliCDBEntry *eFrame = cdb->Get(fpath.GetPath());
4d6eaa95 50
51 if (!eFrame)
52 Fatal(macroname,"Could not get the specified CDB entry!");
53
a24be56b 54 TClonesArray* arFrame = (TClonesArray*) eFrame->GetObject();
55 arFrame->Sort();
56 Int_t nvols = arFrame->GetEntriesFast();
57 Bool_t flag = kTRUE;
58 for(Int_t j=0; j<nvols; j++)
59 {
60 AliAlignObj* alobj = (AliAlignObj*) arFrame->UncheckedAt(j);
61 if (alobj->ApplyToGeometry() == kFALSE) flag = kFALSE;
62 }
4d6eaa95 63 if (!flag)
64 Fatal(macroname,"Error in the application of FRAME alignment objects");
1895a097 65
6fce62af 66 //Produce objects for TOF supermodules
1895a097 67 Int_t iIndex=0; //let all modules have index=0 in a layer with no LUT
ae079791 68 AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
69 UShort_t dvoluid = AliGeomManager::LayerToVolUID(iLayer,iIndex); //dummy vol id
d3a9c52a 70
d3a9c52a 71 Int_t nSMTOF = 18;
6fce62af 72 Int_t j=0;
a24be56b 73 Double_t smdx, smdy, smdz=0., dpsi=0., dtheta, dphi=0.;
1895a097 74 TRandom *rnd = new TRandom(2345);
75 Double_t sigmatr = 0.4; // max shift in cm w.r.t. local ideal RS
76 Double_t sigmarot = 0.06; // max rot in deg w.r.t. local ideal RS (~ 1 mrad)
d3a9c52a 77
4d6eaa95 78 for (Int_t isect=0; isect<nSMTOF; isect++) {
85ce4b22 79 TString symname(Form("TOF/sm%02d",isect));
6fce62af 80 smdx = rnd->Gaus(0.,sigmatr);
81 smdy = rnd->Gaus(0.,sigmatr);
1895a097 82 dtheta = rnd->Gaus(0.,sigmarot);
4d6eaa95 83 new((*array)[j++]) AliAlignObjParams(symname.Data(),
84 dvoluid,
85 smdx, smdy, smdz, dpsi, dtheta, dphi, kFALSE);
d3a9c52a 86 }
6fce62af 87 // Apply objects for TOF supermodules
a24be56b 88 Int_t smCounter=0;
4d6eaa95 89 for (Int_t isect=0; isect<nSMTOF; isect++) {
a24be56b 90 AliAlignObjParams* smobj = (AliAlignObjParams*)array->UncheckedAt(smCounter++);
4d6eaa95 91 //Info(macroname,Form("Applying object for sector %d ",isect));
92 if ( !smobj->ApplyToGeometry() )
85ce4b22 93 Fatal(macroname,Form("application of full misalignment object for sector %d failed!",isect));
4d6eaa95 94
d3a9c52a 95 }
d3a9c52a 96
6fce62af 97 //Produce objects for TOF strips (same sigmas as for residual misalignment)
ae079791 98 AliGeomManager::ELayerID idTOF = AliGeomManager::kTOF;
a24be56b 99 Int_t strId=-1;
d3a9c52a 100
a24be56b 101 Double_t sdx=0., sdy=0., sdz=0., sdpsi=0., sdtheta=0., sdphi=0.;
6ca978d7 102 //TRandom *rnds = new TRandom(4357);
d3a9c52a 103 sigmatr = 0.1; // max shift in cm w.r.t. local ideal RS
104
a24be56b 105 Int_t nstrA=15;
106 Int_t nstrB=19;
107 Int_t nstrC=19;
108 Int_t nSectors=18;
109 Int_t nStrips=nstrA+2*nstrB+2*nstrC;
6876838b 110 Double_t cuty=0., cutz=0., cut=3*sigmatr;
a24be56b 111
85ce4b22 112 for (Int_t isect = 0; isect < nSectors; isect++) {
a24be56b 113 for (Int_t istr = 1; istr <= nStrips; istr++) {
6876838b 114 switch (istr) {
115 case 25:
116 case 29:
117 case 63:
118 case 67:
119 cuty = sigmatr*0.6;
6ca978d7 120 sdy = AliMathBase::TruncatedGaus(0., sigmatr, cut, cuty);
6876838b 121 sdz = AliMathBase::TruncatedGaus(0., sigmatr, cut);
122 strId++;
123 break;
124 /*
125 case 38:
126 cuty = sigmatr*2.5;
127 cutz = sigmatr*2.5;
6ca978d7 128 sdy = AliMathBase::TruncatedGaus(0., sigmatr, cut, cuty);
129 sdz = AliMathBase::TruncatedGaus(0., sigmatr, cut, cutz);
6876838b 130 strId++;
131 break;
132 case 54:
133 cuty = sigmatr*2.5;
134 cutz = sigmatr*2.5;
6ca978d7 135 sdy = AliMathBase::TruncatedGaus(0., sigmatr, cut, cuty);
136 sdz = AliMathBase::TruncatedGaus(0., sigmatr, cutz, cut);
6876838b 137 strId++;
138 break;
139 */
140 default:
141 sdy = AliMathBase::TruncatedGaus(0., sigmatr, cut);
142 sdz = AliMathBase::TruncatedGaus(0., sigmatr, cut);
143 strId++;
144 break;
145 }
146
85ce4b22 147 if ((isect==13 || isect==14 || isect==15) && (istr >= 39 && istr <= 53)) continue;
4d6eaa95 148 new((*array)[j++]) AliAlignObjParams(AliGeomManager::SymName(idTOF,strId),
149 AliGeomManager::LayerToVolUID(idTOF,strId),
150 sdx, sdy, sdz, sdpsi, sdtheta, sdphi, kFALSE);
a24be56b 151 }
1895a097 152 }
153
4d6eaa95 154 if ( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ) {
6fce62af 155 // save in file
dfe9c69d 156 const char* filename = "TOFfullMisalignment.root";
157 TFile f(filename,"RECREATE");
158 if(!f){
159 Error(macroname,"cannot open file for output\n");
160 return;
161 }
6fce62af 162 Info(macroname,"Saving alignment objects in file %s", filename);
1895a097 163 f.cd();
164 f.WriteObject(array,"TOFAlignObjs","kSingleKey");
165 f.Close();
4d6eaa95 166 } else {
1895a097 167 // save in CDB storage
dfe9c69d 168 Info(macroname,"Saving alignment objects in CDB storage %s",
169 Storage.Data());
1895a097 170 AliCDBMetaData* md = new AliCDBMetaData();
171 md->SetResponsible("Silvia Arcelli");
6fce62af 172 md->SetComment("Full misalignment for TOF");
5bd470e1 173 md->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
dfe9c69d 174 AliCDBId id("TOF/Align/Data",0,AliCDBRunRange::Infinity());
1895a097 175 storage->Put(array,id,md);
176 }
177
178 array->Delete();
179
180}
181
6ca978d7 182/*
6876838b 183Double_t LocalTruncatedGaus(Double_t mean, Double_t sigma, Double_t cutatL, Double_t cutatR)
184{
185 // return number generated according to a gaussian distribution N(mean,sigma) truncated at cutat
186 //
187 Double_t value;
188 do{
189 value=gRandom->Gaus(mean,sigma);
190 }while(value-mean<-cutatL || value-mean>cutatR);
191 return value;
192}
6ca978d7 193*/