]> git.uio.no Git - u/mrichter/AliRoot.git/blob - GRP/MakePipeMisalignment.C
START_TIME updated to May 04 2014, 21:02:30 GMT
[u/mrichter/AliRoot.git] / GRP / MakePipeMisalignment.C
1
2 void MakePipeMisalignment(Int_t inputRun=0,
3                           const char* ocdbPath="local://$ALICE_ROOT/OCDB",
4                           Bool_t verbose=true, 
5                           const char* outFileName=0)
6 {
7   // Creates misalignment of the beam pipe, frame and FMD2&3.
8   // 
9   // The misalignment is based on the ITS global alignment object with
10   // the exception of the beam pipe where only the translations are
11   // used ignoring the rotation matrix.
12   AliCDBManager* cdb = AliCDBManager::Instance();
13   cdb->SetDefaultStorage("alien://Folder=/alice/data/2010/OCDB");
14   cdb->SetRun(inputRun);
15
16
17   // Get the geometry 
18   AliGeomManager::LoadGeometry();
19
20   // Get ITS alignment 
21   AliCDBEntry* itsEntry = cdb->Get("ITS/Align/Data");
22   if (!itsEntry) { 
23     Error("MakePipeMisalignment", "Couldn't get ITS alignment data");
24     return;
25   } 
26   TClonesArray* itsArray = static_cast<TClonesArray*>(itsEntry->GetObject());
27   if (!itsArray) { 
28     Error("MakePipeMisalignment", "No array in CDB entry");
29     return;
30   }
31   AliAlignObjParams* itsAlign = 
32     static_cast<AliAlignObjParams*>(itsArray->At(0));
33   if (!itsAlign) { 
34     Error("MakePipeMisalignment", "No alignment object in CDB entry");
35     return;
36   }
37   
38   if (verbose) {
39     Info("MakePipeMisalignment", "ITS alignment:");
40     itsAlign->Print();
41   }
42
43   Double_t itsTrans[3];
44   Double_t itsRot[3];
45   itsAlign->GetTranslation(itsTrans);
46   itsAlign->GetAngles(itsRot);
47
48   Double_t local[] = { 0, 0, 0 };
49
50   if (!gGeoManager->cd("/ALIC_1/CP_1/Cp1_1/CpSupC_1")) return;
51   Double_t pCpSupCA[3];
52   gGeoManager->LocalToMaster(local, pCpSupCA);
53
54   if (!gGeoManager->cd("/ALIC_1/CP_1/Cp3_1/CpSupC_3")) return;
55   Double_t pCpSupCC[3];
56   gGeoManager->LocalToMaster(local, pCpSupCC);
57
58   if (!gGeoManager->cd("/ALIC_1/CP_1/Cp1_1")) return;
59   Double_t pCp1[3];
60   gGeoManager->LocalToMaster(local, pCp1);
61
62   if (!gGeoManager->cd("/ALIC_1/CP_1/Cp1_1/CP1MO_1/CP1AT_1")) return;
63   do { 
64     TGeoNode* node = gGeoManager->GetCurrentNode();
65     if (!node) break;
66     TGeoVolume* volume = node->GetVolume();
67     if (!volume) break;
68     TGeoBBox* bbox = static_cast<TGeoBBox*>(volume->GetShape());
69     if (!bbox) break;
70     local[2] = -bbox->GetDZ();
71   } while (false);
72   if (local[2] == 0) { 
73     Error("MakePipeMisalignement", "Failed to find end of CP1 section");
74     return;
75   }
76   Double_t pCP1AT[3];
77   gGeoManager->LocalToMaster(local, pCP1AT);
78
79
80   
81   // Now, we need to misalign the C-side collar according to the ITS
82   // misalignment. 
83   TGeoHMatrix* itsMat = new TGeoHMatrix();
84   itsAlign->GetMatrix(*itsMat);
85   // itsTrans[2] = 0;
86   // itsMat->SetTranslation(itsTrans);
87   Double_t tCpSupCA[3];
88   itsMat->LocalToMaster(pCpSupCA, tCpSupCA);
89   Double_t tCpSupCC[3];
90   itsMat->LocalToMaster(pCpSupCC, tCpSupCC);
91
92   Info("MakePipeMisalignment", "\n"
93        "\tCollar A-side       (%f,%f,%f)\n" 
94        "\tCollar C-side       (%f,%f,%f)\n"
95        "\tBeam pipe center    (%f,%f,%f)\n"
96        "\tEnd of CP1 A-side   (%f,%f,%f)\n"
97        "\tCollar A-side after (%f,%f,%f)\n" 
98        "\tCollar C-side after (%f,%f,%f)", 
99        pCpSupCA[0], pCpSupCA[1], pCpSupCA[2],
100        pCpSupCC[0], pCpSupCC[1], pCpSupCC[2],
101        pCp1[0],     pCp1[1],     pCp1[2],
102        pCP1AT[0],   pCP1AT[1],   pCP1AT[2],
103        tCpSupCA[0], tCpSupCA[1], tCpSupCA[2],
104        tCpSupCC[0], tCpSupCC[1], tCpSupCC[2]);
105   
106   // Distance from A-side end to mis-aligned C-side Collar
107   Double_t dX = - tCpSupCC[0] + pCP1AT[0] ;
108   Double_t dY = - tCpSupCC[1] + pCP1AT[1] ;
109   Double_t dZ = - tCpSupCC[2] + pCP1AT[2] ;
110   
111   // Rotation angle around X and Y
112   Double_t rotX = TMath::ATan2(dY, dZ);
113   Double_t rotY = TMath::ATan2(dX, dZ);
114
115   
116   Double_t dZc = pCp1[2] - pCP1AT[2];
117   Double_t dXc = TMath::Tan(rotY) * dZc;
118   Double_t dYc = TMath::Tan(rotX) * dZc;
119
120
121   Double_t dZt = pCpSupCC[2] - pCP1AT[2] + itsTrans[2];
122
123   Info("MakePipeMisalignment", "\n"       
124        "\tDistances (%f,%f,%f)\n" 
125        "\trotX=%f rotY=%f\n" 
126        "\tCP1     displacement (x,y)=(%f,%f) dZ=%f\n"
127        "\tCpSubCA displacement (x,y)=(%f,%f) dZ=%f",
128        dX, dY, dZ,
129        rotX * TMath::RadToDeg(), rotY * TMath::RadToDeg(),
130        dXc, dYc, dZc,
131        TMath::Tan(rotY)*dZt, TMath::Tan(rotX)*dZt, dZt);
132
133
134   TGeoRotation* rot = new TGeoRotation();
135   rot->RotateX(rotX*TMath::RadToDeg());
136   rot->RotateY(rotY*TMath::RadToDeg());
137   TGeoCombiTrans* trans = new TGeoCombiTrans(dXc, dYc, 0, rot);
138   trans->Print();
139
140   // Output array 
141   TClonesArray* structArray = new TClonesArray("AliAlignObjParams", 20);
142
143   //dummy vol id
144   UShort_t dvoluid = 
145     AliGeomManager::LayerToVolUID(AliGeomManager::kInvalidLayer,0); 
146
147   //base of symbolic name corresponding to base of path "ALIC_1/B077_1/BSEGMO";
148   const char* baseSymName = "FRAME/Sector"; 
149   for(Int_t sm=0; sm<18; sm++){
150     TString symname =  baseSymName;
151     symname         += sm;
152     new((*structArray)[sm]) AliAlignObjParams(symname.Data(),dvoluid,
153                                              0.,0.,0.,0.,0.,0.,kTRUE);
154   }
155    
156   // --- Beam pipe ---------------------------------------------------
157   AliAlignObjParams* c1Align = 
158     new((*structArray)[18]) AliAlignObjParams("CP1",dvoluid,
159                                               dXc, dYc, 0, rotX, rotY, 0,kTRUE);
160   c1Align->Print();
161
162   // --- C side Collar -----------------------------------------------
163   AliAlignObjParams* cSupCAlign = 
164     new((*structArray)[19]) AliAlignObjParams("CPSUPC",
165                                               dvoluid, 
166                                               tCpSupCC[0]-pCpSupCC[0], 
167                                               tCpSupCC[1]-pCpSupCC[1], 
168                                               tCpSupCC[2]-pCpSupCC[2], 
169                                               0, 0, 0, kTRUE);
170   cSupCAlign->Print();
171   
172   // --- save in CDB storage -----------------------------------------
173   Info("MakeForwardMisAlignment",
174        "Saving alignment objects in CDB storage %s", ocdbPath);
175   AliCDBStorage* storage = cdb->GetStorage(ocdbPath);
176   if (!storage){
177     Error("MakeForwardMisAlignment","Unable to open storage %s\n",ocdbPath);
178     return;
179   }
180
181
182   // --- Make objects and store --------------------------------------
183   AliCDBMetaData* md = new AliCDBMetaData();
184   md->SetResponsible("Grosso Raffaele");
185   md->SetComment("Misalignment for FRAME and beam pipe");
186   md->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
187   AliCDBId id("GRP/Align/Data",0,AliCDBRunRange::Infinity());
188   storage->Put(structArray,id,md);
189
190   gGeoManager->Export("myGeom.root");
191 }