Corrected bug, the histogram vector was not cleared properly
[u/mrichter/AliRoot.git] / PHOS / MakePHOSFullMisAlignment.C
CommitLineData
79ba47c3 1void MakePHOSFullMisAlignment()
2{
3 // Create misalignment object for PHOS module 2
4 // from the survey measurements on P2 in May 2008.
5 // To store alignment in OCDB, define the evnironment variables:
6 // TOCDB=kTRUE
7 // STORAGE="local://$ALICE_ROOT"
8 // Author: Timur Pocheptsov, 19.06.2008
9
10 const char * macroName = "MakePHOS2Alignment";
11
3c759505 12 const AliPHOSGeometry *phosGeom = AliPHOSGeometry::GetInstance("IHEP", "IHEP");
13 if (!phosGeom) {
79ba47c3 14 Error(macroName, "Cannot obtain AliPHOSGeometry singleton.\n");
3c759505 15 return;
16 }
17
79ba47c3 18 //Activate CDB storage and load geometry from CDB
19 //I need valid gGeoManager to create local transformations.
20
21 //[Part of code, taken from ITS version of MakexxxFullMisalignment
22 AliCDBManager * cdb = AliCDBManager::Instance();
23 if (!cdb->IsDefaultStorageSet())
24 cdb->SetDefaultStorage("local://$ALICE_ROOT");
25 cdb->SetRun(0);
26
27 if (TString(gSystem->Getenv("TOCDB")) == TString("kTRUE")) {
28 const TString storageENV(gSystem->Getenv("STORAGE"));
29 if (!storageENV.BeginsWith("local://") && !storageENV.BeginsWith("alien://")) {
30 Error(macroName, "STORAGE variable set to %s is not valid.\n", storageENV.Data());
31 return;
32 }
33
34 AliCDBStorage * storage = cdb->GetStorage(storageENV.Data());
35 if (!storage) {
36 Error(macroName, "Unable to open storage %s.\n", storageENV.Data());
37 return;
38 }
39
40 AliCDBPath path("GRP","Geometry","Data");
41 AliCDBEntry * entry = storage->Get(path.GetPath(), cdb->GetRun());
42 if (!entry) {
43 Error(macroName,"Could not get the specified CDB entry!");
44 return;
45 }
46
47 entry->SetOwner(0);
48 AliGeomManager::SetGeometry((TGeoManager*) entry->GetObject());
49 }else{
50 AliGeomManager::LoadGeometry("geometry.root"); //load geom from default CDB storage
51 }
52 //end of code taken from ITS version of MakexxxFullMisalignment]
53
54 AliPHOSEMCAGeometry * emca = phosGeom->GetEMCAGeometry();
55 TClonesArray alobj("AliAlignObjParams", 16);// + phosGeom->GetNModules() * emca->GetNStripX() * emca->GetNStripZ());
1895a097 56
79ba47c3 57 const Double_t dpsi = 0., dtheta = 0., dphi = 0.;
58 const Double_t displacement = 10.;
59 Int_t iIndex = 0; //let all modules have index=0 in a layer with no LUT
60 const AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
61 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer, iIndex);
62 Int_t i = 0;
1895a097 63
64 // Alignment for 5 PHOS modules
79ba47c3 65
90dbf5fb 66 new(alobj[i++]) AliAlignObjParams("PHOS/Module1",
79ba47c3 67 volid, 0., 0., 0., 0., 0., 0., kTRUE);
90dbf5fb 68 new(alobj[i++]) AliAlignObjParams("PHOS/Module2",
414bd085 69 volid, 2., 0., 0., 0., 0., 0., kTRUE);
79ba47c3 70
71 Double_t rotMatrix[9] = {0.999992695, -0.00295322, -0.0024267,
72 0.002955489, 0.999995199, 0.00093165,
73 0.002423942, -0.000938811, 0.99999662};
74 TGeoRotation rotation;
75 rotation.SetMatrix(rotMatrix);
76 Double_t dX=1.25474126, dY=-1.4088643, dZ=-12.856;
77 AliAlignObjParams * mod3 =
78 new(alobj[i++]) AliAlignObjParams("PHOS/Module3", volid, dX, dY, dZ, 0., 0., 0., kFALSE);
79 mod3->SetRotation(rotation);
80
90dbf5fb 81 new(alobj[i++]) AliAlignObjParams("PHOS/Module4",
79ba47c3 82 volid, 0., 0., 0., 0., 0., 0., kTRUE);
90dbf5fb 83 new(alobj[i++]) AliAlignObjParams("PHOS/Module5",
79ba47c3 84 volid, 0., 0., 0., 0., 0., 0., kTRUE);
1895a097 85
79ba47c3 86 const Double_t dx = 0., dy = 0., dz = 0. ;
a45bb6dc 87 // Alignment of CPV modules
90dbf5fb 88 new(alobj[i++]) AliAlignObjParams("PHOS/Module1/CPV",
a45bb6dc 89 volid, dx, dy, dz, dpsi, dtheta, dphi, kTRUE);
90dbf5fb 90 new(alobj[i++]) AliAlignObjParams("PHOS/Module2/CPV",
a45bb6dc 91 volid, dx, dy, dz, dpsi, dtheta, dphi, kTRUE);
90dbf5fb 92 new(alobj[i++]) AliAlignObjParams("PHOS/Module3/CPV",
a45bb6dc 93 volid, dx, dy, dz, dpsi, dtheta, dphi, kTRUE);
90dbf5fb 94 new(alobj[i++]) AliAlignObjParams("PHOS/Module4/CPV",
a45bb6dc 95 volid, dx, dy, dz, dpsi, dtheta, dphi, kTRUE);
90dbf5fb 96 new(alobj[i++]) AliAlignObjParams("PHOS/Module5/CPV",
a45bb6dc 97 volid, dx, dy, dz, dpsi, dtheta, dphi, kTRUE);
98
1895a097 99 // Alignment for PHOS cradle
90dbf5fb 100 new(alobj[i++]) AliAlignObjParams("PHOS/Cradle0",
1895a097 101 volid, 0., 0., -displacement, dpsi, dtheta, dphi, kTRUE);
90dbf5fb 102 new(alobj[i++]) AliAlignObjParams("PHOS/Cradle1",
1895a097 103 volid, 0., 0., +displacement, dpsi, dtheta, dphi, kTRUE);
104
105 // Alignment for cradle wheels
90dbf5fb 106 new(alobj[i++]) AliAlignObjParams("PHOS/Wheel0",
1895a097 107 volid, 0., 0., -displacement, dpsi, dtheta, dphi, kTRUE);
90dbf5fb 108 new(alobj[i++]) AliAlignObjParams("PHOS/Wheel1",
1895a097 109 volid, 0., 0., -displacement, dpsi, dtheta, dphi, kTRUE);
90dbf5fb 110 new(alobj[i++]) AliAlignObjParams("PHOS/Wheel2",
1895a097 111 volid, 0., 0., +displacement, dpsi, dtheta, dphi, kTRUE);
90dbf5fb 112 new(alobj[i++]) AliAlignObjParams("PHOS/Wheel3",
1895a097 113 volid, 0., 0., +displacement, dpsi, dtheta, dphi, kTRUE);
114
115 // ************************* 2nd step ***************
79ba47c3 116 if ( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ) {
1895a097 117 // save on file
79ba47c3 118 const char * fileName = "PHOSfullMisalignment.root";
119 TFile f(fileName,"RECREATE");
120 if (!f) {
121 Error(macroName, "cannot open file for output\n");
dfe9c69d 122 return;
123 }
79ba47c3 124
125 Info(macroName,"Saving alignment objects to the file %s", fileName);
1895a097 126 f.cd();
79ba47c3 127 f.WriteObject(&alobj,"PHOSAlignObjs","kSingleKey");
1895a097 128 f.Close();
129 }else{
130 // save in CDB storage
79ba47c3 131 TString storageENV = gSystem->Getenv("STORAGE");
132 if(!storageENV.BeginsWith("local://") && !storageENV.BeginsWith("alien://")) {
133 Error(macroName,"STORAGE variable set to %s is not valid. Exiting\n", storageENV.Data());
dfe9c69d 134 return;
135 }
79ba47c3 136
137 Info(macroName,"Saving alignment objects in CDB storage %s", storageENV.Data());
138 AliCDBManager * cdb = AliCDBManager::Instance();
139 AliCDBStorage * storage = cdb->GetStorage(storageENV.Data());
140 if (!storage) {
141 Error(macroName, "Unable to open storage %s\n", storageENV.Data());
dfe9c69d 142 return;
143 }
79ba47c3 144
145 AliCDBMetaData md;
146 md.SetResponsible("Timur Pocheptsov");
147 md.SetComment("Alignment objects for PHOS module 2; survey in May 2008");
148 md.SetAliRootVersion(gSystem->Getenv("ARVERSION"));
dfe9c69d 149 AliCDBId id("PHOS/Align/Data",0,AliCDBRunRange::Infinity());
79ba47c3 150 storage->Put(&alobj, id, &md);
1895a097 151 }
152
79ba47c3 153 alobj.Delete();
1895a097 154}