2 // $MpId: testSegmentation.C,v 1.1 2005/09/19 19:02:53 ivana Exp $
6 #include "AliMUONChamber.h"
7 #include "AliMUONGeometrySegmentation.h"
8 #include "AliMUONVGeometryDESegmentation.h"
9 #include "AliMpPlaneType.h"
10 #include "AliMUONSt345SlatSegmentationV2.h"
11 //#include "AliMpSt345Reader.h"
12 #include "AliMpSegmentationManager.h"
13 #include "AliMpSlat.h"
22 std::map<int,std::string> detElemIdToSlatTypeMap;
24 //_____________________________________________________________________________
25 bool equal(double a, double b, double epsilon=1e-5)
27 double d = fabs(a-b)/b;
28 if ( d < epsilon ) return true;
32 //_____________________________________________________________________________
33 bool error(const char* msg)
35 std::cout << msg << std::endl;
39 //_____________________________________________________________________________
40 bool readDetElemIdToSlatType(const char* file = "/Users/aphecetc/Workspace/aliroot/MUON/mapping/data/station345/DetElemIdToSlatType.dat")
42 std::ifstream in(file);
43 if (!in.good()) return false;
47 while ( in.getline(line,80) )
49 if ( !isdigit(line[0]) ) continue;
50 std::string sline(line);
52 std::string::size_type pos = sline.find_first_of(' ');
53 int detelemid = std::atoi(sline.substr(0,pos).c_str());
54 detElemIdToSlatTypeMap[detelemid] = sline.substr(pos+1);
62 //_____________________________________________________________________________
63 const char* SlatType(int detelemid)
65 if ( detElemIdToSlatTypeMap.empty() ) readDetElemIdToSlatType();
67 std::map<int,std::string>::const_iterator it =
68 detElemIdToSlatTypeMap.find(detelemid);
70 if ( it != detElemIdToSlatTypeMap.end() )
72 return it->second.c_str();
80 //_____________________________________________________________________________
83 // test we can read the map file (detelemid <-> slat type)
84 bool ok = readDetElemIdToSlatType();
90 // now loops over all detelemid and check that:
91 // 1. We can actually read the slat files, both bending and non-bending
92 // 2. Bending and non-bending slats do have the same x-size
94 std::map<int,std::string>::const_iterator it;
95 std::set<std::string> slattypes;
96 std::map<std::string,std::string> problems;
98 for ( it = detElemIdToSlatTypeMap.begin(); it != detElemIdToSlatTypeMap.end();
101 slattypes.insert(it->second);
102 std::cout << it->first << " : " << it->second << " ";
103 AliMpSlat* b = static_cast<AliMpSlat*>
104 (AliMpSegmentationManager::Segmentation(it->first,AliMp::kBendingPlane));
105 AliMpSlat* nb = static_cast<AliMpSlat*>
106 (AliMpSegmentationManager::Segmentation(it->first,AliMp::kNonBendingPlane));
107 std::cout << " B : " << b << " NB : " << nb;
110 std::ostringstream pb;
118 std::cout << " Missing BENDING. ";
126 std::cout << " Missing NON-BENDING.";
128 std::cout << std::endl;
135 // Find which pcb(s) have a different size
136 if ( b->GetSize() != nb->GetSize() )
138 std::cout << "Not the same number of PCBs !" << std::endl;
142 pb << " DIFFERENT SIZES ! Bending= " << bx
143 << " Non-Bending= " << nbx
144 << " delta = " << bx - nbx;
146 for ( size_t i = 0; i < b->GetSize(); ++ i )
148 Double_t delta = b->GetPCB(i)->DX() - nb->GetPCB(i)->DX();
149 if ( fabs(delta*2) > 1E-3 )
151 pb << " DELTA(" << i << ")=" << delta*2;
155 problems[it->second] = pb.str();
160 std::cout << "Number of detelem (per plane): "
161 << detElemIdToSlatTypeMap.size()
163 std::cout << "Number of slat types : " << slattypes.size()
165 std::cout << "(Potential) Problems:" << std::endl;
167 std::map<std::string,std::string>::const_iterator sit;
169 for ( sit = problems.begin(); sit != problems.end(); ++sit )
171 std::cout << sit->first << " : " << sit->second << std::endl;
177 //_____________________________________________________________________________
178 bool getSegmentation(int detElemId,
179 AliMpPlaneType bendingornot,
180 AliMUONVGeometryDESegmentation*& oldSegm,
181 AliMUONVGeometryDESegmentation*& newSegm)
183 AliMUON* muon = static_cast<AliMUON*>(gAlice->GetModule("MUON"));
186 gAlice->Init("${ALICE_ROOT}/MUON/Config.C");
187 muon = static_cast<AliMUON*>(gAlice->GetModule("MUON"));
188 if (!muon) return error("Cannot get MUON !");
191 int ichamber = detElemId/100 - 1;
192 // std::cout << "muon->Chamber(" << ichamber << ")" << std::endl;
193 AliMUONChamber& chamber = muon->Chamber(ichamber);
196 if ( bendingornot == AliMp::kNonBendingPlane ) icathode = 2;
198 AliMUONGeometrySegmentation* gs = chamber.SegmentationModel2(icathode);
199 if (!gs) return error(Form("Cannot get cathode %d",icathode));
201 oldSegm = const_cast<AliMUONVGeometryDESegmentation*>(gs->GetDESegmentation(detElemId));
204 return error(Form("Cannot get segmentation for detElemId",detElemId));
208 new AliMUONSt345SlatSegmentationV2(detElemId,bendingornot);
213 //_____________________________________________________________________________
214 Int_t countPads(AliMUONVGeometryDESegmentation* seg)
220 for ( Int_t ix = 1; ix <= seg->Npx(); ++ix )
222 for ( Int_t iy = 1; iy <= seg->Npy(); ++iy )
224 if ( seg->HasPad(ix,iy) ) ++npads;
230 //_____________________________________________________________________________
231 bool testIC(Int_t d1, Int_t d2, AliMpPlaneType bendingornot)
233 readDetElemIdToSlatType();
234 AliMUONVGeometryDESegmentation* o;
235 AliMUONVGeometryDESegmentation* n;
239 for ( Int_t d = d1; d <= d2; ++d )
241 if ( detElemIdToSlatTypeMap.find(d) == detElemIdToSlatTypeMap.end() ) continue;
242 std::cout << d << std::endl;
243 bool ok = getSegmentation(d,bendingornot,o,n);
244 if (!ok) return false;
246 Int_t nx = std::max(o->Npx(),n->Npx());
247 Int_t ny = std::max(o->Npy(),n->Npy());
249 for ( Int_t ix = 1; ix <= nx; ++ix )
251 for ( Int_t iy = 1; iy <= ny; ++iy )
255 if ( !o->HasPad(ix,iy) || !n->HasPad(ix,iy) ) continue;
256 o->GetPadC(ix,iy,xo,yo,zo);
257 n->GetPadC(ix,iy,xn,yn,zn);
259 if ( !equal(xn,xo) || !equal(yn,yo) )
261 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);
263 // Now tries to go back to ix,iy from positions
266 o->GetPadI(xo,yo,zo,oix,oiy);
267 n->GetPadI(xn,yn,zn,nix,niy);
269 if ( ix != oix || iy != oiy )
273 if ( ix != nix || iy != niy )
279 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);
286 std::cout << "Number of tested pads = " << ntested << std::endl;
291 //_____________________________________________________________________________
292 void countPads(Int_t d1, Int_t d2)
294 readDetElemIdToSlatType();
298 AliMUONVGeometryDESegmentation* o;
299 AliMUONVGeometryDESegmentation* n;
301 AliMpPlaneType pt[] = { AliMp::kNonBendingPlane, AliMp::kBendingPlane };
303 for ( int ipt = 0; ipt < 2; ++ipt )
305 std::cout << ( (pt[ipt] == AliMp::kNonBendingPlane )?"NonBending"
310 for ( Int_t d = d1; d <= d2; ++d )
312 if ( detElemIdToSlatTypeMap.find(d) == detElemIdToSlatTypeMap.end() )
313 continue; // skip non-existing detElemId
314 bool ok = getSegmentation(d,pt[ipt],o,n);
316 Int_t nn = countPads(n);
317 Int_t oo = countPads(o);
320 printf("%4d OLD %5d NEW %5d Delta %6d OLDIXMAX %3d NEWIXMAX %3d\n",d,oo,nn,nn-oo,(o?o->Npx():0),n->Npx());
324 std::cout << "OLD:" << p_onpads << std::endl
325 << "NEW:" << p_nnpads << std::endl;
330 std::cout << "-----" << std::endl
331 << "OLD:" << onpads << std::endl
332 << "NEW:" << nnpads << std::endl;