2 // $MpId: testSegmentation.C,v 1.1 2005/09/19 19:02:53 ivana Exp $
8 #include "AliMUONChamber.h"
9 #include "AliMUONGeometrySegmentation.h"
10 #include "AliMUONVGeometryDESegmentation.h"
11 #include "AliMpPlaneType.h"
12 #include "AliMUONSt345SlatSegmentationV2.h"
13 //#include "AliMpSt345Reader.h"
14 #include "AliMpSegmentationManager.h"
15 #include "AliMpSlat.h"
24 std::map<int,std::string> detElemIdToSlatTypeMap;
26 //_____________________________________________________________________________
27 bool equal(double a, double b, double epsilon=1e-5)
29 double d = fabs(a-b)/b;
30 if ( d < epsilon ) return true;
34 //_____________________________________________________________________________
35 bool error(const char* msg)
37 std::cout << msg << std::endl;
41 //_____________________________________________________________________________
42 bool readDetElemIdToSlatType(const char* file = "/Users/aphecetc/Workspace/aliroot/MUON/mapping/data/station345/DetElemIdToSlatType.dat")
44 std::ifstream in(file);
45 if (!in.good()) return false;
49 while ( in.getline(line,80) )
51 if ( !isdigit(line[0]) ) continue;
52 std::string sline(line);
54 std::string::size_type pos = sline.find_first_of(' ');
55 int detelemid = std::atoi(sline.substr(0,pos).c_str());
56 detElemIdToSlatTypeMap[detelemid] = sline.substr(pos+1);
64 //_____________________________________________________________________________
65 const char* SlatType(int detelemid)
67 if ( detElemIdToSlatTypeMap.empty() ) readDetElemIdToSlatType();
69 std::map<int,std::string>::const_iterator it =
70 detElemIdToSlatTypeMap.find(detelemid);
72 if ( it != detElemIdToSlatTypeMap.end() )
74 return it->second.c_str();
82 //_____________________________________________________________________________
85 // test we can read the map file (detelemid <-> slat type)
86 bool ok = readDetElemIdToSlatType();
92 // now loops over all detelemid and check that:
93 // 1. We can actually read the slat files, both bending and non-bending
94 // 2. Bending and non-bending slats do have the same x-size
96 std::map<int,std::string>::const_iterator it;
97 std::set<std::string> slattypes;
98 std::map<std::string,std::string> problems;
100 for ( it = detElemIdToSlatTypeMap.begin(); it != detElemIdToSlatTypeMap.end();
103 slattypes.insert(it->second);
104 std::cout << it->first << " : " << it->second << " ";
105 AliMpSlat* b = static_cast<AliMpSlat*>
106 (AliMpSegmentationManager::Segmentation(it->first,AliMp::kBendingPlane));
107 AliMpSlat* nb = static_cast<AliMpSlat*>
108 (AliMpSegmentationManager::Segmentation(it->first,AliMp::kNonBendingPlane));
109 std::cout << " B : " << b << " NB : " << nb;
112 std::ostringstream pb;
120 std::cout << " Missing BENDING. ";
128 std::cout << " Missing NON-BENDING.";
130 std::cout << std::endl;
137 // Find which pcb(s) have a different size
138 if ( b->GetSize() != nb->GetSize() )
140 std::cout << "Not the same number of PCBs !" << std::endl;
144 pb << " DIFFERENT SIZES ! Bending= " << bx
145 << " Non-Bending= " << nbx
146 << " delta = " << bx - nbx;
148 for ( size_t i = 0; i < b->GetSize(); ++ i )
150 Double_t delta = b->GetPCB(i)->DX() - nb->GetPCB(i)->DX();
151 if ( fabs(delta*2) > 1E-3 )
153 pb << " DELTA(" << i << ")=" << delta*2;
157 problems[it->second] = pb.str();
162 std::cout << "Number of detelem (per plane): "
163 << detElemIdToSlatTypeMap.size()
165 std::cout << "Number of slat types : " << slattypes.size()
167 std::cout << "(Potential) Problems:" << std::endl;
169 std::map<std::string,std::string>::const_iterator sit;
171 for ( sit = problems.begin(); sit != problems.end(); ++sit )
173 std::cout << sit->first << " : " << sit->second << std::endl;
179 //_____________________________________________________________________________
180 bool getSegmentation(int detElemId,
181 AliMpPlaneType bendingornot,
182 AliMUONVGeometryDESegmentation*& oldSegm,
183 AliMUONVGeometryDESegmentation*& newSegm)
185 AliMUON* muon = static_cast<AliMUON*>(gAlice->GetModule("MUON"));
188 gAlice->Init("${ALICE_ROOT}/MUON/Config.C");
189 muon = static_cast<AliMUON*>(gAlice->GetModule("MUON"));
190 if (!muon) return error("Cannot get MUON !");
193 int ichamber = detElemId/100 - 1;
194 // std::cout << "muon->Chamber(" << ichamber << ")" << std::endl;
195 AliMUONChamber& chamber = muon->Chamber(ichamber);
198 if ( bendingornot == AliMp::kNonBendingPlane ) icathode = 2;
200 AliMUONGeometrySegmentation* gs = chamber.SegmentationModel2(icathode);
201 if (!gs) return error(Form("Cannot get cathode %d",icathode));
203 oldSegm = const_cast<AliMUONVGeometryDESegmentation*>(gs->GetDESegmentation(detElemId));
206 return error(Form("Cannot get segmentation for detElemId",detElemId));
210 new AliMUONSt345SlatSegmentationV2(detElemId,bendingornot);
215 //_____________________________________________________________________________
216 Int_t countPads(AliMUONVGeometryDESegmentation* seg)
222 for ( Int_t ix = 1; ix <= seg->Npx(); ++ix )
224 for ( Int_t iy = 1; iy <= seg->Npy(); ++iy )
226 if ( seg->HasPad(ix,iy) ) ++npads;
232 //_____________________________________________________________________________
233 bool testIC(Int_t d1, Int_t d2, AliMpPlaneType bendingornot)
235 readDetElemIdToSlatType();
236 AliMUONVGeometryDESegmentation* o;
237 AliMUONVGeometryDESegmentation* n;
241 for ( Int_t d = d1; d <= d2; ++d )
243 if ( detElemIdToSlatTypeMap.find(d) == detElemIdToSlatTypeMap.end() ) continue;
244 std::cout << d << std::endl;
245 bool ok = getSegmentation(d,bendingornot,o,n);
246 if (!ok) return false;
248 Int_t nx = std::max(o->Npx(),n->Npx());
249 Int_t ny = std::max(o->Npy(),n->Npy());
251 for ( Int_t ix = 1; ix <= nx; ++ix )
253 for ( Int_t iy = 1; iy <= ny; ++iy )
257 if ( !o->HasPad(ix,iy) || !n->HasPad(ix,iy) ) continue;
258 o->GetPadC(ix,iy,xo,yo,zo);
259 n->GetPadC(ix,iy,xn,yn,zn);
261 if ( !equal(xn,xo) || !equal(yn,yo) )
263 printf("%4d (%4d,%4d) -> OLD (%e,%e) NEW (%e,%e) DELTA (%e,%e)\n",d,ix,iy,xo,yo,xn,yn,xn-xo,yn-yo);
265 // Now tries to go back to ix,iy from positions
268 o->GetPadI(xo,yo,zo,oix,oiy);
269 n->GetPadI(xn,yn,zn,nix,niy);
271 if ( ix != oix || iy != oiy )
275 if ( ix != nix || iy != niy )
281 printf("Circular test failed for %s : (%4d,%4d) -> OLD (%e,%e) NEW (%e,%e) -> OLD (%4d,%4d) NEW (%4d,%4d)\n",msg.c_str(),ix,iy,xo,yo,xn,yn,oix,oiy,nix,niy);
288 std::cout << "Number of tested pads = " << ntested << std::endl;
293 //_____________________________________________________________________________
294 void countPads(Int_t d1, Int_t d2)
296 readDetElemIdToSlatType();
300 AliMUONVGeometryDESegmentation* o;
301 AliMUONVGeometryDESegmentation* n;
303 AliMpPlaneType pt[] = { AliMp::kNonBendingPlane, AliMp::kBendingPlane };
305 for ( int ipt = 0; ipt < 2; ++ipt )
307 std::cout << ( (pt[ipt] == AliMp::kNonBendingPlane )?"NonBending"
312 for ( Int_t d = d1; d <= d2; ++d )
314 if ( detElemIdToSlatTypeMap.find(d) == detElemIdToSlatTypeMap.end() )
315 continue; // skip non-existing detElemId
316 bool ok = getSegmentation(d,pt[ipt],o,n);
318 Int_t nn = countPads(n);
319 Int_t oo = countPads(o);
322 printf("%4d OLD %5d NEW %5d Delta %6d OLDIXMAX %3d NEWIXMAX %3d\n",d,oo,nn,nn-oo,(o?o->Npx():0),n->Npx());
326 std::cout << "OLD:" << p_onpads << std::endl
327 << "NEW:" << p_nnpads << std::endl;
332 std::cout << "-----" << std::endl
333 << "OLD:" << onpads << std::endl
334 << "NEW:" << nnpads << std::endl;